[clang] [clang-tools-extra] [Clang] Add builtins that deduplicate and sort types (PR #106730)
Erich Keane via cfe-commits
cfe-commits at lists.llvm.org
Tue May 13 08:22:28 PDT 2025
================
@@ -3331,6 +3343,65 @@ checkBuiltinTemplateIdType(Sema &SemaRef, BuiltinTemplateDecl *BTD,
QualType HasNoTypeMember = Converted[2].getAsType();
return HasNoTypeMember;
}
+ case BTK__builtin_dedup_pack: {
+ assert(Converted.size() == 1 && "__builtin_dedup_pack should be given "
+ "a parameter pack");
+ TemplateArgument Ts = Converted[0];
+ // Delay the computation until we can compute the final result. We choose
+ // not to remove the duplicates upfront before substitution to keep the code
+ // simple.
+ if (Ts.isDependent())
+ return QualType();
+ assert(Ts.getKind() == clang::TemplateArgument::Pack);
+ llvm::SmallVector<TemplateArgument> OutArgs;
+ llvm::SmallDenseSet<QualType> Seen;
+ // Synthesize a new template argument list, removing duplicates.
+ for (auto T : Ts.getPackAsArray()) {
+ assert(T.getKind() == clang::TemplateArgument::Type);
+ if (!Seen.insert(T.getAsType().getCanonicalType()).second)
+ continue;
+ OutArgs.push_back(T);
+ }
+ return Context.getSubstBuiltinTemplatePack(
+ TemplateArgument::CreatePackCopy(Context, OutArgs));
+ }
+ case BTK__builtin_sort_pack: {
+ assert(Converted.size() == 1);
+ assert(Converted[0].getKind() == TemplateArgument::Pack);
+ // Delay if we have any dependencies, the mangled names may change after
+ // subsistution or may not be well-defined for dependent types.
----------------
erichkeane wrote:
```suggestion
// substitution or may not be well-defined for dependent types.
```
https://github.com/llvm/llvm-project/pull/106730
More information about the cfe-commits
mailing list