summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTom Stellard <tstellar@redhat.com>2019-04-22 22:12:21 +0000
committerTom Stellard <tstellar@redhat.com>2019-04-22 22:12:21 +0000
commit8c8a935cfb42438010af5c08d785c175a493574b (patch)
tree5961508b51f1bddd11a049371eabec6ab1d10fd0
parenta03da8be08a208122e292016cb6cea1f30229677 (diff)
Merging r356198:
------------------------------------------------------------------------ r356198 | abataev | 2019-03-14 13:36:00 -0700 (Thu, 14 Mar 2019) | 5 lines [OPENMP]Fix crash for the ordered(n) clause. If the doacross lop construct is used and the loop counter is declare outside of the loop, the compiler might crash trying to get the address of the loop counter. Patch fixes this problem. ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/cfe/branches/release_80@358923 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/CodeGen/CGStmtOpenMP.cpp5
-rw-r--r--lib/Sema/SemaOpenMP.cpp3
-rw-r--r--test/OpenMP/ordered_doacross_codegen.cpp13
3 files changed, 16 insertions, 5 deletions
diff --git a/lib/CodeGen/CGStmtOpenMP.cpp b/lib/CodeGen/CGStmtOpenMP.cpp
index eb1304d893..44dc1cdee0 100644
--- a/lib/CodeGen/CGStmtOpenMP.cpp
+++ b/lib/CodeGen/CGStmtOpenMP.cpp
@@ -1518,8 +1518,9 @@ void CodeGenFunction::EmitOMPPrivateLoopCounters(
I < E; ++I) {
const auto *DRE = cast<DeclRefExpr>(C->getLoopCounter(I));
const auto *VD = cast<VarDecl>(DRE->getDecl());
- // Override only those variables that are really emitted already.
- if (LocalDeclMap.count(VD)) {
+ // Override only those variables that can be captured to avoid re-emission
+ // of the variables declared within the loops.
+ if (DRE->refersToEnclosingVariableOrCapture()) {
(void)LoopScope.addPrivate(VD, [this, DRE, VD]() {
return CreateMemTemp(DRE->getType(), VD->getName());
});
diff --git a/lib/Sema/SemaOpenMP.cpp b/lib/Sema/SemaOpenMP.cpp
index aedec746af..8a0be0c472 100644
--- a/lib/Sema/SemaOpenMP.cpp
+++ b/lib/Sema/SemaOpenMP.cpp
@@ -4602,8 +4602,7 @@ DeclRefExpr *OpenMPIterationSpaceChecker::buildCounterVar(
Captures.insert(std::make_pair(LCRef, Ref));
return Ref;
}
- return buildDeclRefExpr(SemaRef, VD, VD->getType().getNonReferenceType(),
- DefaultLoc);
+ return cast<DeclRefExpr>(LCRef);
}
Expr *OpenMPIterationSpaceChecker::buildPrivateCounterVar() const {
diff --git a/test/OpenMP/ordered_doacross_codegen.cpp b/test/OpenMP/ordered_doacross_codegen.cpp
index 2f19e9c2d5..a3abf248d7 100644
--- a/test/OpenMP/ordered_doacross_codegen.cpp
+++ b/test/OpenMP/ordered_doacross_codegen.cpp
@@ -16,6 +16,17 @@ extern int n;
int a[10], b[10], c[10], d[10];
void foo();
+// CHECK-LABEL:bar
+void bar() {
+ int i,j;
+// CHECK: call void @__kmpc_doacross_init(
+// CHECK: call void @__kmpc_doacross_fini(
+#pragma omp parallel for ordered(2)
+ for (i = 0; i < n; ++i)
+ for (j = 0; j < n; ++j)
+ a[i] = b[i] + 1;
+}
+
// CHECK-LABEL: @main()
int main() {
int i;
@@ -35,7 +46,7 @@ int main() {
// CHECK: call void @__kmpc_doacross_init([[IDENT]], i32 [[GTID]], i32 1, i8* [[CAST]])
// CHECK: call void @__kmpc_for_static_init_4(
#pragma omp for ordered(1)
- for (i = 0; i < n; ++i) {
+ for (int i = 0; i < n; ++i) {
a[i] = b[i] + 1;
foo();
// CHECK: invoke void [[FOO:.+]](