From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11305 invoked by alias); 23 Jul 2004 17:15:29 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 11297 invoked by uid 48); 23 Jul 2004 17:15:27 -0000 Date: Fri, 23 Jul 2004 17:15:00 -0000 From: "paulg at chiark dot greenend dot org dot uk" To: gcc-bugs@gcc.gnu.org Message-ID: <20040723171525.16693.paulg@chiark.greenend.org.uk> Reply-To: gcc-bugzilla@gcc.gnu.org Subject: [Bug c++/16693] New: Bitwise AND is lost when used within a cast to an enum of the same precision X-Bugzilla-Reason: CC X-SW-Source: 2004-07/txt/msg02765.txt.bz2 List-Id: The following code produces incorrect results when compiled with GCC 3.4.0 and 3.4.1. With both of these compilers the bitwise "AND" gets ignored and the value of "r1" ends up as 0x66 rather than 0x6. GCC 3.3.3 generates the correct answer as does GCC 3.5.0 snapshot taken on 20040717. The console output of the compiler during this run was: Reading specs from /arm/eda/tools/gnu/gcc/3_4_1/linux_rh_7_2-x86/lib/gcc/i686-pc -linux-gnu/3.4.1/specs Configured with: ./configure --prefix=/arm/eda/tools/gnu/gcc/3_4_1 --exec-prefix =/arm/eda/tools/gnu/gcc/3_4_1/linux_rh_7_2-x86 --program-suffix=-3_4_1 -v --with -dwarf2 --enable-version-specific-runtime-libs --with-gnu-as --with-as=/arm/eda/ tools/gnu/binutils/2_15_90_0_3/linux_rh_7_2-x86/bin/as-2_15_90_0_3 --with-gnu-ld --with-ld=/arm/eda/tools/gnu/binutils/2_15_90_0_3/linux_rh_7_2-x86/bin/ld-2_15_ 90_0_3 Thread model: posix gcc version 3.4.1 /arm/eda/tools/gnu/gcc/3_4_1/linux_rh_7_2-x86/libexec/gcc/i686-pc-linux-gnu/3.4 .1/cc1plus -E -quiet -v -D_GNU_SOURCE tst_gcc.cpp -mtune=pentiumpro -o tst_gcc.i i ignoring nonexistent directory "/arm/eda/tools/gnu/gcc/3_4_1/linux_rh_7_2-x86/li b/gcc/i686-pc-linux-gnu/3.4.1/../../../../i686-pc-linux-gnu/include" #include "..." search starts here: #include <...> search starts here: /arm/eda/tools/gnu/gcc/3_4_1/linux_rh_7_2-x86/lib/gcc/i686-pc-linux-gnu/3.4.1/i nclude/c++ /arm/eda/tools/gnu/gcc/3_4_1/linux_rh_7_2-x86/lib/gcc/i686-pc-linux-gnu/3.4.1/i nclude/c++/i686-pc-linux-gnu /arm/eda/tools/gnu/gcc/3_4_1/linux_rh_7_2-x86/lib/gcc/i686-pc-linux-gnu/3.4.1/i nclude/c++/backward /usr/local/include /arm/eda/tools/gnu/gcc/3_4_1/include /arm/eda/tools/gnu/gcc/3_4_1/linux_rh_7_2-x86/lib/gcc/i686-pc-linux-gnu/3.4.1/i nclude /usr/include End of search list. /arm/eda/tools/gnu/gcc/3_4_1/linux_rh_7_2-x86/libexec/gcc/i686-pc-linux-gnu/3.4 .1/cc1plus -fpreprocessed tst_gcc.ii -quiet -dumpbase tst_gcc.cpp -mtune=pentium pro -auxbase tst_gcc -version -o tst_gcc.s GNU C++ version 3.4.1 (i686-pc-linux-gnu) compiled by GNU C version 3.4.1. GGC heuristics: --param ggc-min-expand=98 --param ggc-min-heapsize=129190 /arm/eda/tools/gnu/binutils/2_15_90_0_3/linux_rh_7_2-x86/bin/as-2_15_90_0_3 -V -Qy -o tst_gcc.o tst_gcc.s GNU assembler version 2.15.90.0.3 (i686-pc-linux-gnu) using BFD version 2.15.90. 0.3 20040415 /arm/eda/tools/gnu/gcc/3_4_1/linux_rh_7_2-x86/libexec/gcc/i686-pc-linux-gnu/3.4 .1/collect2 --eh-frame-hdr -m elf_i386 -dynamic-linker /lib/ld-linux.so.2 -o tst _gcc /usr/lib/crt1.o /usr/lib/crti.o /arm/eda/tools/gnu/gcc/3_4_1/linux_rh_7_2-x 86/lib/gcc/i686-pc-linux-gnu/3.4.1/crtbegin.o -L/arm/eda/tools/gnu/gcc/3_4_1/lin ux_rh_7_2-x86/lib/gcc/i686-pc-linux-gnu/3.4.1 -L/arm/eda/tools/gnu/gcc/3_4_1/lin ux_rh_7_2-x86/lib/gcc/i686-pc-linux-gnu/3.4.1/../../.. tst_gcc.o -lstdc++ -lm -l gcc_s -lgcc -lc -lgcc_s -lgcc /arm/eda/tools/gnu/gcc/3_4_1/linux_rh_7_2-x86/lib/ gcc/i686-pc-linux-gnu/3.4.1/crtend.o /usr/lib/crtn.o ---- #include unsigned short ret6666(int) { return 0x66; } typedef enum { a = 0x0, b = 0x1, c = 0x2, d = 0x3, e = 0x4, f = 0x5, g = 0x6, h = 0x7, i = 0x8, j = 0x9, k = 0xa, l = 0xb, m = 0xc, n = 0xd, o = 0xe, p = 0xf } Test_Enum; int main(void) { unsigned char r1; r1 = static_cast(0xf & ret6666(44)); if(r1 == 0x6) { std::cout << "Passed" << std::endl; exit(0); } else { std::cout << "Failed" << std::endl; exit(1); } } -- Summary: Bitwise AND is lost when used within a cast to an enum of the same precision Product: gcc Version: 3.4.1 Status: UNCONFIRMED Severity: normal Priority: P2 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: paulg at chiark dot greenend dot org dot uk CC: gcc-bugs at gcc dot gnu dot org GCC build triplet: i686-pc-linux-gnu GCC host triplet: i686-pc-linux-gnu GCC target triplet: i686-pc-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16693