summary refs log tree commit diff
path: root/src/librustc_codegen_llvm/debuginfo/source_loc.rs
blob: 1f871c7d207a41acc5dd160c9f9086f45b7bddcd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
use super::metadata::UNKNOWN_COLUMN_NUMBER;
use super::utils::{debug_context, span_start};

use crate::common::CodegenCx;
use crate::llvm::debuginfo::DIScope;
use crate::llvm::{self, Value};
use rustc_codegen_ssa::traits::*;

use libc::c_uint;
use rustc_span::{Pos, Span};

impl CodegenCx<'ll, '_> {
    pub fn create_debug_loc(&self, scope: &'ll DIScope, span: Span) -> &'ll Value {
        let loc = span_start(self, span);

        // For MSVC, set the column number to zero.
        // Otherwise, emit it. This mimics clang behaviour.
        // See discussion in https://github.com/rust-lang/rust/issues/42921
        let col_used = if self.sess().target.target.options.is_like_msvc {
            UNKNOWN_COLUMN_NUMBER
        } else {
            loc.col.to_usize() as c_uint
        };

        unsafe {
            llvm::LLVMRustDIBuilderCreateDebugLocation(
                debug_context(self).llcontext,
                loc.line as c_uint,
                col_used,
                scope,
                None,
            )
        }
    }
}