[0/9] [middle-end] Add param to vec_perm_const hook to specify mode of input operand

2022-05-18 Thread Prathamesh Kulkarni via Gcc-patches
Hi,
The attached patch adds another parameter machine_mode op_mode to vec_perm_const
hook to specify mode of input operands. The motivation for doing this
is PR96463,
where we create vec_perm_expr of the form:
lhs = vec_perm_expr
where lhs and rhs have different vector types but same element type
(lhs is SVE and rhs is corresponding advsimd vector).

It seems the following targets were affected: aarch64, i386, arm, ia64,
mips, rs6000, s390, sparc, gcn.

Bootstrapped+tested on x86_64-linux-gnu, aarch64-linux-gnu.
For other targets, I did make all-gcc stage1, which seems to build OK.

Thanks,
Prathamesh
diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi
index c5006afc00d..31ff6ef3f92 100644
--- a/gcc/doc/tm.texi
+++ b/gcc/doc/tm.texi
@@ -6088,7 +6088,7 @@ for the given scalar type @var{type}.  @var{is_packed} is 
false if the scalar
 access using @var{type} is known to be naturally aligned.
 @end deftypefn
 
-@deftypefn {Target Hook} bool TARGET_VECTORIZE_VEC_PERM_CONST (machine_mode 
@var{mode}, rtx @var{output}, rtx @var{in0}, rtx @var{in1}, const 
vec_perm_indices @var{&sel})
+@deftypefn {Target Hook} bool TARGET_VECTORIZE_VEC_PERM_CONST (machine_mode 
@var{mode}, machine_mode @var{op_mode}, rtx @var{output}, rtx @var{in0}, rtx 
@var{in1}, const vec_perm_indices @var{&sel})
 This hook is used to test whether the target can permute up to two
 vectors of mode @var{mode} using the permutation vector @code{sel}, and
 also to emit such a permutation.  In the former case @var{in0}, @var{in1}
diff --git a/gcc/optabs-query.cc b/gcc/optabs-query.cc
index 68dc679cc6a..aef9d4c5d28 100644
--- a/gcc/optabs-query.cc
+++ b/gcc/optabs-query.cc
@@ -417,8 +417,8 @@ can_vec_perm_var_p (machine_mode mode)
with here.  */
 
 bool
-can_vec_perm_const_p (machine_mode mode, const vec_perm_indices &sel,
- bool allow_variable_p)
+can_vec_perm_const_p (machine_mode mode, machine_mode op_mode,
+ const vec_perm_indices &sel, bool allow_variable_p)
 {
   /* If the target doesn't implement a vector mode for the vector type,
  then no operations are supported.  */
@@ -448,7 +448,7 @@ can_vec_perm_const_p (machine_mode mode, const 
vec_perm_indices &sel,
 
   if (targetm.vectorize.vec_perm_const != NULL)
 {
-  if (targetm.vectorize.vec_perm_const (mode, NULL_RTX, NULL_RTX,
+  if (targetm.vectorize.vec_perm_const (mode, op_mode, NULL_RTX, NULL_RTX,
NULL_RTX, sel))
return true;
 
@@ -462,6 +462,13 @@ can_vec_perm_const_p (machine_mode mode, const 
vec_perm_indices &sel,
   return false;
 }
 
+bool
+can_vec_perm_const_p (machine_mode mode, const vec_perm_indices &sel,
+ bool allow_variable_p)
+{
+  return can_vec_perm_const_p (mode, mode, sel, allow_variable_p);
+}
+
 /* Find a widening optab even if it doesn't widen as much as we want.
E.g. if from_mode is HImode, and to_mode is DImode, and there is no
direct HI->SI insn, then return SI->DI, if that exists.  */
diff --git a/gcc/optabs-query.h b/gcc/optabs-query.h
index b9c9fd6f64d..fa22c2210d8 100644
--- a/gcc/optabs-query.h
+++ b/gcc/optabs-query.h
@@ -178,6 +178,8 @@ bool can_conditionally_move_p (machine_mode mode);
 opt_machine_mode qimode_for_vec_perm (machine_mode);
 bool selector_fits_mode_p (machine_mode, const vec_perm_indices &);
 bool can_vec_perm_var_p (machine_mode);
+bool can_vec_perm_const_p (machine_mode, machine_mode, const vec_perm_indices 
&,
+  bool = true);
 bool can_vec_perm_const_p (machine_mode, const vec_perm_indices &,
   bool = true);
 /* Find a widening optab even if it doesn't widen as much as we want.  */
diff --git a/gcc/optabs.cc b/gcc/optabs.cc
index 3d8fa3abdfe..55f10c41789 100644
--- a/gcc/optabs.cc
+++ b/gcc/optabs.cc
@@ -6250,7 +6250,9 @@ expand_vec_perm_const (machine_mode mode, rtx v0, rtx v1,
   if (single_arg_p)
v1 = v0;
 
-  if (targetm.vectorize.vec_perm_const (mode, target, v0, v1, indices))
+  gcc_checking_assert (GET_MODE (v0) == GET_MODE (v1));
+  machine_mode op_mode = GET_MODE (v0);
+  if (targetm.vectorize.vec_perm_const (mode, op_mode, target, v0, v1, 
indices))
return target;
 }
 
@@ -6264,7 +6266,7 @@ expand_vec_perm_const (machine_mode mode, rtx v0, rtx v1,
   v0_qi = gen_lowpart (qimode, v0);
   v1_qi = gen_lowpart (qimode, v1);
   if (targetm.vectorize.vec_perm_const != NULL
- && targetm.vectorize.vec_perm_const (qimode, target_qi, v0_qi,
+ && targetm.vectorize.vec_perm_const (qimode, qimode, target_qi, v0_qi,
   v1_qi, qimode_indices))
return gen_lowpart (mode, target_qi);
 }
diff --git a/gcc/target.def b/gcc/target.def
index d85adf36a39..2713c31dc3f 100644
--- a/gcc/target.def
+++ b/gcc/target.def
@@ -1894,7 +1894,7 @@ try the equivalent byte operation.  If that also fails, 
it will try forcing\n\
 the selector into a register and 

[1/9] AArch64 changes to adjust vec_perm_const hook

2022-05-18 Thread Prathamesh Kulkarni via Gcc-patches
Hi,
The attached patch adjusts vec_perm_const hook to accommodate the new parameter.
For now, it bails out if vmode != op_mode, in follow-up patch to
PR96463, I will add dup
as exception.
Bootstrapped+tested on aarch64-linux-gnu.
Does it look OK ?

Thanks,
Prathamesh
diff --git a/gcc/config/aarch64/aarch64.cc b/gcc/config/aarch64/aarch64.cc
index f4d2a800f39..e6a24a0f9e1 100644
--- a/gcc/config/aarch64/aarch64.cc
+++ b/gcc/config/aarch64/aarch64.cc
@@ -24145,9 +24145,13 @@ aarch64_expand_vec_perm_const_1 (struct 
expand_vec_perm_d *d)
 /* Implement TARGET_VECTORIZE_VEC_PERM_CONST.  */
 
 static bool
-aarch64_vectorize_vec_perm_const (machine_mode vmode, rtx target, rtx op0,
- rtx op1, const vec_perm_indices &sel)
+aarch64_vectorize_vec_perm_const (machine_mode vmode, machine_mode op_mode,
+ rtx target, rtx op0, rtx op1,
+ const vec_perm_indices &sel)
 {
+  if (vmode != op_mode)
+return false;
+
   struct expand_vec_perm_d d;
 
   /* Check whether the mask can be applied to a single vector.  */


Re: [PATCH] libgo: Recognize off64_t / loff_t type definition of musl libc

2022-05-18 Thread Sören Tempel via Gcc-patches
I modified your patch to also define libgo_off_t_type (along to
libgo_loff_t_type) and used that to define Offset_t in mksysinfo.sh.
Furthermore, I fixed the include for the loff_t feature check.

With those two modifications your patch works for me (see attachment).

Greetings,
Sören

Ian Lance Taylor  wrote:
> On Thu, May 12, 2022 at 11:23 AM Sören Tempel via Gcc-patches
>  wrote:
> >
> > The off64_t type is used for defining Offset_t:
> >
> > 
> > https://github.com/golang/gofrontend/blob/4bdff733a0c2a9ddc3eff104b1be03df058a79c4/libgo/mksysinfo.sh#L406-L410
> >
> > On musl, _HAVE_OFF64_T is defined since autoconf doesn't mind it
> > being defined as a macro but -fdump-go-spec does, hence you end up
> > with the following compilation error (even with your patch applied):
> 
> Ah, thanks.
> 
> 
> > Apart from off64_t stuff, there is only one minor issue (see below).
> >
> > > index 7e2b98ba6..487099a33 100644
> > > --- a/libgo/configure.ac
> > > +++ b/libgo/configure.ac
> > > @@ -579,7 +579,7 @@ AC_C_BIGENDIAN
> > > +
> > > +CFLAGS_hold="$CFLAGS"
> > > +CFLAGS="$OSCFLAGS $CFLAGS"
> > >  AC_CHECK_TYPES([loff_t])
> > > +CFLAGS="$CFLAGS_hold"
> >
> > The AC_CHECK_TYPES invocation is missing an include of fcntl.h (which
> > defines loff_t in musl) and as such fails and causes libgo compilation
> > to fail with "reference to undefined name '_libgo_loff_t_type'" as
> > HAVE_LOFF_T is not defined. The invocation needs to be changed to:
> >
> > AC_CHECK_TYPES([loff_t], [], [], [[#include ]])
> >
> > and this needs to be adjusted accordingly in configure as well.
> 
> Hmmm, I added fcntl.h to AC_CHECK_HEADERS.  I thought that would be
> enough to cause it to be included in future tests.  Perhaps not.
> 
> Ian

diff --git a/libgo/config.h.in b/libgo/config.h.in
index 25b8ab8f9ee..2c3c7469675 100644
--- a/libgo/config.h.in
+++ b/libgo/config.h.in
@@ -70,6 +70,9 @@
 /* Define to 1 if you have the `fchownat' function. */
 #undef HAVE_FCHOWNAT
 
+/* Define to 1 if you have the  header file. */
+#undef HAVE_FCNTL_H
+
 /* Define to 1 if you have the `futimesat' function. */
 #undef HAVE_FUTIMESAT
 
diff --git a/libgo/configure b/libgo/configure
index ffe17c9be55..13e21d60c62 100755
--- a/libgo/configure
+++ b/libgo/configure
@@ -15249,7 +15249,7 @@ $as_echo "#define HAVE_GETIPINFO 1" >>confdefs.h
   fi
 
 
-for ac_header in port.h sched.h semaphore.h sys/file.h sys/mman.h syscall.h 
sys/epoll.h sys/event.h sys/inotify.h sys/ptrace.h sys/syscall.h sys/sysctl.h 
sys/user.h sys/utsname.h sys/select.h sys/socket.h net/bpf.h net/if.h 
net/if_arp.h net/route.h netpacket/packet.h sys/prctl.h sys/mount.h sys/vfs.h 
sys/statfs.h sys/timex.h sys/sysinfo.h utime.h linux/ether.h linux/fs.h 
linux/ptrace.h linux/reboot.h netinet/in_syst.h netinet/ip.h 
netinet/ip_mroute.h netinet/if_ether.h lwp.h
+for ac_header in fcntl.h port.h sched.h semaphore.h sys/file.h sys/mman.h 
syscall.h sys/epoll.h sys/event.h sys/inotify.h sys/ptrace.h sys/syscall.h 
sys/sysctl.h sys/user.h sys/utsname.h sys/select.h sys/socket.h net/bpf.h 
net/if.h net/if_arp.h net/route.h netpacket/packet.h sys/prctl.h sys/mount.h 
sys/vfs.h sys/statfs.h sys/timex.h sys/sysinfo.h utime.h linux/ether.h 
linux/fs.h linux/ptrace.h linux/reboot.h netinet/in_syst.h netinet/ip.h 
netinet/ip_mroute.h netinet/if_ether.h lwp.h
 do :
   as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
 ac_fn_c_check_header_mongrel "$LINENO" "$ac_header" "$as_ac_Header" 
"$ac_includes_default"
@@ -15546,7 +15546,10 @@ _ACEOF
 
 fi
 
-ac_fn_c_check_type "$LINENO" "loff_t" "ac_cv_type_loff_t" 
"$ac_includes_default"
+
+CFLAGS_hold="$CFLAGS"
+CFLAGS="$OSCFLAGS $CFLAGS"
+ac_fn_c_check_type "$LINENO" "loff_t" "ac_cv_type_loff_t" "#include "
 if test "x$ac_cv_type_loff_t" = xyes; then :
 
 cat >>confdefs.h <<_ACEOF
@@ -15556,6 +15559,7 @@ _ACEOF
 
 fi
 
+CFLAGS="$CFLAGS_hold"
 
 LIBS_hold="$LIBS"
 LIBS="$LIBS -lm"
diff --git a/libgo/configure.ac b/libgo/configure.ac
index 7e2b98ba67c..bac58b07b41 100644
--- a/libgo/configure.ac
+++ b/libgo/configure.ac
@@ -579,7 +579,7 @@ AC_C_BIGENDIAN
 
 GCC_CHECK_UNWIND_GETIPINFO
 
-AC_CHECK_HEADERS(port.h sched.h semaphore.h sys/file.h sys/mman.h syscall.h 
sys/epoll.h sys/event.h sys/inotify.h sys/ptrace.h sys/syscall.h sys/sysctl.h 
sys/user.h sys/utsname.h sys/select.h sys/socket.h net/bpf.h net/if.h 
net/if_arp.h net/route.h netpacket/packet.h sys/prctl.h sys/mount.h sys/vfs.h 
sys/statfs.h sys/timex.h sys/sysinfo.h utime.h linux/ether.h linux/fs.h 
linux/ptrace.h linux/reboot.h netinet/in_syst.h netinet/ip.h 
netinet/ip_mroute.h netinet/if_ether.h lwp.h)
+AC_CHECK_HEADERS(fcntl.h port.h sched.h semaphore.h sys/file.h sys/mman.h 
syscall.h sys/epoll.h sys/event.h sys/inotify.h sys/ptrace.h sys/syscall.h 
sys/sysctl.h sys/user.h sys/utsname.h sys/select.h sys/socket.h net/bpf.h 
net/if.h net/if_arp.h net/route.h netpacket/packet.h sys/prctl.h sys/mount.h 
sys/vfs.h sys/statfs.h sys/timex.h sys/sysinfo.h utime.h linux/ether.h 
linux/fs

[PATCH] i386: Add a constraint for absolute symboilc address [PR 105576]

2022-05-18 Thread Hongyu Wang via Gcc-patches
Hi,

This patch adds a constraint "Ws" to allow absolute symbolic address for either
function or variable. This also works under -mcmodel=large.

Bootstrapped/regtested on x86_64-pc-linux-gnu{-m32,}

Ok for master?

gcc/ChangeLog:

PR target/105576
* config/i386/constraints.md (Ws): New constraint.
* config/i386/i386-protos.h (ix86_symbolic_address_p):
New proto type.
* config/i386/i386.cc (ix86_symbolic_address_p):
New function to ensure a rtx is a symbolic address.

gcc/testsuite/ChangeLog:

PR target/105576
* gcc.target/i386/pr105576.c: New test.
---
 gcc/config/i386/constraints.md   |  4 
 gcc/config/i386/i386-protos.h|  1 +
 gcc/config/i386/i386.cc  |  7 +++
 gcc/testsuite/gcc.target/i386/pr105576.c | 11 +++
 4 files changed, 23 insertions(+)
 create mode 100644 gcc/testsuite/gcc.target/i386/pr105576.c

diff --git a/gcc/config/i386/constraints.md b/gcc/config/i386/constraints.md
index 7361687632f..ec0702be368 100644
--- a/gcc/config/i386/constraints.md
+++ b/gcc/config/i386/constraints.md
@@ -348,6 +348,10 @@ (define_constraint "Z"
instructions)."
   (match_operand 0 "x86_64_zext_immediate_operand"))
 
+(define_constraint "Ws"
+ "A constraint that matches an absolute symbolic address."
+ (match_test "ix86_symbolic_address_p (op)"))
+
 ;; T prefix is used for different address constraints
 ;;   v - VSIB address
 ;;   s - address with no segment register
diff --git a/gcc/config/i386/i386-protos.h b/gcc/config/i386/i386-protos.h
index 3596ce81ecf..2b8d063850f 100644
--- a/gcc/config/i386/i386-protos.h
+++ b/gcc/config/i386/i386-protos.h
@@ -337,6 +337,7 @@ extern void x86_output_aligned_bss (FILE *, tree, const 
char *,
unsigned HOST_WIDE_INT, unsigned);
 extern void x86_elf_aligned_decl_common (FILE *, tree, const char *,
 unsigned HOST_WIDE_INT, unsigned);
+extern bool ix86_symbolic_address_p (rtx x);
 
 #ifdef RTX_CODE
 extern void ix86_fp_comparison_codes (enum rtx_code code, enum rtx_code *,
diff --git a/gcc/config/i386/i386.cc b/gcc/config/i386/i386.cc
index 86752a6516a..76728d10c8d 100644
--- a/gcc/config/i386/i386.cc
+++ b/gcc/config/i386/i386.cc
@@ -23956,6 +23956,13 @@ ix86_push_rounding (poly_int64 bytes)
   return ROUND_UP (bytes, UNITS_PER_WORD);
 }
 
+bool ix86_symbolic_address_p (rtx x)
+{
+  poly_int64 offset;
+  x = strip_offset (x, &offset);
+  return SYMBOL_REF_P (x) || LABEL_REF_P (x);
+}
+
 /* Target-specific selftests.  */
 
 #if CHECKING_P
diff --git a/gcc/testsuite/gcc.target/i386/pr105576.c 
b/gcc/testsuite/gcc.target/i386/pr105576.c
new file mode 100644
index 000..06dd860d3f3
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr105576.c
@@ -0,0 +1,11 @@
+/* PR target/105576 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -mcmodel=large" } */
+
+extern int var;
+void *addr(void) { return &var; }
+void addr_via_asm(void)
+{
+  asm (".pushsection .xxx,\"aw\"\n\t .dc.a %0\n\t .popsection" :: "Ws"(addr));
+  asm (".pushsection .xxx,\"aw\"\n\t .dc.a %0\n\t .popsection" :: "Ws"(&var));
+}
-- 
2.18.1



Re: PING: [PATCH v2] x86: Fix -fsplit-stack feature detection via TARGET_CAN_SPLIT_STACK

2022-05-18 Thread Sören Tempel via Gcc-patches
Hi,

Uros Bizjak  wrote:
> > > > gcc/ChangeLog:
> > > >
> > > > * config/i386/gnu-user-common.h (defined): Only define
> > > > TARGET_CAN_SPLIT_STACK for glibc targets.
> > > > * config/i386/gnu.h (defined): Ditto.
> 
> This looks good to me, so OK.
> 
> Thanks,
> Uros.

I am not deeply familiar with the GCC development process but since it
seems that this hasn't been merged yet: Is there anything else that I
need to do or what is the process for getting this patch upstreamed? (:

Thank you,
Sören

> > > > ---
> > > > Changes since v1: Use (DEFAULT_LIBC == LIBC_GLIBC) instead of
> > > > OPTION_GLIBC_P to detect use of glibc in a pre-processor context.
> > > >
> > > > Is there a better way to detect use of glibc in the config header?
> > > >
> > > >  gcc/config/i386/gnu-user-common.h | 5 +++--
> > > >  gcc/config/i386/gnu.h | 5 +++--
> > > >  2 files changed, 6 insertions(+), 4 deletions(-)
> > > >
> > > > diff --git a/gcc/config/i386/gnu-user-common.h 
> > > > b/gcc/config/i386/gnu-user-common.h
> > > > index 00226f5a455..e126c3fa9fa 100644
> > > > --- a/gcc/config/i386/gnu-user-common.h
> > > > +++ b/gcc/config/i386/gnu-user-common.h
> > > > @@ -66,7 +66,8 @@ along with GCC; see the file COPYING3.  If not see
> > > >  #define STACK_CHECK_STATIC_BUILTIN 1
> > > >
> > > >  /* We only build the -fsplit-stack support in libgcc if the
> > > > -   assembler has full support for the CFI directives.  */
> > > > -#if HAVE_GAS_CFI_PERSONALITY_DIRECTIVE
> > > > +   assembler has full support for the CFI directives.  Also
> > > > +   we only support -fsplit-stack on glibc targets.  */
> > > > +#if HAVE_GAS_CFI_PERSONALITY_DIRECTIVE && (DEFAULT_LIBC == LIBC_GLIBC)
> > > >  #define TARGET_CAN_SPLIT_STACK
> > > >  #endif
> > > > diff --git a/gcc/config/i386/gnu.h b/gcc/config/i386/gnu.h
> > > > index 25fbc07f58c..17494333bb9 100644
> > > > --- a/gcc/config/i386/gnu.h
> > > > +++ b/gcc/config/i386/gnu.h
> > > > @@ -41,8 +41,9 @@ along with GCC.  If not, see 
> > > > .
> > > >  #define TARGET_THREAD_SSP_OFFSET0x14
> > > >
> > > >  /* We only build the -fsplit-stack support in libgcc if the
> > > > -   assembler has full support for the CFI directives.  */
> > > > -#if HAVE_GAS_CFI_PERSONALITY_DIRECTIVE
> > > > +   assembler has full support for the CFI directives.  Also
> > > > +   we only support -fsplit-stack on glibc targets.  */
> > > > +#if HAVE_GAS_CFI_PERSONALITY_DIRECTIVE && (DEFAULT_LIBC == LIBC_GLIBC)
> > > >  #define TARGET_CAN_SPLIT_STACK
> > > >  #endif
> > > >  /* We steal the last transactional memory word.  */


Re: [PATCH] libgompd: Add OMPD support and global ICV functions

2022-05-18 Thread Jakub Jelinek via Gcc-patches
On Mon, May 16, 2022 at 07:35:17PM +0200, Mohamed Atef via Gcc-patches wrote:
> libgomp/ChangeLog
> 
> 2022-05-15 Mohamed Atef 
> 
> *config/darwin/plugin-suffix.h (SONAME_SUFFIX): Remove ()s.
> *config/hpux/plugin-suffix.h (SONAME_SUFFIX): Remove ()s.
> *config/posix/plugin-suffix.h (SONAME_SUFFIX): Remove ()s.
> *configure: Regenerate.
> *Makefile.am (toolexeclib_LTLIBRARIES): Add libgompd.la.
> (libgompd_la_LDFLAGS, libgompd_la_DEPENDENCIES,
> libgompd_la_LINK,libgompd_la_SOURCES, libgompd_version_dep,
> libgompd_version_script, libgompd.ver-sun, libgompd.ver,
> libgompd_version_info): New.
> *Makefile.in: Regenerate.
> *aclocal.m4: Regenerate.
> *env.c: Include ompd-support.h.
> (parse_debug): New function.
> (gompd_enabled): New Variable.
> (initialize_env): Call gompd_load.
> (initialize_env): Call parse_debug.
> *team.c: Include ompd-support.h.
> (gomp_team_start): Call ompd_bp_parallel_begin.
> (gomp_team_end): Call ompd_bp_parallel_end.
> (gomp_thread_start): Call ompd_bp_thread_start.
> *libgomp.map: ADD OMP_5.0.3 symbol versions.

Add rather than ADD

> *libgompd.map: New.
> *omp-tools.h.in: New.
> *ompd-types.h.in: New.
> *ompd-support.h: New.
> *ompd-support.c: New.
> *ompd-helper.h: New.
> *ompd-helper.c: New.
> *ompd-init.c: New.
> *ompd-icv.c: New.
> *configure.ac (AC_CONFIG_FILES): Add omp-tools.h and ompd-types.h.

Almost ok, minor comments below.
As I said earlier, as this is just partial implementation of the
OMPD, I think it would be better to commit it to a git branch but
already in the upstream repository, say devel/omp/ompd branch.

Do you have a FSF Copyright assignment on file or do you want to
submit this under DCO (https://gcc.gnu.org/dco.html)?  If the latter,
we need Signed-off-by line in your final patch mail and also in the
commit message.
The commit message should include a one line summary, then
empty line, then explanation what the patch is, followed by properly
formatted ChangeLog entry (the above is badly mangled by your mailer),
there should be 2 spaces around the name etc. and after the ChangeLog
entry the Signed-of-by line if you use DCO.
More details in https://gcc.gnu.org/gitwrite.html
In Authenticated access there is a link to a form to request write
access to the repository, please file it and write me as the sponsor.
Then follow the rest of gitwrite to e.g. do contrib/gcc-git-customization.sh
and then you can git gcc-verify to verify whether the ChangeLog entry in
your commit log is ok before you push it.

> --- /dev/null
> +++ b/libgomp/libgompd.map
> @@ -0,0 +1,23 @@
> +OMPD_5.1 {

Shouldn't this be OMPD_5.0 ?
The functions were already in OpenMP 5.0, weren't they?

> +  global:
> +ompd_initialize;
> +ompd_get_api_version;
> +ompd_get_version_string;
> +ompd_process_initialize;
> +ompd_device_initialize;
> +ompd_rel_address_space_handle;
> +ompd_finalize;
> +ompd_enumerate_icvs;
> +ompd_get_icv_from_scope;
> +ompd_get_icv_string_from_scope;
> +ompd_get_thread_handle;
> +ompd_get_thread_in_parallel;
> +ompd_rel_thread_handle;
> +ompd_thread_handle_compare;
> +ompd_get_thread_id;
> +ompd_get_device_from_thread;
> +ompd_bp_thread_begin;
> +ompd_bp_thread_end;

Why is ompd_bp_thread_{begin,end} here?  I thought they were
in libgomp.so.*, not in libgompd.so.*

> +  local:
> +*;
> +};

> +  /* NO cuda for now.  */

We support other kinds of offloading, so better just say
  /* No offloading support for now.  */
or so.

> +  if (device == OMPD_DEVICE_KIND_HOST)
> +{
> +  switch (icv_id)
> + {
> +   case gompd_icv_cancellation_var:
> + return
> +   gompd_get_cancellation ((ompd_address_space_handle_t *) handle,
> +   icv_value);
> +   case gompd_icv_max_task_priority_var:
> + return gompd_get_max_task_priority ((ompd_address_space_handle_t *)
> + handle, icv_value);
> +   case gompd_icv_stacksize_var:
> + return gompd_get_stacksize ((ompd_address_space_handle_t *) handle,
> + icv_value);

You use that overly long (ompd_address_space_handle_t *) handle in all the
spots and it causes various formatting issues.  Wouldn't it be better
to add some temporary variable above the switch
  ompd_address_space_handle_t *whatever
= (ompd_address_space_handle_t *) handle;
(for some good choice of name) and then just use it instead of
(ompd_address_space_handle_t *) handle which would allow always writing
return gompd_whatever (whatever, icv_value);
and not the uglier return with call on the next line, or even worse ( on
a different line from the function name?

> +ompd_rc_t
> +ompd_finalize ()

Please use (void) instead of ()

> +void
> +gompd_load ()

Likewise.

> +void __attribute__ ((noipa))
> +ompd_dll_locations_valid ()

Likewise (and several times more).

Jakub



Re: [committed] Revert 'Use more ARRAY_SIZE.' for mkoffload (was: [PATCH] Use more ARRAY_SIZE.)

2022-05-18 Thread Martin Liška
On 5/17/22 21:03, Tobias Burnus wrote:
> This patch broke offloading – fixed by reverting the patch for
> {gcn,nvptx}/mkoffload.cc – and committed as obvious. Changing a C-code
> generating string without telling the then called C compiler about the
> macro won't fly.  See attachment for
> r13-569-gc9852156dd2fedec130f6d8eb669579ef6237946, which reverts it for
> mkoffload.cc, only.

Thank you for the fix and sorry for the code breakage ;)

Cheers,
Martin


Re: [PATCH 1/3]middle-end: Add the ability to let the target decide the method of argument promotions.

2022-05-18 Thread Richard Sandiford via Gcc-patches
Tamar Christina  writes:
>  […]
>> >> > We generate for e.g.:
>> >> >
>> >> > #include 
>> >> >
>> >> > uint16_t f8 (uint8_t xr, uint8_t xc){
>> >> > return (uint8_t)(xr * xc);
>> >> > }
>> >> >
>> >> > (insn 9 6 10 2 (set (reg:HI 101)
>> >> (zero_extend:HI (reg/v:QI 96 [ xr ]))) "prom.c":4:16 -1
>> >> (nil))
>> >> (insn 10 9 11 2 (set (reg:HI 102)
>> >> (zero_extend:HI (reg/v:QI 98 [ xc ]))) "prom.c":4:16 -1
>> >> (nil))
>> >> (insn 11 10 12 2 (set (reg:SI 103)
>> >> (mult:SI (subreg:SI (reg:HI 101) 0)
>> >> (subreg:SI (reg:HI 102) 0))) "prom.c":4:16 -1
>> >> (nil))
>> >> >
>> >> > Out of expand. The paradoxical subreg isn't generated at all out of
>> >> > expand unless it's needed. It does keep the original params around
>> >> > as
>> >> unused:
>> >> >
>> >> > (insn 2 7 4 2 (set (reg:QI 97)
>> >> (reg:QI 0 x0 [ xr ])) "prom.c":3:37 -1
>> >> (nil))
>> >> (insn 4 2 3 2 (set (reg:QI 99)
>> >> (reg:QI 1 x1 [ xc ])) "prom.c":3:37 -1
>> >> (nil))
>> >> >
>> >> > And the paradoxical subreg is moved into the first operation requiring 
>> >> > it:
>> >> >
>> >> > (insn 11 10 12 2 (set (reg:SI 103)
>> >> (mult:SI (subreg:SI (reg:HI 101) 0)
>> >> (subreg:SI (reg:HI 102) 0))) "prom.c":4:16 -1
>> >> (nil))
>> >>
>> >> Ah, OK, this isn't what I'd imaagined.  I thought the xr and xc
>> >> registers would be SIs and the DECL_RTLs would be QI subregs of those SI
>> regs.
>> >> I think that might work better, for the reasons above.  (That is,
>> >> whenever we need the register in extended form, we can simply extend
>> >> the existing reg rather than create a new one.)
>> >
>> > Ah, I see, no, I explicitly avoid this. When doing the type promotions
>> > I tell it that size of the copies of xr and xc is still the original size, 
>> > e.g. QI (i.e. I
>> don't change 97 and 99).
>> > This is different from what we do with extends where 97 and 99 *would*
>> be changed.
>> >
>> > The reason is that if I make this SI the compiler thinks it knows the
>> > value of all the bits in the register which led to various miscompares as 
>> > it
>> thinks it can use the SI value directly.
>> >
>> > This happens because again the xr and xc are hard regs. So having 97
>> > be
>> >
>> > (set (reg:SI 97) (subreg:SI (reg:QI 0 x0 [ xr ]) 0))
>> >
>> > gets folded to an incorrect
>> >
>> > (set (reg:SI 97) (reg:SI 0 x0 [ xr ]))
>> 
>> This part I would expect (and hope for :-)).
>> 
>> > And now 97 is free to be used without any zero extension, as 97 on it's own
>> is an invalid RTX.
>> 
>> But the way I'd imagined it working, expand would need to insert an
>> extension before any operation that needs the upper 24 bits to be defined
>> (e.g. comparisons, right shifts).  If the DECL_RTL is (subreg:QI (reg:SI x) 
>> 0)
>> then the upper bits are not defined, since SUBREG_PROMOTED_VAR_P
>> would/should be false for the subreg.
>
> Ah I see, my fear here was that if we have a pattern which splits out the 
> zero-extend for whatever reason
> that if it gets folded it would be invalid.  But I think I understand what 
> you meant.  In your case
> we'd never again use the hardreg, but that everything goes through 97. Got it.

Yeah.  The expand code is supposed to move the hard register into a
pseudo at the earliest opportunity (at the head of the function) and
then everything else should use the pseudo.  Using the hard register
later could lead to spill failures, or to attempts to keep the register
live across calls.

>> E.g. for:
>> 
>>   int8_t foo(int8_t x) { return x >> 1; }
>> 
>> x would have a DECL_RTL of (subreg:QI (reg:SI x) 0), the parameter
>> assignment would be expanded as:
>> 
>>   (set (reg:SI x) (reg:SI x0))
>> 
>> the shift would be expanded as:
>> 
>>   (set (reg:SI x) (zero_extend:SI (subreg:QI (reg:SI x) 0)))
>>   (set (reg:SI x) (ashiftrt:SI (reg:SI x) (const_int 1)))
>> 
>> and the return assignment would be expanded as:
>> 
>>   (set (reg:SI x0) (reg:SI x))
>> 
>> x + 1 would instead be expanded to just:
>> 
>>   (set (reg:SI x) (plus:SI (reg:SI x) (const_int 1)))
>> 
>> (without an extension).
>> 
>> I realised later though that, although reusing the DECL_RTL reg for the
>> extension has the nice RA property of avoiding multiple live values, it would
>> make it harder to combine the extension into the operation if the variable is
>> still live afterwards.  So I guess we lose something both ways.
>> 
>> Maybe we need a different approach, not based on changing
>> PROMOTE_MODE.
>> 
>> I wonder how easy it would be to do the promotion in gimple, then reuse
>> backprop to determine when a sign/zero-extension (i.e. a normal gimple cast)
>> can be converted into an “any extend”
>> (probably represented as a new ifn).
>
> Do you mean without changing the hook implementation but keeping the current 
> promotion?

Yeah, keep the hook definitions as they are now, but do the promotion
in gimple by widening types where necessary.

> I guess the problem here is that it's the inverse cases that's the problem 
> isn't it? It's not that in

[Ada] New port arm-qnx

2022-05-18 Thread Pierre-Marie de Rodat via Gcc-patches
The QNX system specs for ARM and AARCH64 are identical. It makes more
sense to have it named for the base architecture.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* Makefile.rtl: Rename system-qnx-aarch64.ads to
system-qnx-arm.ads.
(AARCH64 QNX section): Modify to handle both arm and arch64.
* tracebak.c (__QNX__): Add new __ARMEL__ section.
* sigtramp-arm-qnx.c: New file.
* libgnat/system-qnx-aarch64.ads: Renamed to ...
* libgnat/system-qnx-arm.ads: this.diff --git a/gcc/ada/Makefile.rtl b/gcc/ada/Makefile.rtl
--- a/gcc/ada/Makefile.rtl
+++ b/gcc/ada/Makefile.rtl
@@ -1493,8 +1493,8 @@ ifeq ($(strip $(filter-out arm% linux-androideabi,$(target_cpu) $(target_os))),)
   LIBRARY_VERSION := $(LIB_VERSION)
 endif
 
-# AARCH64 QNX
-ifeq ($(strip $(filter-out aarch64 %qnx,$(target_cpu) $(target_os))),)
+# ARM and AARCH64 QNX
+ifeq ($(strip $(filter-out arm aarch64 %qnx,$(target_cpu) $(target_os))),)
   LIBGNAT_TARGET_PAIRS = \
   a-intnam.ads
+
+#include "sigtramp.h"
+/* See sigtramp.h for a general explanation of functionality.  */
+
+/* --
+   -- 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.
+
+   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.  */
+
+/* -
+   -- Protypes for our internal asm stubs --
+   -
+
+   The registers are expected to be at SIGCONTEXT + 12 (reference the
+   sicontext structure in asm/sigcontext.h which describes the first
+   3 * 4byte fields.)  Even though our symbols will remain local, the
+   prototype claims "extern" and not "static" to prevent compiler complaints
+   about a symbol used but never defined.  */
+
+/* sigtramp stub providing unwind info for common registers.  */
+
+extern void __gnat_sigtramp_common
+  (int signo, void *siginfo, void *sigcontext,
+   __sigtramphandler_t * handler);
+
+void __gnat_sigtramp (int signo, void *si, void *sc,
+  __sigtramphandler_t * handler)
+ __attribute__((optimize(2)));
+
+void __gnat_sigtramp (int signo, void *si, void *ucontext,
+  __sigtramphandler_t * handler)
+{
+  struct sigcontext *mcontext = &((ucontext_t *) ucontext)->uc_mcontext;
+
+  __gnat_sigtramp_common (signo, si, mcontext, handler);
+}
+
+/* asm string construction helpers.  */
+
+#define STR(TEXT) #TEXT
+/* stringify expanded TEXT, surrounding it with double quotes.  */
+
+#define S(E) STR(E)
+/* stringify E, which will resolve as text but may contain macros
+   still to be expanded.  */
+
+/* asm (TEXT) outputs TEXT. These facilitate the output of
+   multiline contents:  */
+#define TAB(S) "\t" S
+#define CR(S)  S "\n"
+
+#undef TCR
+#define TCR(S) TAB(CR(S))
+
+/* Trampoline body block
+   -  */
+
+#define SIGTRAMP_BODY \
+CR("") \
+TCR("# Allocate frame and also save r2 which is the argument register") \
+TCR("# containing the sigcontext, so that we can restore it during") \
+TCR("# unwinding and thereby load the rest of the desired context.") \
+TCR("stmfd	sp!, {r2, r3, lr}") \
+TCR("# The unwinder undo's these operations in reverse order so starting") \
+TCR("# from bottom, restore r2 from the current vsp location, move r2 into") \
+TCR("# the vsp, add 12 bytes to get the start of the register save area") \
+TCR("# then restore the 15 general purpose registers of the frame which") \
+TCR("# raised the signal.") \
+TCR(".save {r0-r15}") \
+TCR(".pad #12") \
+TCR(".movsp r2") \
+TCR(".save {r2}") \
+TCR("# Call the real handler. The signo, siginfo and sigcontext") \
+TCR("# arguments are the same as those we received in r0, r1 and r2.") \
+TCR("blx	r3") \
+TCR("# Restore our callee-saved items, release our frame and return") \
+TCR("# (should never get here!).") \
+TCR("ldmfd	sp, {r2, r3, pc}")
+
+/* Symbol definition block
+   ---  */
+
+#define SIGTRAMP_START(SYM) \
+CR("# " S(SYM) " unwind trampoline") \
+TCR(".type " S(SYM) ", %function") \
+CR("") \
+CR(S(SYM) ":") \
+TCR(".fnstart")
+
+/* Symbol termination block
+     */
+
+#define SIGTRAMP_END(SYM) \
+CR(".fnend") \
+TCR(".size " S(SYM) ", .-" S(SYM))
+
+/*
+  -- And now, the real code --
+   */
+
+/* Text section start.  The compiler isn't aware of that switch.  */
+
+asm (".text\n"
+ TCR(".align 2"));
+
+/* sigtramp stub for common registers.  */
+
+#define TRAMP_COMMON __gnat_sigtramp_common
+
+asm (SIGTRAMP_START(TRAMP_COMMON));
+asm (SIGTRAMP_BODY);
+asm (SIGTRAMP_END(TRAMP_COMMON));


diff --git a/gcc/ada/tracebak.c b/gcc/ada/tracebak.c
--- a/gcc/ada/

[Ada] Small performance tweak in recent change

2022-05-18 Thread Pierre-Marie de Rodat via Gcc-patches
This avoids a useless walk of the prefix chain in instances.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* sem_ch8.adb (Analyze_Subprogram_Renaming): Move final test on
In_Instance to outer condition.diff --git a/gcc/ada/sem_ch8.adb b/gcc/ada/sem_ch8.adb
--- a/gcc/ada/sem_ch8.adb
+++ b/gcc/ada/sem_ch8.adb
@@ -3975,7 +3975,7 @@ package body Sem_Ch8 is
  --  normally illegal renamings can be constructed when expanding
  --  instantiations.
 
- elsif Nkind (Nam) = N_Expanded_Name then
+ elsif Nkind (Nam) = N_Expanded_Name and then not In_Instance then
 declare
function Ult_Expanded_Prefix (N : Node_Id) return Node_Id is
  (if Nkind (N) /= N_Expanded_Name
@@ -3985,7 +3985,6 @@ package body Sem_Ch8 is
 
 begin
if Chars (Entity (Ult_Expanded_Prefix (Nam))) = Chars (New_S)
- and then not In_Instance
then
   Error_Msg_Sloc := Sloc (N);
   Error_Msg_NE




[Ada] Ada.Numerics.Aux.*: Mention more Intrinsic and less C Math Library

2022-05-18 Thread Pierre-Marie de Rodat via Gcc-patches
Since we import the elemental math functions as intrinsics, it's not
accurate to state we're drawing them in from the C math library.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* libgnat/a-nagefl.ads: Replace mentions of C/unix math library
with intrinsics.
* libgnat/a-nallfl.ads: Likewise.  State compatibility
requirements.
* libgnat/a-nalofl.ads: Likewise.
* libgnat/a-nuaufl.ads: Likewise.diff --git a/gcc/ada/libgnat/a-nagefl.ads b/gcc/ada/libgnat/a-nagefl.ads
--- a/gcc/ada/libgnat/a-nagefl.ads
+++ b/gcc/ada/libgnat/a-nagefl.ads
@@ -31,10 +31,10 @@
 --
 
 --  This package provides the basic computational interface for the generic
---  elementary functions. The C library version interfaces with the routines
---  in the C mathematical library.
+--  elementary functions.
 
---  This version here is for use with normal Unix math functions.
+--  This version here delegates to interfaces that typically import as
+--  intrinsics the expected math functions.
 
 with Ada.Numerics.Aux_Long_Long_Float;
 with Ada.Numerics.Aux_Long_Float;


diff --git a/gcc/ada/libgnat/a-nallfl.ads b/gcc/ada/libgnat/a-nallfl.ads
--- a/gcc/ada/libgnat/a-nallfl.ads
+++ b/gcc/ada/libgnat/a-nallfl.ads
@@ -5,7 +5,7 @@
 -- A D A . N U M E R I C S . A U X . L O N G _ L O N G _ F L O A T  --
 --  --
 -- S p e c  --
---  (C Math Library Version, Long Long Float)   --
+--(Instrinsic Version, Long Long Float) --
 --  --
 --  Copyright (C) 1992-2022, Free Software Foundation, Inc. --
 --  --
@@ -30,9 +30,12 @@
 --  --
 --
 
---  This package provides the basic computational interface for the generic
---  elementary functions. The C library version interfaces with the routines
---  in the C mathematical library, and is thus quite portable.
+--  This package provides the basic computational interface for the
+--  generic elementary functions. With the intrinsic version, the
+--  compiler can use its knowledge of the functions to select the most
+--  suitable implementation. It is thus quite portable. These
+--  interfaces are suitable for cases in which Long Long Float and C's
+--  long double share the same representation.
 
 with Ada.Numerics.Aux_Linker_Options;
 pragma Warnings (Off, Ada.Numerics.Aux_Linker_Options);
@@ -42,7 +45,7 @@ package Ada.Numerics.Aux_Long_Long_Float is
 
subtype T is Long_Long_Float;
 
-   --  We import these functions directly from C. Note that we label them
+   --  We import these functions as intrinsics. Note that we label them
--  all as pure functions, because indeed all of them are in fact pure.
 
function Sin (X : T) return T with


diff --git a/gcc/ada/libgnat/a-nalofl.ads b/gcc/ada/libgnat/a-nalofl.ads
--- a/gcc/ada/libgnat/a-nalofl.ads
+++ b/gcc/ada/libgnat/a-nalofl.ads
@@ -5,7 +5,7 @@
 --  A D A . N U M E R I C S . A U X _ L O N G _ F L O A T   --
 --  --
 -- S p e c  --
--- (C Math Library Version, Long Float) --
+--   (Intrinsic Version, Long Float)--
 --  --
 --  Copyright (C) 1992-2022, Free Software Foundation, Inc. --
 --  --
@@ -30,9 +30,12 @@
 --  --
 --
 
---  This package provides the basic computational interface for the generic
---  elementary functions. The C library version interfaces with the routines
---  in the C mathematical library, and is thus quite portable.
+--  This package provides the basic computational interface for the
+--  generic elementary functions. With the intrinsic version, the
+--  compiler can use its knowledge of the functions to select the most
+--  suitable implementation. It is thus quite portable. These
+--  interfaces are suitable for cases in which Long Float and C's
+--  double share the same representation.
 
 with Ada.Numerics.Aux_Linker_Options;
 pragma Warnings (Off, Ada.Numerics.Aux_Linker_Options);
@@ -42,7 +45,7 @@ package Ada.Numerics.Aux_Long_Float is
 
subtype T is L

[Ada] Fix incorrect freezing with generic child unit

2022-05-18 Thread Pierre-Marie de Rodat via Gcc-patches
The Analyze_Associations.Check_Generic_Parent function was using an
incorrect node as the instanciation node for the actual, possibly
leading to incorrect freeze node being created (and later crashing in
gigi). Using Get_Unit_Instantiation_Node fixes the issue.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* sem_ch12.adb (Check_Generic_Parent): Use
Get_Unit_Instantiation_Node instead of Next.diff --git a/gcc/ada/sem_ch12.adb b/gcc/ada/sem_ch12.adb
--- a/gcc/ada/sem_ch12.adb
+++ b/gcc/ada/sem_ch12.adb
@@ -1164,7 +1164,7 @@ package body Sem_Ch12 is
   function Matching_Actual
 (F   : Entity_Id;
  A_F : Entity_Id) return Node_Id;
-  --  Find actual that corresponds to a given a formal parameter. If the
+  --  Find actual that corresponds to a given formal parameter. If the
   --  actuals are positional, return the next one, if any. If the actuals
   --  are named, scan the parameter associations to find the right one.
   --  A_F is the corresponding entity in the analyzed generic, which is
@@ -2063,7 +2063,7 @@ package body Sem_Ch12 is
 
 procedure Check_Generic_Parent is
Inst : constant Node_Id :=
-Next (Unit_Declaration_Node (Actual));
+Get_Unit_Instantiation_Node (Actual);
Par  : Entity_Id;
 
 begin




[Ada] Freezing too strict in instances

2022-05-18 Thread Pierre-Marie de Rodat via Gcc-patches
Should_Freeze_Type is relaxed to only take the relevant case into
account (entities denoted by generic actual parameters as per
13.14(5/3), as well as profile of any subprograms named as per
13.14(10.2/4)), instead of being overly conservative wrt instances and
as a result, wrongly rejecting some legal code.

In practice this means we only need to worry about profile of
subprograms named as part of instances.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* freeze.adb (Should_Freeze_Type): Fix handling of freezing in
instances.diff --git a/gcc/ada/freeze.adb b/gcc/ada/freeze.adb
--- a/gcc/ada/freeze.adb
+++ b/gcc/ada/freeze.adb
@@ -184,9 +184,11 @@ package body Freeze is
--  the designated type. Otherwise freezing the access type does not freeze
--  the designated type.
 
-   function Should_Freeze_Type (Typ : Entity_Id; E : Entity_Id) return Boolean;
-   --  If Typ is in the current scope or in an instantiation, then return True.
-   --  ???Expression functions (represented by E) shouldn't freeze types in
+   function Should_Freeze_Type
+ (Typ : Entity_Id; E : Entity_Id; N : Node_Id) return Boolean;
+   --  If Typ is in the current scope, then return True.
+   --  N is a node whose source location corresponds to the freeze point.
+   --  ??? Expression functions (represented by E) shouldn't freeze types in
--  general, but our current expansion and freezing model requires an early
--  freezing when the dispatch table is needed or when building an aggregate
--  with a subtype of Typ, so return True also in this case.
@@ -198,7 +200,7 @@ package body Freeze is

 
function Should_Freeze_Type
- (Typ : Entity_Id; E : Entity_Id) return Boolean
+ (Typ : Entity_Id; E : Entity_Id; N : Node_Id) return Boolean
is
   function Is_Dispatching_Call_Or_Aggregate
 (N : Node_Id) return Traverse_Result;
@@ -244,7 +246,8 @@ package body Freeze is
 
begin
   return Within_Scope (Typ, Current_Scope)
-or else In_Instance
+or else (Nkind (N) = N_Subprogram_Renaming_Declaration
+ and then Present (Corresponding_Formal_Spec (N)))
 or else (Present (Decl)
  and then Nkind (Decl) = N_Expression_Function
  and then Need_Dispatch_Table (Expression (Decl)) = Abandon);
@@ -4606,7 +4609,7 @@ package body Freeze is
 end if;
 
 if not From_Limited_With (F_Type)
-  and then Should_Freeze_Type (F_Type, E)
+  and then Should_Freeze_Type (F_Type, E, N)
 then
Freeze_And_Append (F_Type, N, Result);
 end if;
@@ -4786,7 +4789,7 @@ package body Freeze is
Set_Etype (E, R_Type);
 end if;
 
-if Should_Freeze_Type (R_Type, E) then
+if Should_Freeze_Type (R_Type, E, N) then
Freeze_And_Append (R_Type, N, Result);
 end if;
 




[Ada] Fast implementation of floating-point mathematical functions

2022-05-18 Thread Pierre-Marie de Rodat via Gcc-patches
This adds a package renaming unit to the GNAT hierarchy so as to expose
the underlying implementation of floating-point mathematical functions,
thus also making it possible to use their vector implementation, if any.

The change also contains a small improvement to the Hide_Public_Entities
mechanism in Sem_Ch7 that makes it possible to clear the Is_Public flag
within instances of generic packages that do not have a body.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* Makefile.rtl (GNATRTL_NONTASKING_OBJS): Add g-gfmafu$(objext).
(SIMD_PATH_TARGET_PAIRS): New variable.
(TRASYM_DWARF_COMMON_OBJS): Minor tweak.
(x86-64/Linux): Use SIMD_PATH_TARGET_PAIRS.
(x32/Linux): Likewise.
* doc/gnat_rm/the_gnat_library.rst (Generic_Fast_Math_Functions):
New entry.
* gnat_rm.texi: Regenerate.
* impunit.adb (Non_Imp_File_Names_95): Add g-gfmafu.
* sem_ch7.adb (Has_Referencer): Do not set In_Nested_Instance for
instances of generic packages that do not have a body.
* libgnat/a-nalofl__simd.ads: New SIMD-enabled version.
* libgnat/a-nuaufl__simd.ads: Likewise.
* libgnat/g-gfmafu.ads: New package renaming unit.

patch.diff.gz
Description: application/gzip


[Ada] Prevent overflow in computation of aggregate size

2022-05-18 Thread Pierre-Marie de Rodat via Gcc-patches
When computing size of a static aggregate to decide if it should be
transformed into assignments and loops we could have an overflow check.
This is mostly harmless, because colossal aggregates will likely crash
the application anyway, no matter how we transform them.

This was not detected because compiler was built with -gnatg switch that
suppresses overflow checks (they are only enabled by an explicit -gnato
switch).

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* exp_aggr.adb (Component_Count): Calculate size as an Uint and
only then check if it is in the range of Int, as otherwise the
multiplication of Int values can overflow.diff --git a/gcc/ada/exp_aggr.adb b/gcc/ada/exp_aggr.adb
--- a/gcc/ada/exp_aggr.adb
+++ b/gcc/ada/exp_aggr.adb
@@ -661,10 +661,10 @@ package body Exp_Aggr is
 
   declare
  UI : constant Uint :=
-Expr_Value (Hi) - Expr_Value (Lo) + 1;
+(Expr_Value (Hi) - Expr_Value (Lo) + 1) * Siz;
   begin
  if UI_Is_In_Int_Range (UI) then
-return Siz * UI_To_Int (UI);
+return UI_To_Int (UI);
  else
 return Int'Last;
  end if;




[Ada] Overriding error on type derived from discriminated untagged private type

2022-05-18 Thread Pierre-Marie de Rodat via Gcc-patches
When a derived type DT has an untagged private parent type PT with a
discriminant, where the full type of PT is tagged, and DT inherits a
function F with an anonymous access result that designates the type, the
compiler wrongly reports an error saying that DT must be declared
abstract or F overridden. A test is added to exclude checking the
abstract overriding rules that should only apply to inherited
subprograms of tagged derived types.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* sem_ch3.adb (Check_Abstract_Overriding): If the type is
derived from an untagged type, then don't perform any of the
abstract overriding error checks.diff --git a/gcc/ada/sem_ch3.adb b/gcc/ada/sem_ch3.adb
--- a/gcc/ada/sem_ch3.adb
+++ b/gcc/ada/sem_ch3.adb
@@ -11047,6 +11047,14 @@ package body Sem_Ch3 is
  Subp := Node (Elmt);
  Alias_Subp := Alias (Subp);
 
+ --  If the parent type is untagged, then no overriding error checks
+ --  are needed (such as in the case of an implicit full type for
+ --  a derived type whose parent is an untagged private type with
+ --  a tagged full type).
+
+ if not Is_Tagged_Type (Etype (T)) then
+null;
+
  --  Inherited subprograms are identified by the fact that they do not
  --  come from source, and the associated source location is the
  --  location of the first subtype of the derived type.
@@ -11065,7 +11073,7 @@ package body Sem_Ch3 is
  --  overriding in Ada 2005, but wrappers need to be built for them
  --  (see exp_ch3, Build_Controlling_Function_Wrappers).
 
- if Is_Null_Extension (T)
+ elsif Is_Null_Extension (T)
and then Has_Controlling_Result (Subp)
and then Ada_Version >= Ada_2005
and then Present (Alias_Subp)




[Ada] Fix internal error on subprogram instantiation

2022-05-18 Thread Pierre-Marie de Rodat via Gcc-patches
The compiler builds renamings for actuals of formal objects for debugging
purposes in this case, but it must not generate them for temporaries.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* exp_dbug.ads (Build_Subprogram_Instance_Renamings): Fix typo.
* exp_dbug.adb (Build_Subprogram_Instance_Renamings): Build the
renaming only for actuals of formal objects.diff --git a/gcc/ada/exp_dbug.adb b/gcc/ada/exp_dbug.adb
--- a/gcc/ada/exp_dbug.adb
+++ b/gcc/ada/exp_dbug.adb
@@ -1028,6 +1028,7 @@ package body Exp_Dbug is
   E := First_Entity (Wrapper);
   while Present (E) loop
  if Nkind (Parent (E)) = N_Object_Declaration
+   and then Present (Corresponding_Generic_Association (Parent (E)))
and then Is_Elementary_Type (Etype (E))
  then
 Loc := Sloc (Expression (Parent (E)));


diff --git a/gcc/ada/exp_dbug.ads b/gcc/ada/exp_dbug.ads
--- a/gcc/ada/exp_dbug.ads
+++ b/gcc/ada/exp_dbug.ads
@@ -1444,7 +1444,7 @@ package Exp_Dbug is
--  placed within the wrapper package of the instance, and the entity in
--  these declarations is encoded in a complex way that GDB does not handle
--  well. These new renaming declarations appear within the body of the
-   --  subprogram, and are redundant from a visibility point of view, but They
+   --  subprogram, and are redundant from a visibility point of view, but they
--  should have no measurable performance impact, and require no special
--  decoding in the debugger.
 




[Ada] Rework optimization skipping pragma check in object declaration

2022-05-18 Thread Pierre-Marie de Rodat via Gcc-patches
When an object declaration is initialized with a type conversion:

 Var : Typ := Typ (Value);

we skip the check for Typ's predicate as it is already checked
during the type conversion.

This is not correct when Var's subtype and the target subtype of the
conversion do not statically match:

 Var : Typ := OtherTyp (Value);

In such case, we can't skip the check of Typ's predicate.

Fix minor typos in comment.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* sem_ch3.adb (Analyze_Object_Declaration): Skip predicate check
for type conversion if object's subtype and expression's subtype
statically match.
* exp_prag.adb (Expand_Pragma_Check): Typo fix in comment.diff --git a/gcc/ada/exp_prag.adb b/gcc/ada/exp_prag.adb
--- a/gcc/ada/exp_prag.adb
+++ b/gcc/ada/exp_prag.adb
@@ -285,7 +285,7 @@ package body Exp_Prag is
   --  expression is not usually the best choice here, because it points to
   --  the location of the topmost tree node, which may be an operator in
   --  the middle of the source text of the expression. For example, it gets
-  --  located on the last AND keyword in a chain of boolean expressiond
+  --  located on the last AND keyword in a chain of boolean expressions
   --  AND'ed together. It is best to put the message on the first character
   --  of the condition, which is the effect of the First_Node call here.
   --  This source location is used to build the default exception message,


diff --git a/gcc/ada/sem_ch3.adb b/gcc/ada/sem_ch3.adb
--- a/gcc/ada/sem_ch3.adb
+++ b/gcc/ada/sem_ch3.adb
@@ -4572,11 +4572,15 @@ package body Sem_Ch3 is
 null;
 
  --  Do not generate a predicate check if the initialization expression
- --  is a type conversion because the conversion has been subjected to
- --  the same check. This is a small optimization which avoid redundant
+ --  is a type conversion whose target subtype statically matches the
+ --  object's subtype because the conversion has been subjected to the
+ --  same check. This is a small optimization which avoids redundant
  --  checks.
 
- elsif Present (E) and then Nkind (E) = N_Type_Conversion then
+ elsif Present (E)
+   and then Nkind (E) in N_Type_Conversion
+   and then Subtypes_Statically_Match (Etype (Subtype_Mark (E)), T)
+ then
 null;
 
  else




[Ada] Spurious error on freezing of tagged types in SPARK

2022-05-18 Thread Pierre-Marie de Rodat via Gcc-patches
SPARK RM 7.7(8) mandates that the freezing point of a tagged type must
occur within the so-called early call region of all its primitives.
This check may lead to spurious errors due to generated constructs being
considered in the search for the start of the early call region.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* sem_elab.adb (Is_Suitable_Construct): Fix for generated
constructs.diff --git a/gcc/ada/sem_elab.adb b/gcc/ada/sem_elab.adb
--- a/gcc/ada/sem_elab.adb
+++ b/gcc/ada/sem_elab.adb
@@ -7346,7 +7346,7 @@ package body Sem_Elab is
 --  is a byproduct of the parser. Such a null statement should be
 --  excluded from the early call region because it carries the
 --  source location of the "end" keyword, and may lead to confusing
---  diagnistics.
+--  diagnostics.
 
 if Nkind (N) = N_Null_Statement
   and then not Comes_From_Source (N)
@@ -7354,6 +7354,16 @@ package body Sem_Elab is
   and then Nkind (Context) = N_Handled_Sequence_Of_Statements
 then
return False;
+
+--  Similarly, internally-generated objects and types may have
+--  out-of-order source locations that confuse diagnostics, e.g.
+--  source locations in the body for objects/types generated in
+--  the spec.
+
+elsif Nkind (N) in N_Full_Type_Declaration | N_Object_Declaration
+  and then not Comes_From_Source (N)
+then
+   return False;
 end if;
 
 --  Otherwise only constructs which correspond to pure Ada




[Ada] Fix problematic underflow for Float_Type'Value

2022-05-18 Thread Pierre-Marie de Rodat via Gcc-patches
We need a couple of guards for boundary conditions in the support code.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* libgnat/s-dourea.adb ("/"): Add guard for zero and infinite
divisor.
* libgnat/s-valuer.adb (Scan_Raw_Real): Add guard for very large
exponent values.diff --git a/gcc/ada/libgnat/s-dourea.adb b/gcc/ada/libgnat/s-dourea.adb
--- a/gcc/ada/libgnat/s-dourea.adb
+++ b/gcc/ada/libgnat/s-dourea.adb
@@ -178,6 +178,12 @@ package body System.Double_Real is
   P, R   : Double_T;
 
begin
+  if Is_Infinity (B) or else Is_Zero (B) then
+ return (A.Hi / B, 0.0);
+  end if;
+  pragma Annotate (CodePeer, Intentional, "test always false",
+   "code deals with infinity");
+
   Q1 := A.Hi / B;
 
   --  Compute R = A - B * Q1
@@ -196,6 +202,12 @@ package body System.Double_Real is
   R, S   : Double_T;
 
begin
+  if Is_Infinity (B.Hi) or else Is_Zero (B.Hi) then
+ return (A.Hi / B.Hi, 0.0);
+  end if;
+  pragma Annotate (CodePeer, Intentional, "test always false",
+   "code deals with infinity");
+
   Q1 := A.Hi / B.Hi;
   R := A - B * Q1;
 


diff --git a/gcc/ada/libgnat/s-valuer.adb b/gcc/ada/libgnat/s-valuer.adb
--- a/gcc/ada/libgnat/s-valuer.adb
+++ b/gcc/ada/libgnat/s-valuer.adb
@@ -645,7 +645,14 @@ package body System.Value_R is
 
   Ptr.all := Index;
   Scan_Exponent (Str, Ptr, Max, Expon, Real => True);
-  Scale := Scale + Expon;
+
+  --  Handle very large exponents like Scan_Exponent
+
+  if Expon < Integer'First / 10 or else Expon > Integer'Last / 10 then
+ Scale := Expon;
+  else
+ Scale := Scale + Expon;
+  end if;
 
   --  Here is where we check for a bad based number
 




[Ada] Secondary stack and a-tags

2022-05-18 Thread Pierre-Marie de Rodat via Gcc-patches
The simple use of Ada.Tags triggers a dependency on the secondary stack
mechanism, which is unwanted on small embedded targets. To avoid this
dependency, we special case a-tags.ali in ALI.Scan_ALI to not set
Sec_Stack_Used. If some other code calls one of the functions returning
a string, this code will also be marked as requiring the secondary
stack. We also remove the need to import and set __gnat_binder_ss_count
in this case by ensuring this variable defaults to 0.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* ali.adb (Scan_ALI): Special case a-tags.ali when setting
Sec_Stack_Used.
* bindgen.adb (Gen_Adainit): Simplify handling of secondary
stack related code, and only import __gnat_binder_ss_count when
needed.
* libgnat/s-secsta.adb (Binder_SS_Count): Default initialize to
0.diff --git a/gcc/ada/ali.adb b/gcc/ada/ali.adb
--- a/gcc/ada/ali.adb
+++ b/gcc/ada/ali.adb
@@ -2079,7 +2079,15 @@ package body ALI is
--  Processing for SS
 
elsif C = 'S' then
-  Opt.Sec_Stack_Used := True;
+  --  Special case: a-tags.ali by itself should not set
+  --  Sec_Stack_Used, only if other code uses the secondary
+  --  stack should we set this flag. This ensures that we do
+  --  not bring the secondary stack unnecessarily when using
+  --  Ada.Tags and not actually using the secondary stack.
+
+  if Get_Name_String (F) /= "a-tags.ali" then
+ Opt.Sec_Stack_Used := True;
+  end if;
 
--  Invalid switch starting with S
 


diff --git a/gcc/ada/bindgen.adb b/gcc/ada/bindgen.adb
--- a/gcc/ada/bindgen.adb
+++ b/gcc/ada/bindgen.adb
@@ -80,12 +80,6 @@ package body Bindgen is
--  domains just before calling the main procedure from the environment
--  task.
 
-   System_Secondary_Stack_Package_In_Closure : Boolean := False;
-   --  Flag indicating whether the unit System.Secondary_Stack is in the
-   --  closure of the partition. This is set by Resolve_Binder_Options, and
-   --  is used to initialize the package in cases where the run-time brings
-   --  in package but the secondary stack is not used.
-
System_Tasking_Restricted_Stages_Used : Boolean := False;
--  Flag indicating whether the unit System.Tasking.Restricted.Stages is in
--  the closure of the partition. This is set by Resolve_Binder_Options,
@@ -612,33 +606,27 @@ package body Bindgen is
  """__gnat_initialize_stack_limit"");");
  end if;
 
- if System_Secondary_Stack_Package_In_Closure then
---  System.Secondary_Stack is in the closure of the program
---  because the program uses the secondary stack or the restricted
---  run-time is unconditionally calling SS_Init. In both cases,
---  SS_Init needs to know the number of secondary stacks created by
---  the binder.
-
+ if Num_Sec_Stacks > 0 then
 WBI ("  Binder_Sec_Stacks_Count : Natural;");
 WBI ("  pragma Import (Ada, Binder_Sec_Stacks_Count, " &
  """__gnat_binder_ss_count"");");
 WBI ("");
+ end if;
 
---  Import secondary stack pool variables if the secondary stack
---  used. They are not referenced otherwise.
+ --  Import secondary stack pool variables if the secondary stack is
+ --  used. They are not referenced otherwise.
 
-if Sec_Stack_Used then
-   WBI ("  Default_Secondary_Stack_Size : " &
-"System.Parameters.Size_Type;");
-   WBI ("  pragma Import (C, Default_Secondary_Stack_Size, " &
-"""__gnat_default_ss_size"");");
+ if Sec_Stack_Used then
+WBI ("  Default_Secondary_Stack_Size : " &
+ "System.Parameters.Size_Type;");
+WBI ("  pragma Import (C, Default_Secondary_Stack_Size, " &
+ """__gnat_default_ss_size"");");
 
-   WBI ("  Default_Sized_SS_Pool : System.Address;");
-   WBI ("  pragma Import (Ada, Default_Sized_SS_Pool, " &
-"""__gnat_default_ss_pool"");");
+WBI ("  Default_Sized_SS_Pool : System.Address;");
+WBI ("  pragma Import (Ada, Default_Sized_SS_Pool, " &
+ """__gnat_default_ss_pool"");");
 
-   WBI ("");
-end if;
+WBI ("");
  end if;
 
  WBI ("   begin");
@@ -686,46 +674,36 @@ package body Bindgen is
  --  Generate the default-sized secondary stack pool if the secondary
  --  stack is used by the program.
 
- if System_Secondary_Stack_Package_In_Closure then
-if Sec_Stack_Used then
-   --  Elaborate the body of the binder to initialize the default-
-

[Ada] Fix the parsing for delta aggregate

2022-05-18 Thread Pierre-Marie de Rodat via Gcc-patches
In Ada 2022, delta aggregate must use parentheses not square brackets
except array delta aggregates.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* gen_il-gen-gen_nodes.adb (Gen_IL.Gen.Gen_Nodes): Add
Is_Homogeneous_Aggregate field for N_Delta_Aggregate nodes.
* par-ch4.adb (P_Aggregate_Or_Paren_Expr): Minor reformatting.
* sem_aggr.adb (Resolve_Delta_Aggregate): Reject square brackets
for record aggregate.
(Resolve_Record_Aggregate): Uniformise error message.diff --git a/gcc/ada/gen_il-gen-gen_nodes.adb b/gcc/ada/gen_il-gen-gen_nodes.adb
--- a/gcc/ada/gen_il-gen-gen_nodes.adb
+++ b/gcc/ada/gen_il-gen-gen_nodes.adb
@@ -509,6 +509,7 @@ begin -- Gen_IL.Gen.Gen_Nodes
 
Cc (N_Delta_Aggregate, N_Subexpr,
(Sy (Expression, Node_Id, Default_Empty),
+Sy (Is_Homogeneous_Aggregate, Flag),
 Sy (Component_Associations, List_Id, Default_No_List)));
 
Cc (N_Extension_Aggregate, N_Subexpr,


diff --git a/gcc/ada/par-ch4.adb b/gcc/ada/par-ch4.adb
--- a/gcc/ada/par-ch4.adb
+++ b/gcc/ada/par-ch4.adb
@@ -1682,6 +1682,7 @@ package body Ch4 is
 
   case Start_Token is
  when Tok_Left_Bracket =>
+
 Set_Component_Associations (Aggregate_Node, Assoc_List);
 Set_Is_Homogeneous_Aggregate (Aggregate_Node);
 T_Right_Bracket;


diff --git a/gcc/ada/sem_aggr.adb b/gcc/ada/sem_aggr.adb
--- a/gcc/ada/sem_aggr.adb
+++ b/gcc/ada/sem_aggr.adb
@@ -3291,6 +3291,15 @@ package body Sem_Aggr is
   if Is_Array_Type (Typ) then
  Resolve_Delta_Array_Aggregate (N, Typ);
   else
+
+ --  Delta aggregates for record types must use parentheses,
+ --  not square brackets.
+
+ if Is_Homogeneous_Aggregate (N) then
+Error_Msg_N
+  ("delta aggregates for record types must use (), not '[']", N);
+ end if;
+
  Resolve_Delta_Record_Aggregate (N, Typ);
   end if;
 
@@ -4916,7 +4925,7 @@ package body Sem_Aggr is
   if Nkind (N) = N_Aggregate
 and then Is_Homogeneous_Aggregate (N)
   then
- Error_Msg_N ("record aggregate must use () and not '[']", N);
+ Error_Msg_N ("record aggregate must use (), not '[']", N);
  return;
   end if;
 




[Ada] Errors missed on ACATS test B650007

2022-05-18 Thread Pierre-Marie de Rodat via Gcc-patches
This ACATS test shows that we need to call Is_Immutably_Limited_Type
in Analyze_Function_Return and also that we have a latent bug in
Is_Immutably_Limited_Type which shouldn't look through private types.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* sem_aux.adb (Is_Immutably_Limited_Type): Do not look through
private types as per RM 7.5(8.1).
* sem_ch6.adb (Analyze_Function_Return): Use
Is_Immutably_Limited_Type as per RM 6.5(5.10).diff --git a/gcc/ada/sem_aux.adb b/gcc/ada/sem_aux.adb
--- a/gcc/ada/sem_aux.adb
+++ b/gcc/ada/sem_aux.adb
@@ -1059,15 +1059,7 @@ package body Sem_Aux is
 end if;
 
  else
-declare
-   Utyp : constant Entity_Id := Underlying_Type (Btype);
-begin
-   if No (Utyp) then
-  return False;
-   else
-  return Is_Immutably_Limited_Type (Utyp);
-   end if;
-end;
+return False;
  end if;
 
   elsif Is_Concurrent_Type (Btype) then


diff --git a/gcc/ada/sem_ch6.adb b/gcc/ada/sem_ch6.adb
--- a/gcc/ada/sem_ch6.adb
+++ b/gcc/ada/sem_ch6.adb
@@ -1566,17 +1566,18 @@ package body Sem_Ch6 is
 
 --  Check RM 6.5 (5.9/3)
 
-if Has_Aliased then
+if Has_Aliased and then not Is_Immutably_Limited_Type (R_Type) then
if Ada_Version < Ada_2012
  and then Warn_On_Ada_2012_Compatibility
then
   Error_Msg_N
-("ALIASED only allowed for limited return objects "
- & "in Ada 2012?y?", N);
+("ALIASED only allowed for immutably limited return " &
+ "objects in Ada 2012?y?", N);
 
-   elsif not Is_Limited_View (R_Type) then
+   else
   Error_Msg_N
-("ALIASED only allowed for limited return objects", N);
+("ALIASED only allowed for immutably limited return " &
+ "objects", N);
end if;
 end if;
 




[Ada] Fix proof of runtime units

2022-05-18 Thread Pierre-Marie de Rodat via Gcc-patches
Update to latest version of Why3 caused some proof regressions.
Fix the proof by changing ghost code.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* libgnat/s-imagei.adb (Set_Digits): Add assertion.
* libgnat/s-imgboo.adb (Image_Boolean): Add assertions.
* libgnat/s-valueu.adb (Scan_Raw_Unsigned): Add assertion.diff --git a/gcc/ada/libgnat/s-imagei.adb b/gcc/ada/libgnat/s-imagei.adb
--- a/gcc/ada/libgnat/s-imagei.adb
+++ b/gcc/ada/libgnat/s-imagei.adb
@@ -388,6 +388,8 @@ package body System.Image_I is
  Prove_Uns_Of_Non_Positive_Value;
  pragma Assert (Uns_Value rem 10 = Uns_Of_Non_Positive (Value rem 10));
  pragma Assert (Uns_Value rem 10 = Uns (-(Value rem 10)));
+ pragma Assert
+   (Uns_Value = From_Big (Big (Uns_T) / Big_10 ** (Nb_Digits - J)));
 
  Prev_Value := Uns_Value;
  Prev_S := S;


diff --git a/gcc/ada/libgnat/s-imgboo.adb b/gcc/ada/libgnat/s-imgboo.adb
--- a/gcc/ada/libgnat/s-imgboo.adb
+++ b/gcc/ada/libgnat/s-imgboo.adb
@@ -37,6 +37,8 @@ pragma Assertion_Policy (Ghost  => Ignore,
  Loop_Invariant => Ignore,
  Assert => Ignore);
 
+with System.Val_Util;
+
 package body System.Img_Bool
   with SPARK_Mode
 is
@@ -55,9 +57,13 @@ is
   if V then
  S (1 .. 4) := "TRUE";
  P := 4;
+ pragma Assert
+   (System.Val_Util.First_Non_Space_Ghost (S, S'First, S'Last) = 1);
   else
  S (1 .. 5) := "FALSE";
  P := 5;
+ pragma Assert
+   (System.Val_Util.First_Non_Space_Ghost (S, S'First, S'Last) = 1);
   end if;
end Image_Boolean;
 


diff --git a/gcc/ada/libgnat/s-valueu.adb b/gcc/ada/libgnat/s-valueu.adb
--- a/gcc/ada/libgnat/s-valueu.adb
+++ b/gcc/ada/libgnat/s-valueu.adb
@@ -645,6 +645,7 @@ package body System.Value_U is
 
   Scan_Exponent (Str, Ptr, Max, Expon);
 
+  pragma Assert (Ptr.all = Raw_Unsigned_Last_Ghost (Str, Ptr_Old, Max));
   pragma Assert
 (if Starts_As_Exponent_Format_Ghost (Str (First_Exp .. Max))
  then Expon = Scan_Exponent_Ghost (Str (First_Exp .. Max)));




[Ada] Crash building VSS with compiler built with assertions

2022-05-18 Thread Pierre-Marie de Rodat via Gcc-patches
When a tagged type T has aspect String_Literal, a derived type defines a
null extension T2, and the context to resolve the use of an object of
type T2 where the string literal is applicable is a class-wide type the
frontend crashes trying to evaluate if the object is a null extension.
This problem does not reproduce when the compiler is built with
assertions disabled.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* sem_ch6.adb (Find_Corresponding_Spec): Avoid calling
Is_Null_Extension with a class-wide type entity.
(Overrides_Visible_Function): Handle alias entities.
* sem_res.adb (Has_Applicable_User_Defined_Literal): Conversion
not needed if the result type of the call is class-wide or if
the result type matches the context type.
* sem_util.ads (Is_Null_Extension): Adding documentation.
(Is_Null_Extension_Of): Adding documentation.
* sem_util.adb (Is_Null_Extension): Adding assertion.
(Is_Null_Extension_Of): Adding assertions.diff --git a/gcc/ada/sem_ch6.adb b/gcc/ada/sem_ch6.adb
--- a/gcc/ada/sem_ch6.adb
+++ b/gcc/ada/sem_ch6.adb
@@ -9867,7 +9867,8 @@ package body Sem_Ch6 is
  and then Ada_Version >= Ada_2005
  and then not Comes_From_Source (E)
  and then Has_Controlling_Result (E)
- and then Is_Null_Extension (Etype (E))
+ and then (not Is_Class_Wide_Type (Etype (E))
+and then Is_Null_Extension (Etype (E)))
  and then Comes_From_Source (Spec)
then
   Set_Has_Completion (E, False);
@@ -11265,7 +11266,8 @@ package body Sem_Ch6 is
 
 function Overrides_Private_Part_Op return Boolean is
Over_Decl : constant Node_Id :=
- Unit_Declaration_Node (Overridden_Operation (S));
+ Unit_Declaration_Node
+   (Ultimate_Alias (Overridden_Operation (S)));
Subp_Decl : constant Node_Id := Unit_Declaration_Node (S);
 
 begin


diff --git a/gcc/ada/sem_res.adb b/gcc/ada/sem_res.adb
--- a/gcc/ada/sem_res.adb
+++ b/gcc/ada/sem_res.adb
@@ -559,7 +559,12 @@ package body Sem_Res is
 
  Set_Etype (Call, Etype (Callee));
 
- if Base_Type (Etype (Call)) /= Base_Type (Typ) then
+ --  Conversion not needed if the result type of the call is class-wide
+ --  or if the result type matches the context type.
+
+ if not Is_Class_Wide_Type (Typ)
+   and then Base_Type (Etype (Call)) /= Base_Type (Typ)
+ then
 --  Conversion may be needed in case of an inherited
 --  aspect of a derived type. For a null extension, we
 --  use a null extension aggregate instead because the


diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb
--- a/gcc/ada/sem_util.adb
+++ b/gcc/ada/sem_util.adb
@@ -19279,6 +19279,8 @@ package body Sem_Util is
   Type_Decl : Node_Id;
   Type_Def  : Node_Id;
begin
+  pragma Assert (not Is_Class_Wide_Type (T));
+
   if Ignore_Privacy then
  Type_Decl := Parent (Underlying_Type (Base_Type (T)));
   else
@@ -19311,7 +19313,10 @@ package body Sem_Util is
 := Underlying_Type (Base_Type (Ancestor));
   Descendant_Type : Entity_Id := Underlying_Type (Base_Type (Descendant));
begin
+  pragma Assert (not Is_Class_Wide_Type (Descendant));
+  pragma Assert (not Is_Class_Wide_Type (Ancestor));
   pragma Assert (Descendant_Type /= Ancestor_Type);
+
   while Descendant_Type /= Ancestor_Type loop
  if not Is_Null_Extension
   (Descendant_Type, Ignore_Privacy => True)


diff --git a/gcc/ada/sem_util.ads b/gcc/ada/sem_util.ads
--- a/gcc/ada/sem_util.ads
+++ b/gcc/ada/sem_util.ads
@@ -2209,12 +2209,14 @@ package Sem_Util is
--  Given a tagged type, returns True if argument is a type extension
--  that introduces no new components (discriminant or nondiscriminant).
--  Ignore_Privacy should be True for use in implementing dynamic semantics.
+   --  Cannot be called with class-wide types.
 
function Is_Null_Extension_Of
  (Descendant, Ancestor : Entity_Id) return Boolean;
--  Given two tagged types, the first a descendant of the second,
--  returns True if every component of Descendant is inherited
--  (directly or indirectly) from Ancestor. Privacy is ignored.
+   --  Cannot be called with class-wide types.
 
function Is_Null_Record_Definition (Record_Def : Node_Id) return Boolean;
--  Returns True for an N_Record_Definition node that has no user-defined




[Ada] Use specific predicate before manipulating BIP_Alloc_Form

2022-05-18 Thread Pierre-Marie de Rodat via Gcc-patches
For the sake of consistency with other similar manipulations.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* exp_ch7.adb (Build_BIP_Cleanup_Stmts): Use Needs_BIP_Alloc_Form.diff --git a/gcc/ada/exp_ch7.adb b/gcc/ada/exp_ch7.adb
--- a/gcc/ada/exp_ch7.adb
+++ b/gcc/ada/exp_ch7.adb
@@ -2850,16 +2850,14 @@ package body Exp_Ch7 is
 Left_Opnd  => New_Occurrence_Of (Fin_Mas_Id, Loc),
 Right_Opnd => Make_Null (Loc));
 
---  For constrained or tagged results escalate the condition to
+--  For unconstrained or tagged results, escalate the condition to
 --  include the allocation format. Generate:
 
 --if BIPallocform > Secondary_Stack'Pos
 --  and then BIPfinalizationmaster /= null
 --then
 
-if not Is_Constrained (Func_Typ)
-  or else Is_Tagged_Type (Func_Typ)
-then
+if Needs_BIP_Alloc_Form (Func_Id) then
declare
   Alloc : constant Entity_Id :=
 Build_In_Place_Formal (Func_Id, BIP_Alloc_Form);




[Ada] Fix Ada-QNX task priority conversion

2022-05-18 Thread Pierre-Marie de Rodat via Gcc-patches
The conversion between OS and Ada priorties should be done in the wider
Interfaces.C.int type rather than Any_Priority otherwise
Constraint_Error will be raised when coverting Any_Priority'Last to int.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* libgnarl/s-osinte__qnx.adb (To_Target_Priority): Perform
arithmetic in int.diff --git a/gcc/ada/libgnarl/s-osinte__qnx.adb b/gcc/ada/libgnarl/s-osinte__qnx.adb
--- a/gcc/ada/libgnarl/s-osinte__qnx.adb
+++ b/gcc/ada/libgnarl/s-osinte__qnx.adb
@@ -87,7 +87,7 @@ package body System.OS_Interface is
  (Prio : System.Any_Priority) return Interfaces.C.int
is
begin
-  return Interfaces.C.int (Prio + 1);
+  return Interfaces.C.int (Prio) + 1;
end To_Target_Priority;
 
-




[Ada] Improve error messages for occurrence of GNAT extensions without -gnatX

2022-05-18 Thread Pierre-Marie de Rodat via Gcc-patches
The error message issued for use of GNAT extension features without
specifying -gnatX (or pragma Extensions_Allowed) was confusing in the
presence of a pragma specifying a language version (such as "pragma
Ada_2022;"), because the pragma supersedes the switch.  The message is
improved by testing for use of such a pragma, plus use of pragma
Extensions_Allowed is now suggested, and several cases are changed to
call the common error procedure for flagging uses of extension features.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* errout.ads (Error_Msg_GNAT_Extension): Add formal Loc and
revise comment.
* errout.adb (Error_Msg_GNAT_Extension): Condition message on
the flag Ada_Version_Pragma, and add suggestion to use of pragma
Extensions_Allowed in messages.
* par-ch3.adb, par-ch5.adb, par-ch6.adb, par-ch11.adb,
par-ch12.adb: Add actual Token_Ptr on calls to
Error_Msg_GNAT_Extension.
* par-ch4.adb: Change Error_Msg to Error_Msg_GNAT_Extension for
error calls related to use of extension features.
* sem_ch13.adb: Likewise.diff --git a/gcc/ada/errout.adb b/gcc/ada/errout.adb
--- a/gcc/ada/errout.adb
+++ b/gcc/ada/errout.adb
@@ -896,12 +896,19 @@ package body Errout is
-- Error_Msg_GNAT_Extension --
--
 
-   procedure Error_Msg_GNAT_Extension (Extension : String) is
-  Loc : constant Source_Ptr := Token_Ptr;
+   procedure Error_Msg_GNAT_Extension (Extension : String; Loc : Source_Ptr) is
begin
   if not Extensions_Allowed then
- Error_Msg (Extension & " is a 'G'N'A'T specific extension", Loc);
- Error_Msg ("\unit must be compiled with -gnatX switch", Loc);
+ Error_Msg (Extension & " is a 'G'N'A'T-specific extension", Loc);
+
+ if No (Ada_Version_Pragma) then
+Error_Msg ("\unit must be compiled with -gnatX "
+   & "or use pragma Extensions_Allowed (On)", Loc);
+ else
+Error_Msg_Sloc := Sloc (Ada_Version_Pragma);
+Error_Msg ("\incompatible with Ada version set#", Loc);
+Error_Msg ("\must use pragma Extensions_Allowed (On)", Loc);
+ end if;
   end if;
end Error_Msg_GNAT_Extension;
 


diff --git a/gcc/ada/errout.ads b/gcc/ada/errout.ads
--- a/gcc/ada/errout.ads
+++ b/gcc/ada/errout.ads
@@ -943,10 +943,11 @@ package Errout is
procedure Error_Msg_Ada_2022_Feature (Feature : String; Loc : Source_Ptr);
--  Analogous to Error_Msg_Ada_2012_Feature, for Ada 2022
 
-   procedure Error_Msg_GNAT_Extension (Extension : String);
+   procedure Error_Msg_GNAT_Extension (Extension : String; Loc : Source_Ptr);
--  If not operating with extensions allowed, posts errors complaining
-   --  that Extension is only supported when the -gnatX switch is enabled,
-   --  with appropriate suggestions to fix it.
+   --  that Extension is only supported when the -gnatX switch is enabled
+   --  or pragma Extensions_Allowed (On) is used. Loc indicates the source
+   --  location of the extension construct.
 
procedure dmsg (Id : Error_Msg_Id) renames Erroutc.dmsg;
--  Debugging routine to dump an error message


diff --git a/gcc/ada/par-ch11.adb b/gcc/ada/par-ch11.adb
--- a/gcc/ada/par-ch11.adb
+++ b/gcc/ada/par-ch11.adb
@@ -234,7 +234,7 @@ package body Ch11 is
   end if;
 
   if Token = Tok_When then
- Error_Msg_GNAT_Extension ("raise when statement");
+ Error_Msg_GNAT_Extension ("raise when statement", Token_Ptr);
 
  Mutate_Nkind (Raise_Node, N_Raise_When_Statement);
 


diff --git a/gcc/ada/par-ch12.adb b/gcc/ada/par-ch12.adb
--- a/gcc/ada/par-ch12.adb
+++ b/gcc/ada/par-ch12.adb
@@ -1225,7 +1225,7 @@ package body Ch12 is
 
  elsif Token = Tok_Left_Paren then
 Error_Msg_GNAT_Extension
-  ("expression default for formal subprograms");
+  ("expression default for formal subprograms", Token_Ptr);
 
 if Nkind (Spec_Node) = N_Function_Specification then
Scan;  --  past "("


diff --git a/gcc/ada/par-ch3.adb b/gcc/ada/par-ch3.adb
--- a/gcc/ada/par-ch3.adb
+++ b/gcc/ada/par-ch3.adb
@@ -2788,7 +2788,7 @@ package body Ch3 is
 else
P_Index_Subtype_Def_With_Fixed_Lower_Bound (Subtype_Mark_Node);
 
-   Error_Msg_GNAT_Extension ("fixed-lower-bound array");
+   Error_Msg_GNAT_Extension ("fixed-lower-bound array", Token_Ptr);
 end if;
 
 exit when Token = Tok_Right_Paren or else Token = Tok_Of;
@@ -2857,7 +2857,8 @@ package body Ch3 is
  P_Index_Subtype_Def_With_Fixed_Lower_Bound
(Subtype_Mark_Node);
 
- Error_Msg_GNAT_Extension ("fixed-lower-bound array");
+ Error_Msg_GNAT_Extension
+   ("fixed-lower-bound array", Token_Ptr);
   end if;
 
   exit when Tok

[Ada] Fix DWARF parsing for 32-bit targets on 64-bit hosts

2022-05-18 Thread Pierre-Marie de Rodat via Gcc-patches
Currently, a 64-bit gnatsymbolize fails to output line numbers and
accurate symbol names when run on 32-bit executables (and vice-versa).
This is because a couple of spots in System.Dwarf_Lines expect the
Address_Size found in the DWARF data to match the host Address'Size.

This patch corrects that assumption.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* libgnat/s-dwalin.adb (Aranges_Lookup, Enable_Cache): Adapt to
changes in the signature of Read_Aranges_*.
(Debug_Info_Lookup): Do not control address size read from
DWARF.
(Read_Aranges_Header): Do not control address size read from
DWARF; return this size.
(Read_Aranges_Entry): Use the size returned by
Read_Aranges_Header.diff --git a/gcc/ada/libgnat/s-dwalin.adb b/gcc/ada/libgnat/s-dwalin.adb
--- a/gcc/ada/libgnat/s-dwalin.adb
+++ b/gcc/ada/libgnat/s-dwalin.adb
@@ -44,8 +44,6 @@ with System.Storage_Elements;  use System.Storage_Elements;
 
 package body System.Dwarf_Lines is
 
-   SSU : constant := System.Storage_Unit;
-
function Get_Load_Displacement (C : Dwarf_Context) return Storage_Offset;
--  Return the displacement between the load address present in the binary
--  and the run-time address at which it is loaded (i.e. non-zero for PIE).
@@ -76,14 +74,16 @@ package body System.Dwarf_Lines is
--  Read an entry format array, as specified by 6.2.4.1
 
procedure Read_Aranges_Entry
- (C : in out Dwarf_Context;
-  Start :out Address;
-  Len   :out Storage_Count);
+ (C : in out Dwarf_Context;
+  Addr_Size :Natural;
+  Start :out Address;
+  Len   :out Storage_Count);
--  Read a single .debug_aranges pair
 
procedure Read_Aranges_Header
  (C   : in out Dwarf_Context;
   Info_Offset :out Offset;
+  Addr_Size   :out Natural;
   Success :out Boolean);
--  Read .debug_aranges header
 
@@ -1069,12 +1069,13 @@ package body System.Dwarf_Lines is
   Info_Offset :out Offset;
   Success :out Boolean)
is
+  Addr_Size : Natural;
begin
   Info_Offset := 0;
   Seek (C.Aranges, 0);
 
   while Tell (C.Aranges) < Length (C.Aranges) loop
- Read_Aranges_Header (C, Info_Offset, Success);
+ Read_Aranges_Header (C, Info_Offset, Addr_Size, Success);
  exit when not Success;
 
  loop
@@ -1082,7 +1083,7 @@ package body System.Dwarf_Lines is
Start : Address;
Len   : Storage_Count;
 begin
-   Read_Aranges_Entry (C, Start, Len);
+   Read_Aranges_Entry (C, Addr_Size, Start, Len);
exit when Start = 0 and Len = 0;
if Addr >= Start
  and then Addr < Start + Len
@@ -1280,9 +1281,6 @@ package body System.Dwarf_Lines is
  Unit_Type := Read (C.Info);
 
  Addr_Sz := Read (C.Info);
- if Addr_Sz /= (Address'Size / SSU) then
-return;
- end if;
 
  Read_Section_Offset (C.Info, Abbrev_Offset, Is64);
 
@@ -1290,9 +1288,6 @@ package body System.Dwarf_Lines is
  Read_Section_Offset (C.Info, Abbrev_Offset, Is64);
 
  Addr_Sz := Read (C.Info);
- if Addr_Sz /= (Address'Size / SSU) then
-return;
- end if;
 
   else
  return;
@@ -1354,6 +1349,7 @@ package body System.Dwarf_Lines is
procedure Read_Aranges_Header
  (C   : in out Dwarf_Context;
   Info_Offset :out Offset;
+  Addr_Size   :out Natural;
   Success :out Boolean)
is
   Unit_Length : Offset;
@@ -1376,10 +1372,7 @@ package body System.Dwarf_Lines is
 
   --  Read address_size (ubyte)
 
-  Sz := Read (C.Aranges);
-  if Sz /= (Address'Size / SSU) then
- return;
-  end if;
+  Addr_Size := Natural (uint8'(Read (C.Aranges)));
 
   --  Read segment_size (ubyte)
 
@@ -1392,7 +1385,7 @@ package body System.Dwarf_Lines is
 
   declare
  Cur_Off : constant Offset := Tell (C.Aranges);
- Align   : constant Offset := 2 * Address'Size / SSU;
+ Align   : constant Offset := 2 * Offset (Addr_Size);
  Space   : constant Offset := Cur_Off mod Align;
   begin
  if Space /= 0 then
@@ -1408,14 +1401,15 @@ package body System.Dwarf_Lines is

 
procedure Read_Aranges_Entry
- (C : in out Dwarf_Context;
-  Start :out Address;
-  Len   :out Storage_Count)
+ (C : in out Dwarf_Context;
+  Addr_Size :Natural;
+  Start :out Address;
+  Len   :out Storage_Count)
is
begin
   --  Read table
 
-  if Address'Size = 32 then
+  if Addr_Size = 4 then
  declare
 S, L : uint32;
  begin
@@ -1425,7 +1419,7 @@ package body System.Dwarf_Lines is
 Len   := Storage_Count (L);
  end

[Ada] arm-qnx-7.1: undefined reference to fma* symbols

2022-05-18 Thread Pierre-Marie de Rodat via Gcc-patches
Configure the arm-qnx runtime packages to avoid generating these
symbols.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* Makefile.rtl (arm-qnx): Use default (non-fma) target pair.diff --git a/gcc/ada/Makefile.rtl b/gcc/ada/Makefile.rtl
--- a/gcc/ada/Makefile.rtl
+++ b/gcc/ada/Makefile.rtl
@@ -1510,7 +1510,6 @@ ifeq ($(strip $(filter-out arm aarch64 %qnx,$(target_cpu) $(target_os))),)
   LIBGNAT_TARGET_PAIRS = \
   a-intnam.ads

[Ada] Fix proof of runtime unit s-valeu

2022-05-18 Thread Pierre-Marie de Rodat via Gcc-patches
Update to provers caused some proof regressions.  Fix the proof by
changing ghost code.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* libgnat/s-valueu.adb (Scan_Raw_Unsigned): Add assertions.diff --git a/gcc/ada/libgnat/s-valueu.adb b/gcc/ada/libgnat/s-valueu.adb
--- a/gcc/ada/libgnat/s-valueu.adb
+++ b/gcc/ada/libgnat/s-valueu.adb
@@ -522,6 +522,9 @@ package body System.Value_U is
   Uval := Base;
   Base := 10;
   pragma Assert (Ptr.all = Last_Num_Init + 1);
+  pragma Assert
+(if Starts_As_Based then P = Last_Num_Based + 1);
+  pragma Assert (not Is_Based);
   pragma Assert (if not Overflow then Uval = Init_Val.Value);
   exit;
end if;
@@ -569,10 +572,6 @@ package body System.Value_U is
   end if;
end if;
 
-   Lemma_Scan_Digit
- (Str, P, Last_Num_Based, Digit, Base, Old_Uval, Uval,
-  Based_Val, Old_Overflow, Overflow);
-
--  If at end of string with no base char, not a based number
--  but we signal Constraint_Error and set the pointer past
--  the end of the field, since this is what the ACVC tests
@@ -580,6 +579,10 @@ package body System.Value_U is
 
P := P + 1;
 
+   Lemma_Scan_Digit
+ (Str, P - 1, Last_Num_Based, Digit, Base, Old_Uval, Uval,
+  Based_Val, Old_Overflow, Overflow);
+
if P > Max then
   Ptr.all := P;
   Bad_Value (Str);
@@ -590,6 +593,7 @@ package body System.Value_U is
if Str (P) = Base_Char then
   Ptr.all := P + 1;
   pragma Assert (Ptr.all = Last_Num_Based + 2);
+  pragma Assert (Is_Based);
   pragma Assert
 (if not Overflow then
Based_Val = Scan_Based_Number_Ghost




[Ada] Disable Vet calls when container checks are disabled

2022-05-18 Thread Pierre-Marie de Rodat via Gcc-patches
Calls to various Vet functions are used throughout the containers
packages to check internal consistency. This patch improves efficiency
by disabling these calls when Container_Checks are suppressed.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* libgnat/a-crbtgo.ads, libgnat/a-rbtgbo.ads,
libgnat/a-cbdlli.adb, libgnat/a-cbhama.adb,
libgnat/a-cbhase.adb, libgnat/a-cdlili.adb,
libgnat/a-cfdlli.adb, libgnat/a-cfhama.adb,
libgnat/a-cfhase.adb, libgnat/a-cidlli.adb,
libgnat/a-cihama.adb, libgnat/a-cihase.adb,
libgnat/a-cohama.adb, libgnat/a-cohase.adb,
libgnat/a-crbtgo.adb, libgnat/a-crdlli.adb, libgnat/a-rbtgbo.adb
(Vet): Make the Vet functions do nothing when
Container_Checks'Enabled is False, and inline them, so the calls
disappear when optimizing.diff --git a/gcc/ada/libgnat/a-cbdlli.adb b/gcc/ada/libgnat/a-cbdlli.adb
--- a/gcc/ada/libgnat/a-cbdlli.adb
+++ b/gcc/ada/libgnat/a-cbdlli.adb
@@ -75,7 +75,7 @@ is
   Src_Pos : Count_Type;
   Tgt_Pos : out Count_Type);
 
-   function Vet (Position : Cursor) return Boolean;
+   function Vet (Position : Cursor) return Boolean with Inline;
--  Checks invariants of the cursor and its designated container, as a
--  simple way of detecting dangling references (see operation Free for a
--  description of the detection mechanism), returning True if all checks
@@ -2210,6 +2210,10 @@ is
 
function Vet (Position : Cursor) return Boolean is
begin
+  if not Container_Checks'Enabled then
+ return True;
+  end if;
+
   if Position.Node = 0 then
  return Position.Container = null;
   end if;


diff --git a/gcc/ada/libgnat/a-cbhama.adb b/gcc/ada/libgnat/a-cbhama.adb
--- a/gcc/ada/libgnat/a-cbhama.adb
+++ b/gcc/ada/libgnat/a-cbhama.adb
@@ -66,7 +66,7 @@ is
procedure Set_Next (Node : in out Node_Type; Next : Count_Type);
pragma Inline (Set_Next);
 
-   function Vet (Position : Cursor) return Boolean;
+   function Vet (Position : Cursor) return Boolean with Inline;
 
--
-- Local Instantiations --
@@ -1175,6 +1175,10 @@ is
 
function Vet (Position : Cursor) return Boolean is
begin
+  if not Container_Checks'Enabled then
+ return True;
+  end if;
+
   if Position.Node = 0 then
  return Position.Container = null;
   end if;


diff --git a/gcc/ada/libgnat/a-cbhase.adb b/gcc/ada/libgnat/a-cbhase.adb
--- a/gcc/ada/libgnat/a-cbhase.adb
+++ b/gcc/ada/libgnat/a-cbhase.adb
@@ -79,7 +79,7 @@ is
procedure Set_Next (Node : in out Node_Type; Next : Count_Type);
pragma Inline (Set_Next);
 
-   function Vet (Position : Cursor) return Boolean;
+   function Vet (Position : Cursor) return Boolean with Inline;
 
--
-- Local Instantiations --
@@ -1496,6 +1496,10 @@ is
 
function Vet (Position : Cursor) return Boolean is
begin
+  if not Container_Checks'Enabled then
+ return True;
+  end if;
+
   if Position.Node = 0 then
  return Position.Container = null;
   end if;


diff --git a/gcc/ada/libgnat/a-cdlili.adb b/gcc/ada/libgnat/a-cdlili.adb
--- a/gcc/ada/libgnat/a-cdlili.adb
+++ b/gcc/ada/libgnat/a-cdlili.adb
@@ -64,7 +64,7 @@ is
   Source   : in out List;
   Position : Node_Access);
 
-   function Vet (Position : Cursor) return Boolean;
+   function Vet (Position : Cursor) return Boolean with Inline;
--  Checks invariants of the cursor and its designated container, as a
--  simple way of detecting dangling references (see operation Free for a
--  description of the detection mechanism), returning True if all checks
@@ -1991,6 +1991,10 @@ is
 
function Vet (Position : Cursor) return Boolean is
begin
+  if not Container_Checks'Enabled then
+ return True;
+  end if;
+
   if Position.Node = null then
  return Position.Container = null;
   end if;


diff --git a/gcc/ada/libgnat/a-cfdlli.adb b/gcc/ada/libgnat/a-cfdlli.adb
--- a/gcc/ada/libgnat/a-cfdlli.adb
+++ b/gcc/ada/libgnat/a-cfdlli.adb
@@ -48,7 +48,7 @@ is
   Before: Count_Type;
   New_Node  : Count_Type);
 
-   function Vet (L : List; Position : Cursor) return Boolean;
+   function Vet (L : List; Position : Cursor) return Boolean with Inline;
 
-
-- "=" --
@@ -1766,8 +1766,11 @@ is
 
function Vet (L : List; Position : Cursor) return Boolean is
   N : Node_Array renames L.Nodes;
-
begin
+  if not Container_Checks'Enabled then
+ return True;
+  end if;
+
   if L.Length = 0 then
  return False;
   end if;


diff --git a/gcc/ada/libgnat/a-cfhama.adb b/gcc/ada/libgnat/a-cfhama.adb
--- a/gcc/ada/libgnat/a-cfhama.adb
+++ b/gcc/ada/libgnat/a-cfhama.adb
@@ -68,7 +68,8 @@ is
procedure Set_Next (Node : in out Node_Type; Next : Count_Type);
pragma Inline (Set_Next);
 
-   function Vet (Container : Map; Positi

[Ada] qnx-7.1: warning in sigtramp-qnx.c __gnat_sigtramp

2022-05-18 Thread Pierre-Marie de Rodat via Gcc-patches
Fix compilation warning. The code was using a cast to struct sigcontext
*, which doesn't exist. It worked by accident.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* sigtramp-qnx.c: Change struct sigcontext * to mcontext_t *.diff --git a/gcc/ada/sigtramp-qnx.c b/gcc/ada/sigtramp-qnx.c
--- a/gcc/ada/sigtramp-qnx.c
+++ b/gcc/ada/sigtramp-qnx.c
@@ -49,7 +49,7 @@ void __gnat_sigtramp (int signo, void *si, void *sc,
 void __gnat_sigtramp (int signo, void *si, void *ucontext,
   __sigtramphandler_t * handler)
 {
-  struct sigcontext *mcontext = &((ucontext_t *) ucontext)->uc_mcontext;
+  mcontext_t *mcontext = &((ucontext_t *) ucontext)->uc_mcontext;
 
   __gnat_sigtramp_common (signo, si, mcontext, handler);
 }




[Ada] Fix proof of runtime unit s-imageu

2022-05-18 Thread Pierre-Marie de Rodat via Gcc-patches
Update to provers caused some proof regressions.  Fix the proof by
adding an assertion.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* libgnat/s-imageu.adb (Set_Image_Unsigned): Change assertion.diff --git a/gcc/ada/libgnat/s-imageu.adb b/gcc/ada/libgnat/s-imageu.adb
--- a/gcc/ada/libgnat/s-imageu.adb
+++ b/gcc/ada/libgnat/s-imageu.adb
@@ -390,16 +390,9 @@ package body System.Image_U is
Acc  => Value)
   = Wrap_Option (V));
   end loop;
+  pragma Assert (Value = 0);
 
   Prove_Unchanged;
-  pragma Assert
-(Scan_Based_Number_Ghost
-   (Str  => S,
-From => P + 1,
-To   => P + Nb_Digits,
-Base => 10,
-Acc  => Value)
- = Wrap_Option (V));
 
   P := P + Nb_Digits;
end Set_Image_Unsigned;




[Ada] Adapt proof of double arithmetic runtime unit

2022-05-18 Thread Pierre-Marie de Rodat via Gcc-patches
After changes in Why3 and generation of VCs, ghost code needs to be
adapted for proofs to remain automatic.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* libgnat/s-aridou.adb (Big3): Change return type.
(Lemma_Mult_Non_Negative, Lemma_Mult_Non_Positive): Reorder
alphabetically.
(Lemma_Concat_Definition, Lemma_Double_Big_2xxsingle): New
lemmas.
(Double_Divide, Scaled_Divide): Add assertions.diff --git a/gcc/ada/libgnat/s-aridou.adb b/gcc/ada/libgnat/s-aridou.adb
--- a/gcc/ada/libgnat/s-aridou.adb
+++ b/gcc/ada/libgnat/s-aridou.adb
@@ -133,7 +133,7 @@ is
  Post => Big_2xx'Result > 0;
--  2**N as a big integer
 
-   function Big3 (X1, X2, X3 : Single_Uns) return Big_Integer is
+   function Big3 (X1, X2, X3 : Single_Uns) return Big_Natural is
  (Big_2xxSingle * Big_2xxSingle * Big (Double_Uns (X1))
 + Big_2xxSingle * Big (Double_Uns (X2))
 + Big (Double_Uns (X3)))
@@ -208,20 +208,6 @@ is
  Ghost,
  Post => abs (X * Y) = abs X * abs Y;
 
-   procedure Lemma_Mult_Non_Negative (X, Y : Big_Integer)
-   with
- Ghost,
- Pre  => (X >= Big_0 and then Y >= Big_0)
-   or else (X <= Big_0 and then Y <= Big_0),
- Post => X * Y >= Big_0;
-
-   procedure Lemma_Mult_Non_Positive (X, Y : Big_Integer)
-   with
- Ghost,
- Pre  => (X <= Big_0 and then Y >= Big_0)
-   or else (X >= Big_0 and then Y <= Big_0),
- Post => X * Y <= Big_0;
-
procedure Lemma_Abs_Rem_Commutation (X, Y : Big_Integer)
with
  Ghost,
@@ -246,6 +232,12 @@ is
  Pre  => M < N and then N < Double_Size,
  Post => Double_Uns'(2)**M < Double_Uns'(2)**N;
 
+   procedure Lemma_Concat_Definition (X, Y : Single_Uns)
+   with
+ Ghost,
+ Post => Big (X & Y) = Big_2xxSingle * Big (Double_Uns (X))
+ + Big (Double_Uns (Y));
+
procedure Lemma_Deep_Mult_Commutation
  (Factor : Big_Integer;
   X, Y   : Single_Uns)
@@ -289,6 +281,11 @@ is
  Pre  => A * S = B * S + R and then S /= 0,
  Post => A = B + R / S;
 
+   procedure Lemma_Double_Big_2xxSingle
+   with
+ Ghost,
+ Post => Big_2xxSingle * Big_2xxSingle = Big_2xxDouble;
+
procedure Lemma_Double_Shift (X : Double_Uns; S, S1 : Double_Uns)
with
  Ghost,
@@ -419,6 +416,20 @@ is
  Ghost,
  Post => X * (Y + Z) = X * Y + X * Z;
 
+   procedure Lemma_Mult_Non_Negative (X, Y : Big_Integer)
+   with
+ Ghost,
+ Pre  => (X >= Big_0 and then Y >= Big_0)
+   or else (X <= Big_0 and then Y <= Big_0),
+ Post => X * Y >= Big_0;
+
+   procedure Lemma_Mult_Non_Positive (X, Y : Big_Integer)
+   with
+ Ghost,
+ Pre  => (X <= Big_0 and then Y >= Big_0)
+   or else (X >= Big_0 and then Y <= Big_0),
+ Post => X * Y <= Big_0;
+
procedure Lemma_Neg_Div (X, Y : Big_Integer)
with
  Ghost,
@@ -552,6 +563,7 @@ is
procedure Lemma_Add_Commutation (X : Double_Uns; Y : Single_Uns) is null;
procedure Lemma_Add_One (X : Double_Uns) is null;
procedure Lemma_Bounded_Powers_Of_2_Increasing (M, N : Natural) is null;
+   procedure Lemma_Concat_Definition (X, Y : Single_Uns) is null;
procedure Lemma_Deep_Mult_Commutation
  (Factor : Big_Integer;
   X, Y   : Single_Uns)
@@ -566,6 +578,7 @@ is
procedure Lemma_Div_Ge (X, Y, Z : Big_Integer) is null;
procedure Lemma_Div_Lt (X, Y, Z : Big_Natural) is null;
procedure Lemma_Div_Eq (A, B, S, R : Big_Integer) is null;
+   procedure Lemma_Double_Big_2xxSingle is null;
procedure Lemma_Double_Shift (X : Double_Uns; S, S1 : Double_Uns) is null;
procedure Lemma_Double_Shift (X : Single_Uns; S, S1 : Natural) is null;
procedure Lemma_Double_Shift_Right (X : Double_Uns; S, S1 : Double_Uns)
@@ -929,10 +942,18 @@ is
pragma Assert (Big (Double_Uns'(Yhi * Zhi)) >= 1);
if Yhi > 1 or else Zhi > 1 then
   pragma Assert (Big (Double_Uns'(Yhi * Zhi)) > 1);
+  pragma Assert (if X = Double_Int'First and then Round then
+Mult > Big_2xxDouble);
elsif Zlo > 0 then
   pragma Assert (Big (Double_Uns'(Yhi * Zlo)) > 0);
+  pragma Assert (if X = Double_Int'First and then Round then
+Mult > Big_2xxDouble);
elsif Ylo > 0 then
   pragma Assert (Big (Double_Uns'(Ylo * Zhi)) > 0);
+  pragma Assert (if X = Double_Int'First and then Round then
+Mult > Big_2xxDouble);
+   else
+  pragma Assert (not (X = Double_Int'First and then Round));
end if;
Prove_Quotient_Zero;
 end if;
@@ -976,6 +997,7 @@ is
   Lemma_Mult_Distribution (Big_2xxSingle,
Big (Double_Uns (Hi (T2))),
Big (Double_Uns 

[Ada] arm-qnx-7.1: stack-checking and sigtramp implementation

2022-05-18 Thread Pierre-Marie de Rodat via Gcc-patches
Rewrite and base on VxWorks RTP implementation.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* sigtramp-arm-qnx.c: Rewrite.diff --git a/gcc/ada/sigtramp-arm-qnx.c b/gcc/ada/sigtramp-arm-qnx.c
--- a/gcc/ada/sigtramp-arm-qnx.c
+++ b/gcc/ada/sigtramp-arm-qnx.c
@@ -6,7 +6,7 @@
  *  *
  * Asm Implementation File  *
  *  *
- *   Copyright (C) 2015-2022, Free Software Foundation, Inc.*
+ * Copyright (C) 2011-2022, Free Software Foundation, Inc.  *
  *  *
  * GNAT is free software;  you can  redistribute it  and/or modify it under *
  * terms of the  GNU General Public License as published  by the Free Soft- *
@@ -33,49 +33,44 @@
  * ARM-QNX version of the __gnat_sigtramp service *
  **/
 
+#include 
 #include 
 
 #include "sigtramp.h"
 /* See sigtramp.h for a general explanation of functionality.  */
 
-/* --
-   -- General comments --
-   --
+/* ---
+   -- Prototypes for our internal asm stubs --
+   ---
 
-   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.
+   Eventhough our symbols will remain local, the prototype claims "extern"
+   and not "static" to prevent compiler complaints about a symbol used but
+   never defined.  */
 
-   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.  */
+/* sigtramp stub providing ARM unwinding info for common registers.  */
 
-/* -
-   -- Protypes for our internal asm stubs --
-   -
-
-   The registers are expected to be at SIGCONTEXT + 12 (reference the
-   sicontext structure in asm/sigcontext.h which describes the first
-   3 * 4byte fields.)  Even though our symbols will remain local, the
-   prototype claims "extern" and not "static" to prevent compiler complaints
-   about a symbol used but never defined.  */
+extern void __gnat_sigtramp_common
+(int signo, void *siginfo, void *sigcontext,
+ __sigtramphandler_t * handler, void * sc_pregs);
 
-/* sigtramp stub providing unwind info for common registers.  */
+/* -
+   -- Common interface implementation --
+   -
 
-extern void __gnat_sigtramp_common
-  (int signo, void *siginfo, void *sigcontext,
-   __sigtramphandler_t * handler);
+   We enforce optimization to minimize the overhead of the extra layer.  */
 
 void __gnat_sigtramp (int signo, void *si, void *sc,
-  __sigtramphandler_t * handler)
+		  __sigtramphandler_t * handler)
  __attribute__((optimize(2)));
 
-void __gnat_sigtramp (int signo, void *si, void *ucontext,
-  __sigtramphandler_t * handler)
+void __gnat_sigtramp (int signo, void *si, void *sc,
+		  __sigtramphandler_t * handler)
 {
-  struct sigcontext *mcontext = &((ucontext_t *) ucontext)->uc_mcontext;
+  mcontext_t *mcontext = &((ucontext_t *) sc)->uc_mcontext;
 
-  __gnat_sigtramp_common (signo, si, mcontext, handler);
+  /* Pass MCONTEXT in the fifth position so that the assembly code can find
+ it at the same stack location as SC_PREGS.  */
+  __gnat_sigtramp_common (signo, si, mcontext, handler, &mcontext->cpu);
 }
 
 /* asm string construction helpers.  */
@@ -98,27 +93,25 @@ void __gnat_sigtramp (int signo, void *si, void *ucontext,
 /* Trampoline body block
-  */
 
+/* The 5 arguments passed to __gnat_sigtramp_common are located in:
+   - r0-r2: arguments to pass on to the actual handler
+   - r3: the actual handler
+   - sp: the address of the reg set to restore
+   All we have to do then is to instruct the unwinder to restore the registers
+   from the value in VSP. Unwinder instructions are executed backwards, so we
+   1- instruct to pop r2 from the VSP (.save {r2})
+   2- move the VSP to the address pointed to by r2 (.movsp r2)
+   3- restore all registers from there. (.save {r0-r15})
+   Once the unwinding instructions are set, we just need to call the handler
+   as r0-r2 are already properly set.
+*/
 #define SIGTRAMP_BODY \
 CR("") \
-TCR("# Allocate frame and also save r2 which is the argument register") \
-TCR("# containing the sigcontext, so that we can restore it during") \
-TCR("# unwinding and thereby load the rest of the desired context.") \
-TCR("stmfd	sp!, {r2, r3, lr}") \
-TCR("# The unwinder undo's these operation

[PATCH v3, rs6000] Implemented f[min/max]_optab by xs[min/max]dp [PR103605]

2022-05-18 Thread HAO CHEN GUI via Gcc-patches
Hi,
  This patch implements optab f[min/max]_optab by xs[min/max]dp on rs6000.
Tests show that outputs of xs[min/max]dp are consistent with the standard
of C99 fmin/max.

  This patch also binds __builtin_vsx_xs[min/max]dp to fmin/max instead
of smin/max. So the builtins always generate xs[min/max]dp on all
platforms.

  Bootstrapped and tested on ppc64 Linux BE and LE with no regressions.
Is this okay for trunk? Any recommendations? Thanks a lot.

ChangeLog
2022-05-18 Haochen Gui 

gcc/
PR target/103605
* rs6000.md (FMINMAX): New.
(minmax_op): New.
(f3): New pattern by UNSPEC_FMAX and UNSPEC_FMIN.
* rs6000-builtins.def (__builtin_vsx_xsmaxdp): Set pattern to fmaxdf3.
(__builtin_vsx_xsmindp): Set pattern to fmindf3.

gcc/testsuite/
PR target/103605
* gcc.dg/pr103605.c: New.

patch.diff
diff --git a/gcc/config/rs6000/rs6000-builtins.def 
b/gcc/config/rs6000/rs6000-builtins.def
index f4a9f24bcc5..8b735493b40 100644
--- a/gcc/config/rs6000/rs6000-builtins.def
+++ b/gcc/config/rs6000/rs6000-builtins.def
@@ -1613,10 +1613,10 @@
 XSCVSPDP vsx_xscvspdp {}

   const double __builtin_vsx_xsmaxdp (double, double);
-XSMAXDP smaxdf3 {}
+XSMAXDP fmaxdf3 {}

   const double __builtin_vsx_xsmindp (double, double);
-XSMINDP smindf3 {}
+XSMINDP fmindf3 {}

   const double __builtin_vsx_xsrdpi (double);
 XSRDPI vsx_xsrdpi {}
diff --git a/gcc/config/rs6000/rs6000.md b/gcc/config/rs6000/rs6000.md
index bf85baa5370..197de0838ee 100644
--- a/gcc/config/rs6000/rs6000.md
+++ b/gcc/config/rs6000/rs6000.md
@@ -158,6 +158,8 @@ (define_c_enum "unspec"
UNSPEC_HASHCHK
UNSPEC_XXSPLTIDP_CONST
UNSPEC_XXSPLTIW_CONST
+   UNSPEC_FMAX
+   UNSPEC_FMIN
   ])

 ;;
@@ -5341,6 +5343,22 @@ (define_insn_and_split "*s3_fpr"
   DONE;
 })

+
+(define_int_iterator FMINMAX [UNSPEC_FMAX UNSPEC_FMIN])
+
+(define_int_attr  minmax_op [(UNSPEC_FMAX "max")
+(UNSPEC_FMIN "min")])
+
+(define_insn "f3"
+  [(set (match_operand:SFDF 0 "vsx_register_operand" "=wa")
+   (unspec:SFDF [(match_operand:SFDF 1 "vsx_register_operand" "wa")
+ (match_operand:SFDF 2 "vsx_register_operand" "wa")]
+ FMINMAX))]
+"TARGET_VSX"
+"xsdp %x0,%x1,%x2"
+[(set_attr "type" "fp")]
+)
+
 (define_expand "movcc"
[(set (match_operand:GPR 0 "gpc_reg_operand")
 (if_then_else:GPR (match_operand 1 "comparison_operator")
diff --git a/gcc/testsuite/gcc.target/powerpc/pr103605.c 
b/gcc/testsuite/gcc.target/powerpc/pr103605.c
new file mode 100644
index 000..e43ac40c2d1
--- /dev/null
+++ b/gcc/testsuite/gcc.target/powerpc/pr103605.c
@@ -0,0 +1,37 @@
+/* { dg-do compile } */
+/* { dg-require-effective-target powerpc_vsx_ok } */
+/* { dg-options "-O1 -mvsx" } */
+/* { dg-final { scan-assembler-times {\mxsmaxdp\M} 3 } } */
+/* { dg-final { scan-assembler-times {\mxsmindp\M} 3 } } */
+
+#include 
+
+double test1 (double d0, double d1)
+{
+  return fmin (d0, d1);
+}
+
+float test2 (float d0, float d1)
+{
+  return fmin (d0, d1);
+}
+
+double test3 (double d0, double d1)
+{
+  return fmax (d0, d1);
+}
+
+float test4 (float d0, float d1)
+{
+  return fmax (d0, d1);
+}
+
+double test5 (double d0, double d1)
+{
+  return __builtin_vsx_xsmindp (d0, d1);
+}
+
+double test6 (double d0, double d1)
+{
+  return __builtin_vsx_xsmaxdp (d0, d1);
+}


[Patch] OpenMP: Add Fortran support for inoutset depend-kind (was: openmp: Add support for inoutset depend-kind)

2022-05-18 Thread Tobias Burnus

On 17.05.22 15:55, Jakub Jelinek via Gcc-patches wrote:

This patch adds support for inoutset depend-kind in depend
clauses.


While this patch adds the Fortran FE bits and converts the C/C++
testcase changes for Fortran.

Bootstrapped/regtested on x86_64-linux.
OK for trunk?

Tobias
-
Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 
München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas 
Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht 
München, HRB 106955
OpenMP: Add Fortran support for inoutset depend-kind

Fortran additions to the C/C++ + ME/libgomp commit
r13-556-g2c16eb3157f86ae561468c540caf8eb326106b5f

gcc/fortran/ChangeLog:

	* gfortran.h (enum gfc_omp_depend_op): Add OMP_DEPEND_INOUTSET.
	(gfc_omp_clauses): Enlarge ENUM_BITFIELD.
	* dump-parse-tree.cc (show_omp_namelist, show_omp_clauses): Handle
	'inoutset' depend modifier.
	* openmp.cc (gfc_match_omp_clauses, gfc_match_omp_depobj): Likewise.
	* trans-openmp.cc (gfc_trans_omp_clauses, gfc_trans_omp_depobj):
	Likewise.

libgomp/ChangeLog:

	* libgomp.texi (OpenMP 5.1): Set 'inoutset' to Y.
	(OpenMP Context Selectors): Add missing comma.
	* testsuite/libgomp.fortran/depend-5.f90: Add inoutset test.
	* testsuite/libgomp.fortran/depend-6.f90: Likewise.
	* testsuite/libgomp.fortran/depend-7.f90: Likewise.
	* testsuite/libgomp.fortran/depend-inoutset-1.f90: New test.

gcc/testsuite/ChangeLog:

	* gfortran.dg/gomp/all-memory-1.f90: Add inoutset test.
	* gfortran.dg/gomp/all-memory-2.f90: Likewise.
	* gfortran.dg/gomp/depobj-1.f90: Likewise.
	* gfortran.dg/gomp/depobj-2.f90: Likewise.

 gcc/fortran/dump-parse-tree.cc |   2 +
 gcc/fortran/gfortran.h |   3 +-
 gcc/fortran/openmp.cc  |  12 +-
 gcc/fortran/trans-openmp.cc|   4 +
 gcc/testsuite/gfortran.dg/gomp/all-memory-1.f90|   3 +
 gcc/testsuite/gfortran.dg/gomp/all-memory-2.f90|   3 +
 gcc/testsuite/gfortran.dg/gomp/depobj-1.f90|   3 +
 gcc/testsuite/gfortran.dg/gomp/depobj-2.f90|   6 +-
 libgomp/libgomp.texi   |   4 +-
 libgomp/testsuite/libgomp.fortran/depend-5.f90 |   8 +-
 libgomp/testsuite/libgomp.fortran/depend-6.f90 |   8 +-
 libgomp/testsuite/libgomp.fortran/depend-7.f90 |   8 +-
 .../libgomp.fortran/depend-inoutset-1.f90  | 170 +
 13 files changed, 221 insertions(+), 13 deletions(-)

diff --git a/gcc/fortran/dump-parse-tree.cc b/gcc/fortran/dump-parse-tree.cc
index a32992035a2..4e8986bd599 100644
--- a/gcc/fortran/dump-parse-tree.cc
+++ b/gcc/fortran/dump-parse-tree.cc
@@ -1379,6 +1379,7 @@ show_omp_namelist (int list_type, gfc_omp_namelist *n)
 	  case OMP_DEPEND_IN: fputs ("in:", dumpfile); break;
 	  case OMP_DEPEND_OUT: fputs ("out:", dumpfile); break;
 	  case OMP_DEPEND_INOUT: fputs ("inout:", dumpfile); break;
+	  case OMP_DEPEND_INOUTSET: fputs ("inoutset:", dumpfile); break;
 	  case OMP_DEPEND_DEPOBJ: fputs ("depobj:", dumpfile); break;
 	  case OMP_DEPEND_MUTEXINOUTSET:
 	fputs ("mutexinoutset:", dumpfile);
@@ -1898,6 +1899,7 @@ show_omp_clauses (gfc_omp_clauses *omp_clauses)
 	case OMP_DEPEND_IN: deptype = "IN"; break;
 	case OMP_DEPEND_OUT: deptype = "OUT"; break;
 	case OMP_DEPEND_INOUT: deptype = "INOUT"; break;
+	case OMP_DEPEND_INOUTSET: deptype = "INOUTSET"; break;
 	case OMP_DEPEND_MUTEXINOUTSET: deptype = "MUTEXINOUTSET"; break;
 	default: gcc_unreachable ();
 	}
diff --git a/gcc/fortran/gfortran.h b/gcc/fortran/gfortran.h
index 1bce2833139..5d970bc1df0 100644
--- a/gcc/fortran/gfortran.h
+++ b/gcc/fortran/gfortran.h
@@ -1271,6 +1271,7 @@ enum gfc_omp_depend_op
   OMP_DEPEND_IN,
   OMP_DEPEND_OUT,
   OMP_DEPEND_INOUT,
+  OMP_DEPEND_INOUTSET,
   OMP_DEPEND_MUTEXINOUTSET,
   OMP_DEPEND_DEPOBJ,
   OMP_DEPEND_SINK_FIRST,
@@ -1540,7 +1541,7 @@ typedef struct gfc_omp_clauses
   ENUM_BITFIELD (gfc_omp_memorder) fail:3;
   ENUM_BITFIELD (gfc_omp_cancel_kind) cancel:3;
   ENUM_BITFIELD (gfc_omp_proc_bind_kind) proc_bind:3;
-  ENUM_BITFIELD (gfc_omp_depend_op) depobj_update:3;
+  ENUM_BITFIELD (gfc_omp_depend_op) depobj_update:4;
   ENUM_BITFIELD (gfc_omp_bind_type) bind:2;
   ENUM_BITFIELD (gfc_omp_at_type) at:2;
   ENUM_BITFIELD (gfc_omp_severity_type) severity:2;
diff --git a/gcc/fortran/openmp.cc b/gcc/fortran/openmp.cc
index 3061e5297b7..63fd4dd2767 100644
--- a/gcc/fortran/openmp.cc
+++ b/gcc/fortran/openmp.cc
@@ -1915,7 +1915,9 @@ gfc_match_omp_clauses (gfc_omp_clauses **cp, const omp_mask mask,
 		break;
 	  m = MATCH_YES;
 	  gfc_omp_depend_op depend_op = OMP_DEPEND_OUT;
-	  if (gfc_match ("inout") == MATCH_YES)
+	  if (gfc_match ("inoutset") == MATCH_YES)
+		depend_op = OMP_DEPEND_INOUTSET;
+	  else if (gfc_match ("inout") == MATCH_YES)
 		depend_op = OMP_DEPEND_INOUT;
 	  else if (gfc_match ("in") == MATCH_YES)
 		depend_op = OMP_DEPEND_IN;
@@ -3805,7 +3807,9 @@ gfc_match_

Re: PING: [PATCH v2] x86: Fix -fsplit-stack feature detection via TARGET_CAN_SPLIT_STACK

2022-05-18 Thread Uros Bizjak via Gcc-patches
On Wed, May 18, 2022 at 9:34 AM Sören Tempel  wrote:
>
> Hi,
>
> Uros Bizjak  wrote:
> > > > > gcc/ChangeLog:
> > > > >
> > > > > * config/i386/gnu-user-common.h (defined): Only define
> > > > > TARGET_CAN_SPLIT_STACK for glibc targets.
> > > > > * config/i386/gnu.h (defined): Ditto.
> >
> > This looks good to me, so OK.
> >
> > Thanks,
> > Uros.
>
> I am not deeply familiar with the GCC development process but since it
> seems that this hasn't been merged yet: Is there anything else that I
> need to do or what is the process for getting this patch upstreamed? (:

You should state in your patch submission that you don't have commit rights.

Anyway, please send me (privately) the updated patch, I'll commit it
in your name later today.

Uros.


Re: [x86 PATCH take 2] Avoid andn and generate shorter not; and with -Oz.

2022-05-18 Thread Uros Bizjak via Gcc-patches
On Tue, May 17, 2022 at 5:52 PM Roger Sayle  wrote:
>
>
> This is a revised version of my i386 backend patch to avoid andn with -Oz,
> when an explicit not;and (or not;test) would be (one byte) shorter.
> https://gcc.gnu.org/pipermail/gcc-patches/2022-April/593168.html
> This revision incorporates Michael Matz's feedback/suggestions with
> explicit checks for LEGACY_INT_REG_P and REX_INT_REG_P.
>
> This patch has been tested against gcc13 trunk on x86_64-pc-linux-gnu
> with make bootstrap and make -k check, both with and without
> --target_board=unix{-m32}, with no new failures.  Ok for mainline?
>
> 2022-05-17  Roger Sayle  
>
> gcc/ChangeLog
> * config/i386/i386.md (define_split):  Split *andsi_1 and
> *andn_si_ccno after reload with -Oz.
>
> gcc/testsuite/ChangeLog
> * gcc.target/i386/bmi-and-3.c: New test case.

OK.

Thanks,
Uros.

>
>
> Thanks in advance,
> Roger
> --
>
> > -Original Message-
> > From: Michael Matz 
> > Sent: 13 April 2022 14:11
> > To: Roger Sayle 
> > Cc: gcc-patches@gcc.gnu.org
> > Subject: Re: [x86 PATCH] Avoid andn and generate shorter not;and with -Oz.
> >
> > Hello,
> >
> > On Wed, 13 Apr 2022, Roger Sayle wrote:
> >
> > > The x86 instruction encoding for SImode andn is longer than the
> > > equivalent notl/andl sequence when the source for the not operand is
> > > the same register as the destination.
> >
> > _And_ when no REX prefixes are necessary for the notl,andn, which they are
> if
> > the respective registers are %r8 or beyond.  As you seem to be fine with
> saving
> > just a byte you ought to test that as well to not waste one again :-)
> >
> >
> > Ciao,
> > Michael.


Re: [x86 PATCH] Correct ix86_rtx_cost for multi-word multiplication.

2022-05-18 Thread Uros Bizjak via Gcc-patches
On Tue, May 17, 2022 at 6:44 PM Roger Sayle  wrote:
>
>
> This is the i386 backend specific piece of my revised patch for
> PR middle-end/98865, where Richard Biener has suggested that I perform
> the desired transformation during RTL expansion where the backend can
> control whether it is profitable to convert a multiplication into a
> bit-wise AND and a negation.  This works well for x86_64, but alas
> exposes a latent bug with -m32, where a DImode multiplication incorrectly
> appears to be cheaper than negdi2+anddi3(!?).  The fix to ix86_rtx_costs
> is to report that a DImode (multi-word) multiplication actually requires
> three SImode multiplications and two SImode additions.  This also corrects
> the cost of TImode multiplication on TARGET_64BIT.
>
> This patch has been tested on x86_64-pc-linux-gnu with make bootstrap
> and make -k check, both with and without --target_board=unix{-m32}, with
> no new failures.  This change avoids the need for a !ia32 target selector
> for the upcoming new test case gcc.target/i386/pr98865.c.
> Ok for mainline?
>
>
> 2022-05-17  Roger Sayle  
>
> gcc/ChangeLog
> * config/i386/i386.cc (ix86_rtx_costs) [MULT]: When mode size
> is wider than word_mode, a multiplication costs three word_mode
> multiplications and two word_mode additions.

LGTM.

Thanks,
Uros.

>
> Thanks in advance,
> Roger
> --
>


Re: [Patch] OpenMP: Add Fortran support for inoutset depend-kind (was: openmp: Add support for inoutset depend-kind)

2022-05-18 Thread Jakub Jelinek via Gcc-patches
On Wed, May 18, 2022 at 11:02:27AM +0200, Tobias Burnus wrote:
> OpenMP: Add Fortran support for inoutset depend-kind
> 
> Fortran additions to the C/C++ + ME/libgomp commit
> r13-556-g2c16eb3157f86ae561468c540caf8eb326106b5f
> 
> gcc/fortran/ChangeLog:
> 
>   * gfortran.h (enum gfc_omp_depend_op): Add OMP_DEPEND_INOUTSET.
>   (gfc_omp_clauses): Enlarge ENUM_BITFIELD.
>   * dump-parse-tree.cc (show_omp_namelist, show_omp_clauses): Handle
>   'inoutset' depend modifier.
>   * openmp.cc (gfc_match_omp_clauses, gfc_match_omp_depobj): Likewise.
>   * trans-openmp.cc (gfc_trans_omp_clauses, gfc_trans_omp_depobj):
>   Likewise.
> 
> libgomp/ChangeLog:
> 
>   * libgomp.texi (OpenMP 5.1): Set 'inoutset' to Y.
>   (OpenMP Context Selectors): Add missing comma.
>   * testsuite/libgomp.fortran/depend-5.f90: Add inoutset test.
>   * testsuite/libgomp.fortran/depend-6.f90: Likewise.
>   * testsuite/libgomp.fortran/depend-7.f90: Likewise.
>   * testsuite/libgomp.fortran/depend-inoutset-1.f90: New test.
> 
> gcc/testsuite/ChangeLog:
> 
>   * gfortran.dg/gomp/all-memory-1.f90: Add inoutset test.
>   * gfortran.dg/gomp/all-memory-2.f90: Likewise.
>   * gfortran.dg/gomp/depobj-1.f90: Likewise.
>   * gfortran.dg/gomp/depobj-2.f90: Likewise.

Ok, thanks.

Jakub



Re: [0/9] [middle-end] Add param to vec_perm_const hook to specify mode of input operand

2022-05-18 Thread Andre Vieira (lists) via Gcc-patches

Hi Prathamesh,

I am just looking at this as it interacts with a change I am trying to 
make, but I'm not a reviewer so take my comments with a pinch of salt ;)


I copied in bits of your patch below to comment.

> -@deftypefn {Target Hook} bool TARGET_VECTORIZE_VEC_PERM_CONST 
(machine_mode @var{mode}, rtx @var{output}, rtx @var{in0}, rtx 
@var{in1}, const vec_perm_indices @var{&sel})
> +@deftypefn {Target Hook} bool TARGET_VECTORIZE_VEC_PERM_CONST 
(machine_mode @var{mode}, machine_mode @var{op_mode}, rtx @var{output}, 
rtx @var{in0}, rtx @var{in1}, const vec_perm_indices @var{&sel})

>  This hook is used to test whether the target can permute up to two
>  vectors of mode @var{mode} using the permutation vector @code{sel}, and
>  also to emit such a permutation.  In the former case @var{in0}, 
@var{in1}


Would be good to also explain what the new op_mode parameter is used for 
here.


> @@ -6250,7 +6250,9 @@ expand_vec_perm_const (machine_mode mode, rtx 
v0, rtx v1,

>    if (single_arg_p)
>      v1 = v0;
>
> -  if (targetm.vectorize.vec_perm_const (mode, target, v0, v1, 
indices))

> +  gcc_checking_assert (GET_MODE (v0) == GET_MODE (v1));
> +  machine_mode op_mode = GET_MODE (v0);
> +  if (targetm.vectorize.vec_perm_const (mode, op_mode, target, 
v0, v1, indices))

>      return target;
>      }

I was surprised by the assert check here. The docs seem to insinuate 
vec_perm needs both input vectors to be of the same mode, so I was 
expecting this to be checked/enforced elsewhere? But it shouldn't hurt I 
guess.


> @@ -1894,7 +1894,7 @@ try the equivalent byte operation.  If that 
also fails, it will try forcing\n\

>  the selector into a register and using the @var{vec_perm@var{mode}}\n\
>  instruction pattern.  There is no need for the hook to handle these 
two\n\

>  implementation approaches itself.",
> - bool, (machine_mode mode, rtx output, rtx in0, rtx in1,
> + bool, (machine_mode mode, machine_mode op_mode, rtx output, rtx 
in0, rtx in1,

>      const vec_perm_indices &sel),
>   NULL)

Same comment as the first, it could do with an inclusion of op_mode in 
the comments explaining the function.


On 18/05/2022 08:06, Prathamesh Kulkarni via Gcc-patches wrote:

Hi,
The attached patch adds another parameter machine_mode op_mode to vec_perm_const
hook to specify mode of input operands. The motivation for doing this
is PR96463,
where we create vec_perm_expr of the form:
lhs = vec_perm_expr
where lhs and rhs have different vector types but same element type
(lhs is SVE and rhs is corresponding advsimd vector).

It seems the following targets were affected: aarch64, i386, arm, ia64,
mips, rs6000, s390, sparc, gcn.

Bootstrapped+tested on x86_64-linux-gnu, aarch64-linux-gnu.
For other targets, I did make all-gcc stage1, which seems to build OK.

Thanks,
Prathamesh


Re: [PATCH] i386: Add a constraint for absolute symboilc address [PR 105576]

2022-05-18 Thread Uros Bizjak via Gcc-patches
On Wed, May 18, 2022 at 9:32 AM Hongyu Wang  wrote:
>
> Hi,
>
> This patch adds a constraint "Ws" to allow absolute symbolic address for 
> either
> function or variable. This also works under -mcmodel=large.
>
> Bootstrapped/regtested on x86_64-pc-linux-gnu{-m32,}
>
> Ok for master?

Maybe you should use:

  asm ("%p0" :: "X"(addr));
  asm ("%p0" :: "X"(&var));

instead.

Uros.

> gcc/ChangeLog:
>
> PR target/105576
> * config/i386/constraints.md (Ws): New constraint.
> * config/i386/i386-protos.h (ix86_symbolic_address_p):
> New proto type.
> * config/i386/i386.cc (ix86_symbolic_address_p):
> New function to ensure a rtx is a symbolic address.
>
> gcc/testsuite/ChangeLog:
>
> PR target/105576
> * gcc.target/i386/pr105576.c: New test.
> ---
>  gcc/config/i386/constraints.md   |  4 
>  gcc/config/i386/i386-protos.h|  1 +
>  gcc/config/i386/i386.cc  |  7 +++
>  gcc/testsuite/gcc.target/i386/pr105576.c | 11 +++
>  4 files changed, 23 insertions(+)
>  create mode 100644 gcc/testsuite/gcc.target/i386/pr105576.c
>
> diff --git a/gcc/config/i386/constraints.md b/gcc/config/i386/constraints.md
> index 7361687632f..ec0702be368 100644
> --- a/gcc/config/i386/constraints.md
> +++ b/gcc/config/i386/constraints.md
> @@ -348,6 +348,10 @@ (define_constraint "Z"
> instructions)."
>(match_operand 0 "x86_64_zext_immediate_operand"))
>
> +(define_constraint "Ws"
> + "A constraint that matches an absolute symbolic address."
> + (match_test "ix86_symbolic_address_p (op)"))
> +
>  ;; T prefix is used for different address constraints
>  ;;   v - VSIB address
>  ;;   s - address with no segment register
> diff --git a/gcc/config/i386/i386-protos.h b/gcc/config/i386/i386-protos.h
> index 3596ce81ecf..2b8d063850f 100644
> --- a/gcc/config/i386/i386-protos.h
> +++ b/gcc/config/i386/i386-protos.h
> @@ -337,6 +337,7 @@ extern void x86_output_aligned_bss (FILE *, tree, const 
> char *,
> unsigned HOST_WIDE_INT, unsigned);
>  extern void x86_elf_aligned_decl_common (FILE *, tree, const char *,
>  unsigned HOST_WIDE_INT, unsigned);
> +extern bool ix86_symbolic_address_p (rtx x);
>
>  #ifdef RTX_CODE
>  extern void ix86_fp_comparison_codes (enum rtx_code code, enum rtx_code *,
> diff --git a/gcc/config/i386/i386.cc b/gcc/config/i386/i386.cc
> index 86752a6516a..76728d10c8d 100644
> --- a/gcc/config/i386/i386.cc
> +++ b/gcc/config/i386/i386.cc
> @@ -23956,6 +23956,13 @@ ix86_push_rounding (poly_int64 bytes)
>return ROUND_UP (bytes, UNITS_PER_WORD);
>  }
>
> +bool ix86_symbolic_address_p (rtx x)
> +{
> +  poly_int64 offset;
> +  x = strip_offset (x, &offset);
> +  return SYMBOL_REF_P (x) || LABEL_REF_P (x);
> +}
> +
>  /* Target-specific selftests.  */
>
>  #if CHECKING_P
> diff --git a/gcc/testsuite/gcc.target/i386/pr105576.c 
> b/gcc/testsuite/gcc.target/i386/pr105576.c
> new file mode 100644
> index 000..06dd860d3f3
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/i386/pr105576.c
> @@ -0,0 +1,11 @@
> +/* PR target/105576 */
> +/* { dg-do compile } */
> +/* { dg-options "-O2 -mcmodel=large" } */
> +
> +extern int var;
> +void *addr(void) { return &var; }
> +void addr_via_asm(void)
> +{
> +  asm (".pushsection .xxx,\"aw\"\n\t .dc.a %0\n\t .popsection" :: 
> "Ws"(addr));
> +  asm (".pushsection .xxx,\"aw\"\n\t .dc.a %0\n\t .popsection" :: 
> "Ws"(&var));
> +}
> --
> 2.18.1
>


'include/cuda/cuda.h': For C++, wrap in 'extern "C"' (was: [PATCH] Allow building GCC with PTX offloading even without CUDA being installed (gcc and nvptx-tools patches))

2022-05-18 Thread Thomas Schwinge
Hi!

On 2017-01-13T19:11:23+0100, Jakub Jelinek  wrote:
> cuda.h header included
> in this patch

To make this '#include'able in C++ code, I've pushed to master branch
commit bdd1dc1bfbe1492edf3ce5e4288cfbc55be329ab
"'include/cuda/cuda.h': For C++, wrap in 'extern "C"'", see attached.


Grüße
 Thomas


-
Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 
München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas 
Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht 
München, HRB 106955
>From bdd1dc1bfbe1492edf3ce5e4288cfbc55be329ab Mon Sep 17 00:00:00 2001
From: Thomas Schwinge 
Date: Fri, 29 Apr 2022 10:33:15 +0200
Subject: [PATCH] 'include/cuda/cuda.h': For C++, wrap in 'extern "C"'

	include/
	* cuda/cuda.h: For C++, wrap in 'extern "C"'.
---
 include/cuda/cuda.h | 8 
 1 file changed, 8 insertions(+)

diff --git a/include/cuda/cuda.h b/include/cuda/cuda.h
index 5c813ad2cf8..d7105fb331e 100644
--- a/include/cuda/cuda.h
+++ b/include/cuda/cuda.h
@@ -32,6 +32,10 @@ the proprietary CUDA toolkit.  */
 
 #define CUDA_VERSION 8000
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 typedef void *CUcontext;
 typedef int CUdevice;
 #if defined(__LP64__) || defined(_WIN64)
@@ -191,4 +195,8 @@ CUresult cuStreamQuery (CUstream);
 CUresult cuStreamSynchronize (CUstream);
 CUresult cuStreamWaitEvent (CUstream, CUevent, unsigned);
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /* GCC_CUDA_H */
-- 
2.35.1



'include/cuda/cuda.h': Add parts necessary for nvptx-tools 'nvptx-run' (was: [PATCH] Allow building GCC with PTX offloading even without CUDA being installed (gcc and nvptx-tools patches))

2022-05-18 Thread Thomas Schwinge
Hi!

On 2017-01-13T19:11:23+0100, Jakub Jelinek  wrote:
> cuda.h header included
> in this patch

In order to be able to use that file without changes for
nvptx-tools 'nvptx-run', I've pushed to GCC master branch
commit 86f64400a5692499856d41462461327b93f82b8d
"'include/cuda/cuda.h': Add parts necessary for nvptx-tools 'nvptx-run'",
see attached.


Grüße
 Thomas


-
Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 
München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas 
Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht 
München, HRB 106955
>From 86f64400a5692499856d41462461327b93f82b8d Mon Sep 17 00:00:00 2001
From: Thomas Schwinge 
Date: Fri, 29 Apr 2022 10:44:12 +0200
Subject: [PATCH] 'include/cuda/cuda.h': Add parts necessary for nvptx-tools
 'nvptx-run'

	include/
	* cuda/cuda.h (enum CUjit_option): Add
	'CU_JIT_GENERATE_DEBUG_INFO', 'CU_JIT_GENERATE_LINE_INFO'.
	(enum CUlimit): Add 'CU_LIMIT_STACK_SIZE',
	'CU_LIMIT_MALLOC_HEAP_SIZE'.
	(cuCtxSetLimit, cuGetErrorName): Add.
---
 include/cuda/cuda.h | 11 ++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/include/cuda/cuda.h b/include/cuda/cuda.h
index d7105fb331e..3938d05d150 100644
--- a/include/cuda/cuda.h
+++ b/include/cuda/cuda.h
@@ -97,7 +97,9 @@ typedef enum {
   CU_JIT_ERROR_LOG_BUFFER = 5,
   CU_JIT_ERROR_LOG_BUFFER_SIZE_BYTES = 6,
   CU_JIT_OPTIMIZATION_LEVEL = 7,
-  CU_JIT_LOG_VERBOSE = 12
+  CU_JIT_GENERATE_DEBUG_INFO = 11,
+  CU_JIT_LOG_VERBOSE = 12,
+  CU_JIT_GENERATE_LINE_INFO = 13,
 } CUjit_option;
 
 typedef enum {
@@ -117,6 +119,11 @@ enum {
   CU_STREAM_NON_BLOCKING = 1
 };
 
+typedef enum {
+  CU_LIMIT_STACK_SIZE = 0x00,
+  CU_LIMIT_MALLOC_HEAP_SIZE = 0x02,
+} CUlimit;
+
 #define cuCtxCreate cuCtxCreate_v2
 CUresult cuCtxCreate (CUcontext *, unsigned, CUdevice);
 #define cuCtxDestroy cuCtxDestroy_v2
@@ -128,6 +135,7 @@ CUresult cuCtxPopCurrent (CUcontext *);
 #define cuCtxPushCurrent cuCtxPushCurrent_v2
 CUresult cuCtxPushCurrent (CUcontext);
 CUresult cuCtxSynchronize (void);
+CUresult cuCtxSetLimit (CUlimit, size_t);
 CUresult cuDeviceGet (CUdevice *, int);
 #define cuDeviceTotalMem cuDeviceTotalMem_v2
 CUresult cuDeviceTotalMem (size_t *, CUdevice);
@@ -143,6 +151,7 @@ CUresult cuEventRecord (CUevent, CUstream);
 CUresult cuEventSynchronize (CUevent);
 CUresult cuFuncGetAttribute (int *, CUfunction_attribute, CUfunction);
 CUresult cuGetErrorString (CUresult, const char **);
+CUresult cuGetErrorName (CUresult, const char **);
 CUresult cuInit (unsigned);
 CUresult cuDriverGetVersion (int *);
 CUresult cuLaunchKernel (CUfunction, unsigned, unsigned, unsigned, unsigned,
-- 
2.35.1



Re: [PATCH] c: Implement new -Wenum-int-mismatch warning [PR105131]

2022-05-18 Thread Pedro Alves
On 2022-05-18 00:56, Marek Polacek via Gcc-patches wrote:

> +In C, an enumerated type is compatible with @code{char}, a signed
> +integer type, or an unsigned integer type.  However, since the choice
> +of the underlying type of an enumerated type is implementation-defined,
> +such mismatches may cause portability issues.  In C++, such mismatches
> +are an error.  In C, this warning is enabled by @option{-Wall}.

Should it also be enabled by -Wc++-compat?

Pedro Alves


Re: [PATCH] i386: Add a constraint for absolute symboilc address [PR 105576]

2022-05-18 Thread Hongyu Wang via Gcc-patches
Oh, I just found that asm ("%p0" :: "i"(addr)); also works on
-mcmodel=large in this case, please ignore this patch. Thanks.

Uros Bizjak via Gcc-patches  于2022年5月18日周三 17:46写道:
>
> On Wed, May 18, 2022 at 9:32 AM Hongyu Wang  wrote:
> >
> > Hi,
> >
> > This patch adds a constraint "Ws" to allow absolute symbolic address for 
> > either
> > function or variable. This also works under -mcmodel=large.
> >
> > Bootstrapped/regtested on x86_64-pc-linux-gnu{-m32,}
> >
> > Ok for master?
>
> Maybe you should use:
>
>   asm ("%p0" :: "X"(addr));
>   asm ("%p0" :: "X"(&var));
>
> instead.
>
> Uros.
>
> > gcc/ChangeLog:
> >
> > PR target/105576
> > * config/i386/constraints.md (Ws): New constraint.
> > * config/i386/i386-protos.h (ix86_symbolic_address_p):
> > New proto type.
> > * config/i386/i386.cc (ix86_symbolic_address_p):
> > New function to ensure a rtx is a symbolic address.
> >
> > gcc/testsuite/ChangeLog:
> >
> > PR target/105576
> > * gcc.target/i386/pr105576.c: New test.
> > ---
> >  gcc/config/i386/constraints.md   |  4 
> >  gcc/config/i386/i386-protos.h|  1 +
> >  gcc/config/i386/i386.cc  |  7 +++
> >  gcc/testsuite/gcc.target/i386/pr105576.c | 11 +++
> >  4 files changed, 23 insertions(+)
> >  create mode 100644 gcc/testsuite/gcc.target/i386/pr105576.c
> >
> > diff --git a/gcc/config/i386/constraints.md b/gcc/config/i386/constraints.md
> > index 7361687632f..ec0702be368 100644
> > --- a/gcc/config/i386/constraints.md
> > +++ b/gcc/config/i386/constraints.md
> > @@ -348,6 +348,10 @@ (define_constraint "Z"
> > instructions)."
> >(match_operand 0 "x86_64_zext_immediate_operand"))
> >
> > +(define_constraint "Ws"
> > + "A constraint that matches an absolute symbolic address."
> > + (match_test "ix86_symbolic_address_p (op)"))
> > +
> >  ;; T prefix is used for different address constraints
> >  ;;   v - VSIB address
> >  ;;   s - address with no segment register
> > diff --git a/gcc/config/i386/i386-protos.h b/gcc/config/i386/i386-protos.h
> > index 3596ce81ecf..2b8d063850f 100644
> > --- a/gcc/config/i386/i386-protos.h
> > +++ b/gcc/config/i386/i386-protos.h
> > @@ -337,6 +337,7 @@ extern void x86_output_aligned_bss (FILE *, tree, const 
> > char *,
> > unsigned HOST_WIDE_INT, unsigned);
> >  extern void x86_elf_aligned_decl_common (FILE *, tree, const char *,
> >  unsigned HOST_WIDE_INT, unsigned);
> > +extern bool ix86_symbolic_address_p (rtx x);
> >
> >  #ifdef RTX_CODE
> >  extern void ix86_fp_comparison_codes (enum rtx_code code, enum rtx_code *,
> > diff --git a/gcc/config/i386/i386.cc b/gcc/config/i386/i386.cc
> > index 86752a6516a..76728d10c8d 100644
> > --- a/gcc/config/i386/i386.cc
> > +++ b/gcc/config/i386/i386.cc
> > @@ -23956,6 +23956,13 @@ ix86_push_rounding (poly_int64 bytes)
> >return ROUND_UP (bytes, UNITS_PER_WORD);
> >  }
> >
> > +bool ix86_symbolic_address_p (rtx x)
> > +{
> > +  poly_int64 offset;
> > +  x = strip_offset (x, &offset);
> > +  return SYMBOL_REF_P (x) || LABEL_REF_P (x);
> > +}
> > +
> >  /* Target-specific selftests.  */
> >
> >  #if CHECKING_P
> > diff --git a/gcc/testsuite/gcc.target/i386/pr105576.c 
> > b/gcc/testsuite/gcc.target/i386/pr105576.c
> > new file mode 100644
> > index 000..06dd860d3f3
> > --- /dev/null
> > +++ b/gcc/testsuite/gcc.target/i386/pr105576.c
> > @@ -0,0 +1,11 @@
> > +/* PR target/105576 */
> > +/* { dg-do compile } */
> > +/* { dg-options "-O2 -mcmodel=large" } */
> > +
> > +extern int var;
> > +void *addr(void) { return &var; }
> > +void addr_via_asm(void)
> > +{
> > +  asm (".pushsection .xxx,\"aw\"\n\t .dc.a %0\n\t .popsection" :: 
> > "Ws"(addr));
> > +  asm (".pushsection .xxx,\"aw\"\n\t .dc.a %0\n\t .popsection" :: 
> > "Ws"(&var));
> > +}
> > --
> > 2.18.1
> >


Re: [PATCH] i386: Add a constraint for absolute symboilc address [PR 105576]

2022-05-18 Thread Uros Bizjak via Gcc-patches
On Wed, May 18, 2022 at 12:14 PM Hongyu Wang  wrote:
>
> Oh, I just found that asm ("%p0" :: "i"(addr)); also works on
> -mcmodel=large in this case, please ignore this patch. Thanks.

-fpic will break compilation with "i" constraint.

Uros.

>
> Uros Bizjak via Gcc-patches  于2022年5月18日周三 17:46写道:
> >
> > On Wed, May 18, 2022 at 9:32 AM Hongyu Wang  wrote:
> > >
> > > Hi,
> > >
> > > This patch adds a constraint "Ws" to allow absolute symbolic address for 
> > > either
> > > function or variable. This also works under -mcmodel=large.
> > >
> > > Bootstrapped/regtested on x86_64-pc-linux-gnu{-m32,}
> > >
> > > Ok for master?
> >
> > Maybe you should use:
> >
> >   asm ("%p0" :: "X"(addr));
> >   asm ("%p0" :: "X"(&var));
> >
> > instead.
> >
> > Uros.
> >
> > > gcc/ChangeLog:
> > >
> > > PR target/105576
> > > * config/i386/constraints.md (Ws): New constraint.
> > > * config/i386/i386-protos.h (ix86_symbolic_address_p):
> > > New proto type.
> > > * config/i386/i386.cc (ix86_symbolic_address_p):
> > > New function to ensure a rtx is a symbolic address.
> > >
> > > gcc/testsuite/ChangeLog:
> > >
> > > PR target/105576
> > > * gcc.target/i386/pr105576.c: New test.
> > > ---
> > >  gcc/config/i386/constraints.md   |  4 
> > >  gcc/config/i386/i386-protos.h|  1 +
> > >  gcc/config/i386/i386.cc  |  7 +++
> > >  gcc/testsuite/gcc.target/i386/pr105576.c | 11 +++
> > >  4 files changed, 23 insertions(+)
> > >  create mode 100644 gcc/testsuite/gcc.target/i386/pr105576.c
> > >
> > > diff --git a/gcc/config/i386/constraints.md 
> > > b/gcc/config/i386/constraints.md
> > > index 7361687632f..ec0702be368 100644
> > > --- a/gcc/config/i386/constraints.md
> > > +++ b/gcc/config/i386/constraints.md
> > > @@ -348,6 +348,10 @@ (define_constraint "Z"
> > > instructions)."
> > >(match_operand 0 "x86_64_zext_immediate_operand"))
> > >
> > > +(define_constraint "Ws"
> > > + "A constraint that matches an absolute symbolic address."
> > > + (match_test "ix86_symbolic_address_p (op)"))
> > > +
> > >  ;; T prefix is used for different address constraints
> > >  ;;   v - VSIB address
> > >  ;;   s - address with no segment register
> > > diff --git a/gcc/config/i386/i386-protos.h b/gcc/config/i386/i386-protos.h
> > > index 3596ce81ecf..2b8d063850f 100644
> > > --- a/gcc/config/i386/i386-protos.h
> > > +++ b/gcc/config/i386/i386-protos.h
> > > @@ -337,6 +337,7 @@ extern void x86_output_aligned_bss (FILE *, tree, 
> > > const char *,
> > > unsigned HOST_WIDE_INT, unsigned);
> > >  extern void x86_elf_aligned_decl_common (FILE *, tree, const char *,
> > >  unsigned HOST_WIDE_INT, 
> > > unsigned);
> > > +extern bool ix86_symbolic_address_p (rtx x);
> > >
> > >  #ifdef RTX_CODE
> > >  extern void ix86_fp_comparison_codes (enum rtx_code code, enum rtx_code 
> > > *,
> > > diff --git a/gcc/config/i386/i386.cc b/gcc/config/i386/i386.cc
> > > index 86752a6516a..76728d10c8d 100644
> > > --- a/gcc/config/i386/i386.cc
> > > +++ b/gcc/config/i386/i386.cc
> > > @@ -23956,6 +23956,13 @@ ix86_push_rounding (poly_int64 bytes)
> > >return ROUND_UP (bytes, UNITS_PER_WORD);
> > >  }
> > >
> > > +bool ix86_symbolic_address_p (rtx x)
> > > +{
> > > +  poly_int64 offset;
> > > +  x = strip_offset (x, &offset);
> > > +  return SYMBOL_REF_P (x) || LABEL_REF_P (x);
> > > +}
> > > +
> > >  /* Target-specific selftests.  */
> > >
> > >  #if CHECKING_P
> > > diff --git a/gcc/testsuite/gcc.target/i386/pr105576.c 
> > > b/gcc/testsuite/gcc.target/i386/pr105576.c
> > > new file mode 100644
> > > index 000..06dd860d3f3
> > > --- /dev/null
> > > +++ b/gcc/testsuite/gcc.target/i386/pr105576.c
> > > @@ -0,0 +1,11 @@
> > > +/* PR target/105576 */
> > > +/* { dg-do compile } */
> > > +/* { dg-options "-O2 -mcmodel=large" } */
> > > +
> > > +extern int var;
> > > +void *addr(void) { return &var; }
> > > +void addr_via_asm(void)
> > > +{
> > > +  asm (".pushsection .xxx,\"aw\"\n\t .dc.a %0\n\t .popsection" :: 
> > > "Ws"(addr));
> > > +  asm (".pushsection .xxx,\"aw\"\n\t .dc.a %0\n\t .popsection" :: 
> > > "Ws"(&var));
> > > +}
> > > --
> > > 2.18.1
> > >


Re: [PATCH] i386: Add a constraint for absolute symboilc address [PR 105576]

2022-05-18 Thread Hongyu Wang via Gcc-patches
> -fpic will break compilation with "i" constraint.

Ah, yes. But "X" is like no constraint, shouldn't we provide something
similar to "S" in aarch64 and riscv?
I think it is better to constrain the operand to constant symbols
rather than allowing everything.

Uros Bizjak  于2022年5月18日周三 18:18写道:
>
> On Wed, May 18, 2022 at 12:14 PM Hongyu Wang  wrote:
> >
> > Oh, I just found that asm ("%p0" :: "i"(addr)); also works on
> > -mcmodel=large in this case, please ignore this patch. Thanks.
>
> -fpic will break compilation with "i" constraint.
>
> Uros.
>
> >
> > Uros Bizjak via Gcc-patches  于2022年5月18日周三 17:46写道:
> > >
> > > On Wed, May 18, 2022 at 9:32 AM Hongyu Wang  wrote:
> > > >
> > > > Hi,
> > > >
> > > > This patch adds a constraint "Ws" to allow absolute symbolic address 
> > > > for either
> > > > function or variable. This also works under -mcmodel=large.
> > > >
> > > > Bootstrapped/regtested on x86_64-pc-linux-gnu{-m32,}
> > > >
> > > > Ok for master?
> > >
> > > Maybe you should use:
> > >
> > >   asm ("%p0" :: "X"(addr));
> > >   asm ("%p0" :: "X"(&var));
> > >
> > > instead.
> > >
> > > Uros.
> > >
> > > > gcc/ChangeLog:
> > > >
> > > > PR target/105576
> > > > * config/i386/constraints.md (Ws): New constraint.
> > > > * config/i386/i386-protos.h (ix86_symbolic_address_p):
> > > > New proto type.
> > > > * config/i386/i386.cc (ix86_symbolic_address_p):
> > > > New function to ensure a rtx is a symbolic address.
> > > >
> > > > gcc/testsuite/ChangeLog:
> > > >
> > > > PR target/105576
> > > > * gcc.target/i386/pr105576.c: New test.
> > > > ---
> > > >  gcc/config/i386/constraints.md   |  4 
> > > >  gcc/config/i386/i386-protos.h|  1 +
> > > >  gcc/config/i386/i386.cc  |  7 +++
> > > >  gcc/testsuite/gcc.target/i386/pr105576.c | 11 +++
> > > >  4 files changed, 23 insertions(+)
> > > >  create mode 100644 gcc/testsuite/gcc.target/i386/pr105576.c
> > > >
> > > > diff --git a/gcc/config/i386/constraints.md 
> > > > b/gcc/config/i386/constraints.md
> > > > index 7361687632f..ec0702be368 100644
> > > > --- a/gcc/config/i386/constraints.md
> > > > +++ b/gcc/config/i386/constraints.md
> > > > @@ -348,6 +348,10 @@ (define_constraint "Z"
> > > > instructions)."
> > > >(match_operand 0 "x86_64_zext_immediate_operand"))
> > > >
> > > > +(define_constraint "Ws"
> > > > + "A constraint that matches an absolute symbolic address."
> > > > + (match_test "ix86_symbolic_address_p (op)"))
> > > > +
> > > >  ;; T prefix is used for different address constraints
> > > >  ;;   v - VSIB address
> > > >  ;;   s - address with no segment register
> > > > diff --git a/gcc/config/i386/i386-protos.h 
> > > > b/gcc/config/i386/i386-protos.h
> > > > index 3596ce81ecf..2b8d063850f 100644
> > > > --- a/gcc/config/i386/i386-protos.h
> > > > +++ b/gcc/config/i386/i386-protos.h
> > > > @@ -337,6 +337,7 @@ extern void x86_output_aligned_bss (FILE *, tree, 
> > > > const char *,
> > > > unsigned HOST_WIDE_INT, unsigned);
> > > >  extern void x86_elf_aligned_decl_common (FILE *, tree, const char *,
> > > >  unsigned HOST_WIDE_INT, 
> > > > unsigned);
> > > > +extern bool ix86_symbolic_address_p (rtx x);
> > > >
> > > >  #ifdef RTX_CODE
> > > >  extern void ix86_fp_comparison_codes (enum rtx_code code, enum 
> > > > rtx_code *,
> > > > diff --git a/gcc/config/i386/i386.cc b/gcc/config/i386/i386.cc
> > > > index 86752a6516a..76728d10c8d 100644
> > > > --- a/gcc/config/i386/i386.cc
> > > > +++ b/gcc/config/i386/i386.cc
> > > > @@ -23956,6 +23956,13 @@ ix86_push_rounding (poly_int64 bytes)
> > > >return ROUND_UP (bytes, UNITS_PER_WORD);
> > > >  }
> > > >
> > > > +bool ix86_symbolic_address_p (rtx x)
> > > > +{
> > > > +  poly_int64 offset;
> > > > +  x = strip_offset (x, &offset);
> > > > +  return SYMBOL_REF_P (x) || LABEL_REF_P (x);
> > > > +}
> > > > +
> > > >  /* Target-specific selftests.  */
> > > >
> > > >  #if CHECKING_P
> > > > diff --git a/gcc/testsuite/gcc.target/i386/pr105576.c 
> > > > b/gcc/testsuite/gcc.target/i386/pr105576.c
> > > > new file mode 100644
> > > > index 000..06dd860d3f3
> > > > --- /dev/null
> > > > +++ b/gcc/testsuite/gcc.target/i386/pr105576.c
> > > > @@ -0,0 +1,11 @@
> > > > +/* PR target/105576 */
> > > > +/* { dg-do compile } */
> > > > +/* { dg-options "-O2 -mcmodel=large" } */
> > > > +
> > > > +extern int var;
> > > > +void *addr(void) { return &var; }
> > > > +void addr_via_asm(void)
> > > > +{
> > > > +  asm (".pushsection .xxx,\"aw\"\n\t .dc.a %0\n\t .popsection" :: 
> > > > "Ws"(addr));
> > > > +  asm (".pushsection .xxx,\"aw\"\n\t .dc.a %0\n\t .popsection" :: 
> > > > "Ws"(&var));
> > > > +}
> > > > --
> > > > 2.18.1
> > > >


[2/9] ARM changes to adjust vec_perm_const hook

2022-05-18 Thread Prathamesh Kulkarni via Gcc-patches
Hi,
The attached patch adjusts vec_perm_const hook to accommodate the new parameter.
For rationale, please see:
https://gcc.gnu.org/pipermail/gcc-patches/2022-May/595128.html
OK to commit if bootstrap+test passes ?

Thanks,
Prathamesh
diff --git a/gcc/config/arm/arm.cc b/gcc/config/arm/arm.cc
index 2afe0445ed5..48759532ab3 100644
--- a/gcc/config/arm/arm.cc
+++ b/gcc/config/arm/arm.cc
@@ -31813,9 +31813,12 @@ arm_expand_vec_perm_const_1 (struct expand_vec_perm_d 
*d)
 /* Implement TARGET_VECTORIZE_VEC_PERM_CONST.  */
 
 static bool
-arm_vectorize_vec_perm_const (machine_mode vmode, rtx target, rtx op0, rtx op1,
- const vec_perm_indices &sel)
+arm_vectorize_vec_perm_const (machine_mode vmode, machine_mode op_mode, rtx 
target,
+ rtx op0, rtx op1, const vec_perm_indices &sel)
 {
+  if (vmode != op_mode)
+return false;
+
   struct expand_vec_perm_d d;
   int i, nelt, which;
 


[3/9] i386 changes to adjust vec_perm_const hook

2022-05-18 Thread Prathamesh Kulkarni via Gcc-patches
Hi,
The attached patch adjusts vec_perm_const hook to accommodate the new parameter.
For rationale, please see:
https://gcc.gnu.org/pipermail/gcc-patches/2022-May/595128.html
Bootstrapped+tested on x86_64-linux-gnu.
OK to commit ?

Thanks,
Prathamesh
diff --git a/gcc/config/i386/i386-expand.cc b/gcc/config/i386/i386-expand.cc
index 806e1f5aaa3..87f02d62338 100644
--- a/gcc/config/i386/i386-expand.cc
+++ b/gcc/config/i386/i386-expand.cc
@@ -22060,9 +22060,12 @@ canonicalize_perm (struct expand_vec_perm_d *d)
 /* Implement TARGET_VECTORIZE_VEC_PERM_CONST.  */
 
 bool
-ix86_vectorize_vec_perm_const (machine_mode vmode, rtx target, rtx op0,
-  rtx op1, const vec_perm_indices &sel)
+ix86_vectorize_vec_perm_const (machine_mode vmode, machine_mode op_mode, rtx 
target,
+  rtx op0, rtx op1, const vec_perm_indices &sel)
 {
+  if (vmode != op_mode)
+return false;
+
   struct expand_vec_perm_d d;
   unsigned char perm[MAX_VECT_LEN];
   unsigned int i, nelt, which;
diff --git a/gcc/config/i386/i386-expand.h b/gcc/config/i386/i386-expand.h
index 9d320c29552..6c650196c9c 100644
--- a/gcc/config/i386/i386-expand.h
+++ b/gcc/config/i386/i386-expand.h
@@ -48,8 +48,9 @@ rtx gen_push (rtx arg);
 rtx gen_pop (rtx arg);
 rtx ix86_expand_builtin (tree exp, rtx target, rtx subtarget,
 machine_mode mode, int ignore);
-bool ix86_vectorize_vec_perm_const (machine_mode vmode, rtx target, rtx op0,
-   rtx op1, const vec_perm_indices &sel);
+bool ix86_vectorize_vec_perm_const (machine_mode vmode, machine_mode op_mode,
+   rtx target, rtx op0, rtx op1,
+   const vec_perm_indices &sel);
 bool ix86_notrack_prefixed_insn_p (rtx_insn *);
 machine_mode ix86_split_reduction (machine_mode mode);
 void ix86_expand_divmod_libfunc (rtx libfunc, machine_mode mode, rtx op0,
diff --git a/gcc/config/i386/sse.md b/gcc/config/i386/sse.md
index 175ce013e5d..50112a8efee 100644
--- a/gcc/config/i386/sse.md
+++ b/gcc/config/i386/sse.md
@@ -15836,7 +15836,7 @@
  sel[7] = 15;
}
  vec_perm_indices indices (sel, 2, 8);
- bool ok = targetm.vectorize.vec_perm_const (V8SImode, target,
+ bool ok = targetm.vectorize.vec_perm_const (V8SImode, V8SImode, 
target,
  arg0, arg1, indices);
  gcc_assert (ok);
  emit_move_insn (operands[0],
@@ -24569,7 +24569,7 @@
  sel[3] = 7;
}
  vec_perm_indices indices (sel, arg0 != arg1 ? 2 : 1, 4);
- bool ok = targetm.vectorize.vec_perm_const (V4SImode, target,
+ bool ok = targetm.vectorize.vec_perm_const (V4SImode, V4SImode, 
target,
  arg0, arg1, indices);
  gcc_assert (ok);
  emit_move_insn (operands[0],


[4/9] rs6000 changes to vec_perm_const hook.

2022-05-18 Thread Prathamesh Kulkarni via Gcc-patches
Hi,
The attached patch adjusts vec_perm_const hook to accommodate the new parameter.
For rationale, please see:
https://gcc.gnu.org/pipermail/gcc-patches/2022-May/595128.html
OK to commit if bootstrap+test passes ?

Thanks,
Prathamesh
diff --git a/gcc/config/rs6000/rs6000.cc b/gcc/config/rs6000/rs6000.cc
index d4defc855d0..8c87101692a 100644
--- a/gcc/config/rs6000/rs6000.cc
+++ b/gcc/config/rs6000/rs6000.cc
@@ -23294,9 +23294,12 @@ rs6000_expand_vec_perm_const_1 (rtx target, rtx op0, 
rtx op1,
 /* Implement TARGET_VECTORIZE_VEC_PERM_CONST.  */
 
 static bool
-rs6000_vectorize_vec_perm_const (machine_mode vmode, rtx target, rtx op0,
-rtx op1, const vec_perm_indices &sel)
+rs6000_vectorize_vec_perm_const (machine_mode vmode, rtx op_mode, rtx target,
+rtx op0, rtx op1, const vec_perm_indices &sel)
 {
+  if (vmode != op_mode)
+return false;
+
   bool testing_p = !target;
 
   /* AltiVec (and thus VSX) can handle arbitrary permutations.  */


[5/9] mips changes to adjust vec_perm_const hook

2022-05-18 Thread Prathamesh Kulkarni via Gcc-patches
Hi,
The attached patch adjusts vec_perm_const hook to accommodate the new parameter.
For rationale, please see:
https://gcc.gnu.org/pipermail/gcc-patches/2022-May/595128.html

Unfortunately, I am not sure how to cross test this patch.
make all-gcc stage-1 seems to build fine.
Is it OK to commit the patch ?

Thanks,
Prathamesh
diff --git a/gcc/config/mips/mips.cc b/gcc/config/mips/mips.cc
index e64928f4113..5eb845960e1 100644
--- a/gcc/config/mips/mips.cc
+++ b/gcc/config/mips/mips.cc
@@ -21790,9 +21790,13 @@ mips_expand_vec_perm_const_1 (struct expand_vec_perm_d 
*d)
 /* Implement TARGET_VECTORIZE_VEC_PERM_CONST.  */
 
 static bool
-mips_vectorize_vec_perm_const (machine_mode vmode, rtx target, rtx op0,
-  rtx op1, const vec_perm_indices &sel)
+mips_vectorize_vec_perm_const (machine_mode vmode, machine_mode op_mode,
+  rtx target, rtx op0, rtx op1,
+  const vec_perm_indices &sel)
 {
+  if (vmode != op_mode)
+return false;
+
   struct expand_vec_perm_d d;
   int i, nelt, which;
   unsigned char orig_perm[MAX_VECT_LEN];


[6/9] sparc changes to adjust vec_perm_const hook

2022-05-18 Thread Prathamesh Kulkarni via Gcc-patches
Hi,
The attached patch adjusts vec_perm_const hook to accommodate the new parameter.
For rationale, please see:
https://gcc.gnu.org/pipermail/gcc-patches/2022-May/595128.html

Unfortunately, I am not sure how to cross test this patch.
make all-gcc stage-1 seems to build fine.
Is it OK to commit the patch ?

Thanks,
Prathamesh
diff --git a/gcc/config/sparc/sparc.cc b/gcc/config/sparc/sparc.cc
index aca925befe1..7e08e86422a 100644
--- a/gcc/config/sparc/sparc.cc
+++ b/gcc/config/sparc/sparc.cc
@@ -712,8 +712,8 @@ static bool sparc_modes_tieable_p (machine_mode, 
machine_mode);
 static bool sparc_can_change_mode_class (machine_mode, machine_mode,
 reg_class_t);
 static HOST_WIDE_INT sparc_constant_alignment (const_tree, HOST_WIDE_INT);
-static bool sparc_vectorize_vec_perm_const (machine_mode, rtx, rtx, rtx,
-   const vec_perm_indices &);
+static bool sparc_vectorize_vec_perm_const (machine_mode, machine_mode, rtx, 
rtx,
+   rtx, const vec_perm_indices &);
 static bool sparc_can_follow_jump (const rtx_insn *, const rtx_insn *);
 static HARD_REG_SET sparc_zero_call_used_regs (HARD_REG_SET);
 
@@ -13035,9 +13035,13 @@ sparc_expand_vec_perm_bmask (machine_mode vmode, rtx 
sel)
 /* Implement TARGET_VEC_PERM_CONST.  */
 
 static bool
-sparc_vectorize_vec_perm_const (machine_mode vmode, rtx target, rtx op0,
-   rtx op1, const vec_perm_indices &sel)
+sparc_vectorize_vec_perm_const (machine_mode vmode, machine_mode op_mode,
+   rtx target, rtx op0, rtx op1,
+   const vec_perm_indices &sel)
 {
+  if (vmode != op_mode)
+return false;
+
   if (!TARGET_VIS2)
 return false;
 


[7/9] ia64 changes to adjust vec_perm_const hook

2022-05-18 Thread Prathamesh Kulkarni via Gcc-patches
Hi,
The attached patch adjusts vec_perm_const hook to accommodate the new parameter.
For rationale, please see:
https://gcc.gnu.org/pipermail/gcc-patches/2022-May/595128.html

Unfortunately, I am not sure how to cross test this patch.
make all-gcc stage-1 seems to build fine.
Is it OK to commit the patch ?

Thanks,
Prathamesh
diff --git a/gcc/config/ia64/ia64.cc b/gcc/config/ia64/ia64.cc
index f9fb681a36c..25e4a47e363 100644
--- a/gcc/config/ia64/ia64.cc
+++ b/gcc/config/ia64/ia64.cc
@@ -332,8 +332,8 @@ static fixed_size_mode ia64_get_reg_raw_mode (int regno);
 static section * ia64_hpux_function_section (tree, enum node_frequency,
 bool, bool);
 
-static bool ia64_vectorize_vec_perm_const (machine_mode, rtx, rtx, rtx,
-  const vec_perm_indices &);
+static bool ia64_vectorize_vec_perm_const (machine_mode, machine_mode, rtx,
+  rtx, rtx, const vec_perm_indices &);
 
 static unsigned int ia64_hard_regno_nregs (unsigned int, machine_mode);
 static bool ia64_hard_regno_mode_ok (unsigned int, machine_mode);
@@ -11751,9 +11751,13 @@ ia64_expand_vec_perm_const_1 (struct expand_vec_perm_d 
*d)
 /* Implement TARGET_VECTORIZE_VEC_PERM_CONST.  */
 
 static bool
-ia64_vectorize_vec_perm_const (machine_mode vmode, rtx target, rtx op0,
-  rtx op1, const vec_perm_indices &sel)
+ia64_vectorize_vec_perm_const (machine_mode vmode, machine_mode op_mode,
+  rtx target, rtx op0, rtx op1,
+  const vec_perm_indices &sel)
 {
+  if (vmode != op_mode)
+return false;
+
   struct expand_vec_perm_d d;
   unsigned char perm[MAX_VECT_LEN];
   unsigned int i, nelt, which;


[8/9] s390 changes to adjust vec_perm_const hook

2022-05-18 Thread Prathamesh Kulkarni via Gcc-patches
Hi,
The attached patch adjusts vec_perm_const hook to accommodate the new parameter.
For rationale, please see:
https://gcc.gnu.org/pipermail/gcc-patches/2022-May/595128.html

Unfortunately, I am not sure how to cross test this patch.
make all-gcc stage-1 seems to build fine.
Is it OK to commit the patch ?

Thanks,
Prathamesh
diff --git a/gcc/config/s390/s390.cc b/gcc/config/s390/s390.cc
index 45bbb6c3d70..e46566c526c 100644
--- a/gcc/config/s390/s390.cc
+++ b/gcc/config/s390/s390.cc
@@ -17175,9 +17175,12 @@ vectorize_vec_perm_const_1 (const struct 
expand_vec_perm_d &d)
hook is supposed to emit the required INSNs.  */
 
 bool
-s390_vectorize_vec_perm_const (machine_mode vmode, rtx target, rtx op0, rtx 
op1,
-  const vec_perm_indices &sel)
+s390_vectorize_vec_perm_const (machine_mode vmode, machine_mode op_mode, rtx 
target,
+  rtx op0, rtx op1, const vec_perm_indices &sel)
 {
+  if (vmode != op_mode)
+return false;
+
   struct expand_vec_perm_d d;
   unsigned int i, nelt;
 


demangler: Reorganize for module demangling

2022-05-18 Thread Nathan Sidwell
Module demangling requires some changes in how substitutions are 
handled.  This adjusts things to make that possible, these are similar 
changes to that made in the the llvm demangler.


nathan
--
Nathan SidwellFrom 65851d65fb36e847a9b8ef3b0519f06d29865a14 Mon Sep 17 00:00:00 2001
From: Nathan Sidwell 
Date: Tue, 8 Mar 2022 10:53:39 -0800
Subject: [PATCH] demangler: Reorganize for module demangling

Module demangling requires some changes in how substitutions are
handled.  This adjusts things to make that possible.

	libiberty/
	* cp-demangle.c (d_name): Add SUBSTABLE parameter,
	push substitution if requested. Adjust unscoped name handling.
	(d_prefix): Reorder main loop. Adjust all calls.
	(d_unqualified_name): Add SCOPE parameter, create qualified
	name here. Adjust all calls.
	(cplus_demangle_type): Do not handle 'S' here, leave all
	to d_class_enum_type.
	(d_class_enum_type): Add SUBSTABLE parameter.
---
 libiberty/cp-demangle.c | 224 +++-
 1 file changed, 84 insertions(+), 140 deletions(-)

diff --git a/libiberty/cp-demangle.c b/libiberty/cp-demangle.c
index fc618fa7383..cf451c5aff2 100644
--- a/libiberty/cp-demangle.c
+++ b/libiberty/cp-demangle.c
@@ -425,13 +425,14 @@ is_ctor_dtor_or_conversion (struct demangle_component *);
 
 static struct demangle_component *d_encoding (struct d_info *, int);
 
-static struct demangle_component *d_name (struct d_info *);
+static struct demangle_component *d_name (struct d_info *, int substable);
 
 static struct demangle_component *d_nested_name (struct d_info *);
 
 static struct demangle_component *d_prefix (struct d_info *, int);
 
-static struct demangle_component *d_unqualified_name (struct d_info *);
+static struct demangle_component *d_unqualified_name (struct d_info *,
+		  struct demangle_component *scope);
 
 static struct demangle_component *d_source_name (struct d_info *);
 
@@ -462,7 +463,7 @@ static struct demangle_component *
 d_bare_function_type (struct d_info *, int);
 
 static struct demangle_component *
-d_class_enum_type (struct d_info *);
+d_class_enum_type (struct d_info *, int);
 
 static struct demangle_component *d_array_type (struct d_info *);
 
@@ -1323,7 +1324,7 @@ d_encoding (struct d_info *di, int top_level)
 dc = d_special_name (di);
   else
 {
-  dc = d_name (di);
+  dc = d_name (di, 0);
 
   if (!dc)
 	/* Failed already.  */;
@@ -1417,80 +1418,64 @@ d_abi_tags (struct d_info *di, struct demangle_component *dc)
 */
 
 static struct demangle_component *
-d_name (struct d_info *di)
+d_name (struct d_info *di, int substable)
 {
   char peek = d_peek_char (di);
-  struct demangle_component *dc;
+  struct demangle_component *dc = NULL;
+  int subst = 0;
 
   switch (peek)
 {
 case 'N':
-  return d_nested_name (di);
+  dc = d_nested_name (di);
+  break;
 
 case 'Z':
-  return d_local_name (di);
+  dc = d_local_name (di);
+  break;
 
 case 'U':
-  return d_unqualified_name (di);
+  dc = d_unqualified_name (di, NULL);
+  break;
 
 case 'S':
   {
-	int subst;
-
-	if (d_peek_next_char (di) != 't')
-	  {
-	dc = d_substitution (di, 0);
-	subst = 1;
-	  }
-	else
+	if (d_peek_next_char (di) == 't')
 	  {
 	d_advance (di, 2);
-	dc = d_make_comp (di, DEMANGLE_COMPONENT_QUAL_NAME,
-			  d_make_name (di, "std", 3),
-			  d_unqualified_name (di));
+	dc = d_make_name (di, "std", 3);
 	di->expansion += 3;
-	subst = 0;
-	  }
-
-	if (d_peek_char (di) != 'I')
-	  {
-	/* The grammar does not permit this case to occur if we
-	   called d_substitution() above (i.e., subst == 1).  We
-	   don't bother to check.  */
 	  }
 	else
 	  {
-	/* This is , which means that we just saw
-	   , which is a substitution
-	   candidate if we didn't just get it from a
-	   substitution.  */
-	if (! subst)
-	  {
-		if (! d_add_substitution (di, dc))
-		  return NULL;
-	  }
-	dc = d_make_comp (di, DEMANGLE_COMPONENT_TEMPLATE, dc,
-			  d_template_args (di));
+	dc = d_substitution (di, 0);
+	if (!dc)
+	  return NULL;
+	subst = 1;
 	  }
-
-	return dc;
   }
+  /* FALLTHROUGH */
 
 case 'L':
 default:
-  dc = d_unqualified_name (di);
+  if (!subst)
+	dc = d_unqualified_name (di, dc);
   if (d_peek_char (di) == 'I')
 	{
 	  /* This is , which means that we just saw
 	 , which is a substitution
 	 candidate.  */
-	  if (! d_add_substitution (di, dc))
+	  if (!subst && !d_add_substitution (di, dc))
 	return NULL;
 	  dc = d_make_comp (di, DEMANGLE_COMPONENT_TEMPLATE, dc,
 			d_template_args (di));
+	  subst = 0;
 	}
-  return dc;
+  break;
 }
+  if (substable && !subst && !d_add_substitution (di, dc))
+return NULL;
+  return dc;
 }
 
 /*  ::= N [] []   E
@@ -1546,54 +1531,51 @@ d_nested_name (struct d_info *di)
if not (in an unresolved-name).  */
 
 static struct demangle_component *
-d_prefix (st

Re: [0/9] [middle-end] Add param to vec_perm_const hook to specify mode of input operand

2022-05-18 Thread Richard Sandiford via Gcc-patches
Prathamesh Kulkarni  writes:
> Hi,
> The attached patch adds another parameter machine_mode op_mode to 
> vec_perm_const
> hook to specify mode of input operands. The motivation for doing this
> is PR96463,
> where we create vec_perm_expr of the form:
> lhs = vec_perm_expr
> where lhs and rhs have different vector types but same element type
> (lhs is SVE and rhs is corresponding advsimd vector).
>
> It seems the following targets were affected: aarch64, i386, arm, ia64,
> mips, rs6000, s390, sparc, gcn.
>
> Bootstrapped+tested on x86_64-linux-gnu, aarch64-linux-gnu.
> For other targets, I did make all-gcc stage1, which seems to build OK.
>
> Thanks,
> Prathamesh
>
> diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi
> index c5006afc00d..31ff6ef3f92 100644
> --- a/gcc/doc/tm.texi
> +++ b/gcc/doc/tm.texi
> @@ -6088,7 +6088,7 @@ for the given scalar type @var{type}.  @var{is_packed} 
> is false if the scalar
>  access using @var{type} is known to be naturally aligned.
>  @end deftypefn
>  
> -@deftypefn {Target Hook} bool TARGET_VECTORIZE_VEC_PERM_CONST (machine_mode 
> @var{mode}, rtx @var{output}, rtx @var{in0}, rtx @var{in1}, const 
> vec_perm_indices @var{&sel})
> +@deftypefn {Target Hook} bool TARGET_VECTORIZE_VEC_PERM_CONST (machine_mode 
> @var{mode}, machine_mode @var{op_mode}, rtx @var{output}, rtx @var{in0}, rtx 
> @var{in1}, const vec_perm_indices @var{&sel})
>  This hook is used to test whether the target can permute up to two
>  vectors of mode @var{mode} using the permutation vector @code{sel}, and
>  also to emit such a permutation.  In the former case @var{in0}, @var{in1}

Like Andre says, the documentation should describe op_mode (and mode).

> diff --git a/gcc/optabs-query.cc b/gcc/optabs-query.cc
> index 68dc679cc6a..aef9d4c5d28 100644
> --- a/gcc/optabs-query.cc
> +++ b/gcc/optabs-query.cc
> @@ -417,8 +417,8 @@ can_vec_perm_var_p (machine_mode mode)
> with here.  */
>  
>  bool
> -can_vec_perm_const_p (machine_mode mode, const vec_perm_indices &sel,
> -   bool allow_variable_p)
> +can_vec_perm_const_p (machine_mode mode, machine_mode op_mode,
> +   const vec_perm_indices &sel, bool allow_variable_p)
>  {

The function comment should describe the new parameter.

>/* If the target doesn't implement a vector mode for the vector type,
>   then no operations are supported.  */
> @@ -448,7 +448,7 @@ can_vec_perm_const_p (machine_mode mode, const 
> vec_perm_indices &sel,
>  
>if (targetm.vectorize.vec_perm_const != NULL)
>  {
> -  if (targetm.vectorize.vec_perm_const (mode, NULL_RTX, NULL_RTX,
> +  if (targetm.vectorize.vec_perm_const (mode, op_mode, NULL_RTX, 
> NULL_RTX,
>   NULL_RTX, sel))
>   return true;
>  
> @@ -462,6 +462,13 @@ can_vec_perm_const_p (machine_mode mode, const 
> vec_perm_indices &sel,
>return false;
>  }
>  
> +bool
> +can_vec_perm_const_p (machine_mode mode, const vec_perm_indices &sel,
> +   bool allow_variable_p)
> +{
> +  return can_vec_perm_const_p (mode, mode, sel, allow_variable_p);
> +}
> +

I can understand why you went for this, but now that we've opened
the door to mismatched modes, I think it would be better if all callers
specified the input mode explicitly.

> diff --git a/gcc/optabs.cc b/gcc/optabs.cc
> index 3d8fa3abdfe..55f10c41789 100644
> --- a/gcc/optabs.cc
> +++ b/gcc/optabs.cc
> @@ -6250,7 +6250,9 @@ expand_vec_perm_const (machine_mode mode, rtx v0, rtx 
> v1,
>if (single_arg_p)
>   v1 = v0;
>  
> -  if (targetm.vectorize.vec_perm_const (mode, target, v0, v1, indices))
> +  gcc_checking_assert (GET_MODE (v0) == GET_MODE (v1));
> +  machine_mode op_mode = GET_MODE (v0);
> +  if (targetm.vectorize.vec_perm_const (mode, op_mode, target, v0, v1, 
> indices))
>   return target;
>  }
>  

(FWIW, I agree the assert is worth having.)

Thanks,
Richard

> @@ -6264,7 +6266,7 @@ expand_vec_perm_const (machine_mode mode, rtx v0, rtx 
> v1,
>v0_qi = gen_lowpart (qimode, v0);
>v1_qi = gen_lowpart (qimode, v1);
>if (targetm.vectorize.vec_perm_const != NULL
> -   && targetm.vectorize.vec_perm_const (qimode, target_qi, v0_qi,
> +   && targetm.vectorize.vec_perm_const (qimode, qimode, target_qi, v0_qi,
>  v1_qi, qimode_indices))
>   return gen_lowpart (mode, target_qi);
>  }
> diff --git a/gcc/target.def b/gcc/target.def
> index d85adf36a39..2713c31dc3f 100644
> --- a/gcc/target.def
> +++ b/gcc/target.def
> @@ -1894,7 +1894,7 @@ try the equivalent byte operation.  If that also fails, 
> it will try forcing\n\
>  the selector into a register and using the @var{vec_perm@var{mode}}\n\
>  instruction pattern.  There is no need for the hook to handle these two\n\
>  implementation approaches itself.",
> - bool, (machine_mode mode, rtx output, rtx in0, rtx in1,
> + bool, (machine_mode mode, machine_mode op_mode, rtx output, rtx in0, rtx 
>

Re: [1/9] AArch64 changes to adjust vec_perm_const hook

2022-05-18 Thread Richard Sandiford via Gcc-patches
Prathamesh Kulkarni  writes:
> Hi,
> The attached patch adjusts vec_perm_const hook to accommodate the new 
> parameter.
> For now, it bails out if vmode != op_mode, in follow-up patch to
> PR96463, I will add dup
> as exception.
> Bootstrapped+tested on aarch64-linux-gnu.
> Does it look OK ?

OK, thanks.

> Thanks,
> Prathamesh
>
> diff --git a/gcc/config/aarch64/aarch64.cc b/gcc/config/aarch64/aarch64.cc
> index f4d2a800f39..e6a24a0f9e1 100644
> --- a/gcc/config/aarch64/aarch64.cc
> +++ b/gcc/config/aarch64/aarch64.cc
> @@ -24145,9 +24145,13 @@ aarch64_expand_vec_perm_const_1 (struct 
> expand_vec_perm_d *d)
>  /* Implement TARGET_VECTORIZE_VEC_PERM_CONST.  */
>  
>  static bool
> -aarch64_vectorize_vec_perm_const (machine_mode vmode, rtx target, rtx op0,
> -   rtx op1, const vec_perm_indices &sel)
> +aarch64_vectorize_vec_perm_const (machine_mode vmode, machine_mode op_mode,
> +   rtx target, rtx op0, rtx op1,
> +   const vec_perm_indices &sel)
>  {
> +  if (vmode != op_mode)
> +return false;
> +
>struct expand_vec_perm_d d;
>  
>/* Check whether the mask can be applied to a single vector.  */


Re: [2/9] ARM changes to adjust vec_perm_const hook

2022-05-18 Thread Richard Sandiford via Gcc-patches
Prathamesh Kulkarni via Gcc-patches  writes:
> Hi,
> The attached patch adjusts vec_perm_const hook to accommodate the new 
> parameter.
> For rationale, please see:
> https://gcc.gnu.org/pipermail/gcc-patches/2022-May/595128.html
> OK to commit if bootstrap+test passes ?
>
> Thanks,
> Prathamesh
>
> diff --git a/gcc/config/arm/arm.cc b/gcc/config/arm/arm.cc
> index 2afe0445ed5..48759532ab3 100644
> --- a/gcc/config/arm/arm.cc
> +++ b/gcc/config/arm/arm.cc
> @@ -31813,9 +31813,12 @@ arm_expand_vec_perm_const_1 (struct 
> expand_vec_perm_d *d)
>  /* Implement TARGET_VECTORIZE_VEC_PERM_CONST.  */
>  
>  static bool
> -arm_vectorize_vec_perm_const (machine_mode vmode, rtx target, rtx op0, rtx 
> op1,
> -   const vec_perm_indices &sel)
> +arm_vectorize_vec_perm_const (machine_mode vmode, machine_mode op_mode, rtx 
> target,

Formatting nit: long line.

Patch is OK with the parameters reflowed, like you did for aarch64.

Same nit for some of the other patches (but some are OK as-is).
OK for 2-8 with that fixed.

Thanks,
Richard

> +   rtx op0, rtx op1, const vec_perm_indices &sel)
>  {
> +  if (vmode != op_mode)
> +return false;
> +
>struct expand_vec_perm_d d;
>int i, nelt, which;
>  


Re: [PATCH] libgompd: Add OMPD support and global ICV functions

2022-05-18 Thread Mohamed Atef via Gcc-patches
On Wed, May 18, 2022 at 9:35 AM Jakub Jelinek  wrote:

> On Mon, May 16, 2022 at 07:35:17PM +0200, Mohamed Atef via Gcc-patches
> wrote:
> > libgomp/ChangeLog
> >
> > 2022-05-15 Mohamed Atef 
> >
> > *config/darwin/plugin-suffix.h (SONAME_SUFFIX): Remove ()s.
> > *config/hpux/plugin-suffix.h (SONAME_SUFFIX): Remove ()s.
> > *config/posix/plugin-suffix.h (SONAME_SUFFIX): Remove ()s.
> > *configure: Regenerate.
> > *Makefile.am (toolexeclib_LTLIBRARIES): Add libgompd.la.
> > (libgompd_la_LDFLAGS, libgompd_la_DEPENDENCIES,
> > libgompd_la_LINK,libgompd_la_SOURCES, libgompd_version_dep,
> > libgompd_version_script, libgompd.ver-sun, libgompd.ver,
> > libgompd_version_info): New.
> > *Makefile.in: Regenerate.
> > *aclocal.m4: Regenerate.
> > *env.c: Include ompd-support.h.
> > (parse_debug): New function.
> > (gompd_enabled): New Variable.
> > (initialize_env): Call gompd_load.
> > (initialize_env): Call parse_debug.
> > *team.c: Include ompd-support.h.
> > (gomp_team_start): Call ompd_bp_parallel_begin.
> > (gomp_team_end): Call ompd_bp_parallel_end.
> > (gomp_thread_start): Call ompd_bp_thread_start.
> > *libgomp.map: ADD OMP_5.0.3 symbol versions.
>
> Add rather than ADD
>
> > *libgompd.map: New.
> > *omp-tools.h.in: New.
> > *ompd-types.h.in: New.
> > *ompd-support.h: New.
> > *ompd-support.c: New.
> > *ompd-helper.h: New.
> > *ompd-helper.c: New.
> > *ompd-init.c: New.
> > *ompd-icv.c: New.
> > *configure.ac (AC_CONFIG_FILES): Add omp-tools.h and ompd-types.h.
>
> Almost ok, minor comments below.
> As I said earlier, as this is just partial implementation of the
> OMPD, I think it would be better to commit it to a git branch but
> already in the upstream repository, say devel/omp/ompd branch.
>
> Do you have a FSF Copyright assignment on file or do you want to
> submit this under DCO (https://gcc.gnu.org/dco.html)?

If the latter, should I remove the header comment?
I mean this part " Copyright (C) 2022 Free Software Foundation, Inc.
  Contributed by Mohamed Atef . "
In fact, I don't know the difference, so which is better for the community?

>   If the latter,
> we need Signed-off-by line in your final patch mail and also in the
> commit message.
> The commit message should include a one line summary, then
> empty line, then explanation what the patch is, followed by properly
> formatted ChangeLog entry (the above is badly mangled by your mailer),
> there should be 2 spaces around the name etc. and after the ChangeLog
> entry the Signed-of-by line if you use DCO.
> More details in https://gcc.gnu.org/gitwrite.html
> In Authenticated access there is a link to a form to request write
> access to the repository, please file it and write me as the sponsor.
> Then follow the rest of gitwrite to e.g. do
> contrib/gcc-git-customization.sh
> and then you can git gcc-verify to verify whether the ChangeLog entry in
> your commit log is ok before you push it.
>
> > --- /dev/null
> > +++ b/libgomp/libgompd.map
> > @@ -0,0 +1,23 @@
> > +OMPD_5.1 {
>
> Shouldn't this be OMPD_5.0 ?
> The functions were already in OpenMP 5.0, weren't they?
>
> > +  global:
> > +ompd_initialize;
> > +ompd_get_api_version;
> > +ompd_get_version_string;
> > +ompd_process_initialize;
> > +ompd_device_initialize;
> > +ompd_rel_address_space_handle;
> > +ompd_finalize;
> > +ompd_enumerate_icvs;
> > +ompd_get_icv_from_scope;
> > +ompd_get_icv_string_from_scope;
> > +ompd_get_thread_handle;
> > +ompd_get_thread_in_parallel;
> > +ompd_rel_thread_handle;
> > +ompd_thread_handle_compare;
> > +ompd_get_thread_id;
> > +ompd_get_device_from_thread;
> > +ompd_bp_thread_begin;
> > +ompd_bp_thread_end;
>
> Why is ompd_bp_thread_{begin,end} here?  I thought they were
> in libgomp.so.*, not in libgompd.so.*
>
> > +  local:
> > +*;
> > +};
>
> > +  /* NO cuda for now.  */
>
> We support other kinds of offloading, so better just say
>   /* No offloading support for now.  */
> or so.
>
> > +  if (device == OMPD_DEVICE_KIND_HOST)
> > +{
> > +  switch (icv_id)
> > + {
> > +   case gompd_icv_cancellation_var:
> > + return
> > +   gompd_get_cancellation ((ompd_address_space_handle_t *)
> handle,
> > +   icv_value);
> > +   case gompd_icv_max_task_priority_var:
> > + return gompd_get_max_task_priority
> ((ompd_address_space_handle_t *)
> > + handle, icv_value);
> > +   case gompd_icv_stacksize_var:
> > + return gompd_get_stacksize ((ompd_address_space_handle_t *)
> handle,
> > + icv_value);
>
> You use that overly long (ompd_address_space_handle_t *) handle in all the
> spots and it causes various formatting issues.  Wouldn't it be better
> to add some temporary variable above the switch
>   ompd_address_space_handle_t *whatever
> = (ompd_address_space_handle_t *) handle;
> (for some good choice of na

Re: [PATCH 15/40] graphite: Extend SCoP detection dump output

2022-05-18 Thread Harwath, Frederik
Hi Richard,

On Tue, 2022-05-17 at 08:21 +, Richard Biener wrote:
> On Mon, 16 May 2022, Tobias Burnus wrote:
>
> > As requested by Richard: Rediffed patch.
> >
> > Changes: s/.c/.cc/ + some whitespace changes.
> > (At least in my email reader, some  were lost. I also fixed
> > too-long line
> > issues.)
> >
> > In addition, FOR_EACH_LOOP was replaced by 'for (auto loop : ...'
> > (macro was removed late in GCC 12 development ? r12-2605-
> > ge41ba804ba5f5c)
> >
> > Otherwise, it should be identical to Frederik's patch, earlier in
> > this thread.
> >
> > On 15.12.21 16:54, Frederik Harwath wrote:
> > > Extend dump output to make understanding why Graphite rejects to
> > > include a loop in a SCoP easier (for GCC developers).
> >
> > OK for mainline?
>
> +  if (printed)
> +fprintf (file, "\b\b");
>
> please find other means of omitting ", ", like by printing it
> _before_ the number but only for the second and following loop
> number.

Done.

>
> I'll also note that
>
> +static void
> +print_sese_loop_numbers (FILE *file, sese_l sese)
> +{
> +  bool printed = false;
> +  for (auto loop : loops_list (cfun, 0))
> +{
> +  if (loop_in_sese_p (loop, sese))
> +   fprintf (file, "%d, ", loop->num);
> +  printed = true;
> +}
>
> is hardly optimal.  Please instead iterate over
> sese.entry->dest->loop_father and children instead which you can do
> by passing that as extra argument to loops_list.

Done.

This had to be extended a little bit, because a SCoP
can consist of consecutive loop-nests and iterating
only over "loops_list (cfun, LI_INCLUDE_ROOT, sese.entry->dest-
>loop_father))" would output only the loops from the first
loop-nest in the SCoP (cf. the test file scop-22a.c that I added).

>
> +
> +  if (dump_file && dump_flags & TDF_DETAILS)
> +{
> +  fprintf (dump_file, "Loops in SCoP: ");
> +  for (auto loop : loops_list (cfun, 0))
> +   if (loop_in_sese_p (loop, s))
> + fprintf (dump_file, "%d ", loop->num);
> +  fprintf (dump_file, "\n");
> +}
>
> you are duplicating functionality of the function you just added ...
>

Fixed.

> Otherwise looks OK to me.

Can I commit the revised patch?

Thanks for your review,
Frederik

-
Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 
München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas 
Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht 
München, HRB 106955
From fb268a37704b1598a84051c735514ff38adad038 Mon Sep 17 00:00:00 2001
From: Frederik Harwath 
Date: Wed, 18 May 2022 07:59:42 +0200
Subject: [PATCH] graphite: Extend SCoP detection dump output

Extend dump output to make understanding why Graphite rejects to
include a loop in a SCoP easier (for GCC developers).

gcc/ChangeLog:

	* graphite-scop-detection.cc (scop_detection::can_represent_loop):
	Output reason for failure to dump file.
	(scop_detection::harmful_loop_in_region): Likewise.
	(scop_detection::graphite_can_represent_expr): Likewise.
	(scop_detection::stmt_has_simple_data_refs_p): Likewise.
	(scop_detection::stmt_simple_for_scop_p): Likewise.
	(print_sese_loop_numbers): New function.
	(scop_detection::add_scop): Use from here.

gcc/testsuite/ChangeLog:

	* gcc.dg/graphite/scop-22a.c: New test.
---
 gcc/graphite-scop-detection.cc   | 184 ---
 gcc/testsuite/gcc.dg/graphite/scop-22a.c |  56 +++
 2 files changed, 219 insertions(+), 21 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/graphite/scop-22a.c

diff --git a/gcc/graphite-scop-detection.cc b/gcc/graphite-scop-detection.cc
index 8c0ee9975579..9792d87ee0ae 100644
--- a/gcc/graphite-scop-detection.cc
+++ b/gcc/graphite-scop-detection.cc
@@ -69,12 +69,27 @@ public:
 fprintf (output.dump_file, "%d", i);
 return output;
   }
+
   friend debug_printer &
   operator<< (debug_printer &output, const char *s)
   {
 fprintf (output.dump_file, "%s", s);
 return output;
   }
+
+  friend debug_printer &
+  operator<< (debug_printer &output, gimple* stmt)
+  {
+print_gimple_stmt (output.dump_file, stmt, 0, TDF_VOPS | TDF_MEMSYMS);
+return output;
+  }
+
+  friend debug_printer &
+  operator<< (debug_printer &output, tree t)
+  {
+print_generic_expr (output.dump_file, t, TDF_SLIM);
+return output;
+  }
 } dp;
 
 #define DEBUG_PRINT(args) do \
@@ -506,6 +521,27 @@ scop_detection::merge_sese (sese_l first, sese_l second) const
   return combined;
 }
 
+/* Print the loop numbers of the loops contained in SESE to FILE. */
+
+static void
+print_sese_loop_numbers (FILE *file, sese_l sese)
+{
+  bool first_loop = true;
+  for (loop_p nest = sese.entry->dest->loop_father; nest; nest = nest->next)
+{
+  if (!loop_in_sese_p (nest, sese))
+break;
+
+  for (auto loop : loops_list (cfun, LI_INCLUDE_ROOT, nest))
+{
+  gcc_assert (loop_in_sese_p (loop, sese));
+
+  fprintf (file, "%s%d", first_loop ? "" : ", ", loop->num);
+  

Re: [PATCH 15/40] graphite: Extend SCoP detection dump output

2022-05-18 Thread Richard Biener via Gcc-patches
On Wed, 18 May 2022, Harwath, Frederik wrote:

> Hi Richard,
> 
> On Tue, 2022-05-17 at 08:21 +, Richard Biener wrote:
> > On Mon, 16 May 2022, Tobias Burnus wrote:
> >
> > > As requested by Richard: Rediffed patch.
> > >
> > > Changes: s/.c/.cc/ + some whitespace changes.
> > > (At least in my email reader, some  were lost. I also fixed
> > > too-long line
> > > issues.)
> > >
> > > In addition, FOR_EACH_LOOP was replaced by 'for (auto loop : ...'
> > > (macro was removed late in GCC 12 development ? r12-2605-
> > > ge41ba804ba5f5c)
> > >
> > > Otherwise, it should be identical to Frederik's patch, earlier in
> > > this thread.
> > >
> > > On 15.12.21 16:54, Frederik Harwath wrote:
> > > > Extend dump output to make understanding why Graphite rejects to
> > > > include a loop in a SCoP easier (for GCC developers).
> > >
> > > OK for mainline?
> >
> > +  if (printed)
> > +fprintf (file, "\b\b");
> >
> > please find other means of omitting ", ", like by printing it
> > _before_ the number but only for the second and following loop
> > number.
> 
> Done.
> 
> >
> > I'll also note that
> >
> > +static void
> > +print_sese_loop_numbers (FILE *file, sese_l sese)
> > +{
> > +  bool printed = false;
> > +  for (auto loop : loops_list (cfun, 0))
> > +{
> > +  if (loop_in_sese_p (loop, sese))
> > +   fprintf (file, "%d, ", loop->num);
> > +  printed = true;
> > +}
> >
> > is hardly optimal.  Please instead iterate over
> > sese.entry->dest->loop_father and children instead which you can do
> > by passing that as extra argument to loops_list.
> 
> Done.
> 
> This had to be extended a little bit, because a SCoP
> can consist of consecutive loop-nests and iterating
> only over "loops_list (cfun, LI_INCLUDE_ROOT, sese.entry->dest-
> >loop_father))" would output only the loops from the first
> loop-nest in the SCoP (cf. the test file scop-22a.c that I added).
> 
> >
> > +
> > +  if (dump_file && dump_flags & TDF_DETAILS)
> > +{
> > +  fprintf (dump_file, "Loops in SCoP: ");
> > +  for (auto loop : loops_list (cfun, 0))
> > +   if (loop_in_sese_p (loop, s))
> > + fprintf (dump_file, "%d ", loop->num);
> > +  fprintf (dump_file, "\n");
> > +}
> >
> > you are duplicating functionality of the function you just added ...
> >
> 
> Fixed.
> 
> > Otherwise looks OK to me.
> 
> Can I commit the revised patch?

Yes.

Thanks,
Richard.


Re: [PATCH] libgompd: Add OMPD support and global ICV functions

2022-05-18 Thread Mohamed Atef via Gcc-patches
Hi Jakub,
  This is the final patch.
I fixed things that you mentioned.
I added two more small functions at ompd-helper.c.
One more thing, the functions in ompd-helper.c are very similar. I can try
to make them generic to a single
function but, I think it's better to get the value of every ICV by
independent functions.

Mohamed.

On Wed, May 18, 2022 at 2:10 PM Mohamed Atef 
wrote:

>
>
> On Wed, May 18, 2022 at 9:35 AM Jakub Jelinek  wrote:
>
>> On Mon, May 16, 2022 at 07:35:17PM +0200, Mohamed Atef via Gcc-patches
>> wrote:
>> > libgomp/ChangeLog
>> >
>> > 2022-05-15 Mohamed Atef 
>> >
>> > *config/darwin/plugin-suffix.h (SONAME_SUFFIX): Remove ()s.
>> > *config/hpux/plugin-suffix.h (SONAME_SUFFIX): Remove ()s.
>> > *config/posix/plugin-suffix.h (SONAME_SUFFIX): Remove ()s.
>> > *configure: Regenerate.
>> > *Makefile.am (toolexeclib_LTLIBRARIES): Add libgompd.la.
>> > (libgompd_la_LDFLAGS, libgompd_la_DEPENDENCIES,
>> > libgompd_la_LINK,libgompd_la_SOURCES, libgompd_version_dep,
>> > libgompd_version_script, libgompd.ver-sun, libgompd.ver,
>> > libgompd_version_info): New.
>> > *Makefile.in: Regenerate.
>> > *aclocal.m4: Regenerate.
>> > *env.c: Include ompd-support.h.
>> > (parse_debug): New function.
>> > (gompd_enabled): New Variable.
>> > (initialize_env): Call gompd_load.
>> > (initialize_env): Call parse_debug.
>> > *team.c: Include ompd-support.h.
>> > (gomp_team_start): Call ompd_bp_parallel_begin.
>> > (gomp_team_end): Call ompd_bp_parallel_end.
>> > (gomp_thread_start): Call ompd_bp_thread_start.
>> > *libgomp.map: ADD OMP_5.0.3 symbol versions.
>>
>> Add rather than ADD
>>
>> > *libgompd.map: New.
>> > *omp-tools.h.in: New.
>> > *ompd-types.h.in: New.
>> > *ompd-support.h: New.
>> > *ompd-support.c: New.
>> > *ompd-helper.h: New.
>> > *ompd-helper.c: New.
>> > *ompd-init.c: New.
>> > *ompd-icv.c: New.
>> > *configure.ac (AC_CONFIG_FILES): Add omp-tools.h and ompd-types.h.
>>
>> Almost ok, minor comments below.
>> As I said earlier, as this is just partial implementation of the
>> OMPD, I think it would be better to commit it to a git branch but
>> already in the upstream repository, say devel/omp/ompd branch.
>>
>> Do you have a FSF Copyright assignment on file or do you want to
>> submit this under DCO (https://gcc.gnu.org/dco.html)?
>
> If the latter, should I remove the header comment?
> I mean this part " Copyright (C) 2022 Free Software Foundation, Inc.
>   Contributed by Mohamed Atef . "
> In fact, I don't know the difference, so which is better for the community?
>
>>   If the latter,
>> we need Signed-off-by line in your final patch mail and also in the
>> commit message.
>> The commit message should include a one line summary, then
>> empty line, then explanation what the patch is, followed by properly
>> formatted ChangeLog entry (the above is badly mangled by your mailer),
>> there should be 2 spaces around the name etc. and after the ChangeLog
>> entry the Signed-of-by line if you use DCO.
>> More details in https://gcc.gnu.org/gitwrite.html
>> In Authenticated access there is a link to a form to request write
>> access to the repository, please file it and write me as the sponsor.
>> Then follow the rest of gitwrite to e.g. do
>> contrib/gcc-git-customization.sh
>> and then you can git gcc-verify to verify whether the ChangeLog entry in
>> your commit log is ok before you push it.
>>
>> > --- /dev/null
>> > +++ b/libgomp/libgompd.map
>> > @@ -0,0 +1,23 @@
>> > +OMPD_5.1 {
>>
>> Shouldn't this be OMPD_5.0 ?
>> The functions were already in OpenMP 5.0, weren't they?
>>
>> > +  global:
>> > +ompd_initialize;
>> > +ompd_get_api_version;
>> > +ompd_get_version_string;
>> > +ompd_process_initialize;
>> > +ompd_device_initialize;
>> > +ompd_rel_address_space_handle;
>> > +ompd_finalize;
>> > +ompd_enumerate_icvs;
>> > +ompd_get_icv_from_scope;
>> > +ompd_get_icv_string_from_scope;
>> > +ompd_get_thread_handle;
>> > +ompd_get_thread_in_parallel;
>> > +ompd_rel_thread_handle;
>> > +ompd_thread_handle_compare;
>> > +ompd_get_thread_id;
>> > +ompd_get_device_from_thread;
>> > +ompd_bp_thread_begin;
>> > +ompd_bp_thread_end;
>>
>> Why is ompd_bp_thread_{begin,end} here?  I thought they were
>> in libgomp.so.*, not in libgompd.so.*
>>
>> > +  local:
>> > +*;
>> > +};
>>
>> > +  /* NO cuda for now.  */
>>
>> We support other kinds of offloading, so better just say
>>   /* No offloading support for now.  */
>> or so.
>>
>> > +  if (device == OMPD_DEVICE_KIND_HOST)
>> > +{
>> > +  switch (icv_id)
>> > + {
>> > +   case gompd_icv_cancellation_var:
>> > + return
>> > +   gompd_get_cancellation ((ompd_address_space_handle_t *)
>> handle,
>> > +   icv_value);
>> > +   case gompd_icv_max_task_priority_var:
>> > + return gompd_get_max_task_priority
>> ((ompd_address_space_handle_t *)
>> > + handle,

Re: [PATCH] libgompd: Add OMPD support and global ICV functions

2022-05-18 Thread Jakub Jelinek via Gcc-patches
On Wed, May 18, 2022 at 02:10:29PM +0200, Mohamed Atef wrote:
> > As I said earlier, as this is just partial implementation of the
> > OMPD, I think it would be better to commit it to a git branch but
> > already in the upstream repository, say devel/omp/ompd branch.
> >
> > Do you have a FSF Copyright assignment on file or do you want to
> > submit this under DCO (https://gcc.gnu.org/dco.html)?
> 
> If the latter, should I remove the header comment?
> I mean this part " Copyright (C) 2022 Free Software Foundation, Inc.
>   Contributed by Mohamed Atef . "
> In fact, I don't know the difference, so which is better for the community?

Getting the FSF Copyright assignment can take a while, in the past it
involved sending snail mail papers and could take a few weeks or more,
I think nowadays it is through email but still can take some time.
The DCO is described in the link above.

As for the Copyright line, I must say I don't know,
https://gcc.gnu.org/pipermail/gcc/2021-June/236217.html
says that it probably should be just
  Copyright The GNU Toolchain Authors.
in that case, but we have the DCO option only for less than a year
and apparently no file has such a Copyright line.

If you wish to use FSF Copyright assignment, somebody needs to mail you
details that you fill in and mail to FSF.

Jakub



Re: [PATCH] libgompd: Add OMPD support and global ICV functions

2022-05-18 Thread Mohamed Atef via Gcc-patches
On Wed, May 18, 2022 at 2:43 PM Jakub Jelinek  wrote:

> On Wed, May 18, 2022 at 02:10:29PM +0200, Mohamed Atef wrote:
> > > As I said earlier, as this is just partial implementation of the
> > > OMPD, I think it would be better to commit it to a git branch but
> > > already in the upstream repository, say devel/omp/ompd branch.
> > >
> > > Do you have a FSF Copyright assignment on file or do you want to
> > > submit this under DCO (https://gcc.gnu.org/dco.html)?
> >
> > If the latter, should I remove the header comment?
> > I mean this part " Copyright (C) 2022 Free Software Foundation, Inc.
> >   Contributed by Mohamed Atef . "
> > In fact, I don't know the difference, so which is better for the
> community?
>

Getting the FSF Copyright assignment can take a while, in the past it
> involved sending snail mail papers and could take a few weeks or more,
> I think nowadays it is through email but still can take some time.
> The DCO is described in the link above.
>
> As for the Copyright line, I must say I don't know,
> https://gcc.gnu.org/pipermail/gcc/2021-June/236217.html
> says that it probably should be just
>   Copyright The GNU Toolchain Authors.
>
I don't have FSF Copyright, I just copied the comment as I thought it's
some standard.
I will change it to "Copyright The GNU Toolchain Authors".

> in that case, but we have the DCO option only for less than a year
> and apparently no file has such a Copyright line.
>
> If you wish to use FSF Copyright assignment, somebody needs to mail you
> details that you fill in and mail to FSF.
>
> I will use DCO, we have less than 2 months to finish the project.

> Jakub
>
Mohamed


Re: [PATCH] libgompd: Add OMPD support and global ICV functions

2022-05-18 Thread Mohamed Atef via Gcc-patches
Hi Jakub,
   Sorry for the rush of emails, I removed the Copyright part, I will use
DCO.
Note: I filled out the form.

On Wed, May 18, 2022 at 2:55 PM Mohamed Atef 
wrote:

>
>
> On Wed, May 18, 2022 at 2:43 PM Jakub Jelinek  wrote:
>
>> On Wed, May 18, 2022 at 02:10:29PM +0200, Mohamed Atef wrote:
>> > > As I said earlier, as this is just partial implementation of the
>> > > OMPD, I think it would be better to commit it to a git branch but
>> > > already in the upstream repository, say devel/omp/ompd branch.
>> > >
>> > > Do you have a FSF Copyright assignment on file or do you want to
>> > > submit this under DCO (https://gcc.gnu.org/dco.html)?
>> >
>> > If the latter, should I remove the header comment?
>> > I mean this part " Copyright (C) 2022 Free Software Foundation, Inc.
>> >   Contributed by Mohamed Atef .
>> "
>> > In fact, I don't know the difference, so which is better for the
>> community?
>>
>
> Getting the FSF Copyright assignment can take a while, in the past it
>> involved sending snail mail papers and could take a few weeks or more,
>> I think nowadays it is through email but still can take some time.
>> The DCO is described in the link above.
>>
>> As for the Copyright line, I must say I don't know,
>> https://gcc.gnu.org/pipermail/gcc/2021-June/236217.html
>> says that it probably should be just
>>   Copyright The GNU Toolchain Authors.
>>
> I don't have FSF Copyright, I just copied the comment as I thought it's
> some standard.
> I will change it to "Copyright The GNU Toolchain Authors".
>
>> in that case, but we have the DCO option only for less than a year
>> and apparently no file has such a Copyright line.
>>
>> If you wish to use FSF Copyright assignment, somebody needs to mail you
>> details that you fill in and mail to FSF.
>>
>> I will use DCO, we have less than 2 months to finish the project.
>
>> Jakub
>>
> Mohamed
>


Re: [PATCH] PR tree-optimization/31178 - Add rshift side effect.

2022-05-18 Thread Andrew MacLeod via Gcc-patches

On 5/18/22 02:41, Richard Biener wrote:

On Tue, May 17, 2022 at 8:41 PM Andrew MacLeod via Gcc-patches
 wrote:

This patch implements side effects of the second operand of a shift
operation.

given A >> B or A << B, the range of B is restricted to [0, PRECISION_A).

Fortran is currently more permissive than this, allowing the range to be
[0, PRECISION_A], so this si the value we currently default to in this
patch.  If the fortran front end were adjusted, we could adjust the end
point.

This currently bootstraps with no regressions on x86_64-pc-linux-gnu.

Is this sufficient, or should I also be checking some other flags which
may allow other values outside this range to be valid?

I think the "undefined behavior" side-effects are dangerous since
I know of no code that makes sure to clamp the shift argument when
hoisting it.  sanitizing shifts will also not help to discover such latent
issues since sanitizing is happening early and it will most definitely
avoid the hoisting itself.

As to that we _definitely_ want a way to disable this [assumption
that the shift operand is in-range] if we make that assumption
even on IL state after optimizations.

Candidates to look for are invariant motion, ifcombine,
partial PRE, PRE in general (we possibly hoist such expressions
across function calls that might terminate the program normally).

That is, what prevents

if (n > 32)
  abort ();
x = i << n;

to be transformed to

x = i << n;
if (n > 32)
  abort ();

?  Yes, that's probably a latent issue in some sense but you would
now optimize the if (n > 32) abort () away while previously x would
have an undetermined value but we'd still abort.

Do you have some statistics on how this particular side-effect
improves code generation?

Richard.


None whatsoever...  just a PR requesting it that has been open for 15 
years :-)


If we don't want to do this optimization, then we should kill the PR. I 
can also attach the path to the PR than if anyone cares enough about 
this functionality, they could pursue the other effects...


Andrew





Re: [PATCH] Add divide by zero side effect.

2022-05-18 Thread Andrew MacLeod via Gcc-patches

On 5/18/22 02:28, Richard Biener wrote:

On Tue, May 17, 2022 at 8:40 PM Andrew MacLeod via Gcc-patches
 wrote:

I haven't checked this patch in yet.  This implements a side effect that
the divisor cannot be 0 after a divide executes. This allows us to fold
the divide away:

a = b / c;
if (c == 0)
dead();

This bootstraps on x86_64-pc-linux-gnu with no regressions, but I first
wanted to check to see if there are some flags or conditions that should
e checked in order NOT to do this optimization.  I am guessing there is
probably something :-)Anyway, this is how we straightforwardly add
side effects now.

Does the patch conditions need tweaking to apply the side effect?

What does "after the stmt" mean?  If the stmt throws internally then on
the EH edge the divisor can be zero.

How do you fold away the divide in your above example?

We dont fold anyway the divide, just the condition checking if c == 0.. 
this would be identical in function to


b= *ptr;
if (ptr == 0)
  dead();

after the b = *ptr stmt is done, ptr is known to be non-zero. likewise,  
after a = b / c, all subsequent stmts know c is non-zero


Any outgoing EH edge from the block will not have this side effect 
applied (ie ptr and c will still be varying, or whatever they were to 
start).  All other edges will have the non-zero effect, as will any 
stmts in this block which occur after the initial one that triggers the 
side effect.


Andrew




Re: [PATCH] c++: suppress -Waddress warnings with *_cast [PR105569]

2022-05-18 Thread Jason Merrill via Gcc-patches

On 5/16/22 13:06, Marek Polacek wrote:

dynamic_cast can legally return nullptr, so I don't think it's helpful
for -Waddress to warn for

   if (dynamic_cast(&ref))
 // ...

More generally, it's likely not useful to warn for the artificial
POINTER_PLUS_EXPRs created by build_base_path.


Normally the POINTER_PLUS_EXPR is guarded by if (nonnull).  But 
build_base_path isn't adding that guard in this case because the operand 
is known to be a reference, which cannot be null 
(http://eel.is/c++draft/dcl.ref#5).  So a warning is indicated for this 
testcase, though it would be good to give a more informative one 
("comparing address of reference to null").



Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?

PR c++/105569

gcc/cp/ChangeLog:

* class.cc (build_base_path): Suppress -Waddress warning.

gcc/testsuite/ChangeLog:

* g++.dg/warn/Waddress-9.C: New test.
---
  gcc/cp/class.cc|  2 ++
  gcc/testsuite/g++.dg/warn/Waddress-9.C | 34 ++
  2 files changed, 36 insertions(+)
  create mode 100644 gcc/testsuite/g++.dg/warn/Waddress-9.C

diff --git a/gcc/cp/class.cc b/gcc/cp/class.cc
index 3c195b35396..06167380423 100644
--- a/gcc/cp/class.cc
+++ b/gcc/cp/class.cc
@@ -518,6 +518,8 @@ build_base_path (enum tree_code code,
  
expr = build1 (NOP_EXPR, ptr_target_type, expr);
  
+  suppress_warning (expr, OPT_Waddress);

+
   indout:
if (!want_pointer)
  {
diff --git a/gcc/testsuite/g++.dg/warn/Waddress-9.C 
b/gcc/testsuite/g++.dg/warn/Waddress-9.C
new file mode 100644
index 000..2ec41949ccf
--- /dev/null
+++ b/gcc/testsuite/g++.dg/warn/Waddress-9.C
@@ -0,0 +1,34 @@
+// PR c++/105569
+// { dg-do compile { target c++11 } }
+// { dg-options -Waddress }
+
+class A {};
+
+class B : public virtual A {};
+
+class C : public A {};
+
+int main() {
+B* object = new B();
+B &ref = *object;
+
+// -Waddress warns here
+bool b = nullptr == dynamic_cast(&ref); // { dg-bogus "-Waddress" }
+bool b4 = nullptr == static_cast(&ref); // { dg-bogus "-Waddress" }
+if (dynamic_cast(&ref)) // { dg-bogus "-Waddress" }
+  {
+  }
+if (static_cast(&ref)) // { dg-bogus "-Waddress" }
+  {
+  }
+
+// -Waddress doesn't warn anymore
+auto ptr = dynamic_cast(&ref);
+bool b2 = ptr == nullptr;
+
+C* cobject = new C();
+C &cref = *cobject;
+
+// -Waddress also doesn't warn anymore
+bool b3 = nullptr == dynamic_cast(&cref);
+}

base-commit: 682e587f1021241758f7dfe0b22651008622a312




[PATCH] Modula-2: merge proposal/review: 2/9 02.patch-set-02

2022-05-18 Thread Gaius Mulley via Gcc-patches
Hello,

this email contains:

2.  the top level /gm2tools contents.

---
New file: gm2tools/autogen.sh
---
#!/bin/sh

# autogen.sh regenerate the autoconf files.
#   Copyright 2013-2022  Free Software Foundation, Inc.
#
# This file is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; see the file COPYING3.  If not see
# .

rm -rf autom4te.cache

# libtoolize
rm -f aclocal.m4
# aclocal -I . -I config -I ../config
aclocal -I . -I ../config
autoreconf -I . -I ../config
automake --include-deps

rm -rf autom4te.cache

exit 0
---
New file: gm2tools/ChangeLog
---
2022-05-17  Gaius Mulley 

* Corrected dates on all source files.

2021-06-14  Gaius Mulley 

* errors.c:  (New file).
* Makefile.am:  (m2color.o) rule added include paths for gcc
system headers.  (errors.o) rule added include paths for gcc
system headers.  Add errors.o to list of modules and add errors.o
to gm2l.
* Makefile.in:  (rebuilt).

2021-06-12  Gaius Mulley 

* gm2tools/Makefile.in:  rebuilt.

2021-06-11  Gaius Mulley 

* gm2tools/Makefile.am:  (man_MANS) set to gm2lgen.1
gm2l.1 gm2lcc.1 gm2lorder.1.  (%.o) includes changed to
find gm2-libiberty and the gcc system.h and config.h.
* gm2tools/Makefile.in:  (rebuilt).

2021-06-09  Gaius Mulley 

* gm2l.1:  (New file).
* gm2lcc.1:  (New file).
* gm2lgen.1:  (New file).
* gm2lorder.1:  (New file).

2021-06-08  Gaius Mulley 

* Makefile.am: (LIBM2PIMPATH) New definition.
(LIBM2CORPATH) New definition.  (LIBM2ISOPATH) New definition.
(gm2l) specify -flibs=pim,iso and pass link paths.
(gm2lcc) specify -flibs=pim,iso and pass link paths.
(gm2lgen) specify -flibs=pim,iso and pass link paths.
(gm2lorder) specify -flibs=pim,iso and pass link paths.
(gm2m) specify -flibs=pim,iso and pass link paths.

2021-06-07  Gaius Mulley 

* aclocal.m4: (New file).
* autogen.sh: (New file).
* configure: (New file).
* configure.ac: (New file).
* m2color.c: (New file).
* Makefile.am: (New file).
* Makefile.in: (New file).
* Makefile.am: (DEBUG_MODULE_LIST) used to display locations of
objects.  Added -B./gcc build directory to pick up link tools
generated in the compiler bootstrap process.
* Makefile.in: (Regenerated).
---
New file: gm2tools/configure.ac
---
# Configure script for gm2tools.
#   Copyright (C) 2021-2022 Free Software Foundation, Inc.
#
# This file is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; see the file COPYING3.  If not see
# .

AC_INIT(package-unused, version-unused,, gm2tools)
AC_CONFIG_SRCDIR(Makefile.am)

# Determine the noncanonical names used for directories.
ACX_NONCANONICAL_BUILD
ACX_NONCANONICAL_HOST
ACX_NONCANONICAL_TARGET

dnl Autoconf 2.5x and later will set a default program prefix if
dnl --target was used, even if it was the same as --host.  Disable
dnl that behavior.  This must be done before AC_CANONICAL_SYSTEM
dnl to take effect.
test "$host_noncanonical" = "$target_noncanonical" &&
  test "$program_prefix$program_suffix$program_transform_name" = \
NONENONEs,x,x, &&
  program_transform_name=s,y,y,

AC_CANONICAL_SYSTEM
AC_ARG_PROGRAM

AM_INIT_AUTOMAKE([1.9.3 no-define foreign no-dist -Wall -Wno-portability])
AM_MAINTAINER_MODE

AC_PROG_INSTALL

AC_PROG_CC

# These should be defined by the top-level configure.
# Copy them into Makefile.
AC_SUBST(GCC_FOR_TARGET)

AM_CONDITIONAL(NATIVE, test "$host_alias" = "$target_alias")

AC_CONFIG_FILES(Makefile)

AC_OUTPUT
--

[PATCH] Modula-2: merge proposal/review: 1/9 01.patch-set-01

2022-05-18 Thread Gaius Mulley via Gcc-patches
hello,

this file is part-01 of the patch set for the gm2 review.


1.  all GCC files which have been patched.
==

The 'Only in' diff output was:

Only in gcc-git-devel-modula2/gcc: m2
Only in gcc-git-devel-modula2/gcc/testsuite: gm2
Only in gcc-git-devel-modula2/gcc/testsuite/lib: gm2-dg.exp
Only in gcc-git-devel-modula2/gcc/testsuite/lib: gm2.exp
Only in gcc-git-devel-modula2/gcc/testsuite/lib: gm2-simple.exp
Only in gcc-git-devel-modula2/gcc/testsuite/lib: gm2-torture.exp
Only in gcc-git-devel-modula2/gcc/doc: gm2.texi
Only in gcc-git-devel-modula2: libgm2
Only in gcc-git-devel-modula2: gm2tools

and the recursive diffs:


diff -x '*autom4te*' -rwu gcc/configure.ac gcc-git-devel-modula2/configure.ac
--- gcc/configure.ac2022-05-17 11:20:57.487964366 +0100
+++ gcc-git-devel-modula2/configure.ac  2022-05-17 14:41:05.480881101 +0100
@@ -140,7 +140,7 @@
 # binutils, gas and ld appear in that order because it makes sense to run
 # "make check" in that particular order.
 # If --enable-gold is used, "gold" may replace "ld".
-host_tools="texinfo flex bison binutils gas ld fixincludes gcc cgen sid sim 
gdb gdbserver gprof etc expect dejagnu m4 utils guile fastjar gnattools libcc1 
gotools c++tools"
+host_tools="texinfo flex bison binutils gas ld fixincludes gcc cgen sid sim 
gdb gdbserver gprof etc expect dejagnu m4 utils guile fastjar gnattools libcc1 
gm2tools gotools c++tools"

 # these libraries are built for the target environment, and are built after
 # the host libraries and the host tools (which may be a cross compiler)
@@ -162,6 +162,7 @@
target-libffi \
target-libobjc \
target-libada \
+   target-libgm2 \
target-libgo \
target-libphobos \
target-zlib"
@@ -459,6 +460,14 @@
   noconfigdirs="$noconfigdirs gnattools"
 fi

+AC_ARG_ENABLE(libgm2,
+[AS_HELP_STRING([--enable-libgm2], [build libgm2 directory])],
+ENABLE_LIBGM2=$enableval,
+ENABLE_LIBGM2=no)
+if test "${ENABLE_LIBGM2}" != "yes" ; then
+  noconfigdirs="$noconfigdirs gm2tools"
+fi
+
 AC_ARG_ENABLE(libssp,
 [AS_HELP_STRING([--enable-libssp], [build libssp directory])],
 ENABLE_LIBSSP=$enableval,
@@ -3617,6 +3626,7 @@
 NCN_STRICT_CHECK_TARGET_TOOLS(GFORTRAN_FOR_TARGET, gfortran)
 NCN_STRICT_CHECK_TARGET_TOOLS(GOC_FOR_TARGET, gccgo)
 NCN_STRICT_CHECK_TARGET_TOOLS(GDC_FOR_TARGET, gdc)
+NCN_STRICT_CHECK_TARGET_TOOLS(GM2_FOR_TARGET, gm2)

 ACX_CHECK_INSTALLED_TARGET_TOOL(AR_FOR_TARGET, ar)
 ACX_CHECK_INSTALLED_TARGET_TOOL(AS_FOR_TARGET, as)
@@ -3655,6 +3665,8 @@
[gcc/gccgo -B$$r/$(HOST_SUBDIR)/gcc/], go)
 GCC_TARGET_TOOL(gdc, GDC_FOR_TARGET, GDC,
[gcc/gdc -B$$r/$(HOST_SUBDIR)/gcc/], d)
+GCC_TARGET_TOOL(gm2, GM2_FOR_TARGET, GM2,
+   [gcc/gm2 -B$$r/$(HOST_SUBDIR)/gcc/], m2)
 GCC_TARGET_TOOL(ld, LD_FOR_TARGET, LD, [ld/ld-new])
 GCC_TARGET_TOOL(lipo, LIPO_FOR_TARGET, LIPO)
 GCC_TARGET_TOOL(nm, NM_FOR_TARGET, NM, [binutils/nm-new])
@@ -3781,6 +3793,9 @@
 # Specify what files to not compare during bootstrap.

 compare_exclusions="gcc/cc*-checksum\$(objext) | gcc/ada/*tools/*"
+compare_exclusions="$compare_exclusions | gcc/m2/gm2-compiler-boot/M2Version*"
+compare_exclusions="$compare_exclusions | gcc/m2/gm2-compiler-boot/SYSTEM*"
+compare_exclusions="$compare_exclusions | gcc/m2/gm2version*"
 case "$target" in
   hppa*64*-*-hpux*) ;;
   hppa*-*-hpux*) compare_exclusions="$compare_exclusions | */libgcc/lib2funcs* 
| gcc/function-tests.o" ;;
diff -x '*autom4te*' -rwu gcc/gcc/c/gccspec.cc 
gcc-git-devel-modula2/gcc/c/gccspec.cc
--- gcc/gcc/c/gccspec.cc2022-05-17 11:20:57.919969752 +0100
+++ gcc-git-devel-modula2/gcc/c/gccspec.cc  2022-05-17 14:41:05.552881117 
+0100
@@ -105,3 +105,9 @@

 /* Number of extra output files that lang_specific_pre_link may generate.  */
 int lang_specific_extra_outfiles = 0;  /* Not used for C.  */
+
+/* lang_register_spec_functions.  Not used for C.  */
+void
+lang_register_spec_functions (void)
+{
+}
diff -x '*autom4te*' -rwu gcc/gcc/c-family/cppspec.cc 
gcc-git-devel-modula2/gcc/c-family/cppspec.cc
--- gcc/gcc/c-family/cppspec.cc 2022-05-17 11:20:57.911969653 +0100
+++ gcc-git-devel-modula2/gcc/c-family/cppspec.cc   2022-05-17 
14:41:05.548881115 +0100
@@ -198,3 +198,9 @@

 /* Number of extra output files that lang_specific_pre_link may generate.  */
 int lang_specific_extra_outfiles = 0;  /* Not used for cpp.  */
+
+/* lang_register_spec_functions.  Not used for cpp.  */
+void
+lang_register_spec_functions (void)
+{
+}
diff -x '*autom4te*' -rwu gcc/gcc/cp/g++spec.cc 
gcc-git-devel-modula2/gcc/cp/g++spec.cc
--- gcc/gcc/cp/g++spec.cc   2022-05-17 11:20:58.163972794 +0100
+++ gcc-git-devel-modula2/gcc/cp/g++spec.cc 2022-05-17 14:41:05.564881118 
+0100
@@ -434,3 +434,9 @@

 /* Number of extra output files that lang_specific_pre_link may generate.  */
 int lang_specific_extra_outfiles = 0;  /* Not used for C++.  */
+
+/*

[PATCH] Modula-2: merge proposal/review: 6/9 06.patch-set-04-3

2022-05-18 Thread Gaius Mulley via Gcc-patches
Hello,

this email contains:

4.  the glue code (between Modula-2 and GCC) part 3/3.
(*.def files).



New file: gcc/m2/gm2-gcc/README

This directory contains the interface code between the Modula-2 front
end and GCC.  In effect this is the Modula-2 compiler GCC Tree API.
It is an internal API only.  Many of these filenames match their GCC C
family counterparts.  So for example m2decl.def and m2decl.c are the
Modula-2 front end version of c-decl.c.

New file: gcc/m2/gm2-gcc/m2type.def

(* m2type.def definition module for m2type.cc.

Copyright (C) 2011-2022 Free Software Foundation, Inc.
Contributed by Gaius Mulley .

This file is part of GNU Modula-2.

GNU Modula-2 is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.

GNU Modula-2 is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
General Public License for more details.

You should have received a copy of the GNU General Public License
along with GNU Modula-2; see the file COPYING3.  If not see
.  *)

DEFINITION MODULE m2type ;

FROM SYSTEM IMPORT ADDRESS ;
FROM m2tree IMPORT Tree ;
FROM m2linemap IMPORT location_t ;


TYPE
   Constructor = ADDRESS ;


(*
   ValueInTypeRange - returns TRUE if the constant, value, lies in the range
  of, type.
*)

PROCEDURE ValueInTypeRange (type: Tree; value: Tree) : BOOLEAN ;


(*
   ValueOutOfTypeRange - returns TRUE if the constant, value, exceed the range
 of, type.
*)

PROCEDURE ValueOutOfTypeRange (type: Tree; value: Tree) : BOOLEAN ;


(*
   ExceedsTypeRange - return TRUE if low or high exceed the range of, type.
*)

PROCEDURE ExceedsTypeRange (type: Tree; low, high: Tree) : BOOLEAN ;


(*
   WithinTypeRange - return TRUE if low and high are within the range of, type.
*)

PROCEDURE WithinTypeRange (type: Tree; low, high: Tree) : BOOLEAN ;


(*
BuildSubrangeType - creates a subrange of, type, with, lowval, highval.
*)

PROCEDURE BuildSubrangeType (location: location_t; name: ADDRESS; type: Tree; 
lowval: Tree; highval: Tree) : Tree ;


(*
BuildCharConstant - creates a character constant given a, string.
*)

PROCEDURE BuildCharConstant (location: location_t; string: ADDRESS) : Tree ;


(*
   BuildCharConstantChar - creates a character constant given a character, ch.
*)

PROCEDURE BuildCharConstantChar (location: location_t; ch: CHAR) : Tree ;


(*
BuildArrayConstructorElement - adds, value, to the constructor_element_list.
*)

PROCEDURE BuildArrayConstructorElement (p: ADDRESS; value: Tree; indice: Tree) ;


(*
BuildEndArrayConstructor - returns a tree containing the array
   compound literal.
*)

PROCEDURE BuildEndArrayConstructor (p: Constructor) : Tree ;


(*
   BuildEndArrayConstructor - returns a tree containing the array
  compound literal.
*)

PROCEDURE BuildStartArrayConstructor (type: Tree) : Constructor ;


(*
BuildRecordConstructorElement - adds, value, to the 
constructor_element_list.
*)

PROCEDURE BuildRecordConstructorElement (p: Constructor; value: Tree) ;


(*
BuildEndRecordConstructor - returns a tree containing the record compound 
literal.
*)

PROCEDURE BuildEndRecordConstructor (p: Constructor) : Tree ;


(*
   BuildStartRecordConstructor - initializes a record compound
 constructor frame.
*)

PROCEDURE BuildStartRecordConstructor (type: Tree) : Constructor ;


(*
BuildEndSetConstructor - finishes building a set constant.
*)

PROCEDURE BuildEndSetConstructor (p: Constructor) : Tree ;


(*
BuildSetConstructorElement - adds, value, to the constructor_element_list.
*)

PROCEDURE BuildSetConstructorElement (p: Constructor; value: Tree) ;


(*
   BuildStartSetConstructor - starts to create a set constant.
  Remember that type is really a record type.
*)

PROCEDURE BuildStartSetConstructor (type: Tree) : Constructor ;


(*
BuildSetType - creates a SET OF [lowval..highval]
*)

PROCEDURE BuildSetType (location: location_t; name: ADDRESS; type: Tree; 
lowval: Tree; highval: Tree; ispacked: BOOLEAN) : Tree ;


(*
BuildConstPointerType - returns a type which is a const pointer to, totype.
*)

PROCEDURE BuildConstPointerType (totype: Tree) : Tree ;


(*
BuildPointerType - returns a type which is a pointer to, totype.
*)

PROCEDURE BuildPointerType (totype: Tree) : Tree ;


(*
BuildEnumerator - build an enumerator and add it to the, enumvalues, list.
  It returns a copy of the value.  --fixme-- why do this?
*)

PROCEDURE BuildEnumerator (location: location_t; name: ADDRESS; 

[PATCH] Modula-2: merge proposal/review: 8/9 08.patch-set-06

2022-05-18 Thread Gaius Mulley via Gcc-patches
Hello,

this file contains:


6.  gcc/m2/Make-lang.in
==
-
New file: gcc/m2/Make-lang.in
-
# Top level -*- makefile -*- fragment for GNU M2.

# Copyright (C) 2000-2022 Free Software Foundation, Inc.

#This file is part of GCC.

#GCC is free software; you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation; either version 3, or (at your option)
#any later version.

#GCC is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#GNU General Public License for more details.

#You should have received a copy of the GNU General Public License
#along with GCC; see the file COPYING3.  If not see
#.

# QUIAT=@
GM2_MAKE_DEBUG=

# Actual names to use when installing a native compiler.
GM2_INSTALL_NAME = $(shell echo gm2|sed '$(program_transform_name)')
GM2_TARGET_INSTALL_NAME = $(target_noncanonical)-$(shell echo gm2|sed 
'$(program_transform_name)')

# Actual names to use when installing a cross-compiler.
GM2_CROSS_NAME = `echo gm2|sed '$(program_transform_cross_name)'`

GM2_1 = ./gm2 -B./stage1/m2 -g -fm2-g
XGCC = ./xgcc -B./
GM2_2 = ./gm2 -B./stage2/m2 -g -fm2-g
CFLAGS=-g   ## remove this
LDLAGS=-g   ## remove this

# Define the name of target independent tools to be installed in $(bindir)
# Names are subject to change

# The tools directly available to the user are built in gm2tools, gm2m is
# an internal tool and therefore built here.

GM2_LINK_TOOLS_INSTALL =
# GM2_LINK_TOOLS_INSTALL = gm2m$(exeext) #  gm2m is not installed as it is 
under development.

GM2_LINK_TOOLS = gm2m$(exeext) gm2l$(exeext) gm2lcc$(exeext) \
 gm2lgen$(exeext) gm2lorder$(exeext)

GM2_LINK_TOOLS_BOOT = stage1/m2/gm2lcc$(exeext) stage1/m2/gm2l$(exeext) \
  stage1/m2/gm2lgen$(exeext) stage1/m2/gm2lorder$(exeext)

ifeq ($(CC1ONLY),yes)
GCC_TOOLS_FOR_GM2 = \
$(GCC_PASSES) $(GCC_PARTS) \
stage1/m2/gcc$(exeext) \
stage1/m2/cc1$(exeext) \
stage1/m2/cpp$(exeext)
else
GCC_TOOLS_FOR_GM2 = \
$(GCC_PASSES) $(GCC_PARTS) \
stage1/m2/gcc$(exeext) \
stage1/m2/cc1$(exeext) \
stage1/m2/cc1plus$(exeext) \
stage1/m2/cpp$(exeext)
endif

CPP_GM2=-fpermissive -DIN_GCC -g

TEXISRC = $(objdir)/m2/images/gnu.eps \
  $(srcdir)/doc/gm2.texi \
  m2/gm2-libs.texi \
  m2/gm2-ebnf.texi \
  m2/SYSTEM-pim.texi \
  m2/SYSTEM-iso.texi \
  m2/Builtins.texi \
  m2/version.texi


# Define the names for selecting GNU Modula-2 in LANGUAGES.
m2 modula-2 modula2: gm2$(exeext) xgcc$(exeext) cc1gm2$(exeext) \
 $(GCC_TOOLS_FOR_GM2)
m2.serial = cc1gm2$(exeext)

# Tell GNU make to ignore these if they exist.
.PHONY: m2 modula-2 modula2

GM2_PROG_DEP=gm2$(exeext) xgcc$(exeext) cc1gm2$(exeext)

TEXI2HTML=python3 $(srcdir)/m2/www/tools/texi2tr/src/texi2tr.py

include m2/config-make
LIBSTDCXX=../$(TARGET_SUBDIR)/libstdc++-v3/src/.libs/libstdc++.a

SRC_PREFIX=G

m2/gm2spec.o: $(srcdir)/m2/gm2spec.cc $(SYSTEM_H) $(GCC_H) $(CONFIG_H) \
   m2/gm2config.h $(TARGET_H) $(PLUGIN_HEADERS) \
   $(generated_files) $(C_TREE_H)
(SHLIB_LINK='$(SHLIB_LINK)' \
SHLIB_MULTILIB='$(SHLIB_MULTILIB)'; \
$(COMPILER) $(ALL_COMPILERFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) \
 $(DRIVER_DEFINES) \
-DLIBSUBDIR=\"$(libsubdir)\" \
-DPREFIX=\"$(prefix)\" \
-c $(srcdir)/m2/gm2spec.cc $(OUTPUT_OPTION))

m2/gm2version.c: gm2version-check; @true

gm2version-check:
$(SHELL) $(srcdir)/m2/tools-src/makeversion -p $(srcdir) m2
$(STAMP) gm2version-check

gm2version.o: m2/gm2version.c
(SHLIB_LINK='$(SHLIB_LINK)' \
SHLIB_MULTILIB='$(SHLIB_MULTILIB)'; \
$(COMPILER) -c $(ALL_COMPILERFLAGS) $(ALL_CPPFLAGS) $(DRIVER_DEFINES) \
-DLIBSUBDIR=\"$(libsubdir)\" \
$(INCLUDES) m2/gm2version.c $(OUTPUT_OPTION))

# Create the compiler driver for M2.
CFLAGS-m2/m2/gm2spec.o += $(DRIVER_DEFINES)

GM2_OBJS = $(GCC_OBJS) m2/gm2version.o \
prefix.o intl.o m2/gm2spec.o

# Create the compiler driver for gm2.
gm2$(exeext): $(GM2_OBJS) $(EXTRA_GCC_OBJS) libcommon-target.a $(LIBDEPS) \
m2/gm2config.h
+$(LINKER) $(ALL_LINKERFLAGS) $(LDFLAGS) -o $@ \
  $(GM2_OBJS) $(EXTRA_GCC_OBJS) libcommon-target.a \
  $(EXTRA_GCC_LIBS) $(LIBS)

# Create a version of the gm2 driver which calls the cross-compiler.
gm2-cross$(exeext): gm2$(exeext)
-rm -f gm2-cross$(exeext)
cp gm2$(exeext) gm2-cross$(exeext)

po-generated:

#
# directories for the public definition, implementation and object libraries
#
GM2_LIB_DIR_LOG= 

[PATCH] Modula-2: merge proposal/review: 9/9 09.patch-set-07

2022-05-18 Thread Gaius Mulley via Gcc-patches
Hello,

this file contains:


7.  gcc/doc/gm2.texi
==
-
New file: gcc/doc/gm2.texi
-
\input texinfo
@c -*-texinfo-*-
@c Copyright (C) 2001-2022 Free Software Foundation, Inc.
@c This is part of the GM2 manual.

@c User level documentation for GNU Modula-2
@c
@c header

@setfilename gm2.info
@settitle The GNU Modula-2 Compiler

@include m2/version.texi
@set version-python  3.5

@include gcc-common.texi

@c Copyright years for this manual.
@set copyrights-gm2 1999-2022

@copying
@c man begin COPYRIGHT
Copyright @copyright{} @value{copyrights-gm2} Free Software Foundation, Inc.

Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with no
Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
A copy of the license is included in the
@c man end
section entitled ``GNU Free Documentation License''.
@ignore
@c man begin COPYRIGHT
man page gfdl(7).
@c man end
@end ignore
@end copying

@ifinfo
@format
@dircategory Software development
@direntry
* gm2: (gm2).   A GCC-based compiler for the Modula-2 language
@end direntry
@end format

@insertcopying
@end ifinfo

@titlepage
@title The GNU Modula-2 Compiler
@versionsubtitle
@author Gaius Mulley

@page
@vskip 0pt plus 1filll
Published by the Free Software Foundation @*
51 Franklin Street, Fifth Floor@*
Boston, MA 02110-1301, USA@*
@sp 1
@insertcopying
@end titlepage
@contents
@page

@c `Top' Node and Master Menu

@ifinfo
@node Top, Overview, (dir), (dir)
@top Introduction
@end ifinfo

@menu
* Overview:: What is GNU Modula-2.
* Using::Using GNU Modula-2.
* Licence::  Licence of GNU Modula-2.
* Contributing:: Contributing to GNU Modula-2.
* Internals::GNU Modula-2 internals.
* EBNF:: EBNF of GNU Modula-2
* Copying::  GNU Public Licence V3.
* Libraries::PIM and ISO library definitions.
* Indices::  Document and function indices.
@end menu

@node Overview, Using, Top, Top
@chapter Overview of GNU Modula-2

@menu
* What is GNU Modula-2::  Brief description of GNU Modula-2.
* Why use GNU Modula-2::  Advantages of GNU Modula-2.
* News::  Latest news about GNU Modula-2.
* Development::   How to get source code using git.
* Obtaining:: Where to get the source code using git.
* Features::  GNU Modula-2 Features
@end menu

@node What is GNU Modula-2, Why use GNU Modula-2, , Using
@section What is GNU Modula-2

GNU Modula-2 is a @uref{http://gcc.gnu.org/frontends.html, front end}
for the GNU Compiler Collection (@uref{http://gcc.gnu.org/, GCC}).
The GNU Modula-2 compiler is compliant with the PIM2, PIM3, PIM4 and
ISO dialects.  Also implemented are a complete set of free ISO
libraries and PIM libraries.

@footnote{The four Modula-2 dialects supported are defined in the following
references:

PIM2: 'Programming in Modula-2', 2nd Edition, Springer Verlag, 1982,
1983 by Niklaus Wirth (PIM2).

PIM3: 'Programming in Modula-2', 3rd Corrected Edition, Springer Verlag,
1985 (PIM3).

PIM4: 'Programming in Modula-2', 4th Edition, Springer Verlag, 1988
(@uref{http://freepages.modula2.org/report4/modula-2.html, PIM4}).

ISO: the ISO Modula-2 language as defined in 'ISO/IEC Information
technology - programming languages - part 1: Modula-2 Language,
ISO/IEC 10514-1 (1996)'
}

@node Why use GNU Modula-2, Release map, What is GNU Modula-2, Using
@section Why use GNU Modula-2

There are a number of advantages of using GNU Modula-2 rather than
translate an existing project into another language.

The first advantage is of maintainability of the original sources
and the ability to debug the original project source code using a
combination of gm2 and gdb.

The second advantage is that gcc runs on many processors and
platforms.  gm2 builds and runs on powerpc64le, amd64, i386, aarch64
to name but a few processors.

The compiler provides semantic analysis and runtime checking (full ISO
Modula-2 checking is implemented) and there is a plugin which can,
under certain conditions, detect runtime errors at compile time.

gm2 can produce swig interface headers to allow access from Python and
other scripting languages.  The compiler supports PIM2, PIM3, PIM4 and
ISO dialects of Modula-2, work is underway to implement M2R10.  Many
of the GCC builtins are available and access to assembly programming
is achieved using the same syntax as that used by GCC.

@node Release map, News, Why use GNU Modula-2, Using
@section Release map

GNU Modula-2 is now part of GCC and therefore will adopt the GCC
release schedule with a git branches matching the various GCC release
numbers.  It is intended that GNU Modula-2 implement more of the GCC
builtins (vararg access) and GCC features.

There is an intention to implement the M2R10 dialect of M

[PATCH v3] rs6000: Fix the check of bif argument number [PR104482]

2022-05-18 Thread Kewen.Lin via Gcc-patches
Hi,

As PR104482 shown, it's one regression about the handlings when
the argument number is more than the one of built-in function
prototype.  The new bif support only catches the case that the
argument number is less than the one of function prototype, but
it misses the case that the argument number is more than the one
of function prototype.  Because it uses "n != expected_args",
n is updated in

   for (n = 0; !VOID_TYPE_P (TREE_VALUE (fnargs)) && n < nargs;
fnargs = TREE_CHAIN (fnargs), n++)

, it's restricted to be less than or equal to expected_args with
the guard !VOID_TYPE_P (TREE_VALUE (fnargs)), so it's wrong.

The fix is to use nargs instead, also move the checking hunk's
location ahead to avoid useless further scanning when the counts
mismatch.

Bootstrapped and regtested on powerpc64-linux-gnu P8 and
powerpc64le-linux-gnu P9 and P10.

v3: Update test case with dg-excess-errors.

v2: Add one test case and refine commit logs.
https://gcc.gnu.org/pipermail/gcc-patches/2022-April/593155.html

v1: https://gcc.gnu.org/pipermail/gcc-patches/2022-March/591768.html

Is it ok for trunk?

BR,
Kewen
-
PR target/104482

gcc/ChangeLog:

* config/rs6000/rs6000-c.cc (altivec_resolve_overloaded_builtin): Fix
the equality check for argument number, and move this hunk ahead.

gcc/testsuite/ChangeLog:

* gcc.target/powerpc/pr104482.c: New test.
---
 gcc/config/rs6000/rs6000-c.cc   | 60 ++---
 gcc/testsuite/gcc.target/powerpc/pr104482.c | 16 ++
 2 files changed, 46 insertions(+), 30 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/powerpc/pr104482.c

diff --git a/gcc/config/rs6000/rs6000-c.cc b/gcc/config/rs6000/rs6000-c.cc
index 9c8cbd7a66e..61881f29230 100644
--- a/gcc/config/rs6000/rs6000-c.cc
+++ b/gcc/config/rs6000/rs6000-c.cc
@@ -1756,6 +1756,36 @@ altivec_resolve_overloaded_builtin (location_t loc, tree 
fndecl,
   vec *arglist = static_cast *> (passed_arglist);
   unsigned int nargs = vec_safe_length (arglist);

+  /* If the number of arguments did not match the prototype, return NULL
+ and the generic code will issue the appropriate error message.  Skip
+ this test for functions where we don't fully describe all the possible
+ overload signatures in rs6000-overload.def (because they aren't relevant
+ to the expansion here).  If we don't, we get confusing error messages.  */
+  /* As an example, for vec_splats we have:
+
+; There are no actual builtins for vec_splats.  There is special handling for
+; this in altivec_resolve_overloaded_builtin in rs6000-c.cc, where the call
+; is replaced by a constructor.  The single overload here causes
+; __builtin_vec_splats to be registered with the front end so that can happen.
+[VEC_SPLATS, vec_splats, __builtin_vec_splats]
+  vsi __builtin_vec_splats (vsi);
+ABS_V4SI SPLATS_FAKERY
+
+So even though __builtin_vec_splats accepts all vector types, the
+infrastructure cheats and just records one prototype.  We end up getting
+an error message that refers to this specific prototype even when we
+are handling a different argument type.  That is completely confusing
+to the user, so it's best to let these cases be handled individually
+in the resolve_vec_splats, etc., helper functions.  */
+
+  if (expected_args != nargs
+  && !(fcode == RS6000_OVLD_VEC_PROMOTE
+  || fcode == RS6000_OVLD_VEC_SPLATS
+  || fcode == RS6000_OVLD_VEC_EXTRACT
+  || fcode == RS6000_OVLD_VEC_INSERT
+  || fcode == RS6000_OVLD_VEC_STEP))
+return NULL;
+
   for (n = 0;
!VOID_TYPE_P (TREE_VALUE (fnargs)) && n < nargs;
fnargs = TREE_CHAIN (fnargs), n++)
@@ -1816,36 +1846,6 @@ altivec_resolve_overloaded_builtin (location_t loc, tree 
fndecl,
   types[n] = type;
 }

-  /* If the number of arguments did not match the prototype, return NULL
- and the generic code will issue the appropriate error message.  Skip
- this test for functions where we don't fully describe all the possible
- overload signatures in rs6000-overload.def (because they aren't relevant
- to the expansion here).  If we don't, we get confusing error messages.  */
-  /* As an example, for vec_splats we have:
-
-; There are no actual builtins for vec_splats.  There is special handling for
-; this in altivec_resolve_overloaded_builtin in rs6000-c.cc, where the call
-; is replaced by a constructor.  The single overload here causes
-; __builtin_vec_splats to be registered with the front end so that can happen.
-[VEC_SPLATS, vec_splats, __builtin_vec_splats]
-  vsi __builtin_vec_splats (vsi);
-ABS_V4SI SPLATS_FAKERY
-
-So even though __builtin_vec_splats accepts all vector types, the
-infrastructure cheats and just records one prototype.  We end up getting
-an error message that refers to this specific prototype even when we
-are handling a different argument type.  That is completely confusing
-to the user, so

[PATCH v3] rs6000: Adjust mov optabs for opaque modes [PR103353]

2022-05-18 Thread Kewen.Lin via Gcc-patches
Hi,

As PR103353 shows, we may want to continue to expand a MMA built-in
function like a normal function, even if we have already emitted
error messages about some missing required conditions.  As shown in
that PR, without one explicit mov optab on OOmode provided, it would
call emit_move_insn recursively.

So this patch is to allow the mov pattern to be generated when we are
expanding to RTL and have seen errors even without MMA supported, it's
expected that the generated pattern would not cause further ICEs as the
compilation would stop soon after expanding.

Bootstrapped and regtested on powerpc64-linux-gnu P8 and
powerpc64le-linux-gnu P9 and P10.

v3: Update test case with dg-excess-errors.

v2: Polish some comments and add one test case as Will and Peter suggested.
https://gcc.gnu.org/pipermail/gcc-patches/2022-April/592916.html

v1: https://gcc.gnu.org/pipermail/gcc-patches/2022-March/591150.html

Is it ok for trunk?

BR,
Kewen
-
PR target/103353

gcc/ChangeLog:

* config/rs6000/mma.md (define_expand movoo): Move TARGET_MMA condition
check to preparation statements and add handlings for !TARGET_MMA.
(define_expand movxo): Likewise.

gcc/testsuite/ChangeLog:

* gcc.target/powerpc/pr103353.c: New test.
---
 gcc/config/rs6000/mma.md| 42 ++---
 gcc/testsuite/gcc.target/powerpc/pr103353.c | 22 +++
 2 files changed, 58 insertions(+), 6 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/powerpc/pr103353.c

diff --git a/gcc/config/rs6000/mma.md b/gcc/config/rs6000/mma.md
index 907c9d6d516..746a77a0957 100644
--- a/gcc/config/rs6000/mma.md
+++ b/gcc/config/rs6000/mma.md
@@ -268,10 +268,25 @@ (define_int_attr avvi4i4i4
[(UNSPEC_MMA_PMXVI8GER4PP   "pmxvi8ger4pp")
 (define_expand "movoo"
   [(set (match_operand:OO 0 "nonimmediate_operand")
(match_operand:OO 1 "input_operand"))]
-  "TARGET_MMA"
+  ""
 {
-  rs6000_emit_move (operands[0], operands[1], OOmode);
-  DONE;
+  if (TARGET_MMA) {
+rs6000_emit_move (operands[0], operands[1], OOmode);
+DONE;
+  }
+  /* Opaque modes are only expected to be available when MMA is supported,
+ but PR103353 shows we may want to continue to expand a MMA built-in
+ function, even if we have already emitted error messages about some
+ missing required conditions.  As shown in that PR, without one
+ explicit mov optab on OOmode provided, it would call emit_move_insn
+ recursively.  So we allow this pattern to be generated when we are
+ expanding to RTL and have seen errors, even though there is no MMA
+ support.  It would not cause further ICEs as the compilation would
+ stop soon after expanding.  */
+  else if (currently_expanding_to_rtl && seen_error ())
+;
+  else
+gcc_unreachable ();
 })

 (define_insn_and_split "*movoo"
@@ -300,10 +315,25 @@ (define_insn_and_split "*movoo"
 (define_expand "movxo"
   [(set (match_operand:XO 0 "nonimmediate_operand")
(match_operand:XO 1 "input_operand"))]
-  "TARGET_MMA"
+  ""
 {
-  rs6000_emit_move (operands[0], operands[1], XOmode);
-  DONE;
+  if (TARGET_MMA) {
+rs6000_emit_move (operands[0], operands[1], XOmode);
+DONE;
+  }
+  /* Opaque modes are only expected to be available when MMA is supported,
+ but PR103353 shows we may want to continue to expand a MMA built-in
+ function, even if we have already emitted error messages about some
+ missing required conditions.  As shown in that PR, without one
+ explicit mov optab on XOmode provided, it would call emit_move_insn
+ recursively.  So we allow this pattern to be generated when we are
+ expanding to RTL and have seen errors, even though there is no MMA
+ support.  It would not cause further ICEs as the compilation would
+ stop soon after expanding.  */
+  else if (currently_expanding_to_rtl && seen_error ())
+;
+  else
+gcc_unreachable ();
 })

 (define_insn_and_split "*movxo"
diff --git a/gcc/testsuite/gcc.target/powerpc/pr103353.c 
b/gcc/testsuite/gcc.target/powerpc/pr103353.c
new file mode 100644
index 000..5d519fb1b7b
--- /dev/null
+++ b/gcc/testsuite/gcc.target/powerpc/pr103353.c
@@ -0,0 +1,22 @@
+/* { dg-require-effective-target powerpc_altivec_ok } */
+/* If the default cpu type is power10 or later, MMA is enabled by default.
+   To keep the test point available all the time, this case specifies
+   -mdejagnu-cpu=power6 to make it be tested without MMA.  */
+/* { dg-options "-maltivec -mdejagnu-cpu=power6" } */
+
+/* Verify there is no ICE and don't check the error messages on MMA
+   requirement since they could be fragile and are not test points
+   of this case.  */
+/* { dg-excess-errors "pr103353" } */
+
+void
+foo (__vector_pair *dst, double *x)
+{
+  dst[0] = __builtin_vsx_lxvp (0, (__vector_pair *)(void *)x);
+}
+
+void
+bar (__vector_pair *src, double *x)
+{
+  __builtin_vsx_stxvp (src[0], 0, (__vector_pair *)(void *)x);
+}


Re: [PATCH] c++: set TYPE_CANONICAL for most templated types

2022-05-18 Thread Jason Merrill via Gcc-patches

On 5/16/22 15:58, Patrick Palka wrote:

When processing a class template specialization, lookup_template_class
uses structural equality for the specialized type whenever one of its
template arguments uses structural equality.  This the sensible thing to
do in a vacuum, but given that we already effectively deduplicate class
specializations via the spec_hasher, it seems to me we can safely assume
that each class specialization is unique and therefore canonical,
regardless of the structure of the template arguments.


Makes sense.


To that end this patch makes us use the canonical type machinery for all
type specializations except for the case where a PARM_DECL appears in
the template arguments (added in r12-3766-g72394d38d929c7).

Additionally, this patch makes us use the canonical type machinery for
TEMPLATE_TEMPLATE_PARMs and BOUND_TEMPLATE_TEMPLATE_PARMs, by extending
canonical_type_parameter appropriately.  A comment in tsubst says it's
unsafe to set TYPE_CANONICAL for a lowered TEMPLATE_TEMPLATE_PARM, but
I'm not sure I understand it.


I think that comment from r120341 became obsolete when r129844 (later 
that year) started to substitute the template parms of ttps.



Note that r10-7817-ga6f400239d792d
recently changed process_template_parm to clear TYPE_CANONICAL for
TEMPLATE_TEMPLATE_PARM consistent with the tsubst comment; this patch
changes both functions to set instead of clear TYPE_CANONICAL for ttps.

This change improves compile time of heavily templated code by around 10%
for me (with a release compiler).  For instance, compile time for the
libstdc++ test std/ranges/adaptors/all.cc drops from 1.45s to 1.25s, and
for the range-v3 test test/view/zip.cpp it goes from 5.38s to 4.88s.
The total number of calls to structural_comptypes for the latter test
drops from 8.5M to 1.5M.  Memory use is unchanged (unsurpisingly).


Nice!


Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for
trunk?  Also tested on cmcstl2 and range-v3 and various boost libraries.
Will also do more testing overnight...


One comment below.


gcc/cp/ChangeLog:

* pt.cc (any_template_arguments_need_structural_equality_p):
Remove.
(struct ctp_hasher): Define.
(ctp_table): Define.
(canonical_type_parameter): Use it.
(process_template_parm): Set TYPE_CANONICAL for
TEMPLATE_TEMPLATE_PARM too.
(lookup_template_class_1): Don't call a_t_a_n_s_e_p.  Inline
the PARM_DECL special case from that subroutine into here.
(tsubst) : Remove special
TYPE_CANONICAL handling specific to ttps, and perform the
remaining handling later.
(find_parm_usage_r): Remove.
* tree.cc (bind_template_template_parm): Set TYPE_CANONICAL
when safe to do so.
* typeck.cc (structural_comptypes) [check_alias]: Increment
processing_template_decl before using
dependent_alias_template_spec_p.
---
  gcc/cp/pt.cc | 166 ---
  gcc/cp/tree.cc   |  16 -
  gcc/cp/typeck.cc |   2 +
  3 files changed, 73 insertions(+), 111 deletions(-)

diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index fa05e9134df..76562877355 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -203,7 +203,6 @@ static tree copy_default_args_to_explicit_spec_1 (tree, 
tree);
  static void copy_default_args_to_explicit_spec (tree);
  static bool invalid_nontype_parm_type_p (tree, tsubst_flags_t);
  static bool dependent_template_arg_p (tree);
-static bool any_template_arguments_need_structural_equality_p (tree);
  static bool dependent_type_p_r (tree);
  static tree tsubst_copy   (tree, tree, tsubst_flags_t, tree);
  static tree tsubst_decl (tree, tree, tsubst_flags_t);
@@ -4526,6 +4525,27 @@ build_template_parm_index (int index,
return t;
  }
  
+struct ctp_hasher : ggc_ptr_hash

+{
+  static hashval_t hash (tree t)
+  {
+tree_code code = TREE_CODE (t);
+hashval_t val = iterative_hash_object (code, 0);
+val = iterative_hash_object (TEMPLATE_TYPE_LEVEL (t), val);
+val = iterative_hash_object (TEMPLATE_TYPE_IDX (t), val);
+if (TREE_CODE (t) == BOUND_TEMPLATE_TEMPLATE_PARM)
+  val = iterative_hash_template_arg (TYPE_TI_ARGS (t), val);
+return val;
+  }
+
+  static bool equal (tree t, tree u)
+  {
+return comptypes (t, u, COMPARE_STRUCTURAL);
+  }
+};
+
+static GTY (()) hash_table *ctp_table;
+
  /* Find the canonical type parameter for the given template type
 parameter.  Returns the canonical type parameter, which may be TYPE
 if no such parameter existed.  */
@@ -4533,21 +4553,13 @@ build_template_parm_index (int index,
  tree
  canonical_type_parameter (tree type)
  {
-  int idx = TEMPLATE_TYPE_IDX (type);
-
-  gcc_assert (TREE_CODE (type) != TEMPLATE_TEMPLATE_PARM);
+  if (ctp_table == NULL)
+ctp_table = hash_table::create_ggc (61);
  
-  if (vec_safe_length (canonical_template_parms) <= (unsigned) idx)

-vec_safe_grow_cleared (canonical_template_parm

[PATCH, committed] testsuite/rs6000: Move pr83660.C to g++.target

2022-05-18 Thread Kewen.Lin via Gcc-patches
Hi,

Move pr83660.C to g++.target.  As comment #3 of PR83660,
renaming it to c isn't one option.

This test case isn't tested before, so this brings back
the test coverage.

Committed as r13-619-g297a69068ddfe2.

BR,
Kewen
-
gcc/testsuite/ChangeLog:

* gcc.target/powerpc/pr83660.C: Moved to...
* g++.target/powerpc/pr83660.C: ...here.
---
 gcc/testsuite/{gcc.target => g++.target}/powerpc/pr83660.C | 0
 1 file changed, 0 insertions(+), 0 deletions(-)
 rename gcc/testsuite/{gcc.target => g++.target}/powerpc/pr83660.C (100%)

diff --git a/gcc/testsuite/gcc.target/powerpc/pr83660.C 
b/gcc/testsuite/g++.target/powerpc/pr83660.C
similarity index 100%
rename from gcc/testsuite/gcc.target/powerpc/pr83660.C
rename to gcc/testsuite/g++.target/powerpc/pr83660.C



Re: [PATCH] c++: constexpr init of union sub-aggr w/ base [PR105491]

2022-05-18 Thread Jason Merrill via Gcc-patches

On 5/17/22 12:34, Patrick Palka wrote:

On Sat, May 7, 2022 at 5:18 PM Jason Merrill  wrote:


On 5/6/22 16:46, Patrick Palka wrote:

On Fri, 6 May 2022, Jason Merrill wrote:


On 5/6/22 16:10, Patrick Palka wrote:

On Fri, 6 May 2022, Patrick Palka wrote:


On Fri, 6 May 2022, Jason Merrill wrote:


On 5/6/22 14:00, Patrick Palka wrote:

On Fri, 6 May 2022, Patrick Palka wrote:


On Fri, 6 May 2022, Jason Merrill wrote:


On 5/6/22 11:22, Patrick Palka wrote:

Here ever since r10-7313-gb599bf9d6d1e18,
reduced_constant_expression_p
in C++11/14 is rejecting the marked sub-aggregate initializer
(of type
S)

   W w = {.D.2445={.s={.D.2387={.m=0}, .b=0}}}
  ^

ultimately because said initializer has CONSTRUCTOR_NO_CLEARING
set,
and
so the function proceeds to verify that all fields of S are
initialized.
And before C++17 we don't expect to see base class fields (since
next_initializable_field skips over the), so the base class
initializer
causes r_c_e_p to return false.


That seems like the primary bug.  I guess r_c_e_p shouldn't be
using
next_initializable_field.  Really that function should only be
used for
aggregates.


I see, I'll try replacing it in r_c_e_p.  Would that be in addition
to
or instead of the clear_no_implicit_zero approach?


I'm testing the following, which uses a custom predicate instead of
next_initializable_field in r_c_e_p.


Let's make it a public predicate, not internal to r_c_e_p.  Maybe it
could be
next_subobject_field, and the current next_initializable_field change to
next_aggregate_field?


Will do.




Looks like the inner initializer {.D.2387={.m=0}, .b=0} is formed
during
the subobject constructor call:

 V::V (&((struct S *) this)->D.2120);

after the evaluation of which, 'result' in cxx_eval_call_expression is
NULL
(presumably because it's a CALL_EXPR, not AGGR_INIT_EXPR?):

 /* This can be null for a subobject constructor call, in
which case what we care about is the initialization
side-effects rather than the value.  We could get at the
value by evaluating *this, but we don't bother; there's
no need to put such a call in the hash table.  */
 result = lval ? ctx->object : ctx->ctor;

so we end up not calling clear_no_implicit_zero for the inner
initializer
directly.  We only call clear_no_implicit_zero after evaluating the
AGGR_INIT_EXPR for outermost initializer (of type W).


Maybe for constructors we could call it on ctx->ctor instead of result,
or
call r_c_e_p in C++20+?


But both ctx->ctor and ->object are NULL during a subobject constructor
call (since we apparently clear these fields when entering a
STATEMENT_LIST):

So I tried instead obtaining the constructor by evaluating new_obj via

--- a/gcc/cp/constexpr.cc
+++ b/gcc/cp/constexpr.cc
@@ -2993,6 +2988,9 @@ cxx_eval_call_expression (const constexpr_ctx *ctx,
tree t,
 in order to detect reading an unitialized object in constexpr
instead
 of value-initializing it.  (reduced_constant_expression_p is
expected to
 take care of clearing the flag.)  */
+  if (new_obj && DECL_CONSTRUCTOR_P (fun))
+result = cxx_eval_constant_expression (ctx, new_obj, /*lval=*/false,
+  non_constant_p, overflow_p);
  if (TREE_CODE (result) == CONSTRUCTOR
  && (cxx_dialect < cxx20
 || !DECL_CONSTRUCTOR_P (fun)))

but that seems to break e.g. g++.dg/cpp2a/constexpr-init12.C because
after the subobject constructor call

 S::S (&((struct W *) this)->s, NON_LVALUE_EXPR <8>);

the constructor for the subobject a.s in new_obj is still completely
missing (I suppose because S::S doesn't initialize any of its members)
so trying to obtain it causes us to complain too soon from
cxx_eval_component_reference:

constexpr-init12.C:16:24:   in ‘constexpr’ expansion of ‘W(42)’
constexpr-init12.C:10:22:   in ‘constexpr’ expansion of
‘((W*)this)->W::s.S::S(8)’
constexpr-init12.C:16:24: error: accessing uninitialized member ‘W::s’
  16 | constexpr auto a = W(42); // { dg-error "not a constant
expression" }
 |^



It does seem dubious that we would clear the flag on an outer ctor when
it's
still set on an inner ctor, should probably add an assert somewhere.


Makes sense, not sure where the best place would be..


On second thought, if I'm understanding your suggestion correctly, I
don't think we can generally enforce such a property for
CONSTRUCTOR_NO_CLEARING, given how cxx_eval_store_expression uses it for
unions:

 union U {
   struct { int x, y; } a;
 } u;
 u.a.x = 0;

Here after evaluating the assignment, the outer ctor for the union will
have CONSTRUCTOR_NO_CLEARING cleared to indicate we finished activating
the union member, but the inner ctor is certainly not fully initialized
so it'll have CONSTRUCTOR_NO_CLEARING set still.


Why clear the flag on the union before the inner ctor is fully initialized, if
the intent is to prevent changi

Re: [PATCH v3] c, c++: -Wswitch warning on [[maybe_unused]] enumerator [PR105497]

2022-05-18 Thread Jason Merrill via Gcc-patches

On 5/17/22 19:55, Marek Polacek wrote:

On Tue, May 10, 2022 at 09:54:12AM -0400, Marek Polacek wrote:

On Tue, May 10, 2022 at 08:58:46AM -0400, Jason Merrill wrote:

On 5/7/22 18:26, Marek Polacek wrote:

Corrected version that avoids an uninitialized warning:

This PR complains that we emit the "enumeration value not handled in
switch" warning even though the enumerator was marked with the
[[maybe_unused]] attribute.

The first snag was that I couldn't just check TREE_USED, because
the enumerator could have been used earlier in the function, which
doesn't play well with the c_do_switch_warnings warning.  Instead,
I had to check the attributes on the CONST_DECL directly, which led
to the second, and worse, snag: in C we don't have direct access to
the CONST_DECL for the enumerator.


I wonder if you want to change that instead of working around it?


I wouldn't mind looking into that; I've hit this discrepancy numerous
times throughout the years and it'd be good to unify it so that the
c-common code doesn't need to hack around it.
  
Let's see how far I'll get...
  
Now done (r13-575), which makes this patch a piece of cake.


Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?


OK.


-- >8 --
This PR complains that we emit the "enumeration value not handled in
switch" warning even though the enumerator was marked with the
[[maybe_unused]] attribute.

I couldn't just check TREE_USED, because the enumerator could have been
used earlier in the function, which doesn't play well with the
c_do_switch_warnings warning.  Instead, I had to check the attributes on
the CONST_DECL.  This is easy since the TYPE_VALUES of an enum type are
now consistent between C and C++, both of which store the CONST_DECL in
its TREE_VALUE.

PR c++/105497

gcc/c-family/ChangeLog:

* c-warn.cc (c_do_switch_warnings): Don't warn about unhandled
enumerator when it was marked with attribute unused.

gcc/testsuite/ChangeLog:

* c-c++-common/Wswitch-1.c: New test.
* g++.dg/warn/Wswitch-4.C: New test.
---
  gcc/c-family/c-warn.cc | 11 +-
  gcc/testsuite/c-c++-common/Wswitch-1.c | 29 ++
  gcc/testsuite/g++.dg/warn/Wswitch-4.C  | 52 ++
  3 files changed, 90 insertions(+), 2 deletions(-)
  create mode 100644 gcc/testsuite/c-c++-common/Wswitch-1.c
  create mode 100644 gcc/testsuite/g++.dg/warn/Wswitch-4.C

diff --git a/gcc/c-family/c-warn.cc b/gcc/c-family/c-warn.cc
index cae89294aea..ea7335f3edf 100644
--- a/gcc/c-family/c-warn.cc
+++ b/gcc/c-family/c-warn.cc
@@ -1738,8 +1738,8 @@ c_do_switch_warnings (splay_tree cases, location_t 
switch_location,
for (chain = TYPE_VALUES (type); chain; chain = TREE_CHAIN (chain))
  {
tree value = TREE_VALUE (chain);
-  if (TREE_CODE (value) == CONST_DECL)
-   value = DECL_INITIAL (value);
+  tree attrs = DECL_ATTRIBUTES (value);
+  value = DECL_INITIAL (value);
node = splay_tree_lookup (cases, (splay_tree_key) value);
if (node)
{
@@ -1769,6 +1769,13 @@ c_do_switch_warnings (splay_tree cases, location_t 
switch_location,
/* We've now determined that this enumerated literal isn't
 handled by the case labels of the switch statement.  */
  
+  /* Don't warn if the enumerator was marked as unused.  We can't use

+TREE_USED here: it could have been set on the enumerator if the
+enumerator was used earlier.  */
+  if (lookup_attribute ("unused", attrs)
+ || lookup_attribute ("maybe_unused", attrs))
+   continue;
+
/* If the switch expression is a constant, we only really care
 about whether that constant is handled by the switch.  */
if (cond && tree_int_cst_compare (cond, value))
diff --git a/gcc/testsuite/c-c++-common/Wswitch-1.c 
b/gcc/testsuite/c-c++-common/Wswitch-1.c
new file mode 100644
index 000..de9ee03b0a3
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/Wswitch-1.c
@@ -0,0 +1,29 @@
+/* PR c++/105497 */
+/* { dg-options "-Wswitch" } */
+
+enum E {
+  A,
+  B,
+  C __attribute((unused)),
+  D
+};
+
+void
+g (enum E e)
+{
+  switch (e)
+{
+case A:
+case B:
+case D:
+  break;
+}
+
+  switch (e) // { dg-warning "not handled in switch" }
+{
+case A:
+case B:
+case C:
+  break;
+}
+}
diff --git a/gcc/testsuite/g++.dg/warn/Wswitch-4.C 
b/gcc/testsuite/g++.dg/warn/Wswitch-4.C
new file mode 100644
index 000..553a57d777b
--- /dev/null
+++ b/gcc/testsuite/g++.dg/warn/Wswitch-4.C
@@ -0,0 +1,52 @@
+// PR c++/105497
+// { dg-do compile { target c++11 } }
+// { dg-options "-Wswitch" }
+
+enum class Button
+{
+Left,
+Right,
+Middle,
+NumberOfButtons [[maybe_unused]]
+};
+
+enum class Sound
+{
+  Bark,
+  Meow,
+  Hiss,
+  Moo __attribute((unused))
+};
+
+enum class Chordata
+{
+  Urochordata,
+  Cephalochordata,
+  Vertebrata
+};
+
+int main()
+{
+  Button b = Button::Left;
+  switch (b) { // { dg-bogus "not 

Re: [PATCH] c++: fix SIGFPE with -Wclass-memaccess [PR105634]

2022-05-18 Thread Jason Merrill via Gcc-patches

On 5/17/22 19:57, Marek Polacek wrote:

Here we crash because we attempt to % by 0.  Thus fixed.
While at it, I've moved the -Wclass-memaccess tests into warn/.
I've checked that the # of expected passes is the same before/after
the move.

Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?


OK.


PR c++/105634

gcc/cp/ChangeLog:

* call.cc (maybe_warn_class_memaccess): Avoid % by zero.

gcc/testsuite/ChangeLog:

* g++.dg/Wclass-memaccess-2.C: Moved to...
* g++.dg/warn/Wclass-memaccess-2.C: ...here.
* g++.dg/Wclass-memaccess-3.C: Moved to...
* g++.dg/warn/Wclass-memaccess-3.C: ...here.
* g++.dg/Wclass-memaccess-4.C: Moved to...
* g++.dg/warn/Wclass-memaccess-4.C: ...here.
* g++.dg/Wclass-memaccess-5.C: Moved to...
* g++.dg/warn/Wclass-memaccess-5.C: ...here.
* g++.dg/Wclass-memaccess-6.C: Moved to...
* g++.dg/warn/Wclass-memaccess-6.C: ...here.
* g++.dg/Wclass-memaccess.C: Moved to...
* g++.dg/warn/Wclass-memaccess.C: ...here.
* g++.dg/warn/Wclass-memaccess-7.C: New test.
---
  gcc/cp/call.cc  |  2 ++
  .../g++.dg/{ => warn}/Wclass-memaccess-2.C  |  0
  .../g++.dg/{ => warn}/Wclass-memaccess-3.C  |  0
  .../g++.dg/{ => warn}/Wclass-memaccess-4.C  |  0
  .../g++.dg/{ => warn}/Wclass-memaccess-5.C  |  0
  .../g++.dg/{ => warn}/Wclass-memaccess-6.C  |  0
  gcc/testsuite/g++.dg/warn/Wclass-memaccess-7.C  | 13 +
  gcc/testsuite/g++.dg/{ => warn}/Wclass-memaccess.C  |  0
  8 files changed, 15 insertions(+)
  rename gcc/testsuite/g++.dg/{ => warn}/Wclass-memaccess-2.C (100%)
  rename gcc/testsuite/g++.dg/{ => warn}/Wclass-memaccess-3.C (100%)
  rename gcc/testsuite/g++.dg/{ => warn}/Wclass-memaccess-4.C (100%)
  rename gcc/testsuite/g++.dg/{ => warn}/Wclass-memaccess-5.C (100%)
  rename gcc/testsuite/g++.dg/{ => warn}/Wclass-memaccess-6.C (100%)
  create mode 100644 gcc/testsuite/g++.dg/warn/Wclass-memaccess-7.C
  rename gcc/testsuite/g++.dg/{ => warn}/Wclass-memaccess.C (100%)

diff --git a/gcc/cp/call.cc b/gcc/cp/call.cc
index 0240e364324..14c6037729f 100644
--- a/gcc/cp/call.cc
+++ b/gcc/cp/call.cc
@@ -10329,6 +10329,8 @@ maybe_warn_class_memaccess (location_t loc, tree fndecl,
  /* Finally, warn on partial copies.  */
  unsigned HOST_WIDE_INT typesize
= tree_to_uhwi (TYPE_SIZE_UNIT (desttype));
+ if (typesize == 0)
+   break;
  if (unsigned HOST_WIDE_INT partial = tree_to_uhwi (sz) % typesize)
warned = warning_at (loc, OPT_Wclass_memaccess,
 (typesize - partial > 1
diff --git a/gcc/testsuite/g++.dg/Wclass-memaccess-2.C 
b/gcc/testsuite/g++.dg/warn/Wclass-memaccess-2.C
similarity index 100%
rename from gcc/testsuite/g++.dg/Wclass-memaccess-2.C
rename to gcc/testsuite/g++.dg/warn/Wclass-memaccess-2.C
diff --git a/gcc/testsuite/g++.dg/Wclass-memaccess-3.C 
b/gcc/testsuite/g++.dg/warn/Wclass-memaccess-3.C
similarity index 100%
rename from gcc/testsuite/g++.dg/Wclass-memaccess-3.C
rename to gcc/testsuite/g++.dg/warn/Wclass-memaccess-3.C
diff --git a/gcc/testsuite/g++.dg/Wclass-memaccess-4.C 
b/gcc/testsuite/g++.dg/warn/Wclass-memaccess-4.C
similarity index 100%
rename from gcc/testsuite/g++.dg/Wclass-memaccess-4.C
rename to gcc/testsuite/g++.dg/warn/Wclass-memaccess-4.C
diff --git a/gcc/testsuite/g++.dg/Wclass-memaccess-5.C 
b/gcc/testsuite/g++.dg/warn/Wclass-memaccess-5.C
similarity index 100%
rename from gcc/testsuite/g++.dg/Wclass-memaccess-5.C
rename to gcc/testsuite/g++.dg/warn/Wclass-memaccess-5.C
diff --git a/gcc/testsuite/g++.dg/Wclass-memaccess-6.C 
b/gcc/testsuite/g++.dg/warn/Wclass-memaccess-6.C
similarity index 100%
rename from gcc/testsuite/g++.dg/Wclass-memaccess-6.C
rename to gcc/testsuite/g++.dg/warn/Wclass-memaccess-6.C
diff --git a/gcc/testsuite/g++.dg/warn/Wclass-memaccess-7.C 
b/gcc/testsuite/g++.dg/warn/Wclass-memaccess-7.C
new file mode 100644
index 000..7e86b248629
--- /dev/null
+++ b/gcc/testsuite/g++.dg/warn/Wclass-memaccess-7.C
@@ -0,0 +1,13 @@
+// PR c++/105634
+// { dg-do compile { target { c++11 } } }
+// { dg-options "-Wall" }
+
+struct s
+{
+  struct {} a[] = 1.0; // { dg-error "" }
+  void f (char *c)
+  {
+s s;
+__builtin_memcpy (&s, c, sizeof(s));
+  }
+};
diff --git a/gcc/testsuite/g++.dg/Wclass-memaccess.C 
b/gcc/testsuite/g++.dg/warn/Wclass-memaccess.C
similarity index 100%
rename from gcc/testsuite/g++.dg/Wclass-memaccess.C
rename to gcc/testsuite/g++.dg/warn/Wclass-memaccess.C

base-commit: c9852156dd2fedec130f6d8eb669579ef6237946




[c-family] Reduce usage of limited_with clauses with -fdump-ada-spec

2022-05-18 Thread Eric Botcazou via Gcc-patches
The problem is that subtypes are not part of the limited view of a package so
we need to use types in conjunction with limited_with clauses, which is not
always desirable since this yields less portable Ada bindings.  The patch
also contains a small enhancement for complex floating-point types.

Tested on x86-64/Linux, applied on mainline and 12 branch.


2022-05-18  Eric Botcazou  

* c-ada-spec.cc (dump_ada_node) : Deal with usual
floating-point complex types.
: Do not use limited_with clause if the designated
type is a scalar type.

-- 
Eric Botcazoudiff --git a/gcc/c-family/c-ada-spec.cc b/gcc/c-family/c-ada-spec.cc
index f291e150934..faf71742522 100644
--- a/gcc/c-family/c-ada-spec.cc
+++ b/gcc/c-family/c-ada-spec.cc
@@ -2105,6 +2105,21 @@ dump_ada_node (pretty_printer *buffer, tree node, tree type, int spc,
 	  append_withs ("Interfaces.C.Extensions", false);
 	  pp_string (buffer, "Extensions.CFloat_128");
 	}
+  else if (TREE_TYPE (node) == float_type_node)
+	{
+	  append_withs ("Ada.Numerics.Complex_Types", false);
+	  pp_string (buffer, "Ada.Numerics.Complex_Types.Complex");
+	}
+  else if (TREE_TYPE (node) == double_type_node)
+	{
+	  append_withs ("Ada.Numerics.Long_Complex_Types", false);
+	  pp_string (buffer, "Ada.Numerics.Long_Complex_Types.Complex");
+	}
+  else if (TREE_TYPE (node) == long_double_type_node)
+	{
+	  append_withs ("Ada.Numerics.Long_Long_Complex_Types", false);
+	  pp_string (buffer, "Ada.Numerics.Long_Long_Complex_Types.Complex");
+	}
   else
 	pp_string (buffer, "");
   break;
@@ -2190,7 +2205,7 @@ dump_ada_node (pretty_printer *buffer, tree node, tree type, int spc,
 	{
 	  tree ref_type = TREE_TYPE (node);
 	  const unsigned int quals = TYPE_QUALS (ref_type);
-	  bool is_access = false;
+	  bool is_access;
 
 	  if (VOID_TYPE_P (ref_type))
 	{
@@ -2242,7 +2257,10 @@ dump_ada_node (pretty_printer *buffer, tree node, tree type, int spc,
 		}
 
 		  if (!package_prefix)
-		pp_string (buffer, "access");
+		{
+		  is_access = false;
+		  pp_string (buffer, "access");
+		}
 		  else if (AGGREGATE_TYPE_P (ref_type))
 		{
 		  if (!type || TREE_CODE (type) != FUNCTION_DECL)
@@ -2256,17 +2274,21 @@ dump_ada_node (pretty_printer *buffer, tree node, tree type, int spc,
 			pp_string (buffer, "all ");
 			}
 		  else if (quals & TYPE_QUAL_CONST)
-			pp_string (buffer, "in ");
+			{
+			  is_access = false;
+			  pp_string (buffer, "in ");
+			}
 		  else
 			{
 			  is_access = true;
 			  pp_string (buffer, "access ");
-			  /* ??? should be configurable: access or in out.  */
 			}
 		}
 		  else
 		{
-		  is_access = true;
+		  /* We want to use regular with clauses for scalar types,
+			 as they are not involved in circular declarations.  */
+		  is_access = false;
 		  pp_string (buffer, "access ");
 
 		  if (!name_only)


Re: [committed] d: Merge upstream dmd 60bfa0ee7, druntime 94bd5bcb, phobos 3a1cd9a01.

2022-05-18 Thread Rainer Orth
Hi Iain,

> Upstream dmd has now released v2.100.0, this patch merges in the
> latest bug fixes since the last sync-up of the release branch, as well
> as all new feature changes on development branch.
[...]
> D runtime changes:
>
> - Import druntime v2.100.0.
>
> Bootstrapped and regression tested on x86_64-linux-gnu/-m32/-mx32, and
> committed to mainline.

this patch broke Solaris bootstrap:

/vol/gcc/src/hg/master/local/libphobos/libdruntime/core/sys/solaris/link.d-mixin-162:162:7:
 error: struct 'core.sys.elf.Elf32_Dyn' at 
/vol/gcc/src/hg/master/local/libphobos/libdruntime/core/sys/elf/package.d:620:1 
conflicts with struct 'core.sys.solaris.sys.link.Elf32_Dyn' at 
/vol/gcc/src/hg/master/local/libphobos/libdruntime/core/sys/solaris/sys/link.d:15:1
/vol/gcc/src/hg/master/local/libphobos/libdruntime/gcc/sections/elf.d:743:9: 
error: template instance 'core.sys.solaris.link.ElfW!"Dyn"' error instantiating
  743 | ElfW!"Dyn"[] dyns;
  | ^

and similarly for Elf64_Dyn.

There were also redefinition errors for DT_NEEDED, DT_STRTAB,
DT_AUXILIARY, and DT_FILTER.

The following patch avoids those by removing the Elf??_Dyn declarations
from core/sys/solaris/sys/link.d resp. adding the missing d_off field in
core/sys/elf/package.d, as well as the duplicate DT_* definitions.  I've
not yet fully checked if there are other duplicates or declarations in
current Solaris  etc. that are missing from the D headers.

This was enough to restore bootstrap for now.

Rainer

-- 
-
Rainer Orth, Center for Biotechnology, Bielefeld University


diff --git a/libphobos/libdruntime/core/sys/elf/package.d b/libphobos/libdruntime/core/sys/elf/package.d
--- a/libphobos/libdruntime/core/sys/elf/package.d
+++ b/libphobos/libdruntime/core/sys/elf/package.d
@@ -624,6 +624,7 @@ struct Elf32_Dyn
   {
   Elf32_Word d_val;
   Elf32_Addr d_ptr;
+  Elf32_Off  d_off;
   } _d_un d_un;
 }
 
diff --git a/libphobos/libdruntime/core/sys/solaris/sys/link.d b/libphobos/libdruntime/core/sys/solaris/sys/link.d
--- a/libphobos/libdruntime/core/sys/solaris/sys/link.d
+++ b/libphobos/libdruntime/core/sys/solaris/sys/link.d
@@ -10,35 +10,13 @@ extern (C):
 nothrow:
 
 public import core.sys.solaris.sys.elftypes;
+public import core.sys.elf;
 import core.stdc.config;
 
-struct Elf32_Dyn
-{
-Elf32_Sword d_tag;
-union _d_un
-{
-Elf32_Word d_val;
-Elf32_Addr d_ptr;
-Elf32_Off  d_off;
-} _d_un d_un;
-}
-
-struct Elf64_Dyn
-{
-Elf64_Xword d_tag;
-union _d_un
-{
-Elf64_Xword d_val;
-Elf64_Addr  d_ptr;
-} _d_un d_un;
-}
-
 enum DT_NULL = 0;
-enum DT_NEEDED   = 1;
 enum DT_PLTRELSZ = 2;
 enum DT_PLTGOT   = 3;
 enum DT_HASH = 4;
-enum DT_STRTAB   = 5;
 enum DT_SYMTAB   = 6;
 enum DT_RELA = 7;
 enum DT_RELASZ   = 8;
@@ -138,9 +116,7 @@ enum DT_VERNEED= 0x6ffe;
 enum DT_VERNEEDNUM = 0x6fff;
 
 enum DT_LOPROC= 0x7000;
-enum DT_AUXILIARY = 0x7ffd;
 enum DT_USED  = 0x7ffe;
-enum DT_FILTER= 0x7fff;
 enum DT_HIPROC= 0x7fff;
 
 enum DF_ORIGIN = 0x0001;


[PATCH v2] c: Implement new -Wenum-int-mismatch warning [PR105131]

2022-05-18 Thread Marek Polacek via Gcc-patches
On Wed, May 18, 2022 at 11:14:25AM +0100, Pedro Alves wrote:
> On 2022-05-18 00:56, Marek Polacek via Gcc-patches wrote:
> 
> > +In C, an enumerated type is compatible with @code{char}, a signed
> > +integer type, or an unsigned integer type.  However, since the choice
> > +of the underlying type of an enumerated type is implementation-defined,
> > +such mismatches may cause portability issues.  In C++, such mismatches
> > +are an error.  In C, this warning is enabled by @option{-Wall}.
> 
> Should it also be enabled by -Wc++-compat?

Yes, that's a good idea.  Fixed here:

Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?

-- >8 --
In C, an enumerated type is compatible with char, a signed integer type,
or an unsigned integer type (6.7.2.2/5).  Therefore this code compiles:

  enum E { l = -1, z = 0, g = 1 };
  int foo(void);
  enum E foo(void) { return z; }

if the underlying type of 'enum E' is 'int' (if not, we emit an error).
This is different for typedefs, where C11 permits typedefs to be
redeclared to the same type, but not to compatible types.  In C++, the
code above is invalid.

It seems desirable to emit a warning in the C case, because it is
probably a mistake and definitely a portability error, given that the
choice of the underlying type is implementation-defined.

To that end, this patch implements a new -Wenum-int-mismatch warning.
Conveniently, we already have comptypes_check_enum_int to detect such
mismatches.  This warning is enabled by either -Wall or -Wc++-compat.

PR c/105131

gcc/c-family/ChangeLog:

* c.opt (Wenum-int-mismatch): New.

gcc/c/ChangeLog:

* c-decl.cc (diagnose_mismatched_decls): Warn about enum/integer type
mismatches.
* c-tree.h (comptypes_check_enum_int): Declare.
* c-typeck.cc (comptypes): No longer static.

gcc/ChangeLog:

* doc/invoke.texi: Document -Wenum-int-mismatch.

gcc/testsuite/ChangeLog:

* gcc.dg/Wenum-int-mismatch-1.c: New test.
* gcc.dg/Wenum-int-mismatch-2.c: New test.
* gcc.dg/Wenum-int-mismatch-3.c: New test.
---
 gcc/c-family/c.opt  |  4 +++
 gcc/c/c-decl.cc | 13 ++--
 gcc/c/c-tree.h  |  1 +
 gcc/c/c-typeck.cc   |  2 +-
 gcc/doc/invoke.texi | 21 +
 gcc/testsuite/gcc.dg/Wenum-int-mismatch-1.c | 35 +
 gcc/testsuite/gcc.dg/Wenum-int-mismatch-2.c | 35 +
 gcc/testsuite/gcc.dg/Wenum-int-mismatch-3.c | 35 +
 8 files changed, 143 insertions(+), 3 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/Wenum-int-mismatch-1.c
 create mode 100644 gcc/testsuite/gcc.dg/Wenum-int-mismatch-2.c
 create mode 100644 gcc/testsuite/gcc.dg/Wenum-int-mismatch-3.c

diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt
index 035b1de0d84..41a20bc625e 100644
--- a/gcc/c-family/c.opt
+++ b/gcc/c-family/c.opt
@@ -638,6 +638,10 @@ Wenum-conversion
 C ObjC C++ ObjC++ Var(warn_enum_conversion) Init(0) Warning LangEnabledBy(C 
ObjC,Wextra)
 Warn about implicit conversion of enum types.
 
+Wenum-int-mismatch
+C ObjC Var(warn_enum_int_mismatch) Warning LangEnabledBy(C ObjC,Wall || 
Wc++-compat)
+Warn about enum/integer type mismatches.
+
 Werror
 C ObjC C++ ObjC++
 ; Documented in common.opt
diff --git a/gcc/c/c-decl.cc b/gcc/c/c-decl.cc
index 83655548fc4..5266a61b859 100644
--- a/gcc/c/c-decl.cc
+++ b/gcc/c/c-decl.cc
@@ -1993,9 +1993,12 @@ diagnose_mismatched_decls (tree newdecl, tree olddecl,
 
   bool pedwarned = false;
   bool warned = false;
+  bool enum_and_int_p = false;
   auto_diagnostic_group d;
 
-  if (!comptypes (oldtype, newtype))
+  int comptypes_result = comptypes_check_enum_int (oldtype, newtype,
+  &enum_and_int_p);
+  if (!comptypes_result)
 {
   if (TREE_CODE (olddecl) == FUNCTION_DECL
  && fndecl_built_in_p (olddecl, BUILT_IN_NORMAL)
@@ -2137,6 +2140,13 @@ diagnose_mismatched_decls (tree newdecl, tree olddecl,
  return false;
}
 }
+  /* Warn about enum/integer type mismatches.  They are compatible types
+ (C2X 6.7.2.2/5), but may pose portability problems.  */
+  else if (enum_and_int_p && TREE_CODE (newdecl) != TYPE_DECL)
+warned = warning_at (DECL_SOURCE_LOCATION (newdecl),
+OPT_Wenum_int_mismatch,
+"conflicting types for %q+D due to enum/integer "
+"mismatch; have %qT", newdecl, newtype);
 
   /* Redeclaration of a type is a constraint violation (6.7.2.3p1),
  but silently ignore the redeclaration if either is in a system
@@ -2146,7 +2156,6 @@ diagnose_mismatched_decls (tree newdecl, tree olddecl,
   if (TREE_CODE (newdecl) == TYPE_DECL)
 {
   bool types_different = false;
-  int comptypes_result;
 
   comptypes_result
= comptypes_check_different_types (oldtype, newtype, &types_differen

[r13-456 Regression] FAIL: g++.dg/tsan/pr88018.C -O0 (test for excess errors) on Linux/x86_64

2022-05-18 Thread skpandey--- via Gcc-patches
On Linux/x86_64,

eccbd7fcee5bbfc47731e8de83c44eee2e3dcc4b is the first bad commit
commit eccbd7fcee5bbfc47731e8de83c44eee2e3dcc4b
Author: Paul A. Clarke 
Date:   Mon Feb 21 12:14:01 2022 -0600

rs6000: Move g++.dg powerpc PR tests to g++.target

caused

FAIL: g++.dg/tsan/pr88018.C   -O0  (test for excess errors)

with GCC configured with

../../gcc/configure 
--prefix=/local/skpandey/gccwork/toolwork/gcc-bisect-master/master/r13-456/usr 
--enable-clocale=gnu --with-system-zlib --with-demangler-in-ld 
--with-fpmath=sse --enable-languages=c,c++,fortran --enable-cet --without-isl 
--enable-libmpx x86_64-linux --disable-bootstrap

To reproduce:

$ cd {build_dir}/gcc && make check RUNTESTFLAGS="tsan.exp=g++.dg/tsan/pr88018.C 
--target_board='unix{-m64}'"
$ cd {build_dir}/gcc && make check RUNTESTFLAGS="tsan.exp=g++.dg/tsan/pr88018.C 
--target_board='unix{-m64\ -march=cascadelake}'"

(Please do not reply to this email, for question about this report, contact me 
at skpgkp2 at gmail dot com)


[PATCH take #2] PR middle-end/98865: Expand X*Y as X&-Y when Y is [0.1].

2022-05-18 Thread Roger Sayle

The patch is a revised solution for PR middle-end/98865 incorporating
the feedback/suggestions from Richard Biener's review here:
https://gcc.gnu.org/pipermail/gcc-patches/2022-May/593928.html
Most significantly, this patch now performs the transformation/optimization
during RTL expansion, where the target's rtx_costs can be used to determine
whether the original multiplication (that may be possibly be implemented by
a shift or lea) is cheaper than a negation and a bit-wise and.

Previously the expression (x>>63)*y would be compiled with -O2 as
shrq$63, %rdi
movq%rdi, %rax
imulq   %rsi, %rax

but with this patch now produces:
sarq$63, %rdi
movq%rdi, %rax
andq%rsi, %rax

Likewise the expression (x>>63)*135 [that appears in a hot-spot of the
Botan AES-128 benchmark] was previously:

shrq$63, %rdi
leaq(%rdi,%rdi,8), %rdx
movq%rdx, %rax
salq$4, %rax
subq%rdx, %rax

now becomes:
movq%rdi, %rax
sarq$63, %rax
andl$135, %eax


This patch has been tested on x86_64-pc-linux-gnu with make bootstrap and
make -k check, both with and without --target_board=unix{-m32}, with no
new failures.  Many thanks to Uros for the speedy review and approval of
my x86_rtx_costs patch that enables this transformation on -m32 using the
correct cost of DImode multiplication.  Ok for mainline?

2022-05-18  Roger Sayle  

gcc/ChangeLog
PR middle-end/98865
* expr.cc (expand_expr_real_2) [MULT_EXPR]:  Expand X*Y as X&Y
when both X and Y are [0, 1], X*Y as X&-Y when Y is [0,1] and
likewise X*Y as -X&Y when X is [0,1] using tree_nonzero_bits.

gcc/testsuite/ChangeLog
PR middle-end/98865
* gcc.target/i386/pr98865.c: New test case.


Thanks in advance,
Roger
--

diff --git a/gcc/expr.cc b/gcc/expr.cc
index 1806091..7197996 100644
--- a/gcc/expr.cc
+++ b/gcc/expr.cc
@@ -9541,6 +9541,38 @@ expand_expr_real_2 (sepops ops, rtx target, machine_mode 
tmode,
}
 
   expand_operands (treeop0, treeop1, subtarget, &op0, &op1, EXPAND_NORMAL);
+
+  /* Expand X*Y as X&-Y when Y must be zero or one.  */
+  if (SCALAR_INT_MODE_P (mode))
+   {
+ bool bit0_p = tree_nonzero_bits (treeop0) == 1;
+ bool bit1_p = tree_nonzero_bits (treeop1) == 1;
+
+ /* Expand X*Y as X&Y when both X and Y must be zero or one.  */
+ if (bit0_p && bit1_p)
+   return REDUCE_BIT_FIELD (expand_and (mode, op0, op1, target));
+
+ if (bit0_p || bit1_p)
+   {
+ bool speed = optimize_insn_for_speed_p ();
+ int cost = add_cost (speed, mode) + neg_cost (speed, mode);
+ struct algorithm algorithm;
+ enum mult_variant variant;
+ if (CONST_INT_P (op1)
+ ? !choose_mult_variant (mode, INTVAL (op1),
+ &algorithm, &variant, cost)
+ : cost < mul_cost (speed, mode))
+   {
+ target = bit0_p ? expand_and (mode, negate_rtx (mode, op0),
+   op1, target)
+ : expand_and (mode, op0,
+   negate_rtx (mode, op1),
+   target);
+ return REDUCE_BIT_FIELD (target);
+   }
+   }
+   }
+
   return REDUCE_BIT_FIELD (expand_mult (mode, op0, op1, target, 
unsignedp));
 
 case TRUNC_MOD_EXPR:
diff --git a/gcc/testsuite/gcc.target/i386/pr98865.c 
b/gcc/testsuite/gcc.target/i386/pr98865.c
new file mode 100644
index 000..d047c4b
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr98865.c
@@ -0,0 +1,54 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+
+#if __SIZEOF_INT__ == 4
+unsigned int foo(unsigned int a, unsigned int b)
+{
+  return (a >> 31) * b;
+}
+
+int bar(int a, int b)
+{
+  return -(a >> 31) * b;
+}
+
+int baz(int a, int b)
+{
+  int c = a >> 31;
+  int d = -c;
+  return d * b;
+}
+
+unsigned int pin(int a, unsigned int b)
+{
+  unsigned int t = a & 1;
+  return t * b;
+}
+#endif
+
+#if __SIZEOF_LONG_LONG__ == 8
+unsigned long long fool(unsigned long long a, unsigned long long b)
+{
+  return (a >> 63) * b;
+}
+
+long long barl (long long a, long long b)
+{
+  return -(a >> 63) * b;
+}
+
+long long bazl (long long a, long long b)
+{
+  long long c = a >> 63;
+  long long d = -c;
+  return d * b;
+}
+
+unsigned long long pinl(long long a, unsigned long long b)
+{
+  unsigned long long t = a & 1;
+  return t * b;
+}
+#endif
+
+/* { dg-final { scan-assembler-not "imul" } } */


Re: [PATCH v2] x86: Document -mcet-switch

2022-05-18 Thread H.J. Lu via Gcc-patches
On Wed, May 11, 2022 at 1:52 PM H.J. Lu  wrote:
>
> When -fcf-protection=branch is used, the compiler will generate jump
> tables for switch statements where the indirect jump is prefixed with
> the NOTRACK prefix, so it can jump to non-ENDBR targets.  Since the
> indirect jump targets are generated by the compiler, they are always
> valid.
>
> Document -mcet-switch to generate jump tables for switch statements with
> ENDBR and skip the NOTRACK prefix for indirect jump.  This option should
> be used when the NOTRACK prefix is disabled.
>
> PR target/104816
> * config/i386/i386.opt: Remove Undocumented.
> * doc/invoke.texi: Document -mcet-switch.
> ---
>  gcc/config/i386/i386.opt | 2 +-
>  gcc/doc/invoke.texi  | 8 +++-
>  2 files changed, 8 insertions(+), 2 deletions(-)
>
> diff --git a/gcc/config/i386/i386.opt b/gcc/config/i386/i386.opt
> index a6b0e28f238..0dbaacb57ed 100644
> --- a/gcc/config/i386/i386.opt
> +++ b/gcc/config/i386/i386.opt
> @@ -1047,7 +1047,7 @@ Enable shadow stack built-in functions from 
> Control-flow Enforcement
>  Technology (CET).
>
>  mcet-switch
> -Target Undocumented Var(flag_cet_switch) Init(0)
> +Target Var(flag_cet_switch) Init(0)
>  Turn on CET instrumentation for switch statements that use a jump table and
>  an indirect jump.
>
> diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
> index 7a35d9613a4..968853690f9 100644
> --- a/gcc/doc/invoke.texi
> +++ b/gcc/doc/invoke.texi
> @@ -1420,7 +1420,8 @@ See RS/6000 and PowerPC Options.
>  -msse4a  -m3dnow  -m3dnowa  -mpopcnt  -mabm  -mbmi  -mtbm  -mfma4  -mxop @gol
>  -madx  -mlzcnt  -mbmi2  -mfxsr  -mxsave  -mxsaveopt  -mrtm  -mhle  -mlwp @gol
>  -mmwaitx  -mclzero  -mpku  -mthreads  -mgfni  -mvaes  -mwaitpkg @gol
> --mshstk -mmanual-endbr -mforce-indirect-call  -mavx512vbmi2 -mavx512bf16 
> -menqcmd @gol
> +-mshstk -mmanual-endbr -mcet-switch -mforce-indirect-call @gol
> +-mavx512vbmi2 -mavx512bf16 -menqcmd @gol
>  -mvpclmulqdq  -mavx512bitalg  -mmovdiri  -mmovdir64b  -mavx512vpopcntdq @gol
>  -mavx5124fmaps  -mavx512vnni  -mavx5124vnniw  -mprfchw  -mrdpid @gol
>  -mrdseed  -msgx -mavx512vp2intersect -mserialize -mtsxldtrk@gol
> @@ -32641,6 +32642,11 @@ function attribute. This is useful when used with 
> the option
>  @option{-fcf-protection=branch} to control ENDBR insertion at the
>  function entry.
>
> +@item -mcet-switch
> +@opindex mcet-switch
> +Turn on CET instrumentation for switch statements that use a jump table
> +and an indirect jump.
> +
>  @item -mcall-ms2sysv-xlogues
>  @opindex mcall-ms2sysv-xlogues
>  @opindex mno-call-ms2sysv-xlogues
> --
> 2.35.1
>

Any comments?

Thanks.

-- 
H.J.


[x86 PATCH] Some additional ix86_rtx_costs clean-ups: NEG, AND and pandn.

2022-05-18 Thread Roger Sayle

Hi Uros,
Very many thanks for the speedy review and approval of my ix86_rtx_costs
patch to correct the cost of multi-word multiplications.  In the same
spirit, this patch tidies up a few additional nits I noticed while there:
Multi-word NOT requires two operations, but multi-word NEG requires
three operations.  Using SSE, vector NOT requires a pxor with -1, but
AND of NOT is cheap thanks to the existence of pandn.  There's also some
legacy (aka incorrect) logic explicitly testing for DImode [independently
of TARGET_64BIT] in determining the cost of logic operations that's not
required.

There should be no behavioural changes from this patch (as confirmed by
testing) but hopefully vectorization and other middle-end passes can now
rely on more sensible "cost" estimates.

This patch has been tested on x86_64-pc-linux-gnu with make bootstrap
and make -k check, both with and without --target_board=unix{-m32}, with
no new failures.  Ok for mainline?


2022-05-18  Roger Sayle  

gcc/ChangeLog
* config/i386/i386.cc (ix86_rtx_costs): Split AND from XOR/IOR.
Multi-word binary logic operations require two instructions.
For vector integer modes, AND with a NOT operand requires only
a single instruction (pandn).
[NOT]: Vector integer NOT requires more than 1 instruction (pxor).
[NEG]: Multi-word negation requires 3 instructions.


Thanks in advance,
Roger
--

diff --git a/gcc/config/i386/i386.cc b/gcc/config/i386/i386.cc
index 86752a6..1701244 100644
--- a/gcc/config/i386/i386.cc
+++ b/gcc/config/i386/i386.cc
@@ -20744,26 +20744,67 @@ ix86_rtx_costs (rtx x, machine_mode mode, int 
outer_code_i, int opno,
}
   /* FALLTHRU */
 
-case AND:
 case IOR:
 case XOR:
   if (GET_MODE_CLASS (mode) == MODE_INT
  && GET_MODE_SIZE (mode) > UNITS_PER_WORD)
{
- *total = (cost->add * 2
-   + (rtx_cost (XEXP (x, 0), mode, outer_code, opno, speed)
-  << (GET_MODE (XEXP (x, 0)) != DImode))
-   + (rtx_cost (XEXP (x, 1), mode, outer_code, opno, speed)
-  << (GET_MODE (XEXP (x, 1)) != DImode)));
+ *total = cost->add * 2
+  + rtx_cost (XEXP (x, 0), mode, outer_code, opno, speed)
+  + rtx_cost (XEXP (x, 1), mode, outer_code, opno, speed);
+ return true;
+   }
+  else if (GET_MODE_CLASS (mode) == MODE_VECTOR_INT)
+   *total = ix86_vec_cost (mode, cost->sse_op);
+  else if (GET_MODE_SIZE (mode) > UNITS_PER_WORD)
+   *total = cost->add * 2;
+  else
+   *total = cost->add;
+  return false;
+
+case AND:
+  if (GET_MODE_CLASS (mode) == MODE_INT
+ && GET_MODE_SIZE (mode) > UNITS_PER_WORD)
+   {
+ *total = cost->add * 2
+  + rtx_cost (XEXP (x, 0), mode, outer_code, opno, speed)
+  + rtx_cost (XEXP (x, 1), mode, outer_code, opno, speed);
  return true;
}
-  else if (code == AND
-  && address_no_seg_operand (x, mode))
+  else if (address_no_seg_operand (x, mode))
{
  *total = cost->lea;
  return true;
}
-  /* FALLTHRU */
+  else if (GET_MODE_CLASS (mode) == MODE_VECTOR_INT)
+   {
+ /* pandn is a single instruction.  */
+ if (GET_CODE (XEXP (x, 0)) == NOT)
+   {
+ *total = ix86_vec_cost (mode, cost->sse_op)
+  + rtx_cost (XEXP (XEXP (x, 0), 0), mode,
+  outer_code, opno, speed)
+  + rtx_cost (XEXP (x, 1), mode,
+  outer_code, opno, speed);
+ return true;
+   }
+ *total = ix86_vec_cost (mode, cost->sse_op);
+   }
+  else if (GET_MODE_SIZE (mode) > UNITS_PER_WORD)
+   *total = cost->add * 2;
+  else
+   *total = cost->add;
+  return false;
+
+case NOT:
+  if (GET_MODE_CLASS (mode) == MODE_VECTOR_INT)
+   // vnot is pxor -1.
+   *total = ix86_vec_cost (mode, cost->sse_op) + 1;
+  else if (GET_MODE_SIZE (mode) > UNITS_PER_WORD)
+   *total = cost->add * 2;
+  else
+   *total = cost->add;
+  return false;
 
 case NEG:
   if (SSE_FLOAT_MODE_SSEMATH_OR_HF_P (mode))
@@ -20781,13 +20822,10 @@ ix86_rtx_costs (rtx x, machine_mode mode, int 
outer_code_i, int opno,
  *total = ix86_vec_cost (mode, cost->sse_op);
  return false;
}
-  /* FALLTHRU */
-
-case NOT:
-  if (GET_MODE_CLASS (mode) == MODE_VECTOR_INT)
+  else if (GET_MODE_CLASS (mode) == MODE_VECTOR_INT)
*total = ix86_vec_cost (mode, cost->sse_op);
   else if (GET_MODE_SIZE (mode) > UNITS_PER_WORD)
-   *total = cost->add * 2;
+   *total = cost->add * 3;
   else
*total = cost->add;
   return false;


Re: [PATCH] Optimize multiply/add of DImode extended to TImode, PR target/103109.

2022-05-18 Thread will schmidt via Gcc-patches
On Tue, 2022-05-17 at 23:15 -0400, Michael Meissner wrote:
> On Fri, May 13, 2022 at 01:20:30PM -0500, will schmidt wrote:
> > On Fri, 2022-05-13 at 12:17 -0400, Michael Meissner wrote:
> > > 
> > > 



> > > gcc/
> > >   PR target/103109
> > >   * config/rs6000/rs6000.md (su_int32): New code attribute.
> > >   (mul3): Convert from define_expand to
> > >   define_insn_and_split.
> > >   (maddld4): Add generator function.
> > 
> > -(define_insn "*maddld4"
> > +(define_insn "maddld4"
> > 
> > Is the removal of the "*" considering adding generator?  (Thats
> > terminology that I'm not immediately familiar with). 
> 
> Yes.  If you have a pattern:
> 
>   (define_insn "foosi2"
> [(set (match_operand:SI 0 "register_operand" "=r")
>   (foo:SI (match_operand:SI 1 "register_operand" "r")))]
>   ""
>   "foo %0,%1")
> 
> It creates a 'gen_foosi2' function that has 2 arguments, and it makes
> the insn
> listed.
> 
> It then has support for insn recognition and output.
> 
> If the pattern starts with a '*', there is no 'gen_foosi2' function
> created,
> but the insn recognitiion and output are still done.
> 
> In practice, you typically use the '*' names for patterns that are
> used as the
> targets of combination, or separate insns for different machines.
> 
> Here is the verbage from rtl.texi:
> 
> These names serve one of two purposes.  The first is to indicate that
> the
> instruction performs a certain standard job for the RTL-generation
> pass of the compiler, such as a move, an addition, or a conditional
> jump.  The second is to help the target generate certain target-
> specific
> operations, such as when implementing target-specific intrinsic
> functions.
> 
> It is better to prefix target-specific names with the name of the
> target, to avoid any clash with current or future standard names.
> 
> The absence of a name is indicated by writing an empty string
> where the name should go.  Nameless instruction patterns are never
> used for generating RTL code, but they may permit several simpler
> insns
> to be combined later on.
> 
> For the purpose of debugging the compiler, you may also specify a
> name beginning with the @samp{*} character.  Such a name is used only
> for identifying the instruction in RTL dumps; it is equivalent to
> having
> a nameless pattern for all other purposes.  Names beginning with the
> @samp{*} character are not required to be unique.


Thanks for the explanation.  :-)

-Will





Re: [PATCH] Add divide by zero side effect.

2022-05-18 Thread Segher Boessenkool
On Tue, May 17, 2022 at 02:39:11PM -0400, Andrew MacLeod via Gcc-patches wrote:
> I haven't checked this patch in yet.  This implements a side effect that 
> the divisor cannot be 0 after a divide executes. This allows us to fold 
> the divide away:

"Side effect" already has a meaning, very commonly used in language
theory, and even in the C standard itself: a function has a side effect
if it does something more than just return a value: if it changes state.
This can be some I/O, or it can just be writing to some non-local data.

Side effects are crucial to what a compiler does, and they are used all
over the place (the gcc/ dir has some thousand mentions of it for
example).

Please don't make life hard for everyone by overloading this term.


Segher


Re: [PATCH] Delay splitting addti3/subti3 until first split pass.

2022-05-18 Thread Michael Meissner via Gcc-patches
On Fri, May 13, 2022 at 12:32:22PM -0500, Segher Boessenkool wrote:
> On Fri, May 13, 2022 at 11:08:48AM -0400, Michael Meissner wrote:
> > Add zero_extendditi2.  Improve lxvr*x code generation.
> 
> 
> 
> Nothing in this pass haas anything to do with the subject.  Which is a
> good thing, because not expanding addti3 etc. to RTL that mimics the
> machine insns is not acceptable at all.

Yes, obviously I got mixed up in terms of the title.

The title should have been:

Add zero_extendditi2.  Improve lxvr*x code generation.

-- 
Michael Meissner, IBM
PO Box 98, Ayer, Massachusetts, USA, 01432
email: meiss...@linux.ibm.com


Re: [PATCH] Add divide by zero side effect.

2022-05-18 Thread Andrew MacLeod via Gcc-patches

On 5/18/22 14:13, Segher Boessenkool wrote:

On Tue, May 17, 2022 at 02:39:11PM -0400, Andrew MacLeod via Gcc-patches wrote:

I haven't checked this patch in yet.  This implements a side effect that
the divisor cannot be 0 after a divide executes. This allows us to fold
the divide away:

"Side effect" already has a meaning, very commonly used in language
theory, and even in the C standard itself: a function has a side effect
if it does something more than just return a value: if it changes state.
This can be some I/O, or it can just be writing to some non-local data.

Side effects are crucial to what a compiler does, and they are used all
over the place (the gcc/ dir has some thousand mentions of it for
example).

Please don't make life hard for everyone by overloading this term.


I'm open to suggestions for a better term!

Is there a commonly used alternate term to describe an observable effect 
on the value of an input operand?


Andrew




[PATCH] Modula-2: merge proposal/review: 2/9 02.patch-set-02 v2

2022-05-18 Thread Gaius Mulley via Gcc-patches
Hello,

this email contains v2:

2.  the top level /gm2tools contents.

-
New file: ./ChangeLog
-
2022-05-18  Gaius Mulley  

* gm2l.1: Corrected default implementation/program module
extension to .mod.
* m2color.c: Reformatted to use GNU coding standard
formatting.

2022-05-17  Gaius Mulley  

* Corrected dates on all source files.

2021-06-14  Gaius Mulley  

* errors.c: (New file).
* Makefile.am: (m2color.o) rule added include paths for gcc
system headers.  (errors.o) rule added include paths for gcc
system headers.  Add errors.o to list of modules and add errors.o
to gm2l.
* Makefile.in: (rebuilt).

2021-06-12  Gaius Mulley  

* gm2tools/Makefile.in: Rebuilt.

2021-06-11  Gaius Mulley  

* gm2tools/Makefile.am: (man_MANS) set to gm2lgen.1
gm2l.1 gm2lcc.1 gm2lorder.1.  (%.o) includes changed to
find gm2-libiberty and the gcc system.h and config.h.
* gm2tools/Makefile.in: (rebuilt).

2021-06-09  Gaius Mulley  

* gm2l.1: (New file).
* gm2lcc.1: (New file).
* gm2lgen.1: (New file).
* gm2lorder.1: (New file).

2021-06-08  Gaius Mulley  

* Makefile.am: (LIBM2PIMPATH) New definition.
(LIBM2CORPATH) New definition.  (LIBM2ISOPATH) New definition.
(gm2l) specify -flibs=pim,iso and pass link paths.
(gm2lcc) specify -flibs=pim,iso and pass link paths.
(gm2lgen) specify -flibs=pim,iso and pass link paths.
(gm2lorder) specify -flibs=pim,iso and pass link paths.
(gm2m) specify -flibs=pim,iso and pass link paths.

2021-06-07  Gaius Mulley  

* aclocal.m4: (New file).
* autogen.sh: (New file).
* configure: (New file).
* configure.ac: (New file).
* m2color.c: (New file).
* Makefile.am: (New file).
* Makefile.in: (New file).
* Makefile.am: (DEBUG_MODULE_LIST) used to display locations of
objects.  Added -B./gcc build directory to pick up link tools
generated in the compiler bootstrap process.
* Makefile.in: (Regenerated).
-
New file: ./gm2l.1
-
.TH gm2l "1" "June 2021" "Modula-2" "User Commands"
.SH NAME
gm2l \- generate an initialization sequence by analyzing module imports.
.SH SYNOPSIS
.B gm2l
.RB [ -fdef= extension ]
.RB [ -fmod= extension ]
.RB [ -h ]
.RB [ --help ]
.RB [ -I searchpath ]
.RB [ --M2RTS ]
.RB [ -M2RTS ]
.RB [ -v ]
.RB [ --verbose ]
.RB [ -o " outputfile" ]
\fImodulefile\fR
.SH DESCRIPTION
.PP
A tool for generating a static initialization sequence by analyzing
module imports.  This tool will generate a textual list of modules in
an order which satisfies a topological order of an import graph.  The
textual list of modules can be manipulated and used by the other
Modula-2 link tools:
.IR gm2lcc (1)
.IR gm2lgen (1)
.IR gm2lorder (1).
The command line program
.IR gm2
can be instructed to automatically invoke
.IR gm2l (1)
and the above programs to construct a C++ scaffold for a Modula-2
application.
.SH OPTIONS
.TP
.B -fdef= extension
assume that definition modules have the posfix \fIextension\fP.  If
this option is not specified then an extension of
.B .def
is assumed.
.TP
.B -fmod= extension
assume that program and implementation modules have the posfix
\fIextension\fP.  If this option is not specified then an extension of
.B .mod
is assumed.
.TP
.B -h
issue a summary help.
.TP
.B --help
equivalent to
.B -h\fR.
.TP
.B -I searchpath
specifies the search path used to find definition, implementation and
program modules.
.TP
.B --M2RTS
do not include the module M2RTS even if it is a dependant module.
.TP
.B -M2RTS
equivalent to
.B --M2RTS\fR.
.TP
.B -v
turn on the verbose flag.  This will display the module name and
associated filename.
.TP
.B --verbose
equivalent to
.B -v\fR.
.SH "SEE ALSO"
.IR gm2lcc (1),
.IR gm2lgen (1),
.IR gm2lorder (1)
and
.IR gm2 (1).
-
New file: ./Makefile.am
-
# Makefile for gm2tools
#   Copyright (C) 2021-2022 Free Software Foundation, Inc.
#
# This file is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; see the file COPYING3.  If not see
# .

ACLOCAL_AMFLAGS = -I ../config

gcc_version := $(shell $(GCC_FOR_TARGET) -dumpversion)

libexecsubdir = $(libexecdir)/gcc/$(target_no

Re: [PATCH] Add divide by zero side effect.

2022-05-18 Thread Segher Boessenkool
On Wed, May 18, 2022 at 04:24:06PM -0400, Andrew MacLeod wrote:
> On 5/18/22 14:13, Segher Boessenkool wrote:
> >"Side effect" already has a meaning, very commonly used in language
> >theory, and even in the C standard itself: a function has a side effect
> >if it does something more than just return a value: if it changes state.
> >This can be some I/O, or it can just be writing to some non-local data.
> >
> >Side effects are crucial to what a compiler does, and they are used all
> >over the place (the gcc/ dir has some thousand mentions of it for
> >example).
> >
> >Please don't make life hard for everyone by overloading this term.
> >
> I'm open to suggestions for a better term!

Glad to hear that, and this isn't set in stione yet!

> Is there a commonly used alternate term to describe an observable effect 
> on the value of an input operand?

I'd use something with "known" in the name.  But:

As far as I understand what you are doing this is not an effect on the
operand at all!  It cannot be one even, the operand is an input only
after all.  Instead, it changes what is known about the value of that
input: it cannot be 0 in this case, it is known to not be 0.

This is similar to other known value things we have in GCC already.  Can
you not just use one of those, even?  What are the benefit to this new
abstraction?


Segher


[PATCH COMMITTED] Revert move of g++.dg/pr69667.C

2022-05-18 Thread Paul A. Clarke via Gcc-patches
Commit eccbd7fcee5bbfc47731e8de83c44eee2e3dcc4b moved the subject file to
g++.target/powerpc.  Unfortunately, test g++.dg/tsan/pr88018.C includes
"../pr69667.C".

Revert the move of this file.

Commit 14e678a2c4a76433fd4029568d28530c921e11ee relaxed some DejaGnu
directives in g++.dg/tsan/pr88018.C, given its more restrictive environment
within g++.target/powerpc.  Revert these changes in that file as well.

2022-05-18  Paul A. Clarke  

gcc/testsuite
PR target/105620
* g++.target/powerpc/pr69667.C: Move to ...
* g++.dg/pr69667.C: here. Also, revert recent dg directives changes.
---
Committed as trivial.

 gcc/testsuite/{g++.target/powerpc => g++.dg}/pr69667.C | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
 rename gcc/testsuite/{g++.target/powerpc => g++.dg}/pr69667.C (97%)

diff --git a/gcc/testsuite/g++.target/powerpc/pr69667.C 
b/gcc/testsuite/g++.dg/pr69667.C
similarity index 97%
rename from gcc/testsuite/g++.target/powerpc/pr69667.C
rename to gcc/testsuite/g++.dg/pr69667.C
index da550cd14bd6..422116dd5995 100644
--- a/gcc/testsuite/g++.target/powerpc/pr69667.C
+++ b/gcc/testsuite/g++.dg/pr69667.C
@@ -1,4 +1,5 @@
-/* { dg-skip-if "" { *-*-darwin* } } */
+/* { dg-do compile { target { powerpc*-*-* && lp64 } } } */
+/* { dg-skip-if "" { powerpc*-*-darwin* } } */
 /* { dg-require-effective-target powerpc_p8vector_ok } */
 /* { dg-options "-mdejagnu-cpu=power8 -w -std=c++14" } */
 
-- 
2.27.0



Re: [PATCH v2] c: Implement new -Wenum-int-mismatch warning [PR105131]

2022-05-18 Thread Joseph Myers
On Wed, 18 May 2022, Marek Polacek via Gcc-patches wrote:

> diff --git a/gcc/testsuite/gcc.dg/Wenum-int-mismatch-1.c 
> b/gcc/testsuite/gcc.dg/Wenum-int-mismatch-1.c
> new file mode 100644
> index 000..f71a308bc19
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/Wenum-int-mismatch-1.c
> @@ -0,0 +1,35 @@
> +/* PR c/105131 */
> +/* { dg-do compile } */
> +/* { dg-options "-Wall" } */

Since some Arm targets default to -fshort-enums, I think it would be best 
for the tests to use -fno-short-enums or otherwise ensure the enums are 
compatible with the expected type, so that they test what's intended.  
Additional tests that don't use the -W options but #include the main tests 
might also be a good idea, to verify that all the types in the tests 
really are compatible as intended.

-- 
Joseph S. Myers
jos...@codesourcery.com


Re: [PATCH] Modula-2: merge proposal/review: 7/9 07.patch-set-05

2022-05-18 Thread Joseph Myers
On Wed, 18 May 2022, Gaius Mulley via Gcc-patches wrote:

> /* This is the contribution to the `documented_lang_options' array in
>toplev.c for gm2.  */

I'm not sure what this is (an unused file?), but documented_lang_options 
was removed in 2003.  And in general, comments referring to .c files, 
throughout the front end, need to be updated to refer to the current names 
of those files (C++ sources have been renamed from .c to .cc in GCC).

-- 
Joseph S. Myers
jos...@codesourcery.com


[PATCH v3] c: Implement new -Wenum-int-mismatch warning [PR105131]

2022-05-18 Thread Marek Polacek via Gcc-patches
On Wed, May 18, 2022 at 08:58:02PM +, Joseph Myers wrote:
> On Wed, 18 May 2022, Marek Polacek via Gcc-patches wrote:
> 
> > diff --git a/gcc/testsuite/gcc.dg/Wenum-int-mismatch-1.c 
> > b/gcc/testsuite/gcc.dg/Wenum-int-mismatch-1.c
> > new file mode 100644
> > index 000..f71a308bc19
> > --- /dev/null
> > +++ b/gcc/testsuite/gcc.dg/Wenum-int-mismatch-1.c
> > @@ -0,0 +1,35 @@
> > +/* PR c/105131 */
> > +/* { dg-do compile } */
> > +/* { dg-options "-Wall" } */
> 
> Since some Arm targets default to -fshort-enums, I think it would be best 
> for the tests to use -fno-short-enums or otherwise ensure the enums are 
> compatible with the expected type, so that they test what's intended.  

You're right, the tests would likely break on ARM because of that.
I've added -fno-short-enums.

> Additional tests that don't use the -W options but #include the main tests 
> might also be a good idea, to verify that all the types in the tests 
> really are compatible as intended.

I've extended the tests to use an enum with __attribute__ ((__packed__)) to
test the case when the underlying type is (un)signed char.  But it seems like
we can't have underlying types wider than int.  I've also included two tests
which #include the two main tests.  Seems like Dejagnu doesn't expect the
diagnostics as per the dg directives in the main tests, which is good.

Is the following ok?

Thanks,

-- >8 --
In C, an enumerated type is compatible with char, a signed integer type,
or an unsigned integer type (6.7.2.2/5).  Therefore this code compiles:

  enum E { l = -1, z = 0, g = 1 };
  int foo(void);
  enum E foo(void) { return z; }

if the underlying type of 'enum E' is 'int' (if not, we emit an error).
This is different for typedefs, where C11 permits typedefs to be
redeclared to the same type, but not to compatible types.  In C++, the
code above is invalid.

It seems desirable to emit a warning in the C case, because it is
probably a mistake and definitely a portability error, given that the
choice of the underlying type is implementation-defined.

To that end, this patch implements a new -Wenum-int-mismatch warning.
Conveniently, we already have comptypes_check_enum_int to detect such
mismatches.  This warning is enabled by either -Wall or -Wc++-compat.

PR c/105131

gcc/c-family/ChangeLog:

* c.opt (Wenum-int-mismatch): New.

gcc/c/ChangeLog:

* c-decl.cc (diagnose_mismatched_decls): Warn about enum/integer type
mismatches.
* c-tree.h (comptypes_check_enum_int): Declare.
* c-typeck.cc (comptypes): No longer static.

gcc/ChangeLog:

* doc/invoke.texi: Document -Wenum-int-mismatch.

gcc/testsuite/ChangeLog:

* gcc.dg/Wenum-int-mismatch-1.c: New test.
* gcc.dg/Wenum-int-mismatch-2.c: New test.
* gcc.dg/Wenum-int-mismatch-3.c: New test.
* gcc.dg/Wenum-int-mismatch-4.c: New test.
* gcc.dg/Wenum-int-mismatch-5.c: New test.
---
 gcc/c-family/c.opt  |  4 ++
 gcc/c/c-decl.cc | 13 ++-
 gcc/c/c-tree.h  |  1 +
 gcc/c/c-typeck.cc   |  2 +-
 gcc/doc/invoke.texi | 21 ++
 gcc/testsuite/gcc.dg/Wenum-int-mismatch-1.c | 43 +
 gcc/testsuite/gcc.dg/Wenum-int-mismatch-2.c | 43 +
 gcc/testsuite/gcc.dg/Wenum-int-mismatch-3.c | 43 +
 gcc/testsuite/gcc.dg/Wenum-int-mismatch-4.c |  5 +++
 gcc/testsuite/gcc.dg/Wenum-int-mismatch-5.c |  5 +++
 10 files changed, 177 insertions(+), 3 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/Wenum-int-mismatch-1.c
 create mode 100644 gcc/testsuite/gcc.dg/Wenum-int-mismatch-2.c
 create mode 100644 gcc/testsuite/gcc.dg/Wenum-int-mismatch-3.c
 create mode 100644 gcc/testsuite/gcc.dg/Wenum-int-mismatch-4.c
 create mode 100644 gcc/testsuite/gcc.dg/Wenum-int-mismatch-5.c

diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt
index 035b1de0d84..41a20bc625e 100644
--- a/gcc/c-family/c.opt
+++ b/gcc/c-family/c.opt
@@ -638,6 +638,10 @@ Wenum-conversion
 C ObjC C++ ObjC++ Var(warn_enum_conversion) Init(0) Warning LangEnabledBy(C 
ObjC,Wextra)
 Warn about implicit conversion of enum types.
 
+Wenum-int-mismatch
+C ObjC Var(warn_enum_int_mismatch) Warning LangEnabledBy(C ObjC,Wall || 
Wc++-compat)
+Warn about enum/integer type mismatches.
+
 Werror
 C ObjC C++ ObjC++
 ; Documented in common.opt
diff --git a/gcc/c/c-decl.cc b/gcc/c/c-decl.cc
index 83655548fc4..5266a61b859 100644
--- a/gcc/c/c-decl.cc
+++ b/gcc/c/c-decl.cc
@@ -1993,9 +1993,12 @@ diagnose_mismatched_decls (tree newdecl, tree olddecl,
 
   bool pedwarned = false;
   bool warned = false;
+  bool enum_and_int_p = false;
   auto_diagnostic_group d;
 
-  if (!comptypes (oldtype, newtype))
+  int comptypes_result = comptypes_check_enum_int (oldtype, newtype,
+  &enum_and_int_p);
+  if (!comptypes_result)
 {
   if (TREE

  1   2   >