www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - 'scope' finds stack corruption bug in druntime

reply Walter Bright <newshound2 digitalmars.com> writes:
https://github.com/dlang/druntime/pull/1799

In complex code, it is impractical to check for this stuff manually. I'm happy 
that 'scope' is proving its worth.
Apr 04 2017
parent reply Steven Schveighoffer <schveiguy yahoo.com> writes:
On Tuesday, 4 April 2017 at 08:32:33 UTC, Walter Bright wrote:
 https://github.com/dlang/druntime/pull/1799

 In complex code, it is impractical to check for this stuff 
 manually. I'm happy that 'scope' is proving its worth.
Not a bug. Exception is allocated in the outer function and is always caught in the outer function. How can it escape? -Steve
Apr 04 2017
parent reply Walter Bright <newshound2 digitalmars.com> writes:
On 4/4/2017 2:22 AM, Steven Schveighoffer wrote:
 On Tuesday, 4 April 2017 at 08:32:33 UTC, Walter Bright wrote:
 https://github.com/dlang/druntime/pull/1799

 In complex code, it is impractical to check for this stuff manually. I'm happy
 that 'scope' is proving its worth.
Not a bug. Exception is allocated in the outer function and is always caught in the outer function. How can it escape?
You are correct, it is a false positive. I updated the PR with another method, as doing the flow analysis to detect the false positive isn't simple.
Apr 04 2017
parent Steven Schveighoffer <schveiguy yahoo.com> writes:
On 4/4/17 6:19 AM, Walter Bright wrote:
 On 4/4/2017 2:22 AM, Steven Schveighoffer wrote:
 On Tuesday, 4 April 2017 at 08:32:33 UTC, Walter Bright wrote:
 https://github.com/dlang/druntime/pull/1799

 In complex code, it is impractical to check for this stuff manually.
 I'm happy
 that 'scope' is proving its worth.
Not a bug. Exception is allocated in the outer function and is always caught in the outer function. How can it escape?
You are correct, it is a false positive. I updated the PR with another method, as doing the flow analysis to detect the false positive isn't simple.
One thing to keep in mind, I'm probably not the only one to consider a pre-allocated scope exception for flow control on a very recursive algorithm using inner functions. If the scope changes are catching a false positive here, they will catch one in others' code as well. Especially people who want to write nogc code. The updates you have implemented are IMO much more complex than an "escape hatch" throwing of an exception to unwind the stack. Not horrific, but definitely more error prone and less intuitive. -Steve
Apr 04 2017