OSDN Git Service

1163dbe72debad7b8384bd019d9ce37d907ead87
[android-x86/external-llvm.git] / test / Instrumentation / HWAddressSanitizer / prologue.ll
1 ; Test -hwasan-with-ifunc flag.
2 ;
3 ; RUN: opt -hwasan -hwasan-allow-ifunc -S < %s | \
4 ; RUN:     FileCheck %s --check-prefixes=CHECK,CHECK-NOGLOBAL,CHECK-TLS,CHECK-HISTORY
5 ; RUN: opt -hwasan -hwasan-allow-ifunc -S -hwasan-with-ifunc=0 -hwasan-with-tls=1 -hwasan-record-stack-history=1 < %s | \
6 ; RUN:     FileCheck %s --check-prefixes=CHECK,CHECK-NOGLOBAL,CHECK-TLS,CHECK-HISTORY
7 ; RUN: opt -hwasan -hwasan-allow-ifunc -S -hwasan-with-ifunc=0 -hwasan-with-tls=1 -hwasan-record-stack-history=0 < %s | \
8 ; RUN:     FileCheck %s --check-prefixes=CHECK,CHECK-NOGLOBAL,CHECK-IFUNC,CHECK-NOHISTORY
9 ; RUN: opt -hwasan -hwasan-allow-ifunc -S -hwasan-with-ifunc=0 -hwasan-with-tls=0 < %s | \
10 ; RUN:     FileCheck %s --check-prefixes=CHECK,CHECK-GLOBAL,CHECK-NOHISTORY
11 ; RUN: opt -hwasan -hwasan-allow-ifunc -S -hwasan-with-ifunc=1  -hwasan-with-tls=0 < %s | \
12 ; RUN:     FileCheck %s --check-prefixes=CHECK,CHECk-NOGLOBAL,CHECK-IFUNC,CHECK-NOHISTORY
13
14 target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
15 target triple = "aarch64--linux-android22"
16
17 ; CHECK-IFUNC: @__hwasan_shadow = external global [0 x i8]
18 ; CHECK-NOIFUNC: @__hwasan_shadow_memory_dynamic_address = external global i64
19
20 define i32 @test_load(i32* %a) sanitize_hwaddress {
21 ; First instrumentation in the function must be to load the dynamic shadow
22 ; address into a local variable.
23 ; CHECK-LABEL: @test_load
24 ; CHECK: entry:
25
26 ; CHECK-NOGLOBAL:   %[[A:[^ ]*]] = call i8* asm "", "=r,0"([0 x i8]* @__hwasan_shadow)
27 ; CHECK-NOGLOBAL:   @llvm.hwasan.check.memaccess(i8* %[[A]]
28
29 ; CHECK-GLOBAL: load i8*, i8** @__hwasan_shadow_memory_dynamic_address
30
31 ; "store i64" is only used to update stack history (this input IR intentionally does not use any i64)
32 ; W/o any allocas, the history is not updated, even if it is enabled explicitly with -hwasan-record-stack-history=1
33 ; CHECK-NOT: store i64
34
35 ; CHECK: ret i32
36
37 entry:
38   %x = load i32, i32* %a, align 4
39   ret i32 %x
40 }
41
42 declare void @use(i32* %p)
43
44 define void @test_alloca() sanitize_hwaddress {
45 ; First instrumentation in the function must be to load the dynamic shadow
46 ; address into a local variable.
47 ; CHECK-LABEL: @test_alloca
48 ; CHECK: entry:
49
50 ; CHECK-IFUNC:   %[[A:[^ ]*]] = call i8* asm "", "=r,0"([0 x i8]* @__hwasan_shadow)
51 ; CHECK-IFUNC:   getelementptr i8, i8* %[[A]]
52
53 ; CHECK-GLOBAL: load i8*, i8** @__hwasan_shadow_memory_dynamic_address
54
55 ; CHECK-TLS:   %[[A:[^ ]*]] = call i8* @llvm.thread.pointer()
56 ; CHECK-TLS:   %[[B:[^ ]*]] = getelementptr i8, i8* %[[A]], i32 48
57 ; CHECK-TLS:   %[[C:[^ ]*]] = bitcast i8* %[[B]] to i64*
58 ; CHECK-TLS:   %[[D:[^ ]*]] = load i64, i64* %[[C]]
59
60 ; CHECK-NOHISTORY-NOT: store i64
61
62 ; CHECK-HISTORY: %[[PTR:[^ ]*]] = inttoptr i64 %[[D]] to i64*
63 ; CHECK-HISTORY: store i64 %{{.*}}, i64* %[[PTR]]
64 ; CHECK-HISTORY: %[[D1:[^ ]*]] = ashr i64 %[[D]], 56
65 ; CHECK-HISTORY: %[[D2:[^ ]*]] = shl nuw nsw i64 %[[D1]], 12
66 ; CHECK-HISTORY: %[[D3:[^ ]*]] = xor i64 %[[D2]], -1
67 ; CHECK-HISTORY: %[[D4:[^ ]*]] = add i64 %[[D]], 8
68 ; CHECK-HISTORY: %[[D5:[^ ]*]] = and i64 %[[D4]], %[[D3]]
69 ; CHECK-HISTORY: store i64 %[[D5]], i64* %[[C]]
70
71 ; CHECK-TLS:   %[[E:[^ ]*]] = or i64 %[[D]], 4294967295
72 ; CHECK-TLS:   = add i64 %[[E]], 1
73
74 ; CHECK-NOHISTORY-NOT: store i64
75
76
77 entry:
78   %x = alloca i32, align 4
79   call void @use(i32* %x)
80   ret void
81 }