Skip to content

Commit d764ad7

Browse files
committed
[OPENMP]Fix PR48394: need to capture variables used in atomic constructs.
The variables used in atomic construct should be captured in outer task-based regions implicitly. Otherwise, the compiler will crash trying to find the address of the local variable. Differential Revision: https://reviews.llvm.org/D92682
1 parent 297c839 commit d764ad7

File tree

2 files changed

+38
-3
lines changed

2 files changed

+38
-3
lines changed

clang/lib/Sema/SemaOpenMP.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3339,12 +3339,15 @@ class DSAAttrChecker final : public StmtVisitor<DSAAttrChecker, void> {
33393339

33403340
void VisitSubCaptures(OMPExecutableDirective *S) {
33413341
// Check implicitly captured variables.
3342-
if (!S->hasAssociatedStmt() || !S->getAssociatedStmt() ||
3343-
S->getDirectiveKind() == OMPD_atomic ||
3342+
if (!S->hasAssociatedStmt() || !S->getAssociatedStmt())
3343+
return;
3344+
if (S->getDirectiveKind() == OMPD_atomic ||
33443345
S->getDirectiveKind() == OMPD_critical ||
33453346
S->getDirectiveKind() == OMPD_section ||
3346-
S->getDirectiveKind() == OMPD_master)
3347+
S->getDirectiveKind() == OMPD_master) {
3348+
Visit(S->getAssociatedStmt());
33473349
return;
3350+
}
33483351
visitSubCaptures(S->getInnermostCapturedStmt());
33493352
// Try to capture inner this->member references to generate correct mappings
33503353
// and diagnostics.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// RUN: %clang_cc1 -verify -triple x86_64-apple-darwin10 -fopenmp -fopenmp-version=50 -x c++ -emit-llvm %s -o - | FileCheck %s
2+
// RUN: %clang_cc1 -fopenmp -fopenmp-version=50 -x c++ -triple x86_64-apple-darwin10 -emit-pch -o %t %s
3+
// RUN: %clang_cc1 -fopenmp -fopenmp-version=50 -x c++ -triple x86_64-apple-darwin10 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s
4+
5+
// RUN: %clang_cc1 -verify -triple x86_64-apple-darwin10 -fopenmp-simd -fopenmp-version=50 -x c++ -emit-llvm %s -o - | FileCheck --check-prefix SIMD-ONLY0 %s
6+
// RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=50 -x c++ -triple x86_64-apple-darwin10 -emit-pch -o %t %s
7+
// RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=50 -x c++ -triple x86_64-apple-darwin10 -include-pch %t -verify %s -emit-llvm -o - | FileCheck --check-prefix SIMD-ONLY0 %s
8+
// SIMD-ONLY0-NOT: {{__kmpc|__tgt}}
9+
// expected-no-diagnostics
10+
11+
#ifndef HEADER
12+
#define HEADER
13+
14+
// CHECK-LABEL: @main
15+
int main() {
16+
unsigned occupanices = 0;
17+
18+
// CHECK: call void @__kmpc_taskloop(%struct.ident_t* @{{.+}}, i32 %{{.+}}, i8* %{{.+}}, i32 1, i64* %{{.+}}, i64* %{{.+}}, i64 %{{.+}}, i32 1, i32 0, i64 0, i8* null)
19+
#pragma omp taskloop
20+
for (int i = 0; i < 1; i++) {
21+
#pragma omp atomic
22+
occupanices++;
23+
}
24+
}
25+
26+
// CHECK: define internal i32 @{{.+}}(
27+
// Check that occupanices var is firstprivatized.
28+
// CHECK-DAG: atomicrmw add i32* [[FP_OCCUP:%.+]], i32 1
29+
// CHECK-DAG: [[FP_OCCUP]] = load i32*, i32** [[FP_OCCUP_ADDR:%[^,]+]],
30+
// CHECK-DAG: call void (i8*, ...) %{{.+}}(i8* %{{.+}}, i32** [[FP_OCCUP_ADDR]])
31+
32+
#endif

0 commit comments

Comments
 (0)