Skip to content
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

[ELF] Internalize enum #83604

Merged
merged 1 commit into from Mar 1, 2024
Merged

Conversation

MaskRay
Copy link
Member

@MaskRay MaskRay commented Mar 1, 2024

g++ -flto has a diagnostic -Wodr about mismatched redeclarations,
which even apply to enum.

Fix #83529

Created using spr 1.3.4
@llvmbot
Copy link
Collaborator

llvmbot commented Mar 1, 2024

@llvm/pr-subscribers-lld

@llvm/pr-subscribers-lld-elf

Author: Fangrui Song (MaskRay)

Changes

g++ -flto has a diagnostic -Wodr about mismatched redeclarations,
which even apply to enum.

Fix #83529


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

3 Files Affected:

  • (modified) lld/ELF/Arch/LoongArch.cpp (+2)
  • (modified) lld/ELF/Arch/PPC64.cpp (+2-1)
  • (modified) lld/ELF/Arch/RISCV.cpp (+2)
diff --git a/lld/ELF/Arch/LoongArch.cpp b/lld/ELF/Arch/LoongArch.cpp
index 49fd979bd0a55c..e0f9abfb382af0 100644
--- a/lld/ELF/Arch/LoongArch.cpp
+++ b/lld/ELF/Arch/LoongArch.cpp
@@ -41,6 +41,7 @@ class LoongArch final : public TargetInfo {
 };
 } // end anonymous namespace
 
+namespace {
 enum Op {
   SUB_W = 0x00110000,
   SUB_D = 0x00118000,
@@ -65,6 +66,7 @@ enum Reg {
   R_T2 = 14,
   R_T3 = 15,
 };
+} // namespace
 
 // Mask out the input's lowest 12 bits for use with `pcalau12i`, in sequences
 // like `pcalau12i + addi.[wd]` or `pcalau12i + {ld,st}.*` where the `pcalau12i`
diff --git a/lld/ELF/Arch/PPC64.cpp b/lld/ELF/Arch/PPC64.cpp
index de52f6a79a40b9..019c073bd541b6 100644
--- a/lld/ELF/Arch/PPC64.cpp
+++ b/lld/ELF/Arch/PPC64.cpp
@@ -26,6 +26,7 @@ using namespace lld::elf;
 constexpr uint64_t ppc64TocOffset = 0x8000;
 constexpr uint64_t dynamicThreadPointerOffset = 0x8000;
 
+namespace {
 // The instruction encoding of bits 21-30 from the ISA for the Xform and Dform
 // instructions that can be used as part of the initial exec TLS sequence.
 enum XFormOpcd {
@@ -139,6 +140,7 @@ enum class PPCPrefixedInsn : uint64_t {
   PSTXV = PREFIX_8LS | 0xd8000000,
   PSTXVP = PREFIX_8LS | 0xf8000000
 };
+
 static bool checkPPCLegacyInsn(uint32_t encoding) {
   PPCLegacyInsn insn = static_cast<PPCLegacyInsn>(encoding);
   if (insn == PPCLegacyInsn::NOINSN)
@@ -164,7 +166,6 @@ enum class LegacyToPrefixMask : uint64_t {
       0x8000000003e00000, // S/T (6-10) - The [S/T]X bit moves from 28 to 5.
 };
 
-namespace {
 class PPC64 final : public TargetInfo {
 public:
   PPC64();
diff --git a/lld/ELF/Arch/RISCV.cpp b/lld/ELF/Arch/RISCV.cpp
index 5fcab4d39d43a8..4798c86f7d1b61 100644
--- a/lld/ELF/Arch/RISCV.cpp
+++ b/lld/ELF/Arch/RISCV.cpp
@@ -57,6 +57,7 @@ class RISCV final : public TargetInfo {
 
 const uint64_t dtpOffset = 0x800;
 
+namespace {
 enum Op {
   ADDI = 0x13,
   AUIPC = 0x17,
@@ -78,6 +79,7 @@ enum Reg {
   X_A0 = 10,
   X_T3 = 28,
 };
+} // namespace
 
 static uint32_t hi20(uint32_t val) { return (val + 0x800) >> 12; }
 static uint32_t lo12(uint32_t val) { return val & 4095; }

Copy link
Member

@thesamesam thesamesam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@MaskRay MaskRay merged commit 4a3f7e7 into main Mar 1, 2024
6 of 7 checks passed
@MaskRay MaskRay deleted the users/MaskRay/spr/elf-internalize-enum branch March 1, 2024 19:17
@MaskRay MaskRay added this to the LLVM 18.X Release milestone Mar 1, 2024
@MaskRay
Copy link
Member Author

MaskRay commented Mar 1, 2024

/cherry-pick 4a3f7e7

llvmbot pushed a commit to llvmbot/llvm-project that referenced this pull request Mar 1, 2024
g++ -flto has a diagnostic `-Wodr` about mismatched redeclarations,
which even apply to `enum`.

Fix llvm#83529

Reviewers: thesamesam

Reviewed By: thesamesam

Pull Request: llvm#83604

(cherry picked from commit 4a3f7e7)
@llvmbot
Copy link
Collaborator

llvmbot commented Mar 1, 2024

/pull-request #83613

llvmbot pushed a commit to llvmbot/llvm-project that referenced this pull request Mar 13, 2024
g++ -flto has a diagnostic `-Wodr` about mismatched redeclarations,
which even apply to `enum`.

Fix llvm#83529

Reviewers: thesamesam

Reviewed By: thesamesam

Pull Request: llvm#83604

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

Successfully merging this pull request may close these issues.

ODR warnings in lld/ELF/Arch/{RISCV,LoongArch}
3 participants