[llvm] 0605b8b - [MCDisassembler] Work around GCC 7 after f4c16c44737caac25bf09ec2d85809820579ae40

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Sun Dec 4 19:34:21 PST 2022


Author: Fangrui Song
Date: 2022-12-05T03:34:14Z
New Revision: 0605b8bf3f2f5ab31e432502f84eab45fb3350fa

URL: https://github.com/llvm/llvm-project/commit/0605b8bf3f2f5ab31e432502f84eab45fb3350fa
DIFF: https://github.com/llvm/llvm-project/commit/0605b8bf3f2f5ab31e432502f84eab45fb3350fa.diff

LOG: [MCDisassembler] Work around GCC 7 after f4c16c44737caac25bf09ec2d85809820579ae40

The use of union isn't really necessary. So just flatten its fields.

Added: 
    

Modified: 
    llvm/include/llvm/MC/MCDisassembler/MCDisassembler.h
    llvm/lib/MC/MCDisassembler/MCDisassembler.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/MC/MCDisassembler/MCDisassembler.h b/llvm/include/llvm/MC/MCDisassembler/MCDisassembler.h
index 55cba3c3bae9..fc2d22eee8df 100644
--- a/llvm/include/llvm/MC/MCDisassembler/MCDisassembler.h
+++ b/llvm/include/llvm/MC/MCDisassembler/MCDisassembler.h
@@ -19,24 +19,19 @@
 
 namespace llvm {
 
-struct XCOFFSymbolInfo {
+struct XCOFFSymbolInfoTy {
   std::optional<XCOFF::StorageMappingClass> StorageMappingClass;
   std::optional<uint32_t> Index;
-  bool IsLabel;
-  XCOFFSymbolInfo(std::optional<XCOFF::StorageMappingClass> Smc,
-                  std::optional<uint32_t> Idx, bool Label)
-      : StorageMappingClass(Smc), Index(Idx), IsLabel(Label) {}
-
-  bool operator<(const XCOFFSymbolInfo &SymInfo) const;
+  bool IsLabel = false;
+  bool operator<(const XCOFFSymbolInfoTy &SymInfo) const;
 };
 
 struct SymbolInfoTy {
   uint64_t Addr;
   StringRef Name;
-  union {
-    uint8_t Type;
-    XCOFFSymbolInfo XCOFFSymInfo;
-  };
+  // XCOFF uses XCOFFSymInfo. Other targets use Type.
+  XCOFFSymbolInfoTy XCOFFSymInfo;
+  uint8_t Type;
 
 private:
   bool IsXCOFF;
@@ -46,8 +41,8 @@ struct SymbolInfoTy {
   SymbolInfoTy(uint64_t Addr, StringRef Name,
                std::optional<XCOFF::StorageMappingClass> Smc,
                std::optional<uint32_t> Idx, bool Label)
-      : Addr(Addr), Name(Name), XCOFFSymInfo(Smc, Idx, Label), IsXCOFF(true),
-        HasType(false) {}
+      : Addr(Addr), Name(Name), XCOFFSymInfo{Smc, Idx, Label}, Type(0),
+        IsXCOFF(true), HasType(false) {}
   SymbolInfoTy(uint64_t Addr, StringRef Name, uint8_t Type,
                bool IsXCOFF = false)
       : Addr(Addr), Name(Name), Type(Type), IsXCOFF(IsXCOFF), HasType(true) {}

diff  --git a/llvm/lib/MC/MCDisassembler/MCDisassembler.cpp b/llvm/lib/MC/MCDisassembler/MCDisassembler.cpp
index e3a084800977..6d7f6ed48ea0 100644
--- a/llvm/lib/MC/MCDisassembler/MCDisassembler.cpp
+++ b/llvm/lib/MC/MCDisassembler/MCDisassembler.cpp
@@ -82,7 +82,7 @@ static uint8_t getSMCPriority(XCOFF::StorageMappingClass SMC) {
 /// The symbols in the same section are sorted in ascending order.
 /// llvm-objdump -D will choose the highest priority symbol to display when
 /// there are symbols with the same address.
-bool XCOFFSymbolInfo::operator<(const XCOFFSymbolInfo &SymInfo) const {
+bool XCOFFSymbolInfoTy::operator<(const XCOFFSymbolInfoTy &SymInfo) const {
   // Label symbols have higher priority than non-label symbols.
   if (IsLabel != SymInfo.IsLabel)
     return SymInfo.IsLabel;


        


More information about the llvm-commits mailing list