llvmorg-github-actions[bot] wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang-codegen

Author: Jameson Nash (vtjnash)

<details>
<summary>Changes</summary>

Reapply #<!-- -->197745, with an additional commit to undo a small part of the 
first commit, pending further analysis of alternatives to that part of it.

In particular, make the `agg.tmp` (CreateAggTemp) values keep using the 
declared expression type of the RValue. This is indeed probably sensible, since 
it lets Sema influence this via the expression type, though it runs into some 
issues where some expression types (notably for any load) haven't had one of 
the equivalent functions getNonLValueExprType/DeduceAutoType/getUnqualifiedType 
called on them, so they are bringing along additional annotation baggage which 
doesn't apply the the rvalue when turned into a temporary (see comments in 
getNonLValueExprType for relevant part of C++ standard). This in turn is also 
rarely relevant, since inventing temporaries aren't often allowed in this part 
of the pipeline (it'd require a move constructor) so the LValue Dest already 
provides the type and the RValue type is ignored. However, it does affect a 
single test (which loads a global but ignores the result) and so this adds an 
extra `getUnqualifiedType` call to `CodeGenFunction::EmitAnyExpr` so that load 
doesn't propagate the qualifiers from source to temporary.

---

Patch is 458.88 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/200427.diff


39 Files Affected:

- (modified) clang/lib/CodeGen/ABIInfoImpl.cpp (+1-1) 
- (modified) clang/lib/CodeGen/CGAtomic.cpp (+4-4) 
- (modified) clang/lib/CodeGen/CGBlocks.cpp (+4-3) 
- (modified) clang/lib/CodeGen/CGBuiltin.cpp (+4-12) 
- (modified) clang/lib/CodeGen/CGCUDANV.cpp (+4-4) 
- (modified) clang/lib/CodeGen/CGCall.cpp (+22-18) 
- (modified) clang/lib/CodeGen/CGClass.cpp (+1-1) 
- (modified) clang/lib/CodeGen/CGDecl.cpp (+4-3) 
- (modified) clang/lib/CodeGen/CGException.cpp (+2-2) 
- (modified) clang/lib/CodeGen/CGExpr.cpp (+6-6) 
- (modified) clang/lib/CodeGen/CGExprAgg.cpp (+1-1) 
- (modified) clang/lib/CodeGen/CGHLSLRuntime.cpp (+6-11) 
- (modified) clang/lib/CodeGen/CGOpenMPRuntime.cpp (+14-12) 
- (modified) clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp (+2-2) 
- (modified) clang/lib/CodeGen/CGStmt.cpp (+1-1) 
- (modified) clang/lib/CodeGen/CGStmtOpenMP.cpp (+12-12) 
- (modified) clang/lib/CodeGen/CodeGenFunction.h (+6-3) 
- (modified) clang/lib/CodeGen/MicrosoftCXXABI.cpp (+1-1) 
- (modified) clang/lib/CodeGen/TargetBuiltins/ARM.cpp (+2-2) 
- (modified) clang/lib/CodeGen/TargetBuiltins/X86.cpp (+2-2) 
- (modified) clang/lib/CodeGen/Targets/X86.cpp (+4-4) 
- (modified) clang/test/CodeGen/scoped-atomic-ops.c (+568-852) 
- (modified) clang/test/CodeGenCUDA/amdgpu-kernel-arg-pointer-type.cu (+95-103) 
- (modified) clang/test/CodeGenCUDA/atomic-options.hip (+144-216) 
- (modified) clang/test/CodeGenCUDA/builtins-amdgcn.cu (+18-27) 
- (modified) clang/test/CodeGenCUDA/builtins-spirv-amdgcn.cu (+36-54) 
- (modified) clang/test/CodeGenCUDA/record-layout.cu (+3-4) 
- (modified) clang/test/CodeGenCXX/amdgcn-func-arg.cpp (+56-31) 
- (modified) clang/test/CodeGenHIP/placement-new-addrspace.hip (+2-3) 
- (modified) clang/test/CodeGenOpenCL/addr-space-struct-arg.cl (+8-12) 
- (modified) clang/test/CodeGenOpenCL/amdgpu-abi-struct-arg-byref.cl (+8-12) 
- (modified) clang/test/CodeGenOpenCL/amdgpu-enqueue-kernel.cl (-2) 
- (modified) clang/test/CodeGenOpenCL/atomic-ops.cl (+2-3) 
- (modified) clang/test/CodeGenSYCL/kernel-caller-entry-point.cpp (+34-35) 
- (modified) clang/test/OpenMP/amdgcn_target_device_vla.cpp (+19-24) 
- (modified) clang/test/OpenMP/amdgpu_target_with_aligned_attribute.c (+7-9) 
- (modified) clang/test/OpenMP/target_teams_generic_loop_codegen.cpp (+7-9) 
- (modified) 
clang/test/OpenMP/target_teams_generic_loop_codegen_as_distribute.cpp (+5-6) 
- (modified) 
clang/test/OpenMP/target_teams_generic_loop_codegen_as_parallel_for.cpp 
(+32-42) 


``````````diff
diff --git a/clang/lib/CodeGen/ABIInfoImpl.cpp 
b/clang/lib/CodeGen/ABIInfoImpl.cpp
index 8ad77ee515d49..887a645a4783a 100644
--- a/clang/lib/CodeGen/ABIInfoImpl.cpp
+++ b/clang/lib/CodeGen/ABIInfoImpl.cpp
@@ -442,7 +442,7 @@ Address CodeGen::EmitVAArgInstr(CodeGenFunction &CGF, 
Address VAListAddr,
     assert(!AI.getCoerceToType() &&
            "Unexpected CoerceToType seen in arginfo in generic VAArg 
emitter!");
 
-    Address Temp = CGF.CreateMemTemp(Ty, "varet");
+    Address Temp = CGF.CreateMemTempWithoutCast(Ty, "varet");
     Val = CGF.Builder.CreateVAArg(VAListAddr.emitRawPointer(CGF),
                                   CGF.ConvertTypeForMem(Ty));
     CGF.Builder.CreateStore(Val, Temp);
diff --git a/clang/lib/CodeGen/CGAtomic.cpp b/clang/lib/CodeGen/CGAtomic.cpp
index b4fd0fdb795aa..270965b109943 100644
--- a/clang/lib/CodeGen/CGAtomic.cpp
+++ b/clang/lib/CodeGen/CGAtomic.cpp
@@ -304,7 +304,7 @@ Address AtomicInfo::CreateTempAlloca() const {
                        ? ValueTy
                        : AtomicTy.getUnqualifiedType();
   Address TempAlloca =
-      CGF.CreateMemTemp(TmpTy, getAtomicAlignment(), "atomic-temp");
+      CGF.CreateMemTempWithoutCast(TmpTy, getAtomicAlignment(), "atomic-temp");
   // Cast to pointer to value type for bitfields.
   if (LVal.isBitField())
     return CGF.Builder.CreatePointerBitCastOrAddrSpaceCast(
@@ -826,7 +826,7 @@ static void EmitAtomicOp(CodeGenFunction &CGF, AtomicExpr 
*E, Address Dest,
 // into a temporary alloca.
 static Address
 EmitValToTemp(CodeGenFunction &CGF, Expr *E) {
-  Address DeclPtr = CGF.CreateMemTemp(E->getType(), ".atomictmp");
+  Address DeclPtr = CGF.CreateMemTempWithoutCast(E->getType(), ".atomictmp");
   CGF.EmitAnyExprToMem(E, DeclPtr, E->getType().getQualifiers(),
                        /*Init*/ true);
   return DeclPtr;
@@ -1025,7 +1025,7 @@ RValue CodeGenFunction::EmitAtomicExpr(AtomicExpr *E) {
       CharUnits PointeeIncAmt =
           getContext().getTypeSizeInChars(MemTy->getPointeeType());
       Val1Scalar = Builder.CreateMul(Val1Scalar, CGM.getSize(PointeeIncAmt));
-      auto Temp = CreateMemTemp(Val1Ty, ".atomictmp");
+      auto Temp = CreateMemTempWithoutCast(Val1Ty, ".atomictmp");
       Val1 = Temp;
       EmitStoreOfScalar(Val1Scalar, MakeAddrLValue(Temp, Val1Ty));
       break;
@@ -1121,7 +1121,7 @@ RValue CodeGenFunction::EmitAtomicExpr(AtomicExpr *E) {
     if (ShouldCastToIntPtrTy)
       Dest = Atomics.castToAtomicIntPointer(Dest);
   } else if (E->isCmpXChg())
-    Dest = CreateMemTemp(RValTy, "cmpxchg.bool");
+    Dest = CreateMemTempWithoutCast(RValTy, "cmpxchg.bool");
   else if (!RValTy->isVoidType()) {
     Dest = Atomics.CreateTempAlloca();
     if (ShouldCastToIntPtrTy)
diff --git a/clang/lib/CodeGen/CGBlocks.cpp b/clang/lib/CodeGen/CGBlocks.cpp
index 1ce22df11e6a7..0683a4937cf37 100644
--- a/clang/lib/CodeGen/CGBlocks.cpp
+++ b/clang/lib/CodeGen/CGBlocks.cpp
@@ -1418,7 +1418,8 @@ void CodeGenFunction::setBlockContextParameter(const 
ImplicitParamDecl *D,
 
   // Allocate a stack slot like for any local variable to guarantee optimal
   // debug info at -O0. The mem2reg pass will eliminate it when optimizing.
-  RawAddress alloc = CreateMemTemp(D->getType(), D->getName() + ".addr");
+  RawAddress alloc =
+      CreateMemTempWithoutCast(D->getType(), D->getName() + ".addr");
   Builder.CreateStore(arg, alloc);
   if (CGDebugInfo *DI = getDebugInfo()) {
     if (CGM.getCodeGenOpts().hasReducedDebugInfo()) {
@@ -1557,8 +1558,8 @@ llvm::Function *CodeGenFunction::GenerateBlockFunction(
     if (!capture.isConstant()) continue;
 
     CharUnits align = getContext().getDeclAlign(variable);
-    Address alloca =
-      CreateMemTemp(variable->getType(), align, "block.captured-const");
+    Address alloca = CreateMemTempWithoutCast(variable->getType(), align,
+                                              "block.captured-const");
 
     Builder.CreateStore(capture.getConstant(), alloca);
 
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 9ceda41c69da5..52ec4e98c00f5 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -2276,10 +2276,9 @@ RValue CodeGenFunction::emitBuiltinOSLogFormat(const 
CallExpr &E) {
         if (!isa<Constant>(ArgVal)) {
           CleanupKind Cleanup = getARCCleanupKind();
           QualType Ty = TheExpr->getType();
-          RawAddress Alloca = RawAddress::invalid();
-          RawAddress Addr = CreateMemTemp(Ty, "os.log.arg", &Alloca);
+          RawAddress Alloca = CreateMemTempWithoutCast(Ty, "os.log.arg");
           ArgVal = EmitARCRetain(Ty, ArgVal);
-          Builder.CreateStore(ArgVal, Addr);
+          Builder.CreateStore(ArgVal, Alloca);
           pushLifetimeExtendedDestroy(Cleanup, Alloca, Ty,
                                       CodeGenFunction::destroyARCStrongPrecise,
                                       Cleanup & EHCleanup);
@@ -6693,13 +6692,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
           getContext().getSizeType(), ArraySize, nullptr,
           ArraySizeModifier::Normal,
           /*IndexTypeQuals=*/0);
-      auto Tmp = CreateMemTemp(SizeArrayTy, "block_sizes");
-      llvm::Value *TmpPtr = Tmp.getPointer();
-      // The EmitLifetime* pair expect a naked Alloca as their last argument,
-      // however for cases where the default AS is not the Alloca AS, Tmp is
-      // actually the Alloca ascasted to the default AS, hence the
-      // stripPointerCasts()
-      llvm::Value *Alloca = TmpPtr->stripPointerCasts();
+      auto Tmp = CreateMemTempWithoutCast(SizeArrayTy, "block_sizes");
+      llvm::Value *Alloca = Tmp.getPointer();
       llvm::Value *ElemPtr;
       EmitLifetimeStart(Alloca);
       // Each of the following arguments specifies the size of the 
corresponding
@@ -6716,8 +6710,6 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
         Builder.CreateAlignedStore(
             V, GEP, CGM.getDataLayout().getPrefTypeAlign(SizeTy));
       }
-      // Return the Alloca itself rather than a potential ascast as this is 
only
-      // used by the paired EmitLifetimeEnd.
       return {ElemPtr, Alloca};
     };
 
diff --git a/clang/lib/CodeGen/CGCUDANV.cpp b/clang/lib/CodeGen/CGCUDANV.cpp
index a727a006969d8..292db6665b8e8 100644
--- a/clang/lib/CodeGen/CGCUDANV.cpp
+++ b/clang/lib/CodeGen/CGCUDANV.cpp
@@ -447,10 +447,10 @@ void 
CGNVCUDARuntime::emitDeviceStubBodyNew(CodeGenFunction &CGF,
   // Create temporary dim3 grid_dim, block_dim.
   ParmVarDecl *GridDimParam = cudaLaunchKernelFD->getParamDecl(1);
   QualType Dim3Ty = GridDimParam->getType();
-  Address GridDim =
-      CGF.CreateMemTemp(Dim3Ty, CharUnits::fromQuantity(8), "grid_dim");
-  Address BlockDim =
-      CGF.CreateMemTemp(Dim3Ty, CharUnits::fromQuantity(8), "block_dim");
+  Address GridDim = CGF.CreateMemTempWithoutCast(
+      Dim3Ty, CharUnits::fromQuantity(8), "grid_dim");
+  Address BlockDim = CGF.CreateMemTempWithoutCast(
+      Dim3Ty, CharUnits::fromQuantity(8), "block_dim");
   Address ShmemSize = CGF.CreateTempAlloca(SizeTy, LangAS::Default,
                                            CGM.getSizeAlign(), "shmem_size");
   Address Stream = CGF.CreateTempAlloca(PtrTy, LangAS::Default,
diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index 2468394929360..40cc275d40273 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -3373,7 +3373,7 @@ void CodeGenFunction::EmitFunctionProlog(const 
CGFunctionInfo &FI,
         // may be aliased, copy it to ensure that the parameter variable is
         // mutable and has a unique adress, as C requires.
         if (ArgI.getIndirectRealign() || ArgI.isIndirectAliased()) {
-          RawAddress AlignedTemp = CreateMemTemp(Ty, "coerce");
+          RawAddress AlignedTemp = CreateMemTempWithoutCast(Ty, "coerce");
 
           // Copy from the incoming argument pointer to the temporary with the
           // appropriate alignment.
@@ -3503,8 +3503,8 @@ void CodeGenFunction::EmitFunctionProlog(const 
CGFunctionInfo &FI,
             ParameterABI::SwiftErrorResult) {
           QualType pointeeTy = Ty->getPointeeType();
           assert(pointeeTy->isPointerType());
-          RawAddress temp =
-              CreateMemTemp(pointeeTy, getPointerAlign(), "swifterror.temp");
+          RawAddress temp = CreateMemTempWithoutCast(
+              pointeeTy, getPointerAlign(), "swifterror.temp");
           Address arg = makeNaturalAddressForPointer(
               V, pointeeTy, getContext().getTypeAlignInChars(pointeeTy));
           llvm::Value *incomingErrorValue = Builder.CreateLoad(arg);
@@ -3556,8 +3556,8 @@ void CodeGenFunction::EmitFunctionProlog(const 
CGFunctionInfo &FI,
 
       llvm::StructType *STy =
           dyn_cast<llvm::StructType>(ArgI.getCoerceToType());
-      Address Alloca =
-          CreateMemTemp(Ty, getContext().getDeclAlign(Arg), Arg->getName());
+      Address Alloca = CreateMemTempWithoutCast(
+          Ty, getContext().getDeclAlign(Arg), Arg->getName());
 
       // Pointer to store into.
       Address Ptr = emitAddressAtOffset(*this, Alloca, ArgI);
@@ -3646,7 +3646,8 @@ void CodeGenFunction::EmitFunctionProlog(const 
CGFunctionInfo &FI,
 
     case ABIArgInfo::CoerceAndExpand: {
       // Reconstruct into a temporary.
-      Address alloca = CreateMemTemp(Ty, getContext().getDeclAlign(Arg));
+      Address alloca =
+          CreateMemTempWithoutCast(Ty, getContext().getDeclAlign(Arg));
       ArgVals.push_back(ParamValue::forIndirect(alloca));
 
       auto coercionType = ArgI.getCoerceAndExpandType();
@@ -3687,7 +3688,8 @@ void CodeGenFunction::EmitFunctionProlog(const 
CGFunctionInfo &FI,
       // If this structure was expanded into multiple arguments then
       // we need to create a temporary and reconstruct it from the
       // arguments.
-      Address Alloca = CreateMemTemp(Ty, getContext().getDeclAlign(Arg));
+      Address Alloca =
+          CreateMemTempWithoutCast(Ty, getContext().getDeclAlign(Arg));
       LValue LV = MakeAddrLValue(Alloca, Ty);
       ArgVals.push_back(ParamValue::forIndirect(Alloca));
 
@@ -3704,8 +3706,8 @@ void CodeGenFunction::EmitFunctionProlog(const 
CGFunctionInfo &FI,
     case ABIArgInfo::TargetSpecific: {
       auto *AI = Fn->getArg(FirstIRArg);
       AI->setName(Arg->getName() + ".target_coerce");
-      Address Alloca =
-          CreateMemTemp(Ty, getContext().getDeclAlign(Arg), Arg->getName());
+      Address Alloca = CreateMemTempWithoutCast(
+          Ty, getContext().getDeclAlign(Arg), Arg->getName());
       Address Ptr = emitAddressAtOffset(*this, Alloca, ArgI);
       CGM.getABIInfo().createCoercedStore(AI, Ptr, ArgI, false, *this);
       if (CodeGenFunction::hasScalarEvaluationKind(Ty)) {
@@ -3724,7 +3726,8 @@ void CodeGenFunction::EmitFunctionProlog(const 
CGFunctionInfo &FI,
       assert(NumIRArgs == 0);
       // Initialize the local variable appropriately.
       if (!hasScalarEvaluationKind(Ty)) {
-        ArgVals.push_back(ParamValue::forIndirect(CreateMemTemp(Ty)));
+        ArgVals.push_back(
+            ParamValue::forIndirect(CreateMemTempWithoutCast(Ty)));
       } else {
         llvm::Value *U = llvm::UndefValue::get(ConvertType(Arg->getType()));
         ArgVals.push_back(ParamValue::forDirect(U));
@@ -5031,7 +5034,7 @@ struct DestroyUnpassedArg final : EHScopeStack::Cleanup {
 RValue CallArg::getRValue(CodeGenFunction &CGF) const {
   if (!HasLV)
     return RV;
-  LValue Copy = CGF.MakeAddrLValue(CGF.CreateMemTemp(Ty), Ty);
+  LValue Copy = CGF.MakeAddrLValue(CGF.CreateMemTempWithoutCast(Ty), Ty);
   CGF.EmitAggregateCopy(Copy, LV, Ty, AggValueSlot::DoesNotOverlap,
                         LV.isVolatile());
   IsUsed = true;
@@ -5610,7 +5613,8 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo 
&CallInfo,
           // For indirect things such as overaligned structs, replace the
           // placeholder with a regular aggregate temporary alloca. Store the
           // address of this alloca into the struct.
-          Addr = CreateMemTemp(info_it->type, "inalloca.indirect.tmp");
+          Addr =
+              CreateMemTempWithoutCast(info_it->type, "inalloca.indirect.tmp");
           Address ArgSlot = Builder.CreateStructGEP(
               ArgMemory, ArgInfo.getInAllocaFieldIndex());
           Builder.CreateStore(Addr.getPointer(), ArgSlot);
@@ -5755,8 +5759,8 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo 
&CallInfo,
           swiftErrorArg = makeNaturalAddressForPointer(
               V, pointeeTy, getContext().getTypeAlignInChars(pointeeTy));
 
-          swiftErrorTemp =
-              CreateMemTemp(pointeeTy, getPointerAlign(), "swifterror.temp");
+          swiftErrorTemp = CreateMemTempWithoutCast(
+              pointeeTy, getPointerAlign(), "swifterror.temp");
           V = swiftErrorTemp.getPointer();
           cast<llvm::AllocaInst>(V)->setSwiftError(true);
 
@@ -5791,7 +5795,7 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo 
&CallInfo,
       // FIXME: Avoid the conversion through memory if possible.
       Address Src = Address::invalid();
       if (!I->isAggregate()) {
-        Src = CreateMemTemp(I->Ty, "coerce");
+        Src = CreateMemTempWithoutCast(I->Ty, "coerce");
         I->copyInto(*this, Src);
       } else {
         Src = I->hasLValue() ? I->getKnownLValue().getAddress()
@@ -5948,7 +5952,7 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo 
&CallInfo,
     case ABIArgInfo::TargetSpecific: {
       Address Src = Address::invalid();
       if (!I->isAggregate()) {
-        Src = CreateMemTemp(I->Ty, "target_coerce");
+        Src = CreateMemTempWithoutCast(I->Ty, "target_coerce");
         I->copyInto(*this, Src);
       } else {
         Src = I->hasLValue() ? I->getKnownLValue().getAddress()
@@ -6484,7 +6488,7 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo 
&CallInfo,
             getContext().getTypeInfoDataSizeInChars(RetTy).Width.getQuantity();
 
         if (!DestPtr.isValid()) {
-          DestPtr = CreateMemTemp(RetTy, "coerce");
+          DestPtr = CreateMemTempWithoutCast(RetTy, "coerce");
           DestIsVolatile = false;
           DestSize = getContext().getTypeSizeInChars(RetTy).getQuantity();
         }
@@ -6509,7 +6513,7 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo 
&CallInfo,
         Address StorePtr = emitAddressAtOffset(*this, DestPtr, RetAI);
         bool DestIsVolatile = ReturnValue.isVolatile();
         if (!DestPtr.isValid()) {
-          DestPtr = CreateMemTemp(RetTy, "target_coerce");
+          DestPtr = CreateMemTempWithoutCast(RetTy, "target_coerce");
           DestIsVolatile = false;
         }
         CGM.getABIInfo().createCoercedStore(CI, StorePtr, RetAI, 
DestIsVolatile,
diff --git a/clang/lib/CodeGen/CGClass.cpp b/clang/lib/CodeGen/CGClass.cpp
index de11e8bca43f1..e52c5f6af2851 100644
--- a/clang/lib/CodeGen/CGClass.cpp
+++ b/clang/lib/CodeGen/CGClass.cpp
@@ -3190,7 +3190,7 @@ void CodeGenFunction::EmitLambdaStaticInvokeBody(const 
CXXMethodDecl *MD) {
 
   CanQualType LambdaType = getContext().getCanonicalTagType(Lambda);
   CanQualType ThisType = getContext().getPointerType(LambdaType);
-  Address ThisPtr = CreateMemTemp(LambdaType, "unused.capture");
+  Address ThisPtr = CreateMemTempWithoutCast(LambdaType, "unused.capture");
   CallArgs.add(RValue::get(ThisPtr.emitRawPointer(*this)), ThisType);
 
   EmitLambdaDelegatingInvokeBody(MD, CallArgs);
diff --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp
index 63ad0bc9ec238..7608f8cb6fc7a 100644
--- a/clang/lib/CodeGen/CGDecl.cpp
+++ b/clang/lib/CodeGen/CGDecl.cpp
@@ -2724,8 +2724,9 @@ void CodeGenFunction::EmitParmDecl(const VarDecl &D, 
ParamValue Arg,
       UseIndirectDebugAddress = !ArgInfo.getIndirectByVal();
     if (UseIndirectDebugAddress) {
       auto PtrTy = getContext().getPointerType(Ty);
-      AllocaPtr = CreateMemTemp(PtrTy, getContext().getTypeAlignInChars(PtrTy),
-                                D.getName() + ".indirect_addr");
+      AllocaPtr = CreateMemTempWithoutCast(
+          PtrTy, getContext().getTypeAlignInChars(PtrTy),
+          D.getName() + ".indirect_addr");
       EmitStoreOfScalar(V, AllocaPtr, /* Volatile */ false, PtrTy);
     }
 
@@ -2762,7 +2763,7 @@ void CodeGenFunction::EmitParmDecl(const VarDecl &D, 
ParamValue Arg,
       DeclPtr = OpenMPLocalAddr;
       AllocaPtr = DeclPtr;
     } else {
-      // Otherwise, create a temporary to hold the value.
+      // Otherwise, create a casted temporary to hold the value.
       DeclPtr = CreateMemTemp(Ty, getContext().getDeclAlign(&D),
                               D.getName() + ".addr", &AllocaPtr);
     }
diff --git a/clang/lib/CodeGen/CGException.cpp 
b/clang/lib/CodeGen/CGException.cpp
index 0576582d34543..99dfaa80be429 100644
--- a/clang/lib/CodeGen/CGException.cpp
+++ b/clang/lib/CodeGen/CGException.cpp
@@ -2130,7 +2130,7 @@ void 
CodeGenFunction::EmitSEHExceptionCodeSave(CodeGenFunction &ParentCGF,
     // On Win64, the info is passed as the first parameter to the filter.
     SEHInfo = &*CurFn->arg_begin();
     SEHCodeSlotStack.push_back(
-        CreateMemTemp(getContext().IntTy, "__exception_code"));
+        CreateMemTempWithoutCast(getContext().IntTy, "__exception_code"));
   } else {
     // On Win32, the EBP on entry to the filter points to the end of an
     // exception registration object. It contains 6 32-bit fields, and the info
@@ -2204,7 +2204,7 @@ void CodeGenFunction::EnterSEHTryStmt(const SEHTryStmt 
&S) {
   assert(Except);
   EHCatchScope *CatchScope = EHStack.pushCatch(1);
   SEHCodeSlotStack.push_back(
-      CreateMemTemp(getContext().IntTy, "__exception_code"));
+      CreateMemTempWithoutCast(getContext().IntTy, "__exception_code"));
 
   // If the filter is known to evaluate to 1, then we can use the clause
   // "catch i8* null". We can't do this on x86 because the filter has to save
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 325902f2127bc..e3f5eae2f453c 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -286,7 +286,7 @@ RValue CodeGenFunction::EmitAnyExpr(const Expr *E,
     return RValue::getComplex(EmitComplexExpr(E, ignoreResult, ignoreResult));
   case TEK_Aggregate:
     if (!ignoreResult && aggSlot.isIgnored())
-      aggSlot = CreateAggTemp(E->getType(), "agg-temp");
+      aggSlot = CreateAggTemp(E->getType().getUnqualifiedType(), "agg-temp");
     EmitAggExpr(E, aggSlot);
     return aggSlot.asRValue();
   }
@@ -492,11 +492,11 @@ static RawAddress 
createReferenceTemporary(CodeGenFunction &CGF,
         CharUnits alignment = CGF.getContext().getTypeAlignInChars(Ty);
         GV->setAlignment(alignment.getAsAlign());
         llvm::Constant *C = GV;
-        if (AS != LangAS::Default)
+        if (AS != Ty.getAddressSpace())
           C = CGF.CGM.performAddrSpaceCast(
-              GV, llvm::PointerType::get(
-                      CGF.getLLVMContext(),
-                      
CGF.getContext().getTargetAddressSpace(LangAS::Default)));
+              GV, llvm::PointerType::get(CGF.getLLVMContext(),
+                                         
CGF.getContext().getTargetAddressSpace(
+                                             Ty.getAddressSpace())));
         // FIXME: Should we put the new global into a COMDAT?
         return RawAddress(C, GV->getValueType(), alignment);
       }
@@ -5977,7 +5977,7 @@ LValue CodeGenFunction::EmitCompoundLiteralLValue(const 
CompoundLiteralExpr *E){
     // make sure to emit the VLA size.
     EmitVariablyModifiedType(E->getType());
 
-  Address DeclPtr = CreateMemTemp(E->getType(), ".compoundliteral");
+  Address DeclPtr = CreateMemTempWithoutCast(E->getType(), ".compoundliteral");
   const Expr *InitExpr = E->getInitializer();
   LValue Result = MakeAddrLValue(DeclPtr, E->getType(), AlignmentSource::Decl);
 
diff --git a/clang/lib/CodeGen/CGExprAgg.cpp b/clang/lib/CodeGen/CGExprAgg.cpp
index d20c9d208975c..befc2659b2f4c 100644
--- a/clang/lib/CodeGen/CGExprAgg.cpp
+++ b/clang/lib/CodeGen/CGExprAgg.cpp
@@ -2203,7 +2203,7 @@ void CodeGenFunction::EmitAggExpr(const Expr *E, 
AggValueSlot Slot) {
 
 LValue CodeGenFunction::EmitAggExprToLValue(const Expr *E) {
   assert(hasAggregateEvaluationKind(E->getType()) && "Invalid argument!");
-  Address Temp = CreateMemTemp(E->getType());
+  Address Temp = CreateMemTempWithoutCast(E->g...
[truncated]

``````````

</details>


https://github.com/llvm/llvm-project/pull/200427
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to