Author: Alexey Bataev
Date: 2020-04-06T12:07:43-04:00
New Revision: 1c924486564461810903603542ffc2d7db204dde

URL: 
https://github.com/llvm/llvm-project/commit/1c924486564461810903603542ffc2d7db204dde
DIFF: 
https://github.com/llvm/llvm-project/commit/1c924486564461810903603542ffc2d7db204dde.diff

LOG: [OPENMP]Fix PR45439: `omp for collapse(2) ordered(2)` generates invalid
IR.

Fixed a crash because of the not quite correct casting of the value of
iterations.

Added: 
    

Modified: 
    clang/lib/CodeGen/CGOpenMPRuntime.cpp
    clang/test/OpenMP/ordered_doacross_codegen.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index 6642851a56bc..737349ea5453 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -11206,10 +11206,9 @@ void CGOpenMPRuntime::emitDoacrossInit(CodeGenFunction 
&CGF,
     // dims.upper = num_iterations;
     LValue UpperLVal = CGF.EmitLValueForField(
         DimsLVal, *std::next(RD->field_begin(), UpperFD));
-    llvm::Value *NumIterVal =
-        CGF.EmitScalarConversion(CGF.EmitScalarExpr(NumIterations[I]),
-                                 D.getNumIterations()->getType(), Int64Ty,
-                                 D.getNumIterations()->getExprLoc());
+    llvm::Value *NumIterVal = CGF.EmitScalarConversion(
+        CGF.EmitScalarExpr(NumIterations[I]), NumIterations[I]->getType(),
+        Int64Ty, NumIterations[I]->getExprLoc());
     CGF.EmitStoreOfScalar(NumIterVal, UpperLVal);
     // dims.stride = 1;
     LValue StrideLVal = CGF.EmitLValueForField(

diff  --git a/clang/test/OpenMP/ordered_doacross_codegen.cpp 
b/clang/test/OpenMP/ordered_doacross_codegen.cpp
index 836f938fbce6..e30e2d557cfd 100644
--- a/clang/test/OpenMP/ordered_doacross_codegen.cpp
+++ b/clang/test/OpenMP/ordered_doacross_codegen.cpp
@@ -25,6 +25,12 @@ void bar() {
   for (i = 0; i < n; ++i)
   for (j = 0; j < n; ++j)
     a[i] = b[i] + 1;
+// CHECK: call void @__kmpc_doacross_init(
+// CHECK: call void @__kmpc_doacross_fini(
+ #pragma omp for collapse(2) ordered(2)
+  for (int i = 0; i < n; i++)
+    for (int j = 0; j < n; j++)
+      ;
 }
 
 // CHECK-LABEL: @main()


        
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to