[clang] Add bit-precise overloads for builtin operators (PR #84755)
Erich Keane via cfe-commits
cfe-commits at lists.llvm.org
Mon Mar 11 06:47:12 PDT 2024
================
@@ -8955,6 +8962,22 @@ class BuiltinOperatorOverloadBuilder {
(S.Context.getAuxTargetInfo() &&
S.Context.getAuxTargetInfo()->hasInt128Type()))
ArithmeticTypes.push_back(S.Context.UnsignedInt128Ty);
+
+ /// _BitInt overloads are a bit special. We don't want to add candidates
+ /// for the entire family of _BitInt types, so instead we only add
+ /// candidates for the unique, unqualified _BitInt types present in the
+ /// candidate type set. The candidate set already handled ensuring the type
+ /// is unqualified and canonical, but because we're adding from N different
+ /// sets, we need to do some extra work to unique things. Copy the
+ /// candidates into a unique set, then copy from that set into the list of
+ /// arithmetic types.
+ llvm::SmallSetVector<CanQualType, 2> BitIntCandidates;
+ llvm::for_each(CandidateTypes, [&BitIntCandidates](
+ BuiltinCandidateTypeSet &Candidate) {
+ for (QualType BitTy : Candidate.bitint_types())
+ BitIntCandidates.insert(CanQualType::CreateUnsafe(BitTy));
+ });
+ llvm::copy(BitIntCandidates, std::back_inserter(ArithmeticTypes));
----------------
erichkeane wrote:
I'm concerned about the assert on `9001`. It seems to me that this changes us from being a reasonably 'fixed' list to having a perhaps-unlimited list.
I think that the intent of that assert is nice (ensuring we can small-vector-opt this list), but this section here makes that no longer guaranteed, right?
The `ArithmeticTypesCap` is 24, and we do a `push_back` of 23 other types (by my count!). So adding TWO bit-int types + having all the rest of the types enabled causes that assert to fire.
https://github.com/llvm/llvm-project/pull/84755
More information about the cfe-commits
mailing list