[cfe-commits] r127176 - in /cfe/trunk: lib/Analysis/CFG.cpp test/SemaCXX/return-noreturn.cpp

Ted Kremenek kremenek at apple.com
Mon Mar 7 14:04:39 PST 2011


Author: kremenek
Date: Mon Mar  7 16:04:39 2011
New Revision: 127176

URL: http://llvm.org/viewvc/llvm-project?rev=127176&view=rev
Log:
Fix null dereference in CFGBlock::FilterEdge that was reported in PR 9412.

Modified:
    cfe/trunk/lib/Analysis/CFG.cpp
    cfe/trunk/test/SemaCXX/return-noreturn.cpp

Modified: cfe/trunk/lib/Analysis/CFG.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CFG.cpp?rev=127176&r1=127175&r2=127176&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/CFG.cpp (original)
+++ cfe/trunk/lib/Analysis/CFG.cpp Mon Mar  7 16:04:39 2011
@@ -2927,15 +2927,15 @@
 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;
       }
     }
   }

Modified: cfe/trunk/test/SemaCXX/return-noreturn.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/return-noreturn.cpp?rev=127176&r1=127175&r2=127176&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/return-noreturn.cpp (original)
+++ cfe/trunk/test/SemaCXX/return-noreturn.cpp Mon Mar  7 16:04:39 2011
@@ -52,3 +52,18 @@
   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}}
+}
+





More information about the cfe-commits mailing list