diff options
author | John McCall <rjmccall@apple.com> | 2011-02-17 10:25:35 +0000 |
---|---|---|
committer | John McCall <rjmccall@apple.com> | 2011-02-17 10:25:35 +0000 |
commit | 56ca35d396d8692c384c785f9aeebcf22563fe1e (patch) | |
tree | cd52281e952ff00244a59c5d47e34459c22fd7c0 /lib/StaticAnalyzer/Core | |
parent | 05c699e97aea64ee8cea1faaca900a39f977350c (diff) |
Change the representation of GNU ?: expressions to use a different expression
class and to bind the shared value using OpaqueValueExpr. This fixes an
unnoticed problem with deserialization of these expressions where the
deserialized form would lose the vital pointer-equality trait; or rather,
it fixes it because this patch also does the right thing for deserializing
OVEs.
Change OVEs to not be a "temporary object" in the sense that copy elision is
permitted.
This new representation is not totally unawkward to work with, but I think
that's really part and parcel with the semantics we're modelling here. In
particular, it's much easier to fix things like the copy elision bug and to
make the CFG look right.
I've tried to update the analyzer to deal with this in at least some
obvious cases, and I think we get a much better CFG out, but the printing
of OpaqueValueExprs probably needs some work.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@125744 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/StaticAnalyzer/Core')
-rw-r--r-- | lib/StaticAnalyzer/Core/BugReporter.cpp | 10 | ||||
-rw-r--r-- | lib/StaticAnalyzer/Core/CoreEngine.cpp | 4 | ||||
-rw-r--r-- | lib/StaticAnalyzer/Core/PathDiagnostic.cpp | 1 |
3 files changed, 11 insertions, 4 deletions
diff --git a/lib/StaticAnalyzer/Core/BugReporter.cpp b/lib/StaticAnalyzer/Core/BugReporter.cpp index d945639ee4..9a84045ebd 100644 --- a/lib/StaticAnalyzer/Core/BugReporter.cpp +++ b/lib/StaticAnalyzer/Core/BugReporter.cpp @@ -93,6 +93,7 @@ static const Stmt* GetNextStmt(const ExplodedNode* N) { // not actual statement points. switch (S->getStmtClass()) { case Stmt::ChooseExprClass: + case Stmt::BinaryConditionalOperatorClass: continue; case Stmt::ConditionalOperatorClass: continue; case Stmt::BinaryOperatorClass: { BinaryOperatorKind Op = cast<BinaryOperator>(S)->getOpcode(); @@ -279,10 +280,11 @@ PathDiagnosticBuilder::getEnclosingStmtLocation(const Stmt *S) { return PathDiagnosticLocation(Parent, SMgr); else return PathDiagnosticLocation(S, SMgr); + case Stmt::BinaryConditionalOperatorClass: case Stmt::ConditionalOperatorClass: // For '?', if we are referring to condition, just have the edge point // to the entire '?' expression. - if (cast<ConditionalOperator>(Parent)->getCond() == S) + if (cast<AbstractConditionalOperator>(Parent)->getCond() == S) return PathDiagnosticLocation(Parent, SMgr); else return PathDiagnosticLocation(S, SMgr); @@ -635,6 +637,7 @@ static void GenerateMinimalPathDiagnostic(PathDiagnostic& PD, } // Determine control-flow for ternary '?'. + case Stmt::BinaryConditionalOperatorClass: case Stmt::ConditionalOperatorClass: { std::string sbuf; llvm::raw_string_ostream os(sbuf); @@ -810,7 +813,7 @@ static bool IsControlFlowExpr(const Stmt *S) { E = E->IgnoreParenCasts(); - if (isa<ConditionalOperator>(E)) + if (isa<AbstractConditionalOperator>(E)) return true; if (const BinaryOperator *B = dyn_cast<BinaryOperator>(E)) @@ -859,8 +862,9 @@ class EdgeBuilder { S = cast<ParenExpr>(S)->IgnoreParens(); firstCharOnly = true; continue; + case Stmt::BinaryConditionalOperatorClass: case Stmt::ConditionalOperatorClass: - S = cast<ConditionalOperator>(S)->getCond(); + S = cast<AbstractConditionalOperator>(S)->getCond(); firstCharOnly = true; continue; case Stmt::ChooseExprClass: diff --git a/lib/StaticAnalyzer/Core/CoreEngine.cpp b/lib/StaticAnalyzer/Core/CoreEngine.cpp index e814361777..070042a641 100644 --- a/lib/StaticAnalyzer/Core/CoreEngine.cpp +++ b/lib/StaticAnalyzer/Core/CoreEngine.cpp @@ -346,8 +346,10 @@ void CoreEngine::HandleBlockExit(const CFGBlock * B, ExplodedNode* Pred) { HandleBranch(cast<BinaryOperator>(Term)->getLHS(), Term, B, Pred); return; + case Stmt::BinaryConditionalOperatorClass: case Stmt::ConditionalOperatorClass: - HandleBranch(cast<ConditionalOperator>(Term)->getCond(), Term, B, Pred); + HandleBranch(cast<AbstractConditionalOperator>(Term)->getCond(), + Term, B, Pred); return; // FIXME: Use constant-folding in CFG construction to simplify this diff --git a/lib/StaticAnalyzer/Core/PathDiagnostic.cpp b/lib/StaticAnalyzer/Core/PathDiagnostic.cpp index efdf5f91b4..872bbfe9e1 100644 --- a/lib/StaticAnalyzer/Core/PathDiagnostic.cpp +++ b/lib/StaticAnalyzer/Core/PathDiagnostic.cpp @@ -173,6 +173,7 @@ PathDiagnosticRange PathDiagnosticLocation::asRange() const { case Stmt::ChooseExprClass: case Stmt::IndirectGotoStmtClass: case Stmt::SwitchStmtClass: + case Stmt::BinaryConditionalOperatorClass: case Stmt::ConditionalOperatorClass: case Stmt::ObjCForCollectionStmtClass: { SourceLocation L = S->getLocStart(); |