[llvm] r320680 - [Verifier] Check that GEP indexes has correct types
Igor Laevsky via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 14 01:33:58 PST 2017
Author: igor.laevsky
Date: Thu Dec 14 01:33:58 2017
New Revision: 320680
URL: http://llvm.org/viewvc/llvm-project?rev=320680&view=rev
Log:
[Verifier] Check that GEP indexes has correct types
Differential Revision: https://reviews.llvm.org/D40391
Added:
llvm/trunk/test/Verifier/non-integer-gep-index.ll
llvm/trunk/test/Verifier/non-integer-gep-index.ll.bc
Modified:
llvm/trunk/lib/IR/Verifier.cpp
Modified: llvm/trunk/lib/IR/Verifier.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Verifier.cpp?rev=320680&r1=320679&r2=320680&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Verifier.cpp (original)
+++ llvm/trunk/lib/IR/Verifier.cpp Thu Dec 14 01:33:58 2017
@@ -3016,7 +3016,11 @@ void Verifier::visitGetElementPtrInst(Ge
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);
Added: llvm/trunk/test/Verifier/non-integer-gep-index.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Verifier/non-integer-gep-index.ll?rev=320680&view=auto
==============================================================================
--- llvm/trunk/test/Verifier/non-integer-gep-index.ll (added)
+++ llvm/trunk/test/Verifier/non-integer-gep-index.ll Thu Dec 14 01:33:58 2017
@@ -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.
Added: llvm/trunk/test/Verifier/non-integer-gep-index.ll.bc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Verifier/non-integer-gep-index.ll.bc?rev=320680&view=auto
==============================================================================
Binary files llvm/trunk/test/Verifier/non-integer-gep-index.ll.bc (added) and llvm/trunk/test/Verifier/non-integer-gep-index.ll.bc Thu Dec 14 01:33:58 2017 differ
More information about the llvm-commits
mailing list