Bug 41817 - bogus "may be uninitialized" (huge testcase, inlining?)
bogus "may be uninitialized" (huge testcase, inlining?)
Status: UNCONFIRMED
Product: gcc
Classification: Unclassified
Component: middle-end
4.4.2
: P3 normal
: ---
Assigned To: Not yet assigned to anyone
: diagnostic
Depends on:
Blocks: Wuninitialized
  Show dependency treegraph
 
Reported: 2009-10-24 17:51 UTC by Marti Raudsepp
Modified: 2010-04-21 23:38 UTC (History)
3 users (show)

See Also:
Host: x86_64-unknown-linux-gnu
Target: x86_64-unknown-linux-gnu
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
dwarf_getcfi_elf.i (164.61 KB, text/plain)
2009-10-24 18:27 UTC, Marti Raudsepp
Details
test-resizing.i (240.98 KB, text/plain)
2009-10-26 03:26 UTC, Marti Raudsepp
Details
st-theme-node.i.gz (152.68 KB, application/x-gzip)
2009-10-26 03:35 UTC, Marti Raudsepp
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Marti Raudsepp 2009-10-24 17:51:21 UTC
When trying to compile elfutils version 0.143 on x86_64 Arch Linux using GCC 4.4.1 or 4.4.2 with options -mtune=k8 -O3, I get the following output:

gcc -D_GNU_SOURCE -DHAVE_CONFIG_H -DIS_LIBDW -I. -I.. -I. -I. -I./../libelf -I.. -I./../lib    -Wall -Werror -Wshadow -Wunused -Wformat=2 -Wextra -std=gnu99 -mtune=k8 -fstack-protector -O3 -pipe -MT dwarf_getcfi_elf.o -MD -MP -MF .deps/dwarf_getcfi_elf.Tpo -c -o dwarf_getcfi_elf.o dwarf_getcfi_elf.c
cc1: warnings being treated as errors
dwarf_getcfi_elf.c: In function ‘dwarf_getcfi_elf’:
dwarf_getcfi_elf.c:164: error: ‘search_table_entries’ may be used uninitialized in this function
dwarf_getcfi_elf.c:164: note: ‘search_table_entries’ was declared here
dwarf_getcfi_elf.c:165: error: ‘search_table_encoding’ may be used uninitialized in this function
dwarf_getcfi_elf.c:165: note: ‘search_table_encoding’ was declared here

This seems to happen with every AMD-related tune option (-mtune=k8, -march=k8, -march=athlon64, -march=amdfam10 etc) when used with -O3.

The offending code from dwarf_getcfi_elf.c follows:

146:static Dwarf_CFI *
147:getcfi_gnu_eh_frame (Elf *elf, const GElf_Ehdr *ehdr, const GElf_Phdr *phdr)
148:{
149:  if (unlikely (phdr->p_filesz < 4))
150:    goto invalid;
151:
152:  Elf_Data *data = elf_getdata_rawchunk (elf, phdr->p_offset, phdr->p_filesz,
153:					 ELF_T_BYTE);
154:  if (data == NULL)
155:    {
156:    invalid_hdr:
157:    invalid:
158:      /* XXX might be read error or corrupt phdr */
159:      __libdw_seterrno (DWARF_E_INVALID_CFI);
160:      return NULL;
161:    }
162:
163:  Dwarf_Addr eh_frame_ptr;
164:  size_t search_table_entries;
165:  uint8_t search_table_encoding;
166:  const uint8_t *search_table = parse_eh_frame_hdr (data->d_buf, phdr->p_filesz,
167:						    phdr->p_vaddr, ehdr,
168:						    &eh_frame_ptr,
169:						    &search_table_entries,
170:						    &search_table_encoding);

----

gcc -v:
Using built-in specs.
Target: x86_64-unknown-linux-gnu
Configured with: ../configure --prefix=/usr --enable-shared --enable-languages=c,c++,fortran,objc,obj-c++,ada --enable-threads=posix --mandir=/usr/share/man --infodir=/usr/share/info --enable-__cxa_atexit --disable-multilib --libdir=/usr/lib --libexecdir=/usr/lib --enable-clocale=gnu --disable-libstdcxx-pch --with-tune=generic
Thread model: posix
gcc version 4.4.2 (GCC) 

The elfutils source can be downloaded from: https://fedorahosted.org/releases/e/l/elfutils/
Comment 1 Andrew Pinski 2009-10-24 18:24:31 UTC
Can you provide the preprocessed source as requested by http://gcc.gnu.org/bugs.html ?
Comment 2 Marti Raudsepp 2009-10-24 18:27:38 UTC
Created attachment 18888 [details]
dwarf_getcfi_elf.i

Sorry! Here you go :)
Comment 3 Marti Raudsepp 2009-10-26 03:26:30 UTC
Created attachment 18893 [details]
test-resizing.i

Another instance of the same bug. This time from GNOME mutter 2.28.0

http://ftp.gnome.org/pub/gnome/sources/mutter/2.28/

gcc -save-temps -DHAVE_CONFIG_H -I. -I../.. -DORBIT2=1 -pthread -I/usr/include/gtk-2.0 -I/usr/lib/gtk-2.0/include -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/pango-1.0 -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng12 -I/usr/include/gconf/2 -I/usr/include/orbit-2.0 -I/usr/include/dbus-1.0 -I/usr/lib/dbus-1.0/include -I/usr/include/startup-notification-1.0 -I/usr/include/clutter-1.0 -I/usr/include/drm -I/usr/include/gobject-introspection-1.0      -march=amdfam10 -fstack-protector -O3 -pipe -Wall -Wchar-subscripts -Wmissing-declarations -Wmissing-prototypes -Wnested-externs -Wpointer-arith -Wcast-align -Wsign-compare -Wall -Werror -ansi -MT test-resizing.o -MD -MP -MF .deps/test-resizing.Tpo -c -o test-resizing.o test-resizing.c                         
gcc: warning: -pipe ignored because -save-temps specified
cc1: warnings being treated as errors
test-resizing.c: In function ‘main’:
test-resizing.c:82: error: ‘height’ is used uninitialized in this function
test-resizing.c:94: note: ‘height’ was declared here
Comment 4 Marti Raudsepp 2009-10-26 03:35:17 UTC
Created attachment 18894 [details]
st-theme-node.i.gz

And yet another in gnome-shell from http://ftp.gnome.org/pub/GNOME/sources/gnome-shell/2.28/

gcc -save-temps -DHAVE_CONFIG_H -I. -I.. -I../src -DPREFIX=\"/usr\" -DLIBDIR=\"/usr/lib\" -DG_DISABLE_DEPRECATED -DG_LOG_DOMAIN=\"St\" -DST_COMPILATION -DPACKAGE_DATA_DIR=\"/usr/share/gnome-shell\" -pthread -I/usr/include/clutter-1.0 -I/usr/include/cairo -I/usr/include/pango-1.0 -I/usr/include/gtk-2.0 -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng12 -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/include/drm -I/usr/lib/gtk-2.0/include -I/usr/include/atk-1.0 -I/usr/include/libcroco-0.6 -I/usr/include/libxml2 -march=k8 -fstack-protector -O3 -pipe -Wall -Wmissing-prototypes -Werror -MT libst_1_0_la-st-theme-node.lo -MD -MP -MF .deps/libst_1_0_la-st-theme-node.Tpo -c st/st-theme-node.c  -fPIC -DPIC -o .libs/libst_1_0_la-st-theme-node.o
gcc: warning: -pipe ignored because -save-temps specified
cc1: warnings being treated as errors
st/st-theme-node.c: In function ‘st_theme_node_get_font’:
st/st-theme-node.c:1661: error: ‘font_style’ may be used uninitialized in this function
st/st-theme-node.c:1663: error: ‘variant’ may be used uninitialized in this function
Comment 5 Andrew Pinski 2009-10-27 02:44:25 UTC
These might not be bogus as there is extra inlining at -O3 which causes us to strip out the address taking and make search_table_entries, etc. look like real variables.
Comment 6 Marti Raudsepp 2009-10-27 08:58:35 UTC
(In reply to comment #5)
> These might not be bogus as there is extra inlining at -O3 which causes us to
> strip out the address taking and make search_table_entries, etc. look like
> real variables.

True, I have changed the summary.

The underlying problem I guess then is that packages use -Werror, but this warning depends on specific settings of the optimizer which changes from user to user.

But "don't use -Werror" or "don't use CFLAGS" is not a useful solution either. Clearly many projects are affected by this.
Comment 7 Manuel López-Ibáñez 2009-11-19 12:19:58 UTC
This is still unconfirmed until someone looks at the dumps and check that the variables are indeed initialized in all paths that can be sensibly detected by GCC.

BTW, when you release code, your compiler flags should not contain -Werror. If some package does, you should really report it upstream because taking into account all the amount of new warnings, and fixes to existing warnings that occur between consecutive GCC releases, that is madness for any user compiling your code.
Comment 8 davidxl 2010-04-21 23:38:25 UTC
This is one of the typical cases that will be handled by patch in http://gcc.gnu.org/ml/gcc-patches/2010-04/msg00706.html

size_t search_table_entries;
search_table = parse_eh_frame_hdr (...&search_table_entries,..);

if (search_table)
{
   use of search_table_entries..

..
}

However the original problem is not shown in trunk compiler either, probably because some earlier transformations hide it.

David