Skip to content

Commit 1b05615

Browse files
authored
Rollup merge of #77614 - khyperia:set_span, r=eddyb
Let backends access span information Sometimes, a backend may need to emit warnings, errors, or otherwise need to know the span of the current item in a basic block. So, add a `set_span` method to give the backend that information. The `set_source_location` method already partially does this, however, it's disabled when debug info is disabled. There needs to be a way to unconditionally provide the span.
2 parents 207832b + c5bc956 commit 1b05615

File tree

3 files changed

+6
-1
lines changed

3 files changed

+6
-1
lines changed

compiler/rustc_codegen_llvm/src/builder.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use rustc_data_structures::small_c_str::SmallCStr;
1616
use rustc_hir::def_id::DefId;
1717
use rustc_middle::ty::layout::TyAndLayout;
1818
use rustc_middle::ty::{self, Ty, TyCtxt};
19-
use rustc_span::sym;
19+
use rustc_span::{sym, Span};
2020
use rustc_target::abi::{self, Align, Size};
2121
use rustc_target::spec::{HasTargetSpec, Target};
2222
use std::borrow::Cow;
@@ -139,6 +139,8 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
139139
unsafe { llvm::LLVMGetInsertBlock(self.llbuilder) }
140140
}
141141

142+
fn set_span(&self, _span: Span) {}
143+
142144
fn position_at_end(&mut self, llbb: &'ll BasicBlock) {
143145
unsafe {
144146
llvm::LLVMPositionBuilderAtEnd(self.llbuilder, llbb);

compiler/rustc_codegen_ssa/src/mir/debuginfo.rs

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ impl<D> DebugScope<D> {
5555
impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
5656
pub fn set_debug_loc(&self, bx: &mut Bx, source_info: mir::SourceInfo) {
5757
let (scope, span) = self.debug_loc(source_info);
58+
bx.set_span(span);
5859
if let Some(scope) = scope {
5960
bx.set_source_location(scope, span);
6061
}

compiler/rustc_codegen_ssa/src/traits/builder.rs

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use crate::MemFlags;
1515

1616
use rustc_middle::ty::layout::{HasParamEnv, TyAndLayout};
1717
use rustc_middle::ty::Ty;
18+
use rustc_span::Span;
1819
use rustc_target::abi::{Abi, Align, Scalar, Size};
1920
use rustc_target::spec::HasTargetSpec;
2021

@@ -44,6 +45,7 @@ pub trait BuilderMethods<'a, 'tcx>:
4445
fn build_sibling_block(&self, name: &str) -> Self;
4546
fn cx(&self) -> &Self::CodegenCx;
4647
fn llbb(&self) -> Self::BasicBlock;
48+
fn set_span(&self, span: Span);
4749

4850
fn position_at_end(&mut self, llbb: Self::BasicBlock);
4951
fn ret_void(&mut self);

0 commit comments

Comments
 (0)