[Openmp-commits] [PATCH] D100620: [OpenMP] Make sure classes work on the device as they do on the host

Johannes Doerfert via Phabricator via Openmp-commits openmp-commits at lists.llvm.org
Thu Apr 15 22:37:44 PDT 2021


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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D100620.337987.patch
Type: text/x-patch
Size: 3048 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20210416/2619f7c2/attachment-0001.bin>


More information about the Openmp-commits mailing list