Bug 44971 - [4.6 Regression] -fcompare-debug failure with uninitialized read in walk_gimple_stmt
Summary: [4.6 Regression] -fcompare-debug failure with uninitialized read in walk_gimp...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: debug (show other bugs)
Version: 4.6.0
: P3 normal
Target Milestone: 4.6.0
Assignee: Richard Biener
URL:
Keywords: compare-debug-failure
Depends on:
Blocks:
 
Reported: 2010-07-17 11:44 UTC by Zdenek Sojka
Modified: 2022-01-18 23:30 UTC (History)
4 users (show)

See Also:
Host: x86_64-pc-linux-gnu
Target: x86_64-pc-linux-gnu
Build:
Known to work:
Known to fail:
Last reconfirmed: 2010-07-18 17:50:44


Attachments
reduced testcase (from libXft sources) (236 bytes, text/plain)
2010-07-17 11:46 UTC, Zdenek Sojka
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Zdenek Sojka 2010-07-17 11:44:00 UTC
Command line:
$ gcc -O2 -fcompare-debug testcase.c

Valgrind output:
$ valgrind -q --trace-children=yes /mnt/svn/gcc-trunk/binary-162222-lto-fortran-checking-yes-rtl-df/bin/gcc -O2 -fcompare-debug testcase.c
testcase.c: In function '_XftCloseint':
testcase.c:21:3: warning: passing argument 1 of '_XftintInfoGet' makes pointer from integer without a cast [enabled by default]
testcase.c:12:6: note: expected 'int *' but argument is of type 'int'
testcase.c:22:13: warning: assignment from incompatible pointer type [enabled by default]
testcase.c:22:48: warning: assignment from incompatible pointer type [enabled by default]
==3128== Conditional jump or move depends on uninitialised value(s)
==3128==    at 0x70BFBB: walk_gimple_stmt (gimple.c:1627)
==3128==    by 0x955003: dump_enumerated_decls (tree-ssa-live.c:1264)
==3128==    by 0x8F7B98: execute_cleanup_cfg_post_optimizing (tree-optimize.c:212)
==3128==    by 0x7B777D: execute_one_pass (passes.c:1563)
==3128==    by 0x7B7A14: execute_pass_list (passes.c:1618)
==3128==    by 0x8F8525: tree_rest_of_compilation (tree-optimize.c:450)
==3128==    by 0xAADBF5: cgraph_expand_function (cgraphunit.c:1629)
==3128==    by 0xAB0A29: cgraph_optimize (cgraphunit.c:1708)
==3128==    by 0xAB101A: cgraph_finalize_compilation_unit (cgraphunit.c:1171)
==3128==    by 0x4DE632: c_write_global_declarations (c-decl.c:9698)
==3128==    by 0x8A41E5: toplev_main (toplev.c:990)
==3128==    by 0x6589BBC: (below main) (in /lib64/libc-2.11.2.so)
==3128== 
gcc: error: testcase.c: -fcompare-debug failure (length)

Tested revisions:
r162222 - fail
r162056 - fail
r161659 - ICEs
r161170 - OK
Comment 1 Zdenek Sojka 2010-07-17 11:46:14 UTC
Created attachment 21234 [details]
reduced testcase (from libXft sources)

The original testcase didn't have any implicit conversions from/to/between pointers.

Command line:
$ gcc -O2 -fcompare-debug pr44971.c
Comment 2 H.J. Lu 2010-07-17 13:37:31 UTC
It is caused by revision 161655:

http://gcc.gnu.org/ml/gcc-cvs/2010-07/msg00006.html
Comment 3 Richard Biener 2010-07-18 17:50:44 UTC
Mine.
Comment 4 Richard Biener 2010-07-18 20:46:52 UTC
@@ -29,7 +29,7 @@
 (note# 0 0 NOTE_INSN_DELETED)
 (note# 0 0 [bb 2] NOTE_INSN_BASIC_BLOCK)
 (note# 0 0 NOTE_INSN_FUNCTION_BEG)
-(insn:TI# 0 0 pr44971.c:22 (set (reg/f:SI 0 ax [orig:58 D.xxxx ] [58])
+(insn:TI# 0 0 pr44971.c:22 (set (reg/v/f:SI 0 ax [orig:58 info ] [58])
         (mem/f/c:SI (symbol_ref:SI ("_XftintInfo")  <var_decl # _XftintInfo>) [ MEM[(struct XftintInfo * *)&_XftintInfo]+0 S4 A32]))# {*movsi_internal} (nil))
 (insn/f:TI# 0 0 pr44971.c:20 (set (mem:SI (pre_dec:SI (reg/f:SI 7 sp)) [ S4 A8])
         (reg/f:SI 6 bp))# {*pushsi2} (nil))
@@ -37,7 +37,7 @@
         (reg/f:SI 7 sp))# {*movsi_internal} (nil))
 (note# 0 0 NOTE_INSN_PROLOGUE_END)
 (insn:TI# 0 0 pr44971.c:22 (set (reg:CCZ 17 flags)
-        (compare:CCZ (reg/f:SI 0 ax [orig:58 D.xxxx ] [58])
+        (compare:CCZ (reg/v/f:SI 0 ax [orig:58 info ] [58])
             (const_int 0 [0])))# {*cmpsi_ccno_1} (nil))
 (jump_insn:TI# 0 0 pr44971.c:22 (set (pc)
         (if_then_else (eq (reg:CCZ 17 flags)
...

caused by phiprop.  It chooses one dereference result to choose the
result.  But debug stmts change order of immediate uses.

With debug stmts (uses of prev_1):

# VUSE <.MEM_8(D)>
info_5 = *prev_1;
# DEBUG prev => prev_1
# VUSE <.MEM_8(D)>
D.1973_6 = *prev_1;

without:

# VUSE <.MEM_8(D)>
D.1973_6 = *prev_1;
# VUSE <.MEM_8(D)>
info_5 = *prev_1;

so relying on stable order of immediate uses is now wrong?  The compare-debug
failure is spurious, there is no difference in the assembly output.
I can fix it by always degrading debug info and creating a new variable.

Alex, why should the immediate use lists show this behavior?
Comment 5 Richard Biener 2010-07-19 13:40:36 UTC
The difference starts to appear with .030t.ealias, where with debug info
we get a massive re-ordering of immediate uses (diff from .029t.forwprop1):

 prev_1 : -->2 uses.
-D.2738_7 = *prev_1;
 info_6 = *prev_1;
 # DEBUG prev => prev_1
+D.2738_7 = *prev_1;
 
 dpy_2(D) : --> no uses.
 # DEBUG D#1 => (long int) dpy_2(D)
 
 info_6 : --> single use.
-if (info_6 != 0B)
 # DEBUG info => info_6
+if (info_6 != 0B)
 
 D.2738_7 : --> single use.
 prev_8 = &D.2738_7->next;
 
 prev_8 : --> single use.
-prev_1 = PHI <&_XftintInfo(2), prev_8(3)>
 # DEBUG prev => prev_8
+prev_1 = PHI <&_XftintInfo(2), prev_8(3)>
 
 .MEM_9(D) : -->2 uses.
 # VUSE <.MEM_9(D)>
-D.2738_7 = *prev_1;
-# VUSE <.MEM_9(D)>
 info_6 = *prev_1;
+# VUSE <.MEM_9(D)>
+D.2738_7 = *prev_1;

Caused by the additional

+No longer having address taken event_base
+
+
+Symbols to be put in SSA form
+
+{ event_base }
+
+
+Incremental SSA update started at block: 0
+

in the debug enabled build (TODO_update_address_taken).  Still
in referenced-vars but only for the debug-enabled build
(it is in fact never added for the -g0 build, added by
remap_decl called from remap_block during inlining).

I may have a patch.
Comment 6 Richard Biener 2010-07-19 16:04:45 UTC
Bah, iterating over cfun->local_decls plus DECL_ARGUMENTS doesn't work because
with IPA-SRA DECL_ARGUMENTs are not in referenced-vars.
Comment 7 Richard Biener 2010-07-20 11:29:10 UTC
Subject: Bug 44971

Author: rguenth
Date: Tue Jul 20 11:28:56 2010
New Revision: 162329

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=162329
Log:
2010-07-20  Richard Guenther  <rguenther@suse.de>

	PR middle-end/44971
	PR middle-end/44988
	* tree-ssa.c (maybe_optimize_var): New function split out from ...
	(execute_update_addresses_taken): ... here.
	(non_rewritable_mem_ref_base): Likewise.
	(execute_update_addresses_taken): Do not iterate over all referenced
	vars but just all local decls and parms.
	Properly check call and asm arguments and rewrite call arguments.

	* gcc.dg/pr44971.c: New testcase.
	* gcc.c-torture/compile/pr44988.c: Likewise.

Added:
    trunk/gcc/testsuite/gcc.c-torture/compile/pr44988.c
    trunk/gcc/testsuite/gcc.dg/pr44971.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/tree-ssa.c

Comment 8 Richard Biener 2010-07-20 11:29:56 UTC
Fixed.