[llvm] [DWARFLinkerParallel] fix build on 32-bit platform. (PR #73388)

via llvm-commits llvm-commits at lists.llvm.org
Sat Nov 25 05:58:13 PST 2023


https://github.com/avl-llvm created https://github.com/llvm/llvm-project/pull/73388

This fixes usage of PointerIntPair on 32-bit platform - https://github.com/llvm/llvm-project/issues/73267.

>From 4b3993a0faee15156f050472c46af3cd886cbbf3 Mon Sep 17 00:00:00 2001
From: Alexey Lapshin <a.v.lapshin at mail.ru>
Date: Sat, 25 Nov 2023 14:09:20 +0100
Subject: [PATCH] [DWARFLinkerParallel] fix build on 32-bit platform.

This fixes usage of PointerIntPair on 32-bit platform.
---
 .../DWARFLinkerCompileUnit.h                  |  4 +++-
 .../DWARFLinkerParallel/DependencyTracker.h   | 21 ++++++++++++++++---
 2 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/llvm/lib/DWARFLinkerParallel/DWARFLinkerCompileUnit.h b/llvm/lib/DWARFLinkerParallel/DWARFLinkerCompileUnit.h
index 39e010fd632393d..28fcc34d867dbdf 100644
--- a/llvm/lib/DWARFLinkerParallel/DWARFLinkerCompileUnit.h
+++ b/llvm/lib/DWARFLinkerParallel/DWARFLinkerCompileUnit.h
@@ -47,7 +47,9 @@ enum ResolveInterCUReferencesMode : bool {
 
 /// Stores all information related to a compile unit, be it in its original
 /// instance of the object file or its brand new cloned and generated DIE tree.
-class CompileUnit : public DwarfUnit {
+/// NOTE: we need alignment of at least 8 bytes as we use
+///       PointerIntPair<CompileUnit *, 3> in the DependencyTracker.h
+class alignas(8) CompileUnit : public DwarfUnit {
 public:
   /// The stages of new compile unit processing.
   enum class Stage : uint8_t {
diff --git a/llvm/lib/DWARFLinkerParallel/DependencyTracker.h b/llvm/lib/DWARFLinkerParallel/DependencyTracker.h
index abd5371471eb95a..b0b6ad3a1e8cfaa 100644
--- a/llvm/lib/DWARFLinkerParallel/DependencyTracker.h
+++ b/llvm/lib/DWARFLinkerParallel/DependencyTracker.h
@@ -135,7 +135,7 @@ class DependencyTracker {
     LiveRootWorklistItemTy(const LiveRootWorklistItemTy &) = default;
     LiveRootWorklistItemTy(LiveRootWorklistActionTy Action,
                            UnitEntryPairTy RootEntry) {
-      RootCU.setInt(static_cast<uint8_t>(Action));
+      RootCU.setInt(Action);
       RootCU.setPointer(RootEntry.CU);
 
       RootDieEntry = RootEntry.DieEntry;
@@ -144,7 +144,7 @@ class DependencyTracker {
                            UnitEntryPairTy RootEntry,
                            UnitEntryPairTy ReferencedBy) {
       RootCU.setPointer(RootEntry.CU);
-      RootCU.setInt(static_cast<uint8_t>(Action));
+      RootCU.setInt(Action);
       RootDieEntry = RootEntry.DieEntry;
 
       ReferencedByCU = ReferencedBy.CU;
@@ -175,7 +175,22 @@ class DependencyTracker {
     /// Root entry.
     /// ASSUMPTION: 3 bits are used to store LiveRootWorklistActionTy value.
     /// Thus LiveRootWorklistActionTy should have no more eight elements.
-    PointerIntPair<CompileUnit *, 3> RootCU;
+
+    /// Pointer traits for CompileUnit.
+    struct CompileUnitPointerTraits {
+      static inline void *getAsVoidPointer(CompileUnit *P) { return P; }
+      static inline CompileUnit *getFromVoidPointer(void *P) {
+        return (CompileUnit *)P;
+      }
+      static constexpr int NumLowBitsAvailable = 3;
+      static_assert(
+          alignof(CompileUnit) >= (1 << NumLowBitsAvailable),
+          "CompileUnit insufficiently aligned to have enough low bits.");
+    };
+
+    PointerIntPair<CompileUnit *, 3, LiveRootWorklistActionTy,
+                   CompileUnitPointerTraits>
+        RootCU;
     const DWARFDebugInfoEntry *RootDieEntry = nullptr;
 
     /// Another root entry which references this RootDieEntry.



More information about the llvm-commits mailing list