public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/16693] New: Bitwise AND is lost when used within a cast to an enum of the same precision
@ 2004-07-23 17:15 paulg at chiark dot greenend dot org dot uk
  2004-07-23 17:18 ` [Bug c++/16693] " paulg at chiark dot greenend dot org dot uk
                   ` (17 more replies)
  0 siblings, 18 replies; 19+ messages in thread
From: paulg at chiark dot greenend dot org dot uk @ 2004-07-23 17:15 UTC (permalink / raw)
  To: gcc-bugs

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 <iostream>

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<Test_Enum>(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


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

end of thread, other threads:[~2004-08-26 12:33 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-07-23 17:15 [Bug c++/16693] New: Bitwise AND is lost when used within a cast to an enum of the same precision paulg at chiark dot greenend dot org dot uk
2004-07-23 17:18 ` [Bug c++/16693] " paulg at chiark dot greenend dot org dot uk
2004-07-23 17:20 ` paulg at chiark dot greenend dot org dot uk
2004-07-23 17:22 ` [Bug c++/16693] [3.4 Regression] " pinskia at gcc dot gnu dot org
2004-07-23 19:04 ` [Bug c++/16693] [3.4/3.5 regression] " bangerth at dealii dot org
2004-07-23 19:06 ` bangerth at dealii dot org
2004-07-24  0:10 ` paulg at chiark dot greenend dot org dot uk
2004-07-26 13:03 ` paulg at chiark dot greenend dot org dot uk
2004-07-26 13:50 ` pinskia at gcc dot gnu dot org
2004-08-10  1:25 ` pinskia at gcc dot gnu dot org
2004-08-10  9:05 ` reichelt at gcc dot gnu dot org
2004-08-19 21:31 ` [Bug middle-end/16693] " mmitchel at gcc dot gnu dot org
2004-08-20  9:33 ` rearnsha at gcc dot gnu dot org
2004-08-22 23:30 ` mmitchel at gcc dot gnu dot org
2004-08-25 17:22 ` cvs-commit at gcc dot gnu dot org
2004-08-25 17:28 ` [Bug middle-end/16693] [3.5 " pinskia at gcc dot gnu dot org
2004-08-25 20:51 ` cvs-commit at gcc dot gnu dot org
2004-08-25 20:58 ` pinskia at gcc dot gnu dot org
2004-08-26 12:33 ` rearnsha 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).