[llvm] 1191970 - [LLVM][IR] Emit diagnostic for invalid pointee type for constant GEP. (#165383)

via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 29 06:08:45 PDT 2025


Author: Paul Walker
Date: 2025-10-29T13:08:40Z
New Revision: 1191970d172854d67633f3454aa938ec261859d5

URL: https://github.com/llvm/llvm-project/commit/1191970d172854d67633f3454aa938ec261859d5
DIFF: https://github.com/llvm/llvm-project/commit/1191970d172854d67633f3454aa938ec261859d5.diff

LOG: [LLVM][IR] Emit diagnostic for invalid pointee type for constant GEP. (#165383)

Fixes https://github.com/llvm/llvm-project/issues/165137

Added: 
    llvm/test/Assembler/constant-getelementptr-scalable_pointee.ll

Modified: 
    llvm/lib/AsmParser/LLParser.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp
index e7a04d98df2af..4cc47c0d0260e 100644
--- a/llvm/lib/AsmParser/LLParser.cpp
+++ b/llvm/lib/AsmParser/LLParser.cpp
@@ -4538,6 +4538,9 @@ bool LLParser::parseValID(ValID &ID, PerFunctionState *PFS, Type *ExpectedTy) {
       if (!Indices.empty() && !Ty->isSized(&Visited))
         return error(ID.Loc, "base element of getelementptr must be sized");
 
+      if (!ConstantExpr::isSupportedGetElementPtr(Ty))
+        return error(ID.Loc, "invalid base element for constant getelementptr");
+
       if (!GetElementPtrInst::getIndexedType(Ty, Indices))
         return error(ID.Loc, "invalid getelementptr indices");
 

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