Skip to content
59 changes: 26 additions & 33 deletions compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::borrow::Cow;
use std::fmt::{self, Write};
use std::hash::{Hash, Hasher};
use std::path::{Path, PathBuf};
use std::sync::Arc;
use std::{iter, ptr};

use libc::{c_char, c_longlong, c_uint};
Expand Down Expand Up @@ -38,7 +39,7 @@ use crate::debuginfo::metadata::type_map::build_type_with_children;
use crate::debuginfo::utils::{WidePtrKind, wide_pointer_kind};
use crate::llvm;
use crate::llvm::debuginfo::{
DICompositeType, DIDescriptor, DIFile, DIFlags, DILexicalBlock, DIScope, DIType,
DIBuilder, DICompositeType, DIDescriptor, DIFile, DIFlags, DILexicalBlock, DIScope, DIType,
DebugEmissionKind, DebugNameTableKind,
};
use crate::value::Value;
Expand Down Expand Up @@ -623,42 +624,38 @@ pub(crate) fn file_metadata<'ll>(cx: &CodegenCx<'ll, '_>, source_file: &SourceFi
let source =
cx.sess().opts.unstable_opts.embed_source.then_some(()).and(source_file.src.as_ref());

unsafe {
llvm::LLVMRustDIBuilderCreateFile(
DIB(cx),
file_name.as_c_char_ptr(),
file_name.len(),
directory.as_c_char_ptr(),
directory.len(),
hash_kind,
hash_value.as_c_char_ptr(),
hash_value.len(),
source.map_or(ptr::null(), |x| x.as_c_char_ptr()),
source.map_or(0, |x| x.len()),
)
}
create_file(DIB(cx), &file_name, &directory, &hash_value, hash_kind, source)
}
}

fn unknown_file_metadata<'ll>(cx: &CodegenCx<'ll, '_>) -> &'ll DIFile {
debug_context(cx).created_files.borrow_mut().entry(None).or_insert_with(|| unsafe {
let file_name = "<unknown>";
let directory = "";
let hash_value = "";
debug_context(cx).created_files.borrow_mut().entry(None).or_insert_with(|| {
create_file(DIB(cx), "<unknown>", "", "", llvm::ChecksumKind::None, None)
})
}

fn create_file<'ll>(
builder: &DIBuilder<'ll>,
file_name: &str,
directory: &str,
hash_value: &str,
hash_kind: llvm::ChecksumKind,
source: Option<&Arc<String>>,
) -> &'ll DIFile {
unsafe {
llvm::LLVMRustDIBuilderCreateFile(
DIB(cx),
builder,
file_name.as_c_char_ptr(),
file_name.len(),
directory.as_c_char_ptr(),
directory.len(),
llvm::ChecksumKind::None,
hash_kind,
hash_value.as_c_char_ptr(),
hash_value.len(),
ptr::null(),
0,
source.map_or(ptr::null(), |x| x.as_c_char_ptr()),
source.map_or(0, |x| x.len()),
)
})
}
}

trait MsvcBasicName {
Expand Down Expand Up @@ -932,17 +929,13 @@ pub(crate) fn build_compile_unit_di_node<'ll, 'tcx>(
};

unsafe {
let compile_unit_file = llvm::LLVMRustDIBuilderCreateFile(
let compile_unit_file = create_file(
debug_context.builder.as_ref(),
name_in_debuginfo.as_c_char_ptr(),
name_in_debuginfo.len(),
work_dir.as_c_char_ptr(),
work_dir.len(),
&name_in_debuginfo,
&work_dir,
"",
llvm::ChecksumKind::None,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this. Empty string now, null pointer before

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But that wouldn't explain the query count changes

ptr::null(),
0,
ptr::null(),
0,
None,
);

let unit_metadata = llvm::LLVMRustDIBuilderCreateCompileUnit(
Expand Down