[clang] [clang-tools-extra] [Clang] Implement `__builtin_sort_pack` (PR #225025)

Corentin Jabot via cfe-commits cfe-commits at lists.llvm.org
Mon Sep 21 01:22:48 PDT 2026


================
@@ -3428,6 +3430,28 @@ static SpirvOperand checkHLSLSpirvTypeOperand(Sema &SemaRef,
   return SpirvOperand::createType(OperandArg);
 }
 
+static QualType sortBuiltinTemplatePack(ASTContext &Context,
+                                        ArrayRef<TemplateArgument> InputArgs) {
+  // FIXME: cache mangling globally?
+  std::unique_ptr<MangleContext> MC(Context.createMangleContext());
+  SmallVector<std::pair<std::string, TemplateArgument>> SortedArgs(
+      InputArgs.size());
+  llvm::transform(
+      InputArgs, SortedArgs.begin(), [&](const TemplateArgument &Arg) {
+        assert(Arg.getKind() == TemplateArgument::Type);
+        std::string MangledName;
+        llvm::raw_string_ostream OS(MangledName);
+        MC->mangleCanonicalTypeName(Arg.getAsType(), OS);
----------------
cor3ntin wrote:

Yes, we do - this is similar to the order you'd get from `__builtin_type_order`.

The rationale for that is somewhere in there
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2025/p2830r10.html

The tl;dr is that a portable order would force us to effectively implement a new kind of mangling and we don't want to do that.
However the order is stable across TUs and portable  on the same platform, modulo bugs (i.e gcc compat)


https://github.com/llvm/llvm-project/pull/225025


More information about the cfe-commits mailing list