[CodeGen][OpenMP] Make EmitLoadOfPointer() type consistent
authorNikita Popov <npopov@redhat.com>
Mon, 21 Mar 2022 16:52:40 +0000 (17:52 +0100)
committerNikita Popov <npopov@redhat.com>
Tue, 22 Mar 2022 08:37:48 +0000 (09:37 +0100)
If necessary insert a bitcast beforehand, so the LLVM-level pointer
type and the Clang-level pointer type line up.

clang/lib/CodeGen/CGStmtOpenMP.cpp
clang/test/OpenMP/target_data_use_device_addr_codegen.cpp

index 94e7e1a..7ce3cd9 100644 (file)
@@ -6949,16 +6949,13 @@ void CodeGenFunction::EmitOMPUseDeviceAddrClause(
     // For declrefs and variable length array need to load the pointer for
     // correct mapping, since the pointer to the data was passed to the runtime.
     if (isa<DeclRefExpr>(Ref->IgnoreParenImpCasts()) ||
-        MatchingVD->getType()->isArrayType())
-      PrivAddr =
-          EmitLoadOfPointer(PrivAddr, getContext()
-                                          .getPointerType(OrigVD->getType())
-                                          ->castAs<PointerType>());
-    llvm::Type *RealElTy =
-        ConvertTypeForMem(OrigVD->getType().getNonReferenceType());
-    llvm::Type *RealTy = RealElTy->getPointerTo();
-    PrivAddr =
-        Builder.CreatePointerBitCastOrAddrSpaceCast(PrivAddr, RealTy, RealElTy);
+        MatchingVD->getType()->isArrayType()) {
+      QualType PtrTy = getContext().getPointerType(
+          OrigVD->getType().getNonReferenceType());
+      PrivAddr = EmitLoadOfPointer(
+          Builder.CreateElementBitCast(PrivAddr, ConvertTypeForMem(PtrTy)),
+          PtrTy->castAs<PointerType>());
+    }
 
     (void)PrivateScope.addPrivate(OrigVD, PrivAddr);
   }
index 9a3f7aa..6bc1631 100644 (file)
@@ -90,8 +90,8 @@ int main() {
 // CHECK: [[A_REF:%.+]] = load float*, float** [[BPTR0_A_ADDR]],
 // CHECK: [[REF_REF:%.+]] = load float*, float** [[BPTR2_REF_ADDR]],
 // CHECK: store float* [[REF_REF]], float** [[TMP_REF_ADDR:%.+]],
-// CHECK: [[ARR:%.+]] = load float*, float** [[BPTR3_ARR_ADDR]],
-// CHECK: [[ARR_REF:%.+]] = bitcast float* [[ARR]] to [4 x float]*
+// CHECK: [[BPTR3_ARR_ADDR_CAST:%.+]] = bitcast float** [[BPTR3_ARR_ADDR]] to [4 x float]**
+// CHECK: [[ARR_REF:%.+]] = load [4 x float]*, [4 x float]** [[BPTR3_ARR_ADDR_CAST]],
 // CHECK: [[VLA_REF:%.+]] = load float*, float** [[BPTR4_VLA_ADDR]],
 // CHECK: [[A:%.+]] = load float, float* [[A_REF]],
 // CHECK: [[INC:%.+]] = fadd float [[A]], 1.000000e+00