Browse Source

[OPENMP] DO not crash on combined constructs in declare target
functions.

If the combined construct is specified in the declare target function
and the device code is emitted, the compiler crashes because of the
incorrectly chosen captured stmt. We should choose the innermost
captured statement, not the outermost.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@332477 91177308-0d34-0410-b5e6-96231b3b80d8

Alexey Bataev 7 years ago
parent
commit
90a2c3d33a
2 changed files with 2 additions and 2 deletions
  1. 1 1
      lib/CodeGen/CGStmtOpenMP.cpp
  2. 1 1
      test/OpenMP/declare_target_codegen.cpp

+ 1 - 1
lib/CodeGen/CGStmtOpenMP.cpp

@@ -3935,7 +3935,7 @@ static void emitCommonOMPTargetDirective(CodeGenFunction &CGF,
     OMPLexicalScope Scope(CGF, S, OMPD_target);
     OMPLexicalScope Scope(CGF, S, OMPD_target);
     CGM.getOpenMPRuntime().emitInlinedDirective(
     CGM.getOpenMPRuntime().emitInlinedDirective(
         CGF, OMPD_target, [&S](CodeGenFunction &CGF, PrePostActionTy &) {
         CGF, OMPD_target, [&S](CodeGenFunction &CGF, PrePostActionTy &) {
-          CGF.EmitStmt(S.getCapturedStmt(OMPD_target)->getCapturedStmt());
+          CGF.EmitStmt(S.getInnermostCapturedStmt()->getCapturedStmt());
         });
         });
     return;
     return;
   }
   }

+ 1 - 1
test/OpenMP/declare_target_codegen.cpp

@@ -82,7 +82,7 @@ int maini1() {
 int baz3() { return 2 + baz2(); }
 int baz3() { return 2 + baz2(); }
 int baz2() {
 int baz2() {
 // CHECK-DAG: define weak void @__omp_offloading_{{.*}}baz2{{.*}}_l[[@LINE+1]](i64 {{.*}})
 // CHECK-DAG: define weak void @__omp_offloading_{{.*}}baz2{{.*}}_l[[@LINE+1]](i64 {{.*}})
-#pragma omp target
+#pragma omp target parallel
   ++c;
   ++c;
   return 2 + baz3();
   return 2 + baz3();
 }
 }