Skip to content

Conversation

@DanielKristofKiss
Copy link
Member

Asan doesn't support scalable types yet. Compiler crashes when alloca's size comes from a scalable type.

Asan doesn't support scalable types yet. Compiler crashes when alloca's size
comes from a scalable type.
@llvmbot llvmbot added clang Clang issues not falling into any other category compiler-rt:sanitizer llvm:transforms labels Aug 26, 2025
@llvmbot
Copy link
Member

llvmbot commented Aug 26, 2025

@llvm/pr-subscribers-compiler-rt-sanitizer

@llvm/pr-subscribers-llvm-transforms

Author: Daniel Kiss (DanielKristofKiss)

Changes

Asan doesn't support scalable types yet. Compiler crashes when alloca's size comes from a scalable type.


Full diff: https://github.com/llvm/llvm-project/pull/155505.diff

2 Files Affected:

  • (added) clang/test/CodeGen/asan-scalabe-vector.cpp (+12)
  • (modified) llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp (+2)
diff --git a/clang/test/CodeGen/asan-scalabe-vector.cpp b/clang/test/CodeGen/asan-scalabe-vector.cpp
new file mode 100644
index 0000000000000..77f46f81f5b70
--- /dev/null
+++ b/clang/test/CodeGen/asan-scalabe-vector.cpp
@@ -0,0 +1,12 @@
+// Regression test for compiler crash
+// RUN: %clang_cc1 -triple aarch64-unknown-linux-gnu -target-feature +sve -target-feature +sve2 -emit-obj -fsanitize=address -fsanitize-address-use-after-scope %s -o - | llvm-objdump -d - | FileCheck %s
+// REQUIRES: aarch64-registered-target
+
+#include <arm_sve.h>
+int biz(svfloat64_t*);
+int foo(){
+    svfloat64_t a,b,c;
+    return biz(&a)+biz(&b)+biz(&c);
+}
+
+//CHECK: 0000000000000000 <_Z3foov>:
\ No newline at end of file
diff --git a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
index 50258af5e26c3..19d6bf56e479c 100644
--- a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
+++ b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
@@ -1406,6 +1406,8 @@ bool AddressSanitizer::isInterestingAlloca(const AllocaInst &AI) {
       (AI.getAllocatedType()->isSized() &&
        // alloca() may be called with 0 size, ignore it.
        ((!AI.isStaticAlloca()) || !getAllocaSizeInBytes(AI).isZero()) &&
+       // alloca() may be called with a scalable parameter, we can't handle it.
+       !AI.getAllocationSize(AI.getDataLayout())->isScalable() &&
        // We are only interested in allocas not promotable to registers.
        // Promotable allocas are common under -O0.
        (!ClSkipPromotableAllocas || !isAllocaPromotable(&AI)) &&

@llvmbot
Copy link
Member

llvmbot commented Aug 26, 2025

@llvm/pr-subscribers-clang

Author: Daniel Kiss (DanielKristofKiss)

Changes

Asan doesn't support scalable types yet. Compiler crashes when alloca's size comes from a scalable type.


Full diff: https://github.com/llvm/llvm-project/pull/155505.diff

2 Files Affected:

  • (added) clang/test/CodeGen/asan-scalabe-vector.cpp (+12)
  • (modified) llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp (+2)
diff --git a/clang/test/CodeGen/asan-scalabe-vector.cpp b/clang/test/CodeGen/asan-scalabe-vector.cpp
new file mode 100644
index 0000000000000..77f46f81f5b70
--- /dev/null
+++ b/clang/test/CodeGen/asan-scalabe-vector.cpp
@@ -0,0 +1,12 @@
+// Regression test for compiler crash
+// RUN: %clang_cc1 -triple aarch64-unknown-linux-gnu -target-feature +sve -target-feature +sve2 -emit-obj -fsanitize=address -fsanitize-address-use-after-scope %s -o - | llvm-objdump -d - | FileCheck %s
+// REQUIRES: aarch64-registered-target
+
+#include <arm_sve.h>
+int biz(svfloat64_t*);
+int foo(){
+    svfloat64_t a,b,c;
+    return biz(&a)+biz(&b)+biz(&c);
+}
+
+//CHECK: 0000000000000000 <_Z3foov>:
\ No newline at end of file
diff --git a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
index 50258af5e26c3..19d6bf56e479c 100644
--- a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
+++ b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
@@ -1406,6 +1406,8 @@ bool AddressSanitizer::isInterestingAlloca(const AllocaInst &AI) {
       (AI.getAllocatedType()->isSized() &&
        // alloca() may be called with 0 size, ignore it.
        ((!AI.isStaticAlloca()) || !getAllocaSizeInBytes(AI).isZero()) &&
+       // alloca() may be called with a scalable parameter, we can't handle it.
+       !AI.getAllocationSize(AI.getDataLayout())->isScalable() &&
        // We are only interested in allocas not promotable to registers.
        // Promotable allocas are common under -O0.
        (!ClSkipPromotableAllocas || !isAllocaPromotable(&AI)) &&

@DanielKristofKiss
Copy link
Member Author

DanielKristofKiss commented Aug 26, 2025

recent regression, doesn't present on the 20.x branch but on main
test is not the best one but ideas are welcome.

@thurstond
Copy link
Contributor

This might overlap with #155357

@DanielKristofKiss
Copy link
Member Author

DanielKristofKiss commented Aug 27, 2025

This might overlap with #155357

Yep, as it went already in drop this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang Clang issues not falling into any other category compiler-rt:sanitizer llvm:transforms

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants