]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
RISC-V: fix internal error on global variable-length array
authorEric Botcazou <ebotcazou@adacore.com>
Sat, 6 Jul 2024 09:56:19 +0000 (11:56 +0200)
committerEric Botcazou <ebotcazou@adacore.com>
Sat, 6 Jul 2024 09:59:00 +0000 (11:59 +0200)
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.

gcc/config/riscv/riscv.cc
gcc/testsuite/gnat.dg/array41.adb [new file with mode: 0644]
gcc/testsuite/gnat.dg/array41.ads [new file with mode: 0644]

index 9bba5da016e950e8acd0dc9d53a82b945e619163..38ed773c222d47a6dcb4dd35794f5fab037415ee 100644 (file)
@@ -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);
     }
diff --git a/gcc/testsuite/gnat.dg/array41.adb b/gcc/testsuite/gnat.dg/array41.adb
new file mode 100644 (file)
index 0000000..d0d5a69
--- /dev/null
@@ -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 (file)
index 0000000..50cde3c
--- /dev/null
@@ -0,0 +1,5 @@
+package Array41 is
+
+  pragma Elaborate_Body;
+
+end Array41;