[lld] [LLD][COFF] Fix ARM64 EC chunks comparator (PR #75407)

Alexandre Ganea via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 13 15:59:36 PST 2023


https://github.com/aganea created https://github.com/llvm/llvm-project/pull/75407

Fix string weak ordering relationship. Since we were only testing `!aType` before, `comp(a, b)` and `comp(b, a)` would both return `true`.

>From ee399382cef40ca752581926d4c07bb9b3746ef8 Mon Sep 17 00:00:00 2001
From: Alexandre Ganea <alex_toresh at yahoo.fr>
Date: Wed, 13 Dec 2023 17:58:56 -0500
Subject: [PATCH] [LLD][COFF] Fix ARM64 EC chunks comparator

---
 lld/COFF/Writer.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lld/COFF/Writer.cpp b/lld/COFF/Writer.cpp
index 89e0f5b2df7441..0d28091efef2b1 100644
--- a/lld/COFF/Writer.cpp
+++ b/lld/COFF/Writer.cpp
@@ -1480,7 +1480,8 @@ void Writer::sortECChunks() {
       llvm::stable_sort(sec->chunks, [=](const Chunk *a, const Chunk *b) {
         std::optional<chpe_range_type> aType = a->getArm64ECRangeType(),
                                        bType = b->getArm64ECRangeType();
-        return !aType || (bType && *aType < *bType);
+        return (!aType ? 0 : (unsigned)*aType + 1) <
+               (!bType ? 0 : (unsigned)*bType + 1);
       });
   }
 }



More information about the llvm-commits mailing list