Bug 17759 – struct that attempts to implicitly cast away const causes segfault
Status
RESOLVED
Resolution
WORKSFORME
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Mac OS X
Creation time
2017-08-17T20:21:02Z
Last change time
2020-03-21T03:56:36Z
Keywords
ice, ice-on-valid-code
Assigned to
No Owner
Creator
Steven Schveighoffer
Comments
Comment #0 by schveiguy — 2017-08-17T20:21:02Z
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 by schveiguy — 2017-08-17T20:21:34Z
should say, attempts to legally *implicitly* cast away const.
Comment #2 by bitter.taste — 2018-03-18T15:51:44Z
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 by schveiguy — 2018-03-18T17:27:04Z
Hm... so alias this resolution needs some kind of memoization to prevent infinite expansion. Interesting.