Bug 43459

Summary: Invalid "may be used uninitialized in this function" warning with -Os
Product: gcc Reporter: rwahl
Component: middle-endAssignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED WORKSFORME    
Severity: normal CC: gcc-bugs, manu
Priority: P3    
Version: 4.4.3   
Target Milestone: ---   
Host: Target:
Build: Known to work:
Known to fail: Last reconfirmed:
Bug Depends on:    
Bug Blocks: 24639    

Description rwahl 2010-03-21 02:04:27 UTC
Simple testcase:

--8<--8<--8<--8<--8<--8<--8<--8<--8<--8<--8<--

#include <errno.h>
#include <unistd.h>

int testfunc(void)
{
    int ret;

    while (1) {
	const unsigned int MY_BUF_SIZE = 20;
    	char buf[MY_BUF_SIZE];
	    
	if (read(0, buf, sizeof(buf)) < 0) {
	    ret = errno;
	    goto bail;
	}

    }

 bail:
    return ret;
}

--8<--8<--8<--8<--8<--8<--8<--8<--8<--8<--8<--

With gcc 4.4.3 I get:

$ gcc -Wextra -Wall -Os -c test.c 
test.c: In function ‘testfunc’:
test.c:6: warning: ‘ret’ may be used uninitialized in this function
$ gcc -Wextra -Wall -c test.c 
$ gcc -Wextra -Wall -O -c test.c 
$ gcc -Wextra -Wall -O2 -c test.c 

gcc 4.3.2 did not show this issue.
Comment 1 Manuel López-Ibáñez 2010-03-21 20:23:27 UTC
I cannot reproduce this in GCC 4.5, so probably it got fixed. Thanks for the report.
Comment 2 rwahl 2010-03-22 23:56:55 UTC
Just checked with gcc-4.4 branch HEAD and it works there, too. So it will be in gcc-4.4.4. I hope its released soon... ;-)