[PATCH] Optimize multiplication for V8QI,V16QI,V32QI under TARGET_AVX512BW [target/95488]

2020-06-04 Thread Hongtao Liu via Gcc-patches
Hi:

+/* Optimize vector MUL generation for V8QI, V16QI and V32QI
+   under TARGET_AVX512BW. i.e. for v16qi a * b, it has
+
+   vpmovzxbw ymm2, xmm0
+   vpmovzxbw ymm3, xmm1
+   vpmullw   ymm4, ymm2, ymm3
+   vpmovwb   xmm0, ymm4
+
+   it would take less instructions than ix86_expand_vecop_qihi.
+   Return true if success.  */

  Bootstrap is ok, regression test on i386/x86-64 backend is ok.

gcc/ChangeLog:
PR target/95488
* config/i386/i386-expand.c (ix86_expand_vecmul_qihi): New
function.
* config/i386/i386-protos.h (ix86_expand_vecmul_qihi): Declare.
* config/i386/sse.md (mul3): Drop mask_name since
there's no real vector char multiplication instruction with
mask. Also optimize it under TARGET_AVX512BW.
(mulv8qi3): New expander.

gcc/testsuite/ChangeLog:
* gcc.target/i386/avx512bw-pr95488-1.c: New test.
* gcc.target/i386/avx512bw-pr95488-2.c: Ditto.
* gcc.target/i386/avx512vl-pr95488-1.c: Ditto.
* gcc.target/i386/avx512vl-pr95488-2.c: Ditto.

-- 
BR,
Hongtao


0001-Optimize-multiplication-for-V8QI-V16QI-V32QI-under-T.patch
Description: Binary data


[PATCH] PowerPC: Add future hwcap2 bits

2020-06-04 Thread Michael Meissner via Gcc-patches
This patch adds support for the two new HWCAP2 fields used by the
__builtin_cpu_supports function.  It adds support in the target_clones
attribute for -mcpu=future.

The two new __builtin_cpu_supports tests are:
__builtin_cpu_supports ("isa_3_1")
__builtin_cpu_supports ("mma")

The bits used are the bits that the Linux kernel engineers will be using for
these new features.

gcc/
2020-06-04  Michael Meissner  

* config/rs6000/ppc-auxv.h (PPC_PLATFORM_FUTURE): Allocate
'future' PowerPC platform.
(PPC_FEATURE2_ARCH_3_1): New HWCAP2 bit for ISA 3.1.
(PPC_FEATURE2_MMA): New HWCAP2 bit for MMA.
* config/rs6000/rs6000-call.c (cpu_supports_info): Add ISA 3.1 and
MMA HWCAP2 bits.
* config/rs6000/rs6000.c (CLONE_ISA_3_1): New clone support.
(rs6000_clone_map): Add 'future' system target_clones support.

testsuite/
2020-06-04  Michael Meissner  

* gcc.target/powerpc/clone3.c: New test for using 'future' with
the target_clones attribute.
---
 gcc/config/rs6000/ppc-auxv.h  |  6 ++
 gcc/config/rs6000/rs6000-call.c   |  4 +++-
 gcc/config/rs6000/rs6000.c|  2 ++
 gcc/testsuite/gcc.target/powerpc/clone3.c | 33 +++
 4 files changed, 44 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.target/powerpc/clone3.c

diff --git a/gcc/config/rs6000/ppc-auxv.h b/gcc/config/rs6000/ppc-auxv.h
index 3232931..e51d039 100644
--- a/gcc/config/rs6000/ppc-auxv.h
+++ b/gcc/config/rs6000/ppc-auxv.h
@@ -48,6 +48,9 @@
 #define PPC_PLATFORM_POWER813
 #define PPC_PLATFORM_POWER914
 
+/* This is not yet official.  */
+#define PPC_PLATFORM_FUTURE15
+
 /* AT_HWCAP bits.  These must match the values defined in the Linux kernel.  */
 #define PPC_FEATURE_32  0x8000
 #define PPC_FEATURE_64  0x4000
@@ -93,6 +96,9 @@
 #define PPC_FEATURE2_SCV0x0010
 #define PPC_FEATURE2_HTM_NO_SUSPEND 0x0008
 
+/* These are not yet official.  */
+#define PPC_FEATURE2_ARCH_3_1   0x0004
+#define PPC_FEATURE2_MMA0x0002
 
 /* Thread Control Block (TCB) offsets of the AT_PLATFORM, AT_HWCAP and
AT_HWCAP2 values.  These must match the values defined in GLIBC.  */
diff --git a/gcc/config/rs6000/rs6000-call.c b/gcc/config/rs6000/rs6000-call.c
index 0ac8054..817a14c 100644
--- a/gcc/config/rs6000/rs6000-call.c
+++ b/gcc/config/rs6000/rs6000-call.c
@@ -172,7 +172,9 @@ static const struct
   { "arch_3_00",   PPC_FEATURE2_ARCH_3_00, 1 },
   { "ieee128", PPC_FEATURE2_HAS_IEEE128,   1 },
   { "darn",PPC_FEATURE2_DARN,  1 },
-  { "scv", PPC_FEATURE2_SCV,   1 }
+  { "scv", PPC_FEATURE2_SCV,   1 },
+  { "arch_3_1",PPC_FEATURE2_ARCH_3_1,  1 },
+  { "mma", PPC_FEATURE2_MMA,   1 },
 };
 
 static void altivec_init_builtins (void);
diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c
index c2ee3b6..3eb8000 100644
--- a/gcc/config/rs6000/rs6000.c
+++ b/gcc/config/rs6000/rs6000.c
@@ -260,6 +260,7 @@ enum {
   CLONE_ISA_2_06,  /* ISA 2.06 (power7).  */
   CLONE_ISA_2_07,  /* ISA 2.07 (power8).  */
   CLONE_ISA_3_00,  /* ISA 3.00 (power9).  */
+  CLONE_ISA_3_1,   /* ISA 3.1 (future).  */
   CLONE_MAX
 };
 
@@ -275,6 +276,7 @@ static const struct clone_map rs6000_clone_map[CLONE_MAX] = 
{
   { OPTION_MASK_POPCNTD,   "arch_2_06" },  /* ISA 2.06 (power7).  */
   { OPTION_MASK_P8_VECTOR, "arch_2_07" },  /* ISA 2.07 (power8).  */
   { OPTION_MASK_P9_VECTOR, "arch_3_00" },  /* ISA 3.00 (power9).  */
+  { OPTION_MASK_FUTURE,"arch_3_1" },   /* ISA 3.1 (future).  */
 };
 
 
diff --git a/gcc/testsuite/gcc.target/powerpc/clone3.c 
b/gcc/testsuite/gcc.target/powerpc/clone3.c
new file mode 100644
index 000..93ee41d
--- /dev/null
+++ b/gcc/testsuite/gcc.target/powerpc/clone3.c
@@ -0,0 +1,33 @@
+/* { dg-do compile { target { powerpc*-*-linux* && lp64 } } } */
+/* { dg-options "-mdejagnu-cpu=power8 -O2" } */
+/* { dg-require-effective-target powerpc_pcrel } */
+/* { dg-require-effective-target ppc_cpu_supports_hw } */
+
+/* Power9 (aka, ISA 3.0) has a MODSD instruction to do modulus, while Power8
+   (aka, ISA 2.07) has to do modulus with divide and multiply.  Make sure
+   both clone functions are generated.
+
+   FUTURE has pc-relative instructions to access static values, while earlier
+   systems used TOC addressing.
+
+   Restrict ourselves to Linux, since IFUNC might not be supported in other
+   operating systems.  */
+
+static long s;
+long *p = 
+
+__attribute__((target_clones("cpu=future,cpu=power9,default")))
+long mod_func (long a, long b)
+{
+  return (a % b) + s;
+}
+
+long mod_func_or (long a, long b, long c)
+{
+  return mod_func (a, b) | 

Re: [PATCH V2] Practical Improvement to Double Precision Complex Divide

2020-06-04 Thread Joseph Myers
On Fri, 5 Jun 2020, Patrick McGehearty wrote:

> diff --git a/libgcc/libgcc2.c b/libgcc/libgcc2.c
> index e0a9fd7..2a1d3dc 100644
> --- a/libgcc/libgcc2.c
> +++ b/libgcc/libgcc2.c
> @@ -2036,26 +2036,77 @@ CONCAT3(__mul,MODE,3) (MTYPE a, MTYPE b, MTYPE c, 
> MTYPE d)
>  CTYPE
>  CONCAT3(__div,MODE,3) (MTYPE a, MTYPE b, MTYPE c, MTYPE d)
>  {
> +#define RBIG ((DBL_MAX)/2.0)
> +#define RMIN (DBL_MIN)
> +#define RMIN2(0x1.0p-512)
> +#define RMINSCAL (0x1.0p+510)

This code is used for many different machine modes and floating-point 
formats (the type and format corresponding to a particular machine mode 
may depend on the target for which GCC is configured).  You can't hardcode 
particular values specific to DFmode (and to DFmode being IEEE binary64) 
here.

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


[PATCH V2] Practical Improvement to Double Precision Complex Divide

2020-06-04 Thread Patrick McGehearty via Gcc-patches
The following patch to libgcc/libgcc2.c __divdc3 provides an
opportunity to gain important improvements to the quality of answers
for the default double precision complex divide routine when dealing
with very large or very small exponents.

The current code correctly implements Smith's method (1962) [1]
further modified by c99's requirements for dealing with NaN (not a
number) results. When working with input values where the exponents
are greater than 512 (i.e. 2.0^512) or less than -512 (i.e. 2.0^-512),
results are substantially different from the answers provided by quad
precision more than 1% of the time. Since the allowed exponent range
for double precision numbers is -1076 to +1023, the error rate may be
unacceptable for many applications. The proposed method reduces the
frequency of "substantially different" answers by more than 99% at a
modest cost of performance.

Differences between current gcc methods and the new method will be
described. Then accuracy and performance differences will be discussed.

(Added for Version 2)
In my initial research, I missed Elen Kalda's proposed patch
https://gcc.gnu.org/legacy-ml/gcc-patches/2019-08/msg01629.html [3]
Thanks to Joseph Myers for providing me with the pointer.
This version includes performance and accuracy comparisions
between Elen's proposed patch and my latest patch version which
has been modified to eliminate two branches.

NOTATION

For all of the following, the notation is:
Input complex values:
  a+bi  (a= 64bit real part, b= 64bit imaginary part)
  c+di
Output complex value:
  e+fi = (a+bi)/(c+di)

For the result tables:
current = current method (SMITH)
b1div = method proposed by Elen Kalda
b2div = alternate method considered by Elen Kalda
new1 = new method using 1 divide and 2 multiplies
new = new method proposed by this patch

DESCRIPTIONS of different complex divide methods:

NAIVE COMPUTATION (-fcx-limited-range):
  e = (a*c + b*d)/(c*c + d*d)
  f = (b*c - a*d)/(c*c + d*d)

Note that c*c and d*d will overflow or underflow if either
c or d is outside the range 2^-538 to 2^512.

This method is available in gcc when the switch -fcx-limited-range is
used. That switch is also enabled by -ffast-math. Only one who has a
clear understanding of the maximum range of intermediate values
generated by a computation should consider using this switch.

SMITH's METHOD (current libgcc):
  if(fabs(c) RBIG) || (FABS (a) > RBIG) || (FABS (b) > RBIG) ) {
  a = a * 0.5;
  b = b * 0.5;
  c = c * 0.5;
  d = d * 0.5;
  }
  /* minimize overflow/underflow issues when c and d are small */
  else if (FABS (d) < RMIN2) {
  a = a * RMINSCAL;
  b = b * RMINSCAL;
  c = c * RMINSCAL;
  d = d * RMINSCAL;
  }
  r = c/d; denom = (c*r) + d;
  if( r > RMIN ) {
  e = (a*r + b) / denom   ;
  f = (b*r - a) / denom
  } else {
  e = (c * (a/d) + b) / denom;
  f = (c * (b/d) - a) / denom;
  }
[ only presenting the fabs(c) < fabs(d) case here, full code in patch. ]

Before any computation of the answer, the code checks for near maximum or
near minimum inputs and scale the results to move all values away from
the extremes. If the complex divide can be computed at all without
generating infinities, these scalings will not affect the accuracy
since they are by a power of 2.  Values that are over RBIG are
relatively rare but it is easy to test for them and required to avoid
unnecessary overflows.

Testing for RMIN2 reveals when both c and d are less than 2^-512.  By
scaling all values by 2^510, the code avoids many underflows in
intermediate computations that otherwise might occur. If scaling a and
b by 2^510 causes either to overflow, then the computation will overflow
whatever method is used.

Next, r (the ratio of c to d) is checked for being near zero. Baudin
and Smith checked r for zero. Checking for values less than DBL_MIN
covers more cases and improves overall accuracy. If r is near zero,
then when it is used in a multiplication, there is a high chance that
the result will underflow to zero, losing significant accuracy. That
underflow can be avoided if the computation is done in a different
order.  When r is subnormal, the code replaces a*r (= a*(c/d)) with
((a/d)*c) which is mathematically the same but avoids the unnecessary
underflow.

TEST Data

Two sets of data are presented to test these methods.  Both sets
contain 10 million pairs of 64bit complex values.  The exponents and
mantissas are generated using multiple calls to random() and then
combining the results. Only values which give results to complex
divide that are representable in 64-bits after being computed in quad
precision are used.

The first data set is labeled "moderate exponents".
The exponent range is limited to -512 to +511.
The second data set is labeled "full exponents".
The exponent range is -1076 to + 1024.

ACCURACY Test results:

Note: All results are based on use of fused multiply-add. If
fused multiply-add is not used, the error rate increases slightly
for 

[committed] libstdc++: Remove workarounds for constrained nested class templates

2020-06-04 Thread Jonathan Wakely via Gcc-patches
With PR c++/92078 and PR c++/92103 both fixed, nested class templates
can now be constrained. That means a number of namespace-scope helpers
can be moved to the class scope, so they're only visible where they're
needed.

* include/bits/iterator_concepts.h (__detail::__ptr, __detail::__ref)
(__detail::__cat, __detail::__diff): Move to class scope in the
relevant __iterator_traits specializations.
(__iterator_traits<>): Use nested class templates instead of ones from
namespace __detail.
* include/bits/stl_iterator.h (__detail::__common_iter_ptr): Move to
class scope in iterator_traits>.
(iterator_traits>): Use nested class template
instead of __detail::__common_iter_ptr.

Tested powerpc64le-linux, committed to master.

Patrick backported the 92103 fix to gcc-10, so this could be
backported too. I will let it baek on master for a while though.


commit f2242ec0d3f1bb13c78ef3c21e0354d84fe57222
Author: Jonathan Wakely 
Date:   Thu Jun 4 23:20:49 2020 +0100

libstdc++: Remove workarounds for constrained nested class templates

With PR c++/92078 and PR c++/92103 both fixed, nested class templates
can now be constrained. That means a number of namespace-scope helpers
can be moved to the class scope, so they're only visible where they're
needed.

* include/bits/iterator_concepts.h (__detail::__ptr, 
__detail::__ref)
(__detail::__cat, __detail::__diff): Move to class scope in the
relevant __iterator_traits specializations.
(__iterator_traits<>): Use nested class templates instead of ones 
from
namespace __detail.
* include/bits/stl_iterator.h (__detail::__common_iter_ptr): Move to
class scope in iterator_traits>.
(iterator_traits>): Use nested class template
instead of __detail::__common_iter_ptr.

diff --git a/libstdc++-v3/include/bits/iterator_concepts.h 
b/libstdc++-v3/include/bits/iterator_concepts.h
index 31b58408fe9..e56abe2be6c 100644
--- a/libstdc++-v3/include/bits/iterator_concepts.h
+++ b/libstdc++-v3/include/bits/iterator_concepts.h
@@ -320,84 +320,26 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
 template
   concept __iter_without_nested_types = !__iter_with_nested_types<_Iter>;
-
-// FIXME: These have to be at namespace-scope because of PR 92103.
-template
-  struct __ptr
-  { using type = void; };
-
-template requires requires { typename _Iter::pointer; }
-  struct __ptr<_Iter, true>
-  { using type = typename _Iter::pointer; };
-
-template requires requires { typename _Iter::pointer; }
-  struct __ptr<_Iter, false>
-  { using type = typename _Iter::pointer; };
-
-template
-  requires (!requires { typename _Iter::pointer; }
- && requires(_Iter& __it) { __it.operator->(); })
-  struct __ptr<_Iter, true>
-  { using type = decltype(std::declval<_Iter&>().operator->()); };
-
-template
-  struct __ref
-  { using type = iter_reference_t<_Iter>; };
-
-template requires requires { typename _Iter::reference; }
-  struct __ref<_Iter>
-  { using type = typename _Iter::reference; };
-
-template
-  struct __cat
-  { using type = input_iterator_tag; };
-
-template
-  requires requires { typename _Iter::iterator_category; }
-  struct __cat<_Iter>
-  { using type = typename _Iter::iterator_category; };
-
-template
-  requires (!requires { typename _Iter::iterator_category; }
-   && __detail::__cpp17_randacc_iterator<_Iter>)
-  struct __cat<_Iter>
-  { using type = random_access_iterator_tag; };
-
-template
-  requires (!requires { typename _Iter::iterator_category; }
-   && __detail::__cpp17_bidi_iterator<_Iter>)
-  struct __cat<_Iter>
-  { using type = bidirectional_iterator_tag; };
-
-template
-  requires (!requires { typename _Iter::iterator_category; }
-   && __detail::__cpp17_fwd_iterator<_Iter>)
-  struct __cat<_Iter>
-  { using type = forward_iterator_tag; };
-
-template
-  struct __diff
-  { using type = void; };
-
-template
-  requires requires {
-   typename incrementable_traits<_Iter>::difference_type;
-  }
-  struct __diff<_Iter>
-  {
-   using type = typename incrementable_traits<_Iter>::difference_type;
-  };
-
   } // namespace __detail
 
   template
 requires __detail::__iter_with_nested_types<_Iterator>
 struct __iterator_traits<_Iterator, void>
 {
+private:
+  template
+   struct __ptr
+   { using type = void; };
+
+  template requires requires { typename _Iter::pointer; }
+   struct __ptr<_Iter>
+   { using type = typename _Iter::pointer; };
+
+public:
   using iterator_category = typename _Iterator::iterator_category;
   using value_type   = typename _Iterator::value_type;
   using 

Re: [PATCH] diagnostics: Consistently add fixit hint for implicit builtin declaration

2020-06-04 Thread Mark Wielaard
Hi,

On Fri, 2020-05-29 at 09:13 -0600, Martin Sebor wrote:
> On 5/28/20 7:13 PM, Mark Wielaard wrote:
> > On Thu, May 28, 2020 at 06:21:39PM -0600, Martin Sebor wrote:
> > > Although few tests bother with it, since you add an option for
> > > the existing warning where there was none before, an even more
> > > exhaustive test than the one you added would also verify the same
> > > option can be used to suppress it (e.g., via #pragma GCC
> > > diagnostic
> > > ignored).
> > 
> > OK. How about this variant with an extra
> > Wbuiltin-declaration-mismatch-ignore.c test?
> > It FAILS with (test for excess errors) before the patch.
> > It PASSes with the patch.
> 
> It looks good to me but I can't formally approve it.

Thanks. Rebased patch attached.
David, would you be able to approve it?
Or do we need to bribe a C frontend maintainer?

Cheers,

Mark
From 719b174233176fae49716936fa4ab9ead54f95cb Mon Sep 17 00:00:00 2001
From: Mark Wielaard 
Date: Thu, 28 May 2020 02:55:36 +0200
Subject: [PATCH] diagnostics: Consistently add fixit hint for implicit builtin
 declaration

There are two warnings that might trigger when a builtin function is
used but not declared yet. Both called through implicitly_declare in
c-decl. The first in implicit_decl_warning does warn for builtins,
but does not add a fixit hint for them (only for non-builtins when
a header is suggested through lookup_name_fuzzy). This warning is
guarded by -Wimplicit-function-declaration. The second warning, which
does include a fixit hint if possible, is given when the implicit
builtin declaration has an incompatible signature. This second warning
cannot be disabled.

This setup means that you only get a fixit-hint for usage of builtin
functions where the implicit signature is different than the actual
signature of the builtin. No fixit hints with header suggestions
are ever generated for builtins like abs, isdigit or putchar.

It seems more consistent to always generate a fixit-hint if possible
for the -Wimplicit-function-declaration warning. And for the second
warning to make it depend on -Wbuiltin-declaration-mismatch like
other warnings about builtin declaration mismatches.

Include a new test to show we get fixit-hints for abs, isdigit and
putchar now. Some small tweaks to existing tests to show the
effect of -Wno-builtin-declaration-mismatch with this change. And
a testcase to show that #pragma GCC diagnostic ignored now works.

gcc/c/ChangeLog:

	* c-decl.c (implicit_decl_warning): When warned and olddecl is
	an undeclared builtin, then add a fixit header hint, if found.
	(implicitly_declare): Add OPT_Wbuiltin_declaration_mismatch to
	warning_at about implicit builtin declaration type mismatch.

gcc/testsuite/ChangeLog:

	* gcc.dg/missing-header-fixit-4.c: Add
	-Wno-implicit-function-declaration.
	* gcc.dg/missing-header-fixit-4.c: Add new expected output.
	* gcc.dg/missing-header-fixit-5.c: New testcase.
	* gcc.dg/Wbuiltin-declaration-mismatch-ignore.c: Likewise.
---
 gcc/c/c-decl.c| 30 ++--
 .../Wbuiltin-declaration-mismatch-ignore.c| 11 ++
 gcc/testsuite/gcc.dg/missing-header-fixit-3.c |  2 +-
 gcc/testsuite/gcc.dg/missing-header-fixit-4.c |  4 +++
 gcc/testsuite/gcc.dg/missing-header-fixit-5.c | 36 +++
 5 files changed, 79 insertions(+), 4 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/Wbuiltin-declaration-mismatch-ignore.c
 create mode 100644 gcc/testsuite/gcc.dg/missing-header-fixit-5.c

diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c
index b3e05be0af87..81bd2ee94f02 100644
--- a/gcc/c/c-decl.c
+++ b/gcc/c/c-decl.c
@@ -3368,8 +3368,30 @@ implicit_decl_warning (location_t loc, tree id, tree olddecl)
 warned = warning_at (loc, OPT_Wimplicit_function_declaration,
 			 G_("implicit declaration of function %qE"), id);
 
-  if (olddecl && warned)
-locate_old_decl (olddecl);
+  if (warned)
+{
+  /* Whether the olddecl is an undeclared builtin function.
+	 locate_old_decl will not generate a diagnostic for those,
+	 so in that case we want to look elsewhere.  */
+  bool undeclared_builtin = (olddecl
+ && TREE_CODE (olddecl) == FUNCTION_DECL
+ && fndecl_built_in_p (olddecl)
+ && !C_DECL_DECLARED_BUILTIN (olddecl));
+  if (undeclared_builtin)
+	{
+	  const char *header = header_for_builtin_fn (olddecl);
+	  if (header)
+	{
+	  rich_location richloc (line_table, loc);
+	  maybe_add_include_fixit (, header, true);
+	  inform (,
+		  "include %qs or provide a declaration of %qE",
+		  header, id);
+	}
+	}
+  else if (olddecl)
+	locate_old_decl (olddecl);
+}
 
   if (!warned)
 hint.suppress ();
@@ -3631,7 +3653,9 @@ implicitly_declare (location_t loc, tree functionid)
 		  (TREE_TYPE (decl)));
 	  if (!comptypes (newtype, TREE_TYPE (decl)))
 		{
-		  bool warned = warning_at (loc, 0, "incompatible implicit "
+		  bool warned = warning_at (loc,
+	OPT_Wbuiltin_declaration_mismatch,
+	

[committed] d: Merge upstream dmd 48d704f08

2020-06-04 Thread Iain Buclaw via Gcc-patches
Hi,

This patch merges the D front-end implementation with upstream dmd
47ed0330f.  Updates the Array interface in dmd/root/array to use a
DArray internally.  Splits out BitArray into a separate header.

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

Regards
Iain.


gcc/d/ChangeLog:

* dmd/MERGE: Merge upstream dmd 48d704f08.
* d-attribs.cc (build_attributes): Use new field name.
* d-builtins.cc (build_frontend_type): Likewise.
(maybe_set_builtin_1): Likewise.
(d_maybe_set_builtin): Likewise.
* d-codegen.cc (build_interface_binfo): Likewise.
(identity_compare_p): Likewise.
(lower_struct_comparison): Likewise.
(build_struct_comparison): Likewise.
(d_build_call): Likewise.
(build_frame_type): Likewise.
(build_closure): Likewise.
* d-compiler.cc (Compiler::paintAsType): Likewise.
(Compiler::loadModule): Likewise.
* d-incpath.cc (add_globalpaths): Likewise.
(add_filepaths): Likewise.
(add_import_paths): Likewise.
* d-lang.cc (deps_write): Likewise.
(d_parse_file): Likewise.
* decl.cc (gcc_attribute_p): Likewise.
(base_vtable_offset): Likewise.
(get_vtable_decl): Likewise.
(build_class_instance): Likewise.
* expr.cc (class ExprVisitor): Likewise.
* modules.cc (layout_moduleinfo_fields): Likewise.
(layout_moduleinfo): Likewise.
(build_module_tree): Likewise.
* toir.cc (class IRVisitor): Likewise.
* typeinfo.cc (class TypeInfoVisitor): Likewise.
(layout_classinfo_interfaces): Likewise.
* types.cc (layout_aggregate_members): Likewise.
(layout_aggregate_type): Likewise.
---
 gcc/d/d-attribs.cc   |   4 +-
 gcc/d/d-builtins.cc  |   8 +-
 gcc/d/d-codegen.cc   |  28 +--
 gcc/d/d-compiler.cc  |   8 +-
 gcc/d/d-incpath.cc   |  10 +-
 gcc/d/d-lang.cc  |  38 ++--
 gcc/d/decl.cc|  44 ++--
 gcc/d/dmd/MERGE  |   2 +-
 gcc/d/dmd/access.c   |   6 +-
 gcc/d/dmd/apply.c|   2 +-
 gcc/d/dmd/arrayop.c  |   6 +-
 gcc/d/dmd/arraytypes.h   |   3 +-
 gcc/d/dmd/attrib.c   |  90 
 gcc/d/dmd/blockexit.c|   8 +-
 gcc/d/dmd/canthrow.c |   8 +-
 gcc/d/dmd/clone.c|  36 +--
 gcc/d/dmd/compiler.h |   1 +
 gcc/d/dmd/cond.c |   8 +-
 gcc/d/dmd/constfold.c|  56 ++---
 gcc/d/dmd/cppmangle.c|  14 +-
 gcc/d/dmd/ctfeexpr.c |  90 
 gcc/d/dmd/dcast.c|  48 ++--
 gcc/d/dmd/dclass.c   |  82 +++
 gcc/d/dmd/declaration.c  |  62 ++
 gcc/d/dmd/denum.c|  20 +-
 gcc/d/dmd/dimport.c  |  24 +-
 gcc/d/dmd/dinterpret.c   | 170 +++
 gcc/d/dmd/dmangle.c  |   6 +-
 gcc/d/dmd/dmodule.c  |  62 +++---
 gcc/d/dmd/doc.c  |  52 ++---
 gcc/d/dmd/dscope.c   |   8 +-
 gcc/d/dmd/dstruct.c  |  48 ++--
 gcc/d/dmd/dsymbol.c  |  40 ++--
 gcc/d/dmd/dtemplate.c| 410 +--
 gcc/d/dmd/escape.c   |  54 ++---
 gcc/d/dmd/expression.c   | 108 -
 gcc/d/dmd/expressionsem.c| 110 +-
 gcc/d/dmd/func.c |  96 
 gcc/d/dmd/hdrgen.c   | 110 +-
 gcc/d/dmd/iasmgcc.c  |   6 +-
 gcc/d/dmd/init.c |  30 +--
 gcc/d/dmd/initsem.c  |  36 +--
 gcc/d/dmd/json.c |  34 +--
 gcc/d/dmd/mtype.c| 114 +-
 gcc/d/dmd/mtype.h|   2 +-
 gcc/d/dmd/nogc.c |   4 +-
 gcc/d/dmd/nspace.c   |  18 +-
 gcc/d/dmd/opover.c   |  40 ++--
 gcc/d/dmd/optimize.c |  18 +-
 gcc/d/dmd/parse.c|  38 ++--
 gcc/d/dmd/root/array.h   | 227 +--
 gcc/d/dmd/root/bitarray.h|  32 +++
 gcc/d/dmd/root/dcompat.h |  12 +
 gcc/d/dmd/root/filename.c|   4 +-
 gcc/d/dmd/root/rmem.h|  11 +-
 gcc/d/dmd/root/stringtable.h |   2 +-
 gcc/d/dmd/sapply.c   |   6 +-
 gcc/d/dmd/statement.c|  44 ++--
 gcc/d/dmd/statementsem.c |  96 
 gcc/d/dmd/traits.c   |  34 +--
 gcc/d/dmd/typesem.c  |   2 +-
 gcc/d/expr.cc|  64 +++---
 gcc/d/modules.cc |  29 +--
 gcc/d/toir.cc|  24 +-
 gcc/d/typeinfo.cc|  56 ++---
 gcc/d/types.cc   |  16 +-
 66 files changed, 1503 insertions(+), 1476 deletions(-)
 create mode 100644 gcc/d/dmd/root/bitarray.h


dmd48d704f08.patch.gz
Description: application/gzip


Re: [PATCH] Do not copy NULL string with memcpy.

2020-06-04 Thread Alexandre Oliva
On Jun  3, 2020, Martin Liška  wrote:

> On 6/3/20 5:58 AM, Alexandre Oliva wrote:
>> Please let me know if you'd prefer me to take this PR over.

> Yes, please take a look.

Here's what I've regstrapped on x86_64-linux-gnu.  It makes both memcpy
calls conditional, and reorders the length computation to match.

I also ran outputs.exp with a memcpy wrapper in gcc.c to detect any
calls with NULL pointers, and nothing else came up.

Ok to install?


[PR95456] avoid memcpy (_, NULL, 0) in gcc.c

From: Alexandre Oliva 

Some newly-added code in gcc.c might call memcpy with a NULL source
pointer and zero-length inputs.  Avoid such calls by rearranging the
code a little.


for  gcc/ChangeLog

PR driver/95456
* gcc.c (do_spec_1): Don't call memcpy (_, NULL, 0).
---
 gcc/gcc.c |   14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/gcc/gcc.c b/gcc/gcc.c
index e2362175f4..c0eb3c1 100644
--- a/gcc/gcc.c
+++ b/gcc/gcc.c
@@ -6024,19 +6024,19 @@ do_spec_1 (const char *spec, int inswitch, const char 
*soft_matched_part)
  }
temp_filename_length
  = dumpdir_length + suffix_length + 1;
-   if (!outbase_length)
- temp_filename_length += basename_length;
-   else
+   if (outbase_length)
  temp_filename_length += outbase_length;
+   else
+ temp_filename_length += basename_length;
tmp = (char *) alloca (temp_filename_length);
if (dumpdir_length)
  memcpy (tmp, dumpdir, dumpdir_length);
-   if (!outbase_length)
- memcpy (tmp + dumpdir_length, input_basename,
- basename_length);
-   else
+   if (outbase_length)
  memcpy (tmp + dumpdir_length, outbase,
  outbase_length);
+   else if (basename_length)
+ memcpy (tmp + dumpdir_length, input_basename,
+ basename_length);
memcpy (tmp + temp_filename_length - suffix_length - 1,
suffix, suffix_length);
if (adjusted_suffix)


-- 
Alexandre Oliva, freedom fighterhe/himhttps://FSFLA.org/blogs/lxo/
Free Software Evangelist  Stallman was right, but he's left :(
GNU Toolchain Engineer   Live long and free, and prosper ethically


[committed] d: Merge upstream dmd 47ed0330f

2020-06-04 Thread Iain Buclaw via Gcc-patches
Hi,

This parch merges the D front-end implementation with upstream dmd
47ed0330f.  Updating the copyright years of the front-end sources.

Committed to mainline.

Regards
Iain


gcc/d/ChangeLog:

* dmd/MERGE: Merge upstream dmd 47ed0330f.
---
 gcc/d/dmd/MERGE  | 2 +-
 gcc/d/dmd/access.c   | 2 +-
 gcc/d/dmd/aggregate.h| 2 +-
 gcc/d/dmd/aliasthis.c| 2 +-
 gcc/d/dmd/aliasthis.h| 2 +-
 gcc/d/dmd/apply.c| 2 +-
 gcc/d/dmd/arrayop.c  | 2 +-
 gcc/d/dmd/arraytypes.h   | 2 +-
 gcc/d/dmd/attrib.c   | 2 +-
 gcc/d/dmd/attrib.h   | 2 +-
 gcc/d/dmd/blockexit.c| 2 +-
 gcc/d/dmd/canthrow.c | 2 +-
 gcc/d/dmd/clone.c| 2 +-
 gcc/d/dmd/compiler.h | 2 +-
 gcc/d/dmd/complex_t.h| 2 +-
 gcc/d/dmd/cond.c | 2 +-
 gcc/d/dmd/cond.h | 2 +-
 gcc/d/dmd/constfold.c| 2 +-
 gcc/d/dmd/cppmangle.c| 2 +-
 gcc/d/dmd/ctfe.h | 2 +-
 gcc/d/dmd/ctfeexpr.c | 2 +-
 gcc/d/dmd/dcast.c| 2 +-
 gcc/d/dmd/dclass.c   | 2 +-
 gcc/d/dmd/declaration.c  | 2 +-
 gcc/d/dmd/declaration.h  | 2 +-
 gcc/d/dmd/delegatize.c   | 2 +-
 gcc/d/dmd/denum.c| 2 +-
 gcc/d/dmd/dimport.c  | 2 +-
 gcc/d/dmd/dinterpret.c   | 2 +-
 gcc/d/dmd/dmacro.c   | 2 +-
 gcc/d/dmd/dmangle.c  | 2 +-
 gcc/d/dmd/dmodule.c  | 2 +-
 gcc/d/dmd/doc.c  | 2 +-
 gcc/d/dmd/doc.h  | 2 +-
 gcc/d/dmd/dscope.c   | 2 +-
 gcc/d/dmd/dstruct.c  | 2 +-
 gcc/d/dmd/dsymbol.c  | 2 +-
 gcc/d/dmd/dsymbol.h  | 2 +-
 gcc/d/dmd/dtemplate.c| 2 +-
 gcc/d/dmd/dversion.c | 2 +-
 gcc/d/dmd/entity.c   | 2 +-
 gcc/d/dmd/enum.h | 2 +-
 gcc/d/dmd/errors.h   | 2 +-
 gcc/d/dmd/escape.c   | 2 +-
 gcc/d/dmd/expression.c   | 2 +-
 gcc/d/dmd/expression.h   | 2 +-
 gcc/d/dmd/expressionsem.c| 2 +-
 gcc/d/dmd/func.c | 2 +-
 gcc/d/dmd/globals.h  | 2 +-
 gcc/d/dmd/hdrgen.c   | 2 +-
 gcc/d/dmd/hdrgen.h   | 2 +-
 gcc/d/dmd/iasm.c | 2 +-
 gcc/d/dmd/iasmgcc.c  | 2 +-
 gcc/d/dmd/identifier.c   | 2 +-
 gcc/d/dmd/identifier.h   | 2 +-
 gcc/d/dmd/idgen.c| 2 +-
 gcc/d/dmd/impcnvgen.c| 2 +-
 gcc/d/dmd/imphint.c  | 2 +-
 gcc/d/dmd/import.h   | 2 +-
 gcc/d/dmd/init.c | 2 +-
 gcc/d/dmd/init.h | 2 +-
 gcc/d/dmd/initsem.c  | 2 +-
 gcc/d/dmd/intrange.c | 2 +-
 gcc/d/dmd/intrange.h | 2 +-
 gcc/d/dmd/json.c | 2 +-
 gcc/d/dmd/json.h | 2 +-
 gcc/d/dmd/lexer.c| 2 +-
 gcc/d/dmd/lexer.h| 2 +-
 gcc/d/dmd/macro.h| 2 +-
 gcc/d/dmd/mangle.h   | 2 +-
 gcc/d/dmd/mars.h | 2 +-
 gcc/d/dmd/module.h   | 2 +-
 gcc/d/dmd/mtype.c| 2 +-
 gcc/d/dmd/mtype.h| 2 +-
 gcc/d/dmd/nogc.c | 2 +-
 gcc/d/dmd/nspace.c   | 2 +-
 gcc/d/dmd/nspace.h   | 2 +-
 gcc/d/dmd/objc.c | 2 +-
 gcc/d/dmd/objc.h | 2 +-
 gcc/d/dmd/opover.c   | 2 +-
 gcc/d/dmd/optimize.c | 2 +-
 gcc/d/dmd/parse.c| 2 +-
 gcc/d/dmd/parse.h| 2 +-
 gcc/d/dmd/root/aav.c | 2 +-
 gcc/d/dmd/root/aav.h | 2 +-
 gcc/d/dmd/root/array.h   | 3 ++-
 gcc/d/dmd/root/checkedint.c  | 2 +-
 gcc/d/dmd/root/checkedint.h  | 2 +-
 gcc/d/dmd/root/ctfloat.h | 2 +-
 gcc/d/dmd/root/dcompat.h | 2 +-
 gcc/d/dmd/root/file.c| 2 +-
 gcc/d/dmd/root/file.h| 2 +-
 gcc/d/dmd/root/filename.c| 2 +-
 gcc/d/dmd/root/filename.h| 2 +-
 gcc/d/dmd/root/hash.h| 2 +-
 gcc/d/dmd/root/object.h  | 2 +-
 gcc/d/dmd/root/outbuffer.c   | 2 +-
 gcc/d/dmd/root/outbuffer.h   | 2 +-
 gcc/d/dmd/root/port.h| 2 +-
 gcc/d/dmd/root/rmem.c| 2 +-
 gcc/d/dmd/root/rmem.h| 2 +-
 gcc/d/dmd/root/root.h| 2 +-
 gcc/d/dmd/root/rootobject.c  | 2 +-
 gcc/d/dmd/root/speller.c | 2 +-
 gcc/d/dmd/root/speller.h | 2 +-
 gcc/d/dmd/root/stringtable.c | 2 +-
 gcc/d/dmd/root/stringtable.h | 2 +-
 gcc/d/dmd/safe.c | 2 +-
 gcc/d/dmd/sapply.c   | 2 +-
 gcc/d/dmd/scope.h| 2 +-
 gcc/d/dmd/sideeffect.c   | 2 +-
 gcc/d/dmd/statement.c| 2 +-
 gcc/d/dmd/statement.h| 2 +-
 gcc/d/dmd/statementsem.c | 2 +-
 gcc/d/dmd/staticassert.c | 2 +-
 gcc/d/dmd/staticassert.h | 2 +-
 gcc/d/dmd/staticcond.c   | 2 +-
 gcc/d/dmd/target.h   | 2 +-
 gcc/d/dmd/template.h | 2 +-
 gcc/d/dmd/tokens.c   | 2 +-
 gcc/d/dmd/tokens.h   | 2 +-
 gcc/d/dmd/traits.c   | 2 +-
 gcc/d/dmd/typesem.c  | 2 +-
 gcc/d/dmd/utf.c  | 2 +-
 gcc/d/dmd/utf.h  | 2 +-
 gcc/d/dmd/utils.c| 2 +-
 gcc/d/dmd/version.h  | 2 +-
 gcc/d/dmd/visitor.h  | 2 +-
 128 

[pushed] c++: Fix complex constexpr virtual cases [PR93310].

2020-06-04 Thread Jason Merrill via Gcc-patches
The code in constexpr for looking up the actual type of the object and then
getting the virtual function from there broke for both of these tests: for
16, it assumed incorrectly that the DECL_VINDEX would apply to the most
derived type's vtable; for 17, it failed to consider that during
construction the base subobject is treated as being of the base type.

Fixed by just doing constant evaluation of the expression that looks up the
function in the vtable.  This means that a virtual call will involve loading
the vptr, so we will reject some calls through non-constexpr variables that
we previously accepted, but this seems appropriate to me.  None of our
testcases were affected.

gcc/cp/ChangeLog:

PR c++/93310
* constexpr.c (cxx_eval_constant_expression) [OBJ_TYPE_REF]:
Evaluate OBJ_TYPE_REF_EXPR.

gcc/testsuite/ChangeLog:

PR c++/93310
* g++.dg/cpp2a/constexpr-virtual16.C: New test.
* g++.dg/cpp2a/constexpr-virtual17.C: New test.
* g++.dg/cpp2a/constexpr-new12.C: Adjust diagnostic.
---
 gcc/cp/constexpr.c| 44 ++-
 gcc/testsuite/g++.dg/cpp2a/constexpr-new12.C  |  2 +-
 .../g++.dg/cpp2a/constexpr-virtual16.C| 22 ++
 .../g++.dg/cpp2a/constexpr-virtual17.C| 28 
 4 files changed, 54 insertions(+), 42 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/cpp2a/constexpr-virtual16.C
 create mode 100644 gcc/testsuite/g++.dg/cpp2a/constexpr-virtual17.C

diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c
index c7d17e9b86e..c01c42bf886 100644
--- a/gcc/cp/constexpr.c
+++ b/gcc/cp/constexpr.c
@@ -6373,47 +6373,9 @@ cxx_eval_constant_expression (const constexpr_ctx *ctx, 
tree t,
   break;
 
 case OBJ_TYPE_REF:
-  {
-   /* Virtual function call.  Let the constexpr machinery figure out
-  the dynamic type.  */
-   int token = tree_to_shwi (OBJ_TYPE_REF_TOKEN (t));
-   tree obj = OBJ_TYPE_REF_OBJECT (t);
-   obj = cxx_eval_constant_expression (ctx, obj, lval, non_constant_p,
-   overflow_p);
-   STRIP_NOPS (obj);
-   /* We expect something in the form of  get x. */
-   if (TREE_CODE (obj) != ADDR_EXPR
-   || !DECL_P (get_base_address (TREE_OPERAND (obj, 0
- {
-   if (!ctx->quiet)
- error_at (loc, "expression %qE is not a constant expression", t);
-   *non_constant_p = true;
-   return t;
- }
-   obj = TREE_OPERAND (obj, 0);
-   while (TREE_CODE (obj) == COMPONENT_REF
-  && DECL_FIELD_IS_BASE (TREE_OPERAND (obj, 1)))
- obj = TREE_OPERAND (obj, 0);
-   tree objtype = TREE_TYPE (obj);
-   if (VAR_P (obj)
-   && DECL_NAME (obj) == heap_identifier
-   && TREE_CODE (objtype) == ARRAY_TYPE)
- objtype = TREE_TYPE (objtype);
-   if (!CLASS_TYPE_P (objtype))
- {
-   if (!ctx->quiet)
- error_at (loc, "expression %qE is not a constant expression", t);
-   *non_constant_p = true;
-   return t;
- }
-   /* Find the function decl in the virtual functions list.  TOKEN is
-  the DECL_VINDEX that says which function we're looking for.  */
-   tree virtuals = BINFO_VIRTUALS (TYPE_BINFO (objtype));
-   if (TARGET_VTABLE_USES_DESCRIPTORS)
- token /= MAX (TARGET_VTABLE_USES_DESCRIPTORS, 1);
-   r = TREE_VALUE (chain_index (token, virtuals));
-   break;
-  }
+  /* Virtual function lookup.  We don't need to do anything fancy.  */
+  return cxx_eval_constant_expression (ctx, OBJ_TYPE_REF_EXPR (t),
+  lval, non_constant_p, overflow_p);
 
 case PLACEHOLDER_EXPR:
   /* Use of the value or address of the current object.  */
diff --git a/gcc/testsuite/g++.dg/cpp2a/constexpr-new12.C 
b/gcc/testsuite/g++.dg/cpp2a/constexpr-new12.C
index fcf398f000e..5a3d06a5fab 100644
--- a/gcc/testsuite/g++.dg/cpp2a/constexpr-new12.C
+++ b/gcc/testsuite/g++.dg/cpp2a/constexpr-new12.C
@@ -24,4 +24,4 @@ foo ()
   return r;
 }
 
-constexpr auto a = foo (); // { dg-error "is not a constant expression" }
+constexpr auto a = foo (); // { dg-error "constant expression" }
diff --git a/gcc/testsuite/g++.dg/cpp2a/constexpr-virtual16.C 
b/gcc/testsuite/g++.dg/cpp2a/constexpr-virtual16.C
new file mode 100644
index 000..8cca8a61723
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/constexpr-virtual16.C
@@ -0,0 +1,22 @@
+// Test constexpr virtual in non-primary vtable.
+// { dg-do compile { target c++20 } }
+
+struct A
+{
+  virtual constexpr int f() const { return 1; };
+};
+
+struct B
+{
+  virtual constexpr int g() const { return 2; };
+};
+
+struct C: A, B
+{
+};
+
+constexpr C c;
+
+constexpr int g(const B& b) { return b.g(); }
+static_assert (g(c) == 2);
+
diff --git a/gcc/testsuite/g++.dg/cpp2a/constexpr-virtual17.C 
b/gcc/testsuite/g++.dg/cpp2a/constexpr-virtual17.C
new 

[PATCH, committed] PR fortran/95500 - Segfault compiling extra interface on intrinsic

2020-06-04 Thread Harald Anlauf
Committed as obvious.  Regtests cleanly on x86_64-pc-linux-gnu.

Thanks to Steve Kargl for the patch.

This is an ICE-on-valid due to a NULL pointer dereference;
it looks safe and could be backported to 9/10.

Thanks,
Harald


PR fortran/95500 - Segfault compiling extra interface on intrinsic

Converting an expression so that it can be passed by reference could
result in a NULL pointer dereference.

2020-06-04  Steven G. Kargl  
Harald Anlauf  

gcc/fortran/
PR fortran/95500
* trans-expr.c (gfc_conv_expr_reference): Do not dereference NULL
pointer.

gcc/testsuite/
PR fortran/95500
* gfortran.dg/pr95500.f90: New test.

diff --git a/gcc/fortran/trans-expr.c b/gcc/fortran/trans-expr.c
index 435eaeb2c99..8b2afd27fb3 100644
--- a/gcc/fortran/trans-expr.c
+++ b/gcc/fortran/trans-expr.c
@@ -8811,6 +8811,7 @@ gfc_conv_expr_reference (gfc_se * se, gfc_expr * expr, bool add_clobber)

   if (expr->expr_type == EXPR_FUNCTION
   && ((expr->value.function.esym
+	   && expr->value.function.esym->result
 	   && expr->value.function.esym->result->attr.pointer
 	   && !expr->value.function.esym->result->attr.dimension)
 	  || (!expr->value.function.esym && !expr->ref
diff --git a/gcc/testsuite/gfortran.dg/pr95500.f90 b/gcc/testsuite/gfortran.dg/pr95500.f90
new file mode 100644
index 000..e9eb7c65c86
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr95500.f90
@@ -0,0 +1,15 @@
+! { dg-do compile }
+! PR fortran/95500 - ICE compiling extra interface on intrinsic
+
+program test_intrinsic
+  implicit none
+  intrinsic :: alog
+  intrinsic :: dlog
+  real (4), parameter :: one = 1
+
+  interface ln
+ procedure :: alog, dlog
+  end interface ln
+
+  write (*,*) 'ln  1', ln (one)
+end program test_intrinsic


[pushed] c++: Fix FE devirt with diamond inheritance [PR95158]

2020-06-04 Thread Jason Merrill via Gcc-patches
This started breaking in GCC 8 because of the fix for PR15272; after that
change, we (correctly) remember the lookup from template parsing time that
found Base::foo through the non-dependent MiddleB base, and so we overlook
the overrider in MiddleA.  But given that, the devirtualization condition
from the fix for PR59031 is insufficient; we know that d has to be a
Derived, and we found Base::foo in Base, but forcing a non-virtual call
gets the wrong function.

Fixed by removing the PR59031 code that the PR67184 patch moved to
build_over_call, and instead looking up the overrider in BINFO_VIRTUALS.

gcc/cp/ChangeLog:

PR c++/95158
* class.c (lookup_vfn_in_binfo): New.
* call.c (build_over_call): Use it.
* cp-tree.h (resolves_to_fixed_type_p): Add default argument.
(lookup_vfn_in_binfo): Declare.

gcc/testsuite/ChangeLog:

PR c++/95158
* g++.dg/template/virtual5.C: New test.
---
 gcc/cp/cp-tree.h |  3 ++-
 gcc/cp/call.c| 22 +
 gcc/cp/class.c   | 14 +++
 gcc/testsuite/g++.dg/template/virtual5.C | 31 
 4 files changed, 59 insertions(+), 11 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/template/virtual5.C

diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index 447d1349117..44cb10cfee5 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -6401,7 +6401,7 @@ extern tree outermost_open_class  (void);
 extern tree current_nonlambda_class_type   (void);
 extern tree finish_struct  (tree, tree);
 extern void finish_struct_1(tree);
-extern int resolves_to_fixed_type_p(tree, int *);
+extern int resolves_to_fixed_type_p(tree, int * = NULL);
 extern void init_class_processing  (void);
 extern int is_empty_class  (tree);
 extern bool is_really_empty_class  (tree, bool);
@@ -6415,6 +6415,7 @@ extern void pop_lang_context  (void);
 extern tree instantiate_type   (tree, tree, tsubst_flags_t);
 extern void build_self_reference   (void);
 extern int same_signature_p(const_tree, const_tree);
+extern tree lookup_vfn_in_binfo(tree, tree);
 extern void maybe_add_class_template_decl_list (tree, tree, int);
 extern void unreverse_member_declarations  (tree);
 extern void invalidate_class_lookup_cache  (void);
diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index a51ebb5d9e3..2b393f96e5b 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -8704,19 +8704,21 @@ build_over_call (struct z_candidate *cand, int flags, 
tsubst_flags_t complain)
return error_mark_node;
}
 
-  /* Optimize away vtable lookup if we know that this
-function can't be overridden.  We need to check if
-the context and the type where we found fn are the same,
-actually FN might be defined in a different class
-type because of a using-declaration. In this case, we
-do not want to perform a non-virtual call.  Note that
-resolves_to_fixed_type_p checks CLASSTYPE_FINAL too.  */
+  /* See if the function member or the whole class type is declared
+final and the call can be devirtualized.  */
   if (DECL_FINAL_P (fn)
- || (resolves_to_fixed_type_p (arg, 0)
- && same_type_ignoring_top_level_qualifiers_p
- (DECL_CONTEXT (fn), BINFO_TYPE (cand->conversion_path 
+ || CLASSTYPE_FINAL (TYPE_METHOD_BASETYPE (TREE_TYPE (fn
flags |= LOOKUP_NONVIRTUAL;
 
+  /* If we know the dynamic type of the object, look up the final overrider
+in the BINFO.  */
+  if (DECL_VINDEX (fn) && (flags & LOOKUP_NONVIRTUAL) == 0
+ && resolves_to_fixed_type_p (arg))
+   {
+ fn = lookup_vfn_in_binfo (DECL_VINDEX (fn), cand->conversion_path);
+ flags |= LOOKUP_NONVIRTUAL;
+   }
+
   /* [class.mfct.non-static]: If a non-static member function of a class
 X is called for an object that is not of type X, or of a type
 derived from X, the behavior is undefined.
diff --git a/gcc/cp/class.c b/gcc/cp/class.c
index 757e010b6b7..f8e38ec9d8c 100644
--- a/gcc/cp/class.c
+++ b/gcc/cp/class.c
@@ -2445,6 +2445,20 @@ get_vcall_index (tree fn, tree type)
   gcc_unreachable ();
 }
 
+/* Given a DECL_VINDEX of a virtual function found in BINFO, return the final
+   overrider at that index in the vtable.  This should only be used when we
+   know that BINFO is correct for the dynamic type of the object.  */
+
+tree
+lookup_vfn_in_binfo (tree idx, tree binfo)
+{
+  int ix = tree_to_shwi (idx);
+  if (TARGET_VTABLE_USES_DESCRIPTORS)
+ix /= MAX (TARGET_VTABLE_USES_DESCRIPTORS, 1);
+  tree virtuals = BINFO_VIRTUALS (binfo);
+  return TREE_VALUE (chain_index (ix, virtuals));
+}
+
 /* Update an entry in the vtable for 

Re: [PATCH 07/13] OpenACC 2.6 deep copy: libgomp parts

2020-06-04 Thread Thomas Schwinge
Hi!

On 2019-12-17T22:03:47-0800, Julian Brown  wrote:
> This part contains the libgomp runtime support for the GOMP_MAP_ATTACH and
> GOMP_MAP_DETACH mapping kinds (etc.)

> --- a/libgomp/oacc-mem.c
> +++ b/libgomp/oacc-mem.c

> @@ -1075,6 +1119,39 @@ goacc_exit_data_internal (struct gomp_device_descr 
> *acc_dev, size_t mapnum,

> + case GOMP_MAP_STRUCT:
> +   {
> + int elems = sizes[i];
> + for (int j = 1; j <= elems; j++)
> +   {
> + struct splay_tree_key_s k;
> + k.host_start = (uintptr_t) hostaddrs[i + j];
> + k.host_end = k.host_start + sizes[i + j];
> + splay_tree_key str;
> + str = splay_tree_lookup (_dev->mem_map, );
> + if (str)
> +   {
> + if (finalize)
> +   {
> + str->refcount -= str->virtual_refcount;
> + str->virtual_refcount = 0;
> +   }
> + if (str->virtual_refcount > 0)
> +   {
> + str->refcount--;
> + str->virtual_refcount--;
> +   }
> + else if (str->refcount > 0)
> +   str->refcount--;
> + if (str->refcount == 0)
> +   gomp_remove_var_async (acc_dev, str, aq);
> +   }
> +   }
> + i += elems;
> +   }
> +   break;

I'm aware that this 'GOMP_MAP_STRUCT' special handling shouldn't have
been there to begin with, and is now scheduled to go away (yay!), but
while testing a few things while reviewing (reverse-engineering the
intentions of) these fix-up patches, I quickly ran into cases where
OpenACC code that I understand to be valid failed, exactly here.  I've
pushed "[OpenACC 'exit data'] Evaluate 'finalize' individually for
'GOMP_MAP_STRUCT' entries" to master branch in commit
a02f1adbfe619ab19cf142438e0a02950d3594da, and releases/gcc-10 branch in
commit 5a1b479aedd83d0362f870f480a24a011e703de4, and then "[OpenACC 'exit
data'] Evaluate 'copyfrom' individually for 'GOMP_MAP_STRUCT' entries" to
master branch in commit 2c838a3e4ea06c69c856d074ae5b0400e08ae3c2, and
releases/gcc-10 branch in commit
4664ca1bc40318dbe60591cfe6d31c3d36d439c3, see attached.


Grüße
 Thomas


-
Mentor Graphics (Deutschland) GmbH, Arnulfstraße 201, 80634 München / Germany
Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Alexander 
Walter
>From a02f1adbfe619ab19cf142438e0a02950d3594da Mon Sep 17 00:00:00 2001
From: Thomas Schwinge 
Date: Thu, 4 Jun 2020 16:01:07 +0200
Subject: [PATCH] [OpenACC 'exit data'] Evaluate 'finalize' individually for
 'GOMP_MAP_STRUCT' entries

Currently, we don't at all evaluate 'finalize' for 'GOMP_MAP_STRUCT' entries.
Fix this by copying/adapting the corresponding non-'GOMP_MAP_STRUCT' code.

	libgomp/
	* oacc-mem.c (goacc_exit_data_internal) :
	Evaluate 'finalize' individually for each entry.
	* testsuite/libgomp.oacc-c-c++-common/struct-1.c: New file.
	* testsuite/libgomp.oacc-c-c++-common/struct-refcount-1.c: Remove
	file.
---
 libgomp/oacc-mem.c|  10 ++
 .../libgomp.oacc-c-c++-common/struct-1.c  | 146 ++
 .../struct-refcount-1.c   |  47 --
 3 files changed, 156 insertions(+), 47 deletions(-)
 create mode 100644 libgomp/testsuite/libgomp.oacc-c-c++-common/struct-1.c
 delete mode 100644 libgomp/testsuite/libgomp.oacc-c-c++-common/struct-refcount-1.c

diff --git a/libgomp/oacc-mem.c b/libgomp/oacc-mem.c
index b7c85cf5976f..a34f4cf0e918 100644
--- a/libgomp/oacc-mem.c
+++ b/libgomp/oacc-mem.c
@@ -1184,6 +1184,16 @@ goacc_exit_data_internal (struct gomp_device_descr *acc_dev, size_t mapnum,
 	int elems = sizes[i];
 	for (int j = 1; j <= elems; j++)
 	  {
+		assert (i + j < mapnum);
+
+		kind = kinds[i + j] & 0xff;
+
+		finalize = false;
+		if (kind == GOMP_MAP_FORCE_FROM
+		|| kind == GOMP_MAP_DELETE
+		|| kind == GOMP_MAP_FORCE_DETACH)
+		  finalize = true;
+
 		struct splay_tree_key_s k;
 		k.host_start = (uintptr_t) hostaddrs[i + j];
 		k.host_end = k.host_start + sizes[i + j];
diff --git a/libgomp/testsuite/libgomp.oacc-c-c++-common/struct-1.c b/libgomp/testsuite/libgomp.oacc-c-c++-common/struct-1.c
new file mode 100644
index ..285be84f244b
--- /dev/null
+++ b/libgomp/testsuite/libgomp.oacc-c-c++-common/struct-1.c
@@ -0,0 +1,146 @@
+/* Test dynamic refcount of separate structure members.  */
+
+#include 
+#include 
+#include 
+
+struct s
+{
+  signed char a;
+  float b;
+};
+
+static void test(unsigned variant)
+{
+  struct s s;
+
+#pragma acc enter data create(s.a, s.b)
+  assert(acc_is_present(, sizeof s.a));
+  assert(acc_is_present(, sizeof s.b));
+
+  if (variant & 4)
+{
+  if (variant & 8)
+	{
+#pragma acc enter data create(s.b)
+	}
+  else
+	acc_create(, sizeof s.b);
+  assert(acc_is_present(, sizeof s.a));
+  assert(acc_is_present(, 

[PATCH, PR fortran/95503] [9/10/11 Regression] ICE in gfc_is_simply_contiguous, at fortran/expr.c:5844

2020-06-04 Thread Harald Anlauf
The following patch fixes an almost obvious ICE in invalid.

Regtested on x86_64-pc-linux-gnu.

OK for master, and backports to 9/10?

Thanks,
Harald


PR fortran/95503 - ICE in gfc_is_simply_contiguous, at fortran/expr.c:5844

The check for assigning a pointer that cannot be determined to be simply
contiguous at compile time to a contiguous pointer does not need to be
invoked if the lhs of the assignment is known to have conflicting attributes.

2020-06-04  Harald Anlauf  

gcc/fortran/
PR fortran/95503
* expr.c (gfc_check_pointer_assign): Skip contiguity check of rhs
of pointer assignment if lhs cannot be simply contiguous.

gcc/testsuite/
PR fortran/95503
* gfortran.dg/pr95503.f90: New test.

diff --git a/gcc/fortran/expr.c b/gcc/fortran/expr.c
index a9fa03ad153..8daa7bb8d06 100644
--- a/gcc/fortran/expr.c
+++ b/gcc/fortran/expr.c
@@ -4346,7 +4346,9 @@ gfc_check_pointer_assign (gfc_expr *lvalue, gfc_expr *rvalue,
  contiguous.  Be lenient in the definition of what counts as
  contiguous.  */

-  if (lhs_attr.contiguous && !gfc_is_simply_contiguous (rvalue, false, true))
+  if (lhs_attr.contiguous
+  && lhs_attr.dimension > 0
+  && !gfc_is_simply_contiguous (rvalue, false, true))
 gfc_warning (OPT_Wextra, "Assignment to contiguous pointer from "
 		 "non-contiguous target at %L", >where);

diff --git a/gcc/testsuite/gfortran.dg/pr95503.f90 b/gcc/testsuite/gfortran.dg/pr95503.f90
new file mode 100644
index 000..4a202b405c4
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr95503.f90
@@ -0,0 +1,7 @@
+! { dg-do compile }
+! PR fortran/95503 - ICE in gfc_is_simply_contiguous
+
+program p
+  complex, target :: a
+  real, pointer, contiguous :: b => a%re ! { dg-error "not an array pointer" }
+end


Fix 'sizeof' usage in 'libgomp.oacc-c-c++-common/deep-copy-{7, 8}.c' (was: [PATCH 11/13] OpenACC 2.6 deep copy: C and C++ execution tests)

2020-06-04 Thread Thomas Schwinge
Hi!

On 2019-12-17T22:04:54-0800, Julian Brown  wrote:
> This part adds C and C++ execution tests to libgomp.

Spotted the following while looking into/for something else:

> --- /dev/null
> +++ b/libgomp/testsuite/libgomp.oacc-c-c++-common/deep-copy-7.c
> @@ -0,0 +1,45 @@

> +struct dc
> +{
> +  int a;
> +  int *b;
> +};

> +  v.b = (int *) malloc (sizeof (int) * n);

> +  assert (!acc_is_present (v.b, sizeof (int *) * n));

> --- /dev/null
> +++ b/libgomp/testsuite/libgomp.oacc-c-c++-common/deep-copy-8.c

> +struct dc
> +{
> +  int a;
> +  int *b;
> +  int *c;
> +  int *d;
> +};

> +  v.b = (int *) malloc (sizeof (int) * n);
> +  v.c = (int *) malloc (sizeof (int) * n);
> +  v.d = (int *) malloc (sizeof (int) * n);

> +  assert (!acc_is_present (v.b, sizeof (int *) * n));
> +  assert (!acc_is_present (v.c, sizeof (int *) * n));
> +  assert (!acc_is_present (v.d, sizeof (int *) * n));

Note 'sizeof (int)' vs. 'sizeof (int *)' -- meaning that these asserts
were dead code, effectively.  ;-) I'd personally always use 'sizeof *v.b'
etc., avoiding these kinds of mismatches.  Here, maintaining the existing
style, I've changed the 'sizeof (int *)' into 'sizeof (int)', and pushed
"Fix 'sizeof' usage in 'libgomp.oacc-c-c++-common/deep-copy-{7,8}.c'" to
master branch in commit db7179ec74dda8c92db18399e5041a96ece8d56d, and
releases/gcc-10 branch in commit
62eeb36773d37fbfda9183ce50b724f834a875f2, see attached.


Grüße
 Thomas


-
Mentor Graphics (Deutschland) GmbH, Arnulfstraße 201, 80634 München / Germany
Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Alexander 
Walter
>From db7179ec74dda8c92db18399e5041a96ece8d56d Mon Sep 17 00:00:00 2001
From: Thomas Schwinge 
Date: Tue, 19 May 2020 22:35:15 +0200
Subject: [PATCH] Fix 'sizeof' usage in
 'libgomp.oacc-c-c++-common/deep-copy-{7,8}.c'

	libgomp/
	* testsuite/libgomp.oacc-c-c++-common/deep-copy-7.c: Fix 'sizeof'
	usage.
	* testsuite/libgomp.oacc-c-c++-common/deep-copy-8.c: Likewise.
---
 libgomp/testsuite/libgomp.oacc-c-c++-common/deep-copy-7.c | 2 +-
 libgomp/testsuite/libgomp.oacc-c-c++-common/deep-copy-8.c | 6 +++---
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/libgomp/testsuite/libgomp.oacc-c-c++-common/deep-copy-7.c b/libgomp/testsuite/libgomp.oacc-c-c++-common/deep-copy-7.c
index a59047af520d..13e5ca2e056c 100644
--- a/libgomp/testsuite/libgomp.oacc-c-c++-common/deep-copy-7.c
+++ b/libgomp/testsuite/libgomp.oacc-c-c++-common/deep-copy-7.c
@@ -38,7 +38,7 @@ main ()
 	assert (v.b[i] == v.a + i);
 
   assert (!acc_is_present (, sizeof (v)));
-  assert (!acc_is_present (v.b, sizeof (int *) * n));
+  assert (!acc_is_present (v.b, sizeof (int) * n));
 }
 
   return 0;
diff --git a/libgomp/testsuite/libgomp.oacc-c-c++-common/deep-copy-8.c b/libgomp/testsuite/libgomp.oacc-c-c++-common/deep-copy-8.c
index 0ca5990b377b..1b4cf2fb6846 100644
--- a/libgomp/testsuite/libgomp.oacc-c-c++-common/deep-copy-8.c
+++ b/libgomp/testsuite/libgomp.oacc-c-c++-common/deep-copy-8.c
@@ -41,9 +41,9 @@ main ()
 	assert (v.b[i] == v.a + i);
 
   assert (acc_is_present (, sizeof (v)));
-  assert (!acc_is_present (v.b, sizeof (int *) * n));
-  assert (!acc_is_present (v.c, sizeof (int *) * n));
-  assert (!acc_is_present (v.d, sizeof (int *) * n));
+  assert (!acc_is_present (v.b, sizeof (int) * n));
+  assert (!acc_is_present (v.c, sizeof (int) * n));
+  assert (!acc_is_present (v.d, sizeof (int) * n));
 }
 
 #pragma acc exit data copyout(v)
-- 
2.26.2

>From 62eeb36773d37fbfda9183ce50b724f834a875f2 Mon Sep 17 00:00:00 2001
From: Thomas Schwinge 
Date: Tue, 19 May 2020 22:35:15 +0200
Subject: [PATCH] Fix 'sizeof' usage in
 'libgomp.oacc-c-c++-common/deep-copy-{7,8}.c'

	libgomp/
	* testsuite/libgomp.oacc-c-c++-common/deep-copy-7.c: Fix 'sizeof'
	usage.
	* testsuite/libgomp.oacc-c-c++-common/deep-copy-8.c: Likewise.

(cherry picked from commit db7179ec74dda8c92db18399e5041a96ece8d56d)
---
 libgomp/testsuite/libgomp.oacc-c-c++-common/deep-copy-7.c | 2 +-
 libgomp/testsuite/libgomp.oacc-c-c++-common/deep-copy-8.c | 6 +++---
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/libgomp/testsuite/libgomp.oacc-c-c++-common/deep-copy-7.c b/libgomp/testsuite/libgomp.oacc-c-c++-common/deep-copy-7.c
index a59047af520d..13e5ca2e056c 100644
--- a/libgomp/testsuite/libgomp.oacc-c-c++-common/deep-copy-7.c
+++ b/libgomp/testsuite/libgomp.oacc-c-c++-common/deep-copy-7.c
@@ -38,7 +38,7 @@ main ()
 	assert (v.b[i] == v.a + i);
 
   assert (!acc_is_present (, sizeof (v)));
-  assert (!acc_is_present (v.b, sizeof (int *) * n));
+  assert (!acc_is_present (v.b, sizeof (int) * n));
 }
 
   return 0;
diff --git a/libgomp/testsuite/libgomp.oacc-c-c++-common/deep-copy-8.c b/libgomp/testsuite/libgomp.oacc-c-c++-common/deep-copy-8.c
index 0ca5990b377b..1b4cf2fb6846 100644
--- a/libgomp/testsuite/libgomp.oacc-c-c++-common/deep-copy-8.c
+++ 

[OpenACC] Repair/restore 'is_tgt_unmapped' checking (was: [PATCH 07/13] OpenACC 2.6 deep copy: libgomp parts)

2020-06-04 Thread Thomas Schwinge
Hi!

On 2020-05-20T20:11:00+0100, Julian Brown  wrote:
> On Wed, 20 May 2020 16:52:02 +0200
> Thomas Schwinge  wrote:
>> On 2019-12-17T22:03:47-0800, Julian Brown 
>> wrote:
>> > --- a/libgomp/oacc-mem.c
>> > +++ b/libgomp/oacc-mem.c
>>
>> >  static int
>> > -find_group_last (int pos, size_t mapnum, unsigned short *kinds)
>> > +find_group_last (int pos, size_t mapnum, size_t *sizes, unsigned short 
>> > *kinds) {
>> >unsigned char kind0 = kinds[pos] & 0xff;
>> > -  int first_pos = pos, last_pos = pos;
>> > +  int first_pos = pos;
>> >
>> > -  if (kind0 == GOMP_MAP_TO_PSET)
>> > +  switch (kind0)
>> >  {
>> > +case GOMP_MAP_TO_PSET:
>> >while (pos + 1 < mapnum && (kinds[pos + 1] & 0xff) == 
>> > GOMP_MAP_POINTER)
>> > -  last_pos = ++pos;
>> > +  pos++;
>> >/* We expect at least one GOMP_MAP_POINTER after a 
>> > GOMP_MAP_TO_PSET.  */
>> > -  assert (last_pos > first_pos);
>> > -}
>> > -  else
>> > -{
>> > +  assert (pos > first_pos);
>> > +  break;
>> > +
>> > +case GOMP_MAP_STRUCT:
>> > +  pos += sizes[pos];
>> > +  break;
>> > +
>> > +case GOMP_MAP_POINTER:
>> > +case GOMP_MAP_ALWAYS_POINTER:
>> > +  /* These mappings are only expected after some other mapping.  If we
>> > +   see one by itself, something has gone wrong.  */
>> > +  gomp_fatal ("unexpected mapping");
>> > +  break;
>> > +
>> > +default:
>> >/* GOMP_MAP_ALWAYS_POINTER can only appear directly after some 
>> > other mapping.  */
>> > -  if (pos + 1 < mapnum
>> > -&& (kinds[pos + 1] & 0xff) == GOMP_MAP_ALWAYS_POINTER)
>> > -  return pos + 1;
>> > +  if (pos + 1 < mapnum)
>> > +  {
>> > +unsigned char kind1 = kinds[pos + 1] & 0xff;
>> > +if (kind1 == GOMP_MAP_ALWAYS_POINTER)
>> > +  return pos + 1;
>> > +  }
>> >
>> > -  /* We can have one or several GOMP_MAP_POINTER mappings after a 
>> > to/from
>> > +  /* We can have zero or more GOMP_MAP_POINTER mappings after a 
>> > to/from (etc.) mapping.  */
>> >while (pos + 1 < mapnum && (kinds[pos + 1] & 0xff) == 
>> > GOMP_MAP_POINTER)
>> > -  last_pos = ++pos;
>> > +  pos++;
>> >  }
>> >
>> > -  return last_pos;
>> > +  return pos;
>> >  }
>>
>> So this now causes grouped (!) mapping of all of 'GOMP_MAP_STRUCT',
>> that is, all its "members" at once.
>>
>> This, I suppose, mandated the removal of (some of) the
>> 'is_tgt_unmapped' checking (unfortunately committed not here, but as
>> part of r279621 "OpenACC reference count overhaul"), where we had
>> unmapping code (conceptually) similar to:
>>
>> bool is_tgt_unmapped = gomp_remove_var (acc_dev, n);
>> assert (is_tgt_unmapped);
>>
>> I'd introduced this a little bit earlier, finding this a simple yet
>> effective run-time, low-overhead consistency checking of (certain
>> aspects of) reference counting -- so just noting here that it's
>> somewhat bad that we can't have this anymore "just" because of
>> 'GOMP_MAP_STRUCT'.  (Maybe there is a way to get it back; that's for
>> later?)
>
> I'm actually looking at this now as part of revisiting the refcounting
> work. I'm seeing what I can come up with in terms of being able to keep
> the runtime test (and fixing the other part you mentioned).

Good idea to skip the checking if 'num_mappings > 1', thanks!  You've
included these changes as part of a different, bigger patch; I've split
them out, and pushed "[OpenACC] Repair/restore 'is_tgt_unmapped'
checking" to master branch in commit
06ec61726d192659cd446e59a91e78745037f0fd, and releases/gcc-10 branch in
commit 125621f569cfac9f4caa6afc1976d42b3d21359e, see attached.

Also note how this checking triggers for OpenACC 'finalize' clause usage
in 'libgomp.oacc-fortran/deep-copy-6.f90' (which I had relatedly XFAILed
before); so good to see that it's useful for something!  (..., and did
your reference count self-checking not catch this case?)


Grüße
 Thomas


-
Mentor Graphics (Deutschland) GmbH, Arnulfstraße 201, 80634 München / Germany
Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Alexander 
Walter
>From 06ec61726d192659cd446e59a91e78745037f0fd Mon Sep 17 00:00:00 2001
From: Thomas Schwinge 
Date: Fri, 29 May 2020 15:22:42 +0200
Subject: [PATCH] [OpenACC] Repair/restore 'is_tgt_unmapped' checking

	libgomp/
	* oacc-mem.c (goacc_exit_datum): Repair 'is_tgt_unmapped'
	checking.
	(acc_unmap_data, goacc_exit_data_internal): Restore
	'is_tgt_unmapped' checking.
	* testsuite/libgomp.oacc-c-c++-common/struct-refcount-1.c: New
	file.
	* testsuite/libgomp.oacc-fortran/deep-copy-6.f90: Adjust.
	* testsuite/libgomp.oacc-fortran/mdc-refcount-1-1-1.f90: Likewise.
	* testsuite/libgomp.oacc-fortran/mdc-refcount-1-2-1.f90: Likewise.
	* testsuite/libgomp.oacc-fortran/mdc-refcount-1-2-2.f90: Likewise.
	* testsuite/libgomp.oacc-fortran/mdc-refcount-1-3-1.f90: Likewise.
	* testsuite/libgomp.oacc-fortran/mdc-refcount-1-4-1.f90: Likewise.

Co-Authored-By: Julian Brown 
---
 libgomp/oacc-mem.c  

[OpenACC] Don't open-code 'gomp_remove_var' in 'acc_unmap_data' (was: [PATCH 2/7] [OpenACC] Adjust dynamic reference count semantics)

2020-06-04 Thread Thomas Schwinge
Hi Julian!

On 2020-05-22T15:16:05-0700, Julian Brown  wrote:
> --- a/libgomp/oacc-mem.c
> +++ b/libgomp/oacc-mem.c

> @@ -475,14 +475,19 @@ acc_unmap_data (void *h)
>gomp_mutex_unlock (_dev->lock);
>gomp_fatal ("cannot unmap target block");
>  }
> -  else if (tgt->refcount > 1)
> -tgt->refcount--;
> -  else
> +
> +  if (tgt->refcount == 1)
>  {
> -  free (tgt->array);
> -  free (tgt);
> +  /* This is the last reference.  Nullifying these fields prevents
> +  'gomp_unmap_tgt' via 'gomp_remove_var' from freeing the target
> +  memory.  */
> +  tgt->tgt_end = 0;
> +  tgt->to_free = NULL;
>  }
>
> +  bool is_tgt_unmapped = gomp_remove_var (acc_dev, n);
> +  assert (is_tgt_unmapped);

Also should again remove the 'splay_tree_remove' that you'd added further
up.  I've pushed "[OpenACC] Don't open-code 'gomp_remove_var' in
'acc_unmap_data'" to master branch in commit
2112d3242f413979931e371423dcead9d19440e7, and releases/gcc-10 branch in
commit 1bca30efec5d684f03dfb88ed93cbe26e68d35b0, see attached.


Grüße
 Thomas


-
Mentor Graphics (Deutschland) GmbH, Arnulfstraße 201, 80634 München / Germany
Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Alexander 
Walter
>From 2112d3242f413979931e371423dcead9d19440e7 Mon Sep 17 00:00:00 2001
From: Thomas Schwinge 
Date: Fri, 29 May 2020 14:21:03 +0200
Subject: [PATCH] [OpenACC] Don't open-code 'gomp_remove_var' in
 'acc_unmap_data'

	libgomp/
	* oacc-mem.c (acc_unmap_data): Don't open-code 'gomp_remove_var'.

Co-Authored-By: Julian Brown 
---
 libgomp/oacc-mem.c | 10 ++
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/libgomp/oacc-mem.c b/libgomp/oacc-mem.c
index 6314f5d8b686..8e8c7c3093d5 100644
--- a/libgomp/oacc-mem.c
+++ b/libgomp/oacc-mem.c
@@ -468,8 +468,6 @@ acc_unmap_data (void *h)
 		  (void *) h, (int) host_size);
 }
 
-  splay_tree_remove (_dev->mem_map, n);
-
   struct target_mem_desc *tgt = n->tgt;
 
   if (tgt->refcount == REFCOUNT_INFINITY)
@@ -482,8 +480,12 @@ acc_unmap_data (void *h)
  'acc_map_data'.  */
   assert (tgt->refcount == 1);
 
-  free (tgt->array);
-  free (tgt);
+  /* Nullifying these fields prevents 'gomp_unmap_tgt' via 'gomp_remove_var'
+ from freeing the target memory.  */
+  tgt->tgt_end = 0;
+  tgt->to_free = NULL;
+
+  gomp_remove_var (acc_dev, n);
 
   gomp_mutex_unlock (_dev->lock);
 
-- 
2.26.2

>From 1bca30efec5d684f03dfb88ed93cbe26e68d35b0 Mon Sep 17 00:00:00 2001
From: Thomas Schwinge 
Date: Fri, 29 May 2020 14:21:03 +0200
Subject: [PATCH] [OpenACC] Don't open-code 'gomp_remove_var' in
 'acc_unmap_data'

	libgomp/
	* oacc-mem.c (acc_unmap_data): Don't open-code 'gomp_remove_var'.

Co-Authored-By: Julian Brown 
(cherry picked from commit 2112d3242f413979931e371423dcead9d19440e7)
---
 libgomp/oacc-mem.c | 10 ++
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/libgomp/oacc-mem.c b/libgomp/oacc-mem.c
index 6314f5d8b686..8e8c7c3093d5 100644
--- a/libgomp/oacc-mem.c
+++ b/libgomp/oacc-mem.c
@@ -468,8 +468,6 @@ acc_unmap_data (void *h)
 		  (void *) h, (int) host_size);
 }
 
-  splay_tree_remove (_dev->mem_map, n);
-
   struct target_mem_desc *tgt = n->tgt;
 
   if (tgt->refcount == REFCOUNT_INFINITY)
@@ -482,8 +480,12 @@ acc_unmap_data (void *h)
  'acc_map_data'.  */
   assert (tgt->refcount == 1);
 
-  free (tgt->array);
-  free (tgt);
+  /* Nullifying these fields prevents 'gomp_unmap_tgt' via 'gomp_remove_var'
+ from freeing the target memory.  */
+  tgt->tgt_end = 0;
+  tgt->to_free = NULL;
+
+  gomp_remove_var (acc_dev, n);
 
   gomp_mutex_unlock (_dev->lock);
 
-- 
2.26.2



[OpenACC] Remove 'tgt' reference counting from 'acc_unmap_data' [PR92854]

2020-06-04 Thread Thomas Schwinge
Hi!

Per the discussion/conclusion in PR92854, I've now pushed "[OpenACC]
Remove 'tgt' reference counting from 'acc_unmap_data' [PR92854]" to
master branch in commit 4662f7fe7863b19fcc20ba58c22880f8d6661f3a, and
releases/gcc-10 branch in commit
0c59837c89bd62e2addf4b34704a1ebe7e3bffab, see attached.


Grüße
 Thomas


-
Mentor Graphics (Deutschland) GmbH, Arnulfstraße 201, 80634 München / Germany
Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Alexander 
Walter
>From 4662f7fe7863b19fcc20ba58c22880f8d6661f3a Mon Sep 17 00:00:00 2001
From: Thomas Schwinge 
Date: Fri, 29 May 2020 14:12:16 +0200
Subject: [PATCH] [OpenACC] Remove 'tgt' reference counting from
 'acc_unmap_data' [PR92854]

	libgomp/
	PR libgomp/92854
	* oacc-mem.c (acc_unmap_data): Remove 'tgt' reference counting.
---
 libgomp/oacc-mem.c | 14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/libgomp/oacc-mem.c b/libgomp/oacc-mem.c
index e2fb651a2334..6314f5d8b686 100644
--- a/libgomp/oacc-mem.c
+++ b/libgomp/oacc-mem.c
@@ -477,13 +477,13 @@ acc_unmap_data (void *h)
   gomp_mutex_unlock (_dev->lock);
   gomp_fatal ("cannot unmap target block");
 }
-  else if (tgt->refcount > 1)
-tgt->refcount--;
-  else
-{
-  free (tgt->array);
-  free (tgt);
-}
+
+  /* Above, we've verified that the mapping must have been set up by
+ 'acc_map_data'.  */
+  assert (tgt->refcount == 1);
+
+  free (tgt->array);
+  free (tgt);
 
   gomp_mutex_unlock (_dev->lock);
 
-- 
2.26.2

>From 0c59837c89bd62e2addf4b34704a1ebe7e3bffab Mon Sep 17 00:00:00 2001
From: Thomas Schwinge 
Date: Fri, 29 May 2020 14:12:16 +0200
Subject: [PATCH] [OpenACC] Remove 'tgt' reference counting from
 'acc_unmap_data' [PR92854]

	libgomp/
	PR libgomp/92854
	* oacc-mem.c (acc_unmap_data): Remove 'tgt' reference counting.

(cherry picked from commit 4662f7fe7863b19fcc20ba58c22880f8d6661f3a)
---
 libgomp/oacc-mem.c | 14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/libgomp/oacc-mem.c b/libgomp/oacc-mem.c
index e2fb651a2334..6314f5d8b686 100644
--- a/libgomp/oacc-mem.c
+++ b/libgomp/oacc-mem.c
@@ -477,13 +477,13 @@ acc_unmap_data (void *h)
   gomp_mutex_unlock (_dev->lock);
   gomp_fatal ("cannot unmap target block");
 }
-  else if (tgt->refcount > 1)
-tgt->refcount--;
-  else
-{
-  free (tgt->array);
-  free (tgt);
-}
+
+  /* Above, we've verified that the mapping must have been set up by
+ 'acc_map_data'.  */
+  assert (tgt->refcount == 1);
+
+  free (tgt->array);
+  free (tgt);
 
   gomp_mutex_unlock (_dev->lock);
 
-- 
2.26.2



Extend 'libgomp.oacc-c-c++-common/pr92854-1.c' some more [PR92854] (was: [PR92854] Add 'libgomp.oacc-c-c++-common/pr92854-1.c')

2020-06-04 Thread Thomas Schwinge
Hi!

On 2019-12-09T12:52:02+0100, I wrote:
> See attached "[PR92854] Add 'libgomp.oacc-c-c++-common/pr92854-1.c'",
> committed to trunk in r279120, "to document the status quo", which does
> match my understanding of the OpenACC 2.6 semantics.

I've now pushed "Extend 'libgomp.oacc-c-c++-common/pr92854-1.c' some more
[PR92854]" to master branch in commit
af8fd1a99d9a21f8088ebb11250cd06a3f275052, and releases/gcc-10 branch in
commit 364f46de9f02dc00e8ff51cc9e2662ae37520389, see attached.


Grüße
 Thomas


-
Mentor Graphics (Deutschland) GmbH, Arnulfstraße 201, 80634 München / Germany
Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Alexander 
Walter
>From af8fd1a99d9a21f8088ebb11250cd06a3f275052 Mon Sep 17 00:00:00 2001
From: Thomas Schwinge 
Date: Fri, 29 May 2020 14:11:27 +0200
Subject: [PATCH] Extend 'libgomp.oacc-c-c++-common/pr92854-1.c' some more
 [PR92854]

	libgomp/
	PR libgomp/92854
	* testsuite/libgomp.oacc-c-c++-common/pr92854-1.c: Extend some
	more.
---
 .../libgomp.oacc-c-c++-common/pr92854-1.c | 64 ++-
 1 file changed, 47 insertions(+), 17 deletions(-)

diff --git a/libgomp/testsuite/libgomp.oacc-c-c++-common/pr92854-1.c b/libgomp/testsuite/libgomp.oacc-c-c++-common/pr92854-1.c
index 6ba96b6bf8f9..79cebf65c348 100644
--- a/libgomp/testsuite/libgomp.oacc-c-c++-common/pr92854-1.c
+++ b/libgomp/testsuite/libgomp.oacc-c-c++-common/pr92854-1.c
@@ -1,31 +1,61 @@
-/* Verify that 'acc_unmap_data' unmaps even in presence of dynamic reference
-   counts.  */
+/* Verify that 'acc_unmap_data' unmaps even in presence of structured and
+   dynamic reference counts, but the device memory remains allocated.  */
 
 /* { dg-skip-if "" { *-*-* } { "*" } { "-DACC_MEM_SHARED=0" } } */
 
 #include 
 #include 
+#include 
 #include 
 
 int
 main ()
 {
   const int N = 180;
-
-  char *h = (char *) malloc (N);
-  char *d = (char *) acc_malloc (N);
-  if (!d)
-abort ();
-  acc_map_data (h, d, N);
-
-  char *d_ = (char *) acc_create (h + 3, N - 77);
-  assert (d_ == d + 3);
-
-  d_ = (char *) acc_create (h, N);
-  assert (d_ == d);
-
-  acc_unmap_data (h);
-  assert (!acc_is_present (h, N));
+  const int N_i = 537;
+  const int C = 37;
+
+  unsigned char *h = (unsigned char *) malloc (N);
+  assert (h);
+  unsigned char *d = (unsigned char *) acc_malloc (N);
+  assert (d);
+
+  for (int i = 0; i < N_i; ++i)
+{
+  acc_map_data (h, d, N);
+  assert (acc_is_present (h, N));
+#pragma acc parallel present(h[0:N])
+  {
+	if (i == 0)
+	  memset (h, C, N);
+  }
+
+  unsigned char *d_ = (unsigned char *) acc_create (h + 3, N - 77);
+  assert (d_ == d + 3);
+
+#pragma acc data create(h[6:N - 44])
+  {
+	d_ = (unsigned char *) acc_create (h, N);
+	assert (d_ == d);
+
+#pragma acc enter data create(h[0:N])
+
+	assert (acc_is_present (h, N));
+	acc_unmap_data (h);
+	assert (!acc_is_present (h, N));
+  }
+
+  /* We can however still access the device memory.  */
+#pragma acc parallel loop deviceptr(d)
+  for (int j = 0; j < N; ++j)
+	d[j] += i * j;
+}
+
+  acc_memcpy_from_device(h, d, N);
+  for (int j = 0; j < N; ++j)
+assert (h[j] == ((C + N_i * (N_i - 1) / 2 * j) % 256));
+
+  acc_free (d);
 
   return 0;
 }
-- 
2.26.2

>From 364f46de9f02dc00e8ff51cc9e2662ae37520389 Mon Sep 17 00:00:00 2001
From: Thomas Schwinge 
Date: Fri, 29 May 2020 14:11:27 +0200
Subject: [PATCH] Extend 'libgomp.oacc-c-c++-common/pr92854-1.c' some more
 [PR92854]

	libgomp/
	PR libgomp/92854
	* testsuite/libgomp.oacc-c-c++-common/pr92854-1.c: Extend some
	more.

(cherry picked from commit af8fd1a99d9a21f8088ebb11250cd06a3f275052)
---
 .../libgomp.oacc-c-c++-common/pr92854-1.c | 64 ++-
 1 file changed, 47 insertions(+), 17 deletions(-)

diff --git a/libgomp/testsuite/libgomp.oacc-c-c++-common/pr92854-1.c b/libgomp/testsuite/libgomp.oacc-c-c++-common/pr92854-1.c
index 6ba96b6bf8f9..79cebf65c348 100644
--- a/libgomp/testsuite/libgomp.oacc-c-c++-common/pr92854-1.c
+++ b/libgomp/testsuite/libgomp.oacc-c-c++-common/pr92854-1.c
@@ -1,31 +1,61 @@
-/* Verify that 'acc_unmap_data' unmaps even in presence of dynamic reference
-   counts.  */
+/* Verify that 'acc_unmap_data' unmaps even in presence of structured and
+   dynamic reference counts, but the device memory remains allocated.  */
 
 /* { dg-skip-if "" { *-*-* } { "*" } { "-DACC_MEM_SHARED=0" } } */
 
 #include 
 #include 
+#include 
 #include 
 
 int
 main ()
 {
   const int N = 180;
-
-  char *h = (char *) malloc (N);
-  char *d = (char *) acc_malloc (N);
-  if (!d)
-abort ();
-  acc_map_data (h, d, N);
-
-  char *d_ = (char *) acc_create (h + 3, N - 77);
-  assert (d_ == d + 3);
-
-  d_ = (char *) acc_create (h, N);
-  assert (d_ == d);
-
-  acc_unmap_data (h);
-  assert (!acc_is_present (h, N));
+  const int N_i = 537;
+  const int C = 37;
+
+  unsigned char *h = (unsigned char *) malloc (N);
+  assert (h);
+  unsigned char *d = (unsigned char *) acc_malloc (N);
+  assert 

[OpenACC] Use 'tgt' returned from 'gomp_map_vars' (was: [PATCH 02/13] OpenACC reference count overhaul)

2020-06-04 Thread Thomas Schwinge
Hi!

On 2020-05-19T17:42:22+0200, I wrote:
> On 2019-12-17T22:02:27-0800, Julian Brown  wrote:
>> --- a/libgomp/oacc-mem.c
>> +++ b/libgomp/oacc-mem.c
>
>> @@ -571,14 +570,16 @@ present_create_copy (unsigned f, void *h, size_t s, 
>> int async)
>>
>>goacc_aq aq = get_goacc_asyncqueue (async);
>>
>> -  tgt = gomp_map_vars_async (acc_dev, aq, mapnum, , NULL, ,
>> - , true, GOMP_MAP_VARS_OPENACC);
>> -  n = tgt->list[0].key;
>> -  assert (n->refcount == 1);
>> -  assert (n->dynamic_refcount == 0);
>> -  n->dynamic_refcount++;
>> +  gomp_map_vars_async (acc_dev, aq, mapnum, , NULL, , 
>> ,
>> +   true, GOMP_MAP_VARS_OPENACC_ENTER_DATA);
>>
>> -  d = tgt->to_free;
>> +  gomp_mutex_lock (_dev->lock);
>> +  n = lookup_host (acc_dev, h, s);
>> +  assert (n != NULL);
>> +  assert (n->tgt_offset == 0);
>> +  assert ((uintptr_t) h == n->host_start);
>> +  d = (void *) n->tgt->tgt_start;
>> +  gomp_mutex_unlock (_dev->lock);
>>  }
>
> [...], is there a reason that you changed this code to look up
> 'n = lookup_host ([...])'?  This is the case that 'gomp_map_vars' enters
> a new mapping, so by construction, 'n = tgt->list[0].key' must hold?  I
> tested the following: [...], and don't see any regressions.

You've included something similar (even slightly better!) in a bigger
other patch that you've sent, so I've now combined/split that out, and
pushed "[OpenACC] Use 'tgt' returned from 'gomp_map_vars'" to master
branch in commit f233418ccf6a16eb3bf53018852c5f8926780143, and
releases/gcc-10 branch in commit
c44c9858962ab8045d57d531a83b430dd7be8d5a, see attached.


Grüße
 Thomas


-
Mentor Graphics (Deutschland) GmbH, Arnulfstraße 201, 80634 München / Germany
Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Alexander 
Walter
>From f233418ccf6a16eb3bf53018852c5f8926780143 Mon Sep 17 00:00:00 2001
From: Thomas Schwinge 
Date: Thu, 14 May 2020 15:49:52 +0200
Subject: [PATCH] [OpenACC] Use 'tgt' returned from 'gomp_map_vars'

	libgomp/
	* oacc-mem.c (goacc_enter_datum): Use 'tgt' returned from
	'gomp_map_vars'.
	 (acc_map_data): Clean up accordingly.

Co-Authored-By: Julian Brown 
---
 libgomp/oacc-mem.c | 27 +++
 1 file changed, 15 insertions(+), 12 deletions(-)

diff --git a/libgomp/oacc-mem.c b/libgomp/oacc-mem.c
index 6713846c9429..e2fb651a2334 100644
--- a/libgomp/oacc-mem.c
+++ b/libgomp/oacc-mem.c
@@ -355,7 +355,6 @@ acc_is_present (void *h, size_t s)
 void
 acc_map_data (void *h, void *d, size_t s)
 {
-  struct target_mem_desc *tgt = NULL;
   size_t mapnum = 1;
   void *hostaddrs = h;
   void *devaddrs = d;
@@ -402,10 +401,13 @@ acc_map_data (void *h, void *d, size_t s)
 
   gomp_mutex_unlock (_dev->lock);
 
-  tgt = gomp_map_vars (acc_dev, mapnum, , , ,
-			   , true, GOMP_MAP_VARS_ENTER_DATA);
+  struct target_mem_desc *tgt
+	= gomp_map_vars (acc_dev, mapnum, , , ,
+			 , true, GOMP_MAP_VARS_ENTER_DATA);
   assert (tgt);
+  assert (tgt->list_count == 1);
   splay_tree_key n = tgt->list[0].key;
+  assert (n);
   assert (n->refcount == 1);
   assert (n->virtual_refcount == 0);
   /* Special reference counting behavior.  */
@@ -555,16 +557,17 @@ goacc_enter_datum (void **hostaddrs, size_t *sizes, void *kinds, int async)
 
   goacc_aq aq = get_goacc_asyncqueue (async);
 
-  gomp_map_vars_async (acc_dev, aq, mapnum, hostaddrs, NULL, sizes, kinds,
-			   true, GOMP_MAP_VARS_OPENACC_ENTER_DATA);
+  struct target_mem_desc *tgt
+	= gomp_map_vars_async (acc_dev, aq, mapnum, hostaddrs, NULL, sizes,
+			   kinds, true, GOMP_MAP_VARS_OPENACC_ENTER_DATA);
+  assert (tgt);
+  assert (tgt->list_count == 1);
+  n = tgt->list[0].key;
+  assert (n);
+  assert (n->refcount == 1);
+  assert (n->virtual_refcount == 0);
 
-  gomp_mutex_lock (_dev->lock);
-  n = lookup_host (acc_dev, hostaddrs[0], sizes[0]);
-  assert (n != NULL);
-  assert (n->tgt_offset == 0);
-  assert ((uintptr_t) hostaddrs[0] == n->host_start);
-  d = (void *) n->tgt->tgt_start;
-  gomp_mutex_unlock (_dev->lock);
+  d = (void *) tgt->tgt_start;
 }
 
   if (profiling_p)
-- 
2.26.2

>From c44c9858962ab8045d57d531a83b430dd7be8d5a Mon Sep 17 00:00:00 2001
From: Thomas Schwinge 
Date: Thu, 14 May 2020 15:49:52 +0200
Subject: [PATCH] [OpenACC] Use 'tgt' returned from 'gomp_map_vars'

	libgomp/
	* oacc-mem.c (goacc_enter_datum): Use 'tgt' returned from
	'gomp_map_vars'.
	 (acc_map_data): Clean up accordingly.

Co-Authored-By: Julian Brown 
(cherry picked from commit f233418ccf6a16eb3bf53018852c5f8926780143)
---
 libgomp/oacc-mem.c | 27 +++
 1 file changed, 15 insertions(+), 12 deletions(-)

diff --git a/libgomp/oacc-mem.c b/libgomp/oacc-mem.c
index 6713846c9429..e2fb651a2334 100644
--- a/libgomp/oacc-mem.c
+++ b/libgomp/oacc-mem.c
@@ -355,7 +355,6 @@ 

[OpenACC] XFAIL behavior of over-eager 'finalize' clause (was: [PATCH 00/13] OpenACC 2.6 manual deep copy support)

2020-06-04 Thread Thomas Schwinge
Hi!

On 2019-12-17T22:02:25-0800, Julian Brown  wrote:
> This patch series provides support for OpenACC 2.6's manual deep copy
> (attach/detach) feature.

As I should find, there is a problem with the OpenACC 'finalize' clause:
unmapping stuff it isn't supposed to (to be fixed later on), which can
easily be made visible when slightly extending...

>  .../libgomp.oacc-fortran/deep-copy-6.f90  |  61 ++

... this test case.  And then I added some more testing; pushed
"[OpenACC] XFAIL behavior of over-eager 'finalize' clause" to master
branch in commit 8d7794c0a2aa6696ab1a91ef209e8a9fe2df56ac, and
releases/gcc-10 branch in commit
d7af812aaca41c3f7425593dcf8c36803e6a1f1e, see attached.


Grüße
 Thomas


-
Mentor Graphics (Deutschland) GmbH, Arnulfstraße 201, 80634 München / Germany
Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Alexander 
Walter
>From 8d7794c0a2aa6696ab1a91ef209e8a9fe2df56ac Mon Sep 17 00:00:00 2001
From: Thomas Schwinge 
Date: Fri, 29 May 2020 21:36:27 +0200
Subject: [PATCH] [OpenACC] XFAIL behavior of over-eager 'finalize' clause

	libgomp/
	* testsuite/libgomp.oacc-fortran/deep-copy-6.f90: XFAIL behavior
	of over-eager 'finalize' clause.
	* testsuite/libgomp.oacc-fortran/deep-copy-6-no_finalize.F90: New
	file.
	* testsuite/libgomp.oacc-fortran/mdc-refcount-1-1-1.f90: Likewise.
	* testsuite/libgomp.oacc-fortran/mdc-refcount-1-1-2.F90: Likewise.
	* testsuite/libgomp.oacc-fortran/mdc-refcount-1-2-1.f90: Likewise.
	* testsuite/libgomp.oacc-fortran/mdc-refcount-1-2-2.f90: Likewise.
	* testsuite/libgomp.oacc-fortran/mdc-refcount-1-3-1.f90: Likewise.
	* testsuite/libgomp.oacc-fortran/mdc-refcount-1-3-2.f90: Likewise.
	* testsuite/libgomp.oacc-fortran/mdc-refcount-1-4-1.f90: Likewise.
	* testsuite/libgomp.oacc-fortran/mdc-refcount-1-4-2.f90: Likewise.
---
 .../deep-copy-6-no_finalize.F90   |  8 
 .../libgomp.oacc-fortran/deep-copy-6.f90  | 16 +++
 .../mdc-refcount-1-1-1.f90| 41 +
 .../mdc-refcount-1-1-2.F90|  9 
 .../mdc-refcount-1-2-1.f90| 43 ++
 .../mdc-refcount-1-2-2.f90| 43 ++
 .../mdc-refcount-1-3-1.f90| 44 +++
 .../mdc-refcount-1-3-2.f90| 44 +++
 .../mdc-refcount-1-4-1.f90| 44 +++
 .../mdc-refcount-1-4-2.f90| 44 +++
 10 files changed, 336 insertions(+)
 create mode 100644 libgomp/testsuite/libgomp.oacc-fortran/deep-copy-6-no_finalize.F90
 create mode 100644 libgomp/testsuite/libgomp.oacc-fortran/mdc-refcount-1-1-1.f90
 create mode 100644 libgomp/testsuite/libgomp.oacc-fortran/mdc-refcount-1-1-2.F90
 create mode 100644 libgomp/testsuite/libgomp.oacc-fortran/mdc-refcount-1-2-1.f90
 create mode 100644 libgomp/testsuite/libgomp.oacc-fortran/mdc-refcount-1-2-2.f90
 create mode 100644 libgomp/testsuite/libgomp.oacc-fortran/mdc-refcount-1-3-1.f90
 create mode 100644 libgomp/testsuite/libgomp.oacc-fortran/mdc-refcount-1-3-2.f90
 create mode 100644 libgomp/testsuite/libgomp.oacc-fortran/mdc-refcount-1-4-1.f90
 create mode 100644 libgomp/testsuite/libgomp.oacc-fortran/mdc-refcount-1-4-2.f90

diff --git a/libgomp/testsuite/libgomp.oacc-fortran/deep-copy-6-no_finalize.F90 b/libgomp/testsuite/libgomp.oacc-fortran/deep-copy-6-no_finalize.F90
new file mode 100644
index ..ed4f10e7a3f8
--- /dev/null
+++ b/libgomp/testsuite/libgomp.oacc-fortran/deep-copy-6-no_finalize.F90
@@ -0,0 +1,8 @@
+! { dg-do run }
+
+/* Nullify the 'finalize' clause, which disturbs reference counting.  */
+#define finalize
+#include "deep-copy-6.f90"
+
+! { dg-output ".*CheCKpOInT1(\n|\r\n|\r)" }
+! { dg-output ".CheCKpOInT2(\n|\r\n|\r)" }
diff --git a/libgomp/testsuite/libgomp.oacc-fortran/deep-copy-6.f90 b/libgomp/testsuite/libgomp.oacc-fortran/deep-copy-6.f90
index 12910d0d6554..a7943d93d542 100644
--- a/libgomp/testsuite/libgomp.oacc-fortran/deep-copy-6.f90
+++ b/libgomp/testsuite/libgomp.oacc-fortran/deep-copy-6.f90
@@ -3,6 +3,7 @@
 ! Test of attachment counters and finalize.
 
 program dtype
+  use openacc
   implicit none
   integer, parameter :: n = 512
   type mytype
@@ -36,7 +37,22 @@ program dtype
   end do
 !$acc end parallel loop
 
+  if (.not. acc_is_present(var%a(5:n - 5))) stop 11
+  if (.not. acc_is_present(var%b(5:n - 5))) stop 12
+  if (.not. acc_is_present(var)) stop 13
 !$acc exit data copyout(var%a(5:n - 5), var%b(5:n - 5)) finalize
+  if (acc_get_device_type() .ne. acc_device_host) then
+ if (acc_is_present(var%a(5:n - 5))) stop 21
+ if (acc_is_present(var%b(5:n - 5))) stop 22
+  end if
+  print *, "CheCKpOInT1"
+  ! { dg-output ".*CheCKpOInT1(\n|\r\n|\r)" }
+  if (.not. acc_is_present(var)) stop 23
+  !TODO { dg-output "STOP 23(\n|\r\n|\r)$" { target { ! openacc_host_selected } } } ! Scan for what we expect in the "XFAILed" case (without actually XFAILing).

Re: [PATCH 1/7] [OpenACC] Missing unlocking on error paths in attach/detach code

2020-06-04 Thread Thomas Schwinge
Hi!

On 2020-05-22T15:16:04-0700, Julian Brown  wrote:
> This patch adds some missing unlocking from error paths in the OpenACC
> attach/detach code, noticed during development of other patches in
> this series.

Thanks, pushed "[OpenACC] Missing unlocking on error paths in
attach/detach code" to master branch in commit
dc9541545d9e5705a97c41713c557f55522b54dc, and releases/gcc-10 branch in
commit 16faaf529cfdefbf577cf6affc5869506b484599, see attached.

..., and then pushed "[OpenACC] Missing unlocking on error paths in
attach/detach code, part II" to master branch in commit
2e24d457d8c97e409549848715ff046cfa9efd3d, and releases/gcc-10 branch in
commit 52022880530d3ae9cdae81db74a40a92f2265c2c, see attached, too.


Grüße
 Thomas


-
Mentor Graphics (Deutschland) GmbH, Arnulfstraße 201, 80634 München / Germany
Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Alexander 
Walter
>From 2e24d457d8c97e409549848715ff046cfa9efd3d Mon Sep 17 00:00:00 2001
From: Thomas Schwinge 
Date: Sat, 23 May 2020 17:20:30 +0200
Subject: [PATCH] [OpenACC] Missing unlocking on error paths in attach/detach
 code, part II

	libgomp/
	* oacc-mem.c (goacc_exit_data_internal): Unlock on error path.
---
 libgomp/oacc-mem.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/libgomp/oacc-mem.c b/libgomp/oacc-mem.c
index c06b7341cbbf..6713846c9429 100644
--- a/libgomp/oacc-mem.c
+++ b/libgomp/oacc-mem.c
@@ -1060,7 +1060,10 @@ goacc_exit_data_internal (struct gomp_device_descr *acc_dev, size_t mapnum,
 	  = splay_tree_lookup (_dev->mem_map, _node);
 
 	if (n == NULL)
-	  gomp_fatal ("struct not mapped for detach operation");
+	  {
+		gomp_mutex_unlock (_dev->lock);
+		gomp_fatal ("struct not mapped for detach operation");
+	  }
 
 	gomp_detach_pointer (acc_dev, aq, n, hostaddr, finalize, NULL);
 	  }
-- 
2.26.2

>From 52022880530d3ae9cdae81db74a40a92f2265c2c Mon Sep 17 00:00:00 2001
From: Thomas Schwinge 
Date: Sat, 23 May 2020 17:20:30 +0200
Subject: [PATCH] [OpenACC] Missing unlocking on error paths in attach/detach
 code, part II

	libgomp/
	* oacc-mem.c (goacc_exit_data_internal): Unlock on error path.

(cherry picked from commit 2e24d457d8c97e409549848715ff046cfa9efd3d)
---
 libgomp/oacc-mem.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/libgomp/oacc-mem.c b/libgomp/oacc-mem.c
index c06b7341cbbf..6713846c9429 100644
--- a/libgomp/oacc-mem.c
+++ b/libgomp/oacc-mem.c
@@ -1060,7 +1060,10 @@ goacc_exit_data_internal (struct gomp_device_descr *acc_dev, size_t mapnum,
 	  = splay_tree_lookup (_dev->mem_map, _node);
 
 	if (n == NULL)
-	  gomp_fatal ("struct not mapped for detach operation");
+	  {
+		gomp_mutex_unlock (_dev->lock);
+		gomp_fatal ("struct not mapped for detach operation");
+	  }
 
 	gomp_detach_pointer (acc_dev, aq, n, hostaddr, finalize, NULL);
 	  }
-- 
2.26.2

>From 2e24d457d8c97e409549848715ff046cfa9efd3d Mon Sep 17 00:00:00 2001
From: Thomas Schwinge 
Date: Sat, 23 May 2020 17:20:30 +0200
Subject: [PATCH] [OpenACC] Missing unlocking on error paths in attach/detach
 code, part II

	libgomp/
	* oacc-mem.c (goacc_exit_data_internal): Unlock on error path.
---
 libgomp/oacc-mem.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/libgomp/oacc-mem.c b/libgomp/oacc-mem.c
index c06b7341cbbf..6713846c9429 100644
--- a/libgomp/oacc-mem.c
+++ b/libgomp/oacc-mem.c
@@ -1060,7 +1060,10 @@ goacc_exit_data_internal (struct gomp_device_descr *acc_dev, size_t mapnum,
 	  = splay_tree_lookup (_dev->mem_map, _node);
 
 	if (n == NULL)
-	  gomp_fatal ("struct not mapped for detach operation");
+	  {
+		gomp_mutex_unlock (_dev->lock);
+		gomp_fatal ("struct not mapped for detach operation");
+	  }
 
 	gomp_detach_pointer (acc_dev, aq, n, hostaddr, finalize, NULL);
 	  }
-- 
2.26.2

>From 52022880530d3ae9cdae81db74a40a92f2265c2c Mon Sep 17 00:00:00 2001
From: Thomas Schwinge 
Date: Sat, 23 May 2020 17:20:30 +0200
Subject: [PATCH] [OpenACC] Missing unlocking on error paths in attach/detach
 code, part II

	libgomp/
	* oacc-mem.c (goacc_exit_data_internal): Unlock on error path.

(cherry picked from commit 2e24d457d8c97e409549848715ff046cfa9efd3d)
---
 libgomp/oacc-mem.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/libgomp/oacc-mem.c b/libgomp/oacc-mem.c
index c06b7341cbbf..6713846c9429 100644
--- a/libgomp/oacc-mem.c
+++ b/libgomp/oacc-mem.c
@@ -1060,7 +1060,10 @@ goacc_exit_data_internal (struct gomp_device_descr *acc_dev, size_t mapnum,
 	  = splay_tree_lookup (_dev->mem_map, _node);
 
 	if (n == NULL)
-	  gomp_fatal ("struct not mapped for detach operation");
+	  {
+		gomp_mutex_unlock (_dev->lock);
+		gomp_fatal ("struct not mapped for detach operation");
+	  }
 
 	gomp_detach_pointer (acc_dev, aq, n, hostaddr, finalize, NULL);
 	  }
-- 
2.26.2



Re: [PATCH V2 1/2] Introduce flag_cunroll_grow_size for cunroll

2020-06-04 Thread Segher Boessenkool
On Thu, Jun 04, 2020 at 08:46:23AM +0200, Richard Biener wrote:
> On Thu, Jun 4, 2020 at 5:34 AM Jiufu Guo  wrote:
> > Patch is updated a little according to comments.
> > Please see if this is ok to commit.
> 
> OK with a proper ChangeLog after bootstrap / testing.
> 
> It's also OK to backport this to the GCC 10 branch if powerpc
> folks want to restore GIMPLE cunroll behavior for their target.

Yes please!  (But first make sure it works as expected, no fallout, etc.)

Thanks to both of you,


Segher


'libgomp.oacc-fortran/{error_, }stop-{1, 2, 3}.f': initialize before the checkpoint

2020-06-04 Thread Thomas Schwinge
Hi!

On 2018-04-19T11:06:18+0200, I wrote:
> [...] I have applied the following in trunk
> r259491 [...]

> libgomp/
> PR libgomp/85463
> * testsuite/libgomp.oacc-fortran/error_stop-1.f: New file.
> * testsuite/libgomp.oacc-fortran/error_stop-2.f: Likewise.
> * testsuite/libgomp.oacc-fortran/error_stop-3.f: Likewise.
> * testsuite/libgomp.oacc-fortran/stop-1.f: Likewise.
> * testsuite/libgomp.oacc-fortran/stop-2.f: Likewise.
> * testsuite/libgomp.oacc-fortran/stop-3.f: Likewise.

To get rid of some noise in certain variants of libgomp testing that I'm
running, I pushed "'libgomp.oacc-fortran/{error_,}stop-{1,2,3}.f':
initialize before the checkpoint" to master branch in commit
1e378edd8f038c52914bc6cac8f6dd5a5c4f8a98, releases/gcc-10 branch in
commit 96bfb6e1d2dadef180c02d0e006ae72315305e76, releases/gcc-9 branch in
commit 62758cf490afdf73f0deeba39aa05583de99b3a4, and releases/gcc-8
branch in commit f4a45e0d85e51bd6550a82f31f70484c03332a4e, see attached.


Grüße
 Thomas


-
Mentor Graphics (Deutschland) GmbH, Arnulfstraße 201, 80634 München / Germany
Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Alexander 
Walter
>From 1e378edd8f038c52914bc6cac8f6dd5a5c4f8a98 Mon Sep 17 00:00:00 2001
From: Thomas Schwinge 
Date: Wed, 6 May 2020 10:05:49 +0200
Subject: [PATCH] 'libgomp.oacc-fortran/{error_,}stop-{1,2,3}.f': initialize
 before the checkpoint

If, for example, GCC is configured such that 'libgomp-plugin-nvptx.so.1'
dynamically links against 'libcuda.so.1', but testing is run on a system where
there is no 'libcuda.so.1', this produces output such as:

PASS: libgomp.oacc-fortran/error_stop-1.f -DACC_DEVICE_TYPE_host=1 -DACC_MEM_SHARED=1 -foffload=disable  -O0  (test for excess errors)
PASS: libgomp.oacc-fortran/error_stop-1.f -DACC_DEVICE_TYPE_host=1 -DACC_MEM_SHARED=1 -foffload=disable  -O0  execution test
FAIL: libgomp.oacc-fortran/error_stop-1.f -DACC_DEVICE_TYPE_host=1 -DACC_MEM_SHARED=1 -foffload=disable  -O0  output pattern test, is  CheCKpOInT

libgomp: while loading libgomp-plugin-nvptx.so.1: libcuda.so.1: cannot open shared object file: No such file or directory
ERROR STOP

Error termination. Backtrace: [...]
, should match CheCKpOInT(
|
|^M)+ERROR STOP (
|
|^M)+Error termination.*

..., where after 'CheCKpOInT' we got 'libgomp: while loading [...]' injected
before the expected 'ERROR STOP'.

	libgomp/
	* testsuite/libgomp.oacc-fortran/error_stop-1.f: Initialize before
	the checkpoint.
	* testsuite/libgomp.oacc-fortran/error_stop-2.f: Likewise.
	* testsuite/libgomp.oacc-fortran/error_stop-3.f: Likewise.
	* testsuite/libgomp.oacc-fortran/stop-1.f: Likewise.
	* testsuite/libgomp.oacc-fortran/stop-2.f: Likewise.
	* testsuite/libgomp.oacc-fortran/stop-3.f: Likewise.
---
 libgomp/testsuite/libgomp.oacc-fortran/error_stop-1.f | 4 
 libgomp/testsuite/libgomp.oacc-fortran/error_stop-2.f | 4 
 libgomp/testsuite/libgomp.oacc-fortran/error_stop-3.f | 4 
 libgomp/testsuite/libgomp.oacc-fortran/stop-1.f   | 4 
 libgomp/testsuite/libgomp.oacc-fortran/stop-2.f   | 4 
 libgomp/testsuite/libgomp.oacc-fortran/stop-3.f   | 4 
 6 files changed, 24 insertions(+)

diff --git a/libgomp/testsuite/libgomp.oacc-fortran/error_stop-1.f b/libgomp/testsuite/libgomp.oacc-fortran/error_stop-1.f
index a3f54d57bc35..de727749a53f 100644
--- a/libgomp/testsuite/libgomp.oacc-fortran/error_stop-1.f
+++ b/libgomp/testsuite/libgomp.oacc-fortran/error_stop-1.f
@@ -3,6 +3,10 @@
   PROGRAM MAIN
   IMPLICIT NONE
 
+! Initialize before the checkpoint, in case this produces any output.
+!$ACC PARALLEL
+!$ACC END PARALLEL
+
   PRINT *, "CheCKpOInT"
 !$ACC PARALLEL
   ERROR STOP
diff --git a/libgomp/testsuite/libgomp.oacc-fortran/error_stop-2.f b/libgomp/testsuite/libgomp.oacc-fortran/error_stop-2.f
index 5d5d20d1bc53..475c9cb58507 100644
--- a/libgomp/testsuite/libgomp.oacc-fortran/error_stop-2.f
+++ b/libgomp/testsuite/libgomp.oacc-fortran/error_stop-2.f
@@ -3,6 +3,10 @@
   PROGRAM MAIN
   IMPLICIT NONE
 
+! Initialize before the checkpoint, in case this produces any output.
+!$ACC PARALLEL
+!$ACC END PARALLEL
+
   PRINT *, "CheCKpOInT"
 !$ACC PARALLEL
   ERROR STOP 35
diff --git a/libgomp/testsuite/libgomp.oacc-fortran/error_stop-3.f b/libgomp/testsuite/libgomp.oacc-fortran/error_stop-3.f
index edb063b182bc..ab63444ce34f 100644
--- a/libgomp/testsuite/libgomp.oacc-fortran/error_stop-3.f
+++ b/libgomp/testsuite/libgomp.oacc-fortran/error_stop-3.f
@@ -3,6 +3,10 @@
   PROGRAM MAIN
   IMPLICIT NONE
 
+! Initialize before the checkpoint, in case this produces any output.
+!$ACC PARALLEL
+!$ACC END PARALLEL
+
   PRINT *, "CheCKpOInT"
 !$ACC PARALLEL
   ERROR STOP "SiGN"
diff --git a/libgomp/testsuite/libgomp.oacc-fortran/stop-1.f b/libgomp/testsuite/libgomp.oacc-fortran/stop-1.f
index 

[COMMITED] testcase for PR95464

2020-06-04 Thread Vladimir Makarov via Gcc-patches
I've added the testcase for 
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95464



diff --git a/gcc/testsuite/gcc.target/i386/pr95464.c b/gcc/testsuite/gcc.target/i386/pr95464.c
new file mode 100644
index 000..33a8290e0cf
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr95464.c
@@ -0,0 +1,64 @@
+/* { dg-options "-O2" } */
+/* { dg-do run { target { { *-*-linux* } && { ! ia32 } } } } */
+
+struct S { unsigned a:1, b:1, c:1, d:1, e:14, f:14; };
+
+__attribute__((noipa)) int
+foo (struct S x)
+{
+  if (x.a != 0 || x.b != 1 || x.c != 0 || x.d != 1
+  || x.e != 7239 || x.f != 6474)
+__builtin_abort ();
+}
+
+__attribute__((noipa)) void
+bar (struct S x, struct S y)
+{
+  if (x.a != 0 || x.b != 1 || x.c != 0 || x.d != 1
+  || x.e != 7239 || x.f != 6474)
+__builtin_abort ();
+  if (y.a != 0 || y.b != 1 || y.c != 1 || y.d != 1
+  || y.e != 16320 || y.f != 7315)
+__builtin_abort ();
+}
+
+__attribute__((noipa)) void
+baz (struct S x)
+{
+  if (x.a != 1 || x.b != 1 || x.c != 1 || x.d != 1
+  || x.e != 16320 || x.f != 7315)
+__builtin_abort ();
+}
+
+__attribute__((noipa)) void
+qux (struct S x, struct S y, unsigned z)
+{
+  struct S a = x, b;
+  for (unsigned i = 0; i < z; ++i)
+foo (x);
+  if (x.a && x.e == 16)
+a.e = 32;
+  b = a;
+  b.c = y.c;
+  b.e = y.e;
+  b.f = y.f;
+  bar (a, b);
+  a = b;
+  __asm volatile ("" : : : "ax", "bx", "cx", "dx", "si", "di",
+#ifdef __OPTIMIZE__
+			   "bp",
+#endif
+			   "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15");
+  a.a = 1;
+  a.c = 1;
+  baz (a);
+}
+
+int
+main ()
+{
+  struct S x = { 0, 1, 0, 1, 7239, 6474 };
+  struct S y = { 1, 0, 1, 0, 16320, 7315 };
+  qux (x, y, 1);
+  return 0;
+}


Re: [PATCH 1/2] [aarch64] Rework fpcr fpsr getter/setter builtins

2020-06-04 Thread Richard Sandiford
Andrea Corallo  writes:
> Hi all,
>
> I'd like to submit this patch introducing the following 64bit builtins
> variants as FPCR and FPSR registers getter/setter:
>
> unsigned long long __builtin_aarch64_get_fpcr64 ()
> void __builtin_aarch64_set_fpcr64 (unsigned long long)
> unsigned long long __builtin_aarch64_get_fpsr64 ()
> void __builtin_aarch64_set_fpsr64 (unsigned long long)

Sound like this part is uncontroversial.  At least, if anyone objects
to it, they should have said so earlier :-)

> @@ -1240,33 +1245,65 @@ aarch64_init_memtag_builtins (void)
>  #undef AARCH64_INIT_MEMTAG_BUILTINS_DECL
>  }
>  
> -/* Initialize all builtins in the AARCH64_BUILTIN_GENERAL group.  */
> +/* Initialize fpsr fpcr getter and setters.  */

“getters”

> @@ -1871,6 +1908,40 @@ aarch64_expand_builtin_memtag (int fcode, tree exp, 
> rtx target)
>return target;
>  }
>  
> +static rtx
> +aarch64_expand_fcr_fpsr_builtin (tree exp, machine_mode mode, bool getter,
> +  bool fpsr)
> +{
> +  int icode;
> +  rtx pat;
> +  rtx target = NULL_RTX;
> +
> +  gcc_assert (mode == SImode || (mode == DImode));
> +
> +  if (getter)
> +{
> +  if (mode == SImode)
> + icode = fpsr ? CODE_FOR_get_fpsr : CODE_FOR_get_fpcr;
> +  else
> + icode = fpsr ? CODE_FOR_get_fpsr64 : CODE_FOR_get_fpcr64;
> +  target = gen_reg_rtx (mode);
> +  pat = GEN_FCN (icode) (target);
> +}
> +  else
> +{
> +  target = NULL_RTX;
> +  if (mode == SImode)
> + icode = fpsr ? CODE_FOR_set_fpsr : CODE_FOR_set_fpcr;
> +  else
> + icode = fpsr ? CODE_FOR_set_fpsr64 : CODE_FOR_set_fpcr64;
> +  tree arg = CALL_EXPR_ARG (exp, 0);
> +  rtx op = force_reg (mode, expand_normal (arg));
> +  pat = GEN_FCN (icode) (op);
> +}
> +  emit_insn (pat);
> +  return target;
> +}
> +
>  /* Expand an expression EXP that calls built-in function FCODE,
> with result going to TARGET if that's convenient.  IGNORE is true
> if the result of the builtin is ignored.  */
> @@ -1879,35 +1950,27 @@ aarch64_general_expand_builtin (unsigned int fcode, 
> tree exp, rtx target,
>   int ignore)
>  {
>int icode;
> -  rtx pat, op0;
> +  rtx op0;
>tree arg0;
>  
>switch (fcode)
>  {
>  case AARCH64_BUILTIN_GET_FPCR:
> +  return aarch64_expand_fcr_fpsr_builtin (exp, SImode, true, false);
>  case AARCH64_BUILTIN_SET_FPCR:
> +  return aarch64_expand_fcr_fpsr_builtin (exp, SImode, false, false);
>  case AARCH64_BUILTIN_GET_FPSR:
> +  return aarch64_expand_fcr_fpsr_builtin (exp, SImode, true, true);
>  case AARCH64_BUILTIN_SET_FPSR:
> -  if ((fcode == AARCH64_BUILTIN_GET_FPCR)
> -   || (fcode == AARCH64_BUILTIN_GET_FPSR))
> - {
> -   icode = (fcode == AARCH64_BUILTIN_GET_FPSR) ?
> - CODE_FOR_get_fpsr : CODE_FOR_get_fpcr;
> -   target = gen_reg_rtx (SImode);
> -   pat = GEN_FCN (icode) (target);
> - }
> -  else
> - {
> -   target = NULL_RTX;
> -   icode = (fcode == AARCH64_BUILTIN_SET_FPSR) ?
> - CODE_FOR_set_fpsr : CODE_FOR_set_fpcr;
> -   arg0 = CALL_EXPR_ARG (exp, 0);
> -   op0 = force_reg (SImode, expand_normal (arg0));
> -   pat = GEN_FCN (icode) (op0);
> - }
> -  emit_insn (pat);
> -  return target;
> -
> +  return aarch64_expand_fcr_fpsr_builtin (exp, SImode, false, true);
> +case AARCH64_BUILTIN_GET_FPCR64:
> +  return aarch64_expand_fcr_fpsr_builtin (exp, DImode, true, false);
> +case AARCH64_BUILTIN_SET_FPCR64:
> +  return aarch64_expand_fcr_fpsr_builtin (exp, DImode, false, false);
> +case AARCH64_BUILTIN_GET_FPSR64:
> +  return aarch64_expand_fcr_fpsr_builtin (exp, DImode, true, true);
> +case AARCH64_BUILTIN_SET_FPSR64:
> +  return aarch64_expand_fcr_fpsr_builtin (exp, DImode, false, true);
>  case AARCH64_PAUTH_BUILTIN_AUTIA1716:
>  case AARCH64_PAUTH_BUILTIN_PACIA1716:
>  case AARCH64_PAUTH_BUILTIN_AUTIB1716:
> diff --git a/gcc/config/aarch64/aarch64.md b/gcc/config/aarch64/aarch64.md
> index 7ad4e918578b..b6836710c9c2 100644
> --- a/gcc/config/aarch64/aarch64.md
> +++ b/gcc/config/aarch64/aarch64.md
> @@ -289,6 +289,10 @@
>  UNSPECV_SET_FPCR ; Represent assign of FPCR content.
>  UNSPECV_GET_FPSR ; Represent fetch of FPSR content.
>  UNSPECV_SET_FPSR ; Represent assign of FPSR content.
> +UNSPECV_GET_FPCR64   ; Represent fetch of 64 bits FPCR 
> content.
> +UNSPECV_SET_FPCR64   ; Represent assign of 64 bits FPCR 
> content.
> +UNSPECV_GET_FPSR64   ; Represent fetch of 64 bits FPSR 
> content.
> +UNSPECV_SET_FPSR64   ; Represent assign of 64 bits FPSR 
> content.
>  UNSPECV_BLOCKAGE ; Represent a blockage
>  UNSPECV_PROBE_STACK_RANGE; Represent stack range probing.
>  UNSPECV_SPECULATION_BARRIER ; Represent speculation barrier.
> @@ -7198,6 +7202,35 @@
>

Re: [COMMITTED] patch for PR95464

2020-06-04 Thread Vladimir Makarov via Gcc-patches



On 2020-06-04 12:55 p.m., H.J. Lu wrote:

On Thu, Jun 4, 2020 at 9:17 AM Jakub Jelinek via Gcc-patches
 wrote:


The testcase from the PR was a dg-do run testcase that FAILed without your
patch, can't we just use that testcase (in gcc.target/i386/, restricted to
lp64 and possibly linux only to make sure frame pointer can be safely
omitted)?

Why lp64?  Shouldn't it be !ia32?


Thank you, H.J.  I'll use ! ia32.




[PATCH 6/7, V2] PowerPC tests: Add PC-relative tests.

2020-06-04 Thread Michael Meissner via Gcc-patches
[PATCH 6/7, V2] PowerPC tests: Add PC-relative tests.

These tests make sure that PC-relative variant is generated for -mcpu=future on
systems that support PC-relative addressing.  The only difference
is I reworded the comments, based on a suggestion by Will Schmidt.

2020-06-03  Michael Meissner  

* gcc.target/powerpc/prefix-pcrel-dd.c: New test.
* gcc.target/powerpc/prefix-pcrel-df.c: New test.
* gcc.target/powerpc/prefix-pcrel-di.c: New test.
* gcc.target/powerpc/prefix-pcrel-hi.c: New test.
* gcc.target/powerpc/prefix-pcrel-kf.c: New test.
* gcc.target/powerpc/prefix-pcrel-qi.c: New test.
* gcc.target/powerpc/prefix-pcrel-sd.c: New test.
* gcc.target/powerpc/prefix-pcrel-sf.c: New test.
* gcc.target/powerpc/prefix-pcrel-si.c: New test.
* gcc.target/powerpc/prefix-pcrel-udi.c: New test.
* gcc.target/powerpc/prefix-pcrel-uhi.c: New test.
* gcc.target/powerpc/prefix-pcrel-uqi.c: New test.
* gcc.target/powerpc/prefix-pcrel-usi.c: New test.
* gcc.target/powerpc/prefix-pcrel-v2df.c: New test.
* gcc.target/powerpc/prefix-pcrel.h: Include file for new tests.
---
 gcc/testsuite/gcc.target/powerpc/prefix-pcrel-dd.c | 13 +++
 gcc/testsuite/gcc.target/powerpc/prefix-pcrel-df.c | 13 +++
 gcc/testsuite/gcc.target/powerpc/prefix-pcrel-di.c | 14 
 gcc/testsuite/gcc.target/powerpc/prefix-pcrel-hi.c | 13 +++
 gcc/testsuite/gcc.target/powerpc/prefix-pcrel-kf.c | 13 +++
 gcc/testsuite/gcc.target/powerpc/prefix-pcrel-qi.c | 13 +++
 gcc/testsuite/gcc.target/powerpc/prefix-pcrel-sd.c | 15 
 gcc/testsuite/gcc.target/powerpc/prefix-pcrel-sf.c | 13 +++
 gcc/testsuite/gcc.target/powerpc/prefix-pcrel-si.c | 13 +++
 .../gcc.target/powerpc/prefix-pcrel-udi.c  | 14 
 .../gcc.target/powerpc/prefix-pcrel-uhi.c  | 13 +++
 .../gcc.target/powerpc/prefix-pcrel-uqi.c  | 13 +++
 .../gcc.target/powerpc/prefix-pcrel-usi.c  | 13 +++
 .../gcc.target/powerpc/prefix-pcrel-v2df.c | 13 +++
 gcc/testsuite/gcc.target/powerpc/prefix-pcrel.h| 41 ++
 15 files changed, 227 insertions(+)
 create mode 100644 gcc/testsuite/gcc.target/powerpc/prefix-pcrel-dd.c
 create mode 100644 gcc/testsuite/gcc.target/powerpc/prefix-pcrel-df.c
 create mode 100644 gcc/testsuite/gcc.target/powerpc/prefix-pcrel-di.c
 create mode 100644 gcc/testsuite/gcc.target/powerpc/prefix-pcrel-hi.c
 create mode 100644 gcc/testsuite/gcc.target/powerpc/prefix-pcrel-kf.c
 create mode 100644 gcc/testsuite/gcc.target/powerpc/prefix-pcrel-qi.c
 create mode 100644 gcc/testsuite/gcc.target/powerpc/prefix-pcrel-sd.c
 create mode 100644 gcc/testsuite/gcc.target/powerpc/prefix-pcrel-sf.c
 create mode 100644 gcc/testsuite/gcc.target/powerpc/prefix-pcrel-si.c
 create mode 100644 gcc/testsuite/gcc.target/powerpc/prefix-pcrel-udi.c
 create mode 100644 gcc/testsuite/gcc.target/powerpc/prefix-pcrel-uhi.c
 create mode 100644 gcc/testsuite/gcc.target/powerpc/prefix-pcrel-uqi.c
 create mode 100644 gcc/testsuite/gcc.target/powerpc/prefix-pcrel-usi.c
 create mode 100644 gcc/testsuite/gcc.target/powerpc/prefix-pcrel-v2df.c
 create mode 100644 gcc/testsuite/gcc.target/powerpc/prefix-pcrel.h

diff --git a/gcc/testsuite/gcc.target/powerpc/prefix-pcrel-dd.c 
b/gcc/testsuite/gcc.target/powerpc/prefix-pcrel-dd.c
new file mode 100644
index 000..bea6185
--- /dev/null
+++ b/gcc/testsuite/gcc.target/powerpc/prefix-pcrel-dd.c
@@ -0,0 +1,13 @@
+/* { dg-do compile } */
+/* { dg-require-effective-target powerpc_pcrel } */
+/* { dg-options "-O2 -mdejagnu-cpu=future" } */
+
+/* Tests whether pc-relative prefixed instructions are generated for the
+   _Decimal64 type.  */
+
+#define TYPE _Decimal64
+
+#include "prefix-pcrel.h"
+
+/* { dg-final { scan-assembler-times {\mplfd\M}  2 } } */
+/* { dg-final { scan-assembler-times {\mpstfd\M} 2 } } */
diff --git a/gcc/testsuite/gcc.target/powerpc/prefix-pcrel-df.c 
b/gcc/testsuite/gcc.target/powerpc/prefix-pcrel-df.c
new file mode 100644
index 000..3b232cd
--- /dev/null
+++ b/gcc/testsuite/gcc.target/powerpc/prefix-pcrel-df.c
@@ -0,0 +1,13 @@
+/* { dg-do compile } */
+/* { dg-require-effective-target powerpc_pcrel } */
+/* { dg-options "-O2 -mdejagnu-cpu=future" } */
+
+/* Tests whether pc-relative prefixed instructions are generated for the
+   double type.  */
+
+#define TYPE double
+
+#include "prefix-pcrel.h"
+
+/* { dg-final { scan-assembler-times {\mplfd\M}  2 } } */
+/* { dg-final { scan-assembler-times {\mpstfd\M} 2 } } */
diff --git a/gcc/testsuite/gcc.target/powerpc/prefix-pcrel-di.c 
b/gcc/testsuite/gcc.target/powerpc/prefix-pcrel-di.c
new file mode 100644
index 000..5727971
--- /dev/null
+++ b/gcc/testsuite/gcc.target/powerpc/prefix-pcrel-di.c
@@ -0,0 +1,14 @@
+/* { dg-do compile } */
+/* { dg-require-effective-target powerpc_pcrel } */
+/* { dg-require-effective-target lp64 } */
+/* { dg-options "-O2 

[PATCH 5/7, V2] PowerPC tests: Prefixed insn with large offsets

2020-06-04 Thread Michael Meissner via Gcc-patches
[PATCH 5/7, V2] PowerPC tests: Prefixed insn with large offsets

Add tests to make sure for -mcpu=future that prefixed load/store instructions
are generated if the offset is larger than 16 bits.  The only difference
is I reworded the comments, based on a suggestion by Will Schmidt.

2020-06-04  Michael Meissner  

* gcc.target/powerpc/prefix-large-dd.c: New test.
* gcc.target/powerpc/prefix-large-df.c: New test.
* gcc.target/powerpc/prefix-large-di.c: New test.
* gcc.target/powerpc/prefix-large-hi.c: New test.
* gcc.target/powerpc/prefix-large-kf.c: New test.
* gcc.target/powerpc/prefix-large-qi.c: New test.
* gcc.target/powerpc/prefix-large-sd.c: New test.
* gcc.target/powerpc/prefix-large-sf.c: New test.
* gcc.target/powerpc/prefix-large-si.c: New test.
* gcc.target/powerpc/prefix-large-udi.c: New test.
* gcc.target/powerpc/prefix-large-uhi.c: New test.
* gcc.target/powerpc/prefix-large-uqi.c: New test.
* gcc.target/powerpc/prefix-large-usi.c: New test.
* gcc.target/powerpc/prefix-large-v2df.c: New test.
* gcc.target/powerpc/prefix-large.h: Include file for new tests.
---
 gcc/testsuite/gcc.target/powerpc/prefix-large-dd.c | 13 +++
 gcc/testsuite/gcc.target/powerpc/prefix-large-df.c | 13 +++
 gcc/testsuite/gcc.target/powerpc/prefix-large-di.c | 14 
 gcc/testsuite/gcc.target/powerpc/prefix-large-hi.c | 13 +++
 gcc/testsuite/gcc.target/powerpc/prefix-large-kf.c | 13 +++
 gcc/testsuite/gcc.target/powerpc/prefix-large-qi.c | 13 +++
 gcc/testsuite/gcc.target/powerpc/prefix-large-sd.c | 19 ++
 gcc/testsuite/gcc.target/powerpc/prefix-large-sf.c | 13 +++
 gcc/testsuite/gcc.target/powerpc/prefix-large-si.c | 13 +++
 .../gcc.target/powerpc/prefix-large-udi.c  | 14 
 .../gcc.target/powerpc/prefix-large-uhi.c  | 13 +++
 .../gcc.target/powerpc/prefix-large-uqi.c  | 13 +++
 .../gcc.target/powerpc/prefix-large-usi.c  | 13 +++
 .../gcc.target/powerpc/prefix-large-v2df.c | 13 +++
 gcc/testsuite/gcc.target/powerpc/prefix-large.h| 40 ++
 15 files changed, 230 insertions(+)
 create mode 100644 gcc/testsuite/gcc.target/powerpc/prefix-large-dd.c
 create mode 100644 gcc/testsuite/gcc.target/powerpc/prefix-large-df.c
 create mode 100644 gcc/testsuite/gcc.target/powerpc/prefix-large-di.c
 create mode 100644 gcc/testsuite/gcc.target/powerpc/prefix-large-hi.c
 create mode 100644 gcc/testsuite/gcc.target/powerpc/prefix-large-kf.c
 create mode 100644 gcc/testsuite/gcc.target/powerpc/prefix-large-qi.c
 create mode 100644 gcc/testsuite/gcc.target/powerpc/prefix-large-sd.c
 create mode 100644 gcc/testsuite/gcc.target/powerpc/prefix-large-sf.c
 create mode 100644 gcc/testsuite/gcc.target/powerpc/prefix-large-si.c
 create mode 100644 gcc/testsuite/gcc.target/powerpc/prefix-large-udi.c
 create mode 100644 gcc/testsuite/gcc.target/powerpc/prefix-large-uhi.c
 create mode 100644 gcc/testsuite/gcc.target/powerpc/prefix-large-uqi.c
 create mode 100644 gcc/testsuite/gcc.target/powerpc/prefix-large-usi.c
 create mode 100644 gcc/testsuite/gcc.target/powerpc/prefix-large-v2df.c
 create mode 100644 gcc/testsuite/gcc.target/powerpc/prefix-large.h

diff --git a/gcc/testsuite/gcc.target/powerpc/prefix-large-dd.c 
b/gcc/testsuite/gcc.target/powerpc/prefix-large-dd.c
new file mode 100644
index 000..81cfe77
--- /dev/null
+++ b/gcc/testsuite/gcc.target/powerpc/prefix-large-dd.c
@@ -0,0 +1,13 @@
+/* { dg-do compile } */
+/* { dg-require-effective-target powerpc_prefixed_addr } */
+/* { dg-options "-O2 -mdejagnu-cpu=future" } */
+
+/* Tests whether prefixed instructions with large numeric offsets are generated
+   for the _Decimal64 type.  */
+
+#define TYPE _Decimal64
+
+#include "prefix-large.h"
+
+/* { dg-final { scan-assembler-times {\mplfd\M}  2 } } */
+/* { dg-final { scan-assembler-times {\mpstfd\M} 2 } } */
diff --git a/gcc/testsuite/gcc.target/powerpc/prefix-large-df.c 
b/gcc/testsuite/gcc.target/powerpc/prefix-large-df.c
new file mode 100644
index 000..b0794dc
--- /dev/null
+++ b/gcc/testsuite/gcc.target/powerpc/prefix-large-df.c
@@ -0,0 +1,13 @@
+/* { dg-do compile } */
+/* { dg-require-effective-target powerpc_prefixed_addr } */
+/* { dg-options "-O2 -mdejagnu-cpu=future" } */
+
+/* Tests whether prefixed instructions with large numeric offsets are generated
+   for the double type.  */
+
+#define TYPE double
+
+#include "prefix-large.h"
+
+/* { dg-final { scan-assembler-times {\mplfd\M}  2 } } */
+/* { dg-final { scan-assembler-times {\mpstfd\M} 2 } } */
diff --git a/gcc/testsuite/gcc.target/powerpc/prefix-large-di.c 
b/gcc/testsuite/gcc.target/powerpc/prefix-large-di.c
new file mode 100644
index 000..d4fcfed
--- /dev/null
+++ b/gcc/testsuite/gcc.target/powerpc/prefix-large-di.c
@@ -0,0 +1,14 @@
+/* { dg-do compile } */
+/* { dg-require-effective-target powerpc_prefixed_addr } */
+/* 

Re: [PATCH] warn on uninitialized accesses by function calls (PR 10138)

2020-06-04 Thread Jeff Law via Gcc-patches
On Fri, 2020-05-15 at 17:31 -0600, Martin Sebor via Gcc-patches wrote:
> Besides better buffer overflow checking, the new GCC 10 attribute
> access also provides an opportunity to detect other kinds of bugs,
> including uninitialized accesses by user-defined functions.
> The attached patch implements this enhancement.
> 
> In addition, the closely related PR 10138 requests that GCC warn when
> passing the address of an uninitialized variable to a const-qualified
> pointer function argument.  Const pointers almost always imply a read
> access of the object, so the patch also enables the warning in these
> cases.  (There are situations when a const pointer doesn't imply it
> and the warning takes care not to trigger overly enthusiastically.)
> Since pointers often point to allocated objects it seemed natural
> (and was surprisingly easy) to also detect uninitialized reads from
> those.
> 
> For optimum results I slightly enhanced the detection of the referenced
> decls and allocations.  In the process, I also noticed and fixed a small
> bug in the existing code.   This helps both find more uninitialized
> variables and reduce the rate of false positives in existing warnings.
> 
> Besides the usual GCC bootstrap/regtest I validated the changes by
> building a number of packages, including Binutils/GDB, Glibc, and
> the Linux kernel.  It found a decent number of likely bugs (about
> half a doze by my count) but also triggered a few false positives.
> One class of such problems was due to the kernel's function
> 
>__check_object_size (const void*, unsigned, bool)
> 
> used to validate the sizes of objects without ever accessing them.
> To accommodate this idiom the patch adds a new  mode to attribute
> access: none.
There's a minor typo in a comment within initialize_argument_information
s/accewss/access/

I'm slightly concerned about the diagnostic wording change breaking scanners and
such, but that's well outside what we consider stable release-to-release.  So,
OK.

I think Bin has some work in tree-ssa-uninit.c that's been approved, but not
merged yet and there may be conflicts (though no fundamental conceptual
conflicts).  I suggest committing immediately rather than waiting for Bin though
-- I'll ping Bin on his change and let him know there's a notable potential for
conflicts.

jeff
> 



[PATCH][GCC] arm: Fix the MVE ACLE vaddq_m polymorphic variants.

2020-06-04 Thread Srinath Parvathaneni
Hello,

This patch fixes the MVE ACLE vaddq_m polymorphic variants by modifying the 
corresponding
intrinsic parameters and vaddq_m polymorphic variant's _Generic case entries in 
"arm_mve.h"
header file.

Please refer to M-profile Vector Extension (MVE) intrinsics [1] for more 
details.
[1] 
https://developer.arm.com/architectures/instruction-sets/simd-isas/helium/mve-intrinsics

Regression tested on arm-none-eabi and found no regressions.

Ok for master and gcc-10 branch?

Thanks,
Srinath.

gcc/ChangeLog:

2020-06-04  Srinath Parvathaneni  

* config/arm/arm_mve.h (__arm_vaddq_m_n_s8): Correct the intrinsic
arguments.
(__arm_vaddq_m_n_s32): Likewise.
(__arm_vaddq_m_n_s16): Likewise.
(__arm_vaddq_m_n_u8): Likewise.
(__arm_vaddq_m_n_u32): Likewise.
(__arm_vaddq_m_n_u16): Likewise.
(__arm_vaddq_m): Modify polymorphic variant.

gcc/testsuite/ChangeLog:

2020-06-04  Srinath Parvathaneni  

* gcc.target/arm/mve/intrinsics/mve_vaddq_m.c: New test.



### Attachment also inlined for ease of reply###


diff --git a/gcc/config/arm/arm_mve.h b/gcc/config/arm/arm_mve.h
index 
1002512a98f9364403f66eba0e320fe5070bdc3a..9ea146189883c09c71842f10d25dc9924b5ae7e3
 100644
--- a/gcc/config/arm/arm_mve.h
+++ b/gcc/config/arm/arm_mve.h
@@ -9713,42 +9713,42 @@ __arm_vabdq_m_u16 (uint16x8_t __inactive, uint16x8_t 
__a, uint16x8_t __b, mve_pr
 
 __extension__ extern __inline int8x16_t
 __attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
-__arm_vaddq_m_n_s8 (int8x16_t __inactive, int8x16_t __a, int8_t __b, 
mve_pred16_t __p)
+__arm_vaddq_m_n_s8 (int8x16_t __inactive, int8x16_t __a, int __b, mve_pred16_t 
__p)
 {
   return __builtin_mve_vaddq_m_n_sv16qi (__inactive, __a, __b, __p);
 }
 
 __extension__ extern __inline int32x4_t
 __attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
-__arm_vaddq_m_n_s32 (int32x4_t __inactive, int32x4_t __a, int32_t __b, 
mve_pred16_t __p)
+__arm_vaddq_m_n_s32 (int32x4_t __inactive, int32x4_t __a, int __b, 
mve_pred16_t __p)
 {
   return __builtin_mve_vaddq_m_n_sv4si (__inactive, __a, __b, __p);
 }
 
 __extension__ extern __inline int16x8_t
 __attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
-__arm_vaddq_m_n_s16 (int16x8_t __inactive, int16x8_t __a, int16_t __b, 
mve_pred16_t __p)
+__arm_vaddq_m_n_s16 (int16x8_t __inactive, int16x8_t __a, int __b, 
mve_pred16_t __p)
 {
   return __builtin_mve_vaddq_m_n_sv8hi (__inactive, __a, __b, __p);
 }
 
 __extension__ extern __inline uint8x16_t
 __attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
-__arm_vaddq_m_n_u8 (uint8x16_t __inactive, uint8x16_t __a, uint8_t __b, 
mve_pred16_t __p)
+__arm_vaddq_m_n_u8 (uint8x16_t __inactive, uint8x16_t __a, int __b, 
mve_pred16_t __p)
 {
   return __builtin_mve_vaddq_m_n_uv16qi (__inactive, __a, __b, __p);
 }
 
 __extension__ extern __inline uint32x4_t
 __attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
-__arm_vaddq_m_n_u32 (uint32x4_t __inactive, uint32x4_t __a, uint32_t __b, 
mve_pred16_t __p)
+__arm_vaddq_m_n_u32 (uint32x4_t __inactive, uint32x4_t __a, int __b, 
mve_pred16_t __p)
 {
   return __builtin_mve_vaddq_m_n_uv4si (__inactive, __a, __b, __p);
 }
 
 __extension__ extern __inline uint16x8_t
 __attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
-__arm_vaddq_m_n_u16 (uint16x8_t __inactive, uint16x8_t __a, uint16_t __b, 
mve_pred16_t __p)
+__arm_vaddq_m_n_u16 (uint16x8_t __inactive, uint16x8_t __a, int __b, 
mve_pred16_t __p)
 {
   return __builtin_mve_vaddq_m_n_uv8hi (__inactive, __a, __b, __p);
 }
@@ -26493,42 +26493,42 @@ __arm_vabdq_m (uint16x8_t __inactive, uint16x8_t __a, 
uint16x8_t __b, mve_pred16
 
 __extension__ extern __inline int8x16_t
 __attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
-__arm_vaddq_m (int8x16_t __inactive, int8x16_t __a, int8_t __b, mve_pred16_t 
__p)
+__arm_vaddq_m (int8x16_t __inactive, int8x16_t __a, int __b, mve_pred16_t __p)
 {
  return __arm_vaddq_m_n_s8 (__inactive, __a, __b, __p);
 }
 
 __extension__ extern __inline int32x4_t
 __attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
-__arm_vaddq_m (int32x4_t __inactive, int32x4_t __a, int32_t __b, mve_pred16_t 
__p)
+__arm_vaddq_m (int32x4_t __inactive, int32x4_t __a, int __b, mve_pred16_t __p)
 {
  return __arm_vaddq_m_n_s32 (__inactive, __a, __b, __p);
 }
 
 __extension__ extern __inline int16x8_t
 __attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
-__arm_vaddq_m (int16x8_t __inactive, int16x8_t __a, int16_t __b, mve_pred16_t 
__p)
+__arm_vaddq_m (int16x8_t __inactive, int16x8_t __a, int __b, mve_pred16_t __p)
 {
  return __arm_vaddq_m_n_s16 (__inactive, __a, __b, __p);
 }
 
 __extension__ extern __inline uint8x16_t
 __attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
-__arm_vaddq_m (uint8x16_t __inactive, uint8x16_t __a, uint8_t __b, 
mve_pred16_t __p)
+__arm_vaddq_m 

Re: [COMMITTED] patch for PR95464

2020-06-04 Thread H.J. Lu via Gcc-patches
On Thu, Jun 4, 2020 at 9:17 AM Jakub Jelinek via Gcc-patches
 wrote:
>
> On Thu, Jun 04, 2020 at 12:13:51PM -0400, Vladimir Makarov via Gcc-patches 
> wrote:
> > The following patch fixes
> >
> >https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95464
> >
> > The patch was successfully bootstrapped and tested on x86-64.  I did not
> > test it on other major targets as they do not deal with STRICT_LOW_PART.
>
> Thanks.
>
> > There is also no test case for this PR as it is hard to check the right code
> > generation.
>
> The testcase from the PR was a dg-do run testcase that FAILed without your
> patch, can't we just use that testcase (in gcc.target/i386/, restricted to
> lp64 and possibly linux only to make sure frame pointer can be safely
> omitted)?

Why lp64?  Shouldn't it be !ia32?

-- 
H.J.


Re: [PATCH] middle-end/95493 - bogus MEM_ATTRS for variable array access

2020-06-04 Thread Richard Biener via Gcc-patches
On June 4, 2020 6:20:36 PM GMT+02:00, Eric Botcazou  
wrote:
>> I'll go with this variant since it is more obvious unless I hear
>> otherwise.
>
>Yes, at least this one doesn't appear to further confuse an already
>confusing 
>implementation. ;-)
>
>> Thanks,
>> Richard.
>> 
>> 
>> The following patch avoids keeping the inherited MEM_ATTRS when
>> set_mem_attributes_minus_bitpos is called with a variable ARRAY_REF.
>> The inherited ones may not reflect the correct offset and neither
>> does the updated alias-set match the inherited MEM_EXPR.  This all
>> ends up confusing path-based alias-analysis, causing wrong-code.
>
>"variable ARRAY_REF" is just an ARRAY_REF with variable index or an
>ARRAY_REF 
>whose base is variable?  In other words, do we end up taking the 
> /* Else do not record a MEM_EXPR.  */
>
>path instead of setting attrs.expr again?

Yes, we're taking this path in the problematical case. 

>> The fix is to stop not adopting a MEM_EXPR for certain kinds of
>> expressions and instead handle everything we can.  There's still
>> the constant kind trees case which I'm too lazy to look into right
>> now.  I did refrain from adding SSA_NAME there and instead avoided
>> calling set_mem_attributes_minus_bitpos when debug expression
>> expansion ended up expanding a SSA definition RHS which should
>> already have taken care of setting the appropriate MEM_ATTRS.
>
>Do we really need to ditch the entire ARRAY_REF path though?  Aren't we
>going 
>to lose some (trivial) disambiguation possibilities later on by
>recording the 
>ARRAY_REF instead of DECL or COMPONENT_REF (+ offset)?

The patch ends up recording the whole Array ref with variable index. All alias 
analysis code deals with this just fine. 
IIRC historically we tried to save memory with stripping and dropping of 
MEM_EXPRs. 

Richard. 



Re: [COMMITTED] patch for PR95464

2020-06-04 Thread Vladimir Makarov via Gcc-patches



On 2020-06-04 12:17 p.m., Jakub Jelinek wrote:

On Thu, Jun 04, 2020 at 12:13:51PM -0400, Vladimir Makarov via Gcc-patches 
wrote:

The following patch fixes

    https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95464

The patch was successfully bootstrapped and tested on x86-64.  I did not
test it on other major targets as they do not deal with STRICT_LOW_PART.

Thanks.


There is also no test case for this PR as it is hard to check the right code
generation.

The testcase from the PR was a dg-do run testcase that FAILed without your
patch, can't we just use that testcase (in gcc.target/i386/, restricted to
lp64 and possibly linux only to make sure frame pointer can be safely
omitted)?




OK, Jakub.  I'll try to create a test for the PR.





[committed] d: Split up d-frontend.cc into multiple parts.

2020-06-04 Thread Iain Buclaw via Gcc-patches
In preparation for possibly switching the front-end implementation from
C++ to D, a lot of changes in the "glue" layer are just noise from lots
of small, but invasive API changes in the DMD front-end headers.

This will be the first of about a dozen or so.  This change splits up
the few implementations in d/d-frontend.cc into separated files.

Regression tested on x86_64-linux-gnu and committed to mainline.

Regards
Iain


gcc/d/ChangeLog:

* Make-lang.in (D_OBJS): Add d-compiler.o, d-ctfloat.o, d-port.o.
* d-frontend.cc (Port::memicmp): Move to d-port.cc.
(Port::strupr): Likewise.
(Port::isFloat32LiteralOutOfRange): Likewise.
(Port::isFloat64LiteralOutOfRange): Likewise.
(Port::readwordLE): Likewise.
(Port::readwordBE): Likewise.
(Port::readlongLE): Likewise.
(Port::readlongBE): Likewise.
(Port::valcpy): Likewise.
(CTFloat::fabs): Move to d-ctfloat.cc.
(CTFloat::ldexp): Likewise.
(CTFloat::isIdentical): Likewise.
(CTFloat::isNaN): Likewise.
(CTFloat::isSNaN): Likewise.
(CTFloat::isInfinity): Likewise.
(CTFloat::parse): Likewise.
(CTFloat::sprint): Likewise.
(CTFloat::hash): Likewise.
(Compiler::genCmain): Move to d-compiler.cc.
(Compiler::paintAsType): Likewise.
(Compiler::loadModule): Likewise.
* d-compiler.cc: New file.
* d-ctfloat.cc: New file.
* d-port.cc: New file.
---
 gcc/d/Make-lang.in  |  26 ++-
 gcc/d/d-compiler.cc | 182 +++
 gcc/d/d-ctfloat.cc  | 143 +++
 gcc/d/d-frontend.cc | 416 
 gcc/d/d-port.cc | 169 ++
 5 files changed, 516 insertions(+), 420 deletions(-)
 create mode 100644 gcc/d/d-compiler.cc
 create mode 100644 gcc/d/d-ctfloat.cc
 create mode 100644 gcc/d/d-port.cc

diff --git a/gcc/d/Make-lang.in b/gcc/d/Make-lang.in
index ac04d074aa5..6c8c611a0f7 100644
--- a/gcc/d/Make-lang.in
+++ b/gcc/d/Make-lang.in
@@ -133,10 +133,28 @@ D_GENERATED_OBJS = d/id.o d/impcnvtab.o
 
 # Language-specific object files for D.
 D_OBJS = \
-   d/d-attribs.o d/d-builtins.o d/d-codegen.o d/d-convert.o \
-   d/d-diagnostic.o d/d-frontend.o d/d-incpath.o d/d-lang.o \
-   d/d-longdouble.o d/d-target.o d/decl.o d/expr.o d/imports.o \
-   d/intrinsics.o d/modules.o d/runtime.o d/toir.o d/typeinfo.o d/types.o
+   d/d-attribs.o \
+   d/d-builtins.o \
+   d/d-codegen.o \
+   d/d-compiler.o \
+   d/d-convert.o \
+   d/d-ctfloat.o \
+   d/d-diagnostic.o \
+   d/d-frontend.o \
+   d/d-incpath.o \
+   d/d-lang.o \
+   d/d-longdouble.o \
+   d/d-port.o \
+   d/d-target.o \
+   d/decl.o \
+   d/expr.o \
+   d/imports.o \
+   d/intrinsics.o \
+   d/modules.o \
+   d/runtime.o \
+   d/toir.o \
+   d/typeinfo.o \
+   d/types.o
 
 # All language-specific object files for D.
 D_ALL_OBJS = $(D_FRONTEND_OBJS) $(D_GENERATED_OBJS) $(D_OBJS) $(D_TARGET_OBJS)
diff --git a/gcc/d/d-compiler.cc b/gcc/d/d-compiler.cc
new file mode 100644
index 000..a27261fb94e
--- /dev/null
+++ b/gcc/d/d-compiler.cc
@@ -0,0 +1,182 @@
+/* d-compiler.cc -- D frontend interface to the gcc back-end.
+   Copyright (C) 2020 Free Software Foundation, Inc.
+
+GCC is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3, or (at your option)
+any later version.
+
+GCC is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3.  If not see
+.  */
+
+#include "config.h"
+#include "system.h"
+#include "coretypes.h"
+
+#include "dmd/compiler.h"
+#include "dmd/scope.h"
+#include "dmd/expression.h"
+#include "dmd/identifier.h"
+#include "dmd/module.h"
+#include "dmd/mtype.h"
+
+#include "tree.h"
+#include "fold-const.h"
+
+#include "d-tree.h"
+
+
+/* Implements the Compiler interface used by the frontend.  */
+
+/* Generate C main() in response to seeing D main().  This used to be in
+   libdruntime, but contained a reference to _Dmain which didn't work when
+   druntime was made into a shared library and was linked to a program, such
+   as a C++ program, that didn't have a _Dmain.  */
+
+void
+Compiler::genCmain (Scope *sc)
+{
+  static bool initialized = false;
+
+  if (initialized)
+return;
+
+  /* The D code to be generated is provided by __entrypoint.di, try to load it,
+ but don't fail if unfound.  */
+  unsigned errors = global.startGagging ();
+  Module *m = Module::load (Loc (), NULL, Identifier::idPool ("__entrypoint"));
+
+  if 

Re: [PATCH] middle-end/95493 - bogus MEM_ATTRS for variable array access

2020-06-04 Thread Eric Botcazou
> I'll go with this variant since it is more obvious unless I hear
> otherwise.

Yes, at least this one doesn't appear to further confuse an already confusing 
implementation. ;-)

> Thanks,
> Richard.
> 
> 
> The following patch avoids keeping the inherited MEM_ATTRS when
> set_mem_attributes_minus_bitpos is called with a variable ARRAY_REF.
> The inherited ones may not reflect the correct offset and neither
> does the updated alias-set match the inherited MEM_EXPR.  This all
> ends up confusing path-based alias-analysis, causing wrong-code.

"variable ARRAY_REF" is just an ARRAY_REF with variable index or an ARRAY_REF 
whose base is variable?  In other words, do we end up taking the 

  /* Else do not record a MEM_EXPR.  */

path instead of setting attrs.expr again?

> The fix is to stop not adopting a MEM_EXPR for certain kinds of
> expressions and instead handle everything we can.  There's still
> the constant kind trees case which I'm too lazy to look into right
> now.  I did refrain from adding SSA_NAME there and instead avoided
> calling set_mem_attributes_minus_bitpos when debug expression
> expansion ended up expanding a SSA definition RHS which should
> already have taken care of setting the appropriate MEM_ATTRS.

Do we really need to ditch the entire ARRAY_REF path though?  Aren't we going 
to lose some (trivial) disambiguation possibilities later on by recording the 
ARRAY_REF instead of DECL or COMPONENT_REF (+ offset)?

-- 
Eric Botcazou


Re: [COMMITTED] patch for PR95464

2020-06-04 Thread Jakub Jelinek via Gcc-patches
On Thu, Jun 04, 2020 at 12:13:51PM -0400, Vladimir Makarov via Gcc-patches 
wrote:
> The following patch fixes
> 
>            https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95464
> 
> The patch was successfully bootstrapped and tested on x86-64.  I did not
> test it on other major targets as they do not deal with STRICT_LOW_PART.

Thanks.

> There is also no test case for this PR as it is hard to check the right code
> generation.

The testcase from the PR was a dg-do run testcase that FAILed without your
patch, can't we just use that testcase (in gcc.target/i386/, restricted to
lp64 and possibly linux only to make sure frame pointer can be safely
omitted)?

Jakub



[COMMITTED] patch for PR95464

2020-06-04 Thread Vladimir Makarov via Gcc-patches

The following patch fixes

   https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95464

The patch was successfully bootstrapped and tested on x86-64.  I did not 
test it on other major targets as they do not deal with STRICT_LOW_PART.


There is also no test case for this PR as it is hard to check the right 
code generation.



Add processing STRICT_LOW_PART for matched reloads.

2020-06-04  Vladimir Makarov  

	PR middle-end/95464
	* lra.c (lra_emit_move): Add processing STRICT_LOW_PART.
	* lra-constraints.c (match_reload): Use STRICT_LOW_PART in output
	reload if the original insn has it too.


diff --git a/gcc/lra-constraints.c b/gcc/lra-constraints.c
index bf6d4a2fd4b..421c453997b 100644
--- a/gcc/lra-constraints.c
+++ b/gcc/lra-constraints.c
@@ -1071,6 +1071,8 @@ match_reload (signed char out, signed char *ins, signed char *outs,
   if (find_reg_note (curr_insn, REG_UNUSED, out_rtx) == NULL_RTX)
 {
   start_sequence ();
+  if (out >= 0 && curr_static_id->operand[out].strict_low)
+	out_rtx = gen_rtx_STRICT_LOW_PART (VOIDmode, out_rtx);
   lra_emit_move (out_rtx, copy_rtx (new_out_reg));
   emit_insn (*after);
   *after = get_insns ();
diff --git a/gcc/lra.c b/gcc/lra.c
index 3435cff6a1d..caa09d86ca6 100644
--- a/gcc/lra.c
+++ b/gcc/lra.c
@@ -490,13 +490,16 @@ void
 lra_emit_move (rtx x, rtx y)
 {
   int old;
-
+  rtx_insn *insn;
+  
   if (GET_CODE (y) != PLUS)
 {
   if (rtx_equal_p (x, y))
 	return;
   old = max_reg_num ();
-  rtx_insn *insn = emit_move_insn (x, y);
+
+  insn = (GET_CODE (x) != STRICT_LOW_PART
+	  ? emit_move_insn (x, y) : emit_insn (gen_rtx_SET (x, y)));
   /* The move pattern may require scratch registers, so convert them
 	 into real registers now.  */
   if (insn != NULL_RTX)


aarch64: PR target/95526: Fix gimplification of varargs

2020-06-04 Thread Alex Coplan
This patch fixes a latent bug exposed by
eb72dc663e9070b281be83a80f6f838a3a878822 in the aarch64 backend that was
causing wrong codegen and several testsuite failures. See the discussion
on the bug for details.

Bootstrapped and regtested on aarch64-linux-gnu. Cleaned up several failing
tests and no new fails introduced:

+PASS: gcc.dg/compat/scalar-by-value-3 c_compat_x_tst.o-c_compat_y_tst.o execute
+PASS: gcc.dg/compat/scalar-by-value-4 c_compat_x_tst.o-c_compat_y_tst.o execute
+PASS: gcc.dg/compat/scalar-by-value-5 c_compat_x_tst.o-c_compat_y_tst.o execute
+PASS: gcc.dg/compat/scalar-by-value-6 c_compat_x_tst.o-c_compat_y_tst.o execute
+PASS: gcc.dg/compat/scalar-return-3 c_compat_x_tst.o-c_compat_y_tst.o execute
+PASS: gcc.dg/compat/scalar-return-4 c_compat_x_tst.o-c_compat_y_tst.o execute
+PASS: gcc.dg/complex-1.c execution test
+PASS: gcc.target/aarch64/aapcs64/va_arg-7.c execution,  -O0
+PASS: gcc.target/aarch64/aapcs64/va_arg-7.c execution,  -O1
+PASS: gcc.target/aarch64/aapcs64/va_arg-7.c execution,  -O2
+PASS: gcc.target/aarch64/aapcs64/va_arg-7.c execution,  -O3 -g
+PASS: gcc.target/aarch64/aapcs64/va_arg-7.c execution,  -Og -g
+PASS: gcc.target/aarch64/aapcs64/va_arg-7.c execution,  -Os

Pre-approved on bugzilla: committing to master.

Thanks,
Alex

---

2020-06-04  Richard Biener  

gcc/ChangeLog:

* config/aarch64/aarch64.c (aarch64_gimplify_va_arg_expr):
  Ensure that tmp_ha is marked TREE_ADDRESSABLE.

---

diff --git a/gcc/config/aarch64/aarch64.c b/gcc/config/aarch64/aarch64.c
index 6352d4f..97da607 100644
--- a/gcc/config/aarch64/aarch64.c
+++ b/gcc/config/aarch64/aarch64.c
@@ -16370,6 +16370,7 @@ aarch64_gimplify_va_arg_expr (tree valist, tree type, 
gimple_seq *pre_p,
}
 
   /* *(field_ptr_t) = *((field_ptr_t)vr_saved_area  */
+  TREE_ADDRESSABLE (tmp_ha) = 1;
   tmp_ha = build1 (ADDR_EXPR, field_ptr_t, tmp_ha);
   addr = t;
   t = fold_convert (field_ptr_t, addr);


[PATCH] avr: Add atmega324pb MCU

2020-06-04 Thread Matwey V. Kornilov via Gcc-patches
Reference: https://www.microchip.com/wwwproducts/en/ATMEGA324PB
---
 gcc/config/avr/avr-mcus.def | 1 +
 gcc/doc/avr-mmcu.texi   | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/gcc/config/avr/avr-mcus.def b/gcc/config/avr/avr-mcus.def
index 24046c367a7..ac80f9e63ff 100644
--- a/gcc/config/avr/avr-mcus.def
+++ b/gcc/config/avr/avr-mcus.def
@@ -207,6 +207,7 @@ AVR_MCU ("atmega323",ARCH_AVR5, AVR_ISA_NONE, 
"__AVR_ATmega323__",
 AVR_MCU ("atmega324a",   ARCH_AVR5, AVR_ISA_NONE, "__AVR_ATmega324A__",
0x0100, 0x0, 0x8000, 0)
 AVR_MCU ("atmega324p",   ARCH_AVR5, AVR_ISA_NONE, "__AVR_ATmega324P__",
0x0100, 0x0, 0x8000, 0)
 AVR_MCU ("atmega324pa",  ARCH_AVR5, AVR_ISA_NONE, "__AVR_ATmega324PA__",   
0x0100, 0x0, 0x8000, 0)
+AVR_MCU ("atmega324pb",  ARCH_AVR5, AVR_ISA_NONE, "__AVR_ATmega324PB__",   
0x0100, 0x0, 0x8000, 0)
 AVR_MCU ("atmega325",ARCH_AVR5, AVR_ISA_NONE, "__AVR_ATmega325__", 
0x0100, 0x0, 0x8000, 0)
 AVR_MCU ("atmega325a",   ARCH_AVR5, AVR_ISA_NONE, "__AVR_ATmega325A__",
0x0100, 0x0, 0x8000, 0)
 AVR_MCU ("atmega325p",   ARCH_AVR5, AVR_ISA_NONE, "__AVR_ATmega325P__",
0x0100, 0x0, 0x8000, 0)
diff --git a/gcc/doc/avr-mmcu.texi b/gcc/doc/avr-mmcu.texi
index 5cd7b50afa2..87ed4476b1a 100644
--- a/gcc/doc/avr-mmcu.texi
+++ b/gcc/doc/avr-mmcu.texi
@@ -38,7 +38,7 @@
 
 @item avr5
 ``Enhanced'' devices with 16@tie{}KiB up to 64@tie{}KiB of program memory.
-@*@var{mcu}@tie{}= @code{atmega16}, @code{atmega16a}, @code{atmega16hva}, 
@code{atmega16hva2}, @code{atmega16hvb}, @code{atmega16hvbrevb}, 
@code{atmega16m1}, @code{atmega16u4}, @code{atmega161}, @code{atmega162}, 
@code{atmega163}, @code{atmega164a}, @code{atmega164p}, @code{atmega164pa}, 
@code{atmega165}, @code{atmega165a}, @code{atmega165p}, @code{atmega165pa}, 
@code{atmega168}, @code{atmega168a}, @code{atmega168p}, @code{atmega168pa}, 
@code{atmega168pb}, @code{atmega169}, @code{atmega169a}, @code{atmega169p}, 
@code{atmega169pa}, @code{atmega32}, @code{atmega32a}, @code{atmega32c1}, 
@code{atmega32hvb}, @code{atmega32hvbrevb}, @code{atmega32m1}, 
@code{atmega32u4}, @code{atmega32u6}, @code{atmega323}, @code{atmega324a}, 
@code{atmega324p}, @code{atmega324pa}, @code{atmega325}, @code{atmega325a}, 
@code{atmega325p}, @code{atmega325pa}, @code{atmega328}, @code{atmega328p}, 
@code{atmega328pb}, @code{atmega329}, @code{atmega329a}, @code{atmega329p}, 
@code{atmega329pa}, @code{atmega3250}, @code{atmega3250a}, @code{atmega3250p}, 
@code{atmega3250pa}, @code{atmega3290}, @code{atmega3290a}, @code{atmega3290p}, 
@code{atmega3290pa}, @code{atmega406}, @code{atmega64}, @code{atmega64a}, 
@code{atmega64c1}, @code{atmega64hve}, @code{atmega64hve2}, @code{atmega64m1}, 
@code{atmega64rfr2}, @code{atmega640}, @code{atmega644}, @code{atmega644a}, 
@code{atmega644p}, @code{atmega644pa}, @code{atmega644rfr2}, @code{atmega645}, 
@code{atmega645a}, @code{atmega645p}, @code{atmega649}, @code{atmega649a}, 
@code{atmega649p}, @code{atmega6450}, @code{atmega6450a}, @code{atmega6450p}, 
@code{atmega6490}, @code{atmega6490a}, @code{atmega6490p}, @code{ata5795}, 
@code{ata5790}, @code{ata5790n}, @code{ata5791}, @code{ata6613c}, 
@code{ata6614q}, @code{ata5782}, @code{ata5831}, @code{ata8210}, 
@code{ata8510}, @code{ata5702m322}, @code{at90pwm161}, @code{at90pwm216}, 
@code{at90pwm316}, @code{at90can32}, @code{at90can64}, @code{at90scr100}, 
@code{at90usb646}, @code{at90usb647}, @code{at94k}, @code{m3000}.
+@*@var{mcu}@tie{}= @code{atmega16}, @code{atmega16a}, @code{atmega16hva}, 
@code{atmega16hva2}, @code{atmega16hvb}, @code{atmega16hvbrevb}, 
@code{atmega16m1}, @code{atmega16u4}, @code{atmega161}, @code{atmega162}, 
@code{atmega163}, @code{atmega164a}, @code{atmega164p}, @code{atmega164pa}, 
@code{atmega165}, @code{atmega165a}, @code{atmega165p}, @code{atmega165pa}, 
@code{atmega168}, @code{atmega168a}, @code{atmega168p}, @code{atmega168pa}, 
@code{atmega168pb}, @code{atmega169}, @code{atmega169a}, @code{atmega169p}, 
@code{atmega169pa}, @code{atmega32}, @code{atmega32a}, @code{atmega32c1}, 
@code{atmega32hvb}, @code{atmega32hvbrevb}, @code{atmega32m1}, 
@code{atmega32u4}, @code{atmega32u6}, @code{atmega323}, @code{atmega324a}, 
@code{atmega324p}, @code{atmega324pa}, @code{atmega324pb}, @code{atmega325}, 
@code{atmega325a}, @code{atmega325p}, @code{atmega325pa}, @code{atmega328}, 
@code{atmega328p}, @code{atmega328pb}, @code{atmega329}, @code{atmega329a}, 
@code{atmega329p}, @code{atmega329pa}, @code{atmega3250}, @code{atmega3250a}, 
@code{atmega3250p}, @code{atmega3250pa}, @code{atmega3290}, @code{atmega3290a}, 
@code{atmega3290p}, @code{atmega3290pa}, @code{atmega406}, @code{atmega64}, 
@code{atmega64a}, @code{atmega64c1}, @code{atmega64hve}, @code{atmega64hve2}, 
@code{atmega64m1}, @code{atmega64rfr2}, @code{atmega640}, @code{atmega644}, 
@code{atmega644a}, @code{atmega644p}, @code{atmega644pa}, @code{atmega644rfr2}, 
@code{atmega645}, @code{atmega645a}, 

RE: [EXT] Re: [PATCH] Optimize and+or+sub into xor+not (PR94882)

2020-06-04 Thread Naveen Hurugalawadi via Gcc-patches
Hi,

Thanks for reviewing the patch and sharing your comments.

>> nop_convert4 cannot happen, constants will have been constant folded here.
Removed.

>> So I think it should be and the other patterns adjusted accordingly.
Modified the remaining patterns accordingly.

Please find attached the modified patch as per your suggestions.
Bootstrapped and regression tested on x86_64-pc-linux-gnu.

Thanks,
Naveen


pr94882-1.patch
Description: pr94882-1.patch


RE: arm: Fix vfp_operand_register for VFP HI regs

2020-06-04 Thread Kyrylo Tkachov
Hi Christophe,

> -Original Message-
> From: Christophe Lyon 
> Sent: 03 June 2020 14:30
> To: Kyrylo Tkachov 
> Cc: gcc-patches@gcc.gnu.org
> Subject: Re: arm: Fix vfp_operand_register for VFP HI regs
> 
> Hi,
> 
> 
> On Thu, 14 May 2020 at 17:08, Christophe Lyon
>  wrote:
> >
> > On Fri, 1 May 2020 at 12:57, Kyrylo Tkachov 
> wrote:
> > >
> > >
> > >
> > > > -Original Message-
> > > > From: Christophe Lyon 
> > > > Sent: 30 April 2020 09:51
> > > > To: Kyrylo Tkachov 
> > > > Cc: gcc-patches@gcc.gnu.org
> > > > Subject: Re: arm: Fix vfp_operand_register for VFP HI regs
> > > >
> > > > On Wed, 29 Apr 2020 at 18:40, Kyrylo Tkachov
> 
> > > > wrote:
> > > > >
> > > > > Hi Christophe,
> > > > >
> > > > > > -Original Message-
> > > > > > From: Gcc-patches  On Behalf
> Of
> > > > > > Christophe Lyon via Gcc-patches
> > > > > > Sent: 29 April 2020 16:53
> > > > > > To: gcc Patches 
> > > > > > Subject: arm: Fix vfp_operand_register for VFP HI regs
> > > > > >
> > > > > > Hi,
> > > > > >
> > > > > > While looking at PR target/94743 I noticed an ICE when I tried to
> save
> > > > > > all the FP registers: this was because all HI registers wouldn't 
> > > > > > match
> > > > > > vfp_register_operand.
> > > > >
> > > > > Hmm, I see that arm_regno_class indeed never returns VFP_REGS and
> > > > would return VFP_HI_REGS here.
> > > > > So the patch looks correct to me.
> > > > > Do you have a testcase for the ICE to add to the testsuite?
> > > > >
> > > >
> > > > No C source code: I found that while extending the list of registers
> > > > pushed in the prologue of an IRQ handler, more-or-less modifying
> > > > arm_save_coproc_regs so that more registers are handled by
> > > > vfp_emit_fstmd.
> > > > The problem occurs when trying to push d16-d31.
> > >
> > > I'd be comfortable taking this now for trunk (GCC 11) so it has time to
> bake.
> > > Once you're ready to post the IRQ handler work we can see about
> backporting this fix it to the branch, if we deem it necessary.
> > > Thanks,
> > > Kyrill
> > >
> >
> > Hi,
> >
> > I've just sent several patches for PR 94743:
> > https://gcc.gnu.org/pipermail/gcc-patches/2020-May/545747.html
> > is v2 of my previous patch: it only emits a warning, and might be
> > sufficient to close the PR, if we decide that
> > we don't want to save the FP registers without explicit user request...
> >
> > Then,
> > [1] https://gcc.gnu.org/pipermail/gcc-patches/2020-May/545748.html
> > [2] https://gcc.gnu.org/pipermail/gcc-patches/2020-May/545749.html
> > are refactorization patches that would make implementing the patch
> > attached here easier.
> >
> > If you apply the attached on top of [1] and [2], you'll notice an ICE
> > fixed by the original patch of this thread.
> >
> > So hopefully applying [1], [2] and the attached should help convince you
> that
> > the vfp_operand_register is OK.
> >
> 
> I've committed [1] and [2] several days ago, so it's now easier to apply
> the patch from
> https://gcc.gnu.org/pipermail/gcc-patches/2020-May/545754.html
> which will trigger an ICE in the new testcases it adds,
> which is fixed by the patch that started this thread:
> https://gcc.gnu.org/pipermail/gcc-patches/2020-April/544877.html

This is okay.
Thanks,
Kyrill

> 
> Is that lalter patch OK?
> 
> Thanks,
> 
> Christophe
> 
> > Thanks
> >
> > > >
> > > >
> > > > > Thanks,
> > > > > Kyrill
> > > > >
> > > > > >
> > > > > > Regression-tested and bootstrapped OK.
> > > > > >
> > > > > > 2020-04-29  Christophe Lyon  
> > > > > >
> > > > > > gcc/
> > > > > > * config/arm/predicates.md (vfp_register_operand): Use
> > > > VFP_HI_REGS
> > > > > > instead of VFP_REGS.
> > > > > >
> > > > > > OK?
> > > > > >
> > > > > > Thanks,
> > > > > >
> > > > > > Christophe


RE: [GCC][PATCH][ARM]: Correct the grouping of operands in MVE vector scatter store intrinsics (PR94735).

2020-06-04 Thread Kyrylo Tkachov
Hi Srinath,

> -Original Message-
> From: Srinath Parvathaneni 
> Sent: 02 June 2020 15:00
> To: gcc-patches@gcc.gnu.org
> Cc: Kyrylo Tkachov 
> Subject: [GCC][PATCH][ARM]: Correct the grouping of operands in MVE
> vector scatter store intrinsics (PR94735).
> 
> Hello,
> 
> The operands in RTL patterns of MVE vector scatter store intrinsics are
> wrongly grouped, because of which few
> vector loads and stores instructions are wrongly getting optimized out with -
> O2.
> 
> A new predicate "mve_scatter_memory" is defined in this patch, this
> predicate returns TRUE on
> matching: (mem(reg)) for MVE scatter store intrinsics.
> This patch fixes the issue by adding define_expand pattern with
> "mve_scatter_memory" predicate and calls the
> corresponding define_insn by passing register_operand as first argument.
> This register_operand is extracted
> from the operand with "mve_scatter_memory" predicate in define_expand
> pattern.
> 
> Please refer to M-profile Vector Extension (MVE) intrinsics [1]  for more
> details.
> [1] https://developer.arm.com/architectures/instruction-sets/simd-
> isas/helium/mve-intrinsics
> 
> Regression tested on arm-none-eabi and found no regressions.
> 
> Ok for trunk?

Ok.
Thanks,
Kyrill

> 
> Thanks,
> Srinath.
> 
> gcc/ChangeLog:
> 
> 2020-06-02Srinath Parvathaneni
> 
>   PR target/94735
>   * config/arm//predicates.md (mve_scatter_memory): Define to
>   match (mem (reg)) for scatter store memory.
>   * config/arm/mve.md (mve_vstrbq_scatter_offset_):
> Modify
>   define_insn to define_expand.
>   (mve_vstrbq_scatter_offset_p_): Likewise.
>   (mve_vstrhq_scatter_offset_): Likewise.
>   (mve_vstrhq_scatter_shifted_offset_p_): Likewise.
>   (mve_vstrhq_scatter_shifted_offset_): Likewise.
>   (mve_vstrdq_scatter_offset_p_v2di): Likewise.
>   (mve_vstrdq_scatter_offset_v2di): Likewise.
>   (mve_vstrdq_scatter_shifted_offset_p_v2di): Likewise.
>   (mve_vstrdq_scatter_shifted_offset_v2di): Likewise.
>   (mve_vstrhq_scatter_offset_fv8hf): Likewise.
>   (mve_vstrhq_scatter_offset_p_fv8hf): Likewise.
>   (mve_vstrhq_scatter_shifted_offset_fv8hf): Likewise.
>   (mve_vstrhq_scatter_shifted_offset_p_fv8hf): Likewise.
>   (mve_vstrwq_scatter_offset_fv4sf): Likewise.
>   (mve_vstrwq_scatter_offset_p_fv4sf): Likewise.
>   (mve_vstrwq_scatter_offset_p_v4si): Likewise.
>   (mve_vstrwq_scatter_offset_v4si): Likewise.
>   (mve_vstrwq_scatter_shifted_offset_fv4sf): Likewise.
>   (mve_vstrwq_scatter_shifted_offset_p_fv4sf): Likewise.
>   (mve_vstrwq_scatter_shifted_offset_p_v4si): Likewise.
>   (mve_vstrwq_scatter_shifted_offset_v4si): Likewise.
>   (mve_vstrbq_scatter_offset__insn): Define insn for
> scatter
>   stores.
>   (mve_vstrbq_scatter_offset_p__insn): Likewise.
>   (mve_vstrhq_scatter_offset__insn): Likewise.
>   (mve_vstrhq_scatter_shifted_offset_p__insn):
> Likewise.
>   (mve_vstrhq_scatter_shifted_offset__insn): Likewise.
>   (mve_vstrdq_scatter_offset_p_v2di_insn): Likewise.
>   (mve_vstrdq_scatter_offset_v2di_insn): Likewise.
>   (mve_vstrdq_scatter_shifted_offset_p_v2di_insn): Likewise.
>   (mve_vstrdq_scatter_shifted_offset_v2di_insn): Likewise.
>   (mve_vstrhq_scatter_offset_fv8hf_insn): Likewise.
>   (mve_vstrhq_scatter_offset_p_fv8hf_insn): Likewise.
>   (mve_vstrhq_scatter_shifted_offset_fv8hf_insn): Likewise.
>   (mve_vstrhq_scatter_shifted_offset_p_fv8hf_insn): Likewise.
>   (mve_vstrwq_scatter_offset_fv4sf_insn): Likewise.
>   (mve_vstrwq_scatter_offset_p_fv4sf_insn): Likewise.
>   (mve_vstrwq_scatter_offset_p_v4si_insn): Likewise.
>   (mve_vstrwq_scatter_offset_v4si_insn): Likewise.
>   (mve_vstrwq_scatter_shifted_offset_fv4sf_insn): Likewise.
>   (mve_vstrwq_scatter_shifted_offset_p_fv4sf_insn): Likewise.
>   (mve_vstrwq_scatter_shifted_offset_p_v4si_insn): Likewise.
>   (mve_vstrwq_scatter_shifted_offset_v4si_insn): Likewise.
> 
> gcc/testsuite/ChangeLog:
> 
> 2020-06-02Srinath Parvathanenisrinath.parvathan...@arm.com
> 
>   PR target/94735
>   * gcc.target/arm/mve/intrinsics/mve_vstore_scatter_base.c: New
> test.
>   * gcc.target/arm/mve/intrinsics/mve_vstore_scatter_base_p.c:
> Likewise.
>   * gcc.target/arm/mve/intrinsics/mve_vstore_scatter_offset.c:
> Likewise.
>   * gcc.target/arm/mve/intrinsics/mve_vstore_scatter_offset_p.c:
> Likewise.
>   * gcc.target/arm/mve/intrinsics/mve_vstore_scatter_shifted_offset.c:
>   Likewise.
>   *
> gcc.target/arm/mve/intrinsics/mve_vstore_scatter_shifted_offset_p.c:
>   Likewise.
> 
> 
> ### Attachment also inlined for ease of reply
> ###
> 
> 
> diff --git a/gcc/config/arm/mve.md b/gcc/config/arm/mve.md
> index
> 986fbfe2abae5f1e91e65f1ff5c84709c43c4617..3a57901bd5bcd770832d59dc7
> 7cd92b6d9b5ecb4 100644
> --- a/gcc/config/arm/mve.md
> +++ b/gcc/config/arm/mve.md
> 

[PATCH] Add new/delete to struct occurence

2020-06-04 Thread Richard Biener


I'm testing the following patch from Jonathan (I asked for an
example how to retrofit an alloc-pool user to new/delete style
operation).  It also introduces NSDMI for member init.

Bootstrap / regtest ongoing on x86_64-unknown-linux-gnu with
a GCC 4.8.5 host compiler (just to make sure...)

I'll be doing the same to vectorizer SLP nodes if it works out.

Richard.

--

This adds an example how to use new/delete operators to pool
allocated objects.

2020-06-04  Jonathan Wakely  

* alloc-pool.h (object_allocator::remove_raw): New.
* tree-ssa-math-opts.c (struct occurrence): Use NSMDI.
(occurrence::occurrence): Add.
(occurrence::~occurrence): Likewise.
(occurrence::new): Likewise.
(occurrence::delete): Likewise.
(occ_new): Remove.
(insert_bb): Use new occurence (...) instead of occ_new.
(register_division_in): Likewise.
(free_bb): Use delete occ instead of manually removing
from the pool.
---
 gcc/alloc-pool.h |  6 
 gcc/tree-ssa-math-opts.c | 65 
 2 files changed, 45 insertions(+), 26 deletions(-)

diff --git a/gcc/alloc-pool.h b/gcc/alloc-pool.h
index fd7194bfea4..4e78dcf6178 100644
--- a/gcc/alloc-pool.h
+++ b/gcc/alloc-pool.h
@@ -524,6 +524,12 @@ public:
 m_allocator.remove (object);
   }
 
+  inline void
+  remove_raw (void *object)
+  {
+m_allocator.remove (object);
+  }
+
   inline size_t
   num_elts_current ()
   {
diff --git a/gcc/tree-ssa-math-opts.c b/gcc/tree-ssa-math-opts.c
index 5fbaa24142e..237eb641589 100644
--- a/gcc/tree-ssa-math-opts.c
+++ b/gcc/tree-ssa-math-opts.c
@@ -121,37 +121,57 @@ along with GCC; see the file COPYING3.  If not see
division.  */
 struct occurrence {
   /* The basic block represented by this structure.  */
-  basic_block bb;
+  basic_block bb = basic_block();
 
   /* If non-NULL, the SSA_NAME holding the definition for a reciprocal
  inserted in BB.  */
-  tree recip_def;
+  tree recip_def = tree();
 
   /* If non-NULL, the SSA_NAME holding the definition for a squared
  reciprocal inserted in BB.  */
-  tree square_recip_def;
+  tree square_recip_def = tree();
 
   /* If non-NULL, the GIMPLE_ASSIGN for a reciprocal computation that
  was inserted in BB.  */
-  gimple *recip_def_stmt;
+  gimple *recip_def_stmt = nullptr;
 
   /* Pointer to a list of "struct occurrence"s for blocks dominated
  by BB.  */
-  struct occurrence *children;
+  struct occurrence *children = nullptr;
 
   /* Pointer to the next "struct occurrence"s in the list of blocks
  sharing a common dominator.  */
-  struct occurrence *next;
+  struct occurrence *next = nullptr;
 
   /* The number of divisions that are in BB before compute_merit.  The
  number of divisions that are in BB or post-dominate it after
  compute_merit.  */
-  int num_divisions;
+  int num_divisions = 0;
 
   /* True if the basic block has a division, false if it is a common
  dominator for basic blocks that do.  If it is false and trapping
  math is active, BB is not a candidate for inserting a reciprocal.  */
-  bool bb_has_division;
+  bool bb_has_division = false;
+
+  /* Construct a struct occurrence for basic block BB, and whose
+ children list is headed by CHILDREN.  */
+  occurrence (basic_block bb, struct occurrence *children)
+  : bb (bb), children (children)
+  {
+bb->aux = this;
+  }
+
+  /* Destroy a struct occurrence and remove it from its basic block.  */
+  ~occurrence ()
+  {
+bb->aux = nullptr;
+  }
+
+  /* Allocate memory for a struct occurrence from OCC_POOL.  */
+  static void* operator new (size_t);
+
+  /* Return memory for a struct occurrence to OCC_POOL.  */
+  static void operator delete (void*, size_t);
 };
 
 static struct
@@ -191,23 +211,17 @@ static struct occurrence *occ_head;
 /* Allocation pool for getting instances of "struct occurrence".  */
 static object_allocator *occ_pool;
 
-
-
-/* Allocate and return a new struct occurrence for basic block BB, and
-   whose children list is headed by CHILDREN.  */
-static struct occurrence *
-occ_new (basic_block bb, struct occurrence *children)
+void* occurrence::operator new (size_t n)
 {
-  struct occurrence *occ;
-
-  bb->aux = occ = occ_pool->allocate ();
-  memset (occ, 0, sizeof (struct occurrence));
-
-  occ->bb = bb;
-  occ->children = children;
-  return occ;
+  gcc_assert (n == sizeof(occurrence));
+  return occ_pool->allocate_raw ();
 }
 
+void occurrence::operator delete (void *occ, size_t n)
+{
+  gcc_assert (n == sizeof(occurrence));
+  occ_pool->remove_raw (occ);
+}
 
 /* Insert NEW_OCC into our subset of the dominator tree.  P_HEAD points to a
list of "struct occurrence"s, one per basic block, having IDOM as
@@ -259,7 +273,7 @@ insert_bb (struct occurrence *new_occ, basic_block idom,
  /* None of the previous blocks has DOM as a dominator: if we tail
 recursed, we would reexamine them uselessly. Just switch BB with

RE: [PATCH][GCC] arm: Fix the MVE ACLE vbicq intrinsics.

2020-06-04 Thread Kyrylo Tkachov
Hi Srinath,

> -Original Message-
> From: Srinath Parvathaneni 
> Sent: 28 May 2020 12:08
> To: gcc-patches@gcc.gnu.org
> Cc: Kyrylo Tkachov 
> Subject: [PATCH][GCC] arm: Fix the MVE ACLE vbicq intrinsics.
> 
> Hello,
> 
> Following MVE intrinsic testcases are failing in GCC testsuite.
> 
> Directory: gcc.target/arm/mve/intrinsics/
> Testcases: vbicq_f16.c, vbicq_f32.c, vbicq_s16.c, vbicq_s32.c, vbicq_s8.c
> ,vbicq_u16.c, vbicq_u32.c and vbicq_u8.c.
> 
> This patch fixes the vbicq intrinsics by modifying the intrinsic parameters
> and polymorphic variants in "arm_mve.h" header file.
> 
> Please refer to M-profile Vector Extension (MVE) intrinsics [1]for more
> details.
> [1] https://developer.arm.com/architectures/instruction-sets/simd-
> isas/helium/mve-intrinsics
> 
> Regression tested on arm-none-eabi and found no regressions.
> 
> Ok for master and gcc-10 branch?

Ok.
Thanks,
Kyrill

> 
> Thanks,
> Srinath.
> 
> gcc/ChangeLog:
> 
> 2020-05-20  Srinath Parvathaneni  
> 
> * config/arm/arm_mve.h (__arm_vbicq_n_u16): Correct the intrinsic
> arguments.
> (__arm_vbicq_n_s16): Likewise.
> (__arm_vbicq_n_u32): Likewise.
> (__arm_vbicq_n_s32): Likewise.
> (__arm_vbicq): Modify polymorphic variant.
> 
> gcc/testsuite/ChangeLog:
> 
> 2020-05-20  Srinath Parvathaneni  
> 
> * gcc.target/arm/mve/intrinsics/vbicq_f16.c: Modify.
> * gcc.target/arm/mve/intrinsics/vbicq_f32.c: Likewise.
> * gcc.target/arm/mve/intrinsics/vbicq_n_s16.c: Likewise.
> * gcc.target/arm/mve/intrinsics/vbicq_n_s32.c: Likewise.
> * gcc.target/arm/mve/intrinsics/vbicq_n_u16.c: Likewise.
> * gcc.target/arm/mve/intrinsics/vbicq_n_u32.c: Likewise.
> * gcc.target/arm/mve/intrinsics/vbicq_s16.c: Likewise.
> * gcc.target/arm/mve/intrinsics/vbicq_s32.c: Likewise.
> * gcc.target/arm/mve/intrinsics/vbicq_s8.c: Likewise.
> * gcc.target/arm/mve/intrinsics/vbicq_u16.c: Likewise.
> * gcc.target/arm/mve/intrinsics/vbicq_u32.c: Likewise.
> * gcc.target/arm/mve/intrinsics/vbicq_u8.c: Likewise.
> 
> 
> ### Attachment also inlined for ease of reply
> ###
> 
> 
> diff --git a/gcc/config/arm/arm_mve.h b/gcc/config/arm/arm_mve.h
> index
> 1002512a98f9364403f66eba0e320fe5070bdc3a..9bc5c97db8fea15d8140d966
> bc501b8a457a1abf 100644
> --- a/gcc/config/arm/arm_mve.h
> +++ b/gcc/config/arm/arm_mve.h
> @@ -6361,7 +6361,7 @@ __arm_vorrq_n_u16 (uint16x8_t __a, const int
> __imm)
> 
>  __extension__ extern __inline uint16x8_t
>  __attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
> -__arm_vbicq_n_u16 (uint16x8_t __a, const uint16_t __imm)
> +__arm_vbicq_n_u16 (uint16x8_t __a, const int __imm)
>  {
>return __builtin_mve_vbicq_n_uv8hi (__a, __imm);
>  }
> @@ -6473,7 +6473,7 @@ __arm_vorrq_n_s16 (int16x8_t __a, const int
> __imm)
> 
>  __extension__ extern __inline int16x8_t
>  __attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
> -__arm_vbicq_n_s16 (int16x8_t __a, const int16_t __imm)
> +__arm_vbicq_n_s16 (int16x8_t __a, const int __imm)
>  {
>return __builtin_mve_vbicq_n_sv8hi (__a, __imm);
>  }
> @@ -6564,7 +6564,7 @@ __arm_vorrq_n_u32 (uint32x4_t __a, const int
> __imm)
> 
>  __extension__ extern __inline uint32x4_t
>  __attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
> -__arm_vbicq_n_u32 (uint32x4_t __a, const uint32_t __imm)
> +__arm_vbicq_n_u32 (uint32x4_t __a, const int __imm)
>  {
>return __builtin_mve_vbicq_n_uv4si (__a, __imm);
>  }
> @@ -6676,7 +6676,7 @@ __arm_vorrq_n_s32 (int32x4_t __a, const int
> __imm)
> 
>  __extension__ extern __inline int32x4_t
>  __attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
> -__arm_vbicq_n_s32 (int32x4_t __a, const int32_t __imm)
> +__arm_vbicq_n_s32 (int32x4_t __a, const int __imm)
>  {
>return __builtin_mve_vbicq_n_sv4si (__a, __imm);
>  }
> @@ -23182,7 +23182,7 @@ __arm_vorrq (uint16x8_t __a, const int __imm)
> 
>  __extension__ extern __inline uint16x8_t
>  __attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
> -__arm_vbicq (uint16x8_t __a, const uint16_t __imm)
> +__arm_vbicq (uint16x8_t __a, const int __imm)
>  {
>   return __arm_vbicq_n_u16 (__a, __imm);
>  }
> @@ -23294,7 +23294,7 @@ __arm_vorrq (int16x8_t __a, const int __imm)
> 
>  __extension__ extern __inline int16x8_t
>  __attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
> -__arm_vbicq (int16x8_t __a, const int16_t __imm)
> +__arm_vbicq (int16x8_t __a, const int __imm)
>  {
>   return __arm_vbicq_n_s16 (__a, __imm);
>  }
> @@ -23385,7 +23385,7 @@ __arm_vorrq (uint32x4_t __a, const int __imm)
> 
>  __extension__ extern __inline uint32x4_t
>  __attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
> -__arm_vbicq (uint32x4_t __a, const uint32_t __imm)
> +__arm_vbicq (uint32x4_t __a, const int __imm)
>  {
>   return __arm_vbicq_n_u32 (__a, __imm);
>  }
> @@ -23497,7 

Re: [PATCH] Fix component mappings with derived types for OpenACC

2020-06-04 Thread Julian Brown
On Tue, 19 May 2020 14:23:34 +0200
Thomas Schwinge  wrote:

> Hi!
> 
> On 2020-01-28T13:41:00+, Julian Brown 
> wrote:
> > On Fri, 24 Jan 2020 10:58:49 +0100
> > Tobias Burnus  wrote:  
> >> the gfortran part is rather obvious and it and the test case look
> >> fine to me → OK.
> >> The oacc-mem.c also looks okay, but I assume Thomas needs to 
> >> rubber-stamp it.  
> >
> > I understand that Thomas is unavailable for the time being, so
> > won't be able to use his rubber-stamp powers. I added the offending
> > libgomp code to start with though, so I think I can go ahead and
> > commit the patch. I'll hold off for 24 hours though in case there
> > are any objections (Jakub?).  
> 
> So, in the end you didn't commit this, and now we've got the
> "un-fixed" OpenACC/Fortran code generation in the GCC 10.1 release,
> so have to deal with it in one way or another going forward,
> regarding libgomp ABI compatibility.  (Ideally), we need to make sure
> that "un-fixed" GCC 10.1-built executables continue to work "as good
> as before" when dynamically linked/running against "fixed" GCC 10.1+
> shared libraries.
> 
> Do we get such desired behavior by the patch quoted below?  In
> particular: removing the 'GOMP_MAP_STRUCT' handling code, but leaving
> in the empty 'case GOMP_MAP_STRUCT:' as a no-op, so that we don't run
> into 'default:' case 'goacc_exit_data_internal UNHANDLED kind'?  Is
> that sufficient?
> 
> Is my understanding correct that "fixed" GCC won't generate such
> 'GOMP_MAP_STRUCT' anymore (I have't studied in detail), and this empty
> 'case GOMP_MAP_STRUCT:' only remains in here for backwards
> compatibility? In this case, please add a comment to the code,
> stating this.  Otherwise, please add a comment why "do nothing" is
> appropriate for 'GOMP_MAP_STRUCT'.  In particular, for both
> scenarios, why we don't need to skip the following 'sizes[i]'
> mappings?

I'm not sure if I got the threading right, but I've now followed up on
this discussion here:

  https://gcc.gnu.org/pipermail/gcc-patches/2020-June/547300.html

Thanks,

Julian


Re: std::optional defaut constructor

2020-06-04 Thread Jonathan Wakely via Gcc-patches

On 04/06/20 00:50 +0200, Marc Glisse wrote:

(I don't currently have a setup that would enable me to commit anything. I'll
try to fix it eventually, but likely not so soon)


Ah, I missed this bit. I'll take care of it for you.

If it's due to the Git conversion let me know if it's something I can
help with off-list.



diff --git a/libstdc++-v3/include/std/optional 
b/libstdc++-v3/include/std/optional
index 37c2ba7a025..e84ba28a806 100644
--- a/libstdc++-v3/include/std/optional
+++ b/libstdc++-v3/include/std/optional
@@ -688,7 +688,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
public:
  using value_type = _Tp;

-  constexpr optional() = default;
+  constexpr optional() noexcept { }

  constexpr optional(nullopt_t) noexcept { }





Re: std::optional defaut constructor

2020-06-04 Thread Jonathan Wakely via Gcc-patches

On 04/06/20 10:34 +0300, Ville Voutilainen via Libstdc++ wrote:

On Thu, 4 Jun 2020 at 10:22, Marc Glisse  wrote:


> So the change is correct. Can we test the change somehow?

It passes the testsuite, and libc++ has been doing it this way for years.
What I feared was some regression where it would yield worse code in some
cases, or lose some property (not guaranteed by the standard) like
triviality (to the point of affecting the ABI?), but I couldn't see
anything like that happening.

(we still have PR86173 causing unnecessary memset in some cases)


Right, I was just wondering whether we can reasonably verify in a test
that the whole
shebang is not zeroed. That may need a tree-dump scan in the test, and probably
should go into PR86173 anyway, so I'm not saying such a thing needs to be a part
of this fix.

I'm kindly suggesting to Jonathan that this should be OK, and backports too.


Yes, looks good to me. Thanks, Marc. OK for master and gcc-10.

I could be persuaded that it should go on gcc-9 too, if anybody feels
strongly. Let's not change this in gcc-8 though, it's not required for
correctness and isn't a codegen regression, and if it does cause a
problem we won't get a chance to fix it after the next gcc-8 release.




[PATCH 2/3] Strip GOMP_MAP_STRUCT from OpenACC exit data mappings

2020-06-04 Thread Julian Brown
As flagged by Thomas, the GOMP_MAP_STRUCT mapping is not itself necessary
for OpenACC "exit data" directives, and is skipped over (now) in libgomp.
We might as well not emit it to start with, in line with the equivalent
OpenMP directive. We can keep the "no-op" handling in libgomp for the
reason of backward compatibility.

I've added a new scan test for the new behaviour. OK?

Julian

gcc/
* gimplify.c (gimplify_adjust_omp_clauses): Remove GOMP_MAP_STRUCT
mapping from OpenACC exit data directives.
---
 gcc/gimplify.c|  3 +-
 .../goacc/struct-enter-exit-data-1.c  | 35 +++
 2 files changed, 37 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/c-c++-common/goacc/struct-enter-exit-data-1.c

diff --git a/gcc/gimplify.c b/gcc/gimplify.c
index cb08b26dc65..e14932fafaf 100644
--- a/gcc/gimplify.c
+++ b/gcc/gimplify.c
@@ -10396,7 +10396,8 @@ gimplify_adjust_omp_clauses (gimple_seq *pre_p, 
gimple_seq body, tree *list_p,
}
}
  else if (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_STRUCT
-  && code == OMP_TARGET_EXIT_DATA)
+  && (code == OMP_TARGET_EXIT_DATA
+  || code == OACC_EXIT_DATA))
remove = true;
  else if (DECL_SIZE (decl)
   && TREE_CODE (DECL_SIZE (decl)) != INTEGER_CST
diff --git a/gcc/testsuite/c-c++-common/goacc/struct-enter-exit-data-1.c 
b/gcc/testsuite/c-c++-common/goacc/struct-enter-exit-data-1.c
new file mode 100644
index 000..4be5674b23e
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/goacc/struct-enter-exit-data-1.c
@@ -0,0 +1,35 @@
+/* Check that extraneous GOMP_MAP_STRUCTs are removed from OpenACC exit data
+   directives.  */
+
+/* { dg-additional-options "-fdump-tree-omplower" } */
+
+#include 
+
+struct str {
+  int a;
+  int *b;
+  int *c;
+  int d;
+};
+
+#define N 1024
+
+int
+main (int argc, char *argv[])
+{
+  struct str s;
+
+  s.b = (int *) malloc (sizeof (int) * N);
+  s.c = (int *) malloc (sizeof (int) * N);
+
+  #pragma acc enter data copyin(s.a, s.b[0:N], s.c[0:N], s.d)
+  /* { dg-final { scan-tree-dump {(?n)#pragma omp target oacc_enter_exit_data 
map\(struct:s \[len: 4\]\) map\(to:s.a \[len: [0-9]+\]\) map\(alloc:s.b \[len: 
[0-9]+\]\) map\(alloc:s.c \[len: [0-9]+\]\) map\(to:s.d \[len: [0-9]+\]\) 
map\(to:\*[_0-9]+ \[len: [0-9]+\]\) map\(attach:s.b \[bias: 0\]\) 
map\(to:\*[_0-9]+ \[len: [0-9]+\]\) map\(attach:s.c \[bias: 0\]\)} omplower } } 
*/
+
+  #pragma acc exit data copyout(s.a, s.b[0:N], s.c[0:N], s.d)
+  /* { dg-final { scan-tree-dump {(?n)#pragma omp target oacc_enter_exit_data 
map\(from:s.a \[len: [0-9]+\]\) map\(release:s.b \[len: [0-9]+\]\) 
map\(release:s.c \[len: [0-9]+\]\) map\(from:s.d \[len: [0-9]+\]\) 
map\(from:\*[_0-9]+ \[len: [0-9]+\]\) map\(detach:s.b \[bias: 0\]\) 
map\(from:\*[_0-9]+ \[len: [0-9]+\]\) map\(detach:s.c \[bias: 0\]\)} omplower } 
} */
+
+  free (s.b);
+  free (s.c);
+
+  return 0;
+}
-- 
2.23.0



[PATCH 0/3] OpenACC "exit data" copyout, and Fortran derived-type members

2020-06-04 Thread Julian Brown
This is a split version of the patch previously posted here:

  https://gcc.gnu.org/legacy-ml/gcc-patches/2020-01/msg00512.html

There were actually a couple of different issues addressed by that patch,
and Thomas raised another (or so).  This separated-out version should
be more-obviously safe (in terms of maintaining backwards compatibility,
where that makes sense).  Further commentary on individual patches.

Tested (as a series) with offloading to NVPTX. OK?

Julian

Julian Brown (3):
  OpenACC "exit data" copyout for struct members
  Strip GOMP_MAP_STRUCT from OpenACC exit data mappings
  Fortran derived-type mapping fix

 gcc/fortran/trans-openmp.c|  4 +-
 gcc/gimplify.c|  3 +-
 .../goacc/struct-enter-exit-data-1.c  | 35 +++
 .../gfortran.dg/goacc/mapping-tests-3.f90 | 15 +++
 .../gfortran.dg/goacc/mapping-tests-4.f90 | 17 +++
 libgomp/oacc-mem.c| 32 --
 .../struct-copyout-1.c| 38 
 .../struct-copyout-2.c| 44 +++
 8 files changed, 153 insertions(+), 35 deletions(-)
 create mode 100644 gcc/testsuite/c-c++-common/goacc/struct-enter-exit-data-1.c
 create mode 100644 gcc/testsuite/gfortran.dg/goacc/mapping-tests-3.f90
 create mode 100644 gcc/testsuite/gfortran.dg/goacc/mapping-tests-4.f90
 create mode 100644 
libgomp/testsuite/libgomp.oacc-c-c++-common/struct-copyout-1.c
 create mode 100644 
libgomp/testsuite/libgomp.oacc-c-c++-common/struct-copyout-2.c

-- 
2.23.0



[PATCH 1/3] OpenACC "exit data" copyout for struct members

2020-06-04 Thread Julian Brown
This patch removes unnecessary special-case code in oacc-mem.c
which prevented copy-back of structure members on OpenACC "exit data"
directives.  I've added a couple of new testcases to verify the behaviour
(which fail without the patch).

(On editing this mail, I notice I omitted to add a comment about
GOMP_MAP_STRUCT being a no-op, and/or no longer emitted for OpenACC
exit data with the patch later in this series.  I'll add such a comment
before commit.)

OK?

Thanks,

Julian

libgomp/
* oacc-mem.c (goacc_exit_data_internal): Remove special-case
(no-copyback) handling for GOMP_MAP_STRUCT.
* testsuite/libgomp.oacc-c-c++-common/struct-copyout-1.c: New test.
* testsuite/libgomp.oacc-c-c++-common/struct-copyout-2.c: New test.
---
 libgomp/oacc-mem.c| 32 --
 .../struct-copyout-1.c| 38 
 .../struct-copyout-2.c| 44 +++
 3 files changed, 82 insertions(+), 32 deletions(-)
 create mode 100644 
libgomp/testsuite/libgomp.oacc-c-c++-common/struct-copyout-1.c
 create mode 100644 
libgomp/testsuite/libgomp.oacc-c-c++-common/struct-copyout-2.c

diff --git a/libgomp/oacc-mem.c b/libgomp/oacc-mem.c
index 2d4bba78efd..232683a85f0 100644
--- a/libgomp/oacc-mem.c
+++ b/libgomp/oacc-mem.c
@@ -1136,38 +1136,6 @@ goacc_exit_data_internal (struct gomp_device_descr 
*acc_dev, size_t mapnum,
  break;
 
case GOMP_MAP_STRUCT:
- {
-   int elems = sizes[i];
-   for (int j = 1; j <= elems; j++)
- {
-   struct splay_tree_key_s k;
-   k.host_start = (uintptr_t) hostaddrs[i + j];
-   k.host_end = k.host_start + sizes[i + j];
-   splay_tree_key str;
-   str = splay_tree_lookup (_dev->mem_map, );
-   if (str)
- {
-   if (finalize)
- {
-   if (str->refcount != REFCOUNT_INFINITY)
- str->refcount -= str->virtual_refcount;
-   str->virtual_refcount = 0;
- }
-   if (str->virtual_refcount > 0)
- {
-   if (str->refcount != REFCOUNT_INFINITY)
- str->refcount--;
-   str->virtual_refcount--;
- }
-   else if (str->refcount > 0
-&& str->refcount != REFCOUNT_INFINITY)
- str->refcount--;
-   if (str->refcount == 0)
- gomp_remove_var_async (acc_dev, str, aq);
- }
- }
-   i += elems;
- }
  break;
 
default:
diff --git a/libgomp/testsuite/libgomp.oacc-c-c++-common/struct-copyout-1.c 
b/libgomp/testsuite/libgomp.oacc-c-c++-common/struct-copyout-1.c
new file mode 100644
index 000..b86f1c921a9
--- /dev/null
+++ b/libgomp/testsuite/libgomp.oacc-c-c++-common/struct-copyout-1.c
@@ -0,0 +1,38 @@
+#include 
+
+struct str1 {
+  int a;
+  int b;
+};
+
+struct str2 {
+  int c;
+  int d;
+  struct str1 s;
+};
+
+int
+main (int argc, char *argv[])
+{
+  struct str2 t;
+
+  t.c = 1;
+  t.d = 2;
+  t.s.a = 3;
+  t.s.b = 4;
+
+  #pragma acc enter data copyin(t.s)
+
+  #pragma acc serial present(t.s) /* { dg-warning "using vector_length 
\\(32\\), ignoring 1" "" { target openacc_nvidia_accel_selected } } */
+  {
+t.s.a = 5;
+t.s.b = 6;
+  }
+
+  #pragma acc exit data copyout(t.s)
+
+  assert (t.s.a == 5);
+  assert (t.s.b == 6);
+
+  return 0;
+}
diff --git a/libgomp/testsuite/libgomp.oacc-c-c++-common/struct-copyout-2.c 
b/libgomp/testsuite/libgomp.oacc-c-c++-common/struct-copyout-2.c
new file mode 100644
index 000..4dd8a3a7e17
--- /dev/null
+++ b/libgomp/testsuite/libgomp.oacc-c-c++-common/struct-copyout-2.c
@@ -0,0 +1,44 @@
+#include 
+#include 
+
+struct str1 {
+  int a;
+  int b;
+  int *c;
+};
+
+#define N 1024
+
+int
+main (int argc, char *argv[])
+{
+  struct str1 s;
+
+  s.a = 1;
+  s.b = 2;
+  s.c = (int *) malloc (sizeof (int) * N);
+
+  for (int i = 0; i < N; i++)
+s.c[i] = i + 10;
+
+  #pragma acc enter data copyin(s.a, s.b, s.c[0:N])
+
+  #pragma acc serial present(s.a, s.b, s.c[0:N]) /* { dg-warning "using 
vector_length \\(32\\), ignoring 1" "" { target openacc_nvidia_accel_selected } 
} */
+  {
+s.a = 3;
+s.b = 4;
+for (int i = 0; i < N; i++)
+  s.c[i] = i + 20;
+  }
+
+  #pragma acc exit data copyout(s.a, s.b, s.c[0:N])
+
+  assert (s.a == 3);
+  assert (s.b == 4);
+  for (int i = 0; i < N; i++)
+assert (s.c[i] == i + 20);
+
+  free (s.c);
+
+  return 0;
+}
-- 
2.23.0



[PATCH 3/3] Fortran derived-type mapping fix

2020-06-04 Thread Julian Brown
This patch provides the same fix for Fortran derived type component
mappings with derived types as the patch posted previously:

  https://gcc.gnu.org/legacy-ml/gcc-patches/2020-01/msg00512.html

IIUC this part was previously approved by Tobias.  OK?

Julian

gcc/fortran/
* trans-openmp.c (gfc_trans_omp_clauses): Use 'inner' not 'decl' for
derived type members which themselves have derived types.

gcc/testsuite/
* gfortran.dg/goacc/mapping-tests-3.f90: New test.
* gfortran.dg/goacc/mapping-tests-4.f90: New test.
---
 gcc/fortran/trans-openmp.c  |  4 ++--
 .../gfortran.dg/goacc/mapping-tests-3.f90   | 15 +++
 .../gfortran.dg/goacc/mapping-tests-4.f90   | 17 +
 3 files changed, 34 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/gfortran.dg/goacc/mapping-tests-3.f90
 create mode 100644 gcc/testsuite/gfortran.dg/goacc/mapping-tests-4.f90

diff --git a/gcc/fortran/trans-openmp.c b/gcc/fortran/trans-openmp.c
index 7e2f6256c43..02c40fdc660 100644
--- a/gcc/fortran/trans-openmp.c
+++ b/gcc/fortran/trans-openmp.c
@@ -2774,9 +2774,9 @@ gfc_trans_omp_clauses (stmtblock_t *block, 
gfc_omp_clauses *clauses,
}
  else
{
- OMP_CLAUSE_DECL (node) = decl;
+ OMP_CLAUSE_DECL (node) = inner;
  OMP_CLAUSE_SIZE (node)
-   = TYPE_SIZE_UNIT (TREE_TYPE (decl));
+   = TYPE_SIZE_UNIT (TREE_TYPE (inner));
}
}
  else if (lastcomp->next
diff --git a/gcc/testsuite/gfortran.dg/goacc/mapping-tests-3.f90 
b/gcc/testsuite/gfortran.dg/goacc/mapping-tests-3.f90
new file mode 100644
index 000..312f596461e
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/goacc/mapping-tests-3.f90
@@ -0,0 +1,15 @@
+! { dg-options "-fopenacc -fdump-tree-omplower" }
+
+subroutine foo
+  type one
+integer i, j
+  end type
+  type two
+type(one) A, B
+  end type
+
+  type(two) x
+
+  !$acc enter data copyin(x%A)
+! { dg-final { scan-tree-dump-times "omp target oacc_enter_exit_data 
map\\(struct:x \\\[len: 1\\\]\\) map\\(to:x.a \\\[len: \[0-9\]+\\\]\\)" 1 
"omplower" } }
+end
diff --git a/gcc/testsuite/gfortran.dg/goacc/mapping-tests-4.f90 
b/gcc/testsuite/gfortran.dg/goacc/mapping-tests-4.f90
new file mode 100644
index 000..6257af942df
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/goacc/mapping-tests-4.f90
@@ -0,0 +1,17 @@
+subroutine foo
+  type one
+integer i, j
+  end type
+  type two
+type(one) A, B
+  end type
+
+  type(two) x
+
+! This is accepted at present, although it represents a probably-unintentional
+! overlapping subcopy.
+  !$acc enter data copyin(x%A, x%A%i)
+! But this raises an error.
+  !$acc enter data copyin(x%A, x%A%i, x%A%i)
+! { dg-error ".x.a.i. appears more than once in map clauses" "" { target 
"*-*-*" } 15 }
+end
-- 
2.23.0



Re: std::optional defaut constructor

2020-06-04 Thread Jonathan Wakely via Gcc-patches

On 04/06/20 13:41 +0200, Richard Biener via Libstdc++ wrote:

On Thu, Jun 4, 2020 at 11:34 AM Ville Voutilainen via Gcc-patches
 wrote:


On Thu, 4 Jun 2020 at 11:53, Marc Glisse  wrote:
>
> On Thu, 4 Jun 2020, Ville Voutilainen wrote:
>
> > On Thu, 4 Jun 2020 at 11:00, Marc Glisse  wrote:
> >> Maybe create a buffer, fill it with some non-zero values (-1?), then call
> >> placement new, and read some value in the middle of the buffer, possibly
> >> with some protection against optimizations? Ah, no, actual constructors
> >> are fine, it is only the inlined initialization that happens with the
> >> defaulted constructor that zeroes things.
> >
> > The zero-init is part of value-initialization of a class type with a
> > defaulted default constructor, so value-initialization with placement
> > new should indeed show us whether the target buffer is zeroed.
>
> Ah, yes, I had forgotten the empty () at the end of the operator new line
> when testing. Now the patch makes this runtime test go from abort to
> success at -O0 (with optimizations, the memset is removed as dead code). I
> am still not sure we want this kind of test though. And I added launder
> more to quiet a warning than with confidence that it does the right thing.
>
> #include 
> struct A {
>int a[1024];
> };
> typedef std::optional O;
> int main(){
>unsigned char t[sizeof(O)];
>__builtin_memset(t, -1, sizeof(t));
>new(t)O();
>if(std::launder(t)[512] != (unsigned char)(-1)) __builtin_abort();
> }

Yeah, I think the patch is OK with or without the test. As a side
note, you don't need the launder
if the check uses the pointer value returned by placement-new.


Doesn't the placement new make the memory state of anything
not explicitely initialized indeterminate?  That is, isn't the
testcase broken anyways since GCC can elide the memset
when seeing the placement new?


Yes.

IIUC -fno-lifetime-dse means the constructor that the placement new
invokes doesn't clobber the old contents of the memory, but it seems
fragile to rely on that remaining true in the long term.



RE: [PATCH PR95254] aarch64: gcc generate inefficient code with fixed sve vector length

2020-06-04 Thread Yangfei (Felix)
Hi,

> -Original Message-
> From: Richard Sandiford [mailto:richard.sandif...@arm.com]
> Sent: Tuesday, June 2, 2020 7:17 PM
> To: Yangfei (Felix) 
> Cc: gcc-patches@gcc.gnu.org; Uros Bizjak ; Jakub
> Jelinek ; Hongtao Liu ; H.J. Lu
> 
> Subject: Re: [PATCH PR95254] aarch64: gcc generate inefficient code with
> fixed sve vector length
>

Snip...
 
> >
> >> FAIL: gcc.target/i386/avx512f-vcvtps2ph-2.c (test for excess errors)
> >> UNRESOLVED: gcc.target/i386/avx512f-vcvtps2ph-2.c compilation failed
> >> to produce executable
> > 154803c154803
> 
> Looks good.  (I know I said that last time too :-))  I've also tested it on 
> arm-
> linux-gnueabihf and powerpc64le-linux-gnu without problems.

Thanks for reviewing and testing the patch  :-)

> As before, I'll hold off applying until the AVX512 problem is fixed.

Looks like the AVX512 problem is fixed with:

https://gcc.gnu.org/git/gitweb.cgi?p=gcc.git;h=43088bb4dadd3d14b6b594c5f9363fe879f3d7f7
 

I'm using: $ runtest --tool gcc i386.exp=avx512f-vcvtps2ph-2.c

Thanks,
Felix


[committed] libstdc++: Make std::copy_n work with negative and non-integral sizes

2020-06-04 Thread Jonathan Wakely via Gcc-patches
Since it was added in C++11, std::copy_n and std::ranges::copy_n should
do nothing given a negative size, but for random access iterators we add
the size to the iterator, possibly resulting in undefined behaviour.

Also, C++20 clarified that std::copy_n requires the Size type to be
convertible to an integral type. We previously assumed that it could be
directly used in arithmetic expressions, without conversion to an
integral type.

This also fixes a bug in the random_access_iterator_wrapper helper adds
some convenience aliases for using the iterator wrappers.

libstdc++-v3/ChangeLog:

* include/bits/ranges_algobase.h (__copy_n_fn): Only call
ranges::copy for positive values.
* include/bits/stl_algo.h (copy_n): Convert Size argument to an
integral type and only call __copy_n for positive values.
* testsuite/util/testsuite_iterators.h
(random_access_iterator_wrapper::operator+=): Fix range check for
negative values.
(output_container, input_container, forward_container)
(bidirectional_container, random_access_container): New alias
templates.
* testsuite/25_algorithms/copy_n/5.cc: New test.

Tested powerpc64le-linux, committed to master.

I think this should be backported too. The ranges::copy_n fix should
go on gcc-10 branch, and the std::copy_n part fixes a C++11 bug that
has been there since we added that algo.


commit e1008cd1d8504775e6a5e39325e396e61b39b84c
Author: Jonathan Wakely 
Date:   Thu Jun 4 13:52:21 2020 +0100

libstdc++: Make std::copy_n work with negative and non-integral sizes

Since it was added in C++11, std::copy_n and std::ranges::copy_n should
do nothing given a negative size, but for random access iterators we add
the size to the iterator, possibly resulting in undefined behaviour.

Also, C++20 clarified that std::copy_n requires the Size type to be
convertible to an integral type. We previously assumed that it could be
directly used in arithmetic expressions, without conversion to an
integral type.

This also fixes a bug in the random_access_iterator_wrapper helper adds
some convenience aliases for using the iterator wrappers.

libstdc++-v3/ChangeLog:

* include/bits/ranges_algobase.h (__copy_n_fn): Only call
ranges::copy for positive values.
* include/bits/stl_algo.h (copy_n): Convert Size argument to an
integral type and only call __copy_n for positive values.
* testsuite/util/testsuite_iterators.h
(random_access_iterator_wrapper::operator+=): Fix range check for
negative values.
(output_container, input_container, forward_container)
(bidirectional_container, random_access_container): New alias
templates.
* testsuite/25_algorithms/copy_n/5.cc: New test.

diff --git a/libstdc++-v3/include/bits/ranges_algobase.h 
b/libstdc++-v3/include/bits/ranges_algobase.h
index 80c9a774301..49ca5ed4155 100644
--- a/libstdc++-v3/include/bits/ranges_algobase.h
+++ b/libstdc++-v3/include/bits/ranges_algobase.h
@@ -492,13 +492,16 @@ namespace ranges
 _Out __result) const
   {
if constexpr (random_access_iterator<_Iter>)
- return ranges::copy(__first, __first + __n, std::move(__result));
+ {
+   if (__n > 0)
+ return ranges::copy(__first, __first + __n, std::move(__result));
+ }
else
  {
for (; __n > 0; --__n, (void)++__result, (void)++__first)
  *__result = *__first;
-   return {std::move(__first), std::move(__result)};
  }
+   return {std::move(__first), std::move(__result)};
   }
   };
 
diff --git a/libstdc++-v3/include/bits/stl_algo.h 
b/libstdc++-v3/include/bits/stl_algo.h
index 932ece55529..b743c87cb80 100644
--- a/libstdc++-v3/include/bits/stl_algo.h
+++ b/libstdc++-v3/include/bits/stl_algo.h
@@ -771,10 +771,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
   __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
typename iterator_traits<_InputIterator>::value_type>)
-  __glibcxx_requires_can_increment(__first, __n);
-  __glibcxx_requires_can_increment(__result, __n);
 
-  return std::__copy_n(__first, __n, __result,
+  const auto __n2 = std::__size_to_integer(__n);
+  if (__n2 <= 0)
+   return __result;
+
+  __glibcxx_requires_can_increment(__first, __n2);
+  __glibcxx_requires_can_increment(__result, __n2);
+
+  return std::__copy_n(__first, __n2, __result,
   std::__iterator_category(__first));
 }
 
diff --git a/libstdc++-v3/testsuite/25_algorithms/copy_n/5.cc 
b/libstdc++-v3/testsuite/25_algorithms/copy_n/5.cc
new file mode 100644
index 000..2ea8c9da0dd
--- /dev/null
+++ 

[PATCH 2/2] add vect_get_slp_vect_def

2020-06-04 Thread Richard Biener


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

Richard.


This adds vect_get_slp_vect_def to get at a SLP nodes vectorized def,
abstracting away the details.  It also fixes one stray failure to
use SLP_TREE_REPRESENTATIVE.

2020-05-04  Richard Biener  

* tree-vectorizer.h (vect_get_slp_vect_def): Declare.
* tree-vect-loop.c (vect_create_epilog_for_reduction): Use it.
* tree-vect-stmts.c (vect_transform_stmt): Likewise.
(vect_is_simple_use): Use SLP_TREE_REPRESENTATIVE.
* tree-vect-slp.c (vect_get_slp_vect_defs): Fold into single
use ...
(vect_get_slp_defs): ... here.
(vect_get_slp_vect_def): New function.
---
 gcc/tree-vect-loop.c  |  2 +-
 gcc/tree-vect-slp.c   | 27 +--
 gcc/tree-vect-stmts.c |  4 ++--
 gcc/tree-vectorizer.h |  1 +
 4 files changed, 17 insertions(+), 17 deletions(-)

diff --git a/gcc/tree-vect-loop.c b/gcc/tree-vect-loop.c
index e3fbf9fe28a..f2c52ae1909 100644
--- a/gcc/tree-vect-loop.c
+++ b/gcc/tree-vect-loop.c
@@ -4719,7 +4719,7 @@ vect_create_epilog_for_reduction (loop_vec_info 
loop_vinfo,
   for (unsigned i = 0; i < vec_num; i++)
 {
   if (slp_node)
-   def = gimple_get_lhs (SLP_TREE_VEC_STMTS (slp_node)[i]->stmt);
+   def = vect_get_slp_vect_def (slp_node, i);
   else
def = gimple_get_lhs (STMT_VINFO_VEC_STMT (rdef_info)->stmt);
   for (j = 0; j < ncopies; j++)
diff --git a/gcc/tree-vect-slp.c b/gcc/tree-vect-slp.c
index 65c49f5e143..1d26c312aa8 100644
--- a/gcc/tree-vect-slp.c
+++ b/gcc/tree-vect-slp.c
@@ -3660,23 +3660,17 @@ vect_create_constant_vectors (vec_info *vinfo, slp_tree 
op_node)
   SLP_TREE_VEC_DEFS (op_node).quick_push (vop);
 }
 
+/* Get the Ith vectorized definition from SLP_NODE.  */
 
-/* Get vectorized definitions from SLP_NODE that contains corresponding
-   vectorized def-stmts.  */
-
-static void
-vect_get_slp_vect_defs (slp_tree slp_node, vec *vec_oprnds)
+tree
+vect_get_slp_vect_def (slp_tree slp_node, unsigned i)
 {
-  stmt_vec_info vec_def_stmt_info;
-  unsigned int i;
-
-  gcc_assert (SLP_TREE_VEC_STMTS (slp_node).exists ());
-
-  FOR_EACH_VEC_ELT (SLP_TREE_VEC_STMTS (slp_node), i, vec_def_stmt_info)
-vec_oprnds->quick_push (gimple_get_lhs (vec_def_stmt_info->stmt));
+  if (SLP_TREE_VEC_STMTS (slp_node).exists ())
+return gimple_get_lhs (SLP_TREE_VEC_STMTS (slp_node)[i]->stmt);
+  else
+return SLP_TREE_VEC_DEFS (slp_node)[i];
 }
 
-
 /* Get N vectorized definitions for SLP_NODE.  */
 
 void
@@ -3696,7 +3690,12 @@ vect_get_slp_defs (vec_info *,
 node or we need to create them (for invariants and constants).  */
   vec_defs.create (SLP_TREE_NUMBER_OF_VEC_STMTS (child));
   if (SLP_TREE_DEF_TYPE (child) == vect_internal_def)
-   vect_get_slp_vect_defs (child, _defs);
+   {
+ unsigned j;
+ stmt_vec_info vec_def_stmt_info;
+ FOR_EACH_VEC_ELT (SLP_TREE_VEC_STMTS (child), j, vec_def_stmt_info)
+   vec_defs.quick_push (gimple_get_lhs (vec_def_stmt_info->stmt));
+   }
   else
vec_defs.splice (SLP_TREE_VEC_DEFS (child));
 
diff --git a/gcc/tree-vect-stmts.c b/gcc/tree-vect-stmts.c
index 4df1d90d5f3..c0be6ef502c 100644
--- a/gcc/tree-vect-stmts.c
+++ b/gcc/tree-vect-stmts.c
@@ -11385,7 +11385,7 @@ vect_transform_stmt (vec_info *vinfo,
  == SLP_TREE_VEC_STMTS (slp_node).length ());
  for (unsigned i = 0; i < SLP_TREE_VEC_STMTS (phi_node).length (); ++i)
add_phi_arg (as_a  (SLP_TREE_VEC_STMTS (phi_node)[i]->stmt),
-gimple_get_lhs (SLP_TREE_VEC_STMTS 
(slp_node)[i]->stmt),
+vect_get_slp_vect_def (slp_node, i),
 e, gimple_phi_arg_location (phi, e->dest_idx));
}
 }
@@ -11850,7 +11850,7 @@ vect_is_simple_use (vec_info *vinfo, stmt_vec_info 
stmt, slp_tree slp_node,
   slp_tree child = SLP_TREE_CHILDREN (slp_node)[operand];
   *slp_def = child;
   if (SLP_TREE_DEF_TYPE (child) == vect_internal_def)
-   *op = gimple_get_lhs (SLP_TREE_SCALAR_STMTS (child)[0]->stmt);
+   *op = gimple_get_lhs (SLP_TREE_REPRESENTATIVE (child)->stmt);
   else
{
  if (def_stmt_info_out)
diff --git a/gcc/tree-vectorizer.h b/gcc/tree-vectorizer.h
index 1396da74e9d..9bb82a546f6 100644
--- a/gcc/tree-vectorizer.h
+++ b/gcc/tree-vectorizer.h
@@ -1753,6 +1753,7 @@ extern void vect_get_vec_defs_for_stmt_copy (vec_info *,
 extern tree vect_init_vector (vec_info *, stmt_vec_info, tree, tree,
   gimple_stmt_iterator *);
 extern tree vect_get_vec_def_for_stmt_copy (vec_info *, tree);
+extern tree vect_get_slp_vect_def (slp_tree, unsigned);
 extern bool vect_transform_stmt (vec_info *, stmt_vec_info,
 gimple_stmt_iterator *,
 slp_tree, slp_instance);
-- 
2.26.1


[PATCH 1/2] Add explicit SLP_TREE_LANES

2020-06-04 Thread Richard Biener


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

Richard.


This adds an explicit number of scalar lanes to the SLP node
avoiding to dispatch between stmts/ops and eventually not require
those vectors at all.

2020-05-27  Richard Biener  

* tree-vectorizer.h (_slp_tree::lanes): New.
(SLP_TREE_LANES): Likewise.
---
 gcc/tree-vect-loop.c  | 13 ++---
 gcc/tree-vect-slp.c   | 14 --
 gcc/tree-vect-stmts.c |  8 ++--
 gcc/tree-vectorizer.h |  3 +++
 4 files changed, 19 insertions(+), 19 deletions(-)

diff --git a/gcc/tree-vect-loop.c b/gcc/tree-vect-loop.c
index ad26663595c..e3fbf9fe28a 100644
--- a/gcc/tree-vect-loop.c
+++ b/gcc/tree-vect-loop.c
@@ -4516,7 +4516,7 @@ vect_create_epilog_for_reduction (loop_vec_info 
loop_vinfo,
   tree induction_index = NULL_TREE;
 
   if (slp_node)
-group_size = SLP_TREE_SCALAR_STMTS (slp_node).length (); 
+group_size = SLP_TREE_LANES (slp_node);
 
   if (nested_in_vect_loop_p (loop, stmt_info))
 {
@@ -6594,7 +6594,7 @@ vectorizable_reduction (loop_vec_info loop_vinfo,
 which each SLP statement has its own initial value and in which
 that value needs to be repeated for every instance of the
 statement within the initial vector.  */
-  unsigned int group_size = SLP_TREE_SCALAR_STMTS (slp_node).length ();
+  unsigned int group_size = SLP_TREE_LANES (slp_node);
   if (!neutral_op
  && !can_duplicate_and_interleave_p (loop_vinfo, group_size,
  TREE_TYPE (vectype_out)))
@@ -7110,9 +7110,8 @@ vect_transform_cycle_phi (loop_vec_info loop_vinfo,
   if (slp_node)
 {
   /* The size vect_schedule_slp_instance computes is off for us.  */
-  vec_num = vect_get_num_vectors
- (LOOP_VINFO_VECT_FACTOR (loop_vinfo)
-  * SLP_TREE_SCALAR_STMTS (slp_node).length (), vectype_in);
+  vec_num = vect_get_num_vectors (LOOP_VINFO_VECT_FACTOR (loop_vinfo)
+ * SLP_TREE_LANES (slp_node), vectype_in);
   ncopies = 1;
 }
   else
@@ -7558,7 +7557,7 @@ vectorizable_induction (loop_vec_info loop_vinfo,
   new_vec, step_vectype, NULL);
 
   /* Now generate the IVs.  */
-  unsigned group_size = SLP_TREE_SCALAR_STMTS (slp_node).length ();
+  unsigned group_size = SLP_TREE_LANES (slp_node);
   unsigned nvects = SLP_TREE_NUMBER_OF_VEC_STMTS (slp_node);
   unsigned elts = const_nunits * nvects;
   /* Compute the number of distinct IVs we need.  First reduce
@@ -7999,7 +7998,7 @@ vectorizable_live_operation (loop_vec_info loop_vinfo,
 {
   gcc_assert (slp_index >= 0);
 
-  int num_scalar = SLP_TREE_SCALAR_STMTS (slp_node).length ();
+  int num_scalar = SLP_TREE_LANES (slp_node);
   int num_vec = SLP_TREE_NUMBER_OF_VEC_STMTS (slp_node);
 
   /* Get the last occurrence of the scalar index from the concatenation of
diff --git a/gcc/tree-vect-slp.c b/gcc/tree-vect-slp.c
index f8b12f0dae9..65c49f5e143 100644
--- a/gcc/tree-vect-slp.c
+++ b/gcc/tree-vect-slp.c
@@ -64,6 +64,7 @@ _slp_tree::_slp_tree ()
   SLP_TREE_REPRESENTATIVE (this) = NULL;
   this->refcnt = 1;
   this->max_nunits = 1;
+  this->lanes = 0;
 }
 
 /* Tear down a SLP node.  */
@@ -134,6 +135,7 @@ vect_create_new_slp_node (vec scalar_stmts, 
unsigned nops)
   SLP_TREE_CHILDREN (node).create (nops);
   SLP_TREE_DEF_TYPE (node) = vect_internal_def;
   SLP_TREE_REPRESENTATIVE (node) = scalar_stmts[0];
+  SLP_TREE_LANES (node) = scalar_stmts.length ();
 
   unsigned i;
   stmt_vec_info stmt_info;
@@ -151,6 +153,7 @@ vect_create_new_slp_node (vec ops)
   slp_tree node = new _slp_tree;
   SLP_TREE_SCALAR_OPS (node) = ops;
   SLP_TREE_DEF_TYPE (node) = vect_external_def;
+  SLP_TREE_LANES (node) = ops.length ();
   return node;
 }
 
@@ -1670,6 +1673,7 @@ slp_copy_subtree (slp_tree node, hash_map )
   SLP_TREE_DEF_TYPE (copy) = SLP_TREE_DEF_TYPE (node);
   SLP_TREE_VECTYPE (copy) = SLP_TREE_VECTYPE (node);
   SLP_TREE_REPRESENTATIVE (copy) = SLP_TREE_REPRESENTATIVE (node);
+  SLP_TREE_LANES (copy) = SLP_TREE_LANES (node);
   copy->max_nunits = node->max_nunits;
   copy->refcnt = 0;
   if (SLP_TREE_SCALAR_STMTS (node).exists ())
@@ -2377,8 +2381,7 @@ vect_optimize_slp (vec_info *vinfo)
 a gap either because the group is larger than the SLP
 group-size or because there is a gap between the groups.  */
  && (known_eq (LOOP_VINFO_VECT_FACTOR (as_a  
(vinfo)), 1U)
- || ((SLP_TREE_SCALAR_STMTS (node).length ()
-  == DR_GROUP_SIZE (first_stmt_info))
+ || ((SLP_TREE_LANES (node) == DR_GROUP_SIZE (first_stmt_info))
  && DR_GROUP_GAP (first_stmt_info) == 0)))
{
  SLP_TREE_LOAD_PERMUTATION (node).release ();
@@ -2612,7 +2615,7 @@ vect_slp_analyze_node_operations_1 (vec_info *vinfo, 
slp_tree node,
vf = 

Re: [EXT] Re: [PATCH] Optimize and+or+sub into xor+not (PR94882)

2020-06-04 Thread Richard Biener via Gcc-patches
On Thu, Jun 4, 2020 at 2:09 PM Marc Glisse  wrote:
>
> On Thu, 4 Jun 2020, Richard Biener via Gcc-patches wrote:
>
> > (if (!TYPE_OVERFLOW_SANITIZED (type) && !TYPE_OVERFLOW_TRAPS (type)
> > && !TYPE_SATURATING (type)
>
> Would the positive form
> TYPE_OVERFLOW_WRAPS (type) || TYPE_OVERFLOW_UNDEFINED (type)
> be roughly equivalent and shorter? Or am I missing some cases?

I think TYPE_OVERFLOW_SANITIZED isn't handled here, not sure
if we have saturating integer types (we have FIXED_POINT_TYPE ones).
At least TYPE_OVERFLOW_* do not check TYPE_SATURATING
but only (ANY-)INTEGER_TYPE-ness.

Richard.

> (I didn't look at the patch and if that's the right condition, just
> randomly commenting on this line)
>
> --
> Marc Glisse


[PATCH] Simplify SLP code wrt SLP_TREE_DEF_TYPE

2020-06-04 Thread Richard Biener


The following removes the ugly pushing of SLP_TREE_DEF_TYPE to
stmt_infos and instead makes sure to handle invariants fully
in vect_is_simple_use plus adjusting a few places I refrained
from touching when enforcing vector types for them.

It also simplifies building SLP nodes with all external operands
from scalars by not doing that in the parent but instead not
building those from the start.  That also gets rid of
vect_update_all_shared_vectypes.

Bootstrapped and tested on x86_64-unknown-linux-gnu.

Richard.

2020-06-04  Richard Biener  

* tree-vect-slp.c (vect_update_all_shared_vectypes): Remove.
(vect_build_slp_tree_2): Simplify building all external op
nodes from scalars.
(vect_slp_analyze_node_operations): Remove push/pop of
STMT_VINFO_DEF_TYPE.
(vect_schedule_slp_instance): Likewise.
* tree-vect-stmts.c (ect_check_store_rhs): Pass in the
stmt_info, use the vect_is_simple_use overload combining
SLP and stmt_info analysis.
(vect_is_simple_cond): Likewise.
(vectorizable_store): Adjust.
(vectorizable_condition): Likewise.
(vect_is_simple_use): Fully handle invariant SLP nodes
here.  Amend stmt_info operand extraction with COND_EXPR
and masked stores.
* tree-vect-loop.c (vectorizable_reduction): Deal with
COND_EXPR representation ugliness.
---
 gcc/tree-vect-loop.c  |   8 +-
 gcc/tree-vect-slp.c   | 203 +++---
 gcc/tree-vect-stmts.c |  72 ++-
 3 files changed, 89 insertions(+), 194 deletions(-)

diff --git a/gcc/tree-vect-loop.c b/gcc/tree-vect-loop.c
index 3c5c0ea9ebc..ad26663595c 100644
--- a/gcc/tree-vect-loop.c
+++ b/gcc/tree-vect-loop.c
@@ -6197,6 +6197,12 @@ vectorizable_reduction (loop_vec_info loop_vinfo,
   gcc_assert (SLP_TREE_REPRESENTATIVE (slp_for_stmt_info) == stmt_info);
 }
   slp_tree *slp_op = XALLOCAVEC (slp_tree, op_type);
+  /* We need to skip an extra operand for COND_EXPRs with embedded
+ comparison.  */
+  unsigned opno_adjust = 0;
+  if (code == COND_EXPR
+  && COMPARISON_CLASS_P (gimple_assign_rhs1 (stmt)))
+opno_adjust = 1;
   for (i = 0; i < op_type; i++)
 {
   /* The condition of COND_EXPR is checked in vectorizable_condition().  */
@@ -6207,7 +6213,7 @@ vectorizable_reduction (loop_vec_info loop_vinfo,
   enum vect_def_type dt;
   tree op;
   if (!vect_is_simple_use (loop_vinfo, stmt_info, slp_for_stmt_info,
-  i, , _op[i], , ,
+  i + opno_adjust, , _op[i], , ,
   _stmt_info))
{
  if (dump_enabled_p ())
diff --git a/gcc/tree-vect-slp.c b/gcc/tree-vect-slp.c
index cc33b64454c..f8b12f0dae9 100644
--- a/gcc/tree-vect-slp.c
+++ b/gcc/tree-vect-slp.c
@@ -616,26 +616,6 @@ vect_update_shared_vectype (stmt_vec_info stmt_info, tree 
vectype)
   return false;
 }
 
-/* Try to infer and assign a vector type to all the statements in STMTS.
-   Used only for BB vectorization.  */
-
-static bool
-vect_update_all_shared_vectypes (vec_info *vinfo, vec stmts)
-{
-  tree vectype, nunits_vectype;
-  if (!vect_get_vector_types_for_stmt (vinfo, stmts[0], ,
-  _vectype, stmts.length ()))
-return false;
-
-  stmt_vec_info stmt_info;
-  unsigned int i;
-  FOR_EACH_VEC_ELT (stmts, i, stmt_info)
-if (!vect_update_shared_vectype (stmt_info, vectype))
-  return false;
-
-  return true;
-}
-
 /* Return true if call statements CALL1 and CALL2 are similar enough
to be combined into the same SLP group.  */
 
@@ -1349,7 +1329,6 @@ vect_build_slp_tree_2 (vec_info *vinfo,
   FOR_EACH_VEC_ELT (oprnds_info, i, oprnd_info)
 {
   slp_tree child;
-  unsigned old_tree_size = this_tree_size;
   unsigned int j;
 
   if (oprnd_info->first_dt == vect_uninitialized_def)
@@ -1376,45 +1355,6 @@ vect_build_slp_tree_2 (vec_info *vinfo,
matches, npermutes,
_tree_size, bst_map)) != NULL)
{
- /* If we have all children of a non-unary child built up from
-scalars then just throw that away and build it up this node
-from scalars.  */
- if (is_a  (vinfo)
- && SLP_TREE_CHILDREN (child).length () > 1
- /* ???  Rejecting patterns this way doesn't work.  We'd have to
-do extra work to cancel the pattern so the uses see the
-scalar version.  */
- && !oprnd_info->any_pattern)
-   {
- slp_tree grandchild;
-
- FOR_EACH_VEC_ELT (SLP_TREE_CHILDREN (child), j, grandchild)
-   if (SLP_TREE_DEF_TYPE (grandchild) != vect_external_def)
- break;
- if (!grandchild
- && vect_update_all_shared_vectypes (vinfo,
- 

Re: [EXT] Re: [PATCH] Optimize and+or+sub into xor+not (PR94882)

2020-06-04 Thread Marc Glisse

On Thu, 4 Jun 2020, Richard Biener via Gcc-patches wrote:


(if (!TYPE_OVERFLOW_SANITIZED (type) && !TYPE_OVERFLOW_TRAPS (type)
&& !TYPE_SATURATING (type)


Would the positive form
TYPE_OVERFLOW_WRAPS (type) || TYPE_OVERFLOW_UNDEFINED (type)
be roughly equivalent and shorter? Or am I missing some cases?

(I didn't look at the patch and if that's the right condition, just 
randomly commenting on this line)


--
Marc Glisse


[PATCH] middle-end/95493 - bogus MEM_ATTRS for variable array access

2020-06-04 Thread Richard Biener


So this is a variant cleaning up set_mem_attributes_minus_bitpos
instead.

Bootstrapped and tested on x86_64-unknown-linux-gnu.

I'll go with this variant since it is more obvious unless I hear
otherwise.

Thanks,
Richard.


The following patch avoids keeping the inherited MEM_ATTRS when
set_mem_attributes_minus_bitpos is called with a variable ARRAY_REF.
The inherited ones may not reflect the correct offset and neither
does the updated alias-set match the inherited MEM_EXPR.  This all
ends up confusing path-based alias-analysis, causing wrong-code.

The fix is to stop not adopting a MEM_EXPR for certain kinds of
expressions and instead handle everything we can.  There's still
the constant kind trees case which I'm too lazy to look into right
now.  I did refrain from adding SSA_NAME there and instead avoided
calling set_mem_attributes_minus_bitpos when debug expression
expansion ended up expanding a SSA definition RHS which should
already have taken care of setting the appropriate MEM_ATTRS.

2020-06-04  Richard Biener  

PR middle-end/95493
* cfgexpand.c (expand_debug_expr): Avoid calling
set_mem_attributes_minus_bitpos when we were expanding
an SSA name.
* emit-rtl.c (set_mem_attributes_minus_bitpos): Remove
ARRAY_REF special-casing, add CONSTRUCTOR to the set of
special-cases we do not want MEM_EXPRs for.  Assert
we end up with reasonable MEM_EXPRs.

* g++.dg/torture/pr95493.C: New testcase.
---
 gcc/cfgexpand.c|  3 +-
 gcc/emit-rtl.c | 63 --
 gcc/testsuite/g++.dg/torture/pr95493.C | 62 +
 3 files changed, 73 insertions(+), 55 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/torture/pr95493.C

diff --git a/gcc/cfgexpand.c b/gcc/cfgexpand.c
index 2f6ec97ed04..b270a4ddb9d 100644
--- a/gcc/cfgexpand.c
+++ b/gcc/cfgexpand.c
@@ -4616,7 +4616,8 @@ expand_debug_expr (tree exp)
  op0 = copy_rtx (op0);
if (op0 == orig_op0)
  op0 = shallow_copy_rtx (op0);
-   set_mem_attributes (op0, exp, 0);
+   if (TREE_CODE (tem) != SSA_NAME)
+ set_mem_attributes (op0, exp, 0);
  }
 
if (known_eq (bitpos, 0) && mode == GET_MODE (op0))
diff --git a/gcc/emit-rtl.c b/gcc/emit-rtl.c
index 2b790636366..f9b0e9714d9 100644
--- a/gcc/emit-rtl.c
+++ b/gcc/emit-rtl.c
@@ -2067,8 +2067,10 @@ set_mem_attributes_minus_bitpos (rtx ref, tree t, int 
objectp,
  new_size = DECL_SIZE_UNIT (t);
}
 
-  /* ???  If we end up with a constant here do record a MEM_EXPR.  */
-  else if (CONSTANT_CLASS_P (t))
+  /* ???  If we end up with a constant or a descriptor do not
+record a MEM_EXPR.  */
+  else if (CONSTANT_CLASS_P (t)
+  || TREE_CODE (t) == CONSTRUCTOR)
;
 
   /* If this is a field reference, record it.  */
@@ -2082,59 +2084,12 @@ set_mem_attributes_minus_bitpos (rtx ref, tree t, int 
objectp,
new_size = DECL_SIZE_UNIT (TREE_OPERAND (t, 1));
}
 
-  /* If this is an array reference, look for an outer field reference.  */
-  else if (TREE_CODE (t) == ARRAY_REF)
-   {
- tree off_tree = size_zero_node;
- /* We can't modify t, because we use it at the end of the
-function.  */
- tree t2 = t;
-
- do
-   {
- tree index = TREE_OPERAND (t2, 1);
- tree low_bound = array_ref_low_bound (t2);
- tree unit_size = array_ref_element_size (t2);
-
- /* We assume all arrays have sizes that are a multiple of a byte.
-First subtract the lower bound, if any, in the type of the
-index, then convert to sizetype and multiply by the size of
-the array element.  */
- if (! integer_zerop (low_bound))
-   index = fold_build2 (MINUS_EXPR, TREE_TYPE (index),
-index, low_bound);
-
- off_tree = size_binop (PLUS_EXPR,
-size_binop (MULT_EXPR,
-fold_convert (sizetype,
-  index),
-unit_size),
-off_tree);
- t2 = TREE_OPERAND (t2, 0);
-   }
- while (TREE_CODE (t2) == ARRAY_REF);
-
- if (DECL_P (t2)
- || (TREE_CODE (t2) == COMPONENT_REF
- /* For trailing arrays t2 doesn't have a size that
-covers all valid accesses.  */
- && ! array_at_struct_end_p (t)))
-   {
- attrs.expr = t2;
- attrs.offset_known_p = false;
- if (poly_int_tree_p (off_tree, ))
-   {
- attrs.offset_known_p = true;
- apply_bitpos = bitpos;
-  

Re: std::optional defaut constructor

2020-06-04 Thread Marc Glisse

On Thu, 4 Jun 2020, Richard Biener wrote:


On Thu, Jun 4, 2020 at 11:34 AM Ville Voutilainen via Gcc-patches
 wrote:


On Thu, 4 Jun 2020 at 11:53, Marc Glisse  wrote:


On Thu, 4 Jun 2020, Ville Voutilainen wrote:


On Thu, 4 Jun 2020 at 11:00, Marc Glisse  wrote:

Maybe create a buffer, fill it with some non-zero values (-1?), then call
placement new, and read some value in the middle of the buffer, possibly
with some protection against optimizations? Ah, no, actual constructors
are fine, it is only the inlined initialization that happens with the
defaulted constructor that zeroes things.


The zero-init is part of value-initialization of a class type with a
defaulted default constructor, so value-initialization with placement
new should indeed show us whether the target buffer is zeroed.


Ah, yes, I had forgotten the empty () at the end of the operator new line
when testing. Now the patch makes this runtime test go from abort to
success at -O0 (with optimizations, the memset is removed as dead code). I
am still not sure we want this kind of test though. And I added launder
more to quiet a warning than with confidence that it does the right thing.

#include 
struct A {
   int a[1024];
};
typedef std::optional O;
int main(){
   unsigned char t[sizeof(O)];
   __builtin_memset(t, -1, sizeof(t));
   new(t)O();
   if(std::launder(t)[512] != (unsigned char)(-1)) __builtin_abort();
}


Yeah, I think the patch is OK with or without the test. As a side
note, you don't need the launder
if the check uses the pointer value returned by placement-new.


Doesn't the placement new make the memory state of anything
not explicitely initialized indeterminate?  That is, isn't the
testcase broken anyways since GCC can elide the memset
when seeing the placement new?


Ah, I was just replying to that in parallel. Yes it is broken, that's why 
I don't really like adding it. But -fno-lifetime-dse may be enough to make 
it work if we really want to.


--
Marc Glisse


Re: std::optional defaut constructor

2020-06-04 Thread Marc Glisse

On Thu, 4 Jun 2020, Ville Voutilainen wrote:


On Thu, 4 Jun 2020 at 11:53, Marc Glisse  wrote:


On Thu, 4 Jun 2020, Ville Voutilainen wrote:


On Thu, 4 Jun 2020 at 11:00, Marc Glisse  wrote:

Maybe create a buffer, fill it with some non-zero values (-1?), then call
placement new, and read some value in the middle of the buffer, possibly
with some protection against optimizations? Ah, no, actual constructors
are fine, it is only the inlined initialization that happens with the
defaulted constructor that zeroes things.


The zero-init is part of value-initialization of a class type with a
defaulted default constructor, so value-initialization with placement
new should indeed show us whether the target buffer is zeroed.


Ah, yes, I had forgotten the empty () at the end of the operator new line
when testing. Now the patch makes this runtime test go from abort to
success at -O0 (with optimizations, the memset is removed as dead code). I
am still not sure we want this kind of test though. And I added launder
more to quiet a warning than with confidence that it does the right thing.

#include 
struct A {
   int a[1024];
};
typedef std::optional O;
int main(){
   unsigned char t[sizeof(O)];
   __builtin_memset(t, -1, sizeof(t));
   new(t)O();
   if(std::launder(t)[512] != (unsigned char)(-1)) __builtin_abort();
}


Yeah, I think the patch is OK with or without the test. As a side
note, you don't need the launder
if the check uses the pointer value returned by placement-new.


Yes, -fno-lifetime-dse is a better way to quiet the warning if
optimizations are enabled and documents why this test is unsafe. Here is
a version closer to what could go in the testsuite, although I'd still
rather not add it at this point. We'll see what Jonathan thinks.
(I didn't test this exact version)

// { dg-options "-std=gnu++17 -fno-lifetime-dse" }
// { dg-do run { target c++17 } }

#include 
#include 

struct A
{
  int a[1024];
};
typedef std::optional O;

void
test01()
{
  unsigned char t[sizeof(O)];
  __builtin_memset(t, -1, sizeof(t));
  new (t) O();
  VERIFY( t[512] == (unsigned char)(-1) );
}

int
main()
{
  test01();
}


--
Marc Glisse


Re: std::optional defaut constructor

2020-06-04 Thread Ville Voutilainen via Gcc-patches
On Thu, 4 Jun 2020 at 14:41, Richard Biener  wrote:
> Doesn't the placement new make the memory state of anything
> not explicitely initialized indeterminate?  That is, isn't the
> testcase broken anyways since GCC can elide the memset
> when seeing the placement new?

Hmm, yes it does, and the test is broken.


Re: std::optional defaut constructor

2020-06-04 Thread Richard Biener via Gcc-patches
On Thu, Jun 4, 2020 at 11:34 AM Ville Voutilainen via Gcc-patches
 wrote:
>
> On Thu, 4 Jun 2020 at 11:53, Marc Glisse  wrote:
> >
> > On Thu, 4 Jun 2020, Ville Voutilainen wrote:
> >
> > > On Thu, 4 Jun 2020 at 11:00, Marc Glisse  wrote:
> > >> Maybe create a buffer, fill it with some non-zero values (-1?), then call
> > >> placement new, and read some value in the middle of the buffer, possibly
> > >> with some protection against optimizations? Ah, no, actual constructors
> > >> are fine, it is only the inlined initialization that happens with the
> > >> defaulted constructor that zeroes things.
> > >
> > > The zero-init is part of value-initialization of a class type with a
> > > defaulted default constructor, so value-initialization with placement
> > > new should indeed show us whether the target buffer is zeroed.
> >
> > Ah, yes, I had forgotten the empty () at the end of the operator new line
> > when testing. Now the patch makes this runtime test go from abort to
> > success at -O0 (with optimizations, the memset is removed as dead code). I
> > am still not sure we want this kind of test though. And I added launder
> > more to quiet a warning than with confidence that it does the right thing.
> >
> > #include 
> > struct A {
> >int a[1024];
> > };
> > typedef std::optional O;
> > int main(){
> >unsigned char t[sizeof(O)];
> >__builtin_memset(t, -1, sizeof(t));
> >new(t)O();
> >if(std::launder(t)[512] != (unsigned char)(-1)) __builtin_abort();
> > }
>
> Yeah, I think the patch is OK with or without the test. As a side
> note, you don't need the launder
> if the check uses the pointer value returned by placement-new.

Doesn't the placement new make the memory state of anything
not explicitely initialized indeterminate?  That is, isn't the
testcase broken anyways since GCC can elide the memset
when seeing the placement new?

Thanks,
Richard.


Re: [PATCH] fix bitmask conflict between PTA_AVX512VP2INTERSECT and PTA_WAITPKG

2020-06-04 Thread Uros Bizjak via Gcc-patches
On Thu, Jun 4, 2020 at 1:15 PM H.J. Lu  wrote:
>
> On Thu, Jun 4, 2020 at 2:55 AM Uros Bizjak  wrote:
> >
> > On Thu, Jun 4, 2020 at 11:50 AM Cui, Lili  wrote:
> > >
> > > Hi Uros,
> > >
> > > This patch is to fix bitmask conflict between PTA_AVX512VP2INTERSECT  and 
> > > PTA_WAITPKG
> > >  in gcc/config/i386/i386.h
> > >
> > > Bootstrap is ok, make-check ok for i386 target. Ok for trunk?
> > >
> > >
> > > gcc/ChangeLog:
> > > * config/i386/i386.h (PTA_WAITPKG): Change bitmask value.
>
> Please add "PR target/95525".
>
> > OK.
>
> Is it OK to backport?

Yes.

Uros.


Re: [PATCH] fix bitmask conflict between PTA_AVX512VP2INTERSECT and PTA_WAITPKG

2020-06-04 Thread H.J. Lu via Gcc-patches
On Thu, Jun 4, 2020 at 2:55 AM Uros Bizjak  wrote:
>
> On Thu, Jun 4, 2020 at 11:50 AM Cui, Lili  wrote:
> >
> > Hi Uros,
> >
> > This patch is to fix bitmask conflict between PTA_AVX512VP2INTERSECT  and 
> > PTA_WAITPKG
> >  in gcc/config/i386/i386.h
> >
> > Bootstrap is ok, make-check ok for i386 target. Ok for trunk?
> >
> >
> > gcc/ChangeLog:
> > * config/i386/i386.h (PTA_WAITPKG): Change bitmask value.

Please add "PR target/95525".

> OK.

Is it OK to backport?

> Thanks,
> Uros.
>
> > ---
> >  gcc/config/i386/i386.h | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/gcc/config/i386/i386.h b/gcc/config/i386/i386.h
> > index 48a5735d4e7..5bae257b435 100644
> > --- a/gcc/config/i386/i386.h
> > +++ b/gcc/config/i386/i386.h
> > @@ -2444,9 +2444,9 @@ const wide_int_bitmask PTA_RDPID (0, HOST_WIDE_INT_1U 
> > << 6);
> >  const wide_int_bitmask PTA_PCONFIG (0, HOST_WIDE_INT_1U << 7);
> >  const wide_int_bitmask PTA_WBNOINVD (0, HOST_WIDE_INT_1U << 8);
> >  const wide_int_bitmask PTA_AVX512VP2INTERSECT (0, HOST_WIDE_INT_1U << 9);
> > -const wide_int_bitmask PTA_WAITPKG (0, HOST_WIDE_INT_1U << 9);
> >  const wide_int_bitmask PTA_PTWRITE (0, HOST_WIDE_INT_1U << 10);
> >  const wide_int_bitmask PTA_AVX512BF16 (0, HOST_WIDE_INT_1U << 11);
> > +const wide_int_bitmask PTA_WAITPKG (0, HOST_WIDE_INT_1U << 12);
> >  const wide_int_bitmask PTA_MOVDIRI(0, HOST_WIDE_INT_1U << 13);
> >  const wide_int_bitmask PTA_MOVDIR64B(0, HOST_WIDE_INT_1U << 14);
> >

Thanks.

-- 
H.J.


Re: [PATCH] fix bitmask conflict between PTA_AVX512VP2INTERSECT and PTA_WAITPKG

2020-06-04 Thread Uros Bizjak via Gcc-patches
On Thu, Jun 4, 2020 at 11:50 AM Cui, Lili  wrote:
>
> Hi Uros,
>
> This patch is to fix bitmask conflict between PTA_AVX512VP2INTERSECT  and 
> PTA_WAITPKG
>  in gcc/config/i386/i386.h
>
> Bootstrap is ok, make-check ok for i386 target. Ok for trunk?
>
>
> gcc/ChangeLog:
> * config/i386/i386.h (PTA_WAITPKG): Change bitmask value.

OK.

Thanks,
Uros.

> ---
>  gcc/config/i386/i386.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/gcc/config/i386/i386.h b/gcc/config/i386/i386.h
> index 48a5735d4e7..5bae257b435 100644
> --- a/gcc/config/i386/i386.h
> +++ b/gcc/config/i386/i386.h
> @@ -2444,9 +2444,9 @@ const wide_int_bitmask PTA_RDPID (0, HOST_WIDE_INT_1U 
> << 6);
>  const wide_int_bitmask PTA_PCONFIG (0, HOST_WIDE_INT_1U << 7);
>  const wide_int_bitmask PTA_WBNOINVD (0, HOST_WIDE_INT_1U << 8);
>  const wide_int_bitmask PTA_AVX512VP2INTERSECT (0, HOST_WIDE_INT_1U << 9);
> -const wide_int_bitmask PTA_WAITPKG (0, HOST_WIDE_INT_1U << 9);
>  const wide_int_bitmask PTA_PTWRITE (0, HOST_WIDE_INT_1U << 10);
>  const wide_int_bitmask PTA_AVX512BF16 (0, HOST_WIDE_INT_1U << 11);
> +const wide_int_bitmask PTA_WAITPKG (0, HOST_WIDE_INT_1U << 12);
>  const wide_int_bitmask PTA_MOVDIRI(0, HOST_WIDE_INT_1U << 13);
>  const wide_int_bitmask PTA_MOVDIR64B(0, HOST_WIDE_INT_1U << 14);
>
>
>
> Thanks,
> Lili.


[PATCH] fix bitmask conflict between PTA_AVX512VP2INTERSECT and PTA_WAITPKG

2020-06-04 Thread Cui, Lili via Gcc-patches
Hi Uros,

This patch is to fix bitmask conflict between PTA_AVX512VP2INTERSECT  and 
PTA_WAITPKG
 in gcc/config/i386/i386.h

Bootstrap is ok, make-check ok for i386 target. Ok for trunk?


gcc/ChangeLog:
* config/i386/i386.h (PTA_WAITPKG): Change bitmask value.
---
 gcc/config/i386/i386.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/config/i386/i386.h b/gcc/config/i386/i386.h
index 48a5735d4e7..5bae257b435 100644
--- a/gcc/config/i386/i386.h
+++ b/gcc/config/i386/i386.h
@@ -2444,9 +2444,9 @@ const wide_int_bitmask PTA_RDPID (0, HOST_WIDE_INT_1U << 
6);
 const wide_int_bitmask PTA_PCONFIG (0, HOST_WIDE_INT_1U << 7);
 const wide_int_bitmask PTA_WBNOINVD (0, HOST_WIDE_INT_1U << 8);
 const wide_int_bitmask PTA_AVX512VP2INTERSECT (0, HOST_WIDE_INT_1U << 9);
-const wide_int_bitmask PTA_WAITPKG (0, HOST_WIDE_INT_1U << 9);
 const wide_int_bitmask PTA_PTWRITE (0, HOST_WIDE_INT_1U << 10);
 const wide_int_bitmask PTA_AVX512BF16 (0, HOST_WIDE_INT_1U << 11);
+const wide_int_bitmask PTA_WAITPKG (0, HOST_WIDE_INT_1U << 12);
 const wide_int_bitmask PTA_MOVDIRI(0, HOST_WIDE_INT_1U << 13);
 const wide_int_bitmask PTA_MOVDIR64B(0, HOST_WIDE_INT_1U << 14);
 


Thanks,
Lili.


0001-Fix-bitmask-conflict-between-PTA_AVX512VP2INTERSECT-.patch
Description: 0001-Fix-bitmask-conflict-between-PTA_AVX512VP2INTERSECT-.patch


RE: [PATCH][RFC] extend DECL_GIMPLE_REG_P to all types

2020-06-04 Thread Alex Coplan
> -Original Message-
> From: Gcc-patches  On Behalf Of Richard
> Biener
> Sent: 07 May 2020 14:40
> To: Richard Sandiford 
> Cc: gcc-patches@gcc.gnu.org
> Subject: Re: [PATCH][RFC] extend DECL_GIMPLE_REG_P to all types
> 
> On Thu, 23 Apr 2020, Richard Biener wrote:
> 
> > On Wed, 22 Apr 2020, Richard Sandiford wrote:
> >
> > > Richard Biener  writes:
> > > > On Wed, 22 Apr 2020, Richard Biener wrote:
> > > >
> > > >>
> > > >> This extends DECL_GIMPLE_REG_P to all types so we can clear
> > > >> TREE_ADDRESSABLE even for integers with partial defs, not just
> > > >> complex and vector variables.  To make that transition easier
> > > >> the patch inverts DECL_GIMPLE_REG_P to DECL_NOT_GIMPLE_REG_P
> > > >> since that makes the default the current state for all other
> > > >> types besides complex and vectors.  That also nicely simplifies
> > > >> code throughout the compiler.
> > > >>
> > > >> TREE_ADDRESSABLE and DECL_NOT_GIMPLE_REG_P are now truly
> > > >> independent, either set prevents a decl from being rewritten
> > > >> into SSA form.
> > > >>
> > > >> For the testcase in PR94703 we're able to expand the partial
> > > >> def'ed local integer to a register then, producing a single
> > > >> movl rather than going through the stack.
> > > >>
> > > >> Bootstrapped on x86_64-unknown-linux-gnu, testing in progress.
> > > >>
> > > >> If there are no objections I'm going to install this once
> > > >> stage1 opens.
> > > >
> > > > Of course there was some fallout.  On 32bit x86
> gcc.dg/torture/pr71522.c
> > > > fails execution because while the GIMPLE is unchanged at RTL
> expansion
> > > > time:
> > > >
> > > > main ()
> > > > {
> > > >   char s[12];
> > > >   long double d;
> > > >
> > > >   MEM  [(char * {ref-all})] = MEM  char[12]>
> > > > [(char * {ref-all})"AAA"];
> > > >   MEM  [(char * {ref-all})] = MEM  char[12]>
> > > > [(char * {ref-all})];
> > > >   _1 = __builtin_strcmp (, "AAA");
> > > >   if (_1 != 0)
> > > > ...
> > > >
> > > > we now assign 'd' an XFmode register (TREE_ADDRESSABLE is cleared
> > > > now since we can set DECL_NOT_GIMPLE_REG_P).  The case is lost
> > > > then, impossible to fix up AFAICS.  On x86 all moves to/from
> > > > XFmode are normalizing, specifically we end up with
> > > >
> > > > fldt.LC0
> > > > fstpt   (%esp)
> > > >
> > > > now the most appealing solution - and totally in the opposite
> > > > direction of this patch - is to simply stop expanding non-SSA names
> > > > as pseudos.  I do not remember the history as why we do this
> > > > but it's likely remanents we preserved from either pre-SSA, times
> > > > we did not go into SSA for -O0 or times we really gone out-of-SSA.
> > > >
> > > > There is _some_ good reason to expand a non-SSA "register" into
> > > > a pseudo though - namely that RTL is not SSA and thus can accept
> > > > partial defs.  And of course that RTL cannot get rid of a stack
> > > > slot assigned to a variable.  Today we have somewhat robust
> > > > infrastructure to deal with partial defs on GIMPLE, namely
> > > > BIT_INSERT_EXPR, but it's not fully exercised.
> > >
> > > Yeah, not being able to get rid of the stack slot seems
> > > worrying here.
> > >
> > > > It's of course possible to fixup the above problematical
> > > > cases (there's precenent with discover_nonconstant_array_refs,
> > > > which could be "easily" extended to handle "weird" accesses
> > > > of non-integral-mode variables) but with the recent discussion
> > > > on making RTL expansion more straight-forward I'd bring up
> > > > the above idea ... it would get rid of quite some special
> > > > code dealing with tcc_reference trees (and MEM_REFs) ending
> > > > up operating on registers.
> > >
> > > It might be nice to do it eventually, but I think at least
> > > is_gimple_reg_type would need to be "return true" first,
> > > otherwise we'll lose too much on aggregates.
> > >
> > > There's also the problem that things passed in registers do need
> > > to be RTL registers at function boundaries, so I'm not sure all
> > > the expand code would necessarily go away.
> > >
> > > Wouldn't want to see all targets suffer for XFmode oddities :-)
> >
> > OK, so here's the patch amemded with some heuristics to catch
> > this.  The heuristic triggers exactly on the previously
> > failing testcase and nothing else on a x86_64 bootstrap and regtest.
> > Citing the code:
> >
> > /* If there's a chance to get a pseudo for t then if it would be of
> float
> > mode
> >and the actual access is via an integer mode (lowered memcpy or
> similar
> >access) then avoid the register expansion if the mode likely is not
> > storage
> >suitable for raw bits processing (like XFmode on i?86).  */
> >
> > static void
> > avoid_type_punning_on_regs (tree t)
> > {
> >   machine_mode access_mode = TYPE_MODE (TREE_TYPE (t));
> >   if (access_mode != BLKmode
> >   && !SCALAR_INT_MODE_P (access_mode))
> > return;
> >   tree base = get_base_address (t);
> 

Re: std::optional defaut constructor

2020-06-04 Thread Ville Voutilainen via Gcc-patches
On Thu, 4 Jun 2020 at 11:53, Marc Glisse  wrote:
>
> On Thu, 4 Jun 2020, Ville Voutilainen wrote:
>
> > On Thu, 4 Jun 2020 at 11:00, Marc Glisse  wrote:
> >> Maybe create a buffer, fill it with some non-zero values (-1?), then call
> >> placement new, and read some value in the middle of the buffer, possibly
> >> with some protection against optimizations? Ah, no, actual constructors
> >> are fine, it is only the inlined initialization that happens with the
> >> defaulted constructor that zeroes things.
> >
> > The zero-init is part of value-initialization of a class type with a
> > defaulted default constructor, so value-initialization with placement
> > new should indeed show us whether the target buffer is zeroed.
>
> Ah, yes, I had forgotten the empty () at the end of the operator new line
> when testing. Now the patch makes this runtime test go from abort to
> success at -O0 (with optimizations, the memset is removed as dead code). I
> am still not sure we want this kind of test though. And I added launder
> more to quiet a warning than with confidence that it does the right thing.
>
> #include 
> struct A {
>int a[1024];
> };
> typedef std::optional O;
> int main(){
>unsigned char t[sizeof(O)];
>__builtin_memset(t, -1, sizeof(t));
>new(t)O();
>if(std::launder(t)[512] != (unsigned char)(-1)) __builtin_abort();
> }

Yeah, I think the patch is OK with or without the test. As a side
note, you don't need the launder
if the check uses the pointer value returned by placement-new.


[Ada] Ada_2020: contracts for formal subprograms

2020-06-04 Thread Pierre-Marie de Rodat
AI12-0272 specifies that pre- and postconditions can be given for formal
subprograms. In the presence of these contracts the formal subprogram
cannot be treated simply as a renaming of the actual, but instead we
must create a subgprogram wrapper that carries the specified contracts
and calls the actual. In this fashion a call to the formal includes both
the contracts specified for the formal and those that come from the
actual.

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

2020-06-04  Ed Schonberg  

gcc/ada/

* sem_ch12.adb (Build_Suprogram_Body_Wrapper,
Build_Subprogram_Decl_Wrapper): New suprograms, to create the
wrappers needed to implement contracts on formsl subprograms at
the point of instantiation.
(Build_Subprogram_Wrappers): New subprogram within
Analyze_Associations, calls the above when the formal subprogram
has contracts, and expansion is enabled.
(Instantiate_Formal_Subprogram): If the actual is not an entity,
such as a function attribute, or a synchronized operation,
create a function with an internal name and call it within the
wrapper.
(Analyze_Generic_Formal_Part): Analyze contracts at the end of
the list of formal declarations.
* sem_prag.adb (Analyze_Pre_Post_Condtion): In Ada_2020 the
aspect and corresponding pragma can appear on a formal
subprogram declaration.
(Find_Related_Declaration_Or_Body): Ditto.--- gcc/ada/sem_ch12.adb
+++ gcc/ada/sem_ch12.adb
@@ -495,6 +495,23 @@ package body Sem_Ch12 is
--  nodes or subprogram body and declaration nodes depending on the case).
--  On return, the node N has been rewritten with the actual body.
 
+   function Build_Subprogram_Decl_Wrapper
+ (Formal_Subp : Entity_Id;
+  Actual_Subp : Entity_Id) return Node_Id;
+   --  Ada 2020 allows formal subprograms to carry pre/postconditions.
+   --  At the point of instantiation these contracts apply to uses of
+   --  the actual subprogram. This is implemented by creating wrapper
+   --  subprograms instead of the renamings previously used to link
+   --  formal subprograms and the corresponding actuals. If the actual
+   --  is not an entity (e.g. an attribute reference) a renaming is
+   --  created to handle the expansion of the attribute.
+
+   function Build_Subprogram_Body_Wrapper
+ (Formal_Subp : Entity_Id;
+  Actual_Subp : Entity_Id) return Node_Id;
+   --  The body of the wrapper is a call to the actual, with the generated
+   --  pre/postconditon checks added.
+
procedure Check_Access_Definition (N : Node_Id);
--  Subsidiary routine to null exclusion processing. Perform an assertion
--  check on Ada version and the presence of an access definition in N.
@@ -1078,6 +1095,14 @@ package body Sem_Ch12 is
   --  In Ada 2005, indicates partial parameterization of a formal
   --  package. As usual an other association must be last in the list.
 
+  procedure Build_Subprogram_Wrappers;
+  --  Ada_2020: AI12-0272 introduces pre/postconditions for formal
+  --  subprograms. The implementation of making the formal into a renaming
+  --  of the actual does not work, given that subprogram renaming cannot
+  --  carry aspect specifications. Instead we must create subprogram
+  --  wrappers whose body is a call to the actual, and whose declaration
+  --  carries the aspects of the formal.
+
   procedure Check_Fixed_Point_Actual (Actual : Node_Id);
   --  Warn if an actual fixed-point type has user-defined arithmetic
   --  operations, but there is no corresponding formal in the generic,
@@ -1131,6 +1156,49 @@ package body Sem_Ch12 is
   --  anonymous types, the presence a formal equality will introduce an
   --  implicit declaration for the corresponding inequality.
 
+  -
+  -- procedure Build_Subprogram_Wrappers --
+  -
+
+  procedure Build_Subprogram_Wrappers is
+ Formal : constant Entity_Id :=
+   Defining_Unit_Name (Specification (Analyzed_Formal));
+ Aspect_Spec : Node_Id;
+ Decl_Node   : Node_Id;
+ Ent : Entity_Id;
+
+  begin
+ --  Create declaration for wrapper subprogram
+
+ if Is_Entity_Name (Match) then
+Ent := Entity (Match);
+ else
+Ent := Defining_Entity (Last (Assoc_List));
+ end if;
+
+ Decl_Node := Build_Subprogram_Decl_Wrapper (Formal, Ent);
+
+ --  Transfer aspect specifications from formal subprogram to wrapper
+
+ Set_Aspect_Specifications (Decl_Node,
+   New_Copy_List_Tree (Aspect_Specifications (Analyzed_Formal)));
+
+ Aspect_Spec := First (Aspect_Specifications (Decl_Node));
+ while Present (Aspect_Spec) loop
+Set_Analyzed (Aspect_Spec, False);
+Next (Aspect_Spec);
+ end loop;

[Ada] New package Ada.Task_Initialization

2020-06-04 Thread Pierre-Marie de Rodat
This package provides a way to set up a global initialization handler
when tasks start.

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

2020-06-04  Arnaud Charlet  

gcc/ada/

* Makefile.rtl: add a-tasini object
* impunit.adb (Non_Imp_File_Names_95): Add s-tasini.
* libgnarl/a-tasini.ads, libgnarl/a-tasini.adb: New files.
* libgnarl/s-taskin.ads (Global_Initialization_Handler): New.
* libgnarl/s-tassta.adb (Task_Wrapper): Call
Global_Initialization_Handler if non null.--- gcc/ada/Makefile.rtl
+++ gcc/ada/Makefile.rtl
@@ -39,6 +39,7 @@ GNATRTL_TASKING_OBJS= \
   a-sytaco$(objext) \
   a-tasatt$(objext) \
   a-taside$(objext) \
+  a-tasini$(objext) \
   a-taster$(objext) \
   g-boubuf$(objext) \
   g-boumai$(objext) \

--- gcc/ada/impunit.adb
+++ gcc/ada/impunit.adb
@@ -181,6 +181,7 @@ package body Impunit is
 ("a-ssicst", F),  -- Ada.Streams.Stream_IO.C_Streams
 ("a-suteio", F),  -- Ada.Strings.Unbounded.Text_IO
 ("a-swuwti", F),  -- Ada.Strings.Wide_Unbounded.Wide_Text_IO
+("a-tasini", F),  -- Ada.Task_Initialization
 ("a-tiocst", F),  -- Ada.Text_IO.C_Streams
 ("a-wtcstr", F),  -- Ada.Wide_Text_IO.C_Streams
 

--- /dev/null
new file mode 100644
+++ gcc/ada/libgnarl/a-tasini.adb
@@ -0,0 +1,46 @@
+--
+--  --
+-- GNAT RUN-TIME LIBRARY (GNARL) COMPONENTS --
+--  --
+--  A D A . T A S K _ I N I T I A L I Z A T I O N   --
+--  --
+--  B o d y --
+--  --
+-- Copyright (C) 2020, Free Software Foundation, Inc.   --
+--  --
+-- GNARL is free software; you can  redistribute it  and/or modify it under --
+-- terms of the  GNU General Public License as published  by the Free Soft- --
+-- ware  Foundation;  either version 3,  or (at your option) any later ver- --
+-- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
+-- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
+-- or FITNESS FOR A PARTICULAR PURPOSE. --
+--  --
+-- As a special exception under Section 7 of GPL version 3, you are granted --
+-- additional permissions described in the GCC Runtime Library Exception,   --
+-- version 3.1, as published by the Free Software Foundation.   --
+--  --
+-- You should have received a copy of the GNU General Public License and--
+-- a copy of the GCC Runtime Library Exception along with this program; --
+-- see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see--
+-- .  --
+--  --
+--
+
+with Ada.Unchecked_Conversion;
+with System.Tasking;
+
+package body Ada.Task_Initialization is
+
+   function To_STIH is new Ada.Unchecked_Conversion
+ (Initialization_Handler, System.Tasking.Initialization_Handler);
+
+   
+   -- Set_Initialization_Handler --
+   
+
+   procedure Set_Initialization_Handler (Handler : Initialization_Handler) is
+   begin
+  System.Tasking.Global_Initialization_Handler := To_STIH (Handler);
+   end Set_Initialization_Handler;
+
+end Ada.Task_Initialization;

--- /dev/null
new file mode 100644
+++ gcc/ada/libgnarl/a-tasini.ads
@@ -0,0 +1,42 @@
+--
+--  --
+-- GNAT RUN-TIME LIBRARY (GNARL) COMPONENTS --
+--  --
+--  A D A . T A S K _ I N I T I A L I Z A T I O N   --
+--  --
+--  S p e c --
+--  --
+-- Copyright (C) 2020, Free Software Foundation, Inc.   --
+--  --
+-- GNARL is free software; you can  redistribute it  and/or modify it under --
+-- terms 

[Ada] Update the documentation in checks.ads about range checks

2020-06-04 Thread Pierre-Marie de Rodat
This documents that range checks are now entirely generated by the
front-end of the compiler.

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

2020-06-04  Eric Botcazou  

gcc/ada/

* checks.ads: Update documentation about range checks and fix
minor other things.--- gcc/ada/checks.ads
+++ gcc/ada/checks.ads
@@ -23,10 +23,10 @@
 --  --
 --
 
---  Package containing routines used to deal with runtime checks. These
+--  Package containing routines used to deal with run-time checks. These
 --  routines are used both by the semantics and by the expander. In some
---  cases, checks are enabled simply by setting flags for gigi, and in
---  other cases the code for the check is expanded.
+--  cases, checks are enabled simply by setting a flag for the back end,
+--  and in other cases the code for the check is expanded.
 
 --  The approach used for range and length checks, in regards to suppressed
 --  checks, is to attempt to detect at compilation time that a constraint
@@ -179,7 +179,7 @@ package Checks is
--  operate anyway since they may generate useful compile time warnings.
 
procedure Apply_Access_Check (N : Node_Id);
-   --  Determines whether an expression node requires a runtime access
+   --  Determines whether an expression node requires a run-time access
--  check and if so inserts the appropriate run-time check.
 
procedure Apply_Accessibility_Check
@@ -200,7 +200,7 @@ package Checks is
--  generated) is prepended to the Actions list of N_Freeze_Entity node N.
--  Note that the check references E'Alignment, so it cannot be emitted
--  before N (its freeze node), otherwise this would cause an illegal
-   --  access before elaboration error in GIGI. For the case of a clear overlay
+   --  access before elaboration error in gigi. For the case of a clear overlay
--  situation, we also check that the size of the overlaying object is not
--  larger than the overlaid object.
 
@@ -339,7 +339,7 @@ package Checks is
--  value should be taken into account, which is not the case currently.
 
procedure Install_Null_Excluding_Check (N : Node_Id);
-   --  Determines whether an access node requires a runtime access check and
+   --  Determines whether an access node requires a run-time access check and
--  if so inserts the appropriate run-time check.
 
procedure Install_Primitive_Elaboration_Check (Subp_Body : Node_Id);
@@ -445,13 +445,10 @@ package Checks is
---
 
--  Range checks are controlled by the Do_Range_Check flag. The front end
-   --  is responsible for setting this flag in relevant nodes. Originally
-   --  the back end generated all corresponding range checks. But later on
-   --  we decided to generate many range checks in the front end. We are now
-   --  in the transitional phase where some of these checks are still done
-   --  by the back end, but many are done by the front end. It is possible
-   --  that in the future we might move all the checks to the front end. The
-   --  main remaining back end checks are for subscript checking.
+   --  is responsible for setting this flag in relevant nodes. Originally the
+   --  back end generated all the corresponding range checks, but later on we
+   --  decided to generate all the range checks in the front end and this is
+   --  the current situation.
 
--  Overflow checks are similarly controlled by the Do_Overflow_Check flag.
--  The difference here is that if back end overflow checks are inactive
@@ -621,7 +618,7 @@ package Checks is
   Source_Typ : Entity_Id := Empty;
   Fixed_Int  : Boolean   := False);
--  For scalar types, determines whether an expression node should be
-   --  flagged as needing a runtime range check. If the node requires such a
+   --  flagged as needing a run-time range check. If the node requires such a
--  check, the Do_Range_Check flag is turned on. The Fixed_Int flag if set
--  causes any fixed-point values to be treated as though they were discrete
--  values (i.e. the underlying integer value is used).
@@ -678,17 +675,12 @@ package Checks is
---
 
--  Some of the earlier processing for checks results in temporarily setting
-   --  the Do_Range_Check flag rather than actually generating checks. Now we
-   --  are moving the generation of such checks into the front end for reasons
-   --  of efficiency and simplicity (there were difficulties in handling this
-   --  in the back end when side effects were present in the expressions being
-   --  checked).
-
-   --  Probably we could eliminate the Do_Range_Check flag entirely and
-   --  generate the checks earlier, but this is a delicate area and it
-   --  seemed safer to implement the following routines, which are called
-   --  late on 

[Ada] Remove OpenACC support

2020-06-04 Thread Pierre-Marie de Rodat
Remove the experimental support for OpenACC in GNAT which has never been
really used and is no longer maintained.

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

2020-06-04  Arnaud Charlet  

gcc/ada/

* back_end.adb, opt.ads, par-prag.adb, sem_ch5.adb,
sem_prag.adb, sinfo.adb, sinfo.ads, snames.ads-tmpl,
doc/gnat_rm/implementation_defined_pragmas.rst: Remove
experimental support for OpenACC.
* gcc-interface/misc.c, gcc-interface/trans.c,
gcc-interface/lang.opt: Ditto.
* gnat_rm.texi: Regenerate.

gcc/testsuite/

* gnat.dg/openacc1.adb: Remove testcase.

patch.diff.gz
Description: application/gzip


[Ada] Put_Image attribute

2020-06-04 Thread Pierre-Marie de Rodat
First cut at implementation of the Put_Image attribute.  Work in
progress. Support for Put_Image is currently disabled (see
Enable_Put_Image in exp_put_image.adb).

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

2020-06-04  Bob Duff  

gcc/ada/

* libgnat/a-stobbu.adb, libgnat/a-stobbu.ads,
libgnat/a-stobfi.adb, libgnat/a-stobfi.ads,
libgnat/a-stoubu.adb, libgnat/a-stoubu.ads,
libgnat/a-stoufi.adb, libgnat/a-stoufi.ads,
libgnat/a-stoufo.adb, libgnat/a-stoufo.ads,
libgnat/a-stouut.adb, libgnat/a-stouut.ads,
libgnat/a-stteou.ads, libgnat/s-putaim.adb,
libgnat/s-putaim.ads, libgnat/s-putima.adb, libgnat/s-putima.ads
(Ada.Strings.Text_Output and children, System.Put_Images): New
runtime support for Put_Image.
* gcc-interface/Make-lang.in (GNAT_ADA_OBJS): Add
exp_put_image.o.
* exp_put_image.adb, exp_put_image.ads: New compiler package
that generates calls to runtime routines that implement
Put_Image.
* Makefile.rtl: Add object files for Ada.Strings.Text_Output and
children and System.Put_Images.
* aspects.adb: Simplify initialization of Canonical_Aspect.
* aspects.ads: Improve documentation. Add Aspect_Put_Image.
* exp_attr.adb: Add support for Put_Image, by calling routines
in Exp_Put_Image.
* sem_util.adb (Is_Predefined_Dispatching_Operation): Return
True for new TSS_Put_Image operation.
* exp_ch3.adb: For tagged types, build a dispatching
TSS_Put_Image operation by calling routines in Exp_Put_Image.
* exp_disp.adb, exp_disp.ads: Make TSS_Put_Image be number 10,
adjusting other operations' numbers after 10. We choose 10
because that's the last number shared by all runtimes.
* exp_strm.adb: Use named notation as appropriate.
* exp_cg.adb, exp_tss.ads: Add TSS_Put_Image.
* libgnat/a-tags.ads: Modify Max_Predef_Prims for the new
TSS_Put_Image.
* impunit.adb: Add new runtime packages.
* rtsfind.adb, rtsfind.ads: Add support for
Ada.Strings.Text_Output, Ada.Strings.Text_Output.Utils, and
System.Put_Images.
* sem_attr.adb: Error checking for Put_Image calls.
* sem_ch12.adb (Valid_Default_Attribute): Support for passing
Put_Image as a generic formal parameter.
* sem_ch13.adb: Analysis of Put_Image aspect. Turn it into a
Put_Image attribute definition clause.
* sem_ch8.adb (Analyze_Subprogram_Renaming): Support for
renaming of the Put_Image attribute.
* snames.adb-tmpl: Fix comments.
* snames.ads-tmpl (Name_Put_Image): New Name_Id.
(Attribute_Put_Image): New Attribute_Id.
* tbuild.adb, tbuild.ads (Make_Increment): New utility.

patch.diff.gz
Description: application/gzip


[Ada] Import Adafinal as convention Ada

2020-06-04 Thread Pierre-Marie de Rodat
This is in general harmless but can cause inconsistencies on some
targets.

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

2020-06-04  Arnaud Charlet  

gcc/ada/

* bindgen.adb (Gen_Adafinal): Adafinal is convention Ada, not C.--- gcc/ada/bindgen.adb
+++ gcc/ada/bindgen.adb
@@ -457,7 +457,7 @@ package body Bindgen is
 
   if not Bind_For_Library and not CodePeer_Mode then
  WBI ("  procedure s_stalib_adafinal;");
- Set_String ("  pragma Import (C, s_stalib_adafinal, ");
+ Set_String ("  pragma Import (Ada, s_stalib_adafinal, ");
  Set_String ("""system__standard_library__adafinal"");");
  Write_Statement_Buffer;
   end if;



[Ada] Wrong walk order in Walk_Library_Items

2020-06-04 Thread Pierre-Marie de Rodat
We need to process the main spec later in Walk_Library_Items in order to
avoid forward references in e.g. CCG.

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

2020-06-04  Arnaud Charlet  

gcc/ada/

* sem.adb (Walk_Library_Items): Defer processing of main spec
after all other specs and before processing bodies.--- gcc/ada/sem.adb
+++ gcc/ada/sem.adb
@@ -1673,6 +1673,7 @@ package body Sem is
   pragma Pack (Unit_Number_Set);
 
   Main_CU : constant Node_Id := Cunit (Main_Unit);
+  Spec_CU : Node_Id := Empty;
 
   Seen, Done : Unit_Number_Set := (others => False);
   --  Seen (X) is True after we have seen unit X in the walk. This is used
@@ -2146,27 +2147,43 @@ package body Sem is
   null;
 
when others =>
-  Par := Scope (Defining_Entity (Unit (CU)));
-
-  if Is_Child_Unit (Defining_Entity (Unit (CU))) then
- while Present (Par)
-   and then Par /= Standard_Standard
-   and then Par /= Cunit_Entity (Main_Unit)
- loop
-Par := Scope (Par);
- end loop;
-  end if;
 
-  if Par /= Cunit_Entity (Main_Unit) then
- Do_Unit_And_Dependents (CU, N);
-  end if;
+  --  Skip spec of main unit for now, we want to process it
+  --  after all other specs.
+
+  if Nkind (Unit (CU)) = N_Package_Declaration
+and then Library_Unit (CU) = Main_CU
+and then CU /= Main_CU
+  then
+ Spec_CU := CU;
+  else
+ Par := Scope (Defining_Entity (Unit (CU)));
+
+ if Is_Child_Unit (Defining_Entity (Unit (CU))) then
+while Present (Par)
+  and then Par /= Standard_Standard
+  and then Par /= Cunit_Entity (Main_Unit)
+loop
+   Par := Scope (Par);
+end loop;
+ end if;
 
+ if Par /= Cunit_Entity (Main_Unit) then
+Do_Unit_And_Dependents (CU, N);
+ end if;
+  end if;
 end case;
  end;
 
  Next_Elmt (Cur);
   end loop;
 
+  --  Now process main package spec if skipped
+
+  if Present (Spec_CU) then
+ Do_Unit_And_Dependents (Spec_CU, Unit (Spec_CU));
+  end if;
+
   --  Now process package bodies on which main depends, followed by bodies
   --  of parents, if present, and finally main itself.
 



[Ada] Fix a couple of oversights in previous change

2020-06-04 Thread Pierre-Marie de Rodat
This adds a missing guard in Make_Final_Call for illegal cases and make
sure Build_Derived_Private_Type does a full derivation in the new
handled cases.

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

2020-06-04  Eric Botcazou  

gcc/ada/

* exp_ch7.adb (Make_Final_Call): Add missing guard.
* sem_ch3.adb (Copy_And_Build): Adjust recursive call for
private types.
(Build_Derived_Private_Type): Deal with underlying full views.--- gcc/ada/exp_ch7.adb
+++ gcc/ada/exp_ch7.adb
@@ -8290,6 +8290,7 @@ package body Exp_Ch7 is
  Ref  := Convert_Concurrent (Ref, Typ);
 
   elsif Is_Private_Type (Typ)
+and then Present (Underlying_Type (Typ))
 and then Is_Concurrent_Type (Underlying_Type (Typ))
   then
  Utyp := Corresponding_Record_Type (Underlying_Type (Typ));

--- gcc/ada/sem_ch3.adb
+++ gcc/ada/sem_ch3.adb
@@ -7735,9 +7735,13 @@ package body Sem_Ch3 is
end if;
 
 else
+   --  If the parent type is private, this is not a completion and
+   --  we build the full derivation recursively as a completion.
+
Build_Derived_Type
  (Full_N, Full_Parent, Full_Der,
-  Is_Completion => False, Derive_Subps => False);
+  Is_Completion => Is_Private_Type (Full_Parent),
+  Derive_Subps => False);
 end if;
 
 --  The full declaration has been introduced into the tree and
@@ -7925,7 +7929,9 @@ package body Sem_Ch3 is
  --  case (see point 5. of its head comment) since we build it for the
  --  derived subtype.
 
- if Present (Full_View (Parent_Type))
+ if (Present (Full_View (Parent_Type))
+ or else (Present (Underlying_Full_View (Parent_Type))
+   and then Is_Completion))
and then not Is_Itype (Derived_Type)
  then
 declare
@@ -7977,8 +7983,14 @@ package body Sem_Ch3 is
 end;
  end if;
 
-  elsif Present (Full_View (Parent_Type))
-and then Has_Discriminants (Full_View (Parent_Type))
+  elsif (Present (Full_View (Parent_Type))
+  and then
+ Has_Discriminants (Full_View (Parent_Type)))
+or else (Present (Underlying_Full_View (Parent_Type))
+  and then
+ Has_Discriminants (Underlying_Full_View (Parent_Type))
+  and then
+ Is_Completion)
   then
  if Has_Unknown_Discriminants (Parent_Type)
and then Nkind (Subtype_Indication (Type_Definition (N))) =



[Ada] Revamp dump and aux output names

2020-06-04 Thread Pierre-Marie de Rodat
This change accepts the new -dumpbase-ext and the preexisting -dumpdir
options as internal GCC options.

It also marks the obsolete -auxbase and -auxbase-strip options for
future removal.

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

2020-06-04  Alexandre Oliva  

gcc/ada/

* switch.adb (Is_Internal_GCC_Switch): Recognize dumpdir and
dumpbase-ext.  Mark auxbase and auxbase-strip for removal.--- gcc/ada/switch.adb
+++ gcc/ada/switch.adb
@@ -165,7 +165,10 @@ package body Switch is
   (Switch_Chars (First .. Last) = "-param"or else
Switch_Chars (First .. Last) = "dumpdir"   or else
Switch_Chars (First .. Last) = "dumpbase"  or else
-   Switch_Chars (First .. Last) = "dumpbase-ext");
+   Switch_Chars (First .. Last) = "dumpbase-ext"  or else
+   -- Can we remove auxbase-strip and auxbase already?
+   Switch_Chars (First .. Last) = "auxbase-strip" or else
+   Switch_Chars (First .. Last) = "auxbase");
end Is_Internal_GCC_Switch;
 
---



[Ada] Fix glitch for N_Delta_Aggregate/N_Case_Expression/N_Quantified_Expression

2020-06-04 Thread Pierre-Marie de Rodat
The Etype of the first 2 nodes is set during type resolution by
procedure Resolve_Delta_Aggregate and Resolve_Case_Expression, whereas
the Etype of the last one is not.

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

2020-06-04  Eric Botcazou  

gcc/ada/

* sinfo.ads (N_Delta_Aggregate): Document Etype field.
(N_Case_Expression): Likewise.
(Is_Syntactic_Field) : Adjust.
: Likewise.--- gcc/ada/sinfo.ads
+++ gcc/ada/sinfo.ads
@@ -4252,6 +4252,7 @@ package Sinfo is
   --  Sloc points to left parenthesis
   --  Expression (Node3)
   --  Component_Associations (List2)
+  --  Etype (Node5-Sem)
 
   --
   -- 4.4  Expression/Relation/Term/Factor/Primary --
@@ -4657,6 +4658,7 @@ package Sinfo is
   --  Sloc points to CASE
   --  Expression (Node3) (the selecting expression)
   --  Alternatives (List4) (the case expression alternatives)
+  --  Etype (Node5-Sem)
   --  Do_Overflow_Check (Flag17-Sem)
 
   
@@ -12118,7 +12120,7 @@ package Sinfo is
 2 => True,--  Iterator_Specification (Node2)
 3 => False,   --  unused
 4 => True,--  Loop_Parameter_Specification (Node4)
-5 => False),  --  Etype (Node5-Sem)
+5 => False),  --  unused
 
  N_Allocator =>
(1 => False,   --  Storage_Pool (Node1-Sem)
@@ -12174,7 +12176,7 @@ package Sinfo is
 2 => False,   --  unused
 3 => True,--  Expression (Node3)
 4 => True,--  Alternatives (List4)
-5 => False),  --  unused
+5 => False),  --  Etype (Node5-Sem)
 
  N_Case_Expression_Alternative =>
(1 => False,   --  Actions (List1-Sem)



[Ada] Fix Is_Absolute_Path on Windows

2020-06-04 Thread Pierre-Marie de Rodat
The Windows filename D:dir\name mean the path relative to drive D
current directory. Windows has current directory on each drive
separately. The D:dir\name was treated absolute before this fix.

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

2020-06-04  Dmitriy Anisimkov  

gcc/ada/

* adaint.c (__gnat_is_absolute_path): Check for directory
separator after drive and colon.
(IS_DIR_SEPARATOR): Define new inline substitution.--- gcc/ada/adaint.c
+++ gcc/ada/adaint.c
@@ -264,6 +264,9 @@ UINT __gnat_current_ccs_encoding;
 
 #ifndef DIR_SEPARATOR
 #define DIR_SEPARATOR '/'
+#define IS_DIR_SEPARATOR(c) ((c) == DIR_SEPARATOR)
+#else
+#define IS_DIR_SEPARATOR(c) ((c) == '/' || (c) == DIR_SEPARATOR)
 #endif
 
 /* Check for cross-compilation.  */
@@ -1709,9 +1712,10 @@ __gnat_is_absolute_path (char *name, int length)
   return 0;
 #else
   return (length != 0) &&
- (*name == '/' || *name == DIR_SEPARATOR
+ (IS_DIR_SEPARATOR(*name)
 #if defined (WINNT) || defined(__DJGPP__)
-  || (length > 1 && ISALPHA (name[0]) && name[1] == ':')
+  || (length > 2 && ISALPHA (name[0]) && name[1] == ':'
+  && IS_DIR_SEPARATOR(name[2]))
 #endif
 	  );
 #endif
@@ -2845,7 +2849,7 @@ __gnat_locate_file_with_predicate (char *file_name, char *path_val,
 
   /* If file_name include directory separator(s), try it first as
  a path name relative to the current directory */
-  for (ptr = file_name; *ptr && *ptr != '/' && *ptr != DIR_SEPARATOR; ptr++)
+  for (ptr = file_name; *ptr && !IS_DIR_SEPARATOR(*ptr); ptr++)
 ;
 
   if (*ptr != 0)
@@ -2886,7 +2890,7 @@ __gnat_locate_file_with_predicate (char *file_name, char *path_val,
   if (*ptr == '"')
 	ptr--;
 
-  if (*ptr != '/' && *ptr != DIR_SEPARATOR)
+  if (!IS_DIR_SEPARATOR(*ptr))
 *++ptr = DIR_SEPARATOR;
 
   strcpy (++ptr, file_name);



[Ada] Alignment clause ignored on completion derived from private type

2020-06-04 Thread Pierre-Marie de Rodat
This fixes the discrepancy visible between an alignment clause put
on a type derived from a private type and an alignment clause put
on a completion derived from the same private type, for example:

with System.OS_Interface;

package P is
  type T is limited private;
  type V is new System.OS_Interface.pthread_mutex_t;
  for V'Alignment use 64;
private
  type T is new System.OS_Interface.pthread_mutex_t;
  for T'Alignment use 64;
end P;

Whereas the alignment clause on V is honored, the one on T is ignored.

This discrepancy occurs because the front-end builds an implicit full
view for V, derived from the full view of the parent, that can carry
the alignment, but it doesn't do it for T; as a matter of fact, that's
correct because a completion cannot have a full view since it's itself
the full view of another entity, but it can have an _underlying_ full
view, which happens in other circumstances (discriminated types).

Therefore the change causes the front-end to build an underlying full
view in this case too and to propagate the alignment clause down to it.
This has exposed a small breach of privacy when such a chain of views
is itself derived, which is fixed.  This also has required adjustments
in the handling of Type Support Subprograms (TSS) to look up the new
underlying full views.

This causes more entities to be generated in the front-end, but the
increase should be small on average because these cases are rare.

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

2020-06-04  Eric Botcazou  

gcc/ada/

* exp_attr.adb (xpand_N_Attribute_Reference) : Call
Find_Inherited_TSS to look up the Stream_Read TSS.
: Likewise for the Stream_Write TSS.
* exp_ch7.adb (Make_Final_Call): Call Underlying_Type on
private types to account for underlying full views.
* exp_strm.ads  (Build_Record_Or_Elementary_Input_Function):
Remove Use_Underlying parameter.
* exp_strm.adb (Build_Record_Or_Elementary_Input_Function):
Likewise and adjust accordingly.
* exp_tss.adb (Find_Inherited_TSS): Deal with full views.
Call Find_Inherited_TSS recursively on the parent type if
the base type is a derived type.
* sem_ch13.adb (Analyze_Attribute_Definition_Clause): Take
into account underlying full views for derived types.
* sem_ch3.adb (Copy_And_Build): Look up the underlying full
view only for a completion.  Be prepared for private types.
(Build_Derived_Private_Type): Build an underlying full view
for a completion in the general case too.--- gcc/ada/exp_attr.adb
+++ gcc/ada/exp_attr.adb
@@ -3879,26 +3879,18 @@ package body Exp_Attr is
--  A special case arises if we have a defined _Read routine,
--  since in this case we are required to call this routine.
 
-   declare
-  Typ : Entity_Id := P_Type;
-   begin
-  if Present (Full_View (Typ)) then
- Typ := Full_View (Typ);
-  end if;
+   if Present (Find_Inherited_TSS (P_Type, TSS_Stream_Read)) then
+  Build_Record_Or_Elementary_Input_Function
+(Loc, P_Type, Decl, Fname);
+  Insert_Action (N, Decl);
 
-  if Present (TSS (Base_Type (Typ), TSS_Stream_Read)) then
- Build_Record_Or_Elementary_Input_Function
-   (Loc, Typ, Decl, Fname, Use_Underlying => False);
- Insert_Action (N, Decl);
+   --  For normal cases, we call the I_xxx routine directly
 
-  --  For normal cases, we call the I_xxx routine directly
-
-  else
- Rewrite (N, Build_Elementary_Input_Call (N));
- Analyze_And_Resolve (N, P_Type);
- return;
-  end if;
-   end;
+   else
+  Rewrite (N, Build_Elementary_Input_Call (N));
+  Analyze_And_Resolve (N, P_Type);
+  return;
+   end if;
 
 --  Array type case
 
@@ -4985,26 +4977,18 @@ package body Exp_Attr is
--  A special case arises if we have a defined _Write routine,
--  since in this case we are required to call this routine.
 
-   declare
-  Typ : Entity_Id := P_Type;
-   begin
-  if Present (Full_View (Typ)) then
- Typ := Full_View (Typ);
-  end if;
-
-  if Present (TSS (Base_Type (Typ), TSS_Stream_Write)) then
- Build_Record_Or_Elementary_Output_Procedure
-   (Loc, Typ, Decl, Pname);
- Insert_Action (N, Decl);
+   if Present (Find_Inherited_TSS (P_Type, TSS_Stream_Write)) then
+  Build_Record_Or_Elementary_Output_Procedure
+   

[Ada] Missing accessibility check on access discriminant in extended return

2020-06-04 Thread Pierre-Marie de Rodat
This patch fixes an issue whereby the compiler may fail to issue static
accessibility errors on access discriminants within subtype indications
within extended return statements.

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

2020-06-04  Justin Squirek  

gcc/ada/

* sem_ch6.adb (Check_Return_Obj_Accessibility): Change to
Check_Return_Construct_Accessibility to better reflect its
purpose.  Add loop to properly obtain the object declaration
from an expanded extended return statement and add calls to get
the original node for associated values. Also, avoid checks when
the return statement being examined comes from an internally
generated function.--- gcc/ada/sem_ch6.adb
+++ gcc/ada/sem_ch6.adb
@@ -696,7 +696,7 @@ package body Sem_Ch6 is
   R_Type : constant Entity_Id := Etype (Scope_Id);
   --  Function result subtype
 
-  procedure Check_Return_Obj_Accessibility (Return_Stmt : Node_Id);
+  procedure Check_Return_Construct_Accessibility (Return_Stmt : Node_Id);
   --  Apply legality rule of 6.5 (5.9) to the access discriminants of an
   --  aggregate in a return statement.
 
@@ -704,24 +704,26 @@ package body Sem_Ch6 is
   --  Check that the return_subtype_indication properly matches the result
   --  subtype of the function, as required by RM-6.5(5.1/2-5.3/2).
 
-  
-  -- Check_Return_Obj_Accessibility --
-  
+  --
+  -- Check_Return_Construct_Accessibility --
+  --
 
-  procedure Check_Return_Obj_Accessibility (Return_Stmt : Node_Id) is
+  procedure Check_Return_Construct_Accessibility (Return_Stmt : Node_Id) is
  Assoc : Node_Id;
  Agg   : Node_Id := Empty;
  Discr : Entity_Id;
  Expr  : Node_Id;
  Obj   : Node_Id;
  Process_Exprs : Boolean := False;
- Return_Obj: Node_Id;
+ Return_Con: Node_Id;
 
   begin
- --  Only perform checks on record types with access discriminants
+ --  Only perform checks on record types with access discriminants and
+ --  non-internally generated functions.
 
  if not Is_Record_Type (R_Type)
or else not Has_Discriminants (R_Type)
+   or else not Comes_From_Source (Return_Stmt)
  then
 return;
  end if;
@@ -738,32 +740,47 @@ package body Sem_Ch6 is
  --  simple return statement the expression is part of the node.
 
  if Nkind (Return_Stmt) = N_Extended_Return_Statement then
-Return_Obj := Last (Return_Object_Declarations (Return_Stmt));
+--  Obtain the object definition from the expanded extended return
 
---  We could be looking at something that's been expanded with
---  an initialzation procedure which we can safely ignore.
+Return_Con := First (Return_Object_Declarations (Return_Stmt));
+while Present (Return_Con) loop
+   --  Inspect the original node to avoid object declarations
+   --  expanded into renamings.
 
-if Nkind (Return_Obj) /= N_Object_Declaration then
-   return;
-end if;
+   if Nkind (Original_Node (Return_Con)) = N_Object_Declaration
+ and then Comes_From_Source (Original_Node (Return_Con))
+   then
+  exit;
+   end if;
+
+   Nlists.Next (Return_Con);
+end loop;
+
+pragma Assert (Present (Return_Con));
+
+--  Could be dealing with a renaming
+
+Return_Con := Original_Node (Return_Con);
  else
-Return_Obj := Return_Stmt;
+Return_Con := Return_Stmt;
  end if;
 
  --  We may need to check an aggregate or a subtype indication
  --  depending on how the discriminants were specified and whether
  --  we are looking at an extended return statement.
 
- if Nkind (Return_Obj) = N_Object_Declaration
-   and then Nkind (Object_Definition (Return_Obj))
+ if Nkind (Return_Con) = N_Object_Declaration
+   and then Nkind (Object_Definition (Return_Con))
   = N_Subtype_Indication
  then
-Assoc := First (Constraints
- (Constraint (Object_Definition (Return_Obj;
+Assoc := Original_Node
+   (First
+ (Constraints
+   (Constraint (Object_Definition (Return_Con);
  else
 --  Qualified expressions may be nested
 
-Agg := Original_Node (Expression (Return_Obj));
+Agg := Original_Node (Expression (Return_Con));
 while Nkind (Agg) = 

[Ada] Add missing conversion in call to Finalize primitive

2020-06-04 Thread Pierre-Marie de Rodat
This makes sure that Convert_View adds the unchecked conversion from
actual to formal type in the case where the type of the actual is
derived from a private formal type and for the Finalize primitive; the
same trick is already used for the call to the Adjust primitive.

That's necessary since Underlying_Type returns the Underlying_Full_View
of a type derived from a private type, when it exists, instead of the
Full_View of the parent type.

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

2020-06-04  Eric Botcazou  

gcc/ada/

* exp_ch7.adb (Make_Final_Call): Set the type of the object, if
it is unanalyzed, before calling Convert_View on it.--- gcc/ada/exp_ch7.adb
+++ gcc/ada/exp_ch7.adb
@@ -8432,6 +8432,15 @@ package body Exp_Ch7 is
end if;
 end;
 
+--  If the object is unanalyzed, set its expected type for use in
+--  Convert_View in case an additional conversion is needed.
+
+if No (Etype (Ref))
+  and then Nkind (Ref) /= N_Unchecked_Type_Conversion
+then
+   Set_Etype (Ref, Typ);
+end if;
+
 Ref := Convert_View (Fin_Id, Ref);
  end if;
 



[Ada] Implement AI12-0275 (Make subtype_mark optional in object renamings)

2020-06-04 Thread Pierre-Marie de Rodat
This set of changes implements the Ada 202X shorthand feature of object
renamings that don't specify an explicit subtype (they have neither a
subtype_mark nor an access_definition), taking their subtype from the
renamed object (which must be denoted by an unambiguous name).

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

2020-06-04  Gary Dismukes  

gcc/ada/

* par-ch3.adb (P_Identifier_Declarations): Add parsing of object
renamings that have neither a subtype_mark nor an
access_definition. Issue an error if the version is earlier than
Ada_2020, and suggest using -gnatX.
* sem_ch8.adb (Analyze_Object_Renaming): Handle
object_renaming_declarations that don't have an explicit
subtype. Errors are issued when the name is inappropriate or
ambiguous, and otherwise the Etype of the renaming entity is set
from the Etype of the renamed object.
* sem_util.adb (Has_Null_Exclusion): Allow for the case of no
subtype given in an N_Object_Renaming_Declaration.
* sprint.adb (Sprint_Node_Actual): Handle printing of
N_Object_Renaming_Declarations that are specified without an
explicit subtype.--- gcc/ada/par-ch3.adb
+++ gcc/ada/par-ch3.adb
@@ -1480,6 +1480,32 @@ package body Ch3 is
  Done := False;
  return;
 
+  --  AI12-0275: Object renaming declaration without subtype_mark or
+  --  access_definition
+
+  elsif Token = Tok_Renames then
+ if Ada_Version < Ada_2020 then
+Error_Msg_SC
+  ("object renaming without subtype is an Ada 202x feature");
+Error_Msg_SC ("\compile with -gnatX");
+ end if;
+
+ Scan; -- past renames
+
+ Decl_Node :=
+   New_Node (N_Object_Renaming_Declaration, Ident_Sloc);
+ Set_Name (Decl_Node, P_Name);
+ Set_Defining_Identifier (Decl_Node, Idents (1));
+
+ P_Aspect_Specifications (Decl_Node, Semicolon => False);
+
+ T_Semicolon;
+
+ Append (Decl_Node, Decls);
+ Done := False;
+
+ return;
+
   --  Otherwise we have an error situation
 
   else

--- gcc/ada/sem_ch8.adb
+++ gcc/ada/sem_ch8.adb
@@ -906,10 +906,108 @@ package body Sem_Ch8 is
 Find_Type (Subtype_Mark (N));
  end if;
 
-  elsif Present (Subtype_Mark (N)) then
- Find_Type (Subtype_Mark (N));
- T := Entity (Subtype_Mark (N));
- Analyze (Nam);
+  elsif Present (Subtype_Mark (N))
+or else not Present (Access_Definition (N))
+  then
+ if Present (Subtype_Mark (N)) then
+Find_Type (Subtype_Mark (N));
+T := Entity (Subtype_Mark (N));
+Analyze (Nam);
+
+ --  AI12-0275: Case of object renaming without a subtype_mark
+
+ else
+Analyze (Nam);
+
+--  Normal case of no overloading in object name
+
+if not Is_Overloaded (Nam) then
+
+   --  Catch error cases (such as attempting to rename a procedure
+   --  or package) using the shorthand form.
+
+   if No (Etype (Nam))
+ or else Etype (Nam) = Standard_Void_Type
+   then
+  Error_Msg_N ("object name expected in renaming", Nam);
+
+  Set_Ekind (Id, E_Variable);
+  Set_Etype (Id, Any_Type);
+
+  return;
+
+   else
+  T := Etype (Nam);
+   end if;
+
+--  Case of overloaded name, which will be illegal if there's more
+--  than one acceptable interpretation (such as overloaded function
+--  calls).
+
+else
+   declare
+  I: Interp_Index;
+  I1   : Interp_Index;
+  It   : Interp;
+  It1  : Interp;
+  Nam1 : Entity_Id;
+
+   begin
+  --  More than one candidate interpretation is available
+
+  --  Remove procedure calls, which syntactically cannot appear
+  --  in this context, but which cannot be removed by type
+  --  checking, because the context does not impose a type.
+
+  Get_First_Interp (Nam, I, It);
+  while Present (It.Typ) loop
+ if It.Typ = Standard_Void_Type then
+Remove_Interp (I);
+ end if;
+
+ Get_Next_Interp (I, It);
+  end loop;
+
+  Get_First_Interp (Nam, I, It);
+  I1  := I;
+  It1 := It;
+
+  --  If there's no type present, we have an error case (such
+  --  as overloaded procedures named in the object renaming).
+
+  if No (It.Typ) then
+ Error_Msg_N ("object name expected in renaming", Nam);
+
+ Set_Ekind 

[Ada] Add another ad-hoc case to the Has_Private_View mechanism

2020-06-04 Thread Pierre-Marie de Rodat
This adds another ad-hoc treatment to Copy_Generic_Node for the case of
type conversions involving access types designing private types, when
the Designated_Type is not referenced in the generic tree.

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

2020-06-04  Eric Botcazou  

gcc/ada/

* sem_ch12.adb (Copy_Generic_Node): Add special handling for a
conversion between access types.--- gcc/ada/sem_ch12.adb
+++ gcc/ada/sem_ch12.adb
@@ -7900,6 +7900,37 @@ package body Sem_Ch12 is
  Sloc (N)));
end if;
 end;
+
+ --  Here is a similar case, for the Designated_Type of an
+ --  access type that is present as target type in a type
+ --  conversion from another access type. In this case, if
+ --  the base types of the designated types are different
+ --  and the conversion was accepted during the semantic
+ --  analysis of the generic, this means that the target
+ --  type cannot have been private (see Valid_Conversion).
+
+ elsif Nkind (Assoc) = N_Identifier
+   and then Nkind (Parent (Assoc)) = N_Type_Conversion
+   and then Subtype_Mark (Parent (Assoc)) = Assoc
+   and then Is_Access_Type (Etype (Assoc))
+   and then Present (Etype (Expression (Parent (Assoc
+   and then
+ Is_Access_Type (Etype (Expression (Parent (Assoc
+ then
+declare
+   Targ_Desig : constant Entity_Id :=
+ Designated_Type (Etype (Assoc));
+   Expr_Desig : constant Entity_Id :=
+ Designated_Type
+   (Etype (Expression (Parent (Assoc;
+begin
+   if Base_Type (Targ_Desig) /= Base_Type (Expr_Desig)
+ and then Is_Private_Type (Targ_Desig)
+   then
+  Check_Private_View
+(New_Occurrence_Of (Targ_Desig, Sloc (N)));
+   end if;
+end;
  end if;
 
   --  The node is a reference to a global type and acts as the



[Ada] New procedure Register_Global_Unhandled_Action

2020-06-04 Thread Pierre-Marie de Rodat
Provided to enhance the GNAT.Exception_Actions API and allowing
registration of an action on unhandled exceptions (e.g. Core_Dump).

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

2020-06-04  Arnaud Charlet  

gcc/ada/

* libgnat/a-exextr.adb (Global_Unhandled_Action): New global
variable.
(Notify_Exception): Take into account Global_Unhandled_Action
and fix latent race condition.
(Exception_Action): Mark Favor_Top_Level so that variables can
be atomic.
(Global_Action): Mark atomic to remove the need for a lock.
* libgnat/g-excact.ads, libgnat/g-excact.adb
(Register_Global_Unhandled_Action): New procedure.
(Register_Global_Action): Remove lock.
* libgnat/s-stalib.ads (Raise_Action): Mark Favor_Top_Level to
be compatible with Exception_Action.
* sem_warn.adb (Warn_On_Unreferenced_Entity): Fix logic wrt
Volatile entities and entities with an address clause: the code
did not match the comment/intent.--- gcc/ada/libgnat/a-exextr.adb
+++ gcc/ada/libgnat/a-exextr.adb
@@ -43,12 +43,23 @@ package body Exception_Traces is
--  Convenient shortcut
 
type Exception_Action is access procedure (E : Exception_Occurrence);
+   pragma Favor_Top_Level (Exception_Action);
+
Global_Action : Exception_Action := null;
+   pragma Atomic (Global_Action);
pragma Export
  (Ada, Global_Action, "__gnat_exception_actions_global_action");
--  Global action, executed whenever an exception is raised.  Changing the
--  export name must be coordinated with code in g-excact.adb.
 
+   Global_Unhandled_Action : Exception_Action := null;
+   pragma Atomic (Global_Unhandled_Action);
+   pragma Export
+ (Ada, Global_Unhandled_Action,
+  "__gnat_exception_actions_global_unhandled_action");
+   --  Global action, executed whenever an unhandled exception is raised.
+   --  Changing the export name must be coordinated with code in g-excact.adb.
+
Raise_Hook_Initialized : Boolean := False;
pragma Export
  (Ada, Raise_Hook_Initialized, "__gnat_exception_actions_initialized");
@@ -77,6 +88,11 @@ package body Exception_Traces is
--
 
procedure Notify_Exception (Excep : EOA; Is_Unhandled : Boolean) is
+  --  Save actions locally to avoid any race condition that would
+  --  reset them to null.
+  Action   : constant Exception_Action := Global_Action;
+  Unhandled_Action : constant Exception_Action := Global_Unhandled_Action;
+
begin
   --  Output the exception information required by the Exception_Trace
   --  configuration. Take care not to output information about internal
@@ -119,8 +135,12 @@ package body Exception_Traces is
  To_Action (Exception_Data_Ptr (Excep.Id).Raise_Hook) (Excep.all);
   end if;
 
-  if Global_Action /= null then
- Global_Action (Excep.all);
+  if Is_Unhandled and Unhandled_Action /= null then
+ Unhandled_Action (Excep.all);
+  end if;
+
+  if Action /= null then
+ Action (Excep.all);
   end if;
end Notify_Exception;
 

--- gcc/ada/libgnat/g-excact.adb
+++ gcc/ada/libgnat/g-excact.adb
@@ -38,9 +38,19 @@ with System.Exception_Table;  use System.Exception_Table;
 package body GNAT.Exception_Actions is
 
Global_Action : Exception_Action;
-   pragma Import (C, Global_Action, "__gnat_exception_actions_global_action");
+   pragma Import
+ (Ada, Global_Action, "__gnat_exception_actions_global_action");
+   pragma Atomic (Global_Action);
--  Imported from Ada.Exceptions. Any change in the external name needs to
-   --  be coordinated with a-except.adb
+   --  be coordinated with a-exextr.adb.
+
+   Global_Unhandled_Action : Exception_Action;
+   pragma Import
+ (Ada, Global_Unhandled_Action,
+  "__gnat_exception_actions_global_unhandled_action");
+   pragma Atomic (Global_Unhandled_Action);
+   --  Imported from Ada.Exceptions. Any change in the external name needs to
+   --  be coordinated with a-exextr.adb.
 
Raise_Hook_Initialized : Boolean;
pragma Import
@@ -61,11 +71,18 @@ package body GNAT.Exception_Actions is
 
procedure Register_Global_Action (Action : Exception_Action) is
begin
-  Lock_Task.all;
   Global_Action := Action;
-  Unlock_Task.all;
end Register_Global_Action;
 
+   --
+   -- Register_Global_Unhandled_Action --
+   --
+
+   procedure Register_Global_Unhandled_Action (Action : Exception_Action) is
+   begin
+  Global_Unhandled_Action := Action;
+   end Register_Global_Unhandled_Action;
+

-- Register_Id_Action --


--- gcc/ada/libgnat/g-excact.ads
+++ gcc/ada/libgnat/g-excact.ads
@@ -57,6 +57,7 @@ package GNAT.Exception_Actions is
 
type Exception_Action is access
  procedure (Occurrence : Exception_Occurrence);
+   pragma 

[Ada] Remove System.Parameters.Single_Lock

2020-06-04 Thread Pierre-Marie de Rodat
This setting has never been used in practice and isn't tested, so remove
it.

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

2020-06-04  Arnaud Charlet  

gcc/ada/

* libgnarl/a-dynpri.adb, libgnarl/a-taside.adb,
libgnarl/a-taster.adb, libgnarl/s-interr.adb,
libgnarl/s-interr__sigaction.adb, libgnarl/s-taasde.adb,
libgnarl/s-taenca.adb, libgnarl/s-taenca.ads,
libgnarl/s-taprop.ads, libgnarl/s-taprop__hpux-dce.adb,
libgnarl/s-taprop__linux.adb, libgnarl/s-taprop__mingw.adb,
libgnarl/s-taprop__posix.adb, libgnarl/s-taprop__qnx.adb,
libgnarl/s-taprop__solaris.adb, libgnarl/s-taprop__vxworks.adb,
libgnarl/s-tarest.adb, libgnarl/s-tasini.adb,
libgnarl/s-tasque.adb, libgnarl/s-tasque.ads,
libgnarl/s-tasren.adb, libgnarl/s-tasren.ads,
libgnarl/s-tassta.adb, libgnarl/s-tasuti.adb,
libgnarl/s-tasuti.ads, libgnarl/s-tpoben.adb,
libgnarl/s-tpobop.adb, libgnarl/s-tpopmo.adb,
libgnarl/s-tposen.adb, libgnat/s-parame.ads,
libgnat/s-parame__ae653.ads, libgnat/s-parame__hpux.ads,
libgnat/s-parame__vxworks.ads: Remove references to Single_Lock
and Global_Lock.

patch.diff.gz
Description: application/gzip


[Ada] Set convention and inlined flag on default null procedure

2020-06-04 Thread Pierre-Marie de Rodat
This slightly tweaks the null procedure generated for a subprogram
default in a generic instantiation: as per RM 12.6 (16 2/2), the
convention is explicitly set to Intrinsic, and the procedure is also
marked inlined.

This has two main effects: first, to help the algorithm computing the
setting of the Is_Public flag in the presence of inlined subprograms,
because this null procedure is somewhat irregular (its body is in the
spec of the package generated for the instantiation); second, to make
sure that the calls to the procedure are eliminated when optimization
is enabled, which seems the right thing to do.

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

2020-06-04  Eric Botcazou  

gcc/ada/

* sem_attr.adb (Resolve_Attribute) : Do not generate
the secondary message about a missing pragma if the convention
of the prefix is Intrinsic.
* sem_ch12.adb (Instantiate_Formal_Subprogram): Only set the
Convention and the Is_Inlined flag on a null procedure.--- gcc/ada/sem_attr.adb
+++ gcc/ada/sem_attr.adb
@@ -10678,6 +10678,7 @@ package body Sem_Attr is
 
  if not Is_Itype (Btyp)
and then not Has_Convention_Pragma (Btyp)
+   and then Convention (Entity (P)) /= Convention_Intrinsic
  then
 Error_Msg_FE
   ("\probable missing pragma Convention for &",

--- gcc/ada/sem_ch12.adb
+++ gcc/ada/sem_ch12.adb
@@ -10785,7 +10785,13 @@ package body Sem_Ch12 is
Make_Handled_Sequence_Of_Statements (Loc,
  Statements => New_List (Make_Null_Statement (Loc;
 
- Set_Is_Intrinsic_Subprogram (Defining_Unit_Name (New_Spec));
+ --  RM 12.6 (16 2/2): The procedure has convention Intrinsic
+
+ Set_Convention (Defining_Unit_Name (New_Spec), Convention_Intrinsic);
+
+ --  Eliminate the calls to it when optimization is enabled
+
+ Set_Is_Inlined (Defining_Unit_Name (New_Spec));
  return Decl_Node;
 
   else



[Ada] Small tweak to special handling of private index types

2020-06-04 Thread Pierre-Marie de Rodat
This both extends the special handling applied to private index types
in array type declarations to generic packages and restricts it to the
index types defined in the same scope as the array type, which is the
original intent of the code.

This fixes the discrepancy between the direct compilation of generic
packages, which would fail, and the compilation of instantiations of
these packages, which would succeed, in peculiar cases.

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

2020-06-04  Eric Botcazou  

gcc/ada/

* sem_ch3.adb (Array_Type_Declaration): Apply special handling
of private index types to generic packages and restrict it to
index types defined in the current scope.--- gcc/ada/sem_ch3.adb
+++ gcc/ada/sem_ch3.adb
@@ -6137,7 +6137,7 @@ package body Sem_Ch3 is
  end if;
 
  --  Add a subtype declaration for each index of private array type
- --  declaration whose etype is also private. For example:
+ --  declaration whose type is also private. For example:
 
  -- package Pkg is
  --type Index is private;
@@ -6147,11 +6147,14 @@ package body Sem_Ch3 is
 
  --  This is currently required by the expander for the internally
  --  generated equality subprogram of records with variant parts in
- --  which the etype of some component is such private type.
+ --  which the type of some component is such a private type. And it
+ --  also helps semantic analysis in peculiar cases where the array
+ --  type is referenced from an instance but not the index directly.
 
- if Ekind (Current_Scope) = E_Package
+ if Is_Package_Or_Generic_Package (Current_Scope)
and then In_Private_Part (Current_Scope)
and then Has_Private_Declaration (Etype (Index))
+   and then Scope (Etype (Index)) = Current_Scope
  then
 declare
Loc   : constant Source_Ptr := Sloc (Def);



[Ada] Fix fallout of cleanup to Has_Private_View mechanism

2020-06-04 Thread Pierre-Marie de Rodat
The Has_Private_View mechanism is also applied to actuals of the
instantiations and there is the same issue for array type actuals whose
component type is the actual of a preceding formal as for global types
whose component type is not referenced in the tree.

This can happen for nested instantiations and in this case we can simply
restore the views of the actuals of the parent instances.

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

2020-06-04  Eric Botcazou  

gcc/ada/

* sem_ch12.adb (Check_Generic_Actuals): Also restore the proper
views of the actuals of the parent instances if the formals are
used as actuals of the children.
(Instantiate_Type): Add comment.--- gcc/ada/sem_ch12.adb
+++ gcc/ada/sem_ch12.adb
@@ -6802,8 +6802,35 @@ package body Sem_Ch12 is
and then Scope (Etype (E)) /= Instance
and then Is_Entity_Name (Subtype_Indication (Parent (E)))
  then
+--  Restore the proper view of the actual from the information
+--  saved earlier by Instantiate_Type.
+
 Check_Private_View (Subtype_Indication (Parent (E)));
 
+--  If the actual is itself the formal of a parent instance,
+--  then also restore the proper view of its actual and so on.
+--  That's necessary for nested instantiations of the form
+
+--generic
+--  type Component is private;
+--  type Array_Type is array (Positive range <>) of Component;
+--procedure Proc;
+
+--  when the outermost actuals have inconsistent views, because
+--  the Component_Type of Array_Type of the inner instantiations
+--  is the actual of Component of the outermost one and not that
+--  of the corresponding inner instantiations.
+
+Astype := Ancestor_Subtype (E);
+while Present (Astype)
+  and then Nkind (Parent (Astype)) = N_Subtype_Declaration
+  and then Present (Generic_Parent_Type (Parent (Astype)))
+  and then Is_Entity_Name (Subtype_Indication (Parent (Astype)))
+loop
+   Check_Private_View (Subtype_Indication (Parent (Astype)));
+   Astype := Ancestor_Subtype (Astype);
+end loop;
+
 Set_Is_Generic_Actual_Type (E);
 
 if Is_Private_Type (E) and then Present (Full_View (E)) then
@@ -13603,6 +13630,10 @@ package body Sem_Ch12 is
   Defining_Identifier => Subt,
   Subtype_Indication  => New_Occurrence_Of (Act_T, Loc));
 
+  --  Record whether the actual is private at this point, so that
+  --  Check_Generic_Actuals can restore its proper view before the
+  --  semantic analysis of the instance.
+
   if Is_Private_Type (Act_T) then
  Set_Has_Private_View (Subtype_Indication (Decl_Node));
   end if;



[Ada] Avoid buffer overflow in Long_Long_Float_Text_IO

2020-06-04 Thread Pierre-Marie de Rodat
The internal packages used to implement Ada.Text_IO.Float_IO declare
some String variables that need to be large enough to hold the longest
possible images computed by Float_IO. If Exp is specified to be zero and
Aft is specified to be Text_IO.Field'Last then the computed image of
Long_Long_Float'Last requires slightly less than 5200 characters.
Change the bounds of these String variables so that they are large
enough to support this case.

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

2020-06-04  Steve Baird  

gcc/ada/

* libgnat/s-imgrea.ads: Declare a named number
Max_Real_Image_Length with value 5200.  Provide a comment
explaining why this value was chosen.
* libgnat/s-imgrea.adb (Set_Image_Real): Increase the upper
bound of the local String variable Digs to
Max_Real_Image_Length.
* libgnat/a-tiflau.adb (Put): Increase the upper bound of the
local String variable Buf to Max_Real_Image_Length.
(Puts): Increase the upper bound of the local String variable
Buf to Max_Real_Image_Length.--- gcc/ada/libgnat/a-tiflau.adb
+++ gcc/ada/libgnat/a-tiflau.adb
@@ -194,7 +194,7 @@ package body Ada.Text_IO.Float_Aux is
   Aft  : Field;
   Exp  : Field)
is
-  Buf : String (1 .. 3 * Field'Last + 2);
+  Buf : String (1 .. Max_Real_Image_Length);
   Ptr : Natural := 0;
 
begin
@@ -212,7 +212,7 @@ package body Ada.Text_IO.Float_Aux is
   Aft  : Field;
   Exp  : Field)
is
-  Buf : String (1 .. 3 * Field'Last + 2);
+  Buf : String (1 .. Max_Real_Image_Length);
   Ptr : Natural := 0;
 
begin

--- gcc/ada/libgnat/s-imgrea.adb
+++ gcc/ada/libgnat/s-imgrea.adb
@@ -151,14 +151,9 @@ package body System.Img_Real is
   Scale : Integer;
   Expon : Integer;
 
-  Field_Max : constant := 255;
-  --  This should be the same value as Ada.[Wide_]Text_IO.Field'Last.
-  --  It is not worth dragging in Ada.Text_IO to pick up this value,
-  --  since it really should never be necessary to change it.
-
-  Digs : String (1 .. 2 * Field_Max + 16);
-  --  Array used to hold digits of converted integer value. This is a
-  --  large enough buffer to accommodate ludicrous values of Fore and Aft.
+  Digs : String (1 .. Max_Real_Image_Length);
+  --  Array used to hold digits of converted integer value. This is a large
+  --  enough buffer to accommodate ludicrous Fore/Aft/Exp combinations.
 
   Ndigs : Natural;
   --  Number of digits stored in Digs (and also subscript of last digit)

--- gcc/ada/libgnat/s-imgrea.ads
+++ gcc/ada/libgnat/s-imgrea.ads
@@ -73,4 +73,9 @@ package System.Img_Real is
--  can be set to any valid values for the case of use from Text_IO. Note
--  that no space is stored at the start for non-negative values.
 
+   Max_Real_Image_Length : constant := 5200;
+   --   If Exp is set to zero and Aft is set to Text_IO.Field'Last (i.e., 255)
+   --   then Long_Long_Float'Last generates an image whose length is
+   --   slightly less than 5200.
+
 end System.Img_Real;



Re: [Patch] Inline optimization for tanh(x)/sinh(x) -> 1.0/cosh(x)

2020-06-04 Thread Christophe Lyon via Gcc-patches
Hi,

On Thu, 4 Jun 2020 at 01:03, Jeff Law via Gcc-patches
 wrote:
>
> On Fri, 2020-01-31 at 15:50 -0300, Vitor Guidi wrote:
> > I took the required steps. The patch is attached to this email, I hope
> > I got it right this time. I did not forward the patch to gcc-patches
> > the first time, sorry for the inconvenience.
> >
> > Thank you for your attention,
> >
> > Vitor.
> >
> > in gcc/ChangeLog:
> > 2020-01-28 Vitor Guidi 
> > * match.pd: New substitution rule for tanh(x)/sinh(x) ->
> > 1.0/cosh(x).
> >
> > in gcc/testsuite/ChangeLog:
> > 2020-01-28 Vitor Guidi 
> > *gcc.dg/tanhbysinh.c (new): New testcase.
> Thanks.  I've installed this on the trunk.  Sorry for the delays.

The new test fails on bare-metal targets (with newlib) such as
arm-eabi, aarch64-elf, moxie and pru:
PASS: gcc.dg/tanhbysinh.c (test for excess errors)
PASS: gcc.dg/tanhbysinh.c scan-tree-dump optimized "cosh "
FAIL: gcc.dg/tanhbysinh.c scan-tree-dump optimized "coshf "
FAIL: gcc.dg/tanhbysinh.c scan-tree-dump optimized "coshl "

I didn't check the dumps manually; why does the optimization depend on
the lib version?

Thanks

Christophe

>
> jeff
> >
>


Re: std::optional defaut constructor

2020-06-04 Thread Marc Glisse

On Thu, 4 Jun 2020, Ville Voutilainen wrote:


On Thu, 4 Jun 2020 at 11:00, Marc Glisse  wrote:

Maybe create a buffer, fill it with some non-zero values (-1?), then call
placement new, and read some value in the middle of the buffer, possibly
with some protection against optimizations? Ah, no, actual constructors
are fine, it is only the inlined initialization that happens with the
defaulted constructor that zeroes things.


The zero-init is part of value-initialization of a class type with a 
defaulted default constructor, so value-initialization with placement 
new should indeed show us whether the target buffer is zeroed.


Ah, yes, I had forgotten the empty () at the end of the operator new line 
when testing. Now the patch makes this runtime test go from abort to 
success at -O0 (with optimizations, the memset is removed as dead code). I 
am still not sure we want this kind of test though. And I added launder 
more to quiet a warning than with confidence that it does the right thing.


#include 
struct A {
  int a[1024];
};
typedef std::optional O;
int main(){
  unsigned char t[sizeof(O)];
  __builtin_memset(t, -1, sizeof(t));
  new(t)O();
  if(std::launder(t)[512] != (unsigned char)(-1)) __builtin_abort();
}

--
Marc Glisse


Re: [PATCH] Add pattern for pointer-diff on addresses with same base/offset (PR 94234)

2020-06-04 Thread Richard Biener via Gcc-patches
On Wed, Jun 3, 2020 at 4:33 PM Marc Glisse  wrote:
>
> On Wed, 3 Jun 2020, Feng Xue OS via Gcc-patches wrote:
>
> >> Ah, looking at the PR, you decided to perform the operation as unsigned
> >> because that has fewer NOP conversions, which, in that particular testcase
> >> where the offsets are originally unsigned, means we simplify better. But I
> >> would expect it to regress other testcases (in particular if the offsets
> >> were originally signed). Also, changing the second argument of
> >> pointer_plus to be signed, as is supposed to eventually happen, would
> >> break your testcase again.
> > The old rule might produce overflow result (offset_a = (signed_int_max)UL,
> > offset_b = 1UL).
>
> signed_int_max-1 does not overflow. But the point is that pointer_plus /
> pointer_diff are defined in a way that if that subtraction would overflow,
> then one of the pointer_plus or pointed_diff would have been undefined
> already. In particular, you cannot have objects larger than half the
> address space, and pointer_plus/pointer_diff have to remain inside an
> object. Doing the subtraction in a signed type keeps (part of) that
> information.
>
> > Additionally, (stype)(offset_a - offset_b) is more compact,
>
> Not if offset_a comes from (utype)a and offset_b from (utype)b with a and
> b signed. Using size_t indices as in the bugzilla testcase is not
> recommended practice. Change it to ssize_t, and we do optimize the
> testcase in CCP1 already.
>
> > there might be
> > further simplification opportunities on offset_a - offset_b, even it is not
> > in form of (A * C - B * C), for example (~A - 1 -> -A). But for old rule, 
> > we have
> > to introduce another rule as (T)A - (T)(B) -> (T)(A - B), which seems to
> > be too generic to benefit performance in all situations.
>
> Sadly, conversions complicate optimizations and are all over the place, we
> need to handle them in more places. I sometimes dream of getting rid of
> NOP conversions, and having a single PLUS_EXPR with some kind of flag
> saying if it can wrap/saturate/trap when seen as a signed/unsigned
> operation, i.e. push the information on the operations instead of objects.
>
> > If the 2nd argument is signed, we can add a specific rule as your suggestion
> > (T)(A * C) - (T)(B * C) -> (T) (A - B) * C.
> >
> >> At the very least we want to keep a comment next to the transformation
> >> explaining the situation.
> >
> >> If there are platforms where the second argument of pointer_plus is a
> >> smaller type than the result of pointer_diff (can this happen? I keep
> >> forgetting all the weird things some platforms do), this version may do an
> >> unsafe zero-extension.
> > If the 2nd argument is a smaller type, this might bring confuse semantic to
> > pointer_plus operator. Suppose the type is a (unsigned) char, the expression
> > "ptr + ((char) -1)" represents ptr + 255 or ptr - 1?
>
> (pointer_plus ptr 255) would mean ptr - 1 on a platform where the second
> argument of pointer_plus has size 1 byte.

Yes.  Note this is the reason for using a signed type for the minus as comment

/* The second argument of pointer_plus must be interpreted as signed, and
   thus sign-extended if necessary.  */

explains.  That the type of the offset operand in a pointer-plus is always
unsigned is semantically incorrect.  Whenever taken out of context you
have to re-interpret the offset value as a signed entity.

And yes, there do exist targets where pointers are larger than offsets.
The size of pointers (ptr_mode) is specified by POINTER_SIZE
while the pointer-plus offset type is SIZETYPE (not SIZE_TYPE,
the C ptrdiff_t type is derived from SIZE_TYPE).

As Marc said for this particular reason pointer-plus offsets should
be instead forced to have signed type [or not forced a particular
sign and precision so the operands sign specifies how to extend it].
But it's far from a trivial task to rectify this IL mistake.

Richard.

>
>
> Do note that I am not a reviewer, what I say isn't final.
>
> --
> Marc Glisse


Re: std::optional defaut constructor

2020-06-04 Thread Ville Voutilainen via Gcc-patches
On Thu, 4 Jun 2020 at 11:00, Marc Glisse  wrote:
> Maybe create a buffer, fill it with some non-zero values (-1?), then call
> placement new, and read some value in the middle of the buffer, possibly
> with some protection against optimizations? Ah, no, actual constructors
> are fine, it is only the inlined initialization that happens with the
> defaulted constructor that zeroes things.

The zero-init is part of value-initialization of a class type with a defaulted
default constructor, so value-initialization with placement new should
indeed show
us whether the target buffer is zeroed.


Re: [EXT] Re: [PATCH] Optimize and+or+sub into xor+not (PR94882)

2020-06-04 Thread Richard Biener via Gcc-patches
On Wed, Jun 3, 2020 at 12:36 PM Naveen Hurugalawadi  wrote:
>
> Hi Richard,
>
> Thanks for reviewing the patch and sharing your comments.
>
> >> pattern should be guarded with !TYPE_OVERFLOW_SANITIZED
> >> and/or !TYPE_OVERFLOW_TRAPS
> Done.
>
> >> can you add some cases with unsigned types and types
> >> smaller than int (thus with integral promotion applied)?
> Done.
>
> Please find attached the modified patch as per your suggestions.
> Bootstrapped and regression tested on x86_64-pc-linux-gnu.

+(simplify
+ (plus (nop_convert1? (minus (nop_convert2? (bit_and @0 @1))
+(nop_convert3? (bit_ior @0 @1
+   (nop_convert4? integer_all_onesp))

nop_convert4 cannot happen, constants will have been constant folded here.
nop_convert2 and nop_convert3 can only happen together since
the bit_and and the bit_ior will have the same type since they share operands.
Btw, one of bit_and or bit_ior needs :c.

+ (if (!TYPE_OVERFLOW_SANITIZED (type) && !TYPE_OVERFLOW_TRAPS (type)
+  && !TYPE_SATURATING (type))

since we now have two types, the type of the plus and the type of the minus
you have to check both of them

So I think it should be

(simplify
 (plus (nop_convert1? (minus@2 (nop_convert2? (bit_and:c @0 @1))
(nop_convert2?
(bit_ior @0 @1
 integer_all_onesp)
 (if (!TYPE_OVERFLOW_SANITIZED (type) && !TYPE_OVERFLOW_TRAPS (type)
 && !TYPE_SATURATING (type)
 && !TYPE_OVERFLOW_SANITIZED (TREE_TYPE (@2))
&& !TYPE_OVERFLOW_TRAPS (TREE_TYPE (@2))
&& !TYPE_SATURATING (TREE_TYPE (@2)))
  (bit_not (convert (bit_xor @0 @1))

and the other patterns adjusted accordingly.

Thanks,
Richard.

> Thanks,
> Naveen


Re: std::optional defaut constructor

2020-06-04 Thread Marc Glisse

On Thu, 4 Jun 2020, Ville Voutilainen wrote:

Right, I was just wondering whether we can reasonably verify in a test 
that the whole shebang is not zeroed. That may need a tree-dump scan in 
the test, and probably should go into PR86173 anyway, so I'm not saying 
such a thing needs to be a part of this fix.


The optimized dumps changed with the patch:

-   = {};
+  MEM[(struct optional *)&] ={v} {CLOBBER};
   MEM[(union _Storage *)&] ={v} {CLOBBER};
+  MEM[(struct _Optional_payload_base *)&]._M_engaged = 0;
   return ;

checking for the absence of " = {}", or the presence of 
_M_engaged, may be robust enough across platforms. It doesn't really 
guarantee that nothing writes to the buffer though.


Maybe create a buffer, fill it with some non-zero values (-1?), then call 
placement new, and read some value in the middle of the buffer, possibly 
with some protection against optimizations? Ah, no, actual constructors 
are fine, it is only the inlined initialization that happens with the 
defaulted constructor that zeroes things.


--
Marc Glisse


Re: std::optional defaut constructor

2020-06-04 Thread Ville Voutilainen via Gcc-patches
On Thu, 4 Jun 2020 at 10:22, Marc Glisse  wrote:

> > So the change is correct. Can we test the change somehow?
>
> It passes the testsuite, and libc++ has been doing it this way for years.
> What I feared was some regression where it would yield worse code in some
> cases, or lose some property (not guaranteed by the standard) like
> triviality (to the point of affecting the ABI?), but I couldn't see
> anything like that happening.
>
> (we still have PR86173 causing unnecessary memset in some cases)

Right, I was just wondering whether we can reasonably verify in a test
that the whole
shebang is not zeroed. That may need a tree-dump scan in the test, and probably
should go into PR86173 anyway, so I'm not saying such a thing needs to be a part
of this fix.

I'm kindly suggesting to Jonathan that this should be OK, and backports too.


  1   2   >