Skip to content

Commit 57b0843

Browse files
committed
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`
1 parent 5478da9 commit 57b0843

File tree

2 files changed

+5
-11
lines changed

2 files changed

+5
-11
lines changed

llvm/include/llvm/MC/MCSymbol.h

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,9 @@ class raw_ostream;
4141
/// it is a reference to an external entity, it has a null section.
4242
class MCSymbol {
4343
protected:
44-
/// A symbol can contain an Offset, or Value, or be Common, but never more
45-
/// than one of these.
44+
// A symbol can be regular, equated to an expression, or a common symbol.
4645
enum Contents : uint8_t {
4746
SymContentsUnset,
48-
SymContentsOffset,
4947
SymContentsVariable,
5048
SymContentsCommon,
5149
SymContentsTargetCommon, // Index stores the section index
@@ -294,20 +292,15 @@ class MCSymbol {
294292
Index = Value;
295293
}
296294

297-
bool isUnset() const { return SymbolContents == SymContentsUnset; }
298-
299295
uint64_t getOffset() const {
300-
assert((SymbolContents == SymContentsUnset ||
301-
SymbolContents == SymContentsOffset) &&
296+
assert(SymbolContents == SymContentsUnset &&
302297
"Cannot get offset for a common/variable symbol");
303298
return Offset;
304299
}
305300
void setOffset(uint64_t Value) {
306-
assert((SymbolContents == SymContentsUnset ||
307-
SymbolContents == SymContentsOffset) &&
301+
assert(SymbolContents == SymContentsUnset &&
308302
"Cannot set offset for a common/variable symbol");
309303
Offset = Value;
310-
SymbolContents = SymContentsOffset;
311304
}
312305

313306
/// Return the size of a 'common' symbol.

llvm/lib/MC/MCParser/AsmParser.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6273,7 +6273,8 @@ bool parseAssignmentExpression(StringRef Name, bool allow_redef,
62736273
// used as a symbol, or it is an absolute symbol).
62746274
Sym = Parser.getContext().lookupSymbol(Name);
62756275
if (Sym) {
6276-
if (!Sym->isUnset() && (!allow_redef || !Sym->isRedefinable()))
6276+
if ((Sym->isVariable() || Sym->isDefined()) &&
6277+
(!allow_redef || !Sym->isRedefinable()))
62776278
return Parser.Error(EqualLoc, "redefinition of '" + Name + "'");
62786279
// If the symbol is redefinable, clone it and update the symbol table
62796280
// to the new symbol. Existing references to the original symbol remain

0 commit comments

Comments
 (0)