Skip to content

Commit 10d930d

Browse files
committed
Prevent debug info generation of zero-span nodes
If a node has a (0, 0) span, it was not in the source, so debug symbols should not be generated for it.
1 parent cf22d74 commit 10d930d

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

src/librustc/middle/trans/base.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,13 @@ impl get_insn_ctxt for fn_ctxt {
131131
}
132132
}
133133

134+
fn fcx_has_nonzero_span(fcx: fn_ctxt) -> bool {
135+
match fcx.span {
136+
None => true,
137+
Some(span) => *span.lo != 0 || *span.hi != 0
138+
}
139+
}
140+
134141
pub fn log_fn_time(ccx: @CrateContext, +name: ~str, start: time::Timespec,
135142
end: time::Timespec) {
136143
let elapsed = 1000 * ((end.sec - start.sec) as int) +
@@ -1158,7 +1165,8 @@ pub fn trans_stmt(cx: block, s: ast::stmt) -> block {
11581165
ast::decl_local(ref locals) => {
11591166
for locals.each |local| {
11601167
bcx = init_local(bcx, *local);
1161-
if cx.sess().opts.extra_debuginfo {
1168+
if cx.sess().opts.extra_debuginfo
1169+
&& fcx_has_nonzero_span(bcx.fcx) {
11621170
debuginfo::create_local_var(bcx, *local);
11631171
}
11641172
}
@@ -1738,7 +1746,7 @@ pub fn copy_args_to_allocas(fcx: fn_ctxt,
17381746
17391747
fcx.llargs.insert(arg_id, local_mem(llarg));
17401748
1741-
if fcx.ccx.sess.opts.extra_debuginfo {
1749+
if fcx.ccx.sess.opts.extra_debuginfo && fcx_has_nonzero_span(fcx) {
17421750
debuginfo::create_arg(bcx, args[arg_n], args[arg_n].ty.span);
17431751
}
17441752
}
@@ -1861,7 +1869,8 @@ pub fn trans_fn(ccx: @CrateContext,
18611869
trans_closure(ccx, path, decl, body, llfndecl, ty_self,
18621870
param_substs, id, impl_id,
18631871
|fcx| {
1864-
if ccx.sess.opts.extra_debuginfo {
1872+
if ccx.sess.opts.extra_debuginfo
1873+
&& fcx_has_nonzero_span(fcx) {
18651874
debuginfo::create_function(fcx);
18661875
}
18671876
},

src/librustc/middle/trans/debuginfo.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -946,7 +946,7 @@ pub fn create_arg(bcx: block, arg: ast::arg, sp: span)
946946
}
947947
948948
pub fn update_source_pos(cx: block, s: span) {
949-
if !cx.sess().opts.debuginfo {
949+
if !cx.sess().opts.debuginfo || (*s.lo == 0 && *s.hi == 0) {
950950
return;
951951
}
952952
let cm = cx.sess().codemap;

0 commit comments

Comments
 (0)