Bug 39799

Summary: [4.5 Regression] missing 'may be used uninitialized' warning
Product: gcc Reporter: Alexander Vodomerov <alexvod>
Component: tree-optimizationAssignee: Not yet assigned to anyone <unassigned>
Severity: normal CC: danglin, gcc-bugs, hubicka, jingyu, manu, matt
Priority: P2 Keywords: diagnostic
Version: 4.4.0   
Target Milestone: 4.6.0   
Host: x86_64-unknown-linux-gnu Target: x86_64-unknown-linux-gnu
Build: x86_64-unknown-linux-gnu Known to work: 4.1.3, 4.6.0, 4.7.0
Known to fail: 4.3.1, 4.5.0 Last reconfirmed: 2009-08-04 22:45:07
Bug Depends on:    
Bug Blocks: 24639    

Description Alexander Vodomerov 2009-04-17 17:54:59 UTC
The following code:

inline int foo(int x)
  return x;
static void bar(int a, int *ptr)
    int b;
    if (b < 40)
      ptr[0] = b;
    b += 1;
  while (--a != 0);
void foobar(int a, int *ptr)
  bar(foo(a), ptr);

generates correct warning when compiled by gcc 4.2.4:
$ gcc -O3 -Wall -Werror -c 1.c
cc1: warnings being treated as errors
1.c: In function ‘foobar’:
1.c:9: warning: ‘b’ may be used uninitialized in this function
1.c:9: note: ‘b’ was declared here

But it compiles without any warning with gcc 4.4.0. The bug reproduces on gcc 4.3.1 as well.
Comment 1 Richard Biener 2009-04-17 20:55:52 UTC
This is because we zero-initialize uninitialized variables during inlining.
Honza, do you remember why we do this?

          /* By inlining function having uninitialized variable, we might
             extend the lifetime (variable might get reused).  This cause
             ICE in the case we end up extending lifetime of SSA name across
             abnormal edge, but also increase register pressure.

             We simply initialize all uninitialized vars by 0 except
             for case we are inlining to very first BB.  We can avoid
             this for all BBs that are not inside strongly connected
             regions of the CFG, but this is expensive to test.  */
Comment 2 Jakub Jelinek 2009-04-20 07:39:45 UTC
See PR31081 for details.
Comment 3 Richard Biener 2009-04-20 09:32:27 UTC
Honza, if overlapping lifetimes are the problem instead of zero-initializing
uninitialized params we could instead create a new uninitialized variable for
Comment 4 Richard Biener 2009-08-04 12:30:08 UTC
GCC 4.3.4 is being released, adjusting target milestone.
Comment 5 Richard Biener 2010-05-22 18:13:33 UTC
GCC 4.3.5 is being released, adjusting target milestone.
Comment 6 Bernd Schmidt 2010-06-30 14:17:16 UTC
Subject: Bug 39799

Author: bernds
Date: Wed Jun 30 14:16:28 2010
New Revision: 161605

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=161605
	PR tree-optimization/39799
	* tree-inline.c (remap_ssa_name): Initialize variable only if

	PR tree-optimization/39799
	* c-c++-common/uninit-17.c: New test.


Comment 7 Matt Hargett 2010-06-30 23:36:24 UTC
Will this be backported to 4.4 and/or 4.5?
Comment 8 John David Anglin 2010-07-01 17:14:18 UTC
c-c++-common/uninit-17.c fails on hppa2.0w-hp-hpux11.11:

Executing on host: /test/gnu/gcc/objdir/gcc/xgcc -B/test/gnu/gcc/objdir/gcc/ /te
st/gnu/gcc/gcc/gcc/testsuite/c-c++-common/uninit-17.c   -Wc++-compat  -O2 -Wunin
itialized -S  -o uninit-17.s    (timeout = 300)
/test/gnu/gcc/gcc/gcc/testsuite/c-c++-common/uninit-17.c: In function 'foobar':
/test/gnu/gcc/gcc/gcc/testsuite/c-c++-common/uninit-17.c:12:9: warning: 'b' is u
sed uninitialized in this function [-Wuninitialized]
/test/gnu/gcc/gcc/gcc/testsuite/c-c++-common/uninit-17.c:12:9: note: 'b' was dec
lared here
output is:
/test/gnu/gcc/gcc/gcc/testsuite/c-c++-common/uninit-17.c: In function 'foobar':
/test/gnu/gcc/gcc/gcc/testsuite/c-c++-common/uninit-17.c:12:9: warning: 'b' is u
sed uninitialized in this function [-Wuninitialized]
/test/gnu/gcc/gcc/gcc/testsuite/c-c++-common/uninit-17.c:12:9: note: 'b' was dec
lared here

PASS: c-c++-common/uninit-17.c  -Wc++-compat   (test for warnings, line 12)
FAIL: c-c++-common/uninit-17.c  -Wc++-compat   (test for warnings, line 14)
FAIL: c-c++-common/uninit-17.c  -Wc++-compat  (test for excess errors)
Excess errors:
/test/gnu/gcc/gcc/gcc/testsuite/c-c++-common/uninit-17.c:12:9: warning: 'b' is u
sed uninitialized in this function [-Wuninitialized]
Comment 9 Richard Biener 2011-06-27 12:12:16 UTC
4.3 branch is being closed, moving to 4.4.7 target.
Comment 10 Richard Biener 2012-01-16 13:43:50 UTC
Fixed since 4.6.
Comment 11 Jakub Jelinek 2012-03-13 12:45:02 UTC
4.4 branch is being closed, moving to 4.5.4 target.
Comment 12 Richard Biener 2012-07-02 09:35:18 UTC
Fixed for 4.6.0.