Skip to content

Commit ba7cf7c

Browse files
committed
Auto merge of #39747 - mattico:fix-llvm4-createcompileunit, r=alexcrichton
[LLVM 4.0] Fix CreateCompileUnit This is largely identical to @dylanmckay's [patch](https://github.com/dylanmckay), except that it doesn't try to use `file_metadata()`. I don't think that is necessary because we don't want the compile unit to be added to `debug_context.created_files`, though I'd like confirmation from someone who knows for sure. If that is needed, I can modify `file_metadata_()` so that it can be used from `compile_unit_metadata()`.
2 parents bae454e + aebce5b commit ba7cf7c

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

src/librustc_llvm/ffi.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1334,8 +1334,7 @@ extern "C" {
13341334

13351335
pub fn LLVMRustDIBuilderCreateCompileUnit(Builder: DIBuilderRef,
13361336
Lang: c_uint,
1337-
File: *const c_char,
1338-
Dir: *const c_char,
1337+
File: DIFile,
13391338
Producer: *const c_char,
13401339
isOptimized: bool,
13411340
Flags: *const c_char,

src/librustc_trans/debuginfo/metadata.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -791,12 +791,15 @@ pub fn compile_unit_metadata(scc: &SharedCrateContext,
791791
let producer = CString::new(producer).unwrap();
792792
let flags = "\0";
793793
let split_name = "\0";
794-
return unsafe {
795-
llvm::LLVMRustDIBuilderCreateCompileUnit(
794+
795+
unsafe {
796+
let file_metadata = llvm::LLVMRustDIBuilderCreateFile(
797+
debug_context.builder, compile_unit_name, work_dir.as_ptr());
798+
799+
return llvm::LLVMRustDIBuilderCreateCompileUnit(
796800
debug_context.builder,
797801
DW_LANG_RUST,
798-
compile_unit_name,
799-
work_dir.as_ptr(),
802+
file_metadata,
800803
producer.as_ptr(),
801804
sess.opts.optimize != config::OptLevel::No,
802805
flags.as_ptr() as *const _,

src/rustllvm/RustWrapper.cpp

+11-3
Original file line numberDiff line numberDiff line change
@@ -474,11 +474,19 @@ extern "C" void LLVMRustDIBuilderFinalize(LLVMRustDIBuilderRef Builder) {
474474
}
475475

476476
extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateCompileUnit(
477-
LLVMRustDIBuilderRef Builder, unsigned Lang, const char *File,
478-
const char *Dir, const char *Producer, bool isOptimized, const char *Flags,
477+
LLVMRustDIBuilderRef Builder, unsigned Lang, LLVMRustMetadataRef FileRef,
478+
const char *Producer, bool isOptimized, const char *Flags,
479479
unsigned RuntimeVer, const char *SplitName) {
480-
return wrap(Builder->createCompileUnit(Lang, File, Dir, Producer, isOptimized,
480+
auto *File = unwrapDI<DIFile>(FileRef);
481+
482+
#if LLVM_VERSION_GE(4, 0)
483+
return wrap(Builder->createCompileUnit(Lang, File, Producer, isOptimized,
481484
Flags, RuntimeVer, SplitName));
485+
#else
486+
return wrap(Builder->createCompileUnit(Lang, File->getFilename(),
487+
File->getDirectory(), Producer, isOptimized,
488+
Flags, RuntimeVer, SplitName));
489+
#endif
482490
}
483491

484492
extern "C" LLVMRustMetadataRef

0 commit comments

Comments
 (0)