Importing rustc-1.52.1
Change-Id: I3598a97301b4b2e71385e5a519f6d2ad946548b6
diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/create_scope_map.rs b/compiler/rustc_codegen_llvm/src/debuginfo/create_scope_map.rs
index 7673dfb..c2725b8 100644
--- a/compiler/rustc_codegen_llvm/src/debuginfo/create_scope_map.rs
+++ b/compiler/rustc_codegen_llvm/src/debuginfo/create_scope_map.rs
@@ -1,4 +1,4 @@
-use super::metadata::{file_metadata, UNKNOWN_COLUMN_NUMBER, UNKNOWN_LINE_NUMBER};
+use super::metadata::file_metadata;
use super::utils::DIB;
use rustc_codegen_ssa::mir::debuginfo::{DebugScope, FunctionDebugContext};
use rustc_codegen_ssa::traits::*;
@@ -102,8 +102,8 @@
DIB(cx),
parent_scope.dbg_scope.unwrap(),
file_metadata,
- loc.line.unwrap_or(UNKNOWN_LINE_NUMBER),
- loc.col.unwrap_or(UNKNOWN_COLUMN_NUMBER),
+ loc.line,
+ loc.col,
)
},
};
diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs
index 6e7c0b3..d5b32e5 100644
--- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs
+++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs
@@ -18,8 +18,8 @@
};
use crate::value::Value;
+use cstr::cstr;
use rustc_codegen_ssa::traits::*;
-use rustc_data_structures::const_cstr;
use rustc_data_structures::fingerprint::Fingerprint;
use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
@@ -979,7 +979,7 @@
// The OSX linker has an idiosyncrasy where it will ignore some debuginfo
// if multiple object files with the same `DW_AT_name` are linked together.
// As a workaround we generate unique names for each object file. Those do
- // not correspond to an actual source file but that should be harmless.
+ // not correspond to an actual source file but that is harmless.
if tcx.sess.target.is_like_osx {
name_in_debuginfo.push("@");
name_in_debuginfo.push(codegen_unit_name);
@@ -992,17 +992,17 @@
let producer = format!("clang LLVM ({})", rustc_producer);
let name_in_debuginfo = name_in_debuginfo.to_string_lossy();
+ let work_dir = tcx.sess.working_dir.0.to_string_lossy();
let flags = "\0";
-
let out_dir = &tcx.output_filenames(LOCAL_CRATE).out_directory;
let split_name = if tcx.sess.target_can_use_split_dwarf() {
tcx.output_filenames(LOCAL_CRATE)
- .split_dwarf_filename(tcx.sess.split_debuginfo(), Some(codegen_unit_name))
+ .split_dwarf_path(tcx.sess.split_debuginfo(), Some(codegen_unit_name))
+ .map(|f| out_dir.join(f))
} else {
None
}
.unwrap_or_default();
- let out_dir = out_dir.to_str().unwrap();
let split_name = split_name.to_str().unwrap();
// FIXME(#60020):
@@ -1024,12 +1024,12 @@
assert!(tcx.sess.opts.debuginfo != DebugInfo::None);
unsafe {
- let file_metadata = llvm::LLVMRustDIBuilderCreateFile(
+ let compile_unit_file = llvm::LLVMRustDIBuilderCreateFile(
debug_context.builder,
name_in_debuginfo.as_ptr().cast(),
name_in_debuginfo.len(),
- out_dir.as_ptr().cast(),
- out_dir.len(),
+ work_dir.as_ptr().cast(),
+ work_dir.len(),
llvm::ChecksumKind::None,
ptr::null(),
0,
@@ -1038,12 +1038,15 @@
let unit_metadata = llvm::LLVMRustDIBuilderCreateCompileUnit(
debug_context.builder,
DW_LANG_RUST,
- file_metadata,
+ compile_unit_file,
producer.as_ptr().cast(),
producer.len(),
tcx.sess.opts.optimize != config::OptLevel::No,
flags.as_ptr().cast(),
0,
+ // NB: this doesn't actually have any perceptible effect, it seems. LLVM will instead
+ // put the path supplied to `MCSplitDwarfFile` into the debug info of the final
+ // output(s).
split_name.as_ptr().cast(),
split_name.len(),
kind,
@@ -1072,7 +1075,7 @@
gcov_cu_info.len() as c_uint,
);
- let llvm_gcov_ident = const_cstr!("llvm.gcov");
+ let llvm_gcov_ident = cstr!("llvm.gcov");
llvm::LLVMAddNamedMetadataOperand(
debug_context.llmod,
llvm_gcov_ident.as_ptr(),
@@ -1090,7 +1093,7 @@
);
llvm::LLVMAddNamedMetadataOperand(
debug_context.llmod,
- const_cstr!("llvm.ident").as_ptr(),
+ cstr!("llvm.ident").as_ptr(),
llvm::LLVMMDNodeInContext(debug_context.llcontext, &name_metadata, 1),
);
}
@@ -1414,7 +1417,7 @@
def_id: DefId,
) -> (&'tcx GeneratorLayout<'tcx>, IndexVec<mir::GeneratorSavedLocal, Option<Symbol>>) {
let body = tcx.optimized_mir(def_id);
- let generator_layout = body.generator_layout.as_ref().unwrap();
+ let generator_layout = body.generator_layout().unwrap();
let mut generator_saved_local_names = IndexVec::from_elem(None, &generator_layout.field_tys);
let state_arg = mir::Local::new(1);
@@ -1839,10 +1842,7 @@
.span;
if !span.is_dummy() {
let loc = cx.lookup_debug_loc(span.lo());
- return Some(SourceInfo {
- file: file_metadata(cx, &loc.file),
- line: loc.line.unwrap_or(UNKNOWN_LINE_NUMBER),
- });
+ return Some(SourceInfo { file: file_metadata(cx, &loc.file), line: loc.line });
}
}
_ => {}
@@ -2369,7 +2369,7 @@
fn get_parameter_names(cx: &CodegenCx<'_, '_>, generics: &ty::Generics) -> Vec<Symbol> {
let mut names = generics
.parent
- .map_or(vec![], |def_id| get_parameter_names(cx, cx.tcx.generics_of(def_id)));
+ .map_or_else(Vec::new, |def_id| get_parameter_names(cx, cx.tcx.generics_of(def_id)));
names.extend(generics.params.iter().map(|param| param.name));
names
}
@@ -2481,7 +2481,7 @@
let loc = cx.lookup_debug_loc(span.lo());
(file_metadata(cx, &loc.file), loc.line)
} else {
- (unknown_file_metadata(cx), None)
+ (unknown_file_metadata(cx), UNKNOWN_LINE_NUMBER)
};
let is_local_to_unit = is_node_local_to_unit(cx, def_id);
@@ -2504,7 +2504,7 @@
linkage_name.as_ptr().cast(),
linkage_name.len(),
file_metadata,
- line_number.unwrap_or(UNKNOWN_LINE_NUMBER),
+ line_number,
type_metadata,
is_local_to_unit,
global,
diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs b/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs
index 955e739..440e4d5 100644
--- a/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs
+++ b/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs
@@ -224,9 +224,9 @@
/// Information about the original source file.
pub file: Lrc<SourceFile>,
/// The (1-based) line number.
- pub line: Option<u32>,
+ pub line: u32,
/// The (1-based) column number.
- pub col: Option<u32>,
+ pub col: u32,
}
impl CodegenCx<'ll, '_> {
@@ -243,16 +243,16 @@
let line = (line + 1) as u32;
let col = (pos - line_pos).to_u32() + 1;
- (file, Some(line), Some(col))
+ (file, line, col)
}
- Err(file) => (file, None, None),
+ Err(file) => (file, UNKNOWN_LINE_NUMBER, UNKNOWN_COLUMN_NUMBER),
};
// For MSVC, omit the column number.
// Otherwise, emit it. This mimics clang behaviour.
// See discussion in https://github.com/rust-lang/rust/issues/42921
if self.sess().target.is_like_msvc {
- DebugLoc { file, line, col: None }
+ DebugLoc { file, line, col: UNKNOWN_COLUMN_NUMBER }
} else {
DebugLoc { file, line, col }
}
@@ -358,9 +358,9 @@
linkage_name.as_ptr().cast(),
linkage_name.len(),
file_metadata,
- loc.line.unwrap_or(UNKNOWN_LINE_NUMBER),
+ loc.line,
function_type_metadata,
- scope_line.unwrap_or(UNKNOWN_LINE_NUMBER),
+ scope_line,
flags,
spflags,
maybe_definition_llfn,
@@ -481,9 +481,9 @@
}
fn get_parameter_names(cx: &CodegenCx<'_, '_>, generics: &ty::Generics) -> Vec<Symbol> {
- let mut names = generics
- .parent
- .map_or(vec![], |def_id| get_parameter_names(cx, cx.tcx.generics_of(def_id)));
+ let mut names = generics.parent.map_or_else(Vec::new, |def_id| {
+ get_parameter_names(cx, cx.tcx.generics_of(def_id))
+ });
names.extend(generics.params.iter().map(|param| param.name));
names
}
@@ -550,14 +550,7 @@
) -> &'ll DILocation {
let DebugLoc { line, col, .. } = self.lookup_debug_loc(span.lo());
- unsafe {
- llvm::LLVMRustDIBuilderCreateDebugLocation(
- line.unwrap_or(UNKNOWN_LINE_NUMBER),
- col.unwrap_or(UNKNOWN_COLUMN_NUMBER),
- scope,
- inlined_at,
- )
- }
+ unsafe { llvm::LLVMRustDIBuilderCreateDebugLocation(line, col, scope, inlined_at) }
}
fn create_vtable_metadata(&self, ty: Ty<'tcx>, vtable: Self::Value) {
@@ -606,7 +599,7 @@
name.as_ptr().cast(),
name.len(),
file_metadata,
- loc.line.unwrap_or(UNKNOWN_LINE_NUMBER),
+ loc.line,
type_metadata,
true,
DIFlags::FlagZero,