[Bug rtl-optimization/119785] UBSAN errors in machmode.h on sparc

2025-04-14 Thread jakub at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119785

Jakub Jelinek  changed:

   What|Removed |Added

   Last reconfirmed||2025-04-14
 CC||jakub at gcc dot gnu.org
 Status|UNCONFIRMED |NEW
 Ever confirmed|0   |1

--- Comment #4 from Jakub Jelinek  ---
Guess this is caused by r6-2055, before that change set_src_cost wasn't passed
mode argument at all.
The problem is while for speed == 0 we pass always QImode, for speed == 1 it is
some random mode after the last vector mode.  In x86 case it is V2HFmode, so it
happens to work somehow, but in the sparc64 case that mode is MAX_MACHINE_MODE
and so doesn't work at all.

2025-04-14  Jakub Jelinek  

PR rtl-optimization/119785
* expmed.cc (init_expmed): Always pass QImode rather than mode to
set_src_cost passed to set_zero_cost.

--- gcc/expmed.cc.jj2025-04-08 14:08:51.234282102 +0200
+++ gcc/expmed.cc   2025-04-14 12:17:48.334123928 +0200
@@ -285,7 +285,7 @@ init_expmed (void)
   for (speed = 0; speed < 2; speed++)
 {
   crtl->maybe_hot_insn_p = speed;
-  set_zero_cost (speed, set_src_cost (const0_rtx, mode, speed));
+  set_zero_cost (speed, set_src_cost (const0_rtx, QImode, speed));

   for (mode = MIN_MODE_INT; mode <= MAX_MODE_INT;
   mode = (machine_mode)(mode + 1))

[Bug rtl-optimization/119785] UBSAN errors in machmode.h on sparc

2025-04-13 Thread sjames at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119785

--- Comment #1 from Sam James  ---
I also see:
```
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior
/root/gcc/gcc/config/sparc/sparc.cc:12093:23
/root/gcc/gcc/config/sparc/sparc.cc:12093:23: runtime error: index 63 out of
bounds for type 'unsigned char [63]'
#0 0x0467e388 in sparc_rtx_costs
/root/gcc/gcc/config/sparc/sparc.cc:12093
#1 0x02d6aa54 in rtx_cost(rtx_def*, machine_mode, rtx_code, int, bool)
/root/gcc/gcc/rtlanal.cc:4615
#2 0x0142dd34 in set_src_cost(rtx_def*, machine_mode, bool)
/root/gcc/gcc/rtl.h:2967
#3 0x0142dd34 in init_expmed() /root/gcc/gcc/expmed.cc:288
#4 0x031859b8 in backend_init_target /root/gcc/gcc/toplev.cc:1800
#5 0x031859b8 in initialize_rtl() /root/gcc/gcc/toplev.cc:1867
#6 0x0173162c in init_function_start(tree_node*)
/root/gcc/gcc/function.cc:5026
#7 0x00ec3b60 in cgraph_node::expand() /root/gcc/gcc/cgraphunit.cc:1844
#8 0x00ec3b60 in cgraph_node::expand() /root/gcc/gcc/cgraphunit.cc:1812
#9 0x00ee1b0c in expand_all_functions /root/gcc/gcc/cgraphunit.cc:2042
#10 0x00ee1b0c in symbol_table::compile()
/root/gcc/gcc/cgraphunit.cc:2418
#11 0x00ee1b0c in symbol_table::compile()
/root/gcc/gcc/cgraphunit.cc:2327
#12 0x00ee429c in symbol_table::finalize_compilation_unit()
/root/gcc/gcc/cgraphunit.cc:2607
#13 0x03181bec in compile_file /root/gcc/gcc/toplev.cc:479
#14 0x003f8bf4 in do_compile /root/gcc/gcc/toplev.cc:2208
#15 0x003f8bf4 in toplev::main(int, char**)
/root/gcc/gcc/toplev.cc:2371
#16 0x003fd52c in main /root/gcc/gcc/main.cc:39
#17 0xfff800010132c660  (/usr/lib64/libc.so.6+0x2c660)
#18 0xfff800010132c768 in __libc_start_main (/usr/lib64/libc.so.6+0x2c768)
#19 0x003fd9fc in _start (/tmp/build/gcc/cc1+0x3fd9fc)

SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior
/root/gcc/gcc/config/sparc/sparc.cc:12093:23
/root/gcc/gcc/config/sparc/sparc.cc:12093:23: runtime error: load of address
0x07874c77 with insufficient space for an object of type 'const unsigned
char'
0x07874c77: note: pointer points here
 0d 0d 0d 0d 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00
00 00 00 00  00 00 00
 ^
#0 0x0467e368 in sparc_rtx_costs
/root/gcc/gcc/config/sparc/sparc.cc:12093
#1 0x02d6aa54 in rtx_cost(rtx_def*, machine_mode, rtx_code, int, bool)
/root/gcc/gcc/rtlanal.cc:4615
#2 0x0142dd34 in set_src_cost(rtx_def*, machine_mode, bool)
/root/gcc/gcc/rtl.h:2967
#3 0x0142dd34 in init_expmed() /root/gcc/gcc/expmed.cc:288
#4 0x031859b8 in backend_init_target /root/gcc/gcc/toplev.cc:1800
#5 0x031859b8 in initialize_rtl() /root/gcc/gcc/toplev.cc:1867
#6 0x0173162c in init_function_start(tree_node*)
/root/gcc/gcc/function.cc:5026
#7 0x00ec3b60 in cgraph_node::expand() /root/gcc/gcc/cgraphunit.cc:1844
#8 0x00ec3b60 in cgraph_node::expand() /root/gcc/gcc/cgraphunit.cc:1812
#9 0x00ee1b0c in expand_all_functions /root/gcc/gcc/cgraphunit.cc:2042
#10 0x00ee1b0c in symbol_table::compile()
/root/gcc/gcc/cgraphunit.cc:2418
#11 0x00ee1b0c in symbol_table::compile()
/root/gcc/gcc/cgraphunit.cc:2327
#12 0x00ee429c in symbol_table::finalize_compilation_unit()
/root/gcc/gcc/cgraphunit.cc:2607
#13 0x03181bec in compile_file /root/gcc/gcc/toplev.cc:479
#14 0x003f8bf4 in do_compile /root/gcc/gcc/toplev.cc:2208
#15 0x003f8bf4 in toplev::main(int, char**)
/root/gcc/gcc/toplev.cc:2371
#16 0x003fd52c in main /root/gcc/gcc/main.cc:39
#17 0xfff800010132c660  (/usr/lib64/libc.so.6+0x2c660)
#18 0xfff800010132c768 in __libc_start_main (/usr/lib64/libc.so.6+0x2c768)
#19 0x003fd9fc in _start (/tmp/build/gcc/cc1+0x3fd9fc)
```

Keeping that in this bug given it also comes via rtx_cost.

[Bug rtl-optimization/119785] UBSAN errors in machmode.h on sparc

2025-04-13 Thread sjames at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119785

--- Comment #3 from Sam James  ---
https://gcc.gnu.org/pipermail/gcc-patches/2024-February/644797.html

[Bug rtl-optimization/119785] UBSAN errors in machmode.h on sparc

2025-04-13 Thread sjames at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119785

--- Comment #2 from Sam James  ---
`~/gcc/configure --enable-host-shared --enable-languages=c,c++,jit
--disable-multilib --host=sparc64-unknown-linux-gnu
--build=sparc64-unknown-linux-gnu --enable-checking=yes,extra,rtl
--with-build-config="bootstrap-ubsan"`