jdoerfert created this revision. jdoerfert added reviewers: JonChesterfield, ABataev, grokos. Herald added subscribers: guansong, yaxunl. Herald added a reviewer: bollu. jdoerfert requested review of this revision. Herald added subscribers: cfe-commits, sstefan1. Herald added a project: clang.
We do provide `operator delete(void*)` in `<new>` but it should be available by default. This is mostly boilerplate to test it and the unconditional include of `<new>` in the header we always in include on the device. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D100620 Files: clang/lib/Headers/openmp_wrappers/__clang_openmp_device_functions.h clang/lib/Headers/openmp_wrappers/new clang/test/Headers/Inputs/include/cstdlib clang/test/Headers/Inputs/include/new clang/test/Headers/target_include_new.cpp Index: clang/test/Headers/target_include_new.cpp =================================================================== --- /dev/null +++ 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 <new>`. + +// 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 Index: clang/test/Headers/Inputs/include/new =================================================================== --- /dev/null +++ clang/test/Headers/Inputs/include/new @@ -0,0 +1,7 @@ + +namespace std +{ + +struct nothrow_t { explicit nothrow_t() = default; }; + +} Index: clang/test/Headers/Inputs/include/cstdlib =================================================================== --- clang/test/Headers/Inputs/include/cstdlib +++ clang/test/Headers/Inputs/include/cstdlib @@ -2,6 +2,9 @@ #include <stdlib.h> +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__)) ; Index: clang/lib/Headers/openmp_wrappers/new =================================================================== --- clang/lib/Headers/openmp_wrappers/new +++ clang/lib/Headers/openmp_wrappers/new @@ -11,7 +11,7 @@ #include_next <new> -#if defined(__NVPTX__) && defined(_OPENMP) +#if defined(_OPENMP) #include <cstdlib> Index: clang/lib/Headers/openmp_wrappers/__clang_openmp_device_functions.h =================================================================== --- clang/lib/Headers/openmp_wrappers/__clang_openmp_device_functions.h +++ 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 <new>`. +#include <new> +#endif + #pragma omp begin declare variant match( \ device = {arch(nvptx, nvptx64)}, implementation = {extension(match_any)})
Index: clang/test/Headers/target_include_new.cpp =================================================================== --- /dev/null +++ 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 <new>`. + +// 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 Index: clang/test/Headers/Inputs/include/new =================================================================== --- /dev/null +++ clang/test/Headers/Inputs/include/new @@ -0,0 +1,7 @@ + +namespace std +{ + +struct nothrow_t { explicit nothrow_t() = default; }; + +} Index: clang/test/Headers/Inputs/include/cstdlib =================================================================== --- clang/test/Headers/Inputs/include/cstdlib +++ clang/test/Headers/Inputs/include/cstdlib @@ -2,6 +2,9 @@ #include <stdlib.h> +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__)) ; Index: clang/lib/Headers/openmp_wrappers/new =================================================================== --- clang/lib/Headers/openmp_wrappers/new +++ clang/lib/Headers/openmp_wrappers/new @@ -11,7 +11,7 @@ #include_next <new> -#if defined(__NVPTX__) && defined(_OPENMP) +#if defined(_OPENMP) #include <cstdlib> Index: clang/lib/Headers/openmp_wrappers/__clang_openmp_device_functions.h =================================================================== --- clang/lib/Headers/openmp_wrappers/__clang_openmp_device_functions.h +++ 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 <new>`. +#include <new> +#endif + #pragma omp begin declare variant match( \ device = {arch(nvptx, nvptx64)}, implementation = {extension(match_any)})
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits