D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 6047 - Segfault when struct with three or more ulongs with a toString is passed to format with at least two substitution clauses with -m64.
Summary: Segfault when struct with three or more ulongs with a toString is passed to f...
Status: RESOLVED WORKSFORME
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86_64 Linux
: P2 critical
Assignee: No Owner
URL:
Keywords: wrong-code
Depends on: 6983
Blocks:
  Show dependency treegraph
 
Reported: 2011-05-23 05:01 UTC by Bernard Helyer
Modified: 2012-04-28 01:42 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 Bernard Helyer 2011-05-23 05:01:35 UTC
import std.string;

struct A { ulong a, b, c; string toString() { return ""; } }

void main()
{
    A a;
    format("%s%s", a, "");
}



There has to be at least 24 bytes (or so) of declarations, so at least three ulongs. The toString has to be there. That second parameter to format has to be there.

Somewhere, there is stack corruption happening. This is preventing SDC's 64 bit build from working correctly (it crashes when it errors, as the Location struct is passed to format, manifesting this when its size_t decls are 64 bits wide).

This could be from DMD or Phobos. I'm not sure.
Comment 1 Bernard Helyer 2011-05-23 05:05:16 UTC
I didn't mention my specs. Linux (64 or 32 bit build and output), 2.053 (but it's been there for months, _at least_, to my knowledge), Phenom II X4, Arch Linux.
Comment 2 kennytm 2011-05-23 05:57:50 UTC
(No-repro on Mac OS X.)
Comment 3 Bernard Helyer 2011-05-23 06:31:32 UTC
I was mistaken -- it's only when building a 64 bit binary.
Comment 4 Nick Sabalausky 2011-11-19 20:59:15 UTC
Raising priority because this is a rather nasty bug to come up against.
Comment 5 Nick Sabalausky 2011-11-21 07:44:59 UTC
The format string can be blank and this bug will still be triggered. So a slight reduction is:

import std.string;

struct A { ulong a, b, c; string toString() { return ""; } }

void main()
{
    A a;
    format("", a, "");
}
Comment 6 Nick Sabalausky 2011-11-21 07:59:44 UTC
Issue 6576 may be related to this.
Comment 7 Nick Sabalausky 2011-11-21 08:46:34 UTC
I think the root cause of this might be issue 6983.
Comment 8 Walter Bright 2012-04-28 01:42:08 UTC
I tried this for -m32 and -m64 on Linux, and the program completes without error on dmd 2.060 latest build.