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

--- Comment #22 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Thomas Schwinge <tschwi...@gcc.gnu.org>:

https://gcc.gnu.org/g:9611ce687904a22da2febbc97acba2ae0f0c3780

commit r15-7542-g9611ce687904a22da2febbc97acba2ae0f0c3780
Author: Thomas Schwinge <tschwi...@baylibre.com>
Date:   Tue Feb 11 17:23:28 2025 +0100

    nvptx: Set 'UI_TARGET' for 'TARGET_EXCEPT_UNWIND_INFO' [PR86660]

    Subversion r263265 (Git commit 77e0a97acf7b00c1e68e4738fdf275a4cffc2e50)
    "[nvptx] Ignore c++ exceptions", originally had set 'UI_TARGET', but as
part of
    Subversion r263287 (Git commit d989dba8ef02c2406b7c9e62b352197dffc6b880)
    "[c++] Don't emit exception tables for UI_NONE", then switched to
'UI_NONE'.

    I understand the intention of using 'UI_NONE' like this, and it happens to
work
    in a lot of cases, but there are ICEs elsewhere: code paths where we run
into
    'internal compiler error: in get_personality_function, at expr.cc:13512':

        13494 /* Extracts the personality function of DECL and returns the
corresponding
        13495    libfunc.  */
        13496
        13497 rtx
        13498 get_personality_function (tree decl)
        13499 {
        13500   tree personality = DECL_FUNCTION_PERSONALITY (decl);
        13501   enum eh_personality_kind pk;
        13502
        13503   pk = function_needs_eh_personality (DECL_STRUCT_FUNCTION
(decl));
        13504   if (pk == eh_personality_none)
        13505     return NULL;
        13506
        13507   if (!personality
        13508       && pk == eh_personality_any)
        13509     personality = lang_hooks.eh_personality ();
        13510
        13511   if (pk == eh_personality_lang)
        13512     gcc_assert (personality != NULL_TREE);
        13513
        13514   return XEXP (DECL_RTL (personality), 0);
        13515 }

    ..., where 'lang_hooks.eh_personality ()' ends up calling
    'gcc/expr.cc:build_personality_function', and we 'return NULL;' for
'UI_NONE':

        13448 /* Build a decl for a personality function given a language
prefix.  */
        13449
        13450 tree
        13451 build_personality_function (const char *lang)
        13452 {
        13453   const char *unwind_and_version;
        13454   tree decl, type;
        13455   char *name;
        13456
        13457   switch (targetm_common.except_unwind_info (&global_options))
        13458     {
        13459     case UI_NONE:
        13460       return NULL;
        [...]

    (Comparing to nvptx' current use of 'UI_NONE', this problem (ICEs mentioned
    above) is way more prevalent for GCN.)

    The GCC internals documentation indeed states, 'gcc/doc/tm.texi':

        @deftypefn {Common Target Hook} {enum unwind_info_type}
TARGET_EXCEPT_UNWIND_INFO (struct gcc_options *@var{opts})
        This hook defines the mechanism that will be used for exception
handling
        by the target.  If the target has ABI specified unwind tables, the hook
        should return @code{UI_TARGET}.  If the target is to use the
        @code{setjmp}/@code{longjmp}-based exception handling scheme, the hook
        should return @code{UI_SJLJ}.  If the target supports DWARF 2 frame
unwind
        information, the hook should return @code{UI_DWARF2}.

        A target may, if exceptions are disabled, choose to return
@code{UI_NONE}.
        This may end up simplifying other parts of target-specific code.  [...]

    Here, note: "if exceptions are disabled" (meaning: '-fno-exceptions' etc.)
may
    "return @code{UI_NONE}".  That's what other back ends do with code like:

        /* For simplicity elsewhere in this file, indicate that all unwind
           info is disabled if we're not emitting unwind tables.  */
        if (!opts->x_flag_exceptions && !opts->x_flag_unwind_tables)
          return UI_NONE;
        else
          return UI_TARGET;

    The corresponding "simplifying other parts of target-specific code"/
    "simplicity elsewhere" would then be the early returns from
    'TARGET_ASM_UNWIND_EMIT', 'ARM_OUTPUT_FN_UNWIND', etc. for
    'TARGET_EXCEPT_UNWIND_INFO != UI_TARGET' (that is, for 'UI_NONE').

    From the documentation (and implementation), however, it does *not* follow
that
    if a target doesn't implement support for exception handling, it may just
set
    'UI_NONE' for 'TARGET_EXCEPT_UNWIND_INFO'.

    Therefore, switch (back) to 'UI_TARGET', implementing some basic support
for
    'exception_section': discard (via a PTX comment block) whatever GCC writes
into
    it.

    With that, all these 'internal compiler error: in get_personality_function'
    test cases turn into PASS, or UNSUPPORTED ('exception handling not
supported'),
    or re-classify into a few other, already known issues.

    (In case that use of 'UI_NONE' like originally intended really makes sense,
and
    is preferable over this 'UI_TARGET' solution, then more work will be
necessary
    for implementing the missing parts, where 'UI_NONE' currently isn't
handled.)

            PR target/86660
            gcc/
            * common/config/nvptx/nvptx-common.cc (nvptx_except_unwind_info):
            'return UI_TARGET;'.
            * config/nvptx/nvptx.cc (nvptx_assemble_integer): Handle
            'exception_section'.
            (nvptx_output_section_asm_op, nvptx_asm_init_sections): New
            functions.
            (TARGET_ASM_INIT_SECTIONS): '#define'.
            * config/nvptx/nvptx.h (TEXT_SECTION_ASM_OP, DATA_SECTION_ASM_OP):
            Don't '#define'.
            (ASM_OUTPUT_DWARF_DELTA): '#define'.

Reply via email to