https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95426

--- Comment #9 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by David Malcolm <dmalc...@gcc.gnu.org>:

https://gcc.gnu.org/g:44564c4c811f4751daf363ca019a9f9bed702f4f

commit r11-839-g44564c4c811f4751daf363ca019a9f9bed702f4f
Author: David Malcolm <dmalc...@redhat.com>
Date:   Sun May 31 13:28:41 2020 -0400

    jit: fix __builtin_unreachable [PR 95426]

    PR jit/95426 reports a crash deep inside "expand" when using
    __builtin_unreachable via gcc_jit_context_get_builtin_function,
    due to BLOCK_FOR_INSN being erroneously used on a barrier within
    rtl_verify_bb_pointers.

    The root cause turns out to be that I didn't implement
    LANG_HOOKS_COMMON_ATTRIBUTE_TABLE and LANG_HOOKS_FORMAT_ATTRIBUTE_TABLE
    for the jit "frontend".  When building a decl for the builtin, the
    libgccjit frontend generates a chain of attributes names, but when
    this is passed to decl_attributes and the attributes are looked up by
    namespace and name within lookup_scoped_attribute_spec, attributes_table
    is empty.  Hence no attributes were being associated with the fndecl,
    and so ECF_NORETURN was not set on the gimple_call (along with various
    other flags missing on the decl, etc), and so the call is treated as
    not terminating its BB, and so the CFG rapidly diverges from the
    equivalent created by the C frontend.

    This patch fixes things by implementing these langhooks, copying the
    minimal attribute-handling code from LTO.  I stepped through the
    creation of the fndecl and verified that with this fix it has the same
    attributes as the equivalent created by the C frontend.

    gcc/jit/ChangeLog:
            PR jit/95426
            * dummy-frontend.c: Include "options.h", "stringpool.h", and
            "attribs.h".
            (ATTR_EXCL): New, copied from lto/lto-lang.c.
            (attr_noreturn_exclusions): Likewise.
            (attr_returns_twice_exclusions): Likewise.
            (attr_const_pure_exclusions): Likewise.
            (jit_attribute_table): Likewise, copied from lto_attribute_table.
            (jit_format_attribute_table): Likewise, copied from
            lto_format_attribute_table.
            (handle_noreturn_attribute): New, copied from lto/lto-lang.c.
            (handle_leaf_attribute): Likewise.
            (handle_const_attribute): Likewise.
            (handle_malloc_attribute): Likewise.
            (handle_pure_attribute): Likewise.
            (handle_novops_attribute): Likewise.
            (get_nonnull_operand): Likewise.
            (handle_nonnull_attribute): Likewise.
            (handle_nothrow_attribute): Likewise.
            (handle_sentinel_attribute): Likewise.
            (handle_type_generic_attribute): Likewise.
            (handle_transaction_pure_attribute): Likewise.
            (handle_returns_twice_attribute): Likewise.
            (handle_patchable_function_entry_attribute): Likewise.
            (ignore_attribute): Likewise.
            (handle_format_attribute): Likewise.
            (handle_format_arg_attribute): Likewise.
            (handle_fnspec_attribute): Likewise.
            (LANG_HOOKS_COMMON_ATTRIBUTE_TABLE): Define.
            (LANG_HOOKS_FORMAT_ATTRIBUTE_TABLE): Define.

    gcc/testsuite/ChangeLog:
            PR jit/95426
            * jit.dg/all-non-failing-tests.h: Add note about...
            * jit.dg/test-builtin-unreachable.c: New test.

Reply via email to