[llvm] [LLVM][IR] Emit diagnostic for invalid pointee type for constant GEP. (PR #165383)
Paul Walker via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 28 05:49:12 PDT 2025
https://github.com/paulwalker-arm created https://github.com/llvm/llvm-project/pull/165383
Fixes https://github.com/llvm/llvm-project/issues/165137
>From 64e41f83f00e328614f8eb175240fe8611cef7b6 Mon Sep 17 00:00:00 2001
From: Paul Walker <paul.walker at arm.com>
Date: Tue, 28 Oct 2025 11:45:54 +0000
Subject: [PATCH] [LLVM][IR] Emit diagnostic for invalid pointee type for
constant GEP.
Fixes https://github.com/llvm/llvm-project/issues/165137
---
llvm/lib/AsmParser/LLParser.cpp | 3 +++
.../Assembler/constant-getelementptr-scalable_pointee.ll | 8 ++++++++
2 files changed, 11 insertions(+)
create mode 100644 llvm/test/Assembler/constant-getelementptr-scalable_pointee.ll
diff --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp
index 5164cec33e6f5..1eda7963ae6be 100644
--- a/llvm/lib/AsmParser/LLParser.cpp
+++ b/llvm/lib/AsmParser/LLParser.cpp
@@ -4541,6 +4541,9 @@ bool LLParser::parseValID(ValID &ID, PerFunctionState *PFS, Type *ExpectedTy) {
if (!GetElementPtrInst::getIndexedType(Ty, Indices))
return error(ID.Loc, "invalid getelementptr indices");
+ if (!ConstantExpr::isSupportedGetElementPtr(Ty))
+ return error(ID.Loc, "invalid base element for constant getelementptr");
+
ID.ConstantVal =
ConstantExpr::getGetElementPtr(Ty, Elts[0], Indices, NW, InRange);
} else if (Opc == Instruction::ShuffleVector) {
diff --git a/llvm/test/Assembler/constant-getelementptr-scalable_pointee.ll b/llvm/test/Assembler/constant-getelementptr-scalable_pointee.ll
new file mode 100644
index 0000000000000..d39039964b3b3
--- /dev/null
+++ b/llvm/test/Assembler/constant-getelementptr-scalable_pointee.ll
@@ -0,0 +1,8 @@
+; RUN: not llvm-as < %s 2>&1 | FileCheck %s
+; Test the case of an invalid pointee type on a constant GEP
+
+; CHECK: invalid base element for constant getelementptr
+
+define ptr @test_scalable_vector_gep(ptr %a) {
+ ret ptr getelementptr (<vscale x 1 x i8>, ptr @a, i64 1)
+}
More information about the llvm-commits
mailing list