linux-sparse.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Christopher Li <sparse@chrisli.org>
To: Thomas Schmid <Thomas.Schmid@br-automation.com>
Cc: Josh Triplett <josht@linux.vnet.ibm.com>, linux-sparse@vger.kernel.org
Subject: Re: [PATCH] Fix implicit cast to float (Was:Re: Initializing float variables without type suffix)
Date: Sun, 8 Feb 2009 23:37:50 -0800	[thread overview]
Message-ID: <70318cbf0902082337r250543c8ic94c0f8f6517565a@mail.gmail.com> (raw)
In-Reply-To: <OFA9A147C1.624E6D79-ONC1257555.00437599-C1257555.00469A67@br-automation.com>

[-- Attachment #1: Type: text/plain, Size: 501 bytes --]

On Fri, Feb 6, 2009 at 4:51 AM, Thomas Schmid
<Thomas.Schmid@br-automation.com> wrote:
> christ.li@gmail.com schrieb am 06.02.2009 05:15:37:
> -       if (newtype->ctype.base_type != &fp_type) {
> +       if (is_int_type(newtype)) {

I change your patch a little bit. The old logic of testing against float
type is better. The type can be a pointer for example. Then using
the long long value is more correct.

See the patch attached.

If there is not objections. I am going to apply this one.

Chris

[-- Attachment #2: Fix-implicit-cast-to-float-Was-Re-Initializing-float-variables-without-type-suffix.patch --]
[-- Type: application/octet-stream, Size: 3986 bytes --]

From patchwork Fri Feb  6 12:51:34 2009
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Subject: Fix implicit cast to float (Was:Re: Initializing float variables
	without type suffix)
Date: Fri, 06 Feb 2009 12:51:34 -0000
From: Thomas Schmid <Thomas.Schmid@br-automation.com>
X-Patchwork-Id: 5874

christ.li@gmail.com schrieb am 06.02.2009 05:15:37:

> cast_to() seems fine.
> 
> In expanding stage, cast_value() did not cast the constant
> correctly.

You're right, I also noticed this in the meantime.

The decision, whether newtype is int_type or fp_type is not made 
correctly.

The following patch seems to work:

Fix implicit cast to float

Modified by Chris.

Signed-Off-By: Thomas Schmid <Thomas.Schmid@br-automation.com>
Signed-Off-By: Christopher Li <sparse@chrisli.org>

--
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Index: sparse.chrisl/evaluate.c
===================================================================
--- sparse.chrisl.orig/evaluate.c
+++ sparse.chrisl/evaluate.c
@@ -313,37 +313,6 @@ static struct expression * cast_to(struc
 	return expr;
 }
 
-static int is_type_type(struct symbol *type)
-{
-	return (type->ctype.modifiers & MOD_TYPE) != 0;
-}
-
-int is_ptr_type(struct symbol *type)
-{
-	if (type->type == SYM_NODE)
-		type = type->ctype.base_type;
-	return type->type == SYM_PTR || type->type == SYM_ARRAY || type->type == SYM_FN;
-}
-
-static inline int is_float_type(struct symbol *type)
-{
-	if (type->type == SYM_NODE)
-		type = type->ctype.base_type;
-	return type->ctype.base_type == &fp_type;
-}
-
-static inline int is_byte_type(struct symbol *type)
-{
-	return type->bit_size == bits_in_char && type->type != SYM_BITFIELD;
-}
-
-static inline int is_void_type(struct symbol *type)
-{
-	if (type->type == SYM_NODE)
-		type = type->ctype.base_type;
-	return type == &void_ctype;
-}
-
 enum {
 	TYPE_NUM = 1,
 	TYPE_BITFIELD = 2,
Index: sparse.chrisl/expand.c
===================================================================
--- sparse.chrisl.orig/expand.c
+++ sparse.chrisl/expand.c
@@ -116,17 +116,17 @@ Int:
 	return;
 
 Float:
-	if (newtype->ctype.base_type != &fp_type) {
+	if (!is_float_type(newtype)) {
 		value = (long long)old->fvalue;
 		expr->type = EXPR_VALUE;
 		expr->taint = 0;
 		goto Int;
 	}
 
-	if (oldtype->ctype.base_type != &fp_type)
+	if (!is_float_type(oldtype))
 		expr->fvalue = (long double)get_longlong(old);
 	else
-		expr->fvalue = old->value;
+		expr->fvalue = old->fvalue;
 
 	if (!(newtype->ctype.modifiers & MOD_LONGLONG)) {
 		if ((newtype->ctype.modifiers & MOD_LONG))
Index: sparse.chrisl/symbol.h
===================================================================
--- sparse.chrisl.orig/symbol.h
+++ sparse.chrisl/symbol.h
@@ -10,6 +10,7 @@
  */
 
 #include "token.h"
+#include "target.h"
 
 /*
  * An identifier with semantic meaning is a "symbol".
@@ -297,6 +298,37 @@ static inline int is_enum_type(const str
 	return (type->type == SYM_ENUM);
 }
 
+static inline int is_type_type(struct symbol *type)
+{
+	return (type->ctype.modifiers & MOD_TYPE) != 0;
+}
+
+static inline int is_ptr_type(struct symbol *type)
+{
+	if (type->type == SYM_NODE)
+		type = type->ctype.base_type;
+	return type->type == SYM_PTR || type->type == SYM_ARRAY || type->type == SYM_FN;
+}
+
+static inline int is_float_type(struct symbol *type)
+{
+	if (type->type == SYM_NODE)
+		type = type->ctype.base_type;
+	return type->ctype.base_type == &fp_type;
+}
+
+static inline int is_byte_type(struct symbol *type)
+{
+	return type->bit_size == bits_in_char && type->type != SYM_BITFIELD;
+}
+
+static inline int is_void_type(struct symbol *type)
+{
+	if (type->type == SYM_NODE)
+		type = type->ctype.base_type;
+	return type == &void_ctype;
+}
+
 static inline int get_sym_type(struct symbol *type)
 {
 	if (type->type == SYM_NODE)

  reply	other threads:[~2009-02-09  7:37 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-07-22 17:31 Documentation? Anywhere? Ben Greenberg
2008-07-24 22:23 ` Josh Triplett
2009-02-04 14:57   ` Initializing float variables without type suffix Thomas Schmid
2009-02-06  4:15     ` Christopher Li
2009-02-06 12:51       ` [PATCH] Fix implicit cast to float (Was:Re: Initializing float variables without type suffix) Thomas Schmid
2009-02-09  7:37         ` Christopher Li [this message]
2009-02-09 13:38           ` Antwort: " Thomas Schmid
2009-02-09 19:15             ` Christopher Li

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=70318cbf0902082337r250543c8ic94c0f8f6517565a@mail.gmail.com \
    --to=sparse@chrisli.org \
    --cc=Thomas.Schmid@br-automation.com \
    --cc=josht@linux.vnet.ibm.com \
    --cc=linux-sparse@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).