1 ; RUN: opt < %s -passes=asan -S | FileCheck %s
2 ; RUN: opt < %s -passes=asan -asan-mapping-scale=5 -S | FileCheck %s
3 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"
4 target triple = "x86_64-unknown-linux-gnu"
5 @xxx = internal global i32 0, align 4, sanitize_address_dyninit ; With dynamic initializer.
6 @XXX = global i32 0, align 4, sanitize_address_dyninit ; With dynamic initializer.
7 @yyy = internal global i32 0, align 4 ; W/o dynamic initializer.
8 @YYY = global i32 0, align 4 ; W/o dynamic initializer.
10 define i32 @initializer() uwtable {
15 define internal void @__cxx_global_var_init() section ".text.startup" {
17 %call = call i32 @initializer()
18 store i32 %call, ptr @xxx, align 4
22 @llvm.global_ctors = appending global [2 x { i32, ptr, ptr }] [{ i32, ptr, ptr } { i32 65535, ptr @__late_ctor, ptr null }, { i32, ptr, ptr } { i32 0, ptr @__early_ctor, ptr null }]
24 define internal void @__late_ctor() sanitize_address section ".text.startup" {
26 call void @__cxx_global_var_init()
30 ; Clang indicated that @xxx was dynamically initailized.
31 ; __asan_{before,after}_dynamic_init should be called from __late_ctor
33 ; CHECK-LABEL: define internal void @__late_ctor
35 ; CHECK: call void @__asan_before_dynamic_init
36 ; CHECK: call void @__cxx_global_var_init
37 ; CHECK: call void @__asan_after_dynamic_init
40 ; CTOR with priority 0 should not be instrumented.
41 define internal void @__early_ctor() sanitize_address section ".text.startup" {
43 call void @__cxx_global_var_init()
46 ; CHECK-LABEL: define internal void @__early_ctor
50 ; Check that xxx is instrumented.
51 define void @touch_xxx() sanitize_address {
52 store i32 0, ptr @xxx, align 4
54 ; CHECK-LABEL: touch_xxx
55 ; CHECK: call void @__asan_report_store4
59 ; Check that XXX is instrumented.
60 define void @touch_XXX() sanitize_address {
61 store i32 0, ptr @XXX, align 4
63 ; CHECK: define void @touch_XXX
64 ; CHECK: call void @__asan_report_store4
69 ; Check that yyy is NOT instrumented (as it does not have dynamic initializer).
70 define void @touch_yyy() sanitize_address {
71 store i32 0, ptr @yyy, align 4
73 ; CHECK: define void @touch_yyy
74 ; CHECK-NOT: call void @__asan_report_store4
78 ; Check that YYY is NOT instrumented (as it does not have dynamic initializer).
79 define void @touch_YYY() sanitize_address {
80 store i32 0, ptr @YYY, align 4
82 ; CHECK: define void @touch_YYY
83 ; CHECK-NOT: call void @__asan_report_store4