[gcc r15-4183] RISC-V: Implement TARGET_CAN_INLINE_P

2024-10-08 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:517d344e416c762a942a3633b6ec73a1d018016e

commit r15-4183-g517d344e416c762a942a3633b6ec73a1d018016e
Author: Yangyu Chen 
Date:   Tue Oct 8 11:08:44 2024 -0600

RISC-V: Implement TARGET_CAN_INLINE_P

Currently, we lack support for TARGET_CAN_INLINE_P on the RISC-V
ISA. As a result, certain functions cannot be optimized with inlining
when specific options, such as __attribute__((target("arch=+v"))) .
This can lead to potential performance issues when building
retargetable binaries for RISC-V.

To address this, I have implemented the riscv_can_inline_p function.
This addition enables inlining when the callee either has no special
options or when the some options match, and also ensuring that the
callee's ISA is a subset of the caller's. I also check some other
options when there is no always_inline set.

gcc/ChangeLog:

* common/config/riscv/riscv-common.cc (cl_opt_var_ref_t): Add
cl_opt_var_ref_t pointer to member of cl_target_option.
(struct riscv_ext_flag_table_t): Add new cl_opt_var_ref_t field.
(RISCV_EXT_FLAG_ENTRY): New macro to simplify the definition of
riscv_ext_flag_table.
(riscv_ext_is_subset): New function to check if the callee's ISA
is a subset of the caller's.
(riscv_x_target_flags_isa_mask): New function to get the mask of
ISA extension in x_target_flags of gcc_options.
* config/riscv/riscv-subset.h (riscv_ext_is_subset): Declare
riscv_ext_is_subset function.
(riscv_x_target_flags_isa_mask): Declare
riscv_x_target_flags_isa_mask function.
* config/riscv/riscv.cc (riscv_can_inline_p): New function.
(TARGET_CAN_INLINE_P): Implement TARGET_CAN_INLINE_P.

Diff:
---
 gcc/common/config/riscv/riscv-common.cc | 372 ++--
 gcc/config/riscv/riscv-subset.h |   3 +
 gcc/config/riscv/riscv.cc   |  66 ++
 3 files changed, 276 insertions(+), 165 deletions(-)

diff --git a/gcc/common/config/riscv/riscv-common.cc 
b/gcc/common/config/riscv/riscv-common.cc
index a6abd903b98f..2adebe0b6f29 100644
--- a/gcc/common/config/riscv/riscv-common.cc
+++ b/gcc/common/config/riscv/riscv-common.cc
@@ -1568,191 +1568,196 @@ riscv_arch_str (bool version_p)
 return std::string();
 }
 
-/* Type for pointer to member of gcc_options.  */
+/* Type for pointer to member of gcc_options and cl_target_option.  */
 typedef int (gcc_options::*opt_var_ref_t);
+typedef int (cl_target_option::*cl_opt_var_ref_t);
 
 /* Types for recording extension to internal flag.  */
 struct riscv_ext_flag_table_t {
   const char *ext;
   opt_var_ref_t var_ref;
+  cl_opt_var_ref_t cl_var_ref;
   int mask;
 };
 
+#define RISCV_EXT_FLAG_ENTRY(NAME, VAR, MASK) \
+  {NAME, &gcc_options::VAR, &cl_target_option::VAR, MASK}
+
 /* Mapping table between extension to internal flag.  */
 static const riscv_ext_flag_table_t riscv_ext_flag_table[] =
 {
-  {"e", &gcc_options::x_target_flags, MASK_RVE},
-  {"m", &gcc_options::x_target_flags, MASK_MUL},
-  {"a", &gcc_options::x_target_flags, MASK_ATOMIC},
-  {"f", &gcc_options::x_target_flags, MASK_HARD_FLOAT},
-  {"d", &gcc_options::x_target_flags, MASK_DOUBLE_FLOAT},
-  {"c", &gcc_options::x_target_flags, MASK_RVC},
-  {"v", &gcc_options::x_target_flags, MASK_FULL_V},
-  {"v", &gcc_options::x_target_flags, MASK_VECTOR},
-
-  {"zicsr",&gcc_options::x_riscv_zi_subext, MASK_ZICSR},
-  {"zifencei", &gcc_options::x_riscv_zi_subext, MASK_ZIFENCEI},
-  {"zicond",   &gcc_options::x_riscv_zi_subext, MASK_ZICOND},
-
-  {"za64rs",  &gcc_options::x_riscv_za_subext, MASK_ZA64RS},
-  {"za128rs", &gcc_options::x_riscv_za_subext, MASK_ZA128RS},
-  {"zawrs",   &gcc_options::x_riscv_za_subext, MASK_ZAWRS},
-  {"zaamo",   &gcc_options::x_riscv_za_subext, MASK_ZAAMO},
-  {"zalrsc",  &gcc_options::x_riscv_za_subext, MASK_ZALRSC},
-  {"zabha",   &gcc_options::x_riscv_za_subext, MASK_ZABHA},
-  {"zacas",   &gcc_options::x_riscv_za_subext, MASK_ZACAS},
-
-  {"zba",&gcc_options::x_riscv_zb_subext, MASK_ZBA},
-  {"zbb",&gcc_options::x_riscv_zb_subext, MASK_ZBB},
-  {"zbc",&gcc_options::x_riscv_zb_subext, MASK_ZBC},
-  {"zbs",&gcc_options::x_riscv_zb_subext, MASK_ZBS},
-
-  {"zfinx",&gcc_options::x_riscv_zinx_subext, MASK_ZFINX},
-  {"zdinx",&gcc_options::x_riscv_zinx_subext, MASK_ZDINX},
-  {"zhinx",&gcc_options::x_riscv_zinx_subext, MASK_ZHINX},
-  {"zhinxmin", &gcc_options::x_riscv_zinx_subext, MASK_ZHINXMIN},
-
-  {"zbkb",   &gcc_options::x_riscv_zk_subext, MASK_ZBKB},
-  {"zbkc",   &gcc_options::x_riscv_zk_subext, MASK_ZBKC},
-  {"zbkx",   &gcc_options::x_riscv_zk_subext, MASK_ZBKX},
-  {"zknd",   &gcc_options::x_riscv_zk_subext, MASK_ZKND},
-  {"zkne",   &gcc_options::x_riscv_zk_subext, MASK_ZKNE},
-  {"zknh",   &gcc_options::x_riscv_zk_subext, MASK_ZKNH},
-  {"zkr",&gcc_options::x_risc

[gcc r15-4131] diagnostics: Fix compile error for MinGW <7.0

2024-10-08 Thread Torbjorn Svensson via Gcc-cvs
https://gcc.gnu.org/g:327b4bcfa05021dbc9a0c8269df1d9becc5757af

commit r15-4131-g327b4bcfa05021dbc9a0c8269df1d9becc5757af
Author: Torbjörn SVENSSON 
Date:   Thu Sep 26 18:12:46 2024 +0200

diagnostics: Fix compile error for MinGW <7.0

The define ENABLE_VIRTUAL_TERMINAL_PROCESSING was introduced in MinGW
7.0

Build failure when building with MinGW 5.0.3:

.../gcc/diagnostic-color.cc:
In function 'bool should_colorize()':
.../gcc/diagnostic-color.cc:317:41:
error: 'ENABLE_VIRTUAL_TERMINAL_PROCESSING' was not declared in this
scope
   mode |= ENABLE_PROCESSED_OUTPUT | ENABLE_VIRTUAL_TERMINAL_PROCESSING;
 ^~
.../gcc/diagnostic-color.cc:317:41:
note: suggested alternative: 'ENABLE_RTL_FLAG_CHECKING'
   mode |= ENABLE_PROCESSED_OUTPUT | ENABLE_VIRTUAL_TERMINAL_PROCESSING;
 ^~
 ENABLE_RTL_FLAG_CHECKING
.../gcc/diagnostic-color.cc:
In function 'bool auto_enable_urls()':
.../gcc/diagnostic-color.cc:407:50:
error: 'ENABLE_VIRTUAL_TERMINAL_PROCESSING' was not declared in this
scope
   if (GetConsoleMode (handle, &mode) && !(mode & 
ENABLE_VIRTUAL_TERMINAL_PROCESSING))
  
^~
.../gcc/diagnostic-color.cc:407:50:
note: suggested alternative: 'ENABLE_RTL_FLAG_CHECKING'
   if (GetConsoleMode (handle, &mode) && !(mode & 
ENABLE_VIRTUAL_TERMINAL_PROCESSING))
  
^~
  ENABLE_RTL_FLAG_CHECKING
Makefile:1195: recipe for target 'diagnostic-color.o' failed
make[1]: *** [diagnostic-color.o] Error 1

gcc/ChangeLog:

* diagnostic-color.cc: Conditionally enable terminal processing
based on define availability.
* pretty-print.cc: Likewise.

Signed-off-by: Torbjörn SVENSSON 

Diff:
---
 gcc/diagnostic-color.cc | 8 +++-
 gcc/pretty-print.cc | 6 +-
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/gcc/diagnostic-color.cc b/gcc/diagnostic-color.cc
index 8b195d023eb7..2ad708c06e6e 100644
--- a/gcc/diagnostic-color.cc
+++ b/gcc/diagnostic-color.cc
@@ -311,12 +311,14 @@ should_colorize (void)
   if ((handle != INVALID_HANDLE_VALUE) && (handle != NULL))
 isconsole = GetConsoleMode (handle, &mode);
 
+#ifdef ENABLE_VIRTUAL_TERMINAL_PROCESSING
   if (isconsole)
 {
   /* Try to enable processing of VT100 escape sequences */
   mode |= ENABLE_PROCESSED_OUTPUT | ENABLE_VIRTUAL_TERMINAL_PROCESSING;
   SetConsoleMode (handle, mode);
 }
+#endif
 
   return isconsole;
 #else
@@ -404,7 +406,11 @@ auto_enable_urls ()
   /* If ansi escape sequences aren't supported by the console, then URLs will
  print mangled from mingw_ansi_fputs's console API translation. It wouldn't
  be useful even if this weren't the case.  */
-  if (GetConsoleMode (handle, &mode) && !(mode & 
ENABLE_VIRTUAL_TERMINAL_PROCESSING))
+  if (GetConsoleMode (handle, &mode)
+#ifdef ENABLE_VIRTUAL_TERMINAL_PROCESSING
+  && !(mode & ENABLE_VIRTUAL_TERMINAL_PROCESSING)
+#endif
+  )
 return false;
 #endif
 
diff --git a/gcc/pretty-print.cc b/gcc/pretty-print.cc
index af452101693b..18c4b2fa3509 100644
--- a/gcc/pretty-print.cc
+++ b/gcc/pretty-print.cc
@@ -679,7 +679,11 @@ mingw_ansi_fputs (const char *str, FILE *fp)
   /* Don't mess up stdio functions with Windows APIs.  */
   fflush (fp);
 
-  if (GetConsoleMode (h, &mode) && !(mode & 
ENABLE_VIRTUAL_TERMINAL_PROCESSING))
+  if (GetConsoleMode (h, &mode)
+#ifdef ENABLE_VIRTUAL_TERMINAL_PROCESSING
+  && !(mode & ENABLE_VIRTUAL_TERMINAL_PROCESSING)
+#endif
+  )
 /* If it is a console, and doesn't support ANSI escape codes, translate
them as needed.  */
 for (;;)


[gcc r15-4132] testsuite: Relax line number match in gfortran.dg/pr95690.f90

2024-10-08 Thread Andreas Schwab via Gcc-cvs
https://gcc.gnu.org/g:d022f6925702b0890a73613d659350b40f44f215

commit r15-4132-gd022f6925702b0890a73613d659350b40f44f215
Author: Andreas Schwab 
Date:   Wed Sep 11 13:08:30 2024 +0200

testsuite: Relax line number match in gfortran.dg/pr95690.f90

The actual line number is target dependent, and immaterial for the test.

* gfortran.dg/pr95690.f90: Allow matching error message anywhere.

Diff:
---
 gcc/testsuite/gfortran.dg/pr95690.f90 | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/gcc/testsuite/gfortran.dg/pr95690.f90 
b/gcc/testsuite/gfortran.dg/pr95690.f90
index 1432937438ac..4bd19b3dcdd0 100644
--- a/gcc/testsuite/gfortran.dg/pr95690.f90
+++ b/gcc/testsuite/gfortran.dg/pr95690.f90
@@ -2,8 +2,10 @@
 module m
 contains
subroutine s
-  print *, (erfc) ! { dg-error "not a floating constant" "" { target 
i?86-*-* x86_64-*-* sparc*-*-* cris-*-* hppa*-*-* } }
-   end ! { dg-error "not a floating constant" "" { target { ! "i?86-*-* 
x86_64-*-* sparc*-*-* cris-*-* hppa*-*-*" } } }
+  print *, (erfc)
+   end
function erfc()
end
 end
+! The actual line number is target dependent, allow any
+! { dg-error "not a floating constant" "" { target *-*-* } 0 }


[gcc r15-4133] Recompute TYPE_MODE and DECL_MODE for vector_type for accelerator.

2024-10-08 Thread Prathamesh Kulkarni via Gcc-cvs
https://gcc.gnu.org/g:ae88da5e070659d37b3c3daa4b880531769183bf

commit r15-4133-gae88da5e070659d37b3c3daa4b880531769183bf
Author: Prathamesh Kulkarni 
Date:   Tue Oct 8 12:38:31 2024 +0530

Recompute TYPE_MODE and DECL_MODE for vector_type for accelerator.

gcc/ChangeLog:
PR ipa/96265
* lto-streamer-in.cc (lto_read_tree_1): Set TYPE_MODE and DECL_MODE
for vector_type if offloading is enabled.
(lto_input_mode_table): Remove handling of vector modes.
* tree-streamer-out.cc (pack_ts_decl_common_value_fields): Stream 
out
VOIDmode for vector_type if offloading is enabled.
(pack_ts_decl_common_value_fields): Likewise.

Signed-off-by: Prathamesh Kulkarni 

Diff:
---
 gcc/lto-streamer-in.cc   | 38 --
 gcc/tree-streamer-out.cc |  6 --
 2 files changed, 28 insertions(+), 16 deletions(-)

diff --git a/gcc/lto-streamer-in.cc b/gcc/lto-streamer-in.cc
index 9d0ec5d589c4..15181c3f5746 100644
--- a/gcc/lto-streamer-in.cc
+++ b/gcc/lto-streamer-in.cc
@@ -1753,16 +1753,30 @@ lto_read_tree_1 (class lto_input_block *ib, class 
data_in *data_in, tree expr)
 with -g1, see for example PR113488.  */
   else if (DECL_P (expr) && DECL_ABSTRACT_ORIGIN (expr) == expr)
DECL_ABSTRACT_ORIGIN (expr) = NULL_TREE;
+}
 
 #ifdef ACCEL_COMPILER
-  if ((VAR_P (expr)
-  || TREE_CODE (expr) == PARM_DECL
-  || TREE_CODE (expr) == FIELD_DECL)
- && AGGREGATE_TYPE_P (TREE_TYPE (expr))
- && DECL_MODE (expr) == VOIDmode)
-   SET_DECL_MODE (expr, TYPE_MODE (TREE_TYPE (expr)));
-#endif
+  if ((VAR_P (expr)
+   || TREE_CODE (expr) == PARM_DECL
+   || TREE_CODE (expr) == FIELD_DECL)
+  && DECL_MODE (expr) == VOIDmode)
+{
+  tree type = TREE_TYPE (expr);
+  if (AGGREGATE_TYPE_P (type))
+   SET_DECL_MODE (expr, TYPE_MODE (type));
+  else if (VECTOR_TYPE_P (type))
+   SET_DECL_MODE (expr, TYPE_MODE_RAW (type));
 }
+
+  if (VECTOR_TYPE_P (expr) && TYPE_MODE (expr) == VOIDmode)
+{
+  poly_uint64 nunits = TYPE_VECTOR_SUBPARTS (expr);
+  tree innertype = TREE_TYPE (expr);
+  machine_mode vmode
+   = mode_for_vector (SCALAR_TYPE_MODE (innertype), nunits).else_blk ();
+  SET_TYPE_MODE (expr, vmode);
+}
+#endif
 }
 
 /* Read the physical representation of a tree node with tag TAG from
@@ -2106,13 +2120,9 @@ lto_input_mode_table (struct lto_file_decl_data 
*file_data)
case MODE_VECTOR_UFRACT:
case MODE_VECTOR_ACCUM:
case MODE_VECTOR_UACCUM:
- /* For unsupported vector modes just use BLKmode,
-if the scalar mode is supported.  */
- if (table[(int) inner] != VOIDmode)
-   {
- table[m] = BLKmode;
- break;
-   }
+ /* Vector modes are recomputed on accel side and shouldn't have
+been streamed-out from host.  */
+ gcc_unreachable ();
  /* FALLTHRU */
default:
  /* This is only used for offloading-target compilations and
diff --git a/gcc/tree-streamer-out.cc b/gcc/tree-streamer-out.cc
index 7de4447a1b53..81f5aeb30a6d 100644
--- a/gcc/tree-streamer-out.cc
+++ b/gcc/tree-streamer-out.cc
@@ -194,7 +194,8 @@ pack_ts_decl_common_value_fields (struct bitpack_d *bp, 
tree expr)
   && (VAR_P (expr)
  || TREE_CODE (expr) == PARM_DECL
  || TREE_CODE (expr) == FIELD_DECL)
-  && AGGREGATE_TYPE_P (TREE_TYPE (expr)))
+  && (AGGREGATE_TYPE_P (TREE_TYPE (expr))
+ || VECTOR_TYPE_P (TREE_TYPE (expr
 bp_pack_machine_mode (bp, VOIDmode);
   else
 bp_pack_machine_mode (bp, DECL_MODE (expr));
@@ -332,7 +333,8 @@ pack_ts_type_common_value_fields (struct bitpack_d *bp, 
tree expr)
  whose size is 256-bits, which is not representable on accelerator.
  Instead stream out VOIDmode, and while streaming-in, recompute
  appropriate TYPE_MODE for accelerator.  */
-  if (lto_stream_offload_p && AGGREGATE_TYPE_P (expr))
+  if (lto_stream_offload_p
+  && (AGGREGATE_TYPE_P (expr) || VECTOR_TYPE_P (expr)))
 bp_pack_machine_mode (bp, VOIDmode);
   /* for VECTOR_TYPE, TYPE_MODE reevaluates the mode using target_flags
  not necessary valid in a global context.


[gcc r15-4136] ada: Extend arm-android section of Makefile.rtl to aarch64

2024-10-08 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:39bd80bee89d68be08d5b41ad71adfb2ec6cff05

commit r15-4136-g39bd80bee89d68be08d5b41ad71adfb2ec6cff05
Author: Olivier Hainque 
Date:   Fri Aug 16 17:12:13 2024 +0200

ada: Extend arm-android section of Makefile.rtl to aarch64

gcc/ada/ChangeLog:

* Makefile.rtl: Extend arm-android section to aarch64, in a similar
fashion as other arm/arch64 configurations. Introduce pair
selection guards to prevent match of aarch64-linux-android on the
regular aarch64-linux% cross as well.

Diff:
---
 gcc/ada/Makefile.rtl | 228 +--
 1 file changed, 223 insertions(+), 5 deletions(-)

diff --git a/gcc/ada/Makefile.rtl b/gcc/ada/Makefile.rtl
index 1512c01f3f8c..9f4c6cd99dcd 100644
--- a/gcc/ada/Makefile.rtl
+++ b/gcc/ada/Makefile.rtl
@@ -1079,9 +1079,21 @@ GCC_SPEC_FILES=
 # $(strip STRING) removes leading and trailing spaces from STRING.
 # If what's left is null then it's a match.
 
+# Setup to make sure at most one match gets selected, useful for android
+# targets which are canonically configured with a linux-android target_os,
+# which would match filtering patterns such as linux% intended to match
+# only regular linux or linux64 variants.
+
+# The current set of selected pairs.  A new match remains allowed
+# as long as this isn't assigned a new value.
+SELECTED_PAIRS=PAIRS_NONE
+
 # PowerPC VxWorks6 and VxWorks7
+ifeq ($(SELECTED_PAIRS),PAIRS_NONE)
 ifeq ($(strip $(filter-out powerpc% wrs vxworks vxworks7%, $(target_cpu) 
$(target_vendor) $(target_os))),)
 
+  SELECTED_PAIRS=powerpc-vxworks
+
   ifeq ($(strip $(filter-out powerpc64, $(target_cpu))),)
  ARCH_STR=ppc64
   else
@@ -1189,10 +1201,14 @@ ifeq ($(strip $(filter-out powerpc% wrs vxworks 
vxworks7%, $(target_cpu) $(targe
 GCC_SPEC_FILES+=vxworks-smp-$(ARCH_STR)-link.spec
   endif
 endif
+endif
 
 # x86/x86_64 VxWorks7
+ifeq ($(SELECTED_PAIRS),PAIRS_NONE)
 ifeq ($(strip $(filter-out %86 x86_64 wrs vxworks7%, $(target_cpu) 
$(target_vendor) $(target_os))),)
 
+  SELECTED_PAIRS=x86-vxworks7
+
   LIBGNAT_TARGET_PAIRS= \
   a-intnam.adsexception propagation
+  # while aarch64 relies on kernel dwarf CFI.  And as a 64bit target,
+  # aarch64 can also incorporate support for 128bit arithmetic.
+
+  ifeq ($(strip $(filter-out arm%, $(target_cpu))),)
+ SELECTED_PAIRS=arm-android
+
+ EH_MECHANISM=-arm
+ SIGTRAMP_OBJ=sigtramp-armdroid.o
+  else
+ SELECTED_PAIRS=aarch64-android
+
+ EH_MECHANISM=-gcc
+ SIGTRAMP_OBJ=
+
+ LIBGNAT_TARGET_PAIRS += $(GNATRTL_128BIT_PAIRS)
+ EXTRA_GNATRTL_NONTASKING_OBJS = $(GNATRTL_128BIT_OBJS)
+  endif
+
+  EXTRA_LIBGNAT_OBJS+=$(SIGTRAMP_OBJ)
   EXTRA_LIBGNAT_SRCS+=sigtramp.h
-  EH_MECHANISM=-arm
   THREADSLIB =
   GNATLIB_SHARED = gnatlib-shared-dual
   LIBRARY_VERSION := $(LIB_VERSION)
 endif
+endif
 
 # ARM and AARCH64 QNX
+ifeq ($(SELECTED_PAIRS),PAIRS_NONE)
 ifeq ($(strip $(filter-out arm aarch64 %qnx,$(target_cpu) $(target_os))),)
+
+  SELECTED_PAIRS=arm-qnx
+
   LIBGNAT_TARGET_PAIRS = \
   a-intnam.ads

[gcc r15-4137] ada: Account for aarch64 in init.c section for Android

2024-10-08 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:3376bc79ba0833f9ad8a9ec4860aeb217710cb5b

commit r15-4137-g3376bc79ba0833f9ad8a9ec4860aeb217710cb5b
Author: Olivier Hainque 
Date:   Fri Aug 16 17:10:59 2024 +0200

ada: Account for aarch64 in init.c section for Android

Unlike the ARM port already there, aarch64 is dwarf CFI based
for unwinding and Android-Linux exposes kernel CFI for signal
handlers.

gcc/ada/ChangeLog:

* init.c (__gnat_error_handler): Map signals straight to Ada
exceptions, without a local CFI trampoline.
(__gnat_adjust_context_for_raise): Guard arm specific code on 
__arm__
compilation. Do nothing otherwise, relying on libgcc's signal
frame recognition for PC/RA adjustments.

Diff:
---
 gcc/ada/init.c | 12 
 1 file changed, 12 insertions(+)

diff --git a/gcc/ada/init.c b/gcc/ada/init.c
index 93e73f53c64c..ad51e2e054da 100644
--- a/gcc/ada/init.c
+++ b/gcc/ada/init.c
@@ -2782,10 +2782,16 @@ __gnat_install_handler ()
 void
 __gnat_adjust_context_for_raise (int signo ATTRIBUTE_UNUSED, void *ucontext)
 {
+#if defined(__arm__)
   mcontext_t *mcontext = &((ucontext_t *) ucontext)->uc_mcontext;
 
   /* ARM Bump has to be an even number because of odd/even architecture.  */
   ((mcontext_t *) mcontext)->arm_pc += 2;
+#endif
+
+  /* Other ports, based on dwarf2 unwinding, typically leverage
+ kernel CFI coordinated with libgcc's explicit support for signal
+ frames.  */
 }
 
 static void
@@ -2826,8 +2832,14 @@ __gnat_error_handler (int sig, siginfo_t *si, void 
*ucontext)
 {
   __gnat_adjust_context_for_raise (sig, ucontext);
 
+  /* The ARM port relies on a sigtramp.  Others such as aarch64,
+ dwarf info based, rely on kernel CFI.  */
+#if defined(__arm__)
   __gnat_sigtramp (sig, (void *) si, (void *) ucontext,
   (__sigtramphandler_t *)&__gnat_map_signal);
+#else
+  __gnat_map_signal (sig, si, ucontext);
+#endif
 }
 
 /* This must be in keeping with System.OS_Interface.Alternate_Stack_Size.  */


[gcc r15-4139] ada: Add System definitions of SIGSYS for Android

2024-10-08 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:c28066c154a7014efd5214dd5f653cab12451a31

commit r15-4139-gc28066c154a7014efd5214dd5f653cab12451a31
Author: Olivier Hainque 
Date:   Mon Aug 26 17:49:12 2024 +0200

ada: Add System definitions of SIGSYS for Android

This allows reusing a-intnam__linux.ads for Android.

gcc/ada/ChangeLog:

* libgnarl/s-linux__android-arm.ads: Define SIGSYS.
* libgnarl/s-linux__android-aarch64.ads: Define SIGSYS.
* libgnarl/s-osinte__android.ads: Expose SIGSYS value.

Diff:
---
 gcc/ada/libgnarl/s-linux__android-aarch64.ads | 1 +
 gcc/ada/libgnarl/s-linux__android-arm.ads | 1 +
 gcc/ada/libgnarl/s-osinte__android.ads| 1 +
 3 files changed, 3 insertions(+)

diff --git a/gcc/ada/libgnarl/s-linux__android-aarch64.ads 
b/gcc/ada/libgnarl/s-linux__android-aarch64.ads
index 6c64626c2941..4e462f2709c7 100644
--- a/gcc/ada/libgnarl/s-linux__android-aarch64.ads
+++ b/gcc/ada/libgnarl/s-linux__android-aarch64.ads
@@ -111,6 +111,7 @@ package System.Linux is
SIGPROF: constant := 27; --  profiling timer expired
SIGXCPU: constant := 24; --  CPU time limit exceeded
SIGXFSZ: constant := 25; --  filesize limit exceeded
+   SIGSYS : constant := 31; --  bad argument to system call
SIGUNUSED  : constant := 31; --  unused signal (GNU/Linux)
SIGSTKFLT  : constant := 16; --  coprocessor stack fault (Linux)
SIG32  : constant := 32; --  glibc internal signal
diff --git a/gcc/ada/libgnarl/s-linux__android-arm.ads 
b/gcc/ada/libgnarl/s-linux__android-arm.ads
index ff369d50f83c..1a21f78ffd8c 100644
--- a/gcc/ada/libgnarl/s-linux__android-arm.ads
+++ b/gcc/ada/libgnarl/s-linux__android-arm.ads
@@ -111,6 +111,7 @@ package System.Linux is
SIGPROF: constant := 27; --  profiling timer expired
SIGXCPU: constant := 24; --  CPU time limit exceeded
SIGXFSZ: constant := 25; --  filesize limit exceeded
+   SIGSYS : constant := 31; --  bad argument to system call
SIGUNUSED  : constant := 31; --  unused signal (GNU/Linux)
SIGSTKFLT  : constant := 16; --  coprocessor stack fault (Linux)
SIG32  : constant := 32; --  glibc internal signal
diff --git a/gcc/ada/libgnarl/s-osinte__android.ads 
b/gcc/ada/libgnarl/s-osinte__android.ads
index 62389061fec5..ee8319890c73 100644
--- a/gcc/ada/libgnarl/s-osinte__android.ads
+++ b/gcc/ada/libgnarl/s-osinte__android.ads
@@ -116,6 +116,7 @@ package System.OS_Interface is
SIGPROF: constant := System.Linux.SIGPROF;
SIGXCPU: constant := System.Linux.SIGXCPU;
SIGXFSZ: constant := System.Linux.SIGXFSZ;
+   SIGSYS : constant := System.Linux.SIGSYS;
SIGUNUSED  : constant := System.Linux.SIGUNUSED;
SIGSTKFLT  : constant := System.Linux.SIGSTKFLT;


[gcc r15-4184] RISC-V: Add implication for M extension.

2024-10-08 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:0a193466f2e87acef9b86e0d086bc6f6017518b0

commit r15-4184-g0a193466f2e87acef9b86e0d086bc6f6017518b0
Author: Tsung Chun Lin 
Date:   Tue Oct 8 17:40:59 2024 -0600

RISC-V: Add implication for M extension.

That M implies Zmmul.

gcc/ChangeLog:

* common/config/riscv/riscv-common.cc: M implies Zmmul.

Diff:
---
 gcc/common/config/riscv/riscv-common.cc | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/gcc/common/config/riscv/riscv-common.cc 
b/gcc/common/config/riscv/riscv-common.cc
index 2adebe0b6f29..60595a3e3561 100644
--- a/gcc/common/config/riscv/riscv-common.cc
+++ b/gcc/common/config/riscv/riscv-common.cc
@@ -75,6 +75,8 @@ struct riscv_implied_info_t
 /* Implied ISA info, must end with NULL sentinel.  */
 static const riscv_implied_info_t riscv_implied_info[] =
 {
+  {"m", "zmmul"},
+
   {"d", "f"},
   {"f", "zicsr"},
   {"d", "zicsr"},


[gcc r15-4185] RISC-V: Enable builtin __riscv_mul with Zmmul extension.

2024-10-08 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:2990f5802a727cbd717587c3a345fa940193049f

commit r15-4185-g2990f5802a727cbd717587c3a345fa940193049f
Author: Tsung Chun Lin 
Date:   Tue Oct 8 17:44:38 2024 -0600

RISC-V: Enable builtin __riscv_mul with Zmmul extension.

From d5b254e19d1f37fe27c7e98a0160e5c22446cfea Mon Sep 17 00:00:00 2001
From: Jim Lin 
Date: Tue, 8 Oct 2024 13:14:32 +0800
Subject: [PATCH] RISC-V: Enable builtin __riscv_mul with Zmmul extension.

gcc/ChangeLog:

* config/riscv/riscv-c.cc: (riscv_cpu_cpp_builtins):
Enable builtin __riscv_mul with Zmmul extension.

Diff:
---
 gcc/config/riscv/riscv-c.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/config/riscv/riscv-c.cc b/gcc/config/riscv/riscv-c.cc
index 71112d9c66d7..7e9c478e97bb 100644
--- a/gcc/config/riscv/riscv-c.cc
+++ b/gcc/config/riscv/riscv-c.cc
@@ -123,7 +123,7 @@ riscv_cpu_cpp_builtins (cpp_reader *pfile)
   if (TARGET_ATOMIC)
 builtin_define ("__riscv_atomic");
 
-  if (TARGET_MUL)
+  if (TARGET_ZMMUL)
 builtin_define ("__riscv_mul");
   if (TARGET_DIV)
 builtin_define ("__riscv_div");


[gcc r15-4186] tree-optimization/116024 - simplify C1-X cmp C2 for UB-on-overflow types

2024-10-08 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:0883c88664d48463dfc79335dccaf15a69230952

commit r15-4186-g0883c88664d48463dfc79335dccaf15a69230952
Author: Artemiy Volkov 
Date:   Tue Oct 8 17:51:08 2024 -0600

tree-optimization/116024 - simplify C1-X cmp C2 for UB-on-overflow types

Implement a match.pd pattern for C1 - X cmp C2, where C1 and C2 are
integer constants and X is of a UB-on-overflow type.  The pattern is
simplified to X rcmp C1 - C2 by moving X and C2 to the other side of the
comparison (with opposite signs).  If C1 - C2 happens to overflow,
replace the whole expression with either a constant 0 or a constant 1
node, depending on the comparison operator and the sign of the overflow.

This transformation allows to occasionally save load-immediate /
subtraction instructions, e.g. the following statement:

10 - (int) x <= 9;

now compiles to

sgt a0,a0,zero

instead of

li  a5,10
sub a0,a5,a0
sltia0,a0,10

on 32-bit RISC-V.

Additional examples can be found in the newly added test file. This
patch has been bootstrapped and regtested on aarch64, x86_64, and
i386, and additionally regtested on riscv32.  Existing tests were
adjusted where necessary.

gcc/ChangeLog:

PR tree-optimization/116024
* match.pd: New transformation around integer comparison.

gcc/testsuite/ChangeLog:

* gcc.dg/tree-ssa/pr116024.c: New test.
* gcc.dg/pr67089-6.c: Adjust.

Diff:
---
 gcc/match.pd | 26 +
 gcc/testsuite/gcc.dg/pr67089-6.c |  4 +-
 gcc/testsuite/gcc.dg/tree-ssa/pr116024.c | 66 
 3 files changed, 94 insertions(+), 2 deletions(-)

diff --git a/gcc/match.pd b/gcc/match.pd
index 6a924f409d9e..d2b7f81df9a1 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -9059,6 +9059,32 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
}
(cmp @0 { res; })
 
+/* Invert sign of X in comparisons of the form C1 - X CMP C2.  */
+
+(for cmp (lt le gt ge eq ne)
+ rcmp (gt ge lt le eq ne)
+  (simplify
+   (cmp (minus INTEGER_CST@0 @1) INTEGER_CST@2)
+/* For UB-on-overflow types, simply switch sides for X and C2
+   to arrive at X RCMP C1 - C2, handling the case when the latter
+   expression overflows.  */
+   (if (!TREE_OVERFLOW (@0) && !TREE_OVERFLOW (@2)
+   && TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (@1)))
+ (with { tree res = int_const_binop (MINUS_EXPR, @0, @2); }
+  (if (TREE_OVERFLOW (res))
+   (switch
+(if (cmp == NE_EXPR)
+ { constant_boolean_node (true, type); })
+(if (cmp == EQ_EXPR)
+ { constant_boolean_node (false, type); })
+{
+  bool less = cmp == LE_EXPR || cmp == LT_EXPR;
+  bool ovf_high = wi::lt_p (wi::to_wide (@0), 0,
+TYPE_SIGN (TREE_TYPE (@0)));
+  constant_boolean_node (less == ovf_high, type);
+})
+  (rcmp @1 { res; }))
+
 /* Canonicalizations of BIT_FIELD_REFs.  */
 
 (simplify
diff --git a/gcc/testsuite/gcc.dg/pr67089-6.c b/gcc/testsuite/gcc.dg/pr67089-6.c
index b59d75b23180..80a33c3f3e2b 100644
--- a/gcc/testsuite/gcc.dg/pr67089-6.c
+++ b/gcc/testsuite/gcc.dg/pr67089-6.c
@@ -57,5 +57,5 @@ T (25, unsigned short, 2U - x, if (r > 2U) foo (0))
 T (26, unsigned char, 2U - x, if (r <= 2U) foo (0))
 
 /* { dg-final { scan-tree-dump-times "ADD_OVERFLOW" 16 "widening_mul" { target 
{ i?86-*-* x86_64-*-* } } } } */
-/* { dg-final { scan-tree-dump-times "SUB_OVERFLOW" 11 "widening_mul" { target 
{ { i?86-*-* x86_64-*-* } && { ! ia32 } } } } } */
-/* { dg-final { scan-tree-dump-times "SUB_OVERFLOW" 9 "widening_mul" { target 
{ { i?86-*-* x86_64-*-* } && ia32 } } } } */
+/* { dg-final { scan-tree-dump-times "SUB_OVERFLOW" 9 "widening_mul" { target 
{ { i?86-*-* x86_64-*-* } && { ! ia32 } } } } } */
+/* { dg-final { scan-tree-dump-times "SUB_OVERFLOW" 7 "widening_mul" { target 
{ { i?86-*-* x86_64-*-* } && ia32 } } } } */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr116024.c 
b/gcc/testsuite/gcc.dg/tree-ssa/pr116024.c
new file mode 100644
index ..6efa0c2f916f
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr116024.c
@@ -0,0 +1,66 @@
+/* PR tree-optimization/116024 */
+/* { dg-do compile } */
+/* { dg-options "-O1 -fdump-tree-forwprop1-details" } */
+
+#include 
+#include 
+
+uint32_t f(void);
+
+int32_t i1(void)
+{
+  int32_t l = 10 - (int32_t)f();
+  return l <= 9; // f() > 0
+}
+
+int32_t i1a(void)
+{
+  int32_t l = 20 - (int32_t)f();
+  return l <= INT32_MIN; // return 0
+}
+
+int32_t i1b(void)
+{
+  int32_t l = 30 - (int32_t)f();
+  return l <= INT32_MIN + 31; // f() == INT32_MAX
+}
+
+int32_t i1c(void)
+{
+  int32_t l = INT32_MAX - 40 - (int32_t)f();
+  return l <= -38; // f() > INT32_MAX - 3
+}
+
+int32_t i1d(void)
+{
+  int32_t l = INT32_MAX - 50 - (int32_t)f();
+  return l <= INT32_MAX - 1; // f() != -50
+

[gcc r15-4187] tree-optimization/116024 - simplify C1-X cmp C2 for unsigned types

2024-10-08 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:65b33d43d29b148e127b1ba997f1bbc2c7028b94

commit r15-4187-g65b33d43d29b148e127b1ba997f1bbc2c7028b94
Author: Artemiy Volkov 
Date:   Tue Oct 8 17:54:55 2024 -0600

tree-optimization/116024 - simplify C1-X cmp C2 for unsigned types

Implement a match.pd transformation inverting the sign of X in
C1 - X cmp C2, where C1 and C2 are integer constants and X is
of an unsigned type, by observing that:

(a) If cmp is == or !=, simply move X and C2 to opposite sides of the
comparison to arrive at X cmp C1 - C2.

(b) If cmp is <:
- C1 - X < C2 means that C1 - X spans the range of 0, 1, ..., C2 - 
1;
- This means that X spans the range of C1 - (C2 - 1),
  C1 - (C2 - 2), ..., C1;
- Subtracting C1 - (C2 - 1), X - (C1 - (C2 - 1)) is one of 0, 1,
  ..., C1 - (C1 - (C2 - 1));
- Simplifying the above, X - (C1 - C2 + 1) is one of 0, 1, ...,
 C2 - 1;
- Summarizing, the expression C1 - X < C2 can be transformed
  into X - (C1 - C2 + 1) < C2.

(c) Similarly, if cmp is <=:
- C1 - X <= C2 means that C1 - X is one of 0, 1, ..., C2;
- It follows that X is one of C1 - C2, C1 - (C2 - 1), ..., C1;
- Subtracting C1 - C2, X - (C1 - C2) has range 0, 1, ..., C2;
- Thus, the expression C1 - X <= C2 can be transformed into
  X - (C1 - C2) <= C2.

(d) The >= and > cases are negations of (b) and (c), respectively.

This transformation allows to occasionally save load-immediate /
subtraction instructions, e.g. the following statement:

300 - (unsigned int)f() < 100;

now compiles to

addia0,a0,-201
sltiu   a0,a0,100

instead of

li  a5,300
sub a0,a5,a0
sltiu   a0,a0,100

on 32-bit RISC-V.

Additional examples can be found in the newly added test file.  This
patch has been bootstrapped and regtested on aarch64, x86_64, and i386,
and additionally regtested on riscv32.

gcc/ChangeLog:

PR tree-optimization/116024
* match.pd: New transformation around integer comparison.

gcc/testsuite/ChangeLog:

* gcc.dg/tree-ssa/pr116024-1.c: New test.

Diff:
---
 gcc/match.pd   | 23 ++-
 gcc/testsuite/gcc.dg/tree-ssa/pr116024-1.c | 65 ++
 2 files changed, 87 insertions(+), 1 deletion(-)

diff --git a/gcc/match.pd b/gcc/match.pd
index d2b7f81df9a1..c0be76a30518 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -9083,7 +9083,28 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
 TYPE_SIGN (TREE_TYPE (@0)));
   constant_boolean_node (less == ovf_high, type);
 })
-  (rcmp @1 { res; }))
+  (rcmp @1 { res; })))
+/* For unsigned types, transform like so (using < as example):
+C1 - X < C2
+  ==>  C1 - X = { 0, 1, ..., C2 - 1 }
+  ==>  X = { C1 - (C2 - 1), ..., C1 + 1, C1 }
+  ==>  X - (C1 - (C2 - 1)) = { 0, 1, ..., C1 - (C1 - (C2 - 1)) }
+  ==>  X - (C1 - C2 + 1) = { 0, 1, ..., C2 - 1 }
+  ==>  X - (C1 - C2 + 1) < C2.
+
+  Similarly,
+C1 - X <= C2 ==> X - (C1 - C2) <= C2;
+C1 - X >= C2 ==> X - (C1 - C2 + 1) >= C2;
+C1 - X > C2 ==> X - (C1 - C2) > C2.  */
+   (if (TYPE_UNSIGNED (TREE_TYPE (@1)))
+ (switch
+   (if (cmp == EQ_EXPR || cmp == NE_EXPR)
+(cmp @1 (minus @0 @2)))
+   (if (cmp == LE_EXPR || cmp == GT_EXPR)
+(cmp (plus @1 (minus @2 @0)) @2))
+   (if (cmp == LT_EXPR || cmp == GE_EXPR)
+(cmp (plus @1 (minus @2
+  (plus @0 { build_one_cst (TREE_TYPE (@1)); }))) @2)))
 
 /* Canonicalizations of BIT_FIELD_REFs.  */
 
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr116024-1.c 
b/gcc/testsuite/gcc.dg/tree-ssa/pr116024-1.c
new file mode 100644
index ..91cb6a7c4f14
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr116024-1.c
@@ -0,0 +1,65 @@
+/* PR tree-optimization/116024 */
+/* { dg-do compile } */
+/* { dg-options "-O1 -fdump-tree-forwprop1-details" } */
+
+#include 
+
+uint32_t f(void);
+
+int32_t i2(void)
+{
+  uint32_t l = 10 - (uint32_t)f();
+  return l <= 20; // f() + 10 <= 20 
+}
+
+int32_t i2a(void)
+{
+  uint32_t l = 10 - (uint32_t)f();
+  return l < 30; // f() + 19 < 30 
+}
+
+int32_t i2b(void)
+{
+  uint32_t l = 200 - (uint32_t)f();
+  return l <= 100; // f() - 100 <= 100 
+}
+
+int32_t i2c(void)
+{
+  uint32_t l = 300 - (uint32_t)f();
+  return l < 100; // f() - 201 < 100
+}
+
+int32_t i2d(void)
+{
+  uint32_t l = 1000 - (uint32_t)f();
+  return l >= 2000; // f() + 999 >= 2000
+}
+
+int32_t i2e(void)
+{
+  uint32_t l = 1000 - (uint32_t)f();
+  return l > 3000; // f() + 2000 > 3000
+}
+
+int32_t i2f(void)
+{
+  uint32_t l = 2 - (uint32_t)f();
+  return l >= 1; // f() - 10001 >= 1
+}
+
+int32_t i2g(void)
+{
+  ui

[gcc r15-4188] tree-optimization/116024 - simplify C1-X cmp C2 for wrapping signed types

2024-10-08 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:e5f5cffb8c8243896a9d3bd0e2b8f14c70f8df1e

commit r15-4188-ge5f5cffb8c8243896a9d3bd0e2b8f14c70f8df1e
Author: Artemiy Volkov 
Date:   Tue Oct 8 18:04:13 2024 -0600

tree-optimization/116024 - simplify C1-X cmp C2 for wrapping signed types

Implement a match.pd transformation inverting the sign of X in
C1 - X cmp C2, where C1 and C2 are integer constants and X is
of a wrapping signed type, by observing that:

(a) If cmp is == or !=, simply move X and C2 to opposite sides of
the comparison to arrive at X cmp C1 - C2.

(b) If cmp is <:
- C1 - X < C2 means that C1 - X spans the values of -INF,
  -INF + 1, ..., C2 - 1;
- Therefore, X is one of C1 - -INF, C1 - (-INF + 1), ...,
  C1 - C2 + 1;
- Subtracting (C1 + 1), X - (C1 + 1) is one of - (-INF) - 1,
  - (-INF) - 2, ..., -C2;
- Using the fact that - (-INF) - 1 is +INF, derive that
  X - (C1 + 1) spans the values +INF, +INF - 1, ..., -C2;
- Thus, the original expression can be simplified to
  X - (C1 + 1) > -C2 - 1.

(c) Similarly, C1 - X <= C2 is equivalent to X - (C1 + 1) >= -C2 - 1.

(d) The >= and > cases are negations of (b) and (c), respectively.

(e) In all cases, the expression -C2 - 1 can be shortened to
bit_not (C2).

This transformation allows to occasionally save load-immediate /
subtraction instructions, e.g. the following statement:

10 - (int)f() >= 20;

now compiles to

addia0,a0,-11
sltia0,a0,-20

instead of

li  a5,10
sub a0,a5,a0
sltit0,a0,20
xoria0,t0,1

on 32-bit RISC-V when compiled with -fwrapv.

Additional examples can be found in the newly added test file.  This
patch has been bootstrapped and regtested on aarch64, x86_64, and i386,
and additionally regtested on riscv32.

gcc/ChangeLog:

PR tree-optimization/116024
* match.pd: New transformation around integer comparison.

gcc/testsuite/ChangeLog:

* gcc.dg/tree-ssa/pr116024-1-fwrapv.c: New test.

Diff:
---
 gcc/match.pd  | 21 +++-
 gcc/testsuite/gcc.dg/tree-ssa/pr116024-1-fwrapv.c | 65 +++
 2 files changed, 85 insertions(+), 1 deletion(-)

diff --git a/gcc/match.pd b/gcc/match.pd
index c0be76a30518..baa6d2f5fd7d 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -9104,7 +9104,26 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
 (cmp (plus @1 (minus @2 @0)) @2))
(if (cmp == LT_EXPR || cmp == GE_EXPR)
 (cmp (plus @1 (minus @2
-  (plus @0 { build_one_cst (TREE_TYPE (@1)); }))) @2)))
+  (plus @0 { build_one_cst (TREE_TYPE (@1)); }))) @2)))
+/* For wrapping signed types (-fwrapv), transform like so (using < as example):
+C1 - X < C2
+  ==>  C1 - X = { -INF, -INF + 1, ..., C2 - 1 }
+  ==>  X = { C1 - (-INF), C1 - (-INF + 1), ..., C1 - C2 + 1 }
+  ==>  X - (C1 + 1) = { - (-INF) - 1, - (-INF) - 2, ..., -C2 }
+  ==>  X - (C1 + 1) = { +INF, +INF - 1, ..., -C2 }
+  ==>  X - (C1 + 1) > -C2 - 1
+  ==>  X - (C1 + 1) > bit_not (C2)
+
+  Similarly,
+C1 - X <= C2 ==> X - (C1 + 1) >= bit_not (C2);
+C1 - X >= C2 ==> X - (C1 + 1) <= bit_not (C2);
+C1 - X > C2 ==> X - (C1 + 1) < bit_not (C2).  */
+   (if (!TYPE_UNSIGNED (TREE_TYPE (@1))
+   && TYPE_OVERFLOW_WRAPS (TREE_TYPE (@1)))
+ (if (cmp == EQ_EXPR || cmp == NE_EXPR)
+   (cmp @1 (minus @0 @2))
+ (rcmp (minus @1 (plus @0 { build_one_cst (TREE_TYPE (@1)); }))
+(bit_not @2
 
 /* Canonicalizations of BIT_FIELD_REFs.  */
 
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr116024-1-fwrapv.c 
b/gcc/testsuite/gcc.dg/tree-ssa/pr116024-1-fwrapv.c
new file mode 100644
index ..24e1abef7742
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr116024-1-fwrapv.c
@@ -0,0 +1,65 @@
+/* PR tree-optimization/116024 */
+/* { dg-do compile } */
+/* { dg-options "-O1 -fdump-tree-forwprop1-details -fwrapv" } */
+
+#include 
+
+uint32_t f(void);
+
+int32_t i2(void)
+{
+  int32_t l = 10 - (int32_t)f();
+  return l <= 20; // f() - 11 >= -21
+}
+
+int32_t i2a(void)
+{
+  int32_t l = 10 - (int32_t)f();
+  return l < 30; // f() - 11 > -31
+}
+
+int32_t i2b(void)
+{
+  int32_t l = 200 - (int32_t)f();
+  return l <= 100; // f() - 201 >= -101
+}
+
+int32_t i2c(void)
+{
+  int32_t l = 300 - (int32_t)f();
+  return l < 100; // f() - 301 > -101
+}
+
+int32_t i2d(void)
+{
+  int32_t l = 1000 - (int32_t)f();
+  return l >= 2000; // f() - 1001 <= -2001
+}
+
+int32_t i2e(void)
+{
+  int32_t l = 1000 - (int32_t)f();
+  return l > 3000; // f() - 1001 < -3001
+}
+
+int32_t i2f(void)
+{
+  int32_t l = 2 - (int32_t)f();
+  return l >= 1; // f() - 20001 <= -10001
+}
+
+int32_t i2g(void)
+{
+  int32_t l = 300

[gcc r15-4189] tree-optimization/116024 - simplify some cases of X +- C1 cmp C2

2024-10-08 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:52fdf1e7eb89a148a9cdd1daade524f4540ab5fa

commit r15-4189-g52fdf1e7eb89a148a9cdd1daade524f4540ab5fa
Author: Artemiy Volkov 
Date:   Tue Oct 8 18:06:23 2024 -0600

tree-optimization/116024 - simplify some cases of X +- C1 cmp C2

Whenever C1 and C2 are integer constants, X is of a wrapping type, and
cmp is a relational operator, the expression X +- C1 cmp C2 can be
simplified in the following cases:

(a) If cmp is <= and C2 -+ C1 == +INF(1), we can transform the initial
comparison in the following way:
   X +- C1 <= C2
   -INF <= X +- C1 <= C2 (add left hand side which holds for any X, C1)
   -INF -+ C1 <= X <= C2 -+ C1 (add -+C1 to all 3 expressions)
   -INF -+ C1 <= X <= +INF (due to (1))
   -INF -+ C1 <= X (eliminate the right hand side since it holds for any X)

(b) By analogy, if cmp if >= and C2 -+ C1 == -INF(1), use the following
sequence of transformations:

   X +- C1 >= C2
   +INF >= X +- C1 >= C2 (add left hand side which holds for any X, C1)
   +INF -+ C1 >= X >= C2 -+ C1 (add -+C1 to all 3 expressions)
   +INF -+ C1 >= X >= -INF (due to (1))
   +INF -+ C1 >= X (eliminate the right hand side since it holds for any X)

(c) The > and < cases are negations of (a) and (b), respectively.

This transformation allows to occasionally save add / sub instructions,
for instance the expression

3 + (uint32_t)f() < 2

compiles to

cmn w0, #4
csetw0, ls

instead of

add w0, w0, 3
cmp w0, 2
csetw0, ls

on aarch64.

Testcases that go together with this patch have been split into two
separate files, one containing testcases for unsigned variables and the
other for wrapping signed ones (and thus compiled with -fwrapv).
Additionally, one aarch64 test has been adjusted since the patch has
caused the generated code to change from

cmn w0, #2
csinc   w0, w1, wzr, cc   (x < -2)

to

cmn w0, #3
csinc   w0, w1, wzr, cs   (x <= -3)

This patch has been bootstrapped and regtested on aarch64, x86_64, and
i386, and additionally regtested on riscv32.

gcc/ChangeLog:

PR tree-optimization/116024
* match.pd: New transformation around integer comparison.

gcc/testsuite/ChangeLog:

* gcc.dg/tree-ssa/pr116024-2.c: New test.
* gcc.dg/tree-ssa/pr116024-2-fwrapv.c: Ditto.
* gcc.target/aarch64/gtu_to_ltu_cmp_1.c: Adjust.

Diff:
---
 gcc/match.pd   | 43 +-
 gcc/testsuite/gcc.dg/tree-ssa/pr116024-2-fwrapv.c  | 38 +++
 gcc/testsuite/gcc.dg/tree-ssa/pr116024-2.c | 37 +++
 .../gcc.target/aarch64/gtu_to_ltu_cmp_1.c  |  2 +-
 4 files changed, 118 insertions(+), 2 deletions(-)

diff --git a/gcc/match.pd b/gcc/match.pd
index baa6d2f5fd7d..e73bb7e2109b 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -9030,6 +9030,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
(cmp @0 { TREE_OVERFLOW (res)
 ? drop_tree_overflow (res) : res; }
 (for cmp (lt le gt ge)
+ rcmp (gt ge lt le)
  (for op (plus minus)
   rop (minus plus)
   (simplify
@@ -9057,7 +9058,47 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
  "X cmp C2 -+ C1"),
 WARN_STRICT_OVERFLOW_COMPARISON);
}
-   (cmp @0 { res; })
+   (cmp @0 { res; })
+/* For wrapping types, simplify the following cases of X +- C1 CMP C2:
+
+   (a) If CMP is <= and C2 -+ C1 == +INF (1), simplify to X >= -INF -+ C1
+   by observing the following:
+
+   X +- C1 <= C2
+  ==>  -INF <= X +- C1 <= C2 (add left hand side which holds for any X, C1)
+  ==>  -INF -+ C1 <= X <= C2 -+ C1 (add -+C1 to all 3 expressions)
+  ==>  -INF -+ C1 <= X <= +INF (due to (1))
+  ==>  -INF -+ C1 <= X (eliminate the right hand side since it holds for any X)
+
+(b) Similarly, if CMP is >= and C2 -+ C1 == -INF (1):
+
+   X +- C1 >= C2
+  ==>  +INF >= X +- C1 >= C2 (add left hand side which holds for any X, C1)
+  ==>  +INF -+ C1 >= X >= C2 -+ C1 (add -+C1 to all 3 expressions)
+  ==>  +INF -+ C1 >= X >= -INF (due to (1))
+  ==>  +INF -+ C1 >= X (eliminate the right hand side since it holds for any X)
+
+(c) The > and < cases are negations of (a) and (b), respectively.  */
+   (if (TYPE_OVERFLOW_WRAPS (TREE_TYPE (@0)))
+ (with
+   {
+   wide_int max = wi::max_value (TREE_TYPE (@0));
+   wide_int min = wi::min_value (TREE_TYPE (@0));
+
+   wide_int c2 = rop == PLUS_EXPR
+ ? wi::add (wi::to_wide (@2), wi::to_wide (@1))
+ : wi::sub (wi::to_wide (@2), wi::to_wide (@1));
+   }
+   (if (((cmp == LE_EXPR || cmp == GT_EXPR) && wi::eq_p (c2, max))
+   || ((cmp == LT_E

[gcc r15-4172] LoongArch: Fix up r15-4130

2024-10-08 Thread Xi Ruoyao via Gcc-cvs
https://gcc.gnu.org/g:60e99901aef8e7efd4d60adf9f82021fcbd1101f

commit r15-4172-g60e99901aef8e7efd4d60adf9f82021fcbd1101f
Author: Xi Ruoyao 
Date:   Wed Jul 10 12:15:23 2024 +0800

LoongArch: Fix up r15-4130

An earlier version of the patch (lacking the regeneration of some files)
was pushed.  Fix it up now.

gcc/ChangeLog:

* config/loongarch/loongarch.opt: Regenerate.
* config/loongarch/loongarch.opt.urls: Regenerate.

Diff:
---
 gcc/config/loongarch/loongarch.opt  | 2 +-
 gcc/config/loongarch/loongarch.opt.urls | 3 +++
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/gcc/config/loongarch/loongarch.opt 
b/gcc/config/loongarch/loongarch.opt
index 6a396b539c46..fae575452fe0 100644
--- a/gcc/config/loongarch/loongarch.opt
+++ b/gcc/config/loongarch/loongarch.opt
@@ -312,7 +312,7 @@ HOST_WIDE_INT la_isa_evolution = 0
 
 mannotate-tablejump
 Target Mask(ANNOTATE_TABLEJUMP) Save
-Annotate table jump instruction (jr {reg}) to correlate it with the jump table
+Annotate table jump instruction (jr {reg}) to correlate it with the jump table.
 
 mfrecipe
 Target Mask(ISA_FRECIPE) Var(la_isa_evolution)
diff --git a/gcc/config/loongarch/loongarch.opt.urls 
b/gcc/config/loongarch/loongarch.opt.urls
index f7545f651039..571c504e61d7 100644
--- a/gcc/config/loongarch/loongarch.opt.urls
+++ b/gcc/config/loongarch/loongarch.opt.urls
@@ -72,6 +72,9 @@ UrlSuffix(gcc/LoongArch-Options.html#index-mpass-mrelax-to-as)
 mtls-dialect=
 UrlSuffix(gcc/LoongArch-Options.html#index-mtls-dialect-1)
 
+mannotate-tablejump
+UrlSuffix(gcc/LoongArch-Options.html#index-mannotate-tablejump)
+
 mfrecipe
 UrlSuffix(gcc/LoongArch-Options.html#index-mfrecipe)


[gcc r15-4144] ada: Add adareducer integration to ICE handling

2024-10-08 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:65491166ddbc83b7283b42dc6d6451668acd9f22

commit r15-4144-g65491166ddbc83b7283b42dc6d6451668acd9f22
Author: Ronan Desplanques 
Date:   Wed Sep 4 15:27:01 2024 +0200

ada: Add adareducer integration to ICE handling

This patch adds a way to have the adareducer tool run on a appropriate
set of files when GNAT crashes. This feature is behind the -gnatd_m
debugging switch.

gcc/ada/ChangeLog:
* comperr.adb (Compiler_Abort): Add call to
Generate_Minimal_Reproducer and replace call to Namet.Unlock with
call to Unlock_If_Locked.
* debug.adb: Document new purpose of -gnatd_m and -gnatd_M.
* fname-uf.adb (Instantiate_SFN_Pattern): New procedure.
(Get_Default_File_Name): New function.
(Get_File_Name): Replace inline code with call to
Instantiate_SFN_Pattern.
* fname-uf.ads (Get_Default_File_Name): New function.
* generate_minimal_reproducer.adb (Generate_Minimal_Reproducer):
New procedure.
* namet.adb (Unlock_If_Locked): New function.
* namet.ads (Unlock_If_Locked): Likewise.
* par-prag.adb (Prag): Add special behavior with -gnatd_M.
* set_targ.adb: Minor fixes to comments.
* gcc-interface/Make-lang.in: Update list of object files.

Diff:
---
 gcc/ada/comperr.adb |  12 +-
 gcc/ada/debug.adb   |   4 +-
 gcc/ada/fname-uf.adb| 301 -
 gcc/ada/fname-uf.ads|   3 +
 gcc/ada/gcc-interface/Make-lang.in  |   2 +
 gcc/ada/generate_minimal_reproducer.adb | 455 
 gcc/ada/namet.adb   |  11 +
 gcc/ada/namet.ads   |   3 +
 gcc/ada/par-prag.adb|   6 +
 gcc/ada/set_targ.adb|   4 +-
 10 files changed, 667 insertions(+), 134 deletions(-)

diff --git a/gcc/ada/comperr.adb b/gcc/ada/comperr.adb
index 2623eed877da..e411ddb5d298 100644
--- a/gcc/ada/comperr.adb
+++ b/gcc/ada/comperr.adb
@@ -30,6 +30,7 @@
 with Atree;  use Atree;
 with Debug;  use Debug;
 with Errout; use Errout;
+with Generate_Minimal_Reproducer;
 with Gnatvsn;use Gnatvsn;
 with Lib;use Lib;
 with Namet;  use Namet;
@@ -263,7 +264,7 @@ package body Comperr is
 Src : Source_Buffer_Ptr;
 
  begin
-Namet.Unlock;
+Namet.Unlock_If_Locked;
 Name_Buffer (1 .. 12) := "gnat_bug.box";
 Name_Len := 12;
 Read_Source_File (Name_Enter, 0, Hi, Src, FD);
@@ -403,6 +404,14 @@ package body Comperr is
Write_Str ("list may be incomplete");
  end;
 
+ begin
+if Debug_Flag_Underscore_M then
+   Generate_Minimal_Reproducer;
+end if;
+ exception
+when others => null;
+ end;
+
  Write_Eol;
  Set_Standard_Output;
 
@@ -539,5 +548,4 @@ package body Comperr is
 
   Write_Char (After);
end Repeat_Char;
-
 end Comperr;
diff --git a/gcc/ada/debug.adb b/gcc/ada/debug.adb
index 2c0bff09e9d1..3dbf3a7b3976 100644
--- a/gcc/ada/debug.adb
+++ b/gcc/ada/debug.adb
@@ -150,7 +150,7 @@ package body Debug is
--  d_j  Read JSON files and populate Repinfo tables (opposite of -gnatRjs)
--  d_k  In CodePeer mode disable expansion of assertion checks
--  d_l  Disable strict alignment of array types with aliased component
-   --  d_m
+   --  d_m  Run adareducer on crash
--  d_n
--  d_o
--  d_p  Ignore assertion pragmas for elaboration
@@ -177,7 +177,7 @@ package body Debug is
--  d_J
--  d_K  (Reserved) Enable reporting a warning on known-problem issues
--  d_L  Output trace information on elaboration checking
-   --  d_M
+   --  d_M  Ignore Source_File_Name and Source_File_Name_Project pragmas
--  d_N
--  d_O
--  d_P
diff --git a/gcc/ada/fname-uf.adb b/gcc/ada/fname-uf.adb
index 983cda487599..cb9363416a62 100644
--- a/gcc/ada/fname-uf.adb
+++ b/gcc/ada/fname-uf.adb
@@ -93,6 +93,15 @@ package body Fname.UF is
--  Table recording calls to Set_File_Name_Pattern. Note that the first two
--  entries are set to represent the standard GNAT rules for file naming.
 
+   procedure Instantiate_SFN_Pattern
+ (Pattern   : SFN_Pattern_Entry;
+  Buf   : in out Bounded_String;
+  Is_Predef : Boolean := False);
+   --  On entry, Buf must contain a unit name. After returning, Buf contains
+   --  the file name corresponding to the unit following the naming pattern
+   --  described by Pattern. Is_Predef must be whether the unit name in Buf
+   --  is a predefined unit name as defined by Is_Predefined_Unit_Name.
+
---
-- File_Name_Of_Body --
---
@@ -164,6 +173,29 @@ package body Fname.UF is
   return Unknown;
en

[gcc r15-4142] ada: sem_prag.adb: fix indentation

2024-10-08 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:b4629ccf3c15b7eafe73beb8b4393419b9968e82

commit r15-4142-gb4629ccf3c15b7eafe73beb8b4393419b9968e82
Author: Ghjuvan Lacambre 
Date:   Wed Sep 4 14:42:07 2024 +0200

ada: sem_prag.adb: fix indentation

The indentation was wrong on these two lines.

gcc/ada/ChangeLog:
* sem_prag.adb (Process_Compile_Time_Warning_Or_Error): Fix
indentation.

Diff:
---
 gcc/ada/sem_prag.adb | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/gcc/ada/sem_prag.adb b/gcc/ada/sem_prag.adb
index 0d43929df720..d1acc3c4921e 100644
--- a/gcc/ada/sem_prag.adb
+++ b/gcc/ada/sem_prag.adb
@@ -8149,8 +8149,8 @@ package body Sem_Prag is
  Analyze_And_Resolve (Arg1x, Standard_Boolean);
 
  if CodePeer_Mode then
-   Rewrite (N, Make_Null_Statement (Loc));
-   return;
+Rewrite (N, Make_Null_Statement (Loc));
+return;
  end if;
 
  --  In GNATprove mode, pragma Compile_Time_Error is translated as


[gcc r15-4146] ada: Legal access discriminant default expression incorrectly rejected

2024-10-08 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:4aa366fcb2a1a1d359207c6826f04be696d5e547

commit r15-4146-g4aa366fcb2a1a1d359207c6826f04be696d5e547
Author: Steve Baird 
Date:   Fri Aug 30 14:13:22 2024 -0700

ada: Legal access discriminant default expression incorrectly rejected

If a limited private partial view of a type has an access discriminant with
a default expression, and if the type (perhaps tagged, perhaps not) is
completed by deriving from an immutably limited type, then the default
discriminant expression should not be rejected.

gcc/ada/ChangeLog:

* sem_ch6.adb (Check_Discriminant_Conformance): In testing whether
a default expression is permitted for an access discriminant, we
need to know whether the discriminated type is immutably limited.
Handle another part of this test that cannot easily be handled in
Sem_Aux.Is_Immutably_Limited. This involves declaring a new local
function, Is_Derived_From_Immutably_Limited_Type.

Diff:
---
 gcc/ada/sem_ch6.adb | 39 +++
 1 file changed, 39 insertions(+)

diff --git a/gcc/ada/sem_ch6.adb b/gcc/ada/sem_ch6.adb
index 076fb89c7b50..c200871b8520 100644
--- a/gcc/ada/sem_ch6.adb
+++ b/gcc/ada/sem_ch6.adb
@@ -6436,6 +6436,14 @@ package body Sem_Ch6 is
   (Typ : Entity_Id) return Boolean;
 --  Returns True iff Typ has a tagged limited partial view.
 
+function Is_Derived_From_Immutably_Limited_Type
+  (Typ : Entity_Id) return Boolean;
+--  Returns True iff Typ is a derived type (tagged or not)
+--  whose ancestor type is immutably limited. The unusual
+--  ("unusual" is one word for it) thing about this function
+--  is that it handles the case where the ancestor name's Entity
+--  attribute has not been set yet.
+
 -
 -- Has_Tagged_Limited_Partial_View --
 -
@@ -6451,6 +6459,31 @@ package body Sem_Ch6 is
  and then Limited_Present (Parent (Priv));
 end Has_Tagged_Limited_Partial_View;
 
+
+-- Is_Derived_From_Immutably_Limited_Type --
+
+
+function Is_Derived_From_Immutably_Limited_Type
+  (Typ : Entity_Id) return Boolean
+is
+   Type_Def : constant Node_Id := Type_Definition (Parent (Typ));
+   Parent_Name : Node_Id;
+begin
+   if Nkind (Type_Def) /= N_Derived_Type_Definition then
+  return False;
+   end if;
+   Parent_Name := Subtype_Indication (Type_Def);
+   if Nkind (Parent_Name) = N_Subtype_Indication then
+  Parent_Name := Subtype_Mark (Parent_Name);
+   end if;
+   if Parent_Name not in N_Has_Entity_Id
+ or else No (Entity (Parent_Name))
+   then
+  Find_Type (Parent_Name);
+   end if;
+   return Is_Immutably_Limited_Type (Entity (Parent_Name));
+end Is_Derived_From_Immutably_Limited_Type;
+
  begin
 if NewD or OldD then
 
@@ -6489,6 +6522,12 @@ package body Sem_Ch6 is
 
  and then not Has_Tagged_Limited_Partial_View
 (Defining_Identifier (N))
+
+ --  Check for another case that would be awkward to handle
+ --  in Is_Immutably_Limited_Type
+
+ and then not Is_Derived_From_Immutably_Limited_Type
+(Defining_Identifier (N))
then
   Error_Msg_N
 ("(Ada 2005) default value for access discriminant "


[gcc r15-4138] ada: Rework s-linux/osinte for arm/aarch64-android sigactions

2024-10-08 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:eeb0a0eae55a68069edd0d9074e7e3adfbceee64

commit r15-4138-geeb0a0eae55a68069edd0d9074e7e3adfbceee64
Author: Olivier Hainque 
Date:   Fri Aug 16 17:08:32 2024 +0200

ada: Rework s-linux/osinte for arm/aarch64-android sigactions

Building an aarch64-android compiler with the current sources
initially intended for arm-android expectedly trips on problems.

This change is meant to address:
```
.../gcc/ada/rts % ../../gnat1 -quiet ... a-stbufi.adb -I.

s-osinte.ads:591:07: error: component "sa_flags" overlaps "sa_mask" at line 
590
```

s-linux__android.ads makes hardcoded assumptions on the size
of sigset_t, based on observations performed in the course of the
arm port.

Then sysem headers show sa_flags placed VERY differently between
the 32 and the 64 bits variants.

See android-sysroot/usr/include/bits/signal_types.h
```
%if defined(__LP64__)

  int sa_flags; \
  union { \
sighandler_t sa_handler; \
void (*sa_sigaction)(int, struct siginfo*, void*); \
  }; \
  sigset_t sa_mask; \
  void (*sa_restorer)(void); \

%else

  union {
sighandler_t sa_handler;
void (*sa_sigaction)(int, struct siginfo*, void*);
  };
  sigset_t sa_mask;
  int sa_flags;
  void (*sa_restorer)(void);

```

gcc/ada/ChangeLog:

* libgnarl/s-linux__android-arm.ads: New file, renaming of ...
* libgnarl/s-linux__android.ads: ... this file.
* libgnarl/s-linux__android-aarch64.ads: New file. Based on the
-arm variant, with sa_ field positions adjusted.
* Makefile.rtl (arm/aarch64-android pairs): Adjust accordingly.
* libgnarl/s-osinte__android.ads: Rather than making assumptions
on the actual type of the C sigset_t, use
Os_Constants.SIZEOF_sigset_t to define an Ada sigset_t type of the
proper size. Use C.int instead of unsigned_long for sa_flags.

Diff:
---
 gcc/ada/Makefile.rtl   |   5 +-
 gcc/ada/libgnarl/s-linux__android-aarch64.ads  | 133 +
 ...linux__android.ads => s-linux__android-arm.ads} |   0
 gcc/ada/libgnarl/s-osinte__android.ads |  10 +-
 4 files changed, 143 insertions(+), 5 deletions(-)

diff --git a/gcc/ada/Makefile.rtl b/gcc/ada/Makefile.rtl
index 9f4c6cd99dcd..d4607e95eff6 100644
--- a/gcc/ada/Makefile.rtl
+++ b/gcc/ada/Makefile.rtl
@@ -1414,7 +1414,6 @@ ifeq ($(strip $(filter-out arm% aarch64 
linux-android%,$(target_cpu) $(target_os
   a-intnam.ads

[gcc r15-4145] ada: Missing constraint check for 'Length attribute reference

2024-10-08 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:985b06da41a089ab5d1295177b90813d29032b72

commit r15-4145-g985b06da41a089ab5d1295177b90813d29032b72
Author: Steve Baird 
Date:   Thu Aug 29 15:17:54 2024 -0700

ada: Missing constraint check for 'Length attribute reference

In some cases involving a universal-integer-valued attribute reference
(typically a 'Length attribute reference) occurring as an actual parameter
in a call, the runtime check that the constraints of the formal parameter
are satisfied is incorrectly not performed.

gcc/ada/ChangeLog:
* sem_attr.adb (Resolve_Attribute): When setting the Etype of a
universal-integer-valued attribute reference to the subtype
determined by its context, use the basetype of that subtype
instead of the subtype itself if there is a possibility that the
attribute value will not satisfy the constraints of that subtype.
Otherwise the compiler is, in effect, assuming something that
might not be true. Except use the subtype in the case of a
not-from-source 'Pos attribute reference in order to avoid
breaking things.

Diff:
---
 gcc/ada/sem_attr.adb | 33 -
 1 file changed, 32 insertions(+), 1 deletion(-)

diff --git a/gcc/ada/sem_attr.adb b/gcc/ada/sem_attr.adb
index 994a45becdc5..9ab197299baf 100644
--- a/gcc/ada/sem_attr.adb
+++ b/gcc/ada/sem_attr.adb
@@ -11231,7 +11231,38 @@ package body Sem_Attr is
   --  If attribute was universal type, reset to actual type
 
   if Is_Universal_Numeric_Type (Etype (N)) then
- Set_Etype (N, Typ);
+
+ --  If evaluating N might yield a value that that does not satisfy
+ --  the constraints of the subtype Typ, then we need to set the
+ --  Etype of N to "Base_Type (Typ)" instead of "Typ".
+ --  Otherwise we can end up incorrectly assuming that the value
+ --  belongs to the subtype and, as a result, eliminating required
+ --  runtime checks.
+ --  Rather than trying to analyze the expression and the subtype to
+ --  test for this case, it seems better to take the simpler approach;
+ --  that is, to ignore this opportunity for an insignificant
+ --  micro-optimization and to instead call Base_Type unconditionally.
+ --  But that doesn't work; it turns out that there is a corner case
+ --  where (for reasons that are not completely understood) we need
+ --  to set the Etype to Typ for reasons of correctness. See below
+ --  for description of this case.
+
+ if Attr_Id = Attribute_Pos
+   and then not Comes_From_Source (N)
+ then
+--  This case occurs when indexing into a packed array and
+--  the index type is an enumeration type that is subject to
+--  an enumeration representation specification.
+--  See the "Analyze_And_Resolve (Expr_Copy, Standard_Natural);"
+--  statement in exp_pakd.adb .
+--  For reasons that are not understood, we see a regression test
+--  failure if we don't handle that case by calling Set_Etype here
+--  with "Typ" instead of "Base_Type (Typ)").
+
+Set_Etype (N, Typ);
+ else
+Set_Etype (N, Base_Type (Typ));
+ end if;
   end if;
 
   --  A Ghost attribute must appear in a specific context


[gcc r15-4135] ada: sem_prag.adb: ignore compile_time_{warning, error} in CodePeer mode

2024-10-08 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:50f023c0d7d9332c2ead2c95c2f9863600ced4ce

commit r15-4135-g50f023c0d7d9332c2ead2c95c2f9863600ced4ce
Author: Ghjuvan Lacambre 
Date:   Mon Sep 2 16:08:16 2024 +0200

ada: sem_prag.adb: ignore compile_time_{warning,error} in CodePeer mode

GNAT sometimes needs help from the GCC back-end in order to check
whether Compile_Time_{Warning,Error} are true. As CodePeer does not have
access to a GCC back-end, it is unable to perform these checks. Thus we
need to remove said pragmas from the tree.

gcc/ada/ChangeLog:
* sem_prag.adb (Process_Compile_Time_Warning_Or_Error): Turn
Compile_Time pragmas into null nodes

Diff:
---
 gcc/ada/sem_prag.adb | 5 +
 1 file changed, 5 insertions(+)

diff --git a/gcc/ada/sem_prag.adb b/gcc/ada/sem_prag.adb
index 2d31c71f366e..0d43929df720 100644
--- a/gcc/ada/sem_prag.adb
+++ b/gcc/ada/sem_prag.adb
@@ -8148,6 +8148,11 @@ package body Sem_Prag is
  Check_Arg_Is_OK_Static_Expression (Arg2, Standard_String);
  Analyze_And_Resolve (Arg1x, Standard_Boolean);
 
+ if CodePeer_Mode then
+   Rewrite (N, Make_Null_Statement (Loc));
+   return;
+ end if;
+
  --  In GNATprove mode, pragma Compile_Time_Error is translated as
  --  a Check pragma in GNATprove mode, handled as an assumption in
  --  GNATprove. This is correct as the compiler will issue an error


[gcc r15-4147] ada: Print the load address in symbolic backtraces

2024-10-08 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:d9b76deb580eb4fc5046d6c0263f420acaa444c9

commit r15-4147-gd9b76deb580eb4fc5046d6c0263f420acaa444c9
Author: Eric Botcazou 
Date:   Fri Sep 6 10:05:58 2024 +0200

ada: Print the load address in symbolic backtraces

The load address of PIE executables is printed in non-symbolic backtraces
(-E binder switch) but it makes sense to print it in symbolic backtraces
(-Es binder switch) too, because symbolic backtraces may degenerate into
non-symbolic ones when the executable is stripped for example.

gcc/ada/ChangeLog:
* libgnat/s-trasym__dwarf.adb (LDAD_Header): New String constant.
(Symbolic_Traceback): Print the load address of the executable at
the beginning if it is not null.

Diff:
---
 gcc/ada/libgnat/s-trasym__dwarf.adb | 12 +++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/gcc/ada/libgnat/s-trasym__dwarf.adb 
b/gcc/ada/libgnat/s-trasym__dwarf.adb
index 1b3680407280..6182316da554 100644
--- a/gcc/ada/libgnat/s-trasym__dwarf.adb
+++ b/gcc/ada/libgnat/s-trasym__dwarf.adb
@@ -637,14 +637,24 @@ package body System.Traceback.Symbolic is
-- Symbolic_Traceback --

 
+   LDAD_Header : constant String := "Load address: ";
+   --  Copied from Ada.Exceptions.Exception_Data
+
function Symbolic_Traceback
  (Traceback: Tracebacks_Array;
   Suppress_Hex : Boolean) return String
is
-  Res : Bounded_String (Max_Length => Max_String_Length);
+  Load_Address : constant Address := Get_Executable_Load_Address;
+  Res  : Bounded_String (Max_Length => Max_String_Length);
+
begin
   System.Soft_Links.Lock_Task.all;
   Init_Exec_Module;
+  if Load_Address /= Null_Address then
+ Append (Res, LDAD_Header);
+ Append_Address (Res, Load_Address);
+ Append (Res, ASCII.LF);
+  end if;
   Symbolic_Traceback_No_Lock (Traceback, Suppress_Hex, Res);
   System.Soft_Links.Unlock_Task.all;


[gcc r15-4148] ada: Early freezeing of types with 'Size'Class

2024-10-08 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:0171938cfc357ed43c2b95ddee504f614cac7982

commit r15-4148-g0171938cfc357ed43c2b95ddee504f614cac7982
Author: squirek 
Date:   Tue Aug 13 11:42:41 2024 +

ada: Early freezeing of types with 'Size'Class

This patch fixes an issue in the compiler whereby declarations of derived 
types
whose parent is a mutably tagged type cause early freezing of the parent 
type -
leading to spurious compile-time errors.

gcc/ada/ChangeLog:
* sem_ch3.adb (Derived_Type_Declaration): Modify generation of
compile time check.

Diff:
---
 gcc/ada/sem_ch3.adb | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/gcc/ada/sem_ch3.adb b/gcc/ada/sem_ch3.adb
index e2050e4a9bfc..2a48882d83c3 100644
--- a/gcc/ada/sem_ch3.adb
+++ b/gcc/ada/sem_ch3.adb
@@ -17956,8 +17956,8 @@ package body Sem_Ch3 is
   --  to the backend since we don't know the true size of
   --  anything at this point.
 
-  Insert_After_And_Analyze (N,
-Make_CW_Size_Compile_Check (T, Root_Class_Typ));
+  Append_Freeze_Actions (T,
+New_List (Make_CW_Size_Compile_Check (T, Root_Class_Typ)));
end if;
 end if;
  end;


[gcc r15-4149] ada: Improved support for incomplete parameter types

2024-10-08 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:0f7e027e7773fbab82b24e08f60c6da7d3f913a5

commit r15-4149-g0f7e027e7773fbab82b24e08f60c6da7d3f913a5
Author: Steve Baird 
Date:   Thu Sep 5 13:42:20 2024 -0700

ada: Improved support for incomplete parameter types

Fix two bugs uncovered by a recent ACATS test C3A1005: a freezing problem
and a case where a user-defined equality function for an incomplete type
was incorrectly hidden from use-clause visibility by the "corresponding"
predefined op (which doesn't actually exist).

gcc/ada/ChangeLog:

* sem_ch6.adb (Analyze_Subprogram_Body_Helper): Don't freeze here
if Has_Delayed_Freeze returns True.
* sem_type.adb (Valid_Equality_Arg): Treat an incomplete type like
a limited type because neither has an implicitly-defined equality
primitive.
(Covers): If either argument is an incomplete type
whose full view is available, then look through to the full view.
* sem_res.adb (Resolve_Actuals): If the actual parameter type is
complete and the formal parameter type is not, then update the
formal parameter type to use the complete view.

Diff:
---
 gcc/ada/sem_ch6.adb  |  4 +++-
 gcc/ada/sem_res.adb  |  9 +
 gcc/ada/sem_type.adb | 15 +++
 3 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/gcc/ada/sem_ch6.adb b/gcc/ada/sem_ch6.adb
index c200871b8520..8cf191d751bd 100644
--- a/gcc/ada/sem_ch6.adb
+++ b/gcc/ada/sem_ch6.adb
@@ -4135,7 +4135,9 @@ package body Sem_Ch6 is
Set_Is_Public (Body_Id, False);
 end if;
 
-Freeze_Before (N, Body_Id);
+if not Has_Delayed_Freeze (Body_Id) then
+   Freeze_Before (N, Body_Id);
+end if;
  end if;
 
  if Nkind (N) /= N_Subprogram_Body_Stub then
diff --git a/gcc/ada/sem_res.adb b/gcc/ada/sem_res.adb
index c8652eed7963..6b673a9c1987 100644
--- a/gcc/ada/sem_res.adb
+++ b/gcc/ada/sem_res.adb
@@ -4658,6 +4658,15 @@ package body Sem_Res is
 A_Typ := Etype (A);
 F_Typ := Etype (F);
 
+--  If A_Typ is complete and F_Typ is not, then adjust F_Typ
+
+if Ekind (F_Typ) = E_Incomplete_Type
+  and then Present (Full_View (F_Typ))
+  and then not Is_Incomplete_Type (A_Typ)
+then
+   F_Typ := Full_View (F_Typ);
+end if;
+
 --  An actual cannot be an untagged formal incomplete type
 
 if Ekind (A_Typ) = E_Incomplete_Type
diff --git a/gcc/ada/sem_type.adb b/gcc/ada/sem_type.adb
index b76c6efd9d9d..75e7dafbc604 100644
--- a/gcc/ada/sem_type.adb
+++ b/gcc/ada/sem_type.adb
@@ -1228,6 +1228,18 @@ package body Sem_Type is
  return Has_Non_Limited_View (T2)
and then Covers (T1, Get_Full_View (Non_Limited_View (T2)));
 
+  --  Coverage for incomplete types
+
+  elsif Ekind (T1) = E_Incomplete_Type
+and then Present (Full_View (T1))
+  then
+ return Covers (Full_View (T1), T2);
+
+  elsif Ekind (T2) = E_Incomplete_Type
+and then Present (Full_View (T2))
+  then
+ return Covers (T1, Full_View (T2));
+
   --  Ada 2005 (AI-412): Coverage for regular incomplete subtypes
 
   elsif Ekind (T1) = E_Incomplete_Subtype then
@@ -3586,6 +3598,9 @@ package body Sem_Type is
   if Is_Anonymous_Access_Type (T) then
  return Ada_Version >= Ada_2005;
 
+  elsif Is_Incomplete_Type (T) then
+ return False;
+
   elsif not Is_Limited_Type (T) then
  return True;


[gcc r15-4140] ada: Use a-nallfl__wraplf.ads for Android

2024-10-08 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:23017cea9c8438865e557782c6c46eb996cf2132

commit r15-4140-g23017cea9c8438865e557782c6c46eb996cf2132
Author: Olivier Hainque 
Date:   Fri Aug 16 19:04:37 2024 +0200

ada: Use a-nallfl__wraplf.ads for Android

This is the most common definition. Otherwise, from the default:

a-nallfl.ads:51:13: ... intrinsic binding type mismatch on result
a-nallfl.ads:51:13: ... intrinsic binding type mismatch on parameter 1
a-nallfl.ads:51:13: ... profile of "Sin" doesn't match the builtin it binds

gcc/ada/ChangeLog:

* Makefile.rtl (arm/aarch64-android): Associate a-nallfl.ads with
libgnat/a-nallfl__wraplf.ads.

Diff:
---
 gcc/ada/Makefile.rtl | 1 +
 1 file changed, 1 insertion(+)

diff --git a/gcc/ada/Makefile.rtl b/gcc/ada/Makefile.rtl
index d4607e95eff6..3f27fe9aca90 100644
--- a/gcc/ada/Makefile.rtl
+++ b/gcc/ada/Makefile.rtl
@@ -1421,6 +1421,7 @@ ifeq ($(strip $(filter-out arm% aarch64 
linux-android%,$(target_cpu) $(target_os
   s-taprop.adb

[gcc r15-4152] ada: Avoid dependency on Long_Long_Long_Integer and System.Img_LLLI for 'Image

2024-10-08 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:7a5f6f764dda359385fb97d8eebe61cab092a200

commit r15-4152-g7a5f6f764dda359385fb97d8eebe61cab092a200
Author: Eric Botcazou 
Date:   Tue Sep 10 12:09:48 2024 +0200

ada: Avoid dependency on Long_Long_Long_Integer and System.Img_LLLI for 
'Image

When the Image attribute is applied directly to another attribute returning
Universal_Integer, for example Enum_Rep, it is converted to the equivalent
of Universal_Integer'Image, which is implemented by Long_Long_Long_Integer
and thus triggers a dependency on System.Img_LLLI, both being unnecessary
in most practical cases.

gcc/ada/ChangeLog:

* exp_imgv.adb (Rewrite_Object_Image): When the prefix is a type
conversion to Universal_Integer, use its expression directly. When
the prefix is an integer literal with Universal_Integer type, try
to compute a narrower type.

Diff:
---
 gcc/ada/exp_imgv.adb | 33 +
 1 file changed, 29 insertions(+), 4 deletions(-)

diff --git a/gcc/ada/exp_imgv.adb b/gcc/ada/exp_imgv.adb
index ce052c13c880..b350542fb712 100644
--- a/gcc/ada/exp_imgv.adb
+++ b/gcc/ada/exp_imgv.adb
@@ -2497,18 +2497,43 @@ package body Exp_Imgv is
   Attr_Name : Name_Id;
   Str_Typ   : Entity_Id)
is
+  P: Node_Id;
   Ptyp : Entity_Id;
 
begin
-  Ptyp := Etype (Pref);
+  P:= Pref;
+  Ptyp := Etype (P);
+
+  --  If the type of the prefix is universal integer, which is a very large
+  --  type, try to compute a narrower type. This may happen when the prefix
+  --  itself is an attribute returning universal integer or a named number.
+
+  if Ptyp = Universal_Integer then
+ if Nkind (P) in N_Type_Conversion | N_Unchecked_Type_Conversion then
+P:= Expression (P);
+Ptyp := Etype (P);
+
+ elsif Nkind (P) = N_Integer_Literal then
+declare
+   Val  : constant Uint:= Intval (P);
+   Neg  : constant Boolean := Val < Uint_0;
+   Bits : constant Nat := Num_Bits (Val) + Boolean'Pos (Neg);
+
+begin
+   if Bits <= System_Max_Integer_Size then
+  Ptyp := Integer_Type_For (UI_From_Int (Bits), not Neg);
+   end if;
+end;
+ end if;
+  end if;
 
   --  If the prefix is a component that depends on a discriminant, then
   --  create an actual subtype for it.
 
-  if Nkind (Pref) = N_Selected_Component then
+  if Nkind (P) = N_Selected_Component then
  declare
 Decl : constant Node_Id :=
- Build_Actual_Subtype_Of_Component (Ptyp, Pref);
+ Build_Actual_Subtype_Of_Component (Ptyp, P);
  begin
 if Present (Decl) then
Insert_Action (N, Decl);
@@ -2521,7 +2546,7 @@ package body Exp_Imgv is
 Make_Attribute_Reference (Sloc (N),
   Prefix => New_Occurrence_Of (Ptyp, Sloc (N)),
   Attribute_Name => Attr_Name,
-  Expressions=> New_List (Unchecked_Convert_To (Ptyp, Pref;
+  Expressions=> New_List (Unchecked_Convert_To (Ptyp, P;
 
   Analyze_And_Resolve (N, Str_Typ);
end Rewrite_Object_Image;


[gcc r15-4160] ada: Fix internal error on elsif part of if-statement containing if-expression

2024-10-08 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:da2a85ac53cbb9a9162cfb9a6da1c2bd47fc0b1b

commit r15-4160-gda2a85ac53cbb9a9162cfb9a6da1c2bd47fc0b1b
Author: Eric Botcazou 
Date:   Wed Sep 11 19:26:18 2024 +0200

ada: Fix internal error on elsif part of if-statement containing 
if-expression

The problem occurs when the compiler is trying to find a context to which
it can hoist finalization actions coming from the if-expression, because
Find_Hook_Context incorrectly returns the N_Elsif_Part node.

gcc/ada/ChangeLog:
PR ada/114640
* exp_util.adb (Find_Hook_Context): For a node present within a
conditional expression, do not return an N_Elsif_Part node.

Diff:
---
 gcc/ada/exp_util.adb | 1 +
 1 file changed, 1 insertion(+)

diff --git a/gcc/ada/exp_util.adb b/gcc/ada/exp_util.adb
index 5aa0f77006c7..8b9ce9a2acc5 100644
--- a/gcc/ada/exp_util.adb
+++ b/gcc/ada/exp_util.adb
@@ -6742,6 +6742,7 @@ package body Exp_Util is
 | N_Aggregate
 | N_Delta_Aggregate
 | N_Extension_Aggregate
+| N_Elsif_Part
   and then Nkind (Parent (Par)) not in N_Function_Call
  | N_Procedure_Call_Statement
  | N_Entry_Call_Statement


[gcc r15-4156] ada: Remove references to internal gnat RFC's

2024-10-08 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:7716b0ebda0cbea7a761fcb014dee98416535274

commit r15-4156-g7716b0ebda0cbea7a761fcb014dee98416535274
Author: Tonu Naks 
Date:   Thu Sep 5 17:23:34 2024 +0300

ada: Remove references to internal gnat RFC's

gcc/ada/ChangeLog:
* doc/gnat_rm/gnat_language_extensions.rst: replace
references to RFC's with appropriate text from the rfc
* gnat_rm.texi: Regenerate.
* gnat_ugn.texi: Regenerate.

Diff:
---
 gcc/ada/doc/gnat_rm/gnat_language_extensions.rst |  925 +++--
 gcc/ada/gnat_rm.texi | 1180 +++---
 gcc/ada/gnat_ugn.texi|2 +-
 3 files changed, 1897 insertions(+), 210 deletions(-)

diff --git a/gcc/ada/doc/gnat_rm/gnat_language_extensions.rst 
b/gcc/ada/doc/gnat_rm/gnat_language_extensions.rst
index af0da9830499..cccf60217d0f 100644
--- a/gcc/ada/doc/gnat_rm/gnat_language_extensions.rst
+++ b/gcc/ada/doc/gnat_rm/gnat_language_extensions.rst
@@ -72,10 +72,24 @@ For example:
   X := X + Squared;
end if;
 
+It is generally a good practice to declare local variables (or constants) with 
as
+short a lifetime as possible. However, introducing a declare block to 
accomplish
+this is a relatively heavy syntactic load along with a traditional extra level
+of indentation. The alternative syntax supported here allows declaring symbols
+in any statement sequence. Lifetime of such local declarations is until the 
end of
+the enclosing construct. The same enclosing construct cannot contain several
+declarations of the same symbol; however, overriding symbols from higher-level
+scopes works similarly to the explicit ``declare`` block.
+
+If the enclosing construct allows an exception handler (such as an accept
+statement, begin-except-end block or a subprogram body), declarations that
+appear at the place of a statement are *not* visible within the handler. Only
+declarations that precede the beginning of the construct with an exception
+handler would be visible in this handler.
+
 .. attention::
 
-   Note that local declarations in statement lists have their own scope, which
-   means that:
+  Here are a couple of examples illustrating the scoping rules described above.
 
1. Those declarations are not visible from the potential exception handler:
 
@@ -115,8 +129,6 @@ For example:
 
And as such the second ``A`` declaration is hiding the first one.
 
-Link to the original RFC:
-https://github.com/AdaCore/ada-spark-rfcs/blob/master/prototyped/rfc-local-vars-without-block.md
 
 Fixed lower bounds for array types and subtypes
 ---
@@ -164,9 +176,6 @@ the efficiency of indexing operations, since the compiler 
statically knows the
 lower bound of unconstrained array formals when the formal's subtype has index
 ranges with static fixed lower bounds.
 
-Link to the original RFC:
-https://github.com/AdaCore/ada-spark-rfcs/blob/master/prototyped/rfc-fixed-lower-bound.rst
-
 Prefixed-view notation for calls to primitive subprograms of untagged types
 ---
 
@@ -181,7 +190,7 @@ This same notation is already available for tagged types. 
This extension allows
 for untagged types. It is allowed for all primitive operations of the type
 independent of whether they were originally declared in a package spec or its
 private part, or were inherited and/or overridden as part of a derived type
-declaration occuring anywhere, so long as the first parameter is of the type,
+declaration occurring anywhere, so long as the first parameter is of the type,
 or an access parameter designating the type.
 
 For example:
@@ -215,9 +224,6 @@ For example:
 pragma Assert (V.Length = 2);
 pragma Assert (V.Nth_Element(1) = 42);
 
-Link to the original RFC:
-https://github.com/AdaCore/ada-spark-rfcs/blob/master/prototyped/rfc-prefixed-untagged.rst
-
 Expression defaults for generic formal functions
 
 
@@ -242,6 +248,11 @@ Here is an example of this feature:
-- ...
 end Stacks;
 
+.. todo::
+
+   I do not understand this feature enough to decide if the description above
+   is sufficient for documentation.
+
 Link to the original RFC:
 
https://github.com/AdaCore/ada-spark-rfcs/blob/master/prototyped/rfc-expression-functions-as-default-for-generic-formal-function-parameters.rst
 
@@ -303,9 +314,6 @@ For example:
f" a double quote is \" and" &
f" an open brace is \{");
 
-Link to the original RFC:
-https://github.com/AdaCore/ada-spark-rfcs/blob/master/prototyped/rfc-string-interpolation.md
-
 Constrained attribute for generic objects
 -
 
@@ -398,8 +406,18 @@ the partial and full views:
type T is tagged null record with First_Controlling_Parameter; -- 
ILLEGAL
 end R;
 
-Link to the original RFC:
-https://github.com/AdaCore/ada-spa

[gcc r15-4158] ada: Add mechanism to test internal error machinery

2024-10-08 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:5339c2165f24f3523fe822c493bf9b1559b5460e

commit r15-4158-g5339c2165f24f3523fe822c493bf9b1559b5460e
Author: Ronan Desplanques 
Date:   Tue Sep 10 11:40:43 2024 +0200

ada: Add mechanism to test internal error machinery

This patch adds a pragma that triggers an internal compiler error when
analyzed. It is not externally documented and makes it possible to test
the code that runs when the compiler encounters an internal error.

gcc/ada/ChangeLog:
* snames.ads-tmpl: Add new pragma definition.
* par-prag.adb (Prag): Handle new pragma.
* sem_prag.adb (Analyze_Pragma): Implement new pragma.

Diff:
---
 gcc/ada/par-prag.adb|  1 +
 gcc/ada/sem_prag.adb| 22 ++
 gcc/ada/snames.ads-tmpl |  2 ++
 3 files changed, 25 insertions(+)

diff --git a/gcc/ada/par-prag.adb b/gcc/ada/par-prag.adb
index ca47afc65eaa..8b953b3e8778 100644
--- a/gcc/ada/par-prag.adb
+++ b/gcc/ada/par-prag.adb
@@ -1562,6 +1562,7 @@ begin
  | Pragma_Short_Circuit_And_Or
  | Pragma_Short_Descriptors
  | Pragma_Simple_Storage_Pool_Type
+ | Pragma_Simulate_Internal_Error
  | Pragma_Static_Elaboration_Desired
  | Pragma_Storage_Size
  | Pragma_Storage_Unit
diff --git a/gcc/ada/sem_prag.adb b/gcc/ada/sem_prag.adb
index d1acc3c4921e..90f9c72e7260 100644
--- a/gcc/ada/sem_prag.adb
+++ b/gcc/ada/sem_prag.adb
@@ -24276,6 +24276,27 @@ package body Sem_Prag is
 end if;
  end Side_Effects;
 
+ 
+ -- Pragma_Simulate_Internal_Error --
+ 
+
+ --  pragma Simulate_Internal_Error;
+
+ --  Since the only purpose of this pragma is to write tests for the
+ --  compiler, it is not documented in the GNAT reference manual. The
+ --  effect of the pragma is to cause the compiler to raise an
+ --  exception when it analyzes the pragma.
+
+ when Pragma_Simulate_Internal_Error =>
+ Simulate_Internal_Error : declare
+Simulated_Internal_Error : exception;
+ begin
+GNAT_Pragma;
+Check_Arg_Count (0);
+
+raise Simulated_Internal_Error;
+ end Simulate_Internal_Error;
+
  --
  -- Simple_Storage_Pool_Type --
  --
@@ -33030,6 +33051,7 @@ package body Sem_Prag is
   Pragma_Shared_Passive =>  0,
   Pragma_Short_Circuit_And_Or   =>  0,
   Pragma_Short_Descriptors  =>  0,
+  Pragma_Simulate_Internal_Error=>  0,
   Pragma_Simple_Storage_Pool_Type   =>  0,
   Pragma_Source_File_Name   =>  0,
   Pragma_Source_File_Name_Project   =>  0,
diff --git a/gcc/ada/snames.ads-tmpl b/gcc/ada/snames.ads-tmpl
index 0d00b89d8e47..b706896073f3 100644
--- a/gcc/ada/snames.ads-tmpl
+++ b/gcc/ada/snames.ads-tmpl
@@ -680,6 +680,7 @@ package Snames is
Name_Shared_Passive : constant Name_Id := N + $;
Name_Side_Effects   : constant Name_Id := N + $; -- GNAT
Name_Simple_Storage_Pool_Type   : constant Name_Id := N + $; -- GNAT
+   Name_Simulate_Internal_Error: constant Name_Id := N + $; -- GNAT
Name_Source_Reference   : constant Name_Id := N + $; -- GNAT
Name_Static_Elaboration_Desired : constant Name_Id := N + $; -- GNAT
 
@@ -1952,6 +1953,7 @@ package Snames is
   Pragma_Shared_Passive,
   Pragma_Side_Effects,
   Pragma_Simple_Storage_Pool_Type,
+  Pragma_Simulate_Internal_Error,
   Pragma_Source_Reference,
   Pragma_Static_Elaboration_Desired,
   Pragma_Stream_Convert,


[gcc r15-4164] ada: Rework the Android sigtramp implementation

2024-10-08 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:c4e90a24d0ac36f8daa08ecac127461a7e294d10

commit r15-4164-gc4e90a24d0ac36f8daa08ecac127461a7e294d10
Author: Olivier Hainque 
Date:   Tue Sep 10 16:46:02 2024 +

ada: Rework the Android sigtramp implementation

The initial signal handling code introduced for aarch64-android
overlooked details of the tasking runtime, not in the initial testing
perimeter.

Specifically, a reference to __gnat_sigtramp from __gnat_error_handler,
initially introduced for the arm port, was prevented if !arm on the
grounds that other ports would rely on kernel CFI. aarch64-android
does provide kernel CFI and __gnat_sigtramp was not provided for this
configuration.

But there is a similar reference from s-intman__android, which kicks in
as soon as the tasking runtime gets activated, triggering link failures.

Testing for more precise target specific parameters from Ada
code is inconvenient and replicating the logic is not attractive in
any case, so this change addresses the problem in the following
fashion:

- Always provide a __gnat_sigtramp entry point, common to the
  tasking and non-tasking signal handling code for all the Android
  configurations,

- There (C code), from target definition macros, select a path
  that either routes directly to the actual signal handler or goes
  through the intermediate layer providing hand crafted CFI
  information which allows unwinding up to the interrupted code.

- Similarily to what was done for VxWorks, move the arm specific
  definitions to a separate header file to make the general structure
  of the common C code easier to grasp,

- Adjust the comments in the common sigtramp.h header to
  account for such an organisation possibility.

gcc/ada/ChangeLog:
* sigtramp-armdroid.c: Refactor into ...
* sigtramp-android.c, sigtramp-android-asm.h: New files.
* Makefile.rtl (arm/aarch64-android section): Add
sigtramp-android.o to EXTRA_LIBGNAT_OBJS unconditionally. Add
sigtramp.h and sigtramp-android-asm.h to EXTRA_LIBGNAT_SRCS.
* init.c (android section, __gnat_error_handler): Defer to
__gnat_sigramp unconditionally again.
* sigtramp.h: Adjust comments to allow neutral signal handling
relays, merely forwarding to the underlying handler without any
intermediate CFI magic.

Diff:
---
 gcc/ada/Makefile.rtl   | 12 ++--
 gcc/ada/init.c |  7 --
 ...{sigtramp-armdroid.c => sigtramp-android-asm.h} | 83 +-
 gcc/ada/sigtramp-android.c | 79 
 gcc/ada/sigtramp.h | 21 --
 5 files changed, 115 insertions(+), 87 deletions(-)

diff --git a/gcc/ada/Makefile.rtl b/gcc/ada/Makefile.rtl
index 3f27fe9aca90..246c0059fb7f 100644
--- a/gcc/ada/Makefile.rtl
+++ b/gcc/ada/Makefile.rtl
@@ -1430,22 +1430,20 @@ ifeq ($(strip $(filter-out arm% aarch64 
linux-android%,$(target_cpu) $(target_os
 
   EXTRA_GNATRTL_TASKING_OBJS=s-linux.o
 
-  # 32bit arm relies on a sigtramp for signal->exception propagation
-  # while aarch64 relies on kernel dwarf CFI.  And as a 64bit target,
-  # aarch64 can also incorporate support for 128bit arithmetic.
+  # ARM and aarch64 rely on different unwinding mechanisms, and as
+  # a 64bit target, aarch64 can also incorporate support for 128bit
+  # arithmetic.
 
   ifeq ($(strip $(filter-out arm%, $(target_cpu))),)
  SELECTED_PAIRS=arm-android
 
  EH_MECHANISM=-arm
- SIGTRAMP_OBJ=sigtramp-armdroid.o
  LIBGNAT_TARGET_PAIRS += \
s-linux.ads
+/* The intended use mode of this header is to provide macros
+   and a prologue to the generation of an asm function, as in
 
-#include "sigtramp.h"
-/* See sigtramp.h for a general explanation of functionality.  */
+ #include 
+ asm (SIGTRAMP_START());
+ asm (SIGTRAMP_BODY);
+ asm (SIGTRAMP_END());
 
-/* --
-   -- General comments --
-   --
-
-   Stubs are generated from toplevel asms,
-   The general idea is to establish CFA as the sigcontext
-   and state where to find the registers as offsets from there.
-
-   We support stubs for VxWorks and Android, providing unwind info for
-   common registers. We might need variants with support for floating
-   point or altivec registers as well at some point.
-
-   For Android it would be simpler to write this in Asm since there's only
-   one variant, but to keep it looking like the VxWorks stubs,
-   C is the choice for our toplevel interface.
-
-   Note that the registers we "restore" here are those to which we have
-   direct access through the system sigcontext structure, which includes
-   only a partial set of the non-volatiles ABI-wise.  */
-
-/* --

[gcc r15-4165] ada: Remove -gnateE information message for noncontiguous enumeration type

2024-10-08 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:409de30d89310ea6ec24b480528c75cb74f8ef85

commit r15-4165-g409de30d89310ea6ec24b480528c75cb74f8ef85
Author: Eric Botcazou 
Date:   Tue Sep 10 15:02:19 2024 +0200

ada: Remove -gnateE information message for noncontiguous enumeration type

It is very confusing for the user because it does not make any reference
to the source code but only to details of the underlying implementation.

gcc/ada/ChangeLog:
* gcc-interface/trans.cc (Raise_Error_to_gnu) :
Do not the generate range information if the value is a call to a
Rep_To_Pos function.

Diff:
---
 gcc/ada/gcc-interface/trans.cc | 5 +
 1 file changed, 5 insertions(+)

diff --git a/gcc/ada/gcc-interface/trans.cc b/gcc/ada/gcc-interface/trans.cc
index ebcf2cdf8fe3..a073b2d94f1c 100644
--- a/gcc/ada/gcc-interface/trans.cc
+++ b/gcc/ada/gcc-interface/trans.cc
@@ -6124,7 +6124,12 @@ Raise_Error_to_gnu (Node_Id gnat_node, tree 
*gnu_result_type_p)
  gnu_index = convert (gnu_type, gnu_index);
}
 
+ /* Do not print the range information for an enumeration type with
+holes since it is meaningless.  */
  if (with_extra_info
+ && !(Nkind (gnat_index) == N_Function_Call
+  && Is_Entity_Name (Name (gnat_index))
+  && Is_Rep_To_Pos (Entity (Name (gnat_index
  && Known_Esize (gnat_type)
  && UI_To_Int (Esize (gnat_type)) <= 32)
gnu_result


[gcc r15-4163] ada: Fix bogus Constraint_Error for 'Wide_Wide_Value on wide enumeration literal

2024-10-08 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:c4d9a73e12b25a9f0ac152df2da5ceac80bd9d6a

commit r15-4163-gc4d9a73e12b25a9f0ac152df2da5ceac80bd9d6a
Author: Eric Botcazou 
Date:   Thu Sep 12 12:45:27 2024 +0200

ada: Fix bogus Constraint_Error for 'Wide_Wide_Value on wide enumeration 
literal

The problem is that 'Wide_Wide_Value is piggybacked on 'Value and the latter
invokes System.Val_Util.Normalize_String, which incorrectly normalizes the
input string in the presence of enumeration literals with wide characters.

gcc/ada/ChangeLog:
PR ada/115507
* exp_imgv.adb (Expand_Valid_Value_Attribute): Add actual parameter
for Is_Wide formal in the call to Valid_Value_Enumeration_NN.
(Expand_Value_Attribute): Likewise.
* libgnat/s-vaen16.ads (Value_Enumeration_16): Add Is_Wide formal.
(Valid_Value_Enumeration_16): Likewise.
* libgnat/s-vaen32.ads (Value_Enumeration_32): Likewise.
(Valid_Value_Enumeration_32): Likewise.
* libgnat/s-vaenu8.ads (Value_Enumeration_8): Likewise.
(Valid_Value_Enumeration_8): Likewise.
* libgnat/s-valboo.adb (Value_Boolean): Pass True for To_Upper_Case
formal parameter in call to Normalize_String.
* libgnat/s-valcha.adb (Value_Character): Likewise.
* libgnat/s-valuen.ads (Value_Enumeration): Add Is_Wide formal.
(Valid_Value_Enumeration): Likewise.
* libgnat/s-valuen.adb (Value_Enumeration_Pos): Likewise and pass
its negation for To_Upper_Case formal in call to Normalize_String.
(Valid_Value_Enumeration): Add Is_Wide formal and forward it in
call to Value_Enumeration_Pos.
(Value_Enumeration): Likewise.
* libgnat/s-valuti.ads (Normalize_String): Add To_Upper_Case formal
parameter and adjust post-condition accordingly.
* libgnat/s-valuti.adb (Normalize_String): Add To_Upper_Case formal
parameter and adjust implementation accordingly.
* libgnat/s-valwch.adb (Value_Wide_Wide_Character): Pass False for
To_Upper_Case formal parameter in call to Normalize_String.

Diff:
---
 gcc/ada/exp_imgv.adb | 42 +-
 gcc/ada/libgnat/s-vaen16.ads |  2 ++
 gcc/ada/libgnat/s-vaen32.ads |  2 ++
 gcc/ada/libgnat/s-vaenu8.ads |  2 ++
 gcc/ada/libgnat/s-valboo.adb |  2 +-
 gcc/ada/libgnat/s-valcha.adb |  4 +++-
 gcc/ada/libgnat/s-valuen.adb | 11 ---
 gcc/ada/libgnat/s-valuen.ads |  5 -
 gcc/ada/libgnat/s-valuti.adb |  9 +
 gcc/ada/libgnat/s-valuti.ads | 14 --
 gcc/ada/libgnat/s-valwch.adb |  2 +-
 11 files changed, 69 insertions(+), 26 deletions(-)

diff --git a/gcc/ada/exp_imgv.adb b/gcc/ada/exp_imgv.adb
index b350542fb712..ef2a3a3250fc 100644
--- a/gcc/ada/exp_imgv.adb
+++ b/gcc/ada/exp_imgv.adb
@@ -1431,11 +1431,11 @@ package body Exp_Imgv is
 
procedure Expand_Valid_Value_Attribute (N : Node_Id) is
   Loc   : constant Source_Ptr := Sloc (N);
+  Args  : constant List_Id:= Expressions (N);
   Btyp  : constant Entity_Id  := Base_Type (Entity (Prefix (N)));
   Rtyp  : constant Entity_Id  := Root_Type (Btyp);
   pragma Assert (Is_Enumeration_Type (Rtyp));
 
-  Args  : constant List_Id := Expressions (N);
   Func  : RE_Id;
   Ttyp  : Entity_Id;
 
@@ -1443,7 +1443,7 @@ package body Exp_Imgv is
   --  Generate:
 
   -- Valid_Value_Enumeration_NN
-  --   (typS, typN'Address, typH'Unrestricted_Access, Num, X)
+  --   (typS, typN'Address, typH'Unrestricted_Access, Num, Is_Wide, X)
 
   Ttyp := Component_Type (Etype (Lit_Indexes (Rtyp)));
 
@@ -1455,6 +1455,10 @@ package body Exp_Imgv is
  Func := RE_Valid_Value_Enumeration_32;
   end if;
 
+  --  The Valid_[Wide_]Wide_Value attribute does not exist
+
+  Prepend_To (Args, New_Occurrence_Of (Standard_False, Loc));
+
   Prepend_To (Args,
 Make_Attribute_Reference (Loc,
   Prefix => New_Occurrence_Of (Rtyp, Loc),
@@ -1546,7 +1550,7 @@ package body Exp_Imgv is
 
--Enum'Val
--  (Value_Enumeration_NN
-   --(typS, typN'Address, typH'Unrestricted_Access, Num, X))
+   --(typS, typN'Address, typH'Unrestricted_Access, Num, Is_Wide, X))
 
--  where typS, typN and typH are the Lit_Strings, Lit_Indexes and Lit_Hash
--  entities from T's root type entity, and Num is Enum'Pos (Enum'Last).
@@ -1558,14 +1562,15 @@ package body Exp_Imgv is
 
procedure Expand_Value_Attribute (N : Node_Id) is
   Loc   : constant Source_Ptr := Sloc (N);
+  Args  : constant List_Id:= Expressions (N);
   Btyp  : constant Entity_Id  := Etype (N);
   pragma Assert (Is_Base_Type (Btyp));
   pragma Assert (Btyp = Base_Type (Entity (Prefix (N;
   Rtyp  : constant Entity_Id  := Root_Type (Btyp);
 
-  Args  : constant List_Id := Expressions (N);

[gcc r15-4153] ada: Add Is_Rep_To_Pos predicate and export it for use in gigi

2024-10-08 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:9ca4d98d0349882510b1ae705087a00ee9dcb0f5

commit r15-4153-g9ca4d98d0349882510b1ae705087a00ee9dcb0f5
Author: Eric Botcazou 
Date:   Tue Sep 10 14:58:21 2024 +0200

ada: Add Is_Rep_To_Pos predicate and export it for use in gigi

This is modeled on the existing Is_Init_Proc predicate.

gcc/ada/ChangeLog:
* exp_tss.ads (Is_Rep_To_Pos): New function declaration.
* exp_tss.adb (Is_Rep_To_Pos): New function body.
* fe.h (Is_Rep_To_Pos): New macro and extern declaration.

Diff:
---
 gcc/ada/exp_tss.adb | 12 
 gcc/ada/exp_tss.ads |  5 +
 gcc/ada/fe.h|  2 ++
 3 files changed, 19 insertions(+)

diff --git a/gcc/ada/exp_tss.adb b/gcc/ada/exp_tss.adb
index 098e001808ea..78eb27e15543 100644
--- a/gcc/ada/exp_tss.adb
+++ b/gcc/ada/exp_tss.adb
@@ -355,6 +355,18 @@ package body Exp_Tss is
   return C1 = TSS_Init_Proc (1) and then C2 = TSS_Init_Proc (2);
end Is_Init_Proc;
 
+   ---
+   -- Is_Rep_To_Pos --
+   ---
+
+   function Is_Rep_To_Pos (E : Entity_Id) return Boolean is
+  C1 : Character;
+  C2 : Character;
+   begin
+  Get_Last_Two_Chars (Chars (E), C1, C2);
+  return C1 = TSS_Rep_To_Pos (1) and then C2 = TSS_Rep_To_Pos (2);
+   end Is_Rep_To_Pos;
+

-- Is_TSS --

diff --git a/gcc/ada/exp_tss.ads b/gcc/ada/exp_tss.ads
index e7f312047a09..aed6a68fabe1 100644
--- a/gcc/ada/exp_tss.ads
+++ b/gcc/ada/exp_tss.ads
@@ -154,6 +154,11 @@ package Exp_Tss is
 
--  WARNING: There is a matching C declaration of this subprogram in fe.h
 
+   function Is_Rep_To_Pos (E : Entity_Id) return Boolean;
+   --  Version for Rep to Pos conversions, same as Is_TSS (E, TSS_Rep_To_Pos);
+
+   --  WARNING: There is a matching C declaration of this subprogram in fe.h
+
function Is_TSS (E : Entity_Id; Nam : TSS_Name_Type) return Boolean;
--  Determines if given entity (E) is the name of a TSS identified by Nam
 
diff --git a/gcc/ada/fe.h b/gcc/ada/fe.h
index 9d3606ce0a7e..36f5e9bfe9ed 100644
--- a/gcc/ada/fe.h
+++ b/gcc/ada/fe.h
@@ -179,8 +179,10 @@ extern void Get_Variant_Encoding   (Entity_Id);
 /* exp_tss: */
 
 #define Is_Init_Proc   exp_tss__is_init_proc
+#define Is_Rep_To_Pos  exp_tss__is_rep_to_pos
 
 extern Boolean Is_Init_Proc(Entity_Id);
+extern Boolean Is_Rep_To_Pos   (Entity_Id);
 
 /* exp_util: */


[gcc r15-4141] ada: Add External_Initialization extension

2024-10-08 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:7e09f16ef980883598268b2044b9b370ec3a9611

commit r15-4141-g7e09f16ef980883598268b2044b9b370ec3a9611
Author: Ronan Desplanques 
Date:   Mon Sep 2 15:38:21 2024 +0200

ada: Add External_Initialization extension

This patch introduces a GNAT extension that adds a new aspect,
External_Initialization. A section is added to the reference
manual with a description of what the aspect does.

The implementation reuses existing mechanisms, in particular
Sinput.L.Load_Source_File and Sem_Res.Set_String_Literal_Subtype.

A new node kind is added, and nodes of that type are present in what
is passed to the back ends. That makes it necessary to update the back
ends to handle the new node type. The C interface is extended to make
that possible.

gcc/ada/ChangeLog:
* aspects.ads: Add entities for External_Initialization.
* checks.adb (Selected_Length_Checks): Add support for
N_External_Initializer nodes.
* doc/gnat_rm/gnat_language_extensions.rst: Add section for the 
added
extension.
* exp_util.adb (Insert_Actions): Add support for 
N_External_Initializer
nodes.
* fe.h (C_Source_Buffer): New function.
* gen_il-fields.ads: Add new field.
* gen_il-gen-gen_nodes.adb: Add N_External_Initializer node kind.
* gen_il-gen.adb: Add new field type.
* gen_il-types.ads: Add new node kind and new field type.
* pprint.adb (Expr_Name): Handle new node kind.
* sem.adb (Analyze): Add support for N_External_Initializer nodes.
* sem_ch13.adb (Analyze_Aspect_Specifications, 
Check_Aspect_At_Freeze_Point):
Add support for External_Initialization aspect.
* sem_ch3.adb (Apply_External_Initialization): New subprogram.
(Analyze_Object_Declaration): Add support for 
External_Initialization aspect.
* sem_res.adb (Resolve_External_Initializer): New procedure.
(Resolve): Add support for N_External_Initializer nodes.
(Set_String_Literal_Subtype): Extend to handle 
N_External_Initializer nodes.
* sinfo-utils.adb (Is_In_Union_Id): Adapt to new field addition.
* sinfo.ads: Add documentation for new node kind and new field.
* sinput.adb, sinput.ads (C_Source_Buffer): Add new C interface 
function.
* snames.ads-tmpl: Add new aspect identifier.
* sprint.adb (Sprint_Node_Actual): Add nop handling of 
N_External_Initializer
nodes.
* types.ads: Modify type to allow for new C interface.
* gcc-interface/trans.cc (gnat_to_gnu): Handle new GNAT node type.
* gcc-interface/Make-lang.in: Update list of stage1 run-time 
library units.
* gnat-style.texi: Regenerate.
* gnat_rm.texi: Regenerate.
* gnat_ugn.texi: Regenerate.

Diff:
---
 gcc/ada/aspects.ads  |   6 ++
 gcc/ada/checks.adb   |   4 +-
 gcc/ada/doc/gnat_rm/gnat_language_extensions.rst |  25 ++
 gcc/ada/exp_util.adb |   1 +
 gcc/ada/fe.h |   7 ++
 gcc/ada/gcc-interface/Make-lang.in   |   2 +
 gcc/ada/gcc-interface/trans.cc   |  11 +++
 gcc/ada/gen_il-fields.ads|   1 +
 gcc/ada/gen_il-gen-gen_nodes.adb |   3 +
 gcc/ada/gen_il-gen.adb   |   1 +
 gcc/ada/gen_il-types.ads |   2 +
 gcc/ada/gnat-style.texi  |   4 +-
 gcc/ada/gnat_rm.texi |  99 ++
 gcc/ada/gnat_ugn.texi|  10 +--
 gcc/ada/pprint.adb   |   1 +
 gcc/ada/sem.adb  |   6 ++
 gcc/ada/sem_ch13.adb |  15 
 gcc/ada/sem_ch3.adb  | 101 ++-
 gcc/ada/sem_res.adb  |  34 ++--
 gcc/ada/sinfo-utils.adb  |   1 +
 gcc/ada/sinfo.ads|  15 
 gcc/ada/sinput.adb   |  19 +
 gcc/ada/sinput.ads   |   9 ++
 gcc/ada/snames.ads-tmpl  |   1 +
 gcc/ada/sprint.adb   |   3 +
 gcc/ada/types.ads|   2 +-
 26 files changed, 329 insertions(+), 54 deletions(-)

diff --git a/gcc/ada/aspects.ads b/gcc/ada/aspects.ads
index adaa11f8a932..2a5e0f216014 100644
--- a/gcc/ada/aspects.ads
+++ b/gcc/ada/aspects.ads
@@ -96,6 +96,7 @@ package Aspects is
   Aspect_Dispatching_Domain,
   Aspect_Dynamic_Predicate,
   Aspect_Exceptional_Cases, -- GNAT
+  Aspect_External_Initialization,   -- GNAT
   Asp

[gcc r15-4143] ada: Fix wrong finalization of anonymous array aggregate

2024-10-08 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:45131b851522180c532bebb3521865e488025af0

commit r15-4143-g45131b851522180c532bebb3521865e488025af0
Author: Eric Botcazou 
Date:   Thu Sep 5 00:19:25 2024 +0200

ada: Fix wrong finalization of anonymous array aggregate

The issue arises when the aggregate consists only of iterated associations
because, in this case, its expansion uses a 2-pass mechanism which creates
a temporary that needs a fully-fledged initialization, thus running afoul
of the optimization that avoids building the initialization procedure in
the anonymous array case.

gcc/ada/ChangeLog:
* exp_aggr.ads (Is_Two_Pass_Aggregate): New function declaration.
* exp_aggr.adb (Is_Two_Pass_Aggregate): New function body.
(Expand_Array_Aggregate): Call Is_Two_Pass_Aggregate to detect the
aggregates that need the 2-pass expansion.
* exp_ch3.adb (Expand_Freeze_Array_Type): In the anonymous array
case, build the initialization procedure if the initial value in
the object declaration is a 2-pass aggregate.

Diff:
---
 gcc/ada/exp_aggr.adb | 22 --
 gcc/ada/exp_aggr.ads |  4 
 gcc/ada/exp_ch3.adb  | 15 ++-
 3 files changed, 30 insertions(+), 11 deletions(-)

diff --git a/gcc/ada/exp_aggr.adb b/gcc/ada/exp_aggr.adb
index 846665eae20b..86d886a302c8 100644
--- a/gcc/ada/exp_aggr.adb
+++ b/gcc/ada/exp_aggr.adb
@@ -5946,12 +5946,7 @@ package body Exp_Aggr is
   then
  return;
 
-  elsif Present (Component_Associations (N))
-and then Nkind (First (Component_Associations (N))) =
- N_Iterated_Component_Association
-and then
-  Present (Iterator_Specification (First (Component_Associations (N
-  then
+  elsif Is_Two_Pass_Aggregate (N) then
  Two_Pass_Aggregate_Expansion (N);
  return;
 
@@ -8872,6 +8867,21 @@ package body Exp_Aggr is
 and then C in Uint_1 | Uint_2 | Uint_4; -- False if No_Uint
end Is_Two_Dim_Packed_Array;
 
+   ---
+   -- Is_Two_Pass_Aggregate --
+   ---
+
+   function Is_Two_Pass_Aggregate (N : Node_Id) return Boolean is
+   begin
+  return Nkind (N) = N_Aggregate
+and then Present (Component_Associations (N))
+and then Nkind (First (Component_Associations (N))) =
+   N_Iterated_Component_Association
+and then
+  Present
+(Iterator_Specification (First (Component_Associations (N;
+   end Is_Two_Pass_Aggregate;
+

-- Late_Expansion --

diff --git a/gcc/ada/exp_aggr.ads b/gcc/ada/exp_aggr.ads
index 17fa38b7ca35..aa79616c609a 100644
--- a/gcc/ada/exp_aggr.ads
+++ b/gcc/ada/exp_aggr.ads
@@ -58,6 +58,10 @@ package Exp_Aggr is
--  Returns True if N is a conditional expression whose Expansion_Delayed
--  flag is set (see sinfo for meaning of flag).
 
+   function Is_Two_Pass_Aggregate (N : Node_Id) return Boolean;
+   --  Return True if N is an aggregate that is to be expanded in two passes.
+   --  This is the case if it consists only of iterated associations.
+
function Static_Array_Aggregate (N : Node_Id) return Boolean;
--  N is an array aggregate that may have a component association with
--  an others clause and a range. If bounds are static and the expressions
diff --git a/gcc/ada/exp_ch3.adb b/gcc/ada/exp_ch3.adb
index ff808aadea88..139fce8b288c 100644
--- a/gcc/ada/exp_ch3.adb
+++ b/gcc/ada/exp_ch3.adb
@@ -5429,17 +5429,22 @@ package body Exp_Ch3 is
   if not Is_Bit_Packed_Array (Typ) then
  if No (Init_Proc (Base)) then
 
---  If this is an anonymous array created for a declaration with
---  an initial value, its init_proc will never be called. The
+--  If this is an anonymous array built for an object declaration
+--  with an initial value, its Init_Proc will never be called. The
 --  initial value itself may have been expanded into assignments,
---  in which case the object declaration is carries the
---  No_Initialization flag.
+--  in which case the declaration has the No_Initialization flag.
+--  The exception is when the initial value is a 2-pass aggregate,
+--  because the special expansion used for it creates a temporary
+--  that needs a fully-fledged initialization.
 
 if Is_Itype (Base)
   and then Nkind (Associated_Node_For_Itype (Base)) =
 N_Object_Declaration
   and then
-(Present (Expression (Associated_Node_For_Itype (Base)))
+((Present (Expression (Associated_Node_For_Itype (Base)))
+and then not
+  Is_Two_Pass_Aggregate
+(Expression (Associated_Node_F

[gcc r15-4150] ada: Fix reproducer generation with child subprograms

2024-10-08 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:a6fc30b29f2e89057538500bb7cf2e233d4e5e41

commit r15-4150-ga6fc30b29f2e89057538500bb7cf2e233d4e5e41
Author: Ronan Desplanques 
Date:   Mon Sep 9 17:05:41 2024 +0200

ada: Fix reproducer generation with child subprograms

This patch fixes a corner case that was not handled correctly by
Generate_Minimal_Reproducer.

gcc/ada/ChangeLog:
* generate_minimal_reproducer.adb (Generate_Minimal_Reproducer):
Fix behavior on child subprograms without specs.

Diff:
---
 gcc/ada/generate_minimal_reproducer.adb | 11 ++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/gcc/ada/generate_minimal_reproducer.adb 
b/gcc/ada/generate_minimal_reproducer.adb
index d9944f127090..ffef91be6906 100644
--- a/gcc/ada/generate_minimal_reproducer.adb
+++ b/gcc/ada/generate_minimal_reproducer.adb
@@ -29,6 +29,7 @@ with Lib;
 with Namet; use Namet;
 with Osint; use Osint;
 with Output; use Output;
+with Sinfo.Nodes;
 with System.CRTL;
 with System.OS_Lib; use System.OS_Lib;
 with Types; use Types;
@@ -126,8 +127,16 @@ begin
 
 File_Copy_Path : constant String :=
   Src_Dir_Path & Directory_Separator & Default_File_Name;
+
+--  We may have synthesized units for child subprograms without
+--  spec files. We need to filter out those units because we would
+--  create bogus spec files that break compilation if we didn't.
+Is_Synthetic_Subprogram_Spec : constant Boolean :=
+  not Sinfo.Nodes.Comes_From_Source (Lib.Cunit (J));
  begin
-if not Lib.Is_Internal_Unit (J) then
+if not Lib.Is_Internal_Unit (J)
+  and then not Is_Synthetic_Subprogram_Spec
+then
--  Mapped_Path_Name might have returned No_File. This has been
--  observed for files with a Source_File_Name pragma.
if Path = No_File then


[gcc r15-4151] ada: Use semantics from the RFC for declarative items mixed with statements

2024-10-08 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:cee753879cdb61c27dd584fcc4932969fb2cd0be

commit r15-4151-gcee753879cdb61c27dd584fcc4932969fb2cd0be
Author: Raphaël AMIARD 
Date:   Thu Aug 29 12:43:54 2024 +0200

ada: Use semantics from the RFC for declarative items mixed with statements

We want to allow statements lists with declarations *and* an exception
handler. What follows from this is that declarations declared in the
statement list are *not* visible from the exception handler, and that
the following code:

declare
A : Integer := 12;
begin
A : Integer := 15;


exception
when others => ...

Roughly expands to:

declare
A : Integer := 12;
begin
declare
A : Integer := 15;
begin

exception
when others => ...

As such, in the code above, there is no more error triggered for
conflicting declarations of `A`.

Move "Local declarations without block" into curated extensions

Restrict legal local decls in statement lists

Only accept object declarations & renamings, as well as use clauses for

gcc/ada/ChangeLog:

* par-ch11.adb (P_Sequence_Of_Statements): Remove Handled
parameter. Always wrap the statements in a block when there are
declarations in it.
* par-ch5.adb: Adapt call to P_Sequence_Of_Statements Update
outdated comment, remove useless `Style_Checks` pragma.
(P_Sequence_Of_Statements): Don't emit an error in core extensions
mode. Emit an error when a non valid declaration is parsed in
sequence of statements.
* par.adb: Adapt P_Sequence_Of_Statements' signature
* doc/gnat_rm/gnat_language_extensions.rst: Adapt documentation
now.
* gnat_rm.texi: Regenerate.
* gnat_ugn.texi: Regenerate.

Diff:
---
 gcc/ada/doc/gnat_rm/gnat_language_extensions.rst |  52 -
 gcc/ada/gnat_rm.texi |  60 ++-
 gcc/ada/gnat_ugn.texi|   2 +-
 gcc/ada/par-ch11.adb |   3 +-
 gcc/ada/par-ch5.adb  | 129 +++
 gcc/ada/par.adb  |   2 +-
 6 files changed, 171 insertions(+), 77 deletions(-)

diff --git a/gcc/ada/doc/gnat_rm/gnat_language_extensions.rst 
b/gcc/ada/doc/gnat_rm/gnat_language_extensions.rst
index b29f23c29efc..af0da9830499 100644
--- a/gcc/ada/doc/gnat_rm/gnat_language_extensions.rst
+++ b/gcc/ada/doc/gnat_rm/gnat_language_extensions.rst
@@ -53,9 +53,12 @@ Features activated via ``-gnatX`` or
 Local Declarations Without Block
 
 
-A basic_declarative_item may appear at the place of any statement.
-This avoids the heavy syntax of block_statements just to declare
-something locally.
+A ``basic_declarative_item`` may appear at the place of any statement. This
+avoids the heavy syntax of block_statements just to declare something locally.
+
+The only valid kind of declarations for now are ``object_declaration``,
+``object_renaming_declaration``, ``use_package_clause`` and
+``use_type_clause``.
 
 For example:
 
@@ -69,6 +72,49 @@ For example:
   X := X + Squared;
end if;
 
+.. attention::
+
+   Note that local declarations in statement lists have their own scope, which
+   means that:
+
+   1. Those declarations are not visible from the potential exception handler:
+
+  .. code-block:: ada
+
+ begin
+A : Integer
+...
+ exception
+when others =>
+Put_Line (A'Image) --  ILLEGAL
+ end;
+
+   2. The following is legal
+
+  .. code-block:: ada
+
+ declare
+A : Integer := 10;
+ begin
+A : Integer := 12;
+ end;
+
+  because it is roughly expanded into
+
+  .. code-block:: ada
+
+ declare
+A : Integer := 10;
+ begin
+declare
+   A : Integer := 12;
+begin
+   ...
+end;
+ end;
+
+   And as such the second ``A`` declaration is hiding the first one.
+
 Link to the original RFC:
 
https://github.com/AdaCore/ada-spark-rfcs/blob/master/prototyped/rfc-local-vars-without-block.md
 
diff --git a/gcc/ada/gnat_rm.texi b/gcc/ada/gnat_rm.texi
index e2686b0a2c78..96f35f7edb87 100644
--- a/gcc/ada/gnat_rm.texi
+++ b/gcc/ada/gnat_rm.texi
@@ -28961,9 +28961,12 @@ Features activated via @code{-gnatX} or
 @subsection Local Declarations Without Block
 
 
-A basic_declarative_item may appear at the place of any statement.
-This avoids the heavy syntax of block_statements just to declare
-something locally.
+A @code{basic_declarative_item} may appear at the place of any statement. This
+avoids the heavy syntax of bloc

[gcc r15-4154] ada: Use corect capacity with two dimensional arrays

2024-10-08 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:4ca91b84aa1cdb5fcd178ecb2bc7a13c9be082e3

commit r15-4154-g4ca91b84aa1cdb5fcd178ecb2bc7a13c9be082e3
Author: Viljar Indus 
Date:   Wed Sep 4 12:21:40 2024 +0300

ada: Use corect capacity with two dimensional arrays

Previously when a bounded list was initialized with an array aggregate
then we used the correct size only if the array was one dimensional.
This patch adds support for deriving the size for multidimensional array
types as well.

gcc/ada/ChangeLog:
* exp_aggr.adb (Build_Siz_Exp): Support deriving the size of the
container aggregate with multi-dimensional arrays. Make the
function return an node of an expression instead of an integer.
Additionally calculate the size expression for
Component_Associations.
(To_Int) make this method available for more functions.
(Aggregate_Size) Relocate the calculation of
Componenet_Associations to Build_Siz_Exp.

Diff:
---
 gcc/ada/exp_aggr.adb | 425 ++-
 1 file changed, 218 insertions(+), 207 deletions(-)

diff --git a/gcc/ada/exp_aggr.adb b/gcc/ada/exp_aggr.adb
index 86d886a302c8..c94a6b9d581a 100644
--- a/gcc/ada/exp_aggr.adb
+++ b/gcc/ada/exp_aggr.adb
@@ -6632,12 +6632,11 @@ package body Exp_Aggr is
 
   Comp  : Node_Id;
   Init_Stat : Node_Id;
-  Siz   : Int;
 
   --  The following are used when the size of the aggregate is not
   --  static and requires a dynamic evaluation.
   Siz_Decl   : Node_Id;
-  Siz_Exp: Node_Id := Empty;
+  Siz_Exp: Node_Id;
 
   --  These variables are used to determine the smallest and largest
   --  choice values. Choice_Lo and Choice_Hi are passed to the New_Indexed
@@ -6648,14 +6647,18 @@ package body Exp_Aggr is
 
   Is_Indexed_Aggregate : Boolean := False;
 
-  function Aggregate_Size return Int;
+  function Aggregate_Size return Node_Id;
   --  Compute number of entries in aggregate, including choices
   --  that cover a range or subtype, as well as iterated constructs.
-  --  Return -1 if the size is not known statically, in which case
-  --  allocate a default size for the aggregate, or build an expression
-  --  to estimate the size dynamically.
+  --  The size of the aggregate can either be a statically known in which
+  --  case it is returned as an integer literal, or it can be a dynamic
+  --  expression in which case an empty node is returned.
+  --
+  --  It is not possible to determine the size for all case. When that
+  --  happens this function returns an empty node. In that case we will
+  --  later just allocate a default size for the aggregate.
 
-  function Build_Siz_Exp (Comp : Node_Id) return Int;
+  function Build_Siz_Exp (Comp : Node_Id) return Node_Id;
   --  When the aggregate contains a single Iterated_Component_Association
   --  or Element_Association with non-static bounds, build an expression
   --  to be used as the allocated size of the container. This may be an
@@ -6678,167 +6681,102 @@ package body Exp_Aggr is
   --  that calls the appropriate operation Insert_Op to add the value of
   --  Expr to each container element with an index in the range.
 
+  function To_Int (Expr : N_Subexpr_Id) return Int;
+  --  Return the Int value corresponding to the bound Expr
+
   
   -- Aggregate_Size --
   
 
-  function Aggregate_Size return Int is
- Comp   : Node_Id;
- Choice : Node_Id;
- Lo, Hi : Node_Id;
- Siz: Int;
-
- procedure Add_Range_Size;
- --  Compute number of components specified by a component association
- --  given by a range or subtype name.
-
- 
- -- Add_Range_Size --
- 
-
- procedure Add_Range_Size is
-function To_Int (Expr : N_Subexpr_Id) return Int;
---  Return the Int value corresponding to the bound Expr
-
-
--- To_Int --
-
-
-function To_Int (Expr : N_Subexpr_Id) return Int is
-begin
-   --  The bounds of the discrete range are integers or enumeration
-   --  literals
-   return UI_To_Int
- ((if Nkind (Expr) = N_Integer_Literal then
- Intval (Expr)
-   else
- Enumeration_Pos (Expr)));
-end To_Int;
-
---  Local variables
-
-Range_Int_Lo : constant Int := To_Int (Lo);
-Range_Int_Hi : constant Int := To_Int (Hi);
-
- begin
-Siz := Siz + Range_Int_Hi - Range_Int_Lo + 1;
-
-if No (Choice_Lo) or else Range_Int_Lo < To_Int (Choice_Lo) then
-   Choice_Lo   := Lo;

[gcc r15-4155] ada: Add dependency lines for External_Initialization

2024-10-08 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:57a26ae990f0fbde0ab6ec1d256d403561a8a4f5

commit r15-4155-g57a26ae990f0fbde0ab6ec1d256d403561a8a4f5
Author: Ronan Desplanques 
Date:   Tue Sep 10 15:54:52 2024 +0200

ada: Add dependency lines for External_Initialization

When a file included through External_Initialization has been modified,
the unit including it must be recompiled. This patch adds the
generation of dependency lines to the handling of the
External_Initialization aspect, to signal that fact to gnatmake and
other tools that invoke GNAT.

gcc/ada/ChangeLog:
* lib-writ.ads (Add_Preprocessing_Dependency): Update
documentation comment.
* sem_ch3.adb (Apply_External_Initialization): Add call to
Add_Preprocessing_Dependency.

Diff:
---
 gcc/ada/lib-writ.ads | 3 ++-
 gcc/ada/sem_ch3.adb  | 3 +++
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/gcc/ada/lib-writ.ads b/gcc/ada/lib-writ.ads
index fd62ef9363c2..38206179dfc7 100644
--- a/gcc/ada/lib-writ.ads
+++ b/gcc/ada/lib-writ.ads
@@ -1064,6 +1064,7 @@ package Lib.Writ is
 
procedure Add_Preprocessing_Dependency (S : Source_File_Index);
--  Indicate that there is a dependency to be added on a preprocessing data
-   --  file or on a preprocessing definition file.
+   --  file, on a preprocessing definition file or on a file included through
+   --  External_Initialization.
 
 end Lib.Writ;
diff --git a/gcc/ada/sem_ch3.adb b/gcc/ada/sem_ch3.adb
index 2a48882d83c3..ea0a97bd39fc 100644
--- a/gcc/ada/sem_ch3.adb
+++ b/gcc/ada/sem_ch3.adb
@@ -47,6 +47,7 @@ with Ghost;  use Ghost;
 with Itypes; use Itypes;
 with Layout; use Layout;
 with Lib;use Lib;
+with Lib.Writ;
 with Lib.Xref;   use Lib.Xref;
 with Mutably_Tagged;use Mutably_Tagged;
 with Namet;  use Namet;
@@ -3947,6 +3948,8 @@ package body Sem_Ch3 is
   return;
end if;
 
+   Lib.Writ.Add_Preprocessing_Dependency (Source_File_I);
+
Expr :=
  Make_External_Initializer
(Sloc (Specification), Source_File_I);


[gcc r15-4166] ada: Fix infinite loop on MSP430 with -mlarge flag

2024-10-08 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:9fd38cc5d636124f0611aa5d26ac4258431f164a

commit r15-4166-g9fd38cc5d636124f0611aa5d26ac4258431f164a
Author: Eric Botcazou 
Date:   Wed Sep 11 20:15:32 2024 +0200

ada: Fix infinite loop on MSP430 with -mlarge flag

This removes the loop trying to find a pointer mode among the integer modes,
which is obsolete and does not work on platforms where pointers have unusual
size like MSP430 or special semantics like Morello.

gcc/ada/ChangeLog:
PR ada/116498
* gcc-interface/decl.cc (validate_size): Use the size of the default
pointer mode as the minimum size for access types and fat pointers.

Diff:
---
 gcc/ada/gcc-interface/decl.cc | 9 ++---
 1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/gcc/ada/gcc-interface/decl.cc b/gcc/ada/gcc-interface/decl.cc
index 880eaff8d0b6..79d60c0c2213 100644
--- a/gcc/ada/gcc-interface/decl.cc
+++ b/gcc/ada/gcc-interface/decl.cc
@@ -9602,14 +9602,9 @@ validate_size (Uint uint_size, tree gnu_type, Entity_Id 
gnat_object,
 old_size = max_size (old_size, true);
 
   /* If this is an access type or a fat pointer, the minimum size is that given
- by the smallest integral mode that's valid for pointers.  */
+ by the default pointer mode.  */
   if (TREE_CODE (gnu_type) == POINTER_TYPE || TYPE_IS_FAT_POINTER_P (gnu_type))
-{
-  scalar_int_mode p_mode = NARROWEST_INT_MODE;
-  while (!targetm.valid_pointer_mode (p_mode))
-   p_mode = GET_MODE_WIDER_MODE (p_mode).require ();
-  old_size = bitsize_int (GET_MODE_BITSIZE (p_mode));
-}
+old_size = bitsize_int (ptr_mode);
 
   /* Issue an error either if the default size of the object isn't a constant
  or if the new size is smaller than it.  */


[gcc r15-4159] ada: Reject mixed container aggregates

2024-10-08 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:48fd89dc4a49cf07dbde6d26c5eb39c97a0490de

commit r15-4159-g48fd89dc4a49cf07dbde6d26c5eb39c97a0490de
Author: Viljar Indus 
Date:   Wed Sep 11 11:26:05 2024 +0300

ada: Reject mixed container aggregates

A container aggregate can either be empty, contain only
positional elements or named element associations. Reject the
scenario where the latter two are both used.

gcc/ada/ChangeLog:
* diagnostics-constructors.adb
(Make_Mixed_Container_Aggregate_Error): New function for the error
message
(Record_Mixed_Container_Aggregate_Error): New function for the
error message.
* diagnostics-constructors.ads: Likewise.
* diagnostics-repository.ads: register new diagnostics id
* diagnostics.ads: add new diagnostics id
* errout.adb (First_And_Last_Node): Detect the span for component
associations.
* sem_aggr.adb (Resolve_Container_Aggregate): reject container
aggregates that have both named and positional elements.

Diff:
---
 gcc/ada/diagnostics-constructors.adb | 39 
 gcc/ada/diagnostics-constructors.ads | 10 +
 gcc/ada/diagnostics-repository.ads   |  5 +
 gcc/ada/diagnostics.ads  |  3 ++-
 gcc/ada/errout.adb   |  2 ++
 gcc/ada/sem_aggr.adb | 25 +++
 6 files changed, 75 insertions(+), 9 deletions(-)

diff --git a/gcc/ada/diagnostics-constructors.adb 
b/gcc/ada/diagnostics-constructors.adb
index 8a9e10a7cbef..ce130cceaa21 100644
--- a/gcc/ada/diagnostics-constructors.adb
+++ b/gcc/ada/diagnostics-constructors.adb
@@ -472,4 +472,43 @@ package body Diagnostics.Constructors is
 (Make_Representation_Too_Late_Error (Rep, Freeze, Def));
end Record_Representation_Too_Late_Error;
 
+   --
+   -- Make_Mixed_Container_Aggregate_Error --
+   --
+
+   function Make_Mixed_Container_Aggregate_Error
+ (Aggr   : Node_Id;
+  Pos_Elem   : Node_Id;
+  Named_Elem : Node_Id) return Diagnostic_Type
+   is
+
+   begin
+  return
+Make_Diagnostic
+  (Msg   =>
+ "container aggregate cannot be both positional and named",
+   Location  => Primary_Labeled_Span (Aggr),
+   Id=> GNAT0011,
+   Kind  => Diagnostics.Error,
+   Spans =>
+ (1 => Secondary_Labeled_Span
+   (Pos_Elem, "positional element "),
+ 2 => Secondary_Labeled_Span
+   (Named_Elem, "named element")));
+   end Make_Mixed_Container_Aggregate_Error;
+
+   
+   -- Record_Mixed_Container_Aggregate_Error --
+   
+
+   procedure Record_Mixed_Container_Aggregate_Error
+ (Aggr   : Node_Id;
+  Pos_Elem   : Node_Id;
+  Named_Elem : Node_Id)
+   is
+   begin
+  Record_Diagnostic
+(Make_Mixed_Container_Aggregate_Error (Aggr, Pos_Elem, Named_Elem));
+   end Record_Mixed_Container_Aggregate_Error;
+
 end Diagnostics.Constructors;
diff --git a/gcc/ada/diagnostics-constructors.ads 
b/gcc/ada/diagnostics-constructors.ads
index 96782b3475fb..973d176f56f2 100644
--- a/gcc/ada/diagnostics-constructors.ads
+++ b/gcc/ada/diagnostics-constructors.ads
@@ -130,4 +130,14 @@ package Diagnostics.Constructors is
   Freeze : Node_Id;
   Def: Node_Id);
 
+   function Make_Mixed_Container_Aggregate_Error
+ (Aggr   : Node_Id;
+  Pos_Elem   : Node_Id;
+  Named_Elem : Node_Id) return Diagnostic_Type;
+
+   procedure Record_Mixed_Container_Aggregate_Error
+ (Aggr   : Node_Id;
+  Pos_Elem   : Node_Id;
+  Named_Elem : Node_Id);
+
 end Diagnostics.Constructors;
diff --git a/gcc/ada/diagnostics-repository.ads 
b/gcc/ada/diagnostics-repository.ads
index b070fda02698..ae8dc6862d66 100644
--- a/gcc/ada/diagnostics-repository.ads
+++ b/gcc/ada/diagnostics-repository.ads
@@ -101,6 +101,11 @@ package Diagnostics.Repository is
 (Status=> Active,
  Human_Id  => new String'("Representation_Too_Late_Error"),
  Documentation => new String'("./error_codes/GNAT0010.md"),
+ Switch=> No_Switch_Id),
+  GNAT0011 =>
+(Status=> Active,
+ Human_Id  => new String'("Mixed_Container_Aggregate_Error"),
+ Documentation => new String'("./error_codes/GNAT0011.md"),
  Switch=> No_Switch_Id));
 
procedure Print_Diagnostic_Repository;
diff --git a/gcc/ada/diagnostics.ads b/gcc/ada/diagnostics.ads
index 18afb1c21baf..f456927b06fe 100644
--- a/gcc/ada/diagnostics.ads
+++ b/gcc/ada/diagnostics.ads
@@ -39,7 +39,8 @@ package Diagnostics is
   GNAT0007,
   GNAT0008,
   GNAT0009,
-  GNAT0010);
+  GNAT0010,
+  GNAT0011);
 
--  

[gcc r15-4161] ada: Fix negative value returned by 'Image for array with nonnegative component

2024-10-08 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:cfbee1856f5125bbabc28088f62a86f3dee5a159

commit r15-4161-gcfbee1856f5125bbabc28088f62a86f3dee5a159
Author: Eric Botcazou 
Date:   Wed Sep 11 19:37:08 2024 +0200

ada: Fix negative value returned by 'Image for array with nonnegative 
component

The problem is that Exp_Put_Image.Build_Elementary_Put_Image_Call uses the
signedness of the base type but the size of the first subtype, hence the
discrepancy between them.

gcc/ada/ChangeLog:
PR ada/115535
* exp_put_image.adb (Build_Elementary_Put_Image_Call): Use the size
of the underlying type to find the support type.

Diff:
---
 gcc/ada/exp_put_image.adb | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/gcc/ada/exp_put_image.adb b/gcc/ada/exp_put_image.adb
index 190ac99b5653..36254fffd618 100644
--- a/gcc/ada/exp_put_image.adb
+++ b/gcc/ada/exp_put_image.adb
@@ -293,10 +293,9 @@ package body Exp_Put_Image is
   Loc : constant Source_Ptr := Sloc (N);
   P_Type  : constant Entity_Id  := Entity (Prefix (N));
   U_Type  : constant Entity_Id  := Underlying_Type (P_Type);
-  FST : constant Entity_Id  := First_Subtype (U_Type);
   Sink: constant Node_Id:= First (Expressions (N));
   Item: constant Node_Id:= Next (Sink);
-  P_Size  : constant Uint   := Esize (FST);
+  P_Size  : constant Uint   := Esize (U_Type);
   Lib_RE  : RE_Id;
 
begin


[gcc r15-4157] ada: Tweak position of comment

2024-10-08 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:3e8b4d3b68df3df29a56d3206df5cddf0d4d01df

commit r15-4157-g3e8b4d3b68df3df29a56d3206df5cddf0d4d01df
Author: Ronan Desplanques 
Date:   Mon Sep 9 17:53:28 2024 +0200

ada: Tweak position of comment

This patch puts a comment explaining the absence of Storage_Size in an
alphabetically sorted list at the spot where Storage_Size would be in
that list.

gcc/ada/ChangeLog:
* snames.ads-tmpl: Tweak position of comment.

Diff:
---
 gcc/ada/snames.ads-tmpl | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/gcc/ada/snames.ads-tmpl b/gcc/ada/snames.ads-tmpl
index b11eb3070fb7..0d00b89d8e47 100644
--- a/gcc/ada/snames.ads-tmpl
+++ b/gcc/ada/snames.ads-tmpl
@@ -680,6 +680,8 @@ package Snames is
Name_Shared_Passive : constant Name_Id := N + $;
Name_Side_Effects   : constant Name_Id := N + $; -- GNAT
Name_Simple_Storage_Pool_Type   : constant Name_Id := N + $; -- GNAT
+   Name_Source_Reference   : constant Name_Id := N + $; -- GNAT
+   Name_Static_Elaboration_Desired : constant Name_Id := N + $; -- GNAT
 
--  Note: Storage_Size is not in this list because its name matches the name
--  of the corresponding attribute. However, it is included in the
@@ -689,8 +691,6 @@ package Snames is
--  Note: Storage_Unit is also omitted from the list because of a clash with
--  an attribute name, and is treated similarly.
 
-   Name_Source_Reference   : constant Name_Id := N + $; -- GNAT
-   Name_Static_Elaboration_Desired : constant Name_Id := N + $; -- GNAT
Name_Stream_Convert : constant Name_Id := N + $; -- GNAT
Name_Subprogram_Variant : constant Name_Id := N + $; -- GNAT
Name_Subtitle   : constant Name_Id := N + $; -- GNAT


[gcc r15-4162] ada: Fix bogus error in instantiation with formal package

2024-10-08 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:d77ba2eec2a560514de162bf9499194250f291e2

commit r15-4162-gd77ba2eec2a560514de162bf9499194250f291e2
Author: Eric Botcazou 
Date:   Wed Sep 11 19:42:03 2024 +0200

ada: Fix bogus error in instantiation with formal package

The compiler reports that an actual does not match the formal when there
is a defaulted formal discrete type because Check_Formal_Package_Instance
fails to skip the implicit base type generated by the compiler.

gcc/ada/ChangeLog:
PR ada/114636
* sem_ch12.adb (Check_Formal_Package_Instance): For a defaulted
formal discrete type, skip the generated implicit base type.

Diff:
---
 gcc/ada/sem_ch12.adb | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/gcc/ada/sem_ch12.adb b/gcc/ada/sem_ch12.adb
index b406cfce3b32..33f6f18c50b2 100644
--- a/gcc/ada/sem_ch12.adb
+++ b/gcc/ada/sem_ch12.adb
@@ -7337,8 +7337,12 @@ package body Sem_Ch12 is
  then
 --  If the formal is a tagged type the corresponding class-wide
 --  type has been generated as well, and it must be skipped.
+--  Likewise, for a formal discrete type, the base type has been
+--  generated as well (see Analyze_Formal_Discrete_Type).
 
-if Is_Type (E2) and then Is_Tagged_Type (E2) then
+if Is_Type (E2)
+  and then (Is_Tagged_Type (E2) or else Is_Enumeration_Type (E2))
+then
Next_Entity (E2);
 end if;


[gcc r15-4167] ssa-math-opts, i386: Handle most unordered values rather than just 2 [PR116896]

2024-10-08 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:ff889b35935d5e796cf308fb2368d4e319c60ece

commit r15-4167-gff889b35935d5e796cf308fb2368d4e319c60ece
Author: Jakub Jelinek 
Date:   Tue Oct 8 10:40:29 2024 +0200

ssa-math-opts, i386: Handle most unordered values rather than just 2 
[PR116896]

On Mon, Oct 07, 2024 at 10:32:57AM +0200, Richard Biener wrote:
> > They are implementation defined, -1, 0, 1, 2 is defined by libstdc++:
> > using type = signed char;
> > enum class _Ord : type { equivalent = 0, less = -1, greater = 1 };
> > enum class _Ncmp : type { _Unordered = 2 };
> > https://eel.is/c++draft/cmp#categories.pre-1 documents them as
> > enum class ord { equal = 0, equivalent = equal, less = -1, greater = 1 
}; // exposition only
> > enum class ncmp { unordered = -127 };   
  // exposition only
> > and now looking at it, LLVM's libc++ takes that literally and uses
> > -1, 0, 1, -127.  One can't use <=> operator without including 
> > which provides the enums, so I think if all we care about is libstdc++,
> > then just hardcoding -1, 0, 1, 2 is fine, if we want to also optimize
> > libc++ when used with gcc, we could support -1, 0, 1, -127 as another
> > option.
> > Supporting arbitrary 4 values doesn't make sense, at least on x86 the
> > only reason to do the conversion to int in an optab is a good sequence
> > to turn the flag comparisons to -1, 0, 1.  So, either we do nothing
> > more than the patch, or add handle both 2 and -127 for unordered,
> > or add support for arbitrary value for the unordered case except
> > -1, 0, 1 (then -1 could mean signed int, 1 unsigned int, 0 do the jumps
> > and any other value what should be returned for unordered.

Here is an incremental patch which adds support for (almost) arbitrary
unordered constant value.  It changes the .SPACESHIP and spaceship4
optab conventions, so 0 means use branches, floating point, -1, 0, 1, 2
results consumed by tree-ssa-math-opts.cc emitted comparisons, -1
means signed int comparisons, -1, 0, 1 results, 1 means unsigned int
comparisons, -1, 0, 1 results, and for constant other than -1, 0, 1
which fit into [-128, 127] converted to the PHI type are otherwise
specified as the last argument (then it is -1, 0, 1, C results).

2024-10-08  Jakub Jelinek  

PR middle-end/116896
* tree-ssa-math-opts.cc (optimize_spaceship): Handle unordered 
values
other than 2, but they still need to be signed char range possibly
converted to the PHI result and can't be in [-1, 1] range.  Use
last .SPACESHIP argument of 1 for unsigned int comparisons, -1 for
signed int, 0 for floating point branches and any other for floating
point with that value as unordered.
* config/i386/i386-expand.cc (ix86_expand_fp_spaceship): Use op2 
rather
const2_rtx if op2 is not const0_rtx for unordered result.
(ix86_expand_int_spaceship): Change INTVAL (op2) == 1 tests to
INTVAL (op2) != -1.
* doc/md.texi (spaceship@var{m}4): Document the above changes.

* gcc.target/i386/pr116896.c: New test.

Diff:
---
 gcc/config/i386/i386-expand.cc   |  8 ++---
 gcc/doc/md.texi  |  7 ++--
 gcc/testsuite/gcc.target/i386/pr116896.c | 59 
 gcc/tree-ssa-math-opts.cc| 42 +--
 4 files changed, 100 insertions(+), 16 deletions(-)

diff --git a/gcc/config/i386/i386-expand.cc b/gcc/config/i386/i386-expand.cc
index 81dd50649007..32840113cf60 100644
--- a/gcc/config/i386/i386-expand.cc
+++ b/gcc/config/i386/i386-expand.cc
@@ -3234,7 +3234,7 @@ ix86_expand_fp_spaceship (rtx dest, rtx op0, rtx op1, rtx 
op2)
   if (l2)
 {
   emit_label (l2);
-  emit_move_insn (dest, const2_rtx);
+  emit_move_insn (dest, op2 == const0_rtx ? const2_rtx : op2);
 }
   emit_label (lend);
 }
@@ -3250,11 +3250,11 @@ ix86_expand_int_spaceship (rtx dest, rtx op0, rtx op1, 
rtx op2)
  operands nor optimize CC mode - we need a mode usable for both
  LT and GT resp. LTU and GTU comparisons with the same unswapped
  operands.  */
-  rtx flags = gen_rtx_REG (INTVAL (op2) == 1 ? CCGCmode : CCmode, FLAGS_REG);
+  rtx flags = gen_rtx_REG (INTVAL (op2) != 1 ? CCGCmode : CCmode, FLAGS_REG);
   rtx tmp = gen_rtx_COMPARE (GET_MODE (flags), op0, op1);
   emit_insn (gen_rtx_SET (flags, tmp));
   rtx lt_tmp = gen_reg_rtx (QImode);
-  ix86_expand_setcc (lt_tmp, INTVAL (op2) == 1 ? LT : LTU, flags,
+  ix86_expand_setcc (lt_tmp, INTVAL (op2) != 1 ? LT : LTU, flags,
 const0_rtx);
   if (GET_MODE (dest) != QImode)
 {
@@ -3264,7 +3264,7 @@ ix86_expand_int_spaceship (rtx dest, rtx op0, rtx op1, 
rtx op2)
   lt_tmp = tmp;
 }
   rtx gt_tmp = gen_reg_rtx (QImode);
-  ix86_expand_setcc

[gcc r14-10754] Add regression test

2024-10-08 Thread Eric Botcazou via Gcc-cvs
https://gcc.gnu.org/g:932d1c3adb5759a0f37779ed027e96647bdb8b60

commit r14-10754-g932d1c3adb5759a0f37779ed027e96647bdb8b60
Author: Eric Botcazou 
Date:   Tue Oct 8 15:08:15 2024 +0200

Add regression test

gcc/testsuite/
PR ada/114636
* gnat.dg/specs/generic_inst1.ads: New test.

Diff:
---
 gcc/testsuite/gnat.dg/specs/generic_inst1.ads | 32 +++
 1 file changed, 32 insertions(+)

diff --git a/gcc/testsuite/gnat.dg/specs/generic_inst1.ads 
b/gcc/testsuite/gnat.dg/specs/generic_inst1.ads
new file mode 100644
index ..fdf48c020b09
--- /dev/null
+++ b/gcc/testsuite/gnat.dg/specs/generic_inst1.ads
@@ -0,0 +1,32 @@
+-- { dg-do compile }
+
+package Generic_Inst1 is
+
+   generic
+  type Terminals is (<>);
+  type Nonterminals is (<>);
+   package Types is
+  type Action is record
+ data : Integer;
+  end record;
+   end Types;
+
+   generic
+  type States is (<>);
+  type Input_T is (<>);
+  type Action_T is private;
+   package FSM is
+   end FSM;
+
+   generic
+  with package Typs is new Types (<>);
+  with package SMs is new FSM
+(States => <>, Input_T => Typs.Terminals, Action_T => Typs.Action);
+   package Gen is
+   end Gen;
+
+   package Typs is new Types (Natural, Integer);
+   package SMs is new FSM (Integer, Natural, Typs.Action);
+   package Generator is new Gen (Typs, SMs);
+
+end Generic_Inst1;


[gcc r14-10753] ada: Fix bogus error in instantiation with formal package

2024-10-08 Thread Eric Botcazou via Gcc-cvs
https://gcc.gnu.org/g:89d2007d211947c0085c6852749a7d348cb458fd

commit r14-10753-g89d2007d211947c0085c6852749a7d348cb458fd
Author: Eric Botcazou 
Date:   Wed Sep 11 19:42:03 2024 +0200

ada: Fix bogus error in instantiation with formal package

The compiler reports that an actual does not match the formal when there
is a defaulted formal discrete type because Check_Formal_Package_Instance
fails to skip the implicit base type generated by the compiler.

gcc/ada/ChangeLog:
PR ada/114636
* sem_ch12.adb (Check_Formal_Package_Instance): For a defaulted
formal discrete type, skip the generated implicit base type.

Diff:
---
 gcc/ada/sem_ch12.adb | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/gcc/ada/sem_ch12.adb b/gcc/ada/sem_ch12.adb
index e7b759c4e88b..c06377ab4c9c 100644
--- a/gcc/ada/sem_ch12.adb
+++ b/gcc/ada/sem_ch12.adb
@@ -6696,8 +6696,12 @@ package body Sem_Ch12 is
  then
 --  If the formal is a tagged type the corresponding class-wide
 --  type has been generated as well, and it must be skipped.
+--  Likewise, for a formal discrete type, the base type has been
+--  generated as well (see Analyze_Formal_Discrete_Type).
 
-if Is_Type (E2) and then Is_Tagged_Type (E2) then
+if Is_Type (E2)
+  and then (Is_Tagged_Type (E2) or else Is_Enumeration_Type (E2))
+then
Next_Entity (E2);
 end if;


[gcc r13-9094] ada: Fix negative value returned by 'Image for array with nonnegative component

2024-10-08 Thread Eric Botcazou via Gcc-cvs
https://gcc.gnu.org/g:d0abc47f940173863966c04d852fa75e76d07be9

commit r13-9094-gd0abc47f940173863966c04d852fa75e76d07be9
Author: Eric Botcazou 
Date:   Wed Sep 11 19:37:08 2024 +0200

ada: Fix negative value returned by 'Image for array with nonnegative 
component

The problem is that Exp_Put_Image.Build_Elementary_Put_Image_Call uses the
signedness of the base type but the size of the first subtype, hence the
discrepancy between them.

gcc/ada/ChangeLog:
PR ada/115535
* exp_put_image.adb (Build_Elementary_Put_Image_Call): Use the size
of the underlying type to find the support type.

Diff:
---
 gcc/ada/exp_put_image.adb | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/gcc/ada/exp_put_image.adb b/gcc/ada/exp_put_image.adb
index 19e0415e4172..578637f3a3e2 100644
--- a/gcc/ada/exp_put_image.adb
+++ b/gcc/ada/exp_put_image.adb
@@ -293,10 +293,9 @@ package body Exp_Put_Image is
   Loc : constant Source_Ptr := Sloc (N);
   P_Type  : constant Entity_Id  := Entity (Prefix (N));
   U_Type  : constant Entity_Id  := Underlying_Type (P_Type);
-  FST : constant Entity_Id  := First_Subtype (U_Type);
   Sink: constant Node_Id:= First (Expressions (N));
   Item: constant Node_Id:= Next (Sink);
-  P_Size  : constant Uint   := Esize (FST);
+  P_Size  : constant Uint   := Esize (U_Type);
   Lib_RE  : RE_Id;
 
begin


[gcc r13-9095] Add regression test

2024-10-08 Thread Eric Botcazou via Gcc-cvs
https://gcc.gnu.org/g:eec5e10a79daa0a4fb41f7fb2e59db3318821e62

commit r13-9095-geec5e10a79daa0a4fb41f7fb2e59db3318821e62
Author: Eric Botcazou 
Date:   Tue Oct 8 15:15:26 2024 +0200

Add regression test

gcc/testsuite/
PR ada/115535
* gnat.dg/put_image1.adb: New test

Diff:
---
 gcc/testsuite/gnat.dg/put_image1.adb | 21 +
 1 file changed, 21 insertions(+)

diff --git a/gcc/testsuite/gnat.dg/put_image1.adb 
b/gcc/testsuite/gnat.dg/put_image1.adb
new file mode 100644
index ..396967ce1157
--- /dev/null
+++ b/gcc/testsuite/gnat.dg/put_image1.adb
@@ -0,0 +1,21 @@
+-- { dg-do run }
+-- { dg-options "-gnat2022" }
+
+with Ada.Text_IO; use Ada.Text_IO;
+
+procedure Put_Image1 is
+
+  type Client_ID_Part is range 0 .. 2**32 - 1 with Size => 32;
+
+  type Client_ID is array (1 .. 2) of Client_ID_Part;
+
+  A : Client_ID := (1479222903, 3163714999);
+
+begin
+   Put_Line (A'Image);
+   -- { dg-output ".* 1479222903,  3163714999.*\n" }
+   Put_Line (A (1)'Image);
+   -- { dg-output " 1479222903.*\n" }
+   Put_Line (A (2)'Image);
+   -- { dg-output " 3163714999.*\n" }
+end;


[gcc r14-10757] Add regression test

2024-10-08 Thread Eric Botcazou via Gcc-cvs
https://gcc.gnu.org/g:4390e95fa5304110562777292c6d3e3dc97de8f6

commit r14-10757-g4390e95fa5304110562777292c6d3e3dc97de8f6
Author: Eric Botcazou 
Date:   Tue Oct 8 15:15:26 2024 +0200

Add regression test

gcc/testsuite/
PR ada/115535
* gnat.dg/put_image1.adb: New test

Diff:
---
 gcc/testsuite/gnat.dg/put_image1.adb | 21 +
 1 file changed, 21 insertions(+)

diff --git a/gcc/testsuite/gnat.dg/put_image1.adb 
b/gcc/testsuite/gnat.dg/put_image1.adb
new file mode 100644
index ..396967ce1157
--- /dev/null
+++ b/gcc/testsuite/gnat.dg/put_image1.adb
@@ -0,0 +1,21 @@
+-- { dg-do run }
+-- { dg-options "-gnat2022" }
+
+with Ada.Text_IO; use Ada.Text_IO;
+
+procedure Put_Image1 is
+
+  type Client_ID_Part is range 0 .. 2**32 - 1 with Size => 32;
+
+  type Client_ID is array (1 .. 2) of Client_ID_Part;
+
+  A : Client_ID := (1479222903, 3163714999);
+
+begin
+   Put_Line (A'Image);
+   -- { dg-output ".* 1479222903,  3163714999.*\n" }
+   Put_Line (A (1)'Image);
+   -- { dg-output " 1479222903.*\n" }
+   Put_Line (A (2)'Image);
+   -- { dg-output " 3163714999.*\n" }
+end;


[gcc r13-9091] ada: Fix bogus error in instantiation with formal package

2024-10-08 Thread Eric Botcazou via Gcc-cvs
https://gcc.gnu.org/g:8547dab3cb619b91112466bc0dc97379240b9011

commit r13-9091-g8547dab3cb619b91112466bc0dc97379240b9011
Author: Eric Botcazou 
Date:   Wed Sep 11 19:42:03 2024 +0200

ada: Fix bogus error in instantiation with formal package

The compiler reports that an actual does not match the formal when there
is a defaulted formal discrete type because Check_Formal_Package_Instance
fails to skip the implicit base type generated by the compiler.

gcc/ada/ChangeLog:
PR ada/114636
* sem_ch12.adb (Check_Formal_Package_Instance): For a defaulted
formal discrete type, skip the generated implicit base type.

Diff:
---
 gcc/ada/sem_ch12.adb | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/gcc/ada/sem_ch12.adb b/gcc/ada/sem_ch12.adb
index ff62ff003278..89581bd5bb60 100644
--- a/gcc/ada/sem_ch12.adb
+++ b/gcc/ada/sem_ch12.adb
@@ -6693,8 +6693,12 @@ package body Sem_Ch12 is
  then
 --  If the formal is a tagged type the corresponding class-wide
 --  type has been generated as well, and it must be skipped.
+--  Likewise, for a formal discrete type, the base type has been
+--  generated as well (see Analyze_Formal_Discrete_Type).
 
-if Is_Type (E2) and then Is_Tagged_Type (E2) then
+if Is_Type (E2)
+  and then (Is_Tagged_Type (E2) or else Is_Enumeration_Type (E2))
+then
Next_Entity (E2);
 end if;


[gcc r13-9092] Add regression test

2024-10-08 Thread Eric Botcazou via Gcc-cvs
https://gcc.gnu.org/g:b3cf0bd981327077fc90fd89540d2fa051675636

commit r13-9092-gb3cf0bd981327077fc90fd89540d2fa051675636
Author: Eric Botcazou 
Date:   Tue Oct 8 15:08:15 2024 +0200

Add regression test

gcc/testsuite/
PR ada/114636
* gnat.dg/specs/generic_inst1.ads: New test.

Diff:
---
 gcc/testsuite/gnat.dg/specs/generic_inst1.ads | 32 +++
 1 file changed, 32 insertions(+)

diff --git a/gcc/testsuite/gnat.dg/specs/generic_inst1.ads 
b/gcc/testsuite/gnat.dg/specs/generic_inst1.ads
new file mode 100644
index ..fdf48c020b09
--- /dev/null
+++ b/gcc/testsuite/gnat.dg/specs/generic_inst1.ads
@@ -0,0 +1,32 @@
+-- { dg-do compile }
+
+package Generic_Inst1 is
+
+   generic
+  type Terminals is (<>);
+  type Nonterminals is (<>);
+   package Types is
+  type Action is record
+ data : Integer;
+  end record;
+   end Types;
+
+   generic
+  type States is (<>);
+  type Input_T is (<>);
+  type Action_T is private;
+   package FSM is
+   end FSM;
+
+   generic
+  with package Typs is new Types (<>);
+  with package SMs is new FSM
+(States => <>, Input_T => Typs.Terminals, Action_T => Typs.Action);
+   package Gen is
+   end Gen;
+
+   package Typs is new Types (Natural, Integer);
+   package SMs is new FSM (Integer, Natural, Typs.Action);
+   package Generator is new Gen (Typs, SMs);
+
+end Generic_Inst1;


[gcc r14-10755] ada: Fix internal error on elsif part of if-statement containing if-expression

2024-10-08 Thread Eric Botcazou via Gcc-cvs
https://gcc.gnu.org/g:c9fe4eae41c0e05ef213b9a47c611d5fc704006a

commit r14-10755-gc9fe4eae41c0e05ef213b9a47c611d5fc704006a
Author: Eric Botcazou 
Date:   Wed Sep 11 19:26:18 2024 +0200

ada: Fix internal error on elsif part of if-statement containing 
if-expression

The problem occurs when the compiler is trying to find a context to which
it can hoist finalization actions coming from the if-expression, because
Find_Hook_Context incorrectly returns the N_Elsif_Part node.

gcc/ada/ChangeLog:
PR ada/114640
* exp_util.adb (Find_Hook_Context): For a node present within a
conditional expression, do not return an N_Elsif_Part node.

Diff:
---
 gcc/ada/exp_util.adb | 1 +
 1 file changed, 1 insertion(+)

diff --git a/gcc/ada/exp_util.adb b/gcc/ada/exp_util.adb
index 47a928a6a40d..f81380846e00 100644
--- a/gcc/ada/exp_util.adb
+++ b/gcc/ada/exp_util.adb
@@ -6555,6 +6555,7 @@ package body Exp_Util is
 | N_Aggregate
 | N_Delta_Aggregate
 | N_Extension_Aggregate
+| N_Elsif_Part
   and then Nkind (Parent (Par)) not in N_Function_Call
  | N_Procedure_Call_Statement
  | N_Entry_Call_Statement


[gcc r13-9093] ada: Fix internal error on elsif part of if-statement containing if-expression

2024-10-08 Thread Eric Botcazou via Gcc-cvs
https://gcc.gnu.org/g:da4f4b27c8f8e29be2003dc3771f8eae3b90e2ff

commit r13-9093-gda4f4b27c8f8e29be2003dc3771f8eae3b90e2ff
Author: Eric Botcazou 
Date:   Wed Sep 11 19:26:18 2024 +0200

ada: Fix internal error on elsif part of if-statement containing 
if-expression

The problem occurs when the compiler is trying to find a context to which
it can hoist finalization actions coming from the if-expression, because
Find_Hook_Context incorrectly returns the N_Elsif_Part node.

gcc/ada/ChangeLog:
PR ada/114640
* exp_util.adb (Find_Hook_Context): For a node present within a
conditional expression, do not return an N_Elsif_Part node.

Diff:
---
 gcc/ada/exp_util.adb | 1 +
 1 file changed, 1 insertion(+)

diff --git a/gcc/ada/exp_util.adb b/gcc/ada/exp_util.adb
index 5435375d92e8..fa1370f70780 100644
--- a/gcc/ada/exp_util.adb
+++ b/gcc/ada/exp_util.adb
@@ -6486,6 +6486,7 @@ package body Exp_Util is
 | N_Aggregate
 | N_Delta_Aggregate
 | N_Extension_Aggregate
+| N_Elsif_Part
   and then Nkind (Parent (Par)) not in N_Function_Call
  | N_Procedure_Call_Statement
  | N_Entry_Call_Statement


[gcc r14-10756] ada: Fix negative value returned by 'Image for array with nonnegative component

2024-10-08 Thread Eric Botcazou via Gcc-cvs
https://gcc.gnu.org/g:f45fc31bd618154c270fa5a7b354d2025800862b

commit r14-10756-gf45fc31bd618154c270fa5a7b354d2025800862b
Author: Eric Botcazou 
Date:   Wed Sep 11 19:37:08 2024 +0200

ada: Fix negative value returned by 'Image for array with nonnegative 
component

The problem is that Exp_Put_Image.Build_Elementary_Put_Image_Call uses the
signedness of the base type but the size of the first subtype, hence the
discrepancy between them.

gcc/ada/ChangeLog:
PR ada/115535
* exp_put_image.adb (Build_Elementary_Put_Image_Call): Use the size
of the underlying type to find the support type.

Diff:
---
 gcc/ada/exp_put_image.adb | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/gcc/ada/exp_put_image.adb b/gcc/ada/exp_put_image.adb
index c298163f36fd..b7327f1f0677 100644
--- a/gcc/ada/exp_put_image.adb
+++ b/gcc/ada/exp_put_image.adb
@@ -293,10 +293,9 @@ package body Exp_Put_Image is
   Loc : constant Source_Ptr := Sloc (N);
   P_Type  : constant Entity_Id  := Entity (Prefix (N));
   U_Type  : constant Entity_Id  := Underlying_Type (P_Type);
-  FST : constant Entity_Id  := First_Subtype (U_Type);
   Sink: constant Node_Id:= First (Expressions (N));
   Item: constant Node_Id:= Next (Sink);
-  P_Size  : constant Uint   := Esize (FST);
+  P_Size  : constant Uint   := Esize (U_Type);
   Lib_RE  : RE_Id;
 
begin


[gcc r14-10758] ada: Fix wrong finalization of anonymous array aggregate

2024-10-08 Thread Eric Botcazou via Gcc-cvs
https://gcc.gnu.org/g:f8e9c36aa3daf9782cf9b887d4f3f28766642b37

commit r14-10758-gf8e9c36aa3daf9782cf9b887d4f3f28766642b37
Author: Eric Botcazou 
Date:   Thu Sep 5 00:19:25 2024 +0200

ada: Fix wrong finalization of anonymous array aggregate

The issue arises when the aggregate consists only of iterated associations
because, in this case, its expansion uses a 2-pass mechanism which creates
a temporary that needs a fully-fledged initialization, thus running afoul
of the optimization that avoids building the initialization procedure in
the anonymous array case.

gcc/ada/ChangeLog:
* exp_aggr.ads (Is_Two_Pass_Aggregate): New function declaration.
* exp_aggr.adb (Is_Two_Pass_Aggregate): New function body.
(Expand_Array_Aggregate): Call Is_Two_Pass_Aggregate to detect the
aggregates that need the 2-pass expansion.
* exp_ch3.adb (Expand_Freeze_Array_Type): In the anonymous array
case, build the initialization procedure if the initial value in
the object declaration is a 2-pass aggregate.

Diff:
---
 gcc/ada/exp_aggr.adb | 22 --
 gcc/ada/exp_aggr.ads |  4 
 gcc/ada/exp_ch3.adb  | 15 ++-
 3 files changed, 30 insertions(+), 11 deletions(-)

diff --git a/gcc/ada/exp_aggr.adb b/gcc/ada/exp_aggr.adb
index 950f310b58cd..a20ca7bb9389 100644
--- a/gcc/ada/exp_aggr.adb
+++ b/gcc/ada/exp_aggr.adb
@@ -5908,12 +5908,7 @@ package body Exp_Aggr is
   then
  return;
 
-  elsif Present (Component_Associations (N))
-and then Nkind (First (Component_Associations (N))) =
- N_Iterated_Component_Association
-and then
-  Present (Iterator_Specification (First (Component_Associations (N
-  then
+  elsif Is_Two_Pass_Aggregate (N) then
  Two_Pass_Aggregate_Expansion (N);
  return;
 
@@ -8710,6 +8705,21 @@ package body Exp_Aggr is
 and then C in Uint_1 | Uint_2 | Uint_4; -- False if No_Uint
end Is_Two_Dim_Packed_Array;
 
+   ---
+   -- Is_Two_Pass_Aggregate --
+   ---
+
+   function Is_Two_Pass_Aggregate (N : Node_Id) return Boolean is
+   begin
+  return Nkind (N) = N_Aggregate
+and then Present (Component_Associations (N))
+and then Nkind (First (Component_Associations (N))) =
+   N_Iterated_Component_Association
+and then
+  Present
+(Iterator_Specification (First (Component_Associations (N;
+   end Is_Two_Pass_Aggregate;
+

-- Late_Expansion --

diff --git a/gcc/ada/exp_aggr.ads b/gcc/ada/exp_aggr.ads
index 8db0a0206630..bed54ecddea3 100644
--- a/gcc/ada/exp_aggr.ads
+++ b/gcc/ada/exp_aggr.ads
@@ -35,6 +35,10 @@ package Exp_Aggr is
--  Returns True if N is an aggregate of some kind whose Expansion_Delayed
--  flag is set (see sinfo for meaning of flag).
 
+   function Is_Two_Pass_Aggregate (N : Node_Id) return Boolean;
+   --  Return True if N is an aggregate that is to be expanded in two passes.
+   --  This is the case if it consists only of iterated associations.
+
procedure Convert_Aggr_In_Object_Decl (N : Node_Id);
--  N is a N_Object_Declaration with an expression which must be an
--  N_Aggregate or N_Extension_Aggregate with Expansion_Delayed.
diff --git a/gcc/ada/exp_ch3.adb b/gcc/ada/exp_ch3.adb
index fdedf3294fec..f8324369b33c 100644
--- a/gcc/ada/exp_ch3.adb
+++ b/gcc/ada/exp_ch3.adb
@@ -4889,17 +4889,22 @@ package body Exp_Ch3 is
 
  if No (Init_Proc (Base)) then
 
---  If this is an anonymous array created for a declaration with
---  an initial value, its init_proc will never be called. The
+--  If this is an anonymous array built for an object declaration
+--  with an initial value, its Init_Proc will never be called. The
 --  initial value itself may have been expanded into assignments,
---  in which case the object declaration is carries the
---  No_Initialization flag.
+--  in which case the declaration has the No_Initialization flag.
+--  The exception is when the initial value is a 2-pass aggregate,
+--  because the special expansion used for it creates a temporary
+--  that needs a fully-fledged initialization.
 
 if Is_Itype (Base)
   and then Nkind (Associated_Node_For_Itype (Base)) =
 N_Object_Declaration
   and then
-(Present (Expression (Associated_Node_For_Itype (Base)))
+((Present (Expression (Associated_Node_For_Itype (Base)))
+and then not
+  Is_Two_Pass_Aggregate
+(Expression (Associated_Node_For_Itype (Base
   or else No_Initialization

[gcc r14-10759] Add regression test

2024-10-08 Thread Eric Botcazou via Gcc-cvs
https://gcc.gnu.org/g:70c46d8e455144cf5968d38b932692cbe0cfa2e1

commit r14-10759-g70c46d8e455144cf5968d38b932692cbe0cfa2e1
Author: Eric Botcazou 
Date:   Tue Oct 8 15:17:27 2024 +0200

Add regression test

gcc/testsuite/
PR ada/116190
* gnat.dg/aggr31.adb: New test.

Diff:
---
 gcc/testsuite/gnat.dg/aggr31.adb | 17 +
 1 file changed, 17 insertions(+)

diff --git a/gcc/testsuite/gnat.dg/aggr31.adb b/gcc/testsuite/gnat.dg/aggr31.adb
new file mode 100644
index ..8e95f808d88e
--- /dev/null
+++ b/gcc/testsuite/gnat.dg/aggr31.adb
@@ -0,0 +1,17 @@
+-- { dg-do run }
+-- { dg-options "-gnat2022" }
+
+with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
+
+procedure Aggr31 is
+
+  My_Array : constant array (1 .. 5) of Unbounded_String :=
+[others => To_Unbounded_String ("Test")];
+
+  This_Crashes : constant array (Natural range <>) of Unbounded_String :=
+[for I of My_Array => I];
+
+begin
+  null;
+end;
+


[gcc r13-9096] ada: Fix wrong finalization of anonymous array aggregate

2024-10-08 Thread Eric Botcazou via Gcc-cvs
https://gcc.gnu.org/g:60b352cd6608727a6c24a2cb1b08b3159a865637

commit r13-9096-g60b352cd6608727a6c24a2cb1b08b3159a865637
Author: Eric Botcazou 
Date:   Thu Sep 5 00:19:25 2024 +0200

ada: Fix wrong finalization of anonymous array aggregate

The issue arises when the aggregate consists only of iterated associations
because, in this case, its expansion uses a 2-pass mechanism which creates
a temporary that needs a fully-fledged initialization, thus running afoul
of the optimization that avoids building the initialization procedure in
the anonymous array case.

gcc/ada/ChangeLog:
* exp_aggr.ads (Is_Two_Pass_Aggregate): New function declaration.
* exp_aggr.adb (Is_Two_Pass_Aggregate): New function body.
(Expand_Array_Aggregate): Call Is_Two_Pass_Aggregate to detect the
aggregates that need the 2-pass expansion.
* exp_ch3.adb (Expand_Freeze_Array_Type): In the anonymous array
case, build the initialization procedure if the initial value in
the object declaration is a 2-pass aggregate.

Diff:
---
 gcc/ada/exp_aggr.adb | 22 --
 gcc/ada/exp_aggr.ads |  4 
 gcc/ada/exp_ch3.adb  | 15 ++-
 3 files changed, 30 insertions(+), 11 deletions(-)

diff --git a/gcc/ada/exp_aggr.adb b/gcc/ada/exp_aggr.adb
index 306f17bb5bfa..bb58613128b8 100644
--- a/gcc/ada/exp_aggr.adb
+++ b/gcc/ada/exp_aggr.adb
@@ -6684,12 +6684,7 @@ package body Exp_Aggr is
   then
  return;
 
-  elsif Present (Component_Associations (N))
-and then Nkind (First (Component_Associations (N))) =
- N_Iterated_Component_Association
-and then
-  Present (Iterator_Specification (First (Component_Associations (N
-  then
+  elsif Is_Two_Pass_Aggregate (N) then
  Two_Pass_Aggregate_Expansion (N);
  return;
 
@@ -9227,6 +9222,21 @@ package body Exp_Aggr is
 and then C in Uint_1 | Uint_2 | Uint_4; -- False if No_Uint
end Is_Two_Dim_Packed_Array;
 
+   ---
+   -- Is_Two_Pass_Aggregate --
+   ---
+
+   function Is_Two_Pass_Aggregate (N : Node_Id) return Boolean is
+   begin
+  return Nkind (N) = N_Aggregate
+and then Present (Component_Associations (N))
+and then Nkind (First (Component_Associations (N))) =
+   N_Iterated_Component_Association
+and then
+  Present
+(Iterator_Specification (First (Component_Associations (N;
+   end Is_Two_Pass_Aggregate;
+

-- Late_Expansion --

diff --git a/gcc/ada/exp_aggr.ads b/gcc/ada/exp_aggr.ads
index 4babf2ec54c3..00591aedc6bb 100644
--- a/gcc/ada/exp_aggr.ads
+++ b/gcc/ada/exp_aggr.ads
@@ -35,6 +35,10 @@ package Exp_Aggr is
--  Returns True if N is an aggregate of some kind whose Expansion_Delayed
--  flag is set (see sinfo for meaning of flag).
 
+   function Is_Two_Pass_Aggregate (N : Node_Id) return Boolean;
+   --  Return True if N is an aggregate that is to be expanded in two passes.
+   --  This is the case if it consists only of iterated associations.
+
procedure Convert_Aggr_In_Object_Decl (N : Node_Id);
--  N is a N_Object_Declaration with an expression which must be an
--  N_Aggregate or N_Extension_Aggregate with Expansion_Delayed.
diff --git a/gcc/ada/exp_ch3.adb b/gcc/ada/exp_ch3.adb
index 715f87fc796d..cfc2970a5f77 100644
--- a/gcc/ada/exp_ch3.adb
+++ b/gcc/ada/exp_ch3.adb
@@ -4896,17 +4896,22 @@ package body Exp_Ch3 is
 
  if No (Init_Proc (Base)) then
 
---  If this is an anonymous array created for a declaration with
---  an initial value, its init_proc will never be called. The
+--  If this is an anonymous array built for an object declaration
+--  with an initial value, its Init_Proc will never be called. The
 --  initial value itself may have been expanded into assignments,
---  in which case the object declaration is carries the
---  No_Initialization flag.
+--  in which case the declaration has the No_Initialization flag.
+--  The exception is when the initial value is a 2-pass aggregate,
+--  because the special expansion used for it creates a temporary
+--  that needs a fully-fledged initialization.
 
 if Is_Itype (Base)
   and then Nkind (Associated_Node_For_Itype (Base)) =
 N_Object_Declaration
   and then
-(Present (Expression (Associated_Node_For_Itype (Base)))
+((Present (Expression (Associated_Node_For_Itype (Base)))
+and then not
+  Is_Two_Pass_Aggregate
+(Expression (Associated_Node_For_Itype (Base
   or else No_Initialization 

[gcc r13-9097] Add regression test

2024-10-08 Thread Eric Botcazou via Gcc-cvs
https://gcc.gnu.org/g:a998902576db03a178fe21aa46ed38647f112a98

commit r13-9097-ga998902576db03a178fe21aa46ed38647f112a98
Author: Eric Botcazou 
Date:   Tue Oct 8 15:17:27 2024 +0200

Add regression test

gcc/testsuite/
PR ada/116190
* gnat.dg/aggr31.adb: New test.

Diff:
---
 gcc/testsuite/gnat.dg/aggr31.adb | 17 +
 1 file changed, 17 insertions(+)

diff --git a/gcc/testsuite/gnat.dg/aggr31.adb b/gcc/testsuite/gnat.dg/aggr31.adb
new file mode 100644
index ..8e95f808d88e
--- /dev/null
+++ b/gcc/testsuite/gnat.dg/aggr31.adb
@@ -0,0 +1,17 @@
+-- { dg-do run }
+-- { dg-options "-gnat2022" }
+
+with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
+
+procedure Aggr31 is
+
+  My_Array : constant array (1 .. 5) of Unbounded_String :=
+[others => To_Unbounded_String ("Test")];
+
+  This_Crashes : constant array (Natural range <>) of Unbounded_String :=
+[for I of My_Array => I];
+
+begin
+  null;
+end;
+


[gcc r15-4175] x86/{,V}AES: adjust when to force EVEX encoding

2024-10-08 Thread Jan Beulich via Gcc-cvs
https://gcc.gnu.org/g:0ab66f099bf0f405542944c5ce178151bea934b2

commit r15-4175-g0ab66f099bf0f405542944c5ce178151bea934b2
Author: Jan Beulich 
Date:   Tue Oct 8 16:05:33 2024 +0200

x86/{,V}AES: adjust when to force EVEX encoding

Commit a79d13a01f8c ("i386: Fix aes/vaes patterns [PR114576]") correctly
said "..., but we need to emit {evex} prefix in the assembly if AES ISA
is not enabled". Yet it did so only for the TARGET_AES insns. Going from
the alternative chosen in the TARGET_VAES insns isn't quite right: If
AES is (also) enabled, EVEX encoding would needlessly be forced.

gcc/

* config/i386/sse.md (vaesdec_, vaesdeclast_,
vaesenc_, vaesenclast_): Replace which_alternative
check by TARGET_AES one.

Diff:
---
 gcc/config/i386/sse.md | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/gcc/config/i386/sse.md b/gcc/config/i386/sse.md
index d6e2135423d0..ccef3e063eca 100644
--- a/gcc/config/i386/sse.md
+++ b/gcc/config/i386/sse.md
@@ -30803,7 +30803,7 @@
  UNSPEC_VAESDEC))]
   "TARGET_VAES"
 {
-  if (which_alternative == 0 && mode == V16QImode)
+  if (!TARGET_AES && mode == V16QImode)
 return "%{evex%} vaesdec\t{%2, %1, %0|%0, %1, %2}";
   else
 return "vaesdec\t{%2, %1, %0|%0, %1, %2}";
@@ -30817,7 +30817,7 @@
  UNSPEC_VAESDECLAST))]
   "TARGET_VAES"
 {
-  if (which_alternative == 0 && mode == V16QImode)
+  if (!TARGET_AES && mode == V16QImode)
 return "%{evex%} vaesdeclast\t{%2, %1, %0|%0, %1, %2}";
   else
 return "vaesdeclast\t{%2, %1, %0|%0, %1, %2}";
@@ -30831,7 +30831,7 @@
  UNSPEC_VAESENC))]
   "TARGET_VAES"
 {
-  if (which_alternative == 0 && mode == V16QImode)
+  if (!TARGET_AES && mode == V16QImode)
 return "%{evex%} vaesenc\t{%2, %1, %0|%0, %1, %2}";
   else
 return "vaesenc\t{%2, %1, %0|%0, %1, %2}";
@@ -30845,7 +30845,7 @@
  UNSPEC_VAESENCLAST))]
   "TARGET_VAES"
 {
-  if (which_alternative == 0 && mode == V16QImode)
+  if (!TARGET_AES && mode == V16QImode)
 return "%{evex%} vaesenclast\t{%2, %1, %0|%0, %1, %2}";
   else
 return "vaesenclast\t{%2, %1, %0|%0, %1, %2}";


[gcc r14-10752] x86/{,V}AES: adjust when to force EVEX encoding

2024-10-08 Thread Jan Beulich via Gcc-cvs
https://gcc.gnu.org/g:965ee6a8221de5f69fce4b8097e77c3c19ab31eb

commit r14-10752-g965ee6a8221de5f69fce4b8097e77c3c19ab31eb
Author: Jan Beulich 
Date:   Tue Oct 8 16:05:33 2024 +0200

x86/{,V}AES: adjust when to force EVEX encoding

Commit a79d13a01f8c ("i386: Fix aes/vaes patterns [PR114576]") correctly
said "..., but we need to emit {evex} prefix in the assembly if AES ISA
is not enabled". Yet it did so only for the TARGET_AES insns. Going from
the alternative chosen in the TARGET_VAES insns isn't quite right: If
AES is (also) enabled, EVEX encoding would needlessly be forced.

gcc/

* config/i386/sse.md (vaesdec_, vaesdeclast_,
vaesenc_, vaesenclast_): Replace which_alternative
check by TARGET_AES one.

Diff:
---
 gcc/config/i386/sse.md | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/gcc/config/i386/sse.md b/gcc/config/i386/sse.md
index 1b6f7c1d6c5d..40880f2cd580 100644
--- a/gcc/config/i386/sse.md
+++ b/gcc/config/i386/sse.md
@@ -30258,7 +30258,7 @@
  UNSPEC_VAESDEC))]
   "TARGET_VAES"
 {
-  if (which_alternative == 0 && mode == V16QImode)
+  if (!TARGET_AES && mode == V16QImode)
 return "%{evex%} vaesdec\t{%2, %1, %0|%0, %1, %2}";
   else
 return "vaesdec\t{%2, %1, %0|%0, %1, %2}";
@@ -30272,7 +30272,7 @@
  UNSPEC_VAESDECLAST))]
   "TARGET_VAES"
 {
-  if (which_alternative == 0 && mode == V16QImode)
+  if (!TARGET_AES && mode == V16QImode)
 return "%{evex%} vaesdeclast\t{%2, %1, %0|%0, %1, %2}";
   else
 return "vaesdeclast\t{%2, %1, %0|%0, %1, %2}";
@@ -30286,7 +30286,7 @@
  UNSPEC_VAESENC))]
   "TARGET_VAES"
 {
-  if (which_alternative == 0 && mode == V16QImode)
+  if (!TARGET_AES && mode == V16QImode)
 return "%{evex%} vaesenc\t{%2, %1, %0|%0, %1, %2}";
   else
 return "vaesenc\t{%2, %1, %0|%0, %1, %2}";
@@ -30300,7 +30300,7 @@
  UNSPEC_VAESENCLAST))]
   "TARGET_VAES"
 {
-  if (which_alternative == 0 && mode == V16QImode)
+  if (!TARGET_AES && mode == V16QImode)
 return "%{evex%} vaesenclast\t{%2, %1, %0|%0, %1, %2}";
   else
 return "vaesenclast\t{%2, %1, %0|%0, %1, %2}";


[gcc r15-4181] Add regression test

2024-10-08 Thread Eric Botcazou via Gcc-cvs
https://gcc.gnu.org/g:8da27c7b3b8e16c09ef86a46746e1295421fa237

commit r15-4181-g8da27c7b3b8e16c09ef86a46746e1295421fa237
Author: Eric Botcazou 
Date:   Tue Oct 8 15:15:26 2024 +0200

Add regression test

gcc/testsuite/
PR ada/115535
* gnat.dg/put_image1.adb: New test

Diff:
---
 gcc/testsuite/gnat.dg/put_image1.adb | 21 +
 1 file changed, 21 insertions(+)

diff --git a/gcc/testsuite/gnat.dg/put_image1.adb 
b/gcc/testsuite/gnat.dg/put_image1.adb
new file mode 100644
index ..396967ce1157
--- /dev/null
+++ b/gcc/testsuite/gnat.dg/put_image1.adb
@@ -0,0 +1,21 @@
+-- { dg-do run }
+-- { dg-options "-gnat2022" }
+
+with Ada.Text_IO; use Ada.Text_IO;
+
+procedure Put_Image1 is
+
+  type Client_ID_Part is range 0 .. 2**32 - 1 with Size => 32;
+
+  type Client_ID is array (1 .. 2) of Client_ID_Part;
+
+  A : Client_ID := (1479222903, 3163714999);
+
+begin
+   Put_Line (A'Image);
+   -- { dg-output ".* 1479222903,  3163714999.*\n" }
+   Put_Line (A (1)'Image);
+   -- { dg-output " 1479222903.*\n" }
+   Put_Line (A (2)'Image);
+   -- { dg-output " 3163714999.*\n" }
+end;


[gcc r15-4182] Add regression test

2024-10-08 Thread Eric Botcazou via Gcc-cvs
https://gcc.gnu.org/g:5f0a381801b754dbbd52695bbdbe48967211659c

commit r15-4182-g5f0a381801b754dbbd52695bbdbe48967211659c
Author: Eric Botcazou 
Date:   Tue Oct 8 15:17:27 2024 +0200

Add regression test

gcc/testsuite/
PR ada/116190
* gnat.dg/aggr31.adb: New test.

Diff:
---
 gcc/testsuite/gnat.dg/aggr31.adb | 17 +
 1 file changed, 17 insertions(+)

diff --git a/gcc/testsuite/gnat.dg/aggr31.adb b/gcc/testsuite/gnat.dg/aggr31.adb
new file mode 100644
index ..8e95f808d88e
--- /dev/null
+++ b/gcc/testsuite/gnat.dg/aggr31.adb
@@ -0,0 +1,17 @@
+-- { dg-do run }
+-- { dg-options "-gnat2022" }
+
+with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
+
+procedure Aggr31 is
+
+  My_Array : constant array (1 .. 5) of Unbounded_String :=
+[others => To_Unbounded_String ("Test")];
+
+  This_Crashes : constant array (Natural range <>) of Unbounded_String :=
+[for I of My_Array => I];
+
+begin
+  null;
+end;
+


[gcc r15-4180] Add regression test

2024-10-08 Thread Eric Botcazou via Gcc-cvs
https://gcc.gnu.org/g:0c002cce5e0e2f3da0f5360f1c49480e5734

commit r15-4180-g0c002cce5e0e2f3da0f5360f1c49480e5734
Author: Eric Botcazou 
Date:   Tue Oct 8 15:08:15 2024 +0200

Add regression test

gcc/testsuite/
PR ada/114636
* gnat.dg/specs/generic_inst1.ads: New test.

Diff:
---
 gcc/testsuite/gnat.dg/specs/generic_inst1.ads | 32 +++
 1 file changed, 32 insertions(+)

diff --git a/gcc/testsuite/gnat.dg/specs/generic_inst1.ads 
b/gcc/testsuite/gnat.dg/specs/generic_inst1.ads
new file mode 100644
index ..fdf48c020b09
--- /dev/null
+++ b/gcc/testsuite/gnat.dg/specs/generic_inst1.ads
@@ -0,0 +1,32 @@
+-- { dg-do compile }
+
+package Generic_Inst1 is
+
+   generic
+  type Terminals is (<>);
+  type Nonterminals is (<>);
+   package Types is
+  type Action is record
+ data : Integer;
+  end record;
+   end Types;
+
+   generic
+  type States is (<>);
+  type Input_T is (<>);
+  type Action_T is private;
+   package FSM is
+   end FSM;
+
+   generic
+  with package Typs is new Types (<>);
+  with package SMs is new FSM
+(States => <>, Input_T => Typs.Terminals, Action_T => Typs.Action);
+   package Gen is
+   end Gen;
+
+   package Typs is new Types (Natural, Integer);
+   package SMs is new FSM (Integer, Natural, Typs.Action);
+   package Generator is new Gen (Typs, SMs);
+
+end Generic_Inst1;


[gcc r15-4170] RISC-V: Add testcases for form 4 of scalar signed SAT_SUB

2024-10-08 Thread Pan Li via Gcc-cvs
https://gcc.gnu.org/g:9252fc398c86ec0eac2c56283e2ded8ea6cfb70c

commit r15-4170-g9252fc398c86ec0eac2c56283e2ded8ea6cfb70c
Author: Pan Li 
Date:   Thu Oct 3 16:47:52 2024 +0800

RISC-V: Add testcases for form 4 of scalar signed SAT_SUB

Form 4:
  #define DEF_SAT_S_SUB_FMT_4(T, UT, MIN, MAX)   \
  T __attribute__((noinline))\
  sat_s_sub_##T##_fmt_4 (T x, T y)   \
  {  \
T minus;   \
bool overflow = __builtin_sub_overflow (x, y, &minus); \
return !overflow ? minus : x < 0 ? MIN : MAX;  \
  }

The below test are passed for this patch.
* The rv64gcv fully regression test.

It is test only patch and obvious up to a point, will commit it
directly if no comments in next 48H.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/sat_arith.h: Add test helper macros.
* gcc.target/riscv/sat_s_sub-4-i16.c: New test.
* gcc.target/riscv/sat_s_sub-4-i32.c: New test.
* gcc.target/riscv/sat_s_sub-4-i64.c: New test.
* gcc.target/riscv/sat_s_sub-4-i8.c: New test.
* gcc.target/riscv/sat_s_sub-run-4-i16.c: New test.
* gcc.target/riscv/sat_s_sub-run-4-i32.c: New test.
* gcc.target/riscv/sat_s_sub-run-4-i64.c: New test.
* gcc.target/riscv/sat_s_sub-run-4-i8.c: New test.

Signed-off-by: Pan Li 

Diff:
---
 gcc/testsuite/gcc.target/riscv/sat_arith.h | 14 ++
 gcc/testsuite/gcc.target/riscv/sat_s_sub-4-i16.c   | 30 ++
 gcc/testsuite/gcc.target/riscv/sat_s_sub-4-i32.c   | 28 
 gcc/testsuite/gcc.target/riscv/sat_s_sub-4-i64.c   | 27 +++
 gcc/testsuite/gcc.target/riscv/sat_s_sub-4-i8.c| 28 
 .../gcc.target/riscv/sat_s_sub-run-4-i16.c | 16 
 .../gcc.target/riscv/sat_s_sub-run-4-i32.c | 16 
 .../gcc.target/riscv/sat_s_sub-run-4-i64.c | 16 
 .../gcc.target/riscv/sat_s_sub-run-4-i8.c  | 16 
 9 files changed, 191 insertions(+)

diff --git a/gcc/testsuite/gcc.target/riscv/sat_arith.h 
b/gcc/testsuite/gcc.target/riscv/sat_arith.h
index fd3879d31c5b..7c3859cc1834 100644
--- a/gcc/testsuite/gcc.target/riscv/sat_arith.h
+++ b/gcc/testsuite/gcc.target/riscv/sat_arith.h
@@ -390,6 +390,17 @@ sat_s_sub_##T##_fmt_3 (T x, T y) \
 #define DEF_SAT_S_SUB_FMT_3_WRAP(T, UT, MIN, MAX) \
   DEF_SAT_S_SUB_FMT_3(T, UT, MIN, MAX)
 
+#define DEF_SAT_S_SUB_FMT_4(T, UT, MIN, MAX)   \
+T __attribute__((noinline))\
+sat_s_sub_##T##_fmt_4 (T x, T y)   \
+{  \
+  T minus;   \
+  bool overflow = __builtin_sub_overflow (x, y, &minus); \
+  return !overflow ? minus : x < 0 ? MIN : MAX;  \
+}
+#define DEF_SAT_S_SUB_FMT_4_WRAP(T, UT, MIN, MAX) \
+  DEF_SAT_S_SUB_FMT_4(T, UT, MIN, MAX)
+
 #define RUN_SAT_S_SUB_FMT_1(T, x, y) sat_s_sub_##T##_fmt_1(x, y)
 #define RUN_SAT_S_SUB_FMT_1_WRAP(T, x, y) RUN_SAT_S_SUB_FMT_1(T, x, y)
 
@@ -399,6 +410,9 @@ sat_s_sub_##T##_fmt_3 (T x, T y) \
 #define RUN_SAT_S_SUB_FMT_3(T, x, y) sat_s_sub_##T##_fmt_3(x, y)
 #define RUN_SAT_S_SUB_FMT_3_WRAP(T, x, y) RUN_SAT_S_SUB_FMT_3(T, x, y)
 
+#define RUN_SAT_S_SUB_FMT_4(T, x, y) sat_s_sub_##T##_fmt_4(x, y)
+#define RUN_SAT_S_SUB_FMT_4_WRAP(T, x, y) RUN_SAT_S_SUB_FMT_4(T, x, y)
+
 
/**/
 /* Saturation Truncate (unsigned and signed)  
*/
 
/**/
diff --git a/gcc/testsuite/gcc.target/riscv/sat_s_sub-4-i16.c 
b/gcc/testsuite/gcc.target/riscv/sat_s_sub-4-i16.c
new file mode 100644
index ..60c22e25eb89
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/sat_s_sub-4-i16.c
@@ -0,0 +1,30 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv64gc -mabi=lp64d -O3 -fdump-rtl-expand-details 
-fno-schedule-insns -fno-schedule-insns2" } */
+/* { dg-final { check-function-bodies "**" "" } } */
+
+#include "sat_arith.h"
+
+/*
+** sat_s_sub_int16_t_fmt_4:
+** sub\s+[atx][0-9]+,\s*a0,\s*a1
+** xor\s+[atx][0-9]+,\s*a0,\s*a1
+** xor\s+[atx][0-9]+,\s*a0,\s*[atx][0-9]+
+** and\s+[atx][0-9]+,\s*[atx][0-9]+,\s*[atx][0-9]+
+** srli\s+[atx][0-9]+,\s*[atx][0-9]+,\s*15
+** andi\s+[atx][0-9]+,\s*[atx][0-9]+,\s*1
+** srai\s+[atx][0-9]+,\s*[atx][0-9]+,\s*63
+** li\s+[atx][0-9]+,\s*32768
+** addi\s+[atx][0-9]+,\s*[atx][0-9]+,\s*-1
+** xor\s+[atx][0-9]+,\s*[atx][0-9]+,\s*[atx][0-9]+
+** neg\s+[atx][0-9]+,\s*[atx][0-9]+
+** and\s+[atx][0-9]+,\s*[atx][0-9]+,\s*[atx][0-9]+
+** addi\s+[atx][0-9]+,\s*[atx][0-9]+,\s*-

[gcc r15-4169] RISC-V: Add testcases for form 3 of scalar signed SAT_SUB

2024-10-08 Thread Pan Li via Gcc-cvs
https://gcc.gnu.org/g:aac2bc48014dd418a5c9dc3a7c962c0f0bb48312

commit r15-4169-gaac2bc48014dd418a5c9dc3a7c962c0f0bb48312
Author: Pan Li 
Date:   Thu Oct 3 16:15:56 2024 +0800

RISC-V: Add testcases for form 3 of scalar signed SAT_SUB

Form 3:
  #define DEF_SAT_S_SUB_FMT_3(T, UT, MIN, MAX) \
  T __attribute__((noinline))  \
  sat_s_sub_##T##_fmt_3 (T x, T y) \
  {\
T minus;   \
bool overflow = __builtin_sub_overflow (x, y, &minus); \
return overflow ? x < 0 ? MIN : MAX : minus;   \
  }

The below test are passed for this patch.
* The rv64gcv fully regression test.

It is test only patch and obvious up to a point, will commit it
directly if no comments in next 48H.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/sat_arith.h: Add test helper macros.
* gcc.target/riscv/sat_s_sub-3-i16.c: New test.
* gcc.target/riscv/sat_s_sub-3-i32.c: New test.
* gcc.target/riscv/sat_s_sub-3-i64.c: New test.
* gcc.target/riscv/sat_s_sub-3-i8.c: New test.
* gcc.target/riscv/sat_s_sub-run-3-i16.c: New test.
* gcc.target/riscv/sat_s_sub-run-3-i32.c: New test.
* gcc.target/riscv/sat_s_sub-run-3-i64.c: New test.
* gcc.target/riscv/sat_s_sub-run-3-i8.c: New test.

Signed-off-by: Pan Li 

Diff:
---
 gcc/testsuite/gcc.target/riscv/sat_arith.h | 14 ++
 gcc/testsuite/gcc.target/riscv/sat_s_sub-3-i16.c   | 30 ++
 gcc/testsuite/gcc.target/riscv/sat_s_sub-3-i32.c   | 28 
 gcc/testsuite/gcc.target/riscv/sat_s_sub-3-i64.c   | 27 +++
 gcc/testsuite/gcc.target/riscv/sat_s_sub-3-i8.c| 28 
 .../gcc.target/riscv/sat_s_sub-run-3-i16.c | 16 
 .../gcc.target/riscv/sat_s_sub-run-3-i32.c | 16 
 .../gcc.target/riscv/sat_s_sub-run-3-i64.c | 16 
 .../gcc.target/riscv/sat_s_sub-run-3-i8.c  | 16 
 9 files changed, 191 insertions(+)

diff --git a/gcc/testsuite/gcc.target/riscv/sat_arith.h 
b/gcc/testsuite/gcc.target/riscv/sat_arith.h
index 66d393399a29..fd3879d31c5b 100644
--- a/gcc/testsuite/gcc.target/riscv/sat_arith.h
+++ b/gcc/testsuite/gcc.target/riscv/sat_arith.h
@@ -379,12 +379,26 @@ sat_s_sub_##T##_fmt_2 (T x, T y) \
 #define DEF_SAT_S_SUB_FMT_2_WRAP(T, UT, MIN, MAX) \
   DEF_SAT_S_SUB_FMT_2(T, UT, MIN, MAX)
 
+#define DEF_SAT_S_SUB_FMT_3(T, UT, MIN, MAX) \
+T __attribute__((noinline))  \
+sat_s_sub_##T##_fmt_3 (T x, T y) \
+{\
+  T minus;   \
+  bool overflow = __builtin_sub_overflow (x, y, &minus); \
+  return overflow ? x < 0 ? MIN : MAX : minus;   \
+}
+#define DEF_SAT_S_SUB_FMT_3_WRAP(T, UT, MIN, MAX) \
+  DEF_SAT_S_SUB_FMT_3(T, UT, MIN, MAX)
+
 #define RUN_SAT_S_SUB_FMT_1(T, x, y) sat_s_sub_##T##_fmt_1(x, y)
 #define RUN_SAT_S_SUB_FMT_1_WRAP(T, x, y) RUN_SAT_S_SUB_FMT_1(T, x, y)
 
 #define RUN_SAT_S_SUB_FMT_2(T, x, y) sat_s_sub_##T##_fmt_2(x, y)
 #define RUN_SAT_S_SUB_FMT_2_WRAP(T, x, y) RUN_SAT_S_SUB_FMT_2(T, x, y)
 
+#define RUN_SAT_S_SUB_FMT_3(T, x, y) sat_s_sub_##T##_fmt_3(x, y)
+#define RUN_SAT_S_SUB_FMT_3_WRAP(T, x, y) RUN_SAT_S_SUB_FMT_3(T, x, y)
+
 
/**/
 /* Saturation Truncate (unsigned and signed)  
*/
 
/**/
diff --git a/gcc/testsuite/gcc.target/riscv/sat_s_sub-3-i16.c 
b/gcc/testsuite/gcc.target/riscv/sat_s_sub-3-i16.c
new file mode 100644
index ..5a1368b11a96
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/sat_s_sub-3-i16.c
@@ -0,0 +1,30 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv64gc -mabi=lp64d -O3 -fdump-rtl-expand-details 
-fno-schedule-insns -fno-schedule-insns2" } */
+/* { dg-final { check-function-bodies "**" "" } } */
+
+#include "sat_arith.h"
+
+/*
+** sat_s_sub_int16_t_fmt_3:
+** sub\s+[atx][0-9]+,\s*a0,\s*a1
+** xor\s+[atx][0-9]+,\s*a0,\s*a1
+** xor\s+[atx][0-9]+,\s*a0,\s*[atx][0-9]+
+** and\s+[atx][0-9]+,\s*[atx][0-9]+,\s*[atx][0-9]+
+** srli\s+[atx][0-9]+,\s*[atx][0-9]+,\s*15
+** andi\s+[atx][0-9]+,\s*[atx][0-9]+,\s*1
+** srai\s+[atx][0-9]+,\s*[atx][0-9]+,\s*63
+** li\s+[atx][0-9]+,\s*32768
+** addi\s+[atx][0-9]+,\s*[atx][0-9]+,\s*-1
+** xor\s+[atx][0-9]+,\s*[atx][0-9]+,\s*[atx][0-9]+
+** neg\s+[atx][0-9]+,\s*[atx][0-9]+
+** and\s+[atx][0-9]+,\s*[atx][0-9]+,\s*[atx][0-9]+
+** addi\s+[atx][0-9]+,\s*[atx][0-9]+,\s*-1
+** and\s+[atx][0-9]+,\s*[atx][0-9]+,\s*[atx][0-9]+
+** or\s+a0,\s*[atx]

[gcc r15-4168] Match: Support form 3 and form 4 for scalar signed integer SAT_SUB

2024-10-08 Thread Pan Li via Gcc-cvs
https://gcc.gnu.org/g:e21a8d9ec63464b2c8301f882a3a04ac59b01fcd

commit r15-4168-ge21a8d9ec63464b2c8301f882a3a04ac59b01fcd
Author: Pan Li 
Date:   Thu Oct 3 16:06:08 2024 +0800

Match: Support form 3 and form 4 for scalar signed integer SAT_SUB

This patch would like to support the form 3 and form 4 of the scalar signed
integer SAT_SUB.  Aka below example:

Form 3:
  #define DEF_SAT_S_ADD_FMT_3(T, UT, MIN, MAX)   \
  T __attribute__((noinline))\
  sat_s_add_##T##_fmt_3 (T x, T y)   \
  {  \
T sum;   \
bool overflow = __builtin_add_overflow (x, y, &sum); \
return overflow ? x < 0 ? MIN : MAX : sum;   \
  }

Form 4:
  #define DEF_SAT_S_SUB_FMT_4(T, UT, MIN, MAX) \
  T __attribute__((noinline))  \
  sat_s_sub_##T##_fmt_4 (T x, T y) \
  {\
T minus;   \
bool overflow = __builtin_sub_overflow (x, y, &minus); \
return !overflow ? minus : x < 0 ? MIN : MAX;  \
  }

DEF_SAT_S_ADD_FMT_3(int8_t, uint8_t, INT8_MIN, INT8_MAX);

Before this patch:
   4   │ __attribute__((noinline))
   5   │ int8_t sat_s_sub_int8_t_fmt_3 (int8_t x, int8_t y)
   6   │ {
   7   │   signed char _1;
   8   │   signed char _2;
   9   │   int8_t _3;
  10   │   __complex__ signed char _6;
  11   │   _Bool _8;
  12   │   signed char _9;
  13   │   signed char _10;
  14   │   signed char _11;
  15   │
  16   │ ;;   basic block 2, loop depth 0
  17   │ ;;pred:   ENTRY
  18   │   _6 = .SUB_OVERFLOW (x_4(D), y_5(D));
  19   │   _2 = IMAGPART_EXPR <_6>;
  20   │   if (_2 != 0)
  21   │ goto ; [50.00%]
  22   │   else
  23   │ goto ; [50.00%]
  24   │ ;;succ:   4
  25   │ ;;3
  26   │
  27   │ ;;   basic block 3, loop depth 0
  28   │ ;;pred:   2
  29   │   _1 = REALPART_EXPR <_6>;
  30   │   goto ; [100.00%]
  31   │ ;;succ:   5
  32   │
  33   │ ;;   basic block 4, loop depth 0
  34   │ ;;pred:   2
  35   │   _8 = x_4(D) < 0;
  36   │   _9 = (signed char) _8;
  37   │   _10 = -_9;
  38   │   _11 = _10 ^ 127;
  39   │ ;;succ:   5
  40   │
  41   │ ;;   basic block 5, loop depth 0
  42   │ ;;pred:   3
  43   │ ;;4
  44   │   # _3 = PHI <_1(3), _11(4)>
  45   │   return _3;
  46   │ ;;succ:   EXIT
  47   │
  48   │ }

After this patch:
   4   │ __attribute__((noinline))
   5   │ int8_t sat_s_sub_int8_t_fmt_3 (int8_t x, int8_t y)
   6   │ {
   7   │   int8_t _3;
   8   │
   9   │ ;;   basic block 2, loop depth 0
  10   │ ;;pred:   ENTRY
  11   │   _3 = .SAT_SUB (x_4(D), y_5(D)); [tail call]
  12   │   return _3;
  13   │ ;;succ:   EXIT
  14   │
  15   │ }

The below test suites are passed for this patch.
* The rv64gcv fully regression test.
* The x86 bootstrap test.
* The x86 fully regression test.

gcc/ChangeLog:

* match.pd: Add case 3 matching pattern for signed SAT_SUB.

Signed-off-by: Pan Li 

Diff:
---
 gcc/match.pd | 13 +
 1 file changed, 13 insertions(+)

diff --git a/gcc/match.pd b/gcc/match.pd
index ba83f0f29e61..d50b732bc86b 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -3388,6 +3388,19 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
(bit_xor:c (negate (convert (lt @0 integer_zerop))) max_value))
  (if (INTEGRAL_TYPE_P (type) && !TYPE_UNSIGNED (type
 
+/* Signed saturation sub, case 3:
+   Z = .SUB_OVERFLOW (X, Y)
+   SAT_S_SUB = IMAGPART_EXPR (Z) != 0 ? (-(T)(X < 0) ^ MAX) : REALPART_EXPR 
(Z);
+
+   The T and UT are type pair like T=int8_t, UT=uint8_t.  */
+(match (signed_integer_sat_sub @0 @1)
+ (cond^ (ne (imagpart (IFN_SUB_OVERFLOW@2 @0 @1)) integer_zerop)
+   (bit_xor:c (negate (convert (lt @0 integer_zerop)))
+  max_value)
+   (realpart @2))
+ (if (INTEGRAL_TYPE_P (type) && !TYPE_UNSIGNED (type)
+  && types_match (type, @0, @1
+
 /* Unsigned saturation truncate, case 1, sizeof (WT) > sizeof (NT).
SAT_U_TRUNC = (NT)x | (NT)(-(X > (WT)(NT)(-1))).  */
 (match (unsigned_integer_sat_trunc @0)


[gcc r15-4179] RISC-V: Add testcases for form 1 of scalar signed SAT_TRUNC

2024-10-08 Thread Pan Li via Gcc-cvs
https://gcc.gnu.org/g:8b407d5c6940a65d78a544f9c66850e619638171

commit r15-4179-g8b407d5c6940a65d78a544f9c66850e619638171
Author: Pan Li 
Date:   Tue Oct 8 11:28:44 2024 +0800

RISC-V: Add testcases for form 1 of scalar signed SAT_TRUNC

Form 1:
  #define DEF_SAT_S_TRUNC_FMT_1(WT, NT, NT_MIN, NT_MAX) \
  NT __attribute__((noinline))  \
  sat_s_trunc_##WT##_to_##NT##_fmt_1 (WT x) \
  { \
NT trunc = (NT)x;   \
return (WT)NT_MIN <= x && x <= (WT)NT_MAX   \
  ? trunc   \
  : x < 0 ? NT_MIN : NT_MAX;\
  }

The below test are passed for this patch.
* The rv64gcv fully regression test.

It is test only patch and obvious up to a point, will commit it
directly if no comments in next 48H.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/sat_arith.h: Add test helper macros.
* gcc.target/riscv/sat_arith_data.h: Add test data for SAT_TRUNC.
* gcc.target/riscv/sat_s_trunc-1-i16-to-i8.c: New test.
* gcc.target/riscv/sat_s_trunc-1-i32-to-i16.c: New test.
* gcc.target/riscv/sat_s_trunc-1-i32-to-i8.c: New test.
* gcc.target/riscv/sat_s_trunc-1-i64-to-i16.c: New test.
* gcc.target/riscv/sat_s_trunc-1-i64-to-i32.c: New test.
* gcc.target/riscv/sat_s_trunc-1-i64-to-i8.c: New test.
* gcc.target/riscv/sat_s_trunc-run-1-i16-to-i8.c: New test.
* gcc.target/riscv/sat_s_trunc-run-1-i32-to-i16.c: New test.
* gcc.target/riscv/sat_s_trunc-run-1-i32-to-i8.c: New test.
* gcc.target/riscv/sat_s_trunc-run-1-i64-to-i16.c: New test.
* gcc.target/riscv/sat_s_trunc-run-1-i64-to-i32.c: New test.
* gcc.target/riscv/sat_s_trunc-run-1-i64-to-i8.c: New test.

Signed-off-by: Pan Li 

Diff:
---
 gcc/testsuite/gcc.target/riscv/sat_arith.h |  15 +++
 gcc/testsuite/gcc.target/riscv/sat_arith_data.h| 110 +
 .../gcc.target/riscv/sat_s_trunc-1-i16-to-i8.c |  26 +
 .../gcc.target/riscv/sat_s_trunc-1-i32-to-i16.c|  28 ++
 .../gcc.target/riscv/sat_s_trunc-1-i32-to-i8.c |  26 +
 .../gcc.target/riscv/sat_s_trunc-1-i64-to-i16.c|  28 ++
 .../gcc.target/riscv/sat_s_trunc-1-i64-to-i32.c|  26 +
 .../gcc.target/riscv/sat_s_trunc-1-i64-to-i8.c |  26 +
 .../gcc.target/riscv/sat_s_trunc-run-1-i16-to-i8.c |  16 +++
 .../riscv/sat_s_trunc-run-1-i32-to-i16.c   |  16 +++
 .../gcc.target/riscv/sat_s_trunc-run-1-i32-to-i8.c |  16 +++
 .../riscv/sat_s_trunc-run-1-i64-to-i16.c   |  16 +++
 .../riscv/sat_s_trunc-run-1-i64-to-i32.c   |  16 +++
 .../gcc.target/riscv/sat_s_trunc-run-1-i64-to-i8.c |  16 +++
 14 files changed, 381 insertions(+)

diff --git a/gcc/testsuite/gcc.target/riscv/sat_arith.h 
b/gcc/testsuite/gcc.target/riscv/sat_arith.h
index 7c3859cc1834..80d7a69e7d9a 100644
--- a/gcc/testsuite/gcc.target/riscv/sat_arith.h
+++ b/gcc/testsuite/gcc.target/riscv/sat_arith.h
@@ -465,4 +465,19 @@ sat_u_trunc_##WT##_to_##NT##_fmt_4 (WT x)  \
 #define RUN_SAT_U_TRUNC_FMT_4(NT, WT, x) sat_u_trunc_##WT##_to_##NT##_fmt_4 (x)
 #define RUN_SAT_U_TRUNC_FMT_4_WRAP(NT, WT, x) RUN_SAT_U_TRUNC_FMT_4(NT, WT, x)
 
+#define DEF_SAT_S_TRUNC_FMT_1(NT, WT, NT_MIN, NT_MAX) \
+NT __attribute__((noinline))  \
+sat_s_trunc_##WT##_to_##NT##_fmt_1 (WT x) \
+{ \
+  NT trunc = (NT)x;   \
+  return (WT)NT_MIN <= x && x <= (WT)NT_MAX   \
+? trunc   \
+: x < 0 ? NT_MIN : NT_MAX;\
+}
+#define DEF_SAT_S_TRUNC_FMT_1_WRAP(NT, WT, NT_MIN, NT_MAX) \
+  DEF_SAT_S_TRUNC_FMT_1(NT, WT, NT_MIN, NT_MAX)
+
+#define RUN_SAT_S_TRUNC_FMT_1(NT, WT, x) sat_s_trunc_##WT##_to_##NT##_fmt_1 (x)
+#define RUN_SAT_S_TRUNC_FMT_1_WRAP(NT, WT, x) RUN_SAT_S_TRUNC_FMT_1(NT, WT, x)
+
 #endif
diff --git a/gcc/testsuite/gcc.target/riscv/sat_arith_data.h 
b/gcc/testsuite/gcc.target/riscv/sat_arith_data.h
index 39a1e17cd3d1..9f9f7d0bcd19 100644
--- a/gcc/testsuite/gcc.target/riscv/sat_arith_data.h
+++ b/gcc/testsuite/gcc.target/riscv/sat_arith_data.h
@@ -42,6 +42,13 @@ TEST_BINARY_STRUCT (int16_t, sssub)
 TEST_BINARY_STRUCT (int32_t, sssub)
 TEST_BINARY_STRUCT (int64_t, sssub)
 
+TEST_UNARY_STRUCT (int8_t, int16_t)
+TEST_UNARY_STRUCT (int8_t, int32_t)
+TEST_UNARY_STRUCT (int8_t, int64_t)
+TEST_UNARY_STRUCT (int16_t, int32_t)
+TEST_UNARY_STRUCT (int16_t, int64_t)
+TEST_UNARY_STRUCT (int32_t, int64_t)
+
 TEST_UNARY_STRUCT_DECL(uint8_t, uint16_t) \
   TEST_UNARY_DATA(uint8_t, uint16_t)[] =
 {
@@ -126,6 +133,109 @@ TEST_UNARY_STRUCT_DECL(uint32_t, uint64_t) \
   {4294967295, 184467440737

[gcc r15-4176] Match: Support form 1 for scalar signed integer SAT_TRUNC

2024-10-08 Thread Pan Li via Gcc-cvs
https://gcc.gnu.org/g:f9f57df85a5411dce201165a42f4b9d57489bed9

commit r15-4176-gf9f57df85a5411dce201165a42f4b9d57489bed9
Author: Pan Li 
Date:   Tue Oct 8 10:02:21 2024 +0800

Match: Support form 1 for scalar signed integer SAT_TRUNC

This patch would like to support the form 1 of the scalar signed
integer SAT_TRUNC.  Aka below example:

Form 1:
  #define DEF_SAT_S_TRUNC_FMT_1(NT, WT, NT_MIN, NT_MAX) \
  NT __attribute__((noinline))  \
  sat_s_trunc_##WT##_to_##NT##_fmt_1 (WT x) \
  { \
NT trunc = (NT)x;   \
return (WT)NT_MIN <= x && x <= (WT)NT_MAX   \
  ? trunc   \
  : x < 0 ? NT_MIN : NT_MAX;\
  }

DEF_SAT_S_TRUNC_FMT_1(int64_t, int32_t, INT32_MIN, INT32_MAX)

Before this patch:
   4   │ __attribute__((noinline))
   5   │ int32_t sat_s_trunc_int64_t_to_int32_t_fmt_1 (int64_t x)
   6   │ {
   7   │   int32_t trunc;
   8   │   unsigned long x.0_1;
   9   │   unsigned long _2;
  10   │   int32_t _3;
  11   │   _Bool _7;
  12   │   int _8;
  13   │   int _9;
  14   │   int _10;
  15   │
  16   │ ;;   basic block 2, loop depth 0
  17   │ ;;pred:   ENTRY
  18   │   x.0_1 = (unsigned long) x_4(D);
  19   │   _2 = x.0_1 + 2147483648;
  20   │   if (_2 > 4294967295)
  21   │ goto ; [50.00%]
  22   │   else
  23   │ goto ; [50.00%]
  24   │ ;;succ:   4
  25   │ ;;3
  26   │
  27   │ ;;   basic block 3, loop depth 0
  28   │ ;;pred:   2
  29   │   trunc_5 = (int32_t) x_4(D);
  30   │   goto ; [100.00%]
  31   │ ;;succ:   5
  32   │
  33   │ ;;   basic block 4, loop depth 0
  34   │ ;;pred:   2
  35   │   _7 = x_4(D) < 0;
  36   │   _8 = (int) _7;
  37   │   _9 = -_8;
  38   │   _10 = _9 ^ 2147483647;
  39   │ ;;succ:   5
  40   │
  41   │ ;;   basic block 5, loop depth 0
  42   │ ;;pred:   3
  43   │ ;;4
  44   │   # _3 = PHI 
  45   │   return _3;
  46   │ ;;succ:   EXIT
  47   │
  48   │ }

After this patch:
   4   │ __attribute__((noinline))
   5   │ int32_t sat_s_trunc_int64_t_to_int32_t_fmt_1 (int64_t x)
   6   │ {
   7   │   int32_t _3;
   8   │
   9   │ ;;   basic block 2, loop depth 0
  10   │ ;;pred:   ENTRY
  11   │   _3 = .SAT_TRUNC (x_4(D)); [tail call]
  12   │   return _3;
  13   │ ;;succ:   EXIT
  14   │
  15   │ }

The below test suites are passed for this patch.
* The rv64gcv fully regression test with pr116861-1.c failed.
* The x86 bootstrap test.
* The x86 fully regression test.

The failed pr116861-1.c ice will be fixed in underlying patch, as it
just trigger one existing bug.

gcc/ChangeLog:

* match.pd: Add case 1 matching pattern for signed SAT_TRUNC.
* tree-ssa-math-opts.cc (gimple_signed_integer_sat_trunc): Add
new decl for signed SAT_TRUNC.
(match_saturation_trunc): Add new func impl to try SAT_TRUNC
pattern on phi node.
(math_opts_dom_walker::after_dom_children): Add
match_saturation_trunc for phi node iteration.

Signed-off-by: Pan Li 

Diff:
---
 gcc/match.pd  | 22 +
 gcc/tree-ssa-math-opts.cc | 61 +++
 2 files changed, 83 insertions(+)

diff --git a/gcc/match.pd b/gcc/match.pd
index d50b732bc86b..6a924f409d9e 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -3461,6 +3461,28 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
   }
   (if (wi::eq_p (trunc_max, int_cst_1) && wi::eq_p (max, int_cst_2))
 
+/* Signed saturation truncate, case 1, sizeof (WT) > sizeof (NT).
+   SAT_S_TRUNC(X) = (unsigned)X + NT_MAX + 1  > Unsigned_MAX ? (NT)X.  */
+(match (signed_integer_sat_trunc @0)
+ (cond^ (gt (plus:c (convert@4 @0) INTEGER_CST@1) INTEGER_CST@2)
+   (bit_xor:c (negate (convert (lt @0 integer_zerop))) INTEGER_CST@3)
+   (convert @0))
+ (if (INTEGRAL_TYPE_P (type) && !TYPE_UNSIGNED (type)
+  && !TYPE_UNSIGNED (TREE_TYPE (@0)) && TYPE_UNSIGNED (TREE_TYPE (@4)))
+ (with
+  {
+   unsigned itype_precision = TYPE_PRECISION (TREE_TYPE (@0));
+   unsigned otype_precision = TYPE_PRECISION (type);
+   wide_int offset = wi::uhwi (HOST_WIDE_INT_1U << (otype_precision - 1), 
itype_precision);
+   wide_int trunc_max = wi::mask (otype_precision, false, itype_precision);
+   wide_int max = wi::mask (otype_precision - 1, false, otype_precision);
+   wide_int int_cst_1 = wi::to_wide (@1);
+   wide_int int_cst_2 = wi::to_wide (@2);
+   wide_int int_cst_3 = wi::to_wide (@3)

[gcc r15-4177] Widening-Mul: Fix one bug of consume after phi node released

2024-10-08 Thread Pan Li via Gcc-cvs
https://gcc.gnu.org/g:2291739ec432abc01c7afc5a07443c575539316a

commit r15-4177-g2291739ec432abc01c7afc5a07443c575539316a
Author: Pan Li 
Date:   Tue Oct 8 11:06:23 2024 +0800

Widening-Mul: Fix one bug of consume after phi node released

When try to matching saturation related pattern on PHI node, we may have
to try each pattern for all phi node of bb.  Aka:

for each PHI node in bb:
  gphi *phi = xxx;
  try_match_sat_add (, phi);
  try_match_sat_sub (, phi);
  try_match_sat_trunc (, phi);

The PHI node will be removed if one of the above 3 sat patterns are
matched.  There will be a problem that, for example, sat_add is
matched and then the phi is removed(freed), and the next 2 sat_sub and
sat_trunc will depend on the removed(freed) phi node.

This patch would like to fix this consume after phi node released issue.
To ensure at most one pattern of the above will be matched.

The below test suites are passed for this patch.
* The rv64gcv fully regression test.
* The x86 bootstrap test.
* The x86 fully regression test.

gcc/ChangeLog:

* tree-ssa-math-opts.cc (build_saturation_binary_arith_call): Rename
to...
(build_saturation_binary_arith_call_and_replace): ...this.
(build_saturation_binary_arith_call_and_insert): ...this.
(match_unsigned_saturation_add): Leverage renamed func.
(match_unsigned_saturation_sub): Ditto.
(match_saturation_add): Return bool on matched and leverage
renamed func.
(match_saturation_sub): Ditto.
(match_saturation_trunc): Ditto.
(math_opts_dom_walker::after_dom_children): Ensure at most one
pattern will be matched for each phi node.

Signed-off-by: Pan Li 

Diff:
---
 gcc/tree-ssa-math-opts.cc | 102 +-
 1 file changed, 56 insertions(+), 46 deletions(-)

diff --git a/gcc/tree-ssa-math-opts.cc b/gcc/tree-ssa-math-opts.cc
index dad8428d3d8a..f9ccdf41d67f 100644
--- a/gcc/tree-ssa-math-opts.cc
+++ b/gcc/tree-ssa-math-opts.cc
@@ -4029,8 +4029,9 @@ extern bool gimple_signed_integer_sat_sub (tree, tree*, 
tree (*)(tree));
 extern bool gimple_signed_integer_sat_trunc (tree, tree*, tree (*)(tree));
 
 static void
-build_saturation_binary_arith_call (gimple_stmt_iterator *gsi, internal_fn fn,
-   tree lhs, tree op_0, tree op_1)
+build_saturation_binary_arith_call_and_replace (gimple_stmt_iterator *gsi,
+   internal_fn fn, tree lhs,
+   tree op_0, tree op_1)
 {
   if (direct_internal_fn_supported_p (fn, TREE_TYPE (lhs), OPTIMIZE_FOR_BOTH))
 {
@@ -4040,20 +4041,19 @@ build_saturation_binary_arith_call 
(gimple_stmt_iterator *gsi, internal_fn fn,
 }
 }
 
-static void
-build_saturation_binary_arith_call (gimple_stmt_iterator *gsi, gphi *phi,
-   internal_fn fn, tree lhs, tree op_0,
-   tree op_1)
+static bool
+build_saturation_binary_arith_call_and_insert (gimple_stmt_iterator *gsi,
+  internal_fn fn, tree lhs,
+  tree op_0, tree op_1)
 {
-  if (direct_internal_fn_supported_p (fn, TREE_TYPE (op_0), OPTIMIZE_FOR_BOTH))
-{
-  gcall *call = gimple_build_call_internal (fn, 2, op_0, op_1);
-  gimple_call_set_lhs (call, lhs);
-  gsi_insert_before (gsi, call, GSI_SAME_STMT);
+  if (!direct_internal_fn_supported_p (fn, TREE_TYPE (op_0), 
OPTIMIZE_FOR_BOTH))
+return false;
 
-  gimple_stmt_iterator psi = gsi_for_stmt (phi);
-  remove_phi_node (&psi, /* release_lhs_p */ false);
-}
+  gcall *call = gimple_build_call_internal (fn, 2, op_0, op_1);
+  gimple_call_set_lhs (call, lhs);
+  gsi_insert_before (gsi, call, GSI_SAME_STMT);
+
+  return true;
 }
 
 /*
@@ -4073,7 +4073,8 @@ match_unsigned_saturation_add (gimple_stmt_iterator *gsi, 
gassign *stmt)
   tree lhs = gimple_assign_lhs (stmt);
 
   if (gimple_unsigned_integer_sat_add (lhs, ops, NULL))
-build_saturation_binary_arith_call (gsi, IFN_SAT_ADD, lhs, ops[0], ops[1]);
+build_saturation_binary_arith_call_and_replace (gsi, IFN_SAT_ADD, lhs,
+   ops[0], ops[1]);
 }
 
 /*
@@ -4115,19 +4116,22 @@ match_unsigned_saturation_add (gimple_stmt_iterator 
*gsi, gassign *stmt)
  *   =>
  *   _6 = .SAT_ADD (x_5(D), y_6(D)); [tail call]  */
 
-static void
+static bool
 match_saturation_add (gimple_stmt_iterator *gsi, gphi *phi)
 {
   if (gimple_phi_num_args (phi) != 2)
-return;
+return false;
 
   tree ops[2];
   tree phi_result = gimple_phi_result (phi);
 
-  if (gimple_unsigned_integer_sat_add (phi_result, ops, NULL)
-  || gimple_signed_integer_sat_add (phi_result, ops, NULL))
-build_saturation_

[gcc r15-4178] RISC-V: Implement scalar SAT_TRUNC for signed integer

2024-10-08 Thread Pan Li via Gcc-cvs
https://gcc.gnu.org/g:110ccfa5c88544c5ec85d31b1ed2c2f9dac163fd

commit r15-4178-g110ccfa5c88544c5ec85d31b1ed2c2f9dac163fd
Author: Pan Li 
Date:   Tue Oct 8 11:22:21 2024 +0800

RISC-V: Implement scalar SAT_TRUNC for signed integer

This patch would like to implement the sstrunc for scalar signed
integer.

Form 1:
  #define DEF_SAT_S_TRUNC_FMT_1(WT, NT, NT_MIN, NT_MAX) \
  NT __attribute__((noinline))  \
  sat_s_trunc_##WT##_to_##NT##_fmt_1 (WT x) \
  { \
NT trunc = (NT)x;   \
return (WT)NT_MIN <= x && x <= (WT)NT_MAX   \
  ? trunc   \
  : x < 0 ? NT_MIN : NT_MAX;\
  }

DEF_SAT_S_TRUNC_FMT_1(int64_t, int32_t, INT32_MIN, INT32_MAX)

Before this patch:
  10   │ sat_s_trunc_int64_t_to_int32_t_fmt_1:
  11   │ li  a5,1
  12   │ sllia5,a5,31
  13   │ li  a4,-1
  14   │ add a5,a0,a5
  15   │ srlia4,a4,32
  16   │ bgtua5,a4,.L2
  17   │ sext.w  a0,a0
  18   │ ret
  19   │ .L2:
  20   │ sraia5,a0,63
  21   │ li  a0,-2147483648
  22   │ xor a0,a0,a5
  23   │ not a0,a0
  24   │ ret

After this patch:
  10   │ sat_s_trunc_int64_t_to_int32_t_fmt_1:
  11   │ li  a5,-2147483648
  12   │ xoria3,a5,-1
  13   │ slt a4,a0,a3
  14   │ slt a5,a5,a0
  15   │ and a5,a4,a5
  16   │ sraia4,a0,63
  17   │ xor a4,a4,a3
  18   │ addia3,a5,-1
  19   │ neg a5,a5
  20   │ and a4,a4,a3
  21   │ and a0,a0,a5
  22   │ or  a0,a0,a4
  23   │ sext.w  a0,a0
  24   │ ret

The below test suites are passed for this patch.
* The rv64gcv fully regression test.

gcc/ChangeLog:

* config/riscv/riscv-protos.h (riscv_expand_sstrunc): Add new
func decl to expand SAT_TRUNC.
* config/riscv/riscv.cc (riscv_expand_sstrunc): Add new func
impl to expand SAT_TRUNC.
* config/riscv/riscv.md (sstrunc2):
Add new pattern for double truncation.
(sstrunc2): Ditto but for quad.
(sstrunc2): Ditto but for oct.

Signed-off-by: Pan Li 

Diff:
---
 gcc/config/riscv/riscv-protos.h |  1 +
 gcc/config/riscv/riscv.cc   | 61 +
 gcc/config/riscv/riscv.md   | 30 
 3 files changed, 92 insertions(+)

diff --git a/gcc/config/riscv/riscv-protos.h b/gcc/config/riscv/riscv-protos.h
index 3d8775e582dc..1e6d10a14020 100644
--- a/gcc/config/riscv/riscv-protos.h
+++ b/gcc/config/riscv/riscv-protos.h
@@ -138,6 +138,7 @@ extern void riscv_expand_ssadd (rtx, rtx, rtx);
 extern void riscv_expand_ussub (rtx, rtx, rtx);
 extern void riscv_expand_sssub (rtx, rtx, rtx);
 extern void riscv_expand_ustrunc (rtx, rtx);
+extern void riscv_expand_sstrunc (rtx, rtx);
 
 #ifdef RTX_CODE
 extern void riscv_expand_int_scc (rtx, enum rtx_code, rtx, rtx, bool 
*invert_ptr = 0);
diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc
index 8708a7b42c6d..57f2554d4910 100644
--- a/gcc/config/riscv/riscv.cc
+++ b/gcc/config/riscv/riscv.cc
@@ -12438,6 +12438,67 @@ riscv_expand_ustrunc (rtx dest, rtx src)
   emit_move_insn (dest, gen_lowpart (mode, xmode_dest));
 }
 
+/* Implement the signed saturation truncation for int mode.
+
+   b = SAT_TRUNC (a);
+   =>
+   1.  lt = a < max
+   2.  gt = min < a
+   3.  mask = lt & gt
+   4.  trunc_mask = -mask
+   5.  sat_mask = mask - 1
+   6.  lt = a < 0
+   7.  neg = -lt
+   8.  sat = neg ^ max
+   9.  trunc = src & trunc_mask
+   10. sat = sat & sat_mask
+   11. dest = trunc | sat  */
+
+void
+riscv_expand_sstrunc (rtx dest, rtx src)
+{
+  machine_mode mode = GET_MODE (dest);
+  unsigned narrow_prec = GET_MODE_PRECISION (mode).to_constant ();
+  HOST_WIDE_INT narrow_max = ((int64_t)1 << (narrow_prec - 1)) - 1; // 127
+  HOST_WIDE_INT narrow_min = -narrow_max - 1; // -128
+
+  rtx xmode_narrow_max = gen_reg_rtx (Xmode);
+  rtx xmode_narrow_min = gen_reg_rtx (Xmode);
+  rtx xmode_lt = gen_reg_rtx (Xmode);
+  rtx xmode_gt = gen_reg_rtx (Xmode);
+  rtx xmode_src = gen_lowpart (Xmode, src);
+  rtx xmode_dest = gen_reg_rtx (Xmode);
+  rtx xmode_mask = gen_reg_rtx (Xmode);
+  rtx xmode_sat = gen_reg_rtx (Xmode);
+  rtx xmode_trunc = gen_reg_rtx (Xmode);
+  rtx xmode_sat_mask = gen_reg_rtx (Xmode);
+  rtx xmode_trunc_mask = gen_reg_rtx (Xmode);
+
+  /* Step-1: lt = src < max, gt = min < src, mask = lt & gt  */
+  emit_move_insn (xmode_narrow_min, gen_int_mode (narrow_min, Xmode));
+  emit_move_insn (xmode_narrow_max, gen_int_mode (narrow_max, Xmode));
+  riscv_emit_binary (LT, xmode_lt, xmode_src, xmode_narrow_max);
+  riscv_emit_binary (LT,

[gcc r15-4173] [RISC-V][PR target/116615] RISC-V: Use default LOGICAL_OP_NON_SHORT_CIRCUIT

2024-10-08 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:34ae3a992a0cc3240d07d69ff12a664cbb5c8be0

commit r15-4173-g34ae3a992a0cc3240d07d69ff12a664cbb5c8be0
Author: Palmer Dabbelt 
Date:   Tue Oct 8 07:28:32 2024 -0600

[RISC-V][PR target/116615] RISC-V: Use default LOGICAL_OP_NON_SHORT_CIRCUIT

> We have cheap logical ops, so let's just move this back to the default
> to take advantage of the standard branch/op hueristics.
>
> gcc/ChangeLog:
>
> PR target/116615
> * config/riscv/riscv.h (LOGICAL_OP_NON_SHORT_CIRCUIT): Remove.
> ---
> There's a bunch more discussion in the bug, but it's starting to smell
> like this was just a holdover from MIPS (where maybe it also shouldn't
> be set).  I haven't tested this, but I figured I'd send the patch to get
> a little more visibility.
>
> I guess we should also kick off something like a SPEC run to make sure
> there's no regressions?
So as I noted earlier, this appears to be a nice win on the BPI. Testsuite
fallout is minimal -- just the one SFB related test tripping at -Os that was
also hit by Andrew P's work.

After looking at it more closely, the SFB codegen and the codegen after
Andrew's work should be equivalent assuming two independent ops can dispatch
together.

The test actually generates sensible code at -Os.  It's the -Os in 
combination
with the -fno-ssa-phiopt that causes problems.   I think the best thing to 
do
here is just skip at -Os.  That still keeps a degree of testing the SFB 
path.

Tested successfully in my tester.  But will wait for the pre-commit tester 
to
render a verdict before moving forward.

PR target/116615
gcc/
* config/riscv/riscv.h (LOGICAL_OP_NON_SHORT_CIRCUIT): Remove.

gcc/testsuite/

* gcc.target/riscv/cset-sext-sfb.c: Skip for -Os.

Co-authored-by: Jeff Law  

Diff:
---
 gcc/config/riscv/riscv.h   | 2 --
 gcc/testsuite/gcc.target/riscv/cset-sext-sfb.c | 2 +-
 2 files changed, 1 insertion(+), 3 deletions(-)

diff --git a/gcc/config/riscv/riscv.h b/gcc/config/riscv/riscv.h
index 3aecb43f8312..53b7b2a40ed9 100644
--- a/gcc/config/riscv/riscv.h
+++ b/gcc/config/riscv/riscv.h
@@ -939,8 +939,6 @@ extern enum riscv_cc get_riscv_cc (const rtx use);
 #define TARGET_VECTOR_MISALIGN_SUPPORTED \
riscv_vector_unaligned_access_p
 
-#define LOGICAL_OP_NON_SHORT_CIRCUIT 0
-
 /* Control the assembler format that we output.  */
 
 /* Output to assembler file text saying following lines
diff --git a/gcc/testsuite/gcc.target/riscv/cset-sext-sfb.c 
b/gcc/testsuite/gcc.target/riscv/cset-sext-sfb.c
index 6e9f8cc61de0..1ee45b33e152 100644
--- a/gcc/testsuite/gcc.target/riscv/cset-sext-sfb.c
+++ b/gcc/testsuite/gcc.target/riscv/cset-sext-sfb.c
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-skip-if "" { *-*-* } { "-O0" "-Og" "-O1" } } */
+/* { dg-skip-if "" { *-*-* } { "-O0" "-Og" "-O1" "-Os" } } */
 /* { dg-options "-march=rv32gc -mtune=sifive-7-series -mbranch-cost=1 
-fno-ssa-phiopt -fdump-rtl-ce1" { target { rv32 } } } */
 /* { dg-options "-march=rv64gc -mtune=sifive-7-series -mbranch-cost=1 
-fno-ssa-phiopt -fdump-rtl-ce1" { target { rv64 } } } */


[gcc r15-4174] aarch64: Expand CTZ to RBIT + CLZ for SVE [PR109498]

2024-10-08 Thread Richard Sandiford via Gcc-cvs
https://gcc.gnu.org/g:c94adf02d31028a25bb7b20ec77aade9d502430b

commit r15-4174-gc94adf02d31028a25bb7b20ec77aade9d502430b
Author: Soumya AR 
Date:   Tue Oct 8 14:37:24 2024 +0100

aarch64: Expand CTZ to RBIT + CLZ for SVE [PR109498]

Currently, we vectorize CTZ for SVE by using the following operation:
.CTZ (X) = (PREC - 1) - .CLZ (X & -X)

Instead, this patch expands CTZ to RBIT + CLZ for SVE, as suggested in 
PR109498.

The patch was bootstrapped and regtested on aarch64-linux-gnu, no 
regression.
OK for mainline?

Signed-off-by: Soumya AR 

gcc/ChangeLog:
PR target/109498
* config/aarch64/aarch64-sve.md (ctz2): Added pattern to 
expand
CTZ to RBIT + CLZ for SVE.

gcc/testsuite/ChangeLog:
PR target/109498
* gcc.target/aarch64/sve/ctz.c: New test.

Diff:
---
 gcc/config/aarch64/aarch64-sve.md  | 17 +++
 gcc/testsuite/gcc.target/aarch64/sve/ctz.c | 49 ++
 2 files changed, 66 insertions(+)

diff --git a/gcc/config/aarch64/aarch64-sve.md 
b/gcc/config/aarch64/aarch64-sve.md
index 90db51e51b9d..06bd3e4bb2c0 100644
--- a/gcc/config/aarch64/aarch64-sve.md
+++ b/gcc/config/aarch64/aarch64-sve.md
@@ -3088,6 +3088,23 @@
 ;; - NOT
 ;; -
 
+(define_expand "ctz2"
+  [(set (match_operand:SVE_I 0 "register_operand")
+   (unspec:SVE_I
+ [(match_dup 2)
+  (ctz:SVE_I
+(match_operand:SVE_I 1 "register_operand"))]
+ UNSPEC_PRED_X))]
+  "TARGET_SVE"
+  {
+ rtx pred = aarch64_ptrue_reg (mode);
+ rtx temp = gen_reg_rtx (mode);
+ emit_insn (gen_aarch64_pred_rbit (temp, pred, operands[1]));
+ emit_insn (gen_aarch64_pred_clz (operands[0], pred, temp));
+ DONE;
+  }
+)
+
 ;; Unpredicated integer unary arithmetic.
 (define_expand "2"
   [(set (match_operand:SVE_I 0 "register_operand")
diff --git a/gcc/testsuite/gcc.target/aarch64/sve/ctz.c 
b/gcc/testsuite/gcc.target/aarch64/sve/ctz.c
new file mode 100644
index ..433a9174f487
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/sve/ctz.c
@@ -0,0 +1,49 @@
+/* { dg-final { check-function-bodies "**" "" } } */
+/* { dg-options "-O3 --param aarch64-autovec-preference=sve-only" } */
+
+#include 
+
+#define FUNC(FUNCTION, NAME, DTYPE) \
+void \
+NAME (DTYPE *__restrict x, DTYPE *__restrict y, int n) { \
+  for (int i = 0; i < n; i++)\
+x[i] = FUNCTION (y[i]); \
+}\
+
+
+/*
+** ctz_uint8:
+** ...
+** rbitz[0-9]+\.b, p[0-7]/m, z[0-9]+\.b
+** clz z[0-9]+\.b, p[0-7]/m, z[0-9]+\.b
+** ...
+*/
+FUNC (__builtin_ctzg, ctz_uint8, uint8_t)
+
+/*
+** ctz_uint16:
+** ...
+** rbitz[0-9]+\.h, p[0-7]/m, z[0-9]+\.h
+** clz z[0-9]+\.h, p[0-7]/m, z[0-9]+\.h
+** ...
+*/
+FUNC (__builtin_ctzg, ctz_uint16, uint16_t)
+
+/*
+** ctz_uint32:
+** ...
+** rbitz[0-9]+\.s, p[0-7]/m, z[0-9]+\.s
+** clz z[0-9]+\.s, p[0-7]/m, z[0-9]+\.s
+** ...
+*/
+FUNC (__builtin_ctz, ctz_uint32, uint32_t)
+
+/*
+** ctz_uint64:
+** ...
+** rbitz[0-9]+\.d, p[0-7]/m, z[0-9]+\.d
+** clz z[0-9]+\.d, p[0-7]/m, z[0-9]+\.d
+** ...
+*/
+FUNC (__builtin_ctzll, ctz_uint64, uint64_t)
+


[gcc r15-4191] gcc, libcpp: Add warning switch for "#pragma once in main file" [PR89808]

2024-10-08 Thread Ken Matsui via Gcc-cvs
https://gcc.gnu.org/g:821d56100e1110ab6a166f50819522254eb30923

commit r15-4191-g821d56100e1110ab6a166f50819522254eb30923
Author: Ken Matsui 
Date:   Fri Mar 1 22:10:55 2024 -0800

gcc, libcpp: Add warning switch for "#pragma once in main file" [PR89808]

This patch adds a warning switch for "#pragma once in main file".  The
warning option name is Wpragma-once-outside-header, which is the same
as Clang provides.

PR preprocessor/89808

gcc/c-family/ChangeLog:

* c.opt (Wpragma_once_outside_header): Define new option.
* c.opt.urls: Regenerate.

gcc/ChangeLog:

* doc/invoke.texi (Warning Options): Document
-Wno-pragma-once-outside-header.

libcpp/ChangeLog:

* include/cpplib.h (cpp_warning_reason): Define
CPP_W_PRAGMA_ONCE_OUTSIDE_HEADER.
* directives.cc (do_pragma_once): Use
CPP_W_PRAGMA_ONCE_OUTSIDE_HEADER.

gcc/testsuite/ChangeLog:

* g++.dg/warn/Wno-pragma-once-outside-header.C: New test.
* g++.dg/warn/Wpragma-once-outside-header.C: New test.

Signed-off-by: Ken Matsui 
Reviewed-by: Marek Polacek 

Diff:
---
 gcc/c-family/c.opt |  4 
 gcc/c-family/c.opt.urls|  3 +++
 gcc/doc/invoke.texi| 10 --
 gcc/testsuite/g++.dg/warn/Wno-pragma-once-outside-header.C |  5 +
 gcc/testsuite/g++.dg/warn/Wpragma-once-outside-header.C|  6 ++
 libcpp/directives.cc   |  3 ++-
 libcpp/include/cpplib.h|  3 ++-
 7 files changed, 30 insertions(+), 4 deletions(-)

diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt
index 9d1fccadbf99..1f2e72a0bb73 100644
--- a/gcc/c-family/c.opt
+++ b/gcc/c-family/c.opt
@@ -1214,6 +1214,10 @@ Wpragmas
 C ObjC C++ ObjC++ Var(warn_pragmas) Init(1) Warning
 Warn about misuses of pragmas.
 
+Wpragma-once-outside-header
+C ObjC C++ ObjC++ Var(warn_pragma_once_outside_header) 
CppReason(CPP_W_PRAGMA_ONCE_OUTSIDE_HEADER) Init(1) Warning
+Warn about #pragma once outside of a header.
+
 Wprio-ctor-dtor
 C ObjC C++ ObjC++ Var(warn_prio_ctor_dtor) Init(1) Warning
 Warn if constructor or destructors with priorities from 0 to 100 are used.
diff --git a/gcc/c-family/c.opt.urls b/gcc/c-family/c.opt.urls
index b77575bc8969..b1593ef41401 100644
--- a/gcc/c-family/c.opt.urls
+++ b/gcc/c-family/c.opt.urls
@@ -684,6 +684,9 @@ 
UrlSuffix(gcc/Warning-Options.html#index-Wno-pointer-to-int-cast)
 Wpragmas
 UrlSuffix(gcc/Warning-Options.html#index-Wno-pragmas)
 
+Wpragma-once-outside-header
+UrlSuffix(gcc/Warning-Options.html#index-Wno-pragma-once-outside-header)
+
 Wprio-ctor-dtor
 UrlSuffix(gcc/Warning-Options.html#index-Wno-prio-ctor-dtor)
 
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index b2f16b45eaf4..c0c8bf1c29a9 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -395,8 +395,8 @@ Objective-C and Objective-C++ Dialects}.
 -Wpacked  -Wno-packed-bitfield-compat  -Wpacked-not-aligned  -Wpadded
 -Wparentheses  -Wno-pedantic-ms-format
 -Wpointer-arith  -Wno-pointer-compare  -Wno-pointer-to-int-cast
--Wno-pragmas  -Wno-prio-ctor-dtor  -Wredundant-decls
--Wrestrict  -Wno-return-local-addr  -Wreturn-type
+-Wno-pragmas  -Wno-pragma-once-outside-header  -Wno-prio-ctor-dtor
+-Wredundant-decls  -Wrestrict  -Wno-return-local-addr  -Wreturn-type
 -Wno-scalar-storage-order  -Wsequence-point
 -Wshadow  -Wshadow=global  -Wshadow=local  -Wshadow=compatible-local
 -Wno-shadow-ivar
@@ -8147,6 +8147,12 @@ Do not warn about misuses of pragmas, such as incorrect 
parameters,
 invalid syntax, or conflicts between pragmas.  See also
 @option{-Wunknown-pragmas}.
 
+@opindex Wno-pragma-once-outside-header
+@opindex Wpragma-once-outside-header
+@item -Wno-pragma-once-outside-header
+Do not warn when @code{#pragma once} is used in a file that is not a header
+file, such as a main file.
+
 @opindex Wno-prio-ctor-dtor
 @opindex Wprio-ctor-dtor
 @item -Wno-prio-ctor-dtor
diff --git a/gcc/testsuite/g++.dg/warn/Wno-pragma-once-outside-header.C 
b/gcc/testsuite/g++.dg/warn/Wno-pragma-once-outside-header.C
new file mode 100644
index ..b5be4d25a9d8
--- /dev/null
+++ b/gcc/testsuite/g++.dg/warn/Wno-pragma-once-outside-header.C
@@ -0,0 +1,5 @@
+// { dg-do assemble  }
+// { dg-options "-Wno-pragma-once-outside-header" }
+
+#pragma once
+int main() {}
diff --git a/gcc/testsuite/g++.dg/warn/Wpragma-once-outside-header.C 
b/gcc/testsuite/g++.dg/warn/Wpragma-once-outside-header.C
new file mode 100644
index ..448e26102919
--- /dev/null
+++ b/gcc/testsuite/g++.dg/warn/Wpragma-once-outside-header.C
@@ -0,0 +1,6 @@
+// { dg-do assemble  }
+// { dg-options "-Werror=pragma-once-outside-header" }
+// { dg-message "some warnings being treated as errors" "" {target "*-*-*"} 0 }
+
+#pragma once  // { dg

[gcc r15-4171] Fix parsing of substring refs in coarrays. [PR51815]

2024-10-08 Thread Andre Vehreschild via Gcc-cvs
https://gcc.gnu.org/g:0ad2c76bea20dbeac753f10df6f9f86d142348d4

commit r15-4171-g0ad2c76bea20dbeac753f10df6f9f86d142348d4
Author: Andre Vehreschild 
Date:   Tue Oct 1 09:30:59 2024 +0200

Fix parsing of substring refs in coarrays. [PR51815]

The parser was greadily taking the substring ref as an array ref because
an array_spec was present.  Fix this by only parsing the coarray (pseudo)
ref when no regular array is present.

gcc/fortran/ChangeLog:

PR fortran/51815

* array.cc (gfc_match_array_ref): Only parse coarray part of
ref.
* match.h (gfc_match_array_ref): Add flag.
* primary.cc (gfc_match_varspec): Request only coarray ref
parsing when no regular array is present.  Report error on
unexpected additional ref.

gcc/testsuite/ChangeLog:

* gfortran.dg/pr102532.f90: Fix dg-errors: Add new error.
* gfortran.dg/coarray/substring_1.f90: New test.

Diff:
---
 gcc/fortran/array.cc  |  9 --
 gcc/fortran/match.h   |  3 +-
 gcc/fortran/primary.cc| 35 ---
 gcc/testsuite/gfortran.dg/coarray/substring_1.f90 | 16 +++
 gcc/testsuite/gfortran.dg/pr102532.f90| 16 +++
 5 files changed, 59 insertions(+), 20 deletions(-)

diff --git a/gcc/fortran/array.cc b/gcc/fortran/array.cc
index 1fa61ebfe2a0..ed8cb54803b8 100644
--- a/gcc/fortran/array.cc
+++ b/gcc/fortran/array.cc
@@ -179,7 +179,7 @@ matched:
 
 match
 gfc_match_array_ref (gfc_array_ref *ar, gfc_array_spec *as, int init,
-int corank)
+int corank, bool coarray_only)
 {
   match m;
   bool matched_bracket = false;
@@ -198,6 +198,8 @@ gfc_match_array_ref (gfc_array_ref *ar, gfc_array_spec *as, 
int init,
matched_bracket = true;
goto coarray;
 }
+  else if (coarray_only && corank != 0)
+goto coarray;
 
   if (gfc_match_char ('(') != MATCH_YES)
 {
@@ -243,11 +245,12 @@ gfc_match_array_ref (gfc_array_ref *ar, gfc_array_spec 
*as, int init,
 coarray:
   if (!matched_bracket && gfc_match_char ('[') != MATCH_YES)
 {
-  if (ar->dimen > 0)
+  int dim = coarray_only ? 0 : ar->dimen;
+  if (dim > 0 || coarray_only)
{
  if (corank != 0)
{
- for (int i = ar->dimen; i < GFC_MAX_DIMENSIONS; ++i)
+ for (int i = dim; i < GFC_MAX_DIMENSIONS; ++i)
ar->dimen_type[i] = DIMEN_THIS_IMAGE;
  ar->codimen = corank;
}
diff --git a/gcc/fortran/match.h b/gcc/fortran/match.h
index 84d84b818259..2c76afb179af 100644
--- a/gcc/fortran/match.h
+++ b/gcc/fortran/match.h
@@ -317,7 +317,8 @@ match gfc_match_init_expr (gfc_expr **);
 
 /* array.cc.  */
 match gfc_match_array_spec (gfc_array_spec **, bool, bool);
-match gfc_match_array_ref (gfc_array_ref *, gfc_array_spec *, int, int);
+match gfc_match_array_ref (gfc_array_ref *, gfc_array_spec *, int, int,
+  bool = false);
 match gfc_match_array_constructor (gfc_expr **);
 
 /* interface.cc.  */
diff --git a/gcc/fortran/primary.cc b/gcc/fortran/primary.cc
index 09add925fcd1..c11359a559b2 100644
--- a/gcc/fortran/primary.cc
+++ b/gcc/fortran/primary.cc
@@ -2192,7 +2192,7 @@ gfc_match_varspec (gfc_expr *primary, int equiv_flag, 
bool sub_flag,
   bool intrinsic;
   bool inferred_type;
   locus old_loc;
-  char sep;
+  char peeked_char;
 
   tail = NULL;
 
@@ -2282,9 +2282,10 @@ gfc_match_varspec (gfc_expr *primary, int equiv_flag, 
bool sub_flag,
sym->ts.u.derived = tgt_expr->ts.u.derived;
 }
 
-  if ((inferred_type && !sym->as && gfc_peek_ascii_char () == '(')
-  || (equiv_flag && gfc_peek_ascii_char () == '(')
-  || gfc_peek_ascii_char () == '[' || sym->attr.codimension
+  peeked_char = gfc_peek_ascii_char ();
+  if ((inferred_type && !sym->as && peeked_char == '(')
+  || (equiv_flag && peeked_char == '(') || peeked_char == '['
+  || sym->attr.codimension
   || (sym->attr.dimension && sym->ts.type != BT_CLASS
  && !sym->attr.proc_pointer && !gfc_is_proc_ptr_comp (primary)
  && !(gfc_matching_procptr_assignment
@@ -2295,6 +2296,8 @@ gfc_match_varspec (gfc_expr *primary, int equiv_flag, 
bool sub_flag,
  || CLASS_DATA (sym)->attr.codimension)))
 {
   gfc_array_spec *as;
+  bool coarray_only = sym->attr.codimension && !sym->attr.dimension
+ && sym->ts.type == BT_CHARACTER;
 
   tail = extend_ref (primary, tail);
   tail->type = REF_ARRAY;
@@ -2310,12 +2313,18 @@ gfc_match_varspec (gfc_expr *primary, int equiv_flag, 
bool sub_flag,
   else
as = sym->as;
 
-  m = gfc_match_array_ref (&tail->u.ar, as, equiv_flag,
-  as ? as->corank : 0);
+  m = gfc_match_array_ref (&tail->u.ar, as, equiv_flag, as ? as->corank : 
0,
+