[llvm-commits] [llvm] r149174 - in /llvm/trunk: lib/MC/MCParser/AsmParser.cpp test/MC/AsmParser/pr11865.s test/MC/AsmParser/variables-invalid.s
Rafael Espindola
rafael.espindola at gmail.com
Fri Jan 27 21:57:00 PST 2012
Author: rafael
Date: Fri Jan 27 23:57:00 2012
New Revision: 149174
URL: http://llvm.org/viewvc/llvm-project?rev=149174&view=rev
Log:
Handle recursive variable definitions directly. This gives us better error
messages and allows us to fix PR11865.
Added:
llvm/trunk/test/MC/AsmParser/pr11865.s
Modified:
llvm/trunk/lib/MC/MCParser/AsmParser.cpp
llvm/trunk/test/MC/AsmParser/variables-invalid.s
Modified: llvm/trunk/lib/MC/MCParser/AsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCParser/AsmParser.cpp?rev=149174&r1=149173&r2=149174&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCParser/AsmParser.cpp (original)
+++ llvm/trunk/lib/MC/MCParser/AsmParser.cpp Fri Jan 27 23:57:00 2012
@@ -1553,22 +1553,22 @@
ActiveMacros.pop_back();
}
-static void MarkUsed(const MCExpr *Value) {
+static bool IsUsedIn(const MCSymbol *Sym, const MCExpr *Value) {
switch (Value->getKind()) {
- case MCExpr::Binary:
- MarkUsed(static_cast<const MCBinaryExpr*>(Value)->getLHS());
- MarkUsed(static_cast<const MCBinaryExpr*>(Value)->getRHS());
+ case MCExpr::Binary: {
+ const MCBinaryExpr *BE = static_cast<const MCBinaryExpr*>(Value);
+ return IsUsedIn(Sym, BE->getLHS()) || IsUsedIn(Sym, BE->getRHS());
break;
+ }
case MCExpr::Target:
case MCExpr::Constant:
- break;
+ return false;
case MCExpr::SymbolRef: {
- static_cast<const MCSymbolRefExpr*>(Value)->getSymbol().setUsed(true);
- break;
+ const MCSymbol &S = static_cast<const MCSymbolRefExpr*>(Value)->getSymbol();
+ return &S.AliasedSymbol() == Sym;
}
case MCExpr::Unary:
- MarkUsed(static_cast<const MCUnaryExpr*>(Value)->getSubExpr());
- break;
+ return IsUsedIn(Sym, static_cast<const MCUnaryExpr*>(Value)->getSubExpr());
}
}
@@ -1580,7 +1580,9 @@
if (ParseExpression(Value))
return true;
- MarkUsed(Value);
+ // Note: we don't count b as used in "a = b". This is to allow
+ // a = b
+ // b = c
if (Lexer.isNot(AsmToken::EndOfStatement))
return TokError("unexpected token in assignment");
@@ -1602,7 +1604,9 @@
//
// 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->isUsed() && !Sym->isVariable())
+ if (IsUsedIn(Sym, Value))
+ 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->isUndefined() && (!Sym->isVariable() || !allow_redef))
return Error(EqualLoc, "redefinition of '" + Name + "'");
Added: llvm/trunk/test/MC/AsmParser/pr11865.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/AsmParser/pr11865.s?rev=149174&view=auto
==============================================================================
--- llvm/trunk/test/MC/AsmParser/pr11865.s (added)
+++ llvm/trunk/test/MC/AsmParser/pr11865.s Fri Jan 27 23:57:00 2012
@@ -0,0 +1,6 @@
+// RUN: llvm-mc -triple i386-unknown-unknown %s
+
+i:
+ .long g
+g = h
+h = i
Modified: llvm/trunk/test/MC/AsmParser/variables-invalid.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/AsmParser/variables-invalid.s?rev=149174&r1=149173&r2=149174&view=diff
==============================================================================
--- llvm/trunk/test/MC/AsmParser/variables-invalid.s (original)
+++ llvm/trunk/test/MC/AsmParser/variables-invalid.s Fri Jan 27 23:57:00 2012
@@ -2,7 +2,7 @@
// RUN: FileCheck --input-file %t %s
.data
-// CHECK: invalid assignment to 't0_v0'
+// CHECK: Recursive use of 't0_v0'
t0_v0 = t0_v0 + 1
t1_v1 = 1
@@ -15,3 +15,9 @@
t3_s0 = t2_s0 + 1
// CHECK: invalid reassignment of non-absolute variable 't3_s0'
t3_s0 = 1
+
+
+// CHECK: Recursive use of 't4_s2'
+ t4_s0 = t4_s1
+ t4_s1 = t4_s2
+ t4_s2 = t4_s0
More information about the llvm-commits
mailing list