CUDA/HIP determines whether a function can be called based on the device/host attributes of callee and caller. Clang assumes the caller is CurContext. This is correct in most cases, however, it is not correct in OpenMP parallel region when CUDA/HIP program is compiled with -fopenmp. This causes incorrect overloading resolution and missed diagnostics. To get the correct caller, clang needs to chase the parent chain of DeclContext starting from CurContext until a function decl or a lambda decl is reached. Sema API is adapted to achieve that and used to determine the caller in hostness check. Reviewed by: Artem Belevich, Richard Smith Differential Revision: https://reviews.llvm.org/D121765
20 lines
648 B
Plaintext
20 lines
648 B
Plaintext
// RUN: %clang_cc1 -fopenmp -fsyntax-only -verify %s
|
|
|
|
#include "Inputs/cuda.h"
|
|
|
|
__device__ void foo(int) {} // expected-note {{candidate function not viable: call to __device__ function from __host__ function}}
|
|
// expected-note@-1 {{'foo' declared here}}
|
|
|
|
int main() {
|
|
#pragma omp parallel
|
|
for (int i = 0; i < 100; i++)
|
|
foo(1); // expected-error {{no matching function for call to 'foo'}}
|
|
|
|
auto Lambda = []() {
|
|
#pragma omp parallel
|
|
for (int i = 0; i < 100; i++)
|
|
foo(1); // expected-error {{reference to __device__ function 'foo' in __host__ __device__ function}}
|
|
};
|
|
Lambda(); // expected-note {{called by 'main'}}
|
|
}
|