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

            Bug ID: 59354
           Summary: Unexpected result in g++ when casting int to char from
                    an stl vector to an array
           Product: gcc
           Version: 4.8.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jori.liesenborgs at gmail dot com

Created attachment 31339
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=31339&action=edit
test code

In the test code, the integer values from sixteen 4x4 blocks (in an stl vector)
are copied into an unsigned char array for 64x4 values. Using just -O3 this
appears to produce an incorrect result.

Some remarks:
 - Adding -mno-sse again yields the right output.
 - If the vector is replaced by a simple array, the correct result is
generated.
 - For 'xBlocks' less than 16, the correct result is also generated

To generate and run the executable:
g++ -O3 -o test test.ii
./test

Generated output (all four lines should actually be the same):
aaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbccccccccccccccccdddddddddddddddd
aaaabbbbccccddddeeeeffffgggghhhhiiiijjjjkkkkllllmmmmnnnnoooopppp
aaaabbbbccccddddeeeeffffgggghhhhiiiijjjjkkkkllllmmmmnnnnoooopppp
aaaabbbbccccddddeeeeffffgggghhhhiiiijjjjkkkkllllmmmmnnnnoooopppp

GCC version info:
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-slackware-linux/4.8.2/lto-wrapper
Target: x86_64-slackware-linux
Configured with: ../gcc-4.8.2/configure --prefix=/usr --libdir=/usr/lib64
--mandir=/usr/man --infodir=/usr/info --enable-shared --enable-bootstrap
--enable-languages=ada,c,c++,fortran,go,java,lto,objc --enable-threads=posix
--enable-checking=release --enable-objc-gc --with-system-zlib
--with-python-dir=/lib64/python2.7/site-packages --disable-libunwind-exceptions
--enable-__cxa_atexit --enable-libssp --enable-lto --with-gnu-ld --verbose
--enable-java-home --with-java-home=/usr/lib64/jvm/jre
--with-jvm-root-dir=/usr/lib64/jvm
--with-jvm-jar-dir=/usr/lib64/jvm/jvm-exports --with-arch-directory=amd64
--with-antlr-jar=/tmp/gcc/antlr-runtime-3.4.jar --enable-java-awt=gtk
--disable-gtktest --disable-multilib --target=x86_64-slackware-linux
--build=x86_64-slackware-linux --host=x86_64-slackware-linux
Thread model: posix
gcc version 4.8.2 (GCC)

Test system was an 8 core slackware 14.0 system, with a /proc/cpuinfo content
like this:
processor    : 0
vendor_id    : GenuineIntel
cpu family    : 6
model        : 58
model name    : Intel(R) Core(TM) i7-3770 CPU @ 3.40GHz
stepping    : 9
microcode    : 0x17
cpu MHz        : 2550.000
cache size    : 8192 KB
physical id    : 0
siblings    : 8
core id        : 0
cpu cores    : 4
apicid        : 0
initial apicid    : 0
fpu        : yes
fpu_exception    : yes
cpuid level    : 13
wp        : yes
flags        : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov
pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx rdtscp lm
constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc
aperfmperf eagerfpu pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3
cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave
avx f16c rdrand lahf_lm ida arat epb xsaveopt pln pts dtherm tpr_shadow vnmi
flexpriority ept vpid fsgsbase smep erms
bogomips    : 6784.34
clflush size    : 64
cache_alignment    : 64
address sizes    : 36 bits physical, 48 bits virtual
power management:

Reply via email to