D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 5533 - Regression(2.051, Linux only): segv: -gc, associative arrays, const pointers to self
Summary: Regression(2.051, Linux only): segv: -gc, associative arrays, const pointers ...
Status: RESOLVED DUPLICATE of issue 7127
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86 Linux
: P2 regression
Assignee: No Owner
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks:
 
Reported: 2011-02-06 12:50 UTC by Russ Lewis
Modified: 2011-12-19 10:08 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Russ Lewis 2011-02-06 12:50:03 UTC
Regression from 2.050 to 2.051 (Linux).

When compiling with -gc -c, the testcase below will cause 2.051 to segv.
File compiles OK on 2.050.
File also compiles just fine (even on 2.051) if -gc is omitted.
DMD produces expected link errors if you compile with only -gc argument.

The key issues appear to be:
  - The foreach loop inside the function.
  - The parent pointer in Foo must be *BOTH* const and a pointer to its own
    type.  If you make it non-const, or a pointer to something else, it works.

TESTCASE:

void DMD_BUG_WORKAROUND()  // issue 3770
{
  /* if you don't have a dummy function like this in the module where a type
   * was declared, then dmd won't give it to you when you use it in an
   * associative array elsewhere, and you'll get link errors.
   */
  Foo    tmp;
  string dummy;

  foreach(name; tmp.table.keys)
    dummy ~= name;
}

struct Foo
{
  const(Foo)       *parent;
  FooElem*[string]  table;
};

struct FooElem
{
};
Comment 1 yebblies 2011-07-03 09:35:02 UTC
This works for me on win32 with dmd head (2.054).
Can anybody reproduce this on linux with the current dmd?
Comment 2 Russ Lewis 2011-07-25 21:45:17 UTC
I tested this on 2.054 (Linux: Fedora 14 x86 32-bit), and the problem still exists.
Comment 3 Russ Lewis 2011-08-26 13:50:27 UTC
I built dmd and ran it under gdb, and it appears that the problem is infinite recursion in the function dwarf_typidx(TYPE*).
Comment 4 David Nadlinger 2011-12-19 10:08:15 UTC

*** This issue has been marked as a duplicate of issue 7127 ***