aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorEric Botcazou <ebotcazou@adacore.com>2024-07-06 11:56:19 +0200
committerEric Botcazou <ebotcazou@adacore.com>2024-07-06 11:59:00 +0200
commit8bc5561c43b195e1638e5acace8b41b3f7512be3 (patch)
tree330eec04ec21ffdad032c2f399883d820770d779 /gcc
parent9a7e3f57e1ab8e6e4cf5ea3c0998aa50c6220579 (diff)
downloadgcc-8bc5561c43b195e1638e5acace8b41b3f7512be3.zip
gcc-8bc5561c43b195e1638e5acace8b41b3f7512be3.tar.gz
gcc-8bc5561c43b195e1638e5acace8b41b3f7512be3.tar.bz2
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.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/config/riscv/riscv.cc4
-rw-r--r--gcc/testsuite/gnat.dg/array41.adb37
-rw-r--r--gcc/testsuite/gnat.dg/array41.ads5
3 files changed, 45 insertions, 1 deletions
diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc
index 9bba5da..38ed773 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);
}
diff --git a/gcc/testsuite/gnat.dg/array41.adb b/gcc/testsuite/gnat.dg/array41.adb
new file mode 100644
index 0000000..d0d5a69
--- /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 0000000..50cde3c
--- /dev/null
+++ b/gcc/testsuite/gnat.dg/array41.ads
@@ -0,0 +1,5 @@
+package Array41 is
+
+ pragma Elaborate_Body;
+
+end Array41;