Skip to content

Commit

Permalink
AsmParser: Disable Darwin-style macro argument expansion on non-darwi…
Browse files Browse the repository at this point in the history
…n targets.

There is code in the wild that relies on $0 not being expanded.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@201784 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
d0k committed Feb 20, 2014
1 parent 7934a2a commit 59f6c76
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
6 changes: 3 additions & 3 deletions lib/MC/MCParser/AsmParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1730,7 +1730,7 @@ bool AsmParser::expandMacro(raw_svector_ostream &OS, StringRef Body,
ArrayRef<MCAsmMacroParameter> Parameters,
ArrayRef<MCAsmMacroArgument> A, const SMLoc &L) {
unsigned NParameters = Parameters.size();
if (NParameters != 0 && NParameters != A.size())
if ((!IsDarwin || NParameters != 0) && NParameters != A.size())
return Error(L, "Wrong number of arguments");

// A macro without parameters is handled differently on Darwin:
Expand All @@ -1740,7 +1740,7 @@ bool AsmParser::expandMacro(raw_svector_ostream &OS, StringRef Body,
std::size_t End = Body.size(), Pos = 0;
for (; Pos != End; ++Pos) {
// Check for a substitution or escape.
if (!NParameters) {
if (IsDarwin && !NParameters) {
// This macro has no parameters, look for $0, $1, etc.
if (Body[Pos] != '$' || Pos + 1 == End)
continue;
Expand All @@ -1763,7 +1763,7 @@ bool AsmParser::expandMacro(raw_svector_ostream &OS, StringRef Body,
if (Pos == End)
break;

if (!NParameters) {
if (IsDarwin && !NParameters) {
switch (Body[Pos + 1]) {
// $$ => $
case '$':
Expand Down
2 changes: 1 addition & 1 deletion test/MC/AsmParser/exprs.s
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: llvm-mc -triple i386-unknown-unknown %s > %t
// RUN: llvm-mc -triple i386-apple-darwin %s

.macro check_expr
.if ($0) != ($1)
Expand Down
12 changes: 12 additions & 0 deletions test/MC/AsmParser/macros-gas.s
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,15 @@ test8 1,2 3

// CHECK: .ascii "1,2,3"
test8 1 2, 3

.macro test10
.ascii "$20"
.endm

test10
// CHECK: .ascii "$20"

test10 42
// CHECK-ERRORS: 102:10: error: Wrong number of arguments
// CHECK-ERRORS-NEXT: test10 42
// CHECK-ERRORS-NEXT: ^

0 comments on commit 59f6c76

Please sign in to comment.