summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2009-10-16 01:57:39 +0000
committerDaniel Dunbar <daniel@zuster.org>2009-10-16 01:57:39 +0000
commit75773ff00da79ecf65e8578cf6f013295a2069cf (patch)
treedf1aeb9b697d49ebf34b3e742fbdc933de86918b /tools
parentfffff915d53361fc575621c5e04ae7df99dd3fab (diff)
downloadllvm-75773ff00da79ecf65e8578cf6f013295a2069cf.tar.gz
llvm-75773ff00da79ecf65e8578cf6f013295a2069cf.tar.bz2
llvm-75773ff00da79ecf65e8578cf6f013295a2069cf.tar.xz
MC: Tweak variable assignment diagnostics, and make reassignment of non-absolute
variables and symbols invalid. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@84232 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools')
-rw-r--r--tools/llvm-mc/AsmParser.cpp25
1 files changed, 18 insertions, 7 deletions
diff --git a/tools/llvm-mc/AsmParser.cpp b/tools/llvm-mc/AsmParser.cpp
index 7174fa8ee8..02b7c396a4 100644
--- a/tools/llvm-mc/AsmParser.cpp
+++ b/tools/llvm-mc/AsmParser.cpp
@@ -741,14 +741,25 @@ bool AsmParser::ParseAssignment(const StringRef &Name) {
// Eat the end of statement marker.
Lexer.Lex();
- // Diagnose assignment to a label.
- //
- // FIXME: Diagnostics. Note the location of the definition as a label.
+ // Validate that the LHS is allowed to be a variable (either it has not been
+ // used as a symbol, or it is an absolute symbol).
+ MCSymbol *Sym = getContext().LookupSymbol(Name);
+ if (Sym) {
+ // Diagnose assignment to a label.
+ //
+ // FIXME: Diagnostics. Note the location of the definition as a label.
+ // FIXME: Diagnose assignment to protected identifier (e.g., register name).
+ if (!Sym->isUndefined() && !Sym->isAbsolute())
+ return Error(EqualLoc, "redefinition of '" + Name + "'");
+ else if (!Sym->isVariable())
+ return Error(EqualLoc, "invalid assignment to '" + Name + "'");
+ else if (!isa<MCConstantExpr>(Sym->getValue()))
+ return Error(EqualLoc, "invalid reassignment of non-absolute variable '" +
+ Name + "'");
+ } else
+ Sym = CreateSymbol(Name);
+
// FIXME: Handle '.'.
- // FIXME: Diagnose assignment to protected identifier (e.g., register name).
- MCSymbol *Sym = CreateSymbol(Name);
- if (!Sym->isUndefined() && !Sym->isAbsolute())
- return Error(EqualLoc, "symbol has already been defined");
// Do the assignment.
Out.EmitAssignment(Sym, Value);