]> git.lizzy.rs Git - rust.git/blob - src/librustc_codegen_llvm/debuginfo/source_loc.rs
Rollup merge of #69697 - GuillaumeGomez:explanation-e0380, r=Dylan-DPC
[rust.git] / src / librustc_codegen_llvm / debuginfo / source_loc.rs
1 use super::metadata::UNKNOWN_COLUMN_NUMBER;
2 use super::utils::{debug_context, span_start};
3
4 use crate::common::CodegenCx;
5 use crate::llvm::debuginfo::DIScope;
6 use crate::llvm::{self, Value};
7 use rustc_codegen_ssa::traits::*;
8
9 use libc::c_uint;
10 use rustc_span::{Pos, Span};
11
12 impl CodegenCx<'ll, '_> {
13     pub fn create_debug_loc(&self, scope: &'ll DIScope, span: Span) -> &'ll Value {
14         let loc = span_start(self, span);
15
16         // For MSVC, set the column number to zero.
17         // Otherwise, emit it. This mimics clang behaviour.
18         // See discussion in https://github.com/rust-lang/rust/issues/42921
19         let col_used = if self.sess().target.target.options.is_like_msvc {
20             UNKNOWN_COLUMN_NUMBER
21         } else {
22             loc.col.to_usize() as c_uint
23         };
24
25         unsafe {
26             llvm::LLVMRustDIBuilderCreateDebugLocation(
27                 debug_context(self).llcontext,
28                 loc.line as c_uint,
29                 col_used,
30                 scope,
31                 None,
32             )
33         }
34     }
35 }