Skip to content

Commit a7b8f0c

Browse files
authored
Work around debug_compile_units skipping nodebug CUs (#59649)
1 parent 04591f9 commit a7b8f0c

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

src/aotcompile.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1957,8 +1957,9 @@ static SmallVector<AOTOutputs, 16> add_output(Module &M, TargetMachine &TM, Stri
19571957
// The DICompileUnit file is not used for anything, but ld64 requires it be a unique string per object file
19581958
// or it may skip emitting debug info for that file. Here set it to ./julia#N
19591959
DIFile *topfile = DIFile::get(M->getContext(), "julia#" + std::to_string(i), ".");
1960-
for (DICompileUnit *CU : M->debug_compile_units())
1961-
CU->replaceOperandWith(0, topfile);
1960+
if (M->getNamedMetadata("llvm.dbg.cu"))
1961+
for (auto CU: M->getNamedMetadata("llvm.dbg.cu")->operands())
1962+
CU->replaceOperandWith(0, topfile);
19621963
timers[i].construct.stopTimer();
19631964

19641965
outputs[i] = add_output_impl(*M, TM, timers[i], unopt_out, opt_out, obj_out, asm_out);

src/llvm-multiversioning.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -487,8 +487,9 @@ void CloneCtx::prepare_vmap(ValueToValueMapTy &vmap)
487487
// The `DISubprogram` cloning on LLVM 5.0 handles this
488488
// but it doesn't hurt to enforce the identity either.
489489
auto &MD = vmap.MD();
490-
for (auto cu: M.debug_compile_units()) {
491-
MD[cu].reset(cu);
490+
if (M.getNamedMetadata("llvm.dbg.cu"))
491+
for (auto cu: M.getNamedMetadata("llvm.dbg.cu")->operands()) {
492+
MD[cu].reset(cu);
492493
}
493494
}
494495

src/llvm-remove-addrspaces.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -336,9 +336,10 @@ bool removeAddrspaces(Module &M, AddrspaceRemapFunction ASRemapper)
336336
}
337337
// Same workaround as in CloneCtx::prepare_vmap to avoid LLVM bug when cloning
338338
auto &MD = VMap.MD();
339-
for (auto cu: M.debug_compile_units()) {
340-
MD[cu].reset(cu);
341-
}
339+
if (M.getNamedMetadata("llvm.dbg.cu"))
340+
for (auto cu: M.getNamedMetadata("llvm.dbg.cu")->operands()) {
341+
MD[cu].reset(cu);
342+
}
342343
// Similarly, copy over and rewrite function bodies
343344
for (Function *F : Functions) {
344345
Function *NF = cast<Function>(VMap[F]);

0 commit comments

Comments
 (0)