From 9ba05cd2e24e600ab59b2ed893ae598abbbc9a36 Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Fri, 21 Sep 2012 18:13:27 +0000 Subject: [PATCH] Add helper method to BodyFarm for creating lvalue-to-rvalue conversions. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@164397 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Analysis/BodyFarm.cpp | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/lib/Analysis/BodyFarm.cpp b/lib/Analysis/BodyFarm.cpp index f7fbcc933d..be8bf52d02 100644 --- a/lib/Analysis/BodyFarm.cpp +++ b/lib/Analysis/BodyFarm.cpp @@ -52,6 +52,9 @@ public: /// Create an implicit cast for an integer conversion. ImplicitCastExpr *makeIntegralCast(const Expr *Arg, QualType Ty); + // Create an implicit cast for lvalue-to-rvaluate conversions. + ImplicitCastExpr *makeLvalueToRvalue(const Expr *Arg, QualType Ty); + private: ASTContext &C; }; @@ -70,6 +73,11 @@ DeclRefExpr *ASTMaker::makeDeclRefExpr(const VarDecl *D) { return DR; } +ImplicitCastExpr *ASTMaker::makeLvalueToRvalue(const Expr *Arg, QualType Ty) { + return ImplicitCastExpr::Create(C, Ty, CK_LValueToRValue, + const_cast(Arg), 0, VK_RValue); +} + ImplicitCastExpr *ASTMaker::makeIntegralCast(const Expr *Arg, QualType Ty) { return ImplicitCastExpr::Create(C, Ty, CK_IntegralCast, const_cast(Arg), 0, VK_RValue); @@ -117,8 +125,7 @@ static Stmt *create_dispatch_once(ASTContext &C, const FunctionDecl *D) { // (1) Create the call. DeclRefExpr *DR = M.makeDeclRefExpr(Block); - 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()); @@ -128,9 +135,7 @@ static Stmt *create_dispatch_once(ASTContext &C, const FunctionDecl *D) { C.IntTy, SourceLocation()); ICE = M.makeIntegralCast(IL, PredicateTy); DR = M.makeDeclRefExpr(Predicate); - ImplicitCastExpr *LValToRval = - ImplicitCastExpr::Create(C, PredicateQPtrTy, CK_LValueToRValue, DR, - 0, VK_RValue); + ImplicitCastExpr *LValToRval = M.makeLvalueToRvalue(DR, PredicateQPtrTy); UnaryOperator *UO = new (C) UnaryOperator(LValToRval, UO_Deref, PredicateTy, VK_LValue, OK_Ordinary, SourceLocation()); @@ -147,13 +152,11 @@ static Stmt *create_dispatch_once(ASTContext &C, const FunctionDecl *D) { // (4) Create the 'if' condition. DR = M.makeDeclRefExpr(Predicate); - LValToRval = ImplicitCastExpr::Create(C, PredicateQPtrTy, CK_LValueToRValue, - DR, 0, VK_RValue); + LValToRval = M.makeLvalueToRvalue(DR, PredicateQPtrTy); UO = new (C) UnaryOperator(LValToRval, UO_Deref, PredicateTy, VK_LValue, OK_Ordinary, SourceLocation()); - LValToRval = ImplicitCastExpr::Create(C, PredicateTy, CK_LValueToRValue, - UO, 0, VK_RValue); + LValToRval = M.makeLvalueToRvalue(UO, PredicateTy); UO = new (C) UnaryOperator(LValToRval, UO_LNot, C.IntTy, VK_RValue, OK_Ordinary, SourceLocation()); -- 2.40.0