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

llvm-svn: 304815
This commit is contained in:
Matthias Braun 2017-06-06 19:00:58 +00:00
parent 49220fb6a1
commit 8b5f9e4438
2 changed files with 21 additions and 2 deletions

View File

@ -16,6 +16,7 @@
#include "llvm/ADT/STLExtras.h" #include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallBitVector.h" #include "llvm/ADT/SmallBitVector.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/CodeGen/GlobalISel/RegisterBank.h" #include "llvm/CodeGen/GlobalISel/RegisterBank.h"
#include "llvm/CodeGen/MIRYamlMapping.h" #include "llvm/CodeGen/MIRYamlMapping.h"
#include "llvm/CodeGen/MachineConstantPool.h" #include "llvm/CodeGen/MachineConstantPool.h"
@ -924,11 +925,17 @@ void MIPrinter::print(const MachineOperand &Op, const TargetRegisterInfo *TRI,
case MachineOperand::MO_JumpTableIndex: case MachineOperand::MO_JumpTableIndex:
OS << "%jump-table." << Op.getIndex(); OS << "%jump-table." << Op.getIndex();
break; break;
case MachineOperand::MO_ExternalSymbol: case MachineOperand::MO_ExternalSymbol: {
StringRef Name = Op.getSymbolName();
OS << '$'; OS << '$';
printLLVMNameWithoutPrefix(OS, Op.getSymbolName()); if (Name.empty()) {
OS << "\"\"";
} else {
printLLVMNameWithoutPrefix(OS, Name);
}
printOffset(Op.getOffset()); printOffset(Op.getOffset());
break; break;
}
case MachineOperand::MO_GlobalAddress: case MachineOperand::MO_GlobalAddress:
Op.getGlobal()->printAsOperand(OS, /*PrintType=*/false, MST); Op.getGlobal()->printAsOperand(OS, /*PrintType=*/false, MST);
printOffset(Op.getOffset()); printOffset(Op.getOffset());

View File

@ -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