1 ; ASan shouldn't instrument code added by UBSan.
3 ; RUN: opt < %s -passes=asan -S | FileCheck %s
4 ; RUN: opt < %s -passes=asan -asan-detect-invalid-pointer-cmp -S | FileCheck %s --check-prefixes=NOCMP
6 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
7 target triple = "x86_64-unknown-linux-gnu"
9 %struct.A = type { ptr }
10 declare void @__ubsan_handle_dynamic_type_cache_miss(ptr, i64, i64) uwtable
11 declare void @__ubsan_handle_pointer_overflow(ptr, i64, i64) uwtable
12 @__ubsan_vptr_type_cache = external global [128 x i64]
13 @.src = private unnamed_addr constant [19 x i8] c"tmp/ubsan/vptr.cpp\00", align 1
14 @0 = private unnamed_addr constant { i16, i16, [4 x i8] } { i16 -1, i16 0, [4 x i8] c"'A'\00" }
15 @_ZTI1A = external constant ptr
16 @1 = private unnamed_addr global { { ptr, i32, i32 }, ptr, ptr, i8 } { { ptr, i32, i32 } { ptr @.src, i32 2, i32 18 }, ptr @0, ptr @_ZTI1A, i8 4 }
17 @2 = private unnamed_addr global { { ptr, i32, i32 } } { { ptr, i32, i32 } { ptr @.src, i32 24, i32 25 } }
19 define void @_Z3BarP1A(ptr %a) uwtable sanitize_address {
20 ; CHECK-LABEL: define void @_Z3BarP1A
22 %vtable = load ptr, ptr %a, align 8
23 ; CHECK: __asan_report_load8
24 %0 = load ptr, ptr %vtable, align 8
25 ; CHECK: __asan_report_load8
26 %1 = ptrtoint ptr %vtable to i64
27 %2 = xor i64 %1, -303164226014115343, !nosanitize !0
28 %3 = mul i64 %2, -7070675565921424023, !nosanitize !0
29 %4 = lshr i64 %3, 47, !nosanitize !0
30 %5 = xor i64 %3, %1, !nosanitize !0
31 %6 = xor i64 %5, %4, !nosanitize !0
32 %7 = mul i64 %6, -7070675565921424023, !nosanitize !0
33 %8 = lshr i64 %7, 47, !nosanitize !0
34 %9 = xor i64 %8, %7, !nosanitize !0
35 %10 = mul i64 %9, -7070675565921424023, !nosanitize !0
36 %11 = and i64 %10, 127, !nosanitize !0
37 %12 = getelementptr inbounds [128 x i64], ptr @__ubsan_vptr_type_cache, i64 0, i64 %11, !nosanitize !0
38 ; CHECK-NOT: __asan_report_load8
39 %13 = load i64, ptr %12, align 8, !nosanitize !0
40 %14 = icmp eq i64 %13, %10, !nosanitize !0
41 br i1 %14, label %cont, label %handler.dynamic_type_cache_miss, !nosanitize !0
43 handler.dynamic_type_cache_miss: ; preds = %entry
44 %15 = ptrtoint ptr %a to i64, !nosanitize !0
45 tail call void @__ubsan_handle_dynamic_type_cache_miss(ptr @1, i64 %15, i64 %10) #2, !nosanitize !0
46 br label %cont, !nosanitize !0
48 cont: ; preds = %handler.dynamic_type_cache_miss, %entry
49 tail call void %0(ptr %a)
54 define void @_Z3foov() uwtable sanitize_address {
55 ; NOCMP-LABEL: define void @_Z3foov
57 %bar = alloca [10 x i8], align 1
58 %arrayidx = getelementptr inbounds [10 x i8], ptr %bar, i64 0, i64 4
59 %0 = ptrtoint ptr %bar to i64, !nosanitize !0
60 ; NOCMP-NOT: call void @__sanitizer_ptr_cmp
61 %1 = icmp ult ptr %bar, inttoptr (i64 -4 to ptr), !nosanitize !0
62 br i1 %1, label %cont, label %handler.pointer_overflow, !nosanitize !0
64 handler.pointer_overflow: ; preds = %entry
65 %2 = add i64 %0, 4, !nosanitize !0
66 call void @__ubsan_handle_pointer_overflow(ptr @2, i64 %0, i64 %2), !nosanitize !0
67 br label %cont, !nosanitize !0
69 cont: ; preds = %handler.pointer_overflow, %entry
70 store i8 0, ptr %arrayidx, align 1