r365037 - Revert "[analyzer][CFG] Return the correct terminator condition"
Kristof Umann via cfe-commits
cfe-commits at lists.llvm.org
Wed Jul 3 06:03:33 PDT 2019
Author: szelethus
Date: Wed Jul 3 06:03:33 2019
New Revision: 365037
URL: http://llvm.org/viewvc/llvm-project?rev=365037&view=rev
Log:
Revert "[analyzer][CFG] Return the correct terminator condition"
This reverts commit 7a57118a6fcfa3770f984453543bbdfd0b233e84.
Causes a bunch of crashes, I need to time to evaluate this.
Modified:
cfe/trunk/include/clang/Analysis/CFG.h
cfe/trunk/lib/Analysis/CFG.cpp
Modified: cfe/trunk/include/clang/Analysis/CFG.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/CFG.h?rev=365037&r1=365036&r2=365037&view=diff
==============================================================================
--- cfe/trunk/include/clang/Analysis/CFG.h (original)
+++ cfe/trunk/include/clang/Analysis/CFG.h Wed Jul 3 06:03:33 2019
@@ -860,12 +860,10 @@ public:
Stmt *getTerminatorStmt() { return Terminator.getStmt(); }
const Stmt *getTerminatorStmt() const { return Terminator.getStmt(); }
- /// \returns the condition of the terminator (condition of an if statement,
- /// for loop, etc).
- const Stmt *getTerminatorCondition(bool StripParens = true) const;
+ Stmt *getTerminatorCondition(bool StripParens = true);
- const Expr *getTerminatorConditionExpr(bool StripParens = true) const {
- return dyn_cast_or_null<Expr>(getTerminatorCondition(StripParens));
+ const Stmt *getTerminatorCondition(bool StripParens = true) const {
+ return const_cast<CFGBlock*>(this)->getTerminatorCondition(StripParens);
}
const Stmt *getLoopTarget() const { return LoopTarget; }
Modified: cfe/trunk/lib/Analysis/CFG.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CFG.cpp?rev=365037&r1=365036&r2=365037&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/CFG.cpp (original)
+++ cfe/trunk/lib/Analysis/CFG.cpp Wed Jul 3 06:03:33 2019
@@ -5615,21 +5615,69 @@ void CFGBlock::printTerminatorJson(raw_o
Out << JsonFormat(TempOut.str(), AddQuotes);
}
-const Stmt *CFGBlock::getTerminatorCondition(bool StripParens) const {
- // If the terminator is a temporary dtor or a virtual base, etc, we can't
- // retrieve a meaningful condition, bail out.
- if (rbegin()->getKind() != CFGElement::Kind::Statement)
+Stmt *CFGBlock::getTerminatorCondition(bool StripParens) {
+ Stmt *Terminator = getTerminatorStmt();
+ if (!Terminator)
return nullptr;
- // This should be the condition of the terminator block.
- const Stmt *S = rbegin()->castAs<CFGStmt>().getStmt();
- if (isa<ObjCForCollectionStmt>(S)) {
- return getTerminatorStmt();
+ Expr *E = nullptr;
+
+ switch (Terminator->getStmtClass()) {
+ default:
+ break;
+
+ case Stmt::CXXForRangeStmtClass:
+ E = cast<CXXForRangeStmt>(Terminator)->getCond();
+ break;
+
+ case Stmt::ForStmtClass:
+ E = cast<ForStmt>(Terminator)->getCond();
+ break;
+
+ case Stmt::WhileStmtClass:
+ E = cast<WhileStmt>(Terminator)->getCond();
+ break;
+
+ case Stmt::DoStmtClass:
+ E = cast<DoStmt>(Terminator)->getCond();
+ break;
+
+ case Stmt::IfStmtClass:
+ E = cast<IfStmt>(Terminator)->getCond();
+ break;
+
+ case Stmt::ChooseExprClass:
+ E = cast<ChooseExpr>(Terminator)->getCond();
+ break;
+
+ case Stmt::IndirectGotoStmtClass:
+ E = cast<IndirectGotoStmt>(Terminator)->getTarget();
+ break;
+
+ case Stmt::SwitchStmtClass:
+ E = cast<SwitchStmt>(Terminator)->getCond();
+ break;
+
+ case Stmt::BinaryConditionalOperatorClass:
+ E = cast<BinaryConditionalOperator>(Terminator)->getCond();
+ break;
+
+ case Stmt::ConditionalOperatorClass:
+ E = cast<ConditionalOperator>(Terminator)->getCond();
+ break;
+
+ case Stmt::BinaryOperatorClass: // '&&' and '||'
+ E = cast<BinaryOperator>(Terminator)->getLHS();
+ break;
+
+ case Stmt::ObjCForCollectionStmtClass:
+ return Terminator;
}
- // Only ObjCForCollectionStmt is known not to be a non-Expr terminator.
- const Expr *Cond = cast<Expr>(S);
- return StripParens ? Cond->IgnoreParens() : Cond;
+ if (!StripParens)
+ return E;
+
+ return E ? E->IgnoreParens() : nullptr;
}
//===----------------------------------------------------------------------===//
More information about the cfe-commits
mailing list