RE: [PATCH v2] arm: Various MVE vec_duplicate fixes [PR99647]

2021-04-08 Thread Kyrylo Tkachov via Gcc-patches


> -Original Message-
> From: Alex Coplan 
> Sent: 07 April 2021 14:15
> To: gcc-patches@gcc.gnu.org
> Cc: ni...@redhat.com; Richard Earnshaw ;
> Ramana Radhakrishnan ; Kyrylo
> Tkachov ; Richard Sandiford
> 
> Subject: [PATCH v2] arm: Various MVE vec_duplicate fixes [PR99647]
> 
> Hi,
> 
> Here is a v2 of my previous attempt:
> https://gcc.gnu.org/pipermail/gcc-patches/2021-April/567724.html
> to fix this PR.
> 
> ---
> 
> This patch fixes various issues with vec_duplicate in the MVE patterns.
> Currently there are two patterns named *mve_mov. The second of
> these is really a vector duplicate rather than a move, so I've renamed
> it accordingly.
> 
> As it stands, there are several issues with this pattern:
> 1. The MVE_types iterator has an entry for TImode, but
>vec_duplicate:TI is invalid.
> 2. The mode of the operand to vec_duplicate is SImode, but it should
>vary according to the vector mode iterator.
> 3. The second alternative of this pattern is bogus: it allows matching
>symbol_refs (the cause of the PR) and const_ints (which means that it
>matches (vec_duplicate (const_int ...)) which is non-canonical: such
>rtxes should be const_vectors instead and handled by the main vector
>move pattern).
> 
> This patch fixes all of these issues, and removes the redundant
> *mve_vec_duplicate pattern.
> 
> Testing:
>  * Bootstrapped and regtested on arm-linux-gnueabihf, no regressions.
>  * Tested an arm-eabi cross configured with --with-float=hard
>--with-arch=armv8.1-m.main+mve, no regressions.
> 
> OK for trunk and eventual backport to GCC 10?

Ok.
Thanks,
Kyrill

> 
> Thanks,
> Alex
> 
> gcc/ChangeLog:
> 
>   PR target/99647
>   * config/arm/iterators.md (MVE_vecs): New.
>   (V_elem): Also handle V2DF.
>   * config/arm/mve.md (*mve_mov): Rename to ...
>   (*mve_vdup): ... this. Remove second alternative since
>   vec_duplicate of const_int is not canonical RTL, and we don't
>   want to match symbol_refs. Fix up modes.
>   (*mve_vec_duplicate): Delete (pattern is redundant).
> 
> gcc/testsuite/ChangeLog:
> 
>   PR target/99647
>   * gcc.c-torture/compile/pr99647.c: New test.


Re: [RFC] ldist: Recognize rawmemchr loop patterns

2021-04-08 Thread Stefan Schulze Frielinghaus via Gcc-patches
ping

On Tue, Mar 16, 2021 at 06:13:21PM +0100, Stefan Schulze Frielinghaus wrote:
> [snip]
> 
> Please find attached a new version of the patch.  A major change compared to
> the previous patch is that I created a separate pass which hopefully makes
> reviewing also easier since it is almost self-contained.  After realizing that
> detecting loops which mimic the behavior of rawmemchr/strlen functions does 
> not
> really fit into the topic of loop distribution, I created a separate pass.  
> Due
> to this I was also able to play around a bit and schedule the pass at 
> different
> times.  Currently it is scheduled right before loop distribution where loop
> header copying already took place which leads to the following effect.  
> Running
> this setup over
> 
> char *t (char *p)
> {
>   for (; *p; ++p);
>   return p;
> }
> 
> the new pass transforms
> 
> char * t (char * p)
> {
>   char _1;
>   char _7;
> 
>[local count: 118111600]:
>   _7 = *p_3(D);
>   if (_7 != 0)
> goto ; [89.00%]
>   else
> goto ; [11.00%]
> 
>[local count: 105119324]:
> 
>[local count: 955630225]:
>   # p_8 = PHI 
>   p_6 = p_8 + 1;
>   _1 = *p_6;
>   if (_1 != 0)
> goto ; [89.00%]
>   else
> goto ; [11.00%]
> 
>[local count: 105119324]:
>   # p_2 = PHI 
>   goto ; [100.00%]
> 
>[local count: 850510901]:
>   goto ; [100.00%]
> 
>[local count: 12992276]:
> 
>[local count: 118111600]:
>   # p_9 = PHI 
>   return p_9;
> 
> }
> 
> into
> 
> char * t (char * p)
> {
>   char * _5;
>   char _7;
> 
>[local count: 118111600]:
>   _7 = *p_3(D);
>   if (_7 != 0)
> goto ; [89.00%]
>   else
> goto ; [11.00%]
> 
>[local count: 105119324]:
>   _5 = p_3(D) + 1;
>   p_10 = .RAWMEMCHR (_5, 0);
> 
>[local count: 118111600]:
>   # p_9 = PHI 
>   return p_9;
> 
> }
> 
> which is fine so far.  However, I haven't made up my mind so far whether it is
> worthwhile to spend more time in order to also eliminate the "first unrolling"
> of the loop.  I gave it a shot by scheduling the pass prior pass copy header
> and ended up with:
> 
> char * t (char * p)
> {
>[local count: 118111600]:
>   p_5 = .RAWMEMCHR (p_3(D), 0);
>   return p_5;
> 
> }
> 
> which seems optimal to me.  The downside of this is that I have to initialize
> scalar evolution analysis which might be undesired that early.
> 
> All this brings me to the question where do you see this peace of code 
> running?
> If in a separate pass when would you schedule it?  If in an existing pass,
> which one would you choose?
> 
> Another topic which came up is whether there exists a more elegant solution to
> my current implementation in order to deal with stores (I'm speaking of the 
> `if
> (store_dr)` statement inside of function transform_loop_1).  For example,
> 
> extern char *p;
> char *t ()
> {
>   for (; *p; ++p);
>   return p;
> }
> 
> ends up as
> 
> char * t ()
> {
>   char * _1;
>   char * _2;
>   char _3;
>   char * p.1_8;
>   char _9;
>   char * p.1_10;
>   char * p.1_11;
> 
>[local count: 118111600]:
>   p.1_8 = p;
>   _9 = *p.1_8;
>   if (_9 != 0)
> goto ; [89.00%]
>   else
> goto ; [11.00%]
> 
>[local count: 105119324]:
> 
>[local count: 955630225]:
>   # p.1_10 = PHI <_1(6), p.1_8(5)>
>   _1 = p.1_10 + 1;
>   p = _1;
>   _3 = *_1;
>   if (_3 != 0)
> goto ; [89.00%]
>   else
> goto ; [11.00%]
> 
>[local count: 105119324]:
>   # _2 = PHI <_1(3)>
>   goto ; [100.00%]
> 
>[local count: 850510901]:
>   goto ; [100.00%]
> 
>[local count: 12992276]:
> 
>[local count: 118111600]:
>   # p.1_11 = PHI <_2(8), p.1_8(7)>
>   return p.1_11;
> 
> }
> 
> where inside the loop a load and store occurs.  For a rawmemchr like loop I
> have to show that we never load from a memory location to which we write.
> Currently I solve this by hard coding those facts which are not generic at 
> all.
> I gave compute_data_dependences_for_loop a try which failed to determine the
> fact that stores only happen to p[0] and loads from p[i] where i>0.  Maybe
> there are more generic solutions to express this in contrast to my current 
> one?
> 
> Thanks again for your input so far.  Really appreciated.
> 
> Cheers,
> Stefan

> diff --git a/gcc/Makefile.in b/gcc/Makefile.in
> index 8a5fb3fd99c..7b2d7405277 100644
> --- a/gcc/Makefile.in
> +++ b/gcc/Makefile.in
> @@ -1608,6 +1608,7 @@ OBJS = \
>   tree-into-ssa.o \
>   tree-iterator.o \
>   tree-loop-distribution.o \
> + tree-loop-pattern.o \
>   tree-nested.o \
>   tree-nrv.o \
>   tree-object-size.o \
> diff --git a/gcc/internal-fn.c b/gcc/internal-fn.c
> index dd7173126fb..957e96a46a4 100644
> --- a/gcc/internal-fn.c
> +++ b/gcc/internal-fn.c
> @@ -2917,6 +2917,33 @@ expand_VEC_CONVERT (internal_fn, gcall *)
>gcc_unreachable ();
>  }
>  
> +void
> +expand_RAWMEMCHR (internal_fn, gcall *stmt)
> +{
> +  expand_operand ops[3];
> +
> +  tree lhs = gimple_call_lhs (stmt);
> +  if (!lhs)
> +return;
> +  tree lhs_type = TREE_TYPE (l

[PATCH] ipa-sra: Release dead LHS SSA_NAME when removing it (PR 99951)

2021-04-08 Thread Martin Jambor
Hi,

When IPA-SRA removes an SSA_NAME from a LHS of a call statement
because it is not necessary, it does not release it.  This patch fixes
that.

Bootstrapped and tested on x86_64, at some point I'll LTO-bootstrap it
too.  I assume this is GCC 12 material, so OK once stage 1 opens?

Thanks,

Martin


gcc/ChangeLog:

2021-04-08  Martin Jambor  

PR ipa/99951
* ipa-param-manipulation.c (ipa_param_adjustments::modify_call):
If removing a call statement LHS SSA name, release it.
---
 gcc/ipa-param-manipulation.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/gcc/ipa-param-manipulation.c b/gcc/ipa-param-manipulation.c
index 132bb24f76a..1d1e64f546a 100644
--- a/gcc/ipa-param-manipulation.c
+++ b/gcc/ipa-param-manipulation.c
@@ -856,6 +856,7 @@ ipa_param_adjustments::modify_call (gcall *stmt,
 
   gcall *new_stmt = gimple_build_call_vec (callee_decl, vargs);
 
+  tree ssa_to_remove = NULL;
   if (tree lhs = gimple_call_lhs (stmt))
 {
   if (!m_skip_return)
@@ -880,6 +881,7 @@ ipa_param_adjustments::modify_call (gcall *stmt,
}
  update_stmt (using_stmt);
}
+ ssa_to_remove = lhs;
}
 }
 
@@ -898,6 +900,8 @@ ipa_param_adjustments::modify_call (gcall *stmt,
   fprintf (dump_file, "\n");
 }
   gsi_replace (&gsi, new_stmt, true);
+  if (ssa_to_remove)
+release_ssa_name (ssa_to_remove);
   if (update_references)
 do
   {
-- 
2.30.2



[PATCH] combine: Fix up expand_compound_operation [PR99905]

2021-04-08 Thread Jakub Jelinek via Gcc-patches
Hi!

The following testcase is miscompiled on x86_64-linux. 
expand_compound_operation is called on
(zero_extract:DI (mem/c:TI (reg/f:DI 16 argp) [3 i+0 S16 A128])
(const_int 16 [0x10])
(const_int 63 [0x3f]))
so mode is DImode, inner_mode is TImode, pos 63, len 16 and modewidth 64.

A couple of lines above the problematic spot we have:
  if (modewidth >= pos + len)
{
  tem = gen_lowpart (mode, XEXP (x, 0));
where the code uses gen_lowpart and then shift left/right to extract it
in mode.  But the guarding condition is false - 64 >= 63 + 16
and so we enter the next condition, where the code shifts XEXP (x, 0)
right by pos and then adds AND.  It does so incorrectly though.
Given the modewidth < pos + len, inner_mode must be necessarily larger
than mode and XEXP (x, 0) has the innermode, but it was calling
simplify_shift_const with mode rather than inner_mode, which meant
inconsistent arguments to simplify_shift_const and in this case made
a DImode MEM shift out of it.

The following patch fixes it, by doing the shift in inner_mode properly
and then after the shift doing the lowpart subreg and masking already
in mode.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2021-04-08  Jakub Jelinek  

PR rtl-optimization/99905
* combine.c (expand_compound_operation): If pos + len > modewidth,
perform the right shift by pos in inner_mode and then convert to mode,
instead of trying to simplify a shift of rtx with inner_mode by pos
as if it was a shift in mode.

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

--- gcc/combine.c.jj2021-01-04 10:25:39.127230495 +0100
+++ gcc/combine.c   2021-04-07 11:33:13.442626682 +0200
@@ -7409,11 +7409,15 @@ expand_compound_operation (rtx x)
  mode, tem, modewidth - len);
 }
   else if (unsignedp && len < HOST_BITS_PER_WIDE_INT)
-tem = simplify_and_const_int (NULL_RTX, mode,
- simplify_shift_const (NULL_RTX, LSHIFTRT,
-   mode, XEXP (x, 0),
-   pos),
- (HOST_WIDE_INT_1U << len) - 1);
+{
+  tem = simplify_shift_const (NULL_RTX, LSHIFTRT, inner_mode,
+ XEXP (x, 0), pos);
+  tem = gen_lowpart (mode, tem);
+  if (!tem || GET_CODE (tem) == CLOBBER)
+   return x;
+  tem = simplify_and_const_int (NULL_RTX, mode, tem,
+   (HOST_WIDE_INT_1U << len) - 1);
+}
   else
 /* Any other cases we can't handle.  */
 return x;
--- gcc/testsuite/gcc.target/i386/pr99905.c.jj  2021-04-07 11:42:40.954292535 
+0200
+++ gcc/testsuite/gcc.target/i386/pr99905.c 2021-04-07 11:42:06.659675315 
+0200
@@ -0,0 +1,33 @@
+/* PR rtl-optimization/99905 */
+/* { dg-do run { target int128 } } */
+/* { dg-options "-Os -mno-mmx -mno-sse" } */
+
+typedef unsigned char U;
+typedef unsigned char __attribute__((__vector_size__ (8))) A;
+typedef unsigned char __attribute__((__vector_size__ (16))) B;
+typedef unsigned char __attribute__((__vector_size__ (32))) C;
+typedef unsigned int __attribute__((__vector_size__ (8))) D;
+typedef unsigned long long __attribute__((__vector_size__ (8))) E;
+typedef unsigned __int128 I;
+typedef unsigned long long L;
+
+D gv;
+I gi;
+
+L __attribute__((__noipa__))
+foo (int ua, int ub, int uc, int ud, E ue, I i)
+{
+  D d = (U) __builtin_bswap16 (i >> 63) + gv;
+  B y = ((union { C a; B b[2];}) (C){ }).b[0] + (B) gi;
+  A z = ((union { B a; A b[2];}) y).b[0] + (A) d;
+  return (L)z;
+}
+
+int
+main ()
+{
+  L x = foo (0, 0, 0, 0, (E) { }, (I) 0x100 << 63);
+  if (x != 0x10001)
+__builtin_abort ();
+  return 0;
+}

Jakub



[PATCH] c++: Don't cache constexpr functions which are passed pointers to heap or static vars being constructed [PR99859]

2021-04-08 Thread Jakub Jelinek via Gcc-patches
Hi!

When cxx_bind_parameters_in_call is called e.g. on a method on an automatic
variable, we evaluate the argument and because ADDR_EXPR of an automatic
decl is not TREE_CONSTANT, we set *non_constant_args and don't cache it.
But when it is called on an object located on the heap (allocated using
C++20 constexpr new) where we represent it as TREE_STATIC artificial
var, or when it is called on a static var that is currently being
constructed, such ADDR_EXPRs are TREE_CONSTANT and we happily cache
such calls, but they can in those cases have side-effects in the heap
or static var objects and so caching them means such side-effects will
happen only once and not as many times as that method or function is called.
Furthermore, as Patrick mentioned in the PR, the argument doesn't need to be
just ADDR_EXPR of the heap or static var or its components, but it could be
a CONSTRUCTOR that has the ADDR_EXPR embedded anywhere.

The following patch fixes it by setting *non_constant_args also when
the argument contains somewhere such an ADDR_EXPR, either of a heap
artificial var or component thereof, or of a static var currently being
constructed (where for that it uses the same check as
cxx_eval_store_expression, ctx->global->values.get (...); addresses of
other static variables would be rejected by cxx_eval_store_expression
and therefore it is ok to cache such calls).

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2021-04-08  Jakub Jelinek  

PR c++/99859
* constexpr.c (addr_of_non_const_var): New function.
(cxx_bind_parameters_in_call): Set *non_constant_args to true
even if cp_walk_tree on arg with addr_of_non_const_var callback
returns true.

* g++.dg/cpp1y/constexpr-99859.C: New test.
* g++.dg/cpp2a/constexpr-new18.C: New test.
* g++.dg/cpp2a/constexpr-new19.C: New test.

--- gcc/cp/constexpr.c.jj   2021-04-07 15:50:32.274927848 +0200
+++ gcc/cp/constexpr.c  2021-04-07 18:21:20.845684670 +0200
@@ -1555,6 +1555,32 @@ free_constructor (tree t)
 }
 }
 
+/* Helper function of cxx_bind_parameters_in_call.  Return non-NULL
+   if *TP is address of a static variable (or part of it) currently being
+   constructed or of a heap artificial variable.  */
+
+static tree
+addr_of_non_const_var (tree *tp, int *walk_subtrees, void *data)
+{
+  if (TREE_CODE (*tp) == ADDR_EXPR)
+if (tree var = get_base_address (TREE_OPERAND (*tp, 0)))
+  if (VAR_P (var) && TREE_STATIC (var))
+   {
+ if (DECL_NAME (var) == heap_uninit_identifier
+ || DECL_NAME (var) == heap_identifier
+ || DECL_NAME (var) == heap_vec_uninit_identifier
+ || DECL_NAME (var) == heap_vec_identifier)
+   return var;
+
+ constexpr_global_ctx *global = (constexpr_global_ctx *) data;
+ if (global->values.get (var))
+   return var;
+   }
+  if (TYPE_P (*tp))
+*walk_subtrees = false;
+  return NULL_TREE;
+}
+
 /* Subroutine of cxx_eval_call_expression.
We are processing a call expression (either CALL_EXPR or
AGGR_INIT_EXPR) in the context of CTX.  Evaluate
@@ -1616,6 +1642,14 @@ cxx_bind_parameters_in_call (const const
/* The destructor needs to see any modifications the callee makes
   to the argument.  */
*non_constant_args = true;
+   /* If arg is or contains address of a heap artificial variable or
+  of a static variable being constructed, avoid caching the
+  function call, as those variables might be modified by the
+  function.  */
+ else if (!*non_constant_args
+  && cp_walk_tree (&arg, addr_of_non_const_var, ctx->global,
+   NULL))
+   *non_constant_args = true;
 
  /* For virtual calls, adjust the this argument, so that it is
 the object on which the method is called, rather than
--- gcc/testsuite/g++.dg/cpp1y/constexpr-99859.C.jj 2021-04-07 
19:15:12.488877570 +0200
+++ gcc/testsuite/g++.dg/cpp1y/constexpr-99859.C2021-04-07 
19:15:33.796641707 +0200
@@ -0,0 +1,24 @@
+// PR c++/99859
+// { dg-do compile { target c++14 } }
+
+constexpr int
+foo (int *x)
+{
+  return ++*x;
+}
+
+struct S { constexpr S () : a(0) { foo (&a); foo (&a); } int a; };
+constexpr S s = S ();
+static_assert (s.a == 2, "");
+
+struct R { int *p; };
+
+constexpr int
+bar (R x)
+{
+  return ++*x.p;
+}
+
+struct T { int a = 0; constexpr T () { bar (R{&a}); bar (R{&a}); } };
+constexpr T t = T ();
+static_assert (t.a == 2, "");
--- gcc/testsuite/g++.dg/cpp2a/constexpr-new18.C.jj 2021-04-07 
17:35:36.272075995 +0200
+++ gcc/testsuite/g++.dg/cpp2a/constexpr-new18.C2021-04-07 
17:35:36.272075995 +0200
@@ -0,0 +1,45 @@
+// PR c++/99859
+// { dg-do compile { target c++20 } }
+
+template 
+struct intrusive_ptr
+{
+  T *ptr = nullptr;
+  constexpr explicit intrusive_ptr(T* p) : ptr(p) {
+++ptr->count_;
+  }
+  constex

Re: [PATCH] ipa-sra: Release dead LHS SSA_NAME when removing it (PR 99951)

2021-04-08 Thread Richard Biener via Gcc-patches
On Thu, Apr 8, 2021 at 11:24 AM Martin Jambor  wrote:
>
> Hi,
>
> When IPA-SRA removes an SSA_NAME from a LHS of a call statement
> because it is not necessary, it does not release it.  This patch fixes
> that.
>
> Bootstrapped and tested on x86_64, at some point I'll LTO-bootstrap it
> too.  I assume this is GCC 12 material, so OK once stage 1 opens?

Yes, and OK.

Richard.

> Thanks,
>
> Martin
>
>
> gcc/ChangeLog:
>
> 2021-04-08  Martin Jambor  
>
> PR ipa/99951
> * ipa-param-manipulation.c (ipa_param_adjustments::modify_call):
> If removing a call statement LHS SSA name, release it.
> ---
>  gcc/ipa-param-manipulation.c | 4 
>  1 file changed, 4 insertions(+)
>
> diff --git a/gcc/ipa-param-manipulation.c b/gcc/ipa-param-manipulation.c
> index 132bb24f76a..1d1e64f546a 100644
> --- a/gcc/ipa-param-manipulation.c
> +++ b/gcc/ipa-param-manipulation.c
> @@ -856,6 +856,7 @@ ipa_param_adjustments::modify_call (gcall *stmt,
>
>gcall *new_stmt = gimple_build_call_vec (callee_decl, vargs);
>
> +  tree ssa_to_remove = NULL;
>if (tree lhs = gimple_call_lhs (stmt))
>  {
>if (!m_skip_return)
> @@ -880,6 +881,7 @@ ipa_param_adjustments::modify_call (gcall *stmt,
> }
>   update_stmt (using_stmt);
> }
> + ssa_to_remove = lhs;
> }
>  }
>
> @@ -898,6 +900,8 @@ ipa_param_adjustments::modify_call (gcall *stmt,
>fprintf (dump_file, "\n");
>  }
>gsi_replace (&gsi, new_stmt, true);
> +  if (ssa_to_remove)
> +release_ssa_name (ssa_to_remove);
>if (update_references)
>  do
>{
> --
> 2.30.2
>


Re: [PATCH] ada/adaint.c (__gnat_copy_attribs): RTEMS should use utime()

2021-04-08 Thread Arnaud Charlet
> Change the preprocessor logic so RTEMS uses utime().
> gcc/ada/
>   * adaint.c (__gnat_copy_attribs): RTEMS should use utime().

This change is OK.

> ---
>  gcc/ada/adaint.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/gcc/ada/adaint.c b/gcc/ada/adaint.c
> index 0a90c92402c..d3b83f61076 100644
> --- a/gcc/ada/adaint.c
> +++ b/gcc/ada/adaint.c
> @@ -3270,7 +3270,7 @@ __gnat_copy_attribs (char *from ATTRIBUTE_UNUSED, char 
> *to ATTRIBUTE_UNUSED,
>   return -1;
>}
>  
> -#if (defined (__vxworks) && _WRS_VXWORKS_MAJOR < 7)
> +#if (defined (__vxworks) && _WRS_VXWORKS_MAJOR < 7) || defined(__rtems__)
>  
>/* VxWorks prior to 7 only has utime.  */
>  
> -- 
> 2.24.4
> 


Re: [committed] libstdc++: Add std::is_scoped_enum for C++23

2021-04-08 Thread Jonathan Wakely via Gcc-patches

On 20/03/21 09:18 -0500, Tim Song wrote:

On Sat, Mar 20, 2021 at 3:58 AM Jonathan Wakely  wrote:




On Sat, 20 Mar 2021, 01:13 Tim Song via Libstdc++,  
wrote:


On Fri, Mar 19, 2021 at 3:13 PM Jonathan Wakely via Libstdc++
 wrote:
>
> Implement this C++23 feature, as proposed by P1048R1.
>
> This implementation assumes that a C++23 compiler supports concepts
> already. I don't see any point in using preprocessor hacks to detect
> compilers which define __cplusplus to a post-C++20 value but don't
> support concepts yet.
>
> libstdc++-v3/ChangeLog:
>
> * include/std/type_traits (is_scoped_enum): Define.
> * include/std/version (__cpp_lib_is_scoped_enum): Define.
> * testsuite/20_util/is_scoped_enum/value.cc: New test.
> * testsuite/20_util/is_scoped_enum/version.cc: New test.
>
> Tested powerpc64le-linux. Committed to trunk.
>

Using __underlying_type breaks for incomplete enumeration types. GCC
doesn't have incomplete scoped enums due to
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89025 but unscoped ones
exist:

enum E {
x = std::is_scoped_enum_v
};



Thanks, I'll just use int then. Maybe not until Monday though.




Using int avoids the hard error, but it appears to give the wrong
answer (presumably because the is_convertible check fails due to E
being incomplete). This may need to be handled explicitly?


This seems to work, at least until PR 89025 is fixed (because you
can't currently refer to an incomplete scoped enum type).

Tested powerpc64le-linux, pushed to trunk.



commit 43ab1dc24abd6fded8d5bf6547f0de6851beb200
Author: Jonathan Wakely 
Date:   Thu Apr 8 10:50:57 2021

libstdc++: Make std::is_scoped_enum work with incomplete types

Tim Song pointed out that using __underlying_type is ill-formed for
incomplete enumeration types, and is_scoped_enum doesn't require a
complete type. This changes the trait to check for conversion to int
instead of to the underlying type.

In order to give the correct result when the trait is used in the
enumerator-list of an incomplete type the partial specialization for
enums has an additional check that fails for incomplete types. This
assumes that an incompelte enumeration type must be an unscoped
enumeration, and so the primary template (with a std::false_type base
characteristic) can be used. This isn't necessarily true, but it is not
currently possible to refer to a scoped enumeration type before its type
is complete (PR c++/89025).

It should be possible to use requires(remove_cv_t<_Tp> __t) in the
partial specialization's assignablility check, but that currently gives
an ICE (PR c++/99968) so there is an extra partial specialization of
is_scoped_enum to handle const types.

libstdc++-v3/ChangeLog:

* include/std/type_traits (is_scoped_enum): Constrain partial
specialization to not match incomplete enum types. Use a
requires-expression instead of instantiating is_convertible.
(is_scoped_enum): Add as workaround for PR c++/99968.
* testsuite/20_util/is_scoped_enum/value.cc: Check with
incomplete types and opaque-enum-declarations.

diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits
index eeab1ca65fc..1f8b57b04a0 100644
--- a/libstdc++-v3/include/std/type_traits
+++ b/libstdc++-v3/include/std/type_traits
@@ -3287,9 +3287,20 @@ template 
 : false_type
 { };
 
-  template requires __is_enum(_Tp)
+  template
+requires __is_enum(_Tp)
+&& requires(_Tp __t) { __t = __t; } // fails if incomplete
 struct is_scoped_enum<_Tp>
-: __not_>::type
+: bool_constant
+{ };
+
+  // FIXME remove this partial specialization and use remove_cv_t<_Tp> above
+  // when PR c++/99968 is fixed.
+  template
+requires __is_enum(_Tp)
+&& requires(_Tp __t) { __t = __t; } // fails if incomplete
+struct is_scoped_enum
+: bool_constant
 { };
 
   template
diff --git a/libstdc++-v3/testsuite/20_util/is_scoped_enum/value.cc b/libstdc++-v3/testsuite/20_util/is_scoped_enum/value.cc
index bab7263ae4a..2cef857a042 100644
--- a/libstdc++-v3/testsuite/20_util/is_scoped_enum/value.cc
+++ b/libstdc++-v3/testsuite/20_util/is_scoped_enum/value.cc
@@ -32,6 +32,8 @@ template
   concept Is_scoped_enum
 = __gnu_test::test_category(true);
 
+struct Incomplete_struct;
+
 void
 test01()
 {
@@ -45,6 +47,9 @@ test01()
   static_assert( ! Is_scoped_enum );
   enum F : int { f1, f2 };
   static_assert( ! Is_scoped_enum );
+  static_assert( ! Is_scoped_enum );
+  struct S;
+  static_assert( ! Is_scoped_enum );
   struct S { };
   static_assert( ! Is_scoped_enum );
 
@@ -60,3 +65,36 @@ test01()
   static_assert( ! Is_scoped_enum );
   static_assert( ! Is_scoped_enum );
 }
+
+enum opaque_unscoped : short;
+enum class opaque_scoped;
+enum class opaque_scoped_with_base : long;
+
+static_assert( ! Is_scoped_enum );
+static_assert( I

[pushed] c++: improve specialization mismatch diagnostic [PR94529]

2021-04-08 Thread Jason Merrill via Gcc-patches
We were telling users they needed more template<> to specialize a member
template in a testcase with no member templates.  Only produce that message
if we actually see a member template, and also always print the candidates.

Tested x86_64-pc-linux-gnu, applying to trunk.

gcc/cp/ChangeLog:

PR c++/94529
* pt.c (determine_specialization): Improve diagnostic.

gcc/testsuite/ChangeLog:

PR c++/94529
* g++.dg/template/mem-spec2.C: New test.
---
 gcc/cp/pt.c   | 11 +++
 gcc/testsuite/g++.dg/template/mem-spec2.C | 11 +++
 2 files changed, 18 insertions(+), 4 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/template/mem-spec2.C

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index dee802121e5..46b237f2ec0 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -2201,6 +2201,7 @@ determine_specialization (tree template_id,
 ++header_count;
 
   tree orig_fns = fns;
+  bool header_mismatch = false;
 
   if (variable_template_p (fns))
 {
@@ -2248,7 +2249,10 @@ determine_specialization (tree template_id,
 specialization but rather a template instantiation, so there
 is no check we can perform here.  */
  if (header_count && header_count != template_count + 1)
-   continue;
+   {
+ header_mismatch = true;
+ continue;
+   }
 
  /* Check that the number of template arguments at the
 innermost level for DECL is the same as for FN.  */
@@ -2482,13 +2486,12 @@ determine_specialization (tree template_id,
 {
   error ("template-id %qD for %q+D does not match any template "
 "declaration", template_id, decl);
-  if (header_count && header_count != template_count + 1)
+  if (header_mismatch)
inform (DECL_SOURCE_LOCATION (decl),
"saw %d %%>, need %d for "
"specializing a member function template",
header_count, template_count + 1);
-  else
-   print_candidates (orig_fns);
+  print_candidates (orig_fns);
   return error_mark_node;
 }
   else if ((templates && TREE_CHAIN (templates))
diff --git a/gcc/testsuite/g++.dg/template/mem-spec2.C 
b/gcc/testsuite/g++.dg/template/mem-spec2.C
new file mode 100644
index 000..bc96159522c
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/mem-spec2.C
@@ -0,0 +1,11 @@
+// PR c++/94529
+
+template 
+struct foo {
+// the issue is const here
+void bar(T& foobar) const { foobar = 0; } // { dg-message "candidate" }
+};
+
+template <> void
+foo::bar(int& foobar) { foobar = 9; } // { dg-error "does not match" }
+// { dg-bogus "member function template" "" { target *-*-* } .-1 }

base-commit: 2cd5333d16419f596d07a830bb3f1c40fa8a7b5c
-- 
2.27.0



GCC 10.3.1 Status Report (2021-04-08)

2021-04-08 Thread Richard Biener
Status
==

GCC 10.3.0 tarballs have been generated and uploaded and the
GCC 10 branch is again open for regression and documentation fixes.


Quality Data


Priority  #   Change from last report
---   ---
P1
P2  326
P3   31   +   6
P4  178   -   1
P5   23
---   ---
Total P1-P3 356   +   6
Total   557   +   5


Previous Report
===

https://gcc.gnu.org/pipermail/gcc/2021-April/235256.html


[PATCH][pushed] Modernize branch_changer.py script.

2021-04-08 Thread Martin Liška
Pushed to master.

maintainer-scripts/ChangeLog:

* branch_changer.py: Modernize and fix flake8 issues.
* setup.cfg: New file.
---
 maintainer-scripts/branch_changer.py | 70 
 maintainer-scripts/setup.cfg |  5 ++
 2 files changed, 45 insertions(+), 30 deletions(-)
 create mode 100644 maintainer-scripts/setup.cfg

diff --git a/maintainer-scripts/branch_changer.py 
b/maintainer-scripts/branch_changer.py
index b0580296c16..d7954361752 100755
--- a/maintainer-scripts/branch_changer.py
+++ b/maintainer-scripts/branch_changer.py
@@ -16,7 +16,8 @@
 #
 # Sample usages of the script:
 #
-# $ ./maintainer-scripts/branch_changer.py api_key 
--new-target-milestone=6.2:6.3 --comment '6.2 has been released' 
--add-known-to-fail=6.2 --limit 3
+# $ ./maintainer-scripts/branch_changer.py api_key 
--new-target-milestone=6.2:6.3 \
+#   --comment '6.2 has been released' --add-known-to-fail=6.2 --limit 3
 #
 # The invocation will set target milestone to 6.3 for all issues that
 # have mistone equal to 6.2. Apart from that, a comment is added to these
@@ -24,7 +25,8 @@
 # At maximum 3 issues will be modified and the script will run
 # in dry mode (no issues are modified), unless you append --doit option.
 #
-# $ ./maintainer-scripts/branch_changer.py api_key 
--new-target-milestone=5.5:6.3 --comment 'GCC 5 branch is being closed' 
--remove 5 --limit 3
+# $ ./maintainer-scripts/branch_changer.py api_key 
--new-target-milestone=5.5:6.3 \
+#   --comment 'GCC 5 branch is being closed' --remove 5 --limit 3
 #
 # Very similar to previous invocation, but instead of adding to known-to-fail,
 # '5' release is removed from all issues that have the regression prefix.
@@ -35,17 +37,19 @@
 # issues that contain '7' in its regression prefix.
 #
 
-import requests
-import json
 import argparse
+import json
 import re
 
-from semantic_version import Version
+import requests
+
+from semantic_version import SimpleSpec
 
 base_url = 'https://gcc.gnu.org/bugzilla/rest.cgi/'
 statuses = ['UNCONFIRMED', 'ASSIGNED', 'SUSPENDED', 'NEW', 'WAITING', 
'REOPENED']
 search_summary = ' Regression]'
-regex = '(.*\[)([0-9\./]*)( [rR]egression])(.*)'
+regex = r'(.*\[)([0-9\./]*)( [rR]egression])(.*)'
+
 
 class Bug:
 def __init__(self, data):
@@ -59,7 +63,7 @@ class Bug:
 
 def parse_summary(self):
 m = re.match(regex, self.data['summary'])
-if m != None:
+if m:
 self.versions = m.group(2).split('/')
 self.is_regression = True
 self.regex_match = m
@@ -116,15 +120,16 @@ class Bug:
 print('  changing target milestone: "%s" to "%s" (same branch)' % 
(old_milestone, new_milestone))
 elif self.is_regression and new_major in self.versions:
 args['target_milestone'] = new_milestone
-print('  changing target milestone: "%s" to "%s" (regresses with 
the new milestone)' % (old_milestone, new_milestone))
+print('  changing target milestone: "%s" to "%s" (regresses with 
the new milestone)'
+  % (old_milestone, new_milestone))
 else:
 print('  not changing target milestone: not a regression or does 
not regress with the new milestone')
 
-if 'target_milestone' in args and comment != None:
+if 'target_milestone' in args and comment:
 print('  adding comment: "%s"' % comment)
-args['comment'] = {'comment': comment }
+args['comment'] = {'comment': comment}
 
-if new_fail_version != None:
+if new_fail_version:
 if self.add_known_to_fail(new_fail_version):
 s = self.serialize_known_to_fail()
 print('  changing known_to_fail: "%s" to "%s"' % 
(self.data['cf_known_to_fail'], s))
@@ -137,8 +142,8 @@ class Bug:
 return False
 
 def serialize_summary(self):
-assert self.versions != None
-assert self.is_regression == True
+assert not self.versions
+assert self.is_regression
 
 new_version = '/'.join(self.versions)
 new_summary = self.regex_match.group(1) + new_version + 
self.regex_match.group(3) + self.regex_match.group(4)
@@ -146,19 +151,19 @@ class Bug:
 
 def serialize_known_to_fail(self):
 assert type(self.fail_versions) is list
-return ', '.join(sorted(self.fail_versions, key = lambda x: Version(x, 
partial = True)))
+return ', '.join(sorted(self.fail_versions, key=lambda x: 
SimpleSpec(x)))
 
 def modify_bug(self, api_key, params, doit):
 u = base_url + 'bug/' + str(self.data['id'])
 
 data = {
 'ids': [self.data['id']],
-'api_key': api_key }
+'api_key': api_key}
 
 data.update(params)
 
 if doit:
-r = requests.put(u, data = json.dumps(data), headers = 
{"content-type": "text/javascript"})
+r = requests.put(u, data=json.dumps(data), 
headers={'content-type'

Re: [Bug libstdc++/99402] [10/11 Regression] std::copy creates _GLIBCXX_DEBUG false positive for attempt to subscript a dereferenceable (start-of-sequence) iterator

2021-04-08 Thread Jonathan Wakely via Gcc-patches

On 11/03/21 18:51 +0100, François Dumont via Libstdc++ wrote:

I eventually prefer to propose this version.

Compared to the previous one I have the _M_can_advance calling the 
former one with correct number of elements to check for advance. And 
the former _M_can_advance is also properly making use of the 
__dp_sign_max_size precision.


Here is the revisited git log:

    libstdc++: [_GLIBCXX_DEBUG] Fix management of __dp_sign_max_size 
[PR 99402]


    __dp_sign precision indicates that we found out what iterator 
comes first or
    last in the range. __dp_sign_max_size is the same plus it gives 
the information
    of the max size of the range that is to say the max_size value 
such that

    distance(lhs, rhs) < max_size.
    Thanks to this additional information we are able to tell when a 
copy of n elements

    to that range will fail even if we do not know exactly how large it is.

    This patch makes sure that we are properly using this information.

    libstdc++-v3/ChangeLog:

    PR libstdc++/99402
    * include/debug/helper_functions.h 
(__can_advance(_InputIterator,

    const std::pair<_Diff, _Distance_precision>&, int)): New.
    (__can_advance(const _Safe_iterator<>&,
    const std::pair<_Diff, _Distance_precision>&, int)): New.
    * include/debug/macros.h 
(__glibcxx_check_can_increment_dist): New,

    use latter.
    (__glibcxx_check_can_increment_range): Adapt to use latter.
    (__glibcxx_check_can_decrement_range): Likewise.
    * include/debug/safe_iterator.h
    (_Safe_iterator<>::_M_can_advance(const std::pair<_Diff, 
_Distance_precision>&,

    int)): New.
    (__can_advance(const _Safe_iterator<>&,
    const std::pair<_Diff, _Distance_precision>&, int)): New.
    * include/debug/safe_iterator.tcc
    (_Safe_iterator<>::_M_can_advance(const std::pair<_Diff, 
_Distance_precision>&,

    int)): New.
    (_Safe_iterator<>::_M_valid_range(const _Safe_iterator<>&,
    std::pair&, bool)): 
Adapt for

    __dp_sign_max_size.
    (__copy_move_a): Adapt to use 
__glibcxx_check_can_increment_dist.

    (__copy_move_backward_a): Likewise.
    (__equal_aux): Likewise.
    * include/debug/stl_iterator.h (__can_advance(const 
std::reverse_iterator<>&,

    const std::pair<_Diff, _Distance_precision>&, int)): New.
    (__can_advance(const std::move_iterator<>&,
    const std::pair<_Diff, _Distance_precision>&, int)): New.
    * testsuite/25_algorithms/copy/debug/99402.cc: New test.

Ok to commit if tests are all PASS ?

François

On 07/03/21 10:30 pm, François Dumont wrote:

Here is the patch to correctly deal with the new __dp_sign_max_size.

I prefer to introduce new __can_advance overloads for this to 
correctly deal with the _Distance_precision in it. _M_valid_range 
was also ignoring __dp_sign_max_size.


    libstdc++: [_GLIBCXX_DEBUG] Fix management of __dp_sign_max_size 
[PR 99402]


    libstdc++-v3/ChangeLog:

    PR libstdc++/99402
    * include/debug/helper_functions.h 
(__can_advance(_InputIterator,

    const std::pair<_Diff, _Distance_precision>&, int)): New.
    (__can_advance(const _Safe_iterator<>&,
    const std::pair<_Diff, _Distance_precision>&, int)): New.
    * include/debug/macros.h 
(__glibcxx_check_can_increment_dist): New,

    use latter.
    (__glibcxx_check_can_increment_range): Adapt to use latter.
    (__glibcxx_check_can_decrement_range): Likewise.
    * include/debug/safe_iterator.h
    (_Safe_iterator<>::_M_can_advance(const std::pair<_Diff, 
_Distance_precision>&,

    int)): New.
    (__can_advance(const _Safe_iterator<>&,
    const std::pair<_Diff, _Distance_precision>&, int)): New.
    * include/debug/safe_iterator.tcc
    (_Safe_iterator<>::_M_can_advance(const std::pair<_Diff, 
_Distance_precision>&,

    int)): New.
    (_Safe_iterator<>::_M_valid_range(const _Safe_iterator<>&,
    std::pair&, 
bool)): Adapt for

    __dp_sign_max_size.
    (__copy_move_a): Adapt to use 
__glibcxx_check_can_increment_dist.

    (__copy_move_backward_a): Likewise.
    (__equal_aux): Likewise.
    * include/debug/stl_iterator.h (__can_advance(const 
std::reverse_iterator<>&,

    const std::pair<_Diff, _Distance_precision>&, int)): New.
    (__can_advance(const std::move_iterator<>&,
    const std::pair<_Diff, _Distance_precision>&, int)): New.
    * testsuite/25_algorithms/copy/debug/99402.cc: New test.

Tested under Linux x86_64.

Ok to commit ?

François






diff --git a/libstdc++-v3/include/debug/helper_functions.h 
b/libstdc++-v3/include/debug/helper_functions.h
index 513e5460eba..c0144ced979 100644
--- a/libstdc++-v3/inc

Re: [PATCH] libstdc++: Reimplement range adaptors [PR99433]

2021-04-08 Thread Jonathan Wakely via Gcc-patches

On 29/03/21 10:33 -0400, Patrick Palka via Libstdc++ wrote:

This rewrites our range adaptor implementation for more comprehensible
error messages, improved SFINAE behavior and conformance to P2281.

The diagnostic improvements mostly come from using appropriately named
functors instead of lambdas in the generic implementation of partial
application and composition of range adaptors, and in the definition of
each of the standard range adaptors.  This makes their pretty printed
types of much shorter and more descriptive.


s/types of/types/




The improved SFINAE behavior comes from constraining the range adaptors'
member functions appropriately.  This improvement fixes PR99433, and is
also necessary in order to implement the wording changes of P2281.

Finally, P2281 clarified that partial application and composition of
range adaptors behaves like a perfect forwarding call wrapper.  This
patch implements this, except that we don't bother adding overloads for
forwarding captured state entities as non-const lvalues, since it seems
it's sufficient to handle the const lvalue and non-const rvalue cases,
given the current set of standard range adaptors.  But such overloads
can be easily added if they turn out to be needed.

Tested on x86_64-pc-linux-gnu, does this look OK for trunk?


OK, thanks.



[committed] d: Update language attribute support, and implement gcc.attributes

2021-04-08 Thread Iain Buclaw via Gcc-patches
This patch updates the GCC attribute support in the D front-end to have
a baseline parity with the LLVM D compiler's own `ldc.attributes'.

The handler that extracts GCC attributes from a list of UDAs has been
improved to take care of some mistakes that could have been warnings.
UDAs attached to field variables are also now processed for any GCC
attributes attached to them.

The following new attributes have been added to the D front-end:

 - @attribute("alloc_size")
 - @attribute("used")
 - @attribute("optimize")
 - @attribute("restrict")
 - @attribute("cold")
 - @attribute("noplt")
 - @attribute("target_clones")
 - @attribute("no_icf")
 - @attribute("noipa")
 - @attribute("symver")

With convenience aliases in a new `gcc.attributes' module to match
the same naming convention as `ldc.attributes':

 - @allocSize()
 - @assumeUsed
 - @fastmath
 - @naked
 - @restrict
 - @cold
 - @noplt
 - @optStrategy()
 - @polly
 - @section()
 - @target()
 - @weak

The old gcc.attribute module has been deprecated, along with the removal
of the following attribute handlers:

 - @attribute("alias"): Has been superseded by `pragma(mangle)'.
 - @attribute("forceinline"): Renamed to always_inline.

Bootstrapped and regression tested on x86_64-linux-gnu/-m32/-mx32, and
committed to mainline.

---
gcc/d/ChangeLog:

* d-attribs.cc: Include fold-const.h and opts.h.
(attr_noreturn_exclusions): Add alloc_size.
(attr_const_pure_exclusions): Likewise.
(attr_inline_exclusions): Add target_clones.
(attr_noinline_exclusions): Rename forceinline to always_inline.
(attr_target_exclusions): New array.
(attr_target_clones_exclusions): New array.
(attr_alloc_exclusions): New array.
(attr_cold_hot_exclusions): New array.
(d_langhook_common_attribute_table): Add new D attribute handlers.
(build_attributes): Update to look for gcc.attributes.  Issue warning
if not given a struct literal.  Handle void initialized arguments.
(handle_always_inline_attribute): Remove function.
(d_handle_noinline_attribute): Don't extract TYPE_LANG_FRONTEND.
(d_handle_forceinline_attribute): Rename to...
(d_handle_always_inline_attribute): ...this.  Remove special handling.
(d_handle_flatten_attribute): Don't extract TYPE_LANG_FRONTEND.
(d_handle_target_attribute): Likewise.  Warn about empty arguments.
(d_handle_target_clones_attribute): New function.
(optimize_args): New static variable.
(parse_optimize_options): New function.
(d_handle_optimize_attribute): New function.
(d_handle_noclone_attribute): Don't extract TYPE_LANG_FRONTEND.
(d_handle_alias_attribute): Remove function.
(d_handle_noicf_attribute): New function.
(d_handle_noipa_attribute): New function.
(d_handle_section_attribute): Call the handle_generic_attribute target
hook after performing target independent processing.
(d_handle_symver_attribute): New function.
(d_handle_noplt_attribute): New function.
(positional_argument): New function.
(d_handle_alloc_size_attribute): New function.
(d_handle_cold_attribute): New function.
(d_handle_restrict_attribute): New function.
(d_handle_used_attribute): New function.
* decl.cc (gcc_attribute_p): Update to look for gcc.attributes.
(get_symbol_decl): Update decl source location of old prototypes to
the new declaration being merged.
* types.cc (layout_aggregate_members): Apply user defined attributes
on fields.

libphobos/ChangeLog:

* libdruntime/Makefile.am (DRUNTIME_DSOURCES): Add
  gcc/attributes.d.
* libdruntime/Makefile.in: Regenerate.
* libdruntime/gcc/attribute.d: Deprecate module, publicly import
gcc.attributes.
* libdruntime/gcc/deh.d: Update imports.
* libdruntime/gcc/attributes.d: New file.

gcc/testsuite/ChangeLog:

* gdc.dg/gdc108.d: Update test.
* gdc.dg/gdc142.d: Likewise.
* gdc.dg/pr90136a.d: Likewise.
* gdc.dg/pr90136b.d: Likewise.
* gdc.dg/pr90136c.d: Likewise.
* gdc.dg/pr95173.d: Likewise.
* gdc.dg/attr_allocsize1.d: New test.
* gdc.dg/attr_allocsize2.d: New test.
* gdc.dg/attr_alwaysinline1.d: New test.
* gdc.dg/attr_cold1.d: New test.
* gdc.dg/attr_exclusions1.d: New test.
* gdc.dg/attr_exclusions2.d: New test.
* gdc.dg/attr_flatten1.d: New test.
* gdc.dg/attr_module.d: New test.
* gdc.dg/attr_noclone1.d: New test.
* gdc.dg/attr_noicf1.d: New test.
* gdc.dg/attr_noinline1.d: New test.
* gdc.dg/attr_noipa1.d: New test.
* gdc.dg/attr_noplt1.d: New test.
* gdc.dg/attr_optimize1.d: New test.
* gdc.dg/attr_optimize2.d: New test.
* gdc.dg/attr_optimize3.d: New test.
* gdc.dg/attr_optimize4.d: New test

[committed] analyzer: fix leak false +ves due to maybe-clobbered regions [PR99042, PR99774]

2021-04-08 Thread David Malcolm via Gcc-patches
Prior to this patch, program_state::detect_leaks worked by finding all
live svalues in the old state and in the new state, and calling
on_svalue_leak for each svalue that has changed from being live to
not being live.

PR analyzer/99042 and PR analyzer/99774 both describe false leak
diagnostics from -fanalyzer (a false FILE * leak in git, and a false
malloc leak in qemu, respectively).

In both cases the root cause of the false leak diagnostic relates to
svalues no longer being explicitly bound in the store due to regions
being conservatively clobbered, due to an unknown function being
called, or due to a write through a pointer that could alias the
region, respectively.

We have a transition from an svalue being explicitly live to not
being explicitly live - but only because the store is being
conservative, clobbering the binding.  The leak detection is looking
for transitions from "definitely live" to "not definitely live",
when it should be looking for transitions from "definitely live"
to "definitely not live".

This patch introduces a new class to temporarily capture information
about svalues that were explicitly live, but for which a region bound
to them got clobbered for conservative reasons.  This new
"uncertainty_t" class is passed around to capture the data long enough
for use in program_state::detect_leaks, where it is used to only
complain about svalues that were definitely live and are now both
not definitely live *or* possibly-live i.e. definitely not-live.

The class also captures for which svalues we can't meaningfully track
sm-state anymore, and resets the svalues back to the "start" state.

Together, these changes fix the false leak reports.

Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu.
Pushed to trunk as r11-8046-g3a66c289a3f395e50de79424e1e6f401a4dc1ab7.

gcc/analyzer/ChangeLog:
PR analyzer/99042
PR analyzer/99774
* engine.cc
(impl_region_model_context::impl_region_model_context): Add
uncertainty param and use it to initialize m_uncertainty.
(impl_region_model_context::get_uncertainty): New.
(impl_sm_context::get_fndecl_for_call): Add NULL for new
uncertainty param when constructing impl_region_model_context.
(impl_sm_context::get_state): Likewise.
(impl_sm_context::set_next_state): Likewise.
(impl_sm_context::warn): Likewise.
(exploded_node::on_stmt): Add uncertainty param
and use it when constructing impl_region_model_context.
(exploded_node::on_edge): Add uncertainty param and pass
to on_edge call.
(exploded_node::detect_leaks): Create uncertainty_t and pass to
impl_region_model_context.
(exploded_graph::get_or_create_node): Create uncertainty_t and
pass to prune_for_point.
(maybe_process_run_of_before_supernode_enodes): Create
uncertainty_t and pass to impl_region_model_context.
(exploded_graph::process_node): Create uncertainty_t instances and
pass around as needed.
* exploded-graph.h
(impl_region_model_context::impl_region_model_context): Add
uncertainty param.
(impl_region_model_context::get_uncertainty): New decl.
(impl_region_model_context::m_uncertainty): New field.
(exploded_node::on_stmt): Add uncertainty param.
(exploded_node::on_edge): Likewise.
* program-state.cc (sm_state_map::on_liveness_change): Get
uncertainty from context and use it to unset sm-state from
svalues as appropriate.
(program_state::on_edge): Add uncertainty param and use it when
constructing impl_region_model_context.  Fix indentation.
(program_state::prune_for_point): Add uncertainty param and use it
when constructing impl_region_model_context.
(program_state::detect_leaks): Get any uncertainty from ctxt and
use it to get maybe-live svalues for dest_state, rather than
definitely-live ones; use this when determining which svalues
have leaked.
(selftest::test_program_state_merging): Create uncertainty_t and
pass to impl_region_model_context.
* program-state.h (program_state::on_edge): Add uncertainty param.
(program_state::prune_for_point): Likewise.
* region-model-impl-calls.cc (call_details::get_uncertainty): New.
(region_model::impl_call_memcpy): Pass uncertainty to
mark_region_as_unknown call.
(region_model::impl_call_memset): Likewise.
(region_model::impl_call_strcpy): Likewise.
* region-model-reachability.cc (reachable_regions::handle_sval):
Also add sval to m_mutable_svals.
* region-model.cc (region_model::on_assignment): Pass any
uncertainty from ctxt to the store::set_value call.
(region_model::handle_unrecognized_call): Get any uncertainty from
ctxt and use it to record mutable svalues at the unknown call.
(region_model::get_reach

[committed] libstdc++: Fix Doxygen warning about ambiguous file name

2021-04-08 Thread Jonathan Wakely via Gcc-patches
libstdc++-v3/ChangeLog:

* include/std/string_view: Adjust Doxygen @file comment.

Tested x86_64-linux. Committed to trunk.

commit 2c1557ac7b7652c63418abac1a1c4b7a9860a9f9
Author: Jonathan Wakely 
Date:   Thu Apr 8 14:47:47 2021

libstdc++: Fix Doxygen warning about ambiguous file name

libstdc++-v3/ChangeLog:

* include/std/string_view: Adjust Doxygen @file comment.

diff --git a/libstdc++-v3/include/std/string_view 
b/libstdc++-v3/include/std/string_view
index 31502f7d58d..33e2129383a 100644
--- a/libstdc++-v3/include/std/string_view
+++ b/libstdc++-v3/include/std/string_view
@@ -22,7 +22,7 @@
 // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 // .
 
-/** @file string_view
+/** @file include/string_view
  *  This is a Standard C++ Library header.
  */
 


[committed] maintainer-scripts: Disable multilib when generating libstdc++ docs

2021-04-08 Thread Jonathan Wakely via Gcc-patches
This allows the docs to be generated on hosts without the necessary
files present for multilib support.

maintainer-scripts/ChangeLog:

* generate_libstdcxx_web_docs: Add --disable-multilib to
configure command.

Tested x86_64-linux. Committed to trunk.

commit acbbb82ea3e2ae145e59ffca6f1ec0699b5f7383
Author: Jonathan Wakely 
Date:   Thu Apr 8 14:48:23 2021

maintainer-scripts: Disable multilib when generating libstdc++ docs

This allows the docs to be generated on hosts without the necessary
files present for multilib support.

maintainer-scripts/ChangeLog:

* generate_libstdcxx_web_docs: Add --disable-multilib to
configure command.

diff --git a/maintainer-scripts/generate_libstdcxx_web_docs 
b/maintainer-scripts/generate_libstdcxx_web_docs
index 74886356bc7..29572172761 100755
--- a/maintainer-scripts/generate_libstdcxx_web_docs
+++ b/maintainer-scripts/generate_libstdcxx_web_docs
@@ -43,7 +43,7 @@ do
   [ $dir == 'libstdc++-v3' ] || disabled_libs="$disabled_libs --disable-$dir"
 done
 set -x
-${SRCDIR}/configure --enable-languages=c,c++ --disable-gcc $disabled_libs 
--docdir=/docs
+${SRCDIR}/configure --enable-languages=c,c++ --disable-gcc --disable-multilib 
$disabled_libs --docdir=/docs
 eval `grep '^target=' config.log`
 make configure-target
 # If the following step fails with an error like


[committed] testsuite: Fix sve/mul_2.c failures

2021-04-08 Thread Richard Sandiford via Gcc-patches
Some sve/mul_2.c tests were failing because we'd (reasonably)
decided to use shifts and adds instead of MULs for some simple
negative constants.  We'd already needed to avoid that when
picking positive constants, so this patch does the same thing
for the negative ones.

Tested on aarch64-linux-gnu, pushed to trunk.

Richard


gcc/testsuite/
* gcc.target/aarch64/sve/mul_2.c: Adjust negative constants to avoid
conversion to shifts and adds.
---
 gcc/testsuite/gcc.target/aarch64/sve/mul_2.c | 14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/gcc/testsuite/gcc.target/aarch64/sve/mul_2.c 
b/gcc/testsuite/gcc.target/aarch64/sve/mul_2.c
index ff049f5bec0..b57e321c01f 100644
--- a/gcc/testsuite/gcc.target/aarch64/sve/mul_2.c
+++ b/gcc/testsuite/gcc.target/aarch64/sve/mul_2.c
@@ -21,14 +21,14 @@ TEST_TYPE (uint8_t, 32, 2, 250)
 
 TEST_TYPE (int8_t, 64, -110, 110)
 TEST_TYPE (uint8_t, 64, 3, 253)
-TEST_TYPE (int16_t, 64, -128, 123)
+TEST_TYPE (int16_t, 64, -123, 123)
 TEST_TYPE (uint16_t, 64, 3, 255)
 
-TEST_TYPE (int8_t, 128, -120, 120)
+TEST_TYPE (int8_t, 128, -119, 120)
 TEST_TYPE (uint8_t, 128, 4, 251)
-TEST_TYPE (int16_t, 128, -128, 123)
+TEST_TYPE (int16_t, 128, -123, 123)
 TEST_TYPE (uint16_t, 128, 2, 255)
-TEST_TYPE (int32_t, 128, -128, 123)
+TEST_TYPE (int32_t, 128, -123, 123)
 TEST_TYPE (uint32_t, 128, 4, 255)
 
 /* { dg-final { scan-assembler-times {\tmul\tz[0-9]+\.b, p[0-7]/m, z[0-9]+\.b, 
z[0-9]+\.b\n} 6 } } */
@@ -37,9 +37,9 @@ TEST_TYPE (uint32_t, 128, 4, 255)
 
 /* { dg-final { scan-assembler-times {\tmul\tz[0-9]+\.b, z[0-9]+\.b, #-100\n} 
1 } } */
 /* { dg-final { scan-assembler-times {\tmul\tz[0-9]+\.b, z[0-9]+\.b, #-110\n} 
1 } } */
-/* { dg-final { scan-assembler-times {\tmul\tz[0-9]+\.b, z[0-9]+\.b, #-120\n} 
1 } } */
-/* { dg-final { scan-assembler-times {\tmul\tz[0-9]+\.h, z[0-9]+\.h, #-128\n} 
2 } } */
-/* { dg-final { scan-assembler-times {\tmul\tz[0-9]+\.s, z[0-9]+\.s, #-128\n} 
1 } } */
+/* { dg-final { scan-assembler-times {\tmul\tz[0-9]+\.b, z[0-9]+\.b, #-119\n} 
1 } } */
+/* { dg-final { scan-assembler-times {\tmul\tz[0-9]+\.h, z[0-9]+\.h, #-123\n} 
2 } } */
+/* { dg-final { scan-assembler-times {\tmul\tz[0-9]+\.s, z[0-9]+\.s, #-123\n} 
1 } } */
 
 /* { dg-final { scan-assembler-times {\tmul\tz[0-9]+\.b, z[0-9]+\.b, #50\n} 6 
} } */
 /* { dg-final { scan-assembler-times {\tmul\tz[0-9]+\.h, z[0-9]+\.h, #50\n} 4 
} } */


[committed] testsuite: Fix Advanced SIMD failures for SVE

2021-04-08 Thread Richard Sandiford via Gcc-patches
This patch just adds some missing +nosve directives to Advanced
SIMD vectorisation tests.

Tested on aarch64-linux-gnu, pushed to trunk.

Richard


gcc/testsuite/
* gcc.target/aarch64/asimd-mull-elem.c: Add +nosve.
* gcc.target/aarch64/pr98772.c: Likewise.
* gcc.target/aarch64/simd/vect_su_add_sub.c: Likewise.
---
 gcc/testsuite/gcc.target/aarch64/asimd-mull-elem.c  | 2 ++
 gcc/testsuite/gcc.target/aarch64/pr98772.c  | 3 +++
 gcc/testsuite/gcc.target/aarch64/simd/vect_su_add_sub.c | 2 ++
 3 files changed, 7 insertions(+)

diff --git a/gcc/testsuite/gcc.target/aarch64/asimd-mull-elem.c 
b/gcc/testsuite/gcc.target/aarch64/asimd-mull-elem.c
index 513721cee0c..8ee7d118251 100644
--- a/gcc/testsuite/gcc.target/aarch64/asimd-mull-elem.c
+++ b/gcc/testsuite/gcc.target/aarch64/asimd-mull-elem.c
@@ -3,6 +3,8 @@
 /* { dg-require-effective-target vect_float } */
 /* { dg-options "-Ofast" } */
 
+#pragma GCC target "+nosve"
+
 #include 
 
 void s_mult_i (int32_t* restrict res, int32_t* restrict a, int32_t b)
diff --git a/gcc/testsuite/gcc.target/aarch64/pr98772.c 
b/gcc/testsuite/gcc.target/aarch64/pr98772.c
index 663221514e9..8259251a7c0 100644
--- a/gcc/testsuite/gcc.target/aarch64/pr98772.c
+++ b/gcc/testsuite/gcc.target/aarch64/pr98772.c
@@ -1,5 +1,8 @@
 /* { dg-do run } */
 /* { dg-options "-O3 -save-temps" } */
+
+#pragma GCC target "+nosve"
+
 #include 
 #include 
 
diff --git a/gcc/testsuite/gcc.target/aarch64/simd/vect_su_add_sub.c 
b/gcc/testsuite/gcc.target/aarch64/simd/vect_su_add_sub.c
index 921c5f15c74..4abb8e92cb4 100644
--- a/gcc/testsuite/gcc.target/aarch64/simd/vect_su_add_sub.c
+++ b/gcc/testsuite/gcc.target/aarch64/simd/vect_su_add_sub.c
@@ -1,6 +1,8 @@
 /* { dg-do compile } */
 /* { dg-options "-O3" } */
 
+#pragma GCC target "+nosve"
+
 typedef int __attribute__ ((mode (SI))) int32_t;
 typedef int __attribute__ ((mode (DI))) int64_t;
 typedef unsigned __attribute__ ((mode (SI))) size_t;


[committed] testsuite: Update error messages in sve/acle/general-c

2021-04-08 Thread Richard Sandiford via Gcc-patches
The “previous definition of 'x'” notes now include the type
of the original definition before “was here”.  There's not really
any need to hard-code that much of the message in the ACLE tests,
so this patch just removes the “was here” from the match string.

Tested on aarch64-linux-gnu, pushed to trunk.

Richard


gcc/testsuite/
* gcc.target/aarch64/sve/acle/general-c/func_redef_1.c: Remove
"was here" from error message.
* gcc.target/aarch64/sve/acle/general-c/func_redef_2.c: Likewise.
* gcc.target/aarch64/sve/acle/general-c/func_redef_3.c: Likewise.
* gcc.target/aarch64/sve/acle/general-c/func_redef_6.c: Likewise.
* gcc.target/aarch64/sve/acle/general-c/type_redef_1.c: Likewise.
* gcc.target/aarch64/sve/acle/general-c/type_redef_2.c: Likewise.
* gcc.target/aarch64/sve/acle/general-c/type_redef_3.c: Likewise.
* gcc.target/aarch64/sve/acle/general-c/type_redef_4.c: Likewise.
* gcc.target/aarch64/sve/acle/general-c/type_redef_5.c: Likewise.
* gcc.target/aarch64/sve/acle/general-c/type_redef_6.c: Likewise.
* gcc.target/aarch64/sve/acle/general-c/type_redef_8.c: Likewise.
* gcc.target/aarch64/sve/acle/general-c/type_redef_9.c: Likewise.
* gcc.target/aarch64/sve/acle/general-c/type_redef_10.c: Likewise.
* gcc.target/aarch64/sve/acle/general-c/type_redef_13.c: Likewise.
---
 .../gcc.target/aarch64/sve/acle/general-c/func_redef_1.c| 2 +-
 .../gcc.target/aarch64/sve/acle/general-c/func_redef_2.c| 2 +-
 .../gcc.target/aarch64/sve/acle/general-c/func_redef_3.c| 2 +-
 .../gcc.target/aarch64/sve/acle/general-c/func_redef_6.c| 2 +-
 .../gcc.target/aarch64/sve/acle/general-c/type_redef_1.c| 2 +-
 .../gcc.target/aarch64/sve/acle/general-c/type_redef_10.c   | 2 +-
 .../gcc.target/aarch64/sve/acle/general-c/type_redef_13.c   | 2 +-
 .../gcc.target/aarch64/sve/acle/general-c/type_redef_2.c| 2 +-
 .../gcc.target/aarch64/sve/acle/general-c/type_redef_3.c| 2 +-
 .../gcc.target/aarch64/sve/acle/general-c/type_redef_4.c| 2 +-
 .../gcc.target/aarch64/sve/acle/general-c/type_redef_5.c| 2 +-
 .../gcc.target/aarch64/sve/acle/general-c/type_redef_6.c| 2 +-
 .../gcc.target/aarch64/sve/acle/general-c/type_redef_8.c| 2 +-
 .../gcc.target/aarch64/sve/acle/general-c/type_redef_9.c| 2 +-
 14 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/gcc/testsuite/gcc.target/aarch64/sve/acle/general-c/func_redef_1.c 
b/gcc/testsuite/gcc.target/aarch64/sve/acle/general-c/func_redef_1.c
index e1b99fa361b..33ed8f7a34a 100644
--- a/gcc/testsuite/gcc.target/aarch64/sve/acle/general-c/func_redef_1.c
+++ b/gcc/testsuite/gcc.target/aarch64/sve/acle/general-c/func_redef_1.c
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
 
-int svadd_n_u8_x; /* { dg-message "note: previous declaration of 
'svadd_n_u8_x' was here" } */
+int svadd_n_u8_x; /* { dg-message "note: previous declaration of 
'svadd_n_u8_x'" } */
 
 #pragma GCC aarch64 "arm_sve.h"  /* { dg-error {'svadd_n_u8_x' redeclared} } */
diff --git a/gcc/testsuite/gcc.target/aarch64/sve/acle/general-c/func_redef_2.c 
b/gcc/testsuite/gcc.target/aarch64/sve/acle/general-c/func_redef_2.c
index 7f653f1173f..67996683a15 100644
--- a/gcc/testsuite/gcc.target/aarch64/sve/acle/general-c/func_redef_2.c
+++ b/gcc/testsuite/gcc.target/aarch64/sve/acle/general-c/func_redef_2.c
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
 
-int svadd_n_u8_x = 1; /* { dg-message "note: previous definition of 
'svadd_n_u8_x' was here" } */
+int svadd_n_u8_x = 1; /* { dg-message "note: previous definition of 
'svadd_n_u8_x'" } */
 
 #pragma GCC aarch64 "arm_sve.h"  /* { dg-error {'svadd_n_u8_x' redeclared} } */
diff --git a/gcc/testsuite/gcc.target/aarch64/sve/acle/general-c/func_redef_3.c 
b/gcc/testsuite/gcc.target/aarch64/sve/acle/general-c/func_redef_3.c
index d9ff15a6c3c..41988b27c81 100644
--- a/gcc/testsuite/gcc.target/aarch64/sve/acle/general-c/func_redef_3.c
+++ b/gcc/testsuite/gcc.target/aarch64/sve/acle/general-c/func_redef_3.c
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
 
-extern __SVInt8_t svadd_u8_x (__SVBool_t, __SVInt8_t, __SVInt8_t); /* { 
dg-message "note: previous declaration of 'svadd_u8_x' was here" } */
+extern __SVInt8_t svadd_u8_x (__SVBool_t, __SVInt8_t, __SVInt8_t); /* { 
dg-message "note: previous declaration of 'svadd_u8_x'" } */
 
 #pragma GCC aarch64 "arm_sve.h"  /* { dg-error {conflicting types for 
'svadd_u8_x'} } */
diff --git a/gcc/testsuite/gcc.target/aarch64/sve/acle/general-c/func_redef_6.c 
b/gcc/testsuite/gcc.target/aarch64/sve/acle/general-c/func_redef_6.c
index 1f04e464449..01d1ca7ec7d 100644
--- a/gcc/testsuite/gcc.target/aarch64/sve/acle/general-c/func_redef_6.c
+++ b/gcc/testsuite/gcc.target/aarch64/sve/acle/general-c/func_redef_6.c
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
 
-typedef int svadd_u8_x; /* { dg-message "note: previous declaration of 
'svadd_u8_x' was here" } */
+typed

[committed] testsuite: Fix gcc.dg/vect/pr99102.c

2021-04-08 Thread Richard Sandiford via Gcc-patches
pr99102.c needs to override the default options to exercise the original
problem, but that means that it also needs to respecify the dump flags.

Tested on aarch64-linux-gnu, pushed to trunk as obvious.

Richard


gcc/testsuite/
* gcc.dg/vect/pr99102.c: Add -fdump-tree-vect-details.
---
 gcc/testsuite/gcc.dg/vect/pr99102.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/testsuite/gcc.dg/vect/pr99102.c 
b/gcc/testsuite/gcc.dg/vect/pr99102.c
index 62d4d333c67..6c1a13f0783 100644
--- a/gcc/testsuite/gcc.dg/vect/pr99102.c
+++ b/gcc/testsuite/gcc.dg/vect/pr99102.c
@@ -1,4 +1,4 @@
-/* { dg-options "-O2 -ftree-vectorize" } */
+/* { dg-options "-O2 -ftree-vectorize -fdump-tree-vect-details" } */
 /* { dg-additional-options "-msve-vector-bits=256" { target aarch64_sve256_hw 
} } */
 long a[44];
 short d, e = -7;


[PATCH] match.pd: Fix sve/vcond_3.c

2021-04-08 Thread Richard Sandiford via Gcc-patches
The sve/vcond_3.c tests had started to fail after PR97690/99305,
because we were generating:

  a = VEC_COND_EXPR ;
  b = a << 15;

instead of:

  a = VEC_COND_EXPR ;

We already have a match.pd rule to handle this kind of thing,
but it didn't handle shifts.

Tested on aarch64-linux-gnu.  OK to install?

Richard


gcc/
* match.pd: Extend vec_cond folds to handle shifts.
---
 gcc/match.pd | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/match.pd b/gcc/match.pd
index 036f92fa959..3ffd9a62670 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -3646,7 +3646,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
 
 /* Sink binary operation to branches, but only if we can fold it.  */
 (for op (tcc_comparison plus minus mult bit_and bit_ior bit_xor
-rdiv trunc_div ceil_div floor_div round_div
+lshift rshift rdiv trunc_div ceil_div floor_div round_div
 trunc_mod ceil_mod floor_mod round_mod min max)
 /* (c ? a : b) op (c ? d : e)  -->  c ? (a op d) : (b op e) */
  (simplify


[PATCH] testsuite: Add -mbig-endian stdint.h requirement

2021-04-08 Thread Richard Sandiford via Gcc-patches
Some AArch64 tests force -mbig-endian and indirectly include stdint.h.
However, not all OSes support both endiannesses, leading to:

FAIL: gcc.target/aarch64/advsimd-intrinsics/bf16_get-be.c   -O0  (test for 
excess errors)
UNRESOLVED: gcc.target/aarch64/advsimd-intrinsics/bf16_get-be.c   -O1   
check-function-bodies test_vget_high_bf16
UNRESOLVED: gcc.target/aarch64/advsimd-intrinsics/bf16_get-be.c   -O1   
check-function-bodies test_vget_low_bf16

etc.  This patch adds an (admittedly special-purpose) target
selector for this.

Tested on aarch64-linux-gnu.  It doesn't really count as AArch64-specific
so: OK to install?

Richard


gcc/
* doc/sourcebuild.texi (stdint_types_mbig_endian): Document.

gcc/testsuite/
* lib/target-supports.exp
(check_effective_target_stdint_types_mbig_endian): New proc.
* gcc.target/aarch64/advsimd-intrinsics/bf16_get-be.c: Require
stdint_types_mbig_endian.
* gcc.target/aarch64/advsimd-intrinsics/bfdot-2.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vdot-3-2.c: Likewise.
---
 gcc/doc/sourcebuild.texi |  4 
 .../aarch64/advsimd-intrinsics/bf16_get-be.c |  1 +
 .../gcc.target/aarch64/advsimd-intrinsics/bfdot-2.c  |  1 +
 .../gcc.target/aarch64/advsimd-intrinsics/vdot-3-2.c |  1 +
 gcc/testsuite/lib/target-supports.exp| 12 
 5 files changed, 19 insertions(+)

diff --git a/gcc/doc/sourcebuild.texi b/gcc/doc/sourcebuild.texi
index 0104916e660..b0001247795 100644
--- a/gcc/doc/sourcebuild.texi
+++ b/gcc/doc/sourcebuild.texi
@@ -2447,6 +2447,10 @@ Target has the basic signed and unsigned C types in 
@code{stdint.h}.
 This will be obsolete when GCC ensures a working @code{stdint.h} for
 all targets.
 
+@item stdint_types_mbig_endian
+Target accepts the option @option{-mbig-endian} and @code{stdint.h}
+can be included without error when @option{-mbig-endian} is passed.
+
 @item stpcpy
 Target provides @code{stpcpy} function.
 
diff --git a/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/bf16_get-be.c 
b/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/bf16_get-be.c
index bd9bb110974..cd27098e63e 100644
--- a/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/bf16_get-be.c
+++ b/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/bf16_get-be.c
@@ -1,4 +1,5 @@
 /* { dg-do assemble { target { aarch64*-*-* } } } */
+/* { dg-require-effective-target stdint_types_mbig_endian } */
 /* { dg-require-effective-target arm_v8_2a_bf16_neon_ok } */
 /* { dg-add-options arm_v8_2a_bf16_neon } */
 /* { dg-additional-options "-mbig-endian -save-temps" } */
diff --git a/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/bfdot-2.c 
b/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/bfdot-2.c
index 58bdee5ac9d..ae0a953f7b4 100755
--- a/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/bfdot-2.c
+++ b/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/bfdot-2.c
@@ -1,4 +1,5 @@
 /* { dg-do assemble { target { aarch64*-*-* } } } */
+/* { dg-require-effective-target stdint_types_mbig_endian } */
 /* { dg-require-effective-target arm_v8_2a_bf16_neon_ok } */
 /* { dg-add-options arm_v8_2a_bf16_neon }  */
 /* { dg-additional-options "-mbig-endian --save-temps" } */
diff --git a/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/vdot-3-2.c 
b/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/vdot-3-2.c
index 96bca2356e4..61c7c51f5ec 100755
--- a/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/vdot-3-2.c
+++ b/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/vdot-3-2.c
@@ -1,4 +1,5 @@
 /* { dg-do assemble { target { aarch64*-*-* } } } */
+/* { dg-require-effective-target stdint_types_mbig_endian } */
 /* { dg-require-effective-target arm_v8_2a_i8mm_ok } */
 /* { dg-add-options arm_v8_2a_i8mm }  */
 /* { dg-additional-options "-mbig-endian -save-temps" } */
diff --git a/gcc/testsuite/lib/target-supports.exp 
b/gcc/testsuite/lib/target-supports.exp
index 1230d194215..ad323107f2e 100644
--- a/gcc/testsuite/lib/target-supports.exp
+++ b/gcc/testsuite/lib/target-supports.exp
@@ -8254,6 +8254,18 @@ proc check_effective_target_stdint_types { } {
 }]
 }
 
+# Like check_effective_target_stdint_types, but test what happens when
+# -mbig-endian is passed.  This test only makes sense on targets that
+# support -mbig-endian; it will fail elsewhere.
+
+proc check_effective_target_stdint_types_mbig_endian { } {
+return [check_no_compiler_messages stdint_types_mbig_endian assembly {
+   #include 
+   int8_t a; int16_t b; int32_t c; int64_t d;
+   uint8_t e; uint16_t f; uint32_t g; uint64_t h;
+} "-mbig-endian"]
+}
+
 # Return 1 if target has the basic signed and unsigned types in
 # , 0 otherwise.  This is for tests that GCC's notions of
 # these types agree with those in the header, as some systems have


[PATCH] testsuite: Update scan-lto-assembler

2021-04-08 Thread Richard Sandiford via Gcc-patches
scan-lto-assembler was looking for the old dump names instead of
the new ones.  There are only two uses of this:

gcc.target/nios2/custom-fp-lto.c
gcc.target/aarch64/pr70044.c

Both of them use single source files, so I think they both want
the same behaviour.

Tested on aarch64-linux-gnu.  OK to install?

Richard


gcc/testsuite/
* lib/scanasm.exp (scan-lto-assembler): Update expected name
of dump file.
---
 gcc/testsuite/lib/scanasm.exp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/testsuite/lib/scanasm.exp b/gcc/testsuite/lib/scanasm.exp
index e7236087a75..0dcb893ec4f 100644
--- a/gcc/testsuite/lib/scanasm.exp
+++ b/gcc/testsuite/lib/scanasm.exp
@@ -754,7 +754,7 @@ proc scan-lto-assembler { args } {
 set testcase [testname-for-summary]
 # The name might include a list of options; extract the file name.
 set filename [lindex $testcase 0]
-set output_file "[file rootname [file tail $filename]].exe.ltrans0.s"
+set output_file "[file rootname [file tail $filename]].ltrans0.ltrans.s"
 verbose "output_file: $output_file"
 dg-scan "scan-lto-assembler" 1 $testcase $output_file $args
 }


Re: [PATCH] c++: Don't cache constexpr functions which are passed pointers to heap or static vars being constructed [PR99859]

2021-04-08 Thread Jason Merrill via Gcc-patches

On 4/8/21 5:36 AM, Jakub Jelinek wrote:

When cxx_bind_parameters_in_call is called e.g. on a method on an automatic
variable, we evaluate the argument and because ADDR_EXPR of an automatic
decl is not TREE_CONSTANT, we set *non_constant_args and don't cache it.
But when it is called on an object located on the heap (allocated using
C++20 constexpr new) where we represent it as TREE_STATIC artificial
var, or when it is called on a static var that is currently being
constructed, such ADDR_EXPRs are TREE_CONSTANT and we happily cache
such calls, but they can in those cases have side-effects in the heap
or static var objects and so caching them means such side-effects will
happen only once and not as many times as that method or function is called.
Furthermore, as Patrick mentioned in the PR, the argument doesn't need to be
just ADDR_EXPR of the heap or static var or its components, but it could be
a CONSTRUCTOR that has the ADDR_EXPR embedded anywhere.



The following patch fixes it by setting *non_constant_args also when
the argument contains somewhere such an ADDR_EXPR, either of a heap
artificial var or component thereof, or of a static var currently being
constructed (where for that it uses the same check as
cxx_eval_store_expression, ctx->global->values.get (...); addresses of
other static variables would be rejected by cxx_eval_store_expression
and therefore it is ok to cache such calls).

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2021-04-08  Jakub Jelinek  

PR c++/99859
* constexpr.c (addr_of_non_const_var): New function.
(cxx_bind_parameters_in_call): Set *non_constant_args to true
even if cp_walk_tree on arg with addr_of_non_const_var callback
returns true.

* g++.dg/cpp1y/constexpr-99859.C: New test.
* g++.dg/cpp2a/constexpr-new18.C: New test.
* g++.dg/cpp2a/constexpr-new19.C: New test.

--- gcc/cp/constexpr.c.jj   2021-04-07 15:50:32.274927848 +0200
+++ gcc/cp/constexpr.c  2021-04-07 18:21:20.845684670 +0200
@@ -1555,6 +1555,32 @@ free_constructor (tree t)
  }
  }
  
+/* Helper function of cxx_bind_parameters_in_call.  Return non-NULL

+   if *TP is address of a static variable (or part of it) currently being
+   constructed or of a heap artificial variable.  */



+static tree
+addr_of_non_const_var (tree *tp, int *walk_subtrees, void *data)
+{
+  if (TREE_CODE (*tp) == ADDR_EXPR)
+if (tree var = get_base_address (TREE_OPERAND (*tp, 0)))
+  if (VAR_P (var) && TREE_STATIC (var))
+   {
+ if (DECL_NAME (var) == heap_uninit_identifier
+ || DECL_NAME (var) == heap_identifier
+ || DECL_NAME (var) == heap_vec_uninit_identifier
+ || DECL_NAME (var) == heap_vec_identifier)
+   return var;
+
+ constexpr_global_ctx *global = (constexpr_global_ctx *) data;
+ if (global->values.get (var))
+   return var;
+   }
+  if (TYPE_P (*tp))
+*walk_subtrees = false;
+  return NULL_TREE;
+}
+
  /* Subroutine of cxx_eval_call_expression.
 We are processing a call expression (either CALL_EXPR or
 AGGR_INIT_EXPR) in the context of CTX.  Evaluate
@@ -1616,6 +1642,14 @@ cxx_bind_parameters_in_call (const const
/* The destructor needs to see any modifications the callee makes
   to the argument.  */
*non_constant_args = true;
+   /* If arg is or contains address of a heap artificial variable or
+  of a static variable being constructed, avoid caching the
+  function call, as those variables might be modified by the
+  function.  */


We don't want to cache even if the call only reads from the variable, 
because the result might depend on a value that can be changed in the 
caller:


struct A
{
  int i;
  constexpr int f() { return i; }
  constexpr A() :
i(0) {
f();
i = 1;
i = f();
  }
};

constexpr A a = A();
static_assert (a.i == 1, "");

OK with this comment adjustment, and adding this case to the tests.


+ else if (!*non_constant_args
+  && cp_walk_tree (&arg, addr_of_non_const_var, ctx->global,
+   NULL))
+   *non_constant_args = true;
  
  	  /* For virtual calls, adjust the this argument, so that it is

 the object on which the method is called, rather than
--- gcc/testsuite/g++.dg/cpp1y/constexpr-99859.C.jj 2021-04-07 
19:15:12.488877570 +0200
+++ gcc/testsuite/g++.dg/cpp1y/constexpr-99859.C2021-04-07 
19:15:33.796641707 +0200
@@ -0,0 +1,24 @@
+// PR c++/99859
+// { dg-do compile { target c++14 } }
+
+constexpr int
+foo (int *x)
+{
+  return ++*x;
+}
+
+struct S { constexpr S () : a(0) { foo (&a); foo (&a); } int a; };
+constexpr S s = S ();
+static_assert (s.a == 2, "");
+
+struct R { int *p; };
+
+constexpr int
+bar (R x)
+{
+  return ++*x.p;
+}
+
+struct T { int a = 0; constexpr T () { bar (R{&a}); bar (R{&a}); } };
+constexpr T t =

Re: [PATCH] c++: constrained CTAD for nested class template [PR97679]

2021-04-08 Thread Jason Merrill via Gcc-patches

On 4/7/21 5:33 PM, Patrick Palka wrote:

In the testcase below, we're crashing during constraint checking of the
implicitly generated deduction guides for the nested class template A::B
because we never substitute the outer template arguments (for A) into
the constraint, neither ahead of time nor as part of satisfaction.

Ideally we'd like to avoid substituting into a constraint ahead of
time, but the "flattening" vector 'tsubst_args' is constructed under the
assumption that all outer template arguments are already substituted in,
and eliminating this assumption to yield a flattening vector that
includes outer (generic) template arguments suitable for substituting
into the constraint would be tricky.  So this patch takes the
approximate approach of substituting the outer arguments into the
constraint ahead of time, so that we could subsequently substitute
'tsubst_args' into the constraint.


This seems reasonable, and related to the substitution needed for 
http://wg21.link/p2103#ca104 , though in this case the substitution 
could be avoided.



NB: I noticed that [over.match.class.deduct]/1, which describes how
guides are formed from constructors of a class template, doesn't mention
that a guide inherits the constraints of the corresponding constructor.
Though [over.match.class.deduct]/2 later suggests that guides do have
constraints: "The associated constraints [of f'] are the conjunction of
the associated constraints of [the guide] g and ..."  So I'm unsure if
we're being conforming by giving guides the constraints of the
corresponding constructor.


I think propagating the constraints is necessary, or deduction would do 
the wrong thing for constructors that try to exclude problematic arguments.



Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for
trunk and 10 branch (after 10.3 is released)?


OK.  Please also document outer_args in the comment for the function.


gcc/cp/ChangeLog:

PR c++/97679
* pt.c (build_deduction_guide): Substitute outer template
arguments into the constraints.

gcc/testsuite/ChangeLog:

PR c++/97679
* g++.dg/cpp2a/concepts-ctad3.C: New test.
---
  gcc/cp/pt.c | 17 +++--
  gcc/testsuite/g++.dg/cpp2a/concepts-ctad3.C | 16 
  2 files changed, 31 insertions(+), 2 deletions(-)
  create mode 100644 gcc/testsuite/g++.dg/cpp2a/concepts-ctad3.C

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 7917a280804..6f44199e8eb 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -28719,7 +28719,15 @@ build_deduction_guide (tree type, tree ctor, tree 
outer_args, tsubst_flags_t com
  if (fparms == error_mark_node)
ok = false;
  if (ci)
-   ci = tsubst_constraint_info (ci, tsubst_args, complain, ctor);
+   {
+ if (outer_args)
+   /* FIXME: We'd like to avoid substituting outer template
+  arguments into the constraint ahead of time, but the
+  construction of tsubst_args assumes that outer arguments
+  are already substituted in.  */
+   ci = tsubst_constraint_info (ci, outer_args, complain, ctor);
+ ci = tsubst_constraint_info (ci, tsubst_args, complain, ctor);
+   }
  
  	  /* Parms are to have DECL_CHAIN tsubsted, which would be skipped if

 cp_unevaluated_operand.  */
@@ -28735,7 +28743,12 @@ build_deduction_guide (tree type, tree ctor, tree 
outer_args, tsubst_flags_t com
  fparms = tsubst_arg_types (fparms, targs, NULL_TREE, complain, ctor);
  fargs = tsubst (fargs, targs, complain, ctor);
  if (ci)
-   ci = tsubst_constraint_info (ci, targs, complain, ctor);
+   {
+ if (outer_args)
+   /* FIXME: As above.  */
+   ci = tsubst_constraint_info (ci, outer_args, complain, ctor);
+ ci = tsubst_constraint_info (ci, targs, complain, ctor);
+   }
}
  
--processing_template_decl;

diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-ctad3.C 
b/gcc/testsuite/g++.dg/cpp2a/concepts-ctad3.C
new file mode 100644
index 000..3546b7461a8
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/concepts-ctad3.C
@@ -0,0 +1,16 @@
+// PR c++/97679
+// { dg-do compile { target c++20 } }
+
+template  struct A {
+  template  struct B {
+B(T) requires V;
+template  B(T, U) requires V || (__is_same(T, char) && 
__is_same(U, int));
+  };
+};
+
+A::B x1(0);
+A::B x2(0); // { dg-error "deduction|no match" }
+
+A::B y1(0, '0');
+A::B y2(0, '0'); // { dg-error "deduction|no match" }
+A::B y3('0', 0);





[committed] libstdc++: Address remaining to_chars/long_double.cc FAILs [PR98384]

2021-04-08 Thread Patrick Palka via Gcc-patches
This works around the remaining reported execution FAILs of this test on
AIX, Solaris and Darwin.  Eventually we should rewrite this test to be
less fragile, but there's not enough time to do that for GCC 11.

Tested on AIX, Solaris and x86_64-pc-linux-gnu, committed to trunk as
"obvious".

libstdc++-v3/ChangeLog:

PR libstdc++/98384
* testsuite/20_util/to_chars/long_double.cc: Don't run the test
on targets without a large long double.  XFAIL the execution on
targets with a non-conforming printf.
---
 .../testsuite/20_util/to_chars/long_double.cc  | 18 +-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/libstdc++-v3/testsuite/20_util/to_chars/long_double.cc 
b/libstdc++-v3/testsuite/20_util/to_chars/long_double.cc
index 5c1f7136f21..22d42067d65 100644
--- a/libstdc++-v3/testsuite/20_util/to_chars/long_double.cc
+++ b/libstdc++-v3/testsuite/20_util/to_chars/long_double.cc
@@ -17,7 +17,23 @@
 
 //  is supported in C++14 as a GNU extension, but this test uses 
C++17
 // hexadecimal floating-point literals.
-// { dg-do run { target c++17 } }
+
+// When long double is larger than double, the long double to_chars overloads
+// are partially implemented in terms of printf, so this test in turn uses
+// printf to verify correctness these overloads.
+// When long double == double, the long double to_chars overloads are simple
+// wrappers around the corresponding double overloads.  Since they don't go
+// through printf, we can't portably verify their output by comparing it with
+// that of printf, so it's simplest to just not run this test on such targets;
+// correctness of these overloads is already implied by that of the double
+// overloads.
+// { dg-do run { target { c++17 && large_long_double } } }
+// { dg-do compile { target { c++17 && { ! large_long_double } } } }
+
+// The system printf on these targets appear to be buggy.  FIXME: Make this 
test
+// more portable and robust to differences in system printf behavior.
+// { dg-xfail-run-if "Non-conforming printf (see PR98384)" { *-*-solaris* 
*-*-darwin* } }
+
 // { dg-require-effective-target ieee-floats }
 
 #include 
-- 
2.31.1.189.g2e36527f23



Re: [PATCH] testsuite: Update scan-lto-assembler

2021-04-08 Thread Jeff Law via Gcc-patches



On 4/8/2021 8:09 AM, Richard Sandiford via Gcc-patches wrote:

scan-lto-assembler was looking for the old dump names instead of
the new ones.  There are only two uses of this:

 gcc.target/nios2/custom-fp-lto.c
 gcc.target/aarch64/pr70044.c

Both of them use single source files, so I think they both want
the same behaviour.

Tested on aarch64-linux-gnu.  OK to install?

Richard


gcc/testsuite/
* lib/scanasm.exp (scan-lto-assembler): Update expected name
of dump file.


OK

jeff



Re: [PATCH] testsuite: Add -mbig-endian stdint.h requirement

2021-04-08 Thread Jeff Law via Gcc-patches



On 4/8/2021 8:08 AM, Richard Sandiford via Gcc-patches wrote:

Some AArch64 tests force -mbig-endian and indirectly include stdint.h.
However, not all OSes support both endiannesses, leading to:

FAIL: gcc.target/aarch64/advsimd-intrinsics/bf16_get-be.c   -O0  (test for 
excess errors)
UNRESOLVED: gcc.target/aarch64/advsimd-intrinsics/bf16_get-be.c   -O1   
check-function-bodies test_vget_high_bf16
UNRESOLVED: gcc.target/aarch64/advsimd-intrinsics/bf16_get-be.c   -O1   
check-function-bodies test_vget_low_bf16

etc.  This patch adds an (admittedly special-purpose) target
selector for this.

Tested on aarch64-linux-gnu.  It doesn't really count as AArch64-specific
so: OK to install?

Richard


gcc/
* doc/sourcebuild.texi (stdint_types_mbig_endian): Document.

gcc/testsuite/
* lib/target-supports.exp
(check_effective_target_stdint_types_mbig_endian): New proc.
* gcc.target/aarch64/advsimd-intrinsics/bf16_get-be.c: Require
stdint_types_mbig_endian.
* gcc.target/aarch64/advsimd-intrinsics/bfdot-2.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vdot-3-2.c: Likewise.


OK

jeff



Re: [PATCH] match.pd: Fix sve/vcond_3.c

2021-04-08 Thread Jeff Law via Gcc-patches



On 4/8/2021 8:06 AM, Richard Sandiford via Gcc-patches wrote:

The sve/vcond_3.c tests had started to fail after PR97690/99305,
because we were generating:

   a = VEC_COND_EXPR ;
   b = a << 15;

instead of:

   a = VEC_COND_EXPR ;

We already have a match.pd rule to handle this kind of thing,
but it didn't handle shifts.

Tested on aarch64-linux-gnu.  OK to install?

Richard


gcc/
* match.pd: Extend vec_cond folds to handle shifts.


OK

jeff



Re: [patch for gcc12 stage1][version 2] add -ftrivial-auto-var-init and variable attribute "uninitialized" to gcc

2021-04-08 Thread Qing Zhao via Gcc-patches
Hi, Kees,

Thanks a lot for your testing on the linux kernel, I am so happy that this time 
it works well.

> On Apr 7, 2021, at 5:19 PM, Kees Cook  wrote:
> 
> On Wed, Mar 24, 2021 at 04:21:49PM -0500, Qing Zhao wrote:
>> This is the 2nd version of the patch for the new security feature for GCC.
>> 
>> Could you please take a look at it and let me know any comments and issues.
> 
> This behaves perfectly as far as I'm able to test in the Linux kernel!
> Thank you!
> 
> For comparison to v1, here's the stack init test output for version 2 of the 
> patch:
> 
> test_stackinit: u8_zero ok
> test_stackinit: u16_zero ok
> test_stackinit: u32_zero ok
> test_stackinit: u64_zero ok
> test_stackinit: char_array_zero ok
> test_stackinit: small_hole_zero ok
> test_stackinit: big_hole_zero ok
> test_stackinit: trailing_hole_zero ok
> test_stackinit: packed_zero ok
> test_stackinit: small_hole_dynamic_partial ok
> test_stackinit: big_hole_dynamic_partial ok
> test_stackinit: trailing_hole_dynamic_partial ok
> test_stackinit: packed_dynamic_partial ok
> test_stackinit: small_hole_static_partial ok
> test_stackinit: big_hole_static_partial ok
> test_stackinit: trailing_hole_static_partial ok
> test_stackinit: packed_static_partial ok
> test_stackinit: small_hole_static_all ok
> test_stackinit: big_hole_static_all ok
> test_stackinit: trailing_hole_static_all ok
> test_stackinit: packed_static_all ok
> test_stackinit: small_hole_dynamic_all ok
> test_stackinit: big_hole_dynamic_all ok
> test_stackinit: trailing_hole_dynamic_all ok
> test_stackinit: packed_dynamic_all ok
> test_stackinit: small_hole_runtime_partial ok
> test_stackinit: big_hole_runtime_partial ok
> test_stackinit: trailing_hole_runtime_partial ok
> test_stackinit: packed_runtime_partial ok
> test_stackinit: small_hole_runtime_all ok
> test_stackinit: big_hole_runtime_all ok
> test_stackinit: trailing_hole_runtime_all ok
> test_stackinit: packed_runtime_all ok
> test_stackinit: u8_none ok
> test_stackinit: u16_none ok
> test_stackinit: u32_none ok
> test_stackinit: u64_none ok
> test_stackinit: char_array_none ok
> test_stackinit: switch_1_none XFAIL (uninit bytes: 8)
> test_stackinit: switch_2_none XFAIL (uninit bytes: 8)
> test_stackinit: small_hole_none ok
> test_stackinit: big_hole_none ok
> test_stackinit: trailing_hole_none ok
> test_stackinit: packed_none ok
> test_stackinit: user ok
> test_stackinit: all tests passed!
> 
> The switch cases are an "expected fail" still, and that's totally fine
> for now[1]. Those were all purged from real kernel code anyway. ;)
> 
> So that's a big "Ack" from me. :)
> 
> What are next steps for this patch?

My understanding is, it needs to be reviewed and get approved by the global 
reviewers first, 
Currently, I am waiting for any comments from global reviewers in order to be 
able to push 
this patch into gcc12 as early as possible. 

> I know a lot of people are looking
> forward to it. (And then long-open bug[2] for auto-init can be closed.)
> 
> Thanks again!

Thank you!


Qing
> 
> -Kees
> 
> [1] Clang doesn't handle this either 
> https://bugs.llvm.org/show_bug.cgi?id=44916 
> 
> [2] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87210 
> 
> 
>> 
>> Thanks.
>> 
>> Qing
>> 
>> **compared to Version 1, this version added the following new features 
>> to address Kees’s comments:
>> 
>> 1.  correctly handle VLA inside a structure for pattern initialization.
>> In tree.c (build_pattern_cst):
>> 
>> +   /* if the field is a variable length array, it should be the last
>> +  field of the record, and no need to initialize.  */
>> +   if (TREE_CODE (TREE_TYPE (field)) == ARRAY_TYPE
>> +   && TYPE_SIZE (TREE_TYPE (field)) == NULL_TREE
>> +   && ((TYPE_DOMAIN (TREE_TYPE (field)) != NULL_TREE
>> +   && TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field)))
>> +  == NULL_TREE)
>> +  || TYPE_DOMAIN (TREE_TYPE (field)) == NULL_TREE))
>> + continue;
>> 
>> 2.  initialize all paddings to zero when -ftrivial-auto-var-init is present.
>> In expr.c (store_constructor):
>> 
>>  Clear the whole structure when
>>-ftrivial-auto-var-init and the structure has paddings.
>> 
>> In gimplify.c (gimplify_init_constructor):
>> 
>>  Clear the whole structure when
>>-ftrivial-auto-var-init and the structure has paddings.
>> 
>> As agreed with Kees, treat the issue related to auto variables outside of 
>> the cases and inside the switch as a low priority one. 
>> 
>> 3. Add  the following new testing cases for the above 1 and 2:
>> 
>>* c-c++-common/auto-init-13.c: New test.
>>* c-c++-common/auto-init-14.c: New test. 
>> 
>>  * gcc.target/aarch64/auto-init-9.c: New test.
>>  * gcc.target/aarch64/auto-init-10.c: New test.
>>* gcc.target/aarch64/auto-init-11.c: New te

Re: [PATCH] c++: Don't substitute into constraints on lambdas [PR99874]

2021-04-08 Thread Jason Merrill via Gcc-patches

On 4/7/21 12:10 PM, Patrick Palka wrote:

We currently substitute through a lambda's constraints whenever we
regenerate it via tsubst_lambda_expr.  This is the wrong approach
because it can lead to hard errors due to constraints being evaluated
out of order (as in the testcase concepts-lambda17.C below), and because
it doesn't mesh well with the recently added REQUIRES_EXPR_EXTRA_ARGS
mechanism for delaying substitution into requires-expressions, which is
the cause of this PR.

But in order to avoid substituting through a lambda's constraints during
regeneration, we we need to be able to get at all in-scope template
parameters and the corresponding template arguments during constraint
checking of a lambda's op().  And this information is not easily
available where we need it, it seems.

To that end, the approach that this patch takes is to add two new fields
to LAMBDA_EXPR (and remove one): LAMBDA_EXPR_REGENERATED_FROM
(replacing LAMBDA_EXPR_INSTANTIATED), and LAMBDA_EXPR_REGENERATING_TARGS.
The former allows us to obtain the complete set of template parameters
that are in-scope for a lambda's op(), and the latter gives us all outer
template arguments that were used to regenerate the lambda.


I'm a little surprised you didn't use a TEMPLATE_INFO for these, but 
this way is fine too.



LAMBDA_EXPR_REGENERATING_TARGS is not strictly necessary -- in an
earlier version of the patch, I walked LAMBDA_EXPR_EXTRA_SCOPE to build
up this set of outer template arguments on demand, but it's cleaner to
do it this way.  (We'd need to walk LAMBDA_EXPR_EXTRA_SCOPE and not
DECL/TYPE_CONTEXT because the latter skips over variable template
scopes.)

This patch also renames the predicate instantiated_lambda_fn_p to
regenerated_lambda_fn_p, for sake of consistency with the rest of the
patch which uses "regenerated" instead of "instantiated".

Bootstrapped and regtested on x86_64-pc-linux-gnu, and also tested on
cmcstl2 and range-v3.  Does this look OK for trunk?


OK.


gcc/cp/ChangeLog:

PR c++/99874
* constraint.cc (get_normalized_constraints_from_decl): Handle
regenerated lambdas.
(satisfy_declaration_constraints): Likewise.  Check for
dependent args later.
* cp-tree.h (LAMBDA_EXPR_INSTANTIATED): Replace with ...
(LAMBDA_EXPR_REGENERATED_FROM): ... this.
(LAMBDA_EXPR_REGENERATING_TARGS): New.
(tree_lambda_expr::regenerated_from): New data member.
(tree_lambda_expr::regenerating_targs): New data member.
(add_to_template_args): Declare.
(regenerated_lambda_fn_p): Likewise.
(most_general_lambda): Likewise.
* lambda.c (build_lambda_expr): Set LAMBDA_EXPR_REGENERATED_FROM
and LAMBDA_EXPR_REGENERATING_TARGS.
* pt.c (add_to_template_args): No longer static.
(tsubst_function_decl): Unconditionally propagate constraints on
the substituted function decl.
(instantiated_lambda_fn_p): Rename to ...
(regenerated_lambda_fn_p): ... this.  Check
LAMBDA_EXPR_REGENERATED_FROM instead of
LAMBDA_EXPR_INSTANTIATED.
(most_general_lambda): Define.
(enclosing_instantiation_of): Adjust after renaming
instantiated_lambda_fn_p.
(tsubst_lambda_expr): Don't substitute or set constraints on
the regenerated lambda.

gcc/testsuite/ChangeLog:

PR c++/99874
* g++.dg/cpp2a/concepts-lambda16.C: New test.
* g++.dg/cpp2a/concepts-lambda17.C: New test.
---
  gcc/cp/constraint.cc  | 43 +++--
  gcc/cp/cp-tree.h  | 20 --
  gcc/cp/lambda.c   |  2 +
  gcc/cp/pt.c   | 42 ++---
  .../g++.dg/cpp2a/concepts-lambda16.C  | 61 +++
  .../g++.dg/cpp2a/concepts-lambda17.C  | 14 +
  6 files changed, 150 insertions(+), 32 deletions(-)
  create mode 100644 gcc/testsuite/g++.dg/cpp2a/concepts-lambda16.C
  create mode 100644 gcc/testsuite/g++.dg/cpp2a/concepts-lambda17.C

diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc
index 5cf43bd6c18..bd526f669ab 100644
--- a/gcc/cp/constraint.cc
+++ b/gcc/cp/constraint.cc
@@ -886,6 +886,16 @@ get_normalized_constraints_from_decl (tree d, bool diag = 
false)
   it has the correct template information attached. */
d = strip_inheriting_ctors (d);
  
+  if (regenerated_lambda_fn_p (d))

+{
+  /* If this lambda was regenerated, DECL_TEMPLATE_PARMS doesn't contain
+all in-scope template parameters, but the lambda from which it was
+ultimately regenerated does, so use that instead.  */
+  tree lambda = CLASSTYPE_LAMBDA_EXPR (DECL_CONTEXT (d));
+  lambda = most_general_lambda (lambda);
+  d = lambda_function (lambda);
+}
+
if (TREE_CODE (d) == TEMPLATE_DECL)
  {
tmpl = d;
@@ -3174,13 +3184,27 @@ satisfy_declaration_constraints (tree t, sat_info info)
args = TI_ARGS (ti);

[committed] VAX: Fix comment for `*bit' pattern's peephole

2021-04-08 Thread Maciej W. Rozycki
The comment for a peephole provided for the `*bit' pattern to be 
produced in comparison elimination from a sequence involving a bitwise 
complement operation of one input operand followed by a bitwise AND 
operation between a bitwise complement of said intermediate result and 
the other input operand (which corresponds to a sequence of MCOM and BIC 
machine instructions) incorrectly refers to the first operation as MNEG 
(which is the machine instruction for arithmetic negation) rather than 
MCOM as it is supposed to.  Fix it.

gcc/
* config/vax/vax.md: Fix comment for `*bit' pattern's 
peephole.
---
Hi,

 Committed as an obvious trivial inline documentation fix.

  Maciej
---
 gcc/config/vax/vax.md |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

gcc-vax-mcom-bic-bit.diff
Index: gcc/gcc/config/vax/vax.md
===
--- gcc.orig/gcc/config/vax/vax.md
+++ gcc/gcc/config/vax/vax.md
@@ -1228,7 +1228,7 @@
 ;; the "*bit" pattern does for the purpose of the compare
 ;; elimination pass.  Try to get rid of the extra operation by hand
 ;; and where the sequence is used to set the condition codes only
-;; convert MNEG/BIC => BIT.
+;; convert MCOM/BIC => BIT.
 (define_peephole2
   [(parallel
  [(set (match_operand:VAXint 0 "register_operand")


[pushed] c++: improve reference binding diagnostic [PR91849]

2021-04-08 Thread Jason Merrill via Gcc-patches
Here we were complaining about binding the lvalue reference to the rvalue
result of converting from float to int, but didn't mention that conversion.
Talk about the type of the initializer instead.

Tested x86_64-pc-linux-gnu, applying to trunk.

gcc/cp/ChangeLog:

PR c++/91849
* call.c (convert_like_internal): Improve reference diagnostic.

gcc/testsuite/ChangeLog:

PR c++/91849
* g++.dg/conversion/ref7.C: New test.
---
 gcc/cp/call.c | 15 +--
 gcc/testsuite/g++.dg/conversion/pr66211.C |  2 +-
 gcc/testsuite/g++.dg/conversion/ref7.C| 17 +
 3 files changed, 31 insertions(+), 3 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/conversion/ref7.C

diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index 4b81d0ff333..c9a8c0d305f 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -7898,8 +7898,19 @@ convert_like_internal (conversion *convs, tree expr, 
tree fn, int argnum,
 "lvalue of type %qI", totype, extype);
else if (!TYPE_REF_IS_RVALUE (ref_type) && !lvalue_p (expr)
 && !CP_TYPE_CONST_NON_VOLATILE_P (TREE_TYPE (ref_type)))
- error_at (loc, "cannot bind non-const lvalue reference of "
-   "type %qH to an rvalue of type %qI", totype, extype);
+ {
+   conversion *next = next_conversion (convs);
+   if (next->kind == ck_std)
+ {
+   next = next_conversion (next);
+   error_at (loc, "cannot bind non-const lvalue reference of "
+ "type %qH to a value of type %qI",
+ totype, next->type);
+ }
+   else
+ error_at (loc, "cannot bind non-const lvalue reference of "
+   "type %qH to an rvalue of type %qI", totype, 
extype);
+ }
else if (!reference_compatible_p (TREE_TYPE (totype), extype))
  {
/* If we're converting from T[] to T[N], don't talk
diff --git a/gcc/testsuite/g++.dg/conversion/pr66211.C 
b/gcc/testsuite/g++.dg/conversion/pr66211.C
index 770e8a0e20f..5c1ae13c76d 100644
--- a/gcc/testsuite/g++.dg/conversion/pr66211.C
+++ b/gcc/testsuite/g++.dg/conversion/pr66211.C
@@ -7,5 +7,5 @@ int main()
 {
   int x = 0;
   double y = 1;
-  f(1 > 0 ? x : y); // { dg-error "cannot bind .* to an rvalue" }
+  f(1 > 0 ? x : y); // { dg-error "cannot bind non-const lvalue reference of 
type .int&. to a value of type .double" }
 }
diff --git a/gcc/testsuite/g++.dg/conversion/ref7.C 
b/gcc/testsuite/g++.dg/conversion/ref7.C
new file mode 100644
index 000..99347cb1c27
--- /dev/null
+++ b/gcc/testsuite/g++.dg/conversion/ref7.C
@@ -0,0 +1,17 @@
+// PR c++/91849
+
+struct A { operator float(); };
+
+void
+g ()
+{
+  float f = 1.f;
+  int &r = f;  // { dg-error "float" }
+  int &r2 = A();   // { dg-error "float" }
+}
+
+void
+g2 ()
+{
+  int &r = 1.f;// { dg-error "float" }
+}

base-commit: ac24fa46e449fbff0ff571951cfcc78b8488f6e7
-- 
2.27.0



[committed] libstdc++: Simplify noexcept-specifiers for move constructors

2021-04-08 Thread Jonathan Wakely via Gcc-patches
This puts the logic for the noexcept-specifier in one place, and then
reuses it elsewhere. This means checking whether the move constructor
can throw doesn't need to do overload resolution and then check whether
some other constructor can throw, we just get the answer directly.

libstdc++-v3/ChangeLog:

* include/bits/hashtable.h (_Hashtable::_S_nothrow_move()):
New function to determine noexcept-specifier for move
constructors.
(_Hashtable): Use _S_nothrow_move() on move constructors.
* testsuite/23_containers/unordered_map/cons/noexcept_move_construct.cc:
Correct static assertion message.
* 
testsuite/23_containers/unordered_multimap/cons/noexcept_move_construct.cc:
Likewise.
* 
testsuite/23_containers/unordered_multiset/cons/noexcept_move_construct.cc:
Likewise.
* testsuite/23_containers/unordered_set/cons/noexcept_move_construct.cc:
Likewise.

Tested powerpc64le-linux. Committed to trunk.

commit 1cbba49e3417d9b0661e70301d6fb7a7f52fd360
Author: Jonathan Wakely 
Date:   Thu Apr 8 16:29:11 2021

libstdc++: Simplify noexcept-specifiers for move constructors

This puts the logic for the noexcept-specifier in one place, and then
reuses it elsewhere. This means checking whether the move constructor
can throw doesn't need to do overload resolution and then check whether
some other constructor can throw, we just get the answer directly.

libstdc++-v3/ChangeLog:

* include/bits/hashtable.h (_Hashtable::_S_nothrow_move()):
New function to determine noexcept-specifier for move
constructors.
(_Hashtable): Use _S_nothrow_move() on move constructors.
* 
testsuite/23_containers/unordered_map/cons/noexcept_move_construct.cc:
Correct static assertion message.
* 
testsuite/23_containers/unordered_multimap/cons/noexcept_move_construct.cc:
Likewise.
* 
testsuite/23_containers/unordered_multiset/cons/noexcept_move_construct.cc:
Likewise.
* 
testsuite/23_containers/unordered_set/cons/noexcept_move_construct.cc:
Likewise.

diff --git a/libstdc++-v3/include/bits/hashtable.h 
b/libstdc++-v3/include/bits/hashtable.h
index fa80675ad91..39872ce5342 100644
--- a/libstdc++-v3/include/bits/hashtable.h
+++ b/libstdc++-v3/include/bits/hashtable.h
@@ -472,10 +472,19 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
__hashtable_alloc(__node_alloc_type(__a))
   { }
 
+  template
+   static constexpr bool
+   _S_nothrow_move()
+   {
+ if _GLIBCXX17_CONSTEXPR (_No_realloc)
+   if _GLIBCXX17_CONSTEXPR (is_nothrow_copy_constructible<_Hash>())
+ return is_nothrow_copy_constructible<_Equal>();
+ return false;
+   }
+
   _Hashtable(_Hashtable&& __ht, __node_alloc_type&& __a,
 true_type /* alloc always equal */)
-   noexcept(std::is_nothrow_copy_constructible<_Hash>::value &&
-std::is_nothrow_copy_constructible<_Equal>::value);
+   noexcept(_S_nothrow_move());
 
   _Hashtable(_Hashtable&&, __node_alloc_type&&,
 false_type /* alloc always equal */);
@@ -508,19 +517,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
   // Use delegating constructors.
   _Hashtable(_Hashtable&& __ht)
-   noexcept( noexcept(
- _Hashtable(std::declval<_Hashtable>(),
-std::declval<__node_alloc_type>(),
-true_type{})) )
+   noexcept(_S_nothrow_move())
   : _Hashtable(std::move(__ht), std::move(__ht._M_node_allocator()),
   true_type{})
   { }
 
   _Hashtable(_Hashtable&& __ht, const allocator_type& __a)
-   noexcept( noexcept(
- _Hashtable(std::declval<_Hashtable>(),
-std::declval<__node_alloc_type>(),
-typename __node_alloc_traits::is_always_equal{})) )
+   noexcept(_S_nothrow_move<__node_alloc_traits::_S_always_equal()>())
   : _Hashtable(std::move(__ht), __node_alloc_type(__a),
   typename __node_alloc_traits::is_always_equal{})
   { }
@@ -1400,8 +1403,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits>::
 _Hashtable(_Hashtable&& __ht, __node_alloc_type&& __a,
   true_type /* alloc always equal */)
-noexcept(std::is_nothrow_copy_constructible<_Hash>::value &&
-std::is_nothrow_copy_constructible<_Equal>::value)
+noexcept(_S_nothrow_move())
 : __hashtable_base(__ht),
   __map_base(__ht),
   __rehash_base(__ht),
diff --git 
a/libstdc++-v3/testsuite/23_containers/unordered_map/cons/noexcept_move_construct.cc
 
b/libstdc++-v3/testsuite/23_containers/unordered_map/cons/noexcept_move_construct.cc
index 96245aa4c88..015646adf23 100644
--- 
a/libstdc++-v3/testsuite/23_containers/unordered_map/cons/noexcept_move_construct.cc
+++ 
b

[committed] c-family: Fix various comment typos in c-warn.c

2021-04-08 Thread Jakub Jelinek via Gcc-patches
Hi!

When looking into PR99420, I have noticed several comment typos.

Fixed thusly, committed to trunk as obvious.

2021-04-08  Jakub Jelinek  

* c-warn.c (do_warn_double_promotion): Fix comment typo,
occured -> occurred.
(check_alignment_of_packed_member): Fix a comment typo,
memeber -> member.
(warn_parm_ptrarray_mismatch): Fix comment typos, os -> of
and onless -> unless.
(warn_parm_array_mismatch): Fix comment typos, declaratation
-> declaration and woud -> would.  Fix up comment indentation.

--- gcc/c-family/c-warn.c.jj2021-03-25 13:41:55.601948169 +0100
+++ gcc/c-family/c-warn.c   2021-04-08 18:43:29.020958538 +0200
@@ -2394,7 +2394,7 @@ do_warn_double_promotion (tree result_ty
  warn about it.  */
   if (c_inhibit_evaluation_warnings)
 return;
-  /* If an invalid conversion has occured, don't warn.  */
+  /* If an invalid conversion has occurred, don't warn.  */
   if (result_type == error_mark_node)
 return;
   if (TYPE_MAIN_VARIANT (result_type) != double_type_node
@@ -2900,7 +2900,7 @@ warn_for_multistatement_macros (location
"this %qs clause", guard_tinfo_to_string (keyword));
 }
 
-/* Return struct or union type if the alignment of data memeber, FIELD,
+/* Return struct or union type if the alignment of data member, FIELD,
is less than the alignment of TYPE.  Otherwise, return NULL_TREE.
If RVALUE is true, only arrays evaluate to pointers.  */
 
@@ -3151,7 +3151,7 @@ vla_bound_parm_decl (tree expr)
 }
 
 /* Diagnose mismatches in VLA bounds between function parameters NEWPARMS
-   of pointer types on a redeclaration os a function previously declared
+   of pointer types on a redeclaration of a function previously declared
with CURPARMS at ORIGLOC.  */
 
 static void
@@ -3220,7 +3220,7 @@ warn_parm_ptrarray_mismatch (location_t
   if (origloc == UNKNOWN_LOCATION)
origloc = newloc;
 
-  /* Issue -Warray-parameter onless one or more mismatches involves
+  /* Issue -Warray-parameter unless one or more mismatches involves
 a VLA bound; then issue -Wvla-parameter.  */
   int opt = OPT_Warray_parameter_;
   /* Traverse the two array types looking for variable bounds and
@@ -3335,15 +3335,15 @@ expr_to_str (pretty_printer &pp, tree ex
 
 /* Detect and diagnose a mismatch between an attribute access specification
on the original declaration of FNDECL and that on the parameters NEWPARMS
-   from its refeclaration.  ORIGLOC is the location of the first declaration
+   from its redeclaration.  ORIGLOC is the location of the first declaration
(FNDECL's is set to the location of the redeclaration).  */
 
 void
 warn_parm_array_mismatch (location_t origloc, tree fndecl, tree newparms)
 {
-/* The original parameter list (copied from the original declaration
-   into the current [re]declaration, FNDECL)).  The two are equal if
-   and only if FNDECL is the first declaratation.  */
+  /* The original parameter list (copied from the original declaration
+ into the current [re]declaration, FNDECL)).  The two are equal if
+ and only if FNDECL is the first declaration.  */
   tree curparms = DECL_ARGUMENTS (fndecl);
   if (!curparms || !newparms || curparms == newparms)
 return;
@@ -3375,7 +3375,7 @@ warn_parm_array_mismatch (location_t ori
   return;
 }
   /* ...otherwise, if at least one spec isn't empty there may be mismatches,
- such as  between f(T*) and f(T[1]), where the former mapping woud be
+ such as between f(T*) and f(T[1]), where the former mapping would be
  empty.  */
 
   /* Create an empty access specification and use it for pointers with

Jakub



[PATCH] c++: Fix two issues with auto function parameter [PR99806]

2021-04-08 Thread Marek Polacek via Gcc-patches
When we have a member function with auto parameter like this:

  struct S {
void f(auto);
  };

cp_parser_member_declaration -> grokfield produces a FUNCTION_DECL
"void S::foo(auto:1)", and then finish_fully_implicit_template turns
that FUNCTION_DECL into a TEMPLATE_DECL.  The bug here is that we only
call cp_parser_save_default_args for a FUNCTION_DECL.  As a consequence,
abbrev10.C is rejected because we complain that the default argument has
not been defined, and abbrev11.C ICEs, because we don't re-parse the
delayed noexcept, so the DEFERRED_PARSE tree leaks into tsubst* where we
crash.  This patch fixes both issues.

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

gcc/cp/ChangeLog:

PR c++/99806
* parser.c (cp_parser_member_declaration): Call
cp_parser_save_default_args even for function templates.
(cp_parser_save_default_args): Extract the function declaration
from a function template.

gcc/testsuite/ChangeLog:

PR c++/99806
* g++.dg/concepts/abbrev10.C: New test.
* g++.dg/concepts/abbrev11.C: New test.
---
 gcc/cp/parser.c  |  8 +---
 gcc/testsuite/g++.dg/concepts/abbrev10.C | 18 ++
 gcc/testsuite/g++.dg/concepts/abbrev11.C | 10 ++
 3 files changed, 33 insertions(+), 3 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/concepts/abbrev10.C
 create mode 100644 gcc/testsuite/g++.dg/concepts/abbrev11.C

diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 59adac4492a..eef6bb3003e 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -26433,7 +26433,8 @@ cp_parser_member_declaration (cp_parser* parser)
  || !DECL_DECLARES_FUNCTION_P (decl))
finish_member_declaration (decl);
 
- if (TREE_CODE (decl) == FUNCTION_DECL)
+ if (TREE_CODE (decl) == FUNCTION_DECL
+ || DECL_FUNCTION_TEMPLATE_P (decl))
cp_parser_save_default_args (parser, decl);
  else if (TREE_CODE (decl) == FIELD_DECL
   && DECL_INITIAL (decl))
@@ -30959,9 +30960,10 @@ cp_parser_late_parsing_for_member (cp_parser* parser, 
tree member_function)
 static void
 cp_parser_save_default_args (cp_parser* parser, tree decl)
 {
-  tree probe;
+  if (DECL_FUNCTION_TEMPLATE_P (decl))
+decl = DECL_TEMPLATE_RESULT (decl);
 
-  for (probe = TYPE_ARG_TYPES (TREE_TYPE (decl));
+  for (tree probe = TYPE_ARG_TYPES (TREE_TYPE (decl));
probe;
probe = TREE_CHAIN (probe))
 if (TREE_PURPOSE (probe))
diff --git a/gcc/testsuite/g++.dg/concepts/abbrev10.C 
b/gcc/testsuite/g++.dg/concepts/abbrev10.C
new file mode 100644
index 000..b611346e926
--- /dev/null
+++ b/gcc/testsuite/g++.dg/concepts/abbrev10.C
@@ -0,0 +1,18 @@
+// PR c++/99806
+// { dg-do compile { target c++14 } }
+// { dg-additional-options "-fconcepts" }
+
+struct S {
+  void f(auto, auto, int = 3);
+  void f2(auto, auto, int = 3) { }
+  template static T g(T, auto, int = 3);
+};
+
+void
+g ()
+{
+  S::g(1, 2);
+  S s;
+  s.f(1, 2);
+  s.f2(1, 2);
+}
diff --git a/gcc/testsuite/g++.dg/concepts/abbrev11.C 
b/gcc/testsuite/g++.dg/concepts/abbrev11.C
new file mode 100644
index 000..ddb479313df
--- /dev/null
+++ b/gcc/testsuite/g++.dg/concepts/abbrev11.C
@@ -0,0 +1,10 @@
+// PR c++/99806
+// { dg-do compile { target c++14 } }
+// { dg-additional-options "-fconcepts" }
+
+template  concept C = requires (T a) { a.f(0); };
+struct S {
+  void f(auto) noexcept(B);
+  static constexpr bool B = true;
+};
+static_assert(C, "");

base-commit: 123b3e03c911a43054c1f88f5d3110e1d084dd4e
-- 
2.30.2



Re: [PATCH] c++: Fix two issues with auto function parameter [PR99806]

2021-04-08 Thread Patrick Palka via Gcc-patches
On Thu, 8 Apr 2021, Marek Polacek via Gcc-patches wrote:

> When we have a member function with auto parameter like this:
> 
>   struct S {
> void f(auto);
>   };
> 
> cp_parser_member_declaration -> grokfield produces a FUNCTION_DECL
> "void S::foo(auto:1)", and then finish_fully_implicit_template turns
> that FUNCTION_DECL into a TEMPLATE_DECL.  The bug here is that we only
> call cp_parser_save_default_args for a FUNCTION_DECL.  As a consequence,
> abbrev10.C is rejected because we complain that the default argument has
> not been defined, and abbrev11.C ICEs, because we don't re-parse the
> delayed noexcept, so the DEFERRED_PARSE tree leaks into tsubst* where we
> crash.  This patch fixes both issues.
> 
> Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk/10.4?
> 
> gcc/cp/ChangeLog:
> 
>   PR c++/99806
>   * parser.c (cp_parser_member_declaration): Call
>   cp_parser_save_default_args even for function templates.
>   (cp_parser_save_default_args): Extract the function declaration
>   from a function template.
> 
> gcc/testsuite/ChangeLog:
> 
>   PR c++/99806
>   * g++.dg/concepts/abbrev10.C: New test.
>   * g++.dg/concepts/abbrev11.C: New test.
> ---
>  gcc/cp/parser.c  |  8 +---
>  gcc/testsuite/g++.dg/concepts/abbrev10.C | 18 ++
>  gcc/testsuite/g++.dg/concepts/abbrev11.C | 10 ++
>  3 files changed, 33 insertions(+), 3 deletions(-)
>  create mode 100644 gcc/testsuite/g++.dg/concepts/abbrev10.C
>  create mode 100644 gcc/testsuite/g++.dg/concepts/abbrev11.C
> 
> diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
> index 59adac4492a..eef6bb3003e 100644
> --- a/gcc/cp/parser.c
> +++ b/gcc/cp/parser.c
> @@ -26433,7 +26433,8 @@ cp_parser_member_declaration (cp_parser* parser)
> || !DECL_DECLARES_FUNCTION_P (decl))
>   finish_member_declaration (decl);
>  
> -   if (TREE_CODE (decl) == FUNCTION_DECL)
> +   if (TREE_CODE (decl) == FUNCTION_DECL
> +   || DECL_FUNCTION_TEMPLATE_P (decl))

I guess you could use DECL_DECLARES_FUNCTION_P here.

>   cp_parser_save_default_args (parser, decl);
> else if (TREE_CODE (decl) == FIELD_DECL
>  && DECL_INITIAL (decl))
> @@ -30959,9 +30960,10 @@ cp_parser_late_parsing_for_member (cp_parser* 
> parser, tree member_function)
>  static void
>  cp_parser_save_default_args (cp_parser* parser, tree decl)
>  {
> -  tree probe;
> +  if (DECL_FUNCTION_TEMPLATE_P (decl))
> +decl = DECL_TEMPLATE_RESULT (decl);

Not sure if it'd be an improvement, but could use STRIP_TEMPLATE here
instead (or perhaps on the caller side).

>  
> -  for (probe = TYPE_ARG_TYPES (TREE_TYPE (decl));
> +  for (tree probe = TYPE_ARG_TYPES (TREE_TYPE (decl));
> probe;
> probe = TREE_CHAIN (probe))
>  if (TREE_PURPOSE (probe))
> diff --git a/gcc/testsuite/g++.dg/concepts/abbrev10.C 
> b/gcc/testsuite/g++.dg/concepts/abbrev10.C
> new file mode 100644
> index 000..b611346e926
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/concepts/abbrev10.C
> @@ -0,0 +1,18 @@
> +// PR c++/99806
> +// { dg-do compile { target c++14 } }
> +// { dg-additional-options "-fconcepts" }
> +
> +struct S {
> +  void f(auto, auto, int = 3);
> +  void f2(auto, auto, int = 3) { }
> +  template static T g(T, auto, int = 3);
> +};
> +
> +void
> +g ()
> +{
> +  S::g(1, 2);
> +  S s;
> +  s.f(1, 2);
> +  s.f2(1, 2);
> +}
> diff --git a/gcc/testsuite/g++.dg/concepts/abbrev11.C 
> b/gcc/testsuite/g++.dg/concepts/abbrev11.C
> new file mode 100644
> index 000..ddb479313df
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/concepts/abbrev11.C
> @@ -0,0 +1,10 @@
> +// PR c++/99806
> +// { dg-do compile { target c++14 } }
> +// { dg-additional-options "-fconcepts" }
> +
> +template  concept C = requires (T a) { a.f(0); };
> +struct S {
> +  void f(auto) noexcept(B);
> +  static constexpr bool B = true;
> +};
> +static_assert(C, "");
> 
> base-commit: 123b3e03c911a43054c1f88f5d3110e1d084dd4e
> -- 
> 2.30.2
> 
> 



Re: [committed] libstdc++: Fix doxygen markup for group close commands

2021-04-08 Thread Jonathan Wakely via Gcc-patches

On 06/04/21 16:54 +0100, Jonathan Wakely wrote:

A change in Doxygen 1.8.16 means that "// @}" is no longer recognized by
Doxygen, so doesn't close a @{ group. A "///" comment needs to be used.


There are a few cases of /* @} */ which need a similar fix.

Tested powerpc64le-linux. Committed to trunk.


commit 014b6dbcaa80fc46c792c270244e7eeef7dce75f
Author: Jonathan Wakely 
Date:   Thu Apr 8 18:22:51 2021

libstdc++: Fix more doxygen markup for group close commands

Similar to r11-8009 but for /* @} */ comments this time, which should
be /** @} */ for Doxygen to recognize them.

libstdc++-v3/ChangeLog:

* include/bits/random.h: Fix doxygen group commands.
* include/bits/regex_constants.h: Likewise.
* include/tr1/random.h: Likewise.

diff --git a/libstdc++-v3/include/bits/random.h b/libstdc++-v3/include/bits/random.h
index 877ac3406b6..1b9cc5f16a9 100644
--- a/libstdc++-v3/include/bits/random.h
+++ b/libstdc++-v3/include/bits/random.h
@@ -1675,7 +1675,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 };
   };
 
-  /* @} */ // group random_generators
+  /// @} group random_generators
 
   /**
* @addtogroup random_distributions Random Number Distributions
@@ -1951,7 +1951,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 operator>>(std::basic_istream<_CharT, _Traits>&,
 	   std::uniform_real_distribution<_RealType>&);
 
-  /* @} */ // group random_distributions_uniform
+  /// @} group random_distributions_uniform
 
   /**
* @addtogroup random_distributions_normal Normal Distributions
@@ -3506,7 +3506,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 { return !(__d1 == __d2); }
 
 
-  /* @} */ // group random_distributions_normal
+  /// @} group random_distributions_normal
 
   /**
* @addtogroup random_distributions_bernoulli Bernoulli Distributions
@@ -4402,7 +4402,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 { return !(__d1 == __d2); }
 
 
-  /* @} */ // group random_distributions_bernoulli
+  /// @} group random_distributions_bernoulli
 
   /**
* @addtogroup random_distributions_poisson Poisson Distributions
@@ -6048,9 +6048,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 { return !(__d1 == __d2); }
 
 
-  /* @} */ // group random_distributions_poisson
+  /// @} group random_distributions_poisson
 
-  /* @} */ // group random_distributions
+  /// @} *group random_distributions
 
   /**
* @addtogroup random_utilities Random Number Utilities
@@ -6101,9 +6101,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 std::vector _M_v;
   };
 
-  /* @} */ // group random_utilities
+  /// @} group random_utilities
 
-  /* @} */ // group random
+  /// @} group random
 
 _GLIBCXX_END_NAMESPACE_VERSION
 } // namespace std
diff --git a/libstdc++-v3/include/bits/regex_constants.h b/libstdc++-v3/include/bits/regex_constants.h
index 340421a5abd..1c3dd36d57c 100644
--- a/libstdc++-v3/include/bits/regex_constants.h
+++ b/libstdc++-v3/include/bits/regex_constants.h
@@ -409,7 +409,7 @@ namespace regex_constants
 
   ///@}
 } // namespace regex_constants
-/* @} */ // group regex
+/// @} group regex
 
 _GLIBCXX_END_NAMESPACE_VERSION
 } // namespace std
diff --git a/libstdc++-v3/include/tr1/random.h b/libstdc++-v3/include/tr1/random.h
index 57c434f6966..9c79cfd8035 100644
--- a/libstdc++-v3/include/tr1/random.h
+++ b/libstdc++-v3/include/tr1/random.h
@@ -1543,7 +1543,7 @@ namespace tr1
 #endif
   };
 
-  /* @} */ // group tr1_random_generators
+  /// @} group tr1_random_generators
 
   /**
* @addtogroup tr1_random_distributions Random Number Distributions
@@ -2046,7 +2046,7 @@ namespace tr1
   bool  _M_easy;
 };
 
-  /* @} */ // group tr1_random_distributions_discrete
+  /// @} group tr1_random_distributions_discrete
 
   /**
* @addtogroup tr1_random_distributions_continuous Continuous Distributions
@@ -2403,9 +2403,9 @@ namespace tr1
   result_type _M_l_d;
 };
 
-  /* @} */ // group tr1_random_distributions_continuous
-  /* @} */ // group tr1_random_distributions
-  /* @} */ // group tr1_random
+  /// @} group tr1_random_distributions_continuous
+  /// @} group tr1_random_distributions
+  /// @} group tr1_random
 }
 
 _GLIBCXX_END_NAMESPACE_VERSION


[committed] libstdc++: Improve error reporting if PDF generation fails

2021-04-08 Thread Jonathan Wakely via Gcc-patches
If pdflatex runs out of memory the build fails with no hint what's
wrong. This adds another grep command to the makefile so that an
out-of-memory error will result in more information being shown.

As suggested in https://bugzilla.redhat.com/show_bug.cgi?id=1841056
using lualatex can be used as a workaround.

libstdc++-v3/ChangeLog:

* doc/Makefile.am (stamp-pdf-doxygen): Also grep for
out-of-memory error in log file.
* doc/Makefile.in: Regenerate.

Tested x86_64-linux. Committed to trunk.

commit be8d5f99f50cf282c21632e60fe1d8857bb5a554
Author: Jonathan Wakely 
Date:   Thu Apr 8 18:37:59 2021

libstdc++: Improve error reporting if PDF generation fails

If pdflatex runs out of memory the build fails with no hint what's
wrong. This adds another grep command to the makefile so that an
out-of-memory error will result in more information being shown.

As suggested in https://bugzilla.redhat.com/show_bug.cgi?id=1841056
using lualatex can be used as a workaround.

libstdc++-v3/ChangeLog:

* doc/Makefile.am (stamp-pdf-doxygen): Also grep for
out-of-memory error in log file.
* doc/Makefile.in: Regenerate.

diff --git a/libstdc++-v3/doc/Makefile.am b/libstdc++-v3/doc/Makefile.am
index 2e0eb187f91..cb9b68ffaea 100644
--- a/libstdc++-v3/doc/Makefile.am
+++ b/libstdc++-v3/doc/Makefile.am
@@ -267,6 +267,7 @@ stamp-pdf-doxygen: stamp-latex-doxygen ${doxygen_outdir}/pdf
else \
  echo "... error"; \
  grep -F 'LaTeX Error' ${doxygen_outdir}/latex/refman.log; \
+ grep -F 'TeX capacity exceeded, sorry' 
${doxygen_outdir}/latex/refman.log; \
  exit 12; \
fi
$(STAMP) stamp-pdf-doxygen


Re: [PATCH v2] c++: Fix two issues with auto function parameter [PR99806]

2021-04-08 Thread Marek Polacek via Gcc-patches
On Thu, Apr 08, 2021 at 04:37:00PM -0400, Patrick Palka wrote:
> On Thu, 8 Apr 2021, Marek Polacek via Gcc-patches wrote:
> 
> > When we have a member function with auto parameter like this:
> > 
> >   struct S {
> > void f(auto);
> >   };
> > 
> > cp_parser_member_declaration -> grokfield produces a FUNCTION_DECL
> > "void S::foo(auto:1)", and then finish_fully_implicit_template turns
> > that FUNCTION_DECL into a TEMPLATE_DECL.  The bug here is that we only
> > call cp_parser_save_default_args for a FUNCTION_DECL.  As a consequence,
> > abbrev10.C is rejected because we complain that the default argument has
> > not been defined, and abbrev11.C ICEs, because we don't re-parse the
> > delayed noexcept, so the DEFERRED_PARSE tree leaks into tsubst* where we
> > crash.  This patch fixes both issues.
> > 
> > Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk/10.4?
> > 
> > gcc/cp/ChangeLog:
> > 
> > PR c++/99806
> > * parser.c (cp_parser_member_declaration): Call
> > cp_parser_save_default_args even for function templates.
> > (cp_parser_save_default_args): Extract the function declaration
> > from a function template.
> > 
> > gcc/testsuite/ChangeLog:
> > 
> > PR c++/99806
> > * g++.dg/concepts/abbrev10.C: New test.
> > * g++.dg/concepts/abbrev11.C: New test.
> > ---
> >  gcc/cp/parser.c  |  8 +---
> >  gcc/testsuite/g++.dg/concepts/abbrev10.C | 18 ++
> >  gcc/testsuite/g++.dg/concepts/abbrev11.C | 10 ++
> >  3 files changed, 33 insertions(+), 3 deletions(-)
> >  create mode 100644 gcc/testsuite/g++.dg/concepts/abbrev10.C
> >  create mode 100644 gcc/testsuite/g++.dg/concepts/abbrev11.C
> > 
> > diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
> > index 59adac4492a..eef6bb3003e 100644
> > --- a/gcc/cp/parser.c
> > +++ b/gcc/cp/parser.c
> > @@ -26433,7 +26433,8 @@ cp_parser_member_declaration (cp_parser* parser)
> >   || !DECL_DECLARES_FUNCTION_P (decl))
> > finish_member_declaration (decl);
> >  
> > - if (TREE_CODE (decl) == FUNCTION_DECL)
> > + if (TREE_CODE (decl) == FUNCTION_DECL
> > + || DECL_FUNCTION_TEMPLATE_P (decl))
> 
> I guess you could use DECL_DECLARES_FUNCTION_P here.

Right, thanks.

> > cp_parser_save_default_args (parser, decl);
> >   else if (TREE_CODE (decl) == FIELD_DECL
> >&& DECL_INITIAL (decl))
> > @@ -30959,9 +30960,10 @@ cp_parser_late_parsing_for_member (cp_parser* 
> > parser, tree member_function)
> >  static void
> >  cp_parser_save_default_args (cp_parser* parser, tree decl)
> >  {
> > -  tree probe;
> > +  if (DECL_FUNCTION_TEMPLATE_P (decl))
> > +decl = DECL_TEMPLATE_RESULT (decl);
> 
> Not sure if it'd be an improvement, but could use STRIP_TEMPLATE here
> instead (or perhaps on the caller side).

Might as well.  How's this?

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

-- >8 --
When we have a member function with auto parameter like this:

  struct S {
void f(auto);
  };

cp_parser_member_declaration -> grokfield produces a FUNCTION_DECL
"void S::foo(auto:1)", and then finish_fully_implicit_template turns
that FUNCTION_DECL into a TEMPLATE_DECL.  The bug here is that we only
call cp_parser_save_default_args for a FUNCTION_DECL.  As a consequence,
abbrev10.C is rejected because we complain that the default argument has
not been defined, and abbrev11.C ICEs, because we don't re-parse the
delayed noexcept, so the DEFERRED_PARSE tree leaks into tsubst* where we
crash.  This patch fixes both issues.

gcc/cp/ChangeLog:

PR c++/99806
* parser.c (cp_parser_member_declaration): Call
cp_parser_save_default_args even for function templates.  Use
STRIP_TEMPLATE on the declaration we're passing.

gcc/testsuite/ChangeLog:

PR c++/99806
* g++.dg/concepts/abbrev10.C: New test.
* g++.dg/concepts/abbrev11.C: New test.
---
 gcc/cp/parser.c  |  4 ++--
 gcc/testsuite/g++.dg/concepts/abbrev10.C | 18 ++
 gcc/testsuite/g++.dg/concepts/abbrev11.C | 10 ++
 3 files changed, 30 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/concepts/abbrev10.C
 create mode 100644 gcc/testsuite/g++.dg/concepts/abbrev11.C

diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 59adac4492a..e6e6ed72a42 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -26433,8 +26433,8 @@ cp_parser_member_declaration (cp_parser* parser)
  || !DECL_DECLARES_FUNCTION_P (decl))
finish_member_declaration (decl);
 
- if (TREE_CODE (decl) == FUNCTION_DECL)
-   cp_parser_save_default_args (parser, decl);
+ if (DECL_DECLARES_FUNCTION_P (decl))
+   cp_parser_save_default_args (parser, STRIP_TEMPLATE (decl));
  else if (TREE_CODE (decl) == FIELD_DECL
   && DECL_INITIAL (decl))
/* Add

Re: [PATCH] c++: Don't substitute into constraints on lambdas [PR99874]

2021-04-08 Thread Patrick Palka via Gcc-patches
On Thu, 8 Apr 2021, Jason Merrill wrote:

> On 4/7/21 12:10 PM, Patrick Palka wrote:
> > We currently substitute through a lambda's constraints whenever we
> > regenerate it via tsubst_lambda_expr.  This is the wrong approach
> > because it can lead to hard errors due to constraints being evaluated
> > out of order (as in the testcase concepts-lambda17.C below), and because
> > it doesn't mesh well with the recently added REQUIRES_EXPR_EXTRA_ARGS
> > mechanism for delaying substitution into requires-expressions, which is
> > the cause of this PR.
> > 
> > But in order to avoid substituting through a lambda's constraints during
> > regeneration, we we need to be able to get at all in-scope template
> > parameters and the corresponding template arguments during constraint
> > checking of a lambda's op().  And this information is not easily
> > available where we need it, it seems.
> > 
> > To that end, the approach that this patch takes is to add two new fields
> > to LAMBDA_EXPR (and remove one): LAMBDA_EXPR_REGENERATED_FROM
> > (replacing LAMBDA_EXPR_INSTANTIATED), and LAMBDA_EXPR_REGENERATING_TARGS.
> > The former allows us to obtain the complete set of template parameters
> > that are in-scope for a lambda's op(), and the latter gives us all outer
> > template arguments that were used to regenerate the lambda.
> 
> I'm a little surprised you didn't use a TEMPLATE_INFO for these, but this way
> is fine too.

Using a TEMPLATE_INFO here works nicely here, I hadn't considered it.
Like so?  Tested on x86_64-pc-linux-gnu.

-- >8 --

Subject: [PATCH] c++: Use a TEMPLATE_INFO to hold regenerated lambda info

A TEMPLATE_INFO is a natural fit for what LAMBDA_EXPR_REGENERATED_FROM
and LAMBDA_EXPR_REGENERATING_TARGS hold, so let's use it instead.

gcc/cp/ChangeLog:

* cp-tree.h (LAMBDA_EXPR_REGENERATED_FROM)
(LAMBDA_EXPR_REGENERATING_TARGS): Replace these with ...
(LAMBDA_EXPR_REGEN_INFO): ... this.
(tree_lambda_expr::regenerated_from)
(tree_lambda_expr::regenerating_targs): Replace these with ...
(tree_lambda_expr::regen_info): ... this.
* constraint.cc (satisfy_declaration_constraints): Adjust
accordingly.
* lambda.c (build_lambda_expr): Likewise.
* pt.c (regenerated_lambda_fn_p): Likewise.
(most_general_lambda): Likewise.
(tsubst_lambda_expr): Likewise.
---
 gcc/cp/constraint.cc |  4 ++--
 gcc/cp/cp-tree.h | 18 +++---
 gcc/cp/lambda.c  |  3 +--
 gcc/cp/pt.c  | 15 +--
 4 files changed, 19 insertions(+), 21 deletions(-)

diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc
index 0a9d1bfea0f..0ddb2990dd9 100644
--- a/gcc/cp/constraint.cc
+++ b/gcc/cp/constraint.cc
@@ -3193,7 +3193,7 @@ satisfy_declaration_constraints (tree t, sat_info info)
 arguments that were used to regenerate the lambda.  */
   gcc_assert (!args || TMPL_ARGS_DEPTH (args) == 1);
   tree lambda = CLASSTYPE_LAMBDA_EXPR (DECL_CONTEXT (t));
-  tree outer_args = LAMBDA_EXPR_REGENERATING_TARGS (lambda);
+  tree outer_args = TI_ARGS (LAMBDA_EXPR_REGEN_INFO (lambda));
   if (args)
args = add_to_template_args (outer_args, args);
   else
@@ -3256,7 +3256,7 @@ satisfy_declaration_constraints (tree t, tree args, 
sat_info info)
   /* As in the two-parameter version of this function.  */
   gcc_assert (TMPL_ARGS_DEPTH (args) == 1);
   tree lambda = CLASSTYPE_LAMBDA_EXPR (DECL_CONTEXT (t));
-  tree outer_args = LAMBDA_EXPR_REGENERATING_TARGS (lambda);
+  tree outer_args = TI_ARGS (LAMBDA_EXPR_REGEN_INFO (lambda));
   args = add_to_template_args (outer_args, args);
 }
   else
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index bf9d5add0cf..e42b82ae5a4 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -1456,15 +1456,12 @@ enum cp_lambda_default_capture_mode_type {
 #define LAMBDA_EXPR_PENDING_PROXIES(NODE) \
   (((struct tree_lambda_expr *)LAMBDA_EXPR_CHECK (NODE))->pending_proxies)
 
-/* The immediate LAMBDA_EXPR from which NODE was regenerated, or NULL_TREE
-   (if NODE was not regenerated via tsubst_lambda_expr).  */
-#define LAMBDA_EXPR_REGENERATED_FROM(NODE) \
-  (((struct tree_lambda_expr *)LAMBDA_EXPR_CHECK (NODE))->regenerated_from)
-
-/* The full set of template arguments used to regenerate NODE, or NULL_TREE
-   (if NODE was not regenerated via tsubst_lambda_expr).  */
-#define LAMBDA_EXPR_REGENERATING_TARGS(NODE) \
-  (((struct tree_lambda_expr *)LAMBDA_EXPR_CHECK (NODE))->regenerating_targs)
+/* If NODE was regenerated via tsubst_lambda_expr, this is a TEMPLATE_INFO
+   whose TI_TEMPLATE is the immediate LAMBDA_EXPR from which NODE was
+   regenerated, and TI_ARGS is the full set of template arguments used
+   to regenerate NODE from the most general lambda.  */
+#define LAMBDA_EXPR_REGEN_INFO(NODE) \
+  (((struct tree_lambda_expr *)LAMBDA_EXPR_CHECK (NODE))->regen_info)
 
 /* The closure type of the lambda, which is also the type of the

Re: [PATCH] lra: Canonicalize mult to shift in address reloads

2021-04-08 Thread Maciej W. Rozycki
On Thu, 25 Mar 2021, Richard Sandiford wrote:

> "Maciej W. Rozycki"  writes:
> > On Wed, 26 Aug 2020, Vladimir Makarov via Gcc-patches wrote:
> >
> >> On 2020-08-26 5:06 a.m., Richard Sandiford wrote:
> >> > 
> >> > I don't think we should we restrict this to (plus (mult X Y) Z),
> >> > since addresses can be more complicated than that.  One way to
> >> > search for all MULTs is:
> >> > 
> >> >subrtx_iterator::array_type array;
> >> >FOR_EACH_SUBRTX (iter, array, x, NONCONST)
> >> >  {
> >> >rtx x = *iter;
> >> >if (GET_CODE (x) == MULT && CONST_INT_P (XEXP (x, 1)))
> >> >  ...
> >> >  }
> >> > 
> >> > (Needs rtl-iter.h)
> >> 
> >> I am agree it would be nice to process a general case.  Alex, you can do 
> >> this
> >> as a separate patch if you want.
> >> 
> >> Richard, thank you for looking at this patch too.
> >
> > [From ; 
> > also commit 6b3034eaba83.]
> >
> >  Guys, this triggers a backend's functional regression and an ICE in the 
> > test suite with the LRA conversion I'm currently working on for the VAX 
> > backend.  Before I go ahead and paper it over in the backend I'd like to 
> > understand why this change was considered correct in the first place.
> >
> >  Contrary to what the change description suggests the ASHIFT form is not 
> > documented to be the canonical form for constant multiplication involving 
> > a power of two for addresses used outside `mem'.
> 
> One thing to note here is that, outside of a mem, there's no distinction
> between an address calculation and normal integer arithmetic.  In other
> words, “addresses used outside of a ‘mem’” aren't a distinct category of
> rtx that can be separated from other things outside of a “mem“.  So…

 In principle you're right, however my interpretation would be that 
whenever TARGET_LEGITIMATE_ADDRESS_P is called the middle end does 
consider the rtx passed an address calculation rather than normal integer 
arithmetic even if potentially.  So I would expect the middle end to 
convert the calculation to the canonical address form before such 
invocation even if to convert it back (revert to the original unconverted 
form) right after the return from TARGET_LEGITIMATE_ADDRESS_P.

 And it seems to me like this change has broken the contract for rtx's 
passed to TARGET_LEGITIMATE_ADDRESS_P that have been produced by the 
middle end rather than individual backends (which I guess may have not 
kept to the contract as indicated by the PR target/43766 fix for x86).

 Have I got my interpretation wrong here?

> > What our rules only say 
> > is that for addresses inside `mem' the MULT form is:
> >
> >* Within address computations (i.e., inside 'mem'), a left shift is
> >  converted into the appropriate multiplication by a power of two.
> >
> >  This change does the reverse of the conversion described above and makes
> > TARGET_LEGITIMATE_ADDRESS_P and possibly other backend code be presented 
> > with either form for indexed addresses, which complicates handling.  The 
> > ICE mentioned above specifically is caused by:
> >
> > (plus:SI (plus:SI (mult:SI (reg:SI 30 [ _10 ])
> > (const_int 4 [0x4]))
> > (reg/f:SI 26 [ _6 ]))
> > (const_int 12 [0xc]))
> 
> …if you write:
> 
> ---
> long *foo ();
> long *bar (long *ptr, long x) { return &foo ()[x + 3]; }
> ---
> 
> then the rtl you get is:
> 
> ---
> …
> (insn 10 9 11 2 (set (reg:SI 32)
> (plus:SI (reg/v:SI 29 [ x ])
> (const_int 3 [0x3]))) "/tmp/foo.c":2:47 -1
>  (nil))
> (insn 11 10 12 2 (set (reg:SI 33)
> (ashift:SI (reg:SI 32)
> (const_int 2 [0x2]))) "/tmp/foo.c":2:47 -1
>  (nil))
> (insn 12 11 13 2 (set (reg:SI 31)
> (plus:SI (reg/f:SI 23 [ _1 ])
> (reg:SI 33))) "/tmp/foo.c":2:40 -1
>  (nil))
> …
> ---
> 
> where the address uses “ashift” rather than “mult”.  Then combine
> tries to generate the same kind of address as the one you quote above,
> but with “ashift” rather than “mult”:
> 
> ---
> Trying 10, 11 -> 12:
>10: r32:SI=r29:SI+0x3
>   REG_DEAD r29:SI
>11: r33:SI=r32:SI<<0x2
>   REG_DEAD r32:SI
>12: r31:SI=r34:SI+r33:SI
>   REG_DEAD r34:SI
>   REG_DEAD r33:SI
> Failed to match this instruction:
> (set (reg:SI 31)
> (plus:SI (plus:SI (ashift:SI (reg/v:SI 29 [ x ])
> (const_int 2 [0x2]))
> (reg:SI 34))
> (const_int 12 [0xc])))
> ---
> 
> So I don't see your VAX change as papering over the issue.  The above
> “ashift” form is what address calculations normally look like outside
> of a “mem”.

[PATCH] propagate attributes to local redeclaration (PR 99420)

2021-04-08 Thread Martin Sebor via Gcc-patches

The C front end ordinarily merges function type attributes upon
the redeclaration of a function but it doesn't do that for those
at local scope, unless the declaration refers to a built-in.

Because the new -Warray-parameter warning relies on the internal
access attribute on the type of the function added by the C front
end for parameters declared using the array notation, it triggers
when it sees a redeclaration of a function in a local scope even
when both declarations use the same array form, issuing a false
positive.

The same problem affects other similar redeclarations involving
attributes, such as unused_result, causing false negatives there.
(Clang and ICC behave as I expect.)

The attached patch lets the front end propagate the type attributes
for all redeclarations, resolving this class of problems for all
affected attributes.

There's another similar piece of code in pushdecl() that I didn't
touch, although  I couldn't come up with a test case showing it's
necessary.  Both hunks go back ages so I wonder if they might have
been obviated by other improvements.

Martin
PR c/99420 - bogus -Warray-parameter on a function redeclaration in function scope
PR c/99972 - missing -Wunused-result on a call to a locally redeclared warn_unused_result function

gcc/c/ChangeLog:

	PR c/99420
	PR c/99972
	* c-decl.c (pushdecl): Always propagate type attribute.

gcc/testsuite/ChangeLog:

	PR c/99420
	PR c/99972
	* gcc.dg/Warray-parameter-9.c: New test.
	* gcc.dg/Wnonnull-6.c: New test.
	* gcc.dg/Wreturn-type3.c: New test.
	* gcc.dg/Wunused-result.c: New test.
	* gcc.dg/attr-noreturn.c: New test.
	* gcc.dg/attr-returns-nonnull.c: New test.

diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c
index 3b2241bfd97..677bfd73a50 100644
--- a/gcc/c/c-decl.c
+++ b/gcc/c/c-decl.c
@@ -3263,11 +3263,10 @@ pushdecl (tree x)
 	  else
 	thistype = type;
 	  b->u.type = TREE_TYPE (b->decl);
-	  if (TREE_CODE (b->decl) == FUNCTION_DECL
-	  && fndecl_built_in_p (b->decl))
-	thistype
-	  = build_type_attribute_variant (thistype,
-	  TYPE_ATTRIBUTES (b->u.type));
+	  /* Propagate the type attributes to the decl.  */
+	  thistype
+	= build_type_attribute_variant (thistype,
+	TYPE_ATTRIBUTES (b->u.type));
 	  TREE_TYPE (b->decl) = thistype;
 	  bind (name, b->decl, scope, /*invisible=*/false, /*nested=*/true,
 		locus);
diff --git a/gcc/testsuite/gcc.dg/Warray-parameter-9.c b/gcc/testsuite/gcc.dg/Warray-parameter-9.c
new file mode 100644
index 000..b5d3d963c88
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/Warray-parameter-9.c
@@ -0,0 +1,54 @@
+/* PR c/99420 - bogus -Warray-parameter on a function redeclaration
+   in function scope
+   { dg-do compile }
+   { dg-options "-Wall" } */
+
+extern int a1[1], a2[2], a3[3], a4[4];
+
+void fa1 (int [1]); // { dg-message "previously declared as 'int\\\[1]'" }
+void fa1 (int [1]);
+
+
+void nested_decl (void)
+{
+  void fa2 (int [2]);
+
+  fa2 (a1); // { dg-warning "\\\[-Warray-bounds|-Wstringop-overflow" }
+  fa2 (a2);
+  fa2 (a3);
+
+  void fa3 (int [3]);
+
+  fa3 (a2); // { dg-warning "\\\[-Warray-bounds|-Wstringop-overflow" }
+  fa3 (a3);
+}
+
+
+void nested_redecl (void)
+{
+  void fa1 (int [2]);   // { dg-warning "argument 1 of type 'int\\\[2]' with mismatched bound" }
+
+  fa1 (a1 + 1); // { dg-warning "\\\[-Warray-bounds|-Wstringop-overflow" }
+  fa1 (a1);
+
+  void fa2 (int [2]);   // { dg-bogus "\\\[-Warray-parameter" }
+
+  fa2 (a1); // { dg-warning "\\\[-Warray-bounds|-Wstringop-overflow" }
+  fa2 (a2);
+  fa2 (a3);
+
+  void fa3 (int [3]);   // { dg-bogus "\\\[-Warray-parameter" }
+
+  fa3 (a2); // { dg-warning "\\\[-Warray-bounds|-Wstringop-overflow" }
+  fa3 (a3);
+
+  void fa4 (int [4]);
+}
+
+void fa4 (int [5]); // { dg-warning "\\\[-Warray-parameter" }
+
+void call_fa4 (void)
+{
+  fa4 (a4);
+  fa4 (a3); // { dg-warning "\\\[-Warray-bounds|-Wstringop-overflow" }
+}
diff --git a/gcc/testsuite/gcc.dg/Wnonnull-6.c b/gcc/testsuite/gcc.dg/Wnonnull-6.c
new file mode 100644
index 000..48f09da996f
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/Wnonnull-6.c
@@ -0,0 +1,93 @@
+/* Verify that attribute nonnull on global and local function declarations
+   or those to pointers to functions is merged.
+   { dg-do compile }
+   { dg-options "-Wall" } */
+
+void fnonnull_local_local (void)
+{
+  extern __attribute__ ((nonnull)) void fnonnull1 (void*);
+
+  fnonnull1 (0);// { dg-warning "\\\[-Wnonnull" }
+}
+
+void gnonnull_local_local (void)
+{
+  extern void fnonnull1 (void*);
+
+  fnonnull1 (0);// { dg-warning "\\\[-Wnonnull" }
+}
+
+
+void fnonnull_local_global (void)
+{
+  extern __attribute__ ((nonnull)) void fnonnull2 (void*);
+
+  fnonnull2 (0);// { dg-warning "\\\[-Wnonnull" }
+}
+
+extern void fnonnull2 (void*);
+
+void gnonnull_local_global (void)
+{
+  fnonnull2 (0);// { dg-warning "\\\[-Wnonnull" }
+}
+
+
+extern __attribute__ ((nonnull)) void fnonnull3 (voi

[committed] libstdc++: Remove spurious line break in doxygen comment

2021-04-08 Thread Jonathan Wakely via Gcc-patches
libstdc++-v3/ChangeLog:

* include/bits/basic_string.h: Tweak doxygen comment.

Tested powerpc64le-linux. Committed to trunk.

commit 96292c3e3439aa167ed7ae595f89b8776e705897
Author: Jonathan Wakely 
Date:   Thu Apr 8 23:39:29 2021

libstdc++: Remove spurious line break in doxygen comment

libstdc++-v3/ChangeLog:

* include/bits/basic_string.h: Tweak doxygen comment.

diff --git a/libstdc++-v3/include/bits/basic_string.h 
b/libstdc++-v3/include/bits/basic_string.h
index 7d819bb1bb7..3c5309d16e6 100644
--- a/libstdc++-v3/include/bits/basic_string.h
+++ b/libstdc++-v3/include/bits/basic_string.h
@@ -4709,8 +4709,7 @@ _GLIBCXX_END_NAMESPACE_CXX11
*  @brief  Insert a string_view.
*  @param __pos1  Position in string to insert at.
*  @param __svt   The object convertible to string_view to insert from.
-   *  @param __pos2  Position in string_view to insert
-   *  from.
+   *  @param __pos2  Position in string_view to insert from.
*  @param __nThe number of characters to insert.
*  @return  Reference to this string.
   */


Re: [PATCH] lra: Canonicalize mult to shift in address reloads

2021-04-08 Thread Maciej W. Rozycki
On Thu, 8 Apr 2021, Maciej W. Rozycki wrote:

> > Does the patch also help to optimise my example above?  If so,
> > it sounds like a good thing for that reason alone.
> 
>  Nope, it actually regresses code produced, causing an extra instruction 
> to be used where it doesn't have to:
> 
> --- test-ira/test.s
> +++ test-lra-legitimate-address-ashift/test.s
> @@ -8,7 +8,8 @@
>   .word 0
>   subl2 $4,%sp
>   calls $0,foo
> - addl3 8(%ap),$3,%r1
> + movl 8(%ap),%r1
> + addl2 $12,%r0
>   moval 0[%r1],%r1
>   addl2 %r1,%r0
>   ret
> 
> (old code is either IRA, or LRA without my change to accept ASHIFT in 
> TARGET_LEGITIMATE_ADDRESS_P).  Please observe that the original ADDL3 
> instruction completes the index calculation (as desired, as noted above), 
> and then the rest boils down to combining it with the base component as 
> handed over by `foo'.
> 
>  NB (%reg) is a base register and [%reg] is an index register, implicitly 
> scaled by the data width determined by the relevant suffix of the mnemonic 
> (`l' here stands for "longword", so 32-bit).  And MOVA is "move address" 
> like x86's LEA.
> 
>  Though frankly what we really want anyway is:
> 
>   calls $0,foo
>   addl3 8(%ap),$3,%r1
>   moval (%r0)[%r1],%r0
>   ret
> 
> because what we need to do here to complete the calculation is to combine 
> the base in %r0 with the index in %r1 -- there's no performance penalty 
> for the use of a base register (an index costs an extra cycle) and the 
> encoding is much shorter:
> 
>   11: de 41 9f 00 moval *0x0[r1],r1
>   15: 00 00 00 51 

 FAOD mind that MOVAL produced here does not come from indexed addressing 
but rather from the ASHIFT pattern, as also shown by the original insn:

(insn 23 22 24 2 (set (reg:SI 1 %r1 [36])
(ashift:SI (reg/v:SI 1 %r1 [orig:29 x ] [29])
(const_int 2 [0x2]))) "test.c":2:56 432 {ashlsi3}
 (nil))

I quoted in last message, or in the past-reload form:

(insn 27 26 28 (parallel [
(set (reg:SI 1 %r1 [36])
(ashift:SI (reg/v:SI 1 %r1 [orig:29 x ] [29])
(const_int 2 [0x2])))
(clobber (reg:CC 16 %psl))
]) "test.c":2:56 433 {*ashlsi3}
 (expr_list:REG_UNUSED (reg:CC 16 %psl)
(nil)))

>   19: c0 51 50addl2 r1,r0
> 
> vs:
> 
>   11: de 41 60 50 moval (r0)[r1],r0
> 
> (because in the absence of a base register the absolute address mode has 
> to be used, which always uses full 32-bit extension, unlike displacements 
> optionally used with a base register).  But while we're not there, we're 
> moving away from rather than towards the desired solution.  This seems to 
> be an unfortunate consequence of how reload works though, so I gather it 
> needs to be fixed in reload.

 So I thought of another experiment and I applied my ASHIFT patch to the 
old reload configuration.  In its unmodified form it caused an ICE with 
your example:

during RTL pass: final
test.c: In function 'bar':
test.c:2:56: internal compiler error: in print_operand_address, at 
config/vax/vax.c:419
2 | long *bar (long *ptr, long x) { return &foo ()[x + 3]; }
  |^
0x1188489f print_operand_address(_IO_FILE*, rtx_def*)
.../gcc/config/vax/vax.c:419
0x111acbbb default_print_operand_address(_IO_FILE*, machine_mode, rtx_def*)
.../gcc/targhooks.c:367
0x10b3115f output_address(machine_mode, rtx_def*)
.../gcc/final.c:4085
0x10b3088b output_asm_insn(char const*, rtx_def**)
.../gcc/final.c:3942
0x10b2ea63 final_scan_insn_1
.../gcc/final.c:3125
0x10b2eda7 final_scan_insn(rtx_insn*, _IO_FILE*, int, int, int*)
.../gcc/final.c:3171
0x10b2bd1f final_1
.../gcc/final.c:2022
0x10b327e3 rest_of_handle_final
.../gcc/final.c:4676
0x10b32d23 execute
.../gcc/final.c:4754
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See  for instructions.

coming from:

(plus:SI (ashift:SI (reg/v:SI 1 %r1 [orig:29 x ] [29])
(const_int 2 [0x2]))
(reg:SI 0 %r0 [33]))

and serving as a proof that backends used not to expect ASHIFT in 
addresses.  Anyway I went ahead and converted `print_operand_address' too, 
yielding this code:

calls $0,foo
movl 8(%ap),%r1
moval 12(%r0)[%r1],%r0
ret

or:

   c:   d0 ac 08 51 movl 0x8(ap),r1
  10:   de 41 a0 0c moval 0xc(r0)[r1],r0
  14:   50 
  15:   04  ret

which does use indexed addressing:

(insn 24 23 17 (parallel [
(set (reg/i:SI 0 %r0)
(plus:SI (plus:SI (ashift:SI (reg/v:SI 1 %r1 [orig:29 x ] [29])
(const_int 2 [0x2]))
(reg:SI 0 %r0 [33]))
(const_int 12 [0xc])))
(clobber (reg:CC 16 %psl))
]) "test.c":2:56 623 {*movaddrsi}
 (expr_