[PATCH] D104392: [HIP] Add support functions for C++ polymorphic types

Yaxun Liu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Jun 21 08:41:45 PDT 2021


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG186f2ac612ad: [HIP] Add support functions for C++ polymorphic types (authored by yaxunl).

Changed prior to commit:
  https://reviews.llvm.org/D104392?vs=353041&id=353388#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D104392/new/

https://reviews.llvm.org/D104392

Files:
  clang/lib/Headers/__clang_hip_runtime_wrapper.h
  clang/test/Headers/hip-header.hip


Index: clang/test/Headers/hip-header.hip
===================================================================
--- clang/test/Headers/hip-header.hip
+++ clang/test/Headers/hip-header.hip
@@ -14,6 +14,29 @@
 
 // expected-no-diagnostics
 
+// Check support for pure and deleted virtual functions
+struct base {
+  __host__
+  __device__
+  virtual void pv() = 0;
+  __host__
+  __device__
+  virtual void dv() = delete;
+};
+struct derived:base {
+  __host__
+  __device__
+  virtual void pv() override {};
+};
+__device__ void test_vf() {
+    derived d;
+}
+// CHECK: @_ZTV7derived = linkonce_odr unnamed_addr addrspace(1) constant { [4 x i8*] } { [4 x i8*] [i8* null, i8* null, i8* bitcast (void (%struct.derived*)* @_ZN7derived2pvEv to i8*), i8* bitcast (void ()* @__cxa_deleted_virtual to i8*)] }, comdat, align 8
+// CHECK: @_ZTV4base = linkonce_odr unnamed_addr addrspace(1) constant { [4 x i8*] } { [4 x i8*] [i8* null, i8* null, i8* bitcast (void ()* @__cxa_pure_virtual to i8*), i8* bitcast (void ()* @__cxa_deleted_virtual to i8*)] }, comdat, align 8
+
+// CHECK: define{{.*}}void @__cxa_pure_virtual()
+// CHECK: define{{.*}}void @__cxa_deleted_virtual()
+
 struct Number {
   __device__ Number(float _x) : x(_x) {}
   float x;
Index: clang/lib/Headers/__clang_hip_runtime_wrapper.h
===================================================================
--- clang/lib/Headers/__clang_hip_runtime_wrapper.h
+++ clang/lib/Headers/__clang_hip_runtime_wrapper.h
@@ -51,6 +51,23 @@
   #define nullptr NULL;
 #endif
 
+#ifdef __cplusplus
+extern "C" {
+  __attribute__((__visibility__("default")))
+  __attribute__((weak))
+  __attribute__((noreturn))
+  __device__ void __cxa_pure_virtual(void) {
+    __builtin_trap();
+  }
+  __attribute__((__visibility__("default")))
+  __attribute__((weak))
+  __attribute__((noreturn))
+  __device__ void __cxa_deleted_virtual(void) {
+    __builtin_trap();
+  }
+}
+#endif //__cplusplus
+
 #if __HIP_ENABLE_DEVICE_MALLOC__
 extern "C" __device__ void *__hip_malloc(size_t __size);
 extern "C" __device__ void *__hip_free(void *__ptr);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D104392.353388.patch
Type: text/x-patch
Size: 2076 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210621/f3b1fe6f/attachment.bin>


More information about the cfe-commits mailing list