llvm-project/clang/test/CodeGenCUDA/openmp-parallel.cu
Yaxun (Sam) Liu d41445113b [CUDA][HIP] Fix hostness check with -fopenmp
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
2022-03-24 15:19:47 -04:00

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();
}