Skip to content

Commit 13065dd

Browse files
committed
Revert "Create a safe wrapper function around LLVMRustDIBuilderCreateFile"
This reverts commit cc41dd4.
1 parent 9298516 commit 13065dd

File tree

1 file changed

+33
-26
lines changed

1 file changed

+33
-26
lines changed

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

+33-26
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use std::borrow::Cow;
22
use std::fmt::{self, Write};
33
use std::hash::{Hash, Hasher};
44
use std::path::{Path, PathBuf};
5-
use std::sync::Arc;
65
use std::{iter, ptr};
76

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

627-
create_file(DIB(cx), &file_name, &directory, &hash_value, hash_kind, source)
626+
unsafe {
627+
llvm::LLVMRustDIBuilderCreateFile(
628+
DIB(cx),
629+
file_name.as_c_char_ptr(),
630+
file_name.len(),
631+
directory.as_c_char_ptr(),
632+
directory.len(),
633+
hash_kind,
634+
hash_value.as_c_char_ptr(),
635+
hash_value.len(),
636+
source.map_or(ptr::null(), |x| x.as_c_char_ptr()),
637+
source.map_or(0, |x| x.len()),
638+
)
639+
}
628640
}
629641
}
630642

631643
fn unknown_file_metadata<'ll>(cx: &CodegenCx<'ll, '_>) -> &'ll DIFile {
632-
debug_context(cx).created_files.borrow_mut().entry(None).or_insert_with(|| {
633-
create_file(DIB(cx), "<unknown>", "", "", llvm::ChecksumKind::None, None)
634-
})
635-
}
644+
debug_context(cx).created_files.borrow_mut().entry(None).or_insert_with(|| unsafe {
645+
let file_name = "<unknown>";
646+
let directory = "";
647+
let hash_value = "";
636648

637-
fn create_file<'ll>(
638-
builder: &DIBuilder<'ll>,
639-
file_name: &str,
640-
directory: &str,
641-
hash_value: &str,
642-
hash_kind: llvm::ChecksumKind,
643-
source: Option<&Arc<String>>,
644-
) -> &'ll DIFile {
645-
unsafe {
646649
llvm::LLVMRustDIBuilderCreateFile(
647-
builder,
650+
DIB(cx),
648651
file_name.as_c_char_ptr(),
649652
file_name.len(),
650653
directory.as_c_char_ptr(),
651654
directory.len(),
652-
hash_kind,
655+
llvm::ChecksumKind::None,
653656
hash_value.as_c_char_ptr(),
654657
hash_value.len(),
655-
source.map_or(ptr::null(), |x| x.as_c_char_ptr()),
656-
source.map_or(0, |x| x.len()),
658+
ptr::null(),
659+
0,
657660
)
658-
}
661+
})
659662
}
660663

661664
trait MsvcBasicName {
@@ -930,13 +933,17 @@ pub(crate) fn build_compile_unit_di_node<'ll, 'tcx>(
930933
};
931934

932935
unsafe {
933-
let compile_unit_file = create_file(
936+
let compile_unit_file = llvm::LLVMRustDIBuilderCreateFile(
934937
debug_context.builder.as_ref(),
935-
&name_in_debuginfo,
936-
&work_dir,
937-
"",
938+
name_in_debuginfo.as_c_char_ptr(),
939+
name_in_debuginfo.len(),
940+
work_dir.as_c_char_ptr(),
941+
work_dir.len(),
938942
llvm::ChecksumKind::None,
939-
None,
943+
ptr::null(),
944+
0,
945+
ptr::null(),
946+
0,
940947
);
941948

942949
let unit_metadata = llvm::LLVMRustDIBuilderCreateCompileUnit(

0 commit comments

Comments
 (0)