Thread overview
[Issue 7750] New: while(true) loop with try/catch block causes segfault
Mar 22, 2012
Brian Palmer
Mar 28, 2012
Don
Apr 11, 2012
Don
Apr 25, 2012
Walter Bright
March 22, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7750

           Summary: while(true) loop with try/catch block causes segfault
           Product: D
           Version: D2
          Platform: All
        OS/Version: Mac OS X
            Status: NEW
          Severity: critical
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: brian+d@codekitchen.net


--- Comment #0 from Brian Palmer <brian+d@codekitchen.net> 2012-03-21 21:56:22 PDT ---
I ran into a segfault when using a try/catch block inside a while(true) loop when there are other statements after the try/catch block. I reduced it down to this consistent segfault:

import std.stdio;

void main() {
  while (true) {
    try {
      throw new Exception("ah");
    } catch (Exception e) {
    }
    writeln("remove this line and it won't segfault");
  }
}

This segfaults in the first iteration on DMD 2.058 on OS X 10.7.3. It segfaults with both -m32 and -m64. Stacktrace:

0   libdyld.dylib                     0x00007fff8f3436cd
misaligned_stack_error_entering_dyld_stub_binder + 0
1   ???                               0x000000010f535030 0 + 4552085552
2   bug1.d.DC445724916B27653F5E50703AE848DF    0x000000010f51f133 _Dmain + 103
3   bug1.d.DC445724916B27653F5E50703AE848DF    0x000000010f52f8dd
D2rt6dmain24mainUiPPaZi7runMainMFZv + 29
4   bug1.d.DC445724916B27653F5E50703AE848DF    0x000000010f52f28d
D2rt6dmain24mainUiPPaZi7tryExecMFMDFZvZv + 45
5   bug1.d.DC445724916B27653F5E50703AE848DF    0x000000010f52f92f
D2rt6dmain24mainUiPPaZi6runAllMFZv + 63
6   bug1.d.DC445724916B27653F5E50703AE848DF    0x000000010f52f28d
D2rt6dmain24mainUiPPaZi7tryExecMFMDFZvZv + 45
7   bug1.d.DC445724916B27653F5E50703AE848DF    0x000000010f52f210 main + 232
8   bug1.d.DC445724916B27653F5E50703AE848DF    0x000000010f51f0c4 start + 52


Removing the writeln, or changing it to a non-infinite loop like int x;while(++x<3) will avoid the segfault, so it seems likely DMD is making a bad assumption about the loop related to it being infinite.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
March 28, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7750


hsteoh@quickfur.ath.cx changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |hsteoh@quickfur.ath.cx


--- Comment #1 from hsteoh@quickfur.ath.cx 2012-03-27 21:09:58 PDT ---
I can't seem to reproduce this problem with the latest git dmd (2.059 candidate) on Linux AMD64. Could it be a Mac-specific problem?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
March 28, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7750


Don <clugdbug@yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |clugdbug@yahoo.com.au


--- Comment #2 from Don <clugdbug@yahoo.com.au> 2012-03-27 23:33:22 PDT ---
(In reply to comment #1)
> I can't seem to reproduce this problem with the latest git dmd (2.059 candidate) on Linux AMD64. Could it be a Mac-specific problem?

Looks like it, based on the first location in the backtrace: misaligned_stack_error_entering_dyld_stub_binder

The stack isn't getting aligned properly before the call to writeln.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
April 11, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7750



--- Comment #3 from Don <clugdbug@yahoo.com.au> 2012-04-11 00:59:23 PDT ---
Probably related to bug 1115.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
April 25, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7750



--- Comment #4 from github-bugzilla@puremagic.com 2012-04-24 18:56:32 PDT ---
Commit pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/1fba8be9f381c01315d01d74b52ce616c5afc745 fix Issue 7750 - while(true) loop with try/catch block causes segfault

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
April 25, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7750



--- Comment #5 from github-bugzilla@puremagic.com 2012-04-24 18:56:46 PDT ---
Commit pushed to dmd-1.x at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/99c11c44985493a1e9974bad8510cf377cd208a5 fix Issue 7750 - while(true) loop with try/catch block causes segfault

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
April 25, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7750


Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla@digitalmars.com
         Resolution|                            |FIXED


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------