[llvm] aa995d9 - [IR][Verifier] Reject GEP into vector with non-byte-addressable element type (#176689)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 20 03:02:32 PST 2026
Author: nataliakokoromyti
Date: 2026-01-20T12:02:26+01:00
New Revision: aa995d96343c5f22ae8dfbeb0035ab04548e1282
URL: https://github.com/llvm/llvm-project/commit/aa995d96343c5f22ae8dfbeb0035ab04548e1282
DIFF: https://github.com/llvm/llvm-project/commit/aa995d96343c5f22ae8dfbeb0035ab04548e1282.diff
LOG: [IR][Verifier] Reject GEP into vector with non-byte-addressable element type (#176689)
Add a verifier check to reject GEP instructions that index into vectors
with non-byte-addressable element types (e.g., <2 x i1>). Such GEPs
cannot have their offset computed in bytes, causing assertions in passes
like SROA that try to compute byte offsets.
Fixes #176628.
Added:
llvm/test/Verifier/gep-vector-non-byte-element.ll
Modified:
llvm/lib/IR/Verifier.cpp
Removed:
################################################################################
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 92e90384c7aab..055b5852dcce7 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -82,6 +82,7 @@
#include "llvm/IR/FPEnv.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/GCStrategy.h"
+#include "llvm/IR/GetElementPtrTypeIterator.h"
#include "llvm/IR/GlobalAlias.h"
#include "llvm/IR/GlobalValue.h"
#include "llvm/IR/GlobalVariable.h"
@@ -4477,6 +4478,17 @@ void Verifier::visitGetElementPtrInst(GetElementPtrInst &GEP) {
}
}
+ // Check that GEP does not index into a vector with non-byte-addressable
+ // elements.
+ for (gep_type_iterator GTI = gep_type_begin(GEP), GTE = gep_type_end(GEP);
+ GTI != GTE; ++GTI) {
+ if (GTI.isVector()) {
+ Type *ElemTy = GTI.getIndexedType();
+ Check(DL.typeSizeEqualsStoreSize(ElemTy),
+ "GEP into vector with non-byte-addressable element type", &GEP);
+ }
+ }
+
Check(GEP.getAddressSpace() == PtrTy->getAddressSpace(),
"GEP address space doesn't match type", &GEP);
diff --git a/llvm/test/Verifier/gep-vector-non-byte-element.ll b/llvm/test/Verifier/gep-vector-non-byte-element.ll
new file mode 100644
index 0000000000000..e7d948920bf14
--- /dev/null
+++ b/llvm/test/Verifier/gep-vector-non-byte-element.ll
@@ -0,0 +1,10 @@
+; RUN: not llvm-as < %s 2>&1 | FileCheck %s
+; CHECK: GEP into vector with non-byte-addressable element type
+
+; This testcase is invalid because we are indexing into a vector
+; with non-byte-addressable element type (i1).
+
+define ptr @test(ptr %p) {
+ %gep = getelementptr <2 x i1>, ptr %p, i64 0, i64 1
+ ret ptr %gep
+}
More information about the llvm-commits
mailing list