Fix LLVM assertions when lowering log statements.
This commit is contained in:
parent
fa6d871e11
commit
544bcfece2
|
@ -306,34 +306,65 @@ fn get_local_var_metadata(bcx: @block_ctxt, local: @ast::local)
|
|||
ret mdval;
|
||||
}
|
||||
|
||||
fn update_source_pos(cx: @block_ctxt, s: codemap::span) {
|
||||
fn update_source_pos(cx: @block_ctxt, s: codemap::span) -> @debug_source_pos {
|
||||
let dsp = @debug_source_pos(cx);
|
||||
if !bcx_ccx(cx).sess.get_opts().debuginfo {
|
||||
ret dsp;
|
||||
}
|
||||
let cm = bcx_ccx(cx).sess.get_codemap();
|
||||
if vec::is_empty(cx.source_pos.pos) {
|
||||
cx.source_pos.usable = true;
|
||||
}
|
||||
cx.source_pos.pos += [codemap::lookup_char_pos(cm, s.lo)]; //XXX maybe hi
|
||||
ret dsp;
|
||||
}
|
||||
|
||||
fn invalidate_source_pos(cx: @block_ctxt) -> @invalidated_source_pos {
|
||||
let isp = @invalidated_source_pos(cx);
|
||||
if !bcx_ccx(cx).sess.get_opts().debuginfo {
|
||||
ret isp;
|
||||
}
|
||||
cx.source_pos.usable = false;
|
||||
ret isp;
|
||||
}
|
||||
|
||||
fn revalidate_source_pos(cx: @block_ctxt) {
|
||||
if !bcx_ccx(cx).sess.get_opts().debuginfo {
|
||||
ret;
|
||||
}
|
||||
cx.source_pos = option::some(
|
||||
codemap::lookup_char_pos(bcx_ccx(cx).sess.get_codemap(),
|
||||
s.lo)); //XXX maybe hi
|
||||
|
||||
cx.source_pos.usable = true;
|
||||
}
|
||||
|
||||
fn reset_source_pos(cx: @block_ctxt) {
|
||||
cx.source_pos = option::none;
|
||||
if !bcx_ccx(cx).sess.get_opts().debuginfo {
|
||||
ret;
|
||||
}
|
||||
vec::pop(cx.source_pos.pos);
|
||||
}
|
||||
|
||||
resource debug_source_pos(bcx: @block_ctxt) {
|
||||
reset_source_pos(bcx);
|
||||
}
|
||||
resource invalidated_source_pos(bcx: @block_ctxt) {
|
||||
revalidate_source_pos(bcx);
|
||||
}
|
||||
|
||||
fn add_line_info(cx: @block_ctxt, llinstr: ValueRef) {
|
||||
if !bcx_ccx(cx).sess.get_opts().debuginfo ||
|
||||
option::is_none(cx.source_pos) {
|
||||
!cx.source_pos.usable ||
|
||||
vec::is_empty(cx.source_pos.pos) {
|
||||
ret;
|
||||
}
|
||||
let loc = option::get(cx.source_pos);
|
||||
let loc = option::get(vec::last(cx.source_pos.pos));
|
||||
let blockmd = get_block_metadata(cx);
|
||||
let kind_id = llvm::LLVMGetMDKindID(as_buf("dbg"), str::byte_len("dbg"));
|
||||
let kind_id = llvm::LLVMGetMDKindID(as_buf("dbg"),
|
||||
str::byte_len("dbg"));
|
||||
let scopedata = [lli32(loc.line as int),
|
||||
lli32(loc.col as int),
|
||||
blockmd.node,
|
||||
llnull()];
|
||||
let dbgscope = llmdnode(scopedata);
|
||||
llvm::LLVMSetMetadata(llinstr, kind_id, dbgscope);
|
||||
llvm::LLVMSetMetadata(llinstr, kind_id, dbgscope);
|
||||
}
|
||||
|
||||
fn get_function_metadata(cx: @crate_ctxt, item: @ast::item,
|
||||
|
|
|
@ -3519,7 +3519,7 @@ fn trans_temp_expr(bcx: @block_ctxt, e: @ast::expr) -> result {
|
|||
// - exprs with non-immediate type never get dest=by_val
|
||||
fn trans_expr(bcx: @block_ctxt, e: @ast::expr, dest: dest) -> @block_ctxt {
|
||||
let tcx = bcx_tcx(bcx);
|
||||
debuginfo::update_source_pos(bcx, e.span);
|
||||
let _s = debuginfo::update_source_pos(bcx, e.span);
|
||||
|
||||
if expr_is_lval(bcx, e) {
|
||||
ret lval_to_dps(bcx, e, dest);
|
||||
|
@ -4014,7 +4014,7 @@ fn trans_stmt(cx: @block_ctxt, s: ast::stmt) -> @block_ctxt {
|
|||
}
|
||||
|
||||
let bcx = cx;
|
||||
debuginfo::update_source_pos(cx, s.span);
|
||||
let _s = debuginfo::update_source_pos(cx, s.span);
|
||||
|
||||
alt s.node {
|
||||
ast::stmt_expr(e, _) { bcx = trans_expr(cx, e, ignore); }
|
||||
|
@ -4038,7 +4038,7 @@ fn trans_stmt(cx: @block_ctxt, s: ast::stmt) -> @block_ctxt {
|
|||
_ { bcx_ccx(cx).sess.unimpl("stmt variant"); }
|
||||
}
|
||||
|
||||
debuginfo::reset_source_pos(cx);
|
||||
//debuginfo::reset_source_pos(cx);
|
||||
ret bcx;
|
||||
}
|
||||
|
||||
|
@ -4063,7 +4063,8 @@ fn new_block_ctxt(cx: @fn_ctxt, parent: block_parent, kind: block_kind,
|
|||
mutable lpad: option::none,
|
||||
sp: cx.sp,
|
||||
fcx: cx,
|
||||
mutable source_pos: option::none};
|
||||
source_pos: {mutable usable: false,
|
||||
mutable pos: []}};
|
||||
alt parent {
|
||||
parent_some(cx) {
|
||||
if cx.unreachable { Unreachable(bcx); }
|
||||
|
@ -4108,7 +4109,8 @@ fn new_raw_block_ctxt(fcx: @fn_ctxt, llbb: BasicBlockRef) -> @block_ctxt {
|
|||
mutable lpad: option::none,
|
||||
sp: fcx.sp,
|
||||
fcx: fcx,
|
||||
mutable source_pos: option::none};
|
||||
source_pos: {mutable usable: false,
|
||||
mutable pos: []}};
|
||||
}
|
||||
|
||||
|
||||
|
@ -4176,7 +4178,8 @@ fn llstaticallocas_block_ctxt(fcx: @fn_ctxt) -> @block_ctxt {
|
|||
mutable lpad: option::none,
|
||||
sp: fcx.sp,
|
||||
fcx: fcx,
|
||||
mutable source_pos: option::none};
|
||||
source_pos: {mutable usable: false,
|
||||
mutable pos: []}};
|
||||
}
|
||||
|
||||
fn llderivedtydescs_block_ctxt(fcx: @fn_ctxt) -> @block_ctxt {
|
||||
|
@ -4190,7 +4193,8 @@ fn llderivedtydescs_block_ctxt(fcx: @fn_ctxt) -> @block_ctxt {
|
|||
mutable lpad: option::none,
|
||||
sp: fcx.sp,
|
||||
fcx: fcx,
|
||||
mutable source_pos: option::none};
|
||||
source_pos: {mutable usable: false,
|
||||
mutable pos: []}};
|
||||
}
|
||||
|
||||
|
||||
|
@ -4263,20 +4267,22 @@ fn trans_block(bcx: @block_ctxt, b: ast::blk) -> @block_ctxt {
|
|||
fn trans_block_dps(bcx: @block_ctxt, b: ast::blk, dest: dest)
|
||||
-> @block_ctxt {
|
||||
let bcx = bcx;
|
||||
debuginfo::update_source_pos(bcx, b.span);
|
||||
block_locals(b) {|local| bcx = alloc_local(bcx, local); };
|
||||
for s: @ast::stmt in b.node.stmts {
|
||||
let _s = debuginfo::update_source_pos(bcx, b.span);
|
||||
bcx = trans_stmt(bcx, *s);
|
||||
//debuginfo::reset_source_pos(bcx);
|
||||
}
|
||||
alt b.node.expr {
|
||||
some(e) {
|
||||
let bt = ty::type_is_bot(bcx_tcx(bcx), ty::expr_ty(bcx_tcx(bcx), e));
|
||||
let _s = debuginfo::update_source_pos(bcx, e.span);
|
||||
bcx = trans_expr(bcx, e, bt ? ignore : dest);
|
||||
//debuginfo::reset_source_pos(bcx);
|
||||
}
|
||||
_ { assert dest == ignore || bcx.unreachable; }
|
||||
}
|
||||
let rv = trans_block_cleanups(bcx, find_scope_cx(bcx));
|
||||
debuginfo::reset_source_pos(bcx);
|
||||
ret rv;
|
||||
}
|
||||
|
||||
|
|
|
@ -408,7 +408,7 @@ fn GEP(cx: @block_ctxt, Pointer: ValueRef, Indices: [ValueRef]) -> ValueRef {
|
|||
unsafe {
|
||||
let instr = llvm::LLVMBuildGEP(B(cx), Pointer, vec::to_ptr(Indices),
|
||||
vec::len(Indices), noname());
|
||||
debuginfo::add_line_info(cx, instr);
|
||||
//debuginfo::add_line_info(cx, instr);
|
||||
ret instr;
|
||||
}
|
||||
}
|
||||
|
@ -425,18 +425,18 @@ fn InBoundsGEP(cx: @block_ctxt, Pointer: ValueRef, Indices: [ValueRef]) ->
|
|||
ValueRef {
|
||||
if cx.unreachable { ret llvm::LLVMGetUndef(T_ptr(T_nil())); }
|
||||
unsafe {
|
||||
let v = llvm::LLVMBuildInBoundsGEP(B(cx), Pointer,
|
||||
vec::to_ptr(Indices),
|
||||
vec::len(Indices), noname());
|
||||
debuginfo::add_line_info(cx, v);
|
||||
ret v;
|
||||
let instr = llvm::LLVMBuildInBoundsGEP(B(cx), Pointer,
|
||||
vec::to_ptr(Indices),
|
||||
vec::len(Indices), noname());
|
||||
//debuginfo::add_line_info(cx, instr);
|
||||
ret instr;
|
||||
}
|
||||
}
|
||||
|
||||
fn StructGEP(cx: @block_ctxt, Pointer: ValueRef, Idx: uint) -> ValueRef {
|
||||
if cx.unreachable { ret llvm::LLVMGetUndef(T_ptr(T_nil())); }
|
||||
let instr = llvm::LLVMBuildStructGEP(B(cx), Pointer, Idx, noname());
|
||||
debuginfo::add_line_info(cx, instr);
|
||||
//debuginfo::add_line_info(cx, instr);
|
||||
ret instr;
|
||||
}
|
||||
|
||||
|
@ -458,84 +458,84 @@ fn GlobalStringPtr(cx: @block_ctxt, _Str: sbuf) -> ValueRef {
|
|||
fn Trunc(cx: @block_ctxt, Val: ValueRef, DestTy: TypeRef) -> ValueRef {
|
||||
if cx.unreachable { ret llvm::LLVMGetUndef(DestTy); }
|
||||
let instr = llvm::LLVMBuildTrunc(B(cx), Val, DestTy, noname());
|
||||
debuginfo::add_line_info(cx, instr);
|
||||
//debuginfo::add_line_info(cx, instr);
|
||||
ret instr;
|
||||
}
|
||||
|
||||
fn ZExt(cx: @block_ctxt, Val: ValueRef, DestTy: TypeRef) -> ValueRef {
|
||||
if cx.unreachable { ret llvm::LLVMGetUndef(DestTy); }
|
||||
let instr = llvm::LLVMBuildZExt(B(cx), Val, DestTy, noname());
|
||||
debuginfo::add_line_info(cx, instr);
|
||||
//debuginfo::add_line_info(cx, instr);
|
||||
ret instr;
|
||||
}
|
||||
|
||||
fn SExt(cx: @block_ctxt, Val: ValueRef, DestTy: TypeRef) -> ValueRef {
|
||||
if cx.unreachable { ret llvm::LLVMGetUndef(DestTy); }
|
||||
let instr = llvm::LLVMBuildSExt(B(cx), Val, DestTy, noname());
|
||||
debuginfo::add_line_info(cx, instr);
|
||||
//debuginfo::add_line_info(cx, instr);
|
||||
ret instr;
|
||||
}
|
||||
|
||||
fn FPToUI(cx: @block_ctxt, Val: ValueRef, DestTy: TypeRef) -> ValueRef {
|
||||
if cx.unreachable { ret llvm::LLVMGetUndef(DestTy); }
|
||||
let instr = llvm::LLVMBuildFPToUI(B(cx), Val, DestTy, noname());
|
||||
debuginfo::add_line_info(cx, instr);
|
||||
//debuginfo::add_line_info(cx, instr);
|
||||
ret instr;
|
||||
}
|
||||
|
||||
fn FPToSI(cx: @block_ctxt, Val: ValueRef, DestTy: TypeRef) -> ValueRef {
|
||||
if cx.unreachable { ret llvm::LLVMGetUndef(DestTy); }
|
||||
let instr = llvm::LLVMBuildFPToSI(B(cx), Val, DestTy, noname());
|
||||
debuginfo::add_line_info(cx, instr);
|
||||
//debuginfo::add_line_info(cx, instr);
|
||||
ret instr;
|
||||
}
|
||||
|
||||
fn UIToFP(cx: @block_ctxt, Val: ValueRef, DestTy: TypeRef) -> ValueRef {
|
||||
if cx.unreachable { ret llvm::LLVMGetUndef(DestTy); }
|
||||
let instr = llvm::LLVMBuildUIToFP(B(cx), Val, DestTy, noname());
|
||||
debuginfo::add_line_info(cx, instr);
|
||||
//debuginfo::add_line_info(cx, instr);
|
||||
ret instr;
|
||||
}
|
||||
|
||||
fn SIToFP(cx: @block_ctxt, Val: ValueRef, DestTy: TypeRef) -> ValueRef {
|
||||
if cx.unreachable { ret llvm::LLVMGetUndef(DestTy); }
|
||||
let instr = llvm::LLVMBuildSIToFP(B(cx), Val, DestTy, noname());
|
||||
debuginfo::add_line_info(cx, instr);
|
||||
//debuginfo::add_line_info(cx, instr);
|
||||
ret instr;
|
||||
}
|
||||
|
||||
fn FPTrunc(cx: @block_ctxt, Val: ValueRef, DestTy: TypeRef) -> ValueRef {
|
||||
if cx.unreachable { ret llvm::LLVMGetUndef(DestTy); }
|
||||
let instr = llvm::LLVMBuildFPTrunc(B(cx), Val, DestTy, noname());
|
||||
debuginfo::add_line_info(cx, instr);
|
||||
//debuginfo::add_line_info(cx, instr);
|
||||
ret instr;
|
||||
}
|
||||
|
||||
fn FPExt(cx: @block_ctxt, Val: ValueRef, DestTy: TypeRef) -> ValueRef {
|
||||
if cx.unreachable { ret llvm::LLVMGetUndef(DestTy); }
|
||||
let instr = llvm::LLVMBuildFPExt(B(cx), Val, DestTy, noname());
|
||||
debuginfo::add_line_info(cx, instr);
|
||||
//debuginfo::add_line_info(cx, instr);
|
||||
ret instr;
|
||||
}
|
||||
|
||||
fn PtrToInt(cx: @block_ctxt, Val: ValueRef, DestTy: TypeRef) -> ValueRef {
|
||||
if cx.unreachable { ret llvm::LLVMGetUndef(DestTy); }
|
||||
let instr = llvm::LLVMBuildPtrToInt(B(cx), Val, DestTy, noname());
|
||||
debuginfo::add_line_info(cx, instr);
|
||||
//debuginfo::add_line_info(cx, instr);
|
||||
ret instr;
|
||||
}
|
||||
|
||||
fn IntToPtr(cx: @block_ctxt, Val: ValueRef, DestTy: TypeRef) -> ValueRef {
|
||||
if cx.unreachable { ret llvm::LLVMGetUndef(DestTy); }
|
||||
let instr = llvm::LLVMBuildIntToPtr(B(cx), Val, DestTy, noname());
|
||||
debuginfo::add_line_info(cx, instr);
|
||||
//debuginfo::add_line_info(cx, instr);
|
||||
ret instr;
|
||||
}
|
||||
|
||||
fn BitCast(cx: @block_ctxt, Val: ValueRef, DestTy: TypeRef) -> ValueRef {
|
||||
if cx.unreachable { ret llvm::LLVMGetUndef(DestTy); }
|
||||
let instr = llvm::LLVMBuildBitCast(B(cx), Val, DestTy, noname());
|
||||
debuginfo::add_line_info(cx, instr);
|
||||
//debuginfo::add_line_info(cx, instr);
|
||||
ret instr;
|
||||
}
|
||||
|
||||
|
@ -543,7 +543,7 @@ fn ZExtOrBitCast(cx: @block_ctxt, Val: ValueRef, DestTy: TypeRef) ->
|
|||
ValueRef {
|
||||
if cx.unreachable { ret llvm::LLVMGetUndef(DestTy); }
|
||||
let instr = llvm::LLVMBuildZExtOrBitCast(B(cx), Val, DestTy, noname());
|
||||
debuginfo::add_line_info(cx, instr);
|
||||
//debuginfo::add_line_info(cx, instr);
|
||||
ret instr;
|
||||
}
|
||||
|
||||
|
@ -551,7 +551,7 @@ fn SExtOrBitCast(cx: @block_ctxt, Val: ValueRef, DestTy: TypeRef) ->
|
|||
ValueRef {
|
||||
if cx.unreachable { ret llvm::LLVMGetUndef(DestTy); }
|
||||
let instr = llvm::LLVMBuildSExtOrBitCast(B(cx), Val, DestTy, noname());
|
||||
debuginfo::add_line_info(cx, instr);
|
||||
//debuginfo::add_line_info(cx, instr);
|
||||
ret instr;
|
||||
}
|
||||
|
||||
|
@ -559,7 +559,7 @@ fn TruncOrBitCast(cx: @block_ctxt, Val: ValueRef, DestTy: TypeRef) ->
|
|||
ValueRef {
|
||||
if cx.unreachable { ret llvm::LLVMGetUndef(DestTy); }
|
||||
let instr = llvm::LLVMBuildTruncOrBitCast(B(cx), Val, DestTy, noname());
|
||||
debuginfo::add_line_info(cx, instr);
|
||||
//debuginfo::add_line_info(cx, instr);
|
||||
ret instr;
|
||||
}
|
||||
|
||||
|
@ -567,28 +567,28 @@ fn Cast(cx: @block_ctxt, Op: Opcode, Val: ValueRef, DestTy: TypeRef,
|
|||
_Name: sbuf) -> ValueRef {
|
||||
if cx.unreachable { ret llvm::LLVMGetUndef(DestTy); }
|
||||
let instr = llvm::LLVMBuildCast(B(cx), Op, Val, DestTy, noname());
|
||||
debuginfo::add_line_info(cx, instr);
|
||||
//debuginfo::add_line_info(cx, instr);
|
||||
ret instr;
|
||||
}
|
||||
|
||||
fn PointerCast(cx: @block_ctxt, Val: ValueRef, DestTy: TypeRef) -> ValueRef {
|
||||
if cx.unreachable { ret llvm::LLVMGetUndef(DestTy); }
|
||||
let instr = llvm::LLVMBuildPointerCast(B(cx), Val, DestTy, noname());
|
||||
debuginfo::add_line_info(cx, instr);
|
||||
//debuginfo::add_line_info(cx, instr);
|
||||
ret instr;
|
||||
}
|
||||
|
||||
fn IntCast(cx: @block_ctxt, Val: ValueRef, DestTy: TypeRef) -> ValueRef {
|
||||
if cx.unreachable { ret llvm::LLVMGetUndef(DestTy); }
|
||||
let instr = llvm::LLVMBuildIntCast(B(cx), Val, DestTy, noname());
|
||||
debuginfo::add_line_info(cx, instr);
|
||||
//debuginfo::add_line_info(cx, instr);
|
||||
ret instr;
|
||||
}
|
||||
|
||||
fn FPCast(cx: @block_ctxt, Val: ValueRef, DestTy: TypeRef) -> ValueRef {
|
||||
if cx.unreachable { ret llvm::LLVMGetUndef(DestTy); }
|
||||
let instr = llvm::LLVMBuildFPCast(B(cx), Val, DestTy, noname());
|
||||
debuginfo::add_line_info(cx, instr);
|
||||
//debuginfo::add_line_info(cx, instr);
|
||||
ret instr;
|
||||
}
|
||||
|
||||
|
@ -670,7 +670,7 @@ fn Call(cx: @block_ctxt, Fn: ValueRef, Args: [ValueRef]) -> ValueRef {
|
|||
unsafe {
|
||||
let instr = llvm::LLVMBuildCall(B(cx), Fn, vec::to_ptr(Args),
|
||||
vec::len(Args), noname());
|
||||
debuginfo::add_line_info(cx, instr);
|
||||
//debuginfo::add_line_info(cx, instr);
|
||||
ret instr;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -386,7 +386,8 @@ type block_ctxt =
|
|||
mutable lpad: option::t<BasicBlockRef>,
|
||||
sp: span,
|
||||
fcx: @fn_ctxt,
|
||||
mutable source_pos: option::t<syntax::codemap::loc>};
|
||||
source_pos: {mutable usable: bool,
|
||||
mutable pos: [syntax::codemap::loc]}};
|
||||
|
||||
// FIXME: we should be able to use option::t<@block_parent> here but
|
||||
// the infinite-tag check in rustboot gets upset.
|
||||
|
|
|
@ -27,6 +27,7 @@ fn pointer_add(bcx: @block_ctxt, ptr: ValueRef, bytes: ValueRef) -> ValueRef {
|
|||
}
|
||||
|
||||
fn alloc_raw(bcx: @block_ctxt, fill: ValueRef, alloc: ValueRef) -> result {
|
||||
let _s = debuginfo::invalidate_source_pos(bcx);
|
||||
let ccx = bcx_ccx(bcx);
|
||||
let llvecty = ccx.opaque_vec_type;
|
||||
let vecsize = Add(bcx, alloc, llsize_of(ccx, llvecty));
|
||||
|
@ -45,6 +46,7 @@ type alloc_result =
|
|||
llunitty: TypeRef};
|
||||
|
||||
fn alloc(bcx: @block_ctxt, vec_ty: ty::t, elts: uint) -> alloc_result {
|
||||
let _s = debuginfo::invalidate_source_pos(bcx);
|
||||
let ccx = bcx_ccx(bcx);
|
||||
let unit_ty = ty::sequence_element_type(bcx_tcx(bcx), vec_ty);
|
||||
let llunitty = type_of_or_i8(bcx, unit_ty);
|
||||
|
|
Loading…
Reference in a new issue