diff mbox

Fix implicit cast to float (Was:Re: Initializing float variables without type suffix)

Message ID OFA9A147C1.624E6D79-ONC1257555.00437599-C1257555.00469A67@br-automation.com (mailing list archive)
State Mainlined, archived
Headers show

Commit Message

Thomas Schmid Feb. 6, 2009, 12:51 p.m. UTC
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

Signed-Off-By: Thomas Schmid <Thomas.Schmid@br-automation.com>

--
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

Comments

Christopher Li Feb. 9, 2009, 7:37 a.m. UTC | #1
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
Thomas Schmid Feb. 9, 2009, 1:38 p.m. UTC | #2
christ.li@gmail.com schrieb am 09.02.2009 08:37:50:

> 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.

Thank you for correcting, your changes work fine for me.

There's only a little problem with the patch,
patch breaks off in evaluate.c, cause there's no function "is_void_type" 
within...

Greetings
Thomas Schmid
--
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
Christopher Li Feb. 9, 2009, 7:15 p.m. UTC | #3
I guess you apply the patch on the official sparse's tree.

The patch is base on my development tree here:

http://git.kernel.org/?p=devel/sparse/chrisl/sparse.git;a=summary

is_type_void() is introduced at change 405cd6edfe2e88c808f0a45f0c2ef92a854dbe67,
warn about explicit usage of sizeof(void).

Chris

On Mon, Feb 9, 2009 at 5:38 AM, Thomas Schmid
<Thomas.Schmid@br-automation.com> wrote:
> christ.li@gmail.com schrieb am 09.02.2009 08:37:50:
>
>> 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.
>
> Thank you for correcting, your changes work fine for me.
>
> There's only a little problem with the patch,
> patch breaks off in evaluate.c, cause there's no function "is_void_type"
> within...
>
> Greetings
> Thomas Schmid
>
--
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
diff mbox

Patch

Index: sparse/expand.c
===================================================================
--- sparse.orig/expand.c        2009-02-06 11:37:17.717913100 +0100
+++ sparse/expand.c     2009-02-06 11:37:34.973482600 +0100
@@ -116,7 +116,7 @@  Int:
        return;
 
 Float:
-       if (newtype->ctype.base_type != &fp_type) {
+       if (is_int_type(newtype)) {
                value = (long long)old->fvalue;
                expr->type = EXPR_VALUE;
                expr->taint = 0;
@@ -126,7 +126,7 @@  Float:
        if (oldtype->ctype.base_type != &fp_type)
                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))