[llvm] [NFC] Add SHF_NONE to fix Werror=extra warning (PR #112808)

Jinsong Ji via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 18 06:09:27 PDT 2024


https://github.com/jsji updated https://github.com/llvm/llvm-project/pull/112808

>From 9fcfbd339b9b7001dd5023fbc44960bbce0a9105 Mon Sep 17 00:00:00 2001
From: Jinsong Ji <jinsong.ji at intel.com>
Date: Fri, 18 Oct 2024 04:03:13 +0200
Subject: [PATCH 1/5] [NFC] Add SHF_NONE to fix Werror=extra warning
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This is one of the many PRs to fix errors with LLVM_ENABLE_WERROR=on. Built by GCC 11.

Fix warnings:

llvm-project/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp: In member function ‘void llvm::AsmPrinter::emitJumpTableSizesSection(const llvm::MachineJumpTableInfo*, const llvm::Function&) const’:
llvm-project/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp:2852:31: error: enumerated and non-enumerated type in conditional expression [-Werror=extra]
 2852 |     int Flags = F.hasComdat() ? ELF::SHF_GROUP : 0;
      |                 ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
---
 llvm/include/llvm/BinaryFormat/ELF.h       | 3 +++
 llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp | 2 +-
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/llvm/include/llvm/BinaryFormat/ELF.h b/llvm/include/llvm/BinaryFormat/ELF.h
index 2eff87c911343f..eb594b1baa9663 100644
--- a/llvm/include/llvm/BinaryFormat/ELF.h
+++ b/llvm/include/llvm/BinaryFormat/ELF.h
@@ -1180,6 +1180,9 @@ enum : unsigned {
 
 // Section flags.
 enum : unsigned {
+  // No flag
+  SHF_NONE= 0x0,
+
   // Section data should be writable during execution.
   SHF_WRITE = 0x1,
 
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index 3a8cde7330efc0..94536f803376ef 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -2849,7 +2849,7 @@ void AsmPrinter::emitJumpTableSizesSection(const MachineJumpTableInfo *MJTI,
 
   if (isElf) {
     MCSymbolELF *LinkedToSym = dyn_cast<MCSymbolELF>(CurrentFnSym);
-    int Flags = F.hasComdat() ? ELF::SHF_GROUP : 0;
+    int Flags = F.hasComdat() ? ELF::SHF_GROUP : ELF::SHF_NONE;
 
     JumpTableSizesSection = OutContext.getELFSection(
         sectionName, ELF::SHT_LLVM_JT_SIZES, Flags, 0, GroupName, F.hasComdat(),

>From 4d5984e68ca916eddecaec4f51c60fc64c0405b0 Mon Sep 17 00:00:00 2001
From: Jinsong Ji <jinsong.ji at intel.com>
Date: Fri, 18 Oct 2024 04:28:10 +0200
Subject: [PATCH 2/5] clangformat

---
 llvm/include/llvm/BinaryFormat/ELF.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/include/llvm/BinaryFormat/ELF.h b/llvm/include/llvm/BinaryFormat/ELF.h
index eb594b1baa9663..2bb50e4b06b44e 100644
--- a/llvm/include/llvm/BinaryFormat/ELF.h
+++ b/llvm/include/llvm/BinaryFormat/ELF.h
@@ -1181,7 +1181,7 @@ enum : unsigned {
 // Section flags.
 enum : unsigned {
   // No flag
-  SHF_NONE= 0x0,
+  SHF_NONE = 0x0,
 
   // Section data should be writable during execution.
   SHF_WRITE = 0x1,

>From 2b81e30221322a1133bc3e48ee3afd01953134ea Mon Sep 17 00:00:00 2001
From: Jinsong Ji <jinsong.ji at intel.com>
Date: Fri, 18 Oct 2024 15:05:20 +0200
Subject: [PATCH 3/5] Revert "clangformat"

This reverts commit 4d5984e68ca916eddecaec4f51c60fc64c0405b0.
---
 llvm/include/llvm/BinaryFormat/ELF.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/include/llvm/BinaryFormat/ELF.h b/llvm/include/llvm/BinaryFormat/ELF.h
index 2bb50e4b06b44e..eb594b1baa9663 100644
--- a/llvm/include/llvm/BinaryFormat/ELF.h
+++ b/llvm/include/llvm/BinaryFormat/ELF.h
@@ -1181,7 +1181,7 @@ enum : unsigned {
 // Section flags.
 enum : unsigned {
   // No flag
-  SHF_NONE = 0x0,
+  SHF_NONE= 0x0,
 
   // Section data should be writable during execution.
   SHF_WRITE = 0x1,

>From 0d08bf6d53d54f0d4cd740e69a48245e19b3423c Mon Sep 17 00:00:00 2001
From: Jinsong Ji <jinsong.ji at intel.com>
Date: Fri, 18 Oct 2024 15:05:22 +0200
Subject: [PATCH 4/5] Revert "[NFC] Add SHF_NONE to fix Werror=extra warning"

This reverts commit 9fcfbd339b9b7001dd5023fbc44960bbce0a9105.
---
 llvm/include/llvm/BinaryFormat/ELF.h       | 3 ---
 llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp | 2 +-
 2 files changed, 1 insertion(+), 4 deletions(-)

diff --git a/llvm/include/llvm/BinaryFormat/ELF.h b/llvm/include/llvm/BinaryFormat/ELF.h
index eb594b1baa9663..2eff87c911343f 100644
--- a/llvm/include/llvm/BinaryFormat/ELF.h
+++ b/llvm/include/llvm/BinaryFormat/ELF.h
@@ -1180,9 +1180,6 @@ enum : unsigned {
 
 // Section flags.
 enum : unsigned {
-  // No flag
-  SHF_NONE= 0x0,
-
   // Section data should be writable during execution.
   SHF_WRITE = 0x1,
 
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index 94536f803376ef..3a8cde7330efc0 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -2849,7 +2849,7 @@ void AsmPrinter::emitJumpTableSizesSection(const MachineJumpTableInfo *MJTI,
 
   if (isElf) {
     MCSymbolELF *LinkedToSym = dyn_cast<MCSymbolELF>(CurrentFnSym);
-    int Flags = F.hasComdat() ? ELF::SHF_GROUP : ELF::SHF_NONE;
+    int Flags = F.hasComdat() ? ELF::SHF_GROUP : 0;
 
     JumpTableSizesSection = OutContext.getELFSection(
         sectionName, ELF::SHT_LLVM_JT_SIZES, Flags, 0, GroupName, F.hasComdat(),

>From 21acf11d1478aa3e7b0e2414a7fe304b98c96ffc Mon Sep 17 00:00:00 2001
From: Jinsong Ji <jinsong.ji at intel.com>
Date: Fri, 18 Oct 2024 15:09:11 +0200
Subject: [PATCH 5/5] cast to unsigned instead

---
 llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index 3a8cde7330efc0..327e7f7f8a1ed8 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -2849,7 +2849,7 @@ void AsmPrinter::emitJumpTableSizesSection(const MachineJumpTableInfo *MJTI,
 
   if (isElf) {
     MCSymbolELF *LinkedToSym = dyn_cast<MCSymbolELF>(CurrentFnSym);
-    int Flags = F.hasComdat() ? ELF::SHF_GROUP : 0;
+    int Flags = F.hasComdat() ? (unsigned)ELF::SHF_GROUP : 0;
 
     JumpTableSizesSection = OutContext.getELFSection(
         sectionName, ELF::SHT_LLVM_JT_SIZES, Flags, 0, GroupName, F.hasComdat(),



More information about the llvm-commits mailing list