Skip to content

Commit 800f263

Browse files
committed
[CUDA][HIP] Fix delete operator for -fopenmp
When new operator is called in OpenMP parallel region, delete operator is resolved and checked. Due to similar issue fixed by https://reviews.llvm.org/D121765, when resolving delete operator, the caller was not determined correctly, which results in error as shown in https://godbolt.org/z/jKhd8qKos. This patch fixes the issue in a similar way as https://reviews.llvm.org/D121765 Reviewed by: Artem Belevich Differential Revision: https://reviews.llvm.org/D123976
1 parent 3de29ad commit 800f263

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

clang/lib/Sema/SemaExprCXX.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1597,7 +1597,7 @@ Sema::BuildCXXTypeConstructExpr(TypeSourceInfo *TInfo,
15971597

15981598
bool Sema::isUsualDeallocationFunction(const CXXMethodDecl *Method) {
15991599
// [CUDA] Ignore this function, if we can't call it.
1600-
const FunctionDecl *Caller = dyn_cast<FunctionDecl>(CurContext);
1600+
const FunctionDecl *Caller = getCurFunctionDecl(/*AllowLambda=*/true);
16011601
if (getLangOpts().CUDA) {
16021602
auto CallPreference = IdentifyCUDAPreference(Caller, Method);
16031603
// If it's not callable at all, it's not the right function.
@@ -1691,7 +1691,7 @@ namespace {
16911691

16921692
// In CUDA, determine how much we'd like / dislike to call this.
16931693
if (S.getLangOpts().CUDA)
1694-
if (auto *Caller = dyn_cast<FunctionDecl>(S.CurContext))
1694+
if (auto *Caller = S.getCurFunctionDecl(/*AllowLambda=*/true))
16951695
CUDAPref = S.IdentifyCUDAPreference(Caller, FD);
16961696
}
16971697

@@ -2830,7 +2830,8 @@ bool Sema::FindAllocationFunctions(SourceLocation StartLoc, SourceRange Range,
28302830
}
28312831

28322832
if (getLangOpts().CUDA)
2833-
EraseUnwantedCUDAMatches(dyn_cast<FunctionDecl>(CurContext), Matches);
2833+
EraseUnwantedCUDAMatches(getCurFunctionDecl(/*AllowLambda=*/true),
2834+
Matches);
28342835
} else {
28352836
// C++1y [expr.new]p22:
28362837
// For a non-placement allocation function, the normal deallocation
Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// RUN: %clang_cc1 -fopenmp -fsyntax-only -verify %s
2+
// RUN: %clang_cc1 -fopenmp -fexceptions -fsyntax-only -verify %s
23

34
#include "Inputs/cuda.h"
45

@@ -7,13 +8,17 @@ __device__ void foo(int) {} // expected-note {{candidate function not viable: ca
78

89
int main() {
910
#pragma omp parallel
10-
for (int i = 0; i < 100; i++)
11+
for (int i = 0; i < 100; i++) {
1112
foo(1); // expected-error {{no matching function for call to 'foo'}}
12-
13+
new int;
14+
}
15+
1316
auto Lambda = []() {
1417
#pragma omp parallel
15-
for (int i = 0; i < 100; i++)
18+
for (int i = 0; i < 100; i++) {
1619
foo(1); // expected-error {{reference to __device__ function 'foo' in __host__ __device__ function}}
17-
};
20+
new int;
21+
}
22+
};
1823
Lambda(); // expected-note {{called by 'main'}}
1924
}

0 commit comments

Comments
 (0)