Skip to content

Commit 0eec226

Browse files
debuginfo: Implement direct debuginfo source location application for ICmp, FCmp, and CallWithConv.
1 parent d98d508 commit 0eec226

File tree

9 files changed

+112
-45
lines changed

9 files changed

+112
-45
lines changed

src/librustc_trans/trans/_match.rs

+19-8
Original file line numberDiff line numberDiff line change
@@ -819,7 +819,7 @@ fn compare_values<'blk, 'tcx>(cx: Block<'blk, 'tcx>,
819819

820820
let _icx = push_ctxt("compare_values");
821821
if ty::type_is_scalar(rhs_t) {
822-
let rs = compare_scalar_types(cx, lhs, rhs, rhs_t, ast::BiEq);
822+
let rs = compare_scalar_types(cx, lhs, rhs, rhs_t, ast::BiEq, debug_loc);
823823
return Result::new(rs.bcx, rs.val);
824824
}
825825

@@ -1149,17 +1149,28 @@ fn compile_submatch_continue<'a, 'p, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
11491149
RangeResult(Result { val: vbegin, .. },
11501150
Result { bcx, val: vend }) => {
11511151
let Result { bcx, val: llge } =
1152-
compare_scalar_types(
1153-
bcx, test_val,
1154-
vbegin, t, ast::BiGe);
1152+
compare_scalar_types(bcx,
1153+
test_val,
1154+
vbegin,
1155+
t,
1156+
ast::BiGe,
1157+
debug_loc);
11551158
let Result { bcx, val: llle } =
1156-
compare_scalar_types(
1157-
bcx, test_val, vend,
1158-
t, ast::BiLe);
1159+
compare_scalar_types(bcx,
1160+
test_val,
1161+
vend,
1162+
t,
1163+
ast::BiLe,
1164+
debug_loc);
11591165
Result::new(bcx, And(bcx, llge, llle, debug_loc))
11601166
}
11611167
LowerBound(Result { bcx, val }) => {
1162-
compare_scalar_types(bcx, test_val, val, t, ast::BiGe)
1168+
compare_scalar_types(bcx,
1169+
test_val,
1170+
val,
1171+
t,
1172+
ast::BiGe,
1173+
debug_loc)
11631174
}
11641175
}
11651176
};

src/librustc_trans/trans/adt.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,7 @@ pub fn trans_get_discr<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, r: &Repr<'tcx>,
751751
RawNullablePointer { nndiscr, nnty, .. } => {
752752
let cmp = if nndiscr == 0 { IntEQ } else { IntNE };
753753
let llptrty = type_of::sizing_type_of(bcx.ccx(), nnty);
754-
val = ICmp(bcx, cmp, Load(bcx, scrutinee), C_null(llptrty));
754+
val = ICmp(bcx, cmp, Load(bcx, scrutinee), C_null(llptrty), DebugLoc::None);
755755
signed = false;
756756
}
757757
StructWrappedNullablePointer { nndiscr, ref discrfield, .. } => {
@@ -770,7 +770,7 @@ fn struct_wrapped_nullable_bitdiscr(bcx: Block, nndiscr: Disr, discrfield: &Disc
770770
let llptrptr = GEPi(bcx, scrutinee, &discrfield[]);
771771
let llptr = Load(bcx, llptrptr);
772772
let cmp = if nndiscr == 0 { IntEQ } else { IntNE };
773-
ICmp(bcx, cmp, llptr, C_null(val_ty(llptr)))
773+
ICmp(bcx, cmp, llptr, C_null(val_ty(llptr)), DebugLoc::None)
774774
}
775775

776776
/// Helper for cases where the discriminant is simply loaded.

src/librustc_trans/trans/base.rs

+20-15
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ use trans::consts;
6666
use trans::context::SharedCrateContext;
6767
use trans::controlflow;
6868
use trans::datum;
69-
use trans::debuginfo::{self, DebugLoc};
69+
use trans::debuginfo::{self, DebugLoc, ToDebugLoc};
7070
use trans::expr;
7171
use trans::foreign;
7272
use trans::glue;
@@ -540,9 +540,10 @@ pub fn compare_scalar_types<'blk, 'tcx>(cx: Block<'blk, 'tcx>,
540540
lhs: ValueRef,
541541
rhs: ValueRef,
542542
t: Ty<'tcx>,
543-
op: ast::BinOp_)
543+
op: ast::BinOp_,
544+
debug_loc: DebugLoc)
544545
-> Result<'blk, 'tcx> {
545-
let f = |a| Result::new(cx, compare_scalar_values(cx, lhs, rhs, a, op));
546+
let f = |a| Result::new(cx, compare_scalar_values(cx, lhs, rhs, a, op, debug_loc));
546547

547548
match t.sty {
548549
ty::ty_tup(ref tys) if tys.is_empty() => f(nil_type),
@@ -561,7 +562,8 @@ pub fn compare_scalar_values<'blk, 'tcx>(cx: Block<'blk, 'tcx>,
561562
lhs: ValueRef,
562563
rhs: ValueRef,
563564
nt: scalar_type,
564-
op: ast::BinOp_)
565+
op: ast::BinOp_,
566+
debug_loc: DebugLoc)
565567
-> ValueRef {
566568
let _icx = push_ctxt("compare_scalar_values");
567569
fn die(cx: Block) -> ! {
@@ -588,7 +590,7 @@ pub fn compare_scalar_values<'blk, 'tcx>(cx: Block<'blk, 'tcx>,
588590
ast::BiGe => llvm::RealOGE,
589591
_ => die(cx)
590592
};
591-
return FCmp(cx, cmp, lhs, rhs);
593+
return FCmp(cx, cmp, lhs, rhs, debug_loc);
592594
}
593595
signed_int => {
594596
let cmp = match op {
@@ -600,7 +602,7 @@ pub fn compare_scalar_values<'blk, 'tcx>(cx: Block<'blk, 'tcx>,
600602
ast::BiGe => llvm::IntSGE,
601603
_ => die(cx)
602604
};
603-
return ICmp(cx, cmp, lhs, rhs);
605+
return ICmp(cx, cmp, lhs, rhs, debug_loc);
604606
}
605607
unsigned_int => {
606608
let cmp = match op {
@@ -612,7 +614,7 @@ pub fn compare_scalar_values<'blk, 'tcx>(cx: Block<'blk, 'tcx>,
612614
ast::BiGe => llvm::IntUGE,
613615
_ => die(cx)
614616
};
615-
return ICmp(cx, cmp, lhs, rhs);
617+
return ICmp(cx, cmp, lhs, rhs, debug_loc);
616618
}
617619
}
618620
}
@@ -623,7 +625,8 @@ pub fn compare_simd_types<'blk, 'tcx>(
623625
rhs: ValueRef,
624626
t: Ty<'tcx>,
625627
size: uint,
626-
op: ast::BinOp)
628+
op: ast::BinOp_,
629+
debug_loc: DebugLoc)
627630
-> ValueRef {
628631
let cmp = match t.sty {
629632
ty::ty_float(_) => {
@@ -634,7 +637,7 @@ pub fn compare_simd_types<'blk, 'tcx>(
634637
cx.sess().bug("compare_simd_types: comparison operators \
635638
not supported for floating point SIMD types")
636639
},
637-
ty::ty_uint(_) => match op.node {
640+
ty::ty_uint(_) => match op {
638641
ast::BiEq => llvm::IntEQ,
639642
ast::BiNe => llvm::IntNE,
640643
ast::BiLt => llvm::IntULT,
@@ -643,7 +646,7 @@ pub fn compare_simd_types<'blk, 'tcx>(
643646
ast::BiGe => llvm::IntUGE,
644647
_ => cx.sess().bug("compare_simd_types: must be a comparison operator"),
645648
},
646-
ty::ty_int(_) => match op.node {
649+
ty::ty_int(_) => match op {
647650
ast::BiEq => llvm::IntEQ,
648651
ast::BiNe => llvm::IntNE,
649652
ast::BiLt => llvm::IntSLT,
@@ -659,7 +662,7 @@ pub fn compare_simd_types<'blk, 'tcx>(
659662
// to get the correctly sized type. This will compile to a single instruction
660663
// once the IR is converted to assembly if the SIMD instruction is supported
661664
// by the target architecture.
662-
SExt(cx, ICmp(cx, cmp, lhs, rhs), return_ty)
665+
SExt(cx, ICmp(cx, cmp, lhs, rhs, debug_loc), return_ty)
663666
}
664667

665668
// Iterates through the elements of a structural type.
@@ -866,14 +869,16 @@ pub fn fail_if_zero_or_overflows<'blk, 'tcx>(
866869
("attempted remainder with a divisor of zero",
867870
"attempted remainder with overflow")
868871
};
872+
let debug_loc = call_info.debug_loc();
873+
869874
let (is_zero, is_signed) = match rhs_t.sty {
870875
ty::ty_int(t) => {
871876
let zero = C_integral(Type::int_from_ty(cx.ccx(), t), 0u64, false);
872-
(ICmp(cx, llvm::IntEQ, rhs, zero), true)
877+
(ICmp(cx, llvm::IntEQ, rhs, zero, debug_loc), true)
873878
}
874879
ty::ty_uint(t) => {
875880
let zero = C_integral(Type::uint_from_ty(cx.ccx(), t), 0u64, false);
876-
(ICmp(cx, llvm::IntEQ, rhs, zero), false)
881+
(ICmp(cx, llvm::IntEQ, rhs, zero, debug_loc), false)
877882
}
878883
_ => {
879884
cx.sess().bug(&format!("fail-if-zero on unexpected type: {}",
@@ -910,10 +915,10 @@ pub fn fail_if_zero_or_overflows<'blk, 'tcx>(
910915
_ => unreachable!(),
911916
};
912917
let minus_one = ICmp(bcx, llvm::IntEQ, rhs,
913-
C_integral(llty, -1, false));
918+
C_integral(llty, -1, false), debug_loc);
914919
with_cond(bcx, minus_one, |bcx| {
915920
let is_min = ICmp(bcx, llvm::IntEQ, lhs,
916-
C_integral(llty, min, true));
921+
C_integral(llty, min, true), debug_loc);
917922
with_cond(bcx, is_min, |bcx| {
918923
controlflow::trans_fail(bcx,
919924
call_info,

src/librustc_trans/trans/build.rs

+25-7
Original file line numberDiff line numberDiff line change
@@ -856,22 +856,32 @@ pub fn FPCast(cx: Block, val: ValueRef, dest_ty: Type) -> ValueRef {
856856

857857

858858
/* Comparisons */
859-
pub fn ICmp(cx: Block, op: IntPredicate, lhs: ValueRef, rhs: ValueRef)
860-
-> ValueRef {
859+
pub fn ICmp(cx: Block,
860+
op: IntPredicate,
861+
lhs: ValueRef,
862+
rhs: ValueRef,
863+
debug_loc: DebugLoc)
864+
-> ValueRef {
861865
unsafe {
862866
if cx.unreachable.get() {
863867
return llvm::LLVMGetUndef(Type::i1(cx.ccx()).to_ref());
864868
}
869+
debug_loc.apply(cx.fcx);
865870
B(cx).icmp(op, lhs, rhs)
866871
}
867872
}
868873

869-
pub fn FCmp(cx: Block, op: RealPredicate, lhs: ValueRef, rhs: ValueRef)
870-
-> ValueRef {
874+
pub fn FCmp(cx: Block,
875+
op: RealPredicate,
876+
lhs: ValueRef,
877+
rhs: ValueRef,
878+
debug_loc: DebugLoc)
879+
-> ValueRef {
871880
unsafe {
872881
if cx.unreachable.get() {
873882
return llvm::LLVMGetUndef(Type::i1(cx.ccx()).to_ref());
874883
}
884+
debug_loc.apply(cx.fcx);
875885
B(cx).fcmp(op, lhs, rhs)
876886
}
877887
}
@@ -941,9 +951,17 @@ pub fn Call(cx: Block,
941951
B(cx).call(fn_, args, attributes)
942952
}
943953

944-
pub fn CallWithConv(cx: Block, fn_: ValueRef, args: &[ValueRef], conv: CallConv,
945-
attributes: Option<AttrBuilder>) -> ValueRef {
946-
if cx.unreachable.get() { return _UndefReturn(cx, fn_); }
954+
pub fn CallWithConv(cx: Block,
955+
fn_: ValueRef,
956+
args: &[ValueRef],
957+
conv: CallConv,
958+
attributes: Option<AttrBuilder>,
959+
debug_loc: DebugLoc)
960+
-> ValueRef {
961+
if cx.unreachable.get() {
962+
return _UndefReturn(cx, fn_);
963+
}
964+
debug_loc.apply(cx.fcx);
947965
B(cx).call_with_conv(fn_, args, conv, attributes)
948966
}
949967

src/librustc_trans/trans/callee.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -827,9 +827,13 @@ pub fn trans_call_inner<'a, 'blk, 'tcx, F>(bcx: Block<'blk, 'tcx>,
827827
abi);
828828
fcx.scopes.borrow_mut().last_mut().unwrap().drop_non_lifetime_clean();
829829

830-
bcx = foreign::trans_native_call(bcx, callee_ty,
831-
llfn, opt_llretslot.unwrap(),
832-
&llargs[], arg_tys);
830+
bcx = foreign::trans_native_call(bcx,
831+
callee_ty,
832+
llfn,
833+
opt_llretslot.unwrap(),
834+
&llargs[],
835+
arg_tys,
836+
debug_loc);
833837
}
834838

835839
fcx.pop_and_trans_custom_cleanup_scope(bcx, arg_cleanup_scope);

src/librustc_trans/trans/expr.rs

+22-4
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,8 @@ fn trans_index<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
696696
let ccx = bcx.ccx();
697697
let mut bcx = bcx;
698698

699+
let index_expr_debug_loc = index_expr.debug_loc();
700+
699701
// Check for overloaded index.
700702
let method_ty = ccx.tcx()
701703
.method_map
@@ -778,13 +780,17 @@ fn trans_index<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
778780
debug!("trans_index: base {}", bcx.val_to_string(base));
779781
debug!("trans_index: len {}", bcx.val_to_string(len));
780782

781-
let bounds_check = ICmp(bcx, llvm::IntUGE, ix_val, len);
783+
let bounds_check = ICmp(bcx,
784+
llvm::IntUGE,
785+
ix_val,
786+
len,
787+
index_expr_debug_loc);
782788
let expect = ccx.get_intrinsic(&("llvm.expect.i1"));
783789
let expected = Call(bcx,
784790
expect,
785791
&[bounds_check, C_bool(ccx, false)],
786792
None,
787-
index_expr.debug_loc());
793+
index_expr_debug_loc);
788794
bcx = with_cond(bcx, expected, |bcx| {
789795
controlflow::trans_fail_bounds_check(bcx,
790796
expr_info(index_expr),
@@ -1744,9 +1750,21 @@ fn trans_eager_binop<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
17441750
}
17451751
ast::BiEq | ast::BiNe | ast::BiLt | ast::BiGe | ast::BiLe | ast::BiGt => {
17461752
if ty::type_is_scalar(rhs_t) {
1747-
unpack_result!(bcx, base::compare_scalar_types(bcx, lhs, rhs, rhs_t, op.node))
1753+
unpack_result!(bcx,
1754+
base::compare_scalar_types(bcx,
1755+
lhs,
1756+
rhs,
1757+
rhs_t,
1758+
op.node,
1759+
binop_debug_loc))
17481760
} else if is_simd {
1749-
base::compare_simd_types(bcx, lhs, rhs, intype, ty::simd_size(tcx, lhs_t), op)
1761+
base::compare_simd_types(bcx,
1762+
lhs,
1763+
rhs,
1764+
intype,
1765+
ty::simd_size(tcx, lhs_t),
1766+
op.node,
1767+
binop_debug_loc)
17501768
} else {
17511769
bcx.tcx().sess.span_bug(binop_expr.span, "comparison operator unsupported for type")
17521770
}

src/librustc_trans/trans/foreign.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use trans::base;
1818
use trans::build::*;
1919
use trans::cabi;
2020
use trans::common::*;
21+
use trans::debuginfo::DebugLoc;
2122
use trans::machine;
2223
use trans::monomorphize;
2324
use trans::type_::Type;
@@ -218,7 +219,8 @@ pub fn trans_native_call<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
218219
llfn: ValueRef,
219220
llretptr: ValueRef,
220221
llargs_rust: &[ValueRef],
221-
passed_arg_tys: Vec<Ty<'tcx>>)
222+
passed_arg_tys: Vec<Ty<'tcx>>,
223+
call_debug_loc: DebugLoc)
222224
-> Block<'blk, 'tcx>
223225
{
224226
let ccx = bcx.ccx();
@@ -370,7 +372,8 @@ pub fn trans_native_call<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
370372
llfn,
371373
&llargs_foreign[],
372374
cc,
373-
Some(attrs));
375+
Some(attrs),
376+
call_debug_loc);
374377

375378
// If the function we just called does not use an outpointer,
376379
// store the result into the rust outpointer. Cast the outpointer

src/librustc_trans/trans/glue.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,11 @@ fn size_and_align_of_dst<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, t: Ty<'tcx>, info:
342342
// Return the sum of sizes and max of aligns.
343343
let size = Add(bcx, sized_size, unsized_size, DebugLoc::None);
344344
let align = Select(bcx,
345-
ICmp(bcx, llvm::IntULT, sized_align, unsized_align),
345+
ICmp(bcx,
346+
llvm::IntULT,
347+
sized_align,
348+
unsized_align,
349+
DebugLoc::None),
346350
sized_align,
347351
unsized_align);
348352
(size, align)

src/librustc_trans/trans/tvec.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,11 @@ pub fn make_drop_glue_unboxed<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
7373
let unit_size = llsize_of_alloc(ccx, llty);
7474
if unit_size != 0 {
7575
let len = get_len(bcx, vptr);
76-
let not_empty = ICmp(bcx, llvm::IntNE, len, C_uint(ccx, 0us));
76+
let not_empty = ICmp(bcx,
77+
llvm::IntNE,
78+
len,
79+
C_uint(ccx, 0us),
80+
DebugLoc::None);
7781
with_cond(bcx, not_empty, |bcx| {
7882
let llalign = C_uint(ccx, machine::llalign_of_min(ccx, llty));
7983
let size = Mul(bcx, C_uint(ccx, unit_size), len, DebugLoc::None);
@@ -443,7 +447,7 @@ pub fn iter_vec_loop<'blk, 'tcx, F>(bcx: Block<'blk, 'tcx>,
443447
{ // i < count
444448
let lhs = Load(cond_bcx, loop_counter);
445449
let rhs = count;
446-
let cond_val = ICmp(cond_bcx, llvm::IntULT, lhs, rhs);
450+
let cond_val = ICmp(cond_bcx, llvm::IntULT, lhs, rhs, DebugLoc::None);
447451

448452
CondBr(cond_bcx, cond_val, body_bcx.llbb, next_bcx.llbb, DebugLoc::None);
449453
}
@@ -497,7 +501,7 @@ pub fn iter_vec_raw<'blk, 'tcx, F>(bcx: Block<'blk, 'tcx>,
497501
let data_ptr =
498502
Phi(header_bcx, val_ty(data_ptr), &[data_ptr], &[bcx.llbb]);
499503
let not_yet_at_end =
500-
ICmp(header_bcx, llvm::IntULT, data_ptr, data_end_ptr);
504+
ICmp(header_bcx, llvm::IntULT, data_ptr, data_end_ptr, DebugLoc::None);
501505
let body_bcx = fcx.new_temp_block("iter_vec_loop_body");
502506
let next_bcx = fcx.new_temp_block("iter_vec_next");
503507
CondBr(header_bcx, not_yet_at_end, body_bcx.llbb, next_bcx.llbb, DebugLoc::None);

0 commit comments

Comments
 (0)