From: Ted Kremenek Date: Fri, 21 Sep 2012 18:33:52 +0000 (+0000) Subject: Add helper method in BodyFarm to create unary dereferences. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0b5c5e487bbbdeb2a7688e6c753d3b2a7c337604;p=clang 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 --- 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(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(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(), C.VoidTy, VK_RValue, SourceLocation()); return CE;