@@ -385,5 +385,35 @@ TEST(VerifierTest, AtomicRMW) {
385385 << Error;
386386}
387387
388+ TEST (VerifierTest, GetElementPtrInst) {
389+ LLVMContext C;
390+ Module M (" M" , C);
391+ FunctionType *FTy = FunctionType::get (Type::getVoidTy (C), /* isVarArg=*/ false );
392+ Function *F = Function::Create (FTy, Function::ExternalLinkage, " foo" , M);
393+ BasicBlock *Entry = BasicBlock::Create (C, " entry" , F);
394+ ReturnInst *RI = ReturnInst::Create (C, Entry);
395+
396+ FixedVectorType *V2P1Ty = FixedVectorType::get (PointerType::get (C, 1 ), 2 );
397+ FixedVectorType *V2P2Ty = FixedVectorType::get (PointerType::get (C, 2 ), 2 );
398+
399+ Instruction *GEPVec = GetElementPtrInst::Create (
400+ Type::getInt8Ty (C), ConstantAggregateZero::get (V2P1Ty),
401+ {ConstantVector::getSplat (ElementCount::getFixed (2 ),
402+ ConstantInt::get (Type::getInt64Ty (C), 0 ))},
403+ Entry);
404+
405+ GEPVec->insertBefore (RI);
406+
407+ // Break the address space of the source value
408+ GEPVec->getOperandUse (0 ).set (ConstantAggregateZero::get (V2P2Ty));
409+
410+ std::string Error;
411+ raw_string_ostream ErrorOS (Error);
412+ EXPECT_TRUE (verifyFunction (*F, &ErrorOS));
413+ EXPECT_TRUE (
414+ StringRef (Error).starts_with (" GEP address space doesn't match type" ))
415+ << Error;
416+ }
417+
388418} // end anonymous namespace
389419} // end namespace llvm
0 commit comments