summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Braun <matze@braunis.de>2017-06-06 19:00:58 +0000
committerMatthias Braun <matze@braunis.de>2017-06-06 19:00:58 +0000
commitae5480dda71f4d4c386a9746d26eb143c342b7a4 (patch)
tree20b0def15f59b28e6f9941afc83cb24f44eeae00
parent5c0660f0168c63a5482438367b08fca1ee655c44 (diff)
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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@304815 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/CodeGen/MIRPrinter.cpp11
-rw-r--r--test/CodeGen/MIR/X86/inline-asm.mir12
2 files changed, 21 insertions, 2 deletions
diff --git a/lib/CodeGen/MIRPrinter.cpp b/lib/CodeGen/MIRPrinter.cpp
index 849866a1040..789ab092998 100644
--- a/lib/CodeGen/MIRPrinter.cpp
+++ b/lib/CodeGen/MIRPrinter.cpp
@@ -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 MachineOperand &Op, const TargetRegisterInfo *TRI,
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());
diff --git a/test/CodeGen/MIR/X86/inline-asm.mir b/test/CodeGen/MIR/X86/inline-asm.mir
new file mode 100644
index 00000000000..be96517144b
--- /dev/null
+++ b/test/CodeGen/MIR/X86/inline-asm.mir
@@ -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