[llvm-commits] [llvm] r84232 - in /llvm/trunk: lib/MC/MCAsmStreamer.cpp test/MC/AsmParser/variables-invalid.s tools/llvm-mc/AsmParser.cpp
Daniel Dunbar
daniel at zuster.org
Thu Oct 15 18:57:39 PDT 2009
Author: ddunbar
Date: Thu Oct 15 20:57:39 2009
New Revision: 84232
URL: http://llvm.org/viewvc/llvm-project?rev=84232&view=rev
Log:
MC: Tweak variable assignment diagnostics, and make reassignment of non-absolute
variables and symbols invalid.
Added:
llvm/trunk/test/MC/AsmParser/variables-invalid.s
Modified:
llvm/trunk/lib/MC/MCAsmStreamer.cpp
llvm/trunk/tools/llvm-mc/AsmParser.cpp
Modified: llvm/trunk/lib/MC/MCAsmStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCAsmStreamer.cpp?rev=84232&r1=84231&r2=84232&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCAsmStreamer.cpp (original)
+++ llvm/trunk/lib/MC/MCAsmStreamer.cpp Thu Oct 15 20:57:39 2009
@@ -125,6 +125,7 @@
OS << '\n';
// FIXME: Lift context changes into super class.
+ // FIXME: Set associated section.
Symbol->setValue(Value);
}
Added: llvm/trunk/test/MC/AsmParser/variables-invalid.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/AsmParser/variables-invalid.s?rev=84232&view=auto
==============================================================================
--- llvm/trunk/test/MC/AsmParser/variables-invalid.s (added)
+++ llvm/trunk/test/MC/AsmParser/variables-invalid.s Thu Oct 15 20:57:39 2009
@@ -0,0 +1,17 @@
+// RUN: not llvm-mc %s 2> %t
+// RUN: FileCheck --input-file %t %s
+
+ .data
+// CHECK: invalid assignment to 't0_v0'
+ t0_v0 = t0_v0 + 1
+
+ t1_v1 = 1
+ t1_v1 = 2
+
+t2_s0:
+// CHECK: redefinition of 't2_s0'
+ t2_s0 = 2
+
+ t3_s0 = t2_s0 + 1
+// CHECK: invalid reassignment of non-absolute variable 't3_s0'
+ t3_s0 = 1
Modified: llvm/trunk/tools/llvm-mc/AsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mc/AsmParser.cpp?rev=84232&r1=84231&r2=84232&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-mc/AsmParser.cpp (original)
+++ llvm/trunk/tools/llvm-mc/AsmParser.cpp Thu Oct 15 20:57:39 2009
@@ -741,14 +741,25 @@
// 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);
More information about the llvm-commits
mailing list