]> granicus.if.org Git - clang/commitdiff
Fix null dereference in CFGBlock::FilterEdge that was reported in PR 9412.
authorTed Kremenek <kremenek@apple.com>
Mon, 7 Mar 2011 22:04:39 +0000 (22:04 +0000)
committerTed Kremenek <kremenek@apple.com>
Mon, 7 Mar 2011 22:04:39 +0000 (22:04 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@127176 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/CFG.cpp
test/SemaCXX/return-noreturn.cpp

index 833d583907b44ebbdfbeee61f67d07c1102e9164..fa98f94057e98c07bb5696ebf3b8822c9b68a72d 100644 (file)
@@ -2927,15 +2927,15 @@ unsigned CFG::getNumBlkExprs() {
 bool CFGBlock::FilterEdge(const CFGBlock::FilterOptions &F,
         const CFGBlock *From, const CFGBlock *To) {
 
-  if (F.IgnoreDefaultsWithCoveredEnums) {
+  if (To && F.IgnoreDefaultsWithCoveredEnums) {
     // If the 'To' has no label or is labeled but the label isn't a
     // CaseStmt then filter this edge.
     if (const SwitchStmt *S =
-  dyn_cast_or_null<SwitchStmt>(From->getTerminator().getStmt())) {
+        dyn_cast_or_null<SwitchStmt>(From->getTerminator().getStmt())) {
       if (S->isAllEnumCasesCovered()) {
-  const Stmt *L = To->getLabel();
-  if (!L || !isa<CaseStmt>(L))
-    return true;
+        const Stmt *L = To->getLabel();
+        if (!L || !isa<CaseStmt>(L))
+          return true;
       }
     }
   }
index e7998680b08cb6253676207a2440ea050accfc8f..53ed0d724527231a80e5339d1d2749517987abbd 100644 (file)
@@ -52,3 +52,18 @@ void test_typedefs() {
   PR9380_Ty test2[20];
 }
 
+// PR9412 - Handle CFG traversal with null successors.
+enum PR9412_MatchType { PR9412_Exact };
+
+template <PR9412_MatchType type> int PR9412_t() {
+  switch (type) {
+    case PR9412_Exact:
+    default:
+        break;
+  }
+} // expected-warning {{control reaches end of non-void function}}
+
+void PR9412_f() {
+    PR9412_t<PR9412_Exact>(); // expected-note {{in instantiation of function template specialization 'PR9412_t<0>' requested here}}
+}
+