https://gcc.gnu.org/bugzilla/show_bug.cgi?id=74751
Bug ID: 74751
Summary: gcc can't generate correct code
Product: gcc
Version: 4.8.5
Status: UNCONFIRMED
Severity: major
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: jeanerpp at gmail dot com
Target Milestone: ---
Created attachment 39272
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=39272&action=edit
c source code to reproduce this issue.
compile and run the attached code, we got wrong result:
$ /usr/bin/gcc -Wall -Wextra -O2 -g3 -o ttt test.c && ./ttt
smac:1122334455667788
dmac:1020304050607080
result:00 00 00 00 00 00 00 00 00 00 00 00
If run with valgrind, memory error reported:
$ valgrind -v --tool=memcheck --track-origins=yes --leak-check=full
--show-reachable=yes ./ttt
..
==30875== Use of uninitialised value of size 8
==30875==at 0x4E7C251: _itoa_word (in /usr/lib64/libc-2.17.so)
==30875==by 0x4E7D325: vfprintf (in /usr/lib64/libc-2.17.so)
==30875==by 0x4E86C98: printf (in /usr/lib64/libc-2.17.so)
==30875==by 0x4005D4: pmac.constprop.1 (test.c:36)
==30875==by 0x400668: IPsecCacheBuildImpl.constprop.0 (test.c:108)
==30875==by 0x400488: main (test.c:121)
==30875== Uninitialised value was created by a stack allocation
==30875==at 0x4005F8: IPsecCacheBuildImpl.constprop.0 (test.c:88)
==30875==
..
In the source code attached, some workaround can be made to solve this issue.
But root cause is expected.
Related information:
$ uname -a
Linux ngnsvr14 3.10.0-327.10.1.el7.x86_64 #1 SMP Sat Jan 23 04:54:55 EST 2016
x86_64 x86_64 x86_64 GNU/Linux
$ cat /etc/redhat-release
Red Hat Enterprise Linux Server release 7.2 (Maipo)
ngnsvr14 []~/tmp/dbg $ /usr/bin/gcc -v
Using built-in specs.
COLLECT_GCC=/usr/bin/gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/lto-wrapper
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man
--infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla
--enable-bootstrap --enable-shared --enable-threads=posix
--enable-checking=release --with-system-zlib --enable-__cxa_atexit
--disable-libunwind-exceptions --enable-gnu-unique-object
--enable-linker-build-id --with-linker-hash-style=gnu
--enable-languages=c,c++,objc,obj-c++,java,fortran,ada,go,lto --enable-plugin
--enable-initfini-array --disable-libgcj
--with-isl=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/isl-install
--with-cloog=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/cloog-install
--enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64
--build=x86_64-redhat-linux
Thread model: posix
gcc version 4.8.5 20150623 (Red Hat 4.8.5-4) (GCC)
ngnsvr14 []~/tmp/dbg $ /usr/bin/gcc --version
gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-4)
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ cat /proc/cpuinfo
..
processor : 39
vendor_id : GenuineIntel
cpu family : 6
model : 62
model name : Intel(R) Xeon(R) CPU E5-2680 v2 @ 2.80GHz
stepping: 4
microcode : 0x428
cpu MHz : 2800.000
cache size : 25600 KB
physical id : 1
siblings: 20
core id : 12
cpu cores : 10
apicid : 57
initial apicid : 57
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 pdpe1gb
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 dca sse4_1 sse4_2 x2apic popcnt
tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm ida arat epb pln pts
dtherm tpr_shadow vnmi flexpriority ept vpid fsgsbase smep erms xsaveopt
bogomips: 5593.25
clflush size: 64
cache_alignment : 64
address sizes : 46 bits physical, 48 bits virtual
power management: