public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/35163] New: folding comparison loses cast
@ 2008-02-11 9:30 Tom dot de dot Vries at Nxp dot com
2008-02-11 10:45 ` [Bug c/35163] " steven at gcc dot gnu dot org
` (9 more replies)
0 siblings, 10 replies; 11+ messages in thread
From: Tom dot de dot Vries at Nxp dot com @ 2008-02-11 9:30 UTC (permalink / raw)
To: gcc-bugs
test.c:
...
int main() {
signed char a = -30;
/* a == sE2 (-30 signed char) */
signed char b = -31;
/* b == sE1 (-31 signed char) */
int r = a <= (unsigned short)b;
/* (unsigned short)b == uFFE1 (65505 unsigned short) */
/*
r
==
a <= (unsigned short)b
==
sE2 <= uFFE1
== arithmetic conversion, rule integral promotion
sFFFFFFE2 <= s0000FFE1
==
-30 <= 65505
==
1
*/
/* gcc evaluates r to 0 instead */
return r;
}
...
The problem seems to occur during a call to
fold-const.c:fold_widened_comparison(), which calls tree.c:get_unwidened():
...
/* Return OP, stripped of any conversions to wider types as much as is safe.
Converting the value back to OP's type makes a value equivalent to OP.
If FOR_TYPE is nonzero, we return a value which, if converted to
type FOR_TYPE, would be equivalent to converting OP to type FOR_TYPE.
If FOR_TYPE is nonzero, unaligned bit-field references may be changed to the
narrowest type that can hold the value, even if they don't exactly fit.
Otherwise, bit-field references are changed to a narrower type
only if they can be fetched directly from memory in that type.
OP must have integer, real or enumeral type. Pointers are not allowed!
There are some cases where the obvious value we could return
would regenerate to OP if converted to OP's type,
but would not extend like OP to wider types.
If FOR_TYPE indicates such extension is contemplated, we eschew such values.
For example, if OP is (unsigned short)(signed char)-1,
we avoid returning (signed char)-1 if FOR_TYPE is int,
even though extending that to an unsigned short would regenerate OP,
since the result of extending (signed char)-1 to (int)
is different from (int) OP. */
tree
get_unwidened (tree op, tree for_type)
...
get_unwidened() is called with op == (int)(unsigned short)-31sc and for_type ==
signed char.
get unwidened() returns -31sc. However, 'Converting the value back to OP's type
makes a value equivalent to OP' would mean convert (int)-31sc == (int)(unsigned
short)-31sc, which is not correct:
(int)-31sc == (int)(unsigned short)-31sc
<==>
(int)-31sc == (int)65505us
<==>
-31si == 65505si
<==>
FALSE
--
Summary: folding comparison loses cast
Product: gcc
Version: 4.3.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: Tom dot de dot Vries at Nxp dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35163
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c/35163] folding comparison loses cast
2008-02-11 9:30 [Bug c/35163] New: folding comparison loses cast Tom dot de dot Vries at Nxp dot com
@ 2008-02-11 10:45 ` steven at gcc dot gnu dot org
2008-02-12 17:08 ` [Bug middle-end/35163] " rguenth at gcc dot gnu dot org
` (8 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: steven at gcc dot gnu dot org @ 2008-02-11 10:45 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from steven at gcc dot gnu dot org 2008-02-11 10:44 -------
CCing fold guru.
--
steven at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |rguenth at gcc dot gnu dot
| |org
Status|UNCONFIRMED |NEW
Ever Confirmed|0 |1
Last reconfirmed|0000-00-00 00:00:00 |2008-02-11 10:44:42
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35163
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug middle-end/35163] folding comparison loses cast
2008-02-11 9:30 [Bug c/35163] New: folding comparison loses cast Tom dot de dot Vries at Nxp dot com
2008-02-11 10:45 ` [Bug c/35163] " steven at gcc dot gnu dot org
@ 2008-02-12 17:08 ` rguenth at gcc dot gnu dot org
2008-02-12 19:37 ` [Bug middle-end/35163] [4.1/4.2/4.3 Regression] " rguenth at gcc dot gnu dot org
` (7 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2008-02-12 17:08 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from rguenth at gcc dot gnu dot org 2008-02-12 17:07 -------
I'll have a look.
--
rguenth at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
AssignedTo|unassigned at gcc dot gnu |rguenth at gcc dot gnu dot
|dot org |org
Status|NEW |ASSIGNED
Last reconfirmed|2008-02-11 10:44:42 |2008-02-12 17:07:57
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35163
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug middle-end/35163] [4.1/4.2/4.3 Regression] folding comparison loses cast
2008-02-11 9:30 [Bug c/35163] New: folding comparison loses cast Tom dot de dot Vries at Nxp dot com
2008-02-11 10:45 ` [Bug c/35163] " steven at gcc dot gnu dot org
2008-02-12 17:08 ` [Bug middle-end/35163] " rguenth at gcc dot gnu dot org
@ 2008-02-12 19:37 ` rguenth at gcc dot gnu dot org
2008-02-12 20:00 ` rguenth at gcc dot gnu dot org
` (6 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2008-02-12 19:37 UTC (permalink / raw)
To: gcc-bugs
--
rguenth at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |wrong-code
Known to fail| |3.3.6
Known to work| |2.95.4
Summary|folding comparison loses |[4.1/4.2/4.3 Regression]
|cast |folding comparison loses
| |cast
Target Milestone|--- |4.3.0
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35163
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug middle-end/35163] [4.1/4.2/4.3 Regression] folding comparison loses cast
2008-02-11 9:30 [Bug c/35163] New: folding comparison loses cast Tom dot de dot Vries at Nxp dot com
` (2 preceding siblings ...)
2008-02-12 19:37 ` [Bug middle-end/35163] [4.1/4.2/4.3 Regression] " rguenth at gcc dot gnu dot org
@ 2008-02-12 20:00 ` rguenth at gcc dot gnu dot org
2008-02-12 21:28 ` rguenth at gcc dot gnu dot org
` (5 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2008-02-12 20:00 UTC (permalink / raw)
To: gcc-bugs
------- Comment #3 from rguenth at gcc dot gnu dot org 2008-02-12 19:59 -------
get_unwidened behaves as documented:
If FOR_TYPE is nonzero, we return a value which, if converted to
type FOR_TYPE, would be equivalent to converting OP to type FOR_TYPE.
thus indeed, (signed char)(int)(unsigned short)-41sc == -41sc. But the
bug instead is that fold specifies FOR_TYPE, where it rather should
not specify it and convert the result to shorter_type if and only if this
conversion is not a truncation.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35163
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug middle-end/35163] [4.1/4.2/4.3 Regression] folding comparison loses cast
2008-02-11 9:30 [Bug c/35163] New: folding comparison loses cast Tom dot de dot Vries at Nxp dot com
` (3 preceding siblings ...)
2008-02-12 20:00 ` rguenth at gcc dot gnu dot org
@ 2008-02-12 21:28 ` rguenth at gcc dot gnu dot org
2008-02-12 21:30 ` [Bug middle-end/35163] [4.1/4.2 " rguenth at gcc dot gnu dot org
` (4 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2008-02-12 21:28 UTC (permalink / raw)
To: gcc-bugs
------- Comment #4 from rguenth at gcc dot gnu dot org 2008-02-12 21:27 -------
Subject: Bug 35163
Author: rguenth
Date: Tue Feb 12 21:26:49 2008
New Revision: 132269
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=132269
Log:
2008-02-12 Richard Guenther <rguenther@suse.de>
PR middle-end/35163
* fold-const.c (fold_widened_comparison): Use get_unwidened in
value-preserving mode. Disallow final truncation.
* gcc.c-torture/execute/pr35163.c: New testcase.
Added:
trunk/gcc/testsuite/gcc.c-torture/execute/pr35163.c
Modified:
trunk/gcc/ChangeLog
trunk/gcc/fold-const.c
trunk/gcc/testsuite/ChangeLog
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35163
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug middle-end/35163] [4.1/4.2 Regression] folding comparison loses cast
2008-02-11 9:30 [Bug c/35163] New: folding comparison loses cast Tom dot de dot Vries at Nxp dot com
` (4 preceding siblings ...)
2008-02-12 21:28 ` rguenth at gcc dot gnu dot org
@ 2008-02-12 21:30 ` rguenth at gcc dot gnu dot org
2008-02-17 3:59 ` pmarques at grupopie dot com
` (3 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2008-02-12 21:30 UTC (permalink / raw)
To: gcc-bugs
------- Comment #5 from rguenth at gcc dot gnu dot org 2008-02-12 21:30 -------
Fixed on the trunk.
--
rguenth at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Known to work|2.95.4 |2.95.4 4.3.0
Summary|[4.1/4.2/4.3 Regression] |[4.1/4.2 Regression] folding
|folding comparison loses |comparison loses cast
|cast |
Target Milestone|4.3.0 |4.1.3
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35163
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug middle-end/35163] [4.1/4.2 Regression] folding comparison loses cast
2008-02-11 9:30 [Bug c/35163] New: folding comparison loses cast Tom dot de dot Vries at Nxp dot com
` (5 preceding siblings ...)
2008-02-12 21:30 ` [Bug middle-end/35163] [4.1/4.2 " rguenth at gcc dot gnu dot org
@ 2008-02-17 3:59 ` pmarques at grupopie dot com
2008-03-25 10:15 ` rguenth at gcc dot gnu dot org
` (2 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: pmarques at grupopie dot com @ 2008-02-17 3:59 UTC (permalink / raw)
To: gcc-bugs
------- Comment #6 from pmarques at grupopie dot com 2008-02-17 03:58 -------
Created an attachment (id=15171)
--> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=15171&action=view)
patch to fix testsuite breakage on 16 bit integer targets
Unfortunately, the testcase assumes 32 bit integers and fails on the avr
target.
The attached patch makes the expected type sizes explicit, so that it doesn't
depend on the natural integer size of the target.
The patch was tested for te avr target and it works as expected.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35163
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug middle-end/35163] [4.1/4.2 Regression] folding comparison loses cast
2008-02-11 9:30 [Bug c/35163] New: folding comparison loses cast Tom dot de dot Vries at Nxp dot com
` (6 preceding siblings ...)
2008-02-17 3:59 ` pmarques at grupopie dot com
@ 2008-03-25 10:15 ` rguenth at gcc dot gnu dot org
2008-03-25 10:18 ` rguenth at gcc dot gnu dot org
2008-03-25 10:19 ` rguenth at gcc dot gnu dot org
9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2008-03-25 10:15 UTC (permalink / raw)
To: gcc-bugs
------- Comment #7 from rguenth at gcc dot gnu dot org 2008-03-25 10:14 -------
Subject: Bug 35163
Author: rguenth
Date: Tue Mar 25 10:14:15 2008
New Revision: 133508
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=133508
Log:
2008-03-25 Richard Guenther <rguenther@suse.de>
Backport from mainline:
2008-02-12 Richard Guenther <rguenther@suse.de>
PR middle-end/35163
* fold-const.c (fold_widened_comparison): Use get_unwidened in
value-preserving mode. Disallow final truncation.
* gcc.c-torture/execute/pr35163.c: New testcase.
Added:
branches/gcc-4_2-branch/gcc/testsuite/gcc.c-torture/execute/pr35163.c
- copied unchanged from r132269,
trunk/gcc/testsuite/gcc.c-torture/execute/pr35163.c
Modified:
branches/gcc-4_2-branch/gcc/ChangeLog
branches/gcc-4_2-branch/gcc/fold-const.c
branches/gcc-4_2-branch/gcc/testsuite/ChangeLog
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35163
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug middle-end/35163] [4.1/4.2 Regression] folding comparison loses cast
2008-02-11 9:30 [Bug c/35163] New: folding comparison loses cast Tom dot de dot Vries at Nxp dot com
` (7 preceding siblings ...)
2008-03-25 10:15 ` rguenth at gcc dot gnu dot org
@ 2008-03-25 10:18 ` rguenth at gcc dot gnu dot org
2008-03-25 10:19 ` rguenth at gcc dot gnu dot org
9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2008-03-25 10:18 UTC (permalink / raw)
To: gcc-bugs
------- Comment #8 from rguenth at gcc dot gnu dot org 2008-03-25 10:18 -------
Fixed.
--
rguenth at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Known to fail|3.3.6 |3.3.6 4.1.2 4.2.3
Known to work|2.95.4 4.3.0 |2.95.4 4.1.3 4.2.4 4.3.0
Resolution| |FIXED
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35163
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug middle-end/35163] [4.1/4.2 Regression] folding comparison loses cast
2008-02-11 9:30 [Bug c/35163] New: folding comparison loses cast Tom dot de dot Vries at Nxp dot com
` (8 preceding siblings ...)
2008-03-25 10:18 ` rguenth at gcc dot gnu dot org
@ 2008-03-25 10:19 ` rguenth at gcc dot gnu dot org
9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2008-03-25 10:19 UTC (permalink / raw)
To: gcc-bugs
------- Comment #9 from rguenth at gcc dot gnu dot org 2008-03-25 10:18 -------
Subject: Bug 35163
Author: rguenth
Date: Tue Mar 25 10:17:54 2008
New Revision: 133509
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=133509
Log:
2008-03-25 Richard Guenther <rguenther@suse.de>
Backport from mainline:
2008-02-12 Richard Guenther <rguenther@suse.de>
PR middle-end/35163
* fold-const.c (fold_widened_comparison): Use get_unwidened in
value-preserving mode. Disallow final truncation.
* gcc.c-torture/execute/pr35163.c: New testcase.
Added:
branches/gcc-4_1-branch/gcc/testsuite/gcc.c-torture/execute/pr35163.c
- copied unchanged from r132269,
trunk/gcc/testsuite/gcc.c-torture/execute/pr35163.c
Modified:
branches/gcc-4_1-branch/gcc/ChangeLog
branches/gcc-4_1-branch/gcc/fold-const.c
branches/gcc-4_1-branch/gcc/testsuite/ChangeLog
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35163
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2008-03-25 10:19 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-02-11 9:30 [Bug c/35163] New: folding comparison loses cast Tom dot de dot Vries at Nxp dot com
2008-02-11 10:45 ` [Bug c/35163] " steven at gcc dot gnu dot org
2008-02-12 17:08 ` [Bug middle-end/35163] " rguenth at gcc dot gnu dot org
2008-02-12 19:37 ` [Bug middle-end/35163] [4.1/4.2/4.3 Regression] " rguenth at gcc dot gnu dot org
2008-02-12 20:00 ` rguenth at gcc dot gnu dot org
2008-02-12 21:28 ` rguenth at gcc dot gnu dot org
2008-02-12 21:30 ` [Bug middle-end/35163] [4.1/4.2 " rguenth at gcc dot gnu dot org
2008-02-17 3:59 ` pmarques at grupopie dot com
2008-03-25 10:15 ` rguenth at gcc dot gnu dot org
2008-03-25 10:18 ` rguenth at gcc dot gnu dot org
2008-03-25 10:19 ` rguenth at gcc dot gnu dot 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).