This is an ICE in the RISC-V back-end calling tree_to_uhwi on the DECL_SIZE of
a global variable-length array. Fixed thusly, tested and approved by Jeff in
the audit trail, and applied on the mainline.
2024-07-06 Eric Botcazou <ebotca...@adacore.com>
PR target/115591
* config/riscv/riscv.cc (riscv_valid_lo_sum_p): Add missing test on
tree_fits_uhwi_p before calling tree_to_uhwi.
2024-07-06 Eric Botcazou <ebotca...@adacore.com>
* gnat.dg/array41.ads, gnat.dg/array41.adb: New test.
--
Eric Botcazou
diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc
index c17141d909a..5e34dc92210 100644
--- a/gcc/config/riscv/riscv.cc
+++ b/gcc/config/riscv/riscv.cc
@@ -1702,7 +1702,9 @@ riscv_valid_lo_sum_p (enum riscv_symbol_type sym_type, machine_mode mode,
align = (SYMBOL_REF_DECL (x)
? DECL_ALIGN (SYMBOL_REF_DECL (x))
: 1);
- size = (SYMBOL_REF_DECL (x) && DECL_SIZE (SYMBOL_REF_DECL (x))
+ size = (SYMBOL_REF_DECL (x)
+ && DECL_SIZE (SYMBOL_REF_DECL (x))
+ && tree_fits_uhwi_p (DECL_SIZE (SYMBOL_REF_DECL (x)))
? tree_to_uhwi (DECL_SIZE (SYMBOL_REF_DECL (x)))
: 2*BITS_PER_WORD);
}
package Array41 is
pragma Elaborate_Body;
end Array41;
-- { dg-do compile }
with System.Storage_Elements;
package body Array41 is
procedure Program_Initialization
with
Export,
Convention => Ada,
External_Name => "program_initialization";
procedure Program_Initialization is
use System.Storage_Elements;
Sdata : Storage_Element
with Import, Convention => Asm, External_Name => "_sdata";
Edata : Storage_Element
with Import, Convention => Asm, External_Name => "_edata";
Data_Size : constant Storage_Offset := Edata'Address - Sdata'Address;
-- Index from 1 so as to avoid subtracting 1 from the size
Data_In_Flash : constant Storage_Array (1 .. Data_Size)
with Import, Convention => Asm, External_Name => "_sidata";
Data_In_Sram : Storage_Array (1 .. Data_Size)
with Volatile, Import, Convention => Asm, External_Name => "_sdata";
begin
-- Copy rw data from flash to ram
for J in Data_In_Flash'Range loop
Data_In_Sram (J) := Data_In_Flash (J);
end loop;
end Program_Initialization;
end Array41;