[llvm] 29c076b - [Lint] Fix crash with scalable alloca
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 4 03:12:08 PDT 2024
Author: Nikita Popov
Date: 2024-09-04T12:11:59+02:00
New Revision: 29c076b8598c9627cea493fdfc1a30c83385e820
URL: https://github.com/llvm/llvm-project/commit/29c076b8598c9627cea493fdfc1a30c83385e820
DIFF: https://github.com/llvm/llvm-project/commit/29c076b8598c9627cea493fdfc1a30c83385e820.diff
LOG: [Lint] Fix crash with scalable alloca
Added:
llvm/test/Analysis/Lint/scalable.ll
Modified:
llvm/lib/Analysis/Lint.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/Lint.cpp b/llvm/lib/Analysis/Lint.cpp
index a44d5a3bbe462a..29b5d38fc93b76 100644
--- a/llvm/lib/Analysis/Lint.cpp
+++ b/llvm/lib/Analysis/Lint.cpp
@@ -436,8 +436,8 @@ void Lint::visitMemoryReference(Instruction &I, const MemoryLocation &Loc,
if (AllocaInst *AI = dyn_cast<AllocaInst>(Base)) {
Type *ATy = AI->getAllocatedType();
- if (!AI->isArrayAllocation() && ATy->isSized())
- BaseSize = DL->getTypeAllocSize(ATy);
+ if (!AI->isArrayAllocation() && ATy->isSized() && !ATy->isScalableTy())
+ BaseSize = DL->getTypeAllocSize(ATy).getFixedValue();
BaseAlign = AI->getAlign();
} else if (GlobalVariable *GV = dyn_cast<GlobalVariable>(Base)) {
// If the global may be defined
diff erently in another compilation unit
diff --git a/llvm/test/Analysis/Lint/scalable.ll b/llvm/test/Analysis/Lint/scalable.ll
new file mode 100644
index 00000000000000..73100eca8835cb
--- /dev/null
+++ b/llvm/test/Analysis/Lint/scalable.ll
@@ -0,0 +1,15 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
+; RUN: opt -S -passes=lint < %s | FileCheck %s
+
+; Make sure we don't crash.
+
+define <vscale x 8 x i8> @test() {
+; CHECK-LABEL: define <vscale x 8 x i8> @test() {
+; CHECK-NEXT: [[A:%.*]] = alloca <vscale x 8 x i8>, align 8
+; CHECK-NEXT: [[V:%.*]] = load <vscale x 8 x i8>, ptr [[A]], align 8
+; CHECK-NEXT: ret <vscale x 8 x i8> [[V]]
+;
+ %a = alloca <vscale x 8 x i8>
+ %v = load <vscale x 8 x i8>, ptr %a
+ ret <vscale x 8 x i8> %v
+}
More information about the llvm-commits
mailing list