Index: include/clang/AST/Expr.h =================================================================== --- include/clang/AST/Expr.h +++ include/clang/AST/Expr.h @@ -1086,20 +1086,10 @@ void computeDependence(const ASTContext &Ctx); public: - DeclRefExpr(ValueDecl *D, bool RefersToEnclosingVariableOrCapture, QualType T, + DeclRefExpr(const ASTContext &Ctx, ValueDecl *D, + bool RefersToEnclosingVariableOrCapture, QualType T, ExprValueKind VK, SourceLocation L, - const DeclarationNameLoc &LocInfo = DeclarationNameLoc()) - : Expr(DeclRefExprClass, T, VK, OK_Ordinary, false, false, false, false), - D(D), DNLoc(LocInfo) { - DeclRefExprBits.HasQualifier = false; - DeclRefExprBits.HasTemplateKWAndArgsInfo = false; - DeclRefExprBits.HasFoundDecl = false; - DeclRefExprBits.HadMultipleCandidates = false; - DeclRefExprBits.RefersToEnclosingVariableOrCapture = - RefersToEnclosingVariableOrCapture; - DeclRefExprBits.Loc = L; - computeDependence(D->getASTContext()); - } + const DeclarationNameLoc &LocInfo = DeclarationNameLoc()); static DeclRefExpr * Create(const ASTContext &Context, NestedNameSpecifierLoc QualifierLoc, Index: lib/AST/ASTContext.cpp =================================================================== --- lib/AST/ASTContext.cpp +++ lib/AST/ASTContext.cpp @@ -4319,7 +4319,7 @@ Arg = TemplateArgument(ArgType); } else if (auto *NTTP = dyn_cast(Param)) { Expr *E = new (*this) DeclRefExpr( - NTTP, /*enclosing*/false, + *this, NTTP, /*enclosing*/ false, NTTP->getType().getNonLValueExprType(*this), Expr::getValueKindForType(NTTP->getType()), NTTP->getLocation()); Index: lib/AST/Expr.cpp =================================================================== --- lib/AST/Expr.cpp +++ lib/AST/Expr.cpp @@ -342,6 +342,22 @@ ExprBits.ContainsUnexpandedParameterPack = true; } +DeclRefExpr::DeclRefExpr(const ASTContext &Ctx, ValueDecl *D, + bool RefersToEnclosingVariableOrCapture, QualType T, + ExprValueKind VK, SourceLocation L, + const DeclarationNameLoc &LocInfo) + : Expr(DeclRefExprClass, T, VK, OK_Ordinary, false, false, false, false), + D(D), DNLoc(LocInfo) { + DeclRefExprBits.HasQualifier = false; + DeclRefExprBits.HasTemplateKWAndArgsInfo = false; + DeclRefExprBits.HasFoundDecl = false; + DeclRefExprBits.HadMultipleCandidates = false; + DeclRefExprBits.RefersToEnclosingVariableOrCapture = + RefersToEnclosingVariableOrCapture; + DeclRefExprBits.Loc = L; + computeDependence(Ctx); +} + DeclRefExpr::DeclRefExpr(const ASTContext &Ctx, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, Index: lib/Analysis/ThreadSafety.cpp =================================================================== --- lib/Analysis/ThreadSafety.cpp +++ lib/Analysis/ThreadSafety.cpp @@ -1901,7 +1901,8 @@ if (isScopedVar) { // Add the managing object as a dummy mutex, mapped to the underlying mutex. SourceLocation MLoc = VD->getLocation(); - DeclRefExpr DRE(VD, false, VD->getType(), VK_LValue, VD->getLocation()); + DeclRefExpr DRE(VD->getASTContext(), VD, false, VD->getType(), + VK_LValue, VD->getLocation()); // FIXME: does this store a pointer to DRE? CapabilityExpr Scp = Analyzer->SxBuilder.translateAttrExpr(&DRE, nullptr); @@ -2431,7 +2432,8 @@ // Create a dummy expression, auto *VD = const_cast(AD.getVarDecl()); - DeclRefExpr DRE(VD, false, VD->getType().getNonReferenceType(), + DeclRefExpr DRE(VD->getASTContext(), VD, false, + VD->getType().getNonReferenceType(), VK_LValue, AD.getTriggerStmt()->getEndLoc()); LocksetBuilder.handleCall(&DRE, DD); break; Index: lib/Analysis/ThreadSafetyCommon.cpp =================================================================== --- lib/Analysis/ThreadSafetyCommon.cpp +++ lib/Analysis/ThreadSafetyCommon.cpp @@ -128,7 +128,8 @@ // Hack to handle constructors, where self cannot be recovered from // the expression. if (SelfDecl && !Ctx.SelfArg) { - DeclRefExpr SelfDRE(SelfDecl, false, SelfDecl->getType(), VK_LValue, + DeclRefExpr SelfDRE(SelfDecl->getASTContext(), SelfDecl, false, + SelfDecl->getType(), VK_LValue, SelfDecl->getLocation()); Ctx.SelfArg = &SelfDRE; Index: lib/CodeGen/CGBlocks.cpp =================================================================== --- lib/CodeGen/CGBlocks.cpp +++ lib/CodeGen/CGBlocks.cpp @@ -1075,7 +1075,7 @@ src = I->second; } } else { - DeclRefExpr declRef(const_cast(variable), + DeclRefExpr declRef(getContext(), const_cast(variable), /*RefersToEnclosingVariableOrCapture*/ CI.isNested(), type.getNonReferenceType(), VK_LValue, SourceLocation()); @@ -1149,7 +1149,7 @@ // We use one of these or the other depending on whether the // reference is nested. - DeclRefExpr declRef(const_cast(variable), + DeclRefExpr declRef(getContext(), const_cast(variable), /*RefersToEnclosingVariableOrCapture*/ CI.isNested(), type, VK_LValue, SourceLocation()); Index: lib/CodeGen/CGDecl.cpp =================================================================== --- lib/CodeGen/CGDecl.cpp +++ lib/CodeGen/CGDecl.cpp @@ -547,7 +547,7 @@ void Emit(CodeGenFunction &CGF, Flags flags) override { // Compute the address of the local variable, in case it's a // byref or something. - DeclRefExpr DRE(const_cast(&Var), false, + DeclRefExpr DRE(CGF.getContext(), const_cast(&Var), false, Var.getType(), VK_LValue, SourceLocation()); llvm::Value *value = CGF.EmitLoadOfScalar(CGF.EmitDeclRefLValue(&DRE), SourceLocation()); @@ -565,7 +565,7 @@ : CleanupFn(CleanupFn), FnInfo(*Info), Var(*Var) {} void Emit(CodeGenFunction &CGF, Flags flags) override { - DeclRefExpr DRE(const_cast(&Var), false, + DeclRefExpr DRE(CGF.getContext(), const_cast(&Var), false, Var.getType(), VK_LValue, SourceLocation()); // Compute the address of the local variable, in case it's a byref // or something. Index: lib/CodeGen/CGObjC.cpp =================================================================== --- lib/CodeGen/CGObjC.cpp +++ lib/CodeGen/CGObjC.cpp @@ -1069,7 +1069,8 @@ // The second argument is the address of the parameter variable. ParmVarDecl *argVar = *OMD->param_begin(); - DeclRefExpr argRef(argVar, false, argVar->getType().getNonReferenceType(), + DeclRefExpr argRef(CGF.getContext(), argVar, false, + argVar->getType().getNonReferenceType(), VK_LValue, SourceLocation()); llvm::Value *argAddr = CGF.EmitLValue(&argRef).getPointer(); argAddr = CGF.Builder.CreateBitCast(argAddr, CGF.Int8PtrTy); @@ -1114,7 +1115,8 @@ // The second argument is the address of the parameter variable. ParmVarDecl *argVar = *OMD->param_begin(); - DeclRefExpr argRef(argVar, false, argVar->getType().getNonReferenceType(), + DeclRefExpr argRef(CGF.getContext(), argVar, false, + argVar->getType().getNonReferenceType(), VK_LValue, SourceLocation()); llvm::Value *argAddr = CGF.EmitLValue(&argRef).getPointer(); argAddr = CGF.Builder.CreateBitCast(argAddr, CGF.Int8PtrTy); @@ -1287,7 +1289,7 @@ // Otherwise, fake up some ASTs and emit a normal assignment. ValueDecl *selfDecl = setterMethod->getSelfDecl(); - DeclRefExpr self(selfDecl, false, selfDecl->getType(), + DeclRefExpr self(getContext(), selfDecl, false, selfDecl->getType(), VK_LValue, SourceLocation()); ImplicitCastExpr selfLoad(ImplicitCastExpr::OnStack, selfDecl->getType(), CK_LValueToRValue, &self, @@ -1298,7 +1300,8 @@ ParmVarDecl *argDecl = *setterMethod->param_begin(); QualType argType = argDecl->getType().getNonReferenceType(); - DeclRefExpr arg(argDecl, false, argType, VK_LValue, SourceLocation()); + DeclRefExpr arg(getContext(), argDecl, false, argType, + VK_LValue, SourceLocation()); ImplicitCastExpr argLoad(ImplicitCastExpr::OnStack, argType.getUnqualifiedType(), CK_LValueToRValue, &arg, VK_RValue); @@ -1460,7 +1463,8 @@ llvm::Value *CodeGenFunction::LoadObjCSelf() { VarDecl *Self = cast(CurFuncDecl)->getSelfDecl(); - DeclRefExpr DRE(Self, /*is enclosing local*/ (CurFuncDecl != CurCodeDecl), + DeclRefExpr DRE(getContext(), Self, + /*is enclosing local*/ (CurFuncDecl != CurCodeDecl), Self->getType(), VK_LValue, SourceLocation()); return EmitLoadOfScalar(EmitDeclRefLValue(&DRE), SourceLocation()); } @@ -1647,8 +1651,8 @@ EmitAutoVarInit(variable); const VarDecl* D = cast(SD->getSingleDecl()); - DeclRefExpr tempDRE(const_cast(D), false, D->getType(), - VK_LValue, SourceLocation()); + DeclRefExpr tempDRE(getContext(), const_cast(D), false, + D->getType(), VK_LValue, SourceLocation()); elementLValue = EmitLValue(&tempDRE); elementType = D->getType(); elementIsVariable = true; @@ -3287,12 +3291,12 @@ StartFunction(FD, ReturnTy, Fn, FI, args); - DeclRefExpr DstExpr(&DstDecl, false, DestTy, + DeclRefExpr DstExpr(getContext(), &DstDecl, false, DestTy, VK_RValue, SourceLocation()); UnaryOperator DST(&DstExpr, UO_Deref, DestTy->getPointeeType(), VK_LValue, OK_Ordinary, SourceLocation(), false); - DeclRefExpr SrcExpr(&SrcDecl, false, SrcTy, + DeclRefExpr SrcExpr(getContext(), &SrcDecl, false, SrcTy, VK_RValue, SourceLocation()); UnaryOperator SRC(&SrcExpr, UO_Deref, SrcTy->getPointeeType(), VK_LValue, OK_Ordinary, SourceLocation(), false); @@ -3370,7 +3374,7 @@ StartFunction(FD, ReturnTy, Fn, FI, args); - DeclRefExpr SrcExpr(&SrcDecl, false, SrcTy, + DeclRefExpr SrcExpr(getContext(), &SrcDecl, false, SrcTy, VK_RValue, SourceLocation()); UnaryOperator SRC(&SrcExpr, UO_Deref, SrcTy->getPointeeType(), @@ -3396,7 +3400,7 @@ CXXConstExpr->getConstructionKind(), SourceRange()); - DeclRefExpr DstExpr(&DstDecl, false, DestTy, + DeclRefExpr DstExpr(getContext(), &DstDecl, false, DestTy, VK_RValue, SourceLocation()); RValue DV = EmitAnyExpr(&DstExpr); Index: lib/CodeGen/CGOpenMPRuntime.cpp =================================================================== --- lib/CodeGen/CGOpenMPRuntime.cpp +++ lib/CodeGen/CGOpenMPRuntime.cpp @@ -353,7 +353,7 @@ if (VD->isLocalVarDeclOrParm()) continue; - DeclRefExpr DRE(const_cast(VD), + DeclRefExpr DRE(CGF.getContext(), const_cast(VD), /*RefersToEnclosingVariableOrCapture=*/false, VD->getType().getNonReferenceType(), VK_LValue, C.getLocation()); Index: lib/CodeGen/CGStmtOpenMP.cpp =================================================================== --- lib/CodeGen/CGStmtOpenMP.cpp +++ lib/CodeGen/CGStmtOpenMP.cpp @@ -73,6 +73,7 @@ assert(VD == VD->getCanonicalDecl() && "Canonical decl must be captured."); DeclRefExpr DRE( + CGF.getContext(), const_cast(VD), isCapturedVar(CGF, VD) || (CGF.CapturedStmtInfo && InlinedShareds.isGlobalVarCaptured(VD)), @@ -191,7 +192,8 @@ auto *VD = C.getCapturedVar(); assert(VD == VD->getCanonicalDecl() && "Canonical decl must be captured."); - DeclRefExpr DRE(const_cast(VD), + DeclRefExpr DRE(CGF.getContext(), + const_cast(VD), isCapturedVar(CGF, VD) || (CGF.CapturedStmtInfo && InlinedShareds.isGlobalVarCaptured(VD)), @@ -222,7 +224,7 @@ LambdaCaptureFields.lookup(OrigVD) || (CapturedStmtInfo && CapturedStmtInfo->lookup(OrigVD)) || (CurCodeDecl && isa(CurCodeDecl)); - DeclRefExpr DRE(const_cast(OrigVD), IsCaptured, + DeclRefExpr DRE(getContext(), const_cast(OrigVD), IsCaptured, OrigDRE->getType(), VK_LValue, OrigDRE->getExprLoc()); return EmitLValue(&DRE); } @@ -763,7 +765,7 @@ const auto *VDInit = cast(cast(*InitsRef)->getDecl()); bool IsRegistered; - DeclRefExpr DRE(const_cast(OrigVD), + DeclRefExpr DRE(getContext(), const_cast(OrigVD), /*RefersToEnclosingVariableOrCapture=*/FD != nullptr, (*IRef)->getType(), VK_LValue, (*IRef)->getExprLoc()); LValue OriginalLVal = EmitLValue(&DRE); @@ -878,8 +880,8 @@ getContext().getTargetInfo().isTLSSupported()) { assert(CapturedStmtInfo->lookup(VD) && "Copyin threadprivates should have been captured!"); - DeclRefExpr DRE(const_cast(VD), true, (*IRef)->getType(), - VK_LValue, (*IRef)->getExprLoc()); + DeclRefExpr DRE(getContext(), const_cast(VD), true, + (*IRef)->getType(), VK_LValue, (*IRef)->getExprLoc()); MasterAddr = EmitLValue(&DRE).getAddress(); LocalDeclMap.erase(VD); } else { @@ -954,6 +956,7 @@ cast(cast(*IDestRef)->getDecl()); PrivateScope.addPrivate(DestVD, [this, OrigVD, IRef]() { DeclRefExpr DRE( + getContext(), const_cast(OrigVD), /*RefersToEnclosingVariableOrCapture=*/CapturedStmtInfo->lookup( OrigVD) != nullptr, @@ -1384,7 +1387,7 @@ dyn_cast(VD->getInit()->IgnoreImpCasts())) { AutoVarEmission Emission = EmitAutoVarAlloca(*VD); const auto *OrigVD = cast(Ref->getDecl()); - DeclRefExpr DRE(const_cast(OrigVD), + DeclRefExpr DRE(getContext(), const_cast(OrigVD), CapturedStmtInfo->lookup(OrigVD) != nullptr, VD->getInit()->getType(), VK_LValue, VD->getInit()->getExprLoc()); @@ -1429,7 +1432,7 @@ } } const auto *OrigVD = cast(cast(*IC)->getDecl()); - DeclRefExpr DRE(const_cast(OrigVD), + DeclRefExpr DRE(getContext(), const_cast(OrigVD), CapturedStmtInfo->lookup(OrigVD) != nullptr, (*IC)->getType(), VK_LValue, (*IC)->getExprLoc()); Address OrigAddr = EmitLValue(&DRE).getAddress(); @@ -1497,7 +1500,7 @@ if (LocalDeclMap.count(VD) || CapturedStmtInfo->lookup(VD) || VD->hasGlobalStorage()) { (void)LoopScope.addPrivate(PrivateVD, [this, VD, E]() { - DeclRefExpr DRE(const_cast(VD), + DeclRefExpr DRE(getContext(), const_cast(VD), LocalDeclMap.count(VD) || CapturedStmtInfo->lookup(VD), E->getType(), VK_LValue, E->getExprLoc()); return EmitLValue(&DRE).getAddress(); @@ -1644,7 +1647,7 @@ if (CED) { OrigAddr = EmitLValue(CED->getInit()->IgnoreImpCasts()).getAddress(); } else { - DeclRefExpr DRE(const_cast(PrivateVD), + DeclRefExpr DRE(getContext(), const_cast(PrivateVD), /*RefersToEnclosingVariableOrCapture=*/false, (*IPC)->getType(), VK_LValue, (*IPC)->getExprLoc()); OrigAddr = EmitLValue(&DRE).getAddress(); @@ -2930,6 +2933,7 @@ for (const auto &Pair : LastprivateDstsOrigs) { const auto *OrigVD = cast(Pair.second->getDecl()); DeclRefExpr DRE( + CGF.getContext(), const_cast(OrigVD), /*RefersToEnclosingVariableOrCapture=*/CGF.CapturedStmtInfo->lookup( OrigVD) != nullptr, Index: lib/Frontend/Rewrite/RewriteModernObjC.cpp =================================================================== --- lib/Frontend/Rewrite/RewriteModernObjC.cpp +++ lib/Frontend/Rewrite/RewriteModernObjC.cpp @@ -2096,8 +2096,8 @@ QualType msgSendType = FD->getType(); // Create a reference to the objc_msgSend() declaration. - DeclRefExpr *DRE = - new (Context) DeclRefExpr(FD, false, msgSendType, VK_LValue, SourceLocation()); + DeclRefExpr *DRE = new (Context) DeclRefExpr(*Context, FD, false, msgSendType, + VK_LValue, SourceLocation()); // Now, we cast the reference to a pointer to the objc_msgSend type. QualType pToFunc = Context->getPointerType(msgSendType); @@ -2584,8 +2584,8 @@ VarDecl *NewVD = VarDecl::Create(*Context, TUDecl, SourceLocation(), SourceLocation(), &Context->Idents.get(S), strType, nullptr, SC_Static); - DeclRefExpr *DRE = new (Context) DeclRefExpr(NewVD, false, strType, VK_LValue, - SourceLocation()); + DeclRefExpr *DRE = new (Context) DeclRefExpr(*Context, NewVD, false, strType, + VK_LValue, SourceLocation()); Expr *Unop = new (Context) UnaryOperator(DRE, UO_AddrOf, Context->getPointerType(DRE->getType()), VK_RValue, OK_Ordinary, @@ -2673,8 +2673,8 @@ QualType msgSendType = MsgSendFlavor->getType(); // Create a reference to the objc_msgSend() declaration. - DeclRefExpr *DRE = new (Context) DeclRefExpr(MsgSendFlavor, false, msgSendType, - VK_LValue, SourceLocation()); + DeclRefExpr *DRE = new (Context) DeclRefExpr( + *Context, MsgSendFlavor, false, msgSendType, VK_LValue, SourceLocation()); CastExpr *cast = NoTypeInfoCStyleCastExpr(Context, Context->getPointerType(Context->VoidTy), @@ -2717,9 +2717,8 @@ getSimpleFunctionType(Context->VoidTy, IntQT, true); std::string NSArrayFName("__NSContainer_literal"); FunctionDecl *NSArrayFD = SynthBlockInitFunctionDecl(NSArrayFName); - DeclRefExpr *NSArrayDRE = - new (Context) DeclRefExpr(NSArrayFD, false, NSArrayFType, VK_RValue, - SourceLocation()); + DeclRefExpr *NSArrayDRE = new (Context) DeclRefExpr( + *Context, NSArrayFD, false, NSArrayFType, VK_RValue, SourceLocation()); SmallVector InitExprs; unsigned NumElements = Exp->getNumElements(); @@ -2796,8 +2795,8 @@ QualType msgSendType = MsgSendFlavor->getType(); // Create a reference to the objc_msgSend() declaration. - DeclRefExpr *DRE = new (Context) DeclRefExpr(MsgSendFlavor, false, msgSendType, - VK_LValue, SourceLocation()); + DeclRefExpr *DRE = new (Context) DeclRefExpr( + *Context, MsgSendFlavor, false, msgSendType, VK_LValue, SourceLocation()); CastExpr *cast = NoTypeInfoCStyleCastExpr(Context, Context->getPointerType(Context->VoidTy), @@ -2840,9 +2839,8 @@ getSimpleFunctionType(Context->VoidTy, IntQT, true); std::string NSDictFName("__NSContainer_literal"); FunctionDecl *NSDictFD = SynthBlockInitFunctionDecl(NSDictFName); - DeclRefExpr *NSDictDRE = - new (Context) DeclRefExpr(NSDictFD, false, NSDictFType, VK_RValue, - SourceLocation()); + DeclRefExpr *NSDictDRE = new (Context) DeclRefExpr( + *Context, NSDictFD, false, NSDictFType, VK_RValue, SourceLocation()); SmallVector KeyExprs; SmallVector ValueExprs; @@ -2950,8 +2948,8 @@ QualType msgSendType = MsgSendFlavor->getType(); // Create a reference to the objc_msgSend() declaration. - DeclRefExpr *DRE = new (Context) DeclRefExpr(MsgSendFlavor, false, msgSendType, - VK_LValue, SourceLocation()); + DeclRefExpr *DRE = new (Context) DeclRefExpr( + *Context, MsgSendFlavor, false, msgSendType, VK_LValue, SourceLocation()); CastExpr *cast = NoTypeInfoCStyleCastExpr(Context, Context->getPointerType(Context->VoidTy), @@ -3178,8 +3176,8 @@ FunctionDecl *FD = FunctionDecl::Create(*Context, TUDecl, SourceLocation(), SourceLocation(), ID, FuncType, nullptr, SC_Extern, false, false); - DeclRefExpr *DRE = new (Context) DeclRefExpr(FD, false, castType, VK_RValue, - SourceLocation()); + DeclRefExpr *DRE = new (Context) DeclRefExpr(*Context, FD, false, castType, + VK_RValue, SourceLocation()); CallExpr *STCE = new (Context) CallExpr(*Context, DRE, MsgExprs, castType, VK_LValue, SourceLocation()); @@ -3247,7 +3245,8 @@ InitExprs.push_back( NoTypeInfoCStyleCastExpr(Context, Context->getObjCIdType(), CK_BitCast, - new (Context) DeclRefExpr(CurMethodDef->getSelfDecl(), + new (Context) DeclRefExpr(*Context, + CurMethodDef->getSelfDecl(), false, Context->getObjCIdType(), VK_RValue, @@ -3278,9 +3277,9 @@ if (LangOpts.MicrosoftExt) { SynthSuperConstructorFunctionDecl(); // Simulate a constructor call... - DeclRefExpr *DRE = new (Context) DeclRefExpr(SuperConstructorFunctionDecl, - false, superType, VK_LValue, - SourceLocation()); + DeclRefExpr *DRE = new (Context) + DeclRefExpr(*Context, SuperConstructorFunctionDecl, false, superType, + VK_LValue, SourceLocation()); SuperRep = new (Context) CallExpr(*Context, DRE, InitExprs, superType, VK_LValue, SourceLocation()); @@ -3343,7 +3342,8 @@ InitExprs.push_back( NoTypeInfoCStyleCastExpr(Context, Context->getObjCIdType(), CK_BitCast, - new (Context) DeclRefExpr(CurMethodDef->getSelfDecl(), + new (Context) DeclRefExpr(*Context, + CurMethodDef->getSelfDecl(), false, Context->getObjCIdType(), VK_RValue, SourceLocation())) @@ -3373,7 +3373,8 @@ if (LangOpts.MicrosoftExt) { SynthSuperConstructorFunctionDecl(); // Simulate a constructor call... - DeclRefExpr *DRE = new (Context) DeclRefExpr(SuperConstructorFunctionDecl, + DeclRefExpr *DRE = new (Context) DeclRefExpr(*Context, + SuperConstructorFunctionDecl, false, superType, VK_LValue, SourceLocation()); SuperRep = new (Context) CallExpr(*Context, DRE, InitExprs, @@ -3517,8 +3518,8 @@ QualType msgSendType = MsgSendFlavor->getType(); // Create a reference to the objc_msgSend() declaration. - DeclRefExpr *DRE = new (Context) DeclRefExpr(MsgSendFlavor, false, msgSendType, - VK_LValue, SourceLocation()); + DeclRefExpr *DRE = new (Context) DeclRefExpr( + *Context, MsgSendFlavor, false, msgSendType, VK_LValue, SourceLocation()); // Need to cast objc_msgSend to "void *" (to workaround a GCC bandaid). // If we don't do this cast, we get the following bizarre warning/note: @@ -3595,8 +3596,8 @@ VarDecl *VD = VarDecl::Create(*Context, TUDecl, SourceLocation(), SourceLocation(), ID, getProtocolType(), nullptr, SC_Extern); - DeclRefExpr *DRE = new (Context) DeclRefExpr(VD, false, getProtocolType(), - VK_LValue, SourceLocation()); + DeclRefExpr *DRE = new (Context) DeclRefExpr( + *Context, VD, false, getProtocolType(), VK_LValue, SourceLocation()); CastExpr *castExpr = NoTypeInfoCStyleCastExpr( Context, Context->getPointerType(DRE->getType()), CK_BitCast, DRE); @@ -5285,15 +5286,15 @@ Tag += FuncName + "_block_impl_" + BlockNumber; FD = SynthBlockInitFunctionDecl(Tag); - DeclRefExpr *DRE = new (Context) DeclRefExpr(FD, false, FType, VK_RValue, - SourceLocation()); + DeclRefExpr *DRE = new (Context) + DeclRefExpr(*Context, FD, false, FType, VK_RValue, SourceLocation()); SmallVector InitExprs; // Initialize the block function. FD = SynthBlockInitFunctionDecl(Func); - DeclRefExpr *Arg = new (Context) DeclRefExpr(FD, false, FD->getType(), - VK_LValue, SourceLocation()); + DeclRefExpr *Arg = new (Context) DeclRefExpr( + *Context, FD, false, FD->getType(), VK_LValue, SourceLocation()); CastExpr *castExpr = NoTypeInfoCStyleCastExpr(Context, Context->VoidPtrTy, CK_BitCast, Arg); InitExprs.push_back(castExpr); @@ -5304,15 +5305,11 @@ VarDecl *NewVD = VarDecl::Create( *Context, TUDecl, SourceLocation(), SourceLocation(), &Context->Idents.get(DescData), Context->VoidPtrTy, nullptr, SC_Static); - UnaryOperator *DescRefExpr = - new (Context) UnaryOperator(new (Context) DeclRefExpr(NewVD, false, - Context->VoidPtrTy, - VK_LValue, - SourceLocation()), - UO_AddrOf, - Context->getPointerType(Context->VoidPtrTy), - VK_RValue, OK_Ordinary, - SourceLocation(), false); + UnaryOperator *DescRefExpr = new (Context) UnaryOperator( + new (Context) DeclRefExpr(*Context, NewVD, false, Context->VoidPtrTy, + VK_LValue, SourceLocation()), + UO_AddrOf, Context->getPointerType(Context->VoidPtrTy), VK_RValue, + OK_Ordinary, SourceLocation(), false); InitExprs.push_back(DescRefExpr); // Add initializers for any closure decl refs. @@ -5324,7 +5321,7 @@ if (isObjCType((*I)->getType())) { // FIXME: Conform to ABI ([[obj retain] autorelease]). FD = SynthBlockInitFunctionDecl((*I)->getName()); - Exp = new (Context) DeclRefExpr(FD, false, FD->getType(), + Exp = new (Context) DeclRefExpr(*Context, FD, false, FD->getType(), VK_LValue, SourceLocation()); if (HasLocalVariableExternalStorage(*I)) { QualType QT = (*I)->getType(); @@ -5335,13 +5332,13 @@ } } else if (isTopLevelBlockPointerType((*I)->getType())) { FD = SynthBlockInitFunctionDecl((*I)->getName()); - Arg = new (Context) DeclRefExpr(FD, false, FD->getType(), + Arg = new (Context) DeclRefExpr(*Context, FD, false, FD->getType(), VK_LValue, SourceLocation()); Exp = NoTypeInfoCStyleCastExpr(Context, Context->VoidPtrTy, CK_BitCast, Arg); } else { FD = SynthBlockInitFunctionDecl((*I)->getName()); - Exp = new (Context) DeclRefExpr(FD, false, FD->getType(), + Exp = new (Context) DeclRefExpr(*Context, FD, false, FD->getType(), VK_LValue, SourceLocation()); if (HasLocalVariableExternalStorage(*I)) { QualType QT = (*I)->getType(); @@ -5370,8 +5367,8 @@ QualType castT = Context->getPointerType(Context->getTagDeclType(RD)); FD = SynthBlockInitFunctionDecl((*I)->getName()); - Exp = new (Context) DeclRefExpr(FD, false, FD->getType(), VK_LValue, - SourceLocation()); + Exp = new (Context) DeclRefExpr(*Context, FD, false, FD->getType(), + VK_LValue, SourceLocation()); bool isNestedCapturedVar = false; if (block) for (const auto &CI : block->captures()) { @@ -7497,9 +7494,9 @@ SourceLocation(), &Context->Idents.get(IvarOffsetName), Context->UnsignedLongTy, nullptr, SC_Extern); - DeclRefExpr *DRE = new (Context) DeclRefExpr(NewVD, false, - Context->UnsignedLongTy, VK_LValue, - SourceLocation()); + DeclRefExpr *DRE = new (Context) + DeclRefExpr(*Context, NewVD, false, Context->UnsignedLongTy, + VK_LValue, SourceLocation()); BinaryOperator *addExpr = new (Context) BinaryOperator(castExpr, DRE, BO_Add, Context->getPointerType(Context->CharTy), Index: lib/Frontend/Rewrite/RewriteObjC.cpp =================================================================== --- lib/Frontend/Rewrite/RewriteObjC.cpp +++ lib/Frontend/Rewrite/RewriteObjC.cpp @@ -2009,7 +2009,7 @@ QualType msgSendType = FD->getType(); // Create a reference to the objc_msgSend() declaration. - DeclRefExpr *DRE = new (Context) DeclRefExpr(FD, false, msgSendType, + DeclRefExpr *DRE = new (Context) DeclRefExpr(*Context, FD, false, msgSendType, VK_LValue, SourceLocation()); // Now, we cast the reference to a pointer to the objc_msgSend type. @@ -2506,8 +2506,8 @@ VarDecl *NewVD = VarDecl::Create(*Context, TUDecl, SourceLocation(), SourceLocation(), &Context->Idents.get(S), strType, nullptr, SC_Static); - DeclRefExpr *DRE = new (Context) DeclRefExpr(NewVD, false, strType, VK_LValue, - SourceLocation()); + DeclRefExpr *DRE = new (Context) DeclRefExpr(*Context, NewVD, false, strType, + VK_LValue, SourceLocation()); Expr *Unop = new (Context) UnaryOperator(DRE, UO_AddrOf, Context->getPointerType(DRE->getType()), VK_RValue, OK_Ordinary, @@ -2589,7 +2589,7 @@ SmallVectorImpl &MsgExprs, ObjCMethodDecl *Method) { // Create a reference to the objc_msgSend_stret() declaration. - DeclRefExpr *STDRE = new (Context) DeclRefExpr(MsgSendStretFlavor, + DeclRefExpr *STDRE = new (Context) DeclRefExpr(*Context, MsgSendStretFlavor, false, msgSendType, VK_LValue, SourceLocation()); // Need to cast objc_msgSend_stret to "void *" (see above comment). @@ -2664,7 +2664,8 @@ InitExprs.push_back( NoTypeInfoCStyleCastExpr(Context, Context->getObjCIdType(), CK_BitCast, - new (Context) DeclRefExpr(CurMethodDef->getSelfDecl(), + new (Context) DeclRefExpr(*Context, + CurMethodDef->getSelfDecl(), false, Context->getObjCIdType(), VK_RValue, @@ -2697,9 +2698,9 @@ if (LangOpts.MicrosoftExt) { SynthSuperConstructorFunctionDecl(); // Simulate a constructor call... - DeclRefExpr *DRE = new (Context) DeclRefExpr(SuperConstructorFunctionDecl, - false, superType, VK_LValue, - SourceLocation()); + DeclRefExpr *DRE = new (Context) + DeclRefExpr(*Context, SuperConstructorFunctionDecl, false, superType, + VK_LValue, SourceLocation()); SuperRep = new (Context) CallExpr(*Context, DRE, InitExprs, superType, VK_LValue, SourceLocation()); @@ -2759,7 +2760,8 @@ InitExprs.push_back( NoTypeInfoCStyleCastExpr(Context, Context->getObjCIdType(), CK_BitCast, - new (Context) DeclRefExpr(CurMethodDef->getSelfDecl(), + new (Context) DeclRefExpr(*Context, + CurMethodDef->getSelfDecl(), false, Context->getObjCIdType(), VK_RValue, SourceLocation())) @@ -2792,9 +2794,9 @@ if (LangOpts.MicrosoftExt) { SynthSuperConstructorFunctionDecl(); // Simulate a constructor call... - DeclRefExpr *DRE = new (Context) DeclRefExpr(SuperConstructorFunctionDecl, - false, superType, VK_LValue, - SourceLocation()); + DeclRefExpr *DRE = new (Context) + DeclRefExpr(*Context, SuperConstructorFunctionDecl, false, superType, + VK_LValue, SourceLocation()); SuperRep = new (Context) CallExpr(*Context, DRE, InitExprs, superType, VK_LValue, SourceLocation()); // The code for super is a little tricky to prevent collision with @@ -2936,8 +2938,8 @@ QualType msgSendType = MsgSendFlavor->getType(); // Create a reference to the objc_msgSend() declaration. - DeclRefExpr *DRE = new (Context) DeclRefExpr(MsgSendFlavor, false, msgSendType, - VK_LValue, SourceLocation()); + DeclRefExpr *DRE = new (Context) DeclRefExpr( + *Context, MsgSendFlavor, false, msgSendType, VK_LValue, SourceLocation()); // Need to cast objc_msgSend to "void *" (to workaround a GCC bandaid). // If we don't do this cast, we get the following bizarre warning/note: @@ -3041,8 +3043,8 @@ VarDecl *VD = VarDecl::Create(*Context, TUDecl, SourceLocation(), SourceLocation(), ID, getProtocolType(), nullptr, SC_Extern); - DeclRefExpr *DRE = new (Context) DeclRefExpr(VD, false, getProtocolType(), - VK_LValue, SourceLocation()); + DeclRefExpr *DRE = new (Context) DeclRefExpr( + *Context, VD, false, getProtocolType(), VK_LValue, SourceLocation()); Expr *DerefExpr = new (Context) UnaryOperator(DRE, UO_AddrOf, Context->getPointerType(DRE->getType()), VK_RValue, OK_Ordinary, SourceLocation(), false); @@ -4411,15 +4413,15 @@ // Simulate a constructor call... FD = SynthBlockInitFunctionDecl(Tag); - DeclRefExpr *DRE = new (Context) DeclRefExpr(FD, false, FType, VK_RValue, - SourceLocation()); + DeclRefExpr *DRE = new (Context) + DeclRefExpr(*Context, FD, false, FType, VK_RValue, SourceLocation()); SmallVector InitExprs; // Initialize the block function. FD = SynthBlockInitFunctionDecl(Func); - DeclRefExpr *Arg = new (Context) DeclRefExpr(FD, false, FD->getType(), - VK_LValue, SourceLocation()); + DeclRefExpr *Arg = new (Context) DeclRefExpr( + *Context, FD, false, FD->getType(), VK_LValue, SourceLocation()); CastExpr *castExpr = NoTypeInfoCStyleCastExpr(Context, Context->VoidPtrTy, CK_BitCast, Arg); InitExprs.push_back(castExpr); @@ -4430,15 +4432,11 @@ VarDecl *NewVD = VarDecl::Create( *Context, TUDecl, SourceLocation(), SourceLocation(), &Context->Idents.get(DescData), Context->VoidPtrTy, nullptr, SC_Static); - UnaryOperator *DescRefExpr = - new (Context) UnaryOperator(new (Context) DeclRefExpr(NewVD, false, - Context->VoidPtrTy, - VK_LValue, - SourceLocation()), - UO_AddrOf, - Context->getPointerType(Context->VoidPtrTy), - VK_RValue, OK_Ordinary, - SourceLocation(), false); + UnaryOperator *DescRefExpr = new (Context) UnaryOperator( + new (Context) DeclRefExpr(*Context, NewVD, false, Context->VoidPtrTy, + VK_LValue, SourceLocation()), + UO_AddrOf, Context->getPointerType(Context->VoidPtrTy), VK_RValue, + OK_Ordinary, SourceLocation(), false); InitExprs.push_back(DescRefExpr); // Add initializers for any closure decl refs. @@ -4450,8 +4448,8 @@ if (isObjCType((*I)->getType())) { // FIXME: Conform to ABI ([[obj retain] autorelease]). FD = SynthBlockInitFunctionDecl((*I)->getName()); - Exp = new (Context) DeclRefExpr(FD, false, FD->getType(), VK_LValue, - SourceLocation()); + Exp = new (Context) DeclRefExpr(*Context, FD, false, FD->getType(), + VK_LValue, SourceLocation()); if (HasLocalVariableExternalStorage(*I)) { QualType QT = (*I)->getType(); QT = Context->getPointerType(QT); @@ -4461,14 +4459,14 @@ } } else if (isTopLevelBlockPointerType((*I)->getType())) { FD = SynthBlockInitFunctionDecl((*I)->getName()); - Arg = new (Context) DeclRefExpr(FD, false, FD->getType(), VK_LValue, - SourceLocation()); + Arg = new (Context) DeclRefExpr(*Context, FD, false, FD->getType(), + VK_LValue, SourceLocation()); Exp = NoTypeInfoCStyleCastExpr(Context, Context->VoidPtrTy, CK_BitCast, Arg); } else { FD = SynthBlockInitFunctionDecl((*I)->getName()); - Exp = new (Context) DeclRefExpr(FD, false, FD->getType(), VK_LValue, - SourceLocation()); + Exp = new (Context) DeclRefExpr(*Context, FD, false, FD->getType(), + VK_LValue, SourceLocation()); if (HasLocalVariableExternalStorage(*I)) { QualType QT = (*I)->getType(); QT = Context->getPointerType(QT); @@ -4495,8 +4493,8 @@ QualType castT = Context->getPointerType(Context->getTagDeclType(RD)); FD = SynthBlockInitFunctionDecl((*I)->getName()); - Exp = new (Context) DeclRefExpr(FD, false, FD->getType(), VK_LValue, - SourceLocation()); + Exp = new (Context) DeclRefExpr(*Context, FD, false, FD->getType(), + VK_LValue, SourceLocation()); bool isNestedCapturedVar = false; if (block) for (const auto &CI : block->captures()) { Index: lib/Sema/Sema.cpp =================================================================== --- lib/Sema/Sema.cpp +++ lib/Sema/Sema.cpp @@ -1415,7 +1415,8 @@ EnterExpressionEvaluationContext scope( S, Sema::ExpressionEvaluationContext::PotentiallyEvaluated); SourceLocation Loc = VD->getLocation(); - Expr *VarRef = new (S.Context) DeclRefExpr(VD, false, T, VK_LValue, Loc); + Expr *VarRef = + new (S.Context) DeclRefExpr(S.Context, VD, false, T, VK_LValue, Loc); ExprResult Result = S.PerformMoveOrCopyInitialization( InitializedEntity::InitializeBlock(Loc, T, false), VD, VD->getType(), VarRef, /*AllowNRVO=*/true); Index: lib/Sema/SemaCUDA.cpp =================================================================== --- lib/Sema/SemaCUDA.cpp +++ lib/Sema/SemaCUDA.cpp @@ -48,7 +48,7 @@ QualType ConfigQTy = ConfigDecl->getType(); DeclRefExpr *ConfigDR = new (Context) - DeclRefExpr(ConfigDecl, false, ConfigQTy, VK_LValue, LLLLoc); + DeclRefExpr(Context, ConfigDecl, false, ConfigQTy, VK_LValue, LLLLoc); MarkFunctionReferenced(LLLLoc, ConfigDecl); return ActOnCallExpr(S, ConfigDR, LLLLoc, ExecConfig, GGGLoc, nullptr, Index: lib/Sema/SemaExpr.cpp =================================================================== --- lib/Sema/SemaExpr.cpp +++ lib/Sema/SemaExpr.cpp @@ -14914,9 +14914,8 @@ // According to the blocks spec, the capture of a variable from // the stack requires a const copy constructor. This is not true // of the copy/move done to move a __block variable to the heap. - Expr *DeclRef = new (S.Context) DeclRefExpr(Var, Nested, - DeclRefType.withConst(), - VK_LValue, Loc); + Expr *DeclRef = new (S.Context) DeclRefExpr( + S.Context, Var, Nested, DeclRefType.withConst(), VK_LValue, Loc); ExprResult Result = S.PerformCopyInitialization( @@ -14992,8 +14991,8 @@ if (S.getLangOpts().OpenMP && RSI->CapRegionKind == CR_OpenMP) S.setOpenMPCaptureKind(Field, Var, RSI->OpenMPLevel); - CopyExpr = new (S.Context) DeclRefExpr(Var, RefersToCapturedVariable, - DeclRefType, VK_LValue, Loc); + CopyExpr = new (S.Context) DeclRefExpr( + S.Context, Var, RefersToCapturedVariable, DeclRefType, VK_LValue, Loc); Var->setReferenced(true); Var->markUsed(S.Context); } Index: lib/Sema/SemaObjCProperty.cpp =================================================================== --- lib/Sema/SemaObjCProperty.cpp +++ lib/Sema/SemaObjCProperty.cpp @@ -1413,7 +1413,7 @@ SynthesizedFunctionScope Scope(*this, getterMethod); ImplicitParamDecl *SelfDecl = getterMethod->getSelfDecl(); DeclRefExpr *SelfExpr = - new (Context) DeclRefExpr(SelfDecl, false, SelfDecl->getType(), + new (Context) DeclRefExpr(Context, SelfDecl, false, SelfDecl->getType(), VK_LValue, PropertyDiagLoc); MarkDeclRefReferenced(SelfExpr); Expr *LoadSelfExpr = @@ -1465,7 +1465,7 @@ SynthesizedFunctionScope Scope(*this, setterMethod); ImplicitParamDecl *SelfDecl = setterMethod->getSelfDecl(); DeclRefExpr *SelfExpr = - new (Context) DeclRefExpr(SelfDecl, false, SelfDecl->getType(), + new (Context) DeclRefExpr(Context, SelfDecl, false, SelfDecl->getType(), VK_LValue, PropertyDiagLoc); MarkDeclRefReferenced(SelfExpr); Expr *LoadSelfExpr = @@ -1481,7 +1481,7 @@ ObjCMethodDecl::param_iterator P = setterMethod->param_begin(); ParmVarDecl *Param = (*P); QualType T = Param->getType().getNonReferenceType(); - DeclRefExpr *rhs = new (Context) DeclRefExpr(Param, false, T, + DeclRefExpr *rhs = new (Context) DeclRefExpr(Context, Param, false, T, VK_LValue, PropertyDiagLoc); MarkDeclRefReferenced(rhs); ExprResult Res = BuildBinOp(S, PropertyDiagLoc, Index: lib/Sema/SemaOverload.cpp =================================================================== --- lib/Sema/SemaOverload.cpp +++ lib/Sema/SemaOverload.cpp @@ -63,8 +63,8 @@ return ExprError(); if (auto *FPT = Fn->getType()->getAs()) S.ResolveExceptionSpec(Loc, FPT); - DeclRefExpr *DRE = new (S.Context) DeclRefExpr(Fn, false, Fn->getType(), - VK_LValue, Loc, LocInfo); + DeclRefExpr *DRE = new (S.Context) + DeclRefExpr(S.Context, Fn, false, Fn->getType(), VK_LValue, Loc, LocInfo); if (HadMultipleCandidates) DRE->setHadMultipleCandidates(true); @@ -6968,8 +6968,8 @@ // lvalues/rvalues and the type. Fortunately, we can allocate this // call on the stack and we don't need its arguments to be // well-formed. - DeclRefExpr ConversionRef(Conversion, false, Conversion->getType(), VK_LValue, - From->getBeginLoc()); + DeclRefExpr ConversionRef(Context, Conversion, false, Conversion->getType(), + VK_LValue, From->getBeginLoc()); ImplicitCastExpr ConversionFn(ImplicitCastExpr::OnStack, Context.getPointerType(Conversion->getType()), CK_FunctionToPointerDecay, Index: lib/Sema/TreeTransform.h =================================================================== --- lib/Sema/TreeTransform.h +++ lib/Sema/TreeTransform.h @@ -3130,9 +3130,9 @@ // Build a reference to the __builtin_shufflevector builtin FunctionDecl *Builtin = cast(Lookup.front()); - Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false, - SemaRef.Context.BuiltinFnTy, - VK_RValue, BuiltinLoc); + Expr *Callee = new (SemaRef.Context) + DeclRefExpr(SemaRef.Context, Builtin, false, + SemaRef.Context.BuiltinFnTy, VK_RValue, BuiltinLoc); QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType()); Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy, CK_BuiltinFnToFnPtr).get();