Re: [PATCH] Treat { 0 } specially for structs with the designated_init attribute.

2020-06-08 Thread Martin Sebor via Gcc-patches

On 6/8/20 7:07 PM, Asher Gordon wrote:

Hi Martin,

Thanks for your helpful comments.

Martin Sebor  writes:


As an aside, the bug number should be referenced in the change
message so that when the patch is committed it's automatically
reflected in the bug entry.  The contrib/mklog.py script should
do that automatically based on new test files added to verify
the bug fix/change, provided one such test is added and starts
with a PR c/95379 comment.  Also mentioning it in the Subject
of the email is helpful.

[...]

I don't think there's any "rule" against it but it's customary
to add test files for new features, rather than modify existing
ones (see also my comment about the post-commit hook above).

[...]

ChangeLog changes need not be included in a patch (and shouldn't
be).  They are now automatically extracted from the commit message
and added to the ChangeLog files by a post-commit hook.


OK, these will be easy to fix. Should my other patch¹ (which implements
-Wuniversal-initializer) also have PR c/95379?


I'm sure that would be fine but since it's a separate enhancement
it doesn't need to.  It's up to you.




Rather than creating own linked list I suggest to consider making
use of one of GCC's data structures.


How would this be done? I read the gccint manual a bit and, from what I
understand, a 'tree' type can be a linked list of other 'tree's. But how
would I make a linked list of generic types ('location_t's)?


I don't think GCC has its own generic linked list container.
There's TREE_CHAIN of tree nodes, but that's probably not
the best choice for this purpose.  I think the vec template
(defined in ) would come closest to it (like
constructor_stack::elements).

GCC has its own garbage collector so it's preferable to avoid
manual memory management and all its pitfalls (plus, it's much
more fun to learn about those unique to the garbage collector ;-)

Martin


If the argument to free was returned from XNEW it should probably
be released by XDELETE (even if the two do the same same thing).


In that case, I believe that all other instances of free (which free
something allocated by either XNEW or XRESIZEVEC) should be changed to
XDELETE. The following patch does that (created against the latest
master, without my patches applied).



I realize the patch doesn't change the text of the message but...
if the name of the field is known at this point, mentioning it in
the message would be a helpful touch.  If it isn't, then "a field"
would be grammatically more correct.  In addition, pointing to
the definition of the struct in a follow-on note would also be
helpful (and in line with other similar messages).  These
improvements are unrelated to the change you're making so could
be made separately, but since you're already making changes here
it's an opportunity to make them now (otherwise they're unlikely
to happen).


I will look into this.

Thanks,
Asher

Footnotes:
¹  https://gcc.gnu.org/pipermail/gcc-patches/2020-June/547460.html





[committed] xtensa: libgcc: fix PR target/95571

2020-06-08 Thread Max Filippov via Gcc-patches
Rewrite uw_install_context without function calls to avoid register
spilling in _Unwind_RaiseException during return context installation.

2020-06-08  Max Filippov  
gcc/testsuite/
* g++.target/xtensa/pr95571.C: New test.
* g++.target/xtensa/xtensa.exp: New testsuite.

libgcc/
* config/xtensa/unwind-dw2-xtensa.c (uw_install_context): Merge
with uw_install_context_1.
---
Tested with xtensa-linux-uclibc, committed to master.

 gcc/testsuite/g++.target/xtensa/pr95571.C  | 43 
 gcc/testsuite/g++.target/xtensa/xtensa.exp | 43 
 libgcc/config/xtensa/unwind-dw2-xtensa.c   | 46 +++---
 3 files changed, 108 insertions(+), 24 deletions(-)
 create mode 100644 gcc/testsuite/g++.target/xtensa/pr95571.C
 create mode 100644 gcc/testsuite/g++.target/xtensa/xtensa.exp

diff --git a/gcc/testsuite/g++.target/xtensa/pr95571.C 
b/gcc/testsuite/g++.target/xtensa/pr95571.C
new file mode 100644
index ..59fe28528380
--- /dev/null
+++ b/gcc/testsuite/g++.target/xtensa/pr95571.C
@@ -0,0 +1,43 @@
+/* { dg-do run } */
+
+extern "C" void abort(void);
+extern "C" void __xtensa_libgcc_window_spill(void);
+
+static int call;
+static int cnt;
+
+extern "C" void *memcpy(void *dst, const void *src, unsigned int sz)
+{
+  char *a = (char *)dst;
+  const char *b = (const char *)src;
+
+  if (call++ == cnt)
+__xtensa_libgcc_window_spill();
+
+  while (sz--)
+*a++ = *b++;
+
+  return dst;
+}
+
+int main()
+{
+  int i;
+
+  for (i = 0; i < 100; ++i)
+{
+  call = 0;
+  cnt = i;
+
+  try
+   {
+ throw 1;
+   }
+  catch (int v)
+   {
+ if (v != 1)
+   abort ();
+   }
+}
+  return 0;
+}
diff --git a/gcc/testsuite/g++.target/xtensa/xtensa.exp 
b/gcc/testsuite/g++.target/xtensa/xtensa.exp
new file mode 100644
index ..f4191201d11f
--- /dev/null
+++ b/gcc/testsuite/g++.target/xtensa/xtensa.exp
@@ -0,0 +1,43 @@
+#  Specific regression driver for Xtensa.
+#  Copyright (C) 2020 Free Software Foundation, Inc.
+#
+#  This file is part of GCC.
+#
+#  GCC is free software; you can redistribute it and/or modify it
+#  under the terms of the GNU General Public License as published by
+#  the Free Software Foundation; either version 3, or (at your option)
+#  any later version.
+#
+#  GCC is distributed in the hope that it will be useful, but
+#  WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+#  General Public License for more details.
+#
+#  You should have received a copy of the GNU General Public License
+#  along with GCC; see the file COPYING3.  If not see
+#  .  */
+
+# GCC testsuite that uses the `dg.exp' driver.
+
+# Exit immediately if this isn't an Xtensa target.
+if {![istarget xtensa*-*-*] } then {
+  return
+}
+
+# Load support procs.
+load_lib g++-dg.exp
+
+global DEFAULT_CXXFLAGS
+if ![info exists DEFAULT_CXXFLAGS] then {
+set DEFAULT_CXXFLAGS " -pedantic-errors"
+}
+
+# Initialize `dg'.
+dg-init
+
+# Main loop.
+dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*.C]] \
+"" $DEFAULT_CXXFLAGS
+
+# All done.
+dg-finish
diff --git a/libgcc/config/xtensa/unwind-dw2-xtensa.c 
b/libgcc/config/xtensa/unwind-dw2-xtensa.c
index 056182a794aa..8a6a44a8b685 100644
--- a/libgcc/config/xtensa/unwind-dw2-xtensa.c
+++ b/libgcc/config/xtensa/unwind-dw2-xtensa.c
@@ -481,37 +481,35 @@ uw_init_context_1 (struct _Unwind_Context *context, void 
*outer_cfa,
 
 /* Install TARGET into CURRENT so that we can return to it.  This is a
macro because __builtin_eh_return must be invoked in the context of
-   our caller.  */
+   our caller, and also because spilling registers of the caller before
+   the context installation may result in reload of wrong register values
+   after the context installation due to the change of the stack pointer
+   in the base save area.  This spilling may be caused by an interrupt
+   handler on baremetal host.  */
 
-#define uw_install_context(CURRENT, TARGET, FRAMES)
 \
+#define uw_install_context(CURRENT, TARGET, FRAMES) \
   do\
 {   \
-  long offset = uw_install_context_1 ((CURRENT), (TARGET));
 \
   void *handler = __builtin_frob_return_addr ((TARGET)->ra);\
-  __builtin_eh_return (offset, handler);\
+  long i;   \
+\
+  /* The eh_return insn assumes a window size of 8, so don't bother
 \
+copying the save areas for registers a8-a15 since they won't be \
+reloaded.  */   \
+  for 

Re: [PATCH] rs6000: Use REAL_TYPE to copy when block move array in structure[PR65421]

2020-06-08 Thread Segher Boessenkool
Hi!

On Mon, Jun 08, 2020 at 02:22:23PM +0800, luoxhu wrote:
> On 2020/6/3 04:32, Segher Boessenkool wrote:
> > On Tue, Jun 02, 2020 at 04:41:50AM -0500, Xionghu Luo wrote:
> >> +  if (TREE_CODE (type) == RECORD_TYPE
> >> +  && rs6000_discover_homogeneous_aggregate (TYPE_MODE (type), type, 
> >> NULL,
> >> +  NULL))
> >> +{
> >> +  tree field_type = TREE_TYPE (first_field (type));
> >> +  if (field_type && TREE_CODE (field_type) == ARRAY_TYPE
> >> +&& TREE_CODE (TREE_TYPE (field_type)) == REAL_TYPE)
> >> +  elt_mode = TYPE_MODE (TREE_TYPE (field_type));
> >> +}
> > 
> > Homogeneous aggregates only exist in the ELFv2 ABI, while the problem
> > here is the SP float things.  You also noticed (elsewhere) that if the
> > struct contains (say) SI, SF, SI, SF, then this does not help.
> > 
> > Is there some better condition this could use, and maybe an expansion
> > that works in more cases as well?
> > 
> > And, it would be lovely if generic code could expand to something better
> > already (not expand to a block move at all, certainly not for something
> > as tiny as this).
> 
> This pr65421 is array in structure, the assignment is just struct to struct
> and won't be split by SROA to element assignment like struct contains 
> or .

Yes, but it is a very small, fixed-length array (4 SP floats in PR65421).
So what we do currently is not very good.

> For pr65421, the arguments and return value are accessed by BLKmode after 
> gimplify,
> since there is no IPA pass, it is never changed from pass gimple to expand.

And that is a problem (not only on Power, but everywhere that likes
registers more than it likes memory...  basically everywhere).

> In expander, the type conversion only happens on expand_assignment of "D.2909 
> = a;"
> (arguments assigned to local variable, stack to stack, generated by 
> expand_block_move,
> insn #13~#20 as followed), the expand_function_start(insn #2~#9) load each 
> element type
> to be DF already, DF to DI conversion in insn #13~#20 cause the later RTL 
> passes fail to
> do forward propagation in 246r.fwprop1.  So my patch tries to use the actual 
> type for
> array in structure here.  If rs6000_discover_homogeneous_aggregate is not 
> allowed to be
> used here, how about expose and call rs6000_aggregate_candidate directly?

I think it would be best if generic code did not force this into memory
at all.

> Not clear why
> "Homogeneous aggregates only exist in the ELFv2 ABI" since double array in 
> structure is a
> common usage?

Homogeneous arguments are a concept from the ELFv2 ABI.  This macro
return false if not
  (TARGET_HARD_FLOAT
   && DEFAULT_ABI == ABI_ELFv2
   && type && AGGREGATE_TYPE_P (type))

On other ABIs we have the exact same problem, so a good solution would
fix it for all such ABIs (but even for all targets if possible).

> To bypass block move requires very generic code change,

Yes.

> the BLK mode is determined very early
> in gimple, remove BLKmode seems huge project in 
> stor-layout.c\function.c\expr.c etc. and not sure
> other targets like it, the ARM64 use OImode register to avoid BLKmode/stack 
> operations, while
> X86 expand to two TImode register assignment and pointer result return.

To get good code they will have to change it to the proper access mode
in some later pass.

> Or do you mean some workaround that don't call emit_block_move to fall in 
> expand_block_move in
> rs6000-string.c when expand_assignment of "D.2909 = a;" below?
> rtx
> store_expr (tree exp, rtx target, int call_param_p,
>   bool nontemporal, bool reverse)
> {
> ...
>   else if (GET_CODE (temp) == PARALLEL)
>   emit_group_store (target, temp, TREE_TYPE (exp),
> int_size_in_bytes (TREE_TYPE (exp)));
>   else if (GET_MODE (temp) == BLKmode)
>   emit_block_move (target, temp, expr_size (exp),
>(call_param_p
> ? BLOCK_OP_CALL_PARM : BLOCK_OP_NORMAL))
> ...
> }

We can cetainly do workarounds in the target code if the generic code
cannot be fixed, or other targets are against this for some reason --
but let's try to do the proper thing first?

Thanks,


Segher


Re: [PATCH 1/7] PowerPC tests: Add prefixed/pcrel tests.

2020-06-08 Thread Segher Boessenkool
Hi!

On Mon, Jun 01, 2020 at 03:53:36PM -0400, Michael Meissner wrote:
> +# Return 1 if the target generates PC-relative instructions automatically for
> +# the PowerPC 'future' machine.

"... automatically, for configurations that allow it"?

If the selector was only for the "future" target, that should be part of
the name; but it is not, that is just a detail of the actual test.

> +proc check_effective_target_powerpc_pcrel { } {
> +return [check_no_messages_and_pattern powerpc_pcrel \
> + {\mpla\M} assembly {
> + static unsigned short s;
> + unsigned short *p_foo (void) { return  }
> + } {-O2 -mcpu=future}]
> +}


> +# Return 1 if the target generates prefixed instructions automatically for 
> the
> +# PowerPC 'future' machine.

Same here.

(It is important that the description for each selector is clear and
accurate, and guides the potential user to what selector to use where).

Okay for trunk with that changed.  Thanks!


Segher


Re: [PATCH] Treat { 0 } specially for structs with the designated_init attribute.

2020-06-08 Thread Asher Gordon via Gcc-patches
Hi Martin,

Thanks for your helpful comments.

Martin Sebor  writes:

> As an aside, the bug number should be referenced in the change
> message so that when the patch is committed it's automatically
> reflected in the bug entry.  The contrib/mklog.py script should
> do that automatically based on new test files added to verify
> the bug fix/change, provided one such test is added and starts
> with a PR c/95379 comment.  Also mentioning it in the Subject
> of the email is helpful.
>
> [...]
>
> I don't think there's any "rule" against it but it's customary
> to add test files for new features, rather than modify existing
> ones (see also my comment about the post-commit hook above).
>
> [...]
>
> ChangeLog changes need not be included in a patch (and shouldn't
> be).  They are now automatically extracted from the commit message
> and added to the ChangeLog files by a post-commit hook.

OK, these will be easy to fix. Should my other patch¹ (which implements
-Wuniversal-initializer) also have PR c/95379?

> Rather than creating own linked list I suggest to consider making
> use of one of GCC's data structures.

How would this be done? I read the gccint manual a bit and, from what I
understand, a 'tree' type can be a linked list of other 'tree's. But how
would I make a linked list of generic types ('location_t's)?

> If the argument to free was returned from XNEW it should probably
> be released by XDELETE (even if the two do the same same thing).

In that case, I believe that all other instances of free (which free
something allocated by either XNEW or XRESIZEVEC) should be changed to
XDELETE. The following patch does that (created against the latest
master, without my patches applied).
From 160f696db8e875ab89d6c383ec7f68a772157089 Mon Sep 17 00:00:00 2001
From: Asher Gordon 
Date: Mon, 8 Jun 2020 20:59:38 -0400
Subject: [PATCH] Replace free with XDELETE.

gcc/c/ChangeLog:

	* c-typeck.c (free_all_tagged_tu_seen_up_to): Replace free
	with XDELETE.
	(finish_init): Likewise.
	(pop_init_level): Likewise.
---
 gcc/c/c-typeck.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c
index 385bf3a1c7b..d97dcf50374 100644
--- a/gcc/c/c-typeck.c
+++ b/gcc/c/c-typeck.c
@@ -1404,7 +1404,7 @@ free_all_tagged_tu_seen_up_to (const struct tagged_tu_seen_cache *tu_til)
   const struct tagged_tu_seen_cache *const tu1
 	= (const struct tagged_tu_seen_cache *) tu;
   tu = tu1->next;
-  free (CONST_CAST (struct tagged_tu_seen_cache *, tu1));
+  XDELETE (CONST_CAST (struct tagged_tu_seen_cache *, tu1));
 }
   tagged_tu_seen_base = tu_til;
 }
@@ -8268,13 +8268,13 @@ finish_init (void)
 {
   struct constructor_stack *q = constructor_stack;
   constructor_stack = q->next;
-  free (q);
+  XDELETE (q);
 }
 
   gcc_assert (!constructor_range_stack);
 
   /* Pop back to the data of the outer initializer (if any).  */
-  free (spelling_base);
+  XDELETE (spelling_base);
 
   constructor_decl = p->decl;
   require_constant_value = p->require_constant_value;
@@ -8287,7 +8287,7 @@ finish_init (void)
   spelling_size = p->spelling_size;
   constructor_top_level = p->top_level;
   initializer_stack = p->next;
-  free (p);
+  XDELETE (p);
 }

 /* Call here when we see the initializer is surrounded by braces.
@@ -8818,7 +8818,7 @@ pop_init_level (location_t loc, int implicit,
   RESTORE_SPELLING_DEPTH (constructor_depth);
 
   constructor_stack = p->next;
-  free (p);
+  XDELETE (p);
 
   if (ret.value == NULL_TREE && constructor_stack == 0)
 ret.value = error_mark_node;
-- 
2.26.2

> I realize the patch doesn't change the text of the message but...
> if the name of the field is known at this point, mentioning it in
> the message would be a helpful touch.  If it isn't, then "a field"
> would be grammatically more correct.  In addition, pointing to
> the definition of the struct in a follow-on note would also be
> helpful (and in line with other similar messages).  These
> improvements are unrelated to the change you're making so could
> be made separately, but since you're already making changes here
> it's an opportunity to make them now (otherwise they're unlikely
> to happen).

I will look into this.

Thanks,
Asher

Footnotes: 
¹  https://gcc.gnu.org/pipermail/gcc-patches/2020-June/547460.html

-- 
One picture is worth 128K words.
   
I prefer to send and receive mail encrypted. Please send me your
public key, and if you do not have my public key, please let me
know. Thanks.

GPG fingerprint: 38F3 975C D173 4037 B397  8095 D4C9 C4FC 5460 8E68


signature.asc
Description: PGP signature


[PATCH] rs6000/testsuite: Allow xxperm* instead of only vperm*

2020-06-08 Thread Segher Boessenkool
Some testcases failed (esp. with --with-cpu=power9) after my change to
prefer xxperm over vperm when all else is equal.  Fix that.  (This also
tightens the relevant REs somewhat).

Tested on way too many configurations.  Committed to trunk.


Segher


2020-06-09  Segher Boessenkool  

gcc/testsuite/
* gcc.target/powerpc/fold-vec-perm-char.c: Allow both vperm/vpermr and
xxperm/xxpermr.
* gcc.target/powerpc/fold-vec-perm-double.c: Ditto.
* gcc.target/powerpc/fold-vec-perm-float.c: Ditto.
* gcc.target/powerpc/fold-vec-perm-int.c: Ditto.
* gcc.target/powerpc/fold-vec-perm-longlong.c: Ditto.
* gcc.target/powerpc/fold-vec-perm-pixel.c: Ditto.
* gcc.target/powerpc/fold-vec-perm-short.c: Ditto.
* gcc.target/powerpc/lvsl-lvsr.c: Ditto.
* gcc.target/powerpc/vec-mult-char-2.c: Ditto.
* gcc.target/powerpc/vsx-vector-6.p9.c: Also allow xxpermr.

---
 gcc/testsuite/gcc.target/powerpc/fold-vec-perm-char.c | 2 +-
 gcc/testsuite/gcc.target/powerpc/fold-vec-perm-double.c   | 2 +-
 gcc/testsuite/gcc.target/powerpc/fold-vec-perm-float.c| 2 +-
 gcc/testsuite/gcc.target/powerpc/fold-vec-perm-int.c  | 2 +-
 gcc/testsuite/gcc.target/powerpc/fold-vec-perm-longlong.c | 2 +-
 gcc/testsuite/gcc.target/powerpc/fold-vec-perm-pixel.c| 2 +-
 gcc/testsuite/gcc.target/powerpc/fold-vec-perm-short.c| 2 +-
 gcc/testsuite/gcc.target/powerpc/lvsl-lvsr.c  | 2 +-
 gcc/testsuite/gcc.target/powerpc/vec-mult-char-2.c| 2 +-
 gcc/testsuite/gcc.target/powerpc/vsx-vector-6.p9.c| 2 +-
 10 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/gcc/testsuite/gcc.target/powerpc/fold-vec-perm-char.c 
b/gcc/testsuite/gcc.target/powerpc/fold-vec-perm-char.c
index d907eae..56a89f3 100644
--- a/gcc/testsuite/gcc.target/powerpc/fold-vec-perm-char.c
+++ b/gcc/testsuite/gcc.target/powerpc/fold-vec-perm-char.c
@@ -28,4 +28,4 @@ testuc (vector unsigned char vuc2, vector unsigned char vuc3,
   return vec_perm (vuc2, vuc3, vuc);
 }
 
-/* { dg-final { scan-assembler-times "vperm" 3 } } */
+/* { dg-final { scan-assembler-times {\m(?:v|xx)permr?\M} 3 } } */
diff --git a/gcc/testsuite/gcc.target/powerpc/fold-vec-perm-double.c 
b/gcc/testsuite/gcc.target/powerpc/fold-vec-perm-double.c
index 7ceca9e..c982bc2 100644
--- a/gcc/testsuite/gcc.target/powerpc/fold-vec-perm-double.c
+++ b/gcc/testsuite/gcc.target/powerpc/fold-vec-perm-double.c
@@ -14,4 +14,4 @@ testd (vector double vd2, vector double vd3, vector unsigned 
char vuc)
   return vec_perm (vd2, vd3, vuc);
 }
 
-/* { dg-final { scan-assembler-times "vperm" 1 } } */
+/* { dg-final { scan-assembler-times {\m(?:v|xx)permr?\M} 1 } } */
diff --git a/gcc/testsuite/gcc.target/powerpc/fold-vec-perm-float.c 
b/gcc/testsuite/gcc.target/powerpc/fold-vec-perm-float.c
index c9cfb0d..64b8ac7 100644
--- a/gcc/testsuite/gcc.target/powerpc/fold-vec-perm-float.c
+++ b/gcc/testsuite/gcc.target/powerpc/fold-vec-perm-float.c
@@ -13,4 +13,4 @@ testf (vector float vf2, vector float vf3, vector unsigned 
char vuc)
   return vec_perm (vf2, vf3, vuc);
 }
 
-/* { dg-final { scan-assembler-times "vperm" 1 } } */
+/* { dg-final { scan-assembler-times {\m(?:v|xx)permr?\M} 1 } } */
diff --git a/gcc/testsuite/gcc.target/powerpc/fold-vec-perm-int.c 
b/gcc/testsuite/gcc.target/powerpc/fold-vec-perm-int.c
index a2fdc26..a6dd595 100644
--- a/gcc/testsuite/gcc.target/powerpc/fold-vec-perm-int.c
+++ b/gcc/testsuite/gcc.target/powerpc/fold-vec-perm-int.c
@@ -28,4 +28,4 @@ testui (vector unsigned int vui2, vector unsigned int vui3,
   return vec_perm (vui2, vui3, vuc);
 }
 
-/* { dg-final { scan-assembler-times "vperm" 3 } } */
+/* { dg-final { scan-assembler-times {\m(?:v|xx)permr?\M} 3 } } */
diff --git a/gcc/testsuite/gcc.target/powerpc/fold-vec-perm-longlong.c 
b/gcc/testsuite/gcc.target/powerpc/fold-vec-perm-longlong.c
index 1333d88..3cc757d 100644
--- a/gcc/testsuite/gcc.target/powerpc/fold-vec-perm-longlong.c
+++ b/gcc/testsuite/gcc.target/powerpc/fold-vec-perm-longlong.c
@@ -29,4 +29,4 @@ testul (vector unsigned long long vul2, vector unsigned long 
long vul3,
   return vec_perm (vul2, vul3, vuc);
 }
 
-/* { dg-final { scan-assembler-times "vperm" 3 } } */
+/* { dg-final { scan-assembler-times {\m(?:v|xx)permr?\M} 3 } } */
diff --git a/gcc/testsuite/gcc.target/powerpc/fold-vec-perm-pixel.c 
b/gcc/testsuite/gcc.target/powerpc/fold-vec-perm-pixel.c
index 0d3cb0a..54fccd2 100644
--- a/gcc/testsuite/gcc.target/powerpc/fold-vec-perm-pixel.c
+++ b/gcc/testsuite/gcc.target/powerpc/fold-vec-perm-pixel.c
@@ -13,4 +13,4 @@ testpx (vector pixel px2, vector pixel px3, vector unsigned 
char vuc)
   return vec_perm (px2, px3, vuc);
 }
 
-/* { dg-final { scan-assembler-times "vperm" 1 } } */
+/* { dg-final { scan-assembler-times {\m(?:v|xx)permr?\M} 1 } } */
diff --git a/gcc/testsuite/gcc.target/powerpc/fold-vec-perm-short.c 
b/gcc/testsuite/gcc.target/powerpc/fold-vec-perm-short.c
index de5303a..6a5d1a7 100644
--- 

[PR95416] outputs.exp: skip lto tests when not using linker plugin

2020-06-08 Thread Alexandre Oliva


When the linker plugin is not available, dump outputs in lto runs are
different from those outputs.exp tests expect, so skip them for now.

Regstrapped on x86_64-linux-gnu.  Ok to install?


for  gcc/testsuite/ChangeLog

* outputs.exp (skip_lto): Set when missing the linker plugin.
---
 testsuite/gcc.misc-tests/outputs.exp |3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git gcc/testsuite/gcc.misc-tests/outputs.exp 
gcc/testsuite/gcc.misc-tests/outputs.exp
index 06a32db..a47f8a6 100644
--- gcc/testsuite/gcc.misc-tests/outputs.exp
+++ gcc/testsuite/gcc.misc-tests/outputs.exp
@@ -42,7 +42,8 @@ if ![check_no_compiler_messages gsplitdwarf object {
 
 # Check for -flto support.  We explicitly test the result to skip
 # tests that use -flto.
-set skip_lto ![check_effective_target_lto]
+set skip_lto { ![check_effective_target_lto] \
+  || ![check_linker_plugin_available] }
 
 # Prepare additional options to be used for linking.
 # We do not compile to an executable, because that requires naming an output.


-- 
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


avoid line breaks in -fverbose-asm tree exprs

2020-06-08 Thread Alexandre Oliva


An asm operand with a "VIEW_CONVERT_EXPR" will output the definition of the struct as asm code.  Oops.

I hoped setting print_rtx_head would affect print_mem_expr, just
because it's in print-rtl rather than tree-pretty-print, but it didn't
help.  I've thus arranged for print_mem_expr to "obey" print_rtx_head
by enabling TDF_SLIM.

Regstrapped on x86_64-linux-gnu.  Ok to install?


Another alternative that occurred to me was to get print_rtx_head
printed by e.g. pp_newline, or otherwise get print-rtl and
pretty-print infrastructure to both use the same line-leading
infrastructure.  I think that would be a much bigger undertaking, so I
figured I'd ask whether that would be desirable, before taking it up.
Thoughts?


for  gcc/ChangeLog

* final.c (output_asm_operand_names): Set print_rtx_head
around print_mem_expr.
* print-rtl.c (print_mem_expr): Enable TDF_SLIM in dump_flags
when print_rtx_head is nonempty.
---
 final.c |3 +++
 print-rtl.c |4 
 2 files changed, 7 insertions(+)

diff --git gcc/final.c gcc/final.c
index a360196..482801db 100644
--- gcc/final.c
+++ gcc/final.c
@@ -3706,9 +3706,12 @@ output_asm_operand_names (rtx *operands, int *oporder, 
int nops)
   wrote = 1;
   if (expr)
{
+ const char *saved_print_rtx_head = print_rtx_head;
  fprintf (asm_out_file, "%s",
   addressp ? "*" : "");
+ print_rtx_head = ASM_COMMENT_START;
  print_mem_expr (asm_out_file, expr);
+ print_rtx_head = saved_print_rtx_head;
  wrote = 1;
}
   else if (REG_P (op) && ORIGINAL_REGNO (op)
diff --git gcc/print-rtl.c gcc/print-rtl.c
index 611ea07..0563540 100644
--- gcc/print-rtl.c
+++ gcc/print-rtl.c
@@ -182,8 +182,12 @@ rtx_reuse_manager::set_seen_def (int reuse_id)
 void
 print_mem_expr (FILE *outfile, const_tree expr)
 {
+  dump_flags_t save_dump_flags = dump_flags;
+  if (*print_rtx_head)
+dump_flags |= TDF_SLIM;
   fputc (' ', outfile);
   print_generic_expr (outfile, CONST_CAST_TREE (expr), dump_flags);
+  dump_flags = save_dump_flags;
 }
 #endif
 

-- 
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


Re: libstdc++: Extend memcmp optimization in std::lexicographical_compare

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

On 08/06/20 22:08 +0100, Jonathan Wakely wrote:

On 08/06/20 19:20 +0100, Jonathan Wakely wrote:

On 05/06/20 22:24 +0200, François Dumont via Libstdc++ wrote:

Hi

    Here is the last of my algo patches this time to extend the 
memcmp optimization to std::deque iterators and _GLIBCXX_DEBUG 
mode.


    To do so I had to return int in implementation details of 
lexicographical_compare to make sure we can treat a deque iterator 
range by chunk in a performant way.


Here's a simpler version, which doesn't alter anything for the
existing code (i.e. all iterators that aren't deque iterators) and
also fixes the infinite loop bug.

This seems simpler and less invasive.

Please take a look.


I've actually tested it in debug mode now, and ...


diff --git a/libstdc++-v3/include/debug/safe_iterator.tcc 
b/libstdc++-v3/include/debug/safe_iterator.tcc
index 888ac803ae5..db6a301655f 100644
--- a/libstdc++-v3/include/debug/safe_iterator.tcc
+++ b/libstdc++-v3/include/debug/safe_iterator.tcc
@@ -470,6 +470,80 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
  return __equal_aux1(__first1, __last1, __first2);
}

+  template
+int


This should return bool here.


+__lexicographical_compare_aux(
+   const ::__gnu_debug::_Safe_iterator<_Ite1, _Seq1, _Cat1>& __first1,
+   const ::__gnu_debug::_Safe_iterator<_Ite1, _Seq1, _Cat1>& __last1,
+   _II2 __first2, _II2 __last2)
+{
+  typename ::__gnu_debug::_Distance_traits<_Ite1>::__type __dist1;
+  __glibcxx_check_valid_range2(__first1, __last1, __dist1);
+  __glibcxx_check_valid_range(__first2, __last2);
+
+  if (__dist1.second > ::__gnu_debug::__dp_equality)
+   return std::__lexicographical_compare_aux(__first1.base(),
+ __last1.base(),
+ __first2, __last2);
+  return std::__lexicographical_compare_aux1(__first1, __last1,
+__first2, __last2);
+}
+
+  template
+int


And here.


+__lexicographical_compare_aux(
+   _II1 __first1, _II1 __last1,
+   const ::__gnu_debug::_Safe_iterator<_Ite2, _Seq2, _Cat2>& __first2,
+   const ::__gnu_debug::_Safe_iterator<_Ite2, _Seq2, _Cat2>& __last2)
+{
+  __glibcxx_check_valid_range(__first1, __last1);
+  typename ::__gnu_debug::_Distance_traits<_II1>::__type __dist2;
+  __glibcxx_check_valid_range2(__first2, __last2, __dist2);
+
+  if (__dist2.second > ::__gnu_debug::__dp_equality)
+   return std::__lexicographical_compare_aux(__first1, __last1,
+ __first2.base(),
+ __last2.base());
+  return std::__lexicographical_compare_aux1(__first1, __last1,
+__first2, __last2);
+}
+
+  template
+int


And here.


+__lexicographical_compare_aux(
+   const ::__gnu_debug::_Safe_iterator<_Ite1, _Seq1, _Cat1>& __first1,
+   const ::__gnu_debug::_Safe_iterator<_Ite1, _Seq1, _Cat1>& __last1,
+   const ::__gnu_debug::_Safe_iterator<_Ite2, _Seq2, _Cat2>& __first2,
+   const ::__gnu_debug::_Safe_iterator<_Ite2, _Seq2, _Cat2>& __last2)
+{
+  typename ::__gnu_debug::_Distance_traits<_Ite1>::__type __dist1;
+  __glibcxx_check_valid_range2(__first1, __last1, __dist1);
+  typename ::__gnu_debug::_Distance_traits<_Ite2>::__type __dist2;
+  __glibcxx_check_valid_range2(__first2, __last2, __dist2);
+
+  if (__dist1.second > ::__gnu_debug::__dp_equality)
+   {
+ if (__dist2.second > ::__gnu_debug::__dp_equality)
+   return std::__lexicographical_compare_aux(__first1.base(),
+ __last1.base(),
+ __first2.base(),
+ __last2.base());
+ return std::__lexicographical_compare_aux(__first1.base(),
+   __last1.base(),
+   __first2, __last2);
+   }
+
+  if (__dist2.second > ::__gnu_debug::__dp_equality)
+   return std::__lexicographical_compare_aux(__first1, __last1,
+ __first2.base(),
+ __last2.base());
+  return std::__lexicographical_compare_aux1(__first1, __last1,
+__first2, __last2);
+}
+
_GLIBCXX_END_NAMESPACE_VERSION
} // namespace std




Re: [PATCH] fortran/95509 - fix spellcheck-operator.f90 regression

2020-06-08 Thread Tom Tromey
Bernhard> Yes, this is probably OK although Fortran is case-
Bernhard> insensitive. I think we lowercase names coming in from the
Bernhard> source (at least for the internal identifier nodes), so we
Bernhard> should not be affected by any case change.

I already checked it in, but FWIW it would be pretty easy to change
get_edit_distance to have a case-insensitive mode.

Tom


[PATCH] guard against calls with fewer arguments than the function type implies (PR 95581)

2020-06-08 Thread Martin Sebor via Gcc-patches

PR 95581 reports an ICE in a call to gimple_call_arg() with
an out-of-bounds argument number (2).  The attached patch avoids
the ICE but I'm not sure it's the right fix.  Other than verifying
the ICE is gone with a powerpc64 cross-compiler I couldn't come up
with a generic test cases to exercise this change.

The call, synthesized by the vectorizer, is

  vect__5.6_24 = __builtin_altivec_mask_for_load (vectp_a.5_8);

but the function is declared by the powerpc64 back end to take two
arguments: long and const void*.  Is it correct for the builtin to
be called with fewer arguments than their type indicates?  (If it
isn't the patch shouldn't be necessary but some other fix would
be needed.)

Martin
PR tree-optimization/95581 - ICE in gimple_call_arg for a call with fewer arguments than function type implies

gcc/ChangeLog:

	PR tree-optimization/95581
	* tree-ssa-uninit.c (maybe_warn_pass_by_reference): Guard against
	calls with fewer arguments than the called function type implies.

diff --git a/gcc/tree-ssa-uninit.c b/gcc/tree-ssa-uninit.c
index 2f0ff724cde..52f2de940c0 100644
--- a/gcc/tree-ssa-uninit.c
+++ b/gcc/tree-ssa-uninit.c
@@ -445,7 +445,7 @@ maybe_warn_pass_by_reference (gimple *stmt, wlimits )
   if (!wlims.wmaybe_uninit)
 return;
 
-  unsigned nargs = gimple_call_num_args (stmt);
+  const unsigned nargs = gimple_call_num_args (stmt);
   if (!nargs)
 return;
 
@@ -480,6 +480,11 @@ maybe_warn_pass_by_reference (gimple *stmt, wlimits )
 
   FOREACH_FUNCTION_ARGS (fntype, argtype, it)
 {
+  /* Guard against calls with fewer arguments than the function
+	 type implies.  See PR 95581.  */
+  if (nargs == argno)
+	break;
+
   ++argno;
 
   if (!POINTER_TYPE_P (argtype))


[RFA] Fix various regressions and kernel build failure due to adjust-alignment issue

2020-06-08 Thread Jeff Law via Gcc-patches

We're seeing some failures due to the local-alignment pass.  For example on sh4:

Tests that now fail, but worked before (16 tests):

gcc.dg/pr48335-1.c (test for excess errors)
gcc.dg/pr48335-2.c (test for excess errors)
gcc.dg/pr48335-5.c (test for excess errors)
gcc.dg/pr48335-6.c (test for excess errors)
gcc.dg/torture/pr48493.c   -O0  (test for excess errors)
gcc.dg/torture/pr48493.c   -O0  (test for excess errors)
gcc.dg/torture/pr48493.c   -O1  (test for excess errors)
gcc.dg/torture/pr48493.c   -O1  (test for excess errors)
gcc.dg/torture/pr48493.c   -O2  (test for excess errors)
gcc.dg/torture/pr48493.c   -O2  (test for excess errors)
gcc.dg/torture/pr48493.c   -O2 -flto -fno-use-linker-plugin -flto-
partition=none  (test for excess errors)
gcc.dg/torture/pr48493.c   -O2 -flto -fno-use-linker-plugin -flto-
partition=none  (test for excess errors)
gcc.dg/torture/pr48493.c   -O3 -g  (test for excess errors)
gcc.dg/torture/pr48493.c   -O3 -g  (test for excess errors)
gcc.dg/torture/pr48493.c   -Os  (test for excess errors)
gcc.dg/torture/pr48493.c   -Os  (test for excess errors)

Or on x86_64:

during GIMPLE pass: adjust_alignment
/home/jenkins/linux/arch/x86/boot/string.c: In function ‘simple_strtoull’:
/home/jenkins/linux/arch/x86/boot/string.c:121:20: internal compiler error: in
execute, at adjust-alignment.c:74
  121 | unsigned long long simple_strtoull(const char *cp, char **endp, unsigned
int base)
  |^~~
0x79c5b3 execute
../../../../../gcc/gcc/adjust-alignment.c:74
Please submit a full bug report,

There may be others, I haven't searched the failing targets extensively for this
issue. 

AFAICT the adjust-alignment pass is supposed to increase alignments of locals
when needed.  It has an assert to ensure that alignments are only increased.

However, if the object was declared with an alignment attribute that is larger
than what LOCAL_ALIGNMENT would produce for the object, then the 
adjust-alignment 
pass trips the assert.

Rather than asserting, just ignoring such objects seems better.  But I'm not
intimately familiar with the issues here.

Bootstrapped and regression tested on x86_64, also verified this fixes the sh4
issue.  All the *-elf targets have also built/tested with this patch with no
regressions.

OK for the trunk?

Jeff


diff --git a/gcc/adjust-alignment.c b/gcc/adjust-alignment.c
index 9b797386bf8..523216a8fcf 100644
--- a/gcc/adjust-alignment.c
+++ b/gcc/adjust-alignment.c
@@ -71,7 +71,8 @@ pass_adjust_alignment::execute (function *fun)
   unsigned align = LOCAL_DECL_ALIGNMENT (var);
 
   /* Make sure alignment only increase.  */
-  gcc_assert (align >= DECL_ALIGN (var));
+  if (DECL_ALIGN (var) >= align)
+	continue;
 
   SET_DECL_ALIGN (var, align);
 }


Re: libstdc++: Extend memcmp optimization in std::lexicographical_compare

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

On 08/06/20 19:20 +0100, Jonathan Wakely wrote:

On 05/06/20 22:24 +0200, François Dumont via Libstdc++ wrote:

Hi

    Here is the last of my algo patches this time to extend the 
memcmp optimization to std::deque iterators and _GLIBCXX_DEBUG mode.


    To do so I had to return int in implementation details of 
lexicographical_compare to make sure we can treat a deque iterator 
range by chunk in a performant way.


Here's a simpler version, which doesn't alter anything for the
existing code (i.e. all iterators that aren't deque iterators) and
also fixes the infinite loop bug.

This seems simpler and less invasive.

Please take a look.


commit b7c4d633e875ccd2b3141f1b74d062fea11ab2c0
Author: Fran??ois Dumont 
Date:   Mon Jun 8 21:58:14 2020 +0100

libstdc++: Extend memcmp optimization in std::lexicographical_compare

Make the memcmp optimization work for std::deque iterators and safe
iterators.

Co-authored-by: Jonathan Wakely  

libstdc++-v3/ChangeLog:

2020-06-08  Fran??ois Dumont  
Jonathan Wakely  

* include/bits/deque.tcc (__lex_cmp_dit): New.
(__lexicographical_compare_aux1): Define overloads for deque
iterators.
* include/bits/stl_algobase.h (__lexicographical_compare::__3way):
New static member function.
(__lexicographical_compare::__3way): Likewise.
(__lexicographical_compare::__lc): Use __3way.
(__lexicographical_compare_aux): Rename to
__lexicographical_compare_aux1 and declare overloads for deque
iterators.
(__lexicographical_compare_aux): Define new forwarding function
that calls __lexicographical_compare_aux1 and declare new overloads
for safe iterators.
(lexicographical_compare): Do not use __niter_base on
parameters.
* include/debug/safe_iterator.tcc
(__lexicographical_compare_aux): Define overloads for safe
iterators.
* testsuite/25_algorithms/lexicographical_compare/1.cc: Add
checks with random access iterators.
* testsuite/25_algorithms/lexicographical_compare/deque_iterators/1.cc:
New test.

diff --git a/libstdc++-v3/include/bits/deque.tcc b/libstdc++-v3/include/bits/deque.tcc
index 1d32a1691c7..ac7f281e04c 100644
--- a/libstdc++-v3/include/bits/deque.tcc
+++ b/libstdc++-v3/include/bits/deque.tcc
@@ -1261,6 +1261,107 @@ _GLIBCXX_END_NAMESPACE_CONTAINER
   return true;
 }
 
+  template
+int
+__lex_cmp_dit(
+	_GLIBCXX_STD_C::_Deque_iterator<_Tp1, _Ref, _Ptr> __first1,
+	_GLIBCXX_STD_C::_Deque_iterator<_Tp1, _Ref, _Ptr> __last1,
+	const _Tp2* __first2, const _Tp2* __last2)
+{
+  const bool __simple =
+	(__is_byte<_Tp1>::__value && __is_byte<_Tp2>::__value
+	 && !__gnu_cxx::__numeric_traits<_Tp1>::__is_signed
+	 && !__gnu_cxx::__numeric_traits<_Tp2>::__is_signed
+	 && __is_pointer<_Ptr>::__value
+#if __cplusplus > 201703L && __cpp_lib_concepts
+	 // For C++20 iterator_traits::value_type is non-volatile
+	 // so __is_byte could be true, but we can't use memcmp with
+	 // volatile data.
+	 && !is_volatile_v<_Tp1>
+	 && !is_volatile_v<_Tp2>
+#endif
+	 );
+  typedef std::__lexicographical_compare<__simple> _Lc;
+
+  while (__first1._M_node != __last1._M_node)
+	{
+	  const ptrdiff_t __len1 = __first1._M_last - __first1._M_cur;
+	  const ptrdiff_t __len2 = __last2 - __first2;
+	  const ptrdiff_t __len = std::min(__len1, __len2);
+	  // if __len1 > __len2 this will return a positive value:
+	  if (int __ret = _Lc::__3way(__first1._M_cur, __first1._M_last,
+	 __first2, __first2 + __len))
+	return __ret;
+
+	  __first1 += __len;
+	  __first2 += __len;
+	}
+  return _Lc::__3way(__first1._M_cur, __last1._M_cur,
+			__first2, __last2);
+}
+
+  template
+inline bool
+__lexicographical_compare_aux1(
+	_GLIBCXX_STD_C::_Deque_iterator<_Tp1, _Ref1, _Ptr1> __first1,
+	_GLIBCXX_STD_C::_Deque_iterator<_Tp1, _Ref1, _Ptr1> __last1,
+	_Tp2* __first2, _Tp2* __last2)
+{ return std::__lex_cmp_dit(__first1, __last1, __first2, __last2) < 0; }
+
+  template
+inline  bool
+__lexicographical_compare_aux1(_Tp1* __first1, _Tp1* __last1,
+	_GLIBCXX_STD_C::_Deque_iterator<_Tp2, _Ref2, _Ptr2> __first2,
+	_GLIBCXX_STD_C::_Deque_iterator<_Tp2, _Ref2, _Ptr2> __last2)
+{ return std::__lex_cmp_dit(__first2, __last2, __first1, __last1) > 0; }
+
+  template
+inline bool
+__lexicographical_compare_aux1(
+		_GLIBCXX_STD_C::_Deque_iterator<_Tp1, _Ref1, _Ptr1> __first1,
+		_GLIBCXX_STD_C::_Deque_iterator<_Tp1, _Ref1, _Ptr1> __last1,
+		_GLIBCXX_STD_C::_Deque_iterator<_Tp2, _Ref2, _Ptr2> __first2,
+		_GLIBCXX_STD_C::_Deque_iterator<_Tp2, _Ref2, _Ptr2> __last2)
+{
+  const bool __simple =
+	(__is_byte<_Tp1>::__value && __is_byte<_Tp2>::__value
+	 && !__gnu_cxx::__numeric_traits<_Tp1>::__is_signed
+	 && 

Re: libstdc++: Extend memcmp optimization in std::lexicographical_compare

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

On 08/06/20 21:07 +0100, Jonathan Wakely wrote:

On 05/06/20 22:24 +0200, François Dumont via Libstdc++ wrote:

diff --git a/libstdc++-v3/include/debug/safe_iterator.tcc 
b/libstdc++-v3/include/debug/safe_iterator.tcc
index 888ac803ae5..ca4e2d52d1d 100644
--- a/libstdc++-v3/include/debug/safe_iterator.tcc
+++ b/libstdc++-v3/include/debug/safe_iterator.tcc
@@ -470,6 +470,80 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 return __equal_aux1(__first1, __last1, __first2);
   }

+  template
+int
+__lexicographical_compare_aux(
+   const ::__gnu_debug::_Safe_iterator<_Ite1, _Seq1, _Cat1>& __first1,
+   const ::__gnu_debug::_Safe_iterator<_Ite1, _Seq1, _Cat1>& __last1,
+   _II2 __first2, _II2 __last2)
+{
+  typename ::__gnu_debug::_Distance_traits<_Ite1>::__type __dist1;
+  __glibcxx_check_valid_range2(__first1, __last1, __dist1);
+  __glibcxx_check_valid_range(__first2, __last2);
+
+  if (__dist1.second > ::__gnu_debug::__dp_equality)
+   return std::__lexicographical_compare_aux(__first1.base(),
+ __last1.base(),
+ __first2, __last2);
+  return std::__lexicographical_compare_aux1(__first1, __last1,
+__first2, __last2);


What's the rationale for the choice of whether to call aux or aux1
here?

It seems to be that if we know [first1, last1) is a valid range, we
use aux with the unsafe iterators (which means we do overload
resolution again for all the overloads that include _Safe_iterator,
but we know we don't have safe iterators now). Otherwise, if we don't
know it's a valid range, we call aux1 with the safe iterators.

Why don't we use aux1 in both cases?


Oh, is it because aux will still use __niter_base and so turn
__normal_iterator arguments into pointers?





Re: [PATCH RFA] tree-inline: Fix VLA handling [PR95552]

2020-06-08 Thread Jason Merrill via Gcc-patches

On 6/8/20 4:19 PM, Jason Merrill wrote:

On 6/8/20 5:46 AM, Eric Botcazou wrote:

The only case handled specially is TYPE_DECL; other DECL_EXPRs fall
through to the default case, where we WALK_SUBTREE over all the operands
of the expression, which for DECL_EXPR is the decl.


It seems hard to believe that the inliner relies on this to copy DECLs 
though,


I agree!  I imagine the actual inliner is unaffected because that 
happens in GIMPLE now, so this only affects FE cloning.  I don't know if 
any other front ends use a walk_tree callback like copy_tree_body_r that 
would replace a type in the same way.



see the calls to remap_decl[s].


Which ones?


And note that remap_decl has had a special
handling for DECL_ORIGINAL_TYPE of TYPE_DECLs since 2003.

Yes, but the problem is that remap_decl isn't getting called.


Are you sure the
problem is not that the TYPE_DECL is not attached to the enclosing 
BIND_EXPR?


Attaching it to the BIND_EXPR doesn't help walk_tree_1 do the right 
thing with the DECL_EXPR.


We could also work around this in copy_tree_body_r as follows, but I 
imagined that other tree walking functions might also be affected by the 
missing call for the TYPE_DECL of a DECL_EXPR.


Jason
commit 4320af50f15c11f6d6a7ddcf0fac51e752c0906f
Author: Jason Merrill 
Date:   Fri Jun 5 22:51:18 2020 -0400

copy-body

diff --git a/gcc/tree-inline.c b/gcc/tree-inline.c
index 3160ca3f88a..2899bcf13e3 100644
--- a/gcc/tree-inline.c
+++ b/gcc/tree-inline.c
@@ -1434,6 +1434,12 @@ copy_tree_body_r (tree *tp, int *walk_subtrees, void *data)
 	  TREE_SET_BLOCK (*tp, new_block);
 	}
 
+  if (TREE_CODE (*tp) == DECL_EXPR
+	  && TREE_CODE (DECL_EXPR_DECL (*tp)) == TYPE_DECL)
+	/* walk_tree_1 walks the type of a type DECL_EXPR but not the decl, so
+	   we clobber the type of the source decl unless we remap it now.  */
+	DECL_EXPR_DECL (*tp) = remap_decl (DECL_EXPR_DECL (*tp), id);
+
   if (TREE_CODE (*tp) != OMP_CLAUSE)
 	TREE_TYPE (*tp) = remap_type (TREE_TYPE (*tp), id);
 


Re: [committed] libstdc++: Implement operator<< for std::unique_ptr (LWG 2948)

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

On 08/06/20 21:22 +0100, Jonathan Wakely wrote:

libstdc++-v3/ChangeLog:

* include/bits/unique_ptr.h (operator<<): Define for C++20.
* testsuite/20_util/unique_ptr/io/lwg2948.cc: New test.


Oops, I forgot to add the test adjustments.

Tested x86_64-linux, committed to master.

commit a37fbff12c3a441753f5eb677cebeab7350f24eb
Author: Jonathan Wakely 
Date:   Mon Jun 8 21:34:46 2020 +0100

libstdc++: Fix failing tests

These started failing with the previous commit, because I forgot to add
the tests after adjusting them.

* testsuite/20_util/default_delete/48631_neg.cc: Adjust dg-error
line number.
* testsuite/20_util/default_delete/void_neg.cc: Likewise.

diff --git a/libstdc++-v3/testsuite/20_util/default_delete/48631_neg.cc b/libstdc++-v3/testsuite/20_util/default_delete/48631_neg.cc
index 6da5a52e28b..0e807c7d57a 100644
--- a/libstdc++-v3/testsuite/20_util/default_delete/48631_neg.cc
+++ b/libstdc++-v3/testsuite/20_util/default_delete/48631_neg.cc
@@ -26,4 +26,4 @@ struct D : B { };
 D d;
 std::default_delete db;
 typedef decltype(db()) type; // { dg-error "no match" }
-// { dg-error "no type" "" { target *-*-* } 115 }
+// { dg-error "no type" "" { target *-*-* } 116 }
diff --git a/libstdc++-v3/testsuite/20_util/default_delete/void_neg.cc b/libstdc++-v3/testsuite/20_util/default_delete/void_neg.cc
index 149b699d106..9f281373b37 100644
--- a/libstdc++-v3/testsuite/20_util/default_delete/void_neg.cc
+++ b/libstdc++-v3/testsuite/20_util/default_delete/void_neg.cc
@@ -25,5 +25,5 @@ void test01()
 {
   std::default_delete d;
   d(nullptr);   // { dg-error "here" }
-  // { dg-error "incomplete" "" { target *-*-* } 80 }
+  // { dg-error "incomplete" "" { target *-*-* } 81 }
 }


[PATCH] PR fortran/95544 - ICE in gfc_can_put_var_on_stack, at fortran/trans-decl.c:494

2020-06-08 Thread Harald Anlauf
Steve did the digging on another of Gerhard's "torture tests" involving
NULL() arguments to intrinsics.  I have mainly cleaned up his patch and
packaged and regtested on x86_64-pc-linux-gnu.

OK for master?

Thanks,
Harald


PR fortran/95544 - Fix ICE in NULL() argument to intrinsics

Fortran 2018: An argument to an intrinsic procedure other than ASSOCIATED,
NULL, or PRESENT shall be a data object.  An EXPR_NULL is not a data
object.  Add checks for intrinsics.

2020-06-08  Steven G. Kargl  
Harald Anlauf  

gcc/fortran/
PR fortran/95544
* check.c (invalid_null_arg): Rename to gfc_invalid_null_arg.
(gfc_check_associated, gfc_check_kind, gfc_check_merge)
(gfc_check_shape, gfc_check_size, gfc_check_spread)
(gfc_check_transfer): Adjust.
(gfc_check_len_lentrim, gfc_check_trim): Check for NULL() argument.
* gfortran.h: Declare gfc_invalid_null_arg ().
* intrinsic.c (check_arglist): Check for NULL() argument.

! { dg-do compile }
! PR fortran/95544 - ICE in gfc_can_put_var_on_stack, at fortran/trans-decl.c:494

program test
   character(:), allocatable :: z
   character(:), pointer :: p
   character(1), pointer :: c
   print *, adjustl (null(z)) ! { dg-error "is not permitted as actual argument" }
   print *, adjustr (null(z)) ! { dg-error "is not permitted as actual argument" }
   print *, len (null(p)) ! { dg-error "is not permitted as actual argument" }
   print *, len (null(z)) ! { dg-error "is not permitted as actual argument" }
   print *, len_trim(null(c)) ! { dg-error "is not permitted as actual argument" }
   print *, len_trim(null(z)) ! { dg-error "is not permitted as actual argument" }
   print *, trim(null(z)) ! { dg-error "is not permitted as actual argument" }
end


[committed] libstdc++: Implement operator<< for std::unique_ptr (LWG 2948)

2020-06-08 Thread Jonathan Wakely via Gcc-patches
libstdc++-v3/ChangeLog:

* include/bits/unique_ptr.h (operator<<): Define for C++20.
* testsuite/20_util/unique_ptr/io/lwg2948.cc: New test.

Tested powerpc64le-linux, committed to master.


commit 187da2ce31f13b2f75d5bb780e30ee364ead9d1d
Author: Jonathan Wakely 
Date:   Mon Jun 8 18:08:14 2020 +0100

libstdc++: Implement operator<< for std::unique_ptr (LWG 2948)

libstdc++-v3/ChangeLog:

* include/bits/unique_ptr.h (operator<<): Define for C++20.
* testsuite/20_util/unique_ptr/io/lwg2948.cc: New test.

diff --git a/libstdc++-v3/include/bits/unique_ptr.h 
b/libstdc++-v3/include/bits/unique_ptr.h
index 3695214808b..d0e4cefadd7 100644
--- a/libstdc++-v3/include/bits/unique_ptr.h
+++ b/libstdc++-v3/include/bits/unique_ptr.h
@@ -39,6 +39,7 @@
 #include 
 #if __cplusplus > 201703L
 # include 
+# include 
 #endif
 
 namespace std _GLIBCXX_VISIBILITY(default)
@@ -934,7 +935,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   public __uniq_ptr_hash>
 { };
 
-#if __cplusplus > 201103L
+#if __cplusplus >= 201402L
   /// @relates unique_ptr @{
 #define __cpp_lib_make_unique 201304
 
@@ -971,7 +972,22 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 inline typename _MakeUniq<_Tp>::__invalid_type
 make_unique(_Args&&...) = delete;
   // @} relates unique_ptr
-#endif
+#endif // C++14
+
+#if __cplusplus > 201703L && __cpp_concepts
+  // _GLIBCXX_RESOLVE_LIB_DEFECTS
+  // 2948. unique_ptr does not define operator<< for stream output
+  /// Stream output operator for unique_ptr
+  template
+inline basic_ostream<_CharT, _Traits>&
+operator<<(basic_ostream<_CharT, _Traits>& __os,
+  const unique_ptr<_Tp, _Dp>& __p)
+requires requires { __os << __p.get(); }
+{
+  __os << __p.get();
+  return __os;
+}
+#endif // C++20
 
   // @} group pointer_abstractions
 
diff --git a/libstdc++-v3/testsuite/20_util/unique_ptr/io/lwg2948.cc 
b/libstdc++-v3/testsuite/20_util/unique_ptr/io/lwg2948.cc
new file mode 100644
index 000..3f4e4dfabe7
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/unique_ptr/io/lwg2948.cc
@@ -0,0 +1,91 @@
+// Copyright (C) 2020 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library 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.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// .
+
+// { dg-options "-std=gnu++2a" }
+// { dg-do run { target c++2a } }
+
+#include 
+#include 
+#include 
+
+template
+  concept streamable = requires (S& o, const T& p) { o << p; };
+
+template
+  bool
+  check(const std::unique_ptr& p)
+  {
+std::ostringstream ss1, ss2;
+ss1 << p;
+ss2 << p.get();
+return ss1.str() == ss2.str();
+  }
+
+void
+test01()
+{
+  static_assert( streamable> );
+
+  std::unique_ptr p;
+  VERIFY( check(p) );
+  p = std::make_unique();
+  VERIFY( check(p) );
+}
+
+template
+  struct deleter
+  {
+struct pointer
+{
+  pointer() { }
+  pointer(std::nullptr_t) { }
+  explicit operator bool() const { return false; }
+  bool operator==(pointer) const { return true; }
+};
+
+void operator()(pointer) const { }
+  };
+
+template
+  int
+  operator<<(std::basic_ostream& o, typename deleter::pointer&&)
+  {
+o << C{'P'};
+return 1; // no requirement that this operator returns the stream
+  }
+
+template
+  using Unique_ptr = std::unique_ptr;
+
+static_assert( streamable>> );
+static_assert( ! streamable>> );
+static_assert( ! streamable>> );
+static_assert( streamable>> );
+
+void
+test02()
+{
+  Unique_ptr> p;
+  VERIFY( check(p) );
+}
+
+int
+main()
+{
+  test01();
+  test02();
+}


Re: [PATCH RFA] tree-inline: Fix VLA handling [PR95552]

2020-06-08 Thread Jason Merrill via Gcc-patches

On 6/8/20 5:46 AM, Eric Botcazou wrote:

The only case handled specially is TYPE_DECL; other DECL_EXPRs fall
through to the default case, where we WALK_SUBTREE over all the operands
of the expression, which for DECL_EXPR is the decl.


It seems hard to believe that the inliner relies on this to copy DECLs though,


I agree!  I imagine the actual inliner is unaffected because that 
happens in GIMPLE now, so this only affects FE cloning.  I don't know if 
any other front ends use a walk_tree callback like copy_tree_body_r that 
would replace a type in the same way.



see the calls to remap_decl[s].


Which ones?


And note that remap_decl has had a special
handling for DECL_ORIGINAL_TYPE of TYPE_DECLs since 2003.

Yes, but the problem is that remap_decl isn't getting called.


Are you sure the
problem is not that the TYPE_DECL is not attached to the enclosing BIND_EXPR?


Attaching it to the BIND_EXPR doesn't help walk_tree_1 do the right 
thing with the DECL_EXPR.


Jason



[committed] d: Fix regression caused by recent refactoring (PR95573)

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

This parch merges the D front-end implementation with upstream dmd
5041e56f1.  Fixing a small regression made by one of the refactorings.

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

Regards
Iain.


gcc/d/ChangeLog:

PR d/95573
* dmd/MERGE: Merge upstream dmd 5041e56f1.
---
 gcc/d/dmd/MERGE   | 2 +-
 gcc/d/dmd/mtype.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/gcc/d/dmd/MERGE b/gcc/d/dmd/MERGE
index e2ebd27b19b..163a70ddb26 100644
--- a/gcc/d/dmd/MERGE
+++ b/gcc/d/dmd/MERGE
@@ -1,4 +1,4 @@
-955b8b36f8bbacc59745b44cdf48ef1ddeb01bcd
+5041e56f12806f13a8fa5e98a6c98279636a8d2a
 
 The first line of this file holds the git revision number of the last
 merge done from the dlang/dmd repository.
diff --git a/gcc/d/dmd/mtype.c b/gcc/d/dmd/mtype.c
index 7684516da99..011aff7ec93 100644
--- a/gcc/d/dmd/mtype.c
+++ b/gcc/d/dmd/mtype.c
@@ -9384,7 +9384,7 @@ Type *Parameter::isLazyArray()
 TypeDelegate *td = (TypeDelegate *)tel;
 TypeFunction *tf = td->next->toTypeFunction();
 
-if (!tf->parameterList.varargs == VARARGnone && 
tf->parameterList.length() == 0)
+if (tf->parameterList.varargs == VARARGnone && 
tf->parameterList.length() == 0)
 {
 return tf->next;// return type of delegate
 }
-- 
2.20.1



Re: libstdc++: Extend memcmp optimization in std::lexicographical_compare

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

On 05/06/20 22:24 +0200, François Dumont via Libstdc++ wrote:

diff --git a/libstdc++-v3/include/debug/safe_iterator.tcc 
b/libstdc++-v3/include/debug/safe_iterator.tcc
index 888ac803ae5..ca4e2d52d1d 100644
--- a/libstdc++-v3/include/debug/safe_iterator.tcc
+++ b/libstdc++-v3/include/debug/safe_iterator.tcc
@@ -470,6 +470,80 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
  return __equal_aux1(__first1, __last1, __first2);
}

+  template
+int
+__lexicographical_compare_aux(
+   const ::__gnu_debug::_Safe_iterator<_Ite1, _Seq1, _Cat1>& __first1,
+   const ::__gnu_debug::_Safe_iterator<_Ite1, _Seq1, _Cat1>& __last1,
+   _II2 __first2, _II2 __last2)
+{
+  typename ::__gnu_debug::_Distance_traits<_Ite1>::__type __dist1;
+  __glibcxx_check_valid_range2(__first1, __last1, __dist1);
+  __glibcxx_check_valid_range(__first2, __last2);
+
+  if (__dist1.second > ::__gnu_debug::__dp_equality)
+   return std::__lexicographical_compare_aux(__first1.base(),
+ __last1.base(),
+ __first2, __last2);
+  return std::__lexicographical_compare_aux1(__first1, __last1,
+__first2, __last2);


What's the rationale for the choice of whether to call aux or aux1
here?

It seems to be that if we know [first1, last1) is a valid range, we
use aux with the unsafe iterators (which means we do overload
resolution again for all the overloads that include _Safe_iterator,
but we know we don't have safe iterators now). Otherwise, if we don't
know it's a valid range, we call aux1 with the safe iterators.

Why don't we use aux1 in both cases?




[committed] d: Merge upstream dmd 955b8b36f.

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

This patch merges the D front-end implementation with upstream dmd
955b8b36f.  Merges AndAndExp and OrOrExp into a LogicalExp AST node.

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

Regards
Iain.


gcc/d/ChangeLog:

* dmd/MERGE: Merge upstream dmd 955b8b36f.
* expr.cc (ExprVisitor::visit (AndAndExp *)): Rename type to ...
(ExprVisitor::visit (LogicalExp *)): ... this.  Handle both 'and if'
and 'or if' expression nodes.
(ExprVisitor::visit (OrOrExp *)): Remove.
---
 gcc/d/dmd/MERGE   |  2 +-
 gcc/d/dmd/dinterpret.c| 63 -
 gcc/d/dmd/expression.c| 28 +++--
 gcc/d/dmd/expression.h| 12 +-
 gcc/d/dmd/expressionsem.c | 85 ++-
 gcc/d/dmd/opover.c|  4 +-
 gcc/d/dmd/optimize.c  | 60 +--
 gcc/d/dmd/parse.c |  4 +-
 gcc/d/dmd/sideeffect.c|  9 +
 gcc/d/dmd/staticcond.c| 28 ++---
 gcc/d/dmd/visitor.h   |  6 +--
 gcc/d/expr.cc | 39 +-
 12 files changed, 60 insertions(+), 280 deletions(-)

diff --git a/gcc/d/dmd/MERGE b/gcc/d/dmd/MERGE
index f71d20cf462..e2ebd27b19b 100644
--- a/gcc/d/dmd/MERGE
+++ b/gcc/d/dmd/MERGE
@@ -1,4 +1,4 @@
-73d8e2fecb9e73422464b4cbf71f2b2967c9a75d
+955b8b36f8bbacc59745b44cdf48ef1ddeb01bcd
 
 The first line of this file holds the git revision number of the last
 merge done from the dlang/dmd repository.
diff --git a/gcc/d/dmd/dinterpret.c b/gcc/d/dmd/dinterpret.c
index 6b4a2b73a7f..ada1d8bc54f 100644
--- a/gcc/d/dmd/dinterpret.c
+++ b/gcc/d/dmd/dinterpret.c
@@ -4465,7 +4465,7 @@ public:
 result = pue->exp();
 }
 
-void visit(AndAndExp *e)
+void visit(LogicalExp *e)
 {
 // Check for an insidePointer expression, evaluate it if so
 interpretFourPointerRelation(pue, e);
@@ -4477,9 +4477,10 @@ public:
 return;
 
 int res;
-if (result->isBool(false))
-res = 0;
-else if (isTrueBool(result))
+const bool andand = e->op == TOKandand;
+if (andand ? result->isBool(false) : isTrueBool(result))
+res = !andand;
+else if (andand ? isTrueBool(result) : result->isBool(false))
 {
 UnionExp ue2;
 result = interpret(, e->e2, istate);
@@ -4497,64 +4498,14 @@ public:
 res = 1;
 else
 {
-result->error("%s does not evaluate to a boolean", 
result->toChars());
+result->error("`%s` does not evaluate to a boolean", 
result->toChars());
 result = CTFEExp::cantexp;
 return;
 }
 }
 else
 {
-result->error("%s cannot be interpreted as a boolean", 
result->toChars());
-result = CTFEExp::cantexp;
-return;
-}
-if (goal != ctfeNeedNothing)
-{
-new(pue) IntegerExp(e->loc, res, e->type);
-result = pue->exp();
-}
-}
-
-void visit(OrOrExp *e)
-{
-// Check for an insidePointer expression, evaluate it if so
-interpretFourPointerRelation(pue, e);
-if (result)
-return;
-
-result = interpret(e->e1, istate);
-if (exceptionOrCant(result))
-return;
-
-int res;
-if (isTrueBool(result))
-res = 1;
-else if (result->isBool(false))
-{
-UnionExp ue2;
-result = interpret(, e->e2, istate);
-if (exceptionOrCant(result))
-return;
-if (result->op == TOKvoidexp)
-{
-assert(e->type->ty == Tvoid);
-result = NULL;
-return;
-}
-if (result->isBool(false))
-res = 0;
-else if (isTrueBool(result))
-res = 1;
-else
-{
-result->error("%s cannot be interpreted as a boolean", 
result->toChars());
-result = CTFEExp::cantexp;
-return;
-}
-}
-else
-{
-result->error("%s cannot be interpreted as a boolean", 
result->toChars());
+result->error("`%s` cannot be interpreted as a boolean", 
result->toChars());
 result = CTFEExp::cantexp;
 return;
 }
diff --git a/gcc/d/dmd/expression.c b/gcc/d/dmd/expression.c
index d15081763df..0b21fc949c5 100644
--- a/gcc/d/dmd/expression.c
+++ b/gcc/d/dmd/expression.c
@@ -1895,7 +1895,7 @@ bool functionParameters(Loc loc, Scope *sc, TypeFunction 
*tf,
 // edtor => (__gate || edtor)
 assert(tmp->edtor);
 Expression *e = tmp->edtor;
-e = new OrOrExp(e->loc, new VarExp(e->loc, gate), e);
+e = new LogicalExp(e->loc, TOKoror, new 

Re: [Patch][RFC] openmp: ensure variables in offload table are streamed out (PRs 94848 + 95551) (was: Re: [Patch][RFC] openmp: don't add artificial const decl to offload table (PRs 94848 + 95551))

2020-06-08 Thread Jakub Jelinek via Gcc-patches
On Mon, Jun 08, 2020 at 09:36:29PM +0200, Tobias Burnus wrote:
> I have now split-off the missed-optimization task to a new
> PR, PR95583, to be handled in a proper way instead of trying
> to cook-up a hackish special-case version.
> 
> This patch now simply sets the force_output flag.
> 
> (a) As output_offload_tables() (i.e. LTO streamout)
> comes very early, one could just set the force_output flag
> in this file without further checks or omp-offload.c changes
> (b) Alternatively, one check that it really works by using
>   gcc_assert (symtab_node::get (it));
> in either or both files.
> (c) or assuming that some optimization worked, one could use:
>   if (!symtab_node::get (it))
> continue;
> 
> The patch does (c) as trimming it to (b) or (a) is trival.

I prefer the patch as is, output_offload_tables() isn't actually that early,
there are all the early optimizations before that.
And if we don't optimize it early enough, perhaps we need a targeted unused
target variable removal subpass (early ipa).

> OK? What about backporting to GCC 10?

Ok.  Please wait a few days before backporting.

Jakub



Re: [PATCH] coroutines: Add a cleanup expression for g-r-o when needed [PR95477].

2020-06-08 Thread Iain Sandoe

Nathan Sidwell  wrote:


On 6/8/20 5:17 AM, Iain Sandoe wrote:

Hi
The PR reports that we fail to destroy the object initially created from
the get-return-object call.   Fixed by adding a cleanup when the DTOR is
non-trivial.  In addition, to meet the specific wording that the call to
get_return_object creates the glvalue for the return, we must construct
that in-place in the return object to avoid a second copy/move CTOR.
tested on x86_64,powerpc64-linux, x86_64-darwin
OK for master?
10.2?
thanks
Iain
gcc/cp/ChangeLog:
PR c++/95477
* coroutines.cc (morph_fn_to_coro): Apply a cleanup to
the get return object when the DTOR is non-trivial.
gcc/testsuite/ChangeLog:
* g++.dg/coroutines/pr95477.C: New test.
---
 gcc/cp/coroutines.cc  | 61 +++
 gcc/testsuite/g++.dg/coroutines/pr95477.C | 37 ++
 2 files changed, 89 insertions(+), 9 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/coroutines/pr95477.C
diff --git a/gcc/cp/coroutines.cc b/gcc/cp/coroutines.cc
index f2d7853477d..5a78bec1c9a 100644
--- a/gcc/cp/coroutines.cc
+++ b/gcc/cp/coroutines.cc
@@ -4284,12 +4284,34 @@ morph_fn_to_coro (tree orig, tree *resumer, tree  
*destroyer)

 tree gro = NULL_TREE;
   tree gro_bind_vars = NULL_TREE;
+  tree gro_cleanup_stmt = NULL_TREE;
   /* We have to sequence the call to get_return_object before initial
  suspend.  */
   if (gro_is_void_p)
-finish_expr_stmt (get_ro);
+r = get_ro;
+  else if (same_type_p (gro_type, fn_return_type))
+{
+ /* [dcl.fct.def.coroutine] / 7
+   The expression promise.get_return_object() is used to initialize the
+   glvalue result or... (see below)
+   Construct the return result directly.  */
+  if (TYPE_NEEDS_CONSTRUCTING (gro_type))
+   {
+ vec *arg = make_tree_vector_single (get_ro);
+ r = build_special_member_call (DECL_RESULT (orig),
+complete_ctor_identifier,
+, gro_type, LOOKUP_NORMAL,
+tf_warning_or_error);
+ release_tree_vector (arg);
+   }
+  else
+   r = build2_loc (fn_start, INIT_EXPR, gro_type,
+   DECL_RESULT (orig), get_ro);
+}
   else
 {
+  /* ... or ... Construct an object that will be used as the single
+   param to the CTOR for the return object.  */
   gro = build_lang_decl (VAR_DECL, get_identifier ("coro.gro"), gro_type);
   DECL_CONTEXT (gro) = current_scope ();
   DECL_ARTIFICIAL (gro) = true;
@@ -4306,8 +4328,21 @@ morph_fn_to_coro (tree orig, tree *resumer, tree  
*destroyer)

}
   else
r = build2_loc (fn_start, INIT_EXPR, gro_type, gro, get_ro);
-  finish_expr_stmt (r);
+  /* The constructed object might require a cleanup.  */
+  if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (gro_type))
+   {
+ tree cleanup
+   = build_special_member_call (gro, complete_dtor_identifier,
+NULL, gro_type, LOOKUP_NORMAL,
+tf_warning_or_error);
+ gro_cleanup_stmt = build_stmt (input_location, CLEANUP_STMT, NULL,
+cleanup, gro);
+   }
 }
+  finish_expr_stmt (r);
+
+  if (gro_cleanup_stmt)
+CLEANUP_BODY (gro_cleanup_stmt) = push_stmt_list ();
 /* Initialize the resume_idx_name to 0, meaning "not started".  */
   tree resume_idx_m
@@ -4349,14 +4384,15 @@ morph_fn_to_coro (tree orig, tree *resumer, tree  
*destroyer)

  promise was constructed.  We now supply a reference to that var,
  either as the return value (if it's the same type) or to the CTOR
  for an object of the return type.  */
-  if (gro_is_void_p)
-r = NULL_TREE;
-  else
-r = rvalue (gro);
 -  if (!same_type_p (gro_type, fn_return_type))
+  if (same_type_p (gro_type, fn_return_type))
+r = gro_is_void_p ? NULL_TREE : DECL_RESULT (orig);
+  else
 {
-  /* The return object is , even if the gro is void.  */
+  /* If we have void gro and a non-class return type, then pick a
+defensive initialisation value.  */
+  r = gro_is_void_p ? integer_zero_node : rvalue (gro);
+  /* The return object is constructed, even if the gro is void.  */


Would error_mark_node work here?  I presume we've already diagnosed the  
problem, so will result in no cascade of errors.


We have not diagnosed the problem - it’s valid to have a void g-r-o and a  
non-void function

return.

I am not sure the circumstance has been identified specifically where this  
(valid) permutation
is found together with a specialization of the traits that has a non-class  
return type. (I spotted

this as a corner-case while working on the code).

Perhaps I should construct a test-case and see how the other compilers  
handle it.


Do you want me to do that as part of this fix, or can it be a follow-on?
thanks

[Patch][RFC] openmp: ensure variables in offload table are streamed out (PRs 94848 + 95551) (was: Re: [Patch][RFC] openmp: don't add artificial const decl to offload table (PRs 94848 + 95551))

2020-06-08 Thread Tobias Burnus

Hi Jakub,

On 6/8/20 5:30 PM, Jakub Jelinek wrote:


I really don't see what is special exactly on TREE_READONLY DECL_ARTIFICIAL


I have now split-off the missed-optimization task to a new
PR, PR95583, to be handled in a proper way instead of trying
to cook-up a hackish special-case version.

This patch now simply sets the force_output flag.

(a) As output_offload_tables() (i.e. LTO streamout)
comes very early, one could just set the force_output flag
in this file without further checks or omp-offload.c changes
(b) Alternatively, one check that it really works by using
  gcc_assert (symtab_node::get (it));
in either or both files.
(c) or assuming that some optimization worked, one could use:
  if (!symtab_node::get (it))
continue;

The patch does (c) as trimming it to (b) or (a) is trival.

All should give currently the same result; the assert checks
for this, the "if (...)" is future-optimizations proof, but
I fear that before adding passes before output_offload_tables()
it makes no difference. (→new PR).

(The omp_finish_file comes late enough, but as the LTO has been
written before, it does not help.)

OK? What about backporting to GCC 10?

Tobias

-
Mentor Graphics (Deutschland) GmbH, Arnulfstraße 201, 80634 München / Germany
Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Alexander 
Walter
openmp: ensure variables in offload table are streamed out (PRs 94848 + 95551)

gcc/ChangeLog:

	PR lto/94848
	PR middle-end/95551
	* omp-offload.c (add_decls_addresses_to_decl_constructor,
	omp_finish_file): Skip removed items.
	* lto-cgraph.c (output_offload_tables): Likewise; set force_output
	to this node for variables and functions.

libgomp/ChangeLog:

	PR lto/94848
	PR middle-end/95551
	* testsuite/libgomp.fortran/target-var.f90: New test.

 gcc/lto-cgraph.c |  8 ++
 gcc/omp-offload.c| 12 -
 libgomp/testsuite/libgomp.fortran/target-var.f90 | 32 
 3 files changed, 51 insertions(+), 1 deletion(-)

diff --git a/gcc/lto-cgraph.c b/gcc/lto-cgraph.c
index a671c671fa7..93a99f3465b 100644
--- a/gcc/lto-cgraph.c
+++ b/gcc/lto-cgraph.c
@@ -1069,6 +1069,10 @@ output_offload_tables (void)
 
   for (unsigned i = 0; i < vec_safe_length (offload_funcs); i++)
 {
+  symtab_node *node = symtab_node::get ((*offload_funcs)[i]);
+  if (!node)
+	continue;
+  node->force_output = true;
   streamer_write_enum (ob->main_stream, LTO_symtab_tags,
 			   LTO_symtab_last_tag, LTO_symtab_unavail_node);
   lto_output_fn_decl_ref (ob->decl_state, ob->main_stream,
@@ -1077,6 +1081,10 @@ output_offload_tables (void)
 
   for (unsigned i = 0; i < vec_safe_length (offload_vars); i++)
 {
+  symtab_node *node = symtab_node::get ((*offload_vars)[i]);
+  if (!node)
+	continue;
+  node->force_output = true;
   streamer_write_enum (ob->main_stream, LTO_symtab_tags,
 			   LTO_symtab_last_tag, LTO_symtab_variable);
   lto_output_var_decl_ref (ob->decl_state, ob->main_stream,
diff --git a/gcc/omp-offload.c b/gcc/omp-offload.c
index b2df91a5724..4e44cfc9d0a 100644
--- a/gcc/omp-offload.c
+++ b/gcc/omp-offload.c
@@ -125,6 +125,10 @@ add_decls_addresses_to_decl_constructor (vec *v_decls,
 #endif
 	  && lookup_attribute ("omp declare target link", DECL_ATTRIBUTES (it));
 
+  /* See also omp_finish_file and output_offload_tables in lto-cgraph.c.  */
+  if (!symtab_node::get (it))
+	continue;
+
   tree size = NULL_TREE;
   if (is_var)
 	size = fold_convert (const_ptr_type_node, DECL_SIZE_UNIT (it));
@@ -341,7 +345,7 @@ omp_finish_file (void)
   add_decls_addresses_to_decl_constructor (offload_vars, v_v);
 
   tree vars_decl_type = build_array_type_nelts (pointer_sized_int_node,
-		num_vars * 2);
+		vec_safe_length (v_v));
   tree funcs_decl_type = build_array_type_nelts (pointer_sized_int_node,
 		 num_funcs);
   SET_TYPE_ALIGN (vars_decl_type, TYPE_ALIGN (pointer_sized_int_node));
@@ -376,11 +380,17 @@ omp_finish_file (void)
   for (unsigned i = 0; i < num_funcs; i++)
 	{
 	  tree it = (*offload_funcs)[i];
+	  /* See also add_decls_addresses_to_decl_constructor
+	 and output_offload_tables in lto-cgraph.c.  */
+	  if (!symtab_node::get (it))
+	continue;
 	  targetm.record_offload_symbol (it);
 	}
   for (unsigned i = 0; i < num_vars; i++)
 	{
 	  tree it = (*offload_vars)[i];
+	  if (!symtab_node::get (it))
+	continue;
 #ifdef ACCEL_COMPILER
 	  if (DECL_HAS_VALUE_EXPR_P (it)
 	  && lookup_attribute ("omp declare target link",
diff --git a/libgomp/testsuite/libgomp.fortran/target-var.f90 b/libgomp/testsuite/libgomp.fortran/target-var.f90
new file mode 100644
index 000..5e5ccd47c96
--- /dev/null
+++ b/libgomp/testsuite/libgomp.fortran/target-var.f90
@@ -0,0 +1,32 @@
+! { dg-additional-options "-O3" }
+!
+! With -O3 the static local variable A.10 generated for
+! the 

Re: [PATCH] coroutines: Ensure distinct DTOR trees [PR95137].

2020-06-08 Thread Nathan Sidwell

On 5/22/20 7:19 AM, Iain Sandoe wrote:

Hi

This is almost obvious - except perhaps I’m missing some more
efficient way of doing it; it seems less than ideal to have to build the
ctor call twice with exactly the same inputs.

If there’s no better way ….


ok.

nathan

--
Nathan Sidwell


Re: [PATCH] coroutines: Handle lambda closure pointers like 'this'.

2020-06-08 Thread Nathan Sidwell

On 5/22/20 8:27 AM, Iain Sandoe wrote:

Hi,

We didn’t quite have time to push this through before the 10.1
deadline, but (since it’s a correctness issue) it should be applied
to the branch too.

tested on x86_64-darwin, linux
OK for master?
10.2 after some bake time?
thanks
Iain

===

It was agreed amongst the implementors that the correct
interpretation of the standard is that lambda closure pointers
should be treated in the same manner as class object pointers.

gcc/cp/ChangeLog:

* coroutines.cc (instantiate_coro_traits): Pass a reference
to lambda closure objects to traits instantiation.
(morph_fn_to_coro): Likewise for promise parameter
preview and allocator lookup.
---
  gcc/cp/coroutines.cc | 19 +--
  1 file changed, 5 insertions(+), 14 deletions(-)

diff --git a/gcc/cp/coroutines.cc b/gcc/cp/coroutines.cc
index b79e2c66b70..6e3f03bdb0d 100644
--- a/gcc/cp/coroutines.cc
+++ b/gcc/cp/coroutines.cc
@@ -304,8 +304,8 @@ instantiate_coro_traits (tree fndecl, location_t kw)
  
while (arg_node != NULL_TREE && !VOID_TYPE_P (TREE_VALUE (arg_node)))

  {
-  /* See PR94807, as to why we must exclude lambda here.  */
-  if (is_this_parameter (arg) && !lambda_p)
+  if (is_this_parameter (arg)
+ || (lambda_p && DECL_NAME (arg) == closure_identifier))


DECL_NAME (arg) == closure_identifier is sufficient -- it's in the 
implementor's namespace.  Just like how is_this_parameter works. (that I 
fixed trunk to not label a lambda's instantiation a this pointer doesn't 
matter here, so you don't have to account for it not being so on 10.2).



{
  /* We pass a reference to *this to the param preview.  */
  tree ct = TREE_TYPE (TREE_TYPE (arg));
@@ -3793,13 +3793,8 @@ morph_fn_to_coro (tree orig, tree *resumer, tree 
*destroyer)
parm.frame_type = actual_type;
  
  	  parm.this_ptr = is_this_parameter (arg);

- /* See PR94807.  When a lambda is in a template instantiation, the
-closure object is named 'this' instead of '__closure'.  */
  if (lambda_p)
-   {
- parm.lambda_cobj = DECL_NAME (arg) == closure_identifier;
- gcc_checking_assert (!parm.this_ptr);
-   }
+   parm.lambda_cobj = DECL_NAME (arg) == closure_identifier;


but this bit will be different on 10.2.  I think you want
if (lambda_p)
 { parm.lambda_cobj = parm.this_ptr || DECL_NAME (arg) == 
closure_identifier;

   parm.this_pointer = false;
}
?


looks ok otherwise, for both.


--
Nathan Sidwell


Re: [PATCH] coroutines: Add a cleanup expression for g-r-o when needed [PR95477].

2020-06-08 Thread Nathan Sidwell

On 6/8/20 5:17 AM, Iain Sandoe wrote:

Hi

The PR reports that we fail to destroy the object initially created from
the get-return-object call.   Fixed by adding a cleanup when the DTOR is
non-trivial.  In addition, to meet the specific wording that the call to
get_return_object creates the glvalue for the return, we must construct
that in-place in the return object to avoid a second copy/move CTOR.

tested on x86_64,powerpc64-linux, x86_64-darwin
OK for master?
10.2?
thanks
Iain

gcc/cp/ChangeLog:

PR c++/95477
* coroutines.cc (morph_fn_to_coro): Apply a cleanup to
the get return object when the DTOR is non-trivial.

gcc/testsuite/ChangeLog:

* g++.dg/coroutines/pr95477.C: New test.
---
  gcc/cp/coroutines.cc  | 61 +++
  gcc/testsuite/g++.dg/coroutines/pr95477.C | 37 ++
  2 files changed, 89 insertions(+), 9 deletions(-)
  create mode 100644 gcc/testsuite/g++.dg/coroutines/pr95477.C

diff --git a/gcc/cp/coroutines.cc b/gcc/cp/coroutines.cc
index f2d7853477d..5a78bec1c9a 100644
--- a/gcc/cp/coroutines.cc
+++ b/gcc/cp/coroutines.cc
@@ -4284,12 +4284,34 @@ morph_fn_to_coro (tree orig, tree *resumer, tree 
*destroyer)
  
tree gro = NULL_TREE;

tree gro_bind_vars = NULL_TREE;
+  tree gro_cleanup_stmt = NULL_TREE;
/* We have to sequence the call to get_return_object before initial
   suspend.  */
if (gro_is_void_p)
-finish_expr_stmt (get_ro);
+r = get_ro;
+  else if (same_type_p (gro_type, fn_return_type))
+{
+ /* [dcl.fct.def.coroutine] / 7
+   The expression promise.get_return_object() is used to initialize the
+   glvalue result or... (see below)
+   Construct the return result directly.  */
+  if (TYPE_NEEDS_CONSTRUCTING (gro_type))
+   {
+ vec *arg = make_tree_vector_single (get_ro);
+ r = build_special_member_call (DECL_RESULT (orig),
+complete_ctor_identifier,
+, gro_type, LOOKUP_NORMAL,
+tf_warning_or_error);
+ release_tree_vector (arg);
+   }
+  else
+   r = build2_loc (fn_start, INIT_EXPR, gro_type,
+   DECL_RESULT (orig), get_ro);
+}
else
  {
+  /* ... or ... Construct an object that will be used as the single
+   param to the CTOR for the return object.  */
gro = build_lang_decl (VAR_DECL, get_identifier ("coro.gro"), gro_type);
DECL_CONTEXT (gro) = current_scope ();
DECL_ARTIFICIAL (gro) = true;
@@ -4306,8 +4328,21 @@ morph_fn_to_coro (tree orig, tree *resumer, tree 
*destroyer)
}
else
r = build2_loc (fn_start, INIT_EXPR, gro_type, gro, get_ro);
-  finish_expr_stmt (r);
+  /* The constructed object might require a cleanup.  */
+  if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (gro_type))
+   {
+ tree cleanup
+   = build_special_member_call (gro, complete_dtor_identifier,
+NULL, gro_type, LOOKUP_NORMAL,
+tf_warning_or_error);
+ gro_cleanup_stmt = build_stmt (input_location, CLEANUP_STMT, NULL,
+cleanup, gro);
+   }
  }
+  finish_expr_stmt (r);
+
+  if (gro_cleanup_stmt)
+CLEANUP_BODY (gro_cleanup_stmt) = push_stmt_list ();
  
/* Initialize the resume_idx_name to 0, meaning "not started".  */

tree resume_idx_m
@@ -4349,14 +4384,15 @@ morph_fn_to_coro (tree orig, tree *resumer, tree 
*destroyer)
   promise was constructed.  We now supply a reference to that var,
   either as the return value (if it's the same type) or to the CTOR
   for an object of the return type.  */
-  if (gro_is_void_p)
-r = NULL_TREE;
-  else
-r = rvalue (gro);
  
-  if (!same_type_p (gro_type, fn_return_type))

+  if (same_type_p (gro_type, fn_return_type))
+r = gro_is_void_p ? NULL_TREE : DECL_RESULT (orig);
+  else
  {
-  /* The return object is , even if the gro is void.  */
+  /* If we have void gro and a non-class return type, then pick a
+defensive initialisation value.  */
+  r = gro_is_void_p ? integer_zero_node : rvalue (gro);
+  /* The return object is constructed, even if the gro is void.  */


Would error_mark_node work here?  I presume we've already diagnosed the 
problem, so will result in no cascade of errors.



if (CLASS_TYPE_P (fn_return_type))
{
  vec *args = NULL;
@@ -4374,12 +4410,19 @@ morph_fn_to_coro (tree orig, tree *resumer, tree 
*destroyer)
  if (args)
release_tree_vector (args);
}
-  else /* ??? suppose we have non-class return and void gro?  */
+  else
r = build1_loc (input_location, CONVERT_EXPR, fn_return_type, r);
  }
  
finish_return_stmt (r);
  
+  if (gro_cleanup_stmt)

+{
+  CLEANUP_BODY (gro_cleanup_stmt)
+   

[PATCH, committed] PR95195 - Fortran testcase should clean up afterwards

2020-06-08 Thread Harald Anlauf
In a parallel make check-fortran there was a race condition due to a
file "test.dat" not being cleaned up.  Adjust testcase to use a
separate filename, and instead of failing catch error message within
the program.

Committed as obvious.

Thanks,
Harald


PR fortran/95195 - Fortran testcase should clean up afterwards

Change testcase to check error message (iomsg) at runtime, rather than to crash.

libgfortran/
PR fortran/95091
* io/transfer.c (finalize_transfer): Fix type in error message.

gcc/testsuite/
PR fortran/95195
* gfortran.dg/namelist_97.f90: Adjust testcase.
diff --git a/gcc/testsuite/gfortran.dg/namelist_97.f90 b/gcc/testsuite/gfortran.dg/namelist_97.f90
index 4907e46b46a..3c6ad7ce3c1 100644
--- a/gcc/testsuite/gfortran.dg/namelist_97.f90
+++ b/gcc/testsuite/gfortran.dg/namelist_97.f90
@@ -1,14 +1,16 @@
 ! { dg-do run }
-! { dg-output "At line 12 .*" }
-! { dg-shouldfail "Fortran runtime error: Namelist formatting .* FORM='UNFORMATTED'" }
 !
 ! PR95195 - improve runtime error when writing a namelist to an unformatted file

 program test
   character(len=11) :: my_form = 'unformatted'
   integer   :: i = 1, j = 2, k = 3
+  character(80) :: iomsg
   namelist /nml1/ i, j, k
-  open  (unit=10, file='test.dat', form=my_form)
-  write (unit=10, nml=nml1)
+  open  (unit=10, file='namelist_97.dat', form=my_form)
+  write (unit=10, nml=nml1, iostat=iostat, iomsg=iomsg)
   close (unit=10, status='delete')
+  if (iostat == 0) stop 1
+  if (iomsg  /= "Namelist formatting for unit connected with FORM='UNFORMATTED'") &
+   stop 2
 end program test
diff --git a/libgfortran/io/transfer.c b/libgfortran/io/transfer.c
index cd51679ff46..dc18bc34b32 100644
--- a/libgfortran/io/transfer.c
+++ b/libgfortran/io/transfer.c
@@ -4127,7 +4127,7 @@ finalize_transfer (st_parameter_dt *dtp)
 	 {
 	   generate_error (>common, LIBERROR_OPTION_CONFLICT,
 			   "Namelist formatting for unit connected "
-			   "with FORM='UNFORMATTED");
+			   "with FORM='UNFORMATTED'");
 	   return;
 	 }



Re: [PATCH RFC] bootstrap: Update requirement to C++11.

2020-06-08 Thread Jason Merrill via Gcc-patches
On Mon, Jun 8, 2020 at 6:54 AM Martin Jambor  wrote:

> Hi,
>
> On Fri, May 15 2020, Jason Merrill via Gcc-patches wrote:
> > commit f466a9f3f121f16b97071162806255fb464718f2
> > Author: Jason Merrill 
> > Date:   Fri May 15 17:15:38 2020 -0400
> >
> > bootstrap: Update requirement to C++11.
> >
> > There was general agreement last November that we would move to
> allowing
> > C++11 features to be used in GCC 11; this patch implements that
> direction.
> >
>
> since this commit (gcc-11-462-g5329b59a2e1) I cannot bootstrap GCC on
> gcc45.fsffrance.org compile farm machine which is an i586-linux-gnu box
> where the system compiler is GCC 4.9.2 which I believe should be new
> enough.  Still, stage 1 fails with the errors below.
>
> What baffles me is that only bootstrap fails on the old machine.  If I
> configure with --disable-bootstrap, make finishes fine.  For the record,
> I configure gcc there with:
>
> /home/jamborm/gcc/trunk/src/configure
> --prefix=/home/jamborm/gcc/trunk/inst --enable-languages=c,c++
> --enable-checking=yes --disable-libsanitizer --disable-multilib
> --disable-libcilkrts --with-gmp=/opt/cfarm/gmp-latest
> --with-mpfr=/opt/cfarm/mpfr-latest --with-mpc=/opt/cfarm/mpc-latest
>
> In my other i686 testing environment, which is a chroot with gcc 8.3.0
> as the system compiler, I can bootstrap without any issues.
>
> I can open a PR if you want me to.
>
> Thanks,
>
> Martin
>
>
> g++ -std=c++11  -fno-PIE -c   -g   -DIN_GCC -fno-exceptions -fno-rtti
> -fasynchronous-unwind-tables -W -Wall -Wno-narrowing -Wwrite-strings
> -Wcast-qual -Wno-format -Wmissing-format-attribute -Woverloaded-virtual
> -pedantic -Wno-long-long -Wno-variadic-macros -Wno-overlength-strings
> -fno-common  -DHAVE_CONFIG_H -I. -I. -I/home/jamborm/gcc/trunk/src/gcc
> -I/home/jamborm/gcc/trunk/src/gcc/.
> -I/home/jamborm/gcc/trunk/src/gcc/../include
> -I/home/jamborm/gcc/trunk/src/gcc/../libcpp/include
> -I/opt/cfarm/gmp-latest/include -I/opt/cfarm/mpfr-latest/include
> -I/opt/cfarm/mpc-latest/include
> -I/home/jamborm/gcc/trunk/src/gcc/../libdecnumber
> -I/home/jamborm/gcc/trunk/src/gcc/../libdecnumber/bid -I../libdecnumber
> -I/home/jamborm/gcc/trunk/src/gcc/../libbacktrace   -o i386-options.o -MT
> i386-options.o -MMD -MP -MF ./.deps/i386-options.TPo
> /home/jamborm/gcc/trunk/src/gcc/config/i386/i386-options.c
> In file included from
> /home/jamborm/gcc/trunk/src/gcc/config/i386/i386-options.c:94:0:
> /home/jamborm/gcc/trunk/src/gcc/config/i386/x86-tune-costs.h:32:56: error:
> uninitialized const member ‘stringop_algs::stringop_strategy::max’
>{rep_prefix_1_byte, {{-1, rep_prefix_1_byte, false;
> ^
> /home/jamborm/gcc/trunk/src/gcc/config/i386/x86-tune-costs.h:32:56:
> warning: missing initializer for member
> ‘stringop_algs::stringop_strategy::max’ [-Wmissing-field-initializers]
>

Hmm, yes, this was PR 49132, fixed in GCC 5.  I think we will want to work
around it by removing the 'const's from stringop_strategy.

Jason


Re: libstdc++: Extend memcmp optimization in std::lexicographical_compare

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

On 05/06/20 22:24 +0200, François Dumont via Libstdc++ wrote:

Hi

    Here is the last of my algo patches this time to extend the memcmp 
optimization to std::deque iterators and _GLIBCXX_DEBUG mode.


    To do so I had to return int in implementation details of 
lexicographical_compare to make sure we can treat a deque iterator 
range by chunk in a performant way.


Tested under Linux x86_64 normal and debug modes.

            * include/bits/stl_algobase.h
            (__lexicographical_compare_impl): Return int.
            (__lexicographical_compare::__lc): Likewise.
            (__lexicographical_compare_aux1(_II1, _II1, _II2, 
_II2)): New.
(__lexicographical_compare_aux1(_Deque_iterator<>, _Deque_iterator<>,
            _II2, _II2)): Declare.
            (__lexicographical_compare_aux1(_II1, _II1,
            _Deque_iterator<>, _Deque_iterator<>)): Declare.
(__lexicographical_compare_aux1(_Deque_iterator<>, _Deque_iterator<>,
            _Deque_iterator<>, _Deque_iterator<>)): Declare.
            (__lexicographical_compare_aux): Adapt, call later.


Is this meant to say "latter"? That's still not correct grammar
though. I think it would be better to name the function it calls
explicitly: "Call __lexicographical_compare_aux1."

            (__lexicographical_compare_aux(_Safe_iterator<>, 
_Safe_iterator<>,

            _II2, _II2)): Declare.
            (__lexicographical_compare_aux(_II1, _II1,
            _Safe_iterator<>, _Safe_iterator<>)): Declare.
            (__lexicographical_compare_aux(_Safe_iterator<>, 
_Safe_iterator<>,

            _Safe_iterator<>, _Safe_iterator<>)): Declare.
            (std::lexicographical_compare): Adapt, call later without 
__niter_base

            usage.
            * include/bits/deque.tcc (__lex_cmp_dit): New.
            (__lexicographical_compare_aux1): New.
            * include/debug/safe_iterator.tcc
            (__lexicographical_compare_aux(const _Safe_iterator<>&,
            const _Safe_iterator<>&, _II2, _II2)): New.
            (__lexicographical_compare_aux(
            const _Safe_iterator<>&, const_Safe_iterator<>&,
            const _Safe_iterator<>&, const _Safe_iterator<>&)): New.
            * testsuite/25_algorithms/lexicographical_compare/1.cc 
(test6, test7):

            New.
            * 
testsuite/25_algorithms/lexicographical_compare/deque_iterators/1.cc:

            New test.

Ok to commit ?

François





diff --git a/libstdc++-v3/include/bits/deque.tcc 
b/libstdc++-v3/include/bits/deque.tcc
index 1d32a1691c7..d7dbe64f3e1 100644
--- a/libstdc++-v3/include/bits/deque.tcc
+++ b/libstdc++-v3/include/bits/deque.tcc
@@ -1261,6 +1261,98 @@ _GLIBCXX_END_NAMESPACE_CONTAINER
  return true;
}

+  template


_II is the wrong name here, it mean InputIterator. All callers of this
function are constrained for random access iterators. This cannot be
called with an input iterator. Please use _RAIter.


+int
+__lex_cmp_dit(
+   const _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Ref, _Ptr>& __first1,
+   const _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Ref, _Ptr>& __last1,
+   _II __first2, _II __last2)
+{
+  typedef _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Ref, _Ptr> _Iter;
+  typedef typename _Iter::difference_type difference_type;
+
+  if (__first1._M_node != __last1._M_node)
+   {
+ difference_type __len = __last2 - __first2;
+ difference_type __flen


What does "flen" mean? Why not use len2 for last2 - first2, as we do
elsewhere? And then use len for min(len1, len2)?



+   = std::min(__len, __first1._M_last - __first1._M_cur);
+ if (int __ret = std::__lexicographical_compare_aux1(


This call (and the three later in this function) will do overload
resolution again on the full set of __lexicographical_compare_aux1
overloads, which includes the ones for deque iterators. But we know
that __first1._M_cur and __first1._M_last are not deque iterators.

__first2 could be a deque iterator, but I'm not sure if we really want
one function that has to handle that case anyway.


+ __first1._M_cur, __first1._M_last, __first2, __first2 + __flen))
+   return __ret;
+
+ __first2 += __flen;
+ __len -= __flen;
+ __flen = std::min(__len, _Iter::_S_buffer_size());
+ for (typename _Iter::_Map_pointer __node = __first1._M_node + 1;
+  __node != __last1._M_node;
+  __first2 += __flen, __len -= __flen,
+  __flen = std::min(__len, _Iter::_S_buffer_size()),
+  ++__node)
+   if (int __ret = std::__lexicographical_compare_aux1(
+ *__node, *__node + 

Re: [PATCH] Treat { 0 } specially for structs with the designated_init attribute.

2020-06-08 Thread Martin Sebor via Gcc-patches

On 6/3/20 9:57 PM, Asher Gordon via Gcc-patches wrote:

Hello,

I accidentally wrote 'free(loc)' instead of 'free (loc)'. Please see the
fixed patch attached below (contrib/check_GNU_style.sh says it's OK
now):


0001-Treat-0-specially-for-structs-with-the-designated_in.patch

 From 0445fba96ee9030feb00ebec893f8dfed153b12d Mon Sep 17 00:00:00 2001
From: Asher Gordon
Date: Wed, 3 Jun 2020 17:20:08 -0400
Subject: [PATCH] Treat { 0 } specially for structs with the designated_init
  attribute.

Closes #95379.


I think the idea behind this change is fine.  I just have a few
minor comments on the implementation.  A C front end maintainer
will need to formally review the patch.

As an aside, the bug number should be referenced in the change
message so that when the patch is committed it's automatically
reflected in the bug entry.  The contrib/mklog.py script should
do that automatically based on new test files added to verify
the bug fix/change, provided one such test is added and starts
with a PR c/95379 comment.  Also mentioning it in the Subject
of the email is helpful.



gcc/ChangeLog:

* doc/extend.texi: Document { 0 } as a special case for the
designated_init attribute.

gcc/c/ChangeLog:

* c-typeck.c (struct location_list): New type.
(struct initializer_stack): Add positional_init_locs for
-Wdesignated-init warnings.
(start_init): Initialize initializer_stack->positional_init_locs
to NULL.
(finish_init): Free initializer_stack->positional_init_locs.
(pop_init_level): Move -Wdesignated-init warning here from
process_init_element so that we can treat { 0 } specially.
(process_init_element): Instead of warning on -Wdesignated-init
here, remember a list of locations where we should warn and do the
actual warning in pop_init_level.

gcc/testsuite/ChangeLog:

* gcc.dg/Wdesignated-init.c: Add tests for ignoring { 0 }.


I don't think there's any "rule" against it but it's customary
to add test files for new features, rather than modify existing
ones (see also my comment about the post-commit hook above).


---
  gcc/ChangeLog   |  5 +++
  gcc/c/ChangeLog | 14 +++


ChangeLog changes need not be included in a patch (and shouldn't
be).  They are now automatically extracted from the commit message
and added to the ChangeLog files by a post-commit hook.



  gcc/c/c-typeck.c| 55 +++--
  gcc/doc/extend.texi |  4 ++
  gcc/testsuite/ChangeLog |  4 ++
  gcc/testsuite/gcc.dg/Wdesignated-init.c |  3 ++
  6 files changed, 81 insertions(+), 4 deletions(-)

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index edbcaf2bc4d..fd60a248226 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -95,6 +95,11 @@
(lto_tree_code_to_tag): Update.
(lto_tag_to_tree_code): Update.
  
+2020-06-03  Asher Gordon

+
+   * doc/extend.texi: Document { 0 } as a special case for the
+   designated_init attribute.
+
  2020-06-02  Felix Yang
  
  	PR target/95459

diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog
index abf31e57688..e77f46930ef 100644
--- a/gcc/c/ChangeLog
+++ b/gcc/c/ChangeLog
@@ -17,6 +17,20 @@
  
  	* c-objc-common.h (LANG_HOOKS_OMP_PREDETERMINED_MAPPING): Redefine.
  
+2020-06-03  Asher Gordon

+
+   * c-typeck.c (struct location_list): New type.
+   (struct initializer_stack): Add positional_init_locs for
+   -Wdesignated-init warnings.
+   (start_init): Initialize initializer_stack->positional_init_locs
+   to NULL.
+   (finish_init): Free initializer_stack->positional_init_locs.
+   (pop_init_level): Move -Wdesignated-init warning here from
+   process_init_element so that we can treat { 0 } specially.
+   (process_init_element): Instead of warning on -Wdesignated-init
+   here, remember a list of locations where we should warn and do the
+   actual warning in pop_init_level.
+
  2020-05-28  Nicolas Bértolo
  
  	* Make-lang.in: Remove extra slash.

diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c
index 385bf3a1c7b..2d04f70f0cf 100644
--- a/gcc/c/c-typeck.c
+++ b/gcc/c/c-typeck.c
@@ -8179,6 +8179,13 @@ struct constructor_range_stack
  
  static struct constructor_range_stack *constructor_range_stack;
  
+/* A list of locations.  */

+
+struct location_list {
+  struct location_list *next;
+  location_t loc;
+};


Rather than creating own linked list I suggest to consider making
use of one of GCC's data structures.


+
  /* This stack records separate initializers that are nested.
 Nested initializers can't happen in ANSI C, but GNU C allows them
 in cases like { ... (struct foo) { ... } ... }.  */
@@ -8197,6 +8204,7 @@ struct initializer_stack
char require_constant_value;
char require_constant_elements;
rich_location *missing_brace_richloc;
+  struct location_list *positional_init_locs;
  };
  
  static struct 

Re: [PATCH] AArch64: Adjust costing of by element MUL to be the same as SAME3 MUL.

2020-06-08 Thread Richard Sandiford
Tamar Christina  writes:
> diff --git a/gcc/config/aarch64/aarch64.c b/gcc/config/aarch64/aarch64.c
> index 
> 97da60762390db81df9cffaf316b909cd1609130..9cc8da338125afa01bc9fb645f4112d2d7ef548c
>  100644
> --- a/gcc/config/aarch64/aarch64.c
> +++ b/gcc/config/aarch64/aarch64.c
> @@ -11279,6 +11279,14 @@ aarch64_rtx_mult_cost (rtx x, enum rtx_code code, 
> int outer, bool speed)
>if (VECTOR_MODE_P (mode))
>  mode = GET_MODE_INNER (mode);
> 
> +  /* The by element versions of the instruction has the same costs as the
> + normal 3 vector version.  So don't add the costs of the duplicate into
> + the costs of the multiply.  */
> +  if (GET_CODE (op0) == VEC_DUPLICATE)
> +op0 = XEXP (op0, 0);
> +  else if (GET_CODE (op1) == VEC_DUPLICATE)
> +op1 = XEXP (op1, 0);
> +
>/* Integer multiply/fma.  */
>if (GET_MODE_CLASS (mode) == MODE_INT)
>  {

SVE doesn't have duplicating forms, so I think we should put this code
under the “if (VECTOR_MODE_P (mode))” condition, before changing “mode”,
and then restrict it to VEC_ADVSIMD modes.

(SVE FMUL does have an indexed form, but the index is relative to the
start of the associated quadword, so it isn't a VEC_DUPLICATE.)

I guess there's a danger that this could underestimate the cost for
integer modes, if the scalar integer input needs to be moved from GPRs.
In that case the cost of a MULT + VEC_DUPLICATE is probably more
accurate, even though it's still one instruction before RA.

But I guess there's no perfect answer there.  The new code will be
right for integer modes in some cases and not in others.  Same if
we leave things as they are.  But maybe it'd be worth having a comment
to say that we're assuming the best case, i.e. that the duplicated
value is naturally in FPRs?

Thanks,
Richard


Re: [Patch][RFC] openmp: don't add artificial const decl to offload table (PRs 94848 + 95551)

2020-06-08 Thread Jakub Jelinek via Gcc-patches
On Mon, Jun 08, 2020 at 05:20:16PM +0200, Tobias Burnus wrote:
> how about the following patch, which is kind of a combination of the
> two? Namely, avoiding of the output of artificial,read-only nonglobal
> variables – and marking all remaining variables and all functions with
> node->force_output. As the LTO writing happens earlier, I only do it
> there. TobiasOn 6/8/20 1:11 PM, Jakub Jelinek wrote:

I really don't see what is special exactly on TREE_READONLY DECL_ARTIFICIAL
function-scope vars and why they should be treated that way, that is not
really some property that should imply special behavior.
There are dozens of reasons why a variable can be DECL_ARTIFICIAL and dozens
of reasons why it can be TREE_READONLY, and FUNCTION_DECL context can have
both automatic variables and static variables etc.

Jakub



Re: [Patch][RFC] openmp: don't add artificial const decl to offload table (PRs 94848 + 95551)

2020-06-08 Thread Tobias Burnus

Hi Jakub,

how about the following patch, which is kind of a combination of the
two? Namely, avoiding of the output of artificial,read-only nonglobal
variables – and marking all remaining variables and all functions with
node->force_output. As the LTO writing happens earlier, I only do it
there. TobiasOn 6/8/20 1:11 PM, Jakub Jelinek wrote:


On Mon, Jun 08, 2020 at 12:44:31PM +0200, Tobias Burnus wrote:

As side-remark or follow up: I have also experimented
with the attached patch.

On the host side, the omp_finish_file call in toplev.c comes
late enough that the the variables is gone and one no longer
writes it to the var table.

However, the write_lto() → output_offload_tables() call is
that early that both the offload table and the variable is
still written. – Hence, this patch fails at run time as
the two tables host_table & target_data have a different size.

I think this patch is the right thing to do, just needs to be slightly
extended.
If we do the decision at output_offload_tables, then for the
vars we choose to keep in the tables, we should set
node->force_output, so that from that point on we don't try to optimize it
away.  Similarly with functions.

  Jakub


-
Mentor Graphics (Deutschland) GmbH, Arnulfstraße 201, 80634 München / Germany
Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Alexander 
Walter
openmp: don't add artificial const decl to offload table (PRs 94848 + 95551)

gcc/ChangeLog:

	PR lto/94848
	PR middle-end/95551
	* omp-offload.c (add_decls_addresses_to_decl_constructor,
	omp_finish_file): Skip readonly aritificial nonglobal variables.
	* lto-cgraph.c (output_offload_tables): Likewise; set force_output
	for variables and functions.

libgomp/ChangeLog:

	PR lto/94848
	PR middle-end/95551
	* testsuite/libgomp.fortran/target-var.f90: New test.

 gcc/lto-cgraph.c | 19 +++---
 gcc/omp-offload.c| 15 ++-
 libgomp/testsuite/libgomp.fortran/target-var.f90 | 32 
 3 files changed, 61 insertions(+), 5 deletions(-)

diff --git a/gcc/lto-cgraph.c b/gcc/lto-cgraph.c
index a671c671fa7..edac1b3e79f 100644
--- a/gcc/lto-cgraph.c
+++ b/gcc/lto-cgraph.c
@@ -1069,18 +1069,29 @@ output_offload_tables (void)
 
   for (unsigned i = 0; i < vec_safe_length (offload_funcs); i++)
 {
+  tree it = (*offload_funcs)[i];
+  symtab_node *node = symtab_node::get (it);
+  if (!node)
+	continue;
+  node->force_output = true;
   streamer_write_enum (ob->main_stream, LTO_symtab_tags,
 			   LTO_symtab_last_tag, LTO_symtab_unavail_node);
-  lto_output_fn_decl_ref (ob->decl_state, ob->main_stream,
-			  (*offload_funcs)[i]);
+  lto_output_fn_decl_ref (ob->decl_state, ob->main_stream, it);
 }
 
   for (unsigned i = 0; i < vec_safe_length (offload_vars); i++)
 {
+  /* See also omp_finish_file and add_decls_addresses_to_decl_constructor
+	 both in omp-offload.c; note that this function is called earlier.  */
+  tree it = (*offload_vars)[i];
+  symtab_node *node = symtab_node::get (it);
+  if (!node || (TREE_READONLY (it) && DECL_ARTIFICIAL (it)
+		&& TREE_CODE (DECL_CONTEXT (it)) == FUNCTION_DECL))
+	continue;
+  node->force_output = true;
   streamer_write_enum (ob->main_stream, LTO_symtab_tags,
 			   LTO_symtab_last_tag, LTO_symtab_variable);
-  lto_output_var_decl_ref (ob->decl_state, ob->main_stream,
-			   (*offload_vars)[i]);
+  lto_output_var_decl_ref (ob->decl_state, ob->main_stream, it);
 }
 
   streamer_write_uhwi_stream (ob->main_stream, 0);
diff --git a/gcc/omp-offload.c b/gcc/omp-offload.c
index b2df91a5724..51348c195bb 100644
--- a/gcc/omp-offload.c
+++ b/gcc/omp-offload.c
@@ -125,6 +125,13 @@ add_decls_addresses_to_decl_constructor (vec *v_decls,
 #endif
 	  && lookup_attribute ("omp declare target link", DECL_ATTRIBUTES (it));
 
+  /* See also omp_finish_file and output_offload_tables in lto-cgraph.c.  */
+  if (!symtab_node::get (it)
+	  || (is_var && TREE_READONLY (it)
+	  && DECL_ARTIFICIAL (it)
+	  && TREE_CODE (DECL_CONTEXT (it)) == FUNCTION_DECL))
+	continue;
+
   tree size = NULL_TREE;
   if (is_var)
 	size = fold_convert (const_ptr_type_node, DECL_SIZE_UNIT (it));
@@ -341,7 +348,7 @@ omp_finish_file (void)
   add_decls_addresses_to_decl_constructor (offload_vars, v_v);
 
   tree vars_decl_type = build_array_type_nelts (pointer_sized_int_node,
-		num_vars * 2);
+		vec_safe_length (v_v));
   tree funcs_decl_type = build_array_type_nelts (pointer_sized_int_node,
 		 num_funcs);
   SET_TYPE_ALIGN (vars_decl_type, TYPE_ALIGN (pointer_sized_int_node));
@@ -381,6 +388,12 @@ omp_finish_file (void)
   for (unsigned i = 0; i < num_vars; i++)
 	{
 	  tree it = (*offload_vars)[i];
+	  /* See also add_decls_addresses_to_decl_constructor
+	 and output_offload_tables in lto-cgraph.c.  */
+	  if 

[Patch 2/3] aarch64: Introduce SLS mitigation for RET and BR instructions

2020-06-08 Thread Matthew Malcomson
Instructions following RET or BR are not necessarily executed.  In order
to avoid speculation past RET and BR we can simply append a speculation
barrier.

Since these speculation barriers will not be architecturally executed,
they are not expected to add a high performance penalty.

The speculation barrier is to be SB when targeting architectures which
have this enabled, and DSB SY + ISB otherwise.

We add tests for each of the cases where such an instruction was seen.

This is implemented by modifying each machine description pattern that
emits either a RET or a BR instruction.  We choose not to use something
like `TARGET_ASM_FUNCTION_EPILOGUE` since it does not affect the
`indirect_jump`, `jump`, `sibcall_insn` and `sibcall_value_insn`
patterns and we find it preferable to implement the functionality in the
same way for every pattern.

There is one particular case which is slightly tricky.  The
implementation of TARGET_ASM_TRAMPOLINE_TEMPLATE uses a BR which needs
to be mitigated against.  The trampoline template is used *once* per
compilation unit, and the TRAMPOLINE_SIZE is exposed to the user via the
builtin macro __LIBGCC_TRAMPOLINE_SIZE__.
In the future we may implement function specific attributes to turn on
and off hardening on a per-function basis.
The fixed nature of the trampoline described above implies it will be
safer to ensure this speculation barrier is always used.

Testing:
  Bootstrap and regtest done on aarch64-none-linux
  Used a temporary hack(1) to use these options on every test in the
  testsuite and a script to check that the output never emitted an
  unmitigated RET or BR.


1) Temporary hack was a change to the testsuite to always use
`-save-temps` and run a script on the assembly output of those
compilations which produced one to ensure every RET or BR is immediately
followed by a speculation barrier.


gcc/ChangeLog:

2020-06-08  Matthew Malcomson  

* config/aarch64/aarch64-protos.h (aarch64_sls_barrier): New.
* config/aarch64/aarch64.c (aarch64_output_casesi): Emit
speculation barrier after BR instruction if needs be.
(aarch64_sls_barrier): New.
(aarch64_asm_trampoline_template): Add needed barriers.
* config/aarch64/aarch64.h (AARCH64_ISA_SB): New.
(TARGET_SB): New.
(TRAMPOLINE_SIZE): Account for barrier.
* config/aarch64/aarch64.md (indirect_jump, *casesi_dispatch,
*do_return, simple_return, *sibcall_insn, *sibcall_value_insn):
Emit barrier if needs be, also account for possible barrier in
"length" attribute.
* config/aarch64/aarch64.opt (-mharden-sls-retbr): Introduce new
option.

gcc/testsuite/ChangeLog:

2020-06-08  Matthew Malcomson  

* gcc.target/aarch64/sls-mitigation/sls-miti-retbr.c: New test.
* gcc.target/aarch64/sls-mitigation/sls-miti-retbr-pacret.c:
New test.
* gcc.target/aarch64/sls-mitigation/sls-mitigation.exp: New file.
* lib/target-supports.exp (check_effective_target_aarch64_asm_sb_ok):
New proc.



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


diff --git a/gcc/config/aarch64/aarch64-protos.h 
b/gcc/config/aarch64/aarch64-protos.h
index 
8ca67d7e69edaf73c84f079e7e1c483009ad10c0..d2eb739bc89ecd9d0212416b8dc3ee4ba236a271
 100644
--- a/gcc/config/aarch64/aarch64-protos.h
+++ b/gcc/config/aarch64/aarch64-protos.h
@@ -780,6 +780,7 @@ extern const atomic_ool_names aarch64_ool_ldeor_names;
 
 tree aarch64_resolve_overloaded_builtin_general (location_t, tree, void *);
 
+const char * aarch64_sls_barrier (int);
 extern bool aarch64_harden_sls_retbr_p (void);
 extern bool aarch64_harden_sls_blr_p (void);
 
diff --git a/gcc/config/aarch64/aarch64.h b/gcc/config/aarch64/aarch64.h
index 
24767c747bab0d711627c5c646937c42f210d70b..5da3d94e335fc315e1d90e6a674f2f09cf1a4529
 100644
--- a/gcc/config/aarch64/aarch64.h
+++ b/gcc/config/aarch64/aarch64.h
@@ -281,6 +281,7 @@ extern unsigned aarch64_architecture_version;
 #define AARCH64_ISA_F32MM (aarch64_isa_flags & AARCH64_FL_F32MM)
 #define AARCH64_ISA_F64MM (aarch64_isa_flags & AARCH64_FL_F64MM)
 #define AARCH64_ISA_BF16  (aarch64_isa_flags & AARCH64_FL_BF16)
+#define AARCH64_ISA_SB(aarch64_isa_flags & AARCH64_FL_SB)
 
 /* Crypto is an optional extension to AdvSIMD.  */
 #define TARGET_CRYPTO (TARGET_SIMD && AARCH64_ISA_CRYPTO)
@@ -378,6 +379,9 @@ extern unsigned aarch64_architecture_version;
 #define TARGET_FIX_ERR_A53_835769_DEFAULT 1
 #endif
 
+/* SB instruction is enabled through +sb.  */
+#define TARGET_SB (AARCH64_ISA_SB)
+
 /* Apply the workaround for Cortex-A53 erratum 835769.  */
 #define TARGET_FIX_ERR_A53_835769  \
   ((aarch64_fix_a53_err835769 == 2)\
@@ -1058,8 +1062,11 @@ typedef struct
 
 #define RETURN_ADDR_RTX aarch64_return_addr
 
-/* BTI c + 3 insns + 2 pointer-sized entries.  */
-#define TRAMPOLINE_SIZE(TARGET_ILP32 ? 24 : 32)
+/* BTI c + 3 insns
+   + sls 

[Patch 3/3] aarch64: Mitigate SLS for BLR instruction

2020-06-08 Thread Matthew Malcomson
This patch introduces the mitigation for Straight Line Speculation past
the BLR instruction.

This mitigation replaces BLR instructions with a BL to a stub which
simply consists of a BR to the original register.  These function stubs
are then appended with a speculation barrier to ensure no straight line
speculation happens after these jumps.

When optimising for speed we use a set of stubs for each function since
this should help the branch predictor make more accurate predictions
about where a stub should branch.

When optimising for size we use one set of stubs for the entire
compilation unit.
This set of stubs can have human readable names, and we are currently
using `__call_indirect_x` for register x.

As an example when optimising for size:
a
BLR x0
instruction would get transformed to
BL __call_indirect_x0
with __call_indirect_x0 labelling a thunk that contains
__call_indirect_x0:
BR X0
speculation barrier

Since we add these function stubs to the assembly output all in one
chunk, we need not add the speculation barrier directly after each one.
This is because we know for certain that the instructions directly after
the BR in all but the last function stub will be from another one of
these stubs and hence will not contain a speculation gadget.
Instead we add a speculation barrier at the end of the sequence of
stubs.

Special care needs to be given to this transformation occuring in
a context where BTI is enabled.  A BLR can jump to a `BTI c` target,
while a BR can only jump to a `BTI c` target if it uses the registers
x16 or x17.
Hence we use constraints to limit the registers used when this
transformation is being made in an environment that uses BTI.

This mitigation does not apply for BLR instructions in the following
places:
- Some accesses to thread-local variables use a code sequence with a BLR
  instruction.  This code sequence is part of the binary interface between
  compiler and linker. If this BLR instruction needs to be mitigated, it'd
  probably be best to do so in the linker. It seems that the code sequence
  for thread-local variable access is unlikely to lead to a Spectre Revalation
  Gadget.
- PLT stubs are produced by the linker and each contain a BLR instruction.
  It seems that at most only after the last PLT stub a Spectre Revalation
  Gadget might appear.

Testing:
  Bootstrap and regtest on AArch64
(with BOOT_CFLAGS="-mharden-sls=retbr,blr")
  Used a temporary hack(1) in gcc-dg.exp to use these options on every
  test in the testsuite, a slight modification to emit the speculation
  barrier after every function stub, and a script to check that the
  output never emitted a BLR, or unmitigated BR or RET instruction.
  Similar on an aarch64-none-elf cross-compiler.

1) Temporary hack emitted a speculation barrier at the end of every stub
function, and used a script to ensure that:
  a) Every RET or BR is immediately followed by a speculation barrier.
  b) No BLR instruction is emitted by compiler.


gcc/ChangeLog:

2020-06-08  Matthew Malcomson  

* config/aarch64/aarch64-protos.h (aarch64_indirect_call_asm):
New declaration.
* config/aarch64/aarch64.c (aarch64_use_return_insn_p): Return
false if hardening BLR instructions.
(aarch64_sls_shared_thunks): Global array to store stub labels.
(aarch64_create_blr_label): New.
(print_asm_branch): New macro.
(aarch64_sls_emit_blr_function_thunks): New.
(aarch64_sls_emit_shared_blr_thunks): New.
(aarch64_asm_file_end): New.
(aarch64_indirect_call_asm): New.
(TARGET_ASM_FILE_END): Use aarch64_asm_file_end.
(TARGET_ASM_FUNCTION_EPILOGUE): Use
aarch64_sls_emit_blr_function_thunks.
* config/aarch64/aarch64.h (struct machine_function): Introduce
`call_via` array to store function-local stub labels.
* config/aarch64/aarch64.md (*call_insn, *call_value_insn): Use
aarch64_indirect_call_asm to emit code when hardening BLR
instructions.

gcc/testsuite/ChangeLog:

2020-06-08  Matthew Malcomson  

* gcc.target/aarch64/sls-mitigation/sls-miti-blr-bti.c: New test.
* gcc.target/aarch64/sls-mitigation/sls-miti-blr.c: New test.



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


diff --git a/gcc/config/aarch64/aarch64-protos.h 
b/gcc/config/aarch64/aarch64-protos.h
index 
d2eb739bc89ecd9d0212416b8dc3ee4ba236a271..e79f9cbc783e75132e999395ff975f9768436419
 100644
--- a/gcc/config/aarch64/aarch64-protos.h
+++ b/gcc/config/aarch64/aarch64-protos.h
@@ -781,6 +781,7 @@ extern const atomic_ool_names aarch64_ool_ldeor_names;
 tree aarch64_resolve_overloaded_builtin_general (location_t, tree, void *);
 
 const char * aarch64_sls_barrier (int);
+const char * aarch64_indirect_call_asm (rtx);
 extern bool aarch64_harden_sls_retbr_p (void);
 extern bool aarch64_harden_sls_blr_p (void);
 
diff --git a/gcc/config/aarch64/aarch64.h 

[Patch 1/3] aarch64: New Straight Line Speculation (SLS) mitigation flags

2020-06-08 Thread Matthew Malcomson
Here we introduce the flags that will be used for straight line speculation.

The new flag introduced is `-mharden-sls=`.
This flag can take arguments of `none`, `all`, or a comma seperated list of one
or more of `retbr` or `blr`.
`none` indicates no special mitigation of the straight line speculation
vulnerability.
`all` requests all mitigations currently implemented.
`retbr` requests that the RET and BR instructions have a speculation barrier
inserted after them.
`blr` requests that BLR instructions are replaced by a BL to a function stub
using a BR with a speculation barrier after it.

Setting this on a per-function basis using attributes or the like is not
enabled, but may be in the future.

gcc/ChangeLog:

2020-06-08  Matthew Malcomson  

* config/aarch64/aarch64-protos.h (aarch64_harden_sls_retbr_p):
New.
(aarch64_harden_sls_blr_p): New.
* config/aarch64/aarch64.c (enum aarch64_sls_hardening_type):
New.
(aarch64_harden_sls_retbr_p): New.
(aarch64_harden_sls_blr_p): New.
(aarch64_validate_sls_mitigation): New.
(aarch64_override_options): Parse options for SLS mitigation.
* config/aarch64/aarch64.opt (-mharden-sls): New option.
* doc/invoke.texi: Document new option.



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


diff --git a/gcc/config/aarch64/aarch64-protos.h 
b/gcc/config/aarch64/aarch64-protos.h
index 
9e43adb7db0373df6cc5ef1d2b22f217aca2aad2..8ca67d7e69edaf73c84f079e7e1c483009ad10c0
 100644
--- a/gcc/config/aarch64/aarch64-protos.h
+++ b/gcc/config/aarch64/aarch64-protos.h
@@ -780,4 +780,7 @@ extern const atomic_ool_names aarch64_ool_ldeor_names;
 
 tree aarch64_resolve_overloaded_builtin_general (location_t, tree, void *);
 
+extern bool aarch64_harden_sls_retbr_p (void);
+extern bool aarch64_harden_sls_blr_p (void);
+
 #endif /* GCC_AARCH64_PROTOS_H */
diff --git a/gcc/config/aarch64/aarch64.c b/gcc/config/aarch64/aarch64.c
index 
e92c7e69fcb7a8689a8b7098b86ff050dc9ab78b..775f49991e5f599a843d3ef490b8cd044acfe78f
 100644
--- a/gcc/config/aarch64/aarch64.c
+++ b/gcc/config/aarch64/aarch64.c
@@ -14466,6 +14466,81 @@ aarch64_validate_mcpu (const char *str, const struct 
processor **res,
   return false;
 }
 
+
+/* Straight line speculation indicators.  */
+enum aarch64_sls_hardening_type
+{
+SLS_NONE = 0,
+SLS_RETBR = 1,
+SLS_BLR = 2,
+SLS_ALL = 3,
+};
+static enum aarch64_sls_hardening_type aarch64_sls_hardening;
+/* Return whether we should mitigatate Straight Line Speculation for the RET
+   and BR instructions.  */
+bool
+aarch64_harden_sls_retbr_p (void)
+{
+  return aarch64_sls_hardening & SLS_RETBR;
+}
+/* Return whether we should mitigatate Straight Line Speculation for the RET
+   and BR instructions.  */
+bool
+aarch64_harden_sls_blr_p (void)
+{
+  return aarch64_sls_hardening & SLS_BLR;
+}
+
+/* As of yet we only allow setting these options globally, in the future we may
+   allow setting them per function.  */
+static void
+aarch64_validate_sls_mitigation (const char *const_str)
+{
+  char *str_root = xstrdup (const_str);
+  char *token_save = NULL;
+  char *str = NULL;
+  int temp = SLS_NONE;
+
+  aarch64_sls_hardening = SLS_NONE;
+  if (strcmp (str_root, "none") == 0)
+goto finish;
+  if (strcmp (str_root, "all") == 0)
+{
+  aarch64_sls_hardening = SLS_ALL;
+  goto finish;
+}
+
+  str = strtok_r (str_root, ",", _save);
+  if (!str)
+{
+  error ("invalid argument given to %<-mharden-sls=%>");
+  goto finish;
+}
+
+  while (str)
+{
+  if (strcmp (str, "blr") == 0)
+   temp |= SLS_BLR;
+  else if (strcmp (str, "retbr") == 0)
+   temp |= SLS_RETBR;
+  else if (strcmp (str, "none") == 0 || strcmp (str, "all") == 0)
+   {
+ error ("%<%s%> must be by itself for %<-mharden-sls=%>", str);
+ break;
+   }
+  else
+   {
+ error ("invalid argument %<%s%> for %<-mharden-sls=%>", str);
+ break;
+   }
+  str = strtok_r (NULL, ",", _save);
+}
+  aarch64_sls_hardening = (aarch64_sls_hardening_type) temp;
+finish:
+  free (str_root);
+  return;
+}
+
 /* Parses CONST_STR for branch protection features specified in
aarch64_branch_protect_types, and set any global variables required.  
Returns
the parsing result and assigns LAST_STR to the last processed token from
@@ -14710,6 +14785,9 @@ aarch64_override_options (void)
   selected_arch = NULL;
   selected_tune = NULL;
 
+  if (aarch64_harden_sls_string)
+  aarch64_validate_sls_mitigation (aarch64_harden_sls_string);
+
   if (aarch64_branch_protection_string)
 aarch64_validate_mbranch_protection (aarch64_branch_protection_string);
 
diff --git a/gcc/config/aarch64/aarch64.opt b/gcc/config/aarch64/aarch64.opt
index 
d99d14c137d8774d3c8dab860d475f68c01a2817..5170361fd5e5721e044d1664e522b2718f654b8e
 100644
--- a/gcc/config/aarch64/aarch64.opt
+++ b/gcc/config/aarch64/aarch64.opt
@@ 

Straight Line Speculation (SLS) mitigation.

2020-06-08 Thread Matthew Malcomson
Hi,

A new speculative cache side-channel vulnerability has been published at
the link below, named "straight-line speculation" (SLS in this patch series).
https://developer.arm.com/support/arm-security-updates/speculative-processor-vulnerability/downloads/straight-line-speculation
This vulnerability has been given CVE number CVE-2020-13844.

We have prepared some toolchain mitigations for this vulnerability.  These
mitigate against the RET, BR case and the BLR case mentioned in the linked
whitepaper.

The part of vulnerability relevant to these toolchain mitigations is as
follows:
Some processors may speculatively execute the instructions immediately
following what should be a change in control flow.  The examples we mitigate in
this patch series are the instructions RET (return), BR (indirect jump) and BLR
(indirect function call).
Where the speculative path contains a suitable code sequence, often described
by researchers as a "Spectre Revelation Gadget", such straight-line speculation
could lead to changes in the caches and similar structures that are indicative
of secrets, making those secrets vulnerable to revelation through timing
analysis.

The gist of the mitigation posted here is:

Every RET and BR instruction has a speculation barrier placed directly after
it.  These speculation barriers are not to be architecturally executed, so the
performance cost is expected to be low.

Each BLR instruction is replaced by a BL to a function stub consisting of a BR
instruction followed by a speculation barrier.
This alternate approach is used since the instructions directly after a BLR are
usually architecturally executed, and this approach ensures the speculation
barrier is off that architecturally executed path.
Arm has been unable to demonstrate straight line speculation past a BL or B
instruction, and so we believe the BL instruction can be used without a
barrier.

In summary, a
  RET
will be transformed to
  RET
  

While a
  BLR x
will be transformed to a
  BL __call_indirect_x
call, with __call_indirect_x being a thunk that looks like
__call_indirect_x:
  BR x
  


The patch series is structured as follows:
1) Introduce new command line arguments.
2) The RET/BR mitigation.
3) The BLR mitigation.

There are a few known places where this toolchain mitigation does not protect
against speculation places:
- Some accesses to thread-local variables use a code sequence including a BLR
  instruction.   This code sequence is part of the binary interface between
  compiler and linker. If this BLR instruction needs to be mitigated, it'd
  probably be best to do so in the linker.
  It seems that the code sequence for thread-local variable access is unlikely
  to lead to a Spectre Revalation Gadget.
- PLT stubs are produced by the linker, and each contain a BLR instruction.
  It seems that at most this could introduce one spectre relevation gadget
  after the last PLT stub.
- Use of BR, RET, or BLR instructions in assembly are not mitigated.
- Use of BR, RET, or BLR instructions in libraries and run-time library
  routines that are not recompiled with this toolchain mitigation are not
  mitigated.

N.b. patches with similar functionality are being posted to LLVM.

Thanks,
Matthew.


Entire patch series attached to cover letter.

all-patches.tar.gz
Description: application/gzip


[PATCH] libsanitizer: use gnu++14

2020-06-08 Thread Martin Liška

Hi.

Thank you for the report. It's caused by fact that LLVM switch in 4d474e078ac7
to c++14. So that I suggest to use gnu++14.

Patch can bootstrap on x86_64-linux-gnu and survives regression tests.
I also verified that abidiff is equal for all libsanitizer shared libraries.
I'm going to install the patch if there are no objections.

Thanks,
Martin
>From d5cc8547786f296931c93c63b3431c65ed8e7d3d Mon Sep 17 00:00:00 2001
From: Martin Liska 
Date: Mon, 8 Jun 2020 16:04:31 +0200
Subject: [PATCH] libsanitizer: use gnu++14

libsanitizer/ChangeLog:

	* asan/Makefile.am: Replace gnu++11 with gnu++14.
	* interception/Makefile.am: Likewise.
	* libbacktrace/Makefile.am: Likewise.
	* lsan/Makefile.am: Likewise.
	* sanitizer_common/Makefile.am: Likewise.
	* tsan/Makefile.am: Likewise.
	* ubsan/Makefile.am: Likewise.
	* asan/Makefile.in: Regenerate.
	* interception/Makefile.in: Likewise.
	* libbacktrace/Makefile.in: Likewise.
	* lsan/Makefile.in: Likewise.
	* sanitizer_common/Makefile.in: Likewise.
	* tsan/Makefile.in: Likewise.
	* ubsan/Makefile.in: Likewise.
---
 libsanitizer/asan/Makefile.am | 2 +-
 libsanitizer/asan/Makefile.in | 2 +-
 libsanitizer/interception/Makefile.am | 2 +-
 libsanitizer/interception/Makefile.in | 2 +-
 libsanitizer/libbacktrace/Makefile.am | 2 +-
 libsanitizer/libbacktrace/Makefile.in | 2 +-
 libsanitizer/lsan/Makefile.am | 2 +-
 libsanitizer/lsan/Makefile.in | 2 +-
 libsanitizer/sanitizer_common/Makefile.am | 2 +-
 libsanitizer/sanitizer_common/Makefile.in | 2 +-
 libsanitizer/tsan/Makefile.am | 2 +-
 libsanitizer/tsan/Makefile.in | 2 +-
 libsanitizer/ubsan/Makefile.am| 2 +-
 libsanitizer/ubsan/Makefile.in| 2 +-
 14 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/libsanitizer/asan/Makefile.am b/libsanitizer/asan/Makefile.am
index 7bba555b171..2e6385509b4 100644
--- a/libsanitizer/asan/Makefile.am
+++ b/libsanitizer/asan/Makefile.am
@@ -9,7 +9,7 @@ DEFS += -DMAC_INTERPOSE_FUNCTIONS -DMISSING_BLOCKS_SUPPORT
 endif
 AM_CXXFLAGS = -Wall -W -Wno-unused-parameter -Wwrite-strings -pedantic -Wno-long-long  -fPIC -fno-builtin -fno-exceptions -fno-rtti -fomit-frame-pointer -funwind-tables -fvisibility=hidden -Wno-variadic-macros -fno-ipa-icf
 AM_CXXFLAGS += $(LIBSTDCXX_RAW_CXX_CXXFLAGS)
-AM_CXXFLAGS += -std=gnu++11
+AM_CXXFLAGS += -std=gnu++14
 AM_CXXFLAGS += $(EXTRA_CXXFLAGS)
 ACLOCAL_AMFLAGS = -I $(top_srcdir) -I $(top_srcdir)/config
 
diff --git a/libsanitizer/asan/Makefile.in b/libsanitizer/asan/Makefile.in
index bad15b7984f..29622bf466a 100644
--- a/libsanitizer/asan/Makefile.in
+++ b/libsanitizer/asan/Makefile.in
@@ -419,7 +419,7 @@ AM_CXXFLAGS = -Wall -W -Wno-unused-parameter -Wwrite-strings -pedantic \
 	-Wno-long-long -fPIC -fno-builtin -fno-exceptions -fno-rtti \
 	-fomit-frame-pointer -funwind-tables -fvisibility=hidden \
 	-Wno-variadic-macros -fno-ipa-icf \
-	$(LIBSTDCXX_RAW_CXX_CXXFLAGS) -std=gnu++11 $(EXTRA_CXXFLAGS)
+	$(LIBSTDCXX_RAW_CXX_CXXFLAGS) -std=gnu++14 $(EXTRA_CXXFLAGS)
 ACLOCAL_AMFLAGS = -I $(top_srcdir) -I $(top_srcdir)/config
 toolexeclib_LTLIBRARIES = libasan.la
 nodist_toolexeclib_HEADERS = libasan_preinit.o
diff --git a/libsanitizer/interception/Makefile.am b/libsanitizer/interception/Makefile.am
index a22e0b4e2af..efa90a49aa1 100644
--- a/libsanitizer/interception/Makefile.am
+++ b/libsanitizer/interception/Makefile.am
@@ -6,7 +6,7 @@ gcc_version := $(shell @get_gcc_base_ver@ $(top_srcdir)/../gcc/BASE-VER)
 DEFS = -D_GNU_SOURCE -D_DEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS 
 AM_CXXFLAGS = -Wall -W -Wno-unused-parameter -Wwrite-strings -pedantic -Wno-long-long  -fPIC -fno-builtin -fno-exceptions -fno-rtti -fomit-frame-pointer -funwind-tables -fvisibility=hidden -Wno-variadic-macros
 AM_CXXFLAGS += $(LIBSTDCXX_RAW_CXX_CXXFLAGS)
-AM_CXXFLAGS += -std=gnu++11
+AM_CXXFLAGS += -std=gnu++14
 AM_CXXFLAGS += $(EXTRA_CXXFLAGS)
 ACLOCAL_AMFLAGS = -I m4
 
diff --git a/libsanitizer/interception/Makefile.in b/libsanitizer/interception/Makefile.in
index c8868faa0c3..a20f52ea4b8 100644
--- a/libsanitizer/interception/Makefile.in
+++ b/libsanitizer/interception/Makefile.in
@@ -337,7 +337,7 @@ AM_CXXFLAGS = -Wall -W -Wno-unused-parameter -Wwrite-strings -pedantic \
 	-Wno-long-long -fPIC -fno-builtin -fno-exceptions -fno-rtti \
 	-fomit-frame-pointer -funwind-tables -fvisibility=hidden \
 	-Wno-variadic-macros $(LIBSTDCXX_RAW_CXX_CXXFLAGS) \
-	-std=gnu++11 $(EXTRA_CXXFLAGS)
+	-std=gnu++14 $(EXTRA_CXXFLAGS)
 ACLOCAL_AMFLAGS = -I m4
 noinst_LTLIBRARIES = libinterception.la
 interception_files = \
diff --git a/libsanitizer/libbacktrace/Makefile.am b/libsanitizer/libbacktrace/Makefile.am
index 9c752272be1..16accd468df 100644
--- a/libsanitizer/libbacktrace/Makefile.am
+++ b/libsanitizer/libbacktrace/Makefile.am
@@ -41,7 +41,7 @@ CXX_WARN_FLAGS = $(WARN_FLAGS) -Wno-unused-parameter
 AM_CFLAGS = $(C_WARN_FLAGS)
 AM_CFLAGS += 

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

2020-06-08 Thread Tamar Christina
Sending to list as well.. not sure why it was stripped from the reply all.

> -Original Message-
> From: Tamar Christina
> Sent: Monday, June 8, 2020 3:25 PM
> To: Jakub Jelinek ; Tobias Burnus
> 
> Cc: Uros Bizjak ; nd 
> Subject: RE: [PATCH PR95254] aarch64: gcc generate inefficient code with
> fixed sve vector length
> 
> This is a bug with where the C++11 feature test is located as discussed in
> https://gcc.gnu.org/pipermail/gcc-patches/2020-June/547395.html
> A patch was approved but not yet applied to trunk
> https://gcc.gnu.org/pipermail/gcc-patches/2020-June/547463.html
> 
> > -Original Message-
> > From: Gcc-patches  On Behalf Of
> Jakub
> > Jelinek via Gcc-patches
> > Sent: Monday, June 8, 2020 2:57 PM
> > To: Tobias Burnus 
> > Cc: Uros Bizjak ; gcc-patches@gcc.gnu.org
> > Subject: Re: [PATCH PR95254] aarch64: gcc generate inefficient code
> > with fixed sve vector length
> >
> > On Mon, Jun 08, 2020 at 03:49:17PM +0200, Tobias Burnus wrote:
> > > Hi,
> > >
> > > I just observe that this patch causes our *nonbootstrap* builds to
> > > fail; I have not yet looked into this nor tried a bootstrap build.
> > >
> > > gcc-mainline/gcc/expr.c: In function 'rtx_insn* emit_move_insn(rtx, rtx)':
> > > gcc-mainline/gcc/expr.c:3830:3: warning: 'auto' changes meaning in
> > > C++11;
> > please remove it [-Wc++0x-compat]
> > >auto candidate_subreg_p = [&](rtx subreg) {
> > >^
> >
> > That means you must be compiling with -std=gnu++98 rather than -
> > std=gnu++11.
> > Current trunk requires C++11.
> > Make sure this is done in a clean tree, or ./config.status -- recheck;
> > ./config.status has been done?
> >
> > Jakub



[PATCH] AArch64: Adjust costing of by element MUL to be the same as SAME3 MUL.

2020-06-08 Thread Tamar Christina
Hi All,

The cost model is currently treating multiplication by element as being more
expensive than 3 same multiplication.  This means that if the value is on the
SIMD side we add an unneeded DUP.  If the value is on the genreg side we use the
more expensive DUP instead of fmov.

This patch corrects the costs such that the two multiplies are costed the same
which allows us to generate

fmulv3.4s, v3.4s, v0.s[0]

instead of

dup v0.4s, v0.s[0]
fmulv3.4s, v3.4s, v0.4s

Bootstrapped Regtested on aarch64-none-linux-gnu and no issues.

Ok for master?

Thanks,
Tamar

gcc/ChangeLog:

* config/aarch64/aarch64.c (aarch64_rtx_mult_cost): Adjust costs for 
mul.

gcc/testsuite/ChangeLog:

* gcc.target/aarch64/asimd-mull-elem.c: New test.

-- 
diff --git a/gcc/config/aarch64/aarch64.c b/gcc/config/aarch64/aarch64.c
index 97da60762390db81df9cffaf316b909cd1609130..9cc8da338125afa01bc9fb645f4112d2d7ef548c 100644
--- a/gcc/config/aarch64/aarch64.c
+++ b/gcc/config/aarch64/aarch64.c
@@ -11279,6 +11279,14 @@ aarch64_rtx_mult_cost (rtx x, enum rtx_code code, int outer, bool speed)
   if (VECTOR_MODE_P (mode))
 mode = GET_MODE_INNER (mode);
 
+  /* The by element versions of the instruction has the same costs as the
+ normal 3 vector version.  So don't add the costs of the duplicate into
+ the costs of the multiply.  */
+  if (GET_CODE (op0) == VEC_DUPLICATE)
+op0 = XEXP (op0, 0);
+  else if (GET_CODE (op1) == VEC_DUPLICATE)
+op1 = XEXP (op1, 0);
+
   /* Integer multiply/fma.  */
   if (GET_MODE_CLASS (mode) == MODE_INT)
 {
diff --git a/gcc/testsuite/gcc.target/aarch64/asimd-mull-elem.c b/gcc/testsuite/gcc.target/aarch64/asimd-mull-elem.c
new file mode 100644
index ..513721cee0c8372781e6daf33bc06e256cab8cb8
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/asimd-mull-elem.c
@@ -0,0 +1,21 @@
+/* { dg-do compile } */
+/* { dg-require-effective-target vect_int } */
+/* { dg-require-effective-target vect_float } */
+/* { dg-options "-Ofast" } */
+
+#include 
+
+void s_mult_i (int32_t* restrict res, int32_t* restrict a, int32_t b)
+{
+for (int x = 0; x < 16; x++)
+  res[x] = a[x] * b;
+}
+
+void s_mult_f (float32_t* restrict res, float32_t* restrict a, float32_t b)
+{
+for (int x = 0; x < 16; x++)
+  res[x] = a[x] * b;
+}
+
+/* { dg-final { scan-assembler-times {\s+mul\tv[0-9]+\.4s, v[0-9]+\.4s, v[0-9]+\.s\[0\]} 4 } } */
+/* { dg-final { scan-assembler-times {\s+fmul\tv[0-9]+\.4s, v[0-9]+\.4s, v[0-9]+\.s\[0\]} 4 } } */



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

2020-06-08 Thread Jakub Jelinek via Gcc-patches
On Mon, Jun 08, 2020 at 03:49:17PM +0200, Tobias Burnus wrote:
> Hi,
> 
> I just observe that this patch causes our *nonbootstrap* builds
> to fail; I have not yet looked into this nor tried a bootstrap
> build.
> 
> gcc-mainline/gcc/expr.c: In function 'rtx_insn* emit_move_insn(rtx, rtx)':
> gcc-mainline/gcc/expr.c:3830:3: warning: 'auto' changes meaning in C++11; 
> please remove it [-Wc++0x-compat]
>auto candidate_subreg_p = [&](rtx subreg) {
>^

That means you must be compiling with -std=gnu++98 rather than -std=gnu++11.
Current trunk requires C++11.
Make sure this is done in a clean tree, or ./config.status --recheck; 
./config.status
has been done?

Jakub



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

2020-06-08 Thread Tobias Burnus

Forgot to mention that this was an accelerator build:

-DHOST_MACHINE=\"x86_64-pc-linux-gnu\" -DTARGET_MACHINE=\"nvptx-unknown-none\"

build which failed.

Tobias

On 6/8/20 3:49 PM, Tobias Burnus wrote:


Hi,

I just observe that this patch causes our *nonbootstrap* builds
to fail; I have not yet looked into this nor tried a bootstrap
build.

gcc-mainline/gcc/expr.c: In function 'rtx_insn* emit_move_insn(rtx,
rtx)':
gcc-mainline/gcc/expr.c:3830:3: warning: 'auto' changes meaning in
C++11; please remove it [-Wc++0x-compat]
   auto candidate_subreg_p = [&](rtx subreg) {
   ^
gcc-mainline/gcc/expr.c:3830:8: error: 'candidate_subreg_p' does not
name a type
   auto candidate_subreg_p = [&](rtx subreg) {
^
gcc-mainline/gcc/expr.c:3838:3: warning: 'auto' changes meaning in
C++11; please remove it [-Wc++0x-compat]
   auto candidate_mem_p = [&](machine_mode innermode, rtx mem) {
   ^
gcc-mainline/gcc/expr.c:3838:8: error: 'candidate_mem_p' does not name
a type
   auto candidate_mem_p = [&](machine_mode innermode, rtx mem) {
^
gcc-mainline/gcc/expr.c:3849:44: error: 'candidate_subreg_p' was not
declared in this scope
   if (SUBREG_P (x) && candidate_subreg_p (x))
^
gcc-mainline/gcc/expr.c:3852:44: error: 'candidate_subreg_p' was not
declared in this scope
   if (SUBREG_P (y) && candidate_subreg_p (y))
^
gcc-mainline/gcc/expr.c:3866:46: error: 'candidate_mem_p' was not
declared in this scope
 && candidate_mem_p (GET_MODE (x_inner), y))

Tobias

On 6/2/20 4:44 AM, Yangfei (Felix) wrote:


Hi,


-Original Message-
From: Richard Sandiford [mailto:richard.sandif...@arm.com]
Sent: Monday, June 1, 2020 4:47 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...

Sounds good.  Maybe at this point the x_inner and y_inner code is
getting
complicated enough to put into a lambda too:

   x_inner = ... (x);
   y_inner = ... (y);

Just a suggestion though.

Yes, that's a good suggestion.  I see the code becomes more cleaner
with another lambda.

Yeah, looks good.

Formatting nit though: multi-line conditions should be wrapped in
(...),
i.e.:

 return (...
 && ...
 && ...);


Done.  v6 patch is based on trunk 20200601.
Bootstrapped and tested on aarch64-linux-gnu.
Also bootstrapped on x86-64-linux-gnu with --enable-multilib (for
building -m32 x86 libgcc).
Regresssion test on x86-64-linux-gnu looks good except for the
following failures which has been confirmed by x86 devs:


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

Thanks,
Felix


-
Mentor Graphics (Deutschland) GmbH, Arnulfstraße 201, 80634 München / Germany
Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Alexander 
Walter


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

2020-06-08 Thread Tobias Burnus

Hi,

I just observe that this patch causes our *nonbootstrap* builds
to fail; I have not yet looked into this nor tried a bootstrap
build.

gcc-mainline/gcc/expr.c: In function 'rtx_insn* emit_move_insn(rtx, rtx)':
gcc-mainline/gcc/expr.c:3830:3: warning: 'auto' changes meaning in C++11; 
please remove it [-Wc++0x-compat]
   auto candidate_subreg_p = [&](rtx subreg) {
   ^
gcc-mainline/gcc/expr.c:3830:8: error: 'candidate_subreg_p' does not name a type
   auto candidate_subreg_p = [&](rtx subreg) {
^
gcc-mainline/gcc/expr.c:3838:3: warning: 'auto' changes meaning in C++11; 
please remove it [-Wc++0x-compat]
   auto candidate_mem_p = [&](machine_mode innermode, rtx mem) {
   ^
gcc-mainline/gcc/expr.c:3838:8: error: 'candidate_mem_p' does not name a type
   auto candidate_mem_p = [&](machine_mode innermode, rtx mem) {
^
gcc-mainline/gcc/expr.c:3849:44: error: 'candidate_subreg_p' was not declared 
in this scope
   if (SUBREG_P (x) && candidate_subreg_p (x))
^
gcc-mainline/gcc/expr.c:3852:44: error: 'candidate_subreg_p' was not declared 
in this scope
   if (SUBREG_P (y) && candidate_subreg_p (y))
^
gcc-mainline/gcc/expr.c:3866:46: error: 'candidate_mem_p' was not declared in 
this scope
 && candidate_mem_p (GET_MODE (x_inner), y))

Tobias

On 6/2/20 4:44 AM, Yangfei (Felix) wrote:


Hi,


-Original Message-
From: Richard Sandiford [mailto:richard.sandif...@arm.com]
Sent: Monday, June 1, 2020 4:47 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...


Sounds good.  Maybe at this point the x_inner and y_inner code is getting
complicated enough to put into a lambda too:

   x_inner = ... (x);
   y_inner = ... (y);

Just a suggestion though.

Yes, that's a good suggestion.  I see the code becomes more cleaner with 
another lambda.


Yeah, looks good.

Formatting nit though: multi-line conditions should be wrapped in (...),
i.e.:

 return (...
 && ...
 && ...);


Done.  v6 patch is based on trunk 20200601.
Bootstrapped and tested on aarch64-linux-gnu.
Also bootstrapped on x86-64-linux-gnu with --enable-multilib (for building -m32 
x86 libgcc).
Regresssion test on x86-64-linux-gnu looks good except for the following 
failures which has been confirmed by x86 devs:


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

Thanks,
Felix


-
Mentor Graphics (Deutschland) GmbH, Arnulfstraße 201, 80634 München / Germany
Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Alexander 
Walter


Re: [PATCH] fortran/95509 - fix spellcheck-operator.f90 regression

2020-06-08 Thread Bernhard Reutner-Fischer via Gcc-patches
On 5 June 2020 17:12:58 CEST, Thomas Koenig via Fortran  
wrote:
>Hi Tom,
>
>> My earlier patch to add case handling to the spell checker caused a
>> Fortran regression.  I believe I must have misread the test results.
>> 
>> This patch fixes the problem by changing the cutoff.  I chose this
>> value because the previous patch effectively multiplied the result of
>> get_edit_distance by 2 (unless a case change is involved).
>
>OK.  Thanks for the patch!

Yes, this is probably OK although Fortran is case- insensitive. I think we 
lowercase names coming in from the source (at least for the internal identifier 
nodes), so we should not be affected by any case change.

thanks,


Re: [PATCH] avoid -Wmaybe-uninitialized in reload_cse_simplify_operands (PR bootstrap/95555)

2020-06-08 Thread Christophe Lyon via Gcc-patches
On Sat, 6 Jun 2020 at 22:30, Martin Sebor via Gcc-patches
 wrote:
>
> A recent enhancement to the uninitialized access coverage to include
> dynamically allocated objects, including alloca and VLAs, triggers
> an expected instance of -Wmaybe-uninitialized on powerpc64-linux
> in reload_cse_simplify_operands where an element of an XALLOCAVEC-
> allocated array is read before it's provably assigned to.  With
> -Werror this causes the bootstrap there to fail.
>
> The attached patch avoids the warning by clearing the element first.
>
> Although not necessary to avoid the warning, the patch also adds
> an assert to verify that the array isn't accessed outside its bounds.
> recog.c sets which_alternative to -1 in a couple of places and
> a number of tests for it being equal to it so I added the assert
> "just to be sure."
>
> Tested on x86_64-linux (the warning was also confirmed gone on
> powerpc64 by the reporter).
>

Thanks for the fix, I've seen the same problem on arm and aarch64
(don't know why bootstrap still works on x86_64)

Christophe

> Martin


Re: [PATCH 3/4] libgcc: fix the handling of return address mangling [PR94891]

2020-06-08 Thread Szabolcs Nagy
The 06/08/2020 09:12, Luis Machado wrote:
> Hi Szabolcs,
> 
> Just to confirm, this is a "unwinder debugger hook ABI" change only in the
> sense that the generated DWARF will be changed, right? So no further action
> from DWARF consumers will be needed. Is that understanding correct?

the _Unwind_DebugHook can currently be called
with a handler argument that's signed (see below),
i don't know how gdb uses this api (e.g. if it
uses DWARF info to check if the argument is signed),
but i plan to change all apis not to pass signed
pointers around since they can cause ABI issues.
(the debugger is special in that it has to know about
pointer auth anyway so it's not critical to change
this api, but i think it's better to do for consistency)

> On 6/5/20 1:51 PM, Szabolcs Nagy wrote:
> > Mangling, currently only used on AArch64 for return address signing,
> > is an internal representation that should not be exposed via
> > 
> >__builtin_return_address return value,
> >__builtin_eh_return handler argument,
> >_Unwind_DebugHook handler argument.
...
> > -static inline void *
> > -uw_frob_return_addr (struct _Unwind_Context *current
> > -__attribute__ ((__unused__)),
> > -struct _Unwind_Context *target)
> > -{
> > -  void *ret_addr = __builtin_frob_return_addr (target->ra);
> > -#ifdef MD_POST_FROB_EH_HANDLER_ADDR
> > -  ret_addr = MD_POST_FROB_EH_HANDLER_ADDR (current, target, ret_addr);
> > -#endif
> > -  return ret_addr;
> > -}
> > -
> >   /* Install TARGET into CURRENT so that we can return to it.  This is a
> >  macro because __builtin_eh_return must be invoked in the context of
> >  our caller.  FRAMES is a number of frames to be unwind.
> > @@ -1667,7 +1649,7 @@ uw_frob_return_addr (struct _Unwind_Context *current
> > do  
> > \
> >   { 
> > \
> > long offset = uw_install_context_1 ((CURRENT), (TARGET));   
> > \
> > -  void *handler = uw_frob_return_addr ((CURRENT), (TARGET));   \
> > +  void *handler = __builtin_frob_return_addr ((TARGET)->ra);   \
> > _Unwind_DebugHook ((TARGET)->cfa, handler); \
> > _Unwind_Frames_Extra (FRAMES);  
> > \
> > __builtin_eh_return (offset, handler);  
> > \

handler is no longer signed after my patch.
(if signing is necessary then __builtin_eh_return
should deal with that.)


Re: [PATCH 3/4] libgcc: fix the handling of return address mangling [PR94891]

2020-06-08 Thread Luis Machado via Gcc-patches

Hi Szabolcs,

Just to confirm, this is a "unwinder debugger hook ABI" change only in 
the sense that the generated DWARF will be changed, right? So no further 
action from DWARF consumers will be needed. Is that understanding correct?


On 6/5/20 1:51 PM, Szabolcs Nagy wrote:

Mangling, currently only used on AArch64 for return address signing,
is an internal representation that should not be exposed via

   __builtin_return_address return value,
   __builtin_eh_return handler argument,
   _Unwind_DebugHook handler argument.

Note that a mangled address might not even fit into a void *, e.g.
with AArch64 ilp32 ABI the return address is stored as 64bit, so
the mangled return address cannot be accessed via _Unwind_GetPtr.

This patch changes the unwinder hooks as follows:

MD_POST_EXTRACT_ROOT_ADDR is removed: root address comes from
__builtin_return_address which is not mangled.

MD_POST_EXTRACT_FRAME_ADDR is renamed to MD_DEMANGLE_RETURN_ADDR,
it now operates on _Unwind_Word instead of void *, so the hook
should work when return address signing is enabled on AArch64 ilp32.
(But for that __builtin_aarch64_autia1716 should be fixed to operate
on 64bit input instead of a void *.)

MD_POST_FROB_EH_HANDLER_ADDR is removed: it is the responsibility of
__builtin_eh_return to do the mangling if necessary.

libgcc/ChangeLog:

2020-06-04  Szabolcs Nagy  

* config/aarch64/aarch64-unwind.h (MD_POST_EXTRACT_ROOT_ADDR): Remove.
(MD_POST_FROB_EH_HANDLER_ADDR): Remove.
(MD_POST_EXTRACT_FRAME_ADDR): Rename to ...
(MD_DEMANGLE_RETURN_ADDR): This.
(aarch64_post_extract_frame_addr): Rename to ...
(aarch64_demangle_return_addr): This.
(aarch64_post_frob_eh_handler_addr): Remove.
* unwind-dw2.c (uw_update_context): Demangle return address.
(uw_frob_return_addr): Remove.
---
  libgcc/config/aarch64/aarch64-unwind.h | 34 --
  libgcc/unwind-dw2.c| 34 ++
  2 files changed, 13 insertions(+), 55 deletions(-)

diff --git a/libgcc/config/aarch64/aarch64-unwind.h 
b/libgcc/config/aarch64/aarch64-unwind.h
index ed84a96db41..b1d732e0b2d 100644
--- a/libgcc/config/aarch64/aarch64-unwind.h
+++ b/libgcc/config/aarch64/aarch64-unwind.h
@@ -27,11 +27,8 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If 
not, see
  
  #define DWARF_REGNUM_AARCH64_RA_STATE 34
  
-#define MD_POST_EXTRACT_ROOT_ADDR(addr)  __builtin_aarch64_xpaclri (addr)

-#define MD_POST_EXTRACT_FRAME_ADDR(context, fs, addr) \
-  aarch64_post_extract_frame_addr (context, fs, addr)
-#define MD_POST_FROB_EH_HANDLER_ADDR(current, target, addr) \
-  aarch64_post_frob_eh_handler_addr (current, target, addr)
+#define MD_DEMANGLE_RETURN_ADDR(context, fs, addr) \
+  aarch64_demangle_return_addr (context, fs, addr)
  #define MD_FROB_UPDATE_CONTEXT(context, fs) \
aarch64_frob_update_context (context, fs)
  
@@ -57,9 +54,10 @@ aarch64_cie_signed_with_b_key (struct _Unwind_Context *context)

 using CFA of current frame.  */
  
  static inline void *

-aarch64_post_extract_frame_addr (struct _Unwind_Context *context,
-_Unwind_FrameState *fs, void *addr)
+aarch64_demangle_return_addr (struct _Unwind_Context *context,
+ _Unwind_FrameState *fs, _Unwind_Word addr_word)
  {
+  void *addr = (void *)addr_word;
if (context->flags & RA_SIGNED_BIT)
  {
_Unwind_Word salt = (_Unwind_Word) context->cfa;
@@ -71,28 +69,6 @@ aarch64_post_extract_frame_addr (struct _Unwind_Context 
*context,
  return addr;
  }
  
-/* Do AArch64 private frob on exception handler's address HANDLER_ADDR before

-   installing it into current context CURRENT.  TARGET is currently not used.
-   We need to sign exception handler's address if CURRENT itself is signed.  */
-
-static inline void *
-aarch64_post_frob_eh_handler_addr (struct _Unwind_Context *current,
-  struct _Unwind_Context *target
-  ATTRIBUTE_UNUSED,
-  void *handler_addr)
-{
-  if (current->flags & RA_SIGNED_BIT)
-{
-  if (aarch64_cie_signed_with_b_key (current))
-   return __builtin_aarch64_pacib1716 (handler_addr,
-   (_Unwind_Word) current->cfa);
-  return __builtin_aarch64_pacia1716 (handler_addr,
-   (_Unwind_Word) current->cfa);
-}
-  else
-return handler_addr;
-}
-
  /* Do AArch64 private initialization on CONTEXT based on frame info FS.  Mark
 CONTEXT as return address signed if bit 0 of DWARF_REGNUM_AARCH64_RA_STATE 
is
 set.  */
diff --git a/libgcc/unwind-dw2.c b/libgcc/unwind-dw2.c
index 62d4a3d29a2..fe896565d2e 100644
--- a/libgcc/unwind-dw2.c
+++ b/libgcc/unwind-dw2.c
@@ -1538,11 +1538,14 @@ uw_update_context (struct _Unwind_Context *context, 
_Unwind_FrameState *fs)
  {
/* Compute the return address 

Re: [PATCH] hurd: libgcc unwinding support over signal trampolines

2020-06-08 Thread Samuel Thibault
Samuel Thibault, le lun. 08 juin 2020 13:36:55 +0200, a ecrit:
> Thomas Schwinge, le lun. 08 juin 2020 12:15:12 +0200, a ecrit:
> > Which GCC branches would you like this on?
> 
> Ideally it's be backported to gcc 9 and 10, so that it lands naturally
> in the Debian packages without having to bother doko.

Actually only gcc 10 would be needed.

Samuel


Re: [PATCH 4/4] ipa-sra: Fix debug info for removed args passed to other functions (PR 93385, 95343)

2020-06-08 Thread Martin Jambor
Hi,

On Thu, May 28 2020, Martin Jambor wrote:
> This patch arguably finishes what I was asked to do in bugzilla PR
> 93385 and remaps *all* occurrences of SSA names discovered to be dead
> in the process of parameter removal during clone materialization
> either to error_mark_node or to DEBUG_EXPR_DECL that represents the
> removed value - including those that appeared as arguments in call
> statements.
>
> However, those error_mark_nodes and DEBUG_EXPR_DECLs occurrences are
> not removed straight away because arguments are removed only as a part
> of call redirection - mostly following the plan for the callee - which
> is not part of clone materialization.  Just for the record, this is
> not something introduced by IPA-SRA, this has always been that way
> since the beginning of IPA infrastructure and for good reasons.
>
> As a consequence, error_mark_node and DEBUG_EXPR_DECL must be allowed
> in places where they are normally not, which this patch does but only
> during IPA passes. Afterwards, they are again banned.  I am confident
> that if some bug allowed one of these to survive until late tree
> passes, the compiler would ICE very quickly and so it is a safe thing
> to do, even if not exactly nicely consistent.  Perhaps safer than the
> temporary decl what the second patch introduced.
>
> Temporarily replacing arguments with associated DEBUG_EXPR_DECL allows
> us to produce debug info allowing the debugger to print values of
> unused parameters which were removed not only in its function but also
> in the caller.  At least sometimes :-) See the removed xfail in
> testcase/gcc.dg/guality/ipa-sra-1.c.
>
> I have attempted to achieve the same thing by associating the
> DEBUG_EXPR_DECL with the artificial temporary and keep track of this
> relationship in on-the side-summaries, constantly remapping both when
> a clone of a clone gets its body and it is doable but quite ugly.
> Injecting the DEBUG_EXPR_DECL directly into the IL works out of the
> box.
>
> Oh, and this patch also fixes PR debug/95343 - a case whee call
> redirection can produce bad debug info.  A non-controversial fix is in
> the first bugzilla comment but it needs all the other bits of this
> patch to really allow debugger to print the value of the removed
> parameter and not "value optimized out."  But perhaps that is what we
> want to backport?
>

this patch missed one small test which lead to an ICE during aarch64-linux
bootstrap.  Otherwise everything stated above holds.  Fixed below.

Thanks,

Martin


gcc/Changelog:

2020-06-05  Martin Jambor  

PR ipa/93385
PR debug/95343
* ipa-param-manipulation.c (transitive_split_p): Handle
error_mark_node.
(ipa_param_adjustments::modify_call): Use index_map if available.
Directly use removed argument if it is a DEBUG_EXP_DECL for
corresponding debug info, assert all are removed.
(ipa_param_body_adjustments::get_removed_call_arg_placeholder): Return
corresponding DEBUG_EXP_DECL if there is one, otherwise return
error_mark_node.
* tree-ssa-operands.c: Include tree-pass.h.
(operands_scanner::get_expr_operands): Allow DEBUG_EXPR_DECL and
error_mark_node in call arguments during simple IPA passes.
* tree-cfg.c (verify_gimple_call): Likewise.

gcc/testsuite/Changelog:

2020-05-26  Martin Jambor  

PR ipa/93385
PR debug/95343
* gcc.dg/guality/pr95343.c: New test.
* gcc.dg/guality/ipa-sra-1.c (bar): Remove xfail.
---
 gcc/ipa-param-manipulation.c | 31 
 gcc/testsuite/gcc.dg/guality/ipa-sra-1.c |  2 +-
 gcc/testsuite/gcc.dg/guality/pr95343.c   | 45 
 gcc/tree-cfg.c   | 14 ++--
 gcc/tree-ssa-operands.c  | 15 ++--
 5 files changed, 94 insertions(+), 13 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/guality/pr95343.c

diff --git a/gcc/ipa-param-manipulation.c b/gcc/ipa-param-manipulation.c
index 71ae4fdc16d..c805350e107 100644
--- a/gcc/ipa-param-manipulation.c
+++ b/gcc/ipa-param-manipulation.c
@@ -469,6 +469,8 @@ transitive_split_p (vec 
*performed_splits,
tree expr, unsigned *sm_idx_p, unsigned *unit_offset_p)
 {
   tree base;
+  if (expr == error_mark_node)
+return false;
   if (!isra_get_ref_base_and_offset (expr, , unit_offset_p))
 return false;
 
@@ -620,6 +622,8 @@ ipa_param_adjustments::modify_call (gcall *stmt,
index = index_map[apm->base_index];
 
  tree arg = gimple_call_arg (stmt, index);
+ gcc_assert (arg != error_mark_node
+ && TREE_CODE (arg) != DEBUG_EXPR_DECL);
 
  vargs.quick_push (arg);
  kept[index] = true;
@@ -792,7 +796,14 @@ ipa_param_adjustments::modify_call (gcall *stmt,
  if (!is_gimple_reg (old_parm) || kept[i])
continue;
  tree origin = DECL_ORIGIN (old_parm);
- tree arg = gimple_call_arg (stmt, i);
+ 

Re: [PATCH 2/4] ipa-sra: Introduce a mini-DCE to tree-inline.c (PR 93385)

2020-06-08 Thread Martin Jambor
Hi,

On Tue, Jun 02 2020, Richard Biener wrote:
> On Thu, 28 May 2020, Martin Jambor wrote:
>
>> PR 93385 reveals that if the user explicitely disables DCE, IPA-SRA
>> can leave behind statements which are useless because their results
>> are eventually not used but can have problematic side effects,
>> especially since their inputs are now bogus that useless parameters
>> were removed.
>> 
>> This patch fixes the problem by doing a similar def-use walk when
>> materializing clones, marking which statements should not be copied
>> and which SSA_NAMEs will be removed by call redirections and now need
>> to be replaced with anything valid.  Default-definition SSA_NAMEs of
>> parameters which are removed and all SSA_NAMEs derived from them (in a
>> phi node or a simple assignment statement) are then remapped to
>> error_mark_node - a sure way to spot it if any is left in place.
>> 
>> There is one exception to the above rule, if such SSA_NAMEs appear as
>> an argument of a call, they need to be removed by call redirection and
>> not as part of clone materialization.  So to have something valid
>> there until that time, this patch pulls out dummy declarations out of
>> thin air.  If you do not like that, see patch number 4 in the series,
>> which changes this, but probably in a controversial way.
>> 
>> This patch only resets debug statements using the removed SSA_NAMEs.
>> The first follow-up patch adjusts debug statements in the current
>> function to still try to make the removed values available in debugger
>> in the current function and the subsequent one also in other functions
>> where they are passed.
>> 
>> gcc/ChangeLog:
>> 
>> 2020-05-14  Martin Jambor  
>> 
>>  PR ipa/93385
>>  * ipa-param-manipulation.h (class ipa_param_body_adjustments): New
>>  members m_dead_stmts, m_dead_ssas, mark_dead_statements and
>>  get_removed_call_arg_placeholder.
>>  * ipa-param-manipulation.c (phi_arg_will_live_p): New function.
>>  (ipa_param_body_adjustments::mark_dead_statements): New method.
>>  (ipa_param_body_adjustments::common_initialization): Call it.
>>  (ipa_param_body_adjustments::ipa_param_body_adjustments): Initialize
>>  new mwmbers.
>>  (ipa_param_body_adjustments::get_removed_call_arg_placeholder): New.
>>  (ipa_param_body_adjustments::modify_call_stmt): Replace dead SSAs
>>  with dummy decls.
>>  * tree-inline.c (remap_gimple_stmt): Do not copy dead statements,
>>  reset dead debug statements.
>>  (copy_phis_for_bb): Do not copy dead PHI nodes.
>> 
>> gcc/testsuite/ChangeLog:
>> 

[...]

>> 
>> diff --git a/gcc/ipa-param-manipulation.c b/gcc/ipa-param-manipulation.c
>> index 978916057f0..1f47f3a4268 100644
>> --- a/gcc/ipa-param-manipulation.c
>> +++ b/gcc/ipa-param-manipulation.c
>> @@ -953,6 +953,99 @@ ipa_param_body_adjustments::carry_over_param (tree t)
>>return new_parm;
>>  }
>>  
>> +/* Return true if BLOCKS_TO_COPY is NULL or if PHI has an argument ARG in
>> +   position that corresponds to an edge that is coming from a block that has
>> +   the corresponding bit set in BLOCKS_TO_COPY.  */
>> +
>> +static bool
>> +phi_arg_will_live_p (gphi *phi, bitmap blocks_to_copy, tree arg)
>> +{
>> +  bool arg_will_survive = false;
>> +  if (!blocks_to_copy)
>> +arg_will_survive = true;
>> +  else
>> +for (unsigned i = 0; i < gimple_phi_num_args (phi); i++)
>> +  if (gimple_phi_arg_def (phi, i) == arg
>> +  && bitmap_bit_p (blocks_to_copy,
>> +   gimple_phi_arg_edge (phi, i)->src->index))
>> +{
>> +  arg_will_survive = true;
>> +  break;
>> +}
>> +  return arg_will_survive;
>> +}
>> +
>> +/* Populate m_dead_stmts given that DEAD_PARAM is going to be removed 
>> without
>> +   any replacement or splitting.  */
>> +
>> +void
>> +ipa_param_body_adjustments::mark_dead_statements (tree dead_param)
>> +{
>> +  if (!is_gimple_reg (dead_param))
>
> Hmm, so non-registers are not a problem?  I guess IPA SRA simply
> ensures there are no actual uses (but call arguments) in that case?
> Please clearly document this function matches IPA SRA capabilities.

OK, added.

>
>> +return;
>> +  tree parm_ddef = ssa_default_def (m_id->src_cfun, dead_param);
>> +  if (!parm_ddef || has_zero_uses (parm_ddef))
>> +return;
>> +
>> +  auto_vec stack;
>> +  m_dead_ssas.add (parm_ddef);
>> +  stack.safe_push (parm_ddef);
>> +  while (!stack.is_empty ())
>> +{
>> +  tree t = stack.pop ();
>> +
>> +  imm_use_iterator imm_iter;
>> +  gimple *stmt;
>> +
>> +  insert_decl_map (m_id, t, error_mark_node);
>> +  FOR_EACH_IMM_USE_STMT (stmt, imm_iter, t)
>> +{
>> +  if (is_gimple_call (stmt)
>> +  || (m_id->blocks_to_copy
>> +  && !bitmap_bit_p (m_id->blocks_to_copy,
>> +gimple_bb (stmt)->index)))
>> +continue;
>> +
>> +  if (is_gimple_debug (stmt))
>> +{
>> +  m_dead_stmts.add (stmt);
>> +  

Re: [PATCH] hurd: libgcc unwinding support over signal trampolines

2020-06-08 Thread Samuel Thibault
Thomas Schwinge, le lun. 08 juin 2020 12:15:12 +0200, a ecrit:
> I'm not currently set up to test this, but I'll assume you have.

Sure :)

> Which GCC branches would you like this on?

Ideally it's be backported to gcc 9 and 10, so that it lands naturally
in the Debian packages without having to bother doko.

> Once we've got this in GCC, please then also cross-reference GCC's
> 'libgcc/config/i386/gnu-unwind.h' file in glibc's
> 'sysdeps/mach/hurd/i386/trampoline.c' file.

Ah, yes, I thought about it and forgot, will do.

Samuel


Re: [Patch][RFC] openmp: don't add aritificial const decl to offload table (PRs 94848 + 95551)

2020-06-08 Thread Jakub Jelinek via Gcc-patches
On Mon, Jun 08, 2020 at 12:44:31PM +0200, Tobias Burnus wrote:
> As side-remark or follow up: I have also experimented
> with the attached patch.
> 
> On the host side, the omp_finish_file call in toplev.c comes
> late enough that the the variables is gone and one no longer
> writes it to the var table.
> 
> However, the write_lto() → output_offload_tables() call is
> that early that both the offload table and the variable is
> still written. – Hence, this patch fails at run time as
> the two tables host_table & target_data have a different size.

I think this patch is the right thing to do, just needs to be slightly
extended.
If we do the decision at output_offload_tables, then for the
vars we choose to keep in the tables, we should set
node->force_output, so that from that point on we don't try to optimize it
away.  Similarly with functions.

Jakub



Re: [stage1][PATCH] Make TOPN counter dynamically allocated.

2020-06-08 Thread Martin Liška

On 6/4/20 1:44 AM, Gerald Pfeifer wrote:

On Wed, 3 Jun 2020, Martin Liška wrote:

Sorry for the breakage. Can you please paste full build output for the
problematic .o file?

I bet it's a C file compilation, where we should use:

__sync_val_compare_and_swap (counter, 0, (intptr_t)node);

Can you please test it?


c++ -std=c++11 -fno-PIE -c -g -DIN_GCC -fno-strict-aliasing
-fno-exceptions -fno-rtti -fasynchronous-unwind-tables -W -Wall
-Wno-narrowing -Wwrite-strings -Wcast-qual -Wno-error=format-diag
-Wno-format -Wmissing-format-attribute -Wove rloaded-virtual -pedantic
-Wno-long-long -Wno-variadic-macros -Wno-overlength-st rings -fno-common
-Wno-error -DHAVE_CONFIG_H -I. -I. -I/scratch/tmp/gerald/GCC-H EAD/gcc
-I/scratch/tmp/gerald/GCC-HEAD/gcc/.
-I/scratch/tmp/gerald/GCC-HEAD/gcc/../include -I./../intl
-I/scratch/tmp/gerald/GCC-HEAD/gcc/../libcpp/include
-I/home/gerald/11-i386/include
-I/scratch/tmp/gerald/GCC-HEAD/gcc/../libdecnumber
-I/scratch/tmp/gerald/GCC-HEAD/gcc/../libdecnumber/dpd -I../libdecnumber
-I/scrat ch/tmp/gerald/GCC-HEAD/gcc/../libbacktrace -I. -I.
-I/scratch/tmp/gerald/GCC-H EAD/gcc -I/scratch/tmp/gerald/GCC-HEAD/gcc/.
-I/scratch/tmp/gerald/GCC-HEAD/gcc/ ../include -I./../intl
-I/scratch/tmp/gerald/GCC-HEAD/gcc/../libcpp/include
-I/home/gerald/11-i386/include
-I/scratch/tmp/gerald/GCC-HEAD/gcc/../libdecnumber
-I/scratch/tmp/gerald/GCC-HEAD/gcc/../libdecnumber/dpd -I../libdecnumber
-I/scrat ch/tmp/gerald/GCC-HEAD/gcc/../libbacktrace \ -DIN_GCOV_TOOL=1
-o libgcov-merge-tool.o 
/scratch/tmp/gerald/GCC-HEAD/gcc/../libgcc/libgcov-merge.c

Alas in tonights build (and the one with JOBS=1 I run during the day)
this now did not fail any longer. On the very same system and with the
same invocation of the build.

No I'm wondering what might have fixed this. The git lob did not show
me something obvious.


I would recommend:

$ git show --format=fuller 871e5ada6d53d5eb495cc9f323983f347487c1b2


Ah, cool.  Great to know, thank you!

Gerald



Hello.

Can you please test the following patch candidate:

diff --git a/libgcc/libgcov.h b/libgcc/libgcov.h
index 1456100815d..accecfe8221 100644
--- a/libgcc/libgcov.h
+++ b/libgcc/libgcov.h
@@ -410,7 +410,7 @@ gcov_counter_set_if_null (gcov_type *counter, struct 
gcov_kvp *node,
 {
 #if GCOV_SUPPORTS_ATOMIC
   if (use_atomic)
-return !__sync_val_compare_and_swap (counter, NULL, (intptr_t)node);
+return !__sync_val_compare_and_swap (counter, 0, (intptr_t)node);
   else
 #endif
 {

Thanks,
Martin


Re: [stage1][PATCH] Lower VEC_COND_EXPR into internal functions.

2020-06-08 Thread Martin Liška

Hello.

Thank you for the approval. There's the patch that defines 4 new 
DEF_INTERNAL_OPTAB_FN.

Patch can bootstrap on x86_64-linux-gnu and survives regression tests.
It also builds on ppc64le-linux-gnu.

Ready to be installed?
Thanks,
Martin
>From ae67d31e1ea7e03bbba216a7b9404009b2dea070 Mon Sep 17 00:00:00 2001
From: Martin Liska 
Date: Mon, 9 Mar 2020 13:23:03 +0100
Subject: [PATCH] Lower VEC_COND_EXPR into internal functions.

gcc/ChangeLog:

2020-03-30  Martin Liska  

	* expr.c (expand_expr_real_2): Put gcc_unreachable, we should reach
	this path.
	(do_store_flag): Likewise here.
	* internal-fn.c (vec_cond_mask_direct): New.
	(vec_cond_direct): Likewise.
	(vec_condu_direct): Likewise.
	(vec_condeq_direct): Likewise.
	(expand_vect_cond_optab_fn): Move from optabs.c.
	(expand_vec_cond_optab_fn): New alias.
	(expand_vec_condu_optab_fn): Likewise.
	(expand_vec_condeq_optab_fn): Likewise.
	(expand_vect_cond_mask_optab_fn): Moved from optabs.c.
	(expand_vec_cond_mask_optab_fn): New alias.
	(direct_vec_cond_mask_optab_supported_p): New.
	(direct_vec_cond_optab_supported_p): Likewise.
	(direct_vec_condu_optab_supported_p): Likewise.
	(direct_vec_condeq_optab_supported_p): Likewise.
	* internal-fn.def (DEF_INTERNAL_OPTAB_CAN_FAIL):
	(VCOND): New new internal optab
	function.
	(VCONDU): Likewise.
	(VCONDEQ): Likewise.
	(VCOND_MASK): Likewise.
	* optabs.c (expand_vec_cond_mask_expr): Removed.
	(expand_vec_cond_expr): Likewise.
	* optabs.h (expand_vec_cond_expr): Likewise.
	(vector_compare_rtx): Likewise.
	* passes.def: Add pass_gimple_isel.
	* tree-cfg.c (verify_gimple_assign_ternary): Add new
	GIMPLE check.
	* tree-pass.h (make_pass_gimple_isel): New.
	* tree-ssa-forwprop.c (pass_forwprop::execute): Do not forward
	to already lowered VEC_COND_EXPR.
	* tree-vect-generic.c (expand_vector_divmod): Expand to SSA_NAME.
	(expand_vector_condition): Expand tcc_comparison of a VEC_COND_EXPR
	into a SSA_NAME.
	(gimple_expand_vec_cond_expr): New.
	(gimple_expand_vec_cond_exprs): New.
	(class pass_gimple_isel): New.
	(make_pass_gimple_isel): New.
	* genemit.c (DEF_INTERNAL_OPTAB_CAN_FAIL): Support optabs that
	can fail.
---
 gcc/expr.c  |  25 +
 gcc/internal-fn.c   |  89 +++
 gcc/internal-fn.def |   5 +
 gcc/optabs.c| 124 +
 gcc/optabs.h|   7 +-
 gcc/passes.def  |   1 +
 gcc/tree-cfg.c  |   8 ++
 gcc/tree-pass.h |   1 +
 gcc/tree-ssa-forwprop.c |   6 +
 gcc/tree-vect-generic.c | 237 +++-
 10 files changed, 349 insertions(+), 154 deletions(-)

diff --git a/gcc/expr.c b/gcc/expr.c
index ca6b1c1291e..3c68b0d754c 100644
--- a/gcc/expr.c
+++ b/gcc/expr.c
@@ -9316,17 +9316,8 @@ expand_expr_real_2 (sepops ops, rtx target, machine_mode tmode,
   if (temp != 0)
 	return temp;
 
-  /* For vector MIN , expand it a VEC_COND_EXPR 
-	 and similarly for MAX .  */
   if (VECTOR_TYPE_P (type))
-	{
-	  tree t0 = make_tree (type, op0);
-	  tree t1 = make_tree (type, op1);
-	  tree comparison = build2 (code == MIN_EXPR ? LE_EXPR : GE_EXPR,
-type, t0, t1);
-	  return expand_vec_cond_expr (type, comparison, t0, t1,
-   original_target);
-	}
+	gcc_unreachable ();
 
   /* At this point, a MEM target is no longer useful; we will get better
 	 code without it.  */
@@ -9915,10 +9906,6 @@ expand_expr_real_2 (sepops ops, rtx target, machine_mode tmode,
 	return temp;
   }
 
-case VEC_COND_EXPR:
-  target = expand_vec_cond_expr (type, treeop0, treeop1, treeop2, target);
-  return target;
-
 case VEC_DUPLICATE_EXPR:
   op0 = expand_expr (treeop0, NULL_RTX, VOIDmode, modifier);
   target = expand_vector_broadcast (mode, op0);
@@ -12249,8 +12236,7 @@ do_store_flag (sepops ops, rtx target, machine_mode mode)
   STRIP_NOPS (arg1);
 
   /* For vector typed comparisons emit code to generate the desired
- all-ones or all-zeros mask.  Conveniently use the VEC_COND_EXPR
- expander for this.  */
+ all-ones or all-zeros mask.  */
   if (TREE_CODE (ops->type) == VECTOR_TYPE)
 {
   tree ifexp = build2 (ops->code, ops->type, arg0, arg1);
@@ -12258,12 +12244,7 @@ do_store_flag (sepops ops, rtx target, machine_mode mode)
 	  && expand_vec_cmp_expr_p (TREE_TYPE (arg0), ops->type, ops->code))
 	return expand_vec_cmp_expr (ops->type, ifexp, target);
   else
-	{
-	  tree if_true = constant_boolean_node (true, ops->type);
-	  tree if_false = constant_boolean_node (false, ops->type);
-	  return expand_vec_cond_expr (ops->type, ifexp, if_true,
-   if_false, target);
-	}
+	gcc_unreachable ();
 }
 
   /* Optimize (x % C1) == C2 or (x % C1) != C2 if it is beneficial
diff --git a/gcc/internal-fn.c b/gcc/internal-fn.c
index 5e9aa60721e..644f234e087 100644
--- a/gcc/internal-fn.c
+++ b/gcc/internal-fn.c
@@ -49,6 +49,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "gimple-ssa.h"
 #include "tree-phinodes.h"
 #include 

Re: [Patch][RFC] openmp: don't add aritificial const decl to offload table (PRs 94848 + 95551)

2020-06-08 Thread Tobias Burnus

As side-remark or follow up: I have also experimented
with the attached patch.

On the host side, the omp_finish_file call in toplev.c comes
late enough that the the variables is gone and one no longer
writes it to the var table.

However, the write_lto() → output_offload_tables() call is
that early that both the offload table and the variable is
still written. – Hence, this patch fails at run time as
the two tables host_table & target_data have a different size.

Tobias

-
Mentor Graphics (Deutschland) GmbH, Arnulfstraße 201, 80634 München / Germany
Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Alexander 
Walter
openmp: skip removed variables for offloading (PRs 94848 + 95551)

gcc/ChangeLog:

	PR lto/94848
	PR middle-end/95551
	* omp-offload.c (add_decls_addresses_to_decl_constructor,
	omp_finish_file): Skip variables which have been removed.

libgomp/ChangeLog:

	PR lto/94848
	PR middle-end/95551
	* testsuite/libgomp.fortran/target-var.f90: New test.

 gcc/lto-cgraph.c  | 3 +++
 gcc/omp-offload.c | 7 ++-
 libgomp/testsuite/libgomp.fortran/target-var.f90 | 32 

diff --git a/gcc/lto-cgraph.c b/gcc/lto-cgraph.c
index a671c67..0c18ce3 100644
--- a/gcc/lto-cgraph.c
+++ b/gcc/lto-cgraph.c
@@ -1077,6 +1077,9 @@ output_offload_tables (void)
 
   for (unsigned i = 0; i < vec_safe_length (offload_vars); i++)
 {
+  if (!symtab_node::get ((*offload_vars)[i]))
+	continue;
+
   streamer_write_enum (ob->main_stream, LTO_symtab_tags,
 			   LTO_symtab_last_tag, LTO_symtab_variable);
   lto_output_var_decl_ref (ob->decl_state, ob->main_stream,
diff --git a/gcc/omp-offload.c b/gcc/omp-offload.c
index b2df91a..8994ce3 100644
--- a/gcc/omp-offload.c
+++ b/gcc/omp-offload.c
@@ -125,6 +125,9 @@ add_decls_addresses_to_decl_constructor (vec *v_decls,
 #endif
 	  && lookup_attribute ("omp declare target link", DECL_ATTRIBUTES (it));
 
+  if (is_var && !symtab_node::get (it))
+   continue;
+
   tree size = NULL_TREE;
   if (is_var)
 	size = fold_convert (const_ptr_type_node, DECL_SIZE_UNIT (it));
@@ -341,7 +344,7 @@ omp_finish_file (void)
   add_decls_addresses_to_decl_constructor (offload_vars, v_v);
 
   tree vars_decl_type = build_array_type_nelts (pointer_sized_int_node,
-		num_vars * 2);
+		vec_safe_length (v_v));
   tree funcs_decl_type = build_array_type_nelts (pointer_sized_int_node,
 		 num_funcs);
   SET_TYPE_ALIGN (vars_decl_type, TYPE_ALIGN (pointer_sized_int_node));
@@ -381,6 +384,8 @@ omp_finish_file (void)
   for (unsigned i = 0; i < num_vars; i++)
 	{
 	  tree it = (*offload_vars)[i];
+	  if (!symtab_node::get (it))
+	continue;
 #ifdef ACCEL_COMPILER
 	  if (DECL_HAS_VALUE_EXPR_P (it)
 	  && lookup_attribute ("omp declare target link",
diff --git a/libgomp/testsuite/libgomp.fortran/target-var.f90 b/libgomp/testsuite/libgomp.fortran/target-var.f90
new file mode 100644
index 000..5e5ccd47c96
--- /dev/null
+++ b/libgomp/testsuite/libgomp.fortran/target-var.f90
@@ -0,0 +1,32 @@
+! { dg-additional-options "-O3" }
+!
+! With -O3 the static local variable A.10 generated for
+! the array constructor [-2, -4, ..., -20] is optimized
+! away - which has to be handled in the offload_vars table.
+!
+program main
+  implicit none (type, external)
+  integer :: j
+  integer, allocatable :: A(:)
+
+  A = [(3*j, j=1, 10)]
+  call bar (A)
+  deallocate (A)
+contains
+  subroutine bar (array)
+integer :: i
+integer :: array(:)
+
+!$omp target map(from:array)
+!$acc parallel copyout(array)
+array = [(-2*i, i = 1, size(array))]
+!$omp do private(array)
+!$acc loop gang private(array)
+do i = 1, 10
+  array(i) = 9*i
+end do
+if (any (array /= [(-2*i, i = 1, 10)])) error stop 2
+!$omp end target
+!$acc end parallel
+  end subroutine bar
+end


Re: [PATCH RFC] bootstrap: Update requirement to C++11.

2020-06-08 Thread Martin Jambor
Hi,

On Fri, May 15 2020, Jason Merrill via Gcc-patches wrote:
> commit f466a9f3f121f16b97071162806255fb464718f2
> Author: Jason Merrill 
> Date:   Fri May 15 17:15:38 2020 -0400
>
> bootstrap: Update requirement to C++11.
> 
> There was general agreement last November that we would move to allowing
> C++11 features to be used in GCC 11; this patch implements that direction.
> 

since this commit (gcc-11-462-g5329b59a2e1) I cannot bootstrap GCC on
gcc45.fsffrance.org compile farm machine which is an i586-linux-gnu box
where the system compiler is GCC 4.9.2 which I believe should be new
enough.  Still, stage 1 fails with the errors below.

What baffles me is that only bootstrap fails on the old machine.  If I
configure with --disable-bootstrap, make finishes fine.  For the record,
I configure gcc there with:

/home/jamborm/gcc/trunk/src/configure --prefix=/home/jamborm/gcc/trunk/inst 
--enable-languages=c,c++ --enable-checking=yes --disable-libsanitizer 
--disable-multilib --disable-libcilkrts --with-gmp=/opt/cfarm/gmp-latest 
--with-mpfr=/opt/cfarm/mpfr-latest --with-mpc=/opt/cfarm/mpc-latest

In my other i686 testing environment, which is a chroot with gcc 8.3.0
as the system compiler, I can bootstrap without any issues.

I can open a PR if you want me to.

Thanks,

Martin


g++ -std=c++11  -fno-PIE -c   -g   -DIN_GCC -fno-exceptions -fno-rtti 
-fasynchronous-unwind-tables -W -Wall -Wno-narrowing -Wwrite-strings 
-Wcast-qual -Wno-format -Wmissing-format-attribute -Woverloaded-virtual 
-pedantic -Wno-long-long -Wno-variadic-macros -Wno-overlength-strings 
-fno-common  -DHAVE_CONFIG_H -I. -I. -I/home/jamborm/gcc/trunk/src/gcc 
-I/home/jamborm/gcc/trunk/src/gcc/. 
-I/home/jamborm/gcc/trunk/src/gcc/../include 
-I/home/jamborm/gcc/trunk/src/gcc/../libcpp/include 
-I/opt/cfarm/gmp-latest/include -I/opt/cfarm/mpfr-latest/include 
-I/opt/cfarm/mpc-latest/include  
-I/home/jamborm/gcc/trunk/src/gcc/../libdecnumber 
-I/home/jamborm/gcc/trunk/src/gcc/../libdecnumber/bid -I../libdecnumber 
-I/home/jamborm/gcc/trunk/src/gcc/../libbacktrace   -o i386-options.o -MT 
i386-options.o -MMD -MP -MF ./.deps/i386-options.TPo 
/home/jamborm/gcc/trunk/src/gcc/config/i386/i386-options.c
In file included from 
/home/jamborm/gcc/trunk/src/gcc/config/i386/i386-options.c:94:0:
/home/jamborm/gcc/trunk/src/gcc/config/i386/x86-tune-costs.h:32:56: error: 
uninitialized const member ‘stringop_algs::stringop_strategy::max’
   {rep_prefix_1_byte, {{-1, rep_prefix_1_byte, false;
^
/home/jamborm/gcc/trunk/src/gcc/config/i386/x86-tune-costs.h:32:56: warning: 
missing initializer for member ‘stringop_algs::stringop_strategy::max’ 
[-Wmissing-field-initializers]
/home/jamborm/gcc/trunk/src/gcc/config/i386/x86-tune-costs.h:32:56: error: 
uninitialized const member ‘stringop_algs::stringop_strategy::alg’
/home/jamborm/gcc/trunk/src/gcc/config/i386/x86-tune-costs.h:32:56: warning: 
missing initializer for member ‘stringop_algs::stringop_strategy::alg’ 
[-Wmissing-field-initializers]
/home/jamborm/gcc/trunk/src/gcc/config/i386/x86-tune-costs.h:32:56: warning: 
missing initializer for member ‘stringop_algs::stringop_strategy::noalign’ 
[-Wmissing-field-initializers]
/home/jamborm/gcc/trunk/src/gcc/config/i386/x86-tune-costs.h:32:56: error: 
uninitialized const member ‘stringop_algs::stringop_strategy::max’
/home/jamborm/gcc/trunk/src/gcc/config/i386/x86-tune-costs.h:32:56: warning: 
missing initializer for member ‘stringop_algs::stringop_strategy::max’ 
[-Wmissing-field-initializers]
/home/jamborm/gcc/trunk/src/gcc/config/i386/x86-tune-costs.h:32:56: error: 
uninitialized const member ‘stringop_algs::stringop_strategy::alg’
/home/jamborm/gcc/trunk/src/gcc/config/i386/x86-tune-costs.h:32:56: warning: 
missing initializer for member ‘stringop_algs::stringop_strategy::alg’ 
[-Wmissing-field-initializers]
/home/jamborm/gcc/trunk/src/gcc/config/i386/x86-tune-costs.h:32:56: warning: 
missing initializer for member ‘stringop_algs::stringop_strategy::noalign’ 
[-Wmissing-field-initializers]
/home/jamborm/gcc/trunk/src/gcc/config/i386/x86-tune-costs.h:32:56: error: 
uninitialized const member ‘stringop_algs::stringop_strategy::max’
/home/jamborm/gcc/trunk/src/gcc/config/i386/x86-tune-costs.h:32:56: warning: 
missing initializer for member ‘stringop_algs::stringop_strategy::max’ 
[-Wmissing-field-initializers]
/home/jamborm/gcc/trunk/src/gcc/config/i386/x86-tune-costs.h:32:56: error: 
uninitialized const member ‘stringop_algs::stringop_strategy::alg’
/home/jamborm/gcc/trunk/src/gcc/config/i386/x86-tune-costs.h:32:56: warning: 
missing initializer for member ‘stringop_algs::stringop_strategy::alg’ 
[-Wmissing-field-initializers]
/home/jamborm/gcc/trunk/src/gcc/config/i386/x86-tune-costs.h:32:56: warning: 
missing initializer for member ‘stringop_algs::stringop_strategy::noalign’ 
[-Wmissing-field-initializers]
/home/jamborm/gcc/trunk/src/gcc/config/i386/x86-tune-costs.h:32:56: 

[Patch][RFC] openmp: don't add aritificial const decl to offload table (PRs 94848 + 95551)

2020-06-08 Thread Tobias Burnus

In the latest PR95551, the issue came up with a Fortran array
constructor ("if ((any (array /= [(-i, i=1, 10)])") used
in a target section within a host procedure. The constructor
is converted into a static local variable
  A.10 = [-1, -2, ...]
ends up in omp-offload.c's offload_vars.

With -O3 optimization, the variable is optimized away on the
host side but it is still in the .gnu.offload_vars (→ host_table,
target_data), causing link errors.

 * * *

I think there is a wider issue (→PR 95551 and others) regarding the
consistency between host and target variables and optimizations, but
I wonder why such a variables has to appear at all in the offload_vars
table.

Hence, I am thinking of the attached patch which does not add TREE_READONLY
variables to .gnu.offload_vars; I additionally require TREE_ARTIFICIAL as I
am thinking of the case such as Fortran parameter to which one an create a
pointer to – which might require the mapping information (is_device_{addr,ptr}).
[The question is whether more needs to be excluded, e.g. to exclude
virtual tables from the exlusion? For instance by requiring
  TREE_CODE (DECL_CONTEXT (decl)) == FUNCTION_DECL ?]

For the test case, with -O3, the variable (A.10.3) is optimized away and
seemingly also not streamed out as it also does not appear with -foffload="-O0".

Thoughts?

Tobias

-
Mentor Graphics (Deutschland) GmbH, Arnulfstraße 201, 80634 München / Germany
Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Alexander 
Walter
openmp: don't add aritificial const decl to offload table (PRs 94848 + 95551)

gcc/ChangeLog:

	PR lto/94848
	PR middle-end/95551
	* lto-cgraph.c (output_offload_tables): Skip readonly
	aritificial variables.
	* omp-offload.c (add_decls_addresses_to_decl_constructor,
	omp_finish_file): Likewise

libgomp/ChangeLog:

	PR lto/94848
	PR middle-end/95551
	* testsuite/libgomp.fortran/target-var.f90: New test.

 gcc/lto-cgraph.c |  4 +++
 gcc/omp-offload.c|  7 +-
 libgomp/testsuite/libgomp.fortran/target-var.f90 | 32 
 3 files changed, 42 insertions(+), 1 deletion(-)

diff --git a/gcc/lto-cgraph.c b/gcc/lto-cgraph.c
index a671c671fa7..747d44c9f84 100644
--- a/gcc/lto-cgraph.c
+++ b/gcc/lto-cgraph.c
@@ -1077,6 +1077,10 @@ output_offload_tables (void)
 
   for (unsigned i = 0; i < vec_safe_length (offload_vars); i++)
 {
+  if (TREE_READONLY ((*offload_vars)[i])
+	  && DECL_ARTIFICIAL ((*offload_vars)[i]))
+	continue;
+
   streamer_write_enum (ob->main_stream, LTO_symtab_tags,
 			   LTO_symtab_last_tag, LTO_symtab_variable);
   lto_output_var_decl_ref (ob->decl_state, ob->main_stream,
diff --git a/gcc/omp-offload.c b/gcc/omp-offload.c
index b2df91a5724..2f6c55d8667 100644
--- a/gcc/omp-offload.c
+++ b/gcc/omp-offload.c
@@ -125,6 +125,9 @@ add_decls_addresses_to_decl_constructor (vec *v_decls,
 #endif
 	  && lookup_attribute ("omp declare target link", DECL_ATTRIBUTES (it));
 
+  if (is_var && TREE_READONLY (it) && DECL_ARTIFICIAL (it))
+	continue;
+
   tree size = NULL_TREE;
   if (is_var)
 	size = fold_convert (const_ptr_type_node, DECL_SIZE_UNIT (it));
@@ -341,7 +344,7 @@ omp_finish_file (void)
   add_decls_addresses_to_decl_constructor (offload_vars, v_v);
 
   tree vars_decl_type = build_array_type_nelts (pointer_sized_int_node,
-		num_vars * 2);
+		vec_safe_length (v_v));
   tree funcs_decl_type = build_array_type_nelts (pointer_sized_int_node,
 		 num_funcs);
   SET_TYPE_ALIGN (vars_decl_type, TYPE_ALIGN (pointer_sized_int_node));
@@ -381,6 +384,8 @@ omp_finish_file (void)
   for (unsigned i = 0; i < num_vars; i++)
 	{
 	  tree it = (*offload_vars)[i];
+	  if (TREE_READONLY (it) && DECL_ARTIFICIAL (it))
+	continue;
 #ifdef ACCEL_COMPILER
 	  if (DECL_HAS_VALUE_EXPR_P (it)
 	  && lookup_attribute ("omp declare target link",
diff --git a/libgomp/testsuite/libgomp.fortran/target-var.f90 b/libgomp/testsuite/libgomp.fortran/target-var.f90
new file mode 100644
index 000..5e5ccd47c96
--- /dev/null
+++ b/libgomp/testsuite/libgomp.fortran/target-var.f90
@@ -0,0 +1,32 @@
+! { dg-additional-options "-O3" }
+!
+! With -O3 the static local variable A.10 generated for
+! the array constructor [-2, -4, ..., -20] is optimized
+! away - which has to be handled in the offload_vars table.
+!
+program main
+  implicit none (type, external)
+  integer :: j
+  integer, allocatable :: A(:)
+
+  A = [(3*j, j=1, 10)]
+  call bar (A)
+  deallocate (A)
+contains
+  subroutine bar (array)
+integer :: i
+integer :: array(:)
+
+!$omp target map(from:array)
+!$acc parallel copyout(array)
+array = [(-2*i, i = 1, size(array))]
+!$omp do private(array)
+!$acc loop gang private(array)
+do i = 1, 10
+  array(i) = 9*i
+end do
+if (any (array /= [(-2*i, i = 1, 10)])) error stop 2
+!$omp end target
+!$acc end parallel
+  end 

Re: [PATCH] hurd: libgcc unwinding support over signal trampolines

2020-06-08 Thread Thomas Schwinge
Hi Samuel!

On 2020-05-29T13:46:50+0200, Samuel Thibault  wrote:
> libgcc is currently missing the support for unwinding over signal
> trampolines on GNU/Hurd.

ACK.  Has been on my long TODO list for a long time.  ;-)

> The attached patch implements it.

Thanks!

I'm not intimately familiar with the unwinding implementation, but your
changes look quite what I'd have guessed they'd look like, and also
somewhat similar to 'libgcc/config/i386/linux-unwind.h'.  (I'll get
there, eventually, again..., but) I'm not currently set up to test this,
but I'll assume you have.

Which GCC branches would you like this on?

> --- /dev/null
> +++ b/src/libgcc/config/i386/gnu-unwind.h
> @@ -0,0 +1,107 @@

> + * i386 sigtramp frame we are looking for follows.
> + * (see glibc/sysdeps/mach/hurd/i386/trampoline.c assembly)
> + *
> + * rpc_wait_trampoline:
> + *   0:  b8 e7 ff ff ff  mov$-25,%eax   mach_msg_trap
> + *   5:  9a 00 00 00 00 07 00lcall  $7,$0
> + *  12:  89 01   movl   %eax, (%ecx)
> + *  14:  89 dc   movl   %ebx, %esp  switch to signal 
> stack
> + *
> + * trampoline:
> + *  16:  ff d2   call   *%edx   call the handler 
> function
> + * RA HERE
> + *  18:  83 c4 0caddl   $12, %esp   pop its args
> + *  21:  c3  retreturn to 
> sigreturn
> + *
> + * firewall:
> + *  22:  f4  hlt
> + */
> +
> +  if (!(   *(unsigned int   *)(context->ra ) == 0xc30cc483
> +&& *(unsigned char  *)(context->ra +  4) ==   0xf4
> +
> +&& *(unsigned int   *)(context->ra -  4) == 0xd2ffdc89
> +&& *(unsigned int   *)(context->ra -  8) == 0x01890007
> +&& *(unsigned int   *)(context->ra - 12) == 0x
> +&& *(unsigned int   *)(context->ra - 16) == 0x9aff
> +&& *(unsigned short *)(context->ra - 18) == 0xe7b8))
> +return _URC_END_OF_STACK;

Once we've got this in GCC, please then also cross-reference GCC's
'libgcc/config/i386/gnu-unwind.h' file in glibc's
'sysdeps/mach/hurd/i386/trampoline.c' file.


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


Re: [PATCH RFA] tree-inline: Fix VLA handling [PR95552]

2020-06-08 Thread Eric Botcazou
> The only case handled specially is TYPE_DECL; other DECL_EXPRs fall
> through to the default case, where we WALK_SUBTREE over all the operands
> of the expression, which for DECL_EXPR is the decl.

It seems hard to believe that the inliner relies on this to copy DECLs though, 
see the calls to remap_decl[s].  And note that remap_decl has had a special 
handling for DECL_ORIGINAL_TYPE of TYPE_DECLs since 2003.  Are you sure the 
problem is not that the TYPE_DECL is not attached to the enclosing BIND_EXPR?

-- 
Eric Botcazou


Re: [PATCH] AArch64+SVE: Add support for unpacked unary ops and BIC

2020-06-08 Thread Richard Sandiford
Hi Joe,

Joe Ramsay  writes:
> Hi!
>
> MD patterns extended for unary ops ABS, CLS, CLZ, CNT, NEG and NOT
> to support unpacked vectors. Also extended patterns for BIC to
> support unpacked vectors where input elements are of the same width.

Thanks for the patch.  Looks good, but...

> @@ -2848,12 +2848,12 @@
>
> ;; Predicated integer unary arithmetic with merging.
> (define_expand "@cond_"
> -  [(set (match_operand:SVE_FULL_I 0 "register_operand")
> -   (unspec:SVE_FULL_I
> +  [(set (match_operand:SVE_I 0 "register_operand")
> +  (unspec:SVE_I
>   [(match_operand: 1 "register_operand")
> -  (SVE_INT_UNARY:SVE_FULL_I
> -(match_operand:SVE_FULL_I 2 "register_operand"))
> - (match_operand:SVE_FULL_I 3 "aarch64_simd_reg_or_zero")]
> + (SVE_INT_UNARY:SVE_I
> +   (match_operand:SVE_I 2 "register_operand"))
> + (match_operand:SVE_I 3 "aarch64_simd_reg_or_zero")]
>   UNSPEC_SEL))]
>"TARGET_SVE"
> )

...it shouldn't be necessary to change the @cond_
expander to get this to work.  If we did change it, we'd also need
to change the associated define_insns (*cond__2 and
*cond__any), otherwise the expanders would generate
unrecognisable instructions.  So I think we should drop this part
of the patch and leave it as future work.

The other SVE_INT_UNARYs are clrsb, clz, popcount, ss_abs and ss_neg.
I agree that we can't easily test those, but that the change should in
principle be correct for them too.  (In particular, all of them need
the element type (Vetype) rather than the container type (Vctype),
which is one of the main questions when extending these patterns.)

Thanks,
Richard


[PATCH] coroutines: Add a cleanup expression for g-r-o when needed [PR95477].

2020-06-08 Thread Iain Sandoe
Hi

The PR reports that we fail to destroy the object initially created from
the get-return-object call.   Fixed by adding a cleanup when the DTOR is
non-trivial.  In addition, to meet the specific wording that the call to
get_return_object creates the glvalue for the return, we must construct
that in-place in the return object to avoid a second copy/move CTOR.

tested on x86_64,powerpc64-linux, x86_64-darwin
OK for master?
10.2?
thanks
Iain

gcc/cp/ChangeLog:

PR c++/95477
* coroutines.cc (morph_fn_to_coro): Apply a cleanup to
the get return object when the DTOR is non-trivial.

gcc/testsuite/ChangeLog:

* g++.dg/coroutines/pr95477.C: New test.
---
 gcc/cp/coroutines.cc  | 61 +++
 gcc/testsuite/g++.dg/coroutines/pr95477.C | 37 ++
 2 files changed, 89 insertions(+), 9 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/coroutines/pr95477.C

diff --git a/gcc/cp/coroutines.cc b/gcc/cp/coroutines.cc
index f2d7853477d..5a78bec1c9a 100644
--- a/gcc/cp/coroutines.cc
+++ b/gcc/cp/coroutines.cc
@@ -4284,12 +4284,34 @@ morph_fn_to_coro (tree orig, tree *resumer, tree 
*destroyer)
 
   tree gro = NULL_TREE;
   tree gro_bind_vars = NULL_TREE;
+  tree gro_cleanup_stmt = NULL_TREE;
   /* We have to sequence the call to get_return_object before initial
  suspend.  */
   if (gro_is_void_p)
-finish_expr_stmt (get_ro);
+r = get_ro;
+  else if (same_type_p (gro_type, fn_return_type))
+{
+ /* [dcl.fct.def.coroutine] / 7
+   The expression promise.get_return_object() is used to initialize the
+   glvalue result or... (see below)
+   Construct the return result directly.  */
+  if (TYPE_NEEDS_CONSTRUCTING (gro_type))
+   {
+ vec *arg = make_tree_vector_single (get_ro);
+ r = build_special_member_call (DECL_RESULT (orig),
+complete_ctor_identifier,
+, gro_type, LOOKUP_NORMAL,
+tf_warning_or_error);
+ release_tree_vector (arg);
+   }
+  else
+   r = build2_loc (fn_start, INIT_EXPR, gro_type,
+   DECL_RESULT (orig), get_ro);
+}
   else
 {
+  /* ... or ... Construct an object that will be used as the single
+   param to the CTOR for the return object.  */
   gro = build_lang_decl (VAR_DECL, get_identifier ("coro.gro"), gro_type);
   DECL_CONTEXT (gro) = current_scope ();
   DECL_ARTIFICIAL (gro) = true;
@@ -4306,8 +4328,21 @@ morph_fn_to_coro (tree orig, tree *resumer, tree 
*destroyer)
}
   else
r = build2_loc (fn_start, INIT_EXPR, gro_type, gro, get_ro);
-  finish_expr_stmt (r);
+  /* The constructed object might require a cleanup.  */
+  if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (gro_type))
+   {
+ tree cleanup
+   = build_special_member_call (gro, complete_dtor_identifier,
+NULL, gro_type, LOOKUP_NORMAL,
+tf_warning_or_error);
+ gro_cleanup_stmt = build_stmt (input_location, CLEANUP_STMT, NULL,
+cleanup, gro);
+   }
 }
+  finish_expr_stmt (r);
+
+  if (gro_cleanup_stmt)
+CLEANUP_BODY (gro_cleanup_stmt) = push_stmt_list ();
 
   /* Initialize the resume_idx_name to 0, meaning "not started".  */
   tree resume_idx_m
@@ -4349,14 +4384,15 @@ morph_fn_to_coro (tree orig, tree *resumer, tree 
*destroyer)
  promise was constructed.  We now supply a reference to that var,
  either as the return value (if it's the same type) or to the CTOR
  for an object of the return type.  */
-  if (gro_is_void_p)
-r = NULL_TREE;
-  else
-r = rvalue (gro);
 
-  if (!same_type_p (gro_type, fn_return_type))
+  if (same_type_p (gro_type, fn_return_type))
+r = gro_is_void_p ? NULL_TREE : DECL_RESULT (orig);
+  else
 {
-  /* The return object is , even if the gro is void.  */
+  /* If we have void gro and a non-class return type, then pick a
+defensive initialisation value.  */
+  r = gro_is_void_p ? integer_zero_node : rvalue (gro);
+  /* The return object is constructed, even if the gro is void.  */
   if (CLASS_TYPE_P (fn_return_type))
{
  vec *args = NULL;
@@ -4374,12 +4410,19 @@ morph_fn_to_coro (tree orig, tree *resumer, tree 
*destroyer)
  if (args)
release_tree_vector (args);
}
-  else /* ??? suppose we have non-class return and void gro?  */
+  else
r = build1_loc (input_location, CONVERT_EXPR, fn_return_type, r);
 }
 
   finish_return_stmt (r);
 
+  if (gro_cleanup_stmt)
+{
+  CLEANUP_BODY (gro_cleanup_stmt)
+= pop_stmt_list (CLEANUP_BODY (gro_cleanup_stmt));
+  add_stmt (gro_cleanup_stmt);
+}
+
   /* Finish up the ramp function.  */
   BIND_EXPR_VARS (gro_context_bind) = gro_bind_vars;
   

Re: [PATCH] forwprop: Ignore scalar mode vectors in simplify_vector_constructor [PR95528]

2020-06-08 Thread Richard Biener
On June 8, 2020 10:14:40 AM GMT+02:00, Jakub Jelinek  wrote:
>Hi!
>
>As mentioned in the PR, the problem is that at least the x86 backend
>asumes
>that the vec_unpack* and vec_pack* optabs with integral modes are for
>the
>AVX512-ish vector masks rather than for very small vectors done in
>GPRs.
>The only other target that seems to have a scalar mode vec_{,un}pack*
>optab
>is aarch64 as discussed in the PR, so there is also a condition for
>that.
>All other targets have just vector mode optabs.
>
>Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

OK. 

Richard. 

>2020-06-08  Jakub Jelinek  
>
>   PR target/95528
>   * tree-ssa-forwprop.c (simplify_vector_constructor): Don't use
>   VEC_UNPACK*_EXPR or VEC_PACK_TRUNC_EXPR with scalar modes unless the
>   type is vector boolean.
>
>   * g++.dg/opt/pr95528.C: New test.
>
>--- gcc/tree-ssa-forwprop.c.jj 2020-05-26 09:28:53.244149208 +0200
>+++ gcc/tree-ssa-forwprop.c2020-06-05 13:10:26.992648945 +0200
>@@ -2401,6 +2401,10 @@ simplify_vector_constructor (gimple_stmt
> && (dblvectype
> = build_vector_type (TREE_TYPE (TREE_TYPE (orig[0])),
>  nelts * 2))
>+/* Only use it for vector modes or for vector booleans
>represented
>+   as scalar bitmasks.  See PR95528.  */
>+&& (VECTOR_MODE_P (TYPE_MODE (dblvectype))
>+|| VECTOR_BOOLEAN_TYPE_P (dblvectype))
> && (optab = optab_for_tree_code (FLOAT_TYPE_P (TREE_TYPE (type))
>  ? VEC_UNPACK_FLOAT_LO_EXPR
>  : VEC_UNPACK_LO_EXPR,
>@@ -2442,6 +2446,13 @@ simplify_vector_constructor (gimple_stmt
>  && (halfvectype
>= build_vector_type (TREE_TYPE (TREE_TYPE (orig[0])),
> nelts / 2))
>+ /* Only use it for vector modes or for vector booleans
>+represented as scalar bitmasks, or allow halfvectype
>+be the element mode.  See PR95528.  */
>+ && (VECTOR_MODE_P (TYPE_MODE (halfvectype))
>+ || VECTOR_BOOLEAN_TYPE_P (halfvectype)
>+ || (TYPE_MODE (halfvectype)
>+ == TYPE_MODE (TREE_TYPE (halfvectype
>  && (optab = optab_for_tree_code (VEC_PACK_TRUNC_EXPR,
>   halfvectype,
>   optab_default))
>--- gcc/testsuite/g++.dg/opt/pr95528.C.jj  2020-06-05 13:13:17.137165849
>+0200
>+++ gcc/testsuite/g++.dg/opt/pr95528.C 2020-06-05 13:13:13.144224118
>+0200
>@@ -0,0 +1,27 @@
>+// PR target/95528
>+// { dg-do compile { target c++11 } }
>+// { dg-options "-O3" }
>+// { dg-additional-options "-march=skylake-avx512" { target i?86-*-*-
>x86_64-*-* } }
>+
>+template  struct b {
>+  typedef a c __attribute__((vector_size(sizeof(a) * 4)));
>+  union {
>+c d;
>+struct {
>+  a e, f, g, h;
>+};
>+  };
>+  b();
>+  b(const b ) : d(i.d) {}
>+  static b j(c);
>+  template  operator b() {
>+b::j(typename b::c{k(e), k(f), k(g), k(h)});
>+return b();
>+  }
>+};
>+template  using l = b;
>+using m = l;
>+using n = l;
>+m o(n i) { return i; }
>+b q;
>+void p() { o(q); }
>
>   Jakub



[PATCH] AArch64+SVE: Add support for unpacked unary ops and BIC

2020-06-08 Thread Joe Ramsay
Hi!

MD patterns extended for unary ops ABS, CLS, CLZ, CNT, NEG and NOT
to support unpacked vectors. Also extended patterns for BIC to
support unpacked vectors where input elements are of the same width.

Tested on x86_64-linux and aarch64-linux hosts.

Thanks,
Joe

gcc/ChangeLog:

2020-05-27  Joe Ramsay  

* config/aarch64/aarch64-sve.md (2): Add support for 
unpacked vectors.
* config/aarch64/aarch64-sve.md (@aarch64_pred_): Add 
support for unpacked vectors.
* config/aarch64/aarch64-sve.md (@cond_): Add support for 
unpacked vectors.
* config/aarch64/aarch64-sve.md (@aarch64_bic): Enable unpacked 
BIC.
* config/aarch64/aarch64-sve-md (*bic3): Enable unpacked BIC.

gcc/testsuite/ChangeLog:

2020-05-27  Joe Ramsay  

* gcc.target/aarch64/sve/logical_unpacked_abs.c: New test.
* gcc.target/aarch64/sve/logical_unpacked_bic_1.c: New test.
* gcc.target/aarch64/sve/logical_unpacked_bic_2.c: New test.
* gcc.target/aarch64/sve/logical_unpacked_bic_3.c: New test.
* gcc.target/aarch64/sve/logical_unpacked_bic_4.c: New test.
* gcc.target/aarch64/sve/logical_unpacked_neg.c: New test.
* gcc.target/aarch64/sve/logical_unpacked_not.c: New test.
---
gcc/config/aarch64/aarch64-sve.md  | 48 +++---
.../gcc.target/aarch64/sve/logical_unpacked_abs.c  | 16 
.../aarch64/sve/logical_unpacked_bic_1.c   | 15 +++
.../aarch64/sve/logical_unpacked_bic_2.c   | 15 +++
.../aarch64/sve/logical_unpacked_bic_3.c   | 15 +++
.../aarch64/sve/logical_unpacked_bic_4.c   | 15 +++
.../gcc.target/aarch64/sve/logical_unpacked_neg.c  | 16 
.../gcc.target/aarch64/sve/logical_unpacked_not.c  | 16 
8 files changed, 132 insertions(+), 24 deletions(-)
create mode 100644 gcc/testsuite/gcc.target/aarch64/sve/logical_unpacked_abs.c
create mode 100644 gcc/testsuite/gcc.target/aarch64/sve/logical_unpacked_bic_1.c
create mode 100644 gcc/testsuite/gcc.target/aarch64/sve/logical_unpacked_bic_2.c
create mode 100644 gcc/testsuite/gcc.target/aarch64/sve/logical_unpacked_bic_3.c
create mode 100644 gcc/testsuite/gcc.target/aarch64/sve/logical_unpacked_bic_4.c
create mode 100644 gcc/testsuite/gcc.target/aarch64/sve/logical_unpacked_neg.c
create mode 100644 gcc/testsuite/gcc.target/aarch64/sve/logical_unpacked_not.c

diff --git a/gcc/config/aarch64/aarch64-sve.md 
b/gcc/config/aarch64/aarch64-sve.md
index 8f0944c..f7100a2 100644
--- a/gcc/config/aarch64/aarch64-sve.md
+++ b/gcc/config/aarch64/aarch64-sve.md
@@ -2822,11 +2822,11 @@

;; Unpredicated integer unary arithmetic.
(define_expand "2"
-  [(set (match_operand:SVE_FULL_I 0 "register_operand")
-   (unspec:SVE_FULL_I
+  [(set (match_operand:SVE_I 0 "register_operand")
+  (unspec:SVE_I
  [(match_dup 2)
-  (SVE_INT_UNARY:SVE_FULL_I
-(match_operand:SVE_FULL_I 1 "register_operand"))]
+ (SVE_INT_UNARY:SVE_I
+   (match_operand:SVE_I 1 "register_operand"))]
  UNSPEC_PRED_X))]
   "TARGET_SVE"
   {
@@ -2836,11 +2836,11 @@

;; Integer unary arithmetic predicated with a PTRUE.
(define_insn "@aarch64_pred_"
-  [(set (match_operand:SVE_FULL_I 0 "register_operand" "=w")
-   (unspec:SVE_FULL_I
+  [(set (match_operand:SVE_I 0 "register_operand" "=w")
+  (unspec:SVE_I
  [(match_operand: 1 "register_operand" "Upl")
-  (SVE_INT_UNARY:SVE_FULL_I
-(match_operand:SVE_FULL_I 2 "register_operand" "w"))]
+ (SVE_INT_UNARY:SVE_I
+   (match_operand:SVE_I 2 "register_operand" "w"))]
  UNSPEC_PRED_X))]
   "TARGET_SVE"
   "\t%0., %1/m, %2."
@@ -2848,12 +2848,12 @@

;; Predicated integer unary arithmetic with merging.
(define_expand "@cond_"
-  [(set (match_operand:SVE_FULL_I 0 "register_operand")
-   (unspec:SVE_FULL_I
+  [(set (match_operand:SVE_I 0 "register_operand")
+  (unspec:SVE_I
  [(match_operand: 1 "register_operand")
-  (SVE_INT_UNARY:SVE_FULL_I
-(match_operand:SVE_FULL_I 2 "register_operand"))
- (match_operand:SVE_FULL_I 3 "aarch64_simd_reg_or_zero")]
+ (SVE_INT_UNARY:SVE_I
+   (match_operand:SVE_I 2 "register_operand"))
+ (match_operand:SVE_I 3 "aarch64_simd_reg_or_zero")]
  UNSPEC_SEL))]
   "TARGET_SVE"
)
@@ -4234,13 +4234,13 @@

;; Unpredicated BIC.
(define_expand "@aarch64_bic"
-  [(set (match_operand:SVE_FULL_I 0 "register_operand")
-   (and:SVE_FULL_I
- (unspec:SVE_FULL_I
+  [(set (match_operand:SVE_I 0 "register_operand")
+  (and:SVE_I
+(unspec:SVE_I
[(match_dup 3)
-(not:SVE_FULL_I (match_operand:SVE_FULL_I 2 
"register_operand"))]
+ 

Re: Fix ICE in ODR enum streaming

2020-06-08 Thread Jakub Jelinek via Gcc-patches
On Sat, Jun 06, 2020 at 10:21:31PM +0200, Jan Hubicka wrote:
> diff --git a/gcc/testsuite/g++.dg/torture/pr95548.C 
> b/gcc/testsuite/g++.dg/torture/pr95548.C
> new file mode 100644
> index 000..bca4f753f7e
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/torture/pr95548.C
> @@ -0,0 +1,8 @@
> +/* { dg-do compile } */
> +enum a { b = (unsigned long)-1 } c;
> +#ifdef __SIZEOF_INT128__
> +enum c { d = (unsigned long)-1 } e;
> +#endif
> +main()
> +{
> +}

The test fails everywhere, e.g. because main doesn't have return type.

Here is what I have committed as obvious for it, tested on x86_64-linux
-m32/-m64, and tested with your ipa change reverted to see the ICE in those
cases.

2020-06-08  Jakub Jelinek  

PR lto/95548
* g++.dg/torture/pr95548.C: Change from dg-do compile to dg-do link,
add return type for main, for __SIZEOF_INT128__ test with __uint128_t
enumerator constants and add a test with unsigned long long
enumerators for all targets.

--- gcc/testsuite/g++.dg/torture/pr95548.C.jj   2020-06-08 10:21:38.779224052 
+0200
+++ gcc/testsuite/g++.dg/torture/pr95548.C  2020-06-08 10:24:48.229422404 
+0200
@@ -1,8 +1,10 @@
-/* { dg-do compile } */
-enum a { b = (unsigned long)-1 } c;
+/* { dg-do link } */
+enum A { A1 = (unsigned long)-1 } a;
+enum B { B1 = (unsigned long long)-1, B2 = 0x123456789abcdef0ULL } b;
 #ifdef __SIZEOF_INT128__
-enum c { d = (unsigned long)-1 } e;
+enum C { C1 = (__uint128_t)-1, C2 = ((__uint128_t) 0x123456789abcdef0ULL) << 
64 | 0x0fedcba987654321ULL } c;
 #endif
-main()
+int
+main ()
 {
 }


Jakub



Re: [patch] Make memory copy functions scalar storage order barriers

2020-06-08 Thread Eric Botcazou
> OK, but all I was saying is that looking at the pointed-to type of
> the address argument to the memcpy looks fragile to me.  For the
> case cited above it would be better to look at the actual
> reference we are looking up and not allowing memcpy handling
> when that reference contains a storage order barrier?  Like
> a && !contains_storage_order_barrier_p (vr->operands) on the whole block
> like we do for the assign from constant/SSA value case?

The memcpy is the storage order barrier though, there is no other, so I'm not 
sure what contains_storage_order_barrier_p should be called on.  Or do you 
mean that an operand should be created for the memcpy with "reverse" set?

> But the above cited case is the _only_ case we're possibly building an
> assignment of a variable - so it's enough to assert that in the above case
> destvar is not TYPE_REVERSE_STORAGE_ORDER?

What about

  /* If we can perform the copy efficiently with first doing all loads
 and then all stores inline it that way.  Currently efficiently
 means that we can load all the memory into a single integer
 register which is what MOVE_MAX gives us.  */
  src_align = get_pointer_alignment (src);

It's also a scalar copy, so it won't work either.

> The other cases all build an aggregate copy assignment with
> a non-reverse-storage-order char[size] type which should be OK, no?

Yes, theoritically, but SRA rewrites the access into a scalar access and we're 
back to square one (I tried), so this can possibly work only if the array type 
is built with TYPE_REVERSE_STORAGE_ORDER too, which implies that the source is 
in reverse order too.  So the only case that could be handled correctly is the 
memcpy between two aggregates types with TYPE_REVERSE_STORAGE_ORDER.

> Note even for the above we probably would be fine if we'd made sure
> to use a !TYPE_REVERSE_STORAGE_ORDER "qualified" type
> for the access.  So the memcpy happens via a native order
> load plus a native order store, exactly what memcpy does (in fact
> the actual order does not matter unless the source and destination
> order "agree")?  Thus maybe amend
> 
>   /* Make sure we are not copying using a floating-point mode or
>  a type whose size possibly does not match its precision.  */
>   if (FLOAT_MODE_P (TYPE_MODE (desttype))
> 
>   || TREE_CODE (desttype) == BOOLEAN_TYPE
>   || TREE_CODE (desttype) == ENUMERAL_TYPE)
> 
> desttype = bitwise_type_for_mode (TYPE_MODE (desttype));
>   if (FLOAT_MODE_P (TYPE_MODE (srctype) )
> 
>   || TREE_CODE (srctype) == BOOLEAN_TYPE
>   || TREE_CODE (srctype) == ENUMERAL_TYPE)
> 
> srctype = bitwise_type_for_mode (TYPE_MODE (srctype));
> 
> with || TYPE_REVERSE_STORAGE_ORDER (srctype) (same for desttype)?

We don't have TYPE_REVERSE_STORAGE_ORDER qualified types, the flag is only set 
on aggregate types and bitwise_type_for_mode will return an integer type.

-- 
Eric Botcazou


[PATCH][Committed][GCC][AArch64] Expand on comment of stack-clash and implicit probing through LR.

2020-06-08 Thread Tamar Christina
Hi All,

This expands the comment on an assert we have in aarch64_layout_frame
and points to an existing comment somewhere else that has a much longer
explanation of what's going on.

Committed under the GCC Obvious rule.

Thanks,
Tamar

gcc/ChangeLog:

* config/aarch64/aarch64.c (aarch64_layout_frame): Expand comments.

-- 
diff --git a/gcc/config/aarch64/aarch64.c b/gcc/config/aarch64/aarch64.c
index 97da60762390db81df9cffaf316b909cd1609130..973c65aa4fb348450872036617362aa17310fb20 100644
--- a/gcc/config/aarch64/aarch64.c
+++ b/gcc/config/aarch64/aarch64.c
@@ -6531,7 +6531,9 @@ aarch64_layout_frame (void)
 	&& !crtl->abi->clobbers_full_reg_p (regno))
   frame.reg_offset[regno] = SLOT_REQUIRED;
 
-  /* With stack-clash, LR must be saved in non-leaf functions.  */
+  /* With stack-clash, LR must be saved in non-leaf functions.  The saving of
+ LR counts as an implicit probe which allows us to maintain the invariant
+ described in the comment at expand_prologue.  */
   gcc_assert (crtl->is_leaf
 	  || maybe_ne (frame.reg_offset[R30_REGNUM], SLOT_NOT_REQUIRED));
 



[PATCH] forwprop: Ignore scalar mode vectors in simplify_vector_constructor [PR95528]

2020-06-08 Thread Jakub Jelinek via Gcc-patches
Hi!

As mentioned in the PR, the problem is that at least the x86 backend asumes
that the vec_unpack* and vec_pack* optabs with integral modes are for the
AVX512-ish vector masks rather than for very small vectors done in GPRs.
The only other target that seems to have a scalar mode vec_{,un}pack* optab
is aarch64 as discussed in the PR, so there is also a condition for that.
All other targets have just vector mode optabs.

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

2020-06-08  Jakub Jelinek  

PR target/95528
* tree-ssa-forwprop.c (simplify_vector_constructor): Don't use
VEC_UNPACK*_EXPR or VEC_PACK_TRUNC_EXPR with scalar modes unless the
type is vector boolean.

* g++.dg/opt/pr95528.C: New test.

--- gcc/tree-ssa-forwprop.c.jj  2020-05-26 09:28:53.244149208 +0200
+++ gcc/tree-ssa-forwprop.c 2020-06-05 13:10:26.992648945 +0200
@@ -2401,6 +2401,10 @@ simplify_vector_constructor (gimple_stmt
  && (dblvectype
  = build_vector_type (TREE_TYPE (TREE_TYPE (orig[0])),
   nelts * 2))
+ /* Only use it for vector modes or for vector booleans represented
+as scalar bitmasks.  See PR95528.  */
+ && (VECTOR_MODE_P (TYPE_MODE (dblvectype))
+ || VECTOR_BOOLEAN_TYPE_P (dblvectype))
  && (optab = optab_for_tree_code (FLOAT_TYPE_P (TREE_TYPE (type))
   ? VEC_UNPACK_FLOAT_LO_EXPR
   : VEC_UNPACK_LO_EXPR,
@@ -2442,6 +2446,13 @@ simplify_vector_constructor (gimple_stmt
   && (halfvectype
 = build_vector_type (TREE_TYPE (TREE_TYPE (orig[0])),
  nelts / 2))
+  /* Only use it for vector modes or for vector booleans
+ represented as scalar bitmasks, or allow halfvectype
+ be the element mode.  See PR95528.  */
+  && (VECTOR_MODE_P (TYPE_MODE (halfvectype))
+  || VECTOR_BOOLEAN_TYPE_P (halfvectype)
+  || (TYPE_MODE (halfvectype)
+  == TYPE_MODE (TREE_TYPE (halfvectype
   && (optab = optab_for_tree_code (VEC_PACK_TRUNC_EXPR,
halfvectype,
optab_default))
--- gcc/testsuite/g++.dg/opt/pr95528.C.jj   2020-06-05 13:13:17.137165849 
+0200
+++ gcc/testsuite/g++.dg/opt/pr95528.C  2020-06-05 13:13:13.144224118 +0200
@@ -0,0 +1,27 @@
+// PR target/95528
+// { dg-do compile { target c++11 } }
+// { dg-options "-O3" }
+// { dg-additional-options "-march=skylake-avx512" { target i?86-*-*- 
x86_64-*-* } }
+
+template  struct b {
+  typedef a c __attribute__((vector_size(sizeof(a) * 4)));
+  union {
+c d;
+struct {
+  a e, f, g, h;
+};
+  };
+  b();
+  b(const b ) : d(i.d) {}
+  static b j(c);
+  template  operator b() {
+b::j(typename b::c{k(e), k(f), k(g), k(h)});
+return b();
+  }
+};
+template  using l = b;
+using m = l;
+using n = l;
+m o(n i) { return i; }
+b q;
+void p() { o(q); }

Jakub



[Ada] Remove the Has_Dynamic_Range_Check flag

2020-06-08 Thread Pierre-Marie de Rodat
The flag was made obsolete some time ago and no fallout has been
detected since then, so this change finally removes it.

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

2020-06-08  Eric Botcazou  

gcc/ada/

* atree.adb (New_Copy): Do not clear Has_Dynamic_Range_Check.
* checks.ads (Append_Range_Checks): Remove Flag_Node parameter.
(Insert_Range_Checks): Likewise and remove default value of
Static_Loc parameter.
* checks.adb (Append_Range_Checks): Remove Flag_Node parameter.
Do not test and set Has_Dynamic_Range_Check.
(Insert_Range_Checks): Likewise and remove default value of
Static_Loc parameter.
* csinfo.adb (CSinfo): Remove 'L' from [NEUB]_Fields pattern and
do not handle Has_Dynamic_Range_Check.
* exp_ch5.adb (Expand_N_Assignment_Statement): Remove argument
in call to Insert_Range_Checks.
* sem_ch3.adb (Analyze_Subtype_Declaration): Do not fiddle
with Has_Dynamic_Range_Check.
(Process_Range_Expr_In_Decl): Remove argument in calls to
Insert_Range_Checks and Append_Range_Checks.
* sinfo.ads (Has_Dynamic_Range_Check): Delete.
(Set_Has_Dynamic_Range_Check): Likewise.
* sinfo.adb (Has_Dynamic_Range_Check): Delete.
(Set_Has_Dynamic_Range_Check): Likewise.
* treepr.adb (Print_Node): Do not print Has_Dynamic_Range_Check.--- gcc/ada/atree.adb
+++ gcc/ada/atree.adb
@@ -1659,12 +1659,6 @@ package body Atree is
  Nodes.Table (New_Id).Rewrite_Ins := False;
  pragma Debug (New_Node_Debugging_Output (New_Id));
 
- --  Clear Has_Dynamic_Range_Check since it doesn't apply anymore
-
- if Nkind (Source) in N_Subexpr then
-Set_Has_Dynamic_Range_Check (New_Id, False);
- end if;
-
  --  Clear Is_Overloaded since we cannot have semantic interpretations
  --  of this new node.
 

--- gcc/ada/checks.adb
+++ gcc/ada/checks.adb
@@ -488,17 +488,13 @@ package body Checks is
  (Checks   : Check_Result;
   Stmts: List_Id;
   Suppress_Typ : Entity_Id;
-  Static_Sloc  : Source_Ptr;
-  Flag_Node: Node_Id)
+  Static_Sloc  : Source_Ptr)
is
   Checks_On : constant Boolean :=
 not Index_Checks_Suppressed (Suppress_Typ)
   or else
 not Range_Checks_Suppressed (Suppress_Typ);
 
-  Internal_Flag_Node   : constant Node_Id:= Flag_Node;
-  Internal_Static_Sloc : constant Source_Ptr := Static_Sloc;
-
begin
   --  For now we just return if Checks_On is false, however this should be
   --  enhanced to check for an always True value in the condition and to
@@ -514,19 +510,11 @@ package body Checks is
  if Nkind (Checks (J)) = N_Raise_Constraint_Error
and then Present (Condition (Checks (J)))
  then
-if Has_Dynamic_Range_Check (Internal_Flag_Node) then
-   pragma Assert (False);
-   null;
-
-else
-   Append_To (Stmts, Checks (J));
-   Set_Has_Dynamic_Range_Check (Internal_Flag_Node);
-end if;
-
+Append_To (Stmts, Checks (J));
  else
 Append_To
   (Stmts,
-Make_Raise_Constraint_Error (Internal_Static_Sloc,
+Make_Raise_Constraint_Error (Static_Sloc,
   Reason => CE_Range_Check_Failed));
  end if;
   end loop;
@@ -3440,14 +3428,6 @@ package body Checks is
 
 Insert_Action (Expr, R_Cno);
 
---  This old code doesn't make sense, why is the context flagged as
---  requiring dynamic range checks now in the middle of generating
---  them ???
-
-if not Do_Static then
-   Set_Has_Dynamic_Range_Check (Expr);
-end if;
-
 --  The triggering condition evaluates to True, the range check
 --  can be converted into a compile time constraint check.
 
@@ -7444,8 +7424,7 @@ package body Checks is
  (Checks   : Check_Result;
   Node : Node_Id;
   Suppress_Typ : Entity_Id;
-  Static_Sloc  : Source_Ptr := No_Location;
-  Flag_Node: Node_Id:= Empty;
+  Static_Sloc  : Source_Ptr;
   Do_Before: Boolean:= False)
is
   Checks_On  : constant Boolean :=
@@ -7453,9 +7432,7 @@ package body Checks is
or else
  not Range_Checks_Suppressed (Suppress_Typ);
 
-  Check_Node   : Node_Id;
-  Internal_Flag_Node   : Node_Id:= Flag_Node;
-  Internal_Static_Sloc : Source_Ptr := Static_Sloc;
+  Check_Node : Node_Id;
 
begin
   --  For now we just return if Checks_On is false, however this should be
@@ -7466,48 +7443,25 @@ package body Checks is
  return;
   end if;
 
-  if Static_Sloc = No_Location then
- Internal_Static_Sloc := Sloc (Node);
-  

[Ada] Implement AI12-0073 (Ravenscar disallows Synchronous_Barriers)

2020-06-08 Thread Pierre-Marie de Rodat
In Ada2020 the Ravenscar profile (but not the Jorvik profile) includes
a "No_Dependence => Ada.Synchronous_Barriers" restriction. This is a
binding interpretation so it applies also to earlier Ada versions, but
the unit Ada.Synchronous_Barriers did not exist before Ada 2012.

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

2020-06-08  Steve Baird  

gcc/ada/

* sem_prag.adb (Analyze_Pragma.Set_Ravenscar_Profile): Add
appropriate call to Set_Restriction_No_Dependence if Ada_Version
>= Ada2012 and Profile is either Ravenscar or a GNAT-defined
Ravenscar variant (i.e., not Jorvik).--- gcc/ada/sem_prag.adb
+++ gcc/ada/sem_prag.adb
@@ -11283,10 +11283,6 @@ package body Sem_Prag is
  --No_Dependence => Ada.Execution_Time.Group_Budget
  --No_Dependence => Ada.Execution_Time.Timers
 
- --  ??? Eventually when AI12-0073 is implemented, we'll register a
- --  No_Dependence restriction on Ada.Synchronous_Barriers
- --  for Ravenscar but not for Jorvik.
-
  if Ada_Version >= Ada_2005 then
 Pref_Id := Make_Identifier (Loc, Name_Find ("ada"));
 Sel_Id  := Make_Identifier (Loc, Name_Find ("execution_time"));
@@ -11325,7 +11321,7 @@ package body Sem_Prag is
  end if;
 
  --  Set the following restriction which was added to Ada 2012 (see
- --  AI-0171):
+ --  AI05-0171):
  --No_Dependence => System.Multiprocessors.Dispatching_Domains
 
  if Ada_Version >= Ada_2012 then
@@ -11350,7 +11346,32 @@ package body Sem_Prag is
   (Unit=> Nod,
Warn=> Treat_Restrictions_As_Warnings,
Profile => Ravenscar);
+
+--  Set the following restriction which was added to Ada 2020,
+--  but as a binding interpretation:
+-- No_Dependence => Ada.Synchronous_Barriers
+--  for Ravenscar (and therefore for Ravenscar variants) but not
+--  for Jorvik. The unit Ada.Synchronous_Barriers was introduced
+--  in Ada2012 (AI05-0174).
+
+if Profile /= Jorvik then
+   Pref_Id := Make_Identifier (Loc, Name_Find ("ada"));
+   Sel_Id  := Make_Identifier (Loc, Name_Find
+  ("synchronous_barriers"));
+
+   Nod :=
+ Make_Selected_Component
+   (Sloc  => Loc,
+Prefix=> Pref_Id,
+Selector_Name => Sel_Id);
+
+   Set_Restriction_No_Dependence
+ (Unit=> Nod,
+  Warn=> Treat_Restrictions_As_Warnings,
+  Profile => Ravenscar);
+end if;
  end if;
+
   end Set_Ravenscar_Profile;
 
--  Start of processing for Analyze_Pragma



[Ada] AI12-0204 Renaming of a prefixed view

2020-06-08 Thread Pierre-Marie de Rodat
AI12-0204 clarified that the prefix of a prefixed view that is renamed
or passed as a formal subprogram must be renamable as an object and
similarly (was already checked by GNAT), the prefix of a prefixed view
that has an implicit 'Access must be legal for 'Access and a
generalized_indexing is illegal if the equivalent prefixed view is
illegal.

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

2020-06-08  Arnaud Charlet  

gcc/ada/

* sem_ch5.adb: Fix typo.
* sem_ch8.adb (Analyze_Renamed_Primitive_Operation): Check that
the prefix of a prefixed view must be renamable as an object.--- gcc/ada/sem_ch5.adb
+++ gcc/ada/sem_ch5.adb
@@ -2390,7 +2390,7 @@ package body Sem_Ch5 is
 --  AI12-0047 stipulates that the domain (array or container)
 --  cannot be a component that depends on a discriminant if the
 --  enclosing object is mutable, to prevent a modification of the
---  dowmain of iteration in the course of an iteration.
+--  domain of iteration in the course of an iteration.
 
 --  If the object is an expression it has been captured in a
 --  temporary, so examine original node.

--- gcc/ada/sem_ch8.adb
+++ gcc/ada/sem_ch8.adb
@@ -1826,6 +1826,7 @@ package body Sem_Ch8 is
   Is_Body : Boolean)
is
   Old_S : Entity_Id;
+  Nam   : Entity_Id;
 
   function Conforms
 (Subp : Entity_Id;
@@ -1902,7 +1903,7 @@ package body Sem_Ch8 is
   end if;
 
   if Old_S = Any_Id then
- Error_Msg_N (" no subprogram or entry matches specification",  N);
+ Error_Msg_N ("no subprogram or entry matches specification",  N);
 
   else
  if Is_Body then
@@ -1920,6 +1921,21 @@ package body Sem_Ch8 is
Error_Msg_N ("mode conformance error in renaming", N);
 end if;
 
+--  AI12-0204: The prefix of a prefixed view that is renamed or
+--  passed as a formal subprogram must be renamable as an object.
+
+Nam := Prefix (Name (N));
+
+if Is_Object_Reference (Nam) then
+   if Is_Dependent_Component_Of_Mutable_Object (Nam) then
+  Error_Msg_N
+("illegal renaming of discriminant-dependent component",
+ Nam);
+   end if;
+else
+   Error_Msg_N ("expect object name in renaming", Nam);
+end if;
+
 --  Enforce the rule given in (RM 6.3.1 (10.1/2)): a prefixed
 --  view of a subprogram is intrinsic, because the compiler has
 --  to generate a wrapper for any call to it. If the name in a



[Ada] Port a modified expansion of Enum_Rep from GNAT to GNATprove

2020-06-08 Thread Pierre-Marie de Rodat
Expansion of Enum_Rep in GNATprove is meant to be a subset of the
expansion in GNAT, so it needs to be kept in sync with the frontend.
Semantics of the compiler is not affected.

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

2020-06-08  Piotr Trojanek  

gcc/ada/

* exp_spark.adb (Expand_SPARK_N_Attribute_Reference): Port
changes in frontend expander.--- gcc/ada/exp_spark.adb
+++ gcc/ada/exp_spark.adb
@@ -200,7 +200,8 @@ package body Exp_SPARK is
  Analyze_And_Resolve (N, Typ);
 
   --  Whenever possible, replace a prefix which is an enumeration literal
-  --  by the corresponding literal value.
+  --  by the corresponding literal value, just like it happens in the GNAT
+  --  expander.
 
   elsif Attr_Id = Attribute_Enum_Rep then
  declare
@@ -215,15 +216,7 @@ package body Exp_SPARK is
 --  If the argument is a literal, expand it
 
 if Nkind (Expr) in N_Has_Entity
-  and then
-(Ekind (Entity (Expr)) = E_Enumeration_Literal
- or else
-   (Nkind (Expr) in N_Has_Entity
-and then Ekind (Entity (Expr)) = E_Constant
-and then Present (Renamed_Object (Entity (Expr)))
-and then Is_Entity_Name (Renamed_Object (Entity (Expr)))
-and then Ekind (Entity (Renamed_Object (Entity (Expr =
-  E_Enumeration_Literal))
+  and then Ekind (Entity (Expr)) = E_Enumeration_Literal
 then
Exp_Attr.Expand_N_Attribute_Reference (N);
 end if;



[Ada] Implement AI12-0290 (Simple_Barriers restriction)

2020-06-08 Thread Pierre-Marie de Rodat
Change the existing implementation of the Simple_Barriers restriction to
conform to the rules given in AI12-0290. Note that the new rules are in
some cases more restrictive than the old rules (so that previously
accepted barriers might now be rejected). For example, references to
non-component subcomponents such as "when Record_Component.Boolean_Field
=>" were previously accepted in most cases.

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

2020-06-08  Steve Baird  

gcc/ada/

* sem_ch13.ads: Export new function
All_Membership_Choices_Static.
* sem_ch13.adb: Implement new function
All_Membership_Choices_Static.  This involves moving the
functions Is_Static_Choice and All_Membership_Choices_Static,
which were previously declared within the function
Is_Predicate_Static, out to library level so that they can be
called by the new function. The already-exisiting code in
Is_Predicate_Static which became the body of
All_Membership_Choices_Static is replaced with a call to the new
function in order to avoid duplication.
* exp_ch9.adb (Is_Pure_Barrier): Several changes needed to
implement rules of AI12-0290 and RM D.7's definition of
"pure-barrier-eligible". These changes include adding a call to
the new function Sem_13.All_Membership_Choices_Static, as per
the "see 4.9" in RM D.7(1.6/5).--- gcc/ada/exp_ch9.adb
+++ gcc/ada/exp_ch9.adb
@@ -53,6 +53,7 @@ with Sem_Ch6;  use Sem_Ch6;
 with Sem_Ch8;  use Sem_Ch8;
 with Sem_Ch9;  use Sem_Ch9;
 with Sem_Ch11; use Sem_Ch11;
+with Sem_Ch13; use Sem_Ch13;
 with Sem_Elab; use Sem_Elab;
 with Sem_Eval; use Sem_Eval;
 with Sem_Prag; use Sem_Prag;
@@ -6236,28 +6237,37 @@ package body Exp_Ch9 is
 when N_Expanded_Name
| N_Identifier
 =>
+
+   --  Because of N_Expanded_Name case, return Skip instead of OK.
+
if No (Entity (N)) then
   return Abandon;
 
elsif Is_Universal_Numeric_Type (Entity (N)) then
-  return OK;
+  return Skip;
end if;
 
case Ekind (Entity (N)) is
   when E_Constant
  | E_Discriminant
- | E_Enumeration_Literal
+  =>
+ return Skip;
+
+  when E_Enumeration_Literal
  | E_Named_Integer
  | E_Named_Real
   =>
- return OK;
+ if not Is_OK_Static_Expression (N) then
+return Abandon;
+ end if;
+ return Skip;
 
   when E_Component =>
- return OK;
+ return Skip;
 
   when E_Variable =>
  if Is_Simple_Barrier_Name (N) then
-return OK;
+return Skip;
  end if;
 
   when E_Function =>
@@ -6268,7 +6278,7 @@ package body Exp_Ch9 is
  if Is_RTE (Entity (N), RE_Protected_Count)
or else Is_RTE (Entity (N), RE_Protected_Count_Entry)
  then
-return OK;
+return Skip;
  end if;
 
   when others =>
@@ -6295,14 +6305,31 @@ package body Exp_Ch9 is
   return OK;
end if;
 
-when N_Short_Circuit =>
+when N_Short_Circuit
+  | N_If_Expression
+  | N_Case_Expression
+=>
return OK;
 
-when N_Indexed_Component
-   | N_Selected_Component
-=>
-   if not Is_Access_Type (Etype (Prefix (N))) then
-  return OK;
+when N_Case_Expression_Alternative =>
+   --  do not traverse Discrete_Choices subtree
+   if Is_Pure_Barrier (Expression (N)) /= Abandon then
+  return Skip;
+   end if;
+
+when N_Expression_With_Actions =>
+   --  this may occur in the case of a Count attribute reference
+   if Original_Node (N) /= N
+ and then Is_Pure_Barrier (Original_Node (N)) /= Abandon
+   then
+  return Skip;
+   end if;
+
+when N_Membership_Test =>
+   if Is_Pure_Barrier (Left_Opnd (N)) /= Abandon
+ and then All_Membership_Choices_Static (N)
+   then
+  return Skip;
end if;
 
 when N_Type_Conversion =>

--- gcc/ada/sem_ch13.adb
+++ gcc/ada/sem_ch13.adb
@@ -91,6 +91,13 @@ package body Sem_Ch13 is
--  type whose inherited alignment is no longer appropriate for the new
--  size value. In this case, we reset the Alignment to 

[Ada] Implement AI12-0291 (Jorvik profile)

2020-06-08 Thread Pierre-Marie de Rodat
The Jorvik profile is a newly defined profile, similar to the Ravenscar
profile but less restrictive in some cases. It differs from the
Ravenscar profile only in the removal of six restrictions and the
relaxation of one (Ravenscar's Simple_Barriers restriction is replaced
with a Pure_Barriers restriction).

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

2020-06-08  Steve Baird  

gcc/ada/

* libgnat/s-rident.ads: Add Jorvik to the Profile_Name
enumeration type.  Add an element for Jorvik to the array
aggregate that is the initial value of the constant
Profile_Info.
* targparm.adb (Get_Target_Parameters): Handle "pragma Profile
(Jorvik);" similarly to "pragma Profile (Ravenscar);".
* snames.ads-tmpl: Declare Name_Jorvik Name_Id. Unlike
Ravenscar, Jorvik is not a pragma name and has no corresponding
element in the Pragma_Id enumeration type; this means that its
declaration must not occur between those of First_Pragma_Name
and Last_Pragma_Name.
* sem_prag.adb (Analyze_Pragma): Add call to
Set_Ravenscar_Profile for Jorvik, similar to the existing calls
for Ravenscar and the GNAT Ravenscar variants.--- gcc/ada/libgnat/s-rident.ads
+++ gcc/ada/libgnat/s-rident.ads
@@ -381,6 +381,7 @@ package System.Rident is
   Restricted_Tasking,
   Restricted,
   Ravenscar,
+  Jorvik,
   GNAT_Extended_Ravenscar,
   GNAT_Ravenscar_EDF);
--  Names of recognized profiles. No_Profile is used to indicate that a
@@ -545,6 +546,67 @@ package System.Rident is
Max_Task_Entries=> 0,
others  => 0)),
 
+ Jorvik  =>
+
+ --  Restrictions for Jorvik profile ..
+
+ --  Note: the table entries here only represent the
+ --  required restriction profile for Jorvik. The
+ --  full Jorvik profile also requires:
+
+ --pragma Dispatching_Policy (FIFO_Within_Priorities);
+ --pragma Locking_Policy (Ceiling_Locking);
+ --pragma Detect_Blocking;
+
+ --  The differences between Ravenscar and Jorvik are
+ --  as follows:
+ -- 1) Ravenscar includes restriction Simple_Barriers;
+ --Jorvik includes Pure_Barriers instead.
+ -- 2) The following 6 restrictions are included in
+ --Ravenscar but not in Jorvik:
+ --  No_Implicit_Heap_Allocations
+ --  No_Relative_Delay
+ --  Max_Entry_Queue_Length => 1
+ --  Max_Protected_Entries => 1
+ --  No_Dependence => Ada.Calendar
+ --  No_Dependence => Ada.Synchronous_Barriers
+ --
+ --  The last of those 7 (i.e., No_Dep => Ada.Synch_Bars)
+ --  is not reflected here (see sem_prag.adb).
+
+   (Set   =>
+  (No_Abort_Statements => True,
+   No_Asynchronous_Control => True,
+   No_Dynamic_Attachment   => True,
+   No_Dynamic_Priorities   => True,
+   No_Local_Protected_Objects  => True,
+   No_Protected_Type_Allocators=> True,
+   No_Requeue_Statements   => True,
+   No_Task_Allocators  => True,
+   No_Task_Attributes_Package  => True,
+   No_Task_Hierarchy   => True,
+   No_Terminate_Alternatives   => True,
+   Max_Asynchronous_Select_Nesting => True,
+   Max_Select_Alternatives => True,
+   Max_Task_Entries=> True,
+
+   --  plus these additional restrictions:
+
+   No_Local_Timing_Events   => True,
+   No_Select_Statements => True,
+   No_Specific_Termination_Handlers => True,
+   No_Task_Termination  => True,
+   Pure_Barriers=> True,
+   others   => False),
+
+--  Value settings for Ravenscar (same as Restricted)
+
+Value =>
+  (Max_Asynchronous_Select_Nesting => 0,
+   Max_Select_Alternatives => 0,
+   Max_Task_Entries  

[Ada] AI12-0085 Missing aspect cases for Remote_Types

2020-06-08 Thread Pierre-Marie de Rodat
This change adds a missing check on setting aspects Storage_Size and
Storage_Pool on remote access-to-class-wide types.

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

2020-06-08  Arnaud Charlet  

gcc/ada/

* sem_cat.ads: Fix typo.
* sem_cat.adb (Validate_Remote_Access_To_Class_Wide_Type): Add
handling of N_Attribute_Definition_Clause.
* sem_ch13.adb (Analyze_Attribute_Definition_Clause): Call
Validate_Remote_Access_To_Class_Wide_Type for Storage_Size and
Storage_Pool.
* sem_attr.adb, exp_ch4.adb: Update comments.--- gcc/ada/exp_ch4.adb
+++ gcc/ada/exp_ch4.adb
@@ -4489,7 +4489,7 @@ package body Exp_Ch4 is
  Error_Msg_N ("?use of an anonymous access type allocator", N);
   end if;
 
-  --  RM E.2.3(22). We enforce that the expected type of an allocator
+  --  RM E.2.2(17). We enforce that the expected type of an allocator
   --  shall not be a remote access-to-class-wide-limited-private type
 
   --  Why is this being done at expansion time, seems clearly wrong ???

--- gcc/ada/sem_attr.adb
+++ gcc/ada/sem_attr.adb
@@ -6004,7 +6004,7 @@ package body Sem_Attr is
 
 --  Validate_Remote_Access_To_Class_Wide_Type for attribute
 --  Storage_Pool since this attribute is not defined for such
---  types (RM E.2.3(22)).
+--  types (RM E.2.2(17)).
 
 Validate_Remote_Access_To_Class_Wide_Type (N);
 
@@ -6038,9 +6038,9 @@ package body Sem_Attr is
Check_Type;
Set_Etype (N, Universal_Integer);
 
-   --   Validate_Remote_Access_To_Class_Wide_Type for attribute
-   --   Storage_Size since this attribute is not defined for
-   --   such types (RM E.2.3(22)).
+   --  Validate_Remote_Access_To_Class_Wide_Type for attribute
+   --  Storage_Size since this attribute is not defined for
+   --  such types (RM E.2.2(17)).
 
Validate_Remote_Access_To_Class_Wide_Type (N);
 

--- gcc/ada/sem_cat.adb
+++ gcc/ada/sem_cat.adb
@@ -1815,7 +1815,17 @@ package body Sem_Cat is
 
   --4. called from sem_res Resolve_Actuals
 
-  if K = N_Attribute_Reference then
+  if K = N_Attribute_Definition_Clause then
+ E := Etype (Entity (N));
+
+ if Is_Remote_Access_To_Class_Wide_Type (E) then
+Error_Msg_Name_1 := Chars (N);
+Error_Msg_N
+  ("cannot specify% aspect for a remote operand", N);
+return;
+ end if;
+
+  elsif K = N_Attribute_Reference then
  E := Etype (Prefix (N));
 
  if Is_Remote_Access_To_Class_Wide_Type (E) then

--- gcc/ada/sem_cat.ads
+++ gcc/ada/sem_cat.ads
@@ -120,8 +120,8 @@ package Sem_Cat is
--  Checks that Storage_Pool and Storage_Size attribute references are
--  not applied to remote access-to-class-wide types. Also checks that the
--  expected type for an allocator cannot be a remote access-to-class-wide
-   --  type. ALso checks that a remote access-to-class-wide type cannot be an
-   --  actual parameter for a generic formal access type. RM E.2.3(22).
+   --  type. Also checks that a remote access-to-class-wide type cannot be an
+   --  actual parameter for a generic formal access type. RM E.2.2(17).
 
procedure Validate_RT_RAT_Component (N : Node_Id);
--  Given N, the package library unit declaration node, we should check

--- gcc/ada/sem_ch13.adb
+++ gcc/ada/sem_ch13.adb
@@ -48,6 +48,7 @@ with Rtsfind;  use Rtsfind;
 with Sem;  use Sem;
 with Sem_Aux;  use Sem_Aux;
 with Sem_Case; use Sem_Case;
+with Sem_Cat;  use Sem_Cat;
 with Sem_Ch3;  use Sem_Ch3;
 with Sem_Ch6;  use Sem_Ch6;
 with Sem_Ch7;  use Sem_Ch7;
@@ -6415,6 +6416,12 @@ package body Sem_Ch13 is
return;
 end if;
 
+--  Validate_Remote_Access_To_Class_Wide_Type for attribute
+--  Storage_Pool since this attribute cannot be defined for such
+--  types (RM E.2.2(17)).
+
+Validate_Remote_Access_To_Class_Wide_Type (N);
+
 --  If the argument is a name that is not an entity name, then
 --  we construct a renaming operation to define an entity of
 --  type storage pool.
@@ -6524,6 +6531,12 @@ package body Sem_Ch13 is
null;
 
 else
+   --  Validate_Remote_Access_To_Class_Wide_Type for attribute
+   --  Storage_Size since this attribute cannot be defined for such
+   --  types (RM E.2.2(17)).
+
+   Validate_Remote_Access_To_Class_Wide_Type (N);
+
Analyze_And_Resolve (Expr, Any_Integer);
 
if Is_Access_Type (U_Ent) then



[Ada] Fix handling of 'Enum_Rep and renamings

2020-06-08 Thread Pierre-Marie de Rodat
Most cases were actually handled fine thanks to some special handling in
exp_attr.adb, but cases of e.g. a renaming of renaming were not handled
properly. Taking this opportunity to simplify the code and remove
special cases by actually adding support for 'Enum_Rep directly in
Eval_Type_Conversion.

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

2020-06-08  Arnaud Charlet  

gcc/ada/

* sem_eval.adb (Eval_Type_Conversion): Fix handling of
enumeration to integer conversions.
* exp_attr.adb (Expand_N_Attribute_Reference
[Attribute_Enum_Rep]): Remove special casing for first-level
renaming, best left to the general folding mechanism via
Eval_Type_Conversion.--- gcc/ada/exp_attr.adb
+++ gcc/ada/exp_attr.adb
@@ -3168,21 +3168,6 @@ package body Exp_Attr is
 Rewrite (N,
   Make_Integer_Literal (Loc, Enumeration_Rep (Entity (Expr;
 
- --  If this is a renaming of a literal, recover the representation
- --  of the original. If it renames an expression there is nothing to
- --  fold.
-
- elsif Nkind (Expr) in N_Has_Entity
-   and then Ekind (Entity (Expr)) = E_Constant
-   and then Present (Renamed_Object (Entity (Expr)))
-   and then Is_Entity_Name (Renamed_Object (Entity (Expr)))
-   and then Ekind (Entity (Renamed_Object (Entity (Expr =
-  E_Enumeration_Literal
- then
-Rewrite (N,
-  Make_Integer_Literal (Loc,
-Enumeration_Rep (Entity (Renamed_Object (Entity (Expr));
-
  --  If not constant-folded above, Enum_Type'Enum_Rep (X) or
  --  X'Enum_Rep expands to
 

--- gcc/ada/sem_eval.adb
+++ gcc/ada/sem_eval.adb
@@ -4031,8 +4031,13 @@ package body Sem_Eval is
 
 --  Real to integer conversion
 
-else
+elsif To_Be_Treated_As_Real (Source_Type) then
Result := UR_To_Uint (Expr_Value_R (Operand));
+
+--  Enumeration to integer conversion, aka 'Enum_Rep
+
+else
+   Result := Expr_Rep_Value (Operand);
 end if;
 
 --  If fixed-point type (Conversion_OK must be set), then the
@@ -4076,7 +4081,6 @@ package body Sem_Eval is
   if Is_Out_Of_Range (N, Etype (N), Assume_Valid => True) then
  Out_Of_Range (N);
   end if;
-
end Eval_Type_Conversion;
 
---



[Ada] Restore Snames.Name_SPARK as it used in the GNATprove backend

2020-06-08 Thread Pierre-Marie de Rodat
The Name_SPARK constant is no longer used in GNAT to implement the
SPARK_05 restriction, but is still used in GNATprove to detect whether
the SPARK.Heap unit has been explicitly WITH-ed.

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

2020-06-08  Piotr Trojanek  

gcc/ada/

* snames.ads-tmpl (Name_SPARK): Restore after being deleted.--- gcc/ada/snames.ads-tmpl
+++ gcc/ada/snames.ads-tmpl
@@ -835,6 +835,7 @@ package Snames is
Name_Section: constant Name_Id := N + $;
Name_Semaphore  : constant Name_Id := N + $;
Name_Simple_Barriers: constant Name_Id := N + $;
+   Name_SPARK  : constant Name_Id := N + $;
Name_SPARK_05   : constant Name_Id := N + $;
Name_Spec_File_Name : constant Name_Id := N + $;
Name_State  : constant Name_Id := N + $;



[Ada] Spurious error on call to controlled primitive

2020-06-08 Thread Pierre-Marie de Rodat
This patch corrects an issue whereby calls to controlled primitives for
types which extend generic formals may be flagged at compile-time as
being non-visible.

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

2020-06-08  Justin Squirek  

gcc/ada/

* sem_ch4.adb (Analyze_One_Call): Add extra condition to the
predicate for deciding when a given controlled call is visible.--- gcc/ada/sem_ch4.adb
+++ gcc/ada/sem_ch4.adb
@@ -3697,15 +3697,15 @@ package body Sem_Ch4 is
 
  --  To avoid breaking privacy, Is_Hidden gets set elsewhere on such
  --  primitives, but we still need to verify that Nam is indeed a
- --  controlled subprogram. So, we do that here and issue the
- --  appropriate error.
+ --  non-visible controlled subprogram. So, we do that here and issue
+ --  the appropriate error.
 
  if Is_Hidden (Nam)
and then not In_Instance
and then not Comes_From_Source (Nam)
and then Comes_From_Source (N)
 
-   --  Verify Nam is a controlled primitive
+   --  Verify Nam is a non-visible controlled primitive
 
and then Nam_In (Chars (Nam), Name_Adjust,
  Name_Finalize,
@@ -3713,6 +3713,7 @@ package body Sem_Ch4 is
and then Ekind (Nam) = E_Procedure
and then Is_Controlled (Etype (First_Form))
and then No (Next_Formal (First_Form))
+   and then not Is_Visibly_Controlled (Etype (First_Form))
  then
 Error_Msg_Node_2 := Etype (First_Form);
 Error_Msg_NE ("call to non-visible controlled primitive & on type"



[Ada] Silence spurious warning on instances of formal vectors

2020-06-08 Thread Pierre-Marie de Rodat
Use pragma Warnings to silence a spurious warning that may occur in
instances of formal vectors.

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

2020-06-08  Claire Dross  

gcc/ada/

* libgnat/a-cofove.adb (Insert_Space): The computation of Index
generates a spurious compiler warning about a value not being in
range for a statically dead branch.  Silence it using pragma
Warnings.--- gcc/ada/libgnat/a-cofove.adb
+++ gcc/ada/libgnat/a-cofove.adb
@@ -868,7 +868,11 @@ is
 --  less than 0, so it is safe to compute the following sum without
 --  fear of overflow.
 
+pragma Warnings
+  (Off, "value not in range of type ""T"" defined at line 4");
 Index := No_Index + Index_Type'Base (Count_Type'Last);
+pragma Warnings
+  (On, "value not in range of type ""T"" defined at line 4");
 
 if Index <= Index_Type'Last then
 



[Ada] Implement predicate checks on qualified expressions (AI12-0100)

2020-06-08 Thread Pierre-Marie de Rodat
Predicate checks are required by AI12-0100 when evaluating qualified
expressions where the qualifying subtype has such checks. Errors rather
than warnings must be issued on static qualified expressions and type
conversions that violate a static predicate, so that's corrected here.
There were also cases where warnings were issued on statically
detectible violations but then checks were not generated, and that is
addressed by these changes as well.

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

2020-06-08  Gary Dismukes  

gcc/ada/

* checks.adb (Apply_Predicate_Check): Refine test for being in a
subprogram body to account for no Corresponding_Body case,
avoiding blowups arising due to other changes here.
* exp_ch4.adb (Expand_N_Qualified_Expression): Apply predicate
checks, if any, after constraint checks are applied.
* sem_eval.ads (Check_Expression_Against_Static_Predicate): Add
Check_Failure_Is_Error formal for conditionalizing warning vs.
error messages.
* sem_eval.adb (Check_Expression_Against_Static_Predicate):
Issue an error message rather than a warning when the new
Check_Failure_Is_Error formal is True. In the nonstatic or
Dynamic_Predicate case where the predicate is known to fail,
emit the check to ensure that folded cases get checks applied.
* sem_res.adb (Resolve_Qualified_Expression): Call
Check_Expression_Against_Static_Predicate, passing True for
Check_Failure_Is_Error, to ensure we reject static predicate
violations. Remove code that was conditionally calling
Apply_Predicate_Check, which is no longer needed, and that check
procedure shouldn't be called from a resolution routine in any
case. Also remove associated comment about preventing infinite
recursion and consistency with Resolve_Type_Conversion, since
that handling was already similarly removed from
Resolve_Type_Convesion at some point.
(Resolve_Type_Conversion): Add passing of True for
Check_Failure_Is_Error parameter on call to
Check_Expression_Against_Static_Predicate, to ensure that static
conversion cases that violate a predicate are rejected as
errors.--- gcc/ada/checks.adb
+++ gcc/ada/checks.adb
@@ -2789,7 +2789,13 @@ package body Checks is
begin
   while Present (P) loop
  if Nkind (P) = N_Subprogram_Body
-   and then Corresponding_Spec (P) = Scope (Entity (N))
+   and then
+ ((Present (Corresponding_Spec (P))
+and then
+  Corresponding_Spec (P) = Scope (Entity (N)))
+or else
+  Defining_Unit_Name (Specification (P)) =
+Scope (Entity (N)))
  then
 In_Body := True;
 exit;

--- gcc/ada/exp_ch4.adb
+++ gcc/ada/exp_ch4.adb
@@ -10424,6 +10424,10 @@ package body Exp_Ch4 is
 
   Apply_Constraint_Check (Operand, Target_Type, No_Sliding => True);
 
+  --  Apply possible predicate check
+
+  Apply_Predicate_Check (Operand, Target_Type);
+
   if Do_Range_Check (Operand) then
  Generate_Range_Check (Operand, Target_Type, CE_Range_Check_Failed);
   end if;

--- gcc/ada/sem_eval.adb
+++ gcc/ada/sem_eval.adb
@@ -324,8 +324,9 @@ package body Sem_Eval is
---
 
procedure Check_Expression_Against_Static_Predicate
- (Expr : Node_Id;
-  Typ  : Entity_Id)
+ (Expr: Node_Id;
+  Typ : Entity_Id;
+  Static_Failure_Is_Error : Boolean := False)
is
begin
   --  Nothing to do if expression is not known at compile time, or the
@@ -383,18 +384,28 @@ package body Sem_Eval is
   --  Here we know that the predicate will fail
 
   --  Special case of static expression failing a predicate (other than one
-  --  that was explicitly specified with a Dynamic_Predicate aspect). This
-  --  is the case where the expression is no longer considered static.
+  --  that was explicitly specified with a Dynamic_Predicate aspect). If
+  --  the expression comes from a qualified_expression or type_conversion
+  --  this is an error (Static_Failure_Is_Error); otherwise we only issue
+  --  a warning and the expression is no longer considered static.
 
   if Is_Static_Expression (Expr)
 and then not Has_Dynamic_Predicate_Aspect (Typ)
   then
- Error_Msg_NE
-   ("??static expression fails static predicate check on &",
-Expr, Typ);
- Error_Msg_N
-   ("\??expression is no longer considered static", Expr);
- Set_Is_Static_Expression (Expr, False);
+ if Static_Failure_Is_Error 

[Ada] Do not warn on partial access to atomic object with address clause

2020-06-08 Thread Pierre-Marie de Rodat
This disables the warning given in the specific case of an atomic
composite object subject to an address clause accessed partially,
when the code is compiled in Ada 2020 mode, on the grounds that
the semantics of these accesses to components of atomic composite
objects is perfectly defined in Ada 2020.

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

2020-06-08  Eric Botcazou  

gcc/ada/

* sem_res.adb (Resolve_Indexed_Component): Do not give a warning
for a nonatomic component of an atomic array which is subject to
an address clause in Ada 2020 mode.
(Resolve_Selected_Component): Likewise for an atomic record.--- gcc/ada/sem_res.adb
+++ gcc/ada/sem_res.adb
@@ -9034,10 +9034,10 @@ package body Sem_Res is
  Eval_Indexed_Component (N);
   end if;
 
-  --  If the array type is atomic, and the component is not atomic, then
-  --  this is worth a warning, since we have a situation where the access
-  --  to the component may cause extra read/writes of the atomic array
-  --  object, or partial word accesses, which could be unexpected.
+  --  If the array type is atomic and the component is not, then this is
+  --  worth a warning before Ada 2020, since we have a situation where the
+  --  access to the component may cause extra read/writes of the atomic
+  --  object, or partial word accesses, both of which may be unexpected.
 
   if Nkind (N) = N_Indexed_Component
 and then Is_Atomic_Ref_With_Address (N)
@@ -9046,6 +9046,7 @@ package body Sem_Res is
  and then Has_Atomic_Components
 (Entity (Prefix (N)
 and then not Is_Atomic (Component_Type (Array_Type))
+and then Ada_Version < Ada_2020
   then
  Error_Msg_N
("??access to non-atomic component of atomic array", Prefix (N));
@@ -10727,15 +10728,16 @@ package body Sem_Res is
   --  Note: No Eval processing is required, because the prefix is of a
   --  record type, or protected type, and neither can possibly be static.
 
-  --  If the record type is atomic, and the component is non-atomic, then
-  --  this is worth a warning, since we have a situation where the access
-  --  to the component may cause extra read/writes of the atomic array
+  --  If the record type is atomic and the component is not, then this is
+  --  worth a warning before Ada 2020, since we have a situation where the
+  --  access to the component may cause extra read/writes of the atomic
   --  object, or partial word accesses, both of which may be unexpected.
 
   if Nkind (N) = N_Selected_Component
 and then Is_Atomic_Ref_With_Address (N)
 and then not Is_Atomic (Entity (S))
 and then not Is_Atomic (Etype (Entity (S)))
+and then Ada_Version < Ada_2020
   then
  Error_Msg_N
("??access to non-atomic component of atomic record",



[Ada] Issue with unnesting of 'First/Last and renaming

2020-06-08 Thread Pierre-Marie de Rodat
If we're doing 'First or 'Last on a renamed variable, the backend may
look at either the Etype of the variable or that of what it was
renaming, so check both to see if we need to place it into the
activation record.

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

2020-06-08  Richard Kenner  

gcc/ada/

* exp_unst.adb (Visit_Node): When visiting array attribute
nodes, in addition to checking the type of Get_Referenced_Object
of the prefix, also check the actual type of the prefix.--- gcc/ada/exp_unst.adb
+++ gcc/ada/exp_unst.adb
@@ -1049,22 +1049,27 @@ package body Exp_Unst is
--  from the (possibly) uplevel reference. We call
--  Get_Referenced_Object to deal with prefixes that
--  are object renamings (prefixes that are types
-   --  can be passed and will simply be returned).
+   --  can be passed and will simply be returned).  But
+   --  it's also legal to get the bounds from the type
+   --  of the prefix, so we have to handle both cases.
 
-   if Is_Constrained
+   declare
+  DT : Boolean := False;
+
+   begin
+  if Is_Constrained
 (Etype (Get_Referenced_Object (Prefix (N
-   then
-  declare
- DT : Boolean := False;
-  begin
+  then
  Check_Static_Type
(Etype (Get_Referenced_Object (Prefix (N))),
-Empty,
-DT);
-  end;
+Empty, DT);
+  end if;
 
-  return OK;
-   end if;
+  if Is_Constrained (Etype (Prefix (N))) then
+ Check_Static_Type
+   (Etype (Prefix (N)), Empty, DT);
+  end if;
+   end;
 
 when others =>
null;



[Ada] Better code generation for nested aggregates

2020-06-08 Thread Pierre-Marie de Rodat
For aggregate components that are aggregates the frontend has been
enhanced to evaluate if the inner aggregate depends on the variable
being assigned to. This enhancement allows the compiler to avoid the
generation of a temporary and thus generate better code for large nested
aggregates.

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

2020-06-08  Javier Miranda  

gcc/ada/

* exp_aggr.adb (Safe_Component): Remove code that considers as
unsafe components that are aggregates; such removal allows the
frontend to proceed and evaluate if they are safe by means of
invoking Safe_Aggregate.--- gcc/ada/exp_aggr.adb
+++ gcc/ada/exp_aggr.adb
@@ -4283,11 +4283,6 @@ package body Exp_Aggr is
 if Is_Overloaded (Expr) then
return False;
 
-elsif Nkind (Expr) = N_Aggregate
-   and then not Is_Others_Aggregate (Expr)
-then
-   return False;
-
 elsif Nkind (Expr) = N_Allocator then
 
--  For now, too complex to analyze



[Ada] Reuse Get_Index_Subtype in the special expander for GNATprove

2020-06-08 Thread Pierre-Marie de Rodat
In the special expander that is only applied in GNATprove mode we had a
code that duplicated Get_Index_Subtype routine from the standard
expander. Now this routine is properly reused. Behaviour of both GNAT
and GNATprove remains unchanged.

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

2020-06-08  Piotr Trojanek  

gcc/ada/

* exp_attr.adb, exp_util.ads, exp_util.adb (Get_Index_Subtype):
Move from the body of Exp_Attr to Exp_Util and expose from the
spec.
* exp_spark.adb (Expand_SPARK_N_Attribute_Reference): Replace
duplicated code with a call to Get_Index_Subtype.--- gcc/ada/exp_attr.adb
+++ gcc/ada/exp_attr.adb
@@ -192,10 +192,6 @@ package body Exp_Attr is
procedure Expand_Update_Attribute (N : Node_Id);
--  Handle the expansion of attribute Update
 
-   function Get_Index_Subtype (N : Node_Id) return Entity_Id;
-   --  Used for Last, Last, and Length, when the prefix is an array type.
-   --  Obtains the corresponding index subtype.
-
procedure Find_Fat_Info
  (T: Entity_Id;
   Fat_Type : out Entity_Id;
@@ -8518,35 +8514,6 @@ package body Exp_Attr is
   return BT;
end Full_Base;
 
-   ---
-   -- Get_Index_Subtype --
-   ---
-
-   function Get_Index_Subtype (N : Node_Id) return Node_Id is
-  P_Type : Entity_Id := Etype (Prefix (N));
-  Indx   : Node_Id;
-  J  : Int;
-
-   begin
-  if Is_Access_Type (P_Type) then
- P_Type := Designated_Type (P_Type);
-  end if;
-
-  if No (Expressions (N)) then
- J := 1;
-  else
- J := UI_To_Int (Expr_Value (First (Expressions (N;
-  end if;
-
-  Indx := First_Index (P_Type);
-  while J > 1 loop
- Next_Index (Indx);
- J := J - 1;
-  end loop;
-
-  return Etype (Indx);
-   end Get_Index_Subtype;
-
---
-- Get_Stream_Convert_Pragma --
---

--- gcc/ada/exp_spark.adb
+++ gcc/ada/exp_spark.adb
@@ -36,7 +36,6 @@ with Nlists;   use Nlists;
 with Nmake;use Nmake;
 with Rtsfind;  use Rtsfind;
 with Sem;  use Sem;
-with Sem_Eval; use Sem_Eval;
 with Sem_Prag; use Sem_Prag;
 with Sem_Res;  use Sem_Res;
 with Sem_Util; use Sem_Util;
@@ -262,37 +261,16 @@ package body Exp_SPARK is
  --  and 'Range_Length when the type is as big as Long_Long_Integer.
 
  declare
-Typ : Entity_Id := Empty;
+Typ : Entity_Id;
  begin
 if Attr_Id = Attribute_Range_Length then
Typ := Etype (Prefix (N));
 
 elsif Attr_Id = Attribute_Length then
-   Typ := Etype (Prefix (N));
+   Typ := Get_Index_Subtype (N);
 
-   declare
-  Indx : Node_Id;
-  J: Int;
-
-   begin
-  if Is_Access_Type (Typ) then
- Typ := Designated_Type (Typ);
-  end if;
-
-  if No (Expressions (N)) then
- J := 1;
-  else
- J := UI_To_Int (Expr_Value (First (Expressions (N;
-  end if;
-
-  Indx := First_Index (Typ);
-  while J > 1 loop
- Next_Index (Indx);
- J := J - 1;
-  end loop;
-
-  Typ := Etype (Indx);
-   end;
+else
+   Typ := Empty;
 end if;
 
 Apply_Universal_Integer_Attribute_Checks (N);

--- gcc/ada/exp_util.adb
+++ gcc/ada/exp_util.adb
@@ -6575,6 +6575,35 @@ package body Exp_Util is
   end;
end Get_Current_Value_Condition;
 
+   ---
+   -- Get_Index_Subtype --
+   ---
+
+   function Get_Index_Subtype (N : Node_Id) return Node_Id is
+  P_Type : Entity_Id := Etype (Prefix (N));
+  Indx   : Node_Id;
+  J  : Int;
+
+   begin
+  if Is_Access_Type (P_Type) then
+ P_Type := Designated_Type (P_Type);
+  end if;
+
+  if No (Expressions (N)) then
+ J := 1;
+  else
+ J := UI_To_Int (Expr_Value (First (Expressions (N;
+  end if;
+
+  Indx := First_Index (P_Type);
+  while J > 1 loop
+ Next_Index (Indx);
+ J := J - 1;
+  end loop;
+
+  return Etype (Indx);
+   end Get_Index_Subtype;
+
-
-- Get_Stream_Size --
-

--- gcc/ada/exp_util.ads
+++ gcc/ada/exp_util.ads
@@ -724,6 +724,10 @@ package Exp_Util is
--  N_Op_Eq), or to determine the result of some other test in other cases
--  (e.g. no access check required if N_Op_Ne Null).
 
+   function Get_Index_Subtype (N : Node_Id) return Entity_Id;
+   --  Used for Last, Last, and Length, when the prefix is an array type.
+   --  Obtains the corresponding index subtype.
+
function Get_Stream_Size (E : Entity_Id) return Uint;
--  Return 

[Ada] Reuse standard expansion of 'First and 'Last in GNATprove mode

2020-06-08 Thread Pierre-Marie de Rodat
Expansion of attribute Enum_Rep applied to First and Last attributes,
both in the standard compilation mode and in the GNATprove mode, relies
on those First and Last attributes being already expanded. However, they
were only expanded in the standard compilation mode; now they are also
expanded in the GNATprove mode.

This change only affects GNATprove; GNAT and other backends are not
affected.

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

2020-06-08  Piotr Trojanek  

gcc/ada/

* exp_spark.adb (Expand_SPARK_N_Attribute_Reference): Apply
standard expansion to attributes First and Last.--- gcc/ada/exp_spark.adb
+++ gcc/ada/exp_spark.adb
@@ -295,6 +295,13 @@ package body Exp_SPARK is
  Make_Explicit_Dereference (Loc, Relocate_Node (Pref)));
 Analyze_And_Resolve (N, Standard_Boolean);
  end if;
+
+  --  For attributes First and Last simply reuse the standard expansion
+
+  elsif Attr_Id = Attribute_First
+or else Attr_Id = Attribute_Last
+  then
+ Exp_Attr.Expand_N_Attribute_Reference (N);
   end if;
end Expand_SPARK_N_Attribute_Reference;
 



[Ada] Ada_2020: shared variable control aspects on formal derived types

2020-06-08 Thread Pierre-Marie de Rodat
This completes the implementation of AI12-0282, which allows variable
control aspects to apply to formal types. This patch extends the
implementation to handle properly formal derived types.

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

2020-06-08  Ed Schonberg  

gcc/ada/

* par-ch12.adb (P_Formal_Derived_Type_Definition): Handle
properly formal derived types that include aspect
specifications, so that the "with" keyword appears twice in the
formal type declaration.
* sem_ch13.adb (Has_Generic_Parent): Return true if the type
itself is a generic formal.--- gcc/ada/par-ch12.adb
+++ gcc/ada/par-ch12.adb
@@ -972,8 +972,14 @@ package body Ch12 is
 
   if Token = Tok_With then
 
- if Ada_Version >= Ada_2020 and Token /= Tok_Private then
+ if Ada_Version >= Ada_2020 and not Next_Token_Is (Tok_Private) then
+
 --  Formal type has aspect specifications, parsed later.
+--  Otherwise this is a formal derived type. Note that it may
+--  also include later aspect specifications, as in:
+
+--type DT is new T with private with atomic;
+
 return Def_Node;
 
  else

--- gcc/ada/sem_ch13.adb
+++ gcc/ada/sem_ch13.adb
@@ -13027,7 +13027,7 @@ package body Sem_Ch13 is
 
function Rep_Item_Too_Early (T : Entity_Id; N : Node_Id) return Boolean is
   function Has_Generic_Parent (E : Entity_Id) return Boolean;
-  --  Return True if any ancestor is a generic type
+  --  Return True if R or any ancestor is a generic type
 
   
   -- Has_Generic_Parent --
@@ -13037,6 +13037,10 @@ package body Sem_Ch13 is
  Ancestor_Type : Entity_Id := Etype (E);
 
   begin
+ if Is_Generic_Type (E) then
+return True;
+ end if;
+
  while Present (Ancestor_Type)
and then not Is_Generic_Type (Ancestor_Type)
and then Etype (Ancestor_Type) /= Ancestor_Type



[Ada] AI12-0309 Missing checks for pragma Suppress

2020-06-08 Thread Pierre-Marie de Rodat
Recognize (no-ops for now) new check names Program_Error_Check,
Tasking_Check.

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

2020-06-08  Arnaud Charlet  

gcc/ada/

* snames.ads-tmpl (Name_Program_Error_Check,
Name_Tasking_Check): New constants.
* types.ads (Program_Error_Check, Tasking_Check): New constants.
(All_Checks): Update accordingly.--- gcc/ada/snames.ads-tmpl
+++ gcc/ada/snames.ads-tmpl
@@ -1199,6 +1199,8 @@ package Snames is
Name_Validity_Check : constant Name_Id := N + $; -- GNAT
Name_Container_Checks   : constant Name_Id := N + $; -- GNAT
Name_Tampering_Check: constant Name_Id := N + $; -- GNAT
+   Name_Program_Error_Check: constant Name_Id := N + $;
+   Name_Tasking_Check  : constant Name_Id := N + $;
Name_All_Checks : constant Name_Id := N + $;
Last_Check_Name : constant Name_Id := N + $;
 

--- gcc/ada/types.ads
+++ gcc/ada/types.ads
@@ -687,11 +687,13 @@ package Types is
Validity_Check : constant := 17;
Container_Checks   : constant := 18;
Tampering_Check: constant := 19;
+   Program_Error_Check: constant := 20;
+   Tasking_Check  : constant := 21;
--  Values used to represent individual predefined checks (including the
--  setting of Atomic_Synchronization, which is implemented internally using
--  a "check" whose name is Atomic_Synchronization).
 
-   All_Checks : constant := 20;
+   All_Checks : constant := 22;
--  Value used to represent All_Checks value
 
subtype Predefined_Check_Id is Check_Id range 1 .. All_Checks;



[Ada] Add Depends contracts to Delete procedures of formal containers

2020-06-08 Thread Pierre-Marie de Rodat
Add a Depends contract to Delete procedures of formal containers to
state that the output value of the Position cursor depends on no inputs
(it is No_Element). This now ensures that no warnings will be emitted
by GNATprove if this value is not used after a call to Delete.

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

2020-06-08  Claire Dross  

gcc/ada/

* libgnat/a-cfdlli.ads, libgnat/a-cfhama.ads,
libgnat/a-cfhase.ads, libgnat/a-cforma.ads, libgnat/a-cforse.ads
(Delete): Add Depends contract.--- gcc/ada/libgnat/a-cfdlli.ads
+++ gcc/ada/libgnat/a-cfdlli.ads
@@ -789,9 +789,10 @@ is
 Count => Count);
 
procedure Delete (Container : in out List; Position : in out Cursor) with
- Global => null,
- Pre=> Has_Element (Container, Position),
- Post   =>
+ Global  => null,
+ Depends => (Container =>+ Position, Position => null),
+ Pre => Has_Element (Container, Position),
+ Post=>
Length (Container) = Length (Container)'Old - 1
 
  --  Position is set to No_Element

--- gcc/ada/libgnat/a-cfhama.ads
+++ gcc/ada/libgnat/a-cfhama.ads
@@ -669,9 +669,10 @@ is
 Find (Container, Key)'Old);
 
procedure Delete (Container : in out Map; Position : in out Cursor) with
- Global => null,
- Pre=> Has_Element (Container, Position),
- Post   =>
+ Global  => null,
+ Depends => (Container =>+ Position, Position => null),
+ Pre => Has_Element (Container, Position),
+ Post=>
Position = No_Element
  and Length (Container) = Length (Container)'Old - 1
 

--- gcc/ada/libgnat/a-cfhase.ads
+++ gcc/ada/libgnat/a-cfhase.ads
@@ -801,9 +801,10 @@ is
--  already in the set.)
 
procedure Delete (Container : in out Set; Position : in out Cursor) with
- Global => null,
- Pre=> Has_Element (Container, Position),
- Post   =>
+ Global  => null,
+ Depends => (Container =>+ Position, Position => null),
+ Pre => Has_Element (Container, Position),
+ Post=>
Position = No_Element
  and Length (Container) = Length (Container)'Old - 1
 

--- gcc/ada/libgnat/a-cforma.ads
+++ gcc/ada/libgnat/a-cforma.ads
@@ -733,9 +733,10 @@ is
 Cut   => Find (Keys (Container), Key)'Old);
 
procedure Delete (Container : in out Map; Position : in out Cursor) with
- Global => null,
- Pre=> Has_Element (Container, Position),
- Post   =>
+ Global  => null,
+ Depends => (Container =>+ Position, Position => null),
+ Pre => Has_Element (Container, Position),
+ Post=>
Position = No_Element
  and Length (Container) = Length (Container)'Old - 1
 

--- gcc/ada/libgnat/a-cforse.ads
+++ gcc/ada/libgnat/a-cforse.ads
@@ -858,9 +858,10 @@ is
  (Container : in out Set;
   Position  : in out Cursor)
with
- Global => null,
- Pre=> Has_Element (Container, Position),
- Post   =>
+ Global  => null,
+ Depends => (Container =>+ Position, Position => null),
+ Pre => Has_Element (Container, Position),
+ Post=>
Position = No_Element
  and Length (Container) = Length (Container)'Old - 1
 



[Ada] gnatbind: Deterministic No_Entry_Calls_In_Elaboration_Code messages

2020-06-08 Thread Pierre-Marie de Rodat
This patch fixes a bug in which the messages produced by
gnatbind could be nondeterministic. In particular, the message:

info:  use pragma Restrictions (No_Entry_Calls_In_Elaboration_Code)

could be missing, depending on details that should be irrelevant.

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

2020-06-08  Bob Duff  

gcc/ada/

* bindo-graphs.adb (function Add_Edge): Rename
Add_Edge_With_Return to Add_Edge; we can tell it returns because
it's a function, and overloading seems appropriate in this case.
If Activates_Task=True, and we're not going to add a new edge
because an existing Pred-->Succ edge already exists, then set
Activates_Task to True on the preexisting edge.  This ensures
that the message:

info: use pragma Restrictions (No_Entry_Calls_In_Elaboration_Code)

appears when appropriate, no matter in what order the edges
happened to be processed.
(procedure Add_Edge): Remove redundant assertions.
(Activates_Task): Other kinds of edges can have
Activates_Task=True.  For example, if we had a With_Edge and
then an Invocation_Edge with Activates_Task=True, then the
With_Edge has Activates_Task set to True.
(Add_Edge_Kind_Check): New procedure to prevent other bugs of
this nature. For example, if we were to sometimes call Add_Edge
for a Spec_Before_Body_Edge followed by Add_Edge for a
With_Edge, and sometimes in the other order, that would cause a
similar bug to what we're fixing here.
(Set_Is_Recorded_Edge): Val parameter is not used. Get rid of
it.
(Set_Activates_Task): New procedure to set the Activates_Task flag.
* bindo-graphs.ads (Library_Graph_Edge_Kind): Reorder the
enumeration literals to facilitate Add_Edge_Kind_Check.
* ali.adb (Known_ALI_Lines): The comment about "still available"
was wrong. Fix that by erasing the comment, and encoding the
relevant information in real code. Take advantage of Ada's full
coverage rules by removing "others =>".  Also DRY.--- gcc/ada/ali.adb
+++ gcc/ada/ali.adb
@@ -242,31 +242,33 @@ package body ALI is
 
--  The following variable records which characters currently are used as
--  line type markers in the ALI file. This is used in Scan_ALI to detect
-   --  (or skip) invalid lines. The following letters are still available:
-   --
-   --B F H J K O Q Z
+   --  (or skip) invalid lines.
 
Known_ALI_Lines : constant array (Character range 'A' .. 'Z') of Boolean :=
- ('A'=> True,  --  argument
-  'C'=> True,  --  SCO information
-  'D'=> True,  --  dependency
-  'E'=> True,  --  external
-  'G'=> True,  --  invocation graph
-  'I'=> True,  --  interrupt
-  'L'=> True,  --  linker option
-  'M'=> True,  --  main program
-  'N'=> True,  --  notes
-  'P'=> True,  --  program
-  'R'=> True,  --  restriction
-  'S'=> True,  --  specific dispatching
-  'T'=> True,  --  task stack information
-  'U'=> True,  --  unit
-  'V'=> True,  --  version
-  'W'=> True,  --  with
-  'X'=> True,  --  xref
-  'Y'=> True,  --  limited_with
-  'Z'=> True,  --  implicit with from instantiation
-  others => False);
+ ('A' | --  argument
+  'C' | --  SCO information
+  'D' | --  dependency
+  'E' | --  external
+  'G' | --  invocation graph
+  'I' | --  interrupt
+  'L' | --  linker option
+  'M' | --  main program
+  'N' | --  notes
+  'P' | --  program
+  'R' | --  restriction
+  'S' | --  specific dispatching
+  'T' | --  task stack information
+  'U' | --  unit
+  'V' | --  version
+  'W' | --  with
+  'X' | --  xref
+  'Y' | --  limited_with
+  'Z'   --  implicit with from instantiation
+  => True,
+
+  --  Still available:
+
+  'B' | 'F' | 'H' | 'J' | 'K' | 'O' | 'Q' => False);
 
--
-- Add_Invocation_Construct --

--- gcc/ada/bindo-graphs.adb
+++ gcc/ada/bindo-graphs.adb
@@ -1060,18 +1060,30 @@ package body Bindo.Graphs is
   --  corresponding specs or bodies, where the body is a predecessor
   --  and the spec is a successor. Add all edges to list Edges.
 
-  function Add_Edge_With_Return
+  procedure Add_Edge_Kind_Check
+(G  : Library_Graph;
+ Pred   : Library_Graph_Vertex_Id;
+ Succ   : Library_Graph_Vertex_Id;
+ Kind   : Library_Graph_Edge_Kind);
+  --  This is called by Add_Edge in the case where there is already a
+  --  Pred-->Succ edge, to assert that the new Kind is appropriate. Raises
+  --  Program_Error if a bug is detected. The purpose is to prevent bugs
+  --  where calling Add_Edge in different orders produces different output.
+
+  

[Ada] AI12-0226 Make objects more consistent

2020-06-08 Thread Pierre-Marie de Rodat
Clean up Analyze_Object_Renaming and Is_Object_Reference while
implementing this new AI and recognize value conversion of objects as an
object reference.

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

2020-06-08  Arnaud Charlet  

gcc/ada/

* sem_ch8.adb (Analyze_Object_Renaming): Simplify code by moving
many special cases to Is_Object_Reference and removing others by
only checking renamings coming from sources.
* sem_util.adb (Is_Object_Reference): Update for AI12-0226 and
add more regular handling of 'Priority. Remove special cases no
longer needed now that we are only checking renamings coming
from sources.--- gcc/ada/sem_ch8.adb
+++ gcc/ada/sem_ch8.adb
@@ -759,12 +759,13 @@ package body Sem_Ch8 is
-
 
procedure Analyze_Object_Renaming (N : Node_Id) is
-  Id  : constant Entity_Id  := Defining_Identifier (N);
-  Loc : constant Source_Ptr := Sloc (N);
-  Nam : constant Node_Id:= Name (N);
-  Dec : Node_Id;
-  T   : Entity_Id;
-  T2  : Entity_Id;
+  Id: constant Entity_Id  := Defining_Identifier (N);
+  Loc   : constant Source_Ptr := Sloc (N);
+  Nam   : constant Node_Id:= Name (N);
+  Is_Object_Ref : Boolean := False;
+  Dec   : Node_Id;
+  T : Entity_Id;
+  T2: Entity_Id;
 
   procedure Check_Constrained_Object;
   --  If the nominal type is unconstrained but the renamed object is
@@ -1016,18 +1017,6 @@ package body Sem_Ch8 is
 Mark_Ghost_Renaming (N, Entity (Nam));
  end if;
 
- --  Reject renamings of conversions unless the type is tagged, or
- --  the conversion is implicit (which can occur for cases of anonymous
- --  access types in Ada 2012).
-
- if Nkind (Nam) = N_Type_Conversion
-   and then Comes_From_Source (Nam)
-   and then not Is_Tagged_Type (T)
- then
-Error_Msg_N
-  ("renaming of conversion only allowed for tagged types", Nam);
- end if;
-
  Resolve (Nam, T);
 
  --  If the renamed object is a function call of a limited type,
@@ -1268,15 +1257,7 @@ package body Sem_Ch8 is
  return;
   end if;
 
-  --  Ada 2005 (AI-327)
-
-  if Ada_Version >= Ada_2005
-and then Nkind (Nam) = N_Attribute_Reference
-and then Attribute_Name (Nam) = Name_Priority
-  then
- null;
-
-  elsif Ada_Version >= Ada_2005 and then Nkind (Nam) in N_Has_Entity then
+  if Ada_Version >= Ada_2005 and then Nkind (Nam) in N_Has_Entity then
  declare
 Nam_Ent  : constant Entity_Id := Entity (Get_Object_Name (Nam));
 Nam_Decl : constant Node_Id   := Declaration_Node (Nam_Ent);
@@ -1375,13 +1356,33 @@ package body Sem_Ch8 is
 
   Init_Object_Size_Align (Id);
 
+  --  If N comes from source then check that the original node is an
+  --  object reference since there may have been several rewritting and
+  --  folding. Do not do this for N_Function_Call or N_Explicit_Dereference
+  --  which might correspond to rewrites of e.g. N_Selected_Component
+  --  (for example Object.Method rewriting).
+  --  If N does not come from source then assume the tree is properly
+  --  formed and accept any object reference. In such cases we do support
+  --  more cases of renamings anyway, so the actual check on which renaming
+  --  is valid is better left to the code generator as a last sanity
+  --  check.
+
+  if Comes_From_Source (N) then
+ if Nkind_In (Nam, N_Function_Call, N_Explicit_Dereference) then
+Is_Object_Ref := Is_Object_Reference (Nam);
+ else
+Is_Object_Ref := Is_Object_Reference (Original_Node (Nam));
+ end if;
+  else
+ Is_Object_Ref := True;
+  end if;
+
   if T = Any_Type or else Etype (Nam) = Any_Type then
  return;
 
-  --  Verify that the renamed entity is an object or a function call. It
-  --  may have been rewritten in several ways.
+  --  Verify that the renamed entity is an object or function call.
 
-  elsif Is_Object_Reference (Nam) then
+  elsif Is_Object_Ref then
  if Comes_From_Source (N) then
 if Is_Dependent_Component_Of_Mutable_Object (Nam) then
Error_Msg_N
@@ -1400,49 +1401,15 @@ package body Sem_Ch8 is
 end if;
  end if;
 
-  --  A static function call may have been folded into a literal
+  --  Weird but legal, equivalent to renaming a function call. Illegal
+  --  if the literal is the result of constant-folding an attribute
+  --  reference that is not a function.
 
-  elsif Nkind (Original_Node (Nam)) = N_Function_Call
-
---  When expansion is disabled, attribute reference is not rewritten
---  as function call. Otherwise it may be rewritten as 

[Ada] Fix socket timeout correction for Windows Server 2019 case

2020-06-08 Thread Pierre-Marie de Rodat
All Windows Servers till 2019 correcting the socket timeout for 500ms.

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

2020-06-08  Dmitriy Anisimkov  

gcc/ada/

* socket.c (__gnat_minus_500ms): Remove
IsWindowsVersionOrGreater from condition.--- gcc/ada/socket.c
+++ gcc/ada/socket.c
@@ -801,10 +801,12 @@ const char * __gnat_gai_strerror(int errcode) {
 
 int __gnat_minus_500ms() {
 #if defined (_WIN32)
-  // Windows Server 2019 and Windows 8.0 do not need 500 millisecond socket
-  // timeout correction.
-  return !(IsWindows8OrGreater() && !IsWindowsServer()
-   || IsWindowsVersionOrGreater(10, 0, 17763));
+  // Windows 8.0 and newer do not need 500 millisecond socket timeout
+  // correction.
+  // We do not know the Windows server version without socket timeout
+  // correction for now. When we know, we can add the call for
+  // IsWindowsVersionOrGreater(10, 0, ) into condition.
+  return !IsWindows8OrGreater() || IsWindowsServer();
 #else
return 0;
 #endif



Re: [PATCH] rs6000: Use REAL_TYPE to copy when block move array in structure[PR65421]

2020-06-08 Thread luoxhu via Gcc-patches
Hi,

On 2020/6/3 04:32, Segher Boessenkool wrote:
> Hi Xiong Hu,
> 
> On Tue, Jun 02, 2020 at 04:41:50AM -0500, Xionghu Luo wrote:
>> Double array in structure as function arguments or return value is accessed
>> by BLKmode, they are stored to stack and load from stack with redundant
>> conversion from DF->DI->DF.  This patch checks the homogeneous type and
>> use the actual element type to do block move to by pass the conversions.
> 
>> @@ -2733,6 +2734,7 @@ expand_block_move (rtx operands[], bool might_overlap)
>> rtx loads[MAX_MOVE_REG];
>> rtx stores[MAX_MOVE_REG];
>> int num_reg = 0;
>> +  machine_mode elt_mode = DImode;
>>   
>> /* If this is not a fixed size move, just call memcpy */
>> if (! constp)
>> @@ -2750,6 +2752,17 @@ expand_block_move (rtx operands[], bool might_overlap)
>> if (bytes > rs6000_block_move_inline_limit)
>>   return 0;
>>   
>> +  tree type = TREE_TYPE (MEM_EXPR (orig_dest));
> 
> Declare elt_mode here as well?
> 
>> +  if (TREE_CODE (type) == RECORD_TYPE
>> +  && rs6000_discover_homogeneous_aggregate (TYPE_MODE (type), type, 
>> NULL,
>> +NULL))
>> +{
>> +  tree field_type = TREE_TYPE (first_field (type));
>> +  if (field_type && TREE_CODE (field_type) == ARRAY_TYPE
>> +  && TREE_CODE (TREE_TYPE (field_type)) == REAL_TYPE)
>> +elt_mode = TYPE_MODE (TREE_TYPE (field_type));
>> +}
> 
> Homogeneous aggregates only exist in the ELFv2 ABI, while the problem
> here is the SP float things.  You also noticed (elsewhere) that if the
> struct contains (say) SI, SF, SI, SF, then this does not help.
> 
> Is there some better condition this could use, and maybe an expansion
> that works in more cases as well?
> 
> And, it would be lovely if generic code could expand to something better
> already (not expand to a block move at all, certainly not for something
> as tiny as this).

This pr65421 is array in structure, the assignment is just struct to struct
and won't be split by SROA to element assignment like struct contains 
or .

pr65421.c.236t.optimized:
foo (const struct A a)
{
  struct A D.2909;

   [local count: 1073741824]:
  D.2909 = a;  // struct to struct.
  return D.2909;
}

pr69143.c.234t.optimized:
blah1 (struct foo1 a)
{
  struct foo1 D.2909;
  float _1;
  float _2;

   [local count: 1073741824]:
  _1 = a.y;
  _2 = a.x;
  D.2909.x = _1;// element to element.
  D.2909.y = _2;// element to element.
  return D.2909;
}

So the expander will choose difference path to expand them...

For pr65421, the arguments and return value are accessed by BLKmode after 
gimplify,
since there is no IPA pass, it is never changed from pass gimple to expand.

In expander, the type conversion only happens on expand_assignment of "D.2909 = 
a;"
(arguments assigned to local variable, stack to stack, generated by 
expand_block_move,
insn #13~#20 as followed), the expand_function_start(insn #2~#9) load each 
element type
to be DF already, DF to DI conversion in insn #13~#20 cause the later RTL 
passes fail to
do forward propagation in 246r.fwprop1.  So my patch tries to use the actual 
type for
array in structure here.  If rs6000_discover_homogeneous_aggregate is not 
allowed to be
used here, how about expose and call rs6000_aggregate_candidate directly?  Not 
clear why
"Homogeneous aggregates only exist in the ELFv2 ABI" since double array in 
structure is a
common usage?

pr65421.c.238r.expand:
1: NOTE_INSN_DELETED
   11: NOTE_INSN_BASIC_BLOCK 2
2: r121:DF=%1:DF
3: r122:DF=%2:DF
4: r123:DF=%3:DF
5: r124:DF=%4:DF
6: [r112:DI+0x20]=r121:DF
7: [r112:DI+0x28]=r122:DF
8: [r112:DI+0x30]=r123:DF
9: [r112:DI+0x38]=r124:DF
   10: NOTE_INSN_FUNCTION_BEG
   13: r125:DI=[r112:DI+0x20]
   15: r126:DI=[r112:DI+0x28]
   17: r127:DI=[r112:DI+0x30]
   19: r128:DI=[r112:DI+0x38]
   14: [r112:DI]=r125:DI
   16: [r112:DI+0x8]=r126:DI
   18: [r112:DI+0x10]=r127:DI
   20: [r112:DI+0x18]=r128:DI
   21: r129:DF=[r112:DI]
   22: r130:DF=[r112:DI+0x8]
   23: r131:DF=[r112:DI+0x10]
   24: r132:DF=[r112:DI+0x18]
   25: r117:DF=r129:DF
   26: r118:DF=r130:DF
   27: r119:DF=r131:DF
   28: r120:DF=r132:DF
   32: %1:DF=r117:DF
   33: %2:DF=r118:DF
   34: %3:DF=r119:DF
   35: %4:DF=r120:DF
   36: use %1:DF
   37: use %2:DF
   38: use %3:DF
   39: use %4:DF

To bypass block move requires very generic code change, the BLK mode is 
determined very early
in gimple, remove BLKmode seems huge project in stor-layout.c\function.c\expr.c 
etc. and not sure
other targets like it, the ARM64 use OImode register to avoid BLKmode/stack 
operations, while
X86 expand to two TImode register assignment and pointer result return.

Or do you mean some workaround that don't call emit_block_move to fall in 
expand_block_move in
rs6000-string.c when expand_assignment of "D.2909 = a;" below?
rtx
store_expr (tree exp, rtx target, int call_param_p,
bool nontemporal, bool reverse)
{
...
  else if