D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 7234 - Segmentation fault when using stdio
Summary: Segmentation fault when using stdio
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: Other All
: P2 normal
Assignee: No Owner
URL:
Keywords: ice-on-invalid-code, ice-on-valid-code
Depends on:
Blocks:
 
Reported: 2012-01-05 11:46 UTC by Robert Clipsham
Modified: 2012-01-28 23:22 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Robert Clipsham 2012-01-05 11:46:11 UTC
The following test case is invalid code, but it is reproducible using valid code (DustMite caused some issues here while narrowing down phobos). It segfaults with dmd 2.057 on both Ubuntu 32 and OS X 64. I've included a comment for how to get a valid code test case, it depends on phobos though!
----
template isInputRange(R) {
    enum bool isInputRange = is(typeof({ R r; if (r.empty) {} }));
}

void formattedWrite(Writer, Char, A...)(Writer w, in Char, A args) {
    foreach (i, arg; args)
        i= &formatGeneric!(Writer, typeof(arg), Char);
}

struct FormatSpec(Char) {}

void formatValue(Writer, T, Char)(Writer w, T val, ref FormatSpec!Char f) if (!isInputRange!T) {
}

private void formatGeneric(Writer, D, Char)(Writer w, const(void)* arg, ref FormatSpec!Char f) {
    formatValue(w, *cast(D*) arg, f);
}
struct File {
    void writefln(S...)(S args) {
        auto w = LockingTextWriter();
        formattedWrite(w, args);
    }

    struct LockingTextWriter {}
}

File stdout;

// You can replace the above with import std.stdio; and
// give the opDispatch below a valid signature to gain a
// valid code test case, it's rather large though!
struct Contract {
    void opDispatch()(){}
}
Contract*mOptional;
void populate()
{
    stdout.writefln("opt   : %s", mOptional);
}
----
Comment 1 Don 2012-01-26 00:15:08 UTC
This seems to be the same as bug 7231.
It reduces to:

struct Bug7324 {
  void opDispatch()(){}
}

void func7234()
{
   Bug7234 r;
   if (r.xxx) {};
}
Comment 2 Walter Bright 2012-01-28 20:48:41 UTC
(In reply to comment #1)
> It reduces to:

That doesn't seg fault, but the original does.
Comment 3 github-bugzilla 2012-01-28 23:22:31 UTC
Commit pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/9926cfdf09c9ecf28a102183562996dea6217051
fix Issue 7234 - Segmentation fault when using stdio