[Bug c/19099] New: No warning for uninitialized local variable use

2004-12-20 Thread gopalv82 at dotgnu dot org
Code similar to the one below does not give a warning (though one is expected).

int foo()
{
  int x = x;
  return x;
}

Though this code in itself seems stupid - this is how it hid into my codebase 
(in a simplified example).

#include 

#define macro2(imm) \
do {\
int __value = (imm);\
printf("macro2 got %d\n", __value);\
}while(0)

#define macro3(imm) \
do { \
int __value = (imm);\
printf("macro3 got %d\n", __value);\
} while(0);
#define macro1(imm)\
do {\
int __value = (imm);\
printf("macro1 got %d\n", __value);\
macro2(__value);\
macro3(__value);\
}while(0)

int foobar()
{
printf("foobar was called\n");
return 42;
}
int main()
{
macro1(foobar());
return 0;
}

The expected output was 
"""
foobar was called 
macro1 got 42
macro2 got 42
macro3 got 42
"""

But I get
"""
[EMAIL PROTECTED] samples $ gcc -Wall -pedantic -ansi -O3 test.c
[EMAIL PROTECTED] samples $ ./a.out 
foobar was called
macro1 got 42
macro2 got 805441120
macro3 got 805441120
"""

The original code was spread accross 4 files. I think the code 
should generate a valid warning because the variable is as good
as being stack/register junk . 

Tested with "gcc (GCC) 3.4.1 20040803 (Gentoo Linux 3.4.1-r3, ssp-3.4-2,
pie-8.7.6.5)".

-- 
   Summary: No warning for uninitialized local variable use
   Product: gcc
   Version: 3.4.1
Status: UNCONFIRMED
  Severity: minor
  Priority: P2
     Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: gopalv82 at dotgnu dot org
CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: powerpc-unknown-linux-gnu
  GCC host triplet: powerpc-unknown-linux-gnu
GCC target triplet: powerpc-unknown-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19099


[Bug c/19099] No warning for uninitialized local variable use

2004-12-20 Thread gopalv82 at dotgnu dot org

--- Additional Comments From gopalv82 at dotgnu dot org  2004-12-21 07:40 
---
Created an attachment (id=7788)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=7788&action=view)
Simple test case

Generates different output with different optimisation levels - but no warnings
at all.

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19099