[llvm] 5dfcb3e - [asan, test] Improve tests to ensure instrumentation even in the presence of StackSafetyAnalysis
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Sat Jan 6 19:57:49 PST 2024
Author: Fangrui Song
Date: 2024-01-06T19:57:45-08:00
New Revision: 5dfcb3e5d1d16bb4f8fce52b3c089119ed977e7f
URL: https://github.com/llvm/llvm-project/commit/5dfcb3e5d1d16bb4f8fce52b3c089119ed977e7f
DIFF: https://github.com/llvm/llvm-project/commit/5dfcb3e5d1d16bb4f8fce52b3c089119ed977e7f.diff
LOG: [asan,test] Improve tests to ensure instrumentation even in the presence of StackSafetyAnalysis
Added:
Modified:
llvm/test/Instrumentation/AddressSanitizer/debug_info_noninstrumented_alloca2.ll
llvm/test/Instrumentation/AddressSanitizer/hoist-argument-init-insts.ll
llvm/test/Instrumentation/AddressSanitizer/lifetime.ll
Removed:
################################################################################
diff --git a/llvm/test/Instrumentation/AddressSanitizer/debug_info_noninstrumented_alloca2.ll b/llvm/test/Instrumentation/AddressSanitizer/debug_info_noninstrumented_alloca2.ll
index dff4e4be4acfc8..fb37b8742365dc 100644
--- a/llvm/test/Instrumentation/AddressSanitizer/debug_info_noninstrumented_alloca2.ll
+++ b/llvm/test/Instrumentation/AddressSanitizer/debug_info_noninstrumented_alloca2.ll
@@ -1,17 +1,18 @@
; Make sure we don't break the IR when moving non-instrumented allocas
-; RUN: opt < %s -passes=asan -S | FileCheck %s
-; RUN: opt < %s -passes=asan -asan-instrument-dynamic-allocas -S | FileCheck %s
+; RUN: opt < %s -passes=asan -asan-use-stack-safety=1 -S | FileCheck %s
+; RUN: opt < %s -passes=asan -asan-use-stack-safety=1 -asan-instrument-dynamic-allocas -S | FileCheck %s
target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-apple-macosx10.10.0"
-define i32 @foo() sanitize_address {
+define i32 @foo(i64 %i) sanitize_address {
entry:
%non_instrumented1 = alloca i32, align 4
%t = load i32, ptr %non_instrumented1, align 4
- %instrumented = alloca i32, align 4
- %ptr = ptrtoint ptr %instrumented to i32
+ %instrumented = alloca [2 x i32], align 4
+ %ai = getelementptr inbounds [2 x i32], ptr %instrumented, i64 0, i64 %i
+ store volatile i8 0, ptr %ai, align 4
ret i32 %t
}
diff --git a/llvm/test/Instrumentation/AddressSanitizer/hoist-argument-init-insts.ll b/llvm/test/Instrumentation/AddressSanitizer/hoist-argument-init-insts.ll
index 5fab725565c955..5ecd4dc7fb9430 100644
--- a/llvm/test/Instrumentation/AddressSanitizer/hoist-argument-init-insts.ll
+++ b/llvm/test/Instrumentation/AddressSanitizer/hoist-argument-init-insts.ll
@@ -1,4 +1,4 @@
-; RUN: opt < %s -passes=asan -S | FileCheck %s
+; RUN: opt < %s -passes=asan -asan-use-after-scope -asan-use-stack-safety=1 -S | FileCheck %s
; Source (-O0 -fsanitize=address -fsanitize-address-use-after-scope):
;; struct S { int x, y; };
@@ -18,15 +18,16 @@ target triple = "x86_64-apple-macosx10.14.0"
; CHECK-LABEL: define {{.*}} @_Z4swapP1SS0_b(
; First come the argument allocas.
-; CHECK: [[argA:%.*]] = alloca ptr,
-; CHECK-NEXT: [[argB:%.*]] = alloca ptr,
-; CHECK-NEXT: [[argDoit:%.*]] = alloca i8,
+; CHECK: %a.addr = alloca ptr, align 8
+; CHECK-NEXT: %b.addr = alloca ptr, align 8
+; CHECK-NEXT: %doit.addr = alloca i8, align 1
; Next, the stores into the argument allocas.
-; CHECK-NEXT: store ptr {{.*}}, ptr [[argA]]
-; CHECK-NEXT: store ptr {{.*}}, ptr [[argB]]
+; CHECK-NEXT: store ptr {{.*}}, ptr %a.addr
+; CHECK-NEXT: store ptr {{.*}}, ptr %b.addr
; CHECK-NEXT: [[frombool:%.*]] = zext i1 {{.*}} to i8
-; CHECK-NEXT: store i8 [[frombool]], ptr [[argDoit]]
+; CHECK-NEXT: store i8 %frombool, ptr %doit.addr, align 1
+; CHECK-NEXT: [[stack_base:%.*]] = alloca i64, align 8
define void @_Z4swapP1SS0_b(ptr %a, ptr %b, i1 zeroext %doit) sanitize_address {
entry:
@@ -65,9 +66,12 @@ return: ; preds = %if.end, %if.then
; CHECK: [[argA:%.*]] = alloca ptr,
; CHECK-NEXT: [[argB:%.*]] = alloca ptr,
; CHECK-NEXT: [[argDoit:%.*]] = alloca i8,
+; CHECK-NEXT: %tmp = alloca %struct.S, align 4
; CHECK-NEXT: store ptr {{.*}}, ptr [[argA]]
; CHECK-NEXT: store ptr {{.*}}, ptr [[argB]]
-; CHECK-NEXT: [[stack_base:%.*]] = alloca i64
+; CHECK-NEXT: %0 = load i8, ptr %doit.addr, align 1
+; CHECK-NEXT: %frombool = zext i1 %doit to i8
+; CHECK-NEXT: store i8 %frombool, ptr %doit.addr, align 1
define void @func_with_load_in_arginit_sequence(ptr %a, ptr %b, i1 zeroext %doit) sanitize_address {
entry:
%a.addr = alloca ptr, align 8
@@ -108,10 +112,13 @@ return: ; preds = %if.end, %if.then
; CHECK: [[argA:%.*]] = alloca ptr,
; CHECK-NEXT: [[argB:%.*]] = alloca ptr,
; CHECK-NEXT: [[argDoit:%.*]] = alloca i8,
+; CHECK-NEXT: %tmp = alloca %struct.S, align 4
+; CHECK-NEXT: %tmp2 = alloca %struct.S, align 4
; CHECK-NEXT: store ptr {{.*}}, ptr [[argA]]
; CHECK-NEXT: store ptr {{.*}}, ptr [[argB]]
; CHECK-NEXT: [[frombool:%.*]] = zext i1 {{.*}} to i8
; CHECK-NEXT: store i8 [[frombool]], ptr [[argDoit]]
+; CHECK-NEXT: %0 = load i8, ptr %doit.addr, align 1
define void @func_with_multiple_interesting_allocas(ptr %a, ptr %b, i1 zeroext %doit) sanitize_address {
entry:
%a.addr = alloca ptr, align 8
diff --git a/llvm/test/Instrumentation/AddressSanitizer/lifetime.ll b/llvm/test/Instrumentation/AddressSanitizer/lifetime.ll
index b57605a6556745..7f158487a47a15 100644
--- a/llvm/test/Instrumentation/AddressSanitizer/lifetime.ll
+++ b/llvm/test/Instrumentation/AddressSanitizer/lifetime.ll
@@ -8,23 +8,24 @@ target triple = "x86_64-unknown-linux-gnu"
declare void @llvm.lifetime.start.p0(i64, ptr nocapture) nounwind
declare void @llvm.lifetime.end.p0(i64, ptr nocapture) nounwind
-define void @lifetime_no_size() sanitize_address {
- ; CHECK-LABEL: define void @lifetime_no_size()
+; CHECK-LABEL: define void @lifetime_no_size(
+define void @lifetime_no_size(i64 %i) sanitize_address {
entry:
- %i = alloca i32, align 4
+ %a = alloca [2 x i32], align 4
- ; Poison memory in prologue: F1F1F1F104F3F3F3
- ; CHECK: store i64 -868083100587789839, ptr %{{[0-9]+}}
+ ; Poison memory in prologue: 0xf3f3f300f1f1f1f1
+ ; CHECK: store i64 -868083117767659023, ptr %[[#]]
- call void @llvm.lifetime.start.p0(i64 -1, ptr %i)
+ call void @llvm.lifetime.start.p0(i64 -1, ptr %a)
; Check that lifetime with no size are ignored.
; CHECK-NOT: store
; CHECK: call void @llvm.lifetime.start
- store volatile i8 0, ptr %i
+ %ai = getelementptr inbounds [2 x i32], ptr %a, i64 0, i64 %i
+ store volatile i8 0, ptr %ai, align 4
; CHECK: store volatile
- call void @llvm.lifetime.end.p0(i64 -1, ptr %i)
+ call void @llvm.lifetime.end.p0(i64 -1, ptr %a)
; Check that lifetime with no size are ignored.
; CHECK-NOT: store
; CHECK: call void @llvm.lifetime.end
@@ -128,24 +129,26 @@ bb1:
}
; Check that arguments of lifetime may come from getelementptr nodes.
-define void @getelementptr_args() sanitize_address{
+define void @getelementptr_args(i64 %i) sanitize_address{
; CHECK-LABEL: define void @getelementptr_args
entry:
%x = alloca [1024 x i8], align 16
- %d = alloca ptr, align 8
+ %a = alloca [2 x ptr], align 8
; F1F1F1F1
; CHECK: store i32 -235802127, ptr %{{[0-9]+}}
- ; F3F3F3F3F3F3F3F3
- ; CHECK: store i64 -868082074056920077, ptr %{{[0-9]+}}
- ; F3F3F3F3F3F3F3F3
- ; CHECK: store i64 -868082074056920077, ptr %{{[0-9]+}}
+ ; CHECK: call void @__asan_set_shadow_f8(i64 %[[#]], i64 128)
+ ; 0xf2f2f2f2f2f2f2f2
+ ; CHECK: store i64 -940422246894996750, ptr %[[#]]
+ ; 0xf2f2f2f2f2f2f2f2
+ ; CHECK: store i64 -940422246894996750, ptr %[[#]]
call void @llvm.lifetime.start.p0(i64 1024, ptr %x)
; CHECK: call void @__asan_set_shadow_00(i64 %{{[0-9]+}}, i64 128)
; CHECK-NEXT: call void @llvm.lifetime.start
- store ptr %x, ptr %d, align 8
+ %ai = getelementptr inbounds [2 x ptr], ptr %a, i64 0, i64 %i
+ store ptr %x, ptr %ai, align 8
; CHECK: store ptr
call void @llvm.lifetime.end.p0(i64 1024, ptr %x)
@@ -154,6 +157,7 @@ entry:
ret void
; CHECK: call void @__asan_set_shadow_00(i64 %{{[0-9]+}}, i64 148)
+ ; CHECK: store i16 0, ptr %[[#]], align 1
; CHECK-NEXT: ret void
}
More information about the llvm-commits
mailing list