Skip to content

Commit

Permalink
[CodeGen] Avoid deprecated Address ctor in EmitLoadOfPointer()
Browse files Browse the repository at this point in the history
This requires some adjustment in caller code, because there was
a confusion regarding the meaning of the PtrTy argument: This
argument is the type of the pointer being loaded, not the addresses
being loaded from.
  • Loading branch information
nikic committed Mar 22, 2022
1 parent a9656bd commit 767ec88
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 16 deletions.
8 changes: 4 additions & 4 deletions clang/lib/CodeGen/CGExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2547,10 +2547,10 @@ Address CodeGenFunction::EmitLoadOfPointer(Address Ptr,
LValueBaseInfo *BaseInfo,
TBAAAccessInfo *TBAAInfo) {
llvm::Value *Addr = Builder.CreateLoad(Ptr);
return Address::deprecated(
Addr,
CGM.getNaturalTypeAlignment(PtrTy->getPointeeType(), BaseInfo, TBAAInfo,
/*forPointeeType=*/true));
return Address(Addr, ConvertTypeForMem(PtrTy->getPointeeType()),
CGM.getNaturalTypeAlignment(PtrTy->getPointeeType(), BaseInfo,
TBAAInfo,
/*forPointeeType=*/true));
}

LValue CodeGenFunction::EmitLoadOfPointerLValue(Address PtrAddr,
Expand Down
15 changes: 5 additions & 10 deletions clang/lib/CodeGen/CGOpenMPRuntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4650,8 +4650,7 @@ CGOpenMPRuntime::getDepobjElements(CodeGenFunction &CGF, LValue DepobjLVal,
RecordDecl *KmpDependInfoRD =
cast<RecordDecl>(KmpDependInfoTy->getAsTagDecl());
LValue Base = CGF.EmitLoadOfPointerLValue(
DepobjLVal.getAddress(CGF),
C.getPointerType(C.VoidPtrTy).castAs<PointerType>());
DepobjLVal.getAddress(CGF), C.VoidPtrTy.castAs<PointerType>());
QualType KmpDependInfoPtrTy = C.getPointerType(KmpDependInfoTy);
Address Addr = CGF.Builder.CreatePointerBitCastOrAddrSpaceCast(
Base.getAddress(CGF), CGF.ConvertTypeForMem(KmpDependInfoPtrTy),
Expand Down Expand Up @@ -4748,8 +4747,7 @@ emitDepobjElementsSizes(CodeGenFunction &CGF, QualType &KmpDependInfoTy,
for (const Expr *E : Data.DepExprs) {
LValue DepobjLVal = CGF.EmitLValue(E->IgnoreParenImpCasts());
LValue Base = CGF.EmitLoadOfPointerLValue(
DepobjLVal.getAddress(CGF),
C.getPointerType(C.VoidPtrTy).castAs<PointerType>());
DepobjLVal.getAddress(CGF), C.VoidPtrTy.castAs<PointerType>());
Address Addr = CGF.Builder.CreatePointerBitCastOrAddrSpaceCast(
Base.getAddress(CGF), KmpDependInfoPtrT,
CGF.ConvertTypeForMem(KmpDependInfoTy));
Expand Down Expand Up @@ -4806,8 +4804,7 @@ static void emitDepobjElements(CodeGenFunction &CGF, QualType &KmpDependInfoTy,
const Expr *E = Data.DepExprs[I];
LValue DepobjLVal = CGF.EmitLValue(E->IgnoreParenImpCasts());
LValue Base = CGF.EmitLoadOfPointerLValue(
DepobjLVal.getAddress(CGF),
C.getPointerType(C.VoidPtrTy).castAs<PointerType>());
DepobjLVal.getAddress(CGF), C.VoidPtrTy.castAs<PointerType>());
Address Addr = CGF.Builder.CreatePointerBitCastOrAddrSpaceCast(
Base.getAddress(CGF), KmpDependInfoPtrT,
CGF.ConvertTypeForMem(KmpDependInfoTy));
Expand Down Expand Up @@ -5055,8 +5052,7 @@ void CGOpenMPRuntime::emitDestroyClause(CodeGenFunction &CGF, LValue DepobjLVal,
QualType FlagsTy;
getDependTypes(C, KmpDependInfoTy, FlagsTy);
LValue Base = CGF.EmitLoadOfPointerLValue(
DepobjLVal.getAddress(CGF),
C.getPointerType(C.VoidPtrTy).castAs<PointerType>());
DepobjLVal.getAddress(CGF), C.VoidPtrTy.castAs<PointerType>());
QualType KmpDependInfoPtrTy = C.getPointerType(KmpDependInfoTy);
Address Addr = CGF.Builder.CreatePointerBitCastOrAddrSpaceCast(
Base.getAddress(CGF), CGF.ConvertTypeForMem(KmpDependInfoPtrTy),
Expand Down Expand Up @@ -6038,8 +6034,7 @@ static llvm::Value *emitReduceFiniFunction(CodeGenModule &CGM,
CodeGenFunction CGF(CGM);
CGF.StartFunction(GlobalDecl(), C.VoidTy, Fn, FnInfo, Args, Loc, Loc);
Address PrivateAddr = CGF.EmitLoadOfPointer(
CGF.GetAddrOfLocalVar(&Param),
C.getPointerType(C.VoidPtrTy).castAs<PointerType>());
CGF.GetAddrOfLocalVar(&Param), C.VoidPtrTy.castAs<PointerType>());
llvm::Value *Size = nullptr;
// If the size of the reduction item is non-constant, load it from global
// threadprivate variable.
Expand Down
3 changes: 1 addition & 2 deletions clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3545,8 +3545,7 @@ llvm::Function *CGOpenMPRuntimeGPU::createParallelDataSharingWrapper(
isOpenMPLoopBoundSharingDirective(D.getDirectiveKind())) {
SharedArgListAddress = CGF.EmitLoadOfPointer(
GlobalArgs, CGF.getContext()
.getPointerType(CGF.getContext().getPointerType(
CGF.getContext().VoidPtrTy))
.getPointerType(CGF.getContext().VoidPtrTy)
.castAs<PointerType>());
}
unsigned Idx = 0;
Expand Down
3 changes: 3 additions & 0 deletions clang/lib/CodeGen/CodeGenFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -2527,6 +2527,9 @@ class CodeGenFunction : public CodeGenTypeCache {
return EmitLoadOfReferenceLValue(RefLVal);
}

/// Load a pointer with type \p PtrTy stored at address \p Ptr.
/// Note that \p PtrTy is the type of the loaded pointer, not the addresses
/// it is loaded from.
Address EmitLoadOfPointer(Address Ptr, const PointerType *PtrTy,
LValueBaseInfo *BaseInfo = nullptr,
TBAAAccessInfo *TBAAInfo = nullptr);
Expand Down

0 comments on commit 767ec88

Please sign in to comment.