All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dibyendu Majumdar <mobile@majumdar.org.uk>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Linux-Sparse <linux-sparse@vger.kernel.org>
Subject: Re: Cast to double being removed
Date: Sat, 18 Mar 2017 01:30:00 +0000	[thread overview]
Message-ID: <CACXZuxegR3CJK5m0UTXMO6P46W9r1P+iM4tP_NST8xDHSy=qjA@mail.gmail.com> (raw)
In-Reply-To: <CACXZuxd_YRpyfTmubOczp7J8xgaXsW89H4TOk7OqhUJ6nU0cmw@mail.gmail.com>

Hi Linus,

On 17 March 2017 at 10:38, Dibyendu Majumdar <mobile@majumdar.org.uk> wrote:
> On 17 March 2017 at 00:24, Linus Torvalds <torvalds@linux-foundation.org> wrote:
>> There's something seriously screwed up with explicit double casting.
>> See the differences between
>>
>>   double f1(void) { return -1; }
>>   double f2(void) { return (double)-1; }
>>   double f3(void) { return -1.0; }
>>
>> and notice how the first one and third ones actually kind-of make
>> sense. The second one? Not so much, it just uses a 64-bit integer.
>>
>> The bug is already at the parse tree stage, the linearization doesn't
>> even see the cast.
>>
>> I think it's this, in simplify_cast():
>>
>>         /* A cast of a constant? */
>>         if (constant(src)) {
>>                 int sign = orig_type->ctype.modifiers & MOD_SIGNED;
>>                 long long val = get_cast_value(src->value, orig_size,
>> size, sign);
>>                 src = value_pseudo(val);
>>                 goto simplify;
>>         }
>>
>> which doesn't even check whether it's a FP value, it just looks if
>> it's a constant and assumes it's an integer. At least it checks the
>> sign ;)
>>
>
> Thank you for pointing me to the location where the issue might be.
>

It seems that not only here but elsewhere also during simplification
of expressions involving constants there is no check whether the
instruction type is floating point. As a test I simply disabled the
simplification if the instruction type is floating point. Good news is
that while before the paranoia test was hanging and giving many
errors, but now it says:

No failures, defects nor flaws have been discovered.
Rounding appears to conform to the proposed IEEE standard P754.
The arithmetic diagnosed appears to be Excellent!
END OF TEST.

Regards
Dibyendu

  reply	other threads:[~2017-03-18  2:29 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-17  0:00 Cast to double being removed Dibyendu Majumdar
2017-03-17  0:24 ` Linus Torvalds
2017-03-17  9:31   ` [PATCH] fix: expansion of integers to floats Luc Van Oostenryck
2017-03-17 10:38   ` Cast to double being removed Dibyendu Majumdar
2017-03-18  1:30     ` Dibyendu Majumdar [this message]
2017-03-19 15:22 ` Luc Van Oostenryck
2017-03-19 15:43   ` Dibyendu Majumdar
2017-03-19 15:54     ` Luc Van Oostenryck
2017-03-19 15:59       ` Dibyendu Majumdar

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='CACXZuxegR3CJK5m0UTXMO6P46W9r1P+iM4tP_NST8xDHSy=qjA@mail.gmail.com' \
    --to=mobile@majumdar.org.uk \
    --cc=linux-sparse@vger.kernel.org \
    --cc=torvalds@linux-foundation.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.