Skip to content

[DWARFLinkerParallel] fix build on 32-bit platform. #73388

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

avl-llvm
Copy link
Collaborator

This fixes usage of PointerIntPair on 32-bit platform - #73267.

This fixes usage of PointerIntPair on 32-bit platform.
@llvmbot
Copy link
Member

llvmbot commented Nov 25, 2023

@llvm/pr-subscribers-debuginfo

Author: None (avl-llvm)

Changes

This fixes usage of PointerIntPair on 32-bit platform - #73267.


Full diff: https://github.com/llvm/llvm-project/pull/73388.diff

2 Files Affected:

  • (modified) llvm/lib/DWARFLinkerParallel/DWARFLinkerCompileUnit.h (+3-1)
  • (modified) llvm/lib/DWARFLinkerParallel/DependencyTracker.h (+18-3)
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.

@avl-llvm avl-llvm merged commit 6b708cc into llvm:main Nov 25, 2023
felipepiovezan pushed a commit to felipepiovezan/llvm-project that referenced this pull request Feb 2, 2024
This fixes usage of PointerIntPair on 32-bit platform -
llvm#73267.

(cherry picked from commit 6b708cc)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants