[llvm] aa5bec0 - [ASan] Prevent assert from scalable vectors in FunctionStackPoisoner. (#155357)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 27 01:00:55 PDT 2025
Author: David Green
Date: 2025-08-27T09:00:52+01:00
New Revision: aa5bec0a6274ebe873cc60238206730929e4dd37
URL: https://github.com/llvm/llvm-project/commit/aa5bec0a6274ebe873cc60238206730929e4dd37
DIFF: https://github.com/llvm/llvm-project/commit/aa5bec0a6274ebe873cc60238206730929e4dd37.diff
LOG: [ASan] Prevent assert from scalable vectors in FunctionStackPoisoner. (#155357)
This has recently started causing 'Invalid size request on a scalable
vector.'
Added:
llvm/test/Instrumentation/AddressSanitizer/asan-scalable-vector.ll
Modified:
llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
index 50258af5e26c3..42c3d4a4f4c46 100644
--- a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
+++ b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
@@ -1219,7 +1219,9 @@ struct FunctionStackPoisoner : public InstVisitor<FunctionStackPoisoner> {
std::optional<TypeSize> Size = AI->getAllocationSize(AI->getDataLayout());
// Check that size is known and can be stored in IntptrTy.
- if (!Size || !ConstantInt::isValueValidForType(IntptrTy, *Size))
+ // TODO: Add support for scalable vectors if possible.
+ if (!Size || Size->isScalable() ||
+ !ConstantInt::isValueValidForType(IntptrTy, *Size))
return;
bool DoPoison = (ID == Intrinsic::lifetime_end);
diff --git a/llvm/test/Instrumentation/AddressSanitizer/asan-scalable-vector.ll b/llvm/test/Instrumentation/AddressSanitizer/asan-scalable-vector.ll
new file mode 100644
index 0000000000000..6a841f2d399c0
--- /dev/null
+++ b/llvm/test/Instrumentation/AddressSanitizer/asan-scalable-vector.ll
@@ -0,0 +1,27 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
+; RUN: opt < %s -passes='asan<use-after-scope>' -S | FileCheck %s
+
+define void @test() #1 {
+; CHECK-LABEL: define void @test(
+; CHECK-SAME: ) #[[ATTR0:[0-9]+]] {
+; CHECK-NEXT: [[ENTRY:.*:]]
+; CHECK-NEXT: [[CTX_PG:%.*]] = alloca <vscale x 16 x i1>, align 2
+; CHECK-NEXT: call void @llvm.lifetime.start.p0(ptr [[CTX_PG]])
+; CHECK-NEXT: [[TMP0:%.*]] = load i8, ptr inttoptr (i64 17592186044416 to ptr), align 1
+; CHECK-NEXT: [[TMP1:%.*]] = icmp ne i8 [[TMP0]], 0
+; CHECK-NEXT: br i1 [[TMP1]], label %[[BB2:.*]], label %[[BB3:.*]]
+; CHECK: [[BB2]]:
+; CHECK-NEXT: call void @__asan_report_store8(i64 0) #[[ATTR4:[0-9]+]]
+; CHECK-NEXT: unreachable
+; CHECK: [[BB3]]:
+; CHECK-NEXT: store ptr [[CTX_PG]], ptr null, align 8
+; CHECK-NEXT: ret void
+;
+entry:
+ %ctx_pg = alloca <vscale x 16 x i1>, align 2
+ call void @llvm.lifetime.start.p0(ptr %ctx_pg)
+ store ptr %ctx_pg, ptr null, align 8
+ ret void
+}
+
+attributes #1 = { sanitize_address }
More information about the llvm-commits
mailing list