public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/58564] New: possible wrong code bug at -O0
@ 2013-09-28 18:10 regehr at cs dot utah.edu
2013-09-28 21:05 ` [Bug c/58564] " mikpelinux at gmail dot com
` (13 more replies)
0 siblings, 14 replies; 15+ messages in thread
From: regehr at cs dot utah.edu @ 2013-09-28 18:10 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58564
Bug ID: 58564
Summary: possible wrong code bug at -O0
Product: gcc
Version: 4.9.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: regehr at cs dot utah.edu
regehr@john-home ~ $ clang -O0 -w small.c ; ./a.out
0
regehr@john-home ~ $ gcc-4.4 -O0 -w small.c ; ./a.out
0
regehr@john-home ~ $ gcc-4.6 -O0 -w small.c ; ./a.out
0
regehr@john-home ~ $ gcc-4.7 -O0 -w small.c ; ./a.out
1
regehr@john-home ~ $ gcc -O0 -w small.c ; ./a.out
1
regehr@john-home ~ $ cat small.c
int printf(const char *, ...);
int a, b;
short *c;
short **d = &c;
int main() {
b = (0, 0 > ((&c == d) & (1 && a ^ 1))) | 0U;
printf("%d\n", b);
return 0;
}
regehr@john-home ~ $ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/home/regehr/z/compiler-install/gcc-r203005-install/libexec/gcc/x86_64-unknown-linux-gnu/4.9.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: /home/regehr/z/compiler-source/gcc/configure
--prefix=/home/regehr/z/compiler-install/gcc-r203005-install
--enable-languages=c,c++ --disable-multilib
Thread model: posix
gcc version 4.9.0 20130928 (experimental) (GCC)
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c/58564] possible wrong code bug at -O0
2013-09-28 18:10 [Bug c/58564] New: possible wrong code bug at -O0 regehr at cs dot utah.edu
@ 2013-09-28 21:05 ` mikpelinux at gmail dot com
2013-09-28 21:25 ` ktietz at gcc dot gnu.org
` (12 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: mikpelinux at gmail dot com @ 2013-09-28 21:05 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58564
Mikael Pettersson <mikpelinux at gmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |ktietz at gcc dot gnu.org,
| |mikpelinux at gmail dot com
--- Comment #1 from Mikael Pettersson <mikpelinux at gmail dot com> ---
4.6 works, 4.7 to trunk don't, started with Kai's r176563.
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c/58564] possible wrong code bug at -O0
2013-09-28 18:10 [Bug c/58564] New: possible wrong code bug at -O0 regehr at cs dot utah.edu
2013-09-28 21:05 ` [Bug c/58564] " mikpelinux at gmail dot com
@ 2013-09-28 21:25 ` ktietz at gcc dot gnu.org
2013-09-29 3:03 ` regehr at cs dot utah.edu
` (11 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: ktietz at gcc dot gnu.org @ 2013-09-28 21:25 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58564
Kai Tietz <ktietz at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution|--- |INVALID
--- Comment #2 from Kai Tietz <ktietz at gcc dot gnu.org> ---
This sample is invalid. And before 4.7 there seems to be wrong result.
You missed the following here in your expression
0 > ((&c == d) & (1 && a ^ 1))
The term (1 && a ^ 1) is not the same as (1 & (a ^ 1))
instead it means in fact (1 != 0 && (a ^ 1) != 0. By this term reduces correct
to:
a ^ 1 != 0 and this is indentical to a != 1.
by this we see 0 > (&c == d) & (a != 1). And this is exactly that what AST
generates (see here -fdump-tree-original).
So error is invalid. But indeed this testcase demonstrate, that we seem to
have still pointer-arthimetic optimization issues, due the term (&c == d) was
resolved ...
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c/58564] possible wrong code bug at -O0
2013-09-28 18:10 [Bug c/58564] New: possible wrong code bug at -O0 regehr at cs dot utah.edu
2013-09-28 21:05 ` [Bug c/58564] " mikpelinux at gmail dot com
2013-09-28 21:25 ` ktietz at gcc dot gnu.org
@ 2013-09-29 3:03 ` regehr at cs dot utah.edu
2013-09-29 9:23 ` mikpelinux at gmail dot com
` (10 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: regehr at cs dot utah.edu @ 2013-09-29 3:03 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58564
--- Comment #3 from John Regehr <regehr at cs dot utah.edu> ---
Kai, this is a real bug, please reopen it.
Here is what I get out of -fdump-tree-original:
b = (int) (d == &c && a != 1);
This is wrong.
One way to illustrate the problem is to remove the useless comma operator from
the test case, which now looks like this (I've also added parens around the ^):
int printf(const char *, ...);
int a, b;
short *c;
short **d = &c;
int main() {
b = (0 > ((&c == d) & (1 && (a ^ 1)))) | 0U;
printf("%d\n", b);
return 0;
}
Now -fdump-tree-original does a better job:
b = (int) (d == &c && a != 1) < 0;
And now all compilers agree on the output:
[regehr@imp r102]$ gcc-4.4 small2.c ; ./a.out
0
[regehr@imp r102]$ gcc-4.5 small2.c ; ./a.out
0
[regehr@imp r102]$ gcc-4.6 small2.c ; ./a.out
0
[regehr@imp r102]$ gcc small2.c ; ./a.out
0
[regehr@imp r102]$ clang small2.c ; ./a.out
0
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c/58564] possible wrong code bug at -O0
2013-09-28 18:10 [Bug c/58564] New: possible wrong code bug at -O0 regehr at cs dot utah.edu
` (2 preceding siblings ...)
2013-09-29 3:03 ` regehr at cs dot utah.edu
@ 2013-09-29 9:23 ` mikpelinux at gmail dot com
2013-09-30 6:53 ` ktietz at gcc dot gnu.org
` (9 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: mikpelinux at gmail dot com @ 2013-09-29 9:23 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58564
--- Comment #4 from Mikael Pettersson <mikpelinux at gmail dot com> ---
(In reply to John Regehr from comment #3)
> Kai, this is a real bug, please reopen it.
>
> Here is what I get out of -fdump-tree-original:
>
> b = (int) (d == &c && a != 1);
>
> This is wrong.
>
> One way to illustrate the problem is to remove the useless comma operator
> from the test case, which now looks like this (I've also added parens around
> the ^):
I can confirm this observation. Adding parentheses around the "a ^ 1" makes no
difference, but removing the comma operator and its left operand "0, " makes
4.7 to trunk compute the same result as 4.6 and older did.
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c/58564] possible wrong code bug at -O0
2013-09-28 18:10 [Bug c/58564] New: possible wrong code bug at -O0 regehr at cs dot utah.edu
` (3 preceding siblings ...)
2013-09-29 9:23 ` mikpelinux at gmail dot com
@ 2013-09-30 6:53 ` ktietz at gcc dot gnu.org
2013-09-30 8:43 ` [Bug middle-end/58564] [4.7/4.8/4.9 Regression] " jakub at gcc dot gnu.org
` (8 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: ktietz at gcc dot gnu.org @ 2013-09-30 6:53 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58564
Kai Tietz <ktietz at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|RESOLVED |REOPENED
Last reconfirmed| |2013-09-30
Resolution|INVALID |---
Ever confirmed|0 |1
--- Comment #5 from Kai Tietz <ktietz at gcc dot gnu.org> ---
Sorry, missed that outer condition is 0 > ... boolean-typed-expr.
Can confirm this issue. Btw this condition has to be always false for unsigned
1-bit precision typed integrals.
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug middle-end/58564] [4.7/4.8/4.9 Regression] possible wrong code bug at -O0
2013-09-28 18:10 [Bug c/58564] New: possible wrong code bug at -O0 regehr at cs dot utah.edu
` (4 preceding siblings ...)
2013-09-30 6:53 ` ktietz at gcc dot gnu.org
@ 2013-09-30 8:43 ` jakub at gcc dot gnu.org
2013-09-30 9:41 ` jakub at gcc dot gnu.org
` (7 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: jakub at gcc dot gnu.org @ 2013-09-30 8:43 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58564
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jakub at gcc dot gnu.org
Component|c |middle-end
Target Milestone|--- |4.7.4
Summary|possible wrong code bug at |[4.7/4.8/4.9 Regression]
|-O0 |possible wrong code bug at
| |-O0
--- Comment #6 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
I think the bug is in the
/* A < 0 ? <sign bit of A> : 0 is simply (A & <sign bit of A>). */
if (TREE_CODE (arg0) == LT_EXPR
&& integer_zerop (TREE_OPERAND (arg0, 1))
&& integer_zerop (op2)
&& (tem = sign_bit_p (TREE_OPERAND (arg0, 0), arg1)))
...
transformation in fold_ternary_loc or sign_bit_p or combination thereof.
We get here with arg0 ((int) (d == &c && a != 1)) < 0, arg1 1U and arg2 0U,
sign_bit_p (surprisingly) looks through zero extensions (of bool to int)
and returns (d == &c && a != 1) and we incorrectly fold it as
(d == &c && a != 1) & 1.
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug middle-end/58564] [4.7/4.8/4.9 Regression] possible wrong code bug at -O0
2013-09-28 18:10 [Bug c/58564] New: possible wrong code bug at -O0 regehr at cs dot utah.edu
` (5 preceding siblings ...)
2013-09-30 8:43 ` [Bug middle-end/58564] [4.7/4.8/4.9 Regression] " jakub at gcc dot gnu.org
@ 2013-09-30 9:41 ` jakub at gcc dot gnu.org
2013-09-30 9:56 ` jakub at gcc dot gnu.org
` (6 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: jakub at gcc dot gnu.org @ 2013-09-30 9:41 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58564
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|REOPENED |ASSIGNED
Assignee|unassigned at gcc dot gnu.org |jakub at gcc dot gnu.org
--- Comment #7 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Created attachment 30932
--> http://gcc.gnu.org/bugzilla/attachment.cgi?id=30932&action=edit
gcc49-pr58564.patch
Untested fix.
Note, this patch doesn't attempt to fold the zero extension of something < 0
into 0 resp. side-effects of something, 0, because I think we are generally
trying to move away from adding further new stuff to fold-const.c, and rather
should improve GIMPLE optimizations.
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug middle-end/58564] [4.7/4.8/4.9 Regression] possible wrong code bug at -O0
2013-09-28 18:10 [Bug c/58564] New: possible wrong code bug at -O0 regehr at cs dot utah.edu
` (6 preceding siblings ...)
2013-09-30 9:41 ` jakub at gcc dot gnu.org
@ 2013-09-30 9:56 ` jakub at gcc dot gnu.org
2013-09-30 20:15 ` jakub at gcc dot gnu.org
` (5 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: jakub at gcc dot gnu.org @ 2013-09-30 9:56 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58564
--- Comment #8 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Created attachment 30933
--> http://gcc.gnu.org/bugzilla/attachment.cgi?id=30933&action=edit
gcc49-pr58564-nonnegative.patch
Actually, teaching fold that it should fold that < 0 into 0 is easy, just needs
making some checks less strict (they were considering only INTEGER_TYPE,
forgetting about BOOLEAN_TYPE or ENUMERAL_TYPE which IMHO can be handled the
same). This latter patch I'm obviously not going to propose for the older
branches.
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug middle-end/58564] [4.7/4.8/4.9 Regression] possible wrong code bug at -O0
2013-09-28 18:10 [Bug c/58564] New: possible wrong code bug at -O0 regehr at cs dot utah.edu
` (7 preceding siblings ...)
2013-09-30 9:56 ` jakub at gcc dot gnu.org
@ 2013-09-30 20:15 ` jakub at gcc dot gnu.org
2013-09-30 20:16 ` jakub at gcc dot gnu.org
` (4 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: jakub at gcc dot gnu.org @ 2013-09-30 20:15 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58564
--- Comment #9 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Author: jakub
Date: Mon Sep 30 20:15:20 2013
New Revision: 203042
URL: http://gcc.gnu.org/viewcvs?rev=203042&root=gcc&view=rev
Log:
PR middle-end/58564
* fold-const.c (fold_ternary_loc): For A < 0 : <sign bit of A> : 0
optimization, punt if sign_bit_p looked through any zero extension.
* gcc.c-torture/execute/pr58564.c: New test.
Added:
trunk/gcc/testsuite/gcc.c-torture/execute/pr58564.c
Modified:
trunk/gcc/ChangeLog
trunk/gcc/fold-const.c
trunk/gcc/testsuite/ChangeLog
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug middle-end/58564] [4.7/4.8/4.9 Regression] possible wrong code bug at -O0
2013-09-28 18:10 [Bug c/58564] New: possible wrong code bug at -O0 regehr at cs dot utah.edu
` (8 preceding siblings ...)
2013-09-30 20:15 ` jakub at gcc dot gnu.org
@ 2013-09-30 20:16 ` jakub at gcc dot gnu.org
2013-09-30 20:17 ` jakub at gcc dot gnu.org
` (3 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: jakub at gcc dot gnu.org @ 2013-09-30 20:16 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58564
--- Comment #10 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Author: jakub
Date: Mon Sep 30 20:16:14 2013
New Revision: 203043
URL: http://gcc.gnu.org/viewcvs?rev=203043&root=gcc&view=rev
Log:
PR middle-end/58564
* fold-const.c (fold_ternary_loc): For A < 0 : <sign bit of A> : 0
optimization, punt if sign_bit_p looked through any zero extension.
* gcc.c-torture/execute/pr58564.c: New test.
Added:
branches/gcc-4_8-branch/gcc/testsuite/gcc.c-torture/execute/pr58564.c
Modified:
branches/gcc-4_8-branch/gcc/ChangeLog
branches/gcc-4_8-branch/gcc/fold-const.c
branches/gcc-4_8-branch/gcc/testsuite/ChangeLog
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug middle-end/58564] [4.7/4.8/4.9 Regression] possible wrong code bug at -O0
2013-09-28 18:10 [Bug c/58564] New: possible wrong code bug at -O0 regehr at cs dot utah.edu
` (9 preceding siblings ...)
2013-09-30 20:16 ` jakub at gcc dot gnu.org
@ 2013-09-30 20:17 ` jakub at gcc dot gnu.org
2013-09-30 20:18 ` [Bug middle-end/58564] [4.7 " jakub at gcc dot gnu.org
` (2 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: jakub at gcc dot gnu.org @ 2013-09-30 20:17 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58564
--- Comment #11 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Author: jakub
Date: Mon Sep 30 20:17:07 2013
New Revision: 203044
URL: http://gcc.gnu.org/viewcvs?rev=203044&root=gcc&view=rev
Log:
PR middle-end/58564
* fold-const.c (tree_unary_nonnegative_warnv_p): Use
INTEGRAL_TYPE_P (t) instead of TREE_CODE (t) == INTEGER_TYPE.
Modified:
trunk/gcc/ChangeLog
trunk/gcc/fold-const.c
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug middle-end/58564] [4.7 Regression] possible wrong code bug at -O0
2013-09-28 18:10 [Bug c/58564] New: possible wrong code bug at -O0 regehr at cs dot utah.edu
` (10 preceding siblings ...)
2013-09-30 20:17 ` jakub at gcc dot gnu.org
@ 2013-09-30 20:18 ` jakub at gcc dot gnu.org
2014-05-07 16:06 ` jakub at gcc dot gnu.org
2014-05-07 16:20 ` jakub at gcc dot gnu.org
13 siblings, 0 replies; 15+ messages in thread
From: jakub at gcc dot gnu.org @ 2013-09-30 20:18 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58564
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Summary|[4.7/4.8/4.9 Regression] |[4.7 Regression] possible
|possible wrong code bug at |wrong code bug at -O0
|-O0 |
--- Comment #12 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Should be fixed for 4.8.2+ so far.
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug middle-end/58564] [4.7 Regression] possible wrong code bug at -O0
2013-09-28 18:10 [Bug c/58564] New: possible wrong code bug at -O0 regehr at cs dot utah.edu
` (11 preceding siblings ...)
2013-09-30 20:18 ` [Bug middle-end/58564] [4.7 " jakub at gcc dot gnu.org
@ 2014-05-07 16:06 ` jakub at gcc dot gnu.org
2014-05-07 16:20 ` jakub at gcc dot gnu.org
13 siblings, 0 replies; 15+ messages in thread
From: jakub at gcc dot gnu.org @ 2014-05-07 16:06 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58564
--- Comment #13 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Author: jakub
Date: Wed May 7 16:05:38 2014
New Revision: 210174
URL: http://gcc.gnu.org/viewcvs?rev=210174&root=gcc&view=rev
Log:
Backported from mainline
2013-09-30 Jakub Jelinek <jakub@redhat.com>
PR middle-end/58564
* fold-const.c (fold_ternary_loc): For A < 0 : <sign bit of A> : 0
optimization, punt if sign_bit_p looked through any zero extension.
* gcc.c-torture/execute/pr58564.c: New test.
Added:
branches/gcc-4_7-branch/gcc/testsuite/gcc.c-torture/execute/pr58564.c
Modified:
branches/gcc-4_7-branch/gcc/ChangeLog
branches/gcc-4_7-branch/gcc/fold-const.c
branches/gcc-4_7-branch/gcc/testsuite/ChangeLog
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug middle-end/58564] [4.7 Regression] possible wrong code bug at -O0
2013-09-28 18:10 [Bug c/58564] New: possible wrong code bug at -O0 regehr at cs dot utah.edu
` (12 preceding siblings ...)
2014-05-07 16:06 ` jakub at gcc dot gnu.org
@ 2014-05-07 16:20 ` jakub at gcc dot gnu.org
13 siblings, 0 replies; 15+ messages in thread
From: jakub at gcc dot gnu.org @ 2014-05-07 16:20 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58564
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution|--- |FIXED
--- Comment #14 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Fixed.
^ permalink raw reply [flat|nested] 15+ messages in thread
end of thread, other threads:[~2014-05-07 16:20 UTC | newest]
Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-09-28 18:10 [Bug c/58564] New: possible wrong code bug at -O0 regehr at cs dot utah.edu
2013-09-28 21:05 ` [Bug c/58564] " mikpelinux at gmail dot com
2013-09-28 21:25 ` ktietz at gcc dot gnu.org
2013-09-29 3:03 ` regehr at cs dot utah.edu
2013-09-29 9:23 ` mikpelinux at gmail dot com
2013-09-30 6:53 ` ktietz at gcc dot gnu.org
2013-09-30 8:43 ` [Bug middle-end/58564] [4.7/4.8/4.9 Regression] " jakub at gcc dot gnu.org
2013-09-30 9:41 ` jakub at gcc dot gnu.org
2013-09-30 9:56 ` jakub at gcc dot gnu.org
2013-09-30 20:15 ` jakub at gcc dot gnu.org
2013-09-30 20:16 ` jakub at gcc dot gnu.org
2013-09-30 20:17 ` jakub at gcc dot gnu.org
2013-09-30 20:18 ` [Bug middle-end/58564] [4.7 " jakub at gcc dot gnu.org
2014-05-07 16:06 ` jakub at gcc dot gnu.org
2014-05-07 16:20 ` jakub 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).