Bug 23781 – [ICE] Segmentation Fault when taking the address of a ref return at CTFE

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2023-03-15T14:18:27Z
Last change time
2023-03-16T01:20:59Z
Keywords
pull
Assigned to
No Owner
Creator
Mathias LANG

Comments

Comment #0 by pro.mathias.lang — 2023-03-15T14:18:27Z
``` struct Bar { int i; } ref const(Bar) func1 (const return ref Bar b) { return b; } immutable E1 = Bar(); enum E2 = &E1.func1(); ``` ``` Program received signal SIGSEGV, Segmentation fault. 0x00005555559ea2e0 in Interpreter::visit(AddrExp*) (this=0x7fffffffced0, e=0x7ffff73366d0) at src/dmd/dinterpret.d:2039 2039 if (ve.var == istate.fd.vthis) (gdb) bt #0 0x00005555559ea2e0 in Interpreter::visit(AddrExp*) (this=0x7fffffffced0, e=0x7ffff73366d0) at src/dmd/dinterpret.d:2039 #1 0x0000555555a6af16 in AddrExp::accept(Visitor*) (this=0x7ffff73366d0, v=0x7fffffffced0) at src/dmd/expression.d:5359 #2 0x00005555559f8705 in _D3dmd10dinterpret9interpretFPSQBd10expression8UnionExpCQCcQz10ExpressionPSQCvQCu10InterStateEQDoQDn8CTFEGoalZQCd ( goal=<incomplete type>, istate=0x0, e=0x7ffff73366d0, pue=0x7fffffffcf30) at src/dmd/dinterpret.d:6552 #3 0x00005555559f875e in _D3dmd10dinterpret9interpretFCQBc10expression10ExpressionPSQCfQCe10InterStateEQCyQCx8CTFEGoalZQCn ( goal=<incomplete type>, istate=0x0, e=0x7ffff73366d0) at src/dmd/dinterpret.d:6562 #4 0x00005555559e49fb in _D3dmd10dinterpret13ctfeInterpretFCQBh10expression10ExpressionZQBd (e=0x7ffff73366d0) at src/dmd/dinterpret.d:101 #5 0x0000555555a61e19 in Expression::ctfeInterpret() (this=0x7ffff73366d0) at src/dmd/expression.d:1683 #6 0x0000555555ac1afe in _D3dmd7initsem19initializerSemanticRCQBj4init11InitializerPSQCg6dscope5ScopeKCQCy5mtype4TypeEQDnQCe13NeedInterpretZ8visitExpMFCQEvQDm14ExpInitializerZQEk (__capture=0x7fffffffd2a0, i=0x7ffff7b06a60) at src/dmd/initsem.d:374 #7 0x0000555555ac38f8 in _D3dmd7initsem19initializerSemanticRCQBj4init11InitializerPSQCg6dscope5ScopeKCQCy5mtype4TypeEQDnQCe13NeedInterpretZ5visit16VisitInitializerMFQEbZQEf (__capture=0x7fffffffd2a0, init=0x7ffff7b06a60) at src/dmd/init.d-mixin-366:372 #8 0x0000555555ac0a7a in initializerSemantic(Initializer*, Scope*, Type*&, NeedInterpret) (init=0x7ffff7b06a60, sc=0x7ffff73312f0, tx=@0x7ffff7b06ae0: 0x7ffff73311f0, needInterpret=<incomplete type>) at src/dmd/initsem.d:962 #9 0x0000555555b156a7 in Semantic2Visitor::visit(VarDeclaration*) (this=0x7fffffffd350, vd=0x7ffff7b06a90) at src/dmd/semantic2.d:276 #10 0x00005555559e0f5a in VarDeclaration::accept(Visitor*) (this=0x7ffff7b06a90, v=0x7fffffffd350) at src/dmd/declaration.d:1724 #11 0x0000555555b14daa in semantic2(Dsymbol*, Scope*) (dsym=0x7ffff7b06a90, sc=0x7ffff73312f0) at src/dmd/semantic2.d:79 #12 0x0000555555b15a67 in Semantic2Visitor::visit(Module*) (this=0x7fffffffd410, mod=0x7ffff7b057a0) at src/dmd/semantic2.d:356 #13 0x0000555555a03bca in Module::accept(Visitor*) (this=0x7ffff7b057a0, v=0x7fffffffd410) at src/dmd/dmodule.d:1261 #14 0x0000555555b14daa in semantic2(Dsymbol*, Scope*) (dsym=0x7ffff7b057a0, sc=0x0) at src/dmd/semantic2.d:79 #15 0x000055555598bf7d in _D3dmd4mars7tryMainFmPPxaKSQz7globals5ParamZi (params=..., argv=0x7fffffffdc98, argc=2) at src/dmd/mars.d:462 #16 0x000055555598dc7d in _Dmain (_param_0=...) at src/dmd/mars.d:962 ``` Build from master as of today (2.102), has been crashing since 2.098 (error before). The underlying problem seems to be the way CTFE handles `CommaExp` rewrites.
Comment #1 by dlang-bot — 2023-03-15T15:59:40Z
@Geod24 created dlang/dmd pull request #14990 "Fix 23781: Segmentation fault on taking the address of a ref return at CTFE" fixing this issue: - Fix 23781: Segmentation fault on taking the address of a ref return at CTFE https://github.com/dlang/dmd/pull/14990
Comment #2 by dlang-bot — 2023-03-15T17:56:01Z
dlang/dmd pull request #14990 "Fix 23781: Segmentation fault on taking the address of a ref return at CTFE" was merged into stable: - 14bbb7d5d0c7495cd971e0ca79c819d936a2523c by Geod24: Fix 23781: Segmentation fault on taking the address of a ref return at CTFE https://github.com/dlang/dmd/pull/14990
Comment #3 by dlang-bot — 2023-03-16T01:20:59Z
dlang/dmd pull request #14992 "merge stable" was merged into master: - 0bb2640b1f7d386fea218bbe228369bdcc1105fd by Geod24: Fix 23781: Segmentation fault on taking the address of a ref return at CTFE https://github.com/dlang/dmd/pull/14992