Index: lib/MC/MCParser/AsmParser.cpp =================================================================== --- lib/MC/MCParser/AsmParser.cpp +++ lib/MC/MCParser/AsmParser.cpp @@ -689,13 +689,14 @@ // Variable symbols may not be marked as defined, so check those // explicitly. If we know it's a variable, we have a definition for // the purposes of this check. - if (Sym->isTemporary() && !Sym->isVariable() && !Sym->isDefined()) + if (Sym->isTemporary() && !Sym->isVariable() && + !Sym->isDefined(/*SetUsed*/ false)) // FIXME: We would really like to refer back to where the symbol was // first referenced for a source location. We need to add something // to track that. Currently, we just point to the end of the file. - printMessage( - getLexer().getLoc(), SourceMgr::DK_Error, - "assembler local symbol '" + Sym->getName() + "' not defined"); + printMessage(getLexer().getLoc(), SourceMgr::DK_Error, + "assembler local symbol '" + Sym->getName() + + "' not defined"); } } @@ -867,11 +868,12 @@ // If this is an absolute variable reference, substitute it now to preserve // semantics in the face of reassignment. - if (Sym->isVariable() && isa(Sym->getVariableValue())) { + if (Sym->isVariable() && + isa(Sym->getVariableValue(/*SetUsed*/ false))) { if (Variant) return Error(EndLoc, "unexpected modifier on variable reference"); - Res = Sym->getVariableValue(); + Res = Sym->getVariableValue(/*SetUsed*/ false); return false; } @@ -903,7 +905,7 @@ MCSymbol *Sym = Ctx.getDirectionalLocalSymbol(IntVal, IDVal == "b"); Res = MCSymbolRefExpr::create(Sym, Variant, getContext()); - if (IDVal == "b" && Sym->isUndefined()) + if (IDVal == "b" && Sym->isUndefined(/*SetUsed*/ false)) return Error(Loc, "invalid reference to undefined symbol"); EndLoc = Lexer.getTok().getEndLoc(); Lex(); // Eat identifier. @@ -1346,7 +1348,7 @@ Sym->redefineIfPossible(); - if (!Sym->isUndefined() || Sym->isVariable()) + if (!Sym->isUndefined(/*SetUsed*/ false) || Sym->isVariable()) return Error(IDLoc, "invalid symbol redefinition"); // Emit the label. @@ -3752,7 +3754,7 @@ return Error(Pow2AlignmentLoc, "invalid '.comm' or '.lcomm' directive " "alignment, can't be less than zero"); - if (!Sym->isUndefined()) + if (!Sym->isUndefined(/*SetUsed*/ false)) return Error(IDLoc, "invalid symbol redefinition"); // Create the Symbol as a common or local common with Size and Pow2Alignment @@ -4002,9 +4004,9 @@ MCSymbol *Sym = getContext().lookupSymbol(Name); if (expect_defined) - TheCondState.CondMet = (Sym && !Sym->isUndefined()); + TheCondState.CondMet = (Sym && !Sym->isUndefined(/*SetUsed*/ false)); else - TheCondState.CondMet = (!Sym || Sym->isUndefined()); + TheCondState.CondMet = (!Sym || Sym->isUndefined(/*SetUsed*/ false)); TheCondState.Ignore = !TheCondState.CondMet; } @@ -4760,7 +4762,8 @@ const MCSymbol &S = static_cast(Value)->getSymbol(); if (S.isVariable()) - return isSymbolUsedInExpression(Sym, S.getVariableValue()); + return isSymbolUsedInExpression(Sym, + S.getVariableValue(/*SetUsed*/ false)); return &S == Sym; } case MCExpr::Unary: @@ -4805,21 +4808,20 @@ // FIXME: Diagnose assignment to protected identifier (e.g., register name). if (isSymbolUsedInExpression(Sym, Value)) return Parser.Error(EqualLoc, "Recursive use of '" + Name + "'"); - else if (Sym->isUndefined() && !Sym->isUsed() && !Sym->isVariable()) + else if (Sym->isUndefined(/*SetUsed*/ false) && !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)) + else if (!Sym->isUndefined(/*SetUsed*/ false) && + (!Sym->isVariable() || !allow_redef)) return Parser.Error(EqualLoc, "redefinition of '" + Name + "'"); else if (!Sym->isVariable()) return Parser.Error(EqualLoc, "invalid assignment to '" + Name + "'"); - else if (!isa(Sym->getVariableValue())) + else if (!isa(Sym->getVariableValue(/*SetUsed*/ false))) return Parser.Error(EqualLoc, "invalid reassignment of non-absolute variable '" + Name + "'"); - - // Don't count these checks as uses. - Sym->setUsed(false); } else if (Name == ".") { if (Parser.getStreamer().EmitValueToOffset(Value, 0)) { Parser.Error(EqualLoc, "expected absolute expression"); Index: test/MC/AsmParser/reassign.s =================================================================== --- /dev/null +++ test/MC/AsmParser/reassign.s @@ -0,0 +1,12 @@ +// RUN: llvm-mc -triple i386-unknown-unknown %s | FileCheck %s + + .text +bar: + + .data +.globl foo +.set foo, bar +.globl foo +.set foo, bar + +// CHECK-NOT: invalid reassignment of non-absolute variable