D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 17759 - struct that attempts to implicitly cast away const causes segfault
Summary: struct that attempts to implicitly cast away const causes segfault
Status: RESOLVED WORKSFORME
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86_64 Mac OS X
: P1 normal
Assignee: No Owner
URL:
Keywords: ice, ice-on-valid-code
Depends on:
Blocks:
 
Reported: 2017-08-17 20:21 UTC by Steven Schveighoffer
Modified: 2020-03-21 03:56 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Steven Schveighoffer 2017-08-17 20:21:02 UTC
Consider the following struct which attempts to legally cast away const:

struct A
{
   int[] a;
   A foo() const { return A.init; }
   alias foo this;
}

The compiler segfaults, all the way back to 2.064. This is the minimum I could do to make it happen. If you change anything, it seems to start compiling.

In LDC, it says "illegal instruction: 4"

If you use -v, I get this output:
predefs   DigitalMars Posix OSX darwin LittleEndian D_Version2 all D_SIMD D_InlineAsm_X86_64 X86_64 D_LP64 D_PIC assert D_HardFloat
binary    dmd
version   v2.075.1
config    /Users/steves/.dvm/compilers/dmd-2.075.1/osx/bin/dmd.conf
parse     testimplicitmutable
importall testimplicitmutable
import    object	(/Users/steves/.dvm/compilers/dmd-2.075.1/osx/bin/../../src/druntime/import/object.d)
import    core.attribute	(/Users/steves/.dvm/compilers/dmd-2.075.1/osx/bin/../../src/druntime/import/core/attribute.d)
semantic  testimplicitmutable
semantic2 testimplicitmutable
semantic3 testimplicitmutable
Segmentation fault: 11
Comment 1 Steven Schveighoffer 2017-08-17 20:21:34 UTC
should say, attempts to legally *implicitly* cast away const.
Comment 2 Citrus 2018-03-18 15:51:44 UTC
This happens because the built-in `opEquals' that's synthesized by the compiler contains a condition such as `(p == q)` that's recursively expanded into `(p.foo == q) and `(p.foo.foo == q)`.
The problem lies in `resolvePropertiesX' that keeps assembling this crazy chain where the `p' is substituted every step.
Comment 3 Steven Schveighoffer 2018-03-18 17:27:04 UTC
Hm... so alias this resolution needs some kind of memoization to prevent infinite expansion. Interesting.
Comment 4 basile-z 2019-07-16 20:32:23 UTC
fixed since 2.086