Skip to content

Commit

Permalink
[BitCode] Diagnose GEPs with no indices
Browse files Browse the repository at this point in the history
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@271849 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
filcab committed Jun 5, 2016
1 parent 780fc2c commit e8dd99a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/Bitcode/Reader/BitcodeReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3090,6 +3090,9 @@ std::error_code BitcodeReader::parseConstants() {
return error("Explicit gep operator type does not match pointee type "
"of pointer operand");

if (Elts.size() < 1)
return error("Invalid gep with no operands");

ArrayRef<Constant *> Indices(Elts.begin() + 1, Elts.end());
V = ConstantExpr::getGetElementPtr(PointeeType, Elts[0], Indices,
BitCode ==
Expand Down
Binary file added test/Bitcode/Inputs/invalid-gep-no-operands.bc
Binary file not shown.
5 changes: 5 additions & 0 deletions test/Bitcode/invalid.test
Original file line number Diff line number Diff line change
Expand Up @@ -217,3 +217,8 @@ RUN: not llvm-dis -disable-output %p/Inputs/invalid-void-constant.bc 2>&1 | \
RUN: FileCheck --check-prefix=VOID-CONSTANT-TYPE %s

VOID-CONSTANT-TYPE: Invalid constant type

RUN: not llvm-dis -disable-output %p/Inputs/invalid-gep-no-operands.bc 2>&1 | \
RUN: FileCheck --check-prefix=GEP-NO-OPERANDS %s

GEP-NO-OPERANDS: Invalid gep with no operands

0 comments on commit e8dd99a

Please sign in to comment.