Index: lib/Target/AMDGPU/AMDGPUMCInstLower.h =================================================================== --- lib/Target/AMDGPU/AMDGPUMCInstLower.h +++ lib/Target/AMDGPU/AMDGPUMCInstLower.h @@ -12,6 +12,7 @@ namespace llvm { +class AMDGPUAsmPrinter; class AMDGPUSubtarget; class MachineInstr; class MCContext; @@ -20,9 +21,11 @@ class AMDGPUMCInstLower { MCContext &Ctx; const AMDGPUSubtarget &ST; + const AMDGPUAsmPrinter &AsmPrinter; public: - AMDGPUMCInstLower(MCContext &ctx, const AMDGPUSubtarget &ST); + AMDGPUMCInstLower(MCContext &ctx, const AMDGPUSubtarget &ST, + const AMDGPUAsmPrinter &AsmPrinter); /// \brief Lower a MachineInstr to an MCInst void lower(const MachineInstr *MI, MCInst &OutMI) const; Index: lib/Target/AMDGPU/AMDGPUMCInstLower.cpp =================================================================== --- lib/Target/AMDGPU/AMDGPUMCInstLower.cpp +++ lib/Target/AMDGPU/AMDGPUMCInstLower.cpp @@ -36,8 +36,9 @@ using namespace llvm; -AMDGPUMCInstLower::AMDGPUMCInstLower(MCContext &ctx, const AMDGPUSubtarget &st): - Ctx(ctx), ST(st) { } +AMDGPUMCInstLower::AMDGPUMCInstLower(MCContext &ctx, const AMDGPUSubtarget &st, + const AMDGPUAsmPrinter &AsmPrinter): + Ctx(ctx), ST(st), AsmPrinter(AsmPrinter) { } static MCSymbolRefExpr::VariantKind getVariantKind(unsigned MOFlags) { switch (MOFlags) { @@ -75,7 +76,9 @@ break; case MachineOperand::MO_GlobalAddress: { const GlobalValue *GV = MO.getGlobal(); - MCSymbol *Sym = Ctx.getOrCreateSymbol(StringRef(GV->getName())); + SmallString<128> SymbolName; + AsmPrinter.getNameWithPrefix(SymbolName, GV); + MCSymbol *Sym = Ctx.getOrCreateSymbol(SymbolName); const MCExpr *SymExpr = MCSymbolRefExpr::create(Sym, getVariantKind(MO.getTargetFlags()),Ctx); const MCExpr *Expr = MCBinaryExpr::createAdd(SymExpr, @@ -97,7 +100,7 @@ void AMDGPUAsmPrinter::EmitInstruction(const MachineInstr *MI) { const AMDGPUSubtarget &STI = MF->getSubtarget(); - AMDGPUMCInstLower MCInstLowering(OutContext, STI); + AMDGPUMCInstLower MCInstLowering(OutContext, STI, *this); StringRef Err; if (!STI.getInstrInfo()->verifyInstruction(*MI, Err)) { Index: test/CodeGen/AMDGPU/gv-name.ll =================================================================== --- /dev/null +++ test/CodeGen/AMDGPU/gv-name.ll @@ -0,0 +1,10 @@ +; RUN: llc < %s -mtriple=amdgcn--amdhsa -mcpu=fiji | FileCheck %s + +; Make sure we don't crash on a global variable with no name. +@0 = external addrspace(1) global i32 + +; CHECK-LABEL: {{^}}test: +define void @test() { + store i32 1, i32 addrspace(1)* @0 + ret void +}