From 833393e021dc1b3844ac6982455a32c2e55f748e Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Mon, 15 Nov 2021 12:09:09 -0500 Subject: [PATCH] [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 --- llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp | 7 ++++--- llvm/test/CodeGen/Generic/inline-asm-special-strings.ll | 9 ++++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp index 041a5d791f87..dd15ba515002 100644 --- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp @@ -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; } diff --git a/llvm/test/CodeGen/Generic/inline-asm-special-strings.ll b/llvm/test/CodeGen/Generic/inline-asm-special-strings.ll index 5ef568863bad..5f9f34d1e78c 100644 --- a/llvm/test/CodeGen/Generic/inline-asm-special-strings.ll +++ b/llvm/test/CodeGen/Generic/inline-asm-special-strings.ll @@ -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 }