Bug 21957 – ice when dmd computes the alignment of an union containing a noreturn

Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2021-05-23T03:41:43Z
Last change time
2021-10-13T13:17:28Z
Keywords
ice, pull
Assigned to
No Owner
Creator
Basile-z

Comments

Comment #0 by b2.temp — 2021-05-23T03:41:43Z
this code causes problem when dmd tries to compute align/side of a type union: --- alias noreturn = typeof(*null); union U { noreturn a; } int main() { return 0; } --- output: ERROR: This is a compiler bug. Please report it via https://issues.dlang.org/enter_bug.cgi with, preferably, a reduced, reproducible example and the information below. DustMite (https://github.com/CyberShadow/DustMite/wiki) can help with the reduction. --- DMD v2.097.0-beta.1-42-g9d718f2f8 predefs single_module runnable_module run_single_module DigitalMars LittleEndian D_Version2 all D_SIMD Posix ELFv1 linux CRuntime_Glibc CppRuntime_Gcc D_InlineAsm_X86_64 X86_64 D_LP64 D_PIC assert D_ModuleInfo D_Exceptions D_TypeInfo D_HardFloat binary /home/basile/dev/repos/dlang/dmd/generated/linux/release/64/dmd version v2.097.0-beta.1-42-g9d718f2f8 config /home/basile/dev/repos/dlang/dmd/generated/linux/release/64/dmd.conf DFLAGS -I/home/basile/dev/repos/dlang/dmd/generated/linux/release/64/../../../../../druntime/import -I/home/basile/dev/repos/dlang/dmd/generated/linux/release/64/../../../../../phobos -L-L/home/basile/dev/repos/dlang/dmd/generated/linux/release/64/../../../../../phobos/generated/linux/release/64 -L--export-dynamic -fPIC --- core.exception.AssertError@src/dmd/aggregate.d(599): Assertion failure ---------------- ??:? _d_assertp [0x8e5b55] src/dmd/aggregate.d:599 pure nothrow @safe void dmd.aggregate.AggregateDeclaration.alignmember(uint, uint, uint*) [0x5d5e5d] src/dmd/aggregate.d:638 uint dmd.aggregate.AggregateDeclaration.placeField(uint*, uint, uint, uint, uint*, uint*, bool) [0x5d5f82] src/dmd/declaration.d:1235 _ZN14VarDeclaration14setFieldOffsetEP20AggregateDeclarationPjb [0x6180e2] src/dmd/dstruct.d:352 _ZN17StructDeclaration12finalizeSizeEv [0x6531d7] src/dmd/aggregate.d:310 _ZN20AggregateDeclaration13determineSizeE3Loc [0x5d53b1] src/dmd/semantic2.d:611 _ZN16Semantic2Visitor5visitEP20AggregateDeclaration [0x76a61d] src/dmd/parsetimevisitor.d:88 _ZN16ParseTimeVisitorI10ASTCodegenE5visitEP17StructDeclaration [0x766485] src/dmd/parsetimevisitor.d:89 _ZN16ParseTimeVisitorI10ASTCodegenE5visitEP16UnionDeclaration [0x7664a9] src/dmd/dstruct.d:778 _ZN16UnionDeclaration6acceptEP7Visitor [0x654085] src/dmd/semantic2.d:78 _Z9semantic2P7DsymbolP5Scope [0x76918d] src/dmd/semantic2.d:339 _ZN16Semantic2Visitor5visitEP6Module [0x769c81] src/dmd/dmodule.d:1548 _ZN6Module6acceptEP7Visitor [0x63bab9] src/dmd/semantic2.d:78 _Z9semantic2P7DsymbolP5Scope [0x76918d] src/dmd/mars.d:495 int dmd.mars.tryMain(ulong, const(char)**, ref dmd.globals.Param) [0x5c782c] src/dmd/mars.d:1070 _Dmain [0x5c9869]
Comment #1 by moonlightsentinel — 2021-05-24T16:20:47Z
The DIP allows noreturn members for structs/unions
Comment #2 by dlang-bot — 2021-10-08T23:56:06Z
@MoonlightSentinel created dlang/dmd pull request #13142 "Fix 21957 - Don't crash when aligning noreturn members " fixing this issue: - Fix 21957 - Don't crash when aligning noreturn members `alignmember` assumes that every type with default alignment has a size greater than zero - which obviously does not apply for `noreturn`. A `noreturn` field with default alignment does not affect the layout of the aggregate because `noreturn.sizeof = noreturn.alignof = 0`. Hence skip the `alignmember` call unless a custom alignment was requested. https://github.com/dlang/dmd/pull/13142
Comment #3 by dlang-bot — 2021-10-11T07:53:22Z
dlang/dmd pull request #13142 "Fix 21957 - Don't crash when aligning noreturn members " was merged into stable: - 3377fa7d85edb97311265f0713b00113cdfd6534 by MoonlightSentinel: Fix 21957 - Don't crash when aligning noreturn members `alignmember` assumes that every type with default alignment has a size greater than zero - which obviously does not apply for `noreturn`. A `noreturn` field with default alignment does not affect the layout of the aggregate because `noreturn.sizeof = noreturn.alignof = 0`. Hence skip the `alignmember` call unless a custom alignment was requested. https://github.com/dlang/dmd/pull/13142
Comment #4 by dlang-bot — 2021-10-13T13:17:28Z
dlang/dmd pull request #13164 "Merge stable" was merged into master: - cde0e07730b7731b35408ded867ec7496bb826e2 by MoonlightSentinel: Fix 21957 - Don't crash when aligning noreturn members `alignmember` assumes that every type with default alignment has a size greater than zero - which obviously does not apply for `noreturn`. A `noreturn` field with default alignment does not affect the layout of the aggregate because `noreturn.sizeof = noreturn.alignof = 0`. Hence skip the `alignmember` call unless a custom alignment was requested. https://github.com/dlang/dmd/pull/13164