Index: lib/CodeGen/AsmPrinter/AsmPrinter.cpp =================================================================== --- lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -695,7 +695,7 @@ OutStreamer->EmitLabel(DeadBlockSyms[i]); } - if (CurrentFnBegin) { + if (CurrentFnBegin && !MF->getTarget().getTargetTriple().isNVPTX()) { if (MAI->useAssignmentForEHBegin()) { MCSymbol *CurPos = OutContext.createTempSymbol(); OutStreamer->EmitLabel(CurPos); @@ -713,6 +713,13 @@ HI.Handler->beginFunction(MF); } + // For NVPTX target initial function labels must follow the debug location for + // the correct relocation info generation. + if (CurrentFnBegin && MF->getTarget().getTargetTriple().isNVPTX()) { + assert(!MAI->useAssignmentForEHBegin() && "EH is not supported for NVPTX."); + OutStreamer->EmitLabel(CurrentFnBegin); + } + // Emit the prologue data. if (F.hasPrologueData()) EmitGlobalConstant(F.getParent()->getDataLayout(), F.getPrologueData()); Index: test/DebugInfo/NVPTX/cu-range-hole.ll =================================================================== --- test/DebugInfo/NVPTX/cu-range-hole.ll +++ test/DebugInfo/NVPTX/cu-range-hole.ll @@ -6,8 +6,8 @@ ; CHECK: .param .b32 b_param_0 ; CHECK: ) ; CHECK: { -; CHECK: Lfunc_begin0: ; CHECK: .loc 1 1 0 +; CHECK: Lfunc_begin0: ; CHECK: .loc 1 1 0 ; CHECK: ret; ; CHECK: Lfunc_end0: @@ -27,6 +27,7 @@ ; CHECK: .param .b32 d_param_0 ; CHECK: ) ; CHECK: { +; CHECK: .loc 1 3 0 ; CHECK: Lfunc_begin2: ; CHECK: .loc 1 3 0 ; CHECK: ret;