Skip to content

Commit ae53c7f

Browse files
committed
[Clang][OpenMP] Fix the issue that a functor is not captured properly in a task region
This patch fixes the issue that a functor is not captured properly if that is used in a task region. It was introduced by https://reviews.llvm.org/D114546 where `CallExpr` is treated specially, but the callee itself is not properly visited. https://reviews.llvm.org/D115902 already did some fix for one case. This patch fixes another case. Fix #57757. Reviewed By: ABataev Differential Revision: https://reviews.llvm.org/D141873
1 parent 61fa12d commit ae53c7f

File tree

2 files changed

+62
-2
lines changed

2 files changed

+62
-2
lines changed

clang/lib/Sema/SemaOpenMP.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4067,9 +4067,13 @@ class DSAAttrChecker final : public StmtVisitor<DSAAttrChecker, void> {
40674067
Visit(C);
40684068
}
40694069
}
4070-
if (Expr *Callee = S->getCallee())
4071-
if (auto *CE = dyn_cast<MemberExpr>(Callee->IgnoreParenImpCasts()))
4070+
if (Expr *Callee = S->getCallee()) {
4071+
auto *CI = Callee->IgnoreParenImpCasts();
4072+
if (auto *CE = dyn_cast<MemberExpr>(CI))
40724073
Visit(CE->getBase());
4074+
else if (auto *CE = dyn_cast<DeclRefExpr>(CI))
4075+
Visit(CE);
4076+
}
40734077
}
40744078
void VisitStmt(Stmt *S) {
40754079
for (Stmt *C : S->children()) {

clang/test/OpenMP/bug57757.cpp

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --function-signature --include-generated-funcs --prefix-filecheck-ir-name _
2+
// RUN: %clang_cc1 -fopenmp -O1 -x c++ -triple x86_64-apple-darwin10 -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK
3+
4+
template <class Function, class... Args>
5+
void run_task(Function function, Args... args) {
6+
#pragma omp task untied
7+
{ function(args...); }
8+
}
9+
10+
void bar(int a, float b);
11+
12+
void foo() {
13+
int a;
14+
float b;
15+
run_task(bar, a, b);
16+
}
17+
// CHECK-LABEL: define {{[^@]+}}@_Z3foov
18+
// CHECK-SAME: () local_unnamed_addr #[[ATTR0:[0-9]+]] {
19+
// CHECK-NEXT: entry:
20+
// CHECK-NEXT: [[TMP0:%.*]] = tail call i32 @__kmpc_global_thread_num(ptr nonnull @[[GLOB1:[0-9]+]])
21+
// CHECK-NEXT: [[TMP1:%.*]] = tail call ptr @__kmpc_omp_task_alloc(ptr nonnull @[[GLOB1]], i32 [[TMP0]], i32 0, i64 56, i64 1, ptr nonnull @.omp_task_entry.)
22+
// CHECK-NEXT: [[TMP2:%.*]] = getelementptr inbounds [[STRUCT_KMP_TASK_T_WITH_PRIVATES:%.*]], ptr [[TMP1]], i64 0, i32 1
23+
// CHECK-NEXT: store ptr @_Z3barif, ptr [[TMP2]], align 8, !tbaa [[TBAA3:![0-9]+]]
24+
// CHECK-NEXT: [[TMP3:%.*]] = getelementptr inbounds [[STRUCT_KMP_TASK_T:%.*]], ptr [[TMP1]], i64 0, i32 2
25+
// CHECK-NEXT: store i32 0, ptr [[TMP3]], align 8, !tbaa [[TBAA12:![0-9]+]]
26+
// CHECK-NEXT: [[TMP4:%.*]] = tail call i32 @__kmpc_omp_task(ptr nonnull @[[GLOB1]], i32 [[TMP0]], ptr [[TMP1]])
27+
// CHECK-NEXT: ret void
28+
//
29+
//
30+
// CHECK-LABEL: define {{[^@]+}}@.omp_task_entry.
31+
// CHECK-SAME: (i32 noundef [[TMP0:%.*]], ptr noalias noundef [[TMP1:%.*]]) #[[ATTR3:[0-9]+]] {
32+
// CHECK-NEXT: entry:
33+
// CHECK-NEXT: [[TMP2:%.*]] = getelementptr inbounds [[STRUCT_KMP_TASK_T:%.*]], ptr [[TMP1]], i64 0, i32 2
34+
// CHECK-NEXT: tail call void @llvm.experimental.noalias.scope.decl(metadata [[META13:![0-9]+]])
35+
// CHECK-NEXT: tail call void @llvm.experimental.noalias.scope.decl(metadata [[META16:![0-9]+]])
36+
// CHECK-NEXT: [[TMP3:%.*]] = load i32, ptr [[TMP2]], align 4, !tbaa [[TBAA18:![0-9]+]], !alias.scope !13, !noalias !16
37+
// CHECK-NEXT: switch i32 [[TMP3]], label [[DOTOMP_OUTLINED__EXIT:%.*]] [
38+
// CHECK-NEXT: i32 0, label [[DOTUNTIED_JMP__I:%.*]]
39+
// CHECK-NEXT: i32 1, label [[DOTUNTIED_NEXT__I:%.*]]
40+
// CHECK-NEXT: ]
41+
// CHECK: .untied.jmp..i:
42+
// CHECK-NEXT: store i32 1, ptr [[TMP2]], align 4, !tbaa [[TBAA18]], !alias.scope !13, !noalias !16
43+
// CHECK-NEXT: [[TMP4:%.*]] = tail call i32 @__kmpc_omp_task(ptr nonnull @[[GLOB1]], i32 [[TMP0]], ptr [[TMP1]]), !noalias !19
44+
// CHECK-NEXT: br label [[DOTOMP_OUTLINED__EXIT]]
45+
// CHECK: .untied.next..i:
46+
// CHECK-NEXT: [[TMP5:%.*]] = getelementptr inbounds [[STRUCT_KMP_TASK_T_WITH_PRIVATES:%.*]], ptr [[TMP1]], i64 0, i32 1
47+
// CHECK-NEXT: [[TMP6:%.*]] = getelementptr inbounds [[STRUCT_KMP_TASK_T_WITH_PRIVATES]], ptr [[TMP1]], i64 0, i32 1, i32 2
48+
// CHECK-NEXT: [[TMP7:%.*]] = getelementptr inbounds [[STRUCT_KMP_TASK_T_WITH_PRIVATES]], ptr [[TMP1]], i64 0, i32 1, i32 1
49+
// CHECK-NEXT: [[TMP8:%.*]] = load ptr, ptr [[TMP5]], align 8, !tbaa [[TBAA20:![0-9]+]], !alias.scope !16, !noalias !13
50+
// CHECK-NEXT: [[TMP9:%.*]] = load i32, ptr [[TMP7]], align 4, !tbaa [[TBAA18]], !alias.scope !16, !noalias !13
51+
// CHECK-NEXT: [[TMP10:%.*]] = load float, ptr [[TMP6]], align 4, !tbaa [[TBAA21:![0-9]+]], !alias.scope !16, !noalias !13
52+
// CHECK-NEXT: tail call void [[TMP8]](i32 noundef [[TMP9]], float noundef [[TMP10]]) #[[ATTR2:[0-9]+]], !noalias !19
53+
// CHECK-NEXT: br label [[DOTOMP_OUTLINED__EXIT]]
54+
// CHECK: .omp_outlined..exit:
55+
// CHECK-NEXT: ret i32 0
56+
//

0 commit comments

Comments
 (0)