[asm] Correctly handle special names in variants

There's really no reason why anyone should use these special names in a variant.
I noticed this while reading the code: all other writes to OS are guarded by
this conditional, and the behavior with the check seems more correct, so
let's add the check.

Differential Revision: https://reviews.llvm.org/D113909
This commit is contained in:
Nico Weber 2021-11-15 12:09:09 -05:00
parent f50c6c1718
commit 833393e021
2 changed files with 10 additions and 6 deletions

View File

@ -351,9 +351,10 @@ static void EmitGCCInlineAsmStr(const char *AsmStr, const MachineInstr *MI,
if (!StrEnd)
report_fatal_error("Unterminated ${:foo} operand in inline asm"
" string: '" + Twine(AsmStr) + "'");
std::string Val(StrStart, StrEnd);
AP->PrintSpecial(MI, OS, Val.c_str());
if (CurVariant == -1 || CurVariant == AsmPrinterVariant) {
std::string Val(StrStart, StrEnd);
AP->PrintSpecial(MI, OS, Val.c_str());
}
LastEmitted = StrEnd+1;
break;
}

View File

@ -1,6 +1,9 @@
; RUN: llc -no-integrated-as < %s | grep "foo 0 0"
; RUN: llc -no-integrated-as < %s | FileCheck %s
define void @bar() nounwind {
tail call void asm sideeffect "foo ${:uid} ${:uid}", ""() nounwind
ret void
; CHECK: foo 0 0{{$}}
tail call void asm sideeffect "foo ${:uid} ${:uid}", ""() nounwind
; CHECK: bar 1 x{{$}}
tail call void asm sideeffect "bar $(${:uid} x$| ${:uid} x$)", ""() nounwind
ret void
}