This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c/16790] New: Integer down cast ignored in larger expression


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]