www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 6308] New: Destruction of temporaries on exception causes segfault

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6308

           Summary: Destruction of temporaries on exception causes
                    segfault
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Keywords: wrong-code
          Severity: major
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: thecybershadow gmail.com



17:52:12 PDT ---
My reply about this issue on dmd-beta is pending moderation, but a bug about
this should probably be filed anyway.

import std.stdio;

void main()
{
    foreach (i; 0..100)
        foreach (line; File("test.d").byLine)
            {}
}

On Windows, when the above program is compiled with DMD from current git and
ran, it crashes with an unhandled exception (Windows displays two standard "has
stopped working" dialogs in succession).

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 13 2011
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6308


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla digitalmars.com



10:27:29 PDT ---
More by Vladimir:

I did a bit of research on this a few days ago. Using a certain debugger
and the map file, I found that the crash occurred in the autogenerated
scope(exit) for getDependencies - the block of code that calls the File
destructor. I didn't look too closely, but it looked like a bad "this"
pointer is passed to the File dtor. I tried a full DMD/Phobos regression
test, but didn't really get anywhere.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 15 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6308




21:48:28 PDT ---
Minimized testcase:

struct C
{
    this(int)
    {
        throw new Exception("Oops!");
    }

    ~this()
    {
    }

    int bar() { return 1; }
}

void foo(int) {}

void main()
{
    foo(C(1).bar());
}

The key finding is that the exception is thrown in the constructor.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 15 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6308


Vladimir Panteleev <thecybershadow gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrej.mitrovich gmail.com



16:29:13 PDT ---
*** Issue 6329 has been marked as a duplicate of this issue. ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 21 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6308




16:32:01 PDT ---
Issue 6329 is an example where the the exception isn't thrown in the
constructor, but in the body of a delegate (dirEntries uses opApply). I'll try
to minimize it.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 21 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6308




23:26:22 PDT ---

 I'll try to minimize it.
Reduced it to a small variation of the above. struct C { void oops() { throw new Exception("Oops!"); } ~this() { } } void main() { C().oops(); } I think DustMite may have taken some shortcuts while reducing Andrej's test case, though - but this test case definitely does show that it's not about throwing in a constructor. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jul 25 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6308


Vladimir Panteleev <thecybershadow gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|Destruction of temporaries  |Destruction of temporaries
                   |on exception causes         |on exception causes
                   |segfault                    |unhandled access violation



23:28:29 PDT ---
By the way, I should probably clearly mention that this is Windows-only.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 25 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6308


Rainer Schuetze <r.sagitario gmx.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |r.sagitario gmx.de



PDT ---
I had a quick look at the disassembly generated for the code in comment 5, and
it turns out that the frame handler pointer is zero, instead of identical code
"C c; c.oops();" that generates something like

mov         edx,dword ptr fs:[0] 
push        offset __Dmain+77h // this is 0 for "C().oops();"
push        edx  
mov         dword ptr fs:[0],esp

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 13 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6308




PDT ---
dmd 2.053 does not crash, but also does not create any exception handling code
at all, while dmd 2.054+ seems to generate setup code for the exception frame,
but no exception code.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 13 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6308


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED



02:13:43 PDT ---
https://github.com/D-Programming-Language/dmd/commit/c616b691793bbc710c88fc23a68c4731b6574529

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 14 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6308


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |soywiz gmail.com



*** Issue 6363 has been marked as a duplicate of this issue. ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 25 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6308




09:25:16 PDT ---
This code:

import std.file;
void main()
{
    string[] dirs;
    foreach (string dir; dirEntries(r"C:\", SpanMode.shallow))
    {
        if (dir.isDir)
            dirs ~= dir;
    }
}


Compiled via DMD 2.055 commit cfab198ee186f6e69c364aaf4206434220d83204 (Aug
15), enters an infinite loop at runtime where exceptions are kept throwing:

=== Bypassed ===
std.file.FileException std\file.d(1156): C:\pagefile.sys: The process cannot
access the file because it is being used by
another process.
----------------
42A540
42A3B7
402A7D
40206D
402950
40298F
40258B
45B855
45B7AC
----------------
object.Error: Access Violation
----------------
42A540
42A3B7
402950
40298F
40258B
45B855
45B7AC
----------------
Bypasses std.file.FileException std\file.d(1156)
object.Error: Access Violation
----------------
42A540
42A3B7
402950
40298F
40258B
45B855
45B7AC
----------------
object.Error: Access Violation
----------------
42A540
42A3B7
402950
40298F
40258B
45B855
45B7AC

It seems after it tries to open the protected pagefile.sys it keeps rethrowing
exceptions and not exiting the foreach loop. It doesn't stop at all, just keeps
rethrowing.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 26 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6308




03:22:49 PDT ---

 It seems after it tries to open the protected pagefile.sys it keeps rethrowing
 exceptions and not exiting the foreach loop. It doesn't stop at all, just keeps
 rethrowing.
I can't reproduce this, it throws a single exception for me. Was this fixed in the meantime? The fact that you can't list C:\ because Phobos can't read a file's attributes is worth a separate bug report, though. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Sep 08 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6308




07:48:16 PDT ---


 It seems after it tries to open the protected pagefile.sys it keeps rethrowing
 exceptions and not exiting the foreach loop. It doesn't stop at all, just keeps
 rethrowing.
I can't reproduce this, it throws a single exception for me. Was this fixed in the meantime?
The final 2.055 release still has this issue, just checked. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Sep 08 2011
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6308




09:16:03 PDT ---



 It seems after it tries to open the protected pagefile.sys it keeps rethrowing
 exceptions and not exiting the foreach loop. It doesn't stop at all, just keeps
 rethrowing.
I can't reproduce this, it throws a single exception for me. Was this fixed in the meantime?
The final 2.055 release still has this issue, just checked.
Note that my bug6329 which was labeled as duplicate of this has a similar issue. First I get a range violation, then `object.Error: Access Violation` is printed many times before the app exits. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Sep 08 2011