From 85d3f1ee8f109c0f180050020ef9d7c233f782e5 Mon Sep 17 00:00:00 2001 From: Francis Visoiu Mistrih Date: Tue, 30 Oct 2018 12:07:18 +0000 Subject: [PATCH] [llc] Error out when -print-machineinstrs is used with an unknown pass We used to assert instead of reporting an error. PR39494 llvm-svn: 345589 --- llvm/lib/CodeGen/TargetPassConfig.cpp | 20 ++++++++++--------- .../CodeGen/X86/llc-print-machineinstrs.mir | 12 +++++++++++ 2 files changed, 23 insertions(+), 9 deletions(-) create mode 100644 llvm/test/CodeGen/X86/llc-print-machineinstrs.mir diff --git a/llvm/lib/CodeGen/TargetPassConfig.cpp b/llvm/lib/CodeGen/TargetPassConfig.cpp index a3b24d1cd664..6a9c3c05f037 100644 --- a/llvm/lib/CodeGen/TargetPassConfig.cpp +++ b/llvm/lib/CodeGen/TargetPassConfig.cpp @@ -806,15 +806,17 @@ void TargetPassConfig::addMachinePasses() { AddingMachinePasses = true; // Insert a machine instr printer pass after the specified pass. - if (!StringRef(PrintMachineInstrs.getValue()).equals("") && - !StringRef(PrintMachineInstrs.getValue()).equals("option-unspecified")) { - const PassRegistry *PR = PassRegistry::getPassRegistry(); - const PassInfo *TPI = PR->getPassInfo(PrintMachineInstrs.getValue()); - const PassInfo *IPI = PR->getPassInfo(StringRef("machineinstr-printer")); - assert (TPI && IPI && "Pass ID not registered!"); - const char *TID = (const char *)(TPI->getTypeInfo()); - const char *IID = (const char *)(IPI->getTypeInfo()); - insertPass(TID, IID); + StringRef PrintMachineInstrsPassName = PrintMachineInstrs.getValue(); + if (!PrintMachineInstrsPassName.equals("") && + !PrintMachineInstrsPassName.equals("option-unspecified")) { + if (const PassInfo *TPI = getPassInfo(PrintMachineInstrsPassName)) { + const PassRegistry *PR = PassRegistry::getPassRegistry(); + const PassInfo *IPI = PR->getPassInfo(StringRef("machineinstr-printer")); + assert(IPI && "failed to get \"machineinstr-printer\" PassInfo!"); + const char *TID = (const char *)(TPI->getTypeInfo()); + const char *IID = (const char *)(IPI->getTypeInfo()); + insertPass(TID, IID); + } } // Print the instruction selected machine code... diff --git a/llvm/test/CodeGen/X86/llc-print-machineinstrs.mir b/llvm/test/CodeGen/X86/llc-print-machineinstrs.mir new file mode 100644 index 000000000000..a890840a478a --- /dev/null +++ b/llvm/test/CodeGen/X86/llc-print-machineinstrs.mir @@ -0,0 +1,12 @@ +# Check that -print-machineinstrs doesn't assert when it's passed an unknown pass name. +# RUN: llc -mtriple=x86_64-- -start-before=greedy -print-machineinstrs=greedy %s -o /dev/null +# RUN: not llc -mtriple=x86_64-- -start-before=greedy -print-machineinstrs=unknown %s -o /dev/null 2>&1 | FileCheck %s +# CHECK: LLVM ERROR: "unknown" pass is not registered. + +... +--- +name: fun +tracksRegLiveness: true +body: | + bb.0: + RET 0