forked from OSchip/llvm-project
[HIP] Add support functions for C++ polymorphic types
Add runtime functions to detect invalid calls to pure or deleted virtual functions. Patch by: Siu Chi Chan Reviewed by: Yaxun Liu Differential Revision: https://reviews.llvm.org/D104392
This commit is contained in:
parent
c02160c17b
commit
186f2ac612
|
@ -51,6 +51,23 @@ typedef __SIZE_TYPE__ size_t;
|
|||
#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);
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue