diff --git a/clang/lib/Headers/openmp_wrappers/__clang_openmp_device_functions.h b/clang/lib/Headers/openmp_wrappers/__clang_openmp_device_functions.h --- a/clang/lib/Headers/openmp_wrappers/__clang_openmp_device_functions.h +++ b/clang/lib/Headers/openmp_wrappers/__clang_openmp_device_functions.h @@ -14,6 +14,12 @@ #error "This file is for OpenMP compilation only." #endif +#ifdef __cplusplus +// Ensure we make `_ZdlPv`, aka. `operator delete(void*)` available without the +// need to `include `. +#include +#endif + #pragma omp begin declare variant match( \ device = {arch(nvptx, nvptx64)}, implementation = {extension(match_any)}) diff --git a/clang/lib/Headers/openmp_wrappers/new b/clang/lib/Headers/openmp_wrappers/new --- a/clang/lib/Headers/openmp_wrappers/new +++ b/clang/lib/Headers/openmp_wrappers/new @@ -11,7 +11,7 @@ #include_next -#if defined(__NVPTX__) && defined(_OPENMP) +#if defined(_OPENMP) #include diff --git a/clang/test/Headers/Inputs/include/cstdlib b/clang/test/Headers/Inputs/include/cstdlib --- a/clang/test/Headers/Inputs/include/cstdlib +++ b/clang/test/Headers/Inputs/include/cstdlib @@ -2,6 +2,9 @@ #include +void *malloc(size_t); +void free(void*); + #if __cplusplus >= 201703L extern int abs (int __x) throw() __attribute__ ((__const__)) ; extern long int labs (long int __x) throw() __attribute__ ((__const__)) ; diff --git a/clang/test/Headers/Inputs/include/new b/clang/test/Headers/Inputs/include/new new file mode 100644 --- /dev/null +++ b/clang/test/Headers/Inputs/include/new @@ -0,0 +1,7 @@ + +namespace std +{ + +struct nothrow_t { explicit nothrow_t() = default; }; + +} diff --git a/clang/test/Headers/target_include_new.cpp b/clang/test/Headers/target_include_new.cpp new file mode 100644 --- /dev/null +++ b/clang/test/Headers/target_include_new.cpp @@ -0,0 +1,32 @@ +// RUN: %clang_cc1 -internal-isystem %S/../../lib/Headers/openmp_wrappers -include __clang_openmp_device_functions.h -internal-isystem %S/Inputs/include -verify -fopenmp -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=nvptx64 -emit-llvm-bc %s -o %t-ppc-host.bc +// RUN: %clang_cc1 -internal-isystem %S/../../lib/Headers/openmp_wrappers -include __clang_openmp_device_functions.h -internal-isystem %S/Inputs/include -verify -fopenmp -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=nvptx64 -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o - | FileCheck %s +// expected-no-diagnostics + +// Ensure we make `_ZdlPv`, aka. `operator delete(void*)` available without the need to `include `. + +// CHECK: define {{.*}}_ZdlPv + +#ifndef HEADER +#define HEADER + +class Base { + public: + virtual ~Base() = default; +}; + +class Derived : public Base { + public: + #pragma omp declare target + Derived(); + #pragma omp end declare target +}; + +Derived::Derived() { } + +int main(void) { + #pragma omp target + { + } + return 0; +} +#endif