public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/66313] New: Unsafe factorization of a*b+a*c
@ 2015-05-27 18:37 glisse at gcc dot gnu.org
  2015-05-28  7:36 ` [Bug middle-end/66313] " rguenth at gcc dot gnu.org
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: glisse at gcc dot gnu.org @ 2015-05-27 18:37 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66313

            Bug ID: 66313
           Summary: Unsafe factorization of a*b+a*c
           Product: gcc
           Version: 6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: glisse at gcc dot gnu.org
  Target Milestone: ---

int f(int a, int b, int c){
  return a * b + a * c;
}
int main(){
  return f(0, __INT_MAX__, __INT_MAX__);
}

$ gcc -fsanitize=undefined e.c
$ ./a.out
e.c:2:16: runtime error: signed integer overflow: 2147483647 + 2147483647
cannot be represented in type 'int'

But I thought I was only computing 0+0?

f(-1, __INT_MAX__, 1) yields:
e.c:2:16: runtime error: signed integer overflow: 2147483647 + 1 cannot be
represented in type 'int'
e.c:2:10: runtime error: signed integer overflow: -2147483648 * -1 cannot be
represented in type 'int'

I am not very excited about restricting this transformation to
TYPE_OVERFLOW_WRAPS, but the alternative is to cast to unsigned (and back after
the operations), which isn't so nice either.


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2015-10-27 14:12 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-05-27 18:37 [Bug middle-end/66313] New: Unsafe factorization of a*b+a*c glisse at gcc dot gnu.org
2015-05-28  7:36 ` [Bug middle-end/66313] " rguenth at gcc dot gnu.org
2015-07-09 13:17 ` mpolacek at gcc dot gnu.org
2015-07-09 14:00 ` rguenth at gcc dot gnu.org
2015-07-09 14:05 ` mpolacek at gcc dot gnu.org
2015-07-10 11:23 ` mpolacek at gcc dot gnu.org
2015-07-10 11:45 ` mpolacek at gcc dot gnu.org
2015-07-10 11:54 ` rguenth at gcc dot gnu.org
2015-07-10 11:59 ` mpolacek at gcc dot gnu.org
2015-07-10 12:19 ` mpolacek at gcc dot gnu.org
2015-10-27 14:12 ` rguenth at gcc dot gnu.org

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 read-only IMAP folder(s) and NNTP newsgroup(s).