forked from OSchip/llvm-project
[Verifier] Check that GEP indexes has correct types
Differential Revision: https://reviews.llvm.org/D40391 llvm-svn: 320680
This commit is contained in:
parent
ef12b41ef7
commit
753395fa0a
|
@ -3016,7 +3016,11 @@ void Verifier::visitGetElementPtrInst(GetElementPtrInst &GEP) {
|
|||
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);
|
||||
|
|
|
@ -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.
|
Binary file not shown.
Loading…
Reference in New Issue