Bug 19371

Summary: [3.4 Regression] Missing uninitialized warning with dead code (pure/const functions)
Product: gcc Reporter: Axel Andersson <axel>
Component: middle-endAssignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED FIXED    
Severity: minor CC: gcc-bugs
Priority: P3 Keywords: diagnostic
Version: 3.4.2   
Target Milestone: 4.1.0   
Host: Target:
Build: Known to work: 2.95.3 4.0.0
Known to fail: 3.4.0 3.3.3 Last reconfirmed: 2005-10-02 19:47:53
Bug Depends on:    
Bug Blocks: 24639    

Description Axel Andersson 2005-01-11 10:25:04 UTC
Consider the following code snippet:

$ cat testcase.c
int bar(int n) {
    return n + 1;
}


int main(void) {
    int a = bar(a);
    int b, c, d;
    b = bar(b);
    (void) bar(c);
    return bar(d);
}

Both a, b, c and d are used before they are initialized. However, we only get a warning from d in gcc 
3.3/3.4.

$ gcc -O2 -Wuninitialized testcase.c 
testcase.c: In function `main':
testcase.c:8: warning: `d' might be used uninitialized in this function

Tested on:
gcc version 3.3 20030304 (Apple Computer, Inc. build 1640)
gcc version 3.4.2 [FreeBSD] 20040728

In gcc 2.95, we get a warning from b, c and d, but not a.

$ gcc -O2 -Wuninitialized testcase.c
testcase.c: In function `main':
testcase.c:8: warning: `b' might be used uninitialized in this function
testcase.c:8: warning: `c' might be used uninitialized in this function
testcase.c:8: warning: `d' might be used uninitialized in this function

Tested on:
gcc version 2.95.3 20010125 (prerelease) (OpenBSD)
Comment 1 Andrew Pinski 2005-01-11 12:49:14 UTC
Confirmed as a regression but was fixed already on the mainline.
On the mainline get a warning about all four including a so that part is not a regression.

I don't know if we can do anything about it as we remove the call to bar as it is a pure/const function 
and we don't use the result of the function at all.
Comment 2 Andrew Pinski 2005-01-11 12:55:53 UTC
If you used the result of the function call, you would get a warning about all four on 3.4 including a 
which does not exist on before 3.4.0.
Comment 3 Jeffrey A. Law 2005-11-08 17:18:37 UTC
No plans exist to address these issues in the 3.x series.  It works as expected in GCC 4.1.