[llvm] 8d4235d - [Lint] Fix another scalable vector crash

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 4 04:05:17 PDT 2024


Author: Nikita Popov
Date: 2024-09-04T13:05:09+02:00
New Revision: 8d4235d97e5bd12b8244f9ffc157651a9a288b36

URL: https://github.com/llvm/llvm-project/commit/8d4235d97e5bd12b8244f9ffc157651a9a288b36
DIFF: https://github.com/llvm/llvm-project/commit/8d4235d97e5bd12b8244f9ffc157651a9a288b36.diff

LOG: [Lint] Fix another scalable vector crash

We also need to check that the memory access LocationSize is not
scalable.

Added: 
    

Modified: 
    llvm/lib/Analysis/Lint.cpp
    llvm/test/Analysis/Lint/scalable.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/Lint.cpp b/llvm/lib/Analysis/Lint.cpp
index 415b16d25efd23..00e430ce8e0ab2 100644
--- a/llvm/lib/Analysis/Lint.cpp
+++ b/llvm/lib/Analysis/Lint.cpp
@@ -454,7 +454,8 @@ void Lint::visitMemoryReference(Instruction &I, const MemoryLocation &Loc,
 
     // Accesses from before the start or after the end of the object are not
     // defined.
-    Check(!Loc.Size.hasValue() || BaseSize == MemoryLocation::UnknownSize ||
+    Check(!Loc.Size.hasValue() || Loc.Size.isScalable() ||
+              BaseSize == MemoryLocation::UnknownSize ||
               (Offset >= 0 && Offset + Loc.Size.getValue() <= BaseSize),
           "Undefined behavior: Buffer overflow", &I);
 

diff  --git a/llvm/test/Analysis/Lint/scalable.ll b/llvm/test/Analysis/Lint/scalable.ll
index 4bcc4dae8d8371..bc12d6738d2aa3 100644
--- a/llvm/test/Analysis/Lint/scalable.ll
+++ b/llvm/test/Analysis/Lint/scalable.ll
@@ -7,6 +7,13 @@ define <vscale x 8 x i8> @alloca_access() {
   ret <vscale x 8 x i8> %v
 }
 
+; CHECK-NOT: Buffer overflow
+define <vscale x 8 x i8> @alloca_access2() {
+  %a = alloca <256 x i8>
+  %v = load <vscale x 8 x i8>, ptr %a
+  ret <vscale x 8 x i8> %v
+}
+
 ; CHECK-NOT: insertelement index out of range
 define <vscale x 8 x half> @insertelement() {
   %insert = insertelement <vscale x 8 x half> poison, half 0xH0000, i64 100


        


More information about the llvm-commits mailing list