From 6e40035988965340555c942d6e7afb6c7527beb1 Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Mon, 7 Mar 2011 22:04:39 +0000 Subject: [PATCH] Fix null dereference in CFGBlock::FilterEdge that was reported in PR 9412. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@127176 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Analysis/CFG.cpp | 10 +++++----- test/SemaCXX/return-noreturn.cpp | 15 +++++++++++++++ 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/lib/Analysis/CFG.cpp b/lib/Analysis/CFG.cpp index 833d583907..fa98f94057 100644 --- a/lib/Analysis/CFG.cpp +++ b/lib/Analysis/CFG.cpp @@ -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(From->getTerminator().getStmt())) { + dyn_cast_or_null(From->getTerminator().getStmt())) { if (S->isAllEnumCasesCovered()) { - const Stmt *L = To->getLabel(); - if (!L || !isa(L)) - return true; + const Stmt *L = To->getLabel(); + if (!L || !isa(L)) + return true; } } } diff --git a/test/SemaCXX/return-noreturn.cpp b/test/SemaCXX/return-noreturn.cpp index e7998680b0..53ed0d7245 100644 --- a/test/SemaCXX/return-noreturn.cpp +++ b/test/SemaCXX/return-noreturn.cpp @@ -52,3 +52,18 @@ void test_typedefs() { PR9380_Ty test2[20]; } +// PR9412 - Handle CFG traversal with null successors. +enum PR9412_MatchType { PR9412_Exact }; + +template int PR9412_t() { + switch (type) { + case PR9412_Exact: + default: + break; + } +} // expected-warning {{control reaches end of non-void function}} + +void PR9412_f() { + PR9412_t(); // expected-note {{in instantiation of function template specialization 'PR9412_t<0>' requested here}} +} + -- 2.40.0