diff options
| author | Daniel Dunbar <daniel@zuster.org> | 2009-10-16 01:57:39 +0000 |
|---|---|---|
| committer | Daniel Dunbar <daniel@zuster.org> | 2009-10-16 01:57:39 +0000 |
| commit | 5f339244fbff3ca33476f1406a80d0b85193db9e (patch) | |
| tree | 44a907caf62c5002cf620d0686bab734b6780929 /llvm/tools/llvm-mc/AsmParser.cpp | |
| parent | 35a99d95b339b3c9b9a6bdf39174f6a15a54f349 (diff) | |
| download | bcm5719-llvm-5f339244fbff3ca33476f1406a80d0b85193db9e.tar.gz bcm5719-llvm-5f339244fbff3ca33476f1406a80d0b85193db9e.zip | |
MC: Tweak variable assignment diagnostics, and make reassignment of non-absolute
variables and symbols invalid.
llvm-svn: 84232
Diffstat (limited to 'llvm/tools/llvm-mc/AsmParser.cpp')
| -rw-r--r-- | llvm/tools/llvm-mc/AsmParser.cpp | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/llvm/tools/llvm-mc/AsmParser.cpp b/llvm/tools/llvm-mc/AsmParser.cpp index 7174fa8ee8e..02b7c396a4b 100644 --- a/llvm/tools/llvm-mc/AsmParser.cpp +++ b/llvm/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); |

