Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug when using noreturn variants in enums #3255

Closed
vi opened this issue Sep 19, 2019 · 3 comments
Closed

Bug when using noreturn variants in enums #3255

vi opened this issue Sep 19, 2019 · 3 comments
Labels
bug Observed behavior contradicts documented or intended behavior stage1 The process of building from source via WebAssembly and the C backend.
Milestone

Comments

@vi
Copy link

vi commented Sep 19, 2019

const assert = @import("std").debug.assert;
const warn = @import("std").debug.warn;

const Q = union(enum) {
    R: noreturn,
};

fn z() u32 {
    var q = Q{ .R=undefined };
    switch(q) {
        .R => |item| return item,
    }
}

test "bug" {
    assert(z() == 4);
}

Crash in --release-fast mode is expected, but it also works weid in safe mode:

$ /opt/zig/zig test test.zig
unreachable: /deps/zig/src/ir.cpp:ir_analyze_instruction_decl_var:14543��t� ����	����t���t���t�`�t��AAa�������� �t�
                                                                                                                          ��t�aA��t�A���t�����@�t� ��t��@�t��AAa���������t�
                      a!��t��v�!���t������t�!��t���t��AA���t������t�"��t�
                                                                         �t��AA���t������t�#��t���t�@�t��AA���t�������t�$��t���t�@�t��AA���t��t���}%�� �t��t���}&����t������t�'��t�X�t��AA���t������t�(��t�a@�t��AA`�t���t���t��t��t��t��t�@�t�@�t�@�t����t�����@
                                                                                                            ��`�t�)��t�@�t��t���t�@�t�����t��t���}*����t�������t�+�t���AAa��t� �t�a���t�����@
                                        ����t�,�t� �t�@�t��AA���t�����@
                                                                       ���t�-��t� �t�@�t��AAa �t��v�a���t�����@
                                                                                                               ��@�t�. �t��t��AAa��t��v�aa �t��v�aa��t��v�a�~t�``����t�/u��dt�m�t��t��AA�~t�``��@
                                            ����t�0X4���dt��t��t���t�@�t���t��AA�~t�``��@
                                                                                         ����t�1�t��AAa�t��v�a�~t�``�� �t�2��t�	�t�@�t�@�t��AAa@�t���t���t� �t���t���t���t���t�a�~t�``����t�3��t��@�t��|t��AA�lt�``����t�4��t�n@�t��AAa��t�8v�a�U��a���	���t�5��t��AAa �t��u�a�lt�a���	��@�t�6��t��AA�U��a��@�t�7��t����t��et��AA�lt�a��@�t�8��t����t��AA�lt�a��@
                                                             ��@�t�9��t���t��AA���������xR����t����� S����t�`�t�(�������dt��AA�`�t�x�t��a��t��t�a���t�dt�U��V������������U��a���	�� �t���t��AA� gt������	�� �t���t��AA��ht�����`���@jt���t��AA��ht������	�� �t���t��AA��nt������	�� �t���t��AA���t�~������ �t��U���t��`�t@�t��U��V���a �t�Pv�aA��t����A��U������ �t���t� �t�� �t��AAa`�t�`�t�`�t�`�t�`�t�aA��tAA@�tA!Q��u�!��t������t�`�t���t���t� ������������U���t��T��`�t���t����!Q�(t�!a��t������T���U��`�t�`�t�aa��t��s�a��U��������� �t�`�t���t� �t��AA��U������ �t���t� �t��`�t� �t��AA��U������ �t�@�t� �t��`�t��AA��U������@
                     �� �t�@�t� �t�`�t��AA���t�~����������`�t��U������������`�t� �t�����`�t�@�t���t�!�v��v�!!�v��v�!�@�t �t��U��V�������������U�������	����t�@�t��AA��U��������� �t�`�t�@�t��AA��U�������	����t�@�t��AAa��t�hv�a��U�������	���t�@�t��AA��U������@
                                                                                                                              ���t�@�t���t��AAa@�t� v�aa@�t� v�a���t���t����������������U���U�����������!Q�xu�!�@pt�����������t���t���t��t��AAa��t����t��t��
                                                                                                       u�a�@pt�������� �t�`�t���t��AA�@pt������	�����t��AAAAa`�t�@�t�a��ht����� ����t���t�	��t��`����AAA����@
                                                          ����t� �t��������AA��t����AAA!����v�!��t!u0��v�!��t�
                                                                                                              ���� �t���t�`�t����A@TagType(Q)�!
                                                                                                                                               �v��v�AA�������A!*Q�8s�!!@
                    ��`���!A������t�A�@�t@�����t�`�t�����t��t�`�t�V���a��t��v�a�`�t�@���`�t���t���t�� �t��AAa��t��t��t��t��t�a�`�t�@��������t�@
                                                                                                                                               ����t���t��AA�`�t�@�����t���t���t���t� �t��AA�`�t�@�����t���t���t���t��AA�`�t�@���@
                                                                             ����t���t���t��t��AA�@�tX�`�@�����t�`�t�������������t���t������t���t������t�!t�t�!!�s��s�!���t��t�`�t�V������������`�t�@����	��@�t���t��AA�`�t�@��������t�@
                                                                                      ����t��AA�`�t�@����	��@�t���t��AAa��t��v�a�`�t�@����	����t���t��AA�`�t�@���@
                      ����t���t���t��AAa��t��v�aa��t��v�a!
                                                          ��������������h�������h���ء��x���8������� ���`������� ���H���@�������(������� ��������X�������������������H���x���0���`���Ȧ�����P�������������x���X���������������������P���8���@������� ������ ���Ȭ������������������������ ����������@��������������У����������X������������� ���`�������(���@���`�������H�������������x���x���0����������������Ы����0���`���(�������"(      h�f��t�8
(�9
   �7�i:E�����fC��(
�HHo?I�PP���Q��RV�<c�,�g�g�~�j6#m�o���*�qJ`0t�+8v��wQԅyl'�ze ��fC����������"����T7��D�����������#�G�xg�^\����D����<������8����ȑƠʏƠ�������ҚBْ=��F�XA��{�`�眡��h�������	������Y��cz��@!
                               AA� wt�`���`���@xt�
                                                  ��t��AA� wt�`���@
��t��AA� wt�`����       ����t���t��AA� wt�`���� ����t���t��AA��nt�����`�t���t���t��AA��nt������	����t���t��AAAAa`�t��t�a��ht�����`�t�`�t���t��AA��ht������	��`�t���t��AAa�jt�8v�a��ht������	����t���t��jt���t��AA�lt�``���	����t���t��AA�~t������	����t���t��AA��t����� ����t���t��jt��AA�~t�``����t���t���t��AA�~t�``��`����u���t��AA�~t�``��`����u����t��AA�~t�``���	���u��t��AA��t�@����	���u���t��AA���t�@��� �����t�������t��AA���t�@����	���u���t��AAAs�@���A!��t� ���!���t�@�����t� u���t��AA!��t� ���!���t�@�����t�u� ��t��AAa�r|s�@���Aborted

I expect correct behaviour to be the same as if function returned undefined directly, without going though enum.

Maybe Q{ .R=undefined } should be compile-time error (not sure).

@andrewrk andrewrk added this to the 0.6.0 milestone Sep 20, 2019
@andrewrk andrewrk added bug Observed behavior contradicts documented or intended behavior stage1 The process of building from source via WebAssembly and the C backend. labels Sep 20, 2019
@andrewrk andrewrk modified the milestones: 0.6.0, 0.7.0 Feb 13, 2020
@andrewrk andrewrk modified the milestones: 0.7.0, 0.8.0 Aug 13, 2020
@andrewrk andrewrk modified the milestones: 0.8.0, 0.9.0 Nov 6, 2020
@andrewrk andrewrk modified the milestones: 0.9.0, 0.10.0 May 19, 2021
@nektro
Copy link
Contributor

nektro commented Oct 12, 2021

trying this with today with 0.9.0-dev.1343+75cecef63 infinite loops.

i think something of note i discovered while looking at this is if you do @compileLog(@sizeOf(noreturn)); you get a compile error error: no size available for type 'noreturn'

@nektro
Copy link
Contributor

nektro commented Oct 12, 2021

my first thought is perhaps the issue is in undefined trying fill an unknown number of bytes with 0xaa and getting stuck

@Vexu
Copy link
Member

Vexu commented Dec 28, 2022

Fixed by c3d5428

@Vexu Vexu closed this as completed Dec 28, 2022
@andrewrk andrewrk modified the milestones: 0.12.0, 0.11.0 Dec 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior stage1 The process of building from source via WebAssembly and the C backend.
Projects
None yet
Development

No branches or pull requests

4 participants