Skip to content

Commit 1191970

Browse files
[LLVM][IR] Emit diagnostic for invalid pointee type for constant GEP. (#165383)
Fixes #165137
1 parent edab721 commit 1191970

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

llvm/lib/AsmParser/LLParser.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4538,6 +4538,9 @@ bool LLParser::parseValID(ValID &ID, PerFunctionState *PFS, Type *ExpectedTy) {
45384538
if (!Indices.empty() && !Ty->isSized(&Visited))
45394539
return error(ID.Loc, "base element of getelementptr must be sized");
45404540

4541+
if (!ConstantExpr::isSupportedGetElementPtr(Ty))
4542+
return error(ID.Loc, "invalid base element for constant getelementptr");
4543+
45414544
if (!GetElementPtrInst::getIndexedType(Ty, Indices))
45424545
return error(ID.Loc, "invalid getelementptr indices");
45434546

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
; RUN: not llvm-as < %s 2>&1 | FileCheck %s
2+
; Test the case of an invalid pointee type on a constant GEP
3+
4+
; CHECK: invalid base element for constant getelementptr
5+
6+
define ptr @test_scalable_vector_gep(ptr %a) {
7+
ret ptr getelementptr (<vscale x 1 x i8>, ptr @a, i64 1)
8+
}

0 commit comments

Comments
 (0)