https://gcc.gnu.org/g:6c5ef4944e3858e7daf1ef75a3afa93a3ece37c5

commit r14-10385-g6c5ef4944e3858e7daf1ef75a3afa93a3ece37c5
Author: Eric Botcazou <ebotca...@adacore.com>
Date:   Sat Jul 6 11:56:19 2024 +0200

    RISC-V: fix internal error on global variable-length array
    
    This is an ICE in the RISC-V back-end calling tree_to_uhwi on the DECL_SIZE
    of a global variable-length array.
    
    gcc/
            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.
    
    gcc/testsuite/
            * gnat.dg/array41.ads, gnat.dg/array41.adb: New test.

Diff:
---
 gcc/config/riscv/riscv.cc         |  4 +++-
 gcc/testsuite/gnat.dg/array41.adb | 37 +++++++++++++++++++++++++++++++++++++
 gcc/testsuite/gnat.dg/array41.ads |  5 +++++
 3 files changed, 45 insertions(+), 1 deletion(-)

diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc
index 0f62b295b96..6fcb6fb4ad3 100644
--- a/gcc/config/riscv/riscv.cc
+++ b/gcc/config/riscv/riscv.cc
@@ -1397,7 +1397,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);
     }
diff --git a/gcc/testsuite/gnat.dg/array41.adb 
b/gcc/testsuite/gnat.dg/array41.adb
new file mode 100644
index 00000000000..d0d5a69eeaf
--- /dev/null
+++ b/gcc/testsuite/gnat.dg/array41.adb
@@ -0,0 +1,37 @@
+-- { 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;
diff --git a/gcc/testsuite/gnat.dg/array41.ads 
b/gcc/testsuite/gnat.dg/array41.ads
new file mode 100644
index 00000000000..50cde3cd819
--- /dev/null
+++ b/gcc/testsuite/gnat.dg/array41.ads
@@ -0,0 +1,5 @@
+package Array41 is
+
+  pragma Elaborate_Body;
+
+end Array41;

Reply via email to