-
Notifications
You must be signed in to change notification settings - Fork 14.3k
IR: Fix verifier missing addrspace mismatch in vector GEPs #114091
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
arsenm
merged 1 commit into
main
from
users/arsenm/ir-verifier-catch-broken-vector-of-pointer-gep
Oct 30, 2024
Merged
IR: Fix verifier missing addrspace mismatch in vector GEPs #114091
arsenm
merged 1 commit into
main
from
users/arsenm/ir-verifier-catch-broken-vector-of-pointer-gep
Oct 30, 2024
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@llvm/pr-subscribers-llvm-ir Author: Matt Arsenault (arsenm) ChangesFull diff: https://github.com/llvm/llvm-project/pull/114091.diff 2 Files Affected:
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index ee807ca13787d5..ffcab98db9aa02 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -4121,8 +4121,9 @@ void Verifier::visitGetElementPtrInst(GetElementPtrInst &GEP) {
GetElementPtrInst::getIndexedType(GEP.getSourceElementType(), Idxs);
Check(ElTy, "Invalid indices for GEP pointer type!", &GEP);
- Check(GEP.getType()->isPtrOrPtrVectorTy() &&
- GEP.getResultElementType() == ElTy,
+ PointerType *PtrTy = dyn_cast<PointerType>(GEP.getType()->getScalarType());
+
+ Check(PtrTy && GEP.getResultElementType() == ElTy,
"GEP is not of right type for indices!", &GEP, ElTy);
if (auto *GEPVTy = dyn_cast<VectorType>(GEP.getType())) {
@@ -4144,10 +4145,8 @@ void Verifier::visitGetElementPtrInst(GetElementPtrInst &GEP) {
}
}
- if (auto *PTy = dyn_cast<PointerType>(GEP.getType())) {
- Check(GEP.getAddressSpace() == PTy->getAddressSpace(),
- "GEP address space doesn't match type", &GEP);
- }
+ Check(GEP.getAddressSpace() == PtrTy->getAddressSpace(),
+ "GEP address space doesn't match type", &GEP);
visitInstruction(GEP);
}
diff --git a/llvm/unittests/IR/VerifierTest.cpp b/llvm/unittests/IR/VerifierTest.cpp
index 91cd35a10e9b92..462578a34da837 100644
--- a/llvm/unittests/IR/VerifierTest.cpp
+++ b/llvm/unittests/IR/VerifierTest.cpp
@@ -385,5 +385,35 @@ TEST(VerifierTest, AtomicRMW) {
<< Error;
}
+TEST(VerifierTest, GetElementPtrInst) {
+ LLVMContext C;
+ Module M("M", C);
+ FunctionType *FTy = FunctionType::get(Type::getVoidTy(C), /*isVarArg=*/false);
+ Function *F = Function::Create(FTy, Function::ExternalLinkage, "foo", M);
+ BasicBlock *Entry = BasicBlock::Create(C, "entry", F);
+ ReturnInst *RI = ReturnInst::Create(C, Entry);
+
+ FixedVectorType *V2P1Ty = FixedVectorType::get(PointerType::get(C, 1), 2);
+ FixedVectorType *V2P2Ty = FixedVectorType::get(PointerType::get(C, 2), 2);
+
+ Instruction *GEPVec = GetElementPtrInst::Create(
+ Type::getInt8Ty(C), ConstantAggregateZero::get(V2P1Ty),
+ {ConstantVector::getSplat(ElementCount::getFixed(2),
+ ConstantInt::get(Type::getInt64Ty(C), 0))},
+ Entry);
+
+ GEPVec->insertBefore(RI);
+
+ // Break the address space of the source value
+ GEPVec->getOperandUse(0).set(ConstantAggregateZero::get(V2P2Ty));
+
+ std::string Error;
+ raw_string_ostream ErrorOS(Error);
+ EXPECT_TRUE(verifyFunction(*F, &ErrorOS));
+ EXPECT_TRUE(
+ StringRef(Error).starts_with("GEP address space doesn't match type"))
+ << Error;
+}
+
} // end anonymous namespace
} // end namespace llvm
|
jhuber6
approved these changes
Oct 29, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
This was referenced Oct 29, 2024
dtcxzyw
approved these changes
Oct 30, 2024
NoumanAmir657
pushed a commit
to NoumanAmir657/llvm-project
that referenced
this pull request
Nov 4, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.