summaryrefslogtreecommitdiffstats
path: root/clang/lib/Analysis/GRExprEngine.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2008-10-28 00:22:11 +0000
committerDouglas Gregor <dgregor@apple.com>2008-10-28 00:22:11 +0000
commit6b75484ba6963a748fe08ea44f11b0de89d3d0c3 (patch)
tree710bfee679d9bb468a45071ab8d3048e6291b9ea /clang/lib/Analysis/GRExprEngine.cpp
parent100f87d6554b5b187a90ce294d6d3d0f6604aee1 (diff)
downloadbcm5719-llvm-6b75484ba6963a748fe08ea44f11b0de89d3d0c3.tar.gz
bcm5719-llvm-6b75484ba6963a748fe08ea44f11b0de89d3d0c3.zip
Improve our handling of (C++) references within Clang. Specifically:
- Do not allow expressions to ever have reference type - Extend Expr::isLvalue to handle more cases where having written a reference into the source implies that the expression is an lvalue (e.g., function calls, C++ casts). - Make GRExprEngine::VisitCall treat the call arguments as lvalues when they are being bound to a reference parameter. llvm-svn: 58306
Diffstat (limited to 'clang/lib/Analysis/GRExprEngine.cpp')
-rw-r--r--clang/lib/Analysis/GRExprEngine.cpp35
1 files changed, 28 insertions, 7 deletions
diff --git a/clang/lib/Analysis/GRExprEngine.cpp b/clang/lib/Analysis/GRExprEngine.cpp
index e843f5d9e17..41579ac3a71 100644
--- a/clang/lib/Analysis/GRExprEngine.cpp
+++ b/clang/lib/Analysis/GRExprEngine.cpp
@@ -1063,22 +1063,43 @@ const GRState* GRExprEngine::EvalLocation(Expr* Ex, NodeTy* Pred,
//===----------------------------------------------------------------------===//
// Transfer function: Function calls.
//===----------------------------------------------------------------------===//
-
void GRExprEngine::VisitCall(CallExpr* CE, NodeTy* Pred,
CallExpr::arg_iterator AI,
CallExpr::arg_iterator AE,
- NodeSet& Dst) {
+ NodeSet& Dst)
+{
+ // Determine the type of function we're calling (if available).
+ const FunctionTypeProto *Proto = NULL;
+ QualType FnType = CE->getCallee()->IgnoreParens()->getType();
+ if (const PointerType *FnTypePtr = FnType->getAsPointerType())
+ Proto = FnTypePtr->getPointeeType()->getAsFunctionTypeProto();
+
+ VisitCallRec(CE, Pred, AI, AE, Dst, Proto, /*ParamIdx=*/0);
+}
+
+void GRExprEngine::VisitCallRec(CallExpr* CE, NodeTy* Pred,
+ CallExpr::arg_iterator AI,
+ CallExpr::arg_iterator AE,
+ NodeSet& Dst, const FunctionTypeProto *Proto,
+ unsigned ParamIdx) {
// Process the arguments.
-
if (AI != AE) {
-
- NodeSet DstTmp;
- Visit(*AI, Pred, DstTmp);
+ // If the call argument is being bound to a reference parameter,
+ // visit it as an lvalue, not an rvalue.
+ bool VisitAsLvalue = false;
+ if (Proto && ParamIdx < Proto->getNumArgs())
+ VisitAsLvalue = Proto->getArgType(ParamIdx)->isReferenceType();
+
+ NodeSet DstTmp;
+ if (VisitAsLvalue)
+ VisitLValue(*AI, Pred, DstTmp);
+ else
+ Visit(*AI, Pred, DstTmp);
++AI;
for (NodeSet::iterator DI=DstTmp.begin(), DE=DstTmp.end(); DI != DE; ++DI)
- VisitCall(CE, *DI, AI, AE, Dst);
+ VisitCallRec(CE, *DI, AI, AE, Dst, Proto, ParamIdx + 1);
return;
}
OpenPOWER on IntegriCloud