summaryrefslogtreecommitdiffstats
path: root/clang/lib/Analysis/BodyFarm.cpp
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2012-09-21 17:54:35 +0000
committerTed Kremenek <kremenek@apple.com>2012-09-21 17:54:35 +0000
commit7241813bd78601c9e2ae0e9ee672c412bdab4e69 (patch)
tree5e1988031ddfabccc1b0228b32ca091dc5768518 /clang/lib/Analysis/BodyFarm.cpp
parent2b5c83ca8f16054a0595eb7e5fd63939177f336e (diff)
downloadbcm5719-llvm-7241813bd78601c9e2ae0e9ee672c412bdab4e69.tar.gz
bcm5719-llvm-7241813bd78601c9e2ae0e9ee672c412bdab4e69.zip
Use helper method to create DeclRefExprs in BodyFarm, hopefully allevating
them being correctly constructed. llvm-svn: 164392
Diffstat (limited to 'clang/lib/Analysis/BodyFarm.cpp')
-rw-r--r--clang/lib/Analysis/BodyFarm.cpp54
1 files changed, 34 insertions, 20 deletions
diff --git a/clang/lib/Analysis/BodyFarm.cpp b/clang/lib/Analysis/BodyFarm.cpp
index 7b1122d5b00..fc874e0c8b1 100644
--- a/clang/lib/Analysis/BodyFarm.cpp
+++ b/clang/lib/Analysis/BodyFarm.cpp
@@ -41,6 +41,31 @@ static bool isDispatchBlock(QualType Ty) {
return true;
}
+namespace {
+class ASTMaker {
+public:
+ ASTMaker(ASTContext &C) : C(C) {}
+
+ DeclRefExpr *makeDeclRefExpr(const VarDecl *D);
+
+private:
+ ASTContext &C;
+};
+}
+
+DeclRefExpr *ASTMaker::makeDeclRefExpr(const VarDecl *D) {
+ DeclRefExpr *DR =
+ DeclRefExpr::Create(/* Ctx = */ C,
+ /* QualifierLoc = */ NestedNameSpecifierLoc(),
+ /* TemplateKWLoc = */ SourceLocation(),
+ /* D = */ const_cast<VarDecl*>(D),
+ /* isEnclosingLocal = */ false,
+ /* NameLoc = */ SourceLocation(),
+ /* T = */ D->getType(),
+ /* VK = */ VK_LValue);
+ return DR;
+}
+
//===----------------------------------------------------------------------===//
// Creation functions for faux ASTs.
//===----------------------------------------------------------------------===//
@@ -79,11 +104,10 @@ static Stmt *create_dispatch_once(ASTContext &C, const FunctionDecl *D) {
// }
// }
+ ASTMaker M(C);
+
// (1) Create the call.
- DeclRefExpr *DR = DeclRefExpr::CreateEmpty(C, false, false, false, false);
- DR->setDecl(const_cast<ParmVarDecl*>(Block));
- DR->setType(Ty);
- DR->setValueKind(VK_LValue);
+ DeclRefExpr *DR = M.makeDeclRefExpr(Block);
ImplicitCastExpr *ICE = ImplicitCastExpr::Create(C, Ty, CK_LValueToRValue,
DR, 0, VK_RValue);
CallExpr *CE = new (C) CallExpr(C, ICE, ArrayRef<Expr*>(), C.VoidTy,
@@ -95,10 +119,7 @@ static Stmt *create_dispatch_once(ASTContext &C, const FunctionDecl *D) {
C.IntTy, SourceLocation());
ICE = ImplicitCastExpr::Create(C, PredicateTy, CK_IntegralCast, IL, 0,
VK_RValue);
- DR = DeclRefExpr::CreateEmpty(C, false, false, false, false);
- DR->setDecl(const_cast<ParmVarDecl*>(Predicate));
- DR->setType(PredicateQPtrTy);
- DR->setValueKind(VK_LValue);
+ DR = M.makeDeclRefExpr(Predicate);
ImplicitCastExpr *LValToRval =
ImplicitCastExpr::Create(C, PredicateQPtrTy, CK_LValueToRValue, DR,
0, VK_RValue);
@@ -117,10 +138,7 @@ static Stmt *create_dispatch_once(ASTContext &C, const FunctionDecl *D) {
SourceLocation());
// (4) Create the 'if' condition.
- DR = DeclRefExpr::CreateEmpty(C, false, false, false, false);
- DR->setDecl(const_cast<ParmVarDecl*>(Predicate));
- DR->setType(PredicateQPtrTy);
- DR->setValueKind(VK_LValue);
+ DR = M.makeDeclRefExpr(Predicate);
LValToRval = ImplicitCastExpr::Create(C, PredicateQPtrTy, CK_LValueToRValue,
DR, 0, VK_RValue);
UO = new (C) UnaryOperator(LValToRval, UO_Deref, PredicateTy,
@@ -136,8 +154,6 @@ static Stmt *create_dispatch_once(ASTContext &C, const FunctionDecl *D) {
return If;
}
-
-
/// Create a fake body for dispatch_sync.
static Stmt *create_dispatch_sync(ASTContext &C, const FunctionDecl *D) {
// Check if we have at least two parameters.
@@ -149,18 +165,16 @@ static Stmt *create_dispatch_sync(ASTContext &C, const FunctionDecl *D) {
QualType Ty = PV->getType();
if (!isDispatchBlock(Ty))
return 0;
-
+
// Everything checks out. Create a fake body that just calls the block.
// This is basically just an AST dump of:
//
// void dispatch_sync(dispatch_queue_t queue, void (^block)(void)) {
// block();
// }
- //
- DeclRefExpr *DR = DeclRefExpr::CreateEmpty(C, false, false, false, false);
- DR->setDecl(const_cast<ParmVarDecl*>(PV));
- DR->setType(Ty);
- DR->setValueKind(VK_LValue);
+ //
+ ASTMaker M(C);
+ DeclRefExpr *DR = M.makeDeclRefExpr(PV);
ImplicitCastExpr *ICE = ImplicitCastExpr::Create(C, Ty, CK_LValueToRValue,
DR, 0, VK_RValue);
CallExpr *CE = new (C) CallExpr(C, ICE, ArrayRef<Expr*>(), C.VoidTy,
OpenPOWER on IntegriCloud