Assembler should accept redefinitions of unused variable symbols.
authorJim Grosbach <grosbach@apple.com>
Tue, 20 Mar 2012 21:33:21 +0000 (21:33 +0000)
committerJim Grosbach <grosbach@apple.com>
Tue, 20 Mar 2012 21:33:21 +0000 (21:33 +0000)
rdar://11027851

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@153137 91177308-0d34-0410-b5e6-96231b3b80d8

lib/MC/MCParser/AsmParser.cpp
lib/MC/MCSymbol.cpp
test/MC/AsmParser/variables-invalid.s

index 41ad1642d28f8c4f45590f6b4474cd02c123bfaf..ab5ddaf4ac005b311100234e31a561bc605071c4 100644 (file)
@@ -1629,6 +1629,8 @@ bool AsmParser::ParseAssignment(StringRef Name, bool allow_redef) {
       return Error(EqualLoc, "Recursive use of '" + Name + "'");
     else if (Sym->isUndefined() && !Sym->isUsed() && !Sym->isVariable())
       ; // Allow redefinitions of undefined symbols only used in directives.
+    else if (Sym->isVariable() && !Sym->isUsed() && allow_redef)
+      ; // Allow redefinitions of variables that haven't yet been used.
     else if (!Sym->isUndefined() && (!Sym->isVariable() || !allow_redef))
       return Error(EqualLoc, "redefinition of '" + Name + "'");
     else if (!Sym->isVariable())
index 87b58d7a533242b3317d757c311b67a08ed5271f..e013e77f58af1ad071a8167f5a26c7a6d039ec62 100644 (file)
@@ -54,8 +54,6 @@ const MCSymbol &MCSymbol::AliasedSymbol() const {
 void MCSymbol::setVariableValue(const MCExpr *Value) {
   assert(!IsUsed && "Cannot set a variable that has already been used.");
   assert(Value && "Invalid variable value!");
-  assert((isUndefined() || (isAbsolute() && isa<MCConstantExpr>(Value))) &&
-         "Invalid redefinition!");
   this->Value = Value;
 
   // Variables should always be marked as in the same "section" as the value.
index 21758d20c8b2644738fc6b50a5520c0f91137681..c466d422b9699377b87564232d0595600061e0ba 100644 (file)
@@ -13,6 +13,7 @@ t2_s0:
         t2_s0 = 2
 
         t3_s0 = t2_s0 + 1
+        .long t3_s0
 // CHECK: invalid reassignment of non-absolute variable 't3_s0'
         t3_s0 = 1