[LLVMbugs] [Bug 12781] New: -Wuninitialized does not understand conditional operators

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Wed May 9 14:27:57 PDT 2012


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

             Bug #: 12781
           Summary: -Wuninitialized does not understand conditional
                    operators
           Product: clang
           Version: trunk
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Static Analyzer
        AssignedTo: kremenek at apple.com
        ReportedBy: rtrieu at google.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified


void foo(bool x) {
  int a;
  int b = a;
  int c = a;
}

-Wuninitialized properly says a is uninitialized

void foo(bool x) {
  int a;
  int b = x ? a : a;
}

-Wuninitialized and -Wconditional-uninitialized gives no warning

void foo(bool x) {
  int a;
  int b = x ? a : a;
  int c = a;
}

Also no warnings

The likely cause of this problem is how the AST is set up for conditional
operators where both expressions are variables.  The l-value to r-value cast
would then be outside of the conditional operator instead of directly on the
DeclRefExprs.  Example AST:
void foo(bool x) (CompoundStmt 0x4afeaa0 <maybe.cc:1:18, line:6:1>
  (DeclStmt 0x4afe868 <line:2:3, col:8>
    0x4afe810 "int a")
  (DeclStmt 0x4afe9c0 <line:3:3, col:20>
    0x4afe890 "int b =
      (ImplicitCastExpr 0x4afe9a8 <col:11, col:19> 'int' <LValueToRValue>
        (ConditionalOperator 0x4afe978 <col:11, col:19> 'int' lvalue
          (ImplicitCastExpr 0x4afe960 <col:11> '_Bool' <LValueToRValue>
            (DeclRefExpr 0x4afe8e8 <col:11> '_Bool' lvalue ParmVar 0x4acc2a0
'x' '_Bool'))
          (DeclRefExpr 0x4afe910 <col:15> 'int' lvalue Var 0x4afe810 'a' 'int')
          (DeclRefExpr 0x4afe938 <col:19> 'int' lvalue Var 0x4afe810 'a'
'int')))")
  (DeclStmt 0x4afea88 <line:5:3, col:12>
    0x4afe9f0 "int c =
      (ImplicitCastExpr 0x4afea70 <col:11> 'int' <LValueToRValue>
        (DeclRefExpr 0x4afea48 <col:11> 'int' lvalue Var 0x4afe810 'a'
'int'))"))

-- 
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