Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2016-03-17
12:16 • Closed ticket [b9b2079e6d]: Segfaults parsing a script. The script works nicely ... artifact: 670c2cbd5c user: dgp
12:15
[b9b2079e6d] Unwind ExceptionAux data after failed compile. check-in: fadc9965ff user: dgp tags: core-8-6-branch
2016-03-10
20:04 • Ticket [b9b2079e6d] Segfaults parsing a script. The script works nicely in versi... artifact: d296500336 user: dgp
20:03
[b9b2079e6d] Proposed fix. When a compileProc fails, it may have done an arbitrary amount of partial... check-in: 569d2e3d4f user: dgp tags: bug-b9b2079e6d
2016-03-09
20:29 • Ticket [b9b2079e6d] Segfaults parsing a script. The script works nicely in versi... artifact: f94467e5e3 user: dgp
16:32 • Ticket [b9b2079e6d]: 3 changes artifact: 9392f59e76 user: dgp
04:00 • Ticket [b9b2079e6d]: 6 changes artifact: 3cb85433d5 user: dgp
2016-03-08
18:27 • New ticket [b9b2079e6d]. artifact: 0dbbeb4946 user: anonymous

Segfaults parsing a script. The script works nicely in version 8.5

Closed / Fixedb9b2079e6d23fb18b7944fbb4b703223cff6ec44Created 11 years agoUpdated 11 years ago
Descriptionplain2016-03-08 18:27:18
This is the most simplified code I have been able to write triggering the segfault. It crashes in 32 and 64 bit versions of tcl (debian sid package)

------
#!/bin/tclsh

foreach i {a b} {set t_$i ""}

proc triggerError {} {
    set var_t ""
    foreach i {a b} {
        set v t_$i
        upvar 1 [coalesce [set var_t] [set v]] t_$i
    }
}

proc coalesce {args} {
    set res ""
    foreach i $args {
        if {$i != ""} {set res $i;break}
    }
    return $res
}

triggerError

puts "END"
------

I think the problem has something to do with the parsing of line 9 (the one with the upvar). If you change it like this:

        set aux [coalesce [set var_t] [set v]]
        upvar 1 $aux t_$i

The problem fades away.
Referenced by2
  • fadc9965ff[b9b2079e6d] Unwind ExceptionAux data after failed compile. check-in2016-03-17 12:15:52
  • 569d2e3d4f[b9b2079e6d] Proposed fix. When a compileProc fails, it may have done an arbitrary amount of partial work, which needs to be undone. When the exception handling machinery got its last big revision, the undoing of what it does was neglected. I think this patch gets it all, but more eyes would be good. check-in2016-03-10 20:03:38
dgpplain2016-03-09 04:00:39
A good demo script is a thing of beauty.

All was well until

http://core.tcl.tk/tcl/info/582877d8ab09712c

With that feature merge, the demo script started hanging.

Later we saw

http://core.tcl.tk/tcl/info/93a75ad1c45fb061

which introduced the segfault still seen in Tcl 8.6.5.
dgpplain2016-03-09 16:32:00
#0  0x000000000053d860 in AdvanceJumps (envPtr=0x7fffffffc6d0)
    at /home/dgp/fossil/tcl8.6/generic/tclOptimize.c:398
#1  0x000000000053d9c9 in TclOptimizeBytecode (envPtr=0x7fffffffc6d0)
    at /home/dgp/fossil/tcl8.6/generic/tclOptimize.c:433
#2  0x00000000004bcf40 in TclSetByteCodeFromAny (interp=0x8205c0, 
    objPtr=0x869680, hookProc=0x0, clientData=0x0)
    at /home/dgp/fossil/tcl8.6/generic/tclCompile.c:848
#3  0x000000000054eb72 in TclProcCompileProc (interp=0x8205c0, 
    procPtr=0x87eee0, bodyPtr=0x869680, nsPtr=0x814790, 
    description=0x5d3ac3 "body of proc", procName=0x8803a0 "triggerError")
    at /home/dgp/fossil/tcl8.6/generic/tclProc.c:2071
dgpplain2016-03-09 20:29:39
A cause of the trouble is that TclEmitInvoke() is
creating INST_JUMP4 for break and continue
exception handling that overlap each other.
This means they mangle each others jump
offsets and hilarity ensues.

Still working on the primary cause.
dgpplain2016-03-10 20:04:06
See proposed fix on branch bug-b9b2079e6d.
dgpplain2016-03-17 12:16:38
Fixed for 8.6.6+
Log in (anonymous is fine) to add a comment.