Skip to content

Commit

Permalink
Auto merge of #39747 - mattico:fix-llvm4-createcompileunit, r=alexcri…
Browse files Browse the repository at this point in the history
…chton

[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()`.
  • Loading branch information
bors committed Feb 11, 2017
2 parents bae454e + aebce5b commit ba7cf7c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
3 changes: 1 addition & 2 deletions src/librustc_llvm/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1334,8 +1334,7 @@ extern "C" {

pub fn LLVMRustDIBuilderCreateCompileUnit(Builder: DIBuilderRef,
Lang: c_uint,
File: *const c_char,
Dir: *const c_char,
File: DIFile,
Producer: *const c_char,
isOptimized: bool,
Flags: *const c_char,
Expand Down
11 changes: 7 additions & 4 deletions src/librustc_trans/debuginfo/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -791,12 +791,15 @@ pub fn compile_unit_metadata(scc: &SharedCrateContext,
let producer = CString::new(producer).unwrap();
let flags = "\0";
let split_name = "\0";
return unsafe {
llvm::LLVMRustDIBuilderCreateCompileUnit(

unsafe {
let file_metadata = llvm::LLVMRustDIBuilderCreateFile(
debug_context.builder, compile_unit_name, work_dir.as_ptr());

return llvm::LLVMRustDIBuilderCreateCompileUnit(
debug_context.builder,
DW_LANG_RUST,
compile_unit_name,
work_dir.as_ptr(),
file_metadata,
producer.as_ptr(),
sess.opts.optimize != config::OptLevel::No,
flags.as_ptr() as *const _,
Expand Down
14 changes: 11 additions & 3 deletions src/rustllvm/RustWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -474,11 +474,19 @@ extern "C" void LLVMRustDIBuilderFinalize(LLVMRustDIBuilderRef Builder) {
}

extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateCompileUnit(
LLVMRustDIBuilderRef Builder, unsigned Lang, const char *File,
const char *Dir, const char *Producer, bool isOptimized, const char *Flags,
LLVMRustDIBuilderRef Builder, unsigned Lang, LLVMRustMetadataRef FileRef,
const char *Producer, bool isOptimized, const char *Flags,
unsigned RuntimeVer, const char *SplitName) {
return wrap(Builder->createCompileUnit(Lang, File, Dir, Producer, isOptimized,
auto *File = unwrapDI<DIFile>(FileRef);

#if LLVM_VERSION_GE(4, 0)
return wrap(Builder->createCompileUnit(Lang, File, Producer, isOptimized,
Flags, RuntimeVer, SplitName));
#else
return wrap(Builder->createCompileUnit(Lang, File->getFilename(),
File->getDirectory(), Producer, isOptimized,
Flags, RuntimeVer, SplitName));
#endif
}

extern "C" LLVMRustMetadataRef
Expand Down

0 comments on commit ba7cf7c

Please sign in to comment.