1 // REQUIRES: x86-registered-target 2 // REQUIRES: nvptx-registered-target 3 4 // Make sure we don't emit vtables for classes with methods that have 5 // inappropriate target attributes. Currently it's mostly needed in 6 // order to avoid emitting vtables for host-only classes on device 7 // side where we can't codegen them. 8 9 // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm -o - %s \ 10 // RUN: | FileCheck %s -check-prefix=CHECK-HOST -check-prefix=CHECK-BOTH 11 // RUN: %clang_cc1 -triple nvptx64-nvidia-cuda -fcuda-is-device -emit-llvm -o - %s \ 12 // RUN: | FileCheck %s -check-prefix=CHECK-DEVICE -check-prefix=CHECK-BOTH 13 14 #include "Inputs/cuda.h" 15 16 struct H { 17 virtual void method(); 18 }; 19 //CHECK-HOST: @_ZTV1H = 20 //CHECK-HOST-SAME: @_ZN1H6methodEv 21 //CHECK-DEVICE-NOT: @_ZTV1H = 22 23 struct D { 24 __device__ virtual void method(); 25 }; 26 27 //CHECK-DEVICE: @_ZTV1D 28 //CHECK-DEVICE-SAME: @_ZN1D6methodEv 29 //CHECK-HOST-NOT: @_ZTV1D 30 31 // This is the case with mixed host and device virtual methods. It's 32 // impossible to emit a valid vtable in that case because only host or 33 // only device methods would be available during host or device 34 // compilation. At the moment Clang (and NVCC) emit NULL pointers for 35 // unavailable methods, 36 struct HD { 37 virtual void h_method(); 38 __device__ virtual void d_method(); 39 }; 40 // CHECK-BOTH: @_ZTV2HD 41 // CHECK-DEVICE-NOT: @_ZN2HD8h_methodEv 42 // CHECK-DEVICE-SAME: null 43 // CHECK-DEVICE-SAME: @_ZN2HD8d_methodEv 44 // CHECK-HOST-SAME: @_ZN2HD8h_methodEv 45 // CHECK-HOST-NOT: @_ZN2HD8d_methodEv 46 // CHECK-HOST-SAME: null 47 // CHECK-BOTH-SAME: ] 48 49 void H::method() {} 50 //CHECK-HOST: define void @_ZN1H6methodEv 51 52 void __device__ D::method() {} 53 //CHECK-DEVICE: define void @_ZN1D6methodEv 54 55 void __device__ HD::d_method() {} 56 // CHECK-DEVICE: define void @_ZN2HD8d_methodEv 57 // CHECK-HOST-NOT: define void @_ZN2HD8d_methodEv 58 void HD::h_method() {} 59 // CHECK-HOST: define void @_ZN2HD8h_methodEv 60 // CHECK-DEVICE-NOT: define void @_ZN2HD8h_methodEv 61 62