Bug 36814

Summary: G++ won't warn about an uninitialized value
Product: gcc Reporter: Jelle Geerts <jellegeerts>
Component: c++Assignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED DUPLICATE    
Severity: normal CC: dberlin, gcc-bugs, jellegeerts, manu, mark, mueller, P.Schaffnit, pinskia, satyam, thutt
Priority: P3    
Version: 4.3.1   
Target Milestone: ---   
Host: i386-undermydesk-freebsd Target: i386-undermydesk-freebsd
Build: i386-undermydesk-freebsd Known to work:
Known to fail: Last reconfirmed:
Bug Depends on:    
Bug Blocks: 24639    
Attachments: output of G++ with the `-v -save-temps' flags
the `.ii' file that G++ created

Description Jelle Geerts 2008-07-12 20:04:11 UTC
Hello,

I've compiled the code below using `g++ -Wuninitialized -O test.cc -o test':

<<<<<<<<<<<<<<<
bool cMyClass::Init()
{
    bool retval;

    if (some_function())
    {
        // If the `goto' is executed, 'return retval;' will use the
        // uninitialized value of 'retval'.
        goto error;
    }

    retval = true;
error:
    return retval;
}
>>>>>>>>>>>>>>>

The problem is explained in the code comments above.

I think that GCC is supposed to warn about this, is that correct?

Thanks, Jelle
Comment 1 Manuel López-Ibáñez 2008-08-18 17:35:42 UTC
We need a preprocessed self-contained, preferably small, testcase. Otherwise we cannot reproduce the bug ourselves.

See http://gcc.gnu.org/bugs.html

Thanks.
Comment 2 Jelle Geerts 2008-08-18 18:14:35 UTC
Created attachment 16086 [details]
output of G++ with the `-v -save-temps' flags
Comment 3 Jelle Geerts 2008-08-18 18:15:03 UTC
Created attachment 16087 [details]
the `.ii' file that G++ created
Comment 4 Jelle Geerts 2008-08-18 18:16:15 UTC
Please see the attachments I created for more information.
Comment 5 Manuel López-Ibáñez 2008-08-18 18:56:30 UTC
possible_bug.cc:1: error: `cMyClass' has not been declared
possible_bug.cc: In function `bool Init()':
possible_bug.cc:5: error: `some_function' was not declared in this scope
possible_bug.cc:5: warning: unused variable 'some_function'

Anyway, I guess the following reproduces the original problem:

bool some_function(void);

bool Init()
{
    bool retval;

    if (some_function())
    {
        // If the `goto' is executed, 'return retval;' will use the
        // uninitialized value of 'retval'.
        goto error;
    }

    retval = true;
error:
    return retval;
}


which is converted to:

bool Init() ()
{
  boolD.2365 retvalD.2430;
  boolD.2365 retval.0D.2432;

  # BLOCK 2
  # PRED: ENTRY (fallthru,exec)
  [pr36814.C : 7] retval.0D.2432_2 = some_functionD.2427 ();
  [pr36814.C : 7] retval.0D.2432_3 = retval.0D.2432_2;
  [pr36814.C : 7] if (retval.0D.2432_3 != 0)
    goto <bb 4> (error);
  else
    goto <bb 3>;
  # SUCC: 4 (true,exec) 3 (false,exec)

  # BLOCK 3
  # PRED: 2 (false,exec)
  [pr36814.C : 14] retvalD.2430_5 = 1;
  # SUCC: 4 (fallthru,exec)

  # BLOCK 4, starting at line 0
  # PRED: 2 (true,exec) 3 (fallthru,exec)
  # retvalD.2430_1 = PHI <retvalD.2430_4(D)(2), 1(3)>
errorL.1:
  return 1;
  # SUCC: EXIT

}

by the first CCP pass. So this is CCP again.

*** This bug has been marked as a duplicate of 18501 ***