1 // RUN: %clang_cc1 -std=c++11 -triple x86_64-unknown-linux -emit-llvm -fsanitize=null %s -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-NULL --check-prefix=ITANIUM 2 // RUN: %clang_cc1 -std=c++11 -triple x86_64-windows -emit-llvm -fsanitize=null %s -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-NULL --check-prefix=MSABI 3 // RUN: %clang_cc1 -std=c++11 -triple x86_64-unknown-linux -emit-llvm -fsanitize=vptr %s -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-VPTR --check-prefix=ITANIUM 4 // RUN: %clang_cc1 -std=c++11 -triple x86_64-windows -emit-llvm -fsanitize=vptr %s -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-VPTR --check-prefix=MSABI 5 struct T { 6 virtual ~T() {} 7 virtual int v() { return 1; } 8 }; 9 10 struct U : T { 11 ~U(); 12 virtual int v() { return 2; } 13 }; 14 15 U::~U() {} 16 17 // ITANIUM: define i32 @_Z5get_vP1T 18 // MSABI: define i32 @"\01?get_v 19 int get_v(T* t) { 20 // First, we check that vtable is not loaded before a type check. 21 // CHECK-NULL-NOT: load {{.*}} (%struct.T*{{.*}})**, {{.*}} (%struct.T*{{.*}})*** 22 // CHECK-NULL: [[UBSAN_CMP_RES:%[0-9]+]] = icmp ne %struct.T* %{{[_a-z0-9]+}}, null 23 // CHECK-NULL-NEXT: br i1 [[UBSAN_CMP_RES]], label %{{.*}}, label %{{.*}} 24 // CHECK-NULL: call void @__ubsan_handle_type_mismatch_v1_abort 25 // Second, we check that vtable is actually loaded once the type check is done. 26 // CHECK-NULL: load {{.*}} (%struct.T*{{.*}})**, {{.*}} (%struct.T*{{.*}})*** 27 return t->v(); 28 } 29 30 // ITANIUM: define void @_Z9delete_itP1T 31 // MSABI: define void @"\01?delete_it 32 void delete_it(T *t) { 33 // First, we check that vtable is not loaded before a type check. 34 // CHECK-VPTR-NOT: load {{.*}} (%struct.T*{{.*}})**, {{.*}} (%struct.T*{{.*}})*** 35 // CHECK-VPTR: br i1 {{.*}} label %{{.*}} 36 // CHECK-VPTR: call void @__ubsan_handle_dynamic_type_cache_miss_abort 37 // Second, we check that vtable is actually loaded once the type check is done. 38 // CHECK-VPTR: load {{.*}} (%struct.T*{{.*}})**, {{.*}} (%struct.T*{{.*}})*** 39 delete t; 40 } 41