Skip to content

Commit 68fff62

Browse files
committed
[LLVM 4.0] Fix CreateCompileUnit
1 parent 064a0ee commit 68fff62

File tree

3 files changed

+22
-12
lines changed

3 files changed

+22
-12
lines changed

src/librustc_llvm/ffi.rs

Lines changed: 1 addition & 2 deletions
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

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -787,17 +787,20 @@ pub fn compile_unit_metadata(scc: &SharedCrateContext,
787787
(option_env!("CFG_VERSION")).expect("CFG_VERSION"));
788788

789789
let compile_unit_name = compile_unit_name.as_ptr();
790-
let work_dir = path2cstr(&work_dir);
791-
let producer = CString::new(producer).unwrap();
790+
let work_dir = path2cstr(&work_dir).as_ptr();
791+
let producer = CString::new(producer).unwrap().as_ptr();
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);
798+
799+
return llvm::LLVMRustDIBuilderCreateCompileUnit(
796800
debug_context.builder,
797801
DW_LANG_RUST,
798-
compile_unit_name,
799-
work_dir.as_ptr(),
800-
producer.as_ptr(),
802+
file_metadata,
803+
producer,
801804
sess.opts.optimize != config::OptLevel::No,
802805
flags.as_ptr() as *const _,
803806
0,

src/rustllvm/RustWrapper.cpp

Lines changed: 11 additions & 3 deletions
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)