[llvm] r304815 - MIRPrinter: Avoid assert() when printing empty INLINEASM strings.

Matthias Braun via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 6 12:00:58 PDT 2017


Author: matze
Date: Tue Jun  6 14:00:58 2017
New Revision: 304815

URL: http://llvm.org/viewvc/llvm-project?rev=304815&view=rev
Log:
MIRPrinter: Avoid assert() when printing empty INLINEASM strings.

CodeGen uses MO_ExternalSymbol to represent the inline assembly strings.
Empty strings for symbol names appear to be invalid. For now just
special case the output code to avoid hitting an `assert()` in
`printLLVMNameWithoutPrefix()`.

This fixes https://llvm.org/PR33317

Added:
    llvm/trunk/test/CodeGen/MIR/X86/inline-asm.mir
Modified:
    llvm/trunk/lib/CodeGen/MIRPrinter.cpp

Modified: llvm/trunk/lib/CodeGen/MIRPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MIRPrinter.cpp?rev=304815&r1=304814&r2=304815&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MIRPrinter.cpp (original)
+++ llvm/trunk/lib/CodeGen/MIRPrinter.cpp Tue Jun  6 14:00:58 2017
@@ -16,6 +16,7 @@
 
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallBitVector.h"
+#include "llvm/ADT/StringExtras.h"
 #include "llvm/CodeGen/GlobalISel/RegisterBank.h"
 #include "llvm/CodeGen/MIRYamlMapping.h"
 #include "llvm/CodeGen/MachineConstantPool.h"
@@ -924,11 +925,17 @@ void MIPrinter::print(const MachineOpera
   case MachineOperand::MO_JumpTableIndex:
     OS << "%jump-table." << Op.getIndex();
     break;
-  case MachineOperand::MO_ExternalSymbol:
+  case MachineOperand::MO_ExternalSymbol: {
+    StringRef Name = Op.getSymbolName();
     OS << '$';
-    printLLVMNameWithoutPrefix(OS, Op.getSymbolName());
+    if (Name.empty()) {
+      OS << "\"\"";
+    } else {
+      printLLVMNameWithoutPrefix(OS, Name);
+    }
     printOffset(Op.getOffset());
     break;
+  }
   case MachineOperand::MO_GlobalAddress:
     Op.getGlobal()->printAsOperand(OS, /*PrintType=*/false, MST);
     printOffset(Op.getOffset());

Added: llvm/trunk/test/CodeGen/MIR/X86/inline-asm.mir
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/MIR/X86/inline-asm.mir?rev=304815&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/MIR/X86/inline-asm.mir (added)
+++ llvm/trunk/test/CodeGen/MIR/X86/inline-asm.mir Tue Jun  6 14:00:58 2017
@@ -0,0 +1,12 @@
+# RUN: llc -o - %s -mtriple=x86_64-- -run-pass none | FileCheck %s
+---
+# Avoid crash/assert when using an emptystring in an INLINEASM.
+# CHECK-LABEL: name: emptystring
+# CHECK: bb.0:
+# CHECK:   INLINEASM $"", 1
+# CHECK:   RET 0
+name: emptystring
+body: |
+  bb.0:
+    INLINEASM $"", 1
+    RET 0




More information about the llvm-commits mailing list