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(TargetTy), "GEP base pointer is not a vector or a vector of pointers", &GEP); Assert(GEP.getSourceElementType()->isSized(), "GEP into unsized type!", &GEP); + SmallVector 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); 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.