[PATCH] D40391: [Verifier] Check that GEP indexes has correct types

Phabricator via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 14 01:34:45 PST 2017


This revision was automatically updated to reflect the committed changes.
Closed by commit rL320680: [Verifier] Check that GEP indexes has correct types (authored by igor.laevsky, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D40391?vs=124076&id=126911#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D40391

Files:
  llvm/trunk/lib/IR/Verifier.cpp
  llvm/trunk/test/Verifier/non-integer-gep-index.ll
  llvm/trunk/test/Verifier/non-integer-gep-index.ll.bc


Index: llvm/trunk/test/Verifier/non-integer-gep-index.ll
===================================================================
--- llvm/trunk/test/Verifier/non-integer-gep-index.ll
+++ llvm/trunk/test/Verifier/non-integer-gep-index.ll
@@ -0,0 +1,8 @@
+; RUN: not opt -verify %s.bc -disable-output
+
+; Test that verifier checks that gep indexes has correct type
+; Specifically we want to check for the following pattern:
+;   %A1 = alloca i64
+;   %G = getelementptr i64, i64* %A1, %A1
+; IR parser checks for this pattern independently from the verifier, so it's
+; impossible to load from .ll file. Hence in this test we use bytecode input.
Index: llvm/trunk/lib/IR/Verifier.cpp
===================================================================
--- llvm/trunk/lib/IR/Verifier.cpp
+++ llvm/trunk/lib/IR/Verifier.cpp
@@ -3016,7 +3016,11 @@
   Assert(isa<PointerType>(TargetTy),
          "GEP base pointer is not a vector or a vector of pointers", &GEP);
   Assert(GEP.getSourceElementType()->isSized(), "GEP into unsized type!", &GEP);
+
   SmallVector<Value*, 16> Idxs(GEP.idx_begin(), GEP.idx_end());
+  Assert(all_of(
+      Idxs, [](Value* V) { return V->getType()->isIntOrIntVectorTy(); }),
+      "GEP indexes must be integers", &GEP);
   Type *ElTy =
       GetElementPtrInst::getIndexedType(GEP.getSourceElementType(), Idxs);
   Assert(ElTy, "Invalid indices for GEP pointer type!", &GEP);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D40391.126911.patch
Type: text/x-patch
Size: 1400 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171214/4bd16276/attachment.bin>


More information about the llvm-commits mailing list