mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-27 11:16:06 +00:00

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
29 lines
690 B
Plaintext
29 lines
690 B
Plaintext
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu \
|
|
// RUN: -fopenmp -emit-llvm -o - -x hip %s | FileCheck %s
|
|
|
|
#include "Inputs/cuda.h"
|
|
|
|
void foo(double) {}
|
|
__device__ void foo(int) {}
|
|
|
|
// Check foo resolves to the host function.
|
|
// CHECK-LABEL: define {{.*}}@_Z5test1v
|
|
// CHECK: call void @_Z3food(double noundef 1.000000e+00)
|
|
void test1() {
|
|
#pragma omp parallel
|
|
for (int i = 0; i < 100; i++)
|
|
foo(1);
|
|
}
|
|
|
|
// Check foo resolves to the host function.
|
|
// CHECK-LABEL: define {{.*}}@_Z5test2v
|
|
// CHECK: call void @_Z3food(double noundef 1.000000e+00)
|
|
void test2() {
|
|
auto Lambda = []() {
|
|
#pragma omp parallel
|
|
for (int i = 0; i < 100; i++)
|
|
foo(1);
|
|
};
|
|
Lambda();
|
|
}
|