diff options
| author | Richard Trieu <rtrieu@google.com> | 2014-06-09 22:53:25 +0000 |
|---|---|---|
| committer | Richard Trieu <rtrieu@google.com> | 2014-06-09 22:53:25 +0000 |
| commit | ddd01cec0e4ecec0ca2f6e02c38281ee562fcd8d (patch) | |
| tree | 37c95111a4e9ec687e3be04eb7f4e149d693c0e2 /clang/lib/Analysis/CFG.cpp | |
| parent | a23043cb9c1ef021a9cf05cd62cce76cd03c0ba2 (diff) | |
| download | bcm5719-llvm-ddd01cec0e4ecec0ca2f6e02c38281ee562fcd8d.tar.gz bcm5719-llvm-ddd01cec0e4ecec0ca2f6e02c38281ee562fcd8d.zip | |
Removing an "if (this == nullptr)" check from two print methods. The condition
will never be true in a well-defined context. The checking for null pointers
has been moved into the caller logic so it does not rely on undefined behavior.
llvm-svn: 210498
Diffstat (limited to 'clang/lib/Analysis/CFG.cpp')
| -rw-r--r-- | clang/lib/Analysis/CFG.cpp | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/clang/lib/Analysis/CFG.cpp b/clang/lib/Analysis/CFG.cpp index 5d2926c0f0e..61e5f5acf01 100644 --- a/clang/lib/Analysis/CFG.cpp +++ b/clang/lib/Analysis/CFG.cpp @@ -3926,7 +3926,8 @@ public: void VisitIfStmt(IfStmt *I) { OS << "if "; - I->getCond()->printPretty(OS,Helper,Policy); + if (Stmt *C = I->getCond()) + C->printPretty(OS, Helper, Policy); } // Default case. @@ -3974,19 +3975,22 @@ public: } void VisitAbstractConditionalOperator(AbstractConditionalOperator* C) { - C->getCond()->printPretty(OS, Helper, Policy); + if (Stmt *Cond = C->getCond()) + Cond->printPretty(OS, Helper, Policy); OS << " ? ... : ..."; } void VisitChooseExpr(ChooseExpr *C) { OS << "__builtin_choose_expr( "; - C->getCond()->printPretty(OS, Helper, Policy); + if (Stmt *Cond = C->getCond()) + Cond->printPretty(OS, Helper, Policy); OS << " )"; } void VisitIndirectGotoStmt(IndirectGotoStmt *I) { OS << "goto *"; - I->getTarget()->printPretty(OS, Helper, Policy); + if (Stmt *T = I->getTarget()) + T->printPretty(OS, Helper, Policy); } void VisitBinaryOperator(BinaryOperator* B) { @@ -3995,7 +3999,8 @@ public: return; } - B->getLHS()->printPretty(OS, Helper, Policy); + if (B->getLHS()) + B->getLHS()->printPretty(OS, Helper, Policy); switch (B->getOpcode()) { case BO_LOr: @@ -4026,7 +4031,8 @@ static void print_elem(raw_ostream &OS, StmtPrinterHelper &Helper, const CFGElement &E) { if (Optional<CFGStmt> CS = E.getAs<CFGStmt>()) { const Stmt *S = CS->getStmt(); - + assert(S != nullptr && "Expecting non-null Stmt"); + // special printing for statement-expressions. if (const StmtExpr *SE = dyn_cast<StmtExpr>(S)) { const CompoundStmt *Sub = SE->getSubStmt(); @@ -4172,8 +4178,9 @@ static void print_block(raw_ostream &OS, const CFG* cfg, OS << L->getName(); else if (CaseStmt *C = dyn_cast<CaseStmt>(Label)) { OS << "case "; - C->getLHS()->printPretty(OS, &Helper, - PrintingPolicy(Helper.getLangOpts())); + if (C->getLHS()) + C->getLHS()->printPretty(OS, &Helper, + PrintingPolicy(Helper.getLangOpts())); if (C->getRHS()) { OS << " ... "; C->getRHS()->printPretty(OS, &Helper, |

