Rust: In 'type_for_mode' langhook also consider all 'int_n' modes/types (was: Modula-2 / Rust: Many targets failing)

Message ID 871qmi6iya.fsf@euler.schwinge.homeip.net
State Accepted
Headers
Series Rust: In 'type_for_mode' langhook also consider all 'int_n' modes/types (was: Modula-2 / Rust: Many targets failing) |

Checks

Context Check Description
snail/gcc-patch-check success Github commit url

Commit Message

Thomas Schwinge Feb. 22, 2023, 11:25 a.m. UTC
  Hi!

Richard, you may remember your words from <https://gcc.gnu.org/PR46805>
"ICE: SIGSEGV in optab_for_tree_code (optabs.c:407) with -O -fno-tree-scev-cprop -ftree-vectorize":

> Ideally we'd never use lang_hooks.types.type_for_mode (or _for_size) in the
> middle-end but had a pure middle-end based implementation.

Is there a canonical PR or other discussion thread for that?

Here's another instance of this issue:

On 2022-12-19T22:23:45+0100, Jan-Benedict Glaw <jbglaw@lug-owl.de> wrote:
> With the recent merges for Modula-2 and Rust, I see a good number of
> targets failing with --enable-languages=all, mostly due to issues with
> the Modula-2 driver.

Thanks for reporting.

>  Modula-2 related issues
> [snipped]

>  Rust related issues
> =====================
>
>  --target=msp430-elfbare
> ~~~~~~~~~~~~~~~~~~~~~~~~~
>       /var/lib/laminar/run/gcc-msp430-elfbare/24/toolchain-build/./gcc/xgcc -B/var/lib/laminar/run/gcc-msp430-elfbare/24/toolchain-build/./gcc/  -xrust -frust-incomplete-and-experimental-compiler-do-not-use -nostdinc /dev/null -S -o /dev/null -fself-test=../../gcc/gcc/testsuite/selftests
>       <built-in>: internal compiler error: Segmentation fault
>       0xf2efbf crash_signal
>             ../../gcc/gcc/toplev.cc:314
>       0x120c8c7 build_function_type(tree_node*, tree_node*, bool)
>             ../../gcc/gcc/tree.cc:7360
>       0x120cc20 build_function_type_list(tree_node*, ...)
>             ../../gcc/gcc/tree.cc:7442
>       0x120d16b build_common_builtin_nodes()
>             ../../gcc/gcc/tree.cc:9883
>       0x8449b4 grs_langhook_init
>             ../../gcc/gcc/rust/rust-lang.cc:132
>       0x8427b2 lang_dependent_init
>             ../../gcc/gcc/toplev.cc:1815
>       0x8427b2 do_compile
>             ../../gcc/gcc/toplev.cc:2110
>       Please submit a full bug report, with preprocessed source (by using -freport-bug).
>       Please include the complete backtrace with any bug report.
>       See <https://gcc.gnu.org/bugs/> for instructions.
>       make[1]: *** [../../gcc/gcc/rust/Make-lang.in:275: s-selftest-rust] Error 1

See also <https://github.com/Rust-GCC/gccrs/issues/1713>
"Test failure on msp430-elfbare target".

I confirm with both upstream GCC master branch and GCC/Rust master
branch:

    $ ../source-gcc/configure --target=msp430-elfbare --enable-languages=rust [...]
    $ make all-gcc [...]
    [...]
    [...]/build-gcc/./gcc/xgcc -B[...]/build-gcc/./gcc/  -xc -nostdinc /dev/null -S -o /dev/null -fself-test=../../source-gcc/gcc/testsuite/selftests
    -fself-test: 57323 pass(es) in 0.420000 seconds
    echo timestamp > s-selftest-c
    [...]/build-gcc/./gcc/xgcc -B[...]/build-gcc/./gcc/  -xrust -frust-incomplete-and-experimental-compiler-do-not-use -nostdinc /dev/null -S -o /dev/null -fself-test=../../source-gcc/gcc/testsuite/selftests
    <built-in>: internal compiler error: Segmentation fault
    0xf51b9f crash_signal
            ../../source-gcc/gcc/toplev.cc:314
    0x12e6a3a build_function_type(tree_node*, tree_node*, bool)
            ../../source-gcc/gcc/tree.cc:7447
    0x12e6ee0 build_function_type_list(tree_node*, ...)
            ../../source-gcc/gcc/tree.cc:7529
    0x12e748e build_common_builtin_nodes()
            ../../source-gcc/gcc/tree.cc:9977
    0x7661c4 grs_langhook_init
            ../../source-gcc/gcc/rust/rust-lang.cc:128
    0x762ac9 lang_dependent_init
            ../../source-gcc/gcc/toplev.cc:1815
    0x762ac9 do_compile
            ../../source-gcc/gcc/toplev.cc:2110
    Please submit a full bug report, with preprocessed source (by using -freport-bug).
    Please include the complete backtrace with any bug report.
    See <https://gcc.gnu.org/bugs/> for instructions.
    make[1]: *** [s-selftest-rust] Error 1
    [...]

OK to push the attached
"Rust: In 'type_for_mode' langhook also consider all 'int_n' modes/types"?


Grüße
 Thomas


-----------------
Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955
  

Comments

Richard Biener Feb. 22, 2023, 11:45 a.m. UTC | #1
On Wed, 22 Feb 2023, Thomas Schwinge wrote:

> Hi!
> 
> Richard, you may remember your words from <https://gcc.gnu.org/PR46805>
> "ICE: SIGSEGV in optab_for_tree_code (optabs.c:407) with -O -fno-tree-scev-cprop -ftree-vectorize":
> 
> > Ideally we'd never use lang_hooks.types.type_for_mode (or _for_size) in the
> > middle-end but had a pure middle-end based implementation.
> 
> Is there a canonical PR or other discussion thread for that?

No, not that I'm aware of.

Richard.

> Here's another instance of this issue:
> 
> On 2022-12-19T22:23:45+0100, Jan-Benedict Glaw <jbglaw@lug-owl.de> wrote:
> > With the recent merges for Modula-2 and Rust, I see a good number of
> > targets failing with --enable-languages=all, mostly due to issues with
> > the Modula-2 driver.
> 
> Thanks for reporting.
> 
> >  Modula-2 related issues
> > [snipped]
> 
> >  Rust related issues
> > =====================
> >
> >  --target=msp430-elfbare
> > ~~~~~~~~~~~~~~~~~~~~~~~~~
> >       /var/lib/laminar/run/gcc-msp430-elfbare/24/toolchain-build/./gcc/xgcc -B/var/lib/laminar/run/gcc-msp430-elfbare/24/toolchain-build/./gcc/  -xrust -frust-incomplete-and-experimental-compiler-do-not-use -nostdinc /dev/null -S -o /dev/null -fself-test=../../gcc/gcc/testsuite/selftests
> >       <built-in>: internal compiler error: Segmentation fault
> >       0xf2efbf crash_signal
> >             ../../gcc/gcc/toplev.cc:314
> >       0x120c8c7 build_function_type(tree_node*, tree_node*, bool)
> >             ../../gcc/gcc/tree.cc:7360
> >       0x120cc20 build_function_type_list(tree_node*, ...)
> >             ../../gcc/gcc/tree.cc:7442
> >       0x120d16b build_common_builtin_nodes()
> >             ../../gcc/gcc/tree.cc:9883
> >       0x8449b4 grs_langhook_init
> >             ../../gcc/gcc/rust/rust-lang.cc:132
> >       0x8427b2 lang_dependent_init
> >             ../../gcc/gcc/toplev.cc:1815
> >       0x8427b2 do_compile
> >             ../../gcc/gcc/toplev.cc:2110
> >       Please submit a full bug report, with preprocessed source (by using -freport-bug).
> >       Please include the complete backtrace with any bug report.
> >       See <https://gcc.gnu.org/bugs/> for instructions.
> >       make[1]: *** [../../gcc/gcc/rust/Make-lang.in:275: s-selftest-rust] Error 1
> 
> See also <https://github.com/Rust-GCC/gccrs/issues/1713>
> "Test failure on msp430-elfbare target".
> 
> I confirm with both upstream GCC master branch and GCC/Rust master
> branch:
> 
>     $ ../source-gcc/configure --target=msp430-elfbare --enable-languages=rust [...]
>     $ make all-gcc [...]
>     [...]
>     [...]/build-gcc/./gcc/xgcc -B[...]/build-gcc/./gcc/  -xc -nostdinc /dev/null -S -o /dev/null -fself-test=../../source-gcc/gcc/testsuite/selftests
>     -fself-test: 57323 pass(es) in 0.420000 seconds
>     echo timestamp > s-selftest-c
>     [...]/build-gcc/./gcc/xgcc -B[...]/build-gcc/./gcc/  -xrust -frust-incomplete-and-experimental-compiler-do-not-use -nostdinc /dev/null -S -o /dev/null -fself-test=../../source-gcc/gcc/testsuite/selftests
>     <built-in>: internal compiler error: Segmentation fault
>     0xf51b9f crash_signal
>             ../../source-gcc/gcc/toplev.cc:314
>     0x12e6a3a build_function_type(tree_node*, tree_node*, bool)
>             ../../source-gcc/gcc/tree.cc:7447
>     0x12e6ee0 build_function_type_list(tree_node*, ...)
>             ../../source-gcc/gcc/tree.cc:7529
>     0x12e748e build_common_builtin_nodes()
>             ../../source-gcc/gcc/tree.cc:9977
>     0x7661c4 grs_langhook_init
>             ../../source-gcc/gcc/rust/rust-lang.cc:128
>     0x762ac9 lang_dependent_init
>             ../../source-gcc/gcc/toplev.cc:1815
>     0x762ac9 do_compile
>             ../../source-gcc/gcc/toplev.cc:2110
>     Please submit a full bug report, with preprocessed source (by using -freport-bug).
>     Please include the complete backtrace with any bug report.
>     See <https://gcc.gnu.org/bugs/> for instructions.
>     make[1]: *** [s-selftest-rust] Error 1
>     [...]
> 
> OK to push the attached
> "Rust: In 'type_for_mode' langhook also consider all 'int_n' modes/types"?
> 
> 
> Grüße
>  Thomas
> 
> 
> -----------------
> Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955
>
  
Arthur Cohen Feb. 22, 2023, 2:30 p.m. UTC | #2
Hi Thomas,

On 2/22/23 12:25, Thomas Schwinge wrote:
> Hi!
> 
> Richard, you may remember your words from <https://gcc.gnu.org/PR46805>
> "ICE: SIGSEGV in optab_for_tree_code (optabs.c:407) with -O -fno-tree-scev-cprop -ftree-vectorize":
> 
>> Ideally we'd never use lang_hooks.types.type_for_mode (or _for_size) in the
>> middle-end but had a pure middle-end based implementation.
> 
> Is there a canonical PR or other discussion thread for that?
> 
> Here's another instance of this issue:
> 
> On 2022-12-19T22:23:45+0100, Jan-Benedict Glaw <jbglaw@lug-owl.de> wrote:
>> With the recent merges for Modula-2 and Rust, I see a good number of
>> targets failing with --enable-languages=all, mostly due to issues with
>> the Modula-2 driver.
> 
> Thanks for reporting.
> 
>>   Modula-2 related issues
>> [snipped]
> 
>>   Rust related issues
>> =====================
>>
>>   --target=msp430-elfbare
>> ~~~~~~~~~~~~~~~~~~~~~~~~~
>>        /var/lib/laminar/run/gcc-msp430-elfbare/24/toolchain-build/./gcc/xgcc -B/var/lib/laminar/run/gcc-msp430-elfbare/24/toolchain-build/./gcc/  -xrust -frust-incomplete-and-experimental-compiler-do-not-use -nostdinc /dev/null -S -o /dev/null -fself-test=../../gcc/gcc/testsuite/selftests
>>        <built-in>: internal compiler error: Segmentation fault
>>        0xf2efbf crash_signal
>>              ../../gcc/gcc/toplev.cc:314
>>        0x120c8c7 build_function_type(tree_node*, tree_node*, bool)
>>              ../../gcc/gcc/tree.cc:7360
>>        0x120cc20 build_function_type_list(tree_node*, ...)
>>              ../../gcc/gcc/tree.cc:7442
>>        0x120d16b build_common_builtin_nodes()
>>              ../../gcc/gcc/tree.cc:9883
>>        0x8449b4 grs_langhook_init
>>              ../../gcc/gcc/rust/rust-lang.cc:132
>>        0x8427b2 lang_dependent_init
>>              ../../gcc/gcc/toplev.cc:1815
>>        0x8427b2 do_compile
>>              ../../gcc/gcc/toplev.cc:2110
>>        Please submit a full bug report, with preprocessed source (by using -freport-bug).
>>        Please include the complete backtrace with any bug report.
>>        See <https://gcc.gnu.org/bugs/> for instructions.
>>        make[1]: *** [../../gcc/gcc/rust/Make-lang.in:275: s-selftest-rust] Error 1
> 
> See also <https://github.com/Rust-GCC/gccrs/issues/1713>
> "Test failure on msp430-elfbare target".
> 
> I confirm with both upstream GCC master branch and GCC/Rust master
> branch:
> 
>      $ ../source-gcc/configure --target=msp430-elfbare --enable-languages=rust [...]
>      $ make all-gcc [...]
>      [...]
>      [...]/build-gcc/./gcc/xgcc -B[...]/build-gcc/./gcc/  -xc -nostdinc /dev/null -S -o /dev/null -fself-test=../../source-gcc/gcc/testsuite/selftests
>      -fself-test: 57323 pass(es) in 0.420000 seconds
>      echo timestamp > s-selftest-c
>      [...]/build-gcc/./gcc/xgcc -B[...]/build-gcc/./gcc/  -xrust -frust-incomplete-and-experimental-compiler-do-not-use -nostdinc /dev/null -S -o /dev/null -fself-test=../../source-gcc/gcc/testsuite/selftests
>      <built-in>: internal compiler error: Segmentation fault
>      0xf51b9f crash_signal
>              ../../source-gcc/gcc/toplev.cc:314
>      0x12e6a3a build_function_type(tree_node*, tree_node*, bool)
>              ../../source-gcc/gcc/tree.cc:7447
>      0x12e6ee0 build_function_type_list(tree_node*, ...)
>              ../../source-gcc/gcc/tree.cc:7529
>      0x12e748e build_common_builtin_nodes()
>              ../../source-gcc/gcc/tree.cc:9977
>      0x7661c4 grs_langhook_init
>              ../../source-gcc/gcc/rust/rust-lang.cc:128
>      0x762ac9 lang_dependent_init
>              ../../source-gcc/gcc/toplev.cc:1815
>      0x762ac9 do_compile
>              ../../source-gcc/gcc/toplev.cc:2110
>      Please submit a full bug report, with preprocessed source (by using -freport-bug).
>      Please include the complete backtrace with any bug report.
>      See <https://gcc.gnu.org/bugs/> for instructions.
>      make[1]: *** [s-selftest-rust] Error 1
>      [...]
> 
> OK to push the attached
> "Rust: In 'type_for_mode' langhook also consider all 'int_n' modes/types"?|

OK :) patch was tested on x86_64 and builds, bootstraps and pass the 
testsuite.

Kindly,

Arthur

> 
> 
> Grüße
>   Thomas
> 
> 
> -----------------
> Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955
  
Jan-Benedict Glaw Feb. 24, 2023, 9:12 a.m. UTC | #3
Hi Thomas / Arthur!

On Wed, 2023-02-22 15:30:37 +0100, Arthur Cohen <arthur.cohen@embecosm.com> wrote:
[..]
> > >   --target=msp430-elfbare
> > > ~~~~~~~~~~~~~~~~~~~~~~~~~
> > >        /var/lib/laminar/run/gcc-msp430-elfbare/24/toolchain-build/./gcc/xgcc -B/var/lib/laminar/run/gcc-msp430-elfbare/24/toolchain-build/./gcc/  -xrust -frust-incomplete-and-experimental-compiler-do-not-use -nostdinc /dev/null -S -o /dev/null -fself-test=../../gcc/gcc/testsuite/selftests
> > >        <built-in>: internal compiler error: Segmentation fault
> > >        0xf2efbf crash_signal
> > >              ../../gcc/gcc/toplev.cc:314
> > >        0x120c8c7 build_function_type(tree_node*, tree_node*, bool)
> > >              ../../gcc/gcc/tree.cc:7360
> > >        0x120cc20 build_function_type_list(tree_node*, ...)
> > >              ../../gcc/gcc/tree.cc:7442
> > >        0x120d16b build_common_builtin_nodes()
> > >              ../../gcc/gcc/tree.cc:9883
> > >        0x8449b4 grs_langhook_init
> > >              ../../gcc/gcc/rust/rust-lang.cc:132
> > >        0x8427b2 lang_dependent_init
> > >              ../../gcc/gcc/toplev.cc:1815
> > >        0x8427b2 do_compile
> > >              ../../gcc/gcc/toplev.cc:2110
> > >        Please submit a full bug report, with preprocessed source (by using -freport-bug).
> > >        Please include the complete backtrace with any bug report.
> > >        See <https://gcc.gnu.org/bugs/> for instructions.
> > >        make[1]: *** [../../gcc/gcc/rust/Make-lang.in:275: s-selftest-rust] Error 1

Confirmed successful build #37 for my msp320-elfbare build at
http://toolchain.lug-owl.de/laminar/jobs/gcc-msp430-elfbare

Thanks,
  Jan-Benedict

--
  
Jan-Benedict Glaw Feb. 25, 2023, 10:20 p.m. UTC | #4
Hi Thomas,

On Wed, 2023-02-22 12:25:01 +0100, Thomas Schwinge <thomas@codesourcery.com> wrote:
> On 2022-12-19T22:23:45+0100, Jan-Benedict Glaw <jbglaw@lug-owl.de> wrote:
> >  Rust related issues
> > =====================
> >
> >  --target=msp430-elfbare
> > ~~~~~~~~~~~~~~~~~~~~~~~~~
> >       /var/lib/laminar/run/gcc-msp430-elfbare/24/toolchain-build/./gcc/xgcc -B/var/lib/laminar/run/gcc-msp430-elfbare/24/toolchain-build/./gcc/  -xrust -frust-incomplete-and-experimental-compiler-do-not-use -nostdinc /dev/null -S -o /dev/null -fself-test=../../gcc/gcc/testsuite/selftests
> >       <built-in>: internal compiler error: Segmentation fault
> >       0xf2efbf crash_signal
> >             ../../gcc/gcc/toplev.cc:314
> >       0x120c8c7 build_function_type(tree_node*, tree_node*, bool)
> >             ../../gcc/gcc/tree.cc:7360
> >       0x120cc20 build_function_type_list(tree_node*, ...)
> >             ../../gcc/gcc/tree.cc:7442
> >       0x120d16b build_common_builtin_nodes()
> >             ../../gcc/gcc/tree.cc:9883
> >       0x8449b4 grs_langhook_init
> >             ../../gcc/gcc/rust/rust-lang.cc:132
> >       0x8427b2 lang_dependent_init
> >             ../../gcc/gcc/toplev.cc:1815
> >       0x8427b2 do_compile
> >             ../../gcc/gcc/toplev.cc:2110
> >       Please submit a full bug report, with preprocessed source (by using -freport-bug).
> >       Please include the complete backtrace with any bug report.
> >       See <https://gcc.gnu.org/bugs/> for instructions.
> >       make[1]: *** [../../gcc/gcc/rust/Make-lang.in:275: s-selftest-rust] Error 1
> 
> See also <https://github.com/Rust-GCC/gccrs/issues/1713>
> "Test failure on msp430-elfbare target".

Confirm: fixed upstream
(http://toolchain.lug-owl.de/laminar/jobs/gcc-msp430-elf/65)

Thanks,
  Jan-Benedict

--
  

Patch

From cae898bef63db18cc40b94ee4d48f85aec258c02 Mon Sep 17 00:00:00 2001
From: Thomas Schwinge <thomas@codesourcery.com>
Date: Wed, 22 Feb 2023 11:42:43 +0100
Subject: [PATCH] Rust: In 'type_for_mode' langhook also consider all 'int_n'
 modes/types

As reported in "Rust related issues" at the end of
<https://inbox.sourceware.org/gcc-patches/20221219212344.ewtuzd2jtztm77x2@lug-owl.de>
"Modula-2 / Rust: Many targets failing",
<https://github.com/Rust-GCC/gccrs/issues/1713>
"Test failure on msp430-elfbare target", for '--target=msp430-elfbar' we ICE:

    <built-in>: internal compiler error: Segmentation fault
    0xf2efbf crash_signal
          ../../gcc/gcc/toplev.cc:314
    0x120c8c7 build_function_type(tree_node*, tree_node*, bool)
          ../../gcc/gcc/tree.cc:7360
    0x120cc20 build_function_type_list(tree_node*, ...)
          ../../gcc/gcc/tree.cc:7442
    0x120d16b build_common_builtin_nodes()
          ../../gcc/gcc/tree.cc:9883
    0x8449b4 grs_langhook_init
          ../../gcc/gcc/rust/rust-lang.cc:132
    [...]

This is due to 'tmp == NULL' for 'gcc/tree.cc:build_common_builtin_nodes':

    tmp = lang_hooks.types.type_for_mode (targetm.eh_return_filter_mode (), 0);

..., were 'targetm.eh_return_filter_mode' (that is,
'gcc/targhooks.cc:default_eh_return_filter_mode',
via calling 'targetm.unwind_word_mode':
'gcc/config/msp430/msp430.cc:msp430_unwind_word_mode') returns 'PSImode',
and 'lang_hooks.types.type_for_mode' (that is,
'gcc/rust/rust-lang.cc:grs_langhook_type_for_mode') returns 'NULL' for
'PSImode'.

As, for example, discussed in <https://gcc.gnu.org/PR46805>
"ICE: SIGSEGV in optab_for_tree_code (optabs.c:407) with -O -fno-tree-scev-cprop -ftree-vectorize",
we have to support "random" modes/types in the 'type_for_mode' langhook.

	gcc/rust/
	* rust-lang.cc (grs_langhook_type_for_mode): Also consider all
	'int_n' modes/types.
---
 gcc/rust/rust-lang.cc | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/gcc/rust/rust-lang.cc b/gcc/rust/rust-lang.cc
index 75f6b4458d7..b4b86236ffc 100644
--- a/gcc/rust/rust-lang.cc
+++ b/gcc/rust/rust-lang.cc
@@ -235,6 +235,21 @@  grs_langhook_type_for_mode (machine_mode mode, int unsignedp)
       if (mode == TYPE_MODE (complex_integer_type_node) && !unsignedp)
 	return complex_integer_type_node;
     }
+
+  /* See (a) <https://github.com/Rust-GCC/gccrs/issues/1713>
+     "Test failure on msp430-elfbare target", and
+     (b) <https://gcc.gnu.org/PR46805>
+     "ICE: SIGSEGV in optab_for_tree_code (optabs.c:407) with -O -fno-tree-scev-cprop -ftree-vectorize"
+     -- we have to support "random" modes/types here.
+     TODO Clean all this up (either locally, or preferably per PR46805:
+     "Ideally we'd never use lang_hooks.types.type_for_mode (or _for_size) in the
+     middle-end but had a pure middle-end based implementation".  */
+  for (size_t i = 0; i < NUM_INT_N_ENTS; i ++)
+    if (int_n_enabled_p[i]
+	&& mode == int_n_data[i].m)
+      return (unsignedp ? int_n_trees[i].unsigned_type
+	      : int_n_trees[i].signed_type);
+
   /* gcc_unreachable */
   return NULL;
 }
-- 
2.25.1