[llvm] [DWARFLinker] Preserve source order of member subprograms (PR #196443)

Jonas Devlieghere via llvm-commits llvm-commits at lists.llvm.org
Thu May 7 15:55:20 PDT 2026


https://github.com/JDevlieghere created https://github.com/llvm/llvm-project/pull/196443

DW_TAG_subprogram was missing from tagToArrayIndex, so member functions had no ordering prefix in their synthetic key and ended up sorted alphabetically by TypePool.

>From 2ae02cb719aec01414a34521742cbaced9d21a90 Mon Sep 17 00:00:00 2001
From: Jonas Devlieghere <jonas at devlieghere.com>
Date: Thu, 7 May 2026 15:54:10 -0700
Subject: [PATCH] [DWARFLinker] Preserve source order of member subprograms

DW_TAG_subprogram was missing from tagToArrayIndex, so member
functions had no ordering prefix in their synthetic key and ended up
sorted alphabetically by TypePool.
---
 llvm/lib/DWARFLinker/Parallel/SyntheticTypeNameBuilder.cpp | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/llvm/lib/DWARFLinker/Parallel/SyntheticTypeNameBuilder.cpp b/llvm/lib/DWARFLinker/Parallel/SyntheticTypeNameBuilder.cpp
index ca918f6e17b38..06d598d22ee50 100644
--- a/llvm/lib/DWARFLinker/Parallel/SyntheticTypeNameBuilder.cpp
+++ b/llvm/lib/DWARFLinker/Parallel/SyntheticTypeNameBuilder.cpp
@@ -741,6 +741,11 @@ std::optional<size_t> OrderedChildrenIndexAssigner::tagToArrayIndex(
   case dwarf::DW_TAG_namelist_item:
     return 6;
   case dwarf::DW_TAG_member:
+  case dwarf::DW_TAG_subprogram:
+    // Methods and data members share the same ordering bucket so that class
+    // members retain their input-DIE order in the output. Without this,
+    // TypePool::sortTypes sorts children alphabetically by synthetic name,
+    // which reorders methods compared to their source declaration order.
     return 7;
   default:
     return std::nullopt;



More information about the llvm-commits mailing list