public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/16790] New: Integer down cast ignored in larger expression
@ 2004-07-27 22:35 andyb at mathworks dot com
  2004-07-27 22:42 ` [Bug c/16790] " andyb at mathworks dot com
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: andyb at mathworks dot com @ 2004-07-27 22:35 UTC (permalink / raw)
  To: gcc-bugs

GCC sometimes ignores integer down casts in larger expressions
starting around version 3.2.2
In GCC 2.95.4, these same downcasts were honored.

The following code snippet is from file int_ops.c

  y_final_1 = (int16_T)(  (int16_T)(u1 << 1)   * mul_const >> nshift_right);
  y_middle  =             (int16_T)(u1 << 1);
  y_final_2 = (int16_T)(       y_middle        * mul_const >> nshift_right);

A programmer would expect y_final_1 and y_final_2 to have the same values
under all conditions.   This is not true with the GCC version 3.2.2 through
to the current.  

y_final_1 = -16384   0xFFFFC000
y_final_2 =  16384   0x00004000

Same sequence of integer operations produced DIFFERENT result.

Compiler log shown below.  I don't see any place on this bugzilla
page to enter the .i file that the bug writing guidelines demand???
I'm hoping the "Commit" button will ask me to upload it or something!
Cheers,
Andy B

bartletta-linux:> /hub/Linux/glibc-2.2.5/i686/apps/gcc-3.4.0/bin/gcc -v
-save-temps -g3 -O0 -o int_ops ../int_ops.c ; int_ops
Reading specs from
/hub/Linux/glibc-2.2.5/i686/apps/gcc-3.4.0/lib/gcc/i686-pc-linux-gnu/3.4.0/specs
Configured with: /home/greg/src/gcc-3.4.0/configure
--prefix=/hub/Linux/glibc-2.2.5/i686/apps/gcc-3.4.0
Thread model: posix
gcc version 3.4.0
/hub/Linux/glibc-2.2.5/i686/apps/gcc-3.4.0/libexec/gcc/i686-pc-linux-gnu/3.4.0/cc1
-E -quiet -v -dD ../int_ops.c -mtune=pentiumpro -fworking-directory -O0 -o int_ops.i
ignoring nonexistent directory
"/hub/Linux/glibc-2.2.5/i686/apps/gcc-3.4.0/lib/gcc/i686-pc-linux-gnu/3.4.0/../../../../i686-pc-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/include
 /hub/Linux/glibc-2.2.5/i686/apps/gcc-3.4.0/include
 /hub/Linux/glibc-2.2.5/i686/apps/gcc-3.4.0/lib/gcc/i686-pc-linux-gnu/3.4.0/include
 /usr/include
End of search list.
 /hub/Linux/glibc-2.2.5/i686/apps/gcc-3.4.0/libexec/gcc/i686-pc-linux-gnu/3.4.0/cc1
-fpreprocessed int_ops.i -quiet -dumpbase int_ops.c -mtune=pentiumpro -auxbase
int_ops -g3 -O0 -version -o int_ops.s
GNU C version 3.4.0 (i686-pc-linux-gnu)
        compiled by GNU C version 3.4.0.
GGC heuristics: --param ggc-min-expand=98 --param ggc-min-heapsize=128673
 as -V -Qy -o int_ops.o int_ops.s
GNU assembler version 2.12 (i686-pc-linux-gnu) using BFD version 2.12
 /hub/Linux/glibc-2.2.5/i686/apps/gcc-3.4.0/libexec/gcc/i686-pc-linux-gnu/3.4.0/collect2
--eh-frame-hdr -m elf_i386 -dynamic-linker /lib/ld-linux.so.2 -o int_ops
/usr/lib/crt1.o /usr/lib/crti.o
/hub/Linux/glibc-2.2.5/i686/apps/gcc-3.4.0/lib/gcc/i686-pc-linux-gnu/3.4.0/crtbegin.o
-L/hub/Linux/glibc-2.2.5/i686/apps/gcc-3.4.0/lib/gcc/i686-pc-linux-gnu/3.4.0
-L/hub/Linux/glibc-2.2.5/i686/apps/gcc-3.4.0/lib/gcc/i686-pc-linux-gnu/3.4.0/../../..
int_ops.o -lgcc -lgcc_eh -lc -lgcc -lgcc_eh
/hub/Linux/glibc-2.2.5/i686/apps/gcc-3.4.0/lib/gcc/i686-pc-linux-gnu/3.4.0/crtend.o
/usr/lib/crtn.o

-- 
           Summary: Integer down cast ignored in larger expression
           Product: gcc
           Version: 3.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: andyb at mathworks dot com
                CC: gcc-bugs at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16790


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

* [Bug c/16790] Integer down cast ignored in larger expression
  2004-07-27 22:35 [Bug c/16790] New: Integer down cast ignored in larger expression andyb at mathworks dot com
@ 2004-07-27 22:42 ` andyb at mathworks dot com
  2004-07-27 23:03 ` pinskia at gcc dot gnu dot org
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: andyb at mathworks dot com @ 2004-07-27 22:42 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From andyb at mathworks dot com  2004-07-27 22:42 -------
Created an attachment (id=6842)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=6842&action=view)
preprocessor output .i file


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16790


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

* [Bug c/16790] Integer down cast ignored in larger expression
  2004-07-27 22:35 [Bug c/16790] New: Integer down cast ignored in larger expression andyb at mathworks dot com
  2004-07-27 22:42 ` [Bug c/16790] " andyb at mathworks dot com
@ 2004-07-27 23:03 ` pinskia at gcc dot gnu dot org
  2004-07-27 23:12 ` [Bug c/16790] [3.3/3.4/3.5 regression] " bangerth at dealii dot org
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-07-27 23:03 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-07-27 23:03 -------
Note 0x8000 is out of range for 16bit ints.

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16790


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

* [Bug c/16790] [3.3/3.4/3.5 regression] Integer down cast ignored in larger expression
  2004-07-27 22:35 [Bug c/16790] New: Integer down cast ignored in larger expression andyb at mathworks dot com
  2004-07-27 22:42 ` [Bug c/16790] " andyb at mathworks dot com
  2004-07-27 23:03 ` pinskia at gcc dot gnu dot org
@ 2004-07-27 23:12 ` bangerth at dealii dot org
  2004-07-27 23:39 ` [Bug middle-end/16790] " pinskia at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: bangerth at dealii dot org @ 2004-07-27 23:12 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From bangerth at dealii dot org  2004-07-27 23:12 -------
Confirmed. A regression in 3.3/3.4/mainline against 2.95. Here's  
a reduced testcase: 
---------------- 
void abort (); 
 
static void compute(unsigned int u1) 
{ 
  unsigned char same_result; 
 
  signed short y_final_1; 
  signed short y_middle; 
  signed short y_final_2; 
 
  y_final_1 = (signed short)( (signed short)(u1 << 1) * 3 >> 1); 
  y_middle  =                 (signed short)(u1 << 1); 
  y_final_2 = (signed short)( y_middle * 3 >> 1); 
 
  if (y_final_1 != y_final_2) 
    abort (); 
} 
 
main() 
{ 
  compute(0x4000U); 
} 
----------------------------- 
 
Note that (0x4000<<1) is just the corner case when casted to signed int, 
since it has only the sign bit set, none of the other bits are set. We 
seem to get this wrong somehow. 
 
W. 

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|                            |1
      Known to fail|                            |3.2.3 3.3.3 3.4.0 3.5.0
      Known to work|                            |2.95
   Last reconfirmed|0000-00-00 00:00:00         |2004-07-27 23:12:21
               date|                            |
            Summary|Integer down cast ignored in|[3.3/3.4/3.5 regression]
                   |larger expression           |Integer down cast ignored in
                   |                            |larger expression
   Target Milestone|---                         |3.3.5


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16790


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

* [Bug middle-end/16790] [3.3/3.4/3.5 regression] Integer down cast ignored in larger expression
  2004-07-27 22:35 [Bug c/16790] New: Integer down cast ignored in larger expression andyb at mathworks dot com
                   ` (2 preceding siblings ...)
  2004-07-27 23:12 ` [Bug c/16790] [3.3/3.4/3.5 regression] " bangerth at dealii dot org
@ 2004-07-27 23:39 ` pinskia at gcc dot gnu dot org
  2004-08-03 21:24 ` cvs-commit at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-07-27 23:39 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-07-27 23:39 -------
To say what happens is this (u1 * 2 is the same as u1 << 1:
(((int) (signed short)(u1 * 2)) * 3)
is being changed by fold (or in the C front-end) into
u1 * 6
most likely because there is a STRIP_NOP or (int)(short)(int_variable) is being changed into int_variable.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |gdr at gcc dot gnu dot org
          Component|c                           |middle-end
           Keywords|                            |wrong-code
   Target Milestone|3.3.5                       |3.4.2


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16790


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

* [Bug middle-end/16790] [3.3/3.4/3.5 regression] Integer down cast ignored in larger expression
  2004-07-27 22:35 [Bug c/16790] New: Integer down cast ignored in larger expression andyb at mathworks dot com
                   ` (3 preceding siblings ...)
  2004-07-27 23:39 ` [Bug middle-end/16790] " pinskia at gcc dot gnu dot org
@ 2004-08-03 21:24 ` cvs-commit at gcc dot gnu dot org
  2004-08-07 21:57 ` [Bug middle-end/16790] [3.3/3.4 " cvs-commit at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu dot org @ 2004-08-03 21:24 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From cvs-commit at gcc dot gnu dot org  2004-08-03 21:24 -------
Subject: Bug 16790

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	sayle@gcc.gnu.org	2004-08-03 21:24:32

Modified files:
	gcc            : ChangeLog fold-const.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/gcc.c-torture/execute: pr16790-1.c 

Log message:
	PR middle-end/16790
	* fold-const.c (extract_muldiv_1) <NOP_EXPR>: Disallow local
	truncations, not just global truncations.
	
	* gcc.c-torture/execute/pr16790-1.c: New test case.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.4785&r2=2.4786
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/fold-const.c.diff?cvsroot=gcc&r1=1.432&r2=1.433
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.4090&r2=1.4091
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.c-torture/execute/pr16790-1.c.diff?cvsroot=gcc&r1=NONE&r2=1.1



-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16790


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

* [Bug middle-end/16790] [3.3/3.4 regression] Integer down cast ignored in larger expression
  2004-07-27 22:35 [Bug c/16790] New: Integer down cast ignored in larger expression andyb at mathworks dot com
                   ` (4 preceding siblings ...)
  2004-08-03 21:24 ` cvs-commit at gcc dot gnu dot org
@ 2004-08-07 21:57 ` cvs-commit at gcc dot gnu dot org
  2004-08-07 22:03 ` [Bug middle-end/16790] [3.3 " pinskia at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu dot org @ 2004-08-07 21:57 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From cvs-commit at gcc dot gnu dot org  2004-08-07 21:56 -------
Subject: Bug 16790

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-3_4-branch
Changes by:	sayle@gcc.gnu.org	2004-08-07 21:56:55

Modified files:
	gcc            : ChangeLog fold-const.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/gcc.c-torture/execute: pr16790-1.c 

Log message:
	PR middle-end/16790
	Backport from mainline.
	* fold-const.c (expand_muldiv_1) <NOP_EXPR>: Disallow local
	truncations, not just global truncations.
	
	* gcc.c-torture/execute/pr16790-1.c: New test case.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=2.2326.2.575&r2=2.2326.2.576
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/fold-const.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.322.2.12&r2=1.322.2.13
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.3389.2.242&r2=1.3389.2.243
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.c-torture/execute/pr16790-1.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=NONE&r2=1.1.4.1



-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16790


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

* [Bug middle-end/16790] [3.3 regression] Integer down cast ignored in larger expression
  2004-07-27 22:35 [Bug c/16790] New: Integer down cast ignored in larger expression andyb at mathworks dot com
                   ` (5 preceding siblings ...)
  2004-08-07 21:57 ` [Bug middle-end/16790] [3.3/3.4 " cvs-commit at gcc dot gnu dot org
@ 2004-08-07 22:03 ` pinskia at gcc dot gnu dot org
  2004-08-08 18:55 ` cvs-commit at gcc dot gnu dot org
  2004-08-08 18:57 ` pinskia at gcc dot gnu dot org
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-08-07 22:03 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-08-07 22:03 -------
Fixed also in 3.4.2.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to work|2.95 3.5.0                  |2.95 3.5.0 3.4.2
            Summary|[3.3/3.4 regression] Integer|[3.3 regression] Integer
                   |down cast ignored in larger |down cast ignored in larger
                   |expression                  |expression
   Target Milestone|3.4.2                       |3.3.5


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16790


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

* [Bug middle-end/16790] [3.3 regression] Integer down cast ignored in larger expression
  2004-07-27 22:35 [Bug c/16790] New: Integer down cast ignored in larger expression andyb at mathworks dot com
                   ` (6 preceding siblings ...)
  2004-08-07 22:03 ` [Bug middle-end/16790] [3.3 " pinskia at gcc dot gnu dot org
@ 2004-08-08 18:55 ` cvs-commit at gcc dot gnu dot org
  2004-08-08 18:57 ` pinskia at gcc dot gnu dot org
  8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu dot org @ 2004-08-08 18:55 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From cvs-commit at gcc dot gnu dot org  2004-08-08 18:55 -------
Subject: Bug 16790

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-3_3-branch
Changes by:	sayle@gcc.gnu.org	2004-08-08 18:55:35

Modified files:
	gcc            : ChangeLog fold-const.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/gcc.c-torture/execute: pr16790-1.c 

Log message:
	2004-08-08  Roger Sayle  <roger@eyesopen.com>
	
	PR middle-end/16790
	Backport from mainline.
	* fold-const.c (expand_muldiv_1) <NOP_EXPR>: Disallow local
	truncations, not just global truncations.
	
	* gcc.c-torture/execute/pr16790-1.c: New test case.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.16114.2.1009&r2=1.16114.2.1010
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/fold-const.c.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.227.2.7&r2=1.227.2.8
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.2261.2.382&r2=1.2261.2.383
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.c-torture/execute/pr16790-1.c.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=NONE&r2=1.1.6.1



-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16790


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

* [Bug middle-end/16790] [3.3 regression] Integer down cast ignored in larger expression
  2004-07-27 22:35 [Bug c/16790] New: Integer down cast ignored in larger expression andyb at mathworks dot com
                   ` (7 preceding siblings ...)
  2004-08-08 18:55 ` cvs-commit at gcc dot gnu dot org
@ 2004-08-08 18:57 ` pinskia at gcc dot gnu dot org
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-08-08 18:57 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-08-08 18:57 -------
Fixed.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16790


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

end of thread, other threads:[~2004-08-08 18:57 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-07-27 22:35 [Bug c/16790] New: Integer down cast ignored in larger expression andyb at mathworks dot com
2004-07-27 22:42 ` [Bug c/16790] " andyb at mathworks dot com
2004-07-27 23:03 ` pinskia at gcc dot gnu dot org
2004-07-27 23:12 ` [Bug c/16790] [3.3/3.4/3.5 regression] " bangerth at dealii dot org
2004-07-27 23:39 ` [Bug middle-end/16790] " pinskia at gcc dot gnu dot org
2004-08-03 21:24 ` cvs-commit at gcc dot gnu dot org
2004-08-07 21:57 ` [Bug middle-end/16790] [3.3/3.4 " cvs-commit at gcc dot gnu dot org
2004-08-07 22:03 ` [Bug middle-end/16790] [3.3 " pinskia at gcc dot gnu dot org
2004-08-08 18:55 ` cvs-commit at gcc dot gnu dot org
2004-08-08 18:57 ` pinskia 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).