Skip to content

Commit a9656bd

Browse files
committed
[CodeGen][OpenMP] Make EmitLoadOfPointer() type consistent
If necessary insert a bitcast beforehand, so the LLVM-level pointer type and the Clang-level pointer type line up.
1 parent 2ddd57a commit a9656bd

File tree

2 files changed

+9
-12
lines changed

2 files changed

+9
-12
lines changed

clang/lib/CodeGen/CGStmtOpenMP.cpp

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6949,16 +6949,13 @@ void CodeGenFunction::EmitOMPUseDeviceAddrClause(
69496949
// For declrefs and variable length array need to load the pointer for
69506950
// correct mapping, since the pointer to the data was passed to the runtime.
69516951
if (isa<DeclRefExpr>(Ref->IgnoreParenImpCasts()) ||
6952-
MatchingVD->getType()->isArrayType())
6953-
PrivAddr =
6954-
EmitLoadOfPointer(PrivAddr, getContext()
6955-
.getPointerType(OrigVD->getType())
6956-
->castAs<PointerType>());
6957-
llvm::Type *RealElTy =
6958-
ConvertTypeForMem(OrigVD->getType().getNonReferenceType());
6959-
llvm::Type *RealTy = RealElTy->getPointerTo();
6960-
PrivAddr =
6961-
Builder.CreatePointerBitCastOrAddrSpaceCast(PrivAddr, RealTy, RealElTy);
6952+
MatchingVD->getType()->isArrayType()) {
6953+
QualType PtrTy = getContext().getPointerType(
6954+
OrigVD->getType().getNonReferenceType());
6955+
PrivAddr = EmitLoadOfPointer(
6956+
Builder.CreateElementBitCast(PrivAddr, ConvertTypeForMem(PtrTy)),
6957+
PtrTy->castAs<PointerType>());
6958+
}
69626959

69636960
(void)PrivateScope.addPrivate(OrigVD, PrivAddr);
69646961
}

clang/test/OpenMP/target_data_use_device_addr_codegen.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ int main() {
9090
// CHECK: [[A_REF:%.+]] = load float*, float** [[BPTR0_A_ADDR]],
9191
// CHECK: [[REF_REF:%.+]] = load float*, float** [[BPTR2_REF_ADDR]],
9292
// CHECK: store float* [[REF_REF]], float** [[TMP_REF_ADDR:%.+]],
93-
// CHECK: [[ARR:%.+]] = load float*, float** [[BPTR3_ARR_ADDR]],
94-
// CHECK: [[ARR_REF:%.+]] = bitcast float* [[ARR]] to [4 x float]*
93+
// CHECK: [[BPTR3_ARR_ADDR_CAST:%.+]] = bitcast float** [[BPTR3_ARR_ADDR]] to [4 x float]**
94+
// CHECK: [[ARR_REF:%.+]] = load [4 x float]*, [4 x float]** [[BPTR3_ARR_ADDR_CAST]],
9595
// CHECK: [[VLA_REF:%.+]] = load float*, float** [[BPTR4_VLA_ADDR]],
9696
// CHECK: [[A:%.+]] = load float, float* [[A_REF]],
9797
// CHECK: [[INC:%.+]] = fadd float [[A]], 1.000000e+00

0 commit comments

Comments
 (0)