Bug 14453 – segfault in release mode

Status
RESOLVED
Resolution
WORKSFORME
Severity
major
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-04-17T03:50:41Z
Last change time
2017-10-03T02:49:01Z
Keywords
wrong-code
Assigned to
No Owner
Creator
Ellery Newcomer

Comments

Comment #0 by ellery-newcomer — 2015-04-17T03:50:41Z
the following code segfaults at runtime with dmd 2.067 (apparently 2.066 also) when compiled like so: dmd -release -O multi_index.d but not when compiled like so: dmd multi_index.d multi_index.d: import std.traits; struct Item { uint id; long time; } void main() { alias Container = MultiIndexContainer!(Item); Container c = new Container(); c.index0.insert( Item(21, 35), ); } template OrderedIndex() { alias void* Node; alias const(Item) Elem; auto _add(Node n) { } size_t insert(Stuff)(Stuff ) if (isImplicitlyConvertible!(Stuff, Elem)) { Node n ; _add(n); return 1; } } class MultiIndexContainer(Value) { this(){ } new(size_t sz) { return new void[](sz).ptr; } mixin OrderedIndex!() index0; }
Comment #1 by drug2004 — 2015-04-17T06:26:26Z
dmd 2.066.1 segfaults too, ldc 2.066.1 and merge-2.067 don't segfault
Comment #2 by k.hara.pg — 2015-07-29T08:50:53Z
I also confirmed it in Win32. Reduced test case: void main() { auto c = new C; c.insert(); } class C { this() {} pure nothrow // necessary new(size_t sz) { void[] a = new void[](sz); return a.ptr; } void insert() { } }
Comment #3 by mxfomin — 2015-07-29T09:35:49Z
Isn't new operator depreciated?
Comment #4 by yebblies — 2016-03-25T08:11:21Z
So, the glue layer generates 'ex' which calls the allocator, then calls the ctor on el_same(ex) which decides that since ex has no side effects (being pure and nothrow) it's fine to just duplicate the tree. So we get: C.new(8), C.new(8).__ctor So basically C.new(8) ISN'T pure in a way that matters quite a lot here.
Comment #5 by ellery-newcomer — 2017-10-03T02:49:01Z
this is not reproducible in dmd 2.076