[llvm] [ASan] Prevent assert from scalable vectors in FunctionStackPoisoner. (PR #155357)
David Green via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 27 00:58:32 PDT 2025
https://github.com/davemgreen updated https://github.com/llvm/llvm-project/pull/155357
>From e0e74ae1e2bb55976ec7ef7537d43177ef077253 Mon Sep 17 00:00:00 2001
From: David Green <david.green at arm.com>
Date: Wed, 27 Aug 2025 08:57:46 +0100
Subject: [PATCH] [ASan] Protect against scalable vectors in
FunctionStackPoisoner.
This has recently started causing 'Invalid size request on a scalable vector.'
---
.../Instrumentation/AddressSanitizer.cpp | 4 ++-
.../AddressSanitizer/asan-scalable-vector.ll | 27 +++++++++++++++++++
2 files changed, 30 insertions(+), 1 deletion(-)
create mode 100644 llvm/test/Instrumentation/AddressSanitizer/asan-scalable-vector.ll
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