OSDN Git Service

[MC] Make llvm-mc fail cleanly on invalid output asm variant.
authorNirav Dave <niravd@google.com>
Mon, 31 Oct 2016 18:36:31 +0000 (18:36 +0000)
committerNirav Dave <niravd@google.com>
Mon, 31 Oct 2016 18:36:31 +0000 (18:36 +0000)
Fixes PR28488.

Reviewers: rnk, majnemer

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D25834

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@285616 91177308-0d34-0410-b5e6-96231b3b80d8

test/MC/AsmParser/invalid-asm-variant.s [new file with mode: 0644]
tools/llvm-mc/llvm-mc.cpp

diff --git a/test/MC/AsmParser/invalid-asm-variant.s b/test/MC/AsmParser/invalid-asm-variant.s
new file mode 100644 (file)
index 0000000..a96bc9a
--- /dev/null
@@ -0,0 +1,3 @@
+//RUN: not llvm-mc --disassemble -triple=x86_64 --output-asm-variant=2 %s -o - 2>&1 | FileCheck %s
+
+//CHECK: error: unable to create instruction printer for target triple 'x86_64' with assembly variant 2.
index 58eb33a..452777b 100644 (file)
@@ -563,6 +563,14 @@ int main(int argc, char **argv) {
     IP = TheTarget->createMCInstPrinter(Triple(TripleName), OutputAsmVariant,
                                         *MAI, *MCII, *MRI);
 
+    if (!IP) {
+      errs()
+          << "error: unable to create instruction printer for target triple '"
+          << TheTriple.normalize() << "' with assembly variant "
+          << OutputAsmVariant << ".\n";
+      return 1;
+    }
+
     // Set the display preference for hex vs. decimal immediates.
     IP->setPrintImmHex(PrintImmHex);