[LLVMbugs] [Bug 13360] New: -Wsometimes-uninitialized does not handle do-while(0) well.

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Fri Jul 13 15:49:43 PDT 2012


http://llvm.org/bugs/show_bug.cgi?id=13360

             Bug #: 13360
           Summary: -Wsometimes-uninitialized does not handle do-while(0)
                    well.
           Product: clang
           Version: unspecified
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: Frontend
        AssignedTo: unassignedclangbugs at nondot.org
        ReportedBy: jordan_rose at apple.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified


% cat do-while.c
void foo();
int test(int b) {
  int x;
  if (b) {
    do {
      foo();
    } while (0);
  } else {
    x = 1;
  }
  return x;
}

% clang -fsyntax-only -Wall do-while.c
do-while.c:7:14: warning: variable 'x' is used uninitialized whenever 'do' loop
      exits because its condition is false [-Wsometimes-uninitialized]
    } while (0);
             ^
do-while.c:11:10: note: uninitialized use occurs here
  return x;
         ^
do-while.c:7:14: note: remove the condition if it is always true
    } while (0);
             ^
             1
do-while.c:3:8: note: initialize the variable 'x' to silence this warning
  int x;
       ^
        = 0


Changing "do-while(0)" to "do-while(1)" is in the running for "worst fixit
ever". :-). The bigger problem, though, is that the do-while loop isn't even
the branch that's responsible for the uninitialized variable -- it's the
if-statement that decides whether 'x' will be initialized or not by the end of
the function.


This also is a problem for if (0) and while (0), but those appear much more
rarely in real programs.

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list