ABataev created this revision.
ABataev added a reviewer: jdoerfert.
Herald added subscribers: guansong, yaxunl.
ABataev requested review of this revision.
Herald added a subscriber: sstefan1.
Herald added a project: clang.

Need to cast the argument for the debug wrapper function call to the
corresponding parameter type to avoid crash.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D99617

Files:
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/test/OpenMP/debug-info-complex-byval.cpp


Index: clang/test/OpenMP/debug-info-complex-byval.cpp
===================================================================
--- /dev/null
+++ clang/test/OpenMP/debug-info-complex-byval.cpp
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -fopenmp -x c++ %s -verify -debug-info-kind=limited -triple 
x86_64-unknown-unknown -emit-llvm -o - | FileCheck %s
+
+// RUN: %clang_cc1 -fopenmp-simd -x c++ %s -verify -debug-info-kind=limited 
-triple x86_64-unknown-unknown -emit-llvm -o - | FileCheck --check-prefix 
SIMD-ONLY0 %s
+// SIMD-ONLY0-NOT: {{__kmpc|__tgt}}
+// expected-no-diagnostics
+
+void a() {
+  float _Complex b;
+  // CHECK: call void (%struct.ident_t*, i32, void (i32*, i32*, ...)*, ...) 
@__kmpc_fork_call(%struct.ident_t* {{.*}}, i32 1, void (i32*, i32*, ...)* 
bitcast (void (i32*, i32*, i64)* [[OUTLINED:@.+]] to void (i32*, i32*, ...)*), 
i64 %{{.*}})
+#pragma omp parallel firstprivate(b)
+  ;
+}
+
+// CHECK: define internal void [[OUTLINED_DEBUG:@.+]](i32* {{.*}}, i32* 
{{.*}}, <2 x float> {{.*}})
+
+// CHECK: define internal void [[OUTLINED]](i32* {{.*}}, i32* {{.*}}, i64 
[[B_VAL:%.+]])
+// CHECK: [[B_ADDR:%.+]] = alloca i64,
+// CHECK: store i64 [[B_VAL]], i64* [[B_ADDR]],
+// CHECK: [[CONV:%.+]] = bitcast i64* [[B_ADDR]] to { float, float }*,
+// CHECK: [[BC:%.+]] = bitcast { float, float }* [[CONV]] to <2 x float>*,
+// CHECK: [[B_VAL:%.+]] = load <2 x float>, <2 x float>* [[BC]],
+// CHECK: call void [[OUTLINED_DEBUG]](i32* %{{.+}}, i32* %{{.+}}, <2 x float> 
[[B_VAL]])
Index: clang/lib/CodeGen/CGStmtOpenMP.cpp
===================================================================
--- clang/lib/CodeGen/CGStmtOpenMP.cpp
+++ clang/lib/CodeGen/CGStmtOpenMP.cpp
@@ -634,14 +634,22 @@
       emitOutlinedFunctionPrologue(WrapperCGF, Args, LocalAddrs, VLASizes,
                                    WrapperCGF.CXXThisValue, WrapperFO);
   llvm::SmallVector<llvm::Value *, 4> CallArgs;
+  auto *PI = F->arg_begin();
   for (const auto *Arg : Args) {
     llvm::Value *CallArg;
     auto I = LocalAddrs.find(Arg);
     if (I != LocalAddrs.end()) {
+      Address Addr = I->second.second;
+      if (PI->getType()->isFirstClassType())
+        ;
       LValue LV = WrapperCGF.MakeAddrLValue(
-          I->second.second,
-          I->second.first ? I->second.first->getType() : Arg->getType(),
+          Addr, I->second.first ? I->second.first->getType() : Arg->getType(),
           AlignmentSource::Decl);
+      if (LV.getType()->isAnyComplexType())
+        LV.setAddress(WrapperCGF.Builder.CreatePointerBitCastOrAddrSpaceCast(
+            LV.getAddress(WrapperCGF),
+            PI->getType()->getPointerTo(
+                LV.getAddress(WrapperCGF).getAddressSpace())));
       CallArg = WrapperCGF.EmitLoadOfScalar(LV, S.getBeginLoc());
     } else {
       auto EI = VLASizes.find(Arg);
@@ -655,6 +663,7 @@
       }
     }
     CallArgs.emplace_back(WrapperCGF.EmitFromMemory(CallArg, Arg->getType()));
+    ++PI;
   }
   CGM.getOpenMPRuntime().emitOutlinedFunctionCall(WrapperCGF, Loc, F, 
CallArgs);
   WrapperCGF.FinishFunction();


Index: clang/test/OpenMP/debug-info-complex-byval.cpp
===================================================================
--- /dev/null
+++ clang/test/OpenMP/debug-info-complex-byval.cpp
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -fopenmp -x c++ %s -verify -debug-info-kind=limited -triple x86_64-unknown-unknown -emit-llvm -o - | FileCheck %s
+
+// RUN: %clang_cc1 -fopenmp-simd -x c++ %s -verify -debug-info-kind=limited -triple x86_64-unknown-unknown -emit-llvm -o - | FileCheck --check-prefix SIMD-ONLY0 %s
+// SIMD-ONLY0-NOT: {{__kmpc|__tgt}}
+// expected-no-diagnostics
+
+void a() {
+  float _Complex b;
+  // CHECK: call void (%struct.ident_t*, i32, void (i32*, i32*, ...)*, ...) @__kmpc_fork_call(%struct.ident_t* {{.*}}, i32 1, void (i32*, i32*, ...)* bitcast (void (i32*, i32*, i64)* [[OUTLINED:@.+]] to void (i32*, i32*, ...)*), i64 %{{.*}})
+#pragma omp parallel firstprivate(b)
+  ;
+}
+
+// CHECK: define internal void [[OUTLINED_DEBUG:@.+]](i32* {{.*}}, i32* {{.*}}, <2 x float> {{.*}})
+
+// CHECK: define internal void [[OUTLINED]](i32* {{.*}}, i32* {{.*}}, i64 [[B_VAL:%.+]])
+// CHECK: [[B_ADDR:%.+]] = alloca i64,
+// CHECK: store i64 [[B_VAL]], i64* [[B_ADDR]],
+// CHECK: [[CONV:%.+]] = bitcast i64* [[B_ADDR]] to { float, float }*,
+// CHECK: [[BC:%.+]] = bitcast { float, float }* [[CONV]] to <2 x float>*,
+// CHECK: [[B_VAL:%.+]] = load <2 x float>, <2 x float>* [[BC]],
+// CHECK: call void [[OUTLINED_DEBUG]](i32* %{{.+}}, i32* %{{.+}}, <2 x float> [[B_VAL]])
Index: clang/lib/CodeGen/CGStmtOpenMP.cpp
===================================================================
--- clang/lib/CodeGen/CGStmtOpenMP.cpp
+++ clang/lib/CodeGen/CGStmtOpenMP.cpp
@@ -634,14 +634,22 @@
       emitOutlinedFunctionPrologue(WrapperCGF, Args, LocalAddrs, VLASizes,
                                    WrapperCGF.CXXThisValue, WrapperFO);
   llvm::SmallVector<llvm::Value *, 4> CallArgs;
+  auto *PI = F->arg_begin();
   for (const auto *Arg : Args) {
     llvm::Value *CallArg;
     auto I = LocalAddrs.find(Arg);
     if (I != LocalAddrs.end()) {
+      Address Addr = I->second.second;
+      if (PI->getType()->isFirstClassType())
+        ;
       LValue LV = WrapperCGF.MakeAddrLValue(
-          I->second.second,
-          I->second.first ? I->second.first->getType() : Arg->getType(),
+          Addr, I->second.first ? I->second.first->getType() : Arg->getType(),
           AlignmentSource::Decl);
+      if (LV.getType()->isAnyComplexType())
+        LV.setAddress(WrapperCGF.Builder.CreatePointerBitCastOrAddrSpaceCast(
+            LV.getAddress(WrapperCGF),
+            PI->getType()->getPointerTo(
+                LV.getAddress(WrapperCGF).getAddressSpace())));
       CallArg = WrapperCGF.EmitLoadOfScalar(LV, S.getBeginLoc());
     } else {
       auto EI = VLASizes.find(Arg);
@@ -655,6 +663,7 @@
       }
     }
     CallArgs.emplace_back(WrapperCGF.EmitFromMemory(CallArg, Arg->getType()));
+    ++PI;
   }
   CGM.getOpenMPRuntime().emitOutlinedFunctionCall(WrapperCGF, Loc, F, CallArgs);
   WrapperCGF.FinishFunction();
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to