[PATCH] D130503: [ASan] Use stack safety analysis to optimize allocas instrumentation.

Kirill Stoimenov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 25 10:49:39 PDT 2022


kstoimenov created this revision.
Herald added subscribers: Enna1, hiraditya.
Herald added a project: All.
kstoimenov requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Added missing alloca optimization which was missed during the implemenation of D112098 <https://reviews.llvm.org/D112098>.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D130503

Files:
  llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
  llvm/test/Instrumentation/AddressSanitizer/asan-stack-safety.ll


Index: llvm/test/Instrumentation/AddressSanitizer/asan-stack-safety.ll
===================================================================
--- llvm/test/Instrumentation/AddressSanitizer/asan-stack-safety.ll
+++ llvm/test/Instrumentation/AddressSanitizer/asan-stack-safety.ll
@@ -8,10 +8,13 @@
 ; NOSAFETY: call void @__asan_store1
 ; NOSAFETY: call void @__asan_store1
 ; NOSAFETY: call void @__asan_store1
+; NOSAFETY: call void @__asan_store1
 ; SAFETY-NOT: call void @__asan_load1
 ; SAFETY-NOT: call void @__asan_store1
 ; SAFETY-NOT: call void @__asan_store1
 ; SAFETY-NOT: call void @__asan_store1
+; SAFETY-NOT: call void @__asan_store1
+
 
 define i32 @load() sanitize_address {
   %buf = alloca [10 x i8], align 1
@@ -27,6 +30,14 @@
   ret i32 0
 }
 
+define i32 @alloca() sanitize_address {
+  %buf.sroa.0 = alloca [10 x i8], align 4
+  %ptr = getelementptr [10 x i8], [10 x i8]* %buf.sroa.0, i32 0, i32 0
+  call void @llvm.lifetime.start.p0i8(i64 10, i8* nonnull %ptr)
+  store volatile i8 0, i8* %ptr, align 4, !tbaa !8
+  call void @llvm.lifetime.end.p0i8(i64 10, i8* nonnull %ptr)
+  ret i32 0
+}
 
 define void @atomicrmw() sanitize_address {
   %buf = alloca [10 x i8], align 1
@@ -41,3 +52,12 @@
   %1 = cmpxchg i8* %arrayidx, i8 %compare_to, i8 %new_value seq_cst seq_cst
   ret void
 }
+
+; Function Attrs: argmemonly mustprogress nofree nosync nounwind willreturn
+declare void @llvm.lifetime.start.p0i8(i64 immarg, i8* nocapture)
+; Function Attrs: argmemonly mustprogress nofree nosync nounwind willreturn
+declare void @llvm.lifetime.end.p0i8(i64 immarg, i8* nocapture)
+
+!8 = !{!9, !9, i64 0}
+!9 = !{!"omnipotent char", !10, i64 0}
+!10 = !{!"Simple C/C++ TBAA"}
Index: llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
===================================================================
--- llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
+++ llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
@@ -1232,7 +1232,9 @@
        // dynamic alloca instrumentation for them as well.
        !AI.isUsedWithInAlloca() &&
        // swifterror allocas are register promoted by ISel
-       !AI.isSwiftError());
+       !AI.isSwiftError() &&
+       // safe allocas are not interesting
+       !(SSGI && SSGI->isSafe(AI)));
 
   ProcessedAllocas[&AI] = IsInteresting;
   return IsInteresting;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D130503.447408.patch
Type: text/x-patch
Size: 2332 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220725/044f3293/attachment.bin>


More information about the llvm-commits mailing list