nhwn: use Option<NonZeroU32> in DebugLoc

This commit is contained in:
Nathan Nguyen 2021-02-18 23:18:20 -06:00
parent 0148b971c9
commit f5aa1bceb9
3 changed files with 13 additions and 12 deletions

View File

@ -102,8 +102,8 @@ fn make_mir_scope(
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.map_or(UNKNOWN_LINE_NUMBER, |n| n.get()),
loc.col.map_or(UNKNOWN_COLUMN_NUMBER, |n| n.get()),
)
},
};

View File

@ -1841,7 +1841,7 @@ fn source_info(&self, cx: &CodegenCx<'ll, 'tcx>) -> Option<SourceInfo<'ll>> {
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),
line: loc.line.map_or(UNKNOWN_LINE_NUMBER, |n| n.get()),
});
}
}
@ -2504,7 +2504,7 @@ pub fn create_global_var_metadata(cx: &CodegenCx<'ll, '_>, def_id: DefId, global
linkage_name.as_ptr().cast(),
linkage_name.len(),
file_metadata,
line_number.unwrap_or(UNKNOWN_LINE_NUMBER),
line_number.map_or(UNKNOWN_LINE_NUMBER, |n| n.get()),
type_metadata,
is_local_to_unit,
global,

View File

@ -38,6 +38,7 @@
use libc::c_uint;
use smallvec::SmallVec;
use std::cell::RefCell;
use std::num::NonZeroU32;
use tracing::debug;
mod create_scope_map;
@ -224,9 +225,9 @@ pub struct DebugLoc {
/// Information about the original source file.
pub file: Lrc<SourceFile>,
/// The (1-based) line number.
pub line: Option<u32>,
pub line: Option<NonZeroU32>,
/// The (1-based) column number.
pub col: Option<u32>,
pub col: Option<NonZeroU32>,
}
impl CodegenCx<'ll, '_> {
@ -243,7 +244,7 @@ pub fn lookup_debug_loc(&self, pos: BytePos) -> DebugLoc {
let line = (line + 1) as u32;
let col = (pos - line_pos).to_u32() + 1;
(file, Some(line), Some(col))
(file, NonZeroU32::new(line), NonZeroU32::new(col))
}
Err(file) => (file, None, None),
};
@ -358,9 +359,9 @@ fn dbg_scope_fn(
linkage_name.as_ptr().cast(),
linkage_name.len(),
file_metadata,
loc.line.unwrap_or(UNKNOWN_LINE_NUMBER),
loc.line.map_or(UNKNOWN_LINE_NUMBER, |n| n.get()),
function_type_metadata,
scope_line.unwrap_or(UNKNOWN_LINE_NUMBER),
scope_line.map_or(UNKNOWN_LINE_NUMBER, |n| n.get()),
flags,
spflags,
maybe_definition_llfn,
@ -552,8 +553,8 @@ fn dbg_loc(
unsafe {
llvm::LLVMRustDIBuilderCreateDebugLocation(
line.unwrap_or(UNKNOWN_LINE_NUMBER),
col.unwrap_or(UNKNOWN_COLUMN_NUMBER),
line.map_or(UNKNOWN_LINE_NUMBER, |n| n.get()),
col.map_or(UNKNOWN_COLUMN_NUMBER, |n| n.get()),
scope,
inlined_at,
)
@ -606,7 +607,7 @@ fn create_dbg_var(
name.as_ptr().cast(),
name.len(),
file_metadata,
loc.line.unwrap_or(UNKNOWN_LINE_NUMBER),
loc.line.map_or(UNKNOWN_LINE_NUMBER, |n| n.get()),
type_metadata,
true,
DIFlags::FlagZero,