[Issue 20934] New: preview=dtorfields segfaults for struct template with disabled default constructor

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Jun 15 16:44:33 UTC 2020


https://issues.dlang.org/show_bug.cgi?id=20934

          Issue ID: 20934
           Summary: preview=dtorfields segfaults for struct template with
                    disabled default constructor
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: moonlightsentinel at disroot.org

This code segfaults when compiled with -preview=dtorfields:

=========================
struct Array
{
    ~this() {}
}

struct CyclicArray()
{
    Array array;
    @disable this();
}

auto heapArray = CyclicArray!()();
=========================

dmd -c -o- cyclic_array.d
cyclic_array.d(12): Error: constructor
cyclic_array.CyclicArray!().CyclicArray.this cannot be used because it is
annotated with @disable
cyclic_array.d(12): Error: this cannot be interpreted at compile time, because
it has no available source code

dmd -c -o- preview=dtorfields cyclic_array.d
Segmentation fault (core dumped)




Running in gdb shows that it tries to do semantic analysis on the missing body
of CyclicArrays disabled dtor:

gdb generated/linux/debug/64/dmd -batch -ex "run -c -o- -preview=dtorfields
cyclic_array.d" -ex "bt" &> gdb.log

[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".

Program received signal SIGSEGV, Segmentation fault.
0x0000000008182b6c in Statement::isCompoundStatement() (this=0x0) at
src/dmd/statement.d:424
424         inout(CompoundStatement)    isCompoundStatement()    { return stmt
== STMT.Compound    ? cast(typeof(return))this : null; }

#0  0x0000000008182b6c in Statement::isCompoundStatement() (this=0x0) at
src/dmd/statement.d:424
#1  0x00000000081c0b29 in
_D3dmd12statementsem15semanticNoScopeFCQBl9statement9StatementPSQCk6dscope5ScopeZQBr
(s=0x0, sc=0x7ffffddea4b0) at src/dmd/statementsem.d:4318
#2  0x00000000081c0397 in
_D3dmd12statementsem13semanticScopeFCQBj9statement9StatementPSQCi6dscope5ScopeQBqQBtZQBx
(s=0x0, sc=0x7ffffdde98b0, sbreak=0x0, scontinue=0x0) at
src/dmd/statementsem.d:4336
#3  0x00000000081daa78 in StatementSemanticVisitor::visit(TryCatchStatement*)
(this=0x7ffffffe90d0, tcs=0x7ffffdde9ef0) at src/dmd/statementsem.d:3826
#4  0x00000000081ec243 in TryCatchStatement::accept(Visitor*)
(this=0x7ffffdde9ef0, v=0x7ffffffe90d0) at src/dmd/statement.d:1980
#5  0x0000000008131bf3 in statementSemantic(Statement*, Scope*)
(s=0x7ffffdde9ef0, sc=0x7ffffdde98b0) at src/dmd/statementsem.d:127
#6  0x00000000081f0fae in Semantic3Visitor::visit(FuncDeclaration*)
(this=0x7ffffffea368, funcdecl=0x7ffffdde7750) at src/dmd/semantic3.d:577
#7  0x00000000081faeee in Semantic3Visitor::visit(CtorDeclaration*)
(this=0x7ffffffea368, ctor=0x7ffffdde7750) at src/dmd/semantic3.d:1407
#8  0x00000000082a3563 in CtorDeclaration::accept(Visitor*)
(this=0x7ffffdde7750, v=0x7ffffffea368) at src/dmd/func.d:3545
#9  0x000000000819131b in semantic3(Dsymbol*, Scope*) (dsym=0x7ffffdde7750,
sc=0x7ffffdde80d0) at src/dmd/semantic3.d:81
#10 0x0000000008286706 in FuncDeclaration::functionSemantic3()
(this=0x7ffffdde7750) at src/dmd/func.d:455
#11 0x000000000816cd46 in FuncDeclaration::functionSemantic()
(this=0x7ffffdde7750) at src/dmd/func.d:429
#12 0x00000000082cdde2 in ExpressionSemanticVisitor::visit(DotVarExp*)
(this=0x7ffffffea6a0, exp=0x7ffffdde9b00) at src/dmd/expressionsem.d:6212
#13 0x00000000082f5ce3 in DotVarExp::accept(Visitor*) (this=0x7ffffdde9b00,
v=0x7ffffffea6a0) at src/dmd/expression.d:4713
#14 0x00000000081313d3 in expressionSemantic(Expression*, Scope*)
(e=0x7ffffdde9b00, sc=0x7fffff6b7d40) at src/dmd/expressionsem.d:11391
#15 0x00000000082c5a21 in
_D3dmd13expressionsem11unaSemanticFCQBi10expression6UnaExpPSQCg6dscope5ScopeZCQCyQBq10Expression
(e=0x7ffffdde9b50, sc=0x7fffff6b7d40) at src/dmd/expressionsem.d:11337
#16 0x00000000082c0699 in ExpressionSemanticVisitor::visit(CallExp*)
(this=0x7ffffffeb760, exp=0x7ffffdde9b50) at src/dmd/expressionsem.d:4311
#17 0x00000000082f5f03 in CallExp::accept(Visitor*) (this=0x7ffffdde9b50,
v=0x7ffffffeb760) at src/dmd/expression.d:4970
#18 0x00000000081313d3 in expressionSemantic(Expression*, Scope*)
(e=0x7ffffdde9b50, sc=0x7fffff6b7d40) at src/dmd/expressionsem.d:11391
#19 0x00000000082c13fe in ExpressionSemanticVisitor::visit(CallExp*)
(this=0x7ffffffec7f0, exp=0x7fffff6b7960) at src/dmd/expressionsem.d:4437
#20 0x00000000082f5f03 in CallExp::accept(Visitor*) (this=0x7fffff6b7960,
v=0x7ffffffec7f0) at src/dmd/expression.d:4970
#21 0x00000000081313d3 in expressionSemantic(Expression*, Scope*)
(e=0x7fffff6b7960, sc=0x7fffff6b7d40) at src/dmd/expressionsem.d:11391
#22 0x000000000828eff1 in
_D3dmd7initsem9inferTypeFCQy4init11InitializerPSQBu6dscope5ScopeZ8visitExpMFCQCxQCa14ExpInitializerZQCx
(init=0x7fffff6b79e0) at src/dmd/initsem.d:644
#23 0x000000000828e82c in
_D3dmd7initsem9inferTypeFCQy4init11InitializerPSQBu6dscope5ScopeZQBo
(init=0x7fffff6b79e0, sc=0x7fffff6b7d40) at src/dmd/initsem.d:702
#24 0x0000000008324dc8 in DsymbolSemanticVisitor::visit(VarDeclaration*)
(this=0x7ffffffed308, dsym=0x7fffff6b7a10) at src/dmd/dsymbolsem.d:822
#25 0x000000000838efe3 in VarDeclaration::accept(Visitor*)
(this=0x7fffff6b7a10, v=0x7ffffffed308) at src/dmd/declaration.d:1646
#26 0x000000000818d68b in dsymbolSemantic(Dsymbol*, Scope*)
(dsym=0x7fffff6b7a10, sc=0x7fffff6b7d40) at src/dmd/dsymbolsem.d:564
#27 0x000000000832cc73 in
_D3dmd10dsymbolsem22DsymbolSemanticVisitor5visitMRCQBx7dmodule6ModuleZ__T9__lambda2TCQDf7dsymbol7DsymbolZQBgMFQBaZv
(s=0x7fffff6b7a10) at src/dmd/dsymbolsem.d:2258
#28 0x000000000812d7d0 in
_D3dmd7dsymbol14foreachDsymbolFPSQBf4root5array__T5ArrayTCQCeQCd7DsymbolZQxMDFQvZvZv
(symbols=0x7fffff6b6570, dg=...) at src/dmd/dsymbol.d:98
#29 0x000000000832cbd4 in DsymbolSemanticVisitor::visit(Module*)
(this=0x7ffffffed438, m=0x7fffff6b5300) at src/dmd/dsymbolsem.d:2255
#30 0x000000000827abb3 in Module::accept(Visitor*) (this=0x7fffff6b5300,
v=0x7ffffffed438) at src/dmd/dmodule.d:1464
#31 0x000000000818d68b in dsymbolSemantic(Dsymbol*, Scope*)
(dsym=0x7fffff6b5300, sc=0x0) at src/dmd/dsymbolsem.d:564
#32 0x0000000008258076 in _D3dmd4mars7tryMainFmPPxaKSQz7globals5ParamZi
(argc=5, argv=0x7ffffffee008, params=...) at src/dmd/mars.d:564
#33 0x00000000082641a2 in D main (_param_0=...) at src/dmd/mars.d:950

--


More information about the Digitalmars-d-bugs mailing list