aboutsummaryrefslogtreecommitdiff
path: root/lib/Analysis
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2012-09-21 18:33:52 +0000
committerTed Kremenek <kremenek@apple.com>2012-09-21 18:33:52 +0000
commit0b5c5e487bbbdeb2a7688e6c753d3b2a7c337604 (patch)
tree4e1d7c018b74868d346e2bd671c76b3e03e1b904 /lib/Analysis
parent9ba05cd2e24e600ab59b2ed893ae598abbbc9a36 (diff)
Add helper method in BodyFarm to create unary dereferences.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@164399 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis')
-rw-r--r--lib/Analysis/BodyFarm.cpp19
1 files changed, 11 insertions, 8 deletions
diff --git a/lib/Analysis/BodyFarm.cpp b/lib/Analysis/BodyFarm.cpp
index be8bf52d02..2faacd4ea3 100644
--- a/lib/Analysis/BodyFarm.cpp
+++ b/lib/Analysis/BodyFarm.cpp
@@ -49,6 +49,9 @@ public:
/// Create a new DeclRefExpr for the referenced variable.
DeclRefExpr *makeDeclRefExpr(const VarDecl *D);
+ /// Create a new UnaryOperator representing a dereference.
+ UnaryOperator *makeDereference(const Expr *Arg, QualType Ty);
+
/// Create an implicit cast for an integer conversion.
ImplicitCastExpr *makeIntegralCast(const Expr *Arg, QualType Ty);
@@ -73,6 +76,11 @@ DeclRefExpr *ASTMaker::makeDeclRefExpr(const VarDecl *D) {
return DR;
}
+UnaryOperator *ASTMaker::makeDereference(const Expr *Arg, QualType Ty) {
+ return new (C) UnaryOperator(const_cast<Expr*>(Arg), UO_Deref, Ty,
+ VK_LValue, OK_Ordinary, SourceLocation());
+}
+
ImplicitCastExpr *ASTMaker::makeLvalueToRvalue(const Expr *Arg, QualType Ty) {
return ImplicitCastExpr::Create(C, Ty, CK_LValueToRValue,
const_cast<Expr*>(Arg), 0, VK_RValue);
@@ -136,9 +144,7 @@ static Stmt *create_dispatch_once(ASTContext &C, const FunctionDecl *D) {
ICE = M.makeIntegralCast(IL, PredicateTy);
DR = M.makeDeclRefExpr(Predicate);
ImplicitCastExpr *LValToRval = M.makeLvalueToRvalue(DR, PredicateQPtrTy);
- UnaryOperator *UO = new (C) UnaryOperator(LValToRval, UO_Deref, PredicateTy,
- VK_LValue, OK_Ordinary,
- SourceLocation());
+ UnaryOperator *UO = M.makeDereference(LValToRval, PredicateTy);
BinaryOperator *B = new (C) BinaryOperator(UO, ICE, BO_Assign,
PredicateTy, VK_RValue,
OK_Ordinary,
@@ -153,9 +159,7 @@ static Stmt *create_dispatch_once(ASTContext &C, const FunctionDecl *D) {
// (4) Create the 'if' condition.
DR = M.makeDeclRefExpr(Predicate);
LValToRval = M.makeLvalueToRvalue(DR, PredicateQPtrTy);
- UO = new (C) UnaryOperator(LValToRval, UO_Deref, PredicateTy,
- VK_LValue, OK_Ordinary,
- SourceLocation());
+ UO = M.makeDereference(LValToRval, PredicateTy);
LValToRval = M.makeLvalueToRvalue(UO, PredicateTy);
UO = new (C) UnaryOperator(LValToRval, UO_LNot, C.IntTy,
VK_RValue, OK_Ordinary, SourceLocation());
@@ -186,8 +190,7 @@ static Stmt *create_dispatch_sync(ASTContext &C, const FunctionDecl *D) {
//
ASTMaker M(C);
DeclRefExpr *DR = M.makeDeclRefExpr(PV);
- ImplicitCastExpr *ICE = ImplicitCastExpr::Create(C, Ty, CK_LValueToRValue,
- DR, 0, VK_RValue);
+ ImplicitCastExpr *ICE = M.makeLvalueToRvalue(DR, Ty);
CallExpr *CE = new (C) CallExpr(C, ICE, ArrayRef<Expr*>(), C.VoidTy,
VK_RValue, SourceLocation());
return CE;