[llvm] 57b0843 - MCSymbol: Remove isUnset

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Sun Aug 3 21:31:16 PDT 2025


Author: Fangrui Song
Date: 2025-08-03T21:31:11-07:00
New Revision: 57b0843f68f5f349c73d1bf54e321a1a6d1800bf

URL: https://github.com/llvm/llvm-project/commit/57b0843f68f5f349c73d1bf54e321a1a6d1800bf
DIFF: https://github.com/llvm/llvm-project/commit/57b0843f68f5f349c73d1bf54e321a1a6d1800bf.diff

LOG: MCSymbol: Remove isUnset

The isUnset state lacks significance and should be treated as equivalent
to an undefined symbol.

Equated and common symbols seem to have subtle semantic distinctions in
GAS, justifying the use of distinct `SymContents*` values.

TODO: Ensure common symbols have a fragment, so that `isDefined()`
returns true, rejecting `.comm c, 4, 4; .set c, 4`

Added: 
    

Modified: 
    llvm/include/llvm/MC/MCSymbol.h
    llvm/lib/MC/MCParser/AsmParser.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/MC/MCSymbol.h b/llvm/include/llvm/MC/MCSymbol.h
index 123e96ef4526a..ddc560ec52501 100644
--- a/llvm/include/llvm/MC/MCSymbol.h
+++ b/llvm/include/llvm/MC/MCSymbol.h
@@ -41,11 +41,9 @@ class raw_ostream;
 /// it is a reference to an external entity, it has a null section.
 class MCSymbol {
 protected:
-  /// A symbol can contain an Offset, or Value, or be Common, but never more
-  /// than one of these.
+  // A symbol can be regular, equated to an expression, or a common symbol.
   enum Contents : uint8_t {
     SymContentsUnset,
-    SymContentsOffset,
     SymContentsVariable,
     SymContentsCommon,
     SymContentsTargetCommon, // Index stores the section index
@@ -294,20 +292,15 @@ class MCSymbol {
     Index = Value;
   }
 
-  bool isUnset() const { return SymbolContents == SymContentsUnset; }
-
   uint64_t getOffset() const {
-    assert((SymbolContents == SymContentsUnset ||
-            SymbolContents == SymContentsOffset) &&
+    assert(SymbolContents == SymContentsUnset &&
            "Cannot get offset for a common/variable symbol");
     return Offset;
   }
   void setOffset(uint64_t Value) {
-    assert((SymbolContents == SymContentsUnset ||
-            SymbolContents == SymContentsOffset) &&
+    assert(SymbolContents == SymContentsUnset &&
            "Cannot set offset for a common/variable symbol");
     Offset = Value;
-    SymbolContents = SymContentsOffset;
   }
 
   /// Return the size of a 'common' symbol.

diff  --git a/llvm/lib/MC/MCParser/AsmParser.cpp b/llvm/lib/MC/MCParser/AsmParser.cpp
index c5611a3859dd1..7782dc1f50055 100644
--- a/llvm/lib/MC/MCParser/AsmParser.cpp
+++ b/llvm/lib/MC/MCParser/AsmParser.cpp
@@ -6273,7 +6273,8 @@ bool parseAssignmentExpression(StringRef Name, bool allow_redef,
   // used as a symbol, or it is an absolute symbol).
   Sym = Parser.getContext().lookupSymbol(Name);
   if (Sym) {
-    if (!Sym->isUnset() && (!allow_redef || !Sym->isRedefinable()))
+    if ((Sym->isVariable() || Sym->isDefined()) &&
+        (!allow_redef || !Sym->isRedefinable()))
       return Parser.Error(EqualLoc, "redefinition of '" + Name + "'");
     // If the symbol is redefinable, clone it and update the symbol table
     // to the new symbol. Existing references to the original symbol remain


        


More information about the llvm-commits mailing list