Skip to content

Commit 1cef8c2

Browse files
committed
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. ------------------------------------------------------------------------ llvm-svn: 358923
1 parent aaac4e0 commit 1cef8c2

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

clang/lib/CodeGen/CGStmtOpenMP.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1518,8 +1518,9 @@ void CodeGenFunction::EmitOMPPrivateLoopCounters(
15181518
I < E; ++I) {
15191519
const auto *DRE = cast<DeclRefExpr>(C->getLoopCounter(I));
15201520
const auto *VD = cast<VarDecl>(DRE->getDecl());
1521-
// Override only those variables that are really emitted already.
1522-
if (LocalDeclMap.count(VD)) {
1521+
// Override only those variables that can be captured to avoid re-emission
1522+
// of the variables declared within the loops.
1523+
if (DRE->refersToEnclosingVariableOrCapture()) {
15231524
(void)LoopScope.addPrivate(VD, [this, DRE, VD]() {
15241525
return CreateMemTemp(DRE->getType(), VD->getName());
15251526
});

clang/lib/Sema/SemaOpenMP.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4602,8 +4602,7 @@ DeclRefExpr *OpenMPIterationSpaceChecker::buildCounterVar(
46024602
Captures.insert(std::make_pair(LCRef, Ref));
46034603
return Ref;
46044604
}
4605-
return buildDeclRefExpr(SemaRef, VD, VD->getType().getNonReferenceType(),
4606-
DefaultLoc);
4605+
return cast<DeclRefExpr>(LCRef);
46074606
}
46084607

46094608
Expr *OpenMPIterationSpaceChecker::buildPrivateCounterVar() const {

clang/test/OpenMP/ordered_doacross_codegen.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,17 @@ extern int n;
1616
int a[10], b[10], c[10], d[10];
1717
void foo();
1818

19+
// CHECK-LABEL:bar
20+
void bar() {
21+
int i,j;
22+
// CHECK: call void @__kmpc_doacross_init(
23+
// CHECK: call void @__kmpc_doacross_fini(
24+
#pragma omp parallel for ordered(2)
25+
for (i = 0; i < n; ++i)
26+
for (j = 0; j < n; ++j)
27+
a[i] = b[i] + 1;
28+
}
29+
1930
// CHECK-LABEL: @main()
2031
int main() {
2132
int i;
@@ -35,7 +46,7 @@ int main() {
3546
// CHECK: call void @__kmpc_doacross_init([[IDENT]], i32 [[GTID]], i32 1, i8* [[CAST]])
3647
// CHECK: call void @__kmpc_for_static_init_4(
3748
#pragma omp for ordered(1)
38-
for (i = 0; i < n; ++i) {
49+
for (int i = 0; i < n; ++i) {
3950
a[i] = b[i] + 1;
4051
foo();
4152
// CHECK: invoke void [[FOO:.+]](

0 commit comments

Comments
 (0)