[cfe-commits] r114056 - in /cfe/trunk: include/clang/Analysis/CFG.h include/clang/Analysis/FlowSensitive/DataflowSolver.h include/clang/Analysis/ProgramPoint.h include/clang/Checker/PathSensitive/GRCoreEngine.h lib/Analysis/CFG.cpp lib/Analysis/CFGStmtMap.cpp lib/Analysis/ReachableCode.cpp lib/Checker/BugReporter.cpp lib/Checker/GRExprEngine.cpp lib/Checker/UnreachableCodeChecker.cpp lib/Sema/AnalysisBasedWarnings.cpp

Zhongxing Xu xuzhongxing at gmail.com
Wed Sep 15 18:25:47 PDT 2010


Author: zhongxingxu
Date: Wed Sep 15 20:25:47 2010
New Revision: 114056

URL: http://llvm.org/viewvc/llvm-project?rev=114056&view=rev
Log:
Introduce new CFGElement hierarchy to support C++ CFG, based on Marcin's patch
and discussions with Ted and Jordy.

Modified:
    cfe/trunk/include/clang/Analysis/CFG.h
    cfe/trunk/include/clang/Analysis/FlowSensitive/DataflowSolver.h
    cfe/trunk/include/clang/Analysis/ProgramPoint.h
    cfe/trunk/include/clang/Checker/PathSensitive/GRCoreEngine.h
    cfe/trunk/lib/Analysis/CFG.cpp
    cfe/trunk/lib/Analysis/CFGStmtMap.cpp
    cfe/trunk/lib/Analysis/ReachableCode.cpp
    cfe/trunk/lib/Checker/BugReporter.cpp
    cfe/trunk/lib/Checker/GRExprEngine.cpp
    cfe/trunk/lib/Checker/UnreachableCodeChecker.cpp
    cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp

Modified: cfe/trunk/include/clang/Analysis/CFG.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/CFG.h?rev=114056&r1=114055&r2=114056&view=diff
==============================================================================
--- cfe/trunk/include/clang/Analysis/CFG.h (original)
+++ cfe/trunk/include/clang/Analysis/CFG.h Wed Sep 15 20:25:47 2010
@@ -38,19 +38,110 @@
 
 /// CFGElement - Represents a top-level expression in a basic block.
 class CFGElement {
-  llvm::PointerIntPair<Stmt *, 2> Data;
 public:
-  enum Type { StartScope, EndScope };
-  explicit CFGElement() {}
-  CFGElement(Stmt *S, bool lvalue) : Data(S, lvalue ? 1 : 0) {}
-  CFGElement(Stmt *S, Type t) : Data(S, t == StartScope ? 2 : 3) {}
-  Stmt *getStmt() const { return Data.getPointer(); }
-  bool asLValue() const { return Data.getInt() == 1; }
-  bool asStartScope() const { return Data.getInt() == 2; }
-  bool asEndScope() const { return Data.getInt() == 3; }
-  bool asDtor() const { return Data.getInt() == 4; }
+  enum Kind {
+    // main kind
+    Statement,
+    StatementAsLValue,
+    Initializer,
+    Dtor,
+    // dtor kind
+    AutomaticObjectDtor,
+    BaseDtor,
+    MemberDtor,
+    TemporaryDtor,
+    DTOR_BEGIN = AutomaticObjectDtor
+  };
+
+protected:
+  // The int bits are used to mark the main kind.
+  llvm::PointerIntPair<void *, 2> Data1;
+  // The int bits are used to mark the dtor kind.
+  llvm::PointerIntPair<void *, 2> Data2;
+
+public:
+  CFGElement() {}
+  CFGElement(void *Ptr, unsigned Int) : Data1(Ptr, Int) {}
+
+  Kind getKind() const { return static_cast<Kind>(Data1.getInt()); }
+
+  Kind getDtorKind() const {
+    assert(getKind() == Dtor);
+    return static_cast<Kind>(Data2.getInt() + DTOR_BEGIN);
+  }
+
+  bool isValid() const { return Data1.getPointer(); }
+
+  operator bool() const { return isValid(); }
+
+  template<class ElemTy> ElemTy getAs() const {
+    if (llvm::isa<ElemTy>(this))
+      return *static_cast<const ElemTy*>(this);
+    return ElemTy();
+  }
+
+  static bool classof(const CFGElement *E) { return true; }
+};
+
+class CFGStmt : public CFGElement {
+public:
+  CFGStmt() {}
+  CFGStmt(Stmt *S, bool asLValue) : CFGElement(S, asLValue) {}
+
+  Stmt *getStmt() const { return static_cast<Stmt *>(Data1.getPointer()); }
+
   operator Stmt*() const { return getStmt(); }
-  operator bool() const { return getStmt() != 0; }
+
+  bool asLValue() const { 
+    return static_cast<Kind>(Data1.getInt()) == StatementAsLValue;
+  }
+
+  static bool classof(const CFGElement *E) {
+    return E->getKind() == Statement || E->getKind() == StatementAsLValue;
+  }
+};
+
+class CFGInitializer : public CFGElement {
+public:
+  static bool classof(const CFGElement *E) {
+    return E->getKind() == Initializer;
+  }
+};
+
+class CFGImplicitDtor : public CFGElement {
+public:
+  static bool classof(const CFGElement *E) {
+    return E->getKind() == Dtor;
+  }
+};
+
+class CFGAutomaticObjDtor: public CFGImplicitDtor {
+public:
+  static bool classof(const CFGElement *E) {
+    return E->getKind() == Dtor && E->getDtorKind() == AutomaticObjectDtor;
+  }
+};
+
+class CFGBaseDtor : public CFGImplicitDtor {
+public:
+  static bool classof(const CFGElement *E) {
+    return E->getKind() == Dtor && E->getDtorKind() == BaseDtor;
+  }
+};
+
+class CFGMemberDtor : public CFGImplicitDtor {
+public:
+  static bool classof(const CFGElement *E) {
+    return E->getKind() == Dtor && E->getDtorKind() == MemberDtor;
+  }
+
+};
+
+class CFGTemporaryDtor : public CFGImplicitDtor {
+public:
+  static bool classof(const CFGElement *E) {
+    return E->getKind() == Dtor && E->getDtorKind() == TemporaryDtor;
+  }
 };
 
 /// CFGBlock - Represents a single basic block in a source-level CFG.
@@ -78,11 +169,11 @@
 ///     &&, ||          expression that uses result of && or ||, RHS
 ///
 class CFGBlock {
-  class StatementList {
+  class ElementList {
     typedef BumpVector<CFGElement> ImplTy;
     ImplTy Impl;
   public:
-    StatementList(BumpVectorContext &C) : Impl(C, 4) {}
+    ElementList(BumpVectorContext &C) : Impl(C, 4) {}
     
     typedef std::reverse_iterator<ImplTy::iterator>       iterator;
     typedef std::reverse_iterator<ImplTy::const_iterator> const_iterator;
@@ -112,7 +203,7 @@
   };
 
   /// Stmts - The set of statements in the basic block.
-  StatementList Stmts;
+  ElementList Elements;
 
   /// Label - An (optional) label that prefixes the executable
   ///  statements in the block.  When this variable is non-NULL, it is
@@ -141,33 +232,33 @@
 
 public:
   explicit CFGBlock(unsigned blockid, BumpVectorContext &C)
-    : Stmts(C), Label(NULL), Terminator(NULL), LoopTarget(NULL),
+    : Elements(C), Label(NULL), Terminator(NULL), LoopTarget(NULL),
       BlockID(blockid), Preds(C, 1), Succs(C, 1) {}
   ~CFGBlock() {}
 
   // Statement iterators
-  typedef StatementList::iterator                      iterator;
-  typedef StatementList::const_iterator                const_iterator;
-  typedef StatementList::reverse_iterator              reverse_iterator;
-  typedef StatementList::const_reverse_iterator        const_reverse_iterator;
-
-  CFGElement                   front()       const { return Stmts.front();   }
-  CFGElement                   back()        const { return Stmts.back();    }
-
-  iterator                     begin()             { return Stmts.begin();   }
-  iterator                     end()               { return Stmts.end();     }
-  const_iterator               begin()       const { return Stmts.begin();   }
-  const_iterator               end()         const { return Stmts.end();     }
-
-  reverse_iterator             rbegin()            { return Stmts.rbegin();  }
-  reverse_iterator             rend()              { return Stmts.rend();    }
-  const_reverse_iterator       rbegin()      const { return Stmts.rbegin();  }
-  const_reverse_iterator       rend()        const { return Stmts.rend();    }
+  typedef ElementList::iterator                      iterator;
+  typedef ElementList::const_iterator                const_iterator;
+  typedef ElementList::reverse_iterator              reverse_iterator;
+  typedef ElementList::const_reverse_iterator        const_reverse_iterator;
+
+  CFGElement                 front()       const { return Elements.front();   }
+  CFGElement                 back()        const { return Elements.back();    }
+
+  iterator                   begin()             { return Elements.begin();   }
+  iterator                   end()               { return Elements.end();     }
+  const_iterator             begin()       const { return Elements.begin();   }
+  const_iterator             end()         const { return Elements.end();     }
+
+  reverse_iterator           rbegin()            { return Elements.rbegin();  }
+  reverse_iterator           rend()              { return Elements.rend();    }
+  const_reverse_iterator     rbegin()      const { return Elements.rbegin();  }
+  const_reverse_iterator     rend()        const { return Elements.rend();    }
 
-  unsigned                     size()        const { return Stmts.size();    }
-  bool                         empty()       const { return Stmts.empty();   }
+  unsigned                   size()        const { return Elements.size();    }
+  bool                       empty()       const { return Elements.empty();   }
 
-  CFGElement operator[](size_t i) const  { return Stmts[i]; }
+  CFGElement operator[](size_t i) const  { return Elements[i]; }
 
   // CFG iterators
   typedef AdjacentBlocks::iterator                              pred_iterator;
@@ -294,11 +385,10 @@
   }
   
   void appendStmt(Stmt* Statement, BumpVectorContext &C, bool asLValue) {
-      Stmts.push_back(CFGElement(Statement, asLValue), C);
+    Elements.push_back(CFGStmt(Statement, asLValue), C);
   }
 };
 
-
 /// CFG - Represents a source-level, intra-procedural CFG that represents the
 ///  control-flow of a Stmt.  The Stmt can represent an entire function body,
 ///  or a single expression.  A CFG will always contain one empty block that
@@ -383,8 +473,10 @@
   void VisitBlockStmts(CALLBACK& O) const {
     for (const_iterator I=begin(), E=end(); I != E; ++I)
       for (CFGBlock::const_iterator BI=(*I)->begin(), BE=(*I)->end();
-           BI != BE; ++BI)
-        O(*BI);
+           BI != BE; ++BI) {
+        if (CFGStmt S = BI->getAs<CFGStmt>())
+          O(S);
+      }
   }
 
   //===--------------------------------------------------------------------===//
@@ -457,18 +549,6 @@
 
 namespace llvm {
 
-/// Implement simplify_type for CFGElement, so that we can dyn_cast from
-/// CFGElement to a specific Stmt class.
-template <> struct simplify_type<const ::clang::CFGElement> {
-  typedef ::clang::Stmt* SimpleType;
-  static SimpleType getSimplifiedValue(const ::clang::CFGElement &Val) {
-    return Val.getStmt();
-  }
-};
-  
-template <> struct simplify_type< ::clang::CFGElement> 
-  : public simplify_type<const ::clang::CFGElement> {};
-  
 // Traits for: CFGBlock
 
 template <> struct GraphTraits< ::clang::CFGBlock* > {

Modified: cfe/trunk/include/clang/Analysis/FlowSensitive/DataflowSolver.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/FlowSensitive/DataflowSolver.h?rev=114056&r1=114055&r2=114056&view=diff
==============================================================================
--- cfe/trunk/include/clang/Analysis/FlowSensitive/DataflowSolver.h (original)
+++ cfe/trunk/include/clang/Analysis/FlowSensitive/DataflowSolver.h Wed Sep 15 20:25:47 2010
@@ -273,8 +273,11 @@
   void ProcessBlock(const CFGBlock* B, bool recordStmtValues,
                     dataflow::forward_analysis_tag) {
 
-    for (StmtItr I=ItrTraits::StmtBegin(B), E=ItrTraits::StmtEnd(B); I!=E;++I)
-      ProcessStmt(*I, recordStmtValues, AnalysisDirTag());
+    for (StmtItr I=ItrTraits::StmtBegin(B), E=ItrTraits::StmtEnd(B); I!=E;++I) {
+      CFGElement E = *I;
+      if (CFGStmt S = E.getAs<CFGStmt>())
+        ProcessStmt(S, recordStmtValues, AnalysisDirTag());
+    }
 
     TF.VisitTerminator(const_cast<CFGBlock*>(B));
   }
@@ -284,8 +287,11 @@
 
     TF.VisitTerminator(const_cast<CFGBlock*>(B));
 
-    for (StmtItr I=ItrTraits::StmtBegin(B), E=ItrTraits::StmtEnd(B); I!=E;++I)
-      ProcessStmt(*I, recordStmtValues, AnalysisDirTag());
+    for (StmtItr I=ItrTraits::StmtBegin(B), E=ItrTraits::StmtEnd(B); I!=E;++I) {
+      CFGElement E = *I;
+      if (CFGStmt S = E.getAs<CFGStmt>())
+        ProcessStmt(S, recordStmtValues, AnalysisDirTag());
+    }
   }
 
   void ProcessStmt(const Stmt* S, bool record, dataflow::forward_analysis_tag) {

Modified: cfe/trunk/include/clang/Analysis/ProgramPoint.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/ProgramPoint.h?rev=114056&r1=114055&r2=114056&view=diff
==============================================================================
--- cfe/trunk/include/clang/Analysis/ProgramPoint.h (original)
+++ cfe/trunk/include/clang/Analysis/ProgramPoint.h Wed Sep 15 20:25:47 2010
@@ -118,10 +118,6 @@
     return B->empty() ? CFGElement() : B->front();
   }
   
-  const Stmt *getFirstStmt() const {
-    return getFirstElement().getStmt();
-  }
-
   static bool classof(const ProgramPoint* Location) {
     return Location->getKind() == BlockEntranceKind;
   }
@@ -136,11 +132,6 @@
     return reinterpret_cast<const CFGBlock*>(getData1());
   }
 
-  const Stmt* getLastStmt() const {
-    const CFGBlock* B = getBlock();
-    return B->empty() ? CFGElement() : B->back();
-  }
-
   const Stmt* getTerminator() const {
     return getBlock()->getTerminator();
   }

Modified: cfe/trunk/include/clang/Checker/PathSensitive/GRCoreEngine.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Checker/PathSensitive/GRCoreEngine.h?rev=114056&r1=114055&r2=114056&view=diff
==============================================================================
--- cfe/trunk/include/clang/Checker/PathSensitive/GRCoreEngine.h (original)
+++ cfe/trunk/include/clang/Checker/PathSensitive/GRCoreEngine.h Wed Sep 15 20:25:47 2010
@@ -259,7 +259,13 @@
 
   /// getStmt - Return the current block-level expression associated with
   ///  this builder.
-  const Stmt* getStmt() const { return B[Idx]; }
+  const Stmt* getStmt() const { 
+    CFGStmt CS = B[Idx].getAs<CFGStmt>();
+    if (CS)
+      return CS.getStmt();
+    else
+      return 0;
+  }
 
   /// getBlock - Return the CFGBlock associated with the block-level expression
   ///  of this builder.

Modified: cfe/trunk/lib/Analysis/CFG.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CFG.cpp?rev=114056&r1=114055&r2=114056&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/CFG.cpp (original)
+++ cfe/trunk/lib/Analysis/CFG.cpp Wed Sep 15 20:25:47 2010
@@ -1846,15 +1846,19 @@
 
   for (CFG::iterator I=cfg.begin(), E=cfg.end(); I != E; ++I)
     for (CFGBlock::iterator BI=(*I)->begin(), EI=(*I)->end(); BI != EI; ++BI)
-      FindSubExprAssignments(*BI, SubExprAssignments);
+      if (CFGStmt S = BI->getAs<CFGStmt>())
+        FindSubExprAssignments(S, SubExprAssignments);
 
   for (CFG::iterator I=cfg.begin(), E=cfg.end(); I != E; ++I) {
 
     // Iterate over the statements again on identify the Expr* and Stmt* at the
     // block-level that are block-level expressions.
 
-    for (CFGBlock::iterator BI=(*I)->begin(), EI=(*I)->end(); BI != EI; ++BI)
-      if (Expr* Exp = dyn_cast<Expr>(*BI)) {
+    for (CFGBlock::iterator BI=(*I)->begin(), EI=(*I)->end(); BI != EI; ++BI) {
+      CFGStmt CS = BI->getAs<CFGStmt>();
+      if (!CS.isValid())
+        continue;
+      if (Expr* Exp = dyn_cast<Expr>(CS.getStmt())) {
 
         if (BinaryOperator* B = dyn_cast<BinaryOperator>(Exp)) {
           // Assignment expressions that are not nested within another
@@ -1875,6 +1879,7 @@
         unsigned x = M->size();
         (*M)[Exp] = x;
       }
+    }
 
     // Look at terminators.  The condition is a block-level expression.
 
@@ -1959,9 +1964,13 @@
     for (CFG::const_iterator I = cfg->begin(), E = cfg->end(); I != E; ++I ) {
       unsigned j = 1;
       for (CFGBlock::const_iterator BI = (*I)->begin(), BEnd = (*I)->end() ;
-           BI != BEnd; ++BI, ++j )
-        StmtMap[*BI] = std::make_pair((*I)->getBlockID(),j);
+           BI != BEnd; ++BI, ++j ) {
+        CFGStmt CS = BI->getAs<CFGStmt>();
+        if (!CS.isValid())
+          continue;
+        StmtMap[CS] = std::make_pair((*I)->getBlockID(),j);
       }
+    }
   }
 
   virtual ~StmtPrinterHelper() {}
@@ -2090,7 +2099,10 @@
 
 static void print_stmt(llvm::raw_ostream &OS, StmtPrinterHelper* Helper,
                        const CFGElement &E) {
-  Stmt *S = E;
+  CFGStmt CS = E.getAs<CFGStmt>();
+  if (!CS)
+    return;
+  Stmt *S = CS.getStmt();
   
   if (Helper) {
     // special printing for statement-expressions.

Modified: cfe/trunk/lib/Analysis/CFGStmtMap.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CFGStmtMap.cpp?rev=114056&r1=114055&r2=114056&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/CFGStmtMap.cpp (original)
+++ cfe/trunk/lib/Analysis/CFGStmtMap.cpp Wed Sep 15 20:25:47 2010
@@ -50,15 +50,18 @@
   // First walk the block-level expressions.
   for (CFGBlock::iterator I = B->begin(), E = B->end(); I != E; ++I) {
     const CFGElement &CE = *I;
-    if (Stmt *S = CE.getStmt()) {
-      CFGBlock *&Entry = SM[S];
-      // If 'Entry' is already initialized (e.g., a terminator was already),
-      // skip.
-      if (Entry)
-        continue;
+    CFGStmt CS = CE.getAs<CFGStmt>();
+    if (!CS.isValid())
+      continue;
+    
+    CFGBlock *&Entry = SM[CS];
+    // If 'Entry' is already initialized (e.g., a terminator was already),
+    // skip.
+    if (Entry)
+      continue;
       
-      Entry = B;
-    }
+    Entry = B;
+    
   }
   
   // Look at the label of the block.

Modified: cfe/trunk/lib/Analysis/ReachableCode.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/ReachableCode.cpp?rev=114056&r1=114055&r2=114056&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/ReachableCode.cpp (original)
+++ cfe/trunk/lib/Analysis/ReachableCode.cpp Wed Sep 15 20:25:47 2010
@@ -31,9 +31,13 @@
   R1 = R2 = SourceRange();
 
 top:
-  if (sn < b.size())
-    S = b[sn].getStmt();
-  else if (b.getTerminator())
+  if (sn < b.size()) {
+    CFGStmt CS = b[sn].getAs<CFGStmt>();
+    if (!CS)
+      goto top;
+    
+    S = CS.getStmt(); 
+  } else if (b.getTerminator())
     S = b.getTerminator();
   else
     return SourceLocation();
@@ -43,7 +47,7 @@
       const BinaryOperator *BO = cast<BinaryOperator>(S);
       if (BO->getOpcode() == BO_Comma) {
         if (sn+1 < b.size())
-          return b[sn+1].getStmt()->getLocStart();
+          return b[sn+1].getAs<CFGStmt>().getStmt()->getLocStart();
         const CFGBlock *n = &b;
         while (1) {
           if (n->getTerminator())
@@ -54,7 +58,7 @@
           if (n->pred_size() != 1)
             return SourceLocation();
           if (!n->empty())
-            return n[0][0].getStmt()->getLocStart();
+            return n[0][0].getAs<CFGStmt>().getStmt()->getLocStart();
         }
       }
       R1 = BO->getLHS()->getSourceRange();

Modified: cfe/trunk/lib/Checker/BugReporter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Checker/BugReporter.cpp?rev=114056&r1=114055&r2=114056&view=diff
==============================================================================
--- cfe/trunk/lib/Checker/BugReporter.cpp (original)
+++ cfe/trunk/lib/Checker/BugReporter.cpp Wed Sep 15 20:25:47 2010
@@ -1165,15 +1165,15 @@
       }
 
       if (const BlockEntrance *BE = dyn_cast<BlockEntrance>(&P)) {
-        if (const Stmt* S = BE->getFirstStmt()) {
-         if (IsControlFlowExpr(S)) {
-           // Add the proper context for '&&', '||', and '?'.
-           EB.addContext(S);
-         }
-         else
-           EB.addExtendedContext(PDB.getEnclosingStmtLocation(S).asStmt());
+        if (CFGStmt S = BE->getFirstElement().getAs<CFGStmt>()) {
+          if (IsControlFlowExpr(S)) {
+            // Add the proper context for '&&', '||', and '?'.
+            EB.addContext(S);
+          }
+          else
+            EB.addExtendedContext(PDB.getEnclosingStmtLocation(S).asStmt());
         }
-
+        
         break;
       }
     } while (0);

Modified: cfe/trunk/lib/Checker/GRExprEngine.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Checker/GRExprEngine.cpp?rev=114056&r1=114055&r2=114056&view=diff
==============================================================================
--- cfe/trunk/lib/Checker/GRExprEngine.cpp (original)
+++ cfe/trunk/lib/Checker/GRExprEngine.cpp Wed Sep 15 20:25:47 2010
@@ -634,7 +634,7 @@
 }
 
 void GRExprEngine::ProcessStmt(const CFGElement CE,GRStmtNodeBuilder& builder) {
-  CurrentStmt = CE.getStmt();
+  CurrentStmt = CE.getAs<CFGStmt>();
   PrettyStackTraceLoc CrashInfo(getContext().getSourceManager(),
                                 CurrentStmt->getLocStart(),
                                 "Error evaluating statement");
@@ -721,7 +721,7 @@
     Builder->SetCleanedState(*I == EntryNode ? CleanedState : GetState(*I));
 
     // Visit the statement.
-    if (CE.asLValue())
+    if (CE.getAs<CFGStmt>().asLValue())
       VisitLValue(cast<Expr>(CurrentStmt), *I, Dst);
     else
       Visit(CurrentStmt, *I, Dst);

Modified: cfe/trunk/lib/Checker/UnreachableCodeChecker.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Checker/UnreachableCodeChecker.cpp?rev=114056&r1=114055&r2=114056&view=diff
==============================================================================
--- cfe/trunk/lib/Checker/UnreachableCodeChecker.cpp (original)
+++ cfe/trunk/lib/Checker/UnreachableCodeChecker.cpp Wed Sep 15 20:25:47 2010
@@ -116,10 +116,12 @@
     // FIXME: This should be extended to include other unreachable markers,
     // such as llvm_unreachable.
     if (!CB->empty()) {
-      const Stmt *First = CB->front();
-      if (const CallExpr *CE = dyn_cast<CallExpr>(First)) {
-        if (CE->isBuiltinCall(Ctx) == Builtin::BI__builtin_unreachable)
-          continue;
+      CFGElement First = CB->front();
+      if (CFGStmt S = First.getAs<CFGStmt>()) {
+        if (const CallExpr *CE = dyn_cast<CallExpr>(S.getStmt())) {
+          if (CE->isBuiltinCall(Ctx) == Builtin::BI__builtin_unreachable)
+            continue;
+        }
       }
     }
 
@@ -173,9 +175,11 @@
 
 // Find the Stmt* in a CFGBlock for reporting a warning
 const Stmt *UnreachableCodeChecker::getUnreachableStmt(const CFGBlock *CB) {
-  if (CB->size() > 0)
-    return CB->front().getStmt();
-  else if (const Stmt *S = CB->getTerminator())
+  for (CFGBlock::const_iterator I = CB->begin(), E = CB->end(); I != E; ++I) {
+    if (CFGStmt S = I->getAs<CFGStmt>())
+      return S;
+  }
+  if (const Stmt *S = CB->getTerminator())
     return S;
   else
     return 0;

Modified: cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp?rev=114056&r1=114055&r2=114056&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp (original)
+++ cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp Wed Sep 15 20:25:47 2010
@@ -129,7 +129,11 @@
       HasPlainEdge = true;
       continue;
     }
-    Stmt *S = B[B.size()-1];
+    CFGElement CE = B[B.size()-1];
+    CFGStmt CS = CE.getAs<CFGStmt>();
+    if (!CS.isValid())
+      continue;
+    Stmt *S = CS.getStmt();
     if (isa<ReturnStmt>(S)) {
       HasLiveReturn = true;
       continue;





More information about the cfe-commits mailing list