Tweak UndefBranchChecker to register the most nested "undefined" expression with bugreporter::registerTrackNullOrUndefValue instead of the condition itself.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@89682 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Analysis/UndefBranchChecker.cpp b/lib/Analysis/UndefBranchChecker.cpp
index 0a66e21..b6861ba 100644
--- a/lib/Analysis/UndefBranchChecker.cpp
+++ b/lib/Analysis/UndefBranchChecker.cpp
@@ -73,9 +73,6 @@
       N->markAsSink();
       if (!BT)
         BT = new BuiltinBug("Branch condition evaluates to a garbage value");
-      EnhancedBugReport *R = new EnhancedBugReport(*BT, BT->getDescription(),N);
-      R->addVisitorCreator(bugreporter::registerTrackNullOrUndefValue, 
-                           Condition);
 
       // What's going on here: we want to highlight the subexpression of the
       // condition that is the most likely source of the "uninitialized
@@ -105,6 +102,10 @@
 
       FindUndefExpr FindIt(Eng.getStateManager(), St);
       Ex = FindIt.FindExpr(Ex);
+
+      // Emit the bug report.
+      EnhancedBugReport *R = new EnhancedBugReport(*BT, BT->getDescription(),N);
+      R->addVisitorCreator(bugreporter::registerTrackNullOrUndefValue, Ex);
       R->addRange(Ex->getSourceRange());
 
       Eng.getBugReporter().EmitReport(R);
diff --git a/test/Analysis/misc-ps.m b/test/Analysis/misc-ps.m
index 385fcaf..1722f7a 100644
--- a/test/Analysis/misc-ps.m
+++ b/test/Analysis/misc-ps.m
@@ -767,6 +767,12 @@
   return x ? 1 : 0; // expected-warning{{Branch condition evaluates to a garbage value}}
 }
 
+int test_uninit_branch_c(void) {
+  int x;
+  if ((short)x) // expected-warning{{Branch condition evaluates to a garbage value}}
+    return 1;
+  return 0; 
+}
 
 //===----------------------------------------------------------------------===//
 // Test passing an undefined value in a message or function call.