[PATCH v3] Modify combine pattern by a pseudo AND with its nonzero bits [PR93453]

2022-07-22 Thread HAO CHEN GUI via Gcc-patches
Hi,
  This patch creates a new function - change_pseudo_and_mask. If recog fails,
the function converts a single pseudo to the pseudo AND with a mask if the
outer operator is IOR/XOR/PLUS and inner operator is ASHIFT or AND. The
conversion helps pattern to match rotate and mask insn on some targets.

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

ChangeLog
2022-07-22  Haochen Gui  

gcc/
PR target/93453
* combine.cc (change_pseudo_and_mask): New.
(recog_for_combine): If recog fails, try again with the pattern
modified by change_pseudo_and_mask.
* config/rs6000/rs6000.md (plus_ior_xor): Remove.
(anonymous split pattern for plus_ior_xor): Remove.

gcc/testsuite/
PR target/93453
* gcc.target/powerpc/pr93453-2.c: New.
* gcc.target/powerpc/rlwimi-2.c: Both 32/64 bit platforms generate the
same number of rlwimi.  Reset the counter.

patch.diff
diff --git a/gcc/combine.cc b/gcc/combine.cc
index a5fabf397f7..e1c1aa7da1c 100644
--- a/gcc/combine.cc
+++ b/gcc/combine.cc
@@ -11599,6 +11599,48 @@ change_zero_ext (rtx pat)
   return changed;
 }

+/* When the outer code of set_src is IOR/XOR/PLUS and the inner code is
+   ASHIFT/AND, convert a pseudo to pseudo AND with a mask if its nonzero_bits
+   is less than its mode mask.  The nonzero_bits in later passes is not a
+   superset of what is known in combine pass.  So an insn with nonzero_bits
+   can't be recoged later.  */
+static bool
+change_pseudo_and_mask (rtx pat)
+{
+  rtx src = SET_SRC (pat);
+  if ((GET_CODE (src) == IOR
+   || GET_CODE (src) == XOR
+   || GET_CODE (src) == PLUS)
+  && (((GET_CODE (XEXP (src, 0)) == ASHIFT
+   || GET_CODE (XEXP (src, 0)) == AND)
+  && REG_P (XEXP (src, 1)
+{
+  rtx reg = XEXP (src, 1);
+  machine_mode mode = GET_MODE (reg);
+  unsigned HOST_WIDE_INT nonzero = nonzero_bits (reg, mode);
+  if (nonzero < GET_MODE_MASK (mode))
+   {
+ int shift;
+
+ if (GET_CODE (XEXP (src, 0)) == ASHIFT)
+   shift = INTVAL (XEXP (XEXP (src, 0), 1));
+ else
+   shift = ctz_hwi (INTVAL (XEXP (XEXP (src, 0), 1)));
+
+ if (shift > 0
+ && (HOST_WIDE_INT_1U << shift) - 1 >= nonzero)
+   {
+ unsigned HOST_WIDE_INT mask = (HOST_WIDE_INT_1U << shift) - 1;
+ rtx x = gen_rtx_AND (mode, reg, GEN_INT (mask));
+ SUBST (XEXP (SET_SRC (pat), 1), x);
+ maybe_swap_commutative_operands (SET_SRC (pat));
+ return true;
+   }
+   }
+}
+  return false;
+}
+
 /* Like recog, but we receive the address of a pointer to a new pattern.
We try to match the rtx that the pointer points to.
If that fails, we may try to modify or replace the pattern,
@@ -11646,7 +11688,10 @@ recog_for_combine (rtx *pnewpat, rtx_insn *insn, rtx 
*pnotes)
}
}
   else
-   changed = change_zero_ext (pat);
+   {
+ changed = change_pseudo_and_mask (pat);
+ changed |= change_zero_ext (pat);
+   }
 }
   else if (GET_CODE (pat) == PARALLEL)
 {
diff --git a/gcc/config/rs6000/rs6000.md b/gcc/config/rs6000/rs6000.md
index 1367a2cb779..2bd6bd5f908 100644
--- a/gcc/config/rs6000/rs6000.md
+++ b/gcc/config/rs6000/rs6000.md
@@ -4207,24 +4207,6 @@ (define_insn_and_split "*rotl3_insert_3_"
(ior:GPR (and:GPR (match_dup 3) (match_dup 4))
 (ashift:GPR (match_dup 1) (match_dup 2])

-(define_code_iterator plus_ior_xor [plus ior xor])
-
-(define_split
-  [(set (match_operand:GPR 0 "gpc_reg_operand")
-   (plus_ior_xor:GPR (ashift:GPR (match_operand:GPR 1 "gpc_reg_operand")
- (match_operand:SI 2 "const_int_operand"))
- (match_operand:GPR 3 "gpc_reg_operand")))]
-  "nonzero_bits (operands[3], mode)
-   < HOST_WIDE_INT_1U << INTVAL (operands[2])"
-  [(set (match_dup 0)
-   (ior:GPR (and:GPR (match_dup 3)
- (match_dup 4))
-(ashift:GPR (match_dup 1)
-(match_dup 2]
-{
-  operands[4] = GEN_INT ((HOST_WIDE_INT_1U << INTVAL (operands[2])) - 1);
-})
-
 (define_insn "*rotlsi3_insert_4"
   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
(ior:SI (and:SI (match_operand:SI 3 "gpc_reg_operand" "0")
diff --git a/gcc/testsuite/gcc.target/powerpc/pr93453-2.c 
b/gcc/testsuite/gcc.target/powerpc/pr93453-2.c
new file mode 100644
index 000..a83a6511653
--- /dev/null
+++ b/gcc/testsuite/gcc.target/powerpc/pr93453-2.c
@@ -0,0 +1,19 @@
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+
+long foo (char a, long b)
+{
+  long c = a;
+  c = c | (b << 12);
+  return c;
+}
+
+long bar (long b, char a)
+{
+  long c = a;
+  long m = -4096;
+  c = c | (b & m);
+  return c;
+}
+
+/* { dg-final { scan-assembler-times {\mrl[wd]imi\M} 2 } } */

[PATCH][pushed] remove 'continue' as last statement in loop

2022-07-22 Thread Martin Liška
PR other/106370

gcc/cp/ChangeLog:

* init.cc (sort_mem_initializers): Remove continue as last stmt
in a loop.

libiberty/ChangeLog:

* _doprnt.c: Remove continue as last stmt
in a loop.
---
 gcc/cp/init.cc  | 1 -
 libiberty/_doprnt.c | 1 -
 2 files changed, 2 deletions(-)

diff --git a/gcc/cp/init.cc b/gcc/cp/init.cc
index a4a0a0ac0c2..edca8437f64 100644
--- a/gcc/cp/init.cc
+++ b/gcc/cp/init.cc
@@ -1436,7 +1436,6 @@ sort_mem_initializers (tree t, tree mem_inits)
  continue;
splice:
  *p = TREE_CHAIN (*p);
- continue;
}
 }
 
diff --git a/libiberty/_doprnt.c b/libiberty/_doprnt.c
index cebaa16056b..c7232d858c6 100644
--- a/libiberty/_doprnt.c
+++ b/libiberty/_doprnt.c
@@ -55,7 +55,6 @@ Foundation, 51 Franklin Street - Fifth Floor, Boston, MA 
02110-1301, USA.  */
 putc(CHAR, stream); \
 ptr++; \
 total_printed++; \
-continue; \
  } while (0)
 
 #define PRINT_TYPE(TYPE) \
-- 
2.37.1



[PATCH] tree-optimization/106387 - properly create SSA name for realigned load

2022-07-22 Thread Richard Biener via Gcc-patches
The following fixes an oversight triggering after the recent change
to bump_vector_ptr.

Bootstrapped on x86_64-unknown-linux-gnu, pushed.

PR tree-optimization/106387
* tree-vect-stmts.cc (vectorizable_load): Use make_ssa_name
if ptr is not an SSA name.
---
 gcc/tree-vect-stmts.cc | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/gcc/tree-vect-stmts.cc b/gcc/tree-vect-stmts.cc
index 01d982eea98..f582d238984 100644
--- a/gcc/tree-vect-stmts.cc
+++ b/gcc/tree-vect-stmts.cc
@@ -10017,7 +10017,10 @@ vectorizable_load (vec_info *vinfo,
 (NULL_TREE, BIT_AND_EXPR, ptr,
  build_int_cst
  (TREE_TYPE (ptr), -(HOST_WIDE_INT) align));
-   ptr = copy_ssa_name (ptr, new_stmt);
+   if (TREE_CODE (ptr) == SSA_NAME)
+ ptr = copy_ssa_name (ptr, new_stmt);
+   else
+ ptr = make_ssa_name (TREE_TYPE (ptr), new_stmt);
gimple_assign_set_lhs (new_stmt, ptr);
vect_finish_stmt_generation (vinfo, stmt_info,
 new_stmt, gsi);
-- 
2.35.3


[PATCH] tree-optimization/106403 - fix ICE with VN of .STORE_LANES

2022-07-22 Thread Richard Biener via Gcc-patches
While .STORE_LANES is not supported by the recent VN patch we were
still accessing the stored value and valueizing it - but
internal_fn_stored_value_index does not support .STORE_LANES and
we failed to honor that case.  Fixed by simply moving the affected
code below the check for the actual supported internal functions.

Bootstrap / regtest running on x86_64-unknown-linux-gnu.

PR tree-optimization/106403
* tree-ssa-sccvn.cc (vn_reference_lookup_3): Move stored
value valueization after check for IFN_MASKED_STORE or
IFN_LEN_STORE.
---
 gcc/tree-ssa-sccvn.cc | 11 ++-
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/gcc/tree-ssa-sccvn.cc b/gcc/tree-ssa-sccvn.cc
index 0ebbc69b502..741e6ebc4ba 100644
--- a/gcc/tree-ssa-sccvn.cc
+++ b/gcc/tree-ssa-sccvn.cc
@@ -3227,11 +3227,6 @@ vn_reference_lookup_3 (ao_ref *ref, tree vuse, void 
*data_,
 {
   gcall *call = as_a  (def_stmt);
   internal_fn fn = gimple_call_internal_fn (call);
-  tree def_rhs = gimple_call_arg (call,
- internal_fn_stored_value_index (fn));
-  def_rhs = vn_valueize (def_rhs);
-  if (TREE_CODE (def_rhs) != VECTOR_CST)
-   return (void *)-1;
 
   tree mask = NULL_TREE, len = NULL_TREE, bias = NULL_TREE;
   switch (fn)
@@ -3251,6 +3246,12 @@ vn_reference_lookup_3 (ao_ref *ref, tree vuse, void 
*data_,
default:
  return (void *)-1;
}
+  tree def_rhs = gimple_call_arg (call,
+ internal_fn_stored_value_index (fn));
+  def_rhs = vn_valueize (def_rhs);
+  if (TREE_CODE (def_rhs) != VECTOR_CST)
+   return (void *)-1;
+
   ao_ref_init_from_ptr_and_size (&lhs_ref,
 vn_valueize (gimple_call_arg (call, 0)),
 TYPE_SIZE_UNIT (TREE_TYPE (def_rhs)));
-- 
2.35.3


[PATCH] tree-optimization/106397 - array prefetch and LC SSA

2022-07-22 Thread Richard Biener via Gcc-patches
The following fixes maintaining LC SSA when array prefetch inserts
mfence instructions on loop exits that do not use memory.  It also
fixes the latent issue that it might split exit edges for this
which will break LC SSA for non-virtuals as well.  It should also
make the process cheaper by accumulating the required (LC) SSA
update until the end of the pass.

Bootstrap and regtest running on x86_64-unknown-linux-gnu.

PR tree-optimization/106397
* tree-ssa-loop-prefetch.cc (emit_mfence_after_loop): Do
not update SSA form here.
(mark_nontemporal_stores): Return whether we marked any
non-temporal stores and inserted mfence.
(loop_prefetch_arrays): Note when we need to update SSA.
(tree_ssa_prefetch_arrays): Perform required (LC) SSA update
at the end of the pass.

* gcc.dg/pr106397.c: New testcase.
---
 gcc/testsuite/gcc.dg/pr106397.c | 17 +
 gcc/tree-ssa-loop-prefetch.cc   | 27 +--
 2 files changed, 34 insertions(+), 10 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/pr106397.c

diff --git a/gcc/testsuite/gcc.dg/pr106397.c b/gcc/testsuite/gcc.dg/pr106397.c
new file mode 100644
index 000..a6b2e913346
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr106397.c
@@ -0,0 +1,17 @@
+/* { dg-do compile } */
+/* { dg-options "-O3 -fprefetch-loop-arrays --param l2-cache-size=0 --param 
prefetch-latency=3 -fprefetch-loop-arrays" } */
+
+int
+bar (void)
+{
+  /* No return statement. */
+}
+
+__attribute__ ((simd)) int
+foo (void)
+{
+  if (bar ())
+return 0;
+
+  __builtin_unreachable ();
+}
diff --git a/gcc/tree-ssa-loop-prefetch.cc b/gcc/tree-ssa-loop-prefetch.cc
index 8f190ae469b..b6690b0e805 100644
--- a/gcc/tree-ssa-loop-prefetch.cc
+++ b/gcc/tree-ssa-loop-prefetch.cc
@@ -1308,8 +1308,6 @@ emit_mfence_after_loop (class loop *loop)
 
   gsi_insert_before (&bsi, call, GSI_NEW_STMT);
 }
-
-  update_ssa (TODO_update_ssa_only_virtuals);
 }
 
 /* Returns true if we can use storent in loop, false otherwise.  */
@@ -1340,23 +1338,27 @@ may_use_storent_in_loop_p (class loop *loop)
 }
 
 /* Marks nontemporal stores in LOOP.  GROUPS contains the description of memory
-   references in the loop.  */
+   references in the loop.  Returns whether we inserted any mfence call.  */
 
-static void
+static bool
 mark_nontemporal_stores (class loop *loop, struct mem_ref_group *groups)
 {
   struct mem_ref *ref;
   bool any = false;
 
   if (!may_use_storent_in_loop_p (loop))
-return;
+return false;
 
   for (; groups; groups = groups->next)
 for (ref = groups->refs; ref; ref = ref->next)
   any |= mark_nontemporal_store (ref);
 
   if (any && FENCE_FOLLOWING_MOVNT != NULL_TREE)
-emit_mfence_after_loop (loop);
+{
+  emit_mfence_after_loop (loop);
+  return true;
+}
+  return false;
 }
 
 /* Determines whether we can profitably unroll LOOP FACTOR times, and if
@@ -1874,10 +1876,11 @@ insn_to_prefetch_ratio_too_small_p (unsigned ninsns, 
unsigned prefetch_count,
 
 
 /* Issue prefetch instructions for array references in LOOP.  Returns
-   true if the LOOP was unrolled.  */
+   true if the LOOP was unrolled and updates NEED_LC_SSA_UPDATE if we need
+   to update SSA for virtual operands and LC SSA for a split edge.  */
 
 static bool
-loop_prefetch_arrays (class loop *loop)
+loop_prefetch_arrays (class loop *loop, bool &need_lc_ssa_update)
 {
   struct mem_ref_group *refs;
   unsigned ahead, ninsns, time, unroll_factor;
@@ -1952,7 +1955,7 @@ loop_prefetch_arrays (class loop *loop)
  unroll_factor))
 goto fail;
 
-  mark_nontemporal_stores (loop, refs);
+  need_lc_ssa_update |= mark_nontemporal_stores (loop, refs);
 
   /* Step 4: what to prefetch?  */
   if (!schedule_prefetches (refs, unroll_factor, ahead))
@@ -1980,6 +1983,7 @@ unsigned int
 tree_ssa_prefetch_arrays (void)
 {
   bool unrolled = false;
+  bool need_lc_ssa_update = false;
   int todo_flags = 0;
 
   if (!targetm.have_prefetch ()
@@ -2028,12 +2032,15 @@ tree_ssa_prefetch_arrays (void)
   if (dump_file && (dump_flags & TDF_DETAILS))
fprintf (dump_file, "Processing loop %d:\n", loop->num);
 
-  unrolled |= loop_prefetch_arrays (loop);
+  unrolled |= loop_prefetch_arrays (loop, need_lc_ssa_update);
 
   if (dump_file && (dump_flags & TDF_DETAILS))
fprintf (dump_file, "\n\n");
 }
 
+  if (need_lc_ssa_update)
+rewrite_into_loop_closed_ssa (NULL, TODO_update_ssa_only_virtuals);
+
   if (unrolled)
 {
   scev_reset ();
-- 
2.35.3


[PATCH] libsanitizer: Fix Solaris 11.3 compilation [PR105531]

2022-07-22 Thread Rainer Orth
The libsanitizer build has been broken on Solaris 11.3 by the latest
import.  An upstream patch to fix this has now been committed:

[sanitizer_common] Support Solaris < 11.4 in GetStaticTlsBoundary
https://reviews.llvm.org/D120059

I'd like to cherry-pick it into libsanitizer, too.

Bootstrapped without regressions on sparc-sun-solaris2.11,
i386-pc-solaris2.11 (both Solaris 11.3 and 11.4), and
x86_64-pc-linux-gnu.

Ok for trunk?

Rainer

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


2022-07-21  Rainer Orth  

libsanitizer:
PR sanitizer/105531
* libsanitizer/sanitizer_common/sanitizer_linux_libcdep.cpp,
libsanitizer/sanitizer_common/sanitizer_solaris.h:: Cherry-pick
llvm-project revision 3776db9a4fd2080d23d6a5f52e405eea44558761.

# HG changeset patch
# Parent  755774c20b0c4c41572195333c097be29d392b53
libsanitizer: Fix Solaris 11.3 compilation [PR105531]

diff --git a/libsanitizer/sanitizer_common/sanitizer_linux_libcdep.cpp b/libsanitizer/sanitizer_common/sanitizer_linux_libcdep.cpp
--- a/libsanitizer/sanitizer_common/sanitizer_linux_libcdep.cpp
+++ b/libsanitizer/sanitizer_common/sanitizer_linux_libcdep.cpp
@@ -27,6 +27,7 @@
 #include "sanitizer_linux.h"
 #include "sanitizer_placement_new.h"
 #include "sanitizer_procmaps.h"
+#include "sanitizer_solaris.h"
 
 #if SANITIZER_NETBSD
 #define _RTLD_SOURCE  // for __lwp_gettcb_fast() / __lwp_getprivate_fast()
@@ -62,6 +63,7 @@
 #endif
 
 #if SANITIZER_SOLARIS
+#include 
 #include 
 #include 
 #endif
@@ -350,19 +352,43 @@ static uptr TlsGetOffset(uptr ti_module,
 extern "C" void *__tls_get_addr(size_t *);
 #endif
 
+static size_t main_tls_modid;
+
 static int CollectStaticTlsBlocks(struct dl_phdr_info *info, size_t size,
   void *data) {
-  if (!info->dlpi_tls_modid)
+  size_t tls_modid;
+#if SANITIZER_SOLARIS
+  // dlpi_tls_modid is only available since Solaris 11.4 SRU 10.  Use
+  // dlinfo(RTLD_DI_LINKMAP) instead which works on all of Solaris 11.3,
+  // 11.4, and Illumos.  The tlsmodid of the executable was changed to 1 in
+  // 11.4 to match other implementations.
+  if (size >= offsetof(dl_phdr_info_test, dlpi_tls_modid))
+main_tls_modid = 1;
+  else
+main_tls_modid = 0;
+  g_use_dlpi_tls_data = 0;
+  Rt_map *map;
+  dlinfo(RTLD_SELF, RTLD_DI_LINKMAP, &map);
+  tls_modid = map->rt_tlsmodid;
+#else
+  main_tls_modid = 1;
+  tls_modid = info->dlpi_tls_modid;
+#endif
+
+  if (tls_modid < main_tls_modid)
 return 0;
-  uptr begin = (uptr)info->dlpi_tls_data;
+  uptr begin;
+#if !SANITIZER_SOLARIS
+  begin = (uptr)info->dlpi_tls_data;
+#endif
   if (!g_use_dlpi_tls_data) {
 // Call __tls_get_addr as a fallback. This forces TLS allocation on glibc
 // and FreeBSD.
 #ifdef __s390__
 begin = (uptr)__builtin_thread_pointer() +
-TlsGetOffset(info->dlpi_tls_modid, 0);
+TlsGetOffset(tls_modid, 0);
 #else
-size_t mod_and_off[2] = {info->dlpi_tls_modid, 0};
+size_t mod_and_off[2] = {tls_modid, 0};
 begin = (uptr)__tls_get_addr(mod_and_off);
 #endif
   }
@@ -370,7 +396,7 @@ static int CollectStaticTlsBlocks(struct
 if (info->dlpi_phdr[i].p_type == PT_TLS) {
   static_cast *>(data)->push_back(
   TlsBlock{begin, begin + info->dlpi_phdr[i].p_memsz,
-   info->dlpi_phdr[i].p_align, info->dlpi_tls_modid});
+   info->dlpi_phdr[i].p_align, tls_modid});
   break;
 }
   return 0;
@@ -382,11 +408,11 @@ static int CollectStaticTlsBlocks(struct
   dl_iterate_phdr(CollectStaticTlsBlocks, &ranges);
   uptr len = ranges.size();
   Sort(ranges.begin(), len);
-  // Find the range with tls_modid=1. For glibc, because libc.so uses PT_TLS,
-  // this module is guaranteed to exist and is one of the initially loaded
-  // modules.
+  // Find the range with tls_modid == main_tls_modid. For glibc, because
+  // libc.so uses PT_TLS, this module is guaranteed to exist and is one of
+  // the initially loaded modules.
   uptr one = 0;
-  while (one != len && ranges[one].tls_modid != 1) ++one;
+  while (one != len && ranges[one].tls_modid != main_tls_modid) ++one;
   if (one == len) {
 // This may happen with musl if no module uses PT_TLS.
 *addr = 0;
diff --git a/libsanitizer/sanitizer_common/sanitizer_solaris.h b/libsanitizer/sanitizer_common/sanitizer_solaris.h
new file mode 100644
--- /dev/null
+++ b/libsanitizer/sanitizer_common/sanitizer_solaris.h
@@ -0,0 +1,56 @@
+//===-- sanitizer_solaris.h -*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This file is a part of Sanitizer runtime

Re: [PATCH] libsanitizer: Fix Solaris 11.3 compilation [PR105531]

2022-07-22 Thread Richard Biener via Gcc-patches
On Fri, Jul 22, 2022 at 11:29 AM Rainer Orth
 wrote:
>
> The libsanitizer build has been broken on Solaris 11.3 by the latest
> import.  An upstream patch to fix this has now been committed:
>
> [sanitizer_common] Support Solaris < 11.4 in GetStaticTlsBoundary
> https://reviews.llvm.org/D120059
>
> I'd like to cherry-pick it into libsanitizer, too.
>
> Bootstrapped without regressions on sparc-sun-solaris2.11,
> i386-pc-solaris2.11 (both Solaris 11.3 and 11.4), and
> x86_64-pc-linux-gnu.
>
> Ok for trunk?

OK.

> Rainer
>
> --
> -
> Rainer Orth, Center for Biotechnology, Bielefeld University
>
>
> 2022-07-21  Rainer Orth  
>
> libsanitizer:
> PR sanitizer/105531
> * libsanitizer/sanitizer_common/sanitizer_linux_libcdep.cpp,
> libsanitizer/sanitizer_common/sanitizer_solaris.h:: Cherry-pick
> llvm-project revision 3776db9a4fd2080d23d6a5f52e405eea44558761.
>


[PATCH] Allow space in git commit-mklog args

2022-07-22 Thread Martin Liška
Hi.

Motivation example:
$ git commit-mklog -a -b 'PR other/106370,PR other/12345'

Preserving a space from git gcc-mklog hook to contrib/mklog.py seems
pretty challenging. Thus I recommend preserving extra mklog args via
env where it's encoded in JSON format.

Thoughts?
Thanks,
Martin

contrib/ChangeLog:

* git-commit-mklog.py: Do not parse -b argument.
Pass mklog_args as json environment variable.
* mklog.py: Parse GCC_MKLOG_ARGS and append it to sys.argv.
* prepare-commit-msg: Do not append GCC_MKLOG_ARGS to args.
---
 contrib/git-commit-mklog.py | 9 +
 contrib/mklog.py| 5 +
 contrib/prepare-commit-msg  | 2 +-
 3 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/contrib/git-commit-mklog.py b/contrib/git-commit-mklog.py
index eda3fc4a892..c7e90c8262f 100755
--- a/contrib/git-commit-mklog.py
+++ b/contrib/git-commit-mklog.py
@@ -24,6 +24,7 @@
 # to mklog.py script.
 
 import argparse
+import json
 import os
 import subprocess
 
@@ -32,8 +33,7 @@ if __name__ == '__main__':
 myenv = os.environ.copy()
 
 parser = argparse.ArgumentParser(description='git-commit-mklog wrapped')
-parser.add_argument('-b', '--pr-numbers', action='store',
-type=lambda arg: arg.split(','), nargs='?',
+parser.add_argument('-b', '--pr-numbers',
 help='Add the specified PRs (comma separated)')
 parser.add_argument('-p', '--fill-up-bug-titles', action='store_true',
 help='Download title of mentioned PRs')
@@ -44,12 +44,13 @@ if __name__ == '__main__':
 myenv['GCC_FORCE_MKLOG'] = '1'
 mklog_args = []
 if args.pr_numbers:
-mklog_args.append(f'-b {",".join(args.pr_numbers)}')
+mklog_args += ['-b', args.pr_numbers]
 if args.fill_up_bug_titles:
 mklog_args.append('-p')
 
 if mklog_args:
-myenv['GCC_MKLOG_ARGS'] = ' '.join(mklog_args)
+# wrap mklog arguments with JSON
+myenv['GCC_MKLOG_ARGS'] = json.dumps(mklog_args)
 
 if args.co:
 for author in args.co.split(','):
diff --git a/contrib/mklog.py b/contrib/mklog.py
index cd5ef0bcc74..fe530ebf773 100755
--- a/contrib/mklog.py
+++ b/contrib/mklog.py
@@ -28,6 +28,7 @@
 
 import argparse
 import datetime
+import json
 import os
 import re
 import subprocess
@@ -336,6 +337,10 @@ def skip_line_in_changelog(line):
 
 
 if __name__ == '__main__':
+extra_args = os.getenv('GCC_MKLOG_ARGS')
+if extra_args:
+sys.argv += json.loads(extra_args)
+
 parser = argparse.ArgumentParser(description=help_message)
 parser.add_argument('input', nargs='?',
 help='Patch file (or missing, read standard input)')
diff --git a/contrib/prepare-commit-msg b/contrib/prepare-commit-msg
index 5da878458cd..969847df6f4 100755
--- a/contrib/prepare-commit-msg
+++ b/contrib/prepare-commit-msg
@@ -78,4 +78,4 @@ else
 tee="cat"
 fi
 
-git $cmd | $tee | git gcc-mklog $GCC_MKLOG_ARGS -c "$COMMIT_MSG_FILE"
+git $cmd | $tee | git gcc-mklog -c "$COMMIT_MSG_FILE"
-- 
2.37.1



[PATCH][pushed] mklog: fill-up subject prefix only for a single PR

2022-07-22 Thread Martin Liška
I've just pushed this one.

Martin

contrib/ChangeLog:

* mklog.py: Use component: [PR xyz] only when one PR is used.
---
 contrib/mklog.py | 21 +
 1 file changed, 9 insertions(+), 12 deletions(-)

diff --git a/contrib/mklog.py b/contrib/mklog.py
index cd5ef0bcc74..8693767a7f6 100755
--- a/contrib/mklog.py
+++ b/contrib/mklog.py
@@ -73,8 +73,6 @@ PATCH must be generated using diff(1)'s -up or -cp options
 script_folder = os.path.realpath(__file__)
 root = os.path.dirname(os.path.dirname(script_folder))
 
-firstpr = ''
-
 
 def find_changelog(path):
 folder = os.path.split(path)[0]
@@ -157,12 +155,13 @@ def get_rel_path_if_prefixed(path, folder):
 
 def generate_changelog(data, no_functions=False, fill_pr_titles=False,
additional_prs=None):
+global prs
+prs = []
+
 changelogs = {}
 changelog_list = []
-prs = []
 out = ''
 diff = PatchSet(data)
-global firstpr
 
 if additional_prs:
 for apr in additional_prs:
@@ -212,9 +211,6 @@ def generate_changelog(data, no_functions=False, 
fill_pr_titles=False,
 if pr not in this_file_prs and pr2 not in prs:
 prs.append(pr2)
 
-if prs:
-firstpr = prs[0]
-
 if fill_pr_titles:
 out += get_pr_titles(prs)
 
@@ -372,11 +368,12 @@ if __name__ == '__main__':
 end = lines[len(start):]
 with open(args.changelog, 'w') as f:
 if not start or not start[0]:
-# initial commit subject line 'component: [PRn]'
-m = prnum_regex.match(firstpr)
-if m:
-title = f'{m.group("comp")}: [PR{m.group("num")}]'
-start.insert(0, title)
+if len(prs) == 1:
+# initial commit subject line 'component: [PRn]'
+m = prnum_regex.match(prs[0])
+if m:
+title = f'{m.group("comp")}: [PR{m.group("num")}]'
+start.insert(0, title)
 if start:
 # append empty line
 if start[-1] != '':
-- 
2.37.1



[patch] libgomp/splay-tree.h: Fix splay_tree_prefix handling

2022-07-22 Thread Tobias Burnus

As is, it is only a cleanup/consistency patch.

However, I did run into this issue when working on the reverse-offload
implementation (to handle reverse lookups of vars and functions).

OK for mainline?

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
libgomp/splay-tree.h: Fix splay_tree_prefix handling

When splay_tree_prefix is defined, the .h file
defines splay_* macros to add the prefix. However,
before those were only unset when additionally
splay_tree_c was defined.
Additionally, for consistency undefine splay_tree_c
also when no splay_tree_prefix is defined - there
is no interdependence either.

libgomp/ChangeLog:

	* splay-tree.h: Fix splay_* macro unsetting if
	splay_tree_prefix is defined.

 libgomp/splay-tree.h | 30 +++---
 1 file changed, 15 insertions(+), 15 deletions(-)

diff --git a/libgomp/splay-tree.h b/libgomp/splay-tree.h
index 8d66dfb51e0..992381c4000 100644
--- a/libgomp/splay-tree.h
+++ b/libgomp/splay-tree.h
@@ -107,24 +107,24 @@ extern void splay_tree_foreach (splay_tree, splay_tree_callback, void *);
 #else  /* splay_tree_c */
 #  ifdef splay_tree_prefix
 #include "splay-tree.c"
-#undef splay_tree_name_1
-#undef splay_tree_name
-#undef splay_tree_node_s
-#undef splay_tree_s
-#undef splay_tree_key_s
-#undef splay_tree_node
-#undef splay_tree
-#undef splay_tree_key
-#undef splay_compare
-#undef splay_tree_lookup
-#undef splay_tree_insert
-#undef splay_tree_remove
-#undef splay_tree_foreach
-#undef splay_tree_callback
-#undef splay_tree_c
 #  endif
+#  undef splay_tree_c
 #endif /* #ifndef splay_tree_c */
 
 #ifdef splay_tree_prefix
+#  undef splay_tree_name_1
+#  undef splay_tree_name
+#  undef splay_tree_node_s
+#  undef splay_tree_s
+#  undef splay_tree_key_s
+#  undef splay_tree_node
+#  undef splay_tree
+#  undef splay_tree_key
+#  undef splay_compare
+#  undef splay_tree_lookup
+#  undef splay_tree_insert
+#  undef splay_tree_remove
+#  undef splay_tree_foreach
+#  undef splay_tree_callback
 #  undef splay_tree_prefix
 #endif


[PATCH] graphds: Fix description of SCC algorithm

2022-07-22 Thread Richard Sandiford via Gcc-patches
graphds_scc says that it uses Tarjan's algorithm, but it looks like
it uses Kosaraju's algorithm instead (dfs one way followed by dfs
the other way).

OK to install?

Richard


gcc/
* graphds.cc (graphds_scc): Fix algorithm attribution.
---
 gcc/graphds.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/graphds.cc b/gcc/graphds.cc
index f4c83e81cf9..91a2ca5c225 100644
--- a/gcc/graphds.cc
+++ b/gcc/graphds.cc
@@ -276,7 +276,7 @@ graphds_dfs (struct graph *g, int *qs, int nq, vec *qt,
 }
 
 /* Determines the strongly connected components of G, using the algorithm of
-   Tarjan -- first determine the postorder dfs numbering in reversed graph,
+   Kosaraju -- first determine the postorder dfs numbering in reversed graph,
then run the dfs on the original graph in the order given by decreasing
numbers assigned by the previous pass.  If SUBGRAPH is not NULL, it
specifies the subgraph of G whose strongly connected components we want
-- 
2.25.1



[PATCH 5/12 V3] arm: Implement target feature macros for PACBTI

2022-07-22 Thread Andrea Corallo via Gcc-patches
Hi Richard,

thanks for reviewing.

Richard Earnshaw  writes:

[...]

> diff --git a/gcc/testsuite/gcc.target/arm/acle/pacbti-m-predef-10.c
> b/gcc/testsuite/gcc.target/arm/acle/pacbti-m-predef-10.c
> new file mode 100644
> index 000..311cf572dd9
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/arm/acle/pacbti-m-predef-10.c
> @@ -0,0 +1,10 @@
> +/* { dg-do compile } */
> +/* { dg-additional-options " -mbranch-protection=bti+pac-ret" } */
>
> This is not enough.  For example, if the testsuite is being run with
> "-march=armv6-m" as the testrun options, we'll get an error that will
> cause a test failure.  You need to run a pre-test rule that validates
> that adding -mbranch-protection is safe.

Right, please find attached the updated patch, it should fix this and
the mentioned spacing issue.

BR

  Andrea

>From d5e0c5c0c4a3a07eb6a65c7626f474a0dbd4f8db Mon Sep 17 00:00:00 2001
From: Andrea Corallo 
Date: Mon, 6 Dec 2021 11:39:59 +0100
Subject: [PATCH] [PATCH 5/12] arm: Implement target feature macros for PACBTI

This patch implements target feature macros when PACBTI is enabled
through the -march option or -mbranch-protection.  The target feature
macros __ARM_FEATURE_PAC_DEFAULT and __ARM_FEATURE_BTI_DEFAULT are
specified in ARM ACLE

__ARM_FEATURE_PAUTH and __ARM_FEATURE_BTI are specified in the
pull-request .

Approved here
.

gcc/

* config/arm/arm-c.c (arm_cpu_builtins): Define
__ARM_FEATURE_BTI_DEFAULT, __ARM_FEATURE_PAC_DEFAULT,
__ARM_FEATURE_PAUTH and __ARM_FEATURE_BTI.

gcc/testsuite/

* lib/target-supports.exp
(check_effective_target_mbranch_protection_ok): New function.
* gcc.target/arm/acle/pacbti-m-predef-2.c: New test.
* gcc.target/arm/acle/pacbti-m-predef-4.c: Likewise.
* gcc.target/arm/acle/pacbti-m-predef-5.c: Likewise.
* gcc.target/arm/acle/pacbti-m-predef-8.c: Likewise.
* gcc.target/arm/acle/pacbti-m-predef-9.c: Likewise.
* gcc.target/arm/acle/pacbti-m-predef-10.c: Likewise.
* gcc.target/arm/acle/pacbti-m-predef-11.c: Likewise.
* gcc.target/arm/acle/pacbti-m-predef-12.c: Likewise.

Co-Authored-By: Tejas Belagod  
---
 gcc/config/arm/arm-c.cc   | 18 +++
 .../gcc.target/arm/acle/pacbti-m-predef-10.c  | 11 +
 .../gcc.target/arm/acle/pacbti-m-predef-11.c  | 11 +
 .../gcc.target/arm/acle/pacbti-m-predef-12.c  | 11 +
 .../gcc.target/arm/acle/pacbti-m-predef-2.c   | 23 +++
 .../gcc.target/arm/acle/pacbti-m-predef-4.c   | 20 
 .../gcc.target/arm/acle/pacbti-m-predef-5.c   | 23 +++
 .../gcc.target/arm/acle/pacbti-m-predef-8.c   | 11 +
 .../gcc.target/arm/acle/pacbti-m-predef-9.c   | 10 
 gcc/testsuite/lib/target-supports.exp | 10 
 10 files changed, 148 insertions(+)
 create mode 100644 gcc/testsuite/gcc.target/arm/acle/pacbti-m-predef-10.c
 create mode 100644 gcc/testsuite/gcc.target/arm/acle/pacbti-m-predef-11.c
 create mode 100644 gcc/testsuite/gcc.target/arm/acle/pacbti-m-predef-12.c
 create mode 100644 gcc/testsuite/gcc.target/arm/acle/pacbti-m-predef-2.c
 create mode 100644 gcc/testsuite/gcc.target/arm/acle/pacbti-m-predef-4.c
 create mode 100644 gcc/testsuite/gcc.target/arm/acle/pacbti-m-predef-5.c
 create mode 100644 gcc/testsuite/gcc.target/arm/acle/pacbti-m-predef-8.c
 create mode 100644 gcc/testsuite/gcc.target/arm/acle/pacbti-m-predef-9.c

diff --git a/gcc/config/arm/arm-c.cc b/gcc/config/arm/arm-c.cc
index a8697b8c62f..190099b2c37 100644
--- a/gcc/config/arm/arm-c.cc
+++ b/gcc/config/arm/arm-c.cc
@@ -212,6 +212,24 @@ arm_cpu_builtins (struct cpp_reader* pfile)
   def_or_undef_macro (pfile, "__ARM_FEATURE_COMPLEX", TARGET_COMPLEX);
   def_or_undef_macro (pfile, "__ARM_32BIT_STATE", TARGET_32BIT);
 
+  def_or_undef_macro (pfile, "__ARM_FEATURE_PAUTH", TARGET_HAVE_PACBTI);
+  def_or_undef_macro (pfile, "__ARM_FEATURE_BTI", TARGET_HAVE_PACBTI);
+  def_or_undef_macro (pfile, "__ARM_FEATURE_BTI_DEFAULT",
+ aarch_enable_bti == 1);
+
+  cpp_undef (pfile, "__ARM_FEATURE_PAC_DEFAULT");
+  if (aarch_ra_sign_scope != AARCH_FUNCTION_NONE)
+  {
+unsigned int pac = 1;
+
+gcc_assert (aarch_ra_sign_key == AARCH_KEY_A);
+
+if (aarch_ra_sign_scope == AARCH_FUNCTION_ALL)
+  pac |= 0x4;
+
+builtin_define_with_int_value ("__ARM_FEATURE_PAC_DEFAULT", pac);
+  }
+
   cpp_undef (pfile, "__ARM_FEATURE_MVE");
   if (TARGET_HAVE_MVE && TARGET_HAVE_MVE_FLOAT)
 {
diff --git a/gcc/testsuite/gcc.target/arm/acle/pacbti-m-predef-10.c 
b/gcc/testsuite/gcc.target/arm/acle/pacbti-m-predef-10.c
new file mode 100644
index 000..4fcc96f3eb4
--- /dev/null
+++ b/gcc/testsuite/gcc.target/arm/acle/pacbti-m-predef-10.c
@@ -0,0 +1,11 @@
+/* {

[Patch] OpenMP requires: Fix diagnostic filename corner case

2022-07-22 Thread Tobias Burnus

This patch addresses a corner case which causes a filename
confusion:
  lto1: error: OpenMP 'requires' directive with 'unified_address' specified 
only in some compilation units
  lto1: note: '1.c' has 'unified_address'
  lto1: note: but '1.c' has not
  lto1: fatal error: errors during merging of translation units

This happens, e.g., for a source code like the following, where two files
are identical except that only one has an additional '#pragma omp requires':


int
main ()
{
  int i;
  #pragma omp target map(from:i)
i = 1;
  return i;
}


Both have 'main._omp_fn.0' - which gets merged to the same decl such
that the source file will be identical.

Without the fatal error shown for requires, it would fail later during
liking due to having the same symbol ('main') multiple times - but that
additional diagnostic is not reached, leaving one puzzled.

I did run into this with 'gcc -fopenmp test_*.c' missing that I had a
second file in that dir which also started with test_...

OK for mainline? Or do you think adding a testcase makes sense?

Tobias

PS: It might also be possible to generate this with class instantiations
for valid code - other than the requires mismatch.

PPS: If compiles as 'gcc -fopenmp .c' / in the testsuite, the new inform
will be:
  lto1: note: '/tmp/ccAs0w67.o' has 'unified_address'
  lto1: note: but '/tmp/ccv6XCfc.o' has not
That avoids the issue with showing the sane name but is not perfect, either.
But that's a known issue and splittitng compiling from linking will improve
the diagnostic!
-
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 requires: Fix diagnostic filename corner case

The issue occurs when there is, e.g., main._omp_fn.0 in two files with
different OpenMP requires clauses.  The function entries in the offload
table ends up having the same decl tree and, hence, the diagnostic showed
the same filename for both.  Solution: Use the .o filename in this case.

Note that the issue does not occur with same-named 'static' functions and
without the fatal error from the requires diagnostic, there would be
later a linker error due to having two 'main'.

gcc/
	* lto-cgraph.cc (input_offload_tables): Improve requires diagnostic
	when filenames come out identically.

diff --git a/gcc/lto-cgraph.cc b/gcc/lto-cgraph.cc
index 062677a32eb..350195d86db 100644
--- a/gcc/lto-cgraph.cc
+++ b/gcc/lto-cgraph.cc
@@ -1893,6 +1893,11 @@ input_offload_tables (bool do_force_output)
 		  if (tmp_decl != NULL_TREE)
 			fn2 = IDENTIFIER_POINTER (DECL_NAME (tmp_decl));
 		}
+		  if (fn1 == fn2)
+		{
+		  fn1 = requires_fn;
+		  fn2 = file_data->file_name;
+		}
 
 		  char buf1[sizeof ("unified_address, unified_shared_memory, "
 "reverse_offload")];


Re: [PATCH] Allow space in git commit-mklog args

2022-07-22 Thread Jonathan Wakely via Gcc-patches
On Fri, 22 Jul 2022 at 10:38, Martin Liška wrote:
>
> Hi.
>
> Motivation example:
> $ git commit-mklog -a -b 'PR other/106370,PR other/12345'
>
> Preserving a space from git gcc-mklog hook to contrib/mklog.py seems
> pretty challenging. Thus I recommend preserving extra mklog args via
> env where it's encoded in JSON format.
>
> Thoughts?

This solution looks much better than trying to get the shell quoting
and word splitting right.

For the record, my suggestion was to surround each arg in double
quotes within the env var and then ...

> diff --git a/contrib/prepare-commit-msg b/contrib/prepare-commit-msg
> index 5da878458cd..969847df6f4 100755
> --- a/contrib/prepare-commit-msg
> +++ b/contrib/prepare-commit-msg
> @@ -78,4 +78,4 @@ else
>  tee="cat"
>  fi
>
> -git $cmd | $tee | git gcc-mklog $GCC_MKLOG_ARGS -c "$COMMIT_MSG_FILE"
> +git $cmd | $tee | git gcc-mklog -c "$COMMIT_MSG_FILE"

... change this to:

mklog() {
  echo "$GCC_MKLOG_ARGS" | xargs -x git gcc-mklog -c "$COMMIT_MSG_FILE"
}
git $cmd | $tee | mklog

This works because xargs respects quotes within its input and so would
pass them correctly to the git gcc-mklog command.

But avoiding this entirely by storing them as json and then not
retrieving them until the mklog.py step is more reliable.


Re: [PATCH] graphds: Fix description of SCC algorithm

2022-07-22 Thread Richard Biener via Gcc-patches
On Fri, Jul 22, 2022 at 12:10 PM Richard Sandiford via Gcc-patches
 wrote:
>
> graphds_scc says that it uses Tarjan's algorithm, but it looks like
> it uses Kosaraju's algorithm instead (dfs one way followed by dfs
> the other way).
>
> OK to install?

OK.

> Richard
>
>
> gcc/
> * graphds.cc (graphds_scc): Fix algorithm attribution.
> ---
>  gcc/graphds.cc | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/gcc/graphds.cc b/gcc/graphds.cc
> index f4c83e81cf9..91a2ca5c225 100644
> --- a/gcc/graphds.cc
> +++ b/gcc/graphds.cc
> @@ -276,7 +276,7 @@ graphds_dfs (struct graph *g, int *qs, int nq, vec 
> *qt,
>  }
>
>  /* Determines the strongly connected components of G, using the algorithm of
> -   Tarjan -- first determine the postorder dfs numbering in reversed graph,
> +   Kosaraju -- first determine the postorder dfs numbering in reversed graph,
> then run the dfs on the original graph in the order given by decreasing
> numbers assigned by the previous pass.  If SUBGRAPH is not NULL, it
> specifies the subgraph of G whose strongly connected components we want
> --
> 2.25.1
>


[PATCH] xtensa: Optimize "bitwise AND NOT with imm" followed by "branch if (not) equal to zero"

2022-07-22 Thread Takayuki 'January June' Suwa via Gcc-patches
The RTL combiner will transform "if ((x & C) == C) goto label;"
into "if ((~x & C) == 0) goto label;" and will try to match it with
the insn patterns.

/* example */
void test_0(int a) {
  if ((char)a == 255)
foo();
}
void test_1(int a) {
  if ((unsigned short)a == 0x)
foo();
}
void test_2(int a) {
  if ((a & 0x3F80) != 0x3F80)
foo();
}

;; before
test_0:
extui   a2, a2, 0, 8
movia3, 0xff
bne a2, a3, .L1
j.l foo, a9
.L1:
ret.n
test_1:
movi.n  a3, -1
extui   a2, a2, 0, 16
extui   a3, a3, 16, 16
bne a2, a3, .L3
j.l foo, a9
.L3:
ret.n
test_2:
movia3, 0x80
extui   a2, a2, 7, 7
addmi   a3, a3, 0x3f00
sllia2, a2, 7
beq a2, a3, .L5
j.l foo, a9
.L5:
ret.n

;; after
test_0:
movia3, 0xff
bnall   a2, a3, .L1
j.l foo, a9
.L1:
ret.n
test_1:
movi.n  a3, -1
extui   a3, a3, 16, 16
bnall   a2, a3, .L3
j.l foo, a9
.L3:
ret.n
test_2:
movia3, 0x80
addmi   a3, a3, 0x3f00
balla2, a3, .L5
j.l foo, a9
.L5:
ret.n

gcc/ChangeLog:

* config/xtensa/xtensa.md (*masktrue_const_bitcmpl):
Add a new insn_and_split pattern, and a few split patterns for
spacial cases.
---
 gcc/config/xtensa/xtensa.md | 84 +
 1 file changed, 84 insertions(+)

diff --git a/gcc/config/xtensa/xtensa.md b/gcc/config/xtensa/xtensa.md
index c02f1a56641..899ce2755aa 100644
--- a/gcc/config/xtensa/xtensa.md
+++ b/gcc/config/xtensa/xtensa.md
@@ -1714,6 +1714,90 @@
(set_attr "mode""none")
(set_attr "length"  "3")])
 
+(define_insn_and_split "*masktrue_const_bitcmpl"
+  [(set (pc)
+   (if_then_else (match_operator 3 "boolean_operator"
+   [(and:SI (not:SI (match_operand:SI 0 "register_operand" 
"r"))
+(match_operand:SI 1 "const_int_operand" "i"))
+(const_int 0)])
+ (label_ref (match_operand 2 "" ""))
+ (pc)))]
+  "exact_log2 (INTVAL (operands[1])) < 0"
+  "#"
+  "&& can_create_pseudo_p ()"
+  [(set (match_dup 4)
+   (match_dup 1))
+   (set (pc)
+   (if_then_else (match_op_dup 3
+   [(and:SI (not:SI (match_dup 0))
+(match_dup 4))
+(const_int 0)])
+ (label_ref (match_dup 2))
+ (pc)))]
+{
+  operands[4] = gen_reg_rtx (SImode);
+}
+  [(set_attr "type""jump")
+   (set_attr "mode""none")
+   (set (attr "length")
+   (if_then_else (match_test "TARGET_DENSITY
+  && IN_RANGE (INTVAL (operands[1]), -32, 95)")
+ (const_int 5)
+ (if_then_else (match_test "xtensa_simm12b (INTVAL 
(operands[1]))")
+   (const_int 6)
+   (const_int 10])
+
+(define_split
+  [(set (pc)
+   (if_then_else (match_operator 2 "boolean_operator"
+   [(subreg:HQI (not:SI (match_operand:SI 0 
"register_operand")) 0)
+(const_int 0)])
+ (label_ref (match_operand 1 ""))
+ (pc)))]
+  "!BYTES_BIG_ENDIAN"
+  [(set (pc)
+   (if_then_else (match_op_dup 2
+   [(and:SI (not:SI (match_dup 0))
+(match_dup 3))
+(const_int 0)])
+ (label_ref (match_dup 1))
+ (pc)))]
+{
+  operands[3] = GEN_INT ((1 << GET_MODE_BITSIZE (mode)) - 1);
+})
+
+(define_split
+  [(set (pc)
+   (if_then_else (match_operator 2 "boolean_operator"
+   [(subreg:HI (not:SI (match_operand:SI 0 
"register_operand")) 2)
+(const_int 0)])
+ (label_ref (match_operand 1 ""))
+ (pc)))]
+  "BYTES_BIG_ENDIAN"
+  [(set (pc)
+   (if_then_else (match_op_dup 2
+   [(and:SI (not:SI (match_dup 0))
+(const_int 65535))
+(const_int 0)])
+ (label_ref (match_dup 1))
+ (pc)))])
+
+(define_split
+  [(set (pc)
+   (if_then_else (match_operator 2 "boolean_operator"
+   [(subreg:QI (not:SI (match_operand:SI 0 
"register_operand")) 3)
+(const_int 0)])
+ (label_ref (match_operand 1 ""))
+ (pc)))]
+  "BYTES_BIG_ENDIAN"
+  [(set (pc)
+   (if_then_else (match_op_dup 2
+   [(and:SI (not:SI (match_dup 0))
+(const_int 255))
+ 

Re: [PATCH] c++: Refer to internal linkage for -Wsubobject-linkage [PR86491]

2022-07-22 Thread Jonathan Wakely via Gcc-patches
ping
https://gcc.gnu.org/pipermail/gcc-patches/2022-June/597560.html

On Thu, 30 Jun 2022 at 17:53, Jonathan Wakely  wrote:
>
> Tested powerpc64le-linux, OK for trunk?
>
> -- >8 --
>
> Since C++11 relaxed the requirement for template arguments to have
> external linkage, it's possible to get -Wsubobject-linkage warnings
> without using any anonymous namespaces. This confuses users when they
> get diagnostics that refer to an anonymous namespace that doesn't exist
> in their code.
>
> This changes the diagnostic to say "has internal linkage" for C++11 and
> later, which is accurate whether internal linkage is due to the 'static'
> specifier, or due to the use of anonymous namespaces.
>
> For C++98 template arguments declared with 'static' are ill-formed
> anyway, so the only way this warning can arise is via anonymous
> namespaces. That means the existing wording is accurate for C++98 and so
> we can keep it.
>
> PR c++/86491
>
> gcc/cp/ChangeLog:
>
> * decl2.cc (constrain_class_visibility): Adjust wording of
> -Wsubobject-linkage to account for cases where anonymous
> namespaces aren't used.
>
> gcc/testsuite/ChangeLog:
>
> * g++.dg/warn/Wsubobject-linkage-3.C: Adjust for new warning.
> * g++.dg/warn/anonymous-namespace-1.C: Use separate dg-warning
> directives for C++98 and everything else.
> * g++.dg/warn/anonymous-namespace-2.C: Likewise.
> * g++.dg/warn/anonymous-namespace-3.C: Likewise.
> ---
>  gcc/cp/decl2.cc   | 12 ++--
>  gcc/testsuite/g++.dg/warn/Wsubobject-linkage-3.C  |  4 ++--
>  gcc/testsuite/g++.dg/warn/anonymous-namespace-1.C |  8 ++--
>  gcc/testsuite/g++.dg/warn/anonymous-namespace-2.C |  9 ++---
>  gcc/testsuite/g++.dg/warn/anonymous-namespace-3.C |  3 ++-
>  5 files changed, 26 insertions(+), 10 deletions(-)
>
> diff --git a/gcc/cp/decl2.cc b/gcc/cp/decl2.cc
> index 3737e5f010c..de53678715e 100644
> --- a/gcc/cp/decl2.cc
> +++ b/gcc/cp/decl2.cc
> @@ -3027,7 +3027,11 @@ constrain_class_visibility (tree type)
>  %qT has a field %qD whose type depends on the type %qT which has no linkage",
>type, t, nlt);
>   }
> -   else
> +   else if (cxx_dialect > cxx98)
> + warning (OPT_Wsubobject_linkage, "\
> +%qT has a field %qD whose type has internal linkage",
> +  type, t);
> +   else // In C++98 this can only happen with unnamed namespaces.
>   warning (OPT_Wsubobject_linkage, "\
>  %qT has a field %qD whose type uses the anonymous namespace",
>type, t);
> @@ -3062,7 +3066,11 @@ constrain_class_visibility (tree type)
>  %qT has a base %qT whose type depends on the type %qT which has no linkage",
>  type, TREE_TYPE (t), nlt);
> }
> - else
> + else if (cxx_dialect > cxx98)
> +   warning (OPT_Wsubobject_linkage, "\
> +%qT has a base %qT whose type has internal linkage",
> +type, TREE_TYPE (t));
> + else // In C++98 this can only happen with unnamed namespaces.
> warning (OPT_Wsubobject_linkage, "\
>  %qT has a base %qT whose type uses the anonymous namespace",
>  type, TREE_TYPE (t));
> diff --git a/gcc/testsuite/g++.dg/warn/Wsubobject-linkage-3.C 
> b/gcc/testsuite/g++.dg/warn/Wsubobject-linkage-3.C
> index 95a04501441..b116fbbb186 100644
> --- a/gcc/testsuite/g++.dg/warn/Wsubobject-linkage-3.C
> +++ b/gcc/testsuite/g++.dg/warn/Wsubobject-linkage-3.C
> @@ -3,7 +3,7 @@
>  namespace { struct Foo { }; }
>
>  #line 6 "foo.C"
> -struct Bar { Foo foo; };   // { dg-warning "anonymous namespace" }
> +struct Bar { Foo foo; };   // { dg-warning "anonymous namespace|internal 
> linkage" }
>  // { dg-bogus "no linkage" "" { target *-*-* } .-1 }
> -struct Bar2 : Foo { }; // { dg-warning "anonymous namespace" }
> +struct Bar2 : Foo { }; // { dg-warning "anonymous namespace|internal 
> linkage" }
>  // { dg-bogus "no linkage" "" { target *-*-* } .-1 }
> diff --git a/gcc/testsuite/g++.dg/warn/anonymous-namespace-1.C 
> b/gcc/testsuite/g++.dg/warn/anonymous-namespace-1.C
> index cf193e0cba5..eed3818c5cf 100644
> --- a/gcc/testsuite/g++.dg/warn/anonymous-namespace-1.C
> +++ b/gcc/testsuite/g++.dg/warn/anonymous-namespace-1.C
> @@ -14,5 +14,9 @@ class foobar1
>  };
>
>  #line 17 "foo.C"
> -class foobar : public bad { }; // { dg-warning "uses the anonymous 
> namespace" }
> -class foobar2 { bad b; }; // { dg-warning "uses the anonymous namespace" }
> +class foobar : public bad { };
> +// { dg-warning "has internal linkage" "" { target c++11 } .-1 }
> +// { dg-warning "uses the anonymous namespace" "" { target c++98_only } .-2 }
> +class foobar2 { bad b; };
> +// { dg-warning "has internal linkage" "" { target c++11 } .-1 }
> +// { dg-warning "uses the anonymous namespace" "

[PATCH] btf: do not use the CHAR `encoding' bit for BTF

2022-07-22 Thread Jose E. Marchesi via Gcc-patches


Contrary to CTF and our previous expectations, as per [1], turns out
that in BTF:

1) The `encoding' field in integer types shall not be treated as a
   bitmap, but as an enumerated, i.e. these bits are exclusive to each
   other.

2) The CHAR bit in `encoding' shall _not_ be set when emitting types
   for char nor `unsigned char'.

Consequently this patch clears the CHAR bit before emitting the
variable part of BTF integral types.  It also updates the testsuite
accordingly, expanding it to check for BOOL bits.

[1] https://lore.kernel.org/bpf/a73586ad-f2dc-0401-1eba-2004357b7...@fb.com/T/#t

gcc/ChangeLog:

* btfout.cc (output_asm_btf_vlen_bytes): Do not use the CHAR
encoding bit in BTF.

gcc/testsuite/ChangeLog:

* gcc.dg/debug/btf/btf-int-1.c: Do not check for char bits in
bti_encoding and check for bool bits.
---
 gcc/btfout.cc  |  4 
 gcc/testsuite/gcc.dg/debug/btf/btf-int-1.c | 18 +++---
 2 files changed, 15 insertions(+), 7 deletions(-)

diff --git a/gcc/btfout.cc b/gcc/btfout.cc
index 31af50521da..576f73d47cf 100644
--- a/gcc/btfout.cc
+++ b/gcc/btfout.cc
@@ -914,6 +914,10 @@ output_asm_btf_vlen_bytes (ctf_container_ref ctfc, 
ctf_dtdef_ref dtd)
   if (dtd->dtd_data.ctti_size < 1)
break;
 
+  /* In BTF the CHAR `encoding' seems to not be used, so clear it
+ here.  */
+  dtd->dtd_u.dtu_enc.cte_format &= ~BTF_INT_CHAR;
+
   encoding = BTF_INT_DATA (dtd->dtd_u.dtu_enc.cte_format,
   dtd->dtd_u.dtu_enc.cte_offset,
   dtd->dtd_u.dtu_enc.cte_bits);
diff --git a/gcc/testsuite/gcc.dg/debug/btf/btf-int-1.c 
b/gcc/testsuite/gcc.dg/debug/btf/btf-int-1.c
index 2381decd6ff..87d9758e9cb 100644
--- a/gcc/testsuite/gcc.dg/debug/btf/btf-int-1.c
+++ b/gcc/testsuite/gcc.dg/debug/btf/btf-int-1.c
@@ -4,7 +4,8 @@
| 0 | encoding | offset | 00 | bits |
encoding:
  signed  1 << 24
- char2 << 24
+ char2 << 24  (not used)
+ bool4 << 24
 
All offsets in this test should be 0.
This test does _not_ check number of bits, as it may vary between targets.
@@ -13,13 +14,14 @@
 /* { dg-do compile } */
 /* { dg-options "-O0 -gbtf -dA" } */
 
-/* Check for 8 BTF_KIND_INT types.  */
-/* { dg-final { scan-assembler-times "\[\t \]0x100\[\t 
\]+\[^\n\]*btt_info" 8 } } */
+/* Check for 9 BTF_KIND_INT types.  */
+/* { dg-final { scan-assembler-times "\[\t \]0x100\[\t 
\]+\[^\n\]*btt_info" 9 } } */
 
-/* Check the signed/char flags, but not bit size. */
-/* { dg-final { scan-assembler-times "\[\t \]0x1..\[\t 
\]+\[^\n\]*bti_encoding" 3 } } */
-/* { dg-final { scan-assembler-times "\[\t \]0x2..\[\t 
\]+\[^\n\]*bti_encoding" 1 } } */
-/* { dg-final { scan-assembler-times "\[\t \]0x3..\[\t 
\]+\[^\n\]*bti_encoding" 1 } } */
+/* Check the signed flags, but not bit size. */
+/* { dg-final { scan-assembler-times "\[\t \]0x1..\[\t 
\]+\[^\n\]*bti_encoding" 4 } } */
+/* { dg-final { scan-assembler-times "\[\t \]0x..\[\t \]+\[^\n\]*bti_encoding" 
3 } } */
+/* { dg-final { scan-assembler-times "\[\t \]0x.\[\t \]+\[^\n\]*bti_encoding" 
1 } } */
+/* { dg-final { scan-assembler-times "\[\t \]0x4..\[\t 
\]+\[^\n\]*bti_encoding" 1 } } */
 
 /* Check that there is a string entry for each type name.  */
 /* { dg-final { scan-assembler-times "ascii \"unsigned char.0\"\[\t 
\]+\[^\n\]*btf_string" 1 } } */
@@ -42,3 +44,5 @@ signed int f = -66;
 
 unsigned long int g = 77;
 signed long int h = 88;
+
+_Bool x = 1;
-- 
2.11.0



Re: [PATCH] c++: ICE with erroneous template redeclaration [PR106311]

2022-07-22 Thread Marek Polacek via Gcc-patches
Ping.

On Fri, Jul 15, 2022 at 11:29:20AM -0400, Marek Polacek via Gcc-patches wrote:
> Here we ICE trying to get DECL_SOURCE_LOCATION of the parm that happens
> to be error_mark_node in this ill-formed test.  I kept running into this
> while reducing code, so it'd be good to have it fixed.
> 
> Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?
> 
>   PR c++/106311
> 
> gcc/cp/ChangeLog:
> 
>   * pt.cc (redeclare_class_template): Check DECL_P before accessing
>   DECL_SOURCE_LOCATION.
> 
> gcc/testsuite/ChangeLog:
> 
>   * g++.dg/template/redecl5.C: New test.
> ---
>  gcc/cp/pt.cc| 3 ++-
>  gcc/testsuite/g++.dg/template/redecl5.C | 5 +
>  2 files changed, 7 insertions(+), 1 deletion(-)
>  create mode 100644 gcc/testsuite/g++.dg/template/redecl5.C
> 
> diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
> index 718dfa5bfa8..0a294e91a79 100644
> --- a/gcc/cp/pt.cc
> +++ b/gcc/cp/pt.cc
> @@ -6377,7 +6377,8 @@ redeclare_class_template (tree type, tree parms, tree 
> cons)
>   {
> auto_diagnostic_group d;
> error ("template parameter %q+#D", tmpl_parm);
> -   inform (DECL_SOURCE_LOCATION (parm), "redeclared here as %q#D", parm);
> +   inform (DECL_P (parm) ? DECL_SOURCE_LOCATION (parm) : input_location,
> +   "redeclared here as %q#D", parm);
> return false;
>   }
>  
> diff --git a/gcc/testsuite/g++.dg/template/redecl5.C 
> b/gcc/testsuite/g++.dg/template/redecl5.C
> new file mode 100644
> index 000..fb2d698e6bc
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/template/redecl5.C
> @@ -0,0 +1,5 @@
> +// PR c++/106311
> +// { dg-do compile }
> +
> +template  struct array; // { dg-error "template parameter" }
> +template  struct array { }; // { dg-error "declared" }
> 
> base-commit: 23dd41c480fa9f06c33c1e6090bbae53869f85af
> -- 
> 2.36.1
> 

Marek



[PATCH 2/2] RTEMS: Use local-exec TLS model by default

2022-07-22 Thread Sebastian Huber
gcc/ChangeLog:

* config/rtems.h (SUBTARGET_CC1_SPEC): Undef and define.
---
 gcc/config/rtems.h | 4 
 1 file changed, 4 insertions(+)

diff --git a/gcc/config/rtems.h b/gcc/config/rtems.h
index 95bcdc41b2f..4742b1f3722 100644
--- a/gcc/config/rtems.h
+++ b/gcc/config/rtems.h
@@ -56,3 +56,7 @@
 /* Prefer int for int32_t (see stdint-newlib.h).  */
 #undef STDINT_LONG32
 #define STDINT_LONG32 (INT_TYPE_SIZE != 32 && LONG_TYPE_SIZE == 32)
+
+/* Default to local-exec TLS model.  */
+#undef SUBTARGET_CC1_SPEC
+#define SUBTARGET_CC1_SPEC " %{!ftls-model=*:-ftls-model=local-exec}"
-- 
2.35.3



[PATCH 1/2] Allow subtarget customization of CC1_SPEC

2022-07-22 Thread Sebastian Huber
gcc/ChangeLog:

* gcc.cc (SUBTARGET_CC1_SPEC): Define if not defined.
(CC1_SPEC): Define to SUBTARGET_CC1_SPEC.
* config/arm/arm.h (CC1_SPEC): Remove.
* config/arc/arc.h (CC1_SPEC): Append SUBTARGET_CC1_SPEC.
* config/cris/cris.h (CC1_SPEC): Likewise.
* config/frv/frv.h (CC1_SPEC): Likewise.
* config/i386/i386.h (CC1_SPEC): Likewise.
* config/ia64/ia64.h (CC1_SPEC): Likewise.
* config/lm32/lm32.h (CC1_SPEC): Likewise.
* config/m32r/m32r.h (CC1_SPEC): Likewise.
* config/mcore/mcore.h (CC1_SPEC): Likewise.
* config/microblaze/microblaze.h: Likewise.
* config/nds32/nds32.h (CC1_SPEC): Likewise.
* config/nios2/nios2.h (CC1_SPEC): Likewise.
* config/pa/pa.h (CC1_SPEC): Likewise.
* config/rs6000/sysv4.h (CC1_SPEC): Likewise.
* config/rx/rx.h (CC1_SPEC): Likewise.
* config/sparc/sparc.h (CC1_SPEC): Likewise.
---
 gcc/config/arc/arc.h   | 3 ++-
 gcc/config/arm/arm.h   | 4 
 gcc/config/cris/cris.h | 3 ++-
 gcc/config/frv/frv.h   | 2 +-
 gcc/config/i386/i386.h | 2 +-
 gcc/config/ia64/ia64.h | 2 +-
 gcc/config/lm32/lm32.h | 2 +-
 gcc/config/m32r/m32r.h | 2 +-
 gcc/config/mcore/mcore.h   | 2 +-
 gcc/config/microblaze/microblaze.h | 3 ++-
 gcc/config/nds32/nds32.h   | 2 +-
 gcc/config/nios2/nios2.h   | 2 +-
 gcc/config/pa/pa.h | 2 +-
 gcc/config/rs6000/sysv4.h  | 3 ++-
 gcc/config/rx/rx.h | 3 ++-
 gcc/config/sparc/sparc.h   | 2 +-
 gcc/gcc.cc | 8 +++-
 17 files changed, 27 insertions(+), 20 deletions(-)

diff --git a/gcc/config/arc/arc.h b/gcc/config/arc/arc.h
index 539a1662084..177287b11aa 100644
--- a/gcc/config/arc/arc.h
+++ b/gcc/config/arc/arc.h
@@ -68,7 +68,8 @@ along with GCC; see the file COPYING3.  If not see
 #define CC1_SPEC "%{EB:%{EL:%emay not use both -EB and -EL}}   \
 %{EB:-mbig-endian} %{EL:-mlittle-endian}   \
 %{G*}  \
-"
+"  \
+SUBTARGET_CC1_SPEC
 extern const char *arc_cpu_to_as (int argc, const char **argv);
 
 #define EXTRA_SPEC_FUNCTIONS   \
diff --git a/gcc/config/arm/arm.h b/gcc/config/arm/arm.h
index f479540812a..24fdf7fde23 100644
--- a/gcc/config/arm/arm.h
+++ b/gcc/config/arm/arm.h
@@ -91,10 +91,6 @@ extern tree arm_bf16_ptr_type_node;
 #undef  CPP_SPEC
 #define CPP_SPEC "%(subtarget_cpp_spec)"
 
-#ifndef CC1_SPEC
-#define CC1_SPEC ""
-#endif
-
 /* This macro defines names of additional specifications to put in the specs
that can be used in various specifications like CC1_SPEC.  Its definition
is an initializer with a subgrouping for each command option.
diff --git a/gcc/config/cris/cris.h b/gcc/config/cris/cris.h
index 6edfe13d92c..ed89b3fa6b0 100644
--- a/gcc/config/cris/cris.h
+++ b/gcc/config/cris/cris.h
@@ -135,7 +135,8 @@ extern int cris_cpu_version;
   %{metrax100:-march=v8}\
   %{march=*:-march=%*}\
   %{mcpu=*:-mcpu=%*}\
-  %(cc1_subtarget)"
+  %(cc1_subtarget)" \
+  SUBTARGET_CC1_SPEC
 
 /* For the cris-*-elf subtarget.  */
 #define CRIS_CC1_SUBTARGET_SPEC \
diff --git a/gcc/config/frv/frv.h b/gcc/config/frv/frv.h
index 8cd67f75b09..b0f39ee238e 100644
--- a/gcc/config/frv/frv.h
+++ b/gcc/config/frv/frv.h
@@ -115,7 +115,7 @@
 
Do not define this macro if it does not need to do anything.  */
 /* For ABI compliance, we need to put bss data into the normal data section.  
*/
-#define CC1_SPEC "%{G*}"
+#define CC1_SPEC "%{G*}" SUBTARGET_CC1_SPEC
 
 #undef LINK_SPEC
 #define LINK_SPEC "\
diff --git a/gcc/config/i386/i386.h b/gcc/config/i386/i386.h
index f16df633e84..f1ceb6b2557 100644
--- a/gcc/config/i386/i386.h
+++ b/gcc/config/i386/i386.h
@@ -614,7 +614,7 @@ extern const char *host_detect_local_cpu (int argc, const 
char **argv);
 #define TARGET_D_HAS_STDCALL_CONVENTION ix86_d_has_stdcall_convention
 
 #ifndef CC1_SPEC
-#define CC1_SPEC "%(cc1_cpu) "
+#define CC1_SPEC "%(cc1_cpu) " SUBTARGET_CC1_SPEC
 #endif
 
 /* This macro defines names of additional specifications to put in the
diff --git a/gcc/config/ia64/ia64.h b/gcc/config/ia64/ia64.h
index bd0ef35e9a4..0e11cef0edc 100644
--- a/gcc/config/ia64/ia64.h
+++ b/gcc/config/ia64/ia64.h
@@ -51,7 +51,7 @@ do {  \
   { "asm_extra", ASM_EXTRA_SPEC }, \
   SUBTARGET_EXTRA_SPECS
 
-#define CC1_SPEC "%(cc1_cpu) "
+#define CC1_SPEC "%(cc1_cpu) " SUBTARGET_CC1_SPEC
 
 #define ASM_EXTRA_SPEC ""
 
diff --git a/gcc/config/lm32/lm32.h b/gcc/config/lm32/lm32.h
index 23f66c90446..65a9141cd94 100644
--- a/gcc/config/lm32/lm32.h
+++ b/gcc/config/lm32/lm32.h
@@ -63,7 +63,7 @@
 #define LIB_SPEC "%{!T*:-T sim.ld}"
 
 #undef  CC1_SPEC
-#define CC1_SPEC "%{G*}"
+#define CC1_SPEC "%{G*}" SUBTARGET_CC1_SPEC
 
 /*---

Re: [PATCH 1/2] Allow subtarget customization of CC1_SPEC

2022-07-22 Thread Jose E. Marchesi via Gcc-patches


Hi Sebastian.

I find "subtarget" confusing in this context.

If it is about rtems.h, linux.h or sol2.h, wouldn't this be better
called OS_CC1_SPEC or similar?  These files specify configurations that
apply to a set of targets, not to a subset of a target...

> gcc/ChangeLog:
>
>   * gcc.cc (SUBTARGET_CC1_SPEC): Define if not defined.
>   (CC1_SPEC): Define to SUBTARGET_CC1_SPEC.
>   * config/arm/arm.h (CC1_SPEC): Remove.
>   * config/arc/arc.h (CC1_SPEC): Append SUBTARGET_CC1_SPEC.
>   * config/cris/cris.h (CC1_SPEC): Likewise.
>   * config/frv/frv.h (CC1_SPEC): Likewise.
>   * config/i386/i386.h (CC1_SPEC): Likewise.
>   * config/ia64/ia64.h (CC1_SPEC): Likewise.
>   * config/lm32/lm32.h (CC1_SPEC): Likewise.
>   * config/m32r/m32r.h (CC1_SPEC): Likewise.
>   * config/mcore/mcore.h (CC1_SPEC): Likewise.
>   * config/microblaze/microblaze.h: Likewise.
>   * config/nds32/nds32.h (CC1_SPEC): Likewise.
>   * config/nios2/nios2.h (CC1_SPEC): Likewise.
>   * config/pa/pa.h (CC1_SPEC): Likewise.
>   * config/rs6000/sysv4.h (CC1_SPEC): Likewise.
>   * config/rx/rx.h (CC1_SPEC): Likewise.
>   * config/sparc/sparc.h (CC1_SPEC): Likewise.
> ---
>  gcc/config/arc/arc.h   | 3 ++-
>  gcc/config/arm/arm.h   | 4 
>  gcc/config/cris/cris.h | 3 ++-
>  gcc/config/frv/frv.h   | 2 +-
>  gcc/config/i386/i386.h | 2 +-
>  gcc/config/ia64/ia64.h | 2 +-
>  gcc/config/lm32/lm32.h | 2 +-
>  gcc/config/m32r/m32r.h | 2 +-
>  gcc/config/mcore/mcore.h   | 2 +-
>  gcc/config/microblaze/microblaze.h | 3 ++-
>  gcc/config/nds32/nds32.h   | 2 +-
>  gcc/config/nios2/nios2.h   | 2 +-
>  gcc/config/pa/pa.h | 2 +-
>  gcc/config/rs6000/sysv4.h  | 3 ++-
>  gcc/config/rx/rx.h | 3 ++-
>  gcc/config/sparc/sparc.h   | 2 +-
>  gcc/gcc.cc | 8 +++-
>  17 files changed, 27 insertions(+), 20 deletions(-)
>
> diff --git a/gcc/config/arc/arc.h b/gcc/config/arc/arc.h
> index 539a1662084..177287b11aa 100644
> --- a/gcc/config/arc/arc.h
> +++ b/gcc/config/arc/arc.h
> @@ -68,7 +68,8 @@ along with GCC; see the file COPYING3.  If not see
>  #define CC1_SPEC "%{EB:%{EL:%emay not use both -EB and -EL}} \
>  %{EB:-mbig-endian} %{EL:-mlittle-endian} \
>  %{G*}\
> -"
> +"\
> +SUBTARGET_CC1_SPEC
>  extern const char *arc_cpu_to_as (int argc, const char **argv);
>  
>  #define EXTRA_SPEC_FUNCTIONS \
> diff --git a/gcc/config/arm/arm.h b/gcc/config/arm/arm.h
> index f479540812a..24fdf7fde23 100644
> --- a/gcc/config/arm/arm.h
> +++ b/gcc/config/arm/arm.h
> @@ -91,10 +91,6 @@ extern tree arm_bf16_ptr_type_node;
>  #undef  CPP_SPEC
>  #define CPP_SPEC "%(subtarget_cpp_spec)"
>  
> -#ifndef CC1_SPEC
> -#define CC1_SPEC ""
> -#endif
> -
>  /* This macro defines names of additional specifications to put in the specs
> that can be used in various specifications like CC1_SPEC.  Its definition
> is an initializer with a subgrouping for each command option.
> diff --git a/gcc/config/cris/cris.h b/gcc/config/cris/cris.h
> index 6edfe13d92c..ed89b3fa6b0 100644
> --- a/gcc/config/cris/cris.h
> +++ b/gcc/config/cris/cris.h
> @@ -135,7 +135,8 @@ extern int cris_cpu_version;
>%{metrax100:-march=v8}\
>%{march=*:-march=%*}\
>%{mcpu=*:-mcpu=%*}\
> -  %(cc1_subtarget)"
> +  %(cc1_subtarget)" \
> +  SUBTARGET_CC1_SPEC
>  
>  /* For the cris-*-elf subtarget.  */
>  #define CRIS_CC1_SUBTARGET_SPEC \
> diff --git a/gcc/config/frv/frv.h b/gcc/config/frv/frv.h
> index 8cd67f75b09..b0f39ee238e 100644
> --- a/gcc/config/frv/frv.h
> +++ b/gcc/config/frv/frv.h
> @@ -115,7 +115,7 @@
>  
> Do not define this macro if it does not need to do anything.  */
>  /* For ABI compliance, we need to put bss data into the normal data section. 
>  */
> -#define CC1_SPEC "%{G*}"
> +#define CC1_SPEC "%{G*}" SUBTARGET_CC1_SPEC
>  
>  #undef   LINK_SPEC
>  #define LINK_SPEC "\
> diff --git a/gcc/config/i386/i386.h b/gcc/config/i386/i386.h
> index f16df633e84..f1ceb6b2557 100644
> --- a/gcc/config/i386/i386.h
> +++ b/gcc/config/i386/i386.h
> @@ -614,7 +614,7 @@ extern const char *host_detect_local_cpu (int argc, const 
> char **argv);
>  #define TARGET_D_HAS_STDCALL_CONVENTION ix86_d_has_stdcall_convention
>  
>  #ifndef CC1_SPEC
> -#define CC1_SPEC "%(cc1_cpu) "
> +#define CC1_SPEC "%(cc1_cpu) " SUBTARGET_CC1_SPEC
>  #endif
>  
>  /* This macro defines names of additional specifications to put in the
> diff --git a/gcc/config/ia64/ia64.h b/gcc/config/ia64/ia64.h
> index bd0ef35e9a4..0e11cef0edc 100644
> --- a/gcc/config/ia64/ia64.h
> +++ b/gcc/config/ia64/ia64.h
> @@ -51,7 +51,7 @@ do {\
>{ "asm_extra", ASM_EXTR

[PATCH] Fix handling of zero capacity regions in -Wanalyzer-allocation-size [PR106394]

2022-07-22 Thread Tim Lange
This patch unifies the handling of zero capacity regions for structs
and other types in the allocation size checker.
Regression-tested on x86_64 Linux.

2022-07-22  Tim Lange  

gcc/analyzer/ChangeLog:

PR analyzer/106394
* region-model.cc (capacity_compatible_with_type): Always return true
if alloc_size is zero.

gcc/testsuite/ChangeLog:

PR analyzer/106394
* gcc.dg/analyzer/pr106394.c: New test.

---
 gcc/analyzer/region-model.cc |  2 +-
 gcc/testsuite/gcc.dg/analyzer/pr106394.c | 19 +++
 2 files changed, 20 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.dg/analyzer/pr106394.c

diff --git a/gcc/analyzer/region-model.cc b/gcc/analyzer/region-model.cc
index 8b7b4e1f697..e01c30407c4 100644
--- a/gcc/analyzer/region-model.cc
+++ b/gcc/analyzer/region-model.cc
@@ -2956,7 +2956,7 @@ capacity_compatible_with_type (tree cst, tree 
pointee_size_tree,
   unsigned HOST_WIDE_INT alloc_size = TREE_INT_CST_LOW (cst);

   if (is_struct)
-return alloc_size >= pointee_size;
+return alloc_size == 0 || alloc_size >= pointee_size;
   return alloc_size % pointee_size == 0;
 }

diff --git a/gcc/testsuite/gcc.dg/analyzer/pr106394.c 
b/gcc/testsuite/gcc.dg/analyzer/pr106394.c
new file mode 100644
index 000..96bb175fc14
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/analyzer/pr106394.c
@@ -0,0 +1,19 @@
+struct msm_gpu {
+  // [...snip...]
+  const struct msm_gpu_perfcntr *perfcntrs;
+  // [...snip...]
+};
+
+struct msm_gpu_perfcntr {
+  // [...snip...]
+  const char *name;
+};
+
+static const struct msm_gpu_perfcntr perfcntrs[] = {};
+
+struct msm_gpu *test(struct msm_gpu *gpu) {
+  // [...snip...]
+  gpu->perfcntrs = perfcntrs;
+  // [...snip...]
+  return gpu;
+}
--
2.36.1


[PATCH 5/12 V4] arm: Implement target feature macros for PACBTI

2022-07-22 Thread Andrea Corallo via Gcc-patches
Andrea Corallo via Gcc-patches  writes:

> Hi Richard,
>
> thanks for reviewing.
>
> Richard Earnshaw  writes:
>
> [...]
>
>> diff --git a/gcc/testsuite/gcc.target/arm/acle/pacbti-m-predef-10.c
>> b/gcc/testsuite/gcc.target/arm/acle/pacbti-m-predef-10.c
>> new file mode 100644
>> index 000..311cf572dd9
>> --- /dev/null
>> +++ b/gcc/testsuite/gcc.target/arm/acle/pacbti-m-predef-10.c
>> @@ -0,0 +1,10 @@
>> +/* { dg-do compile } */
>> +/* { dg-additional-options " -mbranch-protection=bti+pac-ret" } */
>>
>> This is not enough.  For example, if the testsuite is being run with
>> "-march=armv6-m" as the testrun options, we'll get an error that will
>> cause a test failure.  You need to run a pre-test rule that validates
>> that adding -mbranch-protection is safe.
>
> Right, please find attached the updated patch, it should fix this and
> the mentioned spacing issue.

Scratch that, I think the attached is better.

Sorry for the noise.

  Andrea

>From 0238ad4a53b78b8458ed254d0cb226457b6a76de Mon Sep 17 00:00:00 2001
From: Andrea Corallo 
Date: Mon, 6 Dec 2021 11:39:59 +0100
Subject: [PATCH] [PATCH 5/12] arm: Implement target feature macros for PACBTI

This patch implements target feature macros when PACBTI is enabled
through the -march option or -mbranch-protection.  The target feature
macros __ARM_FEATURE_PAC_DEFAULT and __ARM_FEATURE_BTI_DEFAULT are
specified in ARM ACLE

__ARM_FEATURE_PAUTH and __ARM_FEATURE_BTI are specified in the
pull-request .

Approved here
.

gcc/

* config/arm/arm-c.c (arm_cpu_builtins): Define
__ARM_FEATURE_BTI_DEFAULT, __ARM_FEATURE_PAC_DEFAULT,
__ARM_FEATURE_PAUTH and __ARM_FEATURE_BTI.

gcc/testsuite/

* lib/target-supports.exp
(check_effective_target_mbranch_protection_ok): New function.
* gcc.target/arm/acle/pacbti-m-predef-2.c: New test.
* gcc.target/arm/acle/pacbti-m-predef-4.c: Likewise.
* gcc.target/arm/acle/pacbti-m-predef-5.c: Likewise.
* gcc.target/arm/acle/pacbti-m-predef-8.c: Likewise.
* gcc.target/arm/acle/pacbti-m-predef-9.c: Likewise.
* gcc.target/arm/acle/pacbti-m-predef-10.c: Likewise.
* gcc.target/arm/acle/pacbti-m-predef-11.c: Likewise.
* gcc.target/arm/acle/pacbti-m-predef-12.c: Likewise.

Co-Authored-By: Tejas Belagod  
---
 gcc/config/arm/arm-c.cc   | 18 +++
 .../gcc.target/arm/acle/pacbti-m-predef-10.c  | 11 +
 .../gcc.target/arm/acle/pacbti-m-predef-11.c  | 11 +
 .../gcc.target/arm/acle/pacbti-m-predef-12.c  | 11 +
 .../gcc.target/arm/acle/pacbti-m-predef-2.c   | 23 +++
 .../gcc.target/arm/acle/pacbti-m-predef-4.c   | 20 
 .../gcc.target/arm/acle/pacbti-m-predef-5.c   | 23 +++
 .../gcc.target/arm/acle/pacbti-m-predef-8.c   | 12 ++
 .../gcc.target/arm/acle/pacbti-m-predef-9.c   | 11 +
 gcc/testsuite/lib/target-supports.exp | 10 
 10 files changed, 150 insertions(+)
 create mode 100644 gcc/testsuite/gcc.target/arm/acle/pacbti-m-predef-10.c
 create mode 100644 gcc/testsuite/gcc.target/arm/acle/pacbti-m-predef-11.c
 create mode 100644 gcc/testsuite/gcc.target/arm/acle/pacbti-m-predef-12.c
 create mode 100644 gcc/testsuite/gcc.target/arm/acle/pacbti-m-predef-2.c
 create mode 100644 gcc/testsuite/gcc.target/arm/acle/pacbti-m-predef-4.c
 create mode 100644 gcc/testsuite/gcc.target/arm/acle/pacbti-m-predef-5.c
 create mode 100644 gcc/testsuite/gcc.target/arm/acle/pacbti-m-predef-8.c
 create mode 100644 gcc/testsuite/gcc.target/arm/acle/pacbti-m-predef-9.c

diff --git a/gcc/config/arm/arm-c.cc b/gcc/config/arm/arm-c.cc
index a8697b8c62f..190099b2c37 100644
--- a/gcc/config/arm/arm-c.cc
+++ b/gcc/config/arm/arm-c.cc
@@ -212,6 +212,24 @@ arm_cpu_builtins (struct cpp_reader* pfile)
   def_or_undef_macro (pfile, "__ARM_FEATURE_COMPLEX", TARGET_COMPLEX);
   def_or_undef_macro (pfile, "__ARM_32BIT_STATE", TARGET_32BIT);
 
+  def_or_undef_macro (pfile, "__ARM_FEATURE_PAUTH", TARGET_HAVE_PACBTI);
+  def_or_undef_macro (pfile, "__ARM_FEATURE_BTI", TARGET_HAVE_PACBTI);
+  def_or_undef_macro (pfile, "__ARM_FEATURE_BTI_DEFAULT",
+ aarch_enable_bti == 1);
+
+  cpp_undef (pfile, "__ARM_FEATURE_PAC_DEFAULT");
+  if (aarch_ra_sign_scope != AARCH_FUNCTION_NONE)
+  {
+unsigned int pac = 1;
+
+gcc_assert (aarch_ra_sign_key == AARCH_KEY_A);
+
+if (aarch_ra_sign_scope == AARCH_FUNCTION_ALL)
+  pac |= 0x4;
+
+builtin_define_with_int_value ("__ARM_FEATURE_PAC_DEFAULT", pac);
+  }
+
   cpp_undef (pfile, "__ARM_FEATURE_MVE");
   if (TARGET_HAVE_MVE && TARGET_HAVE_MVE_FLOAT)
 {
diff --git a/gcc/testsuite/gcc.target/arm/acle/pacbti-m-predef-10.c 
b/gcc/testsuite/gcc.target/arm/acle/pacbti-m-predef-10.c
new file m

[PATCH 7/12 V2] arm: Emit build attributes for PACBTI target feature

2022-07-22 Thread Andrea Corallo via Gcc-patches
Richard Earnshaw  writes:

> On 28/04/2022 10:45, Andrea Corallo via Gcc-patches wrote:
>> This patch emits assembler directives for PACBTI build attributes as
>> defined by the
>> ABI.
>> 
>> gcc/ChangeLog:
>>  * config/arm/arm.c (arm_file_start): Emit EABI attributes for
>>  Tag_PAC_extension, Tag_BTI_extension, TAG_BTI_use, TAG_PACRET_use.
>
> This bit is OK.
>
>> gcc/testsuite/ChangeLog:
>>  * gcc.target/arm/acle/pacbti-m-predef-1.c: New test.
>>  * gcc.target/arm/acle/pacbti-m-predef-3: Likewise.
>>  * gcc.target/arm/acle/pacbti-m-predef-6.c: Likewise.
>>  * gcc.target/arm/acle/pacbti-m-predef-7.c: Likewise.
>
> These tests contain directives like:
>
> +/* { dg-additional-options " -mbranch-protection=pac-ret+bti
> --save-temps" } */
>
> But they don't check that the architecture permits this (it has to be
> armv8-m.main or later).

Hi Richard,

please find attached the respinned version of the patch.

BR

  Andrea

>From b89ac2dc737593a290345cb96c5d9b048e731bf4 Mon Sep 17 00:00:00 2001
From: Andrea Corallo 
Date: Mon, 6 Dec 2021 11:42:24 +0100
Subject: [PATCH] [PATCH 7/12] arm: Emit build attributes for PACBTI target
 feature

This patch emits assembler directives for PACBTI build attributes as
defined by the
ABI.



gcc/ChangeLog:

* config/arm/arm.c (arm_file_start): Emit EABI attributes for
Tag_PAC_extension, Tag_BTI_extension, TAG_BTI_use, TAG_PACRET_use.

gcc/testsuite/ChangeLog:

* gcc.target/arm/acle/pacbti-m-predef-1.c: New test.
* gcc.target/arm/acle/pacbti-m-predef-3: Likewise.
* gcc.target/arm/acle/pacbti-m-predef-6.c: Likewise.
* gcc.target/arm/acle/pacbti-m-predef-7.c: Likewise.

Co-Authored-By: Tejas Belagod  
---
 gcc/config/arm/arm.cc  | 18 ++
 .../gcc.target/arm/acle/pacbti-m-predef-1.c| 17 +
 .../gcc.target/arm/acle/pacbti-m-predef-3.c| 17 +
 .../gcc.target/arm/acle/pacbti-m-predef-6.c| 16 
 .../gcc.target/arm/acle/pacbti-m-predef-7.c| 17 +
 5 files changed, 85 insertions(+)
 create mode 100644 gcc/testsuite/gcc.target/arm/acle/pacbti-m-predef-1.c
 create mode 100644 gcc/testsuite/gcc.target/arm/acle/pacbti-m-predef-3.c
 create mode 100644 gcc/testsuite/gcc.target/arm/acle/pacbti-m-predef-6.c
 create mode 100644 gcc/testsuite/gcc.target/arm/acle/pacbti-m-predef-7.c

diff --git a/gcc/config/arm/arm.cc b/gcc/config/arm/arm.cc
index 0068817b0f2..ceec14f84b6 100644
--- a/gcc/config/arm/arm.cc
+++ b/gcc/config/arm/arm.cc
@@ -28349,6 +28349,8 @@ static void
 arm_file_start (void)
 {
   int val;
+  bool pac = (aarch_ra_sign_scope != AARCH_FUNCTION_NONE);
+  bool bti = (aarch_enable_bti == 1);
 
   arm_print_asm_arch_directives
 (asm_out_file, TREE_TARGET_OPTION (target_option_default_node));
@@ -28419,6 +28421,22 @@ arm_file_start (void)
arm_emit_eabi_attribute ("Tag_ABI_FP_16bit_format", 38,
 (int) arm_fp16_format);
 
+  if (TARGET_HAVE_PACBTI)
+   {
+ arm_emit_eabi_attribute ("Tag_PAC_extension", 50, 2);
+ arm_emit_eabi_attribute ("Tag_BTI_extension", 52, 2);
+   }
+  else if (pac || bti)
+   {
+ arm_emit_eabi_attribute ("Tag_PAC_extension", 50, 1);
+ arm_emit_eabi_attribute ("Tag_BTI_extension", 52, 1);
+   }
+
+  if (bti)
+arm_emit_eabi_attribute ("TAG_BTI_use", 74, 1);
+  if (pac)
+   arm_emit_eabi_attribute ("TAG_PACRET_use", 76, 1);
+
   if (arm_lang_output_object_attributes_hook)
arm_lang_output_object_attributes_hook();
 }
diff --git a/gcc/testsuite/gcc.target/arm/acle/pacbti-m-predef-1.c 
b/gcc/testsuite/gcc.target/arm/acle/pacbti-m-predef-1.c
new file mode 100644
index 000..225b44de80a
--- /dev/null
+++ b/gcc/testsuite/gcc.target/arm/acle/pacbti-m-predef-1.c
@@ -0,0 +1,17 @@
+/* { dg-do compile } */
+/* { dg-require-effective-target mbranch_protection_ok } */
+/* { dg-additional-options "-march=armv8.1-m.main 
-mbranch-protection=pac-ret+bti --save-temps" } */
+
+#if !defined (__ARM_FEATURE_BTI_DEFAULT)
+#error "Feature test macro __ARM_FEATURE_BTI_DEFAULT should be defined."
+#endif
+
+#if !defined (__ARM_FEATURE_PAC_DEFAULT)
+#error "Feature test macro __ARM_FEATURE_PAC_DEFAULT should be defined."
+#endif
+
+/* { dg-final { scan-assembler-not "\.arch_extension pacbti" } } */
+/* { dg-final { scan-assembler "\.eabi_attribute 50, 1" } } */
+/* { dg-final { scan-assembler "\.eabi_attribute 52, 1" } } */
+/* { dg-final { scan-assembler "\.eabi_attribute 74, 1" } } */
+/* { dg-final { scan-assembler "\.eabi_attribute 76, 1" } } */
diff --git a/gcc/testsuite/gcc.target/arm/acle/pacbti-m-predef-3.c 
b/gcc/testsuite/gcc.target/arm/acle/pacbti-m-predef-3.c
new file mode 100644
index 000..1eae39edf

Re: [PATCH] Fix handling of zero capacity regions in -Wanalyzer-allocation-size [PR106394]

2022-07-22 Thread David Malcolm via Gcc-patches
On Fri, 2022-07-22 at 16:27 +0200, Tim Lange wrote:
> This patch unifies the handling of zero capacity regions for structs
> and other types in the allocation size checker.
> Regression-tested on x86_64 Linux.

Thanks; looks good for trunk.

Dave




Re: [r13-1786 Regression] FAIL: gcc.dg/analyzer/stdarg-3.c (test for excess errors) on Linux/x86_64

2022-07-22 Thread David Malcolm via Gcc-patches
On Thu, 2022-07-21 at 18:35 -0700, skpan...@sc.intel.com wrote:
> On Linux/x86_64,
> 
> b852aa7f265424c8e2036899da5d8306ff06a16c is the first bad commit
> commit b852aa7f265424c8e2036899da5d8306ff06a16c
> Author: David Malcolm 
> Date:   Thu Jul 21 17:29:26 2022 -0400
> 
>     analyzer: fix -Wanalyzer-va-list-exhausted false +ve on va_arg in
> subroutine [PR106383]
> 
> caused
> 
> FAIL: gcc.dg/analyzer/stdarg-3.c (test for excess errors)

Thanks; I somehow managed to miss the FAIL when reviewing the test
results; sorry everyone; it points to a real issue in -fanalyzer for
va_arg in loops.

I've filed this as PR analyzer/106413 ("State explosion on va_arg when
va_start is in top-level function of analysis").

Dave



Re: [PATCH 9/12 V2] arm: Make libgcc bti compatible

2022-07-22 Thread Andrea Corallo via Gcc-patches
Richard Earnshaw  writes:

> On 21/07/2022 10:17, Andrea Corallo via Gcc-patches wrote:
>> Richard Earnshaw  writes:
>> 
>>> On 28/04/2022 10:48, Andrea Corallo via Gcc-patches wrote:
 This change add bti instructions at the beginning of arm specific
 libgcc hand written assembly routines.
 2022-03-31  Andrea Corallo  
* libgcc/config/arm/crti.S (FUNC_START): Add bti instruction
 if
necessary.
* libgcc/config/arm/lib1funcs.S (THUMB_FUNC_START, FUNC_START):
Likewise.

>>>
>>> +#if defined(__ARM_FEATURE_BTI)
>>>
>>> Wouldn't it be better to use __ARM_FEATURE_BTI_DEFAULT?  That way we
>>> only get BTI instructions in multilib variants that have asked for
>>> BTI.
>>>
>>> R.
>> Hi Richard,
>> good point, yes I think so.
>> Please find attached the updated patch.
>> BR
>>Andrea
>> 
>
> I've been pondering this patch.  The way it is implemented would put a
> BTI instruction at the start of every assembler routine in libgcc.
> But the vast majority of functions in libgcc cannot have their address
> taken, so a BTI isn't needed (BTI is only needed when an indirect jump
> could be used).  So I wonder if we really need to do this so
> aggressively?
>
> Perhaps a better approach would be to define a macro (eg MAYBEBTI)
> which expands a BTI if the compilation requires it and nothing
> otherwise), and then manually insert that in any functions that really
> need this (if any).

I guess the main downside of this approach would be the maintanace
burden, we'll have to remember forever that every time an asm function
is called by function pointer we have to add the bti landing pad
manually, otherwise this will be broken when pacbti enabled. WDYT?

If we want to go this way I'll start reworking the patch in this
direction (tho this might not be trivial).

BR

  Andrea


[PATCH] libstdc++: Fix backward compatibility of P2325R3 backport [PR106320]

2022-07-22 Thread Patrick Palka via Gcc-patches
The 11 and 10 partial backports of P2325R3, r11-9555-g92d6121eec and
r10-10808-g22b86cdc4d7fdd, unnecessarily preserved some changes from the
paper that made certain views no longer default constructible, changes
which aren't required to reap the overall benefits of the paper and
which conflicted with the goal to maximize backwards compatibility with
pre-P2325R3 code.

This patch reverts the problematic changes, specifically it relaxes
the constraints on various views' default constructors so that they
reflect only the requirements that were already implicitly imposed by
the NSDMIs of the view.  Thus for example this patch retains the
default_initializable<_Vp> constraint on transform_view's default
constructor since its '_Vp _M_base = _Vp()' NSDMI already reflects this
constraint, and it removes the default_initializable<_Fp> constraint
since the corresponding member '__detail::__box<_Fp> _M_fun' doesn't
require default initializability (specializations of __box are always
default constructible).

After reverting these changes, all static_asserts from p2325.cc that
verify lack of default constructibility now fail as expected, matching
the pre-P2325R3 behavior.

Tested on x86_64-pc-linux-gnu, does this look OK for the 11 and 10
branches?

PR libstdc++/106320

libstdc++-v3/ChangeLog:

* include/std/ranges (single_view): Remove
* testsuite/std/ranges/adaptors/join.cc (test13): New test.
* testsuite/std/ranges/p2325.cc: Fix S to be only non default
constructible and not also non copy constructible.  XFAIL the
tests that verify a non default constructible functor makes a
view non default constructible (lines 94, 97 and 98).  XFAIL
the test that effectively verifies a non default constructible
element type makes single_view non default constructible (line
114).
---
 libstdc++-v3/include/std/ranges| 18 +-
 .../testsuite/std/ranges/adaptors/join.cc  | 15 +++
 libstdc++-v3/testsuite/std/ranges/p2325.cc | 12 
 3 files changed, 28 insertions(+), 17 deletions(-)

diff --git a/libstdc++-v3/include/std/ranges b/libstdc++-v3/include/std/ranges
index bbdfb7dbe5c..0a67c45f1b8 100644
--- a/libstdc++-v3/include/std/ranges
+++ b/libstdc++-v3/include/std/ranges
@@ -200,7 +200,7 @@ namespace ranges
 class single_view : public view_interface>
 {
 public:
-  single_view() requires default_initializable<_Tp> = default;
+  single_view() = default;
 
   constexpr explicit
   single_view(const _Tp& __t)
@@ -1463,9 +1463,7 @@ namespace views::__adaptor
   _Vp _M_base = _Vp();
 
 public:
-  filter_view() requires (default_initializable<_Vp>
- && default_initializable<_Pred>)
-   = default;
+  filter_view() requires default_initializable<_Vp> = default;
 
   constexpr
   filter_view(_Vp __base, _Pred __pred)
@@ -1829,9 +1827,7 @@ namespace views::__adaptor
   _Vp _M_base = _Vp();
 
 public:
-  transform_view() requires (default_initializable<_Vp>
-&& default_initializable<_Fp>)
-   = default;
+  transform_view() requires default_initializable<_Vp> = default;
 
   constexpr
   transform_view(_Vp __base, _Fp __fun)
@@ -2150,9 +2146,7 @@ namespace views::__adaptor
   _Vp _M_base = _Vp();
 
 public:
-  take_while_view() requires (default_initializable<_Vp>
- && default_initializable<_Pred>)
-   = default;
+  take_while_view() requires default_initializable<_Vp> = default;
 
   constexpr
   take_while_view(_Vp base, _Pred __pred)
@@ -2356,9 +2350,7 @@ namespace views::__adaptor
   _Vp _M_base = _Vp();
 
 public:
-  drop_while_view() requires (default_initializable<_Vp>
- && default_initializable<_Pred>)
-   = default;
+  drop_while_view() requires default_initializable<_Vp> = default;
 
   constexpr
   drop_while_view(_Vp __base, _Pred __pred)
diff --git a/libstdc++-v3/testsuite/std/ranges/adaptors/join.cc 
b/libstdc++-v3/testsuite/std/ranges/adaptors/join.cc
index d774e8d9385..14e254bc734 100644
--- a/libstdc++-v3/testsuite/std/ranges/adaptors/join.cc
+++ b/libstdc++-v3/testsuite/std/ranges/adaptors/join.cc
@@ -193,6 +193,20 @@ test11()
 ;
 }
 
+void
+test13()
+{
+  // PR libstdc++/106320
+  auto l = std::views::transform([](auto x) {
+return x | std::views::transform([x=0](auto y) {
+  return y;
+});
+  });
+  static_assert(!std::default_initializable);
+  std::vector> v{{5, 6, 7}};
+  v | l | std::views::join;
+}
+
 int
 main()
 {
@@ -207,4 +221,5 @@ main()
   test09();
   test10();
   test11();
+  test13();
 }
diff --git a/libstdc++-v3/testsuite/std/ranges/p2325.cc 
b/libstdc++-v3/testsuite/std/ranges/p2325.cc
index 205b3458928..99f1b0f08f1 100644
--- a/libstdc++-v3/testsuite/std/ranges/p2325.cc
+++ b/libstdc++-v3/te

[PATCH] Adding three new function attributes for static analysis of file descriptors

2022-07-22 Thread Immad Mir via Gcc-patches
This patch adds three new function attributes to GCC that
are used for static analysis of usage of file descriptors:

1) __attribute__ ((fd_arg(N))): The attributes may be applied to a function that
takes an open file descriptor at refrenced argument N.

It indicates that the passed filedescriptor must not have been closed.
Therefore, when the analyzer is enabled with -fanalyzer, the
analyzer may emit a -Wanalyzer-fd-use-after-close diagnostic
if it detects a code path in which a function with this attribute is
called with a closed file descriptor.

The attribute also indicates that the file descriptor must have been checked for
validity before usage. Therefore, analyzer may emit
-Wanalyzer-fd-use-without-check diagnostic if it detects a code path in
which a function with this attribute is called with a file descriptor that has
not been checked for validity.

2) __attribute__((fd_arg_read(N))): The attribute is identical to
fd_arg, but with the additional requirement that it might read from
the file descriptor, and thus, the file descriptor must not have been opened
as write-only.

The analyzer may emit a -Wanalyzer-access-mode-mismatch
diagnostic if it detects a code path in which a function with this
attribute is called on a file descriptor opened with O_WRONLY.

3) __attribute__((fd_arg_write(N))): The attribute is identical to fd_arg_read
except that the analyzer may emit a -Wanalyzer-access-mode-mismatch diagnostic 
if
it detects a code path in which a function with this attribute is called on a
file descriptor opened with O_RDONLY.

gcc/analyzer/ChangeLog:
* sm-fd.cc (fd_param_diagnostic): New diagnostic class.
(fd_access_mode_mismatch): Change inheritance from fd_diagnostic
to fd_param_diagnostic. Add new overloaded constructor.
(fd_use_after_close): Likewise.
(unchecked_use_of_fd): Likewise and also change name to 
fd_use_without_check.
(double_close): Change name to fd_double_close.
(enum access_directions): New.
(fd_state_machine::on_stmt): Handle calls to function with the
new three function attributes.
(fd_state_machine::check_for_fd_attrs): New.
(fd_state_machine::on_open): Use the new overloaded constructors
of diagnostic classes.

gcc/c-family/ChangeLog:
* c-attribs.cc: (c_common_attribute_table): add three new attributes
namely: fd_arg, fd_arg_read and fd_arg_write.
(handle_fd_arg_attribute): New.

gcc/ChangeLog:
* doc/extend.texi: Add fd_arg, fd_arg_read and fd_arg_write under
"Common Function Attributes" section.
* doc/invoke.texi: Add docs to -Wanalyzer-fd-access-mode-mismatch,
-Wanalyzer-use-after-close, -Wanalyzer-fd-use-without-check that these
warnings may be emitted through usage of three function attributes used
for static analysis of file descriptors namely fd_arg, fd_arg_read and
fd_arg_write.

gcc/testsuite/ChangeLog:
* gcc.dg/analyzer/fd-5.c: New test.
* gcc.dg/analyzer/fd-4.c: Remove quotes around 'read-only' and
'write-only'.
* c-c++-common/attr-fd.c: New test.

Signed-off-by: Immad Mir 
---
 gcc/analyzer/sm-fd.cc| 338 +--
 gcc/c-family/c-attribs.cc|  31 +++
 gcc/doc/extend.texi  |  37 +++
 gcc/doc/invoke.texi  |  18 +-
 gcc/testsuite/c-c++-common/attr-fd.c |  18 ++
 gcc/testsuite/gcc.dg/analyzer/fd-4.c |   8 +-
 gcc/testsuite/gcc.dg/analyzer/fd-5.c |  53 +
 7 files changed, 429 insertions(+), 74 deletions(-)
 create mode 100644 gcc/testsuite/c-c++-common/attr-fd.c
 create mode 100644 gcc/testsuite/gcc.dg/analyzer/fd-5.c

diff --git a/gcc/analyzer/sm-fd.cc b/gcc/analyzer/sm-fd.cc
index 8e4300b06e2..c3dac48509e 100644
--- a/gcc/analyzer/sm-fd.cc
+++ b/gcc/analyzer/sm-fd.cc
@@ -39,10 +39,13 @@ along with GCC; see the file COPYING3.  If not see
 #include "analyzer/analyzer-selftests.h"
 #include "tristate.h"
 #include "selftest.h"
+#include "stringpool.h"
+#include "attribs.h"
 #include "analyzer/call-string.h"
 #include "analyzer/program-point.h"
 #include "analyzer/store.h"
 #include "analyzer/region-model.h"
+#include "bitmap.h"
 
 #if ENABLE_ANALYZER
 
@@ -59,6 +62,13 @@ enum access_mode
   WRITE_ONLY
 };
 
+enum access_directions
+{
+  DIRS_READ_WRITE,
+  DIRS_READ,
+  DIRS_WRITE
+};
+
 class fd_state_machine : public state_machine
 {
 public:
@@ -146,7 +156,7 @@ private:
   void check_for_open_fd (sm_context *sm_ctxt, const supernode *node,
   const gimple *stmt, const gcall *call,
   const tree callee_fndecl,
-  enum access_direction access_fn) const;
+  enum access_directions access_fn) const;
 
   void make_valid_transitions_on_condition (sm_context *sm_ctxt,
 const supernode *node,
@@ -156,6 +166,10 @@ private:
  

Re: [PATCH] libstdc++: Fix backward compatibility of P2325R3 backport [PR106320]

2022-07-22 Thread Patrick Palka via Gcc-patches
On Fri, Jul 22, 2022 at 11:52 AM Patrick Palka  wrote:
>
> The 11 and 10 partial backports of P2325R3, r11-9555-g92d6121eec and
> r10-10808-g22b86cdc4d7fdd, unnecessarily preserved some changes from the
> paper that made certain views no longer default constructible, changes
> which aren't required to reap the overall benefits of the paper and
> which conflicted with the goal to maximize backwards compatibility with
> pre-P2325R3 code.
>
> This patch reverts the problematic changes, specifically it relaxes
> the constraints on various views' default constructors so that they
> reflect only the requirements that were already implicitly imposed by
> the NSDMIs of the view.  Thus for example this patch retains the
> default_initializable<_Vp> constraint on transform_view's default
> constructor since its '_Vp _M_base = _Vp()' NSDMI already reflects this
> constraint, and it removes the default_initializable<_Fp> constraint
> since the corresponding member '__detail::__box<_Fp> _M_fun' doesn't
> require default initializability (specializations of __box are always
> default constructible).
>
> After reverting these changes, all static_asserts from p2325.cc that
> verify lack of default constructibility now fail as expected, matching
> the pre-P2325R3 behavior.
>
> Tested on x86_64-pc-linux-gnu, does this look OK for the 11 and 10
> branches?
>
> PR libstdc++/106320
>
> libstdc++-v3/ChangeLog:
>
> * include/std/ranges (single_view): Remove

Whoops I forgot to finish the changelog entry, will fix.

> * testsuite/std/ranges/adaptors/join.cc (test13): New test.
> * testsuite/std/ranges/p2325.cc: Fix S to be only non default
> constructible and not also non copy constructible.  XFAIL the
> tests that verify a non default constructible functor makes a
> view non default constructible (lines 94, 97 and 98).  XFAIL
> the test that effectively verifies a non default constructible
> element type makes single_view non default constructible (line
> 114).
> ---
>  libstdc++-v3/include/std/ranges| 18 +-
>  .../testsuite/std/ranges/adaptors/join.cc  | 15 +++
>  libstdc++-v3/testsuite/std/ranges/p2325.cc | 12 
>  3 files changed, 28 insertions(+), 17 deletions(-)
>
> diff --git a/libstdc++-v3/include/std/ranges b/libstdc++-v3/include/std/ranges
> index bbdfb7dbe5c..0a67c45f1b8 100644
> --- a/libstdc++-v3/include/std/ranges
> +++ b/libstdc++-v3/include/std/ranges
> @@ -200,7 +200,7 @@ namespace ranges
>  class single_view : public view_interface>
>  {
>  public:
> -  single_view() requires default_initializable<_Tp> = default;
> +  single_view() = default;
>
>constexpr explicit
>single_view(const _Tp& __t)
> @@ -1463,9 +1463,7 @@ namespace views::__adaptor
>_Vp _M_base = _Vp();
>
>  public:
> -  filter_view() requires (default_initializable<_Vp>
> - && default_initializable<_Pred>)
> -   = default;
> +  filter_view() requires default_initializable<_Vp> = default;
>
>constexpr
>filter_view(_Vp __base, _Pred __pred)
> @@ -1829,9 +1827,7 @@ namespace views::__adaptor
>_Vp _M_base = _Vp();
>
>  public:
> -  transform_view() requires (default_initializable<_Vp>
> -&& default_initializable<_Fp>)
> -   = default;
> +  transform_view() requires default_initializable<_Vp> = default;
>
>constexpr
>transform_view(_Vp __base, _Fp __fun)
> @@ -2150,9 +2146,7 @@ namespace views::__adaptor
>_Vp _M_base = _Vp();
>
>  public:
> -  take_while_view() requires (default_initializable<_Vp>
> - && default_initializable<_Pred>)
> -   = default;
> +  take_while_view() requires default_initializable<_Vp> = default;
>
>constexpr
>take_while_view(_Vp base, _Pred __pred)
> @@ -2356,9 +2350,7 @@ namespace views::__adaptor
>_Vp _M_base = _Vp();
>
>  public:
> -  drop_while_view() requires (default_initializable<_Vp>
> - && default_initializable<_Pred>)
> -   = default;
> +  drop_while_view() requires default_initializable<_Vp> = default;
>
>constexpr
>drop_while_view(_Vp __base, _Pred __pred)
> diff --git a/libstdc++-v3/testsuite/std/ranges/adaptors/join.cc 
> b/libstdc++-v3/testsuite/std/ranges/adaptors/join.cc
> index d774e8d9385..14e254bc734 100644
> --- a/libstdc++-v3/testsuite/std/ranges/adaptors/join.cc
> +++ b/libstdc++-v3/testsuite/std/ranges/adaptors/join.cc
> @@ -193,6 +193,20 @@ test11()
>  ;
>  }
>
> +void
> +test13()
> +{
> +  // PR libstdc++/106320
> +  auto l = std::views::transform([](auto x) {
> +return x | std::views::transform([x=0](auto y) {
> +  return y;
> +});
> +  });
> +  static_assert(!std::default_initializable);
> +  std::vector> v{{5, 6, 7}};
> +  v | l 

Re: [PATCH] libstdc++: Fix backward compatibility of P2325R3 backport [PR106320]

2022-07-22 Thread Jonathan Wakely via Gcc-patches
On Fri, 22 Jul 2022 at 16:52, Patrick Palka via Libstdc++
 wrote:
>
> The 11 and 10 partial backports of P2325R3, r11-9555-g92d6121eec and
> r10-10808-g22b86cdc4d7fdd, unnecessarily preserved some changes from the
> paper that made certain views no longer default constructible, changes
> which aren't required to reap the overall benefits of the paper and
> which conflicted with the goal to maximize backwards compatibility with
> pre-P2325R3 code.
>
> This patch reverts the problematic changes, specifically it relaxes
> the constraints on various views' default constructors so that they
> reflect only the requirements that were already implicitly imposed by
> the NSDMIs of the view.  Thus for example this patch retains the
> default_initializable<_Vp> constraint on transform_view's default
> constructor since its '_Vp _M_base = _Vp()' NSDMI already reflects this
> constraint, and it removes the default_initializable<_Fp> constraint
> since the corresponding member '__detail::__box<_Fp> _M_fun' doesn't
> require default initializability (specializations of __box are always
> default constructible).
>
> After reverting these changes, all static_asserts from p2325.cc that
> verify lack of default constructibility now fail as expected, matching
> the pre-P2325R3 behavior.
>
> Tested on x86_64-pc-linux-gnu, does this look OK for the 11 and 10
> branches?

OK for gcc-10 and gcc-11 (with the completed ChangeLog), thanks.



Re: [PATCH] rs6000/test: Update some cases with -mdejagnu-tune

2022-07-22 Thread Segher Boessenkool
On Fri, Jul 22, 2022 at 10:22:51AM +0800, Kewen.Lin wrote:
> on 2022/7/22 02:48, Segher Boessenkool wrote:
> > On Wed, Jul 20, 2022 at 05:31:11PM +0800, Kewen.Lin wrote:
> >> As PR106345 shows, some test cases should be updated with
> >> -mdejagnu-tune, since their test points are sensitive to
> >> rs6000_tune, such as: group_ending_nop, loop align (ic),
> >> float conversion cost etc.
> > 
> > It does not make sense to require -mdejagnu-tune= if -mdejagnu-cpu= is
> > already given?  What is the failure case?
> > 
> 
> I think cpu setting only sets tune setting when tune setting isn't
> explicitly provided as:
> 
>   if (rs6000_tune_index >= 0)
> tune_index = rs6000_tune_index;
>   else if (cpu_index >= 0)
> rs6000_tune_index = tune_index = cpu_index;
> 
> As PR106345 shows, GCC can use an explicit tune setting when it's
> configured, even if there is one "-mdejagnu-cpu=", it doesn't
> override the explicit given one, so we need one explicit
> "-mdejagnu-tune=".

And that is the problem.  GCC's automatic setting is *not* an explicit
option, not given by the user.  --with-tune= should not result in adding
an -mtune= option in the resulting compiler, it should not set command-
line options.

> Although the test case has adopted option "-mdejagnu-cpu=power7", but
> the configured "--with-tune-64=power9" takes effect and make it
> return align_loops instead of align_flags (5).

And it should not do that.

> >> This patch is to replace -mdejagnu-cpu with -mdejagnu-tune
> >> or append -mdejagnu-tune (keep the original -mdejagnu-cpu
> >> when it's required) accordingly.
> > 
> > It is *always* required.  Testcases with -mtune= but unspecified -mcpu=
> > make no sense.
> 
> The loop_align.c testings made me think if we know the insn count for
> the loop on all cpus is in range (4,8] then the cpu setting doesn't matter.

Sure, it probably works without -mcpu=, but it does not make sense :-)

Only using -mtune= while not having -mcpu= serves no purpose in any
"normal" use, so we shouldn't do that in the testsuite either.

> > This should only make a difference if you have -mtune= in your
> > RUNTEST_FLAGS, and you shouldn't do silly things like that.  I suspect
> > you see it in other cases, and those are actual bugs then, that need
> > actual fixing instead of sweeping under the carper.
> 
> Unfortunately it's due to the explicit tune setting in configuration.

So that needs some actual fixes.  Something in how --with-tune= works
is suboptimal?

> > The testcase suggests this is with a compiler configured with
> > --with-cpu= --with-tune=, which should just work, and -mcpu= should
> > override both of those!
> 
> Unfortunately -mcpu= (-mdejagnu-cpu=) doesn't actually override here.

... or that.


Segher


Re: [PATCH] Adding three new function attributes for static analysis of file descriptors

2022-07-22 Thread David Malcolm via Gcc-patches
On Fri, 2022-07-22 at 21:25 +0530, Immad Mir wrote:
> This patch adds three new function attributes to GCC that
> are used for static analysis of usage of file descriptors:
> 
> 1) __attribute__ ((fd_arg(N))): The attributes may be applied to a
> function that
> takes an open file descriptor at refrenced argument N.
> 
> It indicates that the passed filedescriptor must not have been
> closed.
> Therefore, when the analyzer is enabled with -fanalyzer, the
> analyzer may emit a -Wanalyzer-fd-use-after-close diagnostic
> if it detects a code path in which a function with this attribute is
> called with a closed file descriptor.
> 
> The attribute also indicates that the file descriptor must have been
> checked for
> validity before usage. Therefore, analyzer may emit
> -Wanalyzer-fd-use-without-check diagnostic if it detects a code path
> in
> which a function with this attribute is called with a file descriptor
> that has
> not been checked for validity.
> 
> 2) __attribute__((fd_arg_read(N))): The attribute is identical to
> fd_arg, but with the additional requirement that it might read from
> the file descriptor, and thus, the file descriptor must not have been
> opened
> as write-only.
> 
> The analyzer may emit a -Wanalyzer-access-mode-mismatch
> diagnostic if it detects a code path in which a function with this
> attribute is called on a file descriptor opened with O_WRONLY.
> 
> 3) __attribute__((fd_arg_write(N))): The attribute is identical to
> fd_arg_read
> except that the analyzer may emit a -Wanalyzer-access-mode-mismatch
> diagnostic if
> it detects a code path in which a function with this attribute is
> called on a
> file descriptor opened with O_RDONLY.

[...snip...]

Thanks for the updated patch.

This version looks good for trunk.  You indicated (in an off-list
email) that you've tested this, so please go ahead and push this.


Thanks
Dave






Re: [PATCH] rs6000/test: Update some cases with -mdejagnu-tune

2022-07-22 Thread Peter Bergner via Gcc-patches
On 7/22/22 1:17 PM, Segher Boessenkool wrote:
> On Fri, Jul 22, 2022 at 10:22:51AM +0800, Kewen.Lin wrote:
>> on 2022/7/22 02:48, Segher Boessenkool wrote:
>> As PR106345 shows, GCC can use an explicit tune setting when it's
>> configured, even if there is one "-mdejagnu-cpu=", it doesn't
>> override the explicit given one, so we need one explicit
>> "-mdejagnu-tune=".
> 
> And that is the problem.  GCC's automatic setting is *not* an explicit
> option, not given by the user.  --with-tune= should not result in adding
> an -mtune= option in the resulting compiler, it should not set command-
> line options.
>
[snip]
> And it should not do that.

Currently, our rs6000.h has this:

/* Only for use in the testsuite: -mdejagnu-cpu= simply overrides -mcpu=.
   With older versions of Dejagnu the command line arguments you set in
   RUNTESTFLAGS override those set in the testcases; with this option,
   the testcase will always win.  Ditto for -mdejagnu-tune=.  */
#define DRIVER_SELF_SPECS \
  "%{mdejagnu-cpu=*: %

Re: [PATCH] libgo: make match.sh POSIX-shell compatible

2022-07-22 Thread Ian Lance Taylor via Gcc-patches
On Tue, Jul 19, 2022 at 11:35 PM  wrote:
>
> From: Sören Tempel 
>
> The `(( expression ))` syntax is a Bash extension and not supported by
> POSIX shell [1]. However, the arithmetic expressions used by the
> gobuild() function can also be expressed using arithmetic POSIX
> expansions with `$(( expression ))` [2].
>
> Contrary to the Bash extension, arithmetic expansion doesn't set
> the return value if the expression is non-zero but instead just prints
> the expression result. Hence, the expression also needs to be negated.
> Without this patch, match.sh does currently not work correctly if
> /bin/sh is not a symlink to Bash.
>
> [1]: https://www.gnu.org/software/bash/manual/bash.html#Conditional-Constructs
> [2]: 
> https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_04

Thanks.  Committed as follows, which also fixes the similar function
in the gotest script.

Ian
dbf607d2e92cbae9a7f7620b69b9272adbce6381
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index 5ea0406cd8e..2f2fafde1f1 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-ff68b1a147eb60082fd60c198db0ef5477ade938
+a62f20ae78ddd41be682dde8cab075ca4f5dbb2a
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
diff --git a/libgo/match.sh b/libgo/match.sh
index 7ed587ff794..e5ed98de422 100755
--- a/libgo/match.sh
+++ b/libgo/match.sh
@@ -111,7 +111,7 @@ gobuild() {
 if test "$goarch" != "386"; then
line=$(echo "$line" | sed -e "s/\\(${wrap}\\)386\\(${wrap}\\)/\10\2/g")
 fi
-(($line))
+return $((!($line)))
 }
 
 matched=
diff --git a/libgo/testsuite/gotest b/libgo/testsuite/gotest
index 04e4267fbba..0a0a7e14d74 100755
--- a/libgo/testsuite/gotest
+++ b/libgo/testsuite/gotest
@@ -302,7 +302,7 @@ gobuild() {
 if test "$goarch" != "386"; then
line=$(echo "$line" | sed -e "s/\\(${wrap}\\)386\\(${wrap}\\)/\10\2/g")
 fi
-(($line))
+return $((!($line)))
 }
 
 case "x$gofiles" in


Re: [PATCH] rs6000/test: Update some cases with -mdejagnu-tune

2022-07-22 Thread Peter Bergner via Gcc-patches
On 7/22/22 1:53 PM, Peter Bergner wrote:
> So I think the way the code above *should* work is:
>   1) Any -mdejagnu-cpu= usage should filter out all -mcpu= and -mtune= 
> options.
>   2) Any -mdejagnu-tune= usage should filter all -mtune= options.
>  It should not filter out any -mcpu= options.

Like this:

diff --git a/gcc/config/rs6000/rs6000.h b/gcc/config/rs6000/rs6000.h
index 3b8941a8658..26874943795 100644
--- a/gcc/config/rs6000/rs6000.h
+++ b/gcc/config/rs6000/rs6000.h
@@ -86,7 +86,7 @@
RUNTESTFLAGS override those set in the testcases; with this option,
the testcase will always win.  Ditto for -mdejagnu-tune=.  */
 #define DRIVER_SELF_SPECS \
-  "%{mdejagnu-cpu=*: %

Re: [PATCH] xtensa: Optimize "bitwise AND NOT with imm" followed by "branch if (not) equal to zero"

2022-07-22 Thread Max Filippov via Gcc-patches
On Fri, Jul 22, 2022 at 4:18 AM Takayuki 'January June' Suwa
 wrote:
>
> The RTL combiner will transform "if ((x & C) == C) goto label;"
> into "if ((~x & C) == 0) goto label;" and will try to match it with
> the insn patterns.

...

> gcc/ChangeLog:
>
> * config/xtensa/xtensa.md (*masktrue_const_bitcmpl):
> Add a new insn_and_split pattern, and a few split patterns for
> spacial cases.
> ---
>  gcc/config/xtensa/xtensa.md | 84 +
>  1 file changed, 84 insertions(+)

Regtested for target=xtensa-linux-uclibc, no new regressions.
Committed to master.

-- 
Thanks.
-- Max


Re: [PATCH] tree-optimization/106379 - add missing ~(a ^ b) folding for _Bool

2022-07-22 Thread H.J. Lu via Gcc-patches
On Thu, Jul 21, 2022 at 4:24 AM Richard Biener via Gcc-patches
 wrote:
>
> The following makes sure to fold ~(a ^ b) to a == b for truth
> values (but not vectors, we'd have to check for vector support of
> equality).  That turns the PR106379 testcase into a ranger one.
>
> Note that while we arrive at ~(a ^ b) in a convoluted way from
> original !a == !b one can eventually write the expression this
> way directly as well.
>
> Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed.
>
> PR tree-optimization/106379
> * match.pd (~(a ^ b) -> a == b): New pattern.
>
> * gcc.dg/pr106379-1.c: New testcase.
> ---
>  gcc/match.pd  | 6 ++
>  gcc/testsuite/gcc.dg/pr106379-1.c | 9 +
>  2 files changed, 15 insertions(+)
>  create mode 100644 gcc/testsuite/gcc.dg/pr106379-1.c
>
> diff --git a/gcc/match.pd b/gcc/match.pd
> index 8bbc0dbd5cd..88a1a5aa9cc 100644
> --- a/gcc/match.pd
> +++ b/gcc/match.pd
> @@ -1938,6 +1938,12 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
>   (if (tree_nop_conversion_p (type, TREE_TYPE (@0)))
>(bit_not (bit_xor (view_convert @0) @1
>
> +/* ~(a ^ b) is a == b for truth valued a and b.  */
> +(simplify
> + (bit_not (bit_xor:s truth_valued_p@0 truth_valued_p@1))
> + (if (!VECTOR_TYPE_P (type))
> +  (convert (eq @0 @1

For integers, isn't it wrong to convert ~(boolean exp) to boolean exp?


>  /* (x & ~m) | (y & m) -> ((x ^ y) & m) ^ x */
>  (simplify
>   (bit_ior:c (bit_and:cs @0 (bit_not @2)) (bit_and:cs @1 @2))
> diff --git a/gcc/testsuite/gcc.dg/pr106379-1.c 
> b/gcc/testsuite/gcc.dg/pr106379-1.c
> new file mode 100644
> index 000..7f2575e02dc
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/pr106379-1.c
> @@ -0,0 +1,9 @@
> +/* { dg-do compile } */
> +/* { dg-options "-O -fdump-tree-forwprop1" } */
> +
> +_Bool foo (_Bool a, _Bool b)
> +{
> +  return !a == !b;
> +}
> +
> +/* { dg-final { scan-tree-dump "\[ab\]_\[0-9\]+\\(D\\) == 
> \[ba\]_\[0-9\]+\\(D\\)" "forwprop1" } } */
> --
> 2.35.3



--
H.J.


Re: [PATCH] c++: ICE with erroneous template redeclaration [PR106311]

2022-07-22 Thread Jason Merrill via Gcc-patches

On 7/15/22 11:29, Marek Polacek wrote:

Here we ICE trying to get DECL_SOURCE_LOCATION of the parm that happens
to be error_mark_node in this ill-formed test.  I kept running into this
while reducing code, so it'd be good to have it fixed.

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

PR c++/106311

gcc/cp/ChangeLog:

* pt.cc (redeclare_class_template): Check DECL_P before accessing
DECL_SOURCE_LOCATION.

gcc/testsuite/ChangeLog:

* g++.dg/template/redecl5.C: New test.
---
  gcc/cp/pt.cc| 3 ++-
  gcc/testsuite/g++.dg/template/redecl5.C | 5 +
  2 files changed, 7 insertions(+), 1 deletion(-)
  create mode 100644 gcc/testsuite/g++.dg/template/redecl5.C

diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index 718dfa5bfa8..0a294e91a79 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -6377,7 +6377,8 @@ redeclare_class_template (tree type, tree parms, tree 
cons)
{
  auto_diagnostic_group d;
  error ("template parameter %q+#D", tmpl_parm);
- inform (DECL_SOURCE_LOCATION (parm), "redeclared here as %q#D", parm);
+ inform (DECL_P (parm) ? DECL_SOURCE_LOCATION (parm) : input_location,
+ "redeclared here as %q#D", parm);


If we're checking DECL_P, probably we also should avoid passing it to 
%q#D if it's false?



  return false;
}
  
diff --git a/gcc/testsuite/g++.dg/template/redecl5.C b/gcc/testsuite/g++.dg/template/redecl5.C

new file mode 100644
index 000..fb2d698e6bc
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/redecl5.C
@@ -0,0 +1,5 @@
+// PR c++/106311
+// { dg-do compile }
+
+template  struct array; // { dg-error "template parameter" }
+template  struct array { }; // { dg-error "declared" }

base-commit: 23dd41c480fa9f06c33c1e6090bbae53869f85af




Re: [PATCH] c++: Refer to internal linkage for -Wsubobject-linkage [PR86491]

2022-07-22 Thread Jason Merrill via Gcc-patches

On 6/30/22 12:53, Jonathan Wakely via Gcc-patches wrote:

Tested powerpc64le-linux, OK for trunk?

-- >8 --

Since C++11 relaxed the requirement for template arguments to have
external linkage, it's possible to get -Wsubobject-linkage warnings
without using any anonymous namespaces. This confuses users when they
get diagnostics that refer to an anonymous namespace that doesn't exist
in their code.

This changes the diagnostic to say "has internal linkage" for C++11 and
later, which is accurate whether internal linkage is due to the 'static'
specifier, or due to the use of anonymous namespaces.

For C++98 template arguments declared with 'static' are ill-formed
anyway, so the only way this warning can arise is via anonymous
namespaces. That means the existing wording is accurate for C++98 and so
we can keep it.


I'd prefer to keep the existing wording for types that are actually in 
an anonymous namespace.  Checking decl_anon_ns_mem_p seems like the way 
to do that, though it would probably need to remove the existing type 
shortcut and instead just do decl = TYPE_MAIN_DECL (decl).



PR c++/86491

gcc/cp/ChangeLog:

* decl2.cc (constrain_class_visibility): Adjust wording of
-Wsubobject-linkage to account for cases where anonymous
namespaces aren't used.

gcc/testsuite/ChangeLog:

* g++.dg/warn/Wsubobject-linkage-3.C: Adjust for new warning.
* g++.dg/warn/anonymous-namespace-1.C: Use separate dg-warning
directives for C++98 and everything else.
* g++.dg/warn/anonymous-namespace-2.C: Likewise.
* g++.dg/warn/anonymous-namespace-3.C: Likewise.
---
  gcc/cp/decl2.cc   | 12 ++--
  gcc/testsuite/g++.dg/warn/Wsubobject-linkage-3.C  |  4 ++--
  gcc/testsuite/g++.dg/warn/anonymous-namespace-1.C |  8 ++--
  gcc/testsuite/g++.dg/warn/anonymous-namespace-2.C |  9 ++---
  gcc/testsuite/g++.dg/warn/anonymous-namespace-3.C |  3 ++-
  5 files changed, 26 insertions(+), 10 deletions(-)

diff --git a/gcc/cp/decl2.cc b/gcc/cp/decl2.cc
index 3737e5f010c..de53678715e 100644
--- a/gcc/cp/decl2.cc
+++ b/gcc/cp/decl2.cc
@@ -3027,7 +3027,11 @@ constrain_class_visibility (tree type)
  %qT has a field %qD whose type depends on the type %qT which has no linkage",
   type, t, nlt);
  }
-   else
+   else if (cxx_dialect > cxx98)
+ warning (OPT_Wsubobject_linkage, "\
+%qT has a field %qD whose type has internal linkage",
+  type, t);
+   else // In C++98 this can only happen with unnamed namespaces.
  warning (OPT_Wsubobject_linkage, "\
  %qT has a field %qD whose type uses the anonymous namespace",
   type, t);
@@ -3062,7 +3066,11 @@ constrain_class_visibility (tree type)
  %qT has a base %qT whose type depends on the type %qT which has no linkage",
 type, TREE_TYPE (t), nlt);
}
- else
+ else if (cxx_dialect > cxx98)
+   warning (OPT_Wsubobject_linkage, "\
+%qT has a base %qT whose type has internal linkage",
+type, TREE_TYPE (t));
+ else // In C++98 this can only happen with unnamed namespaces.
warning (OPT_Wsubobject_linkage, "\
  %qT has a base %qT whose type uses the anonymous namespace",
 type, TREE_TYPE (t));
diff --git a/gcc/testsuite/g++.dg/warn/Wsubobject-linkage-3.C 
b/gcc/testsuite/g++.dg/warn/Wsubobject-linkage-3.C
index 95a04501441..b116fbbb186 100644
--- a/gcc/testsuite/g++.dg/warn/Wsubobject-linkage-3.C
+++ b/gcc/testsuite/g++.dg/warn/Wsubobject-linkage-3.C
@@ -3,7 +3,7 @@
  namespace { struct Foo { }; }
  
  #line 6 "foo.C"

-struct Bar { Foo foo; };   // { dg-warning "anonymous namespace" }
+struct Bar { Foo foo; };   // { dg-warning "anonymous namespace|internal 
linkage" }
  // { dg-bogus "no linkage" "" { target *-*-* } .-1 }
-struct Bar2 : Foo { }; // { dg-warning "anonymous namespace" }
+struct Bar2 : Foo { }; // { dg-warning "anonymous namespace|internal 
linkage" }
  // { dg-bogus "no linkage" "" { target *-*-* } .-1 }
diff --git a/gcc/testsuite/g++.dg/warn/anonymous-namespace-1.C 
b/gcc/testsuite/g++.dg/warn/anonymous-namespace-1.C
index cf193e0cba5..eed3818c5cf 100644
--- a/gcc/testsuite/g++.dg/warn/anonymous-namespace-1.C
+++ b/gcc/testsuite/g++.dg/warn/anonymous-namespace-1.C
@@ -14,5 +14,9 @@ class foobar1
  };
  
  #line 17 "foo.C"

-class foobar : public bad { }; // { dg-warning "uses the anonymous namespace" }
-class foobar2 { bad b; }; // { dg-warning "uses the anonymous namespace" }
+class foobar : public bad { };
+// { dg-warning "has internal linkage" "" { target c++11 } .-1 }
+// { dg-warning "uses the anonymous namespace" "" { target c++98_only } .-2 }
+class foobar2 { bad b; };
+// { dg-warning "has internal linkage" "" { target c++11 } .-1 }
+// { dg-warning "

Re: [PATCH] c++: CTAD from initializer list [PR106366]

2022-07-22 Thread Jason Merrill via Gcc-patches

On 7/21/22 08:43, Patrick Palka wrote:

During CTAD, we currently perform the first phase of overload resolution
from [over.match.list] only if the class template has a list constructor.
But according to [over.match.class.deduct]/4 it should be enough to just
have a guide that looks like a list constructor (which is a more general
criterion in light of user-defined guides).

Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for
trunk?


OK.


PR c++/106366

gcc/cp/ChangeLog:

* pt.cc (do_class_deduction): Don't consider TYPE_HAS_LIST_CTOR
when setting try_list_ctor.  Reset args even when try_list_ctor
is true and there are no list candidates.  Call resolve_args on
the reset args.

gcc/testsuite/ChangeLog:

* g++.dg/cpp1z/class-deduction112.C: New test.
---
  gcc/cp/pt.cc  | 25 +--
  .../g++.dg/cpp1z/class-deduction112.C | 14 +++
  2 files changed, 26 insertions(+), 13 deletions(-)
  create mode 100644 gcc/testsuite/g++.dg/cpp1z/class-deduction112.C

diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index 718dfa5bfa8..0f26d6f5bce 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -30250,8 +30250,8 @@ do_class_deduction (tree ptype, tree tmpl, tree init,
else if (BRACE_ENCLOSED_INITIALIZER_P (init))
  {
list_init_p = true;
-  try_list_ctor = TYPE_HAS_LIST_CTOR (type);
-  if (try_list_ctor && CONSTRUCTOR_NELTS (init) == 1
+  try_list_ctor = true;
+  if (CONSTRUCTOR_NELTS (init) == 1
  && !CONSTRUCTOR_IS_DESIGNATED_INIT (init))
{
  /* As an exception, the first phase in 16.3.1.7 (considering the
@@ -30310,26 +30310,25 @@ do_class_deduction (tree ptype, tree tmpl, tree init,
  
tree fndecl = error_mark_node;
  
-  /* If this is list-initialization and the class has a list constructor, first

+  /* If this is list-initialization and the class has a list guide, first
   try deducing from the list as a single argument, as [over.match.list].  
*/
-  tree list_cands = NULL_TREE;
-  if (try_list_ctor && cands)
-for (lkp_iterator iter (cands); iter; ++iter)
-  {
-   tree dg = *iter;
+  if (try_list_ctor)
+{
+  tree list_cands = NULL_TREE;
+  for (tree dg : lkp_range (cands))
if (is_list_ctor (dg))
  list_cands = lookup_add (dg, list_cands);
-  }
-  if (list_cands)
-{
-  fndecl = perform_dguide_overload_resolution (list_cands, args, tf_none);
-
+  if (list_cands)
+   fndecl = perform_dguide_overload_resolution (list_cands, args, tf_none);
if (fndecl == error_mark_node)
{
  /* That didn't work, now try treating the list as a sequence of
 arguments.  */
  release_tree_vector (args);
  args = make_tree_vector_from_ctor (init);
+ args = resolve_args (args, complain);
+ if (args == NULL)
+   return error_mark_node;
}
  }
  
diff --git a/gcc/testsuite/g++.dg/cpp1z/class-deduction112.C b/gcc/testsuite/g++.dg/cpp1z/class-deduction112.C

new file mode 100644
index 000..8da5868ff98
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1z/class-deduction112.C
@@ -0,0 +1,14 @@
+// PR c++/106366
+// { dg-do compile { target c++17 } }
+
+#include 
+
+template
+struct A { A(...); };
+
+template
+A(std::initializer_list) -> A;
+
+A a{1,2,3};
+using type = decltype(a);
+using type = A;




[committed] analyzer: fix ICE in binding_cluster ctor [PR106401]

2022-07-22 Thread David Malcolm via Gcc-patches
Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu.
Pushed to trunk as r13-1806-g0fb35a45a28c67.

gcc/analyzer/ChangeLog:
PR analyzer/106401
* store.cc (binding_cluster::binding_cluster): Remove overzealous
assertion; we're checking for tracked_p in
store::get_or_create_cluster.

gcc/testsuite/ChangeLog:
PR analyzer/106401
* gcc.dg/analyzer/memcpy-2.c: New test.

Signed-off-by: David Malcolm 
---
 gcc/analyzer/store.cc| 1 -
 gcc/testsuite/gcc.dg/analyzer/memcpy-2.c | 8 
 2 files changed, 8 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.dg/analyzer/memcpy-2.c

diff --git a/gcc/analyzer/store.cc b/gcc/analyzer/store.cc
index e3dabf300df..0b3fb370d1e 100644
--- a/gcc/analyzer/store.cc
+++ b/gcc/analyzer/store.cc
@@ -1107,7 +1107,6 @@ binding_cluster::binding_cluster (const region 
*base_region)
 : m_base_region (base_region), m_map (),
   m_escaped (false), m_touched (false)
 {
-  gcc_assert (base_region->tracked_p ());
 }
 
 /* binding_cluster's copy ctor.  */
diff --git a/gcc/testsuite/gcc.dg/analyzer/memcpy-2.c 
b/gcc/testsuite/gcc.dg/analyzer/memcpy-2.c
new file mode 100644
index 000..88ec84cb640
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/analyzer/memcpy-2.c
@@ -0,0 +1,8 @@
+/* { dg-additional-options "-Wno-stringop-overflow" } */
+
+void
+main (int c, void *v)
+{
+  static char a[] = "";
+  __builtin_memcpy (v, a, -1);
+}
-- 
2.26.3



[committed] analyzer: fix state explosion on va_arg [PR106413]

2022-07-22 Thread David Malcolm via Gcc-patches
Fix state explosion on va_arg when the call to va_start is in the
top-level function of the analysis.

Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu.
Pushed to trunk as r13-1807-g6d5194a10dc103.

gcc/analyzer/ChangeLog:
PR analyzer/106413
* varargs.cc (region_model::impl_call_va_start): Avoid iterating
through non-existant variadic arguments by initializing the
impl_region to "UNKNOWN" if the va_start occurs in the top-level
function to the analysis.

gcc/testsuite/ChangeLog:
PR analyzer/106413
* gcc.dg/analyzer/torture/stdarg-4.c: New test.

Signed-off-by: David Malcolm 
---
 gcc/analyzer/varargs.cc   |  26 +-
 .../gcc.dg/analyzer/torture/stdarg-4.c| 329 ++
 2 files changed, 350 insertions(+), 5 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/analyzer/torture/stdarg-4.c

diff --git a/gcc/analyzer/varargs.cc b/gcc/analyzer/varargs.cc
index c45585ce457..9400086b10e 100644
--- a/gcc/analyzer/varargs.cc
+++ b/gcc/analyzer/varargs.cc
@@ -667,11 +667,27 @@ region_model::impl_call_va_start (const call_details &cd)
   const svalue *ptr_to_impl_reg = m_mgr->get_ptr_svalue (NULL_TREE, impl_reg);
   set_value (out_reg, ptr_to_impl_reg, cd.get_ctxt ());
 
-  /* "*(&IMPL_REGION) = VA_LIST_VAL (0);".  */
-  const region *init_var_arg_reg
-= m_mgr->get_var_arg_region (get_current_frame (), 0);
-  const svalue *ap_sval = m_mgr->get_ptr_svalue (NULL_TREE, init_var_arg_reg);
-  set_value (impl_reg, ap_sval, cd.get_ctxt ());
+  if (get_stack_depth () > 1)
+{
+  /* The interprocedural case: the frame containing the va_start call
+will have been populated with any variadic aruguments.
+Initialize IMPL_REGION with a ptr to var_arg_region 0.  */
+  const region *init_var_arg_reg
+   = m_mgr->get_var_arg_region (get_current_frame (), 0);
+  const svalue *ap_sval
+   = m_mgr->get_ptr_svalue (NULL_TREE, init_var_arg_reg);
+  set_value (impl_reg, ap_sval, cd.get_ctxt ());
+}
+  else
+{
+  /* The frame containing va_start is an entry-point to the analysis,
+so there won't be any specific var_arg_regions populated within it.
+Initialize IMPL_REGION as the UNKNOWN_SVALUE to avoid state
+explosions on repeated calls to va_arg.  */
+  const svalue *unknown_sval
+   = m_mgr->get_or_create_unknown_svalue (NULL_TREE);
+  set_value (impl_reg, unknown_sval, cd.get_ctxt ());
+}
 }
 
 /* Handle the on_call_pre part of "__builtin_va_copy".  */
diff --git a/gcc/testsuite/gcc.dg/analyzer/torture/stdarg-4.c 
b/gcc/testsuite/gcc.dg/analyzer/torture/stdarg-4.c
new file mode 100644
index 000..8275b0fa9ba
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/analyzer/torture/stdarg-4.c
@@ -0,0 +1,329 @@
+/* { dg-skip-if "" { *-*-* } { "-fno-fat-lto-objects" } { "" } } */
+
+#include "../analyzer-decls.h"
+
+/* va_arg in loop, with no caller to function containing va_start.  */
+
+int test_1a (const char *fmt, ...)
+{
+  __builtin_va_list args;
+  int sum = 0;
+  char ch;
+
+  __builtin_va_start(args, fmt);
+
+  while (ch = *fmt++)
+if (ch == '%')
+  sum += __builtin_va_arg(args, int);
+
+  __builtin_va_end(args);
+
+  return sum;
+}
+
+/* va_arg in loop, with no caller to function containing va_start.  */
+
+static int test_1b_callee (const char *fmt, __builtin_va_list args)
+{
+  int sum = 0;
+  char ch;
+
+  while (ch = *fmt++)
+if (ch == '%')
+  sum += __builtin_va_arg(args, int);
+
+  return sum;
+}
+
+int test_1b_caller (const char *fmt, ...)
+{
+  __builtin_va_list args;
+  int sum = 0;
+
+  __builtin_va_start(args, fmt);
+
+  sum = test_1b_callee (fmt, args);
+
+  __builtin_va_end(args);
+
+  return sum;
+}
+
+/* va_arg in loop, with a caller to the function containing va_start,
+   with specific args.  */
+
+static int
+test_1c_inner (const char *fmt, __builtin_va_list args)
+{
+  int sum = 0;
+  char ch;
+
+  while (ch = *fmt++)
+if (ch == '%')
+  sum += __builtin_va_arg(args, int);
+
+  return sum;
+}
+
+static int
+test_1c_middle (const char *fmt, ...)
+{
+  __builtin_va_list args;
+  int sum = 0;
+
+  __builtin_va_start(args, fmt);
+
+  sum = test_1c_inner (fmt, args);
+
+  __builtin_va_end(args);
+
+  return sum;
+}
+
+void test_1c_outer (void)
+{
+  int sum = test_1c_middle ("%%", 42, 17);
+
+  __analyzer_describe (0, sum); /* { dg-message "'\\(int\\)59'" } */
+}
+
+/* va_arg in loop, with no caller to function containing va_start.  */
+
+int test_2a (int count, ...)
+{
+  __builtin_va_list args;
+  int sum = 0;
+  char ch;
+
+  __builtin_va_start(args, count);
+
+  while (count-- > 0)
+sum += __builtin_va_arg(args, int);
+
+  __builtin_va_end(args);
+
+  return sum;
+}
+
+/* va_arg in loop, with no caller to function containing va_start.  */
+
+static int test_2b_callee (int count, __builtin_va_list args)
+{
+  int sum = 0;
+
+  while (count-- > 0)
+sum += __builtin_va_arg(args, int);
+
+  re

Re: [PATCH] tree-optimization/106379 - add missing ~(a ^ b) folding for _Bool

2022-07-22 Thread Richard Biener via Gcc-patches



> Am 22.07.2022 um 22:17 schrieb H.J. Lu via Gcc-patches 
> :
> 
> On Thu, Jul 21, 2022 at 4:24 AM Richard Biener via Gcc-patches
>  wrote:
>> 
>> The following makes sure to fold ~(a ^ b) to a == b for truth
>> values (but not vectors, we'd have to check for vector support of
>> equality).  That turns the PR106379 testcase into a ranger one.
>> 
>> Note that while we arrive at ~(a ^ b) in a convoluted way from
>> original !a == !b one can eventually write the expression this
>> way directly as well.
>> 
>> Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed.
>> 
>>PR tree-optimization/106379
>>* match.pd (~(a ^ b) -> a == b): New pattern.
>> 
>>* gcc.dg/pr106379-1.c: New testcase.
>> ---
>> gcc/match.pd  | 6 ++
>> gcc/testsuite/gcc.dg/pr106379-1.c | 9 +
>> 2 files changed, 15 insertions(+)
>> create mode 100644 gcc/testsuite/gcc.dg/pr106379-1.c
>> 
>> diff --git a/gcc/match.pd b/gcc/match.pd
>> index 8bbc0dbd5cd..88a1a5aa9cc 100644
>> --- a/gcc/match.pd
>> +++ b/gcc/match.pd
>> @@ -1938,6 +1938,12 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
>>  (if (tree_nop_conversion_p (type, TREE_TYPE (@0)))
>>   (bit_not (bit_xor (view_convert @0) @1
>> 
>> +/* ~(a ^ b) is a == b for truth valued a and b.  */
>> +(simplify
>> + (bit_not (bit_xor:s truth_valued_p@0 truth_valued_p@1))
>> + (if (!VECTOR_TYPE_P (type))
>> +  (convert (eq @0 @1
> 
> For integers, isn't it wrong to convert ~(boolean exp) to boolean exp?

That’s what the (convert. …) should compensate for?

Richard 

> 
>> /* (x & ~m) | (y & m) -> ((x ^ y) & m) ^ x */
>> (simplify
>>  (bit_ior:c (bit_and:cs @0 (bit_not @2)) (bit_and:cs @1 @2))
>> diff --git a/gcc/testsuite/gcc.dg/pr106379-1.c 
>> b/gcc/testsuite/gcc.dg/pr106379-1.c
>> new file mode 100644
>> index 000..7f2575e02dc
>> --- /dev/null
>> +++ b/gcc/testsuite/gcc.dg/pr106379-1.c
>> @@ -0,0 +1,9 @@
>> +/* { dg-do compile } */
>> +/* { dg-options "-O -fdump-tree-forwprop1" } */
>> +
>> +_Bool foo (_Bool a, _Bool b)
>> +{
>> +  return !a == !b;
>> +}
>> +
>> +/* { dg-final { scan-tree-dump "\[ab\]_\[0-9\]+\\(D\\) == 
>> \[ba\]_\[0-9\]+\\(D\\)" "forwprop1" } } */
>> --
>> 2.35.3
> 
> 
> 
> --
> H.J.