Skip to content

Commit d98d508

Browse files
debuginfo: Assign debuginfo source locations to lang-item calls.
1 parent 7884eb8 commit d98d508

File tree

10 files changed

+199
-127
lines changed

10 files changed

+199
-127
lines changed

src/librustc_trans/trans/_match.rs

+69-44
Original file line numberDiff line numberDiff line change
@@ -244,25 +244,29 @@ impl<'a> ConstantExpr<'a> {
244244
// An option identifying a branch (either a literal, an enum variant or a range)
245245
#[derive(Debug)]
246246
enum Opt<'a, 'tcx> {
247-
ConstantValue(ConstantExpr<'a>),
248-
ConstantRange(ConstantExpr<'a>, ConstantExpr<'a>),
249-
Variant(ty::Disr, Rc<adt::Repr<'tcx>>, ast::DefId),
250-
SliceLengthEqual(uint),
251-
SliceLengthGreaterOrEqual(/* prefix length */ uint, /* suffix length */ uint),
247+
ConstantValue(ConstantExpr<'a>, DebugLoc),
248+
ConstantRange(ConstantExpr<'a>, ConstantExpr<'a>, DebugLoc),
249+
Variant(ty::Disr, Rc<adt::Repr<'tcx>>, ast::DefId, DebugLoc),
250+
SliceLengthEqual(uint, DebugLoc),
251+
SliceLengthGreaterOrEqual(/* prefix length */ uint,
252+
/* suffix length */ uint,
253+
DebugLoc),
252254
}
253255

254256
impl<'a, 'tcx> Opt<'a, 'tcx> {
255257
fn eq(&self, other: &Opt<'a, 'tcx>, tcx: &ty::ctxt<'tcx>) -> bool {
256258
match (self, other) {
257-
(&ConstantValue(a), &ConstantValue(b)) => a.eq(b, tcx),
258-
(&ConstantRange(a1, a2), &ConstantRange(b1, b2)) => {
259+
(&ConstantValue(a, _), &ConstantValue(b, _)) => a.eq(b, tcx),
260+
(&ConstantRange(a1, a2, _), &ConstantRange(b1, b2, _)) => {
259261
a1.eq(b1, tcx) && a2.eq(b2, tcx)
260262
}
261-
(&Variant(a_disr, ref a_repr, a_def), &Variant(b_disr, ref b_repr, b_def)) => {
263+
(&Variant(a_disr, ref a_repr, a_def, _),
264+
&Variant(b_disr, ref b_repr, b_def, _)) => {
262265
a_disr == b_disr && *a_repr == *b_repr && a_def == b_def
263266
}
264-
(&SliceLengthEqual(a), &SliceLengthEqual(b)) => a == b,
265-
(&SliceLengthGreaterOrEqual(a1, a2), &SliceLengthGreaterOrEqual(b1, b2)) => {
267+
(&SliceLengthEqual(a, _), &SliceLengthEqual(b, _)) => a == b,
268+
(&SliceLengthGreaterOrEqual(a1, a2, _),
269+
&SliceLengthGreaterOrEqual(b1, b2, _)) => {
266270
a1 == b1 && a2 == b2
267271
}
268272
_ => false
@@ -273,29 +277,39 @@ impl<'a, 'tcx> Opt<'a, 'tcx> {
273277
let _icx = push_ctxt("match::trans_opt");
274278
let ccx = bcx.ccx();
275279
match *self {
276-
ConstantValue(ConstantExpr(lit_expr)) => {
280+
ConstantValue(ConstantExpr(lit_expr), _) => {
277281
let lit_ty = ty::node_id_to_type(bcx.tcx(), lit_expr.id);
278282
let (llval, _) = consts::const_expr(ccx, &*lit_expr);
279283
let lit_datum = immediate_rvalue(llval, lit_ty);
280284
let lit_datum = unpack_datum!(bcx, lit_datum.to_appropriate_datum(bcx));
281285
SingleResult(Result::new(bcx, lit_datum.val))
282286
}
283-
ConstantRange(ConstantExpr(ref l1), ConstantExpr(ref l2)) => {
287+
ConstantRange(ConstantExpr(ref l1), ConstantExpr(ref l2), _) => {
284288
let (l1, _) = consts::const_expr(ccx, &**l1);
285289
let (l2, _) = consts::const_expr(ccx, &**l2);
286290
RangeResult(Result::new(bcx, l1), Result::new(bcx, l2))
287291
}
288-
Variant(disr_val, ref repr, _) => {
292+
Variant(disr_val, ref repr, _, _) => {
289293
adt::trans_case(bcx, &**repr, disr_val)
290294
}
291-
SliceLengthEqual(length) => {
295+
SliceLengthEqual(length, _) => {
292296
SingleResult(Result::new(bcx, C_uint(ccx, length)))
293297
}
294-
SliceLengthGreaterOrEqual(prefix, suffix) => {
298+
SliceLengthGreaterOrEqual(prefix, suffix, _) => {
295299
LowerBound(Result::new(bcx, C_uint(ccx, prefix + suffix)))
296300
}
297301
}
298302
}
303+
304+
fn debug_loc(&self) -> DebugLoc {
305+
match *self {
306+
ConstantValue(_,debug_loc) |
307+
ConstantRange(_, _, debug_loc) |
308+
Variant(_, _, _, debug_loc) |
309+
SliceLengthEqual(_, debug_loc) |
310+
SliceLengthGreaterOrEqual(_, _, debug_loc) => debug_loc
311+
}
312+
}
299313
}
300314

301315
#[derive(Copy, PartialEq)]
@@ -527,18 +541,18 @@ fn enter_opt<'a, 'p, 'blk, 'tcx>(
527541
let _indenter = indenter();
528542

529543
let ctor = match opt {
530-
&ConstantValue(ConstantExpr(expr)) => check_match::ConstantValue(
544+
&ConstantValue(ConstantExpr(expr), _) => check_match::ConstantValue(
531545
const_eval::eval_const_expr(bcx.tcx(), &*expr)
532546
),
533-
&ConstantRange(ConstantExpr(lo), ConstantExpr(hi)) => check_match::ConstantRange(
547+
&ConstantRange(ConstantExpr(lo), ConstantExpr(hi), _) => check_match::ConstantRange(
534548
const_eval::eval_const_expr(bcx.tcx(), &*lo),
535549
const_eval::eval_const_expr(bcx.tcx(), &*hi)
536550
),
537-
&SliceLengthEqual(n) =>
551+
&SliceLengthEqual(n, _) =>
538552
check_match::Slice(n),
539-
&SliceLengthGreaterOrEqual(before, after) =>
553+
&SliceLengthGreaterOrEqual(before, after, _) =>
540554
check_match::SliceWithSubslice(before, after),
541-
&Variant(_, _, def_id) =>
555+
&Variant(_, _, def_id, _) =>
542556
check_match::Constructor::Variant(def_id)
543557
};
544558

@@ -563,27 +577,34 @@ fn get_branches<'a, 'p, 'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
563577
let mut found: Vec<Opt> = vec![];
564578
for br in m {
565579
let cur = br.pats[col];
580+
let debug_loc = DebugLoc::At(cur.id, cur.span);
581+
566582
let opt = match cur.node {
567-
ast::PatLit(ref l) => ConstantValue(ConstantExpr(&**l)),
583+
ast::PatLit(ref l) => {
584+
ConstantValue(ConstantExpr(&**l), debug_loc)
585+
}
568586
ast::PatIdent(..) | ast::PatEnum(..) | ast::PatStruct(..) => {
569587
// This is either an enum variant or a variable binding.
570588
let opt_def = tcx.def_map.borrow().get(&cur.id).cloned();
571589
match opt_def {
572590
Some(def::DefVariant(enum_id, var_id, _)) => {
573591
let variant = ty::enum_variant_with_id(tcx, enum_id, var_id);
574-
Variant(variant.disr_val, adt::represent_node(bcx, cur.id), var_id)
592+
Variant(variant.disr_val,
593+
adt::represent_node(bcx, cur.id),
594+
var_id,
595+
debug_loc)
575596
}
576597
_ => continue
577598
}
578599
}
579600
ast::PatRange(ref l1, ref l2) => {
580-
ConstantRange(ConstantExpr(&**l1), ConstantExpr(&**l2))
601+
ConstantRange(ConstantExpr(&**l1), ConstantExpr(&**l2), debug_loc)
581602
}
582603
ast::PatVec(ref before, None, ref after) => {
583-
SliceLengthEqual(before.len() + after.len())
604+
SliceLengthEqual(before.len() + after.len(), debug_loc)
584605
}
585606
ast::PatVec(ref before, Some(_), ref after) => {
586-
SliceLengthGreaterOrEqual(before.len(), after.len())
607+
SliceLengthGreaterOrEqual(before.len(), after.len(), debug_loc)
587608
}
588609
_ => continue
589610
};
@@ -779,19 +800,21 @@ fn pick_column_to_specialize(def_map: &DefMap, m: &[Match]) -> Option<uint> {
779800
fn compare_values<'blk, 'tcx>(cx: Block<'blk, 'tcx>,
780801
lhs: ValueRef,
781802
rhs: ValueRef,
782-
rhs_t: Ty<'tcx>)
803+
rhs_t: Ty<'tcx>,
804+
debug_loc: DebugLoc)
783805
-> Result<'blk, 'tcx> {
784806
fn compare_str<'blk, 'tcx>(cx: Block<'blk, 'tcx>,
785807
lhs: ValueRef,
786808
rhs: ValueRef,
787-
rhs_t: Ty<'tcx>)
809+
rhs_t: Ty<'tcx>,
810+
debug_loc: DebugLoc)
788811
-> Result<'blk, 'tcx> {
789812
let did = langcall(cx,
790813
None,
791814
&format!("comparison of `{}`",
792815
cx.ty_to_string(rhs_t))[],
793816
StrEqFnLangItem);
794-
callee::trans_lang_call(cx, did, &[lhs, rhs], None)
817+
callee::trans_lang_call(cx, did, &[lhs, rhs], None, debug_loc)
795818
}
796819

797820
let _icx = push_ctxt("compare_values");
@@ -802,7 +825,7 @@ fn compare_values<'blk, 'tcx>(cx: Block<'blk, 'tcx>,
802825

803826
match rhs_t.sty {
804827
ty::ty_rptr(_, mt) => match mt.ty.sty {
805-
ty::ty_str => compare_str(cx, lhs, rhs, rhs_t),
828+
ty::ty_str => compare_str(cx, lhs, rhs, rhs_t, debug_loc),
806829
ty::ty_vec(ty, _) => match ty.sty {
807830
ty::ty_uint(ast::TyU8) => {
808831
// NOTE: cast &[u8] to &str and abuse the str_eq lang item,
@@ -812,7 +835,7 @@ fn compare_values<'blk, 'tcx>(cx: Block<'blk, 'tcx>,
812835
ast::MutImmutable);
813836
let lhs = BitCast(cx, lhs, type_of::type_of(cx.ccx(), t).ptr_to());
814837
let rhs = BitCast(cx, rhs, type_of::type_of(cx.ccx(), t).ptr_to());
815-
compare_str(cx, lhs, rhs, rhs_t)
838+
compare_str(cx, lhs, rhs, rhs_t, debug_loc)
816839
},
817840
_ => cx.sess().bug("only byte strings supported in compare_values"),
818841
},
@@ -1044,20 +1067,20 @@ fn compile_submatch_continue<'a, 'p, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
10441067
debug!("test_val={}", bcx.val_to_string(test_val));
10451068
if opts.len() > 0 {
10461069
match opts[0] {
1047-
ConstantValue(_) | ConstantRange(_, _) => {
1070+
ConstantValue(..) | ConstantRange(..) => {
10481071
test_val = load_if_immediate(bcx, val, left_ty);
10491072
kind = if ty::type_is_integral(left_ty) {
10501073
Switch
10511074
} else {
10521075
Compare
10531076
};
10541077
}
1055-
Variant(_, ref repr, _) => {
1078+
Variant(_, ref repr, _, _) => {
10561079
let (the_kind, val_opt) = adt::trans_switch(bcx, &**repr, val);
10571080
kind = the_kind;
10581081
if let Some(tval) = val_opt { test_val = tval; }
10591082
}
1060-
SliceLengthEqual(_) | SliceLengthGreaterOrEqual(_, _) => {
1083+
SliceLengthEqual(..) | SliceLengthGreaterOrEqual(..) => {
10611084
let (_, len) = tvec::get_base_and_len(bcx, val, left_ty);
10621085
test_val = len;
10631086
kind = Switch;
@@ -1066,8 +1089,8 @@ fn compile_submatch_continue<'a, 'p, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
10661089
}
10671090
for o in &opts {
10681091
match *o {
1069-
ConstantRange(_, _) => { kind = Compare; break },
1070-
SliceLengthGreaterOrEqual(_, _) => { kind = CompareSliceLength; break },
1092+
ConstantRange(..) => { kind = Compare; break },
1093+
SliceLengthGreaterOrEqual(..) => { kind = CompareSliceLength; break },
10711094
_ => ()
10721095
}
10731096
}
@@ -1093,10 +1116,12 @@ fn compile_submatch_continue<'a, 'p, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
10931116
// for the current conditional branch.
10941117
let mut branch_chk = None;
10951118
let mut opt_cx = else_cx;
1119+
let debug_loc = opt.debug_loc();
1120+
10961121
if !exhaustive || i + 1 < len {
10971122
opt_cx = bcx.fcx.new_temp_block("match_case");
10981123
match kind {
1099-
Single => Br(bcx, opt_cx.llbb, DebugLoc::None),
1124+
Single => Br(bcx, opt_cx.llbb, debug_loc),
11001125
Switch => {
11011126
match opt.trans(bcx) {
11021127
SingleResult(r) => {
@@ -1119,7 +1144,7 @@ fn compile_submatch_continue<'a, 'p, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
11191144
let Result { bcx: after_cx, val: matches } = {
11201145
match opt.trans(bcx) {
11211146
SingleResult(Result { bcx, val }) => {
1122-
compare_values(bcx, test_val, val, t)
1147+
compare_values(bcx, test_val, val, t, debug_loc)
11231148
}
11241149
RangeResult(Result { val: vbegin, .. },
11251150
Result { bcx, val: vend }) => {
@@ -1131,7 +1156,7 @@ fn compile_submatch_continue<'a, 'p, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
11311156
compare_scalar_types(
11321157
bcx, test_val, vend,
11331158
t, ast::BiLe);
1134-
Result::new(bcx, And(bcx, llge, llle, DebugLoc::None))
1159+
Result::new(bcx, And(bcx, llge, llle, debug_loc))
11351160
}
11361161
LowerBound(Result { bcx, val }) => {
11371162
compare_scalar_types(bcx, test_val, val, t, ast::BiGe)
@@ -1149,37 +1174,37 @@ fn compile_submatch_continue<'a, 'p, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
11491174
if i + 1 < len && (guarded || multi_pats || kind == CompareSliceLength) {
11501175
branch_chk = Some(JumpToBasicBlock(bcx.llbb));
11511176
}
1152-
CondBr(after_cx, matches, opt_cx.llbb, bcx.llbb, DebugLoc::None);
1177+
CondBr(after_cx, matches, opt_cx.llbb, bcx.llbb, debug_loc);
11531178
}
11541179
_ => ()
11551180
}
11561181
} else if kind == Compare || kind == CompareSliceLength {
1157-
Br(bcx, else_cx.llbb, DebugLoc::None);
1182+
Br(bcx, else_cx.llbb, debug_loc);
11581183
}
11591184

11601185
let mut size = 0;
11611186
let mut unpacked = Vec::new();
11621187
match *opt {
1163-
Variant(disr_val, ref repr, _) => {
1188+
Variant(disr_val, ref repr, _, _) => {
11641189
let ExtractedBlock {vals: argvals, bcx: new_bcx} =
11651190
extract_variant_args(opt_cx, &**repr, disr_val, val);
11661191
size = argvals.len();
11671192
unpacked = argvals;
11681193
opt_cx = new_bcx;
11691194
}
1170-
SliceLengthEqual(len) => {
1195+
SliceLengthEqual(len, _) => {
11711196
let args = extract_vec_elems(opt_cx, left_ty, len, 0, val);
11721197
size = args.vals.len();
11731198
unpacked = args.vals.clone();
11741199
opt_cx = args.bcx;
11751200
}
1176-
SliceLengthGreaterOrEqual(before, after) => {
1201+
SliceLengthGreaterOrEqual(before, after, _) => {
11771202
let args = extract_vec_elems(opt_cx, left_ty, before, after, val);
11781203
size = args.vals.len();
11791204
unpacked = args.vals.clone();
11801205
opt_cx = args.bcx;
11811206
}
1182-
ConstantValue(_) | ConstantRange(_, _) => ()
1207+
ConstantValue(..) | ConstantRange(..) => ()
11831208
}
11841209
let opt_ms = enter_opt(opt_cx, pat_id, dm, m, opt, col, size, val);
11851210
let mut opt_vals = unpacked;

src/librustc_trans/trans/base.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ use trans::closure;
5757
use trans::common::{Block, C_bool, C_bytes_in_context, C_i32, C_integral};
5858
use trans::common::{C_null, C_struct_in_context, C_u64, C_u8, C_undef};
5959
use trans::common::{CrateContext, ExternMap, FunctionContext};
60-
use trans::common::{Result};
60+
use trans::common::{Result, NodeIdAndSpan};
6161
use trans::common::{node_id_type, return_type_is_void};
6262
use trans::common::{tydesc_info, type_is_immediate};
6363
use trans::common::{type_is_zero_size, val_ty};
@@ -379,15 +379,17 @@ pub fn malloc_raw_dyn<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
379379
llty_ptr: Type,
380380
info_ty: Ty<'tcx>,
381381
size: ValueRef,
382-
align: ValueRef)
382+
align: ValueRef,
383+
debug_loc: DebugLoc)
383384
-> Result<'blk, 'tcx> {
384385
let _icx = push_ctxt("malloc_raw_exchange");
385386

386387
// Allocate space:
387388
let r = callee::trans_lang_call(bcx,
388389
require_alloc_fn(bcx, info_ty, ExchangeMallocFnLangItem),
389390
&[size, align],
390-
None);
391+
None,
392+
debug_loc);
391393

392394
Result::new(r.bcx, PointerCast(r.bcx, r.val, llty_ptr))
393395
}
@@ -851,7 +853,7 @@ pub fn cast_shift_rhs<F, G>(op: ast::BinOp,
851853

852854
pub fn fail_if_zero_or_overflows<'blk, 'tcx>(
853855
cx: Block<'blk, 'tcx>,
854-
span: Span,
856+
call_info: NodeIdAndSpan,
855857
divrem: ast::BinOp,
856858
lhs: ValueRef,
857859
rhs: ValueRef,
@@ -879,7 +881,7 @@ pub fn fail_if_zero_or_overflows<'blk, 'tcx>(
879881
}
880882
};
881883
let bcx = with_cond(cx, is_zero, |bcx| {
882-
controlflow::trans_fail(bcx, span, InternedString::new(zero_text))
884+
controlflow::trans_fail(bcx, call_info, InternedString::new(zero_text))
883885
});
884886

885887
// To quote LLVM's documentation for the sdiv instruction:
@@ -913,7 +915,8 @@ pub fn fail_if_zero_or_overflows<'blk, 'tcx>(
913915
let is_min = ICmp(bcx, llvm::IntEQ, lhs,
914916
C_integral(llty, min, true));
915917
with_cond(bcx, is_min, |bcx| {
916-
controlflow::trans_fail(bcx, span,
918+
controlflow::trans_fail(bcx,
919+
call_info,
917920
InternedString::new(overflow_text))
918921
})
919922
})

0 commit comments

Comments
 (0)