[llvm] [IR] Check parameters of target extension types on construction (PR #107268)
Jay Foad via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 5 03:40:12 PDT 2024
================
@@ -792,28 +793,50 @@ TargetExtType::TargetExtType(LLVMContext &C, StringRef Name,
TargetExtType *TargetExtType::get(LLVMContext &C, StringRef Name,
ArrayRef<Type *> Types,
ArrayRef<unsigned> Ints) {
+ return cantFail(getOrError(C, Name, Types, Ints));
+}
+
+Expected<TargetExtType *> TargetExtType::getOrError(LLVMContext &C,
+ StringRef Name,
+ ArrayRef<Type *> Types,
+ ArrayRef<unsigned> Ints) {
const TargetExtTypeKeyInfo::KeyTy Key(Name, Types, Ints);
TargetExtType *TT;
// Since we only want to allocate a fresh target type in case none is found
// and we don't want to perform two lookups (one for checking if existent and
// one for inserting the newly allocated one), here we instead lookup based on
// Key and update the reference to the target type in-place to a newly
// allocated one if not found.
- auto Insertion = C.pImpl->TargetExtTypes.insert_as(nullptr, Key);
- if (Insertion.second) {
+ auto [Iter, Inserted] = C.pImpl->TargetExtTypes.insert_as(nullptr, Key);
+ if (Inserted) {
----------------
jayfoad wrote:
I did grep existing code for `auto \[.*insert` and `Inserted` seemed to be the most common name. And I think it's a pretty good literal description of what the `insert` method did.
https://github.com/llvm/llvm-project/pull/107268
More information about the llvm-commits
mailing list