Re: [PATCH] Add define_insn_and_split for combine to detect x < 123U ? -1 : 0 (PR target/88425)

2018-12-11 Thread Uros Bizjak
On Tue, Dec 11, 2018 at 8:54 AM Jakub Jelinek  wrote:
>
> On Tue, Dec 11, 2018 at 08:44:00AM +0100, Uros Bizjak wrote:
> > > --- gcc/config/i386/i386.md.jj  2018-11-22 10:40:31.179683319 +0100
> > > +++ gcc/config/i386/i386.md 2018-12-10 11:24:49.785830186 +0100
> > > @@ -17195,6 +17195,24 @@ (define_insn "*x86_movcc_0_m1_neg"
> > > (set_attr "mode" "")
> > > (set_attr "length_immediate" "0")])
> > >
> > > +(define_insn_and_split "*x86_movcc_0_m1_neg_leu"
> > > +  [(set (match_operand:SWI48 0 "register_operand" "=r")
> > > +   (neg:SWI48
> > > + (leu:SWI48
> > > +   (match_operand:SWI 1 "nonimmediate_operand" "m")
> > > +   (match_operand:SWI 2 "" ""
> >
> > You can use const_int_operand predicate with "n" constraint here.
>
> The point was to disallow 64-bit constants, so if I use const_int_operand
> above, I'd need to replace CONST_INT_P (operands[2]) test with
> trunc_int_for_mode (INTVAL (operands[2]), SImode) == INTVAL (operands[2])
> or similar, perhaps do it for the 64-bit mode only, so
>   (mode != DImode
>|| (trunc_int_for_mode (INTVAL (operands[2]), SImode)
>== INTVAL (operands[2])))

The above is the preferred way (we already have a couple of instances
in predicates, where trunc_int_for_mode is used for the above case).
I'd recommend to put everything in the preparation statement and FAIL
in case the value is not supported.
Like:

{
  HOST_WIDE_INT val = UINTVAL operands[2];
  if (trunc_int_for_mode (val, SImode) != val || val != -1)
  FAIL;
 ...
}

Uros.

> > > +   (clobber (reg:CC FLAGS_REG))]
> > > +  "CONST_INT_P (operands[2])
> > > +   && INTVAL (operands[2]) != -1
> > > +   && INTVAL (operands[2]) != 2147483647"
> >
> > Can UINTVAL be used here?
>
> Just for the latter, or for both?  For the first one it would
> require UINTVAL (operands[2]) != HOST_WIDE_INT_M1U
> or so.
>
> Jakub


Re: [PATCH] Add define_insn_and_split for combine to detect x < 123U ? -1 : 0 (PR target/88425)

2018-12-11 Thread Jakub Jelinek
On Tue, Dec 11, 2018 at 09:03:08AM +0100, Uros Bizjak wrote:
> On Tue, Dec 11, 2018 at 8:54 AM Jakub Jelinek  wrote:
> >
> > On Tue, Dec 11, 2018 at 08:44:00AM +0100, Uros Bizjak wrote:
> > > > --- gcc/config/i386/i386.md.jj  2018-11-22 10:40:31.179683319 +0100
> > > > +++ gcc/config/i386/i386.md 2018-12-10 11:24:49.785830186 +0100
> > > > @@ -17195,6 +17195,24 @@ (define_insn "*x86_movcc_0_m1_neg"
> > > > (set_attr "mode" "")
> > > > (set_attr "length_immediate" "0")])
> > > >
> > > > +(define_insn_and_split "*x86_movcc_0_m1_neg_leu"
> > > > +  [(set (match_operand:SWI48 0 "register_operand" "=r")
> > > > +   (neg:SWI48
> > > > + (leu:SWI48
> > > > +   (match_operand:SWI 1 "nonimmediate_operand" "m")
> > > > +   (match_operand:SWI 2 "" ""
> > >
> > > You can use const_int_operand predicate with "n" constraint here.
> >
> > The point was to disallow 64-bit constants, so if I use const_int_operand
> > above, I'd need to replace CONST_INT_P (operands[2]) test with
> > trunc_int_for_mode (INTVAL (operands[2]), SImode) == INTVAL (operands[2])
> > or similar, perhaps do it for the 64-bit mode only, so
> >   (mode != DImode
> >|| (trunc_int_for_mode (INTVAL (operands[2]), SImode)
> >== INTVAL (operands[2])))
> 
> The above is the preferred way (we already have a couple of instances
> in predicates, where trunc_int_for_mode is used for the above case).
> I'd recommend to put everything in the preparation statement and FAIL
> in case the value is not supported.
> Like:
> 
> {
>   HOST_WIDE_INT val = UINTVAL operands[2];
>   if (trunc_int_for_mode (val, SImode) != val || val != -1)
>   FAIL;
>  ...
> }

If it is in preparation statements, then if it does FAIL, then it will ICE,
because it matched as insn already, the FAIL would just mean it couldn't be
split and we then would need to provide some pattern to handle it.

Jakub


[PATCH] rs6000: Don't use rs6000_isa_flags_explicit for soft float tests (PR88145)

2018-12-11 Thread Segher Boessenkool
...specifically, those for builtins.  Soft float can be enabled
implicitly, too (for certain CPUs for example).  We should use
rs6000_isa_flags instead, to decide whether to expand a builtin or
to bail out with an error instead.

Tested on powerpc64-linux {-m32,-m64}.  Committing.


Segher


2018-12-11  Segher Boessenkool  

PR target/88145
* config/rs6000/rs6000.c (rs6000_expand_zeroop_builtin): Use
rs6000_isa_flags instead of rs6000_isa_flags_explicit to decide
whether soft float is enabled.
(rs6000_expand_mtfsb_builtin): Ditto.
(rs6000_expand_set_fpscr_rn_builtin): Ditto.
(rs6000_expand_set_fpscr_drn_builtin): Ditto.

---
 gcc/config/rs6000/rs6000.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c
index f7b2515..4a75e6d 100644
--- a/gcc/config/rs6000/rs6000.c
+++ b/gcc/config/rs6000/rs6000.c
@@ -13339,7 +13339,7 @@ rs6000_expand_zeroop_builtin (enum insn_code icode, rtx 
target)
 return 0;
 
   if (icode == CODE_FOR_rs6000_mffsl
-  && rs6000_isa_flags_explicit & OPTION_MASK_SOFT_FLOAT)
+  && rs6000_isa_flags & OPTION_MASK_SOFT_FLOAT)
 {
   error ("__builtin_mffsl() not supported with -msoft-float");
   return const0_rtx;
@@ -13411,7 +13411,7 @@ rs6000_expand_mtfsb_builtin (enum insn_code icode, tree 
exp)
 /* Builtin not supported on this processor.  */
 return 0;
 
-  if (rs6000_isa_flags_explicit & OPTION_MASK_SOFT_FLOAT)
+  if (rs6000_isa_flags & OPTION_MASK_SOFT_FLOAT)
 {
   error ("__builtin_mtfsb0 and __builtin_mtfsb1 not supported with 
-msoft-float");
   return const0_rtx;
@@ -13448,7 +13448,7 @@ rs6000_expand_set_fpscr_rn_builtin (enum insn_code 
icode, tree exp)
 /* Builtin not supported on this processor.  */
 return 0;
 
-  if (rs6000_isa_flags_explicit & OPTION_MASK_SOFT_FLOAT)
+  if (rs6000_isa_flags & OPTION_MASK_SOFT_FLOAT)
 {
   error ("__builtin_set_fpscr_rn not supported with -msoft-float");
   return const0_rtx;
@@ -13492,7 +13492,7 @@ rs6000_expand_set_fpscr_drn_builtin (enum insn_code 
icode, tree exp)
 fatal_error (input_location,
 "__builtin_set_fpscr_drn is not supported in 32-bit mode.");
 
-  if (rs6000_isa_flags_explicit & OPTION_MASK_SOFT_FLOAT)
+  if (rs6000_isa_flags & OPTION_MASK_SOFT_FLOAT)
 {
   error ("__builtin_set_fpscr_drn not supported with -msoft-float");
   return const0_rtx;
-- 
1.8.3.1



Re: [committed] [PR tree-optimization/80520] Throttle path splitting slightly.

2018-12-11 Thread Richard Biener
On Tue, Dec 11, 2018 at 5:56 AM Jeff Law  wrote:
>
>
>
> This is a pre-req for fixing 80520.  Essentially the goal here is to
> keep the key code in this form:
>
>   
>   [ ... ]
>   if (_20 != 0)
> goto ; [50.00%]
>   else
> goto ; [50.00%]
>
>[local count: 531502203]:
>   _18 = _25 ^ 2567483615;
>
>[local count: 1063004407]:
>   # prephitmp_49 = PHI <_25(3), _18(4)>
>   _2 = (void *) ivtmp.8_30;
>   MEM[base: _2, offset: 0B] = prephitmp_49;
>   ivtmp.8_29 = ivtmp.8_30 + 8;
>   if (ivtmp.8_29 != _6)
> goto ; [98.99%]
>   else
> goto ; [1.01%]
>
>
> Split-paths wants to duplicate bb5 into bb4.  It's just not all that
> profitable to do so.  We can get ever-so-slightly better code on a
> target like microblaze and perhaps others with delay slots and no
> conditional move/execution capabilities.  But that seems more like
> something we should be tackling at the RTL level.
>
> To finish fixing 80520 we will need to improve the RTL if-conversion
> where we presumably can cost things and make a good choice between the
> branchy code we have vs straightline code with a conditional move or
> conditional execution.  I'm not tackling that yet.
>
> Note that split-path-5 has the same basic structure.  A half-diamond
> with a single statement in the middle block that should be trivially
> if-convertable if profitable.  So I adjusted that testcase.
>
> Bootstrapped and regression tested on x86_64.  Installing on the trunk
> momentarily.

You seem to have committed two copies of the changes?

Richard.


Re: [PATCH] Make LTO tests that require recent binutils UNSUPPORTED with older ones (PR lto/86004)

2018-12-11 Thread Richard Biener
On Tue, 11 Dec 2018, Jakub Jelinek wrote:

> Hi!
> 
> As mentioned in the PR, older binutils (like 2.25) complain on these tests
> when using -r that:
> plugin needed to handle lto object
> The following patch introduces an effective target and guards those tests on
> a linker with this issue fixed.
> 
> Regtested on x86_64-linux and i686-linux, plus regtested on x86_64-linux
> with 2.25 binutils, where the patch converts all those FAILs into
> UNSUPPORTEDs.
> 
> Ok for trunk?

OK.

> 2018-12-11  Jakub Jelinek  
> 
>   PR lto/86004
>   * lib/target-supports.exp (check_effective_target_lto_incremental):
>   New.
>   * g++.dg/lto/pr69137_0.C: Require lto_incremental effective target.
>   * g++.dg/lto/pr65316_0.C: Likewise.
>   * g++.dg/lto/pr85176_0.C: Likewise.
>   * g++.dg/lto/pr79000_0.C: Likewise.
>   * g++.dg/lto/pr66180_0.C: Likewise.
>   * g++.dg/lto/pr65193_0.C: Likewise.
>   * g++.dg/lto/pr69077_0.C: Likewise.
>   * g++.dg/lto/pr68057_0.C: Likewise.
>   * g++.dg/lto/pr66705_0.C: Likewise.
>   * g++.dg/lto/pr65302_0.C: Likewise.
>   * g++.dg/lto/20091002-1_0.C: Likewise.
>   * g++.dg/lto/pr81940_0.C: Likewise.
>   * g++.dg/lto/pr64043_0.C: Likewise.
>   * g++.dg/lto/pr65549_0.C: Likewise.
>   * g++.dg/lto/pr69133_0.C: Likewise.
>   * gfortran.dg/lto/pr79108_0.f90: Likewise.
> 
> --- gcc/testsuite/lib/target-supports.exp.jj  2018-12-04 20:40:01.491379395 
> +0100
> +++ gcc/testsuite/lib/target-supports.exp 2018-12-10 15:39:37.714763670 
> +0100
> @@ -8014,6 +8014,18 @@ proc check_effective_target_lto { } {
>  } "-flto"]
>  }
>  
> +# Return 1 if the compiler and linker support incremental link-time
> +# optimization.
> +
> +proc check_effective_target_lto_incremental { } {
> +if ![check_effective_target_lto] {
> + return 0
> +}
> +return [check_no_compiler_messages lto_incremental executable {
> + int main () { return 0; }
> +} "-flto -r -nostdlib"]
> +}
> +
>  # Return 1 if -mx32 -maddress-mode=short can compile, 0 otherwise.
>  
>  proc check_effective_target_maybe_x32 { } {
> --- gcc/testsuite/g++.dg/lto/pr69137_0.C.jj   2016-01-15 20:37:28.533589631 
> +0100
> +++ gcc/testsuite/g++.dg/lto/pr69137_0.C  2018-12-10 15:42:38.355806095 
> +0100
> @@ -1,4 +1,5 @@
>  // { dg-lto-do link }
> +// { dg-require-effective-target lto_incremental }
>  // { dg-lto-options { { -std=c++11 -g -flto } } }
>  // { dg-extra-ld-options "-r -nostdlib" }
>  
> --- gcc/testsuite/g++.dg/lto/pr65316_0.C.jj   2017-11-06 17:24:08.773286226 
> +0100
> +++ gcc/testsuite/g++.dg/lto/pr65316_0.C  2018-12-10 15:41:01.092398551 
> +0100
> @@ -1,4 +1,5 @@
>  // { dg-lto-do link }
> +// { dg-require-effective-target lto_incremental }
>  // { dg-lto-options { { -flto -std=c++11 -g2 -fno-lto-odr-type-merging -O2 
> -Wno-return-type } } }
>  // { dg-extra-ld-options "-r -nostdlib -O2 -fno-lto-odr-type-merging" }
>  
> --- gcc/testsuite/g++.dg/lto/pr85176_0.C.jj   2018-04-04 16:13:42.972551086 
> +0200
> +++ gcc/testsuite/g++.dg/lto/pr85176_0.C  2018-12-10 15:43:20.838110547 
> +0100
> @@ -1,4 +1,5 @@
>  // { dg-lto-do link }
> +// { dg-require-effective-target lto_incremental }
>  // { dg-lto-options { { -flto -g1 } } }
>  // { dg-extra-ld-options "-r -nostdlib" }
>  namespace a {
> --- gcc/testsuite/g++.dg/lto/pr79000_0.C.jj   2017-01-09 11:35:04.310821717 
> +0100
> +++ gcc/testsuite/g++.dg/lto/pr79000_0.C  2018-12-10 15:42:54.657539190 
> +0100
> @@ -1,4 +1,5 @@
>  // { dg-lto-do link }
> +// { dg-require-effective-target lto_incremental }
>  // { dg-lto-options { "-flto -g" } }
>  // { dg-extra-ld-options "-r -nostdlib" }
>  
> --- gcc/testsuite/g++.dg/lto/pr66180_0.C.jj   2015-05-29 15:04:33.064803028 
> +0200
> +++ gcc/testsuite/g++.dg/lto/pr66180_0.C  2018-12-10 15:41:39.730765940 
> +0100
> @@ -1,4 +1,5 @@
>  // { dg-lto-do link }
> +// { dg-require-effective-target lto_incremental }
>  // { dg-lto-options { { -flto -std=c++14 -r -nostdlib } } }
>  #include 
>  namespace {
> --- gcc/testsuite/g++.dg/lto/pr65193_0.C.jj   2017-11-06 17:24:08.774286214 
> +0100
> +++ gcc/testsuite/g++.dg/lto/pr65193_0.C  2018-12-10 15:40:23.564012993 
> +0100
> @@ -1,5 +1,6 @@
>  /* { dg-lto-do link } */
>  /* { dg-require-effective-target fpic } */
> +/* { dg-require-effective-target lto_incremental } */
>  /* { dg-lto-options {{-fPIC -r -nostdlib -flto -O2 -g -Wno-return-type}} } */
>  
>  void frexp (int, int *);
> --- gcc/testsuite/g++.dg/lto/pr69077_0.C.jj   2017-11-06 17:24:08.770286263 
> +0100
> +++ gcc/testsuite/g++.dg/lto/pr69077_0.C  2018-12-10 15:42:19.886108489 
> +0100
> @@ -1,4 +1,5 @@
>  // { dg-lto-do link }
> +// { dg-require-effective-target lto_incremental }
>  // { dg-lto-options { { -O3 -g -flto } } }
>  // { dg-extra-ld-options "-r -nostdlib" }
>  
> --- gcc/testsuite/g++.dg/lto/pr68057_0.C.jj   2015-11-09 13:39:21.418394784 
> +0100
> +++ gcc/testsuite/g++.dg/lto/pr68057_0.C  2018-12-10 1

[committed] Avoid -Wmissing-attributes warnings in libquadmath

2018-12-11 Thread Jakub Jelinek
Hi!

The following patch avoids -Wmissing-attributes warnings in quadmath
headers.

Bootstrapped/regtested on x86_64-linux and i686-linux, committed to trunk.

2018-12-11  Jakub Jelinek  

PR c/88430
* quadmath_weak.h (__qmath2): Add __quadmath_throw.

--- libquadmath/quadmath_weak.h.jj  2018-11-07 14:44:06.583181795 +0100
+++ libquadmath/quadmath_weak.h 2018-12-10 18:30:27.326983966 +0100
@@ -1,5 +1,5 @@
 /* GCC Quad-Precision Math Library
-   Copyright (C) 2010, 2011 Free Software Foundation, Inc.
+   Copyright (C) 2010-2018 Free Software Foundation, Inc.
Written by Tobias Burnus  
 
 This file is part of the libquadmath library.
@@ -25,7 +25,8 @@ Boston, MA 02110-1301, USA.  */
 
 #if SUPPORTS_WEAK
 # define __qmath2(name,name2,type) \
-  static __typeof(type) name __attribute__ ((__weakref__(#name2)));
+  static __typeof(type) name __attribute__ ((__weakref__(#name2))) \
+   __quadmath_throw;
 # define __qmath_(name) __qmath_ ## name
 #else
 # define __qmath2(name,name2,type)

Jakub


Re: [PATCH] Delete powerpcspe

2018-12-11 Thread Richard Biener
On Mon, Dec 10, 2018 at 9:13 PM Segher Boessenkool
 wrote:
>
> On Mon, Dec 10, 2018 at 06:25:31PM +, Andrew Jenner wrote:
> > Sorry for the slow response on this, I was on vacation last week.
> >
> > On 03/12/2018 21:48, Jakub Jelinek wrote:
> > >I'd give the maintainers the last week to act if they don't want this
> > >to happen and if nothing happens, commit it.  PR81084 lists all the reasons
> > >why it should be removed when it is totally unmaintained.
> > >Just make sure to put stuff that belongs there to gcc/ChangeLog and without
> > >gcc/ prefixes.
> >
> > Yes, please go ahead and commit
>
> Committed to trunk as r266961.
>
> > - it's not fair on other maintainers to
> > have to work around my lack of action on this port. I will continue to
> > work on it out-of-tree and hope to restore it once it is in proper shape.
>
> The more important thing is maintenance...  Regular and/or frequent tests
> (posted to gcc-testresults@), bug tracker maintenance, etc.  You need to
> be visible.

Very much agreed on that.  Though if we pull out this card we're applying
double-standards here considering for example ia64 or some embedded ports.

Richard.

>
> Segher


Re: [PATCH] Add define_insn_and_split for combine to detect x < 123U ? -1 : 0 (PR target/88425)

2018-12-11 Thread Uros Bizjak
On Tue, Dec 11, 2018 at 9:14 AM Jakub Jelinek  wrote:
>
> On Tue, Dec 11, 2018 at 09:03:08AM +0100, Uros Bizjak wrote:
> > On Tue, Dec 11, 2018 at 8:54 AM Jakub Jelinek  wrote:
> > >
> > > On Tue, Dec 11, 2018 at 08:44:00AM +0100, Uros Bizjak wrote:
> > > > > --- gcc/config/i386/i386.md.jj  2018-11-22 10:40:31.179683319 +0100
> > > > > +++ gcc/config/i386/i386.md 2018-12-10 11:24:49.785830186 +0100
> > > > > @@ -17195,6 +17195,24 @@ (define_insn "*x86_movcc_0_m1_neg"
> > > > > (set_attr "mode" "")
> > > > > (set_attr "length_immediate" "0")])
> > > > >
> > > > > +(define_insn_and_split 
> > > > > "*x86_movcc_0_m1_neg_leu"
> > > > > +  [(set (match_operand:SWI48 0 "register_operand" "=r")
> > > > > +   (neg:SWI48
> > > > > + (leu:SWI48
> > > > > +   (match_operand:SWI 1 "nonimmediate_operand" "m")
> > > > > +   (match_operand:SWI 2 "" 
> > > > > ""
> > > >
> > > > You can use const_int_operand predicate with "n" constraint here.
> > >
> > > The point was to disallow 64-bit constants, so if I use const_int_operand
> > > above, I'd need to replace CONST_INT_P (operands[2]) test with
> > > trunc_int_for_mode (INTVAL (operands[2]), SImode) == INTVAL (operands[2])
> > > or similar, perhaps do it for the 64-bit mode only, so
> > >   (mode != DImode
> > >|| (trunc_int_for_mode (INTVAL (operands[2]), SImode)
> > >== INTVAL (operands[2])))
> >
> > The above is the preferred way (we already have a couple of instances
> > in predicates, where trunc_int_for_mode is used for the above case).
> > I'd recommend to put everything in the preparation statement and FAIL
> > in case the value is not supported.
> > Like:
> >
> > {
> >   HOST_WIDE_INT val = UINTVAL operands[2];
> >   if (trunc_int_for_mode (val, SImode) != val || val != -1)
> >   FAIL;
> >  ...
> > }
>
> If it is in preparation statements, then if it does FAIL, then it will ICE,
> because it matched as insn already, the FAIL would just mean it couldn't be
> split and we then would need to provide some pattern to handle it.

OK, let's go with your original patch then. Other approaches are more
complex that the original patch.

Thanks,
Uros.


Re: [PATCH] Make LTO tests that require recent binutils UNSUPPORTED with older ones (PR lto/86004)

2018-12-11 Thread Jakub Jelinek
On Tue, Dec 11, 2018 at 08:52:12AM +0100, Rainer Orth wrote:
> Hi Jakub,
> 
> > As mentioned in the PR, older binutils (like 2.25) complain on these tests
> > when using -r that:
> > plugin needed to handle lto object
> > The following patch introduces an effective target and guards those tests on
> > a linker with this issue fixed.
> >
> > Regtested on x86_64-linux and i686-linux, plus regtested on x86_64-linux
> > with 2.25 binutils, where the patch converts all those FAILs into
> > UNSUPPORTEDs.
> >
> > Ok for trunk?
> 
> please document the new effective-target keyword in sourcebuild.texi.

So like this?

2018-12-11  Jakub Jelinek  

PR lto/86004
* doc/sourcebuild.texi (lto_incremental): Document new effective
target.

* lib/target-supports.exp (check_effective_target_lto_incremental):
New.
* g++.dg/lto/pr69137_0.C: Require lto_incremental effective target.
* g++.dg/lto/pr65316_0.C: Likewise.
* g++.dg/lto/pr85176_0.C: Likewise.
* g++.dg/lto/pr79000_0.C: Likewise.
* g++.dg/lto/pr66180_0.C: Likewise.
* g++.dg/lto/pr65193_0.C: Likewise.
* g++.dg/lto/pr69077_0.C: Likewise.
* g++.dg/lto/pr68057_0.C: Likewise.
* g++.dg/lto/pr66705_0.C: Likewise.
* g++.dg/lto/pr65302_0.C: Likewise.
* g++.dg/lto/20091002-1_0.C: Likewise.
* g++.dg/lto/pr81940_0.C: Likewise.
* g++.dg/lto/pr64043_0.C: Likewise.
* g++.dg/lto/pr65549_0.C: Likewise.
* g++.dg/lto/pr69133_0.C: Likewise.
* gfortran.dg/lto/pr79108_0.f90: Likewise.

--- gcc/doc/sourcebuild.texi.jj 2018-11-27 09:48:58.095110442 +0100
+++ gcc/doc/sourcebuild.texi2018-12-11 10:06:03.766267580 +0100
@@ -2265,6 +2265,10 @@ Target keeps null pointer checks, either
 @item lto
 Compiler has been configured to support link-time optimization (LTO).
 
+@item lto_incremental
+Compiler and linker support link-time optimization relocatable linking
+with @option{-r} and @option{-flto} options.
+
 @item naked_functions
 Target supports the @code{naked} function attribute.
 
--- gcc/testsuite/lib/target-supports.exp.jj2018-12-04 20:40:01.491379395 
+0100
+++ gcc/testsuite/lib/target-supports.exp   2018-12-10 15:39:37.714763670 
+0100
@@ -8014,6 +8014,18 @@ proc check_effective_target_lto { } {
 } "-flto"]
 }
 
+# Return 1 if the compiler and linker support incremental link-time
+# optimization.
+
+proc check_effective_target_lto_incremental { } {
+if ![check_effective_target_lto] {
+   return 0
+}
+return [check_no_compiler_messages lto_incremental executable {
+   int main () { return 0; }
+} "-flto -r -nostdlib"]
+}
+
 # Return 1 if -mx32 -maddress-mode=short can compile, 0 otherwise.
 
 proc check_effective_target_maybe_x32 { } {
--- gcc/testsuite/g++.dg/lto/pr69137_0.C.jj 2016-01-15 20:37:28.533589631 
+0100
+++ gcc/testsuite/g++.dg/lto/pr69137_0.C2018-12-10 15:42:38.355806095 
+0100
@@ -1,4 +1,5 @@
 // { dg-lto-do link }
+// { dg-require-effective-target lto_incremental }
 // { dg-lto-options { { -std=c++11 -g -flto } } }
 // { dg-extra-ld-options "-r -nostdlib" }
 
--- gcc/testsuite/g++.dg/lto/pr65316_0.C.jj 2017-11-06 17:24:08.773286226 
+0100
+++ gcc/testsuite/g++.dg/lto/pr65316_0.C2018-12-10 15:41:01.092398551 
+0100
@@ -1,4 +1,5 @@
 // { dg-lto-do link }
+// { dg-require-effective-target lto_incremental }
 // { dg-lto-options { { -flto -std=c++11 -g2 -fno-lto-odr-type-merging -O2 
-Wno-return-type } } }
 // { dg-extra-ld-options "-r -nostdlib -O2 -fno-lto-odr-type-merging" }
 
--- gcc/testsuite/g++.dg/lto/pr85176_0.C.jj 2018-04-04 16:13:42.972551086 
+0200
+++ gcc/testsuite/g++.dg/lto/pr85176_0.C2018-12-10 15:43:20.838110547 
+0100
@@ -1,4 +1,5 @@
 // { dg-lto-do link }
+// { dg-require-effective-target lto_incremental }
 // { dg-lto-options { { -flto -g1 } } }
 // { dg-extra-ld-options "-r -nostdlib" }
 namespace a {
--- gcc/testsuite/g++.dg/lto/pr79000_0.C.jj 2017-01-09 11:35:04.310821717 
+0100
+++ gcc/testsuite/g++.dg/lto/pr79000_0.C2018-12-10 15:42:54.657539190 
+0100
@@ -1,4 +1,5 @@
 // { dg-lto-do link }
+// { dg-require-effective-target lto_incremental }
 // { dg-lto-options { "-flto -g" } }
 // { dg-extra-ld-options "-r -nostdlib" }
 
--- gcc/testsuite/g++.dg/lto/pr66180_0.C.jj 2015-05-29 15:04:33.064803028 
+0200
+++ gcc/testsuite/g++.dg/lto/pr66180_0.C2018-12-10 15:41:39.730765940 
+0100
@@ -1,4 +1,5 @@
 // { dg-lto-do link }
+// { dg-require-effective-target lto_incremental }
 // { dg-lto-options { { -flto -std=c++14 -r -nostdlib } } }
 #include 
 namespace {
--- gcc/testsuite/g++.dg/lto/pr65193_0.C.jj 2017-11-06 17:24:08.774286214 
+0100
+++ gcc/testsuite/g++.dg/lto/pr65193_0.C2018-12-10 15:40:23.564012993 
+0100
@@ -1,5 +1,6 @@
 /* { dg-lto-do link } */
 /* { dg-require-effective-target fpic } */
+/* { dg-require-effective-target lto_incremental } */
 /* { dg-lto-options {{-fPIC -r -nostdl

Re: [PATCH] PR86957

2018-12-11 Thread Thomas Schwinge
Hi Indu!

I recently saw that you just started contributing to GCC, so: welcome,
and enjoy to journey!

On Mon, 10 Dec 2018 12:54:09 -0800, Indu Bhagat  wrote:
> On 12/06/2018 05:54 PM, Indu Bhagat wrote:
> > [...]

Thanks for looking into this issue again.  As I said in private email,
such things (like looking at the wrong build's test logs) happen to all
of us.  As long as we learn -- or, at least try to learn ;-) -- something
from that, that's fine, as far as I'm concerned.

Evidently, the peer review/collaboration that we have in these Free
Software/Open Source software projects worked, and we eventually caught
this issue.  :-)

> > 2. I do however see other tests (a total of 23) which are have 
> > regressed from
> >PASS --> UNRESOLVED. A diff is attached.
> >
> >Each one of them is due to "Error/Warning threshold exceeded: 1 0 
> > (max. 1 3)"
> False alarm.
> 
> Looks like there is some flakiness I ran into.

Anything we could help you with, or that you have questions about?

> New testsuite runs (make check-gcc) on a fresh builds of the GCC (with 
> and without missing-profile) enabled look OK.
> One additional failure as expected (Wmissing-profile.c). No additional 
> unresolved tests.

Good, thanks for verifying!


Grüße
 Thomas


Re: [PATCH] Make LTO tests that require recent binutils UNSUPPORTED with older ones (PR lto/86004)

2018-12-11 Thread Rainer Orth
Hi Jakub,

> On Tue, Dec 11, 2018 at 08:52:12AM +0100, Rainer Orth wrote:
>> Hi Jakub,
>> 
>> > As mentioned in the PR, older binutils (like 2.25) complain on these tests
>> > when using -r that:
>> > plugin needed to handle lto object
>> > The following patch introduces an effective target and guards those tests 
>> > on
>> > a linker with this issue fixed.
>> >
>> > Regtested on x86_64-linux and i686-linux, plus regtested on x86_64-linux
>> > with 2.25 binutils, where the patch converts all those FAILs into
>> > UNSUPPORTEDs.
>> >
>> > Ok for trunk?
>> 
>> please document the new effective-target keyword in sourcebuild.texi.
>
> So like this?

ok, thanks.

Rainer

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


[PATCH 3/9] [libbacktrace] Handle alt FORMS without .gnu_debugaltlink

2018-12-11 Thread Tom de Vries
Handle DW_FORM_GNU_strp_alt and DW_FORM_GNU_ref_alt references robustly in
presence of missing .gnu_debugaltlink file.

2018-11-11  Tom de Vries  

* dwarf.c (enum attr_val_encoding): Add ATTR_VAL_NONE.
(read_attribute): Add altlink parameter.  Handle missing altlink for
DW_FORM_GNU_strp_alt and DW_FORM_GNU_ref_alt.
(find_address_ranges, build_address_map, build_dwarf_data): Add and
handle altlink parameter.
(read_referenced_name, read_function_entry): Add argument to
read_attribute call.
---
 libbacktrace/dwarf.c | 39 +++
 1 file changed, 27 insertions(+), 12 deletions(-)

diff --git a/libbacktrace/dwarf.c b/libbacktrace/dwarf.c
index b571c9fbb06..8b802a085ca 100644
--- a/libbacktrace/dwarf.c
+++ b/libbacktrace/dwarf.c
@@ -129,6 +129,8 @@ struct abbrevs
 
 enum attr_val_encoding
 {
+  /* No attribute value.  */
+  ATTR_VAL_NONE,
   /* An address.  */
   ATTR_VAL_ADDRESS,
   /* A unsigned integer.  */
@@ -700,7 +702,7 @@ static int
 read_attribute (enum dwarf_form form, struct dwarf_buf *buf,
int is_dwarf64, int version, int addrsize,
const unsigned char *dwarf_str, size_t dwarf_str_size,
-   struct attr_val *val)
+   struct attr_val *val, struct dwarf_data *altlink)
 {
   /* Avoid warnings about val.u.FIELD may be used uninitialized if
  this function is inlined.  The warnings aren't valid but can
@@ -806,7 +808,7 @@ read_attribute (enum dwarf_form form, struct dwarf_buf *buf,
form = read_uleb128 (buf);
return read_attribute ((enum dwarf_form) form, buf, is_dwarf64,
   version, addrsize, dwarf_str, dwarf_str_size,
-  val);
+  val, altlink);
   }
 case DW_FORM_sec_offset:
   val->encoding = ATTR_VAL_REF_SECTION;
@@ -832,12 +834,22 @@ read_attribute (enum dwarf_form form, struct dwarf_buf 
*buf,
   val->u.uint = read_uleb128 (buf);
   return 1;
 case DW_FORM_GNU_ref_alt:
-  val->encoding = ATTR_VAL_REF_SECTION;
   val->u.uint = read_offset (buf, is_dwarf64);
+  if (altlink == NULL)
+   {
+ val->encoding = ATTR_VAL_NONE;
+ return 1;
+   }
+  val->encoding = ATTR_VAL_REF_SECTION;
   return 1;
 case DW_FORM_GNU_strp_alt:
-  val->encoding = ATTR_VAL_REF_SECTION;
   val->u.uint = read_offset (buf, is_dwarf64);
+  if (altlink == NULL)
+   {
+ val->encoding = ATTR_VAL_NONE;
+ return 1;
+   }
+  val->encoding = ATTR_VAL_REF_SECTION;
   return 1;
 default:
   dwarf_buf_error (buf, "unrecognized DWARF form");
@@ -1277,7 +1289,8 @@ find_address_ranges (struct backtrace_state *state, 
uintptr_t base_address,
 size_t dwarf_ranges_size,
 int is_bigendian, backtrace_error_callback error_callback,
 void *data, struct unit *u,
-struct unit_addrs_vector *addrs)
+struct unit_addrs_vector *addrs,
+struct dwarf_data *altlink)
 {
   while (unit_buf->left > 0)
 {
@@ -1313,7 +1326,7 @@ find_address_ranges (struct backtrace_state *state, 
uintptr_t base_address,
 
  if (!read_attribute (abbrev->attrs[i].form, unit_buf,
   u->is_dwarf64, u->version, u->addrsize,
-  dwarf_str, dwarf_str_size, &val))
+  dwarf_str, dwarf_str_size, &val, altlink))
return 0;
 
  switch (abbrev->attrs[i].name)
@@ -1412,7 +1425,7 @@ find_address_ranges (struct backtrace_state *state, 
uintptr_t base_address,
dwarf_str, dwarf_str_size,
dwarf_ranges, dwarf_ranges_size,
is_bigendian, error_callback, data,
-   u, addrs))
+   u, addrs, altlink))
return 0;
}
 }
@@ -1431,7 +1444,8 @@ build_address_map (struct backtrace_state *state, 
uintptr_t base_address,
   const unsigned char *dwarf_ranges, size_t dwarf_ranges_size,
   const unsigned char *dwarf_str, size_t dwarf_str_size,
   int is_bigendian, backtrace_error_callback error_callback,
-  void *data, struct unit_addrs_vector *addrs)
+  void *data, struct unit_addrs_vector *addrs,
+  struct dwarf_data *altlink)
 {
   struct dwarf_buf info;
   struct backtrace_vector units;
@@ -1533,7 +1547,7 @@ build_address_map (struct backtrace_state *state, 
uintptr_t base_address,
dwarf_str, dwarf_str_size,
dwarf_ranges, dwarf_ranges_size,
is_bigendian, error_callback, data,
-   u, addrs))
+  

[PATCH 0/9] [libbacktrace] Handle .gnu_debugaltlink

2018-12-11 Thread Tom de Vries
[ Part of this patch series was earlier posted as "[libbacktrace] Handle
DW_FORM_GNU_strp_alt" here (
https://gcc.gnu.org/ml/gcc-patches/2018-11/msg01091.html ).

This patch series is based on the patch series submitted here (
https://gcc.gnu.org/ml/gcc-patches/2018-11/msg01091.html).  It needs the part
that adds keeping track of units.  ]

The dwz tool attempts to optimize DWARF debugging information contained in ELF
shared libraries and ELF executables for size.

With the dwz -m option, it attempts to optimize by moving DWARF debugging
information entries (DIEs), strings and macro descriptions duplicated in
more than one object into a newly created ELF ET_REL object whose filename is
given as -m option argument.  The debug sections in the executables and
shared libraries specified on the command line are then modified again,
referring to the entities in the newly created object.

After a dwz invocation:
...
$ dwz -m c.debug a.out b.out
...
both a.out and b.out contain a .gnu_debugaltlink section referring to c.debug,
and use "DWZ DWARF multifile extensions" such as DW_FORM_GNU_strp_alt and
DW_FORM_GNU_ref_alt to refer to the content of c.debug.

The .gnu_debugaltlink consists of a filename and the expected buildid.

This patch series adds to libbacktrace:
- reading the dwarf of the .gnu_debugaltlink
- support for FORM_GNU_strp_alt and FORM_GNU_ref_alt
- a test-case btest_dwz
- a test-case printdwarftest_dwz_cmp.sh

Bootstrapped and reg-tested on x86_64.

OK for trunk?

Thanks,
- Tom

Tom de Vries (9):
  [libbacktrace] Read .gnu_debugaltlink
  [libbacktrace] Add altlink field to struct dwarf_data
  [libbacktrace] Handle alt FORMS without .gnu_debugaltlink
  [libbacktrace] Handle DW_FORM_GNU_strp_alt
  [libbacktrace] Unify function name preference handling
  [libbacktrace] Factor out read_referenced_name_1
  [libbacktrace] Handle DW_FORM_GNU_ref_alt
  [libbacktrace] Add btest_dwz test-case
  [libbacktrace] Add printdwarftest_dwz_cmp.sh test-case

 libbacktrace/Makefile.am   |  23 +++
 libbacktrace/Makefile.in   |  88 ---
 libbacktrace/configure |  57 ++-
 libbacktrace/configure.ac  |   3 +
 libbacktrace/dwarf.c   | 274 +
 libbacktrace/elf.c | 103 -
 libbacktrace/internal.h|   4 +-
 libbacktrace/pecoff.c  |   3 +-
 libbacktrace/printdwarftest.c  | 241 +
 libbacktrace/printdwarftest_dwz_cmp.sh |   8 +
 libbacktrace/xcoff.c   |   3 +-
 11 files changed, 711 insertions(+), 96 deletions(-)
 create mode 100644 libbacktrace/printdwarftest.c
 create mode 100755 libbacktrace/printdwarftest_dwz_cmp.sh

-- 
2.16.4



[PATCH 2/9] [libbacktrace] Add altlink field to struct dwarf_data

2018-12-11 Thread Tom de Vries
Add an altlink field to struct dwarf_data, and initialize it with the pointer
to the struct dwarf_data for the .gnu_debugaltlink.

2018-11-11  Tom de Vries  

* dwarf.c (struct dwarf_data): Add altlink field.
(backtrace_dwarf_add): Add and handle fileline_entry and
fileline_altlink parameters.
* elf.c (elf_add): Add and handle fileline_entry parameter.  Add args to
backtrace_dwarf_add call.
(phdr_callback, backtrace_initialize): Add arguments to elf_add calls.
* internal.h (backtrace_dwarf_add): Add fileline_entry and
fileline_altlink parameters.
* pecoff.c (coff_add): Add args to backtrace_dwarf_add call.
* xcoff.c (xcoff_add): Same.
---
 libbacktrace/dwarf.c| 13 ++---
 libbacktrace/elf.c  | 24 +++-
 libbacktrace/internal.h |  4 +++-
 libbacktrace/pecoff.c   |  3 ++-
 libbacktrace/xcoff.c|  3 ++-
 5 files changed, 32 insertions(+), 15 deletions(-)

diff --git a/libbacktrace/dwarf.c b/libbacktrace/dwarf.c
index 0f8f70881f8..b571c9fbb06 100644
--- a/libbacktrace/dwarf.c
+++ b/libbacktrace/dwarf.c
@@ -343,6 +343,8 @@ struct dwarf_data
 {
   /* The data for the next file we know about.  */
   struct dwarf_data *next;
+  /* The data for .gnu_debugaltlink.  */
+  struct dwarf_data *altlink;
   /* The base address for this file.  */
   uintptr_t base_address;
   /* A sorted list of address ranges.  */
@@ -2968,7 +2970,7 @@ build_dwarf_data (struct backtrace_state *state,
  size_t dwarf_str_size,
  int is_bigendian,
  backtrace_error_callback error_callback,
- void *data)
+ void *data, struct dwarf_data *altlink)
 {
   struct unit_addrs_vector addrs_vec;
   struct unit_addrs *addrs;
@@ -2995,6 +2997,7 @@ build_dwarf_data (struct backtrace_state *state,
 return NULL;
 
   fdata->next = NULL;
+  fdata->altlink = altlink;
   fdata->base_address = base_address;
   fdata->addrs = addrs;
   fdata->addrs_count = addrs_count;
@@ -3031,7 +3034,8 @@ backtrace_dwarf_add (struct backtrace_state *state,
 size_t dwarf_str_size,
 int is_bigendian,
 backtrace_error_callback error_callback,
-void *data, fileline *fileline_fn)
+void *data, fileline *fileline_fn, void **fileline_entry,
+void *fileline_altlink)
 {
   struct dwarf_data *fdata;
 
@@ -3039,10 +3043,13 @@ backtrace_dwarf_add (struct backtrace_state *state,
dwarf_line, dwarf_line_size, dwarf_abbrev,
dwarf_abbrev_size, dwarf_ranges, dwarf_ranges_size,
dwarf_str, dwarf_str_size, is_bigendian,
-   error_callback, data);
+   error_callback, data, fileline_altlink);
   if (fdata == NULL)
 return 0;
 
+  if (fileline_entry != NULL)
+*fileline_entry = fdata;
+
   if (!state->threaded)
 {
   struct dwarf_data **pp;
diff --git a/libbacktrace/elf.c b/libbacktrace/elf.c
index f3bc2119c07..aeb248ec5e3 100644
--- a/libbacktrace/elf.c
+++ b/libbacktrace/elf.c
@@ -2638,8 +2638,8 @@ static int
 elf_add (struct backtrace_state *state, const char *filename, int descriptor,
 uintptr_t base_address, backtrace_error_callback error_callback,
 void *data, fileline *fileline_fn, int *found_sym, int *found_dwarf,
-int exe, int debuginfo, const char *with_buildid_data,
-uint32_t with_buildid_size)
+void **fileline_entry, int exe, int debuginfo,
+const char *with_buildid_data, uint32_t with_buildid_size)
 {
   struct backtrace_view ehdr_view;
   b_elf_ehdr ehdr;
@@ -3037,7 +3037,8 @@ elf_add (struct backtrace_state *state, const char 
*filename, int descriptor,
backtrace_release_view (state, &debugaltlink_view, error_callback,
data);
  ret = elf_add (state, NULL, d, base_address, error_callback, data,
-fileline_fn, found_sym, found_dwarf, 0, 1, NULL, 0);
+fileline_fn, found_sym, found_dwarf, NULL, 0, 1, NULL,
+0);
  if (ret < 0)
backtrace_close (d, error_callback, data);
  else
@@ -3075,7 +3076,8 @@ elf_add (struct backtrace_state *state, const char 
*filename, int descriptor,
backtrace_release_view (state, &debugaltlink_view, error_callback,
data);
  ret = elf_add (state, NULL, d, base_address, error_callback, data,
-fileline_fn, found_sym, found_dwarf, 0, 1, NULL, 0);
+fileline_fn, found_sym, found_dwarf, NULL, 0, 1, NULL,
+0);
  if (ret < 0)
backtrace_close (d, error_callback, data);
  else
@@ -3090,6 +3092,7 @@ elf_add (struct backtrace_state *state, const char 
*filename, int 

[PATCH 4/9] [libbacktrace] Handle DW_FORM_GNU_strp_alt

2018-12-11 Thread Tom de Vries
Handle DW_FORM_GNU_strp_alt which references the .debug_str section in the
.gnu_debugaltlink file.

2018-11-11  Tom de Vries  

* dwarf.c (read_attribute): Handle DW_FORM_GNU_strp_alt
using altlink.
---
 libbacktrace/dwarf.c | 25 +
 1 file changed, 17 insertions(+), 8 deletions(-)

diff --git a/libbacktrace/dwarf.c b/libbacktrace/dwarf.c
index 8b802a085ca..341b84605c0 100644
--- a/libbacktrace/dwarf.c
+++ b/libbacktrace/dwarf.c
@@ -843,14 +843,23 @@ read_attribute (enum dwarf_form form, struct dwarf_buf 
*buf,
   val->encoding = ATTR_VAL_REF_SECTION;
   return 1;
 case DW_FORM_GNU_strp_alt:
-  val->u.uint = read_offset (buf, is_dwarf64);
-  if (altlink == NULL)
-   {
- val->encoding = ATTR_VAL_NONE;
- return 1;
-   }
-  val->encoding = ATTR_VAL_REF_SECTION;
-  return 1;
+  {
+   uint64_t offset;
+   offset = read_offset (buf, is_dwarf64);
+   if (altlink == NULL)
+ {
+   val->encoding = ATTR_VAL_NONE;
+   return 1;
+ }
+   if (offset >= altlink->dwarf_str_size)
+ {
+   dwarf_buf_error (buf, "DW_FORM_GNU_strp_alt out of range");
+   return 0;
+ }
+   val->encoding = ATTR_VAL_STRING;
+   val->u.string = (const char *) altlink->dwarf_str + offset;
+   return 1;
+  }
 default:
   dwarf_buf_error (buf, "unrecognized DWARF form");
   return 0;
-- 
2.16.4



[PATCH 1/9] [libbacktrace] Read .gnu_debugaltlink

2018-12-11 Thread Tom de Vries
Read the elf file pointed at by the .gnu_debugaltlink section, and verify that
the build id matches.

2018-11-11  Tom de Vries  

* elf.c (elf_add): Add and handle with_buildid_data and
with_buildid_size parameters.  Handle .gnu_debugaltlink section.
(phdr_callback, backtrace_initialize): Add arguments to elf_add calls.
---
 libbacktrace/elf.c | 95 +++---
 1 file changed, 90 insertions(+), 5 deletions(-)

diff --git a/libbacktrace/elf.c b/libbacktrace/elf.c
index f4863f0bea5..f3bc2119c07 100644
--- a/libbacktrace/elf.c
+++ b/libbacktrace/elf.c
@@ -2638,7 +2638,8 @@ static int
 elf_add (struct backtrace_state *state, const char *filename, int descriptor,
 uintptr_t base_address, backtrace_error_callback error_callback,
 void *data, fileline *fileline_fn, int *found_sym, int *found_dwarf,
-int exe, int debuginfo)
+int exe, int debuginfo, const char *with_buildid_data,
+uint32_t with_buildid_size)
 {
   struct backtrace_view ehdr_view;
   b_elf_ehdr ehdr;
@@ -2670,6 +2671,11 @@ elf_add (struct backtrace_state *state, const char 
*filename, int descriptor,
   int debuglink_view_valid;
   const char *debuglink_name;
   uint32_t debuglink_crc;
+  struct backtrace_view debugaltlink_view;
+  int debugaltlink_view_valid;
+  const char *debugaltlink_name;
+  const char *debugaltlink_buildid_data;
+  uint32_t debugaltlink_buildid_size;
   off_t min_offset;
   off_t max_offset;
   struct backtrace_view debug_view;
@@ -2694,6 +2700,10 @@ elf_add (struct backtrace_state *state, const char 
*filename, int descriptor,
   debuglink_view_valid = 0;
   debuglink_name = NULL;
   debuglink_crc = 0;
+  debugaltlink_view_valid = 0;
+  debugaltlink_name = NULL;
+  debugaltlink_buildid_data = NULL;
+  debugaltlink_buildid_size = 0;
   debug_view_valid = 0;
   opd = NULL;
 
@@ -2873,6 +2883,15 @@ elf_add (struct backtrace_state *state, const char 
*filename, int descriptor,
  buildid_data = ¬e->name[0] + ((note->namesz + 3) & ~ 3);
  buildid_size = note->descsz;
}
+
+ if (with_buildid_size != 0)
+   {
+ if (buildid_size != with_buildid_size)
+   goto fail;
+
+ if (memcmp (buildid_data, with_buildid_data, buildid_size) != 0)
+   goto fail;
+   }
}
 
   /* Read the debuglink file if present.  */
@@ -2899,6 +2918,27 @@ elf_add (struct backtrace_state *state, const char 
*filename, int descriptor,
}
}
 
+  if (!debugaltlink_view_valid
+ && strcmp (name, ".gnu_debugaltlink") == 0)
+   {
+ const char *debugaltlink_data;
+ size_t debugaltlink_name_len;
+
+ if (!backtrace_get_view (state, descriptor, shdr->sh_offset,
+  shdr->sh_size, error_callback, data,
+  &debugaltlink_view))
+   goto fail;
+
+ debugaltlink_view_valid = 1;
+ debugaltlink_data = (const char *) debugaltlink_view.data;
+ debugaltlink_name = debugaltlink_data;
+ debugaltlink_name_len = strnlen (debugaltlink_data, shdr->sh_size);
+ debugaltlink_buildid_data = (debugaltlink_data
+  + debugaltlink_name_len
+  + 1);
+ debugaltlink_buildid_size = shdr->sh_size - debugaltlink_name_len - 1;
+   }
+
   /* Read the .opd section on PowerPC64 ELFv1.  */
   if (ehdr.e_machine == EM_PPC64
  && (ehdr.e_flags & EF_PPC64_ABI) < 2
@@ -2993,8 +3033,11 @@ elf_add (struct backtrace_state *state, const char 
*filename, int descriptor,
  if (debuglink_view_valid)
backtrace_release_view (state, &debuglink_view, error_callback,
data);
+ if (debugaltlink_view_valid)
+   backtrace_release_view (state, &debugaltlink_view, error_callback,
+   data);
  ret = elf_add (state, NULL, d, base_address, error_callback, data,
-fileline_fn, found_sym, found_dwarf, 0, 1);
+fileline_fn, found_sym, found_dwarf, 0, 1, NULL, 0);
  if (ret < 0)
backtrace_close (d, error_callback, data);
  else
@@ -3028,8 +3071,11 @@ elf_add (struct backtrace_state *state, const char 
*filename, int descriptor,
 
  backtrace_release_view (state, &debuglink_view, error_callback,
  data);
+ if (debugaltlink_view_valid)
+   backtrace_release_view (state, &debugaltlink_view, error_callback,
+   data);
  ret = elf_add (state, NULL, d, base_address, error_callback, data,
-fileline_fn, found_sym, found_dwarf, 0, 1);
+fileline_fn, found_sym, found_dwarf, 0, 1, NULL, 0);
  if (ret < 0)
backtrace_close (

[PATCH 6/9] [libbacktrace] Factor out read_referenced_name_1

2018-12-11 Thread Tom de Vries
Factor out the common handling of DW_AT_abstract_origin and
DW_AT_specification from read_function_entry and read_referenced_name.

2018-12-10  Tom de Vries  

* dwarf.c (read_referenced_name_1): New function.  Factor out of ...
(read_referenced_name): ... here, and ...
(read_function_entry): ... here.
---
 libbacktrace/dwarf.c | 83 +++-
 1 file changed, 50 insertions(+), 33 deletions(-)

diff --git a/libbacktrace/dwarf.c b/libbacktrace/dwarf.c
index 2483295beb4..99e5f4c3f51 100644
--- a/libbacktrace/dwarf.c
+++ b/libbacktrace/dwarf.c
@@ -2111,6 +2111,42 @@ read_line_info (struct backtrace_state *state, struct 
dwarf_data *ddata,
   return 0;
 }
 
+static const char *read_referenced_name (struct dwarf_data *, struct unit *,
+uint64_t, backtrace_error_callback,
+void *);
+
+/* Read the name of a function from a DIE referenced by ATTR with VAL.  */
+
+static const char *
+read_referenced_name_1 (struct dwarf_data *ddata, struct unit *u,
+   struct attr *attr, struct attr_val *val,
+   backtrace_error_callback error_callback, void *data)
+{
+  switch (attr->name)
+{
+case DW_AT_abstract_origin:
+case DW_AT_specification:
+  break;
+default:
+  return NULL;
+}
+
+  if (attr->form == DW_FORM_ref_addr
+  || attr->form == DW_FORM_ref_sig8)
+{
+  /* This refers to an abstract origin defined in
+some other compilation unit.  We can handle
+this case if we must, but it's harder.  */
+  return NULL;
+}
+
+  if (val->encoding == ATTR_VAL_UINT
+  || val->encoding == ATTR_VAL_REF_UNIT)
+return read_referenced_name (ddata, u, val->u.uint, error_callback, data);
+
+  return NULL;
+}
+
 /* Read the name of a function from a DIE referenced by a
DW_AT_abstract_origin or DW_AT_specification tag.  OFFSET is within
the same compilation unit.  */
@@ -2194,24 +2230,14 @@ read_referenced_name (struct dwarf_data *ddata, struct 
unit *u,
case DW_AT_specification:
  /* Second name preference: override DW_AT_name, don't override
 DW_AT_linkage_name.  */
- if (abbrev->attrs[i].form == DW_FORM_ref_addr
- || abbrev->attrs[i].form == DW_FORM_ref_sig8)
-   {
- /* This refers to a specification defined in some other
-compilation unit.  We can handle this case if we
-must, but it's harder.  */
- break;
-   }
- if (val.encoding == ATTR_VAL_UINT
- || val.encoding == ATTR_VAL_REF_UNIT)
-   {
- const char *name;
+ {
+   const char *name;
 
- name = read_referenced_name (ddata, u, val.u.uint,
+   name = read_referenced_name_1 (ddata, u, &abbrev->attrs[i], &val,
   error_callback, data);
- if (name != NULL)
-   ret = name;
-   }
+   if (name != NULL)
+ ret = name;
+ }
  break;
 
default:
@@ -2436,24 +2462,15 @@ read_function_entry (struct backtrace_state *state, 
struct dwarf_data *ddata,
 DW_AT_linkage_name.  */
  if (have_linkage_name)
break;
- if (abbrev->attrs[i].form == DW_FORM_ref_addr
- || abbrev->attrs[i].form == DW_FORM_ref_sig8)
-   {
- /* This refers to an abstract origin defined in
-some other compilation unit.  We can handle
-this case if we must, but it's harder.  */
- break;
-   }
- if (val.encoding == ATTR_VAL_UINT
- || val.encoding == ATTR_VAL_REF_UNIT)
-   {
- const char *name;
+ {
+   const char *name;
 
- name = read_referenced_name (ddata, u, val.u.uint,
-  error_callback, data);
- if (name != NULL)
-   function->name = name;
-   }
+   name
+ = read_referenced_name_1 (ddata, u, &abbrev->attrs[i],
+   &val, error_callback, data);
+   if (name != NULL)
+ function->name = name;
+ }
  break;
 
case DW_AT_name:
-- 
2.16.4



[PATCH 7/9] [libbacktrace] Handle DW_FORM_GNU_ref_alt

2018-12-11 Thread Tom de Vries
2018-12-10  Tom de Vries  

* dwarf.c (enum attr_val_encoding): Add ATTR_VAL_REF_ALT_INFO.
(struct unit): Add low and high fields.
(struct unit_vector): New type.
(struct dwarf_data): Add units and units_counts fields.
(read_attribute): Handle DW_FORM_GNU_ref_alt using
ATTR_VAL_REF_ALT_INFO.
(find_unit): New function.
(find_address_ranges): Add and handle unit_tag parameter.
(build_address_map): Add and handle units_vec parameter.
(read_referenced_name_1): Handle DW_FORM_GNU_ref_alt.
(build_dwarf_data): Pass units_vec to build_address_map.  Store 
resulting
units vector.
---
 libbacktrace/dwarf.c | 101 ++-
 1 file changed, 91 insertions(+), 10 deletions(-)

diff --git a/libbacktrace/dwarf.c b/libbacktrace/dwarf.c
index 99e5f4c3f51..9a0b93120c8 100644
--- a/libbacktrace/dwarf.c
+++ b/libbacktrace/dwarf.c
@@ -143,6 +143,8 @@ enum attr_val_encoding
   ATTR_VAL_REF_UNIT,
   /* An offset to other data within the .dwarf_info section.  */
   ATTR_VAL_REF_INFO,
+  /* An offset to other data within the alt .dwarf_info section.  */
+  ATTR_VAL_REF_ALT_INFO,
   /* An offset to data in some other section.  */
   ATTR_VAL_REF_SECTION,
   /* A type signature.  */
@@ -281,6 +283,10 @@ struct unit
   /* The offset of UNIT_DATA from the start of the information for
  this compilation unit.  */
   size_t unit_data_offset;
+  /* Start of the compilation unit.  */
+  size_t low;
+  /* End of the compilation unit.  */
+  size_t high;
   /* DWARF version.  */
   int version;
   /* Whether unit is DWARF64.  */
@@ -339,6 +345,14 @@ struct unit_addrs_vector
   size_t count;
 };
 
+/* A growable vector of compilation unit pointer.  */
+
+struct unit_vector
+{
+  struct backtrace_vector vec;
+  size_t count;
+};
+
 /* The information we need to map a PC to a file and line.  */
 
 struct dwarf_data
@@ -353,6 +367,10 @@ struct dwarf_data
   struct unit_addrs *addrs;
   /* Number of address ranges in list.  */
   size_t addrs_count;
+  /* A sorted list of units.  */
+  struct unit **units;
+  /* Number of units in the list.  */
+  size_t units_count;
   /* The unparsed .debug_info section.  */
   const unsigned char *dwarf_info;
   size_t dwarf_info_size;
@@ -840,7 +858,7 @@ read_attribute (enum dwarf_form form, struct dwarf_buf *buf,
  val->encoding = ATTR_VAL_NONE;
  return 1;
}
-  val->encoding = ATTR_VAL_REF_SECTION;
+  val->encoding = ATTR_VAL_REF_ALT_INFO;
   return 1;
 case DW_FORM_GNU_strp_alt:
   {
@@ -866,6 +884,34 @@ read_attribute (enum dwarf_form form, struct dwarf_buf 
*buf,
 }
 }
 
+/* Compare a unit offset against a unit for bsearch.  */
+
+static int
+units_search (const void *vkey, const void *ventry)
+{
+  const uintptr_t *key = (const uintptr_t *) vkey;
+  const struct unit *entry = *((const struct unit *const *) ventry);
+  uintptr_t offset;
+
+  offset = *key;
+  if (offset < entry->low)
+return -1;
+  else if (offset >= entry->high)
+return 1;
+  else
+return 0;
+}
+
+/* Find a unit in PU containing OFFSET.  */
+
+static struct unit *
+find_unit (struct unit **pu, size_t units_count, size_t offset)
+{
+  struct unit **u;
+  u = bsearch (&offset, pu, units_count, sizeof (struct unit *), units_search);
+  return u == NULL ? NULL : *u;
+}
+
 /* Compare function_addrs for qsort.  When ranges are nested, make the
smallest one sort last.  */
 
@@ -1299,7 +1345,7 @@ find_address_ranges (struct backtrace_state *state, 
uintptr_t base_address,
 int is_bigendian, backtrace_error_callback error_callback,
 void *data, struct unit *u,
 struct unit_addrs_vector *addrs,
-struct dwarf_data *altlink)
+struct dwarf_data *altlink, enum dwarf_tag *unit_tag)
 {
   while (unit_buf->left > 0)
 {
@@ -1322,6 +1368,9 @@ find_address_ranges (struct backtrace_state *state, 
uintptr_t base_address,
   if (abbrev == NULL)
return 0;
 
+  if (unit_tag != NULL)
+   *unit_tag = abbrev->tag;
+
   lowpc = 0;
   have_lowpc = 0;
   highpc = 0;
@@ -1434,7 +1483,7 @@ find_address_ranges (struct backtrace_state *state, 
uintptr_t base_address,
dwarf_str, dwarf_str_size,
dwarf_ranges, dwarf_ranges_size,
is_bigendian, error_callback, data,
-   u, addrs, altlink))
+   u, addrs, altlink, NULL))
return 0;
}
 }
@@ -1454,6 +1503,7 @@ build_address_map (struct backtrace_state *state, 
uintptr_t base_address,
   const unsigned char *dwarf_str, size_t dwarf_str_size,
   int is_bigendian, backtrace_error_callback error_callback,
   void *data, struct unit_addrs_vector *addrs,
+  

[PATCH 5/9] [libbacktrace] Unify function name preference handling

2018-12-11 Thread Tom de Vries
Both read_function_entry and read_referenced_name implement a priority scheme
for names.  The priorities are:
- 1st: DW_AT_linkage_name
- 2nd: Name from DW_AT_abstract_origin or DW_AT_specification
- 3rd: DW_AT_name.

Ensure both functions fully adhere to it.

2018-11-21  Tom de Vries  

* dwarf.c (read_referenced_name): Don't allow DW_AT_name to override any
name.
(read_function_entry): Same.  Don't allow name found via
DW_AT_abstract_origin or case DW_AT_specification to override linkage
name.
---
 libbacktrace/dwarf.c | 33 +++--
 1 file changed, 23 insertions(+), 10 deletions(-)

diff --git a/libbacktrace/dwarf.c b/libbacktrace/dwarf.c
index 341b84605c0..2483295beb4 100644
--- a/libbacktrace/dwarf.c
+++ b/libbacktrace/dwarf.c
@@ -2175,18 +2175,25 @@ read_referenced_name (struct dwarf_data *ddata, struct 
unit *u,
   switch (abbrev->attrs[i].name)
{
case DW_AT_name:
- /* We prefer the linkage name if get one.  */
+ /* Third name preference: don't override.  A name we found in some
+other way, will normally be more useful -- e.g., this name is
+normally not mangled.  */
+ if (ret != NULL)
+   break;
  if (val.encoding == ATTR_VAL_STRING)
ret = val.u.string;
  break;
 
case DW_AT_linkage_name:
case DW_AT_MIPS_linkage_name:
+ /* First name preference: override all.  */
  if (val.encoding == ATTR_VAL_STRING)
return val.u.string;
  break;
 
case DW_AT_specification:
+ /* Second name preference: override DW_AT_name, don't override
+DW_AT_linkage_name.  */
  if (abbrev->attrs[i].form == DW_FORM_ref_addr
  || abbrev->attrs[i].form == DW_FORM_ref_sig8)
{
@@ -2339,6 +2346,7 @@ read_function_entry (struct backtrace_state *state, 
struct dwarf_data *ddata,
   int highpc_is_relative;
   uint64_t ranges;
   int have_ranges;
+  int have_linkage_name;
 
   code = read_uleb128 (unit_buf);
   if (code == 0)
@@ -2375,6 +2383,7 @@ read_function_entry (struct backtrace_state *state, 
struct dwarf_data *ddata,
   highpc_is_relative = 0;
   ranges = 0;
   have_ranges = 0;
+  have_linkage_name = 0;
   for (i = 0; i < abbrev->num_attrs; ++i)
{
  struct attr_val val;
@@ -2423,6 +2432,10 @@ read_function_entry (struct backtrace_state *state, 
struct dwarf_data *ddata,
 
case DW_AT_abstract_origin:
case DW_AT_specification:
+ /* Second name preference: override DW_AT_name, don't override
+DW_AT_linkage_name.  */
+ if (have_linkage_name)
+   break;
  if (abbrev->attrs[i].form == DW_FORM_ref_addr
  || abbrev->attrs[i].form == DW_FORM_ref_sig8)
{
@@ -2444,21 +2457,21 @@ read_function_entry (struct backtrace_state *state, 
struct dwarf_data *ddata,
  break;
 
case DW_AT_name:
+ /* Third name preference: don't override.  */
+ if (function->name != NULL)
+   break;
  if (val.encoding == ATTR_VAL_STRING)
-   {
- /* Don't override a name we found in some other
-way, as it will normally be more
-useful--e.g., this name is normally not
-mangled.  */
- if (function->name == NULL)
-   function->name = val.u.string;
-   }
+   function->name = val.u.string;
  break;
 
case DW_AT_linkage_name:
case DW_AT_MIPS_linkage_name:
+ /* First name preference: override all.  */
  if (val.encoding == ATTR_VAL_STRING)
-   function->name = val.u.string;
+   {
+ function->name = val.u.string;
+ have_linkage_name = 1;
+   }
  break;
 
case DW_AT_low_pc:
-- 
2.16.4



[PATCH 9/9] [libbacktrace] Add printdwarftest_dwz_cmp.sh test-case

2018-12-11 Thread Tom de Vries
2018-12-10  Tom de Vries  

* Makefile.am (TESTS): Add printdwarftest_dwz_cmp.sh.
* Makefile.in: Regenerate.
* printdwarftest.c: New file.
* printdwarftest_dwz_cmp.sh: New file.
---
 libbacktrace/Makefile.am   |  11 ++
 libbacktrace/Makefile.in   |  75 +++---
 libbacktrace/printdwarftest.c  | 241 +
 libbacktrace/printdwarftest_dwz_cmp.sh |   8 ++
 4 files changed, 315 insertions(+), 20 deletions(-)
 create mode 100644 libbacktrace/printdwarftest.c
 create mode 100755 libbacktrace/printdwarftest_dwz_cmp.sh

diff --git a/libbacktrace/Makefile.am b/libbacktrace/Makefile.am
index 497cc2f5c97..f270cf16833 100644
--- a/libbacktrace/Makefile.am
+++ b/libbacktrace/Makefile.am
@@ -167,6 +167,17 @@ if HAVE_DWZ
 
 TESTS += btest_dwz
 
+printdwarftest.lo: dwarf.c
+
+printdwarftest_SOURCES = printdwarftest.c testlib.c
+printdwarftest_LDADD = libbacktrace.la
+
+check_PROGRAMS += printdwarftest
+
+printdwarftest_dwz_cmp.sh: printdwarftest_dwz
+
+TESTS += printdwarftest_dwz_cmp.sh
+
 endif HAVE_DWZ
 
 stest_SOURCES = stest.c
diff --git a/libbacktrace/Makefile.in b/libbacktrace/Makefile.in
index 0abfcb42460..d5cc8e958c4 100644
--- a/libbacktrace/Makefile.in
+++ b/libbacktrace/Makefile.in
@@ -120,17 +120,21 @@ POST_UNINSTALL = :
 build_triplet = @build@
 host_triplet = @host@
 target_triplet = @target@
-check_PROGRAMS = $(am__EXEEXT_1) $(am__EXEEXT_2) $(am__EXEEXT_3)
+check_PROGRAMS = $(am__EXEEXT_1) $(am__EXEEXT_2) $(am__EXEEXT_3) \
+   $(am__EXEEXT_4) $(am__EXEEXT_5)
 @NATIVE_TRUE@am__append_1 = test_elf test_xcoff_32 test_xcoff_64 \
 @NATIVE_TRUE@  test_pecoff test_unknown unittest unittest_alloc \
-@NATIVE_TRUE@  btest btest_alloc stest stest_alloc ztest \
-@NATIVE_TRUE@  ztest_alloc edtest edtest_alloc
-@HAVE_DWZ_TRUE@@NATIVE_TRUE@am__append_2 = btest_dwz
-@HAVE_ZLIB_TRUE@@NATIVE_TRUE@am__append_3 = -lz
-@HAVE_ZLIB_TRUE@@NATIVE_TRUE@am__append_4 = -lz
-@HAVE_PTHREAD_TRUE@@NATIVE_TRUE@am__append_5 = ttest ttest_alloc
-@HAVE_OBJCOPY_DEBUGLINK_TRUE@@NATIVE_TRUE@am__append_6 = dtest
-@HAVE_COMPRESSED_DEBUG_TRUE@@NATIVE_TRUE@am__append_7 = ctestg ctesta \
+@NATIVE_TRUE@  btest btest_alloc
+@HAVE_DWZ_TRUE@@NATIVE_TRUE@am__append_2 = btest_dwz \
+@HAVE_DWZ_TRUE@@NATIVE_TRUE@   printdwarftest_dwz_cmp.sh
+@HAVE_DWZ_TRUE@@NATIVE_TRUE@am__append_3 = printdwarftest
+@NATIVE_TRUE@am__append_4 = stest stest_alloc ztest ztest_alloc edtest \
+@NATIVE_TRUE@  edtest_alloc
+@HAVE_ZLIB_TRUE@@NATIVE_TRUE@am__append_5 = -lz
+@HAVE_ZLIB_TRUE@@NATIVE_TRUE@am__append_6 = -lz
+@HAVE_PTHREAD_TRUE@@NATIVE_TRUE@am__append_7 = ttest ttest_alloc
+@HAVE_OBJCOPY_DEBUGLINK_TRUE@@NATIVE_TRUE@am__append_8 = dtest
+@HAVE_COMPRESSED_DEBUG_TRUE@@NATIVE_TRUE@am__append_9 = ctestg ctesta \
 @HAVE_COMPRESSED_DEBUG_TRUE@@NATIVE_TRUE@  ctestg_alloc \
 @HAVE_COMPRESSED_DEBUG_TRUE@@NATIVE_TRUE@  ctesta_alloc
 subdir = .
@@ -178,13 +182,14 @@ libbacktrace_noformat_la_OBJECTS =  \
 @NATIVE_TRUE@  test_xcoff_64$(EXEEXT) test_pecoff$(EXEEXT) \
 @NATIVE_TRUE@  test_unknown$(EXEEXT) unittest$(EXEEXT) \
 @NATIVE_TRUE@  unittest_alloc$(EXEEXT) btest$(EXEEXT) \
-@NATIVE_TRUE@  btest_alloc$(EXEEXT) stest$(EXEEXT) \
-@NATIVE_TRUE@  stest_alloc$(EXEEXT) ztest$(EXEEXT) \
-@NATIVE_TRUE@  ztest_alloc$(EXEEXT) edtest$(EXEEXT) \
-@NATIVE_TRUE@  edtest_alloc$(EXEEXT)
-@HAVE_PTHREAD_TRUE@@NATIVE_TRUE@am__EXEEXT_2 = ttest$(EXEEXT) \
+@NATIVE_TRUE@  btest_alloc$(EXEEXT)
+@HAVE_DWZ_TRUE@@NATIVE_TRUE@am__EXEEXT_2 = printdwarftest$(EXEEXT)
+@NATIVE_TRUE@am__EXEEXT_3 = stest$(EXEEXT) stest_alloc$(EXEEXT) \
+@NATIVE_TRUE@  ztest$(EXEEXT) ztest_alloc$(EXEEXT) \
+@NATIVE_TRUE@  edtest$(EXEEXT) edtest_alloc$(EXEEXT)
+@HAVE_PTHREAD_TRUE@@NATIVE_TRUE@am__EXEEXT_4 = ttest$(EXEEXT) \
 @HAVE_PTHREAD_TRUE@@NATIVE_TRUE@   ttest_alloc$(EXEEXT)
-@HAVE_COMPRESSED_DEBUG_TRUE@@NATIVE_TRUE@am__EXEEXT_3 =  \
+@HAVE_COMPRESSED_DEBUG_TRUE@@NATIVE_TRUE@am__EXEEXT_5 =  \
 @HAVE_COMPRESSED_DEBUG_TRUE@@NATIVE_TRUE@  ctestg$(EXEEXT) \
 @HAVE_COMPRESSED_DEBUG_TRUE@@NATIVE_TRUE@  ctesta$(EXEEXT) \
 @HAVE_COMPRESSED_DEBUG_TRUE@@NATIVE_TRUE@  ctestg_alloc$(EXEEXT) \
@@ -247,6 +252,12 @@ edtest_OBJECTS = $(am_edtest_OBJECTS)
 @NATIVE_TRUE@am_edtest_alloc_OBJECTS = $(am__objects_5)
 edtest_alloc_OBJECTS = $(am_edtest_alloc_OBJECTS)
 @NATIVE_TRUE@edtest_alloc_DEPENDENCIES = libbacktrace_alloc.la
+@HAVE_DWZ_TRUE@@NATIVE_TRUE@am_printdwarftest_OBJECTS =  \
+@HAVE_DWZ_TRUE@@NATIVE_TRUE@   printdwarftest.$(OBJEXT) \
+@HAVE_DWZ_TRUE@@NATIVE_TRUE@   testlib.$(OBJEXT)
+printdwarftest_OBJECTS = $(am_printdwarftest_OBJECTS)
+@HAVE_DWZ_TRUE@@NATIVE_TRUE@printdwarftest_DEPENDENCIES =  \
+@HAVE_DWZ_TRUE@@NATIVE_TRUE@   libbacktrace.la
 @NATIVE_TRUE@am_stest_OBJECTS = stest.$(OBJEXT)
 stest_OBJECTS = $(am_stest_OBJECTS)
 @NATIVE_TRUE@stest_DEPENDENCIES = libbacktrace.la
@@ -361,8 +372,8 @@ SOURCES = $(libbacktrace_la_SOURCES) 
$(EXTRA_libbacktrace_la_SOURCES) \
$(btest_alloc_SOURCES) $(ctesta_SOURCE

Re: [Ada] Gigi support for OpenACC pragmas

2018-12-11 Thread Olivier Hainque
(A message that remained in my drafts box)

> On 3 Dec 2018, at 16:50, Pierre-Marie de Rodat  wrote:
> 
> Matching front-end bits to support Acc_Kernels, Acc_Parallel,
> Acc_Loop and Acc_Data.

Note that this was all originally contributed by Ghujan Lacambre
()

Olivier




[PATCH 8/9] [libbacktrace] Add btest_dwz test-case

2018-12-11 Thread Tom de Vries
2018-11-11  Tom de Vries  

* configure.ac (DWZ): Set with AC_CHECK_PROG.
(HAVE_DWZ): Set with AM_CONDITIONAL.
* configure: Regenerate.
* Makefile.am (TESTS): Add btest_dwz.
* Makefile.in: Regenerate.
---
 libbacktrace/Makefile.am  | 12 ++
 libbacktrace/Makefile.in  | 29 ++--
 libbacktrace/configure| 57 +--
 libbacktrace/configure.ac |  3 +++
 4 files changed, 92 insertions(+), 9 deletions(-)

diff --git a/libbacktrace/Makefile.am b/libbacktrace/Makefile.am
index 1a3680bc98c..497cc2f5c97 100644
--- a/libbacktrace/Makefile.am
+++ b/libbacktrace/Makefile.am
@@ -157,6 +157,18 @@ btest_alloc_LDADD = libbacktrace_alloc.la
 
 check_PROGRAMS += btest_alloc
 
+if HAVE_DWZ
+
+%_dwz: %
+   rm -f $@_common.debug
+   cp $< $@
+   cp $< $@_2
+   $(DWZ) -m $@_common.debug $@ $@_2
+
+TESTS += btest_dwz
+
+endif HAVE_DWZ
+
 stest_SOURCES = stest.c
 stest_LDADD = libbacktrace.la
 
diff --git a/libbacktrace/Makefile.in b/libbacktrace/Makefile.in
index 6eaa1e28c01..0abfcb42460 100644
--- a/libbacktrace/Makefile.in
+++ b/libbacktrace/Makefile.in
@@ -125,11 +125,12 @@ check_PROGRAMS = $(am__EXEEXT_1) $(am__EXEEXT_2) 
$(am__EXEEXT_3)
 @NATIVE_TRUE@  test_pecoff test_unknown unittest unittest_alloc \
 @NATIVE_TRUE@  btest btest_alloc stest stest_alloc ztest \
 @NATIVE_TRUE@  ztest_alloc edtest edtest_alloc
-@HAVE_ZLIB_TRUE@@NATIVE_TRUE@am__append_2 = -lz
+@HAVE_DWZ_TRUE@@NATIVE_TRUE@am__append_2 = btest_dwz
 @HAVE_ZLIB_TRUE@@NATIVE_TRUE@am__append_3 = -lz
-@HAVE_PTHREAD_TRUE@@NATIVE_TRUE@am__append_4 = ttest ttest_alloc
-@HAVE_OBJCOPY_DEBUGLINK_TRUE@@NATIVE_TRUE@am__append_5 = dtest
-@HAVE_COMPRESSED_DEBUG_TRUE@@NATIVE_TRUE@am__append_6 = ctestg ctesta \
+@HAVE_ZLIB_TRUE@@NATIVE_TRUE@am__append_4 = -lz
+@HAVE_PTHREAD_TRUE@@NATIVE_TRUE@am__append_5 = ttest ttest_alloc
+@HAVE_OBJCOPY_DEBUGLINK_TRUE@@NATIVE_TRUE@am__append_6 = dtest
+@HAVE_COMPRESSED_DEBUG_TRUE@@NATIVE_TRUE@am__append_7 = ctestg ctesta \
 @HAVE_COMPRESSED_DEBUG_TRUE@@NATIVE_TRUE@  ctestg_alloc \
 @HAVE_COMPRESSED_DEBUG_TRUE@@NATIVE_TRUE@  ctesta_alloc
 subdir = .
@@ -620,6 +621,7 @@ CYGPATH_W = @CYGPATH_W@
 DEFS = @DEFS@
 DSYMUTIL = @DSYMUTIL@
 DUMPBIN = @DUMPBIN@
+DWZ = @DWZ@
 ECHO_C = @ECHO_C@
 ECHO_N = @ECHO_N@
 ECHO_T = @ECHO_T@
@@ -774,7 +776,7 @@ libbacktrace_la_LIBADD = \
$(ALLOC_FILE)
 
 libbacktrace_la_DEPENDENCIES = $(libbacktrace_la_LIBADD)
-TESTS = $(check_PROGRAMS) $(am__append_5)
+TESTS = $(check_PROGRAMS) $(am__append_2) $(am__append_6)
 @NATIVE_TRUE@check_LTLIBRARIES = libbacktrace_alloc.la \
 @NATIVE_TRUE@  libbacktrace_noformat.la
 @NATIVE_TRUE@libbacktrace_alloc_la_SOURCES = $(libbacktrace_la_SOURCES)
@@ -809,9 +811,9 @@ TESTS = $(check_PROGRAMS) $(am__append_5)
 @NATIVE_TRUE@stest_alloc_LDADD = libbacktrace_alloc.la
 @NATIVE_TRUE@ztest_SOURCES = ztest.c testlib.c
 @NATIVE_TRUE@ztest_CFLAGS = -DSRCDIR=\"$(srcdir)\"
-@NATIVE_TRUE@ztest_LDADD = libbacktrace.la $(am__append_2) \
+@NATIVE_TRUE@ztest_LDADD = libbacktrace.la $(am__append_3) \
 @NATIVE_TRUE@  $(CLOCK_GETTIME_LINK)
-@NATIVE_TRUE@ztest_alloc_LDADD = libbacktrace_alloc.la $(am__append_3) \
+@NATIVE_TRUE@ztest_alloc_LDADD = libbacktrace_alloc.la $(am__append_4) \
 @NATIVE_TRUE@  $(CLOCK_GETTIME_LINK)
 @NATIVE_TRUE@ztest_alloc_SOURCES = $(ztest_SOURCES)
 @NATIVE_TRUE@ztest_alloc_CFLAGS = $(ztest_CFLAGS)
@@ -1532,6 +1534,13 @@ ctesta_alloc.log: ctesta_alloc$(EXEEXT)
--log-file $$b.log --trs-file $$b.trs \
$(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) 
-- $(LOG_COMPILE) \
"$$tst" $(AM_TESTS_FD_REDIRECT)
+btest_dwz.log: btest_dwz
+   @p='btest_dwz'; \
+   b='btest_dwz'; \
+   $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \
+   --log-file $$b.log --trs-file $$b.trs \
+   $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) 
-- $(LOG_COMPILE) \
+   "$$tst" $(AM_TESTS_FD_REDIRECT)
 dtest.log: dtest
@p='dtest'; \
b='dtest'; \
@@ -1695,6 +1704,12 @@ uninstall-am:
 @NATIVE_TRUE@  $(srcdir)/xcoff.c \
 @NATIVE_TRUE@  > $@
 
+@HAVE_DWZ_TRUE@@NATIVE_TRUE@%_dwz: %
+@HAVE_DWZ_TRUE@@NATIVE_TRUE@   rm -f $@_common.debug
+@HAVE_DWZ_TRUE@@NATIVE_TRUE@   cp $< $@
+@HAVE_DWZ_TRUE@@NATIVE_TRUE@   cp $< $@_2
+@HAVE_DWZ_TRUE@@NATIVE_TRUE@   $(DWZ) -m $@_common.debug $@ $@_2
+
 @NATIVE_TRUE@edtest2_build.c: gen_edtest2_build; @true
 @NATIVE_TRUE@gen_edtest2_build: $(srcdir)/edtest2.c
 @NATIVE_TRUE@  cat $(srcdir)/edtest2.c > tmp-edtest2_build.c
diff --git a/libbacktrace/configure b/libbacktrace/configure
index c316dde1ad2..2ea112bde68 100755
--- a/libbacktrace/configure
+++ b/libbacktrace/configure
@@ -672,6 +672,9 @@ LD
 FGREP
 SED
 LIBTOOL
+HAVE_DWZ_FALSE
+HAVE_DWZ_TRUE
+DWZ
 RANLIB
 MAINT
 MAINTAINER_MODE_FALSE
@@ -5366,6 +5369,52 @@ case "$AWK" in
 "") as_fn_error $? "can't build without awk" "$LINENO" 5 ;;
 esac
 
+# Extract the first word of "

[PATCH 0/2][ARC] Fixes needed for the upcomming release.

2018-12-11 Thread Claudiu Zissulescu
Hi Andrew,

Please find two small patches which are fixing a number of issues found in the 
upcomming release.

Ok to apply?
Claudiu

Claudiu Zissulescu (2):
  [ARC] Fix REG_CLASS_NAMES
  [ARC] Fix millicode wrong blink restore.

 gcc/config/arc/arc.c   |  4 +---
 gcc/config/arc/arc.h   |  1 +
 gcc/testsuite/gcc.target/arc/milli-1.c | 23 +++
 3 files changed, 25 insertions(+), 3 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/arc/milli-1.c

-- 
2.19.1



[PATCH 2/2] [ARC] Fix millicode wrong blink restore.

2018-12-11 Thread Claudiu Zissulescu
The blink is restored wrongly when using millicode and regular load
instructions.

gcc/
-xx-xx  Claudiu Zissulescu  

* config/arc/arc.c (arc_restore_callee_milli) Don't clobber off
variable.

testsuite/
-xx-xx  Claudiu Zissulescu  

* gcc.target/arc/milli-1.c: New test.
---
 gcc/config/arc/arc.c   |  4 +---
 gcc/testsuite/gcc.target/arc/milli-1.c | 23 +++
 2 files changed, 24 insertions(+), 3 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/arc/milli-1.c

diff --git a/gcc/config/arc/arc.c b/gcc/config/arc/arc.c
index 55175215bfe..5af3ee6c9e0 100644
--- a/gcc/config/arc/arc.c
+++ b/gcc/config/arc/arc.c
@@ -3597,9 +3597,7 @@ arc_restore_callee_milli (unsigned int gmask,
 insn = frame_insn (insn);
 
   /* Add DWARF info.  */
-  for (regno = start_reg, off = 0;
-   regno <= end_reg;
-   regno++, off += UNITS_PER_WORD)
+  for (regno = start_reg; regno <= end_reg; regno++)
 {
   reg = gen_rtx_REG (SImode, regno);
   add_reg_note (insn, REG_CFA_RESTORE, reg);
diff --git a/gcc/testsuite/gcc.target/arc/milli-1.c 
b/gcc/testsuite/gcc.target/arc/milli-1.c
new file mode 100644
index 000..b501b39eb81
--- /dev/null
+++ b/gcc/testsuite/gcc.target/arc/milli-1.c
@@ -0,0 +1,23 @@
+/* { dg-do compile } */
+/* { dg-options "-Os" } */
+
+/* Test if we restore correctly blink when using millicode.  */
+extern void bar (void);
+
+void foo (void)
+{
+  __asm__ volatile ( "" : : : "r13","r14","r15","r16","r17","r18","r20","r21");
+  bar();
+}
+
+void foo2 (void)
+{
+  bar();
+  __asm__ volatile ( "" : : : "r13","r14","r15","r16","r17","r18","r20","r21");
+}
+
+/* { dg-final { scan-assembler-not "st.*r13,\\\[sp" } } */
+/* { dg-final { scan-assembler-not "st.*r14,\\\[sp" } } */
+/* { dg-final { scan-assembler-not "st.*r15,\\\[sp" } } */
+/* { dg-final { scan-assembler "ld.*blink,\\\[sp,32" } } */
+/* { dg-final { scan-assembler "mov_s.*r12,32" } } */
-- 
2.19.1



[PATCH 1/2] [ARC] Fix REG_CLASS_NAMES

2018-12-11 Thread Claudiu Zissulescu
Forgot a class name, fix it.

gcc/
-xx-xx  Claudiu Zissulescu  

* config/arc/arc.h (REG_CLASS_NAMES): Add SIBCALL_REGS.


---
 gcc/config/arc/arc.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/gcc/config/arc/arc.h b/gcc/config/arc/arc.h
index 4d01c99a540..80e785e6562 100644
--- a/gcc/config/arc/arc.h
+++ b/gcc/config/arc/arc.h
@@ -491,6 +491,7 @@ enum reg_class
   "R0R1_CD_REGS",\
   "R0R3_CD_REGS",\
   "ARCOMPACT16_REGS",\
+  "SIBCALL_REGS",\
   "AC16_H_REGS", \
   "DOUBLE_REGS", \
   "GENERAL_REGS",\
-- 
2.19.1



[PATCH] TLC to ccmp.c

2018-12-11 Thread Richard Biener


Not sure who approved that...

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

Richard.

2018-12-11  Richard Biener  

* ccmp.c (ccmp_candidate_p): Use GIMPLE API properly.

Index: gcc/ccmp.c
===
--- gcc/ccmp.c  (revision 266956)
+++ gcc/ccmp.c  (working copy)
@@ -94,7 +94,6 @@ ccmp_tree_comparison_p (tree t, basic_bl
 static bool
 ccmp_candidate_p (gimple *g)
 {
-  tree rhs;
   tree lhs, op0, op1;
   gimple *gs0, *gs1;
   tree_code tcode;
@@ -103,20 +102,18 @@ ccmp_candidate_p (gimple *g)
   if (!g)
 return false;
 
-  rhs = gimple_assign_rhs_to_tree (g);
-  tcode = TREE_CODE (rhs);
+  tcode = gimple_assign_rhs_code (g);
   if (tcode != BIT_AND_EXPR && tcode != BIT_IOR_EXPR)
 return false;
 
   lhs = gimple_assign_lhs (g);
-  op0 = TREE_OPERAND (rhs, 0);
-  op1 = TREE_OPERAND (rhs, 1);
-  bb = gimple_bb (g);
-
+  op0 = gimple_assign_rhs1 (g);
+  op1 = gimple_assign_rhs2 (g);
   if ((TREE_CODE (op0) != SSA_NAME) || (TREE_CODE (op1) != SSA_NAME)
   || !has_single_use (lhs))
 return false;
 
+  bb = gimple_bb (g);
   gs0 = get_gimple_for_ssa_name (op0); /* gs0 may be NULL */
   gs1 = get_gimple_for_ssa_name (op1); /* gs1 may be NULL */
 


Re: [ARM/FDPIC v4 00/20] FDPIC ABI for ARM

2018-12-11 Thread Christophe Lyon

Ping?


On 03/12/2018 10:19, Christophe Lyon wrote:

Ping?

The series started here:
https://gcc.gnu.org/ml/gcc-patches/2018-11/msg01464.html

Thanks,

Christophe

On Mon, 26 Nov 2018 at 11:14, Christophe Lyon
 wrote:


Ping?

Thanks

On Fri, 16 Nov 2018 at 16:48, Christophe Lyon  wrote:


From: Christophe Lyon 

Hello,

This patch series implements the GCC contribution of the FDPIC ABI for
ARM targets.

This ABI enables to run Linux on ARM MMU-less cores and supports
shared libraries to reduce the memory footprint.

Without MMU, text and data segments relative distances are different
from one process to another, hence the need for a dedicated FDPIC
register holding the start address of the data segment. One of the
side effects is that function pointers require two words to be
represented: the address of the code, and the data segment start
address. These two words are designated as "Function Descriptor",
hence the "FD PIC" name.

On ARM, the FDPIC register is r9 [1], and the target name is
arm-uclinuxfdpiceabi. Note that arm-uclinux exists, but uses another
ABI and the BFLAT file format; it does not support code sharing.
The -mfdpic option is enabled by default, and -mno-fdpic should be
used to build the Linux kernel.

This work was developed some time ago by STMicroelectronics, and was
presented during Linaro Connect SFO15 (September 2015). You can watch
the discussion and read the slides [2].
This presentation was related to the toolchain published on github [3],
which is based on binutils-2.22, gcc-4.7, uclibc-0.9.33.2, gdb-7.5.1
and qemu-2.3.0, and for which pre-built binaries are available [3].

The ABI itself is described in details in [1].

Our Linux kernel patches have been updated and committed by Nicolas
Pitre (Linaro) in July 2017. They are required so that the loader is
able to handle this new file type. Indeed, the ELF files are tagged
with ELFOSABI_ARM_FDPIC. This new tag has been allocated by ARM, as
well as the new relocations involved.

The binutils, QEMU and uclibc-ng patch series have been merged
recently. [4][5][6]

This series provides support for architectures that support ARM and/or
Thumb-2 and has been tested on arm-linux-gnueabi without regression,
as well as arm-uclinuxfdpiceabi, using QEMU. arm-uclinuxfdpiceabi has
more failures than arm-linux-gnueabi, but is quite functional.

Are the GCC patches OK for inclusion in master?

Changes between v3 and v4:

- improved documentation (patch 1)
- emit an error message (sorry) if the target architecture does not
   support arm nor thumb-2 modes (patch 4)
- handle Richard's comments on patch 4 (comments, unspec)
- added .align directive (patch 5)
- fixed use of kernel helpers (__kernel_cmpxchg, __kernel_dmb) (patch 6)
- code factorization in patch 7
- typos/internal function name in patch 8
- improved patch 12
- dropped patch 16
- patch 20 introduces arm_arch*_thumb_ok effective targets to help
   skip some tests
- I tested patch 2 on xtensa-buildroot-uclinux-uclibc, it adds many
   new tests, but a few regressions
   (https://gcc.gnu.org/ml/gcc-patches/2018-11/msg00713.html)
- I compiled and executed several LTP tests to exercise pthreads and signals
- I wrote and executed a simple testcase to change the interaction
   with __kernel_cmpxchg (ie. call the kernel helper rather than use an
   implementation in libgcc as requested by Richard)

Changes between v2 and v3:
- added doc entry for -mfdpic new option
- took Kyrill's comments into account (use "Armv7" instead of "7",
   code factorization, use preprocessor instead of hard-coding "r9",
   remove leftover code for thumb1 support, fixed comments)
- rebase over recent trunk
- patches with changes: 1, 2 (commit message), 3 (rebase), 4, 6, 7, 9,
   14 (rebase), 19 (rebase)

Changes between v1 and v2:
- fix GNU coding style
- exit with an error for pre-Armv7
- use ACLE __ARM_ARCH and remove dead code for pre-Armv4
- remove unsupported attempts of pre-Armv7/thumb1 support
- add instructions in comments next to opcodes
- merge patches 11 and 13
- fixed protected visibility handling in patch 8
- merged legitimize_tls_address_fdpic and
   legitimize_tls_address_not_fdpic as requested

Thanks,

Christophe.


[1] https://github.com/mickael-guene/fdpic_doc/blob/master/abi.txt
[2] 
http://connect.linaro.org/resource/sfo15/sfo15-406-arm-fdpic-toolset-kernel-libraries-for-cortex-m-cortex-r-mmuless-cores/
[3] https://github.com/mickael-guene/fdpic_manifest
[4] 
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=commit;h=f1ac0afe481e83c9a33f247b81fa7de789edc4d9
[5] 
https://git.qemu.org/?p=qemu.git;a=commit;h=e8fa72957419c11984608062c7dcb204a6003a06
[6] 
https://cgit.uclibc-ng.org/cgi/cgit/uclibc-ng.git/commit/?id=13c46fbc1e5a021f2b9ed32d83aecc93ae5e655d

Christophe Lyon (20):
   [ARM] FDPIC: Add -mfdpic option support
   [ARM] FDPIC: Handle arm*-*-uclinuxfdpiceabi in configure scripts
   [ARM] FDPIC: Force FDPIC related options unless -mno-fdpic is provided
   [ARM] FDPIC: Add support for F

[PATCH] Rip out rhs-to-tree from tree-affine.c

2018-12-11 Thread Richard Biener


After the previous cleanup the following is more straight-forward now.
This should make tree-affine behave wrt the "new" GIMPLE world.

Bootstrapped and tested on x86_64-unknown-linux-gnu, now making
sure there are no codegen changes as expected.

Richard.

2018-12-11  Richard Biener  

* tree-affine.c (expr_to_aff_combination): New function split
out from...
(tree_to_aff_combination): ... here.
(aff_combination_expand): Avoid building a GENERIC tree.

Index: gcc/tree-affine.c
===
--- gcc/tree-affine.c   (revision 266956)
+++ gcc/tree-affine.c   (working copy)
@@ -259,101 +259,56 @@ aff_combination_convert (aff_tree *comb,
 }
 }
 
-/* Splits EXPR into an affine combination of parts.  */
+/* Tries to handle OP0 CODE OP1 as affine combination of parts.  Returns
+   true when that was successful and returns the combination in COMB.  */
 
-void
-tree_to_aff_combination (tree expr, tree type, aff_tree *comb)
+static bool
+expr_to_aff_combination (aff_tree *comb, tree_code code, tree type,
+tree op0, tree op1 = NULL_TREE)
 {
   aff_tree tmp;
-  enum tree_code code;
-  tree cst, core, toffset;
   poly_int64 bitpos, bitsize, bytepos;
-  machine_mode mode;
-  int unsignedp, reversep, volatilep;
-
-  STRIP_NOPS (expr);
 
-  code = TREE_CODE (expr);
   switch (code)
 {
 case POINTER_PLUS_EXPR:
-  tree_to_aff_combination (TREE_OPERAND (expr, 0), type, comb);
-  tree_to_aff_combination (TREE_OPERAND (expr, 1), sizetype, &tmp);
+  tree_to_aff_combination (op0, type, comb);
+  tree_to_aff_combination (op1, sizetype, &tmp);
   aff_combination_add (comb, &tmp);
-  return;
+  return true;
 
 case PLUS_EXPR:
 case MINUS_EXPR:
-  tree_to_aff_combination (TREE_OPERAND (expr, 0), type, comb);
-  tree_to_aff_combination (TREE_OPERAND (expr, 1), type, &tmp);
+  tree_to_aff_combination (op0, type, comb);
+  tree_to_aff_combination (op1, type, &tmp);
   if (code == MINUS_EXPR)
aff_combination_scale (&tmp, -1);
   aff_combination_add (comb, &tmp);
-  return;
+  return true;
 
 case MULT_EXPR:
-  cst = TREE_OPERAND (expr, 1);
-  if (TREE_CODE (cst) != INTEGER_CST)
+  if (TREE_CODE (op1) != INTEGER_CST)
break;
-  tree_to_aff_combination (TREE_OPERAND (expr, 0), type, comb);
-  aff_combination_scale (comb, wi::to_widest (cst));
-  return;
+  tree_to_aff_combination (op0, type, comb);
+  aff_combination_scale (comb, wi::to_widest (op1));
+  return true;
 
 case NEGATE_EXPR:
-  tree_to_aff_combination (TREE_OPERAND (expr, 0), type, comb);
+  tree_to_aff_combination (op0, type, comb);
   aff_combination_scale (comb, -1);
-  return;
+  return true;
 
 case BIT_NOT_EXPR:
   /* ~x = -x - 1 */
-  tree_to_aff_combination (TREE_OPERAND (expr, 0), type, comb);
+  tree_to_aff_combination (op0, type, comb);
   aff_combination_scale (comb, -1);
   aff_combination_add_cst (comb, -1);
-  return;
-
-case ADDR_EXPR:
-  /* Handle &MEM[ptr + CST] which is equivalent to POINTER_PLUS_EXPR.  */
-  if (TREE_CODE (TREE_OPERAND (expr, 0)) == MEM_REF)
-   {
- expr = TREE_OPERAND (expr, 0);
- tree_to_aff_combination (TREE_OPERAND (expr, 0), type, comb);
- tree_to_aff_combination (TREE_OPERAND (expr, 1), sizetype, &tmp);
- aff_combination_add (comb, &tmp);
- return;
-   }
-  core = get_inner_reference (TREE_OPERAND (expr, 0), &bitsize, &bitpos,
- &toffset, &mode, &unsignedp, &reversep,
- &volatilep);
-  if (!multiple_p (bitpos, BITS_PER_UNIT, &bytepos))
-   break;
-  aff_combination_const (comb, type, bytepos);
-  if (TREE_CODE (core) == MEM_REF)
-   {
- tree mem_offset = TREE_OPERAND (core, 1);
- aff_combination_add_cst (comb, wi::to_poly_widest (mem_offset));
- core = TREE_OPERAND (core, 0);
-   }
-  else
-   core = build_fold_addr_expr (core);
-
-  if (TREE_CODE (core) == ADDR_EXPR)
-   aff_combination_add_elt (comb, core, 1);
-  else
-   {
- tree_to_aff_combination (core, type, &tmp);
- aff_combination_add (comb, &tmp);
-   }
-  if (toffset)
-   {
- tree_to_aff_combination (toffset, type, &tmp);
- aff_combination_add (comb, &tmp);
-   }
-  return;
+  return true;
 
 CASE_CONVERT:
   {
-   tree otype = TREE_TYPE (expr);
-   tree inner = TREE_OPERAND (expr, 0);
+   tree otype = type;
+   tree inner = op0;
tree itype = TREE_TYPE (inner);
enum tree_code icode = TREE_CODE (inner);
 
@@ -376,9 +331,7 @@ tree_to_aff_combination (tree expr, tree
  {
op0 = fold_convert (otype, op0);
op1 = fold_convert (otype, op1);
-  

Re: [PATCH] Set DEMANGLE_RECURSION_LIMIT to 1536

2018-12-11 Thread Pedro Alves
On 12/11/2018 12:33 AM, Jeff Law wrote:

> Actually I would strongly suggest avoiding alloca completely.  This
> isn't particularly performance sensitive code 

On the contrary, the demangler is very performance-sensitive code for GDB.

See 
and Tromey's response.

> and alloca can be abused
> in all kinds of interesting ways.

Thanks,
Pedro Alves


Re: [PATCH] Set DEMANGLE_RECURSION_LIMIT to 1536

2018-12-11 Thread Pedro Alves
On 12/11/2018 06:58 AM, Jakub Jelinek wrote:
> On Mon, Dec 10, 2018 at 05:33:19PM -0700, Jeff Law wrote:
 where di.num_comps is just strlen (mangled) * 2.  Without any analysis
 whatsoever, bumping the "recursion" limit will just mean we can process 1.5
 times long names.  Either we need more precise analysis on what we are
 looking for (how big arrays we'll need) or it needs to be an independent
 limit and certainly should allow say 10KB symbols too if they are
 reasonable.
>>>
>>> If the problem is alloca, we could avoid using alloca if the size
>>> passes a threshold.  Perhaps even use a better data structure than a
>>> preallocated array based on a guess about the number of components...
>> Actually I would strongly suggest avoiding alloca completely.  This
>> isn't particularly performance sensitive code and alloca can be abused
>> in all kinds of interesting ways.
> 
> We can't use malloc, 

I noticed that the comment on top of __cxa_demangle says:

  "If OUTPUT_BUFFER is not long enough, it is expanded using realloc."

and __cxa_demangle calls 'free'.

And d_demangle, seemingly the workhorse for __cxa_demangle says:

/* Entry point for the demangler.  If MANGLED is a g++ v3 ABI mangled
   name, return a buffer allocated with malloc holding the demangled
   name.  OPTIONS is the usual libiberty demangler options.  On
   success, this sets *PALC to the allocated size of the returned
   buffer.  On failure, this sets *PALC to 0 for a bad name, or 1 for
   a memory allocation failure, and returns NULL.  */

cplus_demangle, the entry point that gdb uses, also relies on malloc.

Ian earlier mentioned that we've wanted to avoid malloc because some
programs call the demangler from a signal handler, but it seems like
we already do, these functions already aren't safe to use from
signal handlers as is.  Where does the "we can't use malloc" idea
come from?  Is there some entry point that avoids
the malloc/realloc/free calls?

Not advocating for adding to the number of malloc calls willy-nilly BTW.
I'd prefer to reduce the number of mallocs/rellocs calls within the
demangler and also within the bfd_demangle wrapper, for performance
reasons, for example by making it possible to reuse a growing buffer
across demangling invocations.

> therefore on some targets alloca (or VLAs) are the only
> option, and for small sizes even if mmap is available using it is too
> costly.
> 
> Though, I like Jason's suggestion of just adding a maxinum of the number
> of components and number of substitutions and failing if we need more.
> 
>   Jakub

Thanks,
Pedro Alves


[PATCH] Fix PR88448

2018-12-11 Thread Richard Biener


The following should fix PR88448, I've reverted the semantics changing
part of the gimple_assign_set_rhs_* previous change settling for
an alternate fix for the tree-complex.c issue.

Bootstrap & regtest in progress on x86_64-unknown-linux-gnu.

Richard.

2018-12-11  Richard Biener  

PR middle-end/88448
PR middle-end/88415
* gimple.c (gimple_assign_set_rhs_with_ops): Revert previous
change.
* tree-complex.c (update_complex_assignment): Properly transfer
or clean EH info around gimple_assign_set_rhs_with_ops.

Index: gcc/gimple.c
===
--- gcc/gimple.c(revision 266975)
+++ gcc/gimple.c(working copy)
@@ -1752,7 +1752,7 @@ gimple_assign_set_rhs_with_ops (gimple_s
   if (new_rhs_ops > 2)
 gimple_assign_set_rhs3 (stmt, op3);
   if (stmt != old_stmt)
-gsi_replace (gsi, stmt, true);
+gsi_replace (gsi, stmt, false);
 }
 
 
Index: gcc/tree-complex.c
===
--- gcc/tree-complex.c  (revision 266975)
+++ gcc/tree-complex.c  (working copy)
@@ -698,12 +698,11 @@ update_complex_components_on_edge (edge
 static void
 update_complex_assignment (gimple_stmt_iterator *gsi, tree r, tree i)
 {
-  gimple *stmt;
-
+  gimple *old_stmt = gsi_stmt (*gsi);
   gimple_assign_set_rhs_with_ops (gsi, COMPLEX_EXPR, r, i);
-  stmt = gsi_stmt (*gsi);
+  gimple *stmt = gsi_stmt (*gsi);
   update_stmt (stmt);
-  if (maybe_clean_eh_stmt (stmt))
+  if (maybe_clean_or_replace_eh_stmt (old_stmt, stmt))
 bitmap_set_bit (need_eh_cleanup, gimple_bb (stmt)->index);
 
   update_complex_components (gsi, gsi_stmt (*gsi), r, i);


[aarch64] PR target/87369 Prefer bsl/bit/bif for copysign

2018-12-11 Thread Richard Earnshaw (lists)
The copysign operations will almost always be performed on values in
floating-point registers.  As such, we do not want the compiler to
simplify the operations into code sequences that can only be done using
the general-purpose register set.  Unfortunately, this is what is
currently happening.

Fortunately, it seems quite unlikely that copysign() will be
subsequently followed by other logical operations on the values
involved, so I think it is acceptable to use an unspec here.  This
allows us to preserve the operation in a form that allows the register
allocator to make the right choice later on, without limitation on the
final form of the operation (well, if we do end up using the gp register
bank, we get a dead constant load that we cannot easily eliminate at a
late stage).

PR target/37369
* config/aarch64/iterators.md (sizem1): Add sizes for SFmode and DFmode.
(Vbtype): Add SFmode mapping.
* config/aarch64/aarch64.md (copysigndf3, copysignsf3): Delete.
(copysign3): New expand pattern.
(copysign3_insn): New insn pattern.

Applied to trunk

R.
diff --git a/gcc/config/aarch64/aarch64.md b/gcc/config/aarch64/aarch64.md
index 82af4d47f78..6657316c5dd 100644
--- a/gcc/config/aarch64/aarch64.md
+++ b/gcc/config/aarch64/aarch64.md
@@ -222,6 +222,7 @@ (define_c_enum "unspec" [
 UNSPEC_FADDA
 UNSPEC_REV_SUBREG
 UNSPEC_SPECULATION_TRACKER
+UNSPEC_COPYSIGN
 ])
 
 (define_c_enum "unspecv" [
@@ -5987,49 +5988,47 @@ (define_expand "lrint2"
 ;;   LDR d2, #(1 << 63)
 ;;   BSL v2.8b, [y], [x]
 ;;
-;; or another, equivalent, sequence using one of BSL/BIT/BIF.
-;; aarch64_simd_bsldf will select the best suited of these instructions
-;; to generate based on register allocation, and knows how to partially
-;; constant fold based on the values of X and Y, so expand through that.
-
-(define_expand "copysigndf3"
-  [(match_operand:DF 0 "register_operand")
-   (match_operand:DF 1 "register_operand")
-   (match_operand:DF 2 "register_operand")]
+;; or another, equivalent, sequence using one of BSL/BIT/BIF.  Because
+;; we expect these operations to nearly always operate on
+;; floating-point values, we do not want the operation to be
+;; simplified into a bit-field insert operation that operates on the
+;; integer side, since typically that would involve three inter-bank
+;; register copies.  As we do not expect copysign to be followed by
+;; other logical operations on the result, it seems preferable to keep
+;; this as an unspec operation, rather than exposing the underlying
+;; logic to the compiler.
+
+(define_expand "copysign3"
+  [(match_operand:GPF 0 "register_operand")
+   (match_operand:GPF 1 "register_operand")
+   (match_operand:GPF 2 "register_operand")]
   "TARGET_FLOAT && TARGET_SIMD"
 {
-  rtx mask = gen_reg_rtx (DImode);
-  emit_move_insn (mask, GEN_INT (HOST_WIDE_INT_1U << 63));
-  emit_insn (gen_aarch64_simd_bsldf (operands[0], mask,
- operands[2], operands[1]));
+  rtx bitmask = gen_reg_rtx (mode);
+  emit_move_insn (bitmask, GEN_INT (HOST_WIDE_INT_M1U
+<< (GET_MODE_BITSIZE (mode) - 1)));
+  emit_insn (gen_copysign3_insn (operands[0], operands[1], operands[2],
+   bitmask));
   DONE;
 }
 )
 
-;; As above, but we must first get to a 64-bit value if we wish to use
-;; aarch64_simd_bslv2sf.
-
-(define_expand "copysignsf3"
-  [(match_operand:SF 0 "register_operand")
-   (match_operand:SF 1 "register_operand")
-   (match_operand:SF 2 "register_operand")]
+(define_insn "copysign3_insn"
+  [(set (match_operand:GPF 0 "register_operand" "=w,w,w,r")
+	(unspec:GPF [(match_operand:GPF 1 "register_operand" "w,0,w,r")
+		 (match_operand:GPF 2 "register_operand" "w,w,0,0")
+		 (match_operand: 3 "register_operand" "0,w,w,X")]
+	 UNSPEC_COPYSIGN))]
   "TARGET_FLOAT && TARGET_SIMD"
-{
-  rtx v_bitmask = gen_reg_rtx (V2SImode);
-
-  /* Juggle modes to get us in to a vector mode for BSL.  */
-  rtx op1 = lowpart_subreg (DImode, operands[1], SFmode);
-  rtx op2 = lowpart_subreg (V2SFmode, operands[2], SFmode);
-  rtx tmp = gen_reg_rtx (V2SFmode);
-  emit_move_insn (v_bitmask,
-		  aarch64_simd_gen_const_vector_dup (V2SImode,
-		 HOST_WIDE_INT_M1U << 31));
-  emit_insn (gen_aarch64_simd_bslv2sf (tmp, v_bitmask, op2, op1));
-  emit_move_insn (operands[0], lowpart_subreg (SFmode, tmp, V2SFmode));
-  DONE;
-}
+  "@
+   bsl\\t%0., %2., %1.
+   bit\\t%0., %2., %3.
+   bif\\t%0., %1., %3.
+   bfxil\\t%0, %1, #0, "
+  [(set_attr "type" "neon_bsl,neon_bsl,neon_bsl,bfm")]
 )
 
+
 ;; For xorsign (x, y), we want to generate:
 ;;
 ;; LDR   d2, #1<<63
diff --git a/gcc/config/aarch64/iterators.md b/gcc/config/aarch64/iterators.md
index a80755734d6..ae75666167d 100644
--- a/gcc/config/aarch64/iterators.md
+++ b/gcc/config/aarch64/iterators.md
@@ -601,7 +601,8 @@ (define_mode_attr size [(QI "b") (HI "h") (SI "w")])
 (define_mode_attr sizen [(QI "8") (HI "16") (SI "32") (DI "64")])
 
 ;; Give the ordinal of the MSB in the mode
-(define_mode_attr 

[Ada] Suppress call to Initial_Condition when the annotation is ignored

2018-12-11 Thread Pierre-Marie de Rodat
This patch suppresses the generation of the Initial_Condition procedure
tasked with verifying the run-time semantics of the pragma when the
pragma is ignored by means of -gnata, pragma Assertion_Policy, etc.


-- Source --


--  all_asserts_off.adc

pragma Assertion_Policy (Ignore);

--  all_asserts_on.adc

pragma Assertion_Policy (Check);

--  ic_off.adc

pragma Assertion_Policy (Initial_Condition => Ignore);

--  ic_on.adc

pragma Assertion_Policy (Initial_Condition => Check);

--  init_cond.ads

package Init_Cond
  with SPARK_Mode,
   Initial_Condition => Flag = False
is
   Flag : Boolean := True;

   procedure Set_Flag;
end Init_Cond;

--  init_cond.adb

package body Init_Cond
  with SPARK_Mode
is
   procedure Set_Flag is
   begin
  Flag := True;
   end Set_Flag;
end Init_Cond;


-- Compilation and output --


& gcc  -c -S -gnatDG init_cond.adb -gnatec=all_asserts_on.adc
& grep -c "Initial_Condition;" init_cond.adb.dg
& grep -c "_elabb" init_cond.s
& gcc  -c -S -gnatDG init_cond.adb -gnatec=ic_on.adc
& grep -c "Initial_Condition;" init_cond.adb.dg
& grep -c "_elabb" init_cond.s
& gcc  -c -S -gnatDG init_cond.adb -gnatec=all_asserts_off.adc
& grep -c "Initial_Condition;" init_cond.adb.dg
& grep -c "_elabb" init_cond.s
& gcc  -c -S -gnatDG init_cond.adb -gnatec=ic_off.adc
& grep -c "Initial_Condition;" init_cond.adb.dg
& grep -c "_elabb" init_cond.s
2
4
2
4
0
0
0
0

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

2018-12-11  Hristian Kirtchev  

gcc/ada/

* exp_prag.adb (Expand_Pragma_Initial_Condition): Do not
generate an Initial_Condition procedure and a call to it when
the associated pragma is ignored.
* sem_ch10.adb (Analyze_Compilation_Unit): Minor cleanup.--- gcc/ada/exp_prag.adb
+++ gcc/ada/exp_prag.adb
@@ -1636,10 +1636,16 @@ package body Exp_Prag is
   Expr := Get_Pragma_Arg (First (Pragma_Argument_Associations (IC_Prag)));
   Loc  := Sloc (IC_Prag);
 
+  --  Nothing to do when the pragma is ignored because its semantics are
+  --  suppressed.
+
+  if Is_Ignored (IC_Prag) then
+ return;
+
   --  Nothing to do when the pragma or its argument are illegal because
   --  there is no valid expression to check.
 
-  if Error_Posted (IC_Prag) or else Error_Posted (Expr) then
+  elsif Error_Posted (IC_Prag) or else Error_Posted (Expr) then
  return;
   end if;
 

--- gcc/ada/sem_ch10.adb
+++ gcc/ada/sem_ch10.adb
@@ -1203,8 +1203,6 @@ package body Sem_Ch10 is
 --  binder generated code of all the units involved in a partition
 --  when control-flow preservation is requested.
 
---  Case of units which do not require an elaboration entity
-
 if not Opt.Suppress_Control_Flow_Optimizations
   and then
   ( --  Pure units do not need checks
@@ -1232,16 +1230,16 @@ package body Sem_Ch10 is
 or else Acts_As_Spec (N)
   )
 then
-   --  This is a case where we only need the entity for
-   --  checking to prevent multiple elaboration checks.
+   --  This is a case where we only need the entity for checking to
+   --  prevent multiple elaboration checks.
 
Set_Elaboration_Entity_Required (Spec_Id, False);
 
---  Case of elaboration entity is required for access before
---  elaboration checking (so certainly we must build it).
+--  Otherwise the unit requires an elaboration entity because it
+--  carries a body.
 
 else
-   Set_Elaboration_Entity_Required (Spec_Id, True);
+   Set_Elaboration_Entity_Required (Spec_Id);
 end if;
 
 Build_Elaboration_Entity (N, Spec_Id);



[Ada] Crash on nesting of subunits with bodies acting as specs

2018-12-11 Thread Pierre-Marie de Rodat
This patch corrects an issue whereby a set of nested subunits including
subprogram subunits acting as bodies would cause a crash when a child
subunit "withs" an ansestor in certain instances due to a mismanagment
of the scope stack.


-- Source --


--  w.ads

package W is
end;

--  w-b.ads

package W.B is
  pragma Elaborate_Body;
end;

--  w-b.adb

with W.B.C;

package body w.B is end;

--  w-b-c.adb

with W;
procedure W.B.C is
  package D is
procedure E;
  end;
  package body D is separate;
begin
  null;
end;

--  w-b-c-d.adb

separate (W.B.C)
package body D is
  procedure E is separate;
end;

--  w-b-c-d-e.adb

with W;

separate (W.B.C.D)
procedure E is
begin
  null;
end;

-
-- Compilation --
-

$ gnatmake -q w-b.adb

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

2018-12-11  Justin Squirek  

gcc/ada/

* sem_ch10.adb (Analyze_Subunit): Modify conditional to fully
remove parent contexts from library-level subprogram bodies in
addition to package bodies.--- gcc/ada/sem_ch10.adb
+++ gcc/ada/sem_ch10.adb
@@ -2352,7 +2352,9 @@ package body Sem_Ch10 is
Remove_Scope;
 end if;
 
-if Nkind (Unit (Lib_Spec)) = N_Package_Body then
+if Nkind_In
+ (Unit (Lib_Spec), N_Package_Body, N_Subprogram_Body)
+then
Remove_Context (Library_Unit (Lib_Spec));
 end if;
  end if;



[Ada] Fix an ICE on instantiated subprogram with -gnatc

2018-12-11 Thread Pierre-Marie de Rodat
The following should compile quietly:

$ gcc -c p-proc.ads -gnatc

procedure P.Proc is new G;

with Q;

package P is

  generic procedure G;

end P;

with System;
with Unchecked_Conversion;

package Q is

  generic package Inner_G is

type T is access all Integer;

function Cnv is new Unchecked_Conversion (System.Address, T);

  end Inner_G;

end Q;

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

2018-12-11  Eric Botcazou  

gcc/ada/

* gcc-interface/trans.c (elaborate_all_entities_for_package):
Skip aliasing subprograms.--- gcc/ada/gcc-interface/trans.c
+++ gcc/ada/gcc-interface/trans.c
@@ -9278,7 +9278,9 @@ elaborate_all_entities_for_package (Entity_Id gnat_package)
 	continue;
   if (kind == E_Operator)
 	continue;
-  if (IN (kind, Subprogram_Kind) && Is_Intrinsic_Subprogram (gnat_entity))
+  if (IN (kind, Subprogram_Kind)
+	  && (Present (Alias (gnat_entity))
+	  || Is_Intrinsic_Subprogram (gnat_entity)))
 	continue;
   if (Is_Itype (gnat_entity))
 	continue;



[Ada] Remove vxworks*-crtbe-link.spec

2018-12-11 Thread Pierre-Marie de Rodat
The VxWorks crtbe are now part of libgcc, needed to support C++ on this
target.

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

2018-12-11  Jerome Lambourg  

gcc/ada/

* Makefile.rtl, gcc-interface/Makefile.in: Remove crtbe bits for
VxWorks.
* libgnat/system-vxworks-arm-rtp-smp.ads,
libgnat/system-vxworks-arm-rtp.ads,
libgnat/system-vxworks-arm.ads,
libgnat/system-vxworks-e500-kernel.ads,
libgnat/system-vxworks-e500-rtp-smp.ads,
libgnat/system-vxworks-e500-rtp.ads,
libgnat/system-vxworks-ppc-kernel.ads,
libgnat/system-vxworks-ppc-rtp-smp.ads,
libgnat/system-vxworks-ppc-rtp.ads,
libgnat/system-vxworks-ppc.ads,
libgnat/system-vxworks-x86-kernel.ads,
libgnat/system-vxworks-x86-rtp-smp.ads,
libgnat/system-vxworks-x86-rtp.ads,
libgnat/system-vxworks7-aarch64-rtp-smp.ads,
libgnat/system-vxworks7-aarch64.ads,
libgnat/system-vxworks7-arm-rtp-smp.ads,
libgnat/system-vxworks7-e500-kernel.ads,
libgnat/system-vxworks7-e500-rtp-smp.ads,
libgnat/system-vxworks7-e500-rtp.ads,
libgnat/system-vxworks7-ppc-kernel.ads,
libgnat/system-vxworks7-ppc-rtp-smp.ads,
libgnat/system-vxworks7-ppc-rtp.ads,
libgnat/system-vxworks7-ppc64-kernel.ads,
libgnat/system-vxworks7-ppc64-rtp-smp.ads,
libgnat/system-vxworks7-x86-kernel.ads,
libgnat/system-vxworks7-x86-rtp-smp.ads,
libgnat/system-vxworks7-x86-rtp.ads,
libgnat/system-vxworks7-x86_64-kernel.ads,
libgnat/system-vxworks7-x86_64-rtp-smp.ads: Remove pragma
Linker_Options for --specs.
* vx_crtbegin.c, vx_crtbegin.inc, vx_crtbegin_array.c,
vx_crtbegin_attr.c, vx_crtend.c, vxworks-gnat-crtbe-link.spec:
Remove.--- gcc/ada/Makefile.rtl
+++ gcc/ada/Makefile.rtl
@@ -857,16 +857,6 @@ VX_SIGTRAMP_EXTRA_SRCS=sigtramp.h sigtramp-vxworks-target.inc
 # aside the library itself. Typically useful for crtbegin/crtend kind of files.
 EXTRA_ADALIB_OBJS=
 
-# crt files for VxWorks exception tables registration, referenced by
-# spec files in the runtime library.
-VX_CRTBE_EXTRA_ADALIB_OBJS=vx_crtbegin.o vx_crtbegin_array.o vx_crtend.o
-
-# Contructor attributes (with priorities) are only supported on VxWorks 7
-# or for RTPs.
-ifneq ($(strip $(filter vxworks7% rtp%,$(target_os) $(THREAD_KIND))),)
-VX_CRTBE_EXTRA_ADALIB_OBJS+=vx_crtbegin_attr.o
-endif
-
 # GCC spec files to be installed in $(libsubdir), so --specs=
 # finds them at runtime.
 GCC_SPEC_FILES=
@@ -894,7 +884,6 @@ ifeq ($(strip $(filter-out powerpc% wrs vxworks vxworksspe vxworks7 vxworks7spe,
 
   VX=$(strip $(if $(filter vxworks7%, $(target_os)), vxworks7, vxworks))
   SVX=system-$(VX)
-  GCC_SPEC_FILES+=$(VX)-gnat-crtbe-link.spec
 
   LIBGNAT_TARGET_PAIRS = \
   a-intnam.ads $(RTSDIR)/s.ads
 	$(MV) $(RTSDIR)/s.ads $(RTSDIR)/system.ads
 	$(MAKE) $(FLAGS_TO_PASS) \
@@ -936,21 +935,6 @@ init.o: init.c adaint.h raise.h
 	$(COMPILER) -c $(ALL_COMPILERFLAGS) $(ADA_CFLAGS) \
 	 $(ALL_CPPFLAGS) $(INCLUDES) $< $(OUTPUT_OPTION)
 
-vx_crtbegin.o : vx_crtbegin.c vx_crtbegin.inc
-	$(COMPILER) -c $(ALL_COMPILERFLAGS) $(ADA_CFLAGS) \
-		 -iquote $(srcdir) -iquote $(ftop_srcdir)/libgcc \
-	 $(ALL_CPPFLAGS) $(INCLUDES) $< $(OUTPUT_OPTION)
-
-vx_crtbegin_auto.o : vx_crtbegin_auto.c vx_crtbegin.inc
-	$(COMPILER) -c $(ALL_COMPILERFLAGS) $(ADA_CFLAGS) \
-		 -iquote $(srcdir) -iquote $(ftop_srcdir)/libgcc \
-	 $(ALL_CPPFLAGS) $(INCLUDES) $< $(OUTPUT_OPTION)
-
-vx_crtend.o : vx_crtend.c
-	$(COMPILER) -c $(ALL_COMPILERFLAGS) $(ADA_CFLAGS) \
-		 -iquote $(srcdir) -iquote $(ftop_srcdir)/libgcc \
-	 $(ALL_CPPFLAGS) $(INCLUDES) $< $(OUTPUT_OPTION)
-
 init-vxsim.o : init-vxsim.c
 	$(COMPILER) -c $(ALL_COMPILERFLAGS) $(ADA_CFLAGS) \
 	 $(ALL_CPPFLAGS) $(INCLUDES) $< $(OUTPUT_OPTION)

--- gcc/ada/libgnat/system-vxworks-arm-rtp-smp.ads
+++ gcc/ada/libgnat/system-vxworks-arm-rtp-smp.ads
@@ -120,10 +120,6 @@ package System is
 
 private
 
-   pragma Linker_Options ("--specs=vxworks-gnat-crtbe-link.spec");
-   --  Pull in crtbegin/crtend objects and register exceptions for ZCX.
-   --  This is commented out by our Makefile for SJLJ runtimes.
-
pragma Linker_Options ("--specs=vxworks-smp-arm-link.spec");
pragma Linker_Options ("--specs=vxworks-arm-link.spec");
--  Setup proper set of -L's for this configuration

--- gcc/ada/libgnat/system-vxworks-arm-rtp.ads
+++ gcc/ada/libgnat/system-vxworks-arm-rtp.ads
@@ -120,10 +120,6 @@ package System is
 
 private
 
-   pragma Linker_Options ("--specs=vxworks-gnat-crtbe-link.spec");
-   --  Pull in crtbegin/crtend objects and register exceptions for ZCX.
-   --  This is commented out by our Makefile for SJLJ runtimes.
-
pragma Linker_Options ("--specs=vxworks-arm-link.spec");
--  Setup proper set of -L's for this configuration
 

--- gcc/ada/libgnat/system-vxworks-arm.ads
+++ gcc/ada/libgnat/sys

[Ada] Spurious visibility error on aspect Predicate

2018-12-11 Thread Pierre-Marie de Rodat
The GNAT-defined aspect Predicate has the same semantics as the Ada
aspect Dynamic_Predicate, including direct visibility to the components
of a record type to which the aspect applies.

The following must compile quietly:

   gcc -c integer_stacks.ads


pragma SPARK_Mode (On);

with Bounded_Stacks;
package Integer_Stacks is
 new Bounded_Stacks (Element => Integer, Default_Element => 0);

generic
   type Element is private;
   Default_Element : Element;
package Bounded_Stacks is

   type Stack (Capacity : Positive) is tagged private
  with Default_Initial_Condition => Empty (Stack);

   function "=" (Left, Right : Stack) return Boolean;

   function Extent (This : Stack) return Natural;

   function Empty (This : Stack) return Boolean;

   function Full (This : Stack) return Boolean;

   procedure Reset (This : out Stack) with
 Post'Class => Empty (This) and
   not Full (This),
 Global => null,
 Depends=> (This =>+ null);

   procedure Push (This : in out Stack;  Item : Element) with
 Pre'Class  => not Full (This) and
   Extent (This) < This.Capacity,
 Post'Class => not Empty (This) and
   Extent (This) = Extent (This'Old) + 1,
 Global => null,
 Depends=> (This =>+ Item);

   procedure Pop (This : in out Stack;  Item : out Element) with
 Pre'Class  => not Empty (This),
 Post'Class => not Full (This) and
   Extent (This) = Extent (This'Old) - 1,
 Global => null,
 Depends=> (This =>+ null, Item => This);

   function Peek (This : Stack) return Element with
 Pre'Class => not Empty (This),
 Global=> null,
 Depends   => (Peek'Result => This);

private

   type Contents is array (Positive range <>) of Element;

   type Stack (Capacity : Positive) is tagged record
  Values : Contents (1 .. Capacity); -- := (others => Default_Element);
--Top: Natural;
  Top: Natural := 0;
   end record with Predicate => Top <= Capacity,
 Annotate => (GNATprove,
  Intentional,
  "type ""Stack"" is not fully initialized",
  "Because zeroing Top is sufficient");

end Bounded_Stacks;

package body Bounded_Stacks is

   
   -- Extent --
   

   function Extent (This : Stack) return Natural is
 (This.Top);

   ---
   -- Empty --
   ---

   function Empty (This : Stack) return Boolean is
 (This.Top = 0);

   --
   -- Full --
   --

   function Full (This : Stack) return Boolean is
 (This.Top = This.Capacity);

   ---
   -- Reset --
   ---

   procedure Reset (This : out Stack) is
   begin
  This := (This.Capacity, Top => 0, others => <>);
--This.Top := 0;
   end Reset;

   --
   -- Push --
   --

   procedure Push (This : in out Stack;  Item : Element) is
   begin
  This.Top := This.Top + 1;
  This.Values (This.Top) := Item;
   end Push;

   -
   -- Pop --
   -

   procedure Pop (This : in out Stack;  Item : out Element) is
   begin
  Item := This.Values (This.Top);
  This.Top := This.Top - 1;
   end Pop;

   --
   -- Peek --
   --

   function Peek (This : Stack) return Element is
 (This.Values (This.Top));

   -
   -- "=" --
   -

   function "=" (Left, Right : Stack) return Boolean is
   begin
  if Left.Top /= Right.Top then
 return False;
  else
 for K in 1 .. Left.Top loop
if Left.Values (K) /= Right.Values (K) then
   return False;
end if;
 end loop;
 return True;
  end if;
   end "=";

end Bounded_Stacks;


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

2018-12-11  Ed Schonberg  

gcc/ada/

* sem_ch13.adb (Check_Aspect_At_End_Of_Declarations,
Freeze_Entity_Checks): Process aspect Predicate in the same
fashion as aspect Dynamic_Predicate.--- gcc/ada/sem_ch13.adb
+++ gcc/ada/sem_ch13.adb
@@ -9364,6 +9364,7 @@ package body Sem_Ch13 is
  --  components and discriminants of the type.
 
  elsif A_Id  = Aspect_Dynamic_Predicate
+   or else A_Id = Aspect_Predicate
or else A_Id = Aspect_Priority
  then
 Push_Type (Ent);
@@ -11252,6 +11253,7 @@ package body Sem_Ch13 is
then
   A_Id := Get_Aspect_Id (Ritem);
   if A_Id = Aspect_Dynamic_Predicate
+or else A_Id = Aspect_Predicate
 or else A_Id = Aspect_Priority
   then
 --  Retrieve the visibility to components and discriminants



[Ada] Spurious errors on aspect specifications in generic units

2018-12-11 Thread Pierre-Marie de Rodat
This patch fixes spurious errors on aspect specifications on record
types when the aspect expression references a component of the type that
is not a discriminant. The patch also cleans up the legality checks on
aspect specifications, and improves error message on illegal aspect
specifications whose expressions are not conformant between
specification and freeze point, because of changes in visibility.

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

2018-12-11  Ed Schonberg  

gcc/ada/

* sem_ch13.adb (Push_Type, Pop_Type): New procedures, used for
analysis of aspect expressions for record types, whose
components (not only discriminants) may be referenced in aspect
expressions.
(Analyze_Aspect_Specifications, Analyze_Aspects_At_Freeze_Point,
Analyze_Aspect_At_End-Of_Declarations,
Resolve_Aspect_Expressions): Use the new subprograms.
(Check_Aspect_At_End_Of_Declarations): Improve error message.
(Build_Predicate_Functions): Do not build their bodies in a
generic unit.
(Is_Derived_Type_With_Constraint): New subprogram to uncover and
reject aspect specificationss on types that appear after the
type is frozen.
* sem_ch13.ads (Push_Scope_And_Install_Discriminants,
Uninstall_Discriminants_And_Pop_Scope): Remove.
* sem_ch6.adb, sem_ch6.ads (Fully_Conformant_Expressions):
Additional parameter to improve error message on illegal aspect
specifications whose resolution differ between aspect
specification and freeze point.
* freeze.adb: Remove references to
Install/Uninstall_Discriminants.

gcc/testsuite/

* gnat.dg/aspect1.adb, gnat.dg/aspect1_horizontal.adb,
gnat.dg/aspect1_horizontal.ads, gnat.dg/aspect1_vectors_2d.ads:
New testcase.
* gnat.dg/static_pred1.adb: Expect an error message.--- gcc/ada/freeze.adb
+++ gcc/ada/freeze.adb
@@ -1938,12 +1938,6 @@ package body Freeze is
 --  for a description of how we handle aspect visibility).
 
 elsif Has_Delayed_Aspects (E) then
-
-   --  Retrieve the visibility to the discriminants in order to
-   --  analyze properly the aspects.
-
-   Push_Scope_And_Install_Discriminants (E);
-
declare
   Ritem : Node_Id;
 
@@ -1960,8 +1954,6 @@ package body Freeze is
  Ritem := Next_Rep_Item (Ritem);
   end loop;
end;
-
-   Uninstall_Discriminants_And_Pop_Scope (E);
 end if;
 
 --  If an incomplete type is still not frozen, this may be a

--- gcc/ada/sem_ch13.adb
+++ gcc/ada/sem_ch13.adb
@@ -230,6 +230,23 @@ package body Sem_Ch13 is
--  is True. This warning inserts the string Msg to describe the construct
--  causing biasing.
 
+   ---
+   --  Visibility of Discriminants in Aspect Specifications --
+   ---
+
+   --  The discriminants of a type are visible when analyzing the aspect
+   --  specifications of a type declaration or protected type declaration,
+   --  but not when analyzing those of a subtype declaration. The following
+   --  routines enforce this distinction.
+
+   procedure Push_Type (E : Entity_Id);
+   --  Push scope E and make visible the discriminants of type entity E if E
+   --  has discriminants and is not a subtype.
+
+   procedure Pop_Type (E : Entity_Id);
+   --  Remove visibility to the discriminants of type entity E and pop the
+   --  scope stack if E has discriminants and is not a subtype.
+
---
-- Table for Validate_Compile_Time_Warning_Error --
---
@@ -1353,6 +1370,13 @@ package body Sem_Ch13 is
   if May_Inherit_Delayed_Rep_Aspects (E) then
  Inherit_Delayed_Rep_Aspects (ASN);
   end if;
+
+  if In_Instance
+and then E /= Base_Type (E)
+and then Is_First_Subtype (E)
+  then
+ Inherit_Rep_Item_Chain (Base_Type (E), E);
+  end if;
end Analyze_Aspects_At_Freeze_Point;
 
---
@@ -5462,11 +5486,12 @@ package body Sem_Ch13 is
   --  described in "Handling of Default and Per-Object
   --  Expressions" in sem.ads.
 
-  --  The visibility to the discriminants must be restored
+  --  The visibility to the components must be established
+  --  and restored before and after analysis.
 
-  Push_Scope_And_Install_Discriminants (U_Ent);
+  Push_Type (U_Ent);
   Preanalyze_Spec_Expression (Expr, RTE (RE_CPU_Range));
-  Uninstall_Discriminants_And_Pop_Scope (U_Ent);
+  Pop_Type (U_Ent);
 
   if not Is_OK_Stat

[Ada] Additionsal trasformations for unnesting in package bodies

2018-12-11 Thread Pierre-Marie de Rodat
This patch extends the previous algorithm for creating an explicit
elaboration procedure for a package body when expansion generates
subprograms in the statement part of the body. For unnesting to work
properly, these subprograms must appear within an explicit subprogram
body so that uplevel references can be placed in the proper activation
record.

Ongoing work for LLVM generation.

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

2018-12-11  Ed Schonberg  

gcc/ada/

* exp_ch7.adb (Check_Unnesting_Elaboration_Code): Extend
algorithm to cover subprograms generated in nested loops and in
exception handlers, in order to build an explicit elaboration
procedure in more complex cases.--- gcc/ada/exp_ch7.adb
+++ gcc/ada/exp_ch7.adb
@@ -3996,15 +3996,23 @@ package body Exp_Ch7 is
--
 
procedure Check_Unnesting_Elaboration_Code (N : Node_Id) is
-  Loc : constant Source_Ptr := Sloc (N);
+  Loc   : constant Source_Ptr := Sloc (N);
+  First_Ent : Entity_Id := Empty;
+  Loop_Id   : Entity_Id := Empty;
 
   function Contains_Subprogram (Blk : Entity_Id) return Boolean;
   --  Check recursively whether a loop or block contains a subprogram that
   --  may need an activation record.
 
   function First_Local_Scope (L : List_Id) return Entity_Id;
-  --  Find first block or loop that contains a subprogram and is not itself
-  --  nested within another local scope.
+  --  Find first entity in the elaboration code of the body that
+  --  contains or represents a subprogrsam body. A body can appear
+  --  within a block or a loop. or can appear by itself if generated
+  --  for an object declaration that involves controlled actions.
+  --  The first such entity encountered is used to reset the scopes
+  --  of all entities that become local to the hew elboration procedure.
+  --  This is needed for subsequent unnesting, which depends on the
+  --  scope links to determine the nesting level of each subprogram.
 
   --
   --  Contains_Subprogram --
@@ -4037,6 +4045,7 @@ package body Exp_Ch7 is
   ---
 
   function First_Local_Scope (L : List_Id) return Entity_Id is
+ Id   : Entity_Id;
  Scop : Entity_Id;
  Stat : Node_Id;
 
@@ -4045,13 +4054,27 @@ package body Exp_Ch7 is
  while Present (Stat) loop
 case Nkind (Stat) is
when N_Block_Statement =>
-  if Present (Identifier (Stat)) then
- return Entity (Identifier (Stat));
+  Id := Entity (Identifier (Stat));
+  if No (First_Ent) then
+ First_Ent := Id;
+  end if;
+
+  if Present (Id) and then Contains_Subprogram (Id) then
+ return Id;
   end if;
 
when N_Loop_Statement =>
-  if Contains_Subprogram (Entity (Identifier (Stat))) then
- return Entity (Identifier (Stat));
+  Id := Entity (Identifier (Stat));
+  if No (First_Ent) then
+ First_Ent := Id;
+  end if;
+
+  if Contains_Subprogram (Id) then
+ if Scope (Id) = Current_Scope then
+Loop_Id := Id;
+ end if;
+
+ return Id;
   end if;
 
when N_If_Statement =>
@@ -4101,7 +4124,12 @@ package body Exp_Ch7 is
   end;
 
when N_Subprogram_Body =>
-  return Defining_Entity (Stat);
+  Id := Defining_Entity (Stat);
+  if No (First_Ent) then
+ First_Ent := Id;
+  end if;
+
+  return Id;
 
when others =>
   null;
@@ -4115,6 +4143,7 @@ package body Exp_Ch7 is
 
   --  Local variables
 
+  H_Seq : constant Node_Id := Handled_Statement_Sequence (N);
   Elab_Body : Node_Id;
   Elab_Call : Node_Id;
   Elab_Proc : Entity_Id;
@@ -4124,11 +4153,30 @@ package body Exp_Ch7 is
 
begin
   if Unnest_Subprogram_Mode
-and then Present (Handled_Statement_Sequence (N))
+and then Present (H_Seq)
 and then Is_Compilation_Unit (Current_Scope)
   then
  Ent :=
-   First_Local_Scope (Statements (Handled_Statement_Sequence (N)));
+   First_Local_Scope (Statements (H_Seq));
+
+ --  There msy be subprograms declared in the exception handlers
+ --  of the current body.
+
+ if No (Ent) and then Present (Exception_Handlers (H_Seq)) then
+declare
+   Handler : Node_Id := First (Exception_Handlers (H_Seq));
+begin
+   while Present (Handler) loop
+  Ent := First_Local_Scop

[Ada] Better error message from GNATprove on illegal switch

2018-12-11 Thread Pierre-Marie de Rodat
When a compilation switch is wrongly passed to GNATprove without the
leading hyphen, this patch issues a clear error message instead of the
obscure 'usage' message previously displayed.

There is no impact on compilation.

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

2018-12-11  Yannick Moy  

gcc/ada/

* gnat1drv.adb (Gnat1drv): Issue specific error message in
GNATprove mode when multiple file names on the command line.
* osint.adb, osint.ads (Dump_Command_Line_Source_File_Names):
New procedure to print file names on the command line.--- gcc/ada/gnat1drv.adb
+++ gcc/ada/gnat1drv.adb
@@ -1161,8 +1161,21 @@ begin
   --  gnat1 is invoked from gcc in the normal case.
 
   if Osint.Number_Of_Files /= 1 then
- Usage;
- Write_Eol;
+
+ --  In GNATprove mode, gcc is not called, so we may end up with
+ --  switches wrongly interpreted as source file names when they are
+ --  written by mistake without a starting hyphen. Issue a specific
+ --  error message but do not print the internal 'usage' message.
+
+ if GNATprove_Mode then
+Write_Str ("one of the following is not a valid switch"
+   & " or source file name: ");
+Osint.Dump_Command_Line_Source_File_Names;
+ else
+Usage;
+Write_Eol;
+ end if;
+
  Osint.Fail ("you must provide one source file");
 
   elsif Usage_Requested then

--- gcc/ada/osint.adb
+++ gcc/ada/osint.adb
@@ -787,6 +787,17 @@ package body Osint is
   end if;
end Dir_In_Src_Search_Path;
 
+   -
+   -- Dump_Command_Line_Source_File_Names --
+   -
+
+   procedure Dump_Command_Line_Source_File_Names is
+   begin
+  for J in 1 .. Number_Of_Files loop
+ Write_Str (File_Names (J).all & " ");
+  end loop;
+   end Dump_Command_Line_Source_File_Names;
+

-- Dump_Source_File_Names --


--- gcc/ada/osint.ads
+++ gcc/ada/osint.ads
@@ -508,6 +508,9 @@ package Osint is
--  (i.e. Include_Dir_Default_Prefix). The text is sent to whatever Output
--  is currently using (e.g. standard output or standard error).
 
+   procedure Dump_Command_Line_Source_File_Names;
+   --  Prints out the names of all source files on the command-line
+
---
-- Representation of Library Information --
---



[Ada] Stubs that complete generic subprogram do have a "prior declaration"

2018-12-11 Thread Pierre-Marie de Rodat
The intuition behind the Is_Subprogram_Stub_Without_Prior_Declaration
utility routine is to detect stubs that act as subprogram declarations
and False on stubs that act as completions. This behaviour is now fixed
for stubs that correspond to generic subprogram declarations.

This patch affects a routine that is only used in GNATprove, so no
frontend test provided. An example where the result changed from True to
False is:

---
-- p.ads --
---

package P is
   generic
   procedure Proc;
end P;

---
-- p.adb --
---

package body P is
   procedure Proc is separate; -- now we return False for this stub
end P;


-- p-proc.adb --


separate (P)
procedure Proc is
begin
   null;
end;

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

2018-12-11  Piotr Trojanek  

gcc/ada/

* sem_util.adb (Is_Subprogram_Stub_Without_Prior_Declaration):
Return False on stubs that complete a generic subprogram.
* sem_util.ads: Update corresponding comment.--- gcc/ada/sem_util.adb
+++ gcc/ada/sem_util.adb
@@ -17471,12 +17471,30 @@ package body Sem_Util is
  (N : Node_Id) return Boolean
is
begin
-  --  A subprogram stub without prior declaration serves as declaration for
-  --  the actual subprogram body. As such, it has an attached defining
-  --  entity of E_[Generic_]Function or E_[Generic_]Procedure.
+  pragma Assert (Nkind (N) = N_Subprogram_Body_Stub);
 
-  return Nkind (N) = N_Subprogram_Body_Stub
-and then Ekind (Defining_Entity (N)) /= E_Subprogram_Body;
+  case Ekind (Defining_Entity (N)) is
+
+ --  A subprogram stub without prior declaration serves as declaration
+ --  for the actual subprogram body. As such, it has an attached
+ --  defining entity of E_Function or E_Procedure.
+
+ when E_Function
+| E_Procedure
+ =>
+return True;
+
+ --  Otherwise, it is completes a [generic] subprogram declaration
+
+ when E_Generic_Function
+| E_Generic_Procedure
+| E_Subprogram_Body
+ =>
+return False;
+
+ when others =>
+raise Program_Error;
+  end case;
end Is_Subprogram_Stub_Without_Prior_Declaration;
 
---

--- gcc/ada/sem_util.ads
+++ gcc/ada/sem_util.ads
@@ -2001,8 +2001,8 @@ package Sem_Util is
 
function Is_Subprogram_Stub_Without_Prior_Declaration
  (N : Node_Id) return Boolean;
-   --  Return True if N is a subprogram stub with no prior subprogram
-   --  declaration.
+   --  Given an N_Subprogram_Body_Stub node N, return True if N is a subprogram
+   --  stub with no prior subprogram declaration.
 
function Is_Suitable_Primitive (Subp_Id : Entity_Id) return Boolean;
--  Determine whether arbitrary subprogram Subp_Id may act as a primitive of



[Ada] Support access types in GNATprove

2018-12-11 Thread Pierre-Marie de Rodat
SPARK RM has been updated to support access types in SPARK. Part of this
support is that now SPARK RM 3.1 lists access types as having full
default initialization. Now updated.

There is no impact on compilation.

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

2018-12-11  Yannick Moy  

gcc/ada/

* sem_util.adb (Has_Full_Default_Initialization): Consider
access types as having full default initialization.--- gcc/ada/sem_util.adb
+++ gcc/ada/sem_util.adb
@@ -10880,6 +10880,11 @@ package body Sem_Util is
   if Is_Scalar_Type (Typ) then
  return Has_Default_Aspect (Typ);
 
+  --  An access type is fully default initialized by default
+
+  elsif Is_Access_Type (Typ) then
+ return True;
+
   --  An array type is fully default initialized if its element type is
   --  scalar and the array type carries aspect Default_Component_Value or
   --  the element type is fully default initialized.



[Ada] Complete implementation of RM C.6(19) clause

2018-12-11 Thread Pierre-Marie de Rodat
This ensures that the compiler fully implements the C.6(19) clause of
the Ada Reference Manual and gives a warning when the clause does change
the passing mechanism of the affected parameter.

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

2018-12-11  Eric Botcazou  

gcc/ada/

* fe.h (Is_Atomic_Object): Declare.
(Is_Volatile_Object): Likewise.
* gcc-interface/trans.c (atomic_or_volatile_copy_required_p):
New.
(Call_to_gnu): Generate a copy for an actual parameter passed by
reference if the conditions set forth by RM C.6(19) are met and
specificially deal with an atomic actual parameter.

gcc/testsuite/

* gnat.dg/atomic11.adb, gnat.dg/atomic11_pkg1.ads,
gnat.dg/atomic11_pkg2.ads: New testcase.--- gcc/ada/fe.h
+++ gcc/ada/fe.h
@@ -281,13 +281,17 @@ extern Boolean Is_OK_Static_Subtype	(Entity_Id);
 #define Defining_Entity			sem_util__defining_entity
 #define First_Actual			sem_util__first_actual
 #define Next_Actual			sem_util__next_actual
+#define Is_Atomic_Object		sem_util__is_atomic_object
 #define Is_Variable_Size_Record 	sem_util__is_variable_size_record
+#define Is_Volatile_Object		sem_util__is_volatile_object
 #define Requires_Transient_Scope	sem_util__requires_transient_scope
 
 extern Entity_Id Defining_Entity	(Node_Id);
 extern Node_Id First_Actual		(Node_Id);
 extern Node_Id Next_Actual		(Node_Id);
+extern Boolean Is_Atomic_Object 	(Node_Id);
 extern Boolean Is_Variable_Size_Record 	(Entity_Id Id);
+extern Boolean Is_Volatile_Object 	(Node_Id);
 extern Boolean Requires_Transient_Scope	(Entity_Id);
 
 /* sinfo: */

--- gcc/ada/gcc-interface/trans.c
+++ gcc/ada/gcc-interface/trans.c
@@ -4936,6 +4936,35 @@ create_init_temporary (const char *prefix, tree gnu_init, tree *gnu_init_stmt,
   return gnu_temp;
 }
 
+/* Return whether ACTUAL parameter corresponding to FORMAL_TYPE must be passed
+   by copy in a call as per RM C.6(19).  Note that we use the same predicates
+   as in the front-end for RM C.6(12) because it's purely a legality issue.  */
+
+static bool
+atomic_or_volatile_copy_required_p (Node_Id actual, Entity_Id formal_type)
+{
+  /* We should not have a scalar type here because such a type is passed
+ by copy.  But the Interlocked routines in System.Aux_DEC force some
+ of the their scalar parameters to be passed by reference so we need
+ to preserve that if we do not want to break the interface.  */
+  if (Is_Scalar_Type (formal_type))
+return false;
+
+  if (Is_Atomic_Object (actual) && !Is_Atomic (formal_type))
+{
+  post_error ("?atomic actual passed by copy (RM C.6(19))", actual);
+  return true;
+}
+
+  if (Is_Volatile_Object (actual) && !Is_Volatile (formal_type))
+{
+  post_error ("?volatile actual passed by copy (RM C.6(19))", actual);
+  return true;
+}
+
+  return false;
+}
+
 /* Subroutine of gnat_to_gnu to translate gnat_node, either an N_Function_Call
or an N_Procedure_Call_Statement, to a GCC tree, which is returned.
GNU_RESULT_TYPE_P is a pointer to where we should place the result type.
@@ -5150,13 +5179,18 @@ Call_to_gnu (Node_Id gnat_node, tree *gnu_result_type_p, tree gnu_target,
 	  = build_compound_expr (TREE_TYPE (gnu_name), init, gnu_name);
 	}
 
-  /* If we are passing a non-addressable parameter by reference, pass the
-	 address of a copy.  In the In Out or Out case, set up to copy back
-	 out after the call.  */
+  /* If we are passing a non-addressable actual parameter by reference,
+	 pass the address of a copy and, in the In Out or Out case, set up
+	 to copy back after the call.  We also need to do that if the actual
+	 parameter is atomic or volatile but the formal parameter is not.  */
   if (is_by_ref_formal_parm
 	  && (gnu_name_type = gnat_to_gnu_type (Etype (gnat_name)))
-	  && !addressable_p (gnu_name, gnu_name_type))
+	  && (!addressable_p (gnu_name, gnu_name_type)
+	  || (Comes_From_Source (gnat_node)
+		  && atomic_or_volatile_copy_required_p (gnat_actual,
+			 gnat_formal_type
 	{
+	  const bool atomic_p = atomic_access_required_p (gnat_actual, &sync);
 	  tree gnu_orig = gnu_name, gnu_temp, gnu_stmt;
 
 	  /* Do not issue warnings for CONSTRUCTORs since this is not a copy
@@ -5236,6 +5270,8 @@ Call_to_gnu (Node_Id gnat_node, tree *gnu_result_type_p, tree gnu_target,
 	}
 
 	  /* Create an explicit temporary holding the copy.  */
+	  if (atomic_p)
+	gnu_name = build_atomic_load (gnu_name, sync);
 	  gnu_temp
 	= create_init_temporary ("A", gnu_name, &gnu_stmt, gnat_actual);
 
@@ -5256,8 +5292,13 @@ Call_to_gnu (Node_Id gnat_node, tree *gnu_result_type_p, tree gnu_target,
 		 (TREE_OPERAND (TREE_OPERAND (gnu_orig, 1), 1)))
 		gnu_orig = TREE_OPERAND (gnu_orig, 2);
 
-	  gnu_stmt
-		= build_binary_op (MODIFY_EXPR, NULL_TREE, gnu_orig, gnu_temp);
+	  if (atomic_p)
+		gnu_stmt
+		  = build_atomic_store (gnu_orig, gnu_temp, sync);
+	  else
+		gnu_stmt
+		  = build_binar

[Ada] Remove vxlink and vxaddr2line from this repository

2018-12-11 Thread Pierre-Marie de Rodat
Those tools need a dedicated repository as they're VxWorks specific and
not related with the Ada front-end.

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

2018-12-11  Jerome Lambourg  

gcc/ada/

* vxaddr2line.adb, vxlink-bind.adb, vxlink-bind.ads,
vxlink-link.adb, vxlink-link.ads, vxlink-main.adb, vxlink.adb,
vxlink.ads: Remove.
* gcc-interface/Make-lang.in, gcc-interface/Makefile.in: Remove
bits for vxaddr2line.--- gcc/ada/gcc-interface/Make-lang.in
+++ gcc/ada/gcc-interface/Make-lang.in
@@ -675,12 +675,10 @@ regnattools:
 cross-gnattools: force
 	$(MAKE) -C ada $(ADA_TOOLS_FLAGS_TO_PASS) gnattools1-re
 	$(MAKE) -C ada $(ADA_TOOLS_FLAGS_TO_PASS) gnattools2
-	$(MAKE) -C ada $(ADA_TOOLS_FLAGS_TO_PASS) gnattools4
 
 canadian-gnattools: force
 	$(MAKE) -C ada $(ADA_TOOLS_FLAGS_TO_PASS) gnattools1-re
 	$(MAKE) -C ada $(ADA_TOOLS_FLAGS_TO_PASS) gnattools2
-	$(MAKE) -C ada $(ADA_TOOLS_FLAGS_TO_PASS) gnattools4
 
 gnatlib gnatlib-sjlj gnatlib-zcx gnatlib-shared: force
 	$(MAKE) -C ada $(COMMON_FLAGS_TO_PASS)  \
@@ -811,8 +809,6 @@ doc/gnat-style.pdf: ada/gnat-style.texi $(gcc_docdir)/include/fdl.texi
 # gnatlink, gnatls, gnatmake, gnatname, gnatprep, gnatxref, gnatfind,
 # gnatclean).
 # gnatdll is only used on Windows.
-# vxaddr2line is only used for cross VxWorks ports (it calls the underlying
-# cross addr2line).
 ada.install-common:
 	$(MKDIR) $(DESTDIR)$(bindir)
 	-if [ -f gnat1$(exeext) ] ; \
@@ -829,11 +825,6 @@ ada.install-common:
 	  done; \
 	  $(RM) $(DESTDIR)$(bindir)/gnatdll$(exeext); \
 	  $(INSTALL_PROGRAM) gnatdll$(exeext) $(DESTDIR)$(bindir)/gnatdll$(exeext); \
-	  if [ -f vxaddr2line$(exeext) ] ; \
-	  then \
-	$(RM) $(DESTDIR)$(bindir)/vxaddr2line$(exeext); \
-	$(INSTALL_PROGRAM) vxaddr2line$(exeext) $(DESTDIR)$(bindir)/vxaddr2line$(exeext); \
-	  fi ; \
 	fi
 
 #
@@ -859,7 +850,6 @@ ada.uninstall:
 	  -$(RM) $(DESTDIR)$(bindir)/$$install_name; \
 	done
 	-$(RM) $(DESTDIR)$(tooldir)/bin/gnatdll$(exeext)
-	-$(RM) $(DESTDIR)$(tooldir)/bin/vxaddr2line$(exeext)
 
 # Clean hooks:
 # A lot of the ancillary files are deleted by the main makefile.

--- gcc/ada/gcc-interface/Makefile.in
+++ gcc/ada/gcc-interface/Makefile.in
@@ -434,19 +434,6 @@ gnattools2: ../stamp-tools
 	$(MAKE) -C tools -f ../Makefile $(TOOLS_FLAGS_TO_PASS) \
 	  TOOLSCASE=native common-tools $(EXTRA_GNATTOOLS)
 
-# those tools are only built for the cross version
-gnattools4: ../stamp-tools
-ifeq ($(ENABLE_VXADDR2LINE),true)
-	$(MAKE) -C tools -f ../Makefile $(TOOLS_FLAGS_TO_PASS) \
-	  TOOLSCASE=cross top_buildir=../../.. \
-	  ../../vxaddr2line$(exeext)
-endif
-ifeq ($(ENABLE_VXLINK),true)
-	$(MAKE) -C tools -f ../Makefile $(TOOLS_FLAGS_TO_PASS) \
-	  TOOLSCASE=cross top_build=../../.. \
-	  ../../vxlink$(exeext)
-endif
-
 common-tools: ../stamp-tools
 	$(GNATMAKE) -j0 -c -b $(ADA_INCLUDES) \
 	  --GNATBIND="$(GNATBIND)" --GCC="$(CC) $(ALL_ADAFLAGS)" \
@@ -477,18 +464,6 @@ common-tools: ../stamp-tools
 	$(GNATLINK) -v gnatdll -o $@ \
 	  --GCC="$(CC) $(ADA_INCLUDES)" --LINK="$(GCC_LINK)" $(TOOLS_LIBS)
 
-../../vxaddr2line$(exeext): ../stamp-tools
-	$(GNATMAKE) -c  $(ADA_INCLUDES) vxaddr2line --GCC="$(CC) $(ALL_ADAFLAGS)"
-	$(GNATBIND) $(ADA_INCLUDES) $(GNATBIND_FLAGS) vxaddr2line
-	$(GNATLINK) -v vxaddr2line -o $@ \
-	  --GCC="$(CC) $(ADA_INCLUDES)" --LINK="$(GCC_LINK)" ../targext.o $(CLIB)
-
-../../vxlink$(exeext): ../stamp-tools
-	$(GNATMAKE) -c  $(ADA_INCLUDES) vxlink-main --GCC="$(CC) $(ALL_ADAFLAGS)"
-	$(GNATBIND) $(ADA_INCLUDES) $(GNATBIND_FLAGS) vxlink-main
-	$(GNATLINK) -v vxlink-main -o $@ \
-	  --GCC="$(CC) $(ADA_INCLUDES)" --LINK="$(GCC_LINK)"
-
 gnatmake-re: ../stamp-tools
 	$(GNATMAKE) -j0 $(ADA_INCLUDES) -u sdefault --GCC="$(CC) $(MOST_ADA_FLAGS)"
 	$(GNATMAKE) -j0 -c $(ADA_INCLUDES) gnatmake --GCC="$(CC) $(ALL_ADAFLAGS)"

--- gcc/ada/vxaddr2line.adb
deleted file mode 100644
+++ /dev/null
@@ -1,525 +0,0 @@
---
---  --
--- GNAT COMPILER COMPONENTS --
---  --
---   V X A D D R 2 L I N E  --
---  --
--- B o d y  --
---  --
--- Copyright (C) 2002-2018, AdaCore --
---  --
--- GNAT is free software;  you can  redistribute it  and/or modify it under --
--- terms of the  GNU General Public License as published  by the Free Soft- --
--- ware  Foundation;  either version 3,  or (at your option) any later ver- --
--- sion.  GNAT is distributed in the 

[Ada] Crash on ignored Ghost expression function

2018-12-11 Thread Pierre-Marie de Rodat
This patch updates freezing to ensure that freeze nodes are inserted
into the tree when the entity being frozen is non-Ghost, and the context
is an ignored Ghost spec expression.

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

2018-12-11  Hristian Kirtchev  

gcc/ada/

* exp_util.adb (Insert_Action): Add new formal parameter
Spec_Expr_OK.
(Insert_Actions): Add new formal parameter Spec_Expr_OK. Update
all calls to Insert_Actions where relevant. Honour an insertion
from a spec expression context when requested by the caller.
* exp_util.ads (Insert_Action): Add new formal parameter
Spec_Expr_OK.
(Insert_Actions): Add new formal parameter Spec_Expr_OK.
* freeze.adb (Add_To_Result): Force the insertion of the freeze
node even when the context is a spec expression.

gcc/testsuite/

* gnat.dg/ghost2.adb, gnat.dg/ghost2.ads: New testcase.--- gcc/ada/exp_util.adb
+++ gcc/ada/exp_util.adb
@@ -6702,20 +6702,34 @@ package body Exp_Util is
-- Insert_Action --
---
 
-   procedure Insert_Action (Assoc_Node : Node_Id; Ins_Action : Node_Id) is
+   procedure Insert_Action
+ (Assoc_Node   : Node_Id;
+  Ins_Action   : Node_Id;
+  Spec_Expr_OK : Boolean := False)
+   is
begin
   if Present (Ins_Action) then
- Insert_Actions (Assoc_Node, New_List (Ins_Action));
+ Insert_Actions
+   (Assoc_Node   => Assoc_Node,
+Ins_Actions  => New_List (Ins_Action),
+Spec_Expr_OK => Spec_Expr_OK);
   end if;
end Insert_Action;
 
--  Version with check(s) suppressed
 
procedure Insert_Action
- (Assoc_Node : Node_Id; Ins_Action : Node_Id; Suppress : Check_Id)
+ (Assoc_Node   : Node_Id;
+  Ins_Action   : Node_Id;
+  Suppress : Check_Id;
+  Spec_Expr_OK : Boolean := False)
is
begin
-  Insert_Actions (Assoc_Node, New_List (Ins_Action), Suppress);
+  Insert_Actions
+(Assoc_Node   => Assoc_Node,
+ Ins_Actions  => New_List (Ins_Action),
+ Suppress => Suppress,
+ Spec_Expr_OK => Spec_Expr_OK);
end Insert_Action;
 
-
@@ -6734,7 +6748,11 @@ package body Exp_Util is
-- Insert_Actions --

 
-   procedure Insert_Actions (Assoc_Node : Node_Id; Ins_Actions : List_Id) is
+   procedure Insert_Actions
+ (Assoc_Node   : Node_Id;
+  Ins_Actions  : List_Id;
+  Spec_Expr_OK : Boolean := False)
+   is
   N : Node_Id;
   P : Node_Id;
 
@@ -6745,14 +6763,20 @@ package body Exp_Util is
  return;
   end if;
 
+  --  Insert the action when the context is "Handling of Default and Per-
+  --  Object Expressions" only when requested by the caller.
+
+  if Spec_Expr_OK then
+ null;
+
   --  Ignore insert of actions from inside default expression (or other
   --  similar "spec expression") in the special spec-expression analyze
   --  mode. Any insertions at this point have no relevance, since we are
   --  only doing the analyze to freeze the types of any static expressions.
-  --  See section "Handling of Default Expressions" in the spec of package
-  --  Sem for further details.
+  --  See section "Handling of Default and Per-Object Expressions" in the
+  --  spec of package Sem for further details.
 
-  if In_Spec_Expression then
+  elsif In_Spec_Expression then
  return;
   end if;
 
@@ -7429,9 +7453,10 @@ package body Exp_Util is
--  Version with check(s) suppressed
 
procedure Insert_Actions
- (Assoc_Node  : Node_Id;
-  Ins_Actions : List_Id;
-  Suppress: Check_Id)
+ (Assoc_Node   : Node_Id;
+  Ins_Actions  : List_Id;
+  Suppress : Check_Id;
+  Spec_Expr_OK : Boolean := False)
is
begin
   if Suppress = All_Checks then
@@ -7439,7 +7464,7 @@ package body Exp_Util is
 Sva : constant Suppress_Array := Scope_Suppress.Suppress;
  begin
 Scope_Suppress.Suppress := (others => True);
-Insert_Actions (Assoc_Node, Ins_Actions);
+Insert_Actions (Assoc_Node, Ins_Actions, Spec_Expr_OK);
 Scope_Suppress.Suppress := Sva;
  end;
 
@@ -7448,7 +7473,7 @@ package body Exp_Util is
 Svg : constant Boolean := Scope_Suppress.Suppress (Suppress);
  begin
 Scope_Suppress.Suppress (Suppress) := True;
-Insert_Actions (Assoc_Node, Ins_Actions);
+Insert_Actions (Assoc_Node, Ins_Actions, Spec_Expr_OK);
 Scope_Suppress.Suppress (Suppress) := Svg;
  end;
   end if;

--- gcc/ada/exp_util.ads
+++ gcc/ada/exp_util.ads
@@ -89,39 +89,54 @@ package Exp_Util is
--  calls, and this guarantee is preserved for the special cases above.
 
procedure Insert_Action
- (Assoc_Node : Node_Id;
-  Ins_Action : Node_Id);
+ (Assoc_Node   : Node_Id;
+  Ins_Actio

[Ada] Crash on generic instantiation in ignored Ghost context

2018-12-11 Thread Pierre-Marie de Rodat
The following patch corrects the freezing of entities to properly
preserve all freeze nodes in case of recursive freezing when the context
is ignored Ghost, and the construct frozen is non-Ghost.

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

2018-12-11  Hristian Kirtchev  

gcc/ada/

* freeze.adb (Add_To_Result): Move the ignored Ghost-specific
handling of freeze nodes to...
(Freeze_Entity): ...here. This ensures that the freeze nodes of
constructs that have recursive freezing are preserved when the
context is ignored Ghost, and the top level construct being
frozen is non-Ghost.

gcc/testsuite/

* gnat.dg/ghost3.adb, gnat.dg/ghost3.ads: New testcase.--- gcc/ada/freeze.adb
+++ gcc/ada/freeze.adb
@@ -2241,29 +2241,7 @@ package body Freeze is
 
   procedure Add_To_Result (Fnod : Node_Id) is
   begin
- --  The Ghost mode of the enclosing context is ignored, while the
- --  entity being frozen is living. Insert the freezing action prior
- --  to the start of the enclosing ignored Ghost region. As a result
- --  the freezeing action will be preserved when the ignored Ghost
- --  context is eliminated. The insertion must take place even when
- --  the context is a spec expression, otherwise "Handling of Default
- --  and Per-Object Expressions" will suppress the insertion, and the
- --  freeze node will be dropped on the floor.
-
- if Saved_GM = Ignore
-   and then Ghost_Mode /= Ignore
-   and then Present (Ignored_Ghost_Region)
- then
-Insert_Action
-  (Assoc_Node   => Ignored_Ghost_Region,
-   Ins_Action   => Fnod,
-   Spec_Expr_OK => True);
-
- --  Otherwise add the freezing action to the result list
-
- else
-Append_New_To (Result, Fnod);
- end if;
+ Append_New_To (Result, Fnod);
   end Add_To_Result;
 
   
@@ -5301,6 +5279,7 @@ package body Freeze is
 
   if Is_Itype (E) and then Is_Record_Type (Scope (E)) then
  Test_E := Scope (E);
+
   elsif Is_Itype (E) and then Present (Underlying_Type (Scope (E)))
 and then Is_Record_Type (Underlying_Type (Scope (E)))
   then
@@ -5582,8 +5561,8 @@ package body Freeze is
  --  Here for other than a subprogram or type
 
  else
---  If entity has a type, and it is not a generic unit, then
---  freeze it first (RM 13.14(10)).
+--  If entity has a type, and it is not a generic unit, then freeze
+--  it first (RM 13.14(10)).
 
 if Present (Etype (E))
   and then Ekind (E) /= E_Generic_Function
@@ -5603,7 +5582,7 @@ package body Freeze is
  and then Has_Delayed_Aspects (E)
then
   Set_Has_Delayed_Aspects (E, False);
-  Set_Has_Delayed_Freeze (E, False);
+  Set_Has_Delayed_Freeze  (E, False);
   Set_Freeze_Node (E, Empty);
end if;
 end if;
@@ -6916,18 +6895,35 @@ package body Freeze is
 
   Check_Debug_Info_Needed (E);
 
-  --  Special handling for subprograms
+  --  If subprogram has address clause then reset Is_Public flag, since we
+  --  do not want the backend to generate external references.
 
-  if Is_Subprogram (E) then
+  if Is_Subprogram (E)
+and then Present (Address_Clause (E))
+and then not Is_Library_Level_Entity (E)
+  then
+ Set_Is_Public (E, False);
+  end if;
 
- --  If subprogram has address clause then reset Is_Public flag, since
- --  we do not want the backend to generate external references.
+  --  The Ghost mode of the enclosing context is ignored, while the
+  --  entity being frozen is living. Insert the freezing action prior
+  --  to the start of the enclosing ignored Ghost region. As a result
+  --  the freezeing action will be preserved when the ignored Ghost
+  --  context is eliminated. The insertion must take place even when
+  --  the context is a spec expression, otherwise "Handling of Default
+  --  and Per-Object Expressions" will suppress the insertion, and the
+  --  freeze node will be dropped on the floor.
+
+  if Saved_GM = Ignore
+and then Ghost_Mode /= Ignore
+and then Present (Ignored_Ghost_Region)
+  then
+ Insert_Actions
+   (Assoc_Node   => Ignored_Ghost_Region,
+Ins_Actions  => Result,
+Spec_Expr_OK => True);
 
- if Present (Address_Clause (E))
-   and then not Is_Library_Level_Entity (E)
- then
-Set_Is_Public (E, False);
- end if;
+ Result := No_List;
   end if;
 
<>

--- /dev/null
new file mode 100644
+++ gcc/testsuite/gnat.dg/ghost3.adb
@@ -0,0 +1,5 @@
+--  { dg-do compile }
+
+

[Ada] Crash on compilation unit function that builds in place

2018-12-11 Thread Pierre-Marie de Rodat
This patch fixes a crash on a function that builds its limited result in
place. Previously this was handled properly only if the function was a
child unit.

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

2018-12-11  Ed Schonberg  

gcc/ada/

* sem_ch3.adb (Build_Itype_Reference): Handle properly an itype
reference created for a function that is a compilation unit, for
example if the function builds in place an object of a limited
type.

gcc/testsuite/

* gnat.dg/bip_cu.adb, gnat.dg/bip_cu_constructor.adb,
gnat.dg/bip_cu_constructor.ads, gnat.dg/bip_cu_t.adb,
gnat.dg/bip_cu_t.ads: New testcase.--- gcc/ada/sem_ch3.adb
+++ gcc/ada/sem_ch3.adb
@@ -10368,12 +10368,13 @@ package body Sem_Ch3 is
  --  If Nod is a library unit entity, then Insert_After won't work,
  --  because Nod is not a member of any list. Therefore, we use
  --  Add_Global_Declaration in this case. This can happen if we have a
- --  build-in-place library function.
+ --  build-in-place library function, child unit or not.
 
  if (Nkind (Nod) in N_Entity and then Is_Compilation_Unit (Nod))
or else
- (Nkind (Nod) = N_Defining_Program_Unit_Name
-   and then Is_Compilation_Unit (Defining_Identifier (Nod)))
+ (Nkind_In (Nod,
+N_Defining_Program_Unit_Name, N_Subprogram_Declaration)
+   and then Is_Compilation_Unit (Defining_Entity (Nod)))
  then
 Add_Global_Declaration (IR);
  else

--- /dev/null
new file mode 100644
+++ gcc/testsuite/gnat.dg/bip_cu.adb
@@ -0,0 +1,10 @@
+--  { dg-do compile }
+
+with BIP_CU_T; use BIP_CU_T;
+with BIP_CU_Constructor;
+
+procedure BIP_CU is
+Value : constant T := BIP_CU_Constructor;
+begin
+null;
+end;

--- /dev/null
new file mode 100644
+++ gcc/testsuite/gnat.dg/bip_cu_constructor.adb
@@ -0,0 +1,5 @@
+with BIP_CU_T; use BIP_CU_T;
+function BIP_CU_Constructor return T is
+begin
+   return Make_T (Name => "Rumplestiltskin");
+end BIP_CU_Constructor;

--- /dev/null
new file mode 100644
+++ gcc/testsuite/gnat.dg/bip_cu_constructor.ads
@@ -0,0 +1,2 @@
+with BIP_CU_T; use BIP_CU_T;
+function BIP_CU_Constructor return T;

--- /dev/null
new file mode 100644
+++ gcc/testsuite/gnat.dg/bip_cu_t.adb
@@ -0,0 +1,8 @@
+package body BIP_CU_T is
+
+   function Make_T (Name : String) return T is
+   begin
+  return (Name => To_Unbounded_String (Name), others => <>);
+   end Make_T;
+
+end BIP_CU_T;

--- /dev/null
new file mode 100644
+++ gcc/testsuite/gnat.dg/bip_cu_t.ads
@@ -0,0 +1,10 @@
+with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
+
+package BIP_CU_T is
+   type T is limited private;
+   function Make_T (Name : String) return T;
+private
+   type T is limited record
+  Name : Unbounded_String;
+   end record;
+end BIP_CU_T;



[Ada] Missing predicate check on declaration with aggregate expression

2018-12-11 Thread Pierre-Marie de Rodat
This patch adds a missing predicate check on the initial value of an
object whose declaration initializes the object with an aggregate. Such
a declaration is marked No_Initialization to prevent a call to a default
initialization procedure, but the check is needed on the value of the
aggregate.

Executing the following:

   gnatmake -q -gnata pred
   ./pred

must yield:

   raised SYSTEM.ASSERTIONS.ASSERT_FAILURE :
 Dynamic_Predicate failed at root.ads:30


with Root;

procedure Pred is
begin
   null;
end Pred;

package Root with SPARK_Mode is
   type Index_Type is range 1 .. Natural'Last;

   type Element_Type is private;
   Null_Element : constant Element_Type;

   type Foobar_Type is array (Index_Type range <>) of Element_Type
 with Dynamic_Predicate =>
Foobar_Type'First > 0 and Foobar_Type'Length > 0;

   Null_Foobar : constant Foobar_Type;

private
   type Kind_Type is (Kind_Invalid, Kind_Valid);

   type Element_Type (Kind : Kind_Type := Kind_Invalid) is record
  Index1 : Index_Type;

  case Kind is
 when Kind_Valid =>
Index2 : Index_Type;
 when Kind_Invalid =>
null;
  end case;
   end record;

   Null_Element : constant Element_Type := (Kind   => Kind_Invalid,
Index1 => Index_Type'First);

   Null_Foobar : constant Foobar_Type := (1 .. 0 => Null_Element);
end Root;

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

2018-12-11  Ed Schonberg  

gcc/ada/

* sem_ch3.adb (Analyze_Object_Declaration): Apply
Dynamic_Predicate check to an object of an array type
initialized with an aggregate.--- gcc/ada/sem_ch3.adb
+++ gcc/ada/sem_ch3.adb
@@ -4454,11 +4454,16 @@ package body Sem_Ch3 is
   --  default initialization when we have at least one case of an explicit
   --  default initial value and then this is not an internal declaration
   --  whose initialization comes later (as for an aggregate expansion).
+  --  If expression is an aggregate it may be expanded into assignments
+  --  and the declaration itself is marked with No_Initialization, but
+  --  the predicate still applies.
 
   if not Suppress_Assignment_Checks (N)
 and then Present (Predicate_Function (T))
 and then not Predicates_Ignored (T)
-and then not No_Initialization (N)
+and then
+  (not No_Initialization (N)
+or else (Present (E) and then Nkind (E) = N_Aggregate))
 and then
   (Present (E)
 or else



[Ada] gnatbind: ghost code with -gnatQ

2018-12-11 Thread Pierre-Marie de Rodat
This patch fixes a bug where if a library unit is compiled with -gnatQ,
and that library unit is an ignored Ghost unit, then gnatbind silently
fails.

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

2018-12-11  Bob Duff  

gcc/ada/

* gnat1drv.adb (gnat1drv): Pass the correct Object value when
calling Write_ALI in the case of -gnatQ.
* gnatbind.adb (Gnatbind): Avoid silent failure; give an error
message.--- gcc/ada/gnat1drv.adb
+++ gcc/ada/gnat1drv.adb
@@ -1452,10 +1452,11 @@ begin
  Tree_Gen;
 
  --  Generate ALI file if specially requested, or for missing subunits,
- --  subunits or predefined generic.
+ --  subunits or predefined generic. For ignored ghost code, the object
+ --  file IS generated, so Object should be True.
 
  if Opt.Force_ALI_Tree_File then
-Write_ALI (Object => False);
+Write_ALI (Object => Is_Ignored_Ghost_Unit (Main_Unit_Node));
  end if;
 
  Namet.Finalize;

--- gcc/ada/gnatbind.adb
+++ gcc/ada/gnatbind.adb
@@ -790,6 +790,7 @@ begin
   --  Quit if some file needs compiling
 
   if No_Object_Specified then
+ Error_Msg ("no object specified");
  raise Unrecoverable_Error;
   end if;
 



[Ada] Fix setting of Has_Predicate flag for aggregate subtypes

2018-12-11 Thread Pierre-Marie de Rodat
This patch enures that the subtype of an aggregate has the Has_Predicate
flag properly set if the array component has a predicate, including the
case the predicate function for the component has not been constructed
yet.

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

2018-12-11  Ed Schonberg  

gcc/ada/

* sem_aggr.adb (Array_Aggr_Subtype. Resolve_Aggr_Expr): Indicate
that aggregate subtype has a predicate if the component type has
a predicate; do not rely on exisatence of predicate function for
component, in case component is a type no yet frozen, for which
predicate function has not been created yet.--- gcc/ada/sem_aggr.adb
+++ gcc/ada/sem_aggr.adb
@@ -611,6 +611,16 @@ package body Sem_Aggr is
   Set_Is_Constrained (Itype, True);
   Set_Is_Internal(Itype, True);
 
+  if Has_Predicates (Typ) then
+ Set_Has_Predicates (Itype);
+
+ if Present (Predicate_Function (Typ)) then
+Set_Predicate_Function (Itype, Predicate_Function (Typ));
+ else
+Set_Predicated_Parent (Itype, Predicated_Parent (Typ));
+ end if;
+  end if;
+
   --  A simple optimization: purely positional aggregates of static
   --  components should be passed to gigi unexpanded whenever possible, and
   --  regardless of the staticness of the bounds themselves. Subsequent
@@ -1627,7 +1637,7 @@ package body Sem_Aggr is
  --  component assignments. If the expression covers several components
  --  the analysis and the predicate check take place later.
 
- if Present (Predicate_Function (Component_Typ))
+ if Has_Predicates (Component_Typ)
and then Analyzed (Expr)
  then
 Apply_Predicate_Check (Expr, Component_Typ);
@@ -4194,7 +4204,7 @@ package body Sem_Aggr is
  --  because the aggegate might not be expanded into individual
  --  component assignments.
 
- if Present (Predicate_Function (Expr_Type))
+ if Has_Predicates (Expr_Type)
and then Analyzed (Expr)
  then
 Apply_Predicate_Check (Expr, Expr_Type);



[Ada] Plug small loophole with pathological packed array type

2018-12-11 Thread Pierre-Marie de Rodat
This fixes a crash in gigi on a pathological packed array type, whose
component type is a record type without representation clause or packing
but with a clause that bumps its size to a non-multiple value of the
storage unit.  In this case, the front-end fails to detect that calls
to the packing manpulation routines of the run time are necessary.

The fix doesn't change anything for non-pathological cases, i.e. when
the component type has a representation clause or is packed.

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

2018-12-11  Eric Botcazou  

gcc/ada/

* exp_aggr.adb (Packed_Array_Aggregate_Handled): Bail out for
any non-scalar type as component type of the array.

gcc/testsuite/

* gnat.dg/packed_array.adb, gnat.dg/packed_array.ads,
gnat.dg/packed_array_pkg.ads: New testcase.--- gcc/ada/exp_aggr.adb
+++ gcc/ada/exp_aggr.adb
@@ -7893,9 +7893,7 @@ package body Exp_Aggr is
  return False;
   end if;
 
-  if not Is_Scalar_Type (Component_Type (Typ))
-and then Has_Non_Standard_Rep (Component_Type (Typ))
-  then
+  if not Is_Scalar_Type (Ctyp) then
  return False;
   end if;
 

--- /dev/null
new file mode 100644
+++ gcc/testsuite/gnat.dg/packed_array.adb
@@ -0,0 +1,5 @@
+package body Packed_Array is
+
+  procedure Dummy is null;
+
+end;

--- /dev/null
new file mode 100644
+++ gcc/testsuite/gnat.dg/packed_array.ads
@@ -0,0 +1,9 @@
+with Packed_Array_Pkg; use Packed_Array_Pkg;
+
+package Packed_Array is
+
+  C : constant Small_Rec2 := (Lo => 1, Hi => Max, A => (1 => (2, 3)));
+
+  procedure Dummy;
+
+end;

--- /dev/null
new file mode 100644
+++ gcc/testsuite/gnat.dg/packed_array_pkg.ads
@@ -0,0 +1,20 @@
+package Packed_Array_Pkg is
+
+  type Rec1 is record
+I : Integer;
+S : Short_Integer;
+  end record;
+  for Rec1'Size use 49;
+
+  type Arr is array (Positive range <>) of Rec1;
+  for Arr'Component_Size use 49;
+
+  type Rec2 (Lo, Hi : Positive) is record
+A : Arr (Lo .. Hi);
+  end record;
+
+  Max : Positive := 1;
+
+  subtype Small_Rec2 is Rec2 (1, Max);
+
+end;



[Ada] Volatility, validity checks, and System.Aux_DEC

2018-12-11 Thread Pierre-Marie de Rodat
This patch updates validity checks to prevent the validation of an
by-reference formal parameter because the parameter is not being read in
the process.

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

2018-12-11  Hristian Kirtchev  

gcc/ada/

* checks.adb: Add with and use clauses for Sem_Mech.
(Ensure_Valid): Update the "annoying special case" to include
entry and function calls. Use Get_Called_Entity to obtain the
entry or subprogram being invoked, rather than retrieving it
manually. Parameters passed by reference do not need a validity
check.

gcc/testsuite/

* gnat.dg/valid4.adb, gnat.dg/valid4_pkg.adb,
gnat.dg/valid4_pkg.ads: New testcase.--- gcc/ada/checks.adb
+++ gcc/ada/checks.adb
@@ -50,6 +50,7 @@ with Sem_Ch3;  use Sem_Ch3;
 with Sem_Ch8;  use Sem_Ch8;
 with Sem_Disp; use Sem_Disp;
 with Sem_Eval; use Sem_Eval;
+with Sem_Mech; use Sem_Mech;
 with Sem_Res;  use Sem_Res;
 with Sem_Util; use Sem_Util;
 with Sem_Warn; use Sem_Warn;
@@ -6071,7 +6072,8 @@ package body Checks is
 
   --  An annoying special case. If this is an out parameter of a scalar
   --  type, then the value is not going to be accessed, therefore it is
-  --  inappropriate to do any validity check at the call site.
+  --  inappropriate to do any validity check at the call site. Likewise
+  --  if the parameter is passed by reference.
 
   else
  --  Only need to worry about scalar types
@@ -6097,25 +6099,20 @@ package body Checks is
   P := Parent (N);
end if;
 
-   --  Only need to worry if we are argument of a procedure call
-   --  since functions don't have out parameters. If this is an
-   --  indirect or dispatching call, get signature from the
-   --  subprogram type.
+   --  If this is an indirect or dispatching call, get signature
+   --  from the subprogram type.
 
-   if Nkind (P) = N_Procedure_Call_Statement then
+   if Nkind_In (P, N_Entry_Call_Statement,
+   N_Function_Call,
+   N_Procedure_Call_Statement)
+   then
+  E := Get_Called_Entity (P);
   L := Parameter_Associations (P);
 
-  if Is_Entity_Name (Name (P)) then
- E := Entity (Name (P));
-  else
- pragma Assert (Nkind (Name (P)) = N_Explicit_Dereference);
- E := Etype (Name (P));
-  end if;
-
   --  Only need to worry if there are indeed actuals, and if
-  --  this could be a procedure call, otherwise we cannot get a
-  --  match (either we are not an argument, or the mode of the
-  --  formal is not OUT). This test also filters out the
+  --  this could be a subprogram call, otherwise we cannot get
+  --  a match (either we are not an argument, or the mode of
+  --  the formal is not OUT). This test also filters out the
   --  generic case.
 
   if Is_Non_Empty_List (L) and then Is_Subprogram (E) then
@@ -6126,7 +6123,10 @@ package body Checks is
  F := First_Formal (E);
  A := First (L);
  while Present (F) loop
-if Ekind (F) = E_Out_Parameter and then A = N then
+if A = N
+  and then (Ekind (F) = E_Out_Parameter
+ or else Mechanism (F) = By_Reference)
+then
return;
 end if;
 

--- /dev/null
new file mode 100644
+++ gcc/testsuite/gnat.dg/valid4.adb
@@ -0,0 +1,13 @@
+--  { dg-do run }
+--  { dg-options "-gnatVa" }
+
+with Valid4_Pkg; use Valid4_Pkg;
+
+procedure Valid4 is
+begin
+   Proc (Global);
+
+   if Global then
+  raise Program_Error;
+   end if;
+end Valid4;

--- /dev/null
new file mode 100644
+++ gcc/testsuite/gnat.dg/valid4_pkg.adb
@@ -0,0 +1,19 @@
+package body Valid4_Pkg is
+   procedure Inner_Proc (B : in out Boolean);
+   pragma Export_Procedure
+ (Inner_Proc,
+  External=> "Inner_Proc",
+  Parameter_Types => (Boolean),
+  Mechanism   => Reference);
+
+   procedure Inner_Proc (B : in out Boolean) is
+   begin
+  B := True;
+  Global := False;
+   end Inner_Proc;
+
+   procedure Proc (B : in out Boolean) is
+   begin
+  Inner_Proc (B);
+   end Proc;
+end Valid4_Pkg;

--- /dev/null
new file mode 100644
+++ gcc/testsuite/gnat.dg/valid4_pkg.ads
@@ -0,0 +1,10 @@
+package Valid4_Pkg is
+   Global : Boolean := False;
+
+   procedure Proc (B : in out Boolean);
+   pragma Export_Procedure
+ (Proc,
+  External=> "Proc",
+  Parameter_Types => (Boolean),
+  Mechanism   => Refere

[Ada] Improve error message when named number passed as global item

2018-12-11 Thread Pierre-Marie de Rodat
When a named number is used in Global/Depends contracts as global item,
the error message could be confusing to users new to Ada. Now the
message explains that named numbers are not objects.

For instance on the following illegal code snippet:

 $ gcc -c bad_global.ads

 1. package Bad_Global is
 2.
 3.X : constant := 1;
 4.Y : constant := 1.0;
 5.
 6.procedure P with
 7.  Global => (Input => X,
 |
>>> global item must denote object, state or current instance
of concurrent type
>>> named number "X" is not an object

 8. In_Out => Y);
  |
>>> global item must denote object, state or current instance
of concurrent type
>>> named number "Y" is not an object

 9.
10. end Bad_Global;

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

2018-12-11  Yannick Moy  

gcc/ada/

* sem_prag.adb (Analyze_Global_Item): Refine error message.--- gcc/ada/sem_prag.adb
+++ gcc/ada/sem_prag.adb
@@ -2282,6 +2282,12 @@ package body Sem_Prag is
   SPARK_Msg_N
 ("global item must denote object, state or current "
  & "instance of concurrent type", Item);
+
+  if Ekind (Item_Id) in Named_Kind then
+ SPARK_Msg_NE
+   ("\named number & is not an object", Item, Item);
+  end if;
+
   return;
end if;
 



[Ada] Do not expand code inside ignored ghost bodies

2018-12-11 Thread Pierre-Marie de Rodat
While ignored ghost code is not compiled into the executable, it may
lead to compilation errors when it makes use of language features
requiring runtime support that is not available in the available runtime
library.  These errors are spurious, as the executable will never call
in these runtime units.

This patch deactivates the expansion of code inside ignored ghost bodies
of subprograms and packages, so that this code is still checked for
possible semantic errors, but it does not force the presence of useless
runtime units.

There is no impact on the executable produced.

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

2018-12-11  Yannick Moy  

gcc/ada/

* sem_ch6.adb (Analyze_Subprogram_Body_Helper): Deactivate
expansion in ignored ghost subprogram body.
* sem_ch7.adb (Analyze_Package_Body_Helper): Deactivate
expansion in ignored ghost package body.

gcc/testsuite/

* gnat.dg/ghost4.adb: New testcase.--- gcc/ada/sem_ch6.adb
+++ gcc/ada/sem_ch6.adb
@@ -3370,6 +3370,7 @@ package body Sem_Ch6 is
 
   Saved_GM   : constant Ghost_Mode_Type := Ghost_Mode;
   Saved_IGR  : constant Node_Id := Ignored_Ghost_Region;
+  Saved_EA   : constant Boolean := Expander_Active;
   Saved_ISMP : constant Boolean :=
  Ignore_SPARK_Mode_Pragmas_In_Instance;
   --  Save the Ghost and SPARK mode-related data to restore on exit
@@ -3610,6 +3611,18 @@ package body Sem_Ch6 is
  end if;
   end if;
 
+  --  Deactivate expansion inside the body of ignored Ghost entities,
+  --  as this code will ultimately be ignored. This avoids requiring the
+  --  presence of run-time units which are not needed. Only do this for
+  --  user entities, as internally generated entitities might still need
+  --  to be expanded (e.g. those generated for types).
+
+  if Present (Ignored_Ghost_Region)
+and then Comes_From_Source (Body_Id)
+  then
+ Expander_Active := False;
+  end if;
+
   --  Previously we scanned the body to look for nested subprograms, and
   --  rejected an inline directive if nested subprograms were present,
   --  because the back-end would generate conflicting symbols for the
@@ -4588,6 +4601,10 @@ package body Sem_Ch6 is
   end if;
 
<>
+  if Present (Ignored_Ghost_Region) then
+ Expander_Active := Saved_EA;
+  end if;
+
   Ignore_SPARK_Mode_Pragmas_In_Instance := Saved_ISMP;
   Restore_Ghost_Region (Saved_GM, Saved_IGR);
end Analyze_Subprogram_Body_Helper;

--- gcc/ada/sem_ch7.adb
+++ gcc/ada/sem_ch7.adb
@@ -669,6 +669,7 @@ package body Sem_Ch7 is
 
   Saved_GM   : constant Ghost_Mode_Type := Ghost_Mode;
   Saved_IGR  : constant Node_Id := Ignored_Ghost_Region;
+  Saved_EA   : constant Boolean := Expander_Active;
   Saved_ISMP : constant Boolean :=
  Ignore_SPARK_Mode_Pragmas_In_Instance;
   --  Save the Ghost and SPARK mode-related data to restore on exit
@@ -780,6 +781,18 @@ package body Sem_Ch7 is
 
   Mark_And_Set_Ghost_Body (N, Spec_Id);
 
+  --  Deactivate expansion inside the body of ignored Ghost entities,
+  --  as this code will ultimately be ignored. This avoids requiring the
+  --  presence of run-time units which are not needed. Only do this for
+  --  user entities, as internally generated entitities might still need
+  --  to be expanded (e.g. those generated for types).
+
+  if Present (Ignored_Ghost_Region)
+and then Comes_From_Source (Body_Id)
+  then
+ Expander_Active := False;
+  end if;
+
   --  If the body completes the initial declaration of a compilation unit
   --  which is subject to pragma Elaboration_Checks, set the model of the
   --  pragma because it applies to all parts of the unit.
@@ -1075,6 +1088,10 @@ package body Sem_Ch7 is
  end if;
   end if;
 
+  if Present (Ignored_Ghost_Region) then
+ Expander_Active := Saved_EA;
+  end if;
+
   Ignore_SPARK_Mode_Pragmas_In_Instance := Saved_ISMP;
   Restore_Ghost_Region (Saved_GM, Saved_IGR);
end Analyze_Package_Body_Helper;

--- /dev/null
new file mode 100644
+++ gcc/testsuite/gnat.dg/ghost4.adb
@@ -0,0 +1,15 @@
+pragma Restrictions (No_Secondary_Stack);
+
+procedure Ghost4 is
+
+   procedure Dummy with Ghost is
+  function Slice (S : String) return String is
+ (S (S'First .. S'First + 3));
+
+  X : String := Slice ("hello");
+   begin
+ null;
+   end Dummy;
+begin
+   Dummy;
+end Ghost4;



[Ada] Spurious error with pragma Thread_Local_Storage

2018-12-11 Thread Pierre-Marie de Rodat
The following patch modifies the checks related to pragma
Thread_Local_Storage to correct a confusion in semantics which led to
spurious errors.


-- Source --


--  pack.ads

package Pack is
   type Arr is array (1 .. 5) of Boolean;

   type Arr_With_Default is array (1 .. 5) of Boolean
 with Default_Component_Value => False;

   type Int is new Integer range 1 .. 5;

   type Int_With_Default is new Integer range 1 .. 5
 with Default_Value => 1;

   protected type Prot_Typ is
  entry E;
   end Prot_Typ;

   type Rec_1 is record
  Comp : Integer;
   end record;

   type Rec_2 is record
  Comp : Int;
   end record;

   type Rec_3 is record
  Comp : Int_With_Default;
   end record;

   task type Task_Typ is
  entry E;
   end Task_Typ;
end Pack;

--  pack.adb

package body Pack is
   function F (Val : Int) return Int is
   begin
  if Val <= 1 then
 return 1;
  else
 return F (Val - 1) * Val;
  end if;
   end F;

   function F (Val : Int_With_Default) return Int_With_Default is
   begin
  if Val <= 1 then
 return 1;
  else
 return F (Val - 1) * Val;
  end if;
   end F;

   function F (Val : Integer) return Integer is
   begin
  if Val <= 1 then
 return 1;
  else
 return F (Val - 1) * Val;
  end if;
   end F;

   protected body Prot_Typ is
  entry E when True is begin null; end E;
   end Prot_Typ;

   task body Task_Typ is
   begin
  accept E;
   end Task_Typ;

   Obj_1 : Arr;  --  OK
   pragma Thread_Local_Storage (Obj_1);

   Obj_2 : Arr := (others => True);  --  OK
   pragma Thread_Local_Storage (Obj_2);

   Obj_3 : Arr := (others => F (2) = Integer (3));   --  ERROR
   pragma Thread_Local_Storage (Obj_3);

   Obj_4 : Arr_With_Default; --  ERROR
   pragma Thread_Local_Storage (Obj_4);

   Obj_5 : Arr_With_Default := (others => True); --  OK
   pragma Thread_Local_Storage (Obj_5);

   Obj_6 : Arr_With_Default := (others => F (2) = Integer (3));  --  ERROR
   pragma Thread_Local_Storage (Obj_6);

   Obj_7 : Integer;  --  OK
   pragma Thread_Local_Storage (Obj_7);

   Obj_8 : Integer := 1; --  OK
   pragma Thread_Local_Storage (Obj_8);

   Obj_9 : Integer := F (2); --  ERROR
   pragma Thread_Local_Storage (Obj_9);

   Obj_10 : Int; --  OK
   pragma Thread_Local_Storage (Obj_10);

   Obj_11 : Int := 1;--  OK
   pragma Thread_Local_Storage (Obj_11);

   Obj_12 : Int := F (2);--  ERROR
   pragma Thread_Local_Storage (Obj_12);

   Obj_13 : Int_With_Default;--  ERROR
   pragma Thread_Local_Storage (Obj_13);

   Obj_14 : Int_With_Default := 1;   --  OK
   pragma Thread_Local_Storage (Obj_14);

   Obj_15 : Int_With_Default := F (2);   --  ERROR
   pragma Thread_Local_Storage (Obj_15);

   Obj_16 : Prot_Typ;--  ERROR
   pragma Thread_Local_Storage (Obj_16);

   Obj_17 : Rec_1;   --  OK
   pragma Thread_Local_Storage (Obj_17);

   Obj_18 : Rec_1 := (others => 1);  --  OK
   pragma Thread_Local_Storage (Obj_18);

   Obj_19 : Rec_1 := (others => F (2));  --  ERROR
   pragma Thread_Local_Storage (Obj_19);

   Obj_20 : Rec_2;   --  OK
   pragma Thread_Local_Storage (Obj_20);

   Obj_21 : Rec_2 := (others => 1);  --  OK
   pragma Thread_Local_Storage (Obj_21);

   Obj_22 : Rec_2 := (others => F (2));  --  ERROR
   pragma Thread_Local_Storage (Obj_22);

   Obj_23 : Rec_3;   --  ERROR
   pragma Thread_Local_Storage (Obj_23);

   Obj_24 : Rec_3 := (others => 1);  --  OK
   pragma Thread_Local_Storage (Obj_24);

   Obj_25 : Rec_3 := (others => F (2));  --  ERROR
   pragma Thread_Local_Storage (Obj_25);

   Obj_26 : Task_Typ;--  ERROR
   pragma Thread_Local_Storage (Obj_26);
end Pack;


-- Compilation and output --


$ gcc -c pack.adb
pack.adb:47:04: Thread_Local_Storage variable "Obj_4" is improperly
  initialized
pack.adb:47:04: only allowed initialization is explicit "null", static
  expression or static aggregate
pack.adb:62:04: Thread_Local_Storage variable "Obj_9" is improperly
  initia

[Ada] Crash on misplaced First operation for GNAT iterable type

2018-12-11 Thread Pierre-Marie de Rodat
This patch improves the handling of an improper declaaration of aspect
First for a GNAT-defined iterable type,

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

2018-12-11  Ed Schonberg  

gcc/ada/

* sem_util.adb (Get_Actual_Subtype): Function can return type
mark.
(Get_Cursor_Type): Improve recovery and error message on a
misplaced First aspect for an iterable type.

gcc/testsuite/

* gnat.dg/iter4.adb: New testcase.--- gcc/ada/sem_util.adb
+++ gcc/ada/sem_util.adb
@@ -9049,6 +9049,13 @@ package body Sem_Util is
 
  else
 Decl := Build_Actual_Subtype (Typ, N);
+
+--  The call may yield a declaration, or just return the entity
+
+if Decl = Typ then
+   return Typ;
+end if;
+
 Atyp := Defining_Identifier (Decl);
 
 --  If Build_Actual_Subtype generated a new declaration then use it
@@ -9162,6 +9169,9 @@ package body Sem_Util is
   if First_Op = Any_Id then
  Error_Msg_N ("aspect Iterable must specify First operation", Aspect);
  return Any_Type;
+
+  elsif not Analyzed (First_Op) then
+ Analyze (First_Op);
   end if;
 
   Cursor := Any_Type;
@@ -9195,7 +9205,8 @@ package body Sem_Util is
 
   if Cursor = Any_Type then
  Error_Msg_N
-   ("No legal primitive operation First for Iterable type", Aspect);
+   ("primitive operation for Iterable type must appear "
+ & "in the same list of declarations as the type", Aspect);
   end if;
 
   return Cursor;

--- /dev/null
new file mode 100644
+++ gcc/testsuite/gnat.dg/iter4.adb
@@ -0,0 +1,36 @@
+--  { dg-do compile }
+
+procedure Iter4 is
+   package Root is
+  type Result is tagged record
+ B : Boolean;
+  end record;
+
+  type T is tagged record
+ I : Integer;
+  end record
+  with Iterable => (First   => Pkg.First, --  { dg-error "primitive operation for Iterable type must appear in the same list of declarations as the type" }
+Next=> Pkg.Next,
+Has_Element => Pkg.Has_Element,
+Element => Pkg.Element);
+
+  package Pkg is
+ function First (Dummy : T) return Natural is (0);
+ function Next (Dummy : T; Cursor : Natural) return Natural is
+   (Cursor + 1);
+ function Has_Element (Value : T; Cursor : Natural) return Boolean is
+   (Cursor <= Value.I);
+ function Element (Dummy : T; Cursor : Natural) return Result is
+   ((B => Cursor mod 2 = 0));
+  end Pkg;
+   end Root;
+
+   package Derived is
+  type T is new Root.T with record
+ C : Character;
+  end record;
+   end Derived;
+
+begin
+   null;
+end;



[Ada] Add "Global => null" contracts to Ada.Calendar routines

2018-12-11 Thread Pierre-Marie de Rodat
Routines in Ada.Real_Time are already annotated with Global => null
contracts to suppress spurious warnings from the flow analysis in
GNATprove. This patch adds such contracts to Ada.Calendar. No change in
runtime behavior expected.

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

2018-12-11  Piotr Trojanek  

gcc/ada/

* libgnat/a-calend.ads: Add "Global => null" contracts to pure
routines.--- gcc/ada/libgnat/a-calend.ads
+++ gcc/ada/libgnat/a-calend.ads
@@ -61,17 +61,19 @@ is
--  the result will contain all elapsed leap seconds since the start of
--  Ada time until now.
 
-   function Year(Date : Time) return Year_Number;
-   function Month   (Date : Time) return Month_Number;
-   function Day (Date : Time) return Day_Number;
-   function Seconds (Date : Time) return Day_Duration;
+   function Year(Date : Time) return Year_Number  with Global => null;
+   function Month   (Date : Time) return Month_Number with Global => null;
+   function Day (Date : Time) return Day_Number   with Global => null;
+   function Seconds (Date : Time) return Day_Duration with Global => null;
 
procedure Split
  (Date: Time;
   Year: out Year_Number;
   Month   : out Month_Number;
   Day : out Day_Number;
-  Seconds : out Day_Duration);
+  Seconds : out Day_Duration)
+   with
+ Global => null;
--  Break down a time value into its date components set in the current
--  time zone. If Split is called on a time value created using Ada 2005
--  Time_Of in some arbitrary time zone, the input value will always be
@@ -81,7 +83,9 @@ is
  (Year: Year_Number;
   Month   : Month_Number;
   Day : Day_Number;
-  Seconds : Day_Duration := 0.0) return Time;
+  Seconds : Day_Duration := 0.0) return Time
+   with
+ Global => null;
--  GNAT Note: Normally when procedure Split is called on a Time value
--  result of a call to function Time_Of, the out parameters of procedure
--  Split are identical to the in parameters of function Time_Of. However,
@@ -97,19 +101,27 @@ is
--  Seconds may be 14340.0 (3:59:00) instead of 10740.0 (2:59:00 being
--  a time that not exist).
 
-   function "+" (Left : Time; Right : Duration) return Time;
-   function "+" (Left : Duration; Right : Time) return Time;
-   function "-" (Left : Time; Right : Duration) return Time;
-   function "-" (Left : Time; Right : Time) return Duration;
+   function "+" (Left : Time; Right : Duration) return Time
+   with
+ Global => null;
+   function "+" (Left : Duration; Right : Time) return Time
+   with
+ Global => null;
+   function "-" (Left : Time; Right : Duration) return Time
+   with
+ Global => null;
+   function "-" (Left : Time; Right : Time) return Duration
+   with
+ Global => null;
--  The first three functions will raise Time_Error if the resulting time
--  value is less than the start of Ada time in UTC or greater than the
--  end of Ada time in UTC. The last function will raise Time_Error if the
--  resulting difference cannot fit into a duration value.
 
-   function "<"  (Left, Right : Time) return Boolean;
-   function "<=" (Left, Right : Time) return Boolean;
-   function ">"  (Left, Right : Time) return Boolean;
-   function ">=" (Left, Right : Time) return Boolean;
+   function "<"  (Left, Right : Time) return Boolean with Global => null;
+   function "<=" (Left, Right : Time) return Boolean with Global => null;
+   function ">"  (Left, Right : Time) return Boolean with Global => null;
+   function ">=" (Left, Right : Time) return Boolean with Global => null;
 
Time_Error : exception;
 



Re: [Ada] Add "Global => null" contracts to Ada.Calendar routines

2018-12-11 Thread Florian Weimer
* Pierre-Marie de Rodat:

> procedure Split
>   (Date: Time;
>Year: out Year_Number;
>Month   : out Month_Number;
>Day : out Day_Number;
> -  Seconds : out Day_Duration);
> +  Seconds : out Day_Duration)
> +   with
> + Global => null;

Is this really correct?  Doesn't this call UTC_Time_Offset eventually,
via Formatting_Operations.Split with Use_TZ => False?

Thanks,
Florian


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

2018-12-11 Thread Umesh Kalappa
Hi All,

Please find the attached patch for the subjected issue .

Do please let me know your thoughts and comments on the same .

Thank you
~Umesh


pr84762.patch
Description: Binary data


Re: [Ada] Add "Global => null" contracts to Ada.Calendar routines

2018-12-11 Thread Piotr Trojanek
On Tue, 11 Dec 2018 12:48:15 +0100, Florian Weimer wrote:
> * Pierre-Marie de Rodat:
> 
> > procedure Split
> >   (Date: Time;
> >Year: out Year_Number;
> >Month   : out Month_Number;
> >Day : out Day_Number;
> > -  Seconds : out Day_Duration);
> > +  Seconds : out Day_Duration)
> > +   with
> > + Global => null;
> 
> Is this really correct? Doesn't this call UTC_Time_Offset eventually, via
> Formatting_Operations.Split with Use_TZ => False?

You are right. I will remove the Global contracts from non-arithmetic routines.
Thanks for noticing this!


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

2018-12-11 Thread Jakub Jelinek
On Tue, Dec 11, 2018 at 05:30:48PM +0530, Umesh Kalappa wrote:
> Hi All,
> 
> Please find the attached patch for the subjected issue .
> 
> Do please let me know your thoughts and comments on the same .

Not a patch review (will defer that to rs6000 maintainers), but
some comments on gcc-patches patch submissions.

The subject should ideally start with [PATCH] or similar,
then have some short summary of what the patch is about and if
it fixes some PR, just PR something/12345 reference,
the subjects you are posting like:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84762
don't say anything relevant except for the PR 84762 number,
so anyone reading gcc-patches needs to open that bug in order to even find
out if it is something for him or somebody else.

If you are sending a patch for an area that has some maintainer(s),
usually you should either mention those maintainers in To: (and CC:
gcc-patches) or To: gcc-patches, CC: the maintainers, to draw their
attention.  See MAINTAINERS file in GCC tree.

The mail body should start with a short explanation of what the problem is
and how are you solving it, again, so that people don't have to jump to
bugzilla to find out (of course, short is enough, no need to duplicate
dozens of comments from the PR), should include information on what
target(s) it has been bootstrapped/regtested.  And, it is always better if
it is the patch author that posts it, or is at least CCed so that he can
answer review questions.

Thanks.

Jakub


Re: [C PATCH] Fix ubsan -fsanitize=float-cast-overflow ICE (PR sanitizer/88426)

2018-12-11 Thread Marek Polacek
On Tue, Dec 11, 2018 at 08:21:50AM +0100, Jakub Jelinek wrote:
> Hi!
> 
> The following testcase ICEs since the c_save_expr removal.  Unlike other
> spots where we use save_expr and potentially pass that to function ubsan
> calls, in this case we weren't calling c_fully_fold and
> c_fully_fold_internal unfortunately doesn't recurse into CALL_EXPRs, so
> the gimplifier then sees C_MAYBE_CONST_EXPRs and ICEs on them.  E.g.
> for shift sanitization etc. we call c_fully_fold like this.
> 
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
> 
> 2018-12-11  Jakub Jelinek  
> 
>   PR sanitizer/88426
>   * c-convert.c (convert): Call c_fully_fold before calling
>   ubsan_instrument_float_cast.
> 
>   * c-c++-common/ubsan/float-cast-overflow-11.c: New test.

Ok, thanks.

Marek


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

2018-12-11 Thread Jonathan Wakely

On 11/12/18 13:28 +0100, Jakub Jelinek wrote:

On Tue, Dec 11, 2018 at 05:30:48PM +0530, Umesh Kalappa wrote:

Hi All,

Please find the attached patch for the subjected issue .

Do please let me know your thoughts and comments on the same .


Not a patch review (will defer that to rs6000 maintainers), but
some comments on gcc-patches patch submissions.

The subject should ideally start with [PATCH] or similar,
then have some short summary of what the patch is about and if
it fixes some PR, just PR something/12345 reference,
the subjects you are posting like:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84762
don't say anything relevant except for the PR 84762 number,
so anyone reading gcc-patches needs to open that bug in order to even find
out if it is something for him or somebody else.

If you are sending a patch for an area that has some maintainer(s),
usually you should either mention those maintainers in To: (and CC:
gcc-patches) or To: gcc-patches, CC: the maintainers, to draw their
attention.  See MAINTAINERS file in GCC tree.

The mail body should start with a short explanation of what the problem is
and how are you solving it, again, so that people don't have to jump to
bugzilla to find out (of course, short is enough, no need to duplicate
dozens of comments from the PR), should include information on what
target(s) it has been bootstrapped/regtested.  And, it is always better if
it is the patch author that posts it, or is at least CCed so that he can
answer review questions.


Also, as noted at https://gcc.gnu.org/contribute.html#patches the
ChangeLog entry should be in plain text, not part of the patch.

"The ChangeLog entries should be plaintext rather than part of the
patch since the top of the ChangeLog changes rapidly and a patch to
the ChangeLog would probably no longer apply by the time your patch is
reviewed."

Some people add it as a second attachment, e.g.
https://gcc.gnu.org/ml/gcc-patches/2018-11/msg02524.html
or just inline in the email body, e.g.
https://gcc.gnu.org/ml/gcc-patches/2018-12/msg00622.html
Either is better than including the ChangeLog entry as part of the
patch itself.

Following the https://gcc.gnu.org/contribute.html#patches policies
will make it much more likely that patches will be seen by the right
people and reviewed.




Re: Too strict synchronization with the local (host) thread?

2018-12-11 Thread Chung-Lin Tang

On 2018/12/7 11:56 PM, Thomas Schwinge wrote:

--- a/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-79.c
+++ b/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-79.c
@@ -114,6 +114,7 @@ main (int argc, char **argv)
  
for (i = 0; i < N; i++)

  {
+  stream = (CUstream) acc_get_cuda_stream (i & 1);
r = cuLaunchKernel (delay, 1, 1, 1, 1, 1, 1, 0, stream, kargs, 0);

What's the motivation for this change?


To place work on both streams 0 and 1.


..., and this change are needed because we're now more strictly
synchronizing with the local (host) thread.

Regarding the case of "libgomp.oacc-c-c++-common/lib-81.c", as currently
present:

 [...]
   for (i = 0; i < N; i++)
 {
   r = cuLaunchKernel (delay, 1, 1, 1, 1, 1, 1, 0, streams[i], kargs, 
0);
   if (r != CUDA_SUCCESS)
 {
   fprintf (stderr, "cuLaunchKernel failed: %d\n", r);
   abort ();
 }
 }

This launches N kernels on N separate async queues/CUDA streams, [0..N).

   acc_wait_all_async (N);

Then, the "acc_wait_all_async (N)" -- in my understanding! -- should
*not*  synchronize with the local (host) thread, but instead just set up
the additional async queue/CUDA stream N to "depend" on [0..N).

   for (i = 0; i <= N; i++)
 {
   if (acc_async_test (i) != 0)
 abort ();
 }

Thus, all [0..N) should then still be "acc_async_test (i) != 0" (still
running).

   acc_wait (N);

Here, the "acc_wait (N)" would synchronize the local (host) thread with
async queue/CUDA stream N and thus recursively with [0..N).

   for (i = 0; i <= N; i++)
 {
   if (acc_async_test (i) != 1)
 abort ();
 }
 [...]

So, then all these async queues/CUDA streams here indeed are
"acc_async_test (i) != 1", thas is, idle.


Now, the more strict synchronization with the local (host) thread is not
wrong in term of correctness, but I suppose it will impact performance of
otherwise asynchronous operations, which now get synchronized too much?

Or, of course, I'm misunderstanding something...


IIRC, we encountered many issues where people misunderstood the meaning of 
"wait+async",
using it as if the local host sync happened, where in our original 
implementation it does not.

Also some areas of the OpenACC spec were vague on whether the local host 
synchronization should
or should not happen; basically, the wording treated as if it was only an 
implementation detail
and didn't matter, and didn't acknowledge that this would be something visible 
to the user.

At the end, IIRC, I decided that adding a local host synchronization is easier 
for all of us,
and took the opportunity of the re-org to make this change.

That said, I didn't notice those tests you listed above were meant to test such 
delicate behavior.


(For avoidance of doubt, I would accept the "async re-work" as is, but we
should eventually clarify this, and restore the behavior we -- apparently
-- had before, where we didn't synchronize so much?  (So, technically,
the "async re-work" would constitute a regression for this kind of
usage?)


It's not hard to restore the old behavior, just a few lines to delete. Although 
as described
above, this change was deliberate.

This might be another issue to raise with the committee. I think I tried on 
this exact issue
a long time ago, but never got answers.

Thanks,
Chung-Lin


Re: [PATCH] Delete powerpcspe

2018-12-11 Thread Jeff Law
On 12/11/18 1:44 AM, Richard Biener wrote:
> On Mon, Dec 10, 2018 at 9:13 PM Segher Boessenkool
>  wrote:
>>
>> On Mon, Dec 10, 2018 at 06:25:31PM +, Andrew Jenner wrote:
>>> Sorry for the slow response on this, I was on vacation last week.
>>>
>>> On 03/12/2018 21:48, Jakub Jelinek wrote:
 I'd give the maintainers the last week to act if they don't want this
 to happen and if nothing happens, commit it.  PR81084 lists all the reasons
 why it should be removed when it is totally unmaintained.
 Just make sure to put stuff that belongs there to gcc/ChangeLog and without
 gcc/ prefixes.
>>>
>>> Yes, please go ahead and commit
>>
>> Committed to trunk as r266961.
>>
>>> - it's not fair on other maintainers to
>>> have to work around my lack of action on this port. I will continue to
>>> work on it out-of-tree and hope to restore it once it is in proper shape.
>>
>> The more important thing is maintenance...  Regular and/or frequent tests
>> (posted to gcc-testresults@), bug tracker maintenance, etc.  You need to
>> be visible.
> 
> Very much agreed on that.  Though if we pull out this card we're applying
> double-standards here considering for example ia64 or some embedded ports.
The biggest problem with the embedded ports is lack of reliable
simulator testing combined with reduced address space availability.  So
you end up with a test that works fine today, but due to a runtime clash
of the stack and heap it may well fail tomorrow due to an unrelated code
change (by changing what's on the stack and where).  Or worse yet, you
end up with hundreds of tests that time out, causing the testrun to go
on so long it's useless.

One way to deal with these problems is to create a fake simulator that
always returns success.  That's what my tester does for the embedded
targets.  That allows us to do reliable compile-time tests as well as
the various scan-whatever tests.

It would be trivial to start sending those results to gcc-testresults.

jeff


Re: [PATCH 4/6, OpenACC, libgomp] Async re-work, libgomp/target.c changes (revised, v2)

2018-12-11 Thread Chung-Lin Tang

On 2018/12/7 1:43 AM, Jakub Jelinek wrote:

On Thu, Dec 06, 2018 at 06:21:16PM +0100, Thomas Schwinge wrote:

On Tue, 25 Sep 2018 21:11:24 +0800, Chung-Lin Tang  
wrote:

Hi Jakub,
This part has changes to 'struct goacc_asyncqueue*' arguments to various
memory copying/mapping functions. To lessen the amount of code changes new 
'gomp_map/unmap_vars_async'
functions names are used (with the non-async original names defined with the 
asyncqueue==NULL).


Is that the way you'd like this to be done, or should instead that
"struct goacc_asyncqueue *aq" parameter be added/passed through all the
existing functions?  (The latter would be my preference, actually.)


I'd prefer not to increase the amount of arguments where possible, because
many of the functions already have more arguments than can be passed in
registers.  Could it be e.g. added into gomp_coalesce_buf which is already
passed around?

Another option would be to use always_inline as C template if the OpenMP and
OpenACC needs diverge too much, then have simply small wrappers that just
call the always_inline function, in one case with the argument NULL or other
constant, in another one with whatever it has been called with.

Jakub


I have revised the patch to make both gomp_[un]map_vars and 
gomp_[un]map_vars_async
point to gomp_[un]map_vars_internal, which is static always_inline. This should
alleviate that part of the concerns.

Thanks,
Chung-Lin

Index: libgomp/target.c
===
--- libgomp/target.c(revision 266973)
+++ libgomp/target.c(working copy)
@@ -177,6 +177,22 @@ gomp_device_copy (struct gomp_device_descr *device
 }
 }
 
+static inline void
+goacc_device_copy_async (struct gomp_device_descr *devicep,
+bool (*copy_func) (int, void *, const void *, size_t,
+   struct goacc_asyncqueue *),
+const char *dst, void *dstaddr,
+const char *src, const void *srcaddr,
+size_t size, struct goacc_asyncqueue *aq)
+{
+  if (!copy_func (devicep->target_id, dstaddr, srcaddr, size, aq))
+{
+  gomp_mutex_unlock (&devicep->lock);
+  gomp_fatal ("Copying of %s object [%p..%p) to %s object [%p..%p) failed",
+ src, srcaddr, srcaddr + size, dst, dstaddr, dstaddr + size);
+}
+}
+
 /* Infrastructure for coalescing adjacent or nearly adjacent (in device 
addresses)
host to device memory transfers.  */
 
@@ -263,8 +279,9 @@ gomp_to_device_kind_p (int kind)
 }
 }
 
-static void
+attribute_hidden void
 gomp_copy_host2dev (struct gomp_device_descr *devicep,
+   struct goacc_asyncqueue *aq,
void *d, const void *h, size_t sz,
struct gomp_coalesce_buf *cbuf)
 {
@@ -293,14 +310,23 @@ gomp_copy_host2dev (struct gomp_device_descr *devi
}
}
 }
-  gomp_device_copy (devicep, devicep->host2dev_func, "dev", d, "host", h, sz);
+  if (aq)
+goacc_device_copy_async (devicep, devicep->openacc.async.host2dev_func,
+"dev", d, "host", h, sz, aq);
+  else
+gomp_device_copy (devicep, devicep->host2dev_func, "dev", d, "host", h, 
sz);
 }
 
-static void
+attribute_hidden void
 gomp_copy_dev2host (struct gomp_device_descr *devicep,
+   struct goacc_asyncqueue *aq,
void *h, const void *d, size_t sz)
 {
-  gomp_device_copy (devicep, devicep->dev2host_func, "host", h, "dev", d, sz);
+  if (aq)
+goacc_device_copy_async (devicep, devicep->openacc.async.dev2host_func,
+"host", h, "dev", d, sz, aq);
+  else
+gomp_device_copy (devicep, devicep->dev2host_func, "host", h, "dev", d, 
sz);
 }
 
 static void
@@ -318,7 +344,8 @@ gomp_free_device_memory (struct gomp_device_descr
Helper function of gomp_map_vars.  */
 
 static inline void
-gomp_map_vars_existing (struct gomp_device_descr *devicep, splay_tree_key oldn,
+gomp_map_vars_existing (struct gomp_device_descr *devicep,
+   struct goacc_asyncqueue *aq, splay_tree_key oldn,
splay_tree_key newn, struct target_var_desc *tgt_var,
unsigned char kind, struct gomp_coalesce_buf *cbuf)
 {
@@ -340,7 +367,7 @@ static inline void
 }
 
   if (GOMP_MAP_ALWAYS_TO_P (kind))
-gomp_copy_host2dev (devicep,
+gomp_copy_host2dev (devicep, aq,
(void *) (oldn->tgt->tgt_start + oldn->tgt_offset
  + newn->host_start - oldn->host_start),
(void *) newn->host_start,
@@ -358,8 +385,8 @@ get_kind (bool short_mapkind, void *kinds, int idx
 }
 
 static void
-gomp_map_pointer (struct target_mem_desc *tgt, uintptr_t host_ptr,
- uintptr_t target_offset, uintptr_t bias,
+gomp_map_pointer (struct target_mem_desc *tgt, struct goacc_asyncqueue *aq,
+ uintptr_t host_p

Re: [PATCH 6/6, OpenACC, libgomp] Async re-work, nvptx changes (revised, v2)

2018-12-11 Thread Chung-Lin Tang

On 2018/12/10 6:02 PM, Chung-Lin Tang wrote:

On 2018/12/7 04:57 AM, Thomas Schwinge wrote>> --- 
a/libgomp/plugin/plugin-nvptx.c

+++ b/libgomp/plugin/plugin-nvptx.c



+struct goacc_asyncqueue *
+GOMP_OFFLOAD_openacc_async_construct (void)
+{
+  struct goacc_asyncqueue *aq
+    = GOMP_PLUGIN_malloc (sizeof (struct goacc_asyncqueue));
+  aq->cuda_stream = NULL;
+  CUDA_CALL_ASSERT (cuStreamCreate, &aq->cuda_stream, CU_STREAM_DEFAULT);


Curiously (this was the same in the code before): does this have to be
"CU_STREAM_DEFAULT" instead of "CU_STREAM_NON_BLOCKING", because we want
to block anything from running in parallel with "acc_async_sync" GPU
kernels, that use the "NULL" stream?  (Not asking you to change this now,
but I wonder if this is overly strict?)


IIUC, this non-blocking only pertains to the "Legacy Default Stream" in CUDA, 
which we're pretty much ignoring; we should be using the newer per-thread default stream 
model. We could review this issue later.


+  if (aq->cuda_stream == NULL)
+    GOMP_PLUGIN_fatal ("CUDA stream create NULL\n");


Can this actually happen, given the "CUDA_CALL_ASSERT" usage above?


Hmm, yeah I think this is superfluous too...


+  CUDA_CALL_ASSERT (cuStreamSynchronize, aq->cuda_stream);


Why is the synchronization needed here?


I don't remember, could likely be something added during debug.
I'll remove this and test if things are okay.


I have removed the above seemingly unneeded lines and re-tested, appears okay.
Also the formerly attached version seemed to for some reason had many conflicts
with older code, all resolved in this v2 nvptx part.

Thanks,
Chung-Lin
Index: libgomp/plugin/cuda/cuda.h
===
--- libgomp/plugin/cuda/cuda.h  (revision 266973)
+++ libgomp/plugin/cuda/cuda.h  (working copy)
@@ -54,7 +54,11 @@ typedef enum {
   CUDA_ERROR_INVALID_CONTEXT = 201,
   CUDA_ERROR_NOT_FOUND = 500,
   CUDA_ERROR_NOT_READY = 600,
-  CUDA_ERROR_LAUNCH_FAILED = 719
+  CUDA_ERROR_LAUNCH_FAILED = 719,
+  CUDA_ERROR_COOPERATIVE_LAUNCH_TOO_LARGE = 720,
+  CUDA_ERROR_NOT_PERMITTED = 800,
+  CUDA_ERROR_NOT_SUPPORTED = 801,
+  CUDA_ERROR_UNKNOWN = 999
 } CUresult;
 
 typedef enum {
@@ -173,6 +177,8 @@ CUresult cuModuleLoadData (CUmodule *, const void
 CUresult cuModuleUnload (CUmodule);
 CUresult cuOccupancyMaxPotentialBlockSize(int *, int *, CUfunction,
  CUoccupancyB2DSize, size_t, int);
+typedef void (*CUstreamCallback)(CUstream, CUresult, void *);
+CUresult cuStreamAddCallback(CUstream, CUstreamCallback, void *, unsigned int);
 CUresult cuStreamCreate (CUstream *, unsigned);
 #define cuStreamDestroy cuStreamDestroy_v2
 CUresult cuStreamDestroy (CUstream);
Index: libgomp/plugin/cuda-lib.def
===
--- libgomp/plugin/cuda-lib.def (revision 266973)
+++ libgomp/plugin/cuda-lib.def (working copy)
@@ -42,6 +42,7 @@ CUDA_ONE_CALL (cuModuleLoad)
 CUDA_ONE_CALL (cuModuleLoadData)
 CUDA_ONE_CALL (cuModuleUnload)
 CUDA_ONE_CALL_MAYBE_NULL (cuOccupancyMaxPotentialBlockSize)
+CUDA_ONE_CALL (cuStreamAddCallback)
 CUDA_ONE_CALL (cuStreamCreate)
 CUDA_ONE_CALL (cuStreamDestroy)
 CUDA_ONE_CALL (cuStreamQuery)
Index: libgomp/plugin/plugin-nvptx.c
===
--- libgomp/plugin/plugin-nvptx.c   (revision 266973)
+++ libgomp/plugin/plugin-nvptx.c   (working copy)
@@ -192,21 +192,18 @@ cuda_error (CUresult r)
 static unsigned int instantiated_devices = 0;
 static pthread_mutex_t ptx_dev_lock = PTHREAD_MUTEX_INITIALIZER;
 
-struct cuda_map
+/* NVPTX/CUDA specific definition of asynchronous queues.  */
+struct goacc_asyncqueue
 {
-  CUdeviceptr d;
-  size_t size;
-  bool active;
-  struct cuda_map *next;
+  CUstream cuda_stream;
 };
 
-struct ptx_stream
+struct nvptx_callback
 {
-  CUstream stream;
-  pthread_t host_thread;
-  bool multithreaded;
-  struct cuda_map *map;
-  struct ptx_stream *next;
+  void (*fn) (void *);
+  void *ptr;
+  struct goacc_asyncqueue *aq;
+  struct nvptx_callback *next;
 };
 
 /* Thread-specific data for PTX.  */
@@ -213,120 +210,13 @@ static pthread_mutex_t ptx_dev_lock = PTHREAD_MUTE
 
 struct nvptx_thread
 {
-  struct ptx_stream *current_stream;
+  /* We currently have this embedded inside the plugin because libgomp manages
+ devices through integer target_ids.  This might be better if using an
+ opaque target-specific pointer directly from gomp_device_descr.  */
   struct ptx_device *ptx_dev;
 };
 
-static struct cuda_map *
-cuda_map_create (size_t size)
-{
-  struct cuda_map *map = GOMP_PLUGIN_malloc (sizeof (struct cuda_map));
 
-  assert (map);
-
-  map->next = NULL;
-  map->size = size;
-  map->active = false;
-
-  CUDA_CALL_ERET (NULL, cuMemAlloc, &map->d, size);
-  assert (map->d);
-
-  return map;
-}
-
-static void
-cuda_map_destroy (struct cuda_map *map)
-{
-  CUDA_CALL_ASSERT (cuMemFree, map->d);
-  free (map);
-}
-
-/

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

2018-12-11 Thread Segher Boessenkool
Hi Umesh,

On Tue, Dec 11, 2018 at 05:30:48PM +0530, Umesh Kalappa wrote:
> Please find the attached patch for the subjected issue .
> 
> Do please let me know your thoughts and comments on the same .

First of all: do you have a copyright assignment with the FSF?

Second: please don't send application/octet-stream attachments.


diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index ee5f183..d1c0edb 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,14 @@
+2018-12-06  Lokesh Janghel  
+
+PR target/84762
+* config/rs6000/rs6000.c (rs6000_return_in_msb): Retrun in svr4 for
+small struct value.
+(rs6000_option_override_internal): Modify the condition for aix or
+svr4. 
+   * config/rs6000/rs6000.opt : Modify the -msvr4-struct-return option.
+   * config/rs6000/rs6000-opts.h : Add enum for svr4 option (Big endian 
+   and Little endian).

The changelog should not be part of the patch, but written before it.
Not as diff, just as the text it is.

Indent is one tab.  Not a tab and a space, not nine spaces.

There shouldn't be trailing spaces.

There should not be a space before a colon.

"Modify XYZ." means that you should have "(XYZ): Modify." instead; but
you probably can say more than just "Modify", too.  Like, _what_ have you
changed about it :-)

s/retrun/return/

The changelog should mention everything you change.  I haven't checked
if it does here, but all the testcases are missing (those have their own
changelog, in gcc/testsuite/ChangeLog).

+/* Return small structs in register,
+   gnu: LSB-aligned,
+   standard: MSB-aligned*/

This should end with dot space space */

+enum rs6000_svr4_struct_return {
+  SVR4_STRUCT_RETURN_GNU=1,
+  SVR4_STRUCT_RETURN_STD
+};

I think a simple boolean would be easier?

diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c
index 2765263..4751b61 100644
--- a/gcc/config/rs6000/rs6000.c
+++ b/gcc/config/rs6000/rs6000.c
@@ -4632,7 +4632,8 @@ rs6000_option_override_internal (bool global_init_p)
   /* Set aix_struct_return last, after the ABI is determined.
 If -maix-struct-return or -msvr4-struct-return was explicitly
 used, don't override with the ABI default.  */
-  if (!global_options_set.x_aix_struct_return)
+  if (!global_options_set.x_aix_struct_return
+  && !rs6000_current_svr4_struct_return)
aix_struct_return = (DEFAULT_ABI != ABI_V4 || DRAFT_V4_STRUCT_RET);

Why this change?

 static bool
 rs6000_return_in_msb (const_tree valtype)
 {
-  return (DEFAULT_ABI == ABI_ELFv2
- && BYTES_BIG_ENDIAN
+  return ((DEFAULT_ABI == ABI_ELFv2
+  || (DEFAULT_ABI == ABI_V4
+  && rs6000_current_svr4_struct_return == SVR4_STRUCT_RETURN_STD))
+ && BYTES_BIG_ENDIAN
  && AGGREGATE_TYPE_P (valtype)
  && (rs6000_function_arg_padding (TYPE_MODE (valtype), valtype)
  == PAD_UPWARD));

Indents are with tabs, not eight spaces.  There never should be tabs
after spaces though.

Please write this as

  if (DEFAULT_ABI == ABI_ELFv2
  && BYTES_BIG_ENDIAN
  && AGGREGATE_TYPE_P (valtype)
  && (rs6000_function_arg_padding (TYPE_MODE (valtype), valtype)
  == PAD_UPWARD))
return true;

  if (DEFAULT_ABI == ABI_V4
  && rs6000_current_svr4_struct_return == SVR4_STRUCT_RETURN_STD
  && BYTES_BIG_ENDIAN
  && AGGREGATE_TYPE_P (valtype)
  && (rs6000_function_arg_padding (TYPE_MODE (valtype), valtype)
  == PAD_UPWARD))
return true;

  return false;

But, on the other hand, you should do this in rs6000_function_arg_padding
instead I think.

-msvr4-struct-return
-Target Report RejectNegative Var(aix_struct_return,0) Save
-Return small structures in registers (SVR4 default).
+msvr4-struct-return=
+Target RejectNegative Joined Enum(rs6000_svr4_struct_return)  
Var(rs6000_current_svr4_struct_return)
+-msvr4-struct-return=[standard,gnu] Return small structures in registers (SVR4 
default).
+
+Enum
+Name(rs6000_svr4_struct_return) Type(enum rs6000_svr4_struct_return)
+
+EnumValue
+Enum(rs6000_svr4_struct_return) String(standard) Value(SVR4_STRUCT_RETURN_STD) 
+
+EnumValue
+Enum(rs6000_svr4_struct_return) String(gnu) Value(SVR4_STRUCT_RETURN_GNU) 

You are removing the -msvr4-struct-return option (without =).  We shouldn't
delete command line options.

--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,10 @@
+2018-12-06  Lokesh Janghel  
+
+PR target/84762
+* gcc.target/pr84762-1.c: New testcase.
+* gcc.target/pr84762-2.c: New testcase.
+* gcc.target/pr84762-3.c: New testcase.

These should be before the patch as well.

+++ b/gcc/testsuite/gcc.target/powerpc/pr84762-1.c
@@ -0,0 +1,9 @@
+/* { dg-do run { target powerpc*-*-* rs6000-*-* } } */

You don't have to mention the target in gcc.target/powerpc; just say

+/* { dg-do run } */

+struct smallstruct { char a; char b; char c; };
+
+struct smallstruct f(void)
+{
+  struct smallstruct s = { 0x11

Re: [PATCH] Set DEMANGLE_RECURSION_LIMIT to 1536

2018-12-11 Thread Ian Lance Taylor via gcc-patches
On Tue, Dec 11, 2018 at 3:05 AM Pedro Alves  wrote:
>
> I noticed that the comment on top of __cxa_demangle says:
>
>   "If OUTPUT_BUFFER is not long enough, it is expanded using realloc."
>
> and __cxa_demangle calls 'free'.
>
> And d_demangle, seemingly the workhorse for __cxa_demangle says:
>
> /* Entry point for the demangler.  If MANGLED is a g++ v3 ABI mangled
>name, return a buffer allocated with malloc holding the demangled
>name.  OPTIONS is the usual libiberty demangler options.  On
>success, this sets *PALC to the allocated size of the returned
>buffer.  On failure, this sets *PALC to 0 for a bad name, or 1 for
>a memory allocation failure, and returns NULL.  */
>
> cplus_demangle, the entry point that gdb uses, also relies on malloc.
>
> Ian earlier mentioned that we've wanted to avoid malloc because some
> programs call the demangler from a signal handler, but it seems like
> we already do, these functions already aren't safe to use from
> signal handlers as is.  Where does the "we can't use malloc" idea
> come from?  Is there some entry point that avoids
> the malloc/realloc/free calls?

cplus_demangle_v3_callback and cplus_demangle_print_callback.

Ian


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

2018-12-11 Thread Umesh Kalappa
Thank you Jakub for the information.

Will make a note of it.

Umesh



On Tue, Dec 11, 2018, 17:58 Jakub Jelinek  On Tue, Dec 11, 2018 at 05:30:48PM +0530, Umesh Kalappa wrote:
> > Hi All,
> >
> > Please find the attached patch for the subjected issue .
> >
> > Do please let me know your thoughts and comments on the same .
>
> Not a patch review (will defer that to rs6000 maintainers), but
> some comments on gcc-patches patch submissions.
>
> The subject should ideally start with [PATCH] or similar,
> then have some short summary of what the patch is about and if
> it fixes some PR, just PR something/12345 reference,
> the subjects you are posting like:
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84762
> don't say anything relevant except for the PR 84762 number,
> so anyone reading gcc-patches needs to open that bug in order to even find
> out if it is something for him or somebody else.
>
> If you are sending a patch for an area that has some maintainer(s),
> usually you should either mention those maintainers in To: (and CC:
> gcc-patches) or To: gcc-patches, CC: the maintainers, to draw their
> attention.  See MAINTAINERS file in GCC tree.
>
> The mail body should start with a short explanation of what the problem is
> and how are you solving it, again, so that people don't have to jump to
> bugzilla to find out (of course, short is enough, no need to duplicate
> dozens of comments from the PR), should include information on what
> target(s) it has been bootstrapped/regtested.  And, it is always better if
> it is the patch author that posts it, or is at least CCed so that he can
> answer review questions.
>
> Thanks.
>
> Jakub
>


Re: [gofrontend-dev] Re: libgo patch committed: Add precise stack scan support

2018-12-11 Thread Matthias Klose
On 10.12.18 16:54, Cherry Zhang wrote:
> On Mon, Dec 10, 2018 at 1:41 AM Matthias Klose  wrote:
> 
>> On 06.12.18 00:09, Ian Lance Taylor wrote:
>>> This libgo patch by Cherry Zhang adds support for precise stack
>>> scanning to the Go runtime.  This uses per-function stack maps stored
>>> in the exception tables in the language-specific data area.  The
>>> compiler needs to generate these stack maps; currently this is only
>>> done by a version of LLVM, not by GCC.  Each safepoint in a function
>>> is associated with a (real or dummy) landing pad, and its "type info"
>>> in the exception table is a pointer to the stack map. When a stack is
>>> scanned, the stack map is found by the stack unwinding code.
>>>
>>> For precise stack scan we need to unwind the stack. There are three
>> cases:
>>>
>>> - If a goroutine is scanning its own stack, it can unwind the stack
>>> and scan the frames.
>>>
>>> - If a goroutine is scanning another, stopped, goroutine, it cannot
>>> directly unwind the target stack. We handle this by switching
>>> (runtime.gogo) to the target g, letting it unwind and scan the stack,
>>> and switch back.
>>>
>>> - If we are scanning a goroutine that is blocked in a syscall, we send
>>> a signal to the target goroutine's thread, and let the signal handler
>>> unwind and scan the stack. Extra care is needed as this races with
>>> enter/exit syscall.
>>>
>>> Currently this is only implemented on GNU/Linux.
>>>
>>> Bootstrapped and ran Go testsuite on x86_64-pc-linux-gnu.  Committed
>>> to mainline.
>>
>> this broke the libgo build on ARM32:
>>
>> ../../../src/libgo/runtime/go-unwind.c: In function
>> 'scanstackwithmap_callback':
>> ../../../src/libgo/runtime/go-unwind.c:754:18: error: '_URC_NORMAL_STOP'
>> undeclared (first use in this function)
>>   754 |   return _URC_NORMAL_STOP;
>>   |  ^~~~
>> ../../../src/libgo/runtime/go-unwind.c:754:18: note: each undeclared
>> identifier
>> is reported only once for each function i
>> t appears in
>> ../../../src/libgo/runtime/go-unwind.c: In function
>> 'probestackmaps_callback':
>> ../../../src/libgo/runtime/go-unwind.c:802:10: error: '_URC_NORMAL_STOP'
>> undeclared (first use in this function)
>>   802 |   return _URC_NORMAL_STOP;
>>   |  ^~~~
>> ../../../src/libgo/runtime/go-unwind.c:803:1: warning: control reaches end
>> of
>> non-void function [-Wreturn-type]
>>   803 | }
>>   | ^
>> make[6]: *** [Makefile:1474: runtime/go-unwind.lo] Error 1
>> make[6]: Leaving directory
>> '/<>/build/arm-linux-gnueabihf/libgo'
>>
>>
> Hell Matthias,
> 
> Thank you for the report. And sorry about the breakage. Does
> https://go-review.googlesource.com/c/gofrontend/+/153417 (or the patch
> below) fix ARM32 build? I don't have an ARM32 machine at hand to test.

this fixes the build.

currently running the testsuite, almost every test case core dumps on
arm-linux-gnueabihf

Matthias


Fix alignment of dynamically allocated stack areas on ppc-vxworks

2018-12-11 Thread Olivier Hainque
Hello,

The attached patch, provided by Eric Botcazou (thanks!), installs
definitions of RS6000_STARTING_FRAME_OFFSET and STACK_DYNAMIC_OFFSET
for PowerPC VxWorks, which has STACK_BOUNDARY set to 128
unconditionally.

AFAICS, this is the third OS config file doing this, after Darwin
and AIX. It seems like we could (should ?) account for STACK_BOUNDARY
or maybe PREFERRED_STACK_BOUNDARY in the common rs6000.h definition.

We have tested this successfully with a gcc-8 based compiler for
powerpc-wrs-vxworks, where this fixes SEGVs observed on Ada programs
performing dynamic stack allocations.

With Kind Regards,

Olivier

2018-12-11  Eric Botcazou  

* config/rs6000/vxworks.h (RS6000_STARTING_FRAME_OFFSET): Define,
accounting for STACK_BOUNDARY 128.
(STACK_DYNAMIC_OFFSET): Likewise.

diff --git a/gcc/config/rs6000/vxworks.h b/gcc/config/rs6000/vxworks.h
index d2033f6..24fe9ba 100644
--- a/gcc/config/rs6000/vxworks.h
+++ b/gcc/config/rs6000/vxworks.h
@@ -116,7 +116,7 @@ VXWORKS_ADDITIONAL_CPP_SPEC
 #undef SDATA_DEFAULT_SIZE
 #define SDATA_DEFAULT_SIZE (TARGET_VXWORKS_RTP ? 8 : 0)
 
-/* Enforce 16bytes alignment for the stack pointer, to permit general
+/* Enforce 16-byte alignment for the stack pointer, to permit general
compliance with e.g. Altivec instructions requirements.  Make sure
this isn't overruled by the EABI constraints.  */
 
@@ -128,6 +128,40 @@ VXWORKS_ADDITIONAL_CPP_SPEC
 
 #undef  ABI_STACK_BOUNDARY
 
+/* Offset within stack frame to start allocating local variables at.
+   If FRAME_GROWS_DOWNWARD, this is the offset to the END of the
+   first local allocated.  Otherwise, it is the offset to the BEGINNING
+   of the first local allocated.
+
+   On the RS/6000, the frame pointer is the same as the stack pointer,
+   except for dynamic allocations.  So we start after the fixed area and
+   outgoing parameter area.
+
+   If the function uses dynamic stack space (CALLS_ALLOCA is set), that
+   space needs to be aligned to STACK_BOUNDARY, i.e. the sum of the
+   sizes of the fixed area and the parameter area must be a multiple of
+   STACK_BOUNDARY.  */
+
+#undef RS6000_STARTING_FRAME_OFFSET
+#define RS6000_STARTING_FRAME_OFFSET   \
+  (cfun->calls_alloca  \
+   ? RS6000_ALIGN (crtl->outgoing_args_size + RS6000_SAVE_AREA, 16)\
+   : (RS6000_ALIGN (crtl->outgoing_args_size, 16) + RS6000_SAVE_AREA))
+
+/* Offset from the stack pointer register to an item dynamically
+   allocated on the stack, e.g., by `alloca'.
+
+   The default value for this macro is `STACK_POINTER_OFFSET' plus the
+   length of the outgoing arguments.  The default is correct for most
+   machines.  See `function.c' for details.
+
+   This value must be a multiple of STACK_BOUNDARY (hard coded in
+   `emit-rtl.c').  */
+#undef STACK_DYNAMIC_OFFSET
+#define STACK_DYNAMIC_OFFSET(FUNDECL)  \
+   RS6000_ALIGN (crtl->outgoing_args_size.to_constant ()   \
++ STACK_POINTER_OFFSET, 16)
+
 #undef SUBSUBTARGET_OVERRIDE_OPTIONS
 #define SUBSUBTARGET_OVERRIDE_OPTIONS  \
   do { \


Re: [PATCH] Set DEMANGLE_RECURSION_LIMIT to 1536

2018-12-11 Thread Pedro Alves
On 12/11/2018 02:25 PM, Ian Lance Taylor wrote:
> On Tue, Dec 11, 2018 at 3:05 AM Pedro Alves  wrote:

>> Ian earlier mentioned that we've wanted to avoid malloc because some
>> programs call the demangler from a signal handler, but it seems like
>> we already do, these functions already aren't safe to use from
>> signal handlers as is.  Where does the "we can't use malloc" idea
>> come from?  Is there some entry point that avoids
>> the malloc/realloc/free calls?
> 
> cplus_demangle_v3_callback and cplus_demangle_print_callback.

Ah, gotcha.  Thanks!  Interesting.

Pedro Alves


Re: [PATCH, OpenACC] Add support for gang local storage allocation in shared memory

2018-12-11 Thread Julian Brown
On Fri, 17 Aug 2018 18:39:00 +0200
Bernhard Reutner-Fischer  wrote:

> On 16 August 2018 17:46:43 CEST, Julian Brown
>  wrote:
> >On Wed, 15 Aug 2018 21:56:54 +0200
> >Bernhard Reutner-Fischer  wrote:
> >  
> >> On 15 August 2018 18:46:37 CEST, Julian Brown
> >>  wrote:  
> >> >On Mon, 13 Aug 2018 12:06:21 -0700
> >> >Cesar Philippidis  wrote:
> >> 
> >> atttribute has more t than strictly necessary. 
> >> Don't like signed integer levels where they should be some
> >> unsigned. Also don't like single switch cases instead of if.
> >> And omitting function comments even if the hook way above is
> >> documented may be ok ish but is a bit lazy ;)  
> >
> >Here's a new version with those comments addressed. I also changed
> >the logic around a little to avoid adding decls to the vec in
> >omp_context which would never be given the gang-private attribute.
> >
> >Re-tested with offloading to NVPTX.
> >
> >OK?  
> 
> (TREE_CODE (var) == VAR_DECL
> Is nowadays known as VAR_P (decl), FWIW.

Fixed. (And also Tom's formatting nit mentioned in another email.)

> ISTM that global variables are not JIT-friendly.
> No further comments from me.

Probably true, but AFAIK nobody's trying to use the (GCC) JIT with the
PTX backend, and the backend already uses global variables for several
other purposes. Of course PTX code is JIT'ted itself by the NVidia
runtime, but I guess that's not what you were referring to!

Is this version OK? Re-tested with offloading to NVPTX.

Thanks,

Julian
commit 3335ddfa72944be5359280116e8eb4febd4ed3c7
Author: Julian Brown 
Date:   Thu Aug 9 20:27:04 2018 -0700

[OpenACC] Add support for gang local storage allocation in shared memory

2018-08-10  Julian Brown  
	Chung-Lin Tang  

	gcc/
	* config/nvptx/nvptx.c (tree-hash-traits.h): Include.
	(gangprivate_shared_size): New global variable.
	(gangprivate_shared_align): Likewise.
	(gangprivate_shared_sym): Likewise.
	(gangprivate_shared_hmap): Likewise.
	(nvptx_option_override): Initialize gangprivate_shared_sym,
	gangprivate_shared_align.
	(nvptx_file_end): Output gangprivate_shared_sym.
	(nvptx_goacc_expand_accel_var): New function.
	(nvptx_set_current_function): New function.
	(TARGET_SET_CURRENT_FUNCTION): Define hook.
	(TARGET_GOACC_EXPAND_ACCEL): Likewise.
	* doc/tm.texi (TARGET_GOACC_EXPAND_ACCEL_VAR): Document new hook.
	* doc/tm.texi.in (TARGET_GOACC_EXPAND_ACCEL_VAR): Likewise.
	* expr.c (expand_expr_real_1): Remap decls marked with the
	"oacc gangprivate" attribute.
	* omp-low.c (omp_context): Add oacc_partitioning_level and
	oacc_addressable_var_decls fields.
	(new_omp_context): Initialize oacc_addressable_var_decls in new
	omp_context.
	(delete_omp_context): Delete oacc_addressable_var_decls in old
	omp_context.
	(lower_oacc_head_tail): Record partitioning-level count in omp context.
	(oacc_record_private_var_clauses, oacc_record_vars_in_bind)
	(mark_oacc_gangprivate): New functions.
	(lower_omp_for): Call oacc_record_private_var_clauses with "for"
	clauses.  Call mark_oacc_gangprivate for gang-partitioned loops.
	(lower_omp_target): Call oacc_record_private_var_clauses with "target"
	clauses.
	Call mark_oacc_gangprivate for offloaded target regions.
	(lower_omp_1): Call vars_in_bind for GIMPLE_BIND within OMP regions.
	* target.def (expand_accel_var): New hook.

	libgomp/
	* testsuite/libgomp.oacc-c-c++-common/gang-private-1.c: New test.
	* testsuite/libgomp.oacc-c-c++-common/loop-gwv-2.c: New test.
	* testsuite/libgomp.oacc-c/pr85465.c: New test.
	* testsuite/libgomp.oacc-fortran/gangprivate-attrib-1.f90: New test.

diff --git a/gcc/config/nvptx/nvptx.c b/gcc/config/nvptx/nvptx.c
index 9903a27..02c2847 100644
--- a/gcc/config/nvptx/nvptx.c
+++ b/gcc/config/nvptx/nvptx.c
@@ -73,6 +73,7 @@
 #include "cfgloop.h"
 #include "fold-const.h"
 #include "intl.h"
+#include "tree-hash-traits.h"
 
 /* This file should be included last.  */
 #include "target-def.h"
@@ -137,6 +138,12 @@ static unsigned worker_red_size;
 static unsigned worker_red_align;
 static GTY(()) rtx worker_red_sym;
 
+/* Shared memory block for gang-private variables.  */
+static unsigned gangprivate_shared_size;
+static unsigned gangprivate_shared_align;
+static GTY(()) rtx gangprivate_shared_sym;
+static hash_map gangprivate_shared_hmap;
+
 /* Global lock variable, needed for 128bit worker & gang reductions.  */
 static GTY(()) tree global_lock_var;
 
@@ -210,6 +217,10 @@ nvptx_option_override (void)
   SET_SYMBOL_DATA_AREA (worker_red_sym, DATA_AREA_SHARED);
   worker_red_align = GET_MODE_ALIGNMENT (SImode) / BITS_PER_UNIT;
 
+  gangprivate_shared_sym = gen_rtx_SYMBOL_REF (Pmode, "__gangprivate_shared");
+  SET_SYMBOL_DATA_AREA (gangprivate_shared_sym, DATA_AREA_SHARED);
+  gangprivate_shared_align = GET_MODE_ALIGNMENT (SImode) / BITS_PER_UNIT;
+
   diagnose_openacc_conflict (TARGET_GOMP, "-m

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

2018-12-11 Thread Umesh Kalappa
Thank you Segher, will work on your suggestions.

Umesh

On Tue, Dec 11, 2018, 19:23 Segher Boessenkool  Hi Umesh,
>
> On Tue, Dec 11, 2018 at 05:30:48PM +0530, Umesh Kalappa wrote:
> > Please find the attached patch for the subjected issue .
> >
> > Do please let me know your thoughts and comments on the same .
>
> First of all: do you have a copyright assignment with the FSF?
>
> Second: please don't send application/octet-stream attachments.
>
>
> diff --git a/gcc/ChangeLog b/gcc/ChangeLog
> index ee5f183..d1c0edb 100644
> --- a/gcc/ChangeLog
> +++ b/gcc/ChangeLog
> @@ -1,3 +1,14 @@
> +2018-12-06  Lokesh Janghel  
> +
> +PR target/84762
> +* config/rs6000/rs6000.c (rs6000_return_in_msb): Retrun in svr4
> for
> +small struct value.
> +(rs6000_option_override_internal): Modify the condition for aix or
> +svr4.
> +   * config/rs6000/rs6000.opt : Modify the -msvr4-struct-return
> option.
> +   * config/rs6000/rs6000-opts.h : Add enum for svr4 option (Big
> endian
> +   and Little endian).
>
> The changelog should not be part of the patch, but written before it.
> Not as diff, just as the text it is.
>
> Indent is one tab.  Not a tab and a space, not nine spaces.
>
> There shouldn't be trailing spaces.
>
> There should not be a space before a colon.
>
> "Modify XYZ." means that you should have "(XYZ): Modify." instead; but
> you probably can say more than just "Modify", too.  Like, _what_ have you
> changed about it :-)
>
> s/retrun/return/
>
> The changelog should mention everything you change.  I haven't checked
> if it does here, but all the testcases are missing (those have their own
> changelog, in gcc/testsuite/ChangeLog).
>
> +/* Return small structs in register,
> +   gnu: LSB-aligned,
> +   standard: MSB-aligned*/
>
> This should end with dot space space */
>
> +enum rs6000_svr4_struct_return {
> +  SVR4_STRUCT_RETURN_GNU=1,
> +  SVR4_STRUCT_RETURN_STD
> +};
>
> I think a simple boolean would be easier?
>
> diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c
> index 2765263..4751b61 100644
> --- a/gcc/config/rs6000/rs6000.c
> +++ b/gcc/config/rs6000/rs6000.c
> @@ -4632,7 +4632,8 @@ rs6000_option_override_internal (bool global_init_p)
>/* Set aix_struct_return last, after the ABI is determined.
>  If -maix-struct-return or -msvr4-struct-return was explicitly
>  used, don't override with the ABI default.  */
> -  if (!global_options_set.x_aix_struct_return)
> +  if (!global_options_set.x_aix_struct_return
> +  && !rs6000_current_svr4_struct_return)
> aix_struct_return = (DEFAULT_ABI != ABI_V4 || DRAFT_V4_STRUCT_RET);
>
> Why this change?
>
>  static bool
>  rs6000_return_in_msb (const_tree valtype)
>  {
> -  return (DEFAULT_ABI == ABI_ELFv2
> - && BYTES_BIG_ENDIAN
> +  return ((DEFAULT_ABI == ABI_ELFv2
> +  || (DEFAULT_ABI == ABI_V4
> +  && rs6000_current_svr4_struct_return == SVR4_STRUCT_RETURN_STD))
> + && BYTES_BIG_ENDIAN
>   && AGGREGATE_TYPE_P (valtype)
>   && (rs6000_function_arg_padding (TYPE_MODE (valtype), valtype)
>   == PAD_UPWARD));
>
> Indents are with tabs, not eight spaces.  There never should be tabs
> after spaces though.
>
> Please write this as
>
>   if (DEFAULT_ABI == ABI_ELFv2
>   && BYTES_BIG_ENDIAN
>   && AGGREGATE_TYPE_P (valtype)
>   && (rs6000_function_arg_padding (TYPE_MODE (valtype), valtype)
>   == PAD_UPWARD))
> return true;
>
>   if (DEFAULT_ABI == ABI_V4
>   && rs6000_current_svr4_struct_return == SVR4_STRUCT_RETURN_STD
>   && BYTES_BIG_ENDIAN
>   && AGGREGATE_TYPE_P (valtype)
>   && (rs6000_function_arg_padding (TYPE_MODE (valtype), valtype)
>   == PAD_UPWARD))
> return true;
>
>   return false;
>
> But, on the other hand, you should do this in rs6000_function_arg_padding
> instead I think.
>
> -msvr4-struct-return
> -Target Report RejectNegative Var(aix_struct_return,0) Save
> -Return small structures in registers (SVR4 default).
> +msvr4-struct-return=
> +Target RejectNegative Joined Enum(rs6000_svr4_struct_return)
> Var(rs6000_current_svr4_struct_return)
> +-msvr4-struct-return=[standard,gnu] Return small structures in registers
> (SVR4 default).
> +
> +Enum
> +Name(rs6000_svr4_struct_return) Type(enum rs6000_svr4_struct_return)
> +
> +EnumValue
> +Enum(rs6000_svr4_struct_return) String(standard)
> Value(SVR4_STRUCT_RETURN_STD)
> +
> +EnumValue
> +Enum(rs6000_svr4_struct_return) String(gnu) Value(SVR4_STRUCT_RETURN_GNU)
>
> You are removing the -msvr4-struct-return option (without =).  We shouldn't
> delete command line options.
>
> --- a/gcc/testsuite/ChangeLog
> +++ b/gcc/testsuite/ChangeLog
> @@ -1,3 +1,10 @@
> +2018-12-06  Lokesh Janghel  
> +
> +PR target/84762
> +* gcc.target/pr84762-1.c: New testcase.
> +* gcc.target/pr84762-2.c: New testcase.
> +* gcc.target/pr84762-3.c: New testcase.
>
> These sho

Re: [PATCH] accept all C integer types in function parameters referenced by alloc_align (PR 88363)

2018-12-11 Thread Jason Merrill

On 12/11/18 2:17 AM, Jakub Jelinek wrote:

On Mon, Dec 10, 2018 at 04:30:11PM -0700, Martin Sebor wrote:

Some of my testing exposed a minor problem in GCC 9's validation
of the type of function parameters referred to by attribute
positional arguments.  Whereas GCC 8 accepts all C integer types,
including enumerated types, such as:

   enum AllocAlign { Align16 = 16, Align32 = 32 };

   __attribute__ ((alloc_align (1))) void*
   alloc (size_t, enum AllocAlign)

GCC 9 only accepts signed and unsigned integer types.  This change
(introduced by myself) was unintentional, and a fix for it is in
the attached trivial patch.  I plan to commit it without approval
in the next day or so unless any concerns or suggestions come up.


There is nothing obvious about this, so please don't commit it without
approval.  GCC 8 and older used to accept
even float or void * or struct arguments and just ignored them.
I think we need to discuss what types we want to allow without warnings and
what we should warn.
As I wrote in the PR, I believe e.g. using alloc_align/alloc_size with
bool/_Bool is just a clear bug, you can store 0 or 1 in there, but e.g.
alignment 0 doesn't make sense.
Enums are on the border line, I'll defer to C/C++ maintainers whether we
want to include that or not.


I'd think we should allow (unscoped) enums in most places where we want 
an integer constant.


Jason


Re: C++ PATCH for c++/86608, reading constexpr volatile variable

2018-12-11 Thread Jason Merrill

On 12/10/18 8:48 PM, Marek Polacek wrote:

A template-argument for a non-type template-parameter shall be a converted
constant expression.  But an lvalue-to-rvalue conversion applied to a volatile
glvalue is not allowed to be part of the evaluation of a constant expression.
So this test should be rejected.


It occurred to me after my note on IRC that the 
potential_constant_expression_1 test we were talking about,


  if (TREE_THIS_VOLATILE (t) && !DECL_P (t))

ought to test want_rval rather than !DECL_P so that we consistently 
reject the lvalue-to-rvalue conversion, and not other uses of a volatile 
lvalue.  And the diagnostic ought to talk about that rather than 
"side-effects".


It might still be appropriate to change non_const_var_error, but I'd 
think it could check TREE_THIS_VOLATILE itself, rather than the caller; 
I don't see a need for the two calls to differ in their handling of 
volatile variables.


Perhaps decl_maybe_constant_var_p should return false for constexpr 
volatile, as well.


Jason


Re: [PATCH 2/4] c/c++, asm: Use nicer error for duplicate asm qualifiers

2018-12-11 Thread David Malcolm
On Mon, 2018-12-10 at 22:47 +, Segher Boessenkool wrote:

[...]

> diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c
> index 121a91c..652e53c 100644
> --- a/gcc/c/c-parser.c
> +++ b/gcc/c/c-parser.c
> @@ -6360,41 +6360,54 @@ c_parser_for_statement (c_parser *parser,
> bool ivdep, unsigned short unroll,
>  static tree
>  c_parser_asm_statement (c_parser *parser)
>  {
> -  tree quals, str, outputs, inputs, clobbers, labels, ret;
> -  bool simple, is_volatile, is_inline, is_goto;
> +  tree str, outputs, inputs, clobbers, labels, ret;
> +  bool simple;
>location_t asm_loc = c_parser_peek_token (parser)->location;
>int section, nsections;
>  
>gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM));
>c_parser_consume_token (parser);
>  
> -  quals = NULL_TREE;
> -  is_volatile = false;
> -  is_inline = false;
> -  is_goto = false;
> +  /* Handle the asm-qualifier-list.  */
> +  location_t volatile_loc = UNKNOWN_LOCATION;
> +  location_t inline_loc = UNKNOWN_LOCATION;
> +  location_t goto_loc = UNKNOWN_LOCATION;
>for (;;)
>  {
> -  switch (c_parser_peek_token (parser)->keyword)
> +  c_token *token = c_parser_peek_token (parser);
> +  location_t loc = token->location;
> +  switch (token->keyword)
>   {
>   case RID_VOLATILE:
> -   if (is_volatile)
> - break;
> -   is_volatile = true;
> -   quals = c_parser_peek_token (parser)->value;
> +   if (volatile_loc)
> + {
> +   error_at (loc, "duplicate asm qualifier %qE", token-
> >value);
> +   inform (volatile_loc, "first seen here");
> + }

Thanks for the improvements.

Is there test coverage for these errors and notes?

A diagnostic nit (new with gcc 9): please add an:
auto_diagnostic_group d;
to the start of the guarded block, so that the "error" and "note" are
known to be related.

See:
https://gcc.gnu.org/onlinedocs/gccint/Guidelines-for-Diagnostics.html#Group-logically-related-diagnostics


> +   else
> + volatile_loc = loc;
> c_parser_consume_token (parser);
> continue;
>  
>   case RID_INLINE:
> -   if (is_inline)
> - break;
> -   is_inline = true;
> +   if (inline_loc)
> + {
> +   error_at (loc, "duplicate asm qualifier %qE", token-
> >value);
> +   inform (inline_loc, "first seen here");

Likewise.

> + }
> +   else
> + inline_loc = loc;
> c_parser_consume_token (parser);
> continue;
>  
>   case RID_GOTO:
> -   if (is_goto)
> - break;
> -   is_goto = true;
> +   if (goto_loc)
> + {
> +   error_at (loc, "duplicate asm qualifier %qE", token-
> >value);
> +   inform (goto_loc, "first seen here");
> + }

Likewise.

> +   else
> + goto_loc = loc;
> c_parser_consume_token (parser);
> continue;

[...]
 
> diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
> index 1cc34ba..06a6bb0 100644
> --- a/gcc/cp/parser.c
> +++ b/gcc/cp/parser.c
> @@ -19649,29 +19646,50 @@ cp_parser_asm_definition (cp_parser*
> parser)
>  }
>  
>/* Handle the asm-qualifier-list.  */
> +  location_t volatile_loc = UNKNOWN_LOCATION;
> +  location_t inline_loc = UNKNOWN_LOCATION;
> +  location_t goto_loc = UNKNOWN_LOCATION;
>if (cp_parser_allow_gnu_extensions_p (parser))
>  for (;;)
>{
> + cp_token *token = cp_lexer_peek_token (parser->lexer);
> + location_t loc = token->location;
>   switch (cp_lexer_peek_token (parser->lexer)->keyword)
> {
> case RID_VOLATILE:
> - if (volatile_p)
> -   break;
> - volatile_p = true;
> + if (volatile_loc)
> +   {
> + error_at (loc, "duplicate asm qualifier %qT", token-
> >u.value);
> + inform (volatile_loc, "first seen here");

Likewise.

> +   }
> + else
> +   volatile_loc = loc;
>   cp_lexer_consume_token (parser->lexer);
>   continue;
>  
> case RID_INLINE:
> - if (inline_p || !parser->in_function_body)
> + if (!parser->in_function_body)
> break;
> - inline_p = true;
> + if (inline_loc)
> +   {
> + error_at (loc, "duplicate asm qualifier %qT", token-
> >u.value);
> + inform (inline_loc, "first seen here");

Likewise.

> +   }
> + else
> +   inline_loc = loc;
>   cp_lexer_consume_token (parser->lexer);
>   continue;
>  
> case RID_GOTO:
> - if (goto_p || !parser->in_function_body)
> + if (!parser->in_function_body)
> break;
> - goto_p = true;
> + if (goto_loc)
> +   {
> + error_at (loc, "duplicate asm qualifier %qT", token-
> >u.value);
> + inform (goto_loc, "first seen here");

Likewise.

> +   }
> + else
> +   goto_loc = loc;
>   cp_lexer_consume_token (parser->le

Re: [PATCH] accept all C integer types in function parameters referenced by alloc_align (PR 88363)

2018-12-11 Thread Marek Polacek
On Tue, Dec 11, 2018 at 08:17:26AM +0100, Jakub Jelinek wrote:
> On Mon, Dec 10, 2018 at 04:30:11PM -0700, Martin Sebor wrote:
> > Some of my testing exposed a minor problem in GCC 9's validation
> > of the type of function parameters referred to by attribute
> > positional arguments.  Whereas GCC 8 accepts all C integer types,
> > including enumerated types, such as:
> > 
> >   enum AllocAlign { Align16 = 16, Align32 = 32 };
> > 
> >   __attribute__ ((alloc_align (1))) void*
> >   alloc (size_t, enum AllocAlign)
> > 
> > GCC 9 only accepts signed and unsigned integer types.  This change
> > (introduced by myself) was unintentional, and a fix for it is in
> > the attached trivial patch.  I plan to commit it without approval
> > in the next day or so unless any concerns or suggestions come up.
> 
> There is nothing obvious about this, so please don't commit it without
> approval.  GCC 8 and older used to accept

I agree that this isn't an obvious change.

> even float or void * or struct arguments and just ignored them.
> I think we need to discuss what types we want to allow without warnings and
> what we should warn.
> As I wrote in the PR, I believe e.g. using alloc_align/alloc_size with
> bool/_Bool is just a clear bug, you can store 0 or 1 in there, but e.g.
> alignment 0 doesn't make sense.
> Enums are on the border line, I'll defer to C/C++ maintainers whether we
> want to include that or not.

For C, I'd allow them (and I think I've made a change to that effect in the
past in the C FE).

Marek


[PATCH 9/9][GCC][Arm] Add ACLE intrinsics for complex mutliplication and addition

2018-12-11 Thread Tamar Christina
Hi All,

This patch adds NEON intrinsics and tests for the Armv8.3-a complex
multiplication and add instructions with a rotate along the Argand plane.

The instructions are documented in the ArmARM[1] and the intrinsics 
specification
will be published on the Arm website [2].

The Lane versions of these instructions are special in that they always select 
a pair.
using index 0 means selecting lane 0 and 1.  Because of this the range check 
for the
intrinsics require special handling.

On Arm, in order to implement some of the lane intrinsics we're using the 
structure of the
register file.  The lane variant of these instructions always select a D 
register, but the data
itself can be stored in Q registers.  This means that for single precision 
complex numbers you are
only allowed to select D[0] but using the register file layout you can get the 
range 0-1 for lane indices
by selecting between Dn[0] and Dn+1[0].

Same reasoning applies for half float complex numbers, except there your D 
register indexes can be 0 or 1, so you have
a total range of 4 elements (for a V8HF).


[1] 
https://developer.arm.com/docs/ddi0487/latest/arm-architecture-reference-manual-armv8-for-armv8-a-architecture-profile
[2] https://developer.arm.com/docs/101028/latest

Bootstrapped Regtested on arm-none-gnueabihf and no issues.

Ok for trunk?

Thanks,
Tamar

gcc/ChangeLog:

2018-12-11  Tamar Christina  

* config/arm/arm-builtins.c
(enum arm_type_qualifiers): Add qualifier_lane_pair_index.
(MAC_LANE_PAIR_QUALIFIERS): New.
(arm_expand_builtin_args): Use it.
(arm_expand_builtin_1): Likewise.
* config/arm/arm-protos.h (neon_vcmla_lane_prepare_operands): New.
* config/arm/arm.c (neon_vcmla_lane_prepare_operands): New.
* config/arm/arm-c.c (arm_cpu_builtins): Add __ARM_FEATURE_COMPLEX.
* config/arm/arm_neon.h:
(vcadd_rot90_f16): New.
(vcaddq_rot90_f16): New.
(vcadd_rot270_f16): New.
(vcaddq_rot270_f16): New.
(vcmla_f16): New.
(vcmlaq_f16): New.
(vcmla_lane_f16): New.
(vcmla_laneq_f16): New.
(vcmlaq_lane_f16): New.
(vcmlaq_laneq_f16): New.
(vcmla_rot90_f16): New.
(vcmlaq_rot90_f16): New.
(vcmla_rot90_lane_f16): New.
(vcmla_rot90_laneq_f16): New.
(vcmlaq_rot90_lane_f16): New.
(vcmlaq_rot90_laneq_f16): New.
(vcmla_rot180_f16): New.
(vcmlaq_rot180_f16): New.
(vcmla_rot180_lane_f16): New.
(vcmla_rot180_laneq_f16): New.
(vcmlaq_rot180_lane_f16): New.
(vcmlaq_rot180_laneq_f16): New.
(vcmla_rot270_f16): New.
(vcmlaq_rot270_f16): New.
(vcmla_rot270_lane_f16): New.
(vcmla_rot270_laneq_f16): New.
(vcmlaq_rot270_lane_f16): New.
(vcmlaq_rot270_laneq_f16): New.
(vcadd_rot90_f32): New.
(vcaddq_rot90_f32): New.
(vcadd_rot270_f32): New.
(vcaddq_rot270_f32): New.
(vcmla_f32): New.
(vcmlaq_f32): New.
(vcmla_lane_f32): New.
(vcmla_laneq_f32): New.
(vcmlaq_lane_f32): New.
(vcmlaq_laneq_f32): New.
(vcmla_rot90_f32): New.
(vcmlaq_rot90_f32): New.
(vcmla_rot90_lane_f32): New.
(vcmla_rot90_laneq_f32): New.
(vcmlaq_rot90_lane_f32): New.
(vcmlaq_rot90_laneq_f32): New.
(vcmla_rot180_f32): New.
(vcmlaq_rot180_f32): New.
(vcmla_rot180_lane_f32): New.
(vcmla_rot180_laneq_f32): New.
(vcmlaq_rot180_lane_f32): New.
(vcmlaq_rot180_laneq_f32): New.
(vcmla_rot270_f32): New.
(vcmlaq_rot270_f32): New.
(vcmla_rot270_lane_f32): New.
(vcmla_rot270_laneq_f32): New.
(vcmlaq_rot270_lane_f32): New.
(vcmlaq_rot270_laneq_f32): New.
* config/arm/arm_neon_builtins.def (vcadd90, vcadd270, vcmla0, vcmla90,
vcmla180, vcmla270, vcmla_lane0, vcmla_lane90, vcmla_lane180, 
vcmla_lane270,
vcmla_laneq0, vcmla_laneq90, vcmla_laneq180, vcmla_laneq270,
vcmlaq_lane0, vcmlaq_lane90, vcmlaq_lane180, vcmlaq_lane270): New.
* config/arm/neon.md (neon_vcmla_lane,
neon_vcmla_laneq, neon_vcmlaq_lane): New.

gcc/testsuite/ChangeLog:

2018-12-11  Tamar Christina  

* gcc.target/aarch64/advsimd-intrinsics/vector-complex.c: Add AArch32 
regexpr.
* gcc.target/aarch64/advsimd-intrinsics/vector-complex_f16.c: Likewise.

-- 
diff --git a/gcc/config/arm/arm-builtins.c b/gcc/config/arm/arm-builtins.c
index 563ca51dcd0d63046d2bf577ca86d5f70a466bcf..1c7eac4b9eae55b76687b9239a2d71f31cc7b8d9 100644
--- a/gcc/config/arm/arm-builtins.c
+++ b/gcc/config/arm/arm-builtins.c
@@ -82,7 +82,10 @@ enum arm_type_qualifiers
   /* A void pointer.  */
   qualifier_void_pointer = 0x800,
   /* A const void pointer.  */
-  qualifier_const_void_pointer = 0x802
+  qualifier_const_void_pointer = 0x802,
+  /* Lane indices selected in pairs - must be within range of p

[PATCH 6/9][GCC][AArch64] Add Armv8.3-a complex intrinsics

2018-12-11 Thread Tamar Christina
Hi All,

This patch adds NEON intrinsics and tests for the Armv8.3-a complex
multiplication and add instructions with a rotate along the Argand plane.

The instructions are documented in the ArmARM[1] and the intrinsics 
specification
will be published on the Arm website [2].

The Lane versions of these instructions are special in that they always select 
a pair.
using index 0 means selecting lane 0 and 1.  Because of this the range check 
for the
intrinsics require special handling.

[1] 
https://developer.arm.com/docs/ddi0487/latest/arm-architecture-reference-manual-armv8-for-armv8-a-architecture-profile
[2] https://developer.arm.com/docs/101028/latest

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

Ok for trunk?

Thanks,
Tamar

gcc/ChangeLog:

2018-12-11  Tamar Christina  

* config/aarch64/aarch64-builtins.c (enum aarch64_type_qualifiers): Add 
qualifier_lane_pair_index.
(TYPES_QUADOP_LANE_PAIR): New.
(aarch64_simd_expand_args): Use it.
(aarch64_simd_expand_builtin): Likewise.
* config/aarch64/aarch64-c.c (aarch64_update_cpp_builtins): Add 
__ARM_FEATURE_COMPLEX.
* config/aarch64/aarch64-simd-builtins.def (fcadd90, fcadd270, fcmla0, 
fcmla90,
fcmla180, fcmla270, fcmla_lane0, fcmla_lane90, fcmla_lane180, 
fcmla_lane270,
fcmla_laneq0, fcmla_laneq90, fcmla_laneq180, fcmla_laneq270,
fcmlaq_lane0, fcmlaq_lane90, fcmlaq_lane180, fcmlaq_lane270): New.
* config/aarch64/aarch64-simd.md (aarch64_fcmla_lane,
aarch64_fcmla_laneq, aarch64_fcmlaq_lane): New.
* config/aarch64/arm_neon.h:
(vcadd_rot90_f16): New.
(vcaddq_rot90_f16): New.
(vcadd_rot270_f16): New.
(vcaddq_rot270_f16): New.
(vcmla_f16): New.
(vcmlaq_f16): New.
(vcmla_lane_f16): New.
(vcmla_laneq_f16): New.
(vcmlaq_lane_f16): New.
(vcmlaq_rot90_lane_f16): New.
(vcmla_rot90_laneq_f16): New.
(vcmla_rot90_lane_f16): New.
(vcmlaq_rot90_f16): New.
(vcmla_rot90_f16): New.
(vcmlaq_laneq_f16): New.
(vcmla_rot180_laneq_f16): New.
(vcmla_rot180_lane_f16): New.
(vcmlaq_rot180_f16): New.
(vcmla_rot180_f16): New.
(vcmlaq_rot90_laneq_f16): New.
(vcmlaq_rot270_laneq_f16): New.
(vcmlaq_rot270_lane_f16): New.
(vcmla_rot270_laneq_f16): New.
(vcmlaq_rot270_f16): New.
(vcmla_rot270_f16): New.
(vcmlaq_rot180_laneq_f16): New.
(vcmlaq_rot180_lane_f16): New.
(vcmla_rot270_lane_f16): New.
(vcadd_rot90_f32): New.
(vcaddq_rot90_f32): New.
(vcaddq_rot90_f64): New.
(vcadd_rot270_f32): New.
(vcaddq_rot270_f32): New.
(vcaddq_rot270_f64): New.
(vcmla_f32): New.
(vcmlaq_f32): New.
(vcmlaq_f64): New.
(vcmla_lane_f32): New.
(vcmla_laneq_f32): New.
(vcmlaq_lane_f32): New.
(vcmlaq_laneq_f32): New.
(vcmla_rot90_f32): New.
(vcmlaq_rot90_f32): New.
(vcmlaq_rot90_f64): New.
(vcmla_rot90_lane_f32): New.
(vcmla_rot90_laneq_f32): New.
(vcmlaq_rot90_lane_f32): New.
(vcmlaq_rot90_laneq_f32): New.
(vcmla_rot180_f32): New.
(vcmlaq_rot180_f32): New.
(vcmlaq_rot180_f64): New.
(vcmla_rot180_lane_f32): New.
(vcmla_rot180_laneq_f32): New.
(vcmlaq_rot180_lane_f32): New.
(vcmlaq_rot180_laneq_f32): New.
(vcmla_rot270_f32): New.
(vcmlaq_rot270_f32): New.
(vcmlaq_rot270_f64): New.
(vcmla_rot270_lane_f32): New.
(vcmla_rot270_laneq_f32): New.
(vcmlaq_rot270_lane_f32): New.
(vcmlaq_rot270_laneq_f32): New.

gcc/testsuite/ChangeLog:

2018-12-11  Tamar Christina  

* gcc.target/aarch64/advsimd-intrinsics/vector-complex.c: New test.
* gcc.target/aarch64/advsimd-intrinsics/vector-complex_f16.c: New test.

-- 
diff --git a/gcc/config/aarch64/aarch64-builtins.c b/gcc/config/aarch64/aarch64-builtins.c
index 8cced94567008e28b1761ec8771589a3925f2904..aaf18a909828b3eeac9d3b676f429923609972a3 100644
--- a/gcc/config/aarch64/aarch64-builtins.c
+++ b/gcc/config/aarch64/aarch64-builtins.c
@@ -102,7 +102,10 @@ enum aarch64_type_qualifiers
   /* Lane indices - must be in range, and flipped for bigendian.  */
   qualifier_lane_index = 0x200,
   /* Lane indices for single lane structure loads and stores.  */
-  qualifier_struct_load_store_lane_index = 0x400
+  qualifier_struct_load_store_lane_index = 0x400,
+  /* Lane indices selected in pairs. - must be in range, and flipped for
+ bigendian.  */
+  qualifier_lane_pair_index = 0x800,
 };
 
 typedef struct
@@ -171,6 +174,11 @@ aarch64_types_ternopu_imm_qualifiers[SIMD_MAX_BUILTIN_ARGS]
 #define TYPES_TERNOPUI (aarch64_types_ternopu_imm_qualifiers)
 
 
+static enum aarch64_type_qualifiers
+aarch64_types_quadop_lane_pair_qualifiers[SIMD_MAX_BUILTIN_ARGS]
+  = { qualifie

Re: C++ PATCH for c++/88216, ICE with class type in non-type template parameter

2018-12-11 Thread Jason Merrill

On 12/10/18 2:52 PM, Marek Polacek wrote:

+  if (processing_template_decl && value_dependent_expression_p (expr))


You don't need to check processing_template_decl before 
value_dependent_expression_p.


I would lean toward checking for value-dependence in 
convert_nontype_argument, which already does that a lot.  Enough, 
actually, that perhaps we should remember the result in a local variable.


Jason


Re: [PATCH 2/4] c/c++, asm: Use nicer error for duplicate asm qualifiers

2018-12-11 Thread David Malcolm
On Tue, 2018-12-11 at 10:35 -0500, David Malcolm wrote:
> On Mon, 2018-12-10 at 22:47 +, Segher Boessenkool wrote:
> 
> [...]
> 
> > diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c
> > index 121a91c..652e53c 100644
> > --- a/gcc/c/c-parser.c
> > +++ b/gcc/c/c-parser.c
> > @@ -6360,41 +6360,54 @@ c_parser_for_statement (c_parser *parser,
> > bool ivdep, unsigned short unroll,
> >  static tree
> >  c_parser_asm_statement (c_parser *parser)
> >  {
> > -  tree quals, str, outputs, inputs, clobbers, labels, ret;
> > -  bool simple, is_volatile, is_inline, is_goto;
> > +  tree str, outputs, inputs, clobbers, labels, ret;
> > +  bool simple;
> >location_t asm_loc = c_parser_peek_token (parser)->location;
> >int section, nsections;
> >  
> >gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM));
> >c_parser_consume_token (parser);
> >  
> > -  quals = NULL_TREE;
> > -  is_volatile = false;
> > -  is_inline = false;
> > -  is_goto = false;
> > +  /* Handle the asm-qualifier-list.  */
> > +  location_t volatile_loc = UNKNOWN_LOCATION;
> > +  location_t inline_loc = UNKNOWN_LOCATION;
> > +  location_t goto_loc = UNKNOWN_LOCATION;
> >for (;;)
> >  {
> > -  switch (c_parser_peek_token (parser)->keyword)
> > +  c_token *token = c_parser_peek_token (parser);
> > +  location_t loc = token->location;
> > +  switch (token->keyword)
> > {
> > case RID_VOLATILE:
> > - if (is_volatile)
> > -   break;
> > - is_volatile = true;
> > - quals = c_parser_peek_token (parser)->value;
> > + if (volatile_loc)
> > +   {
> > + error_at (loc, "duplicate asm qualifier %qE", token-
> > > value);
> > 
> > + inform (volatile_loc, "first seen here");
> > +   }
> 
> Thanks for the improvements.
> 
> Is there test coverage for these errors and notes?
> 
> A diagnostic nit (new with gcc 9): please add an:
> auto_diagnostic_group d;
> to the start of the guarded block, so that the "error" and "note" are
> known to be related.
> 
> See:  
> https://gcc.gnu.org/onlinedocs/gccint/Guidelines-for-Diagnostics.html
> #Group-logically-related-diagnostics

For bonus points, these could offer fix-it hints, so that an IDE can
offer to delete the duplicate qualifier token.  The above code could
be:

  if (volatile_loc)
complain_about_duplicate_asm_qualifier (token->value, loc,
volatile_loc);
  else
volatile_loc = loc;


void
complain_about_duplicate_asm_qualifier (tree value,
location_t duplicate_loc,
location_t first_loc)
{
   auto_diagnostic_group d;
   gcc_rich_location richloc (duplicate_loc);
   richloc.add_fixit_remove ();
   error_at (&richloc, "duplicate asm qualifier %qE", value);
   inform (first_loc, "first seen here");
}

or somesuch, where rich_location::add_fixit_remove adds a fix-it hint
suggesting the removal of all of "loc", the duplicate token; given that
it's 5 lines at this point, a subroutine seems justified, to eliminate
duplication at the 6 sites it's done.

Caveat: haven't tried to compile the above.

Dave


> > + else
> > +   volatile_loc = loc;
> >   c_parser_consume_token (parser);
> >   continue;
> >  
> > case RID_INLINE:
> > - if (is_inline)
> > -   break;
> > - is_inline = true;
> > + if (inline_loc)
> > +   {
> > + error_at (loc, "duplicate asm qualifier %qE", token-
> > > value);
> > 
> > + inform (inline_loc, "first seen here");
> 
> Likewise.
> 
> > +   }
> > + else
> > +   inline_loc = loc;
> >   c_parser_consume_token (parser);
> >   continue;
> >  
> > case RID_GOTO:
> > - if (is_goto)
> > -   break;
> > - is_goto = true;
> > + if (goto_loc)
> > +   {
> > + error_at (loc, "duplicate asm qualifier %qE", token-
> > > value);
> > 
> > + inform (goto_loc, "first seen here");
> > +   }
> 
> Likewise.
> 
> > + else
> > +   goto_loc = loc;
> >   c_parser_consume_token (parser);
> >   continue;
> 
> [...]
>  
> > diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
> > index 1cc34ba..06a6bb0 100644
> > --- a/gcc/cp/parser.c
> > +++ b/gcc/cp/parser.c
> > @@ -19649,29 +19646,50 @@ cp_parser_asm_definition (cp_parser*
> > parser)
> >  }
> >  
> >/* Handle the asm-qualifier-list.  */
> > +  location_t volatile_loc = UNKNOWN_LOCATION;
> > +  location_t inline_loc = UNKNOWN_LOCATION;
> > +  location_t goto_loc = UNKNOWN_LOCATION;
> >if (cp_parser_allow_gnu_extensions_p (parser))
> >  for (;;)
> >{
> > +   cp_token *token = cp_lexer_peek_token (parser->lexer);
> > +   location_t loc = token->location;
> > switch (cp_lexer_peek_token (parser->lexer)->keyword)
> >   {
> >   case RID_VOLATILE:
> > -   if (volatile_p)
> > - break;
> > -   volatile_p = true;
> > +   if (volatile_loc)
> > + {
> > +   error_at 

Re: [C++ Patch] Add location_t parameter to grokvardecl

2018-12-11 Thread Jason Merrill

On 12/10/18 5:23 AM, Paolo Carlini wrote:

Hi,

the other day I noticed that we weren't getting right the first location 
of pr53037-4.C, for a variable, whereas the next one, for a function, 
was Ok. Indeed, we were passing a location only to grokfndecl. In other 
terms, I found a good empirical reason to move the declaration of the 
local loc = declarator ? declarator->id_loc : input_location further up 
;) Tested x86_64-linux.


OK.

Jason



Re: [PATCH] [RFC] PR target/52813 and target/11807

2018-12-11 Thread Richard Sandiford
Dimitar Dimitrov  writes:
> On понеделник, 10 декември 2018 г. 11:21:53 EET Richard Sandiford wrote:
>> Dimitar Dimitrov  writes:
>> > I have tested this fix on x86_64 host, and found no regression in the C
>> > and C++ testsuites.  I'm marking this patch as RFC simply because I don't
>> > have experience with other architectures, and I don't have a setup to
>> > test all architectures supported by GCC.
>> > 
>> > gcc/ChangeLog:
>> > 
>> > 2018-12-07  Dimitar Dimitrov  
>> > 
>> >* cfgexpand.c (asm_clobber_reg_is_valid): Also produce
>> >error when stack pointer is clobbered.
>> >(expand_asm_stmt): Refactor clobber check in separate function.
>> > 
>> > gcc/testsuite/ChangeLog:
>> > 
>> > 2018-12-07  Dimitar Dimitrov  
>> > 
>> >* gcc.target/i386/pr52813.c: New test.
>> > 
>> > Signed-off-by: Dimitar Dimitrov 
>> 
>> LGTM.  Do you have a copyright assignment on file?  'Fraid this is
>> probably big enough to need one.
> Yes, I have copyright assignment.

OK, great.  I went ahead and applied the patch.

Thanks,
Richard


PING^2: [PATCH] i386; Add -mmanual-endbr and cf_check function attribute

2018-12-11 Thread H.J. Lu
On Mon, Dec 3, 2018 at 5:45 AM H.J. Lu  wrote:
>
> On Mon, Jun 18, 2018 at 2:20 AM Richard Biener
>  wrote:
> >
> > On Fri, Jun 15, 2018 at 2:59 PM H.J. Lu  wrote:
> > >
> > > Currently GCC inserts ENDBR instruction at entries of all non-static
> > > functions, unless LTO compilation is used.  Marking all functions,
> > > which are not called indirectly with nocf_check attribute, is not
> > > ideal since 99% of functions in a program may be of this kind.
> > >
> > > This patch adds -mmanual-endbr and cf_check function attribute.  They
> > > can be used together with -fcf-protection such that ENDBR instruction
> > > is inserted only at entries of functions with cf_check attribute.  It
> > > can limit number of ENDBR instructions to reduce program size.
> > >
> > > OK for trubk?
> >
> > I wonder if the linker could assist with ENDBR creation by
> > redirecting all non-direct call relocs to a linker-generated
> > stub with ENBR and a direct branch?
> >
>
> The goal of this patch is to add as few as ENDBR as possible
> to reduce program size as much as possible.   Also there is no
> relocation for indirect branch via register.
>

Hi Honza, Jakub, Jeff, Richard,

Here is the rebased patch.  Can you guys take a look?

Thanks.


-- 
H.J.
From 5934c6be6495b2d6f278646e25f9e684f6610e2b Mon Sep 17 00:00:00 2001
From: "H.J. Lu" 
Date: Thu, 14 Jun 2018 09:19:27 -0700
Subject: [PATCH] i386; Add -mmanual-endbr and cf_check function attribute

Currently GCC inserts ENDBR instruction at entries of all non-static
functions, unless LTO compilation is used.  Marking all functions,
which are not called indirectly with nocf_check attribute, is not
ideal since 99% of functions in a program may be of this kind.

This patch adds -mmanual-endbr and cf_check function attribute.  They
can be used together with -fcf-protection such that ENDBR instruction
is inserted only at entries of functions with cf_check attribute.  It
can limit number of ENDBR instructions to reduce program size.

gcc/

	* config/i386/i386.c (rest_of_insert_endbranch): Insert ENDBR
	at the function entry only when -mmanual-endbr isn't used or
	there is cf_check function attribute.
	(ix86_attribute_table): Add cf_check.
	* config/i386/i386.opt: Add -mmanual-endbr.
	* doc/extend.texi: Document cf_check attribute.
	* doc/invoke.texi: Document -mmanual-endbr.

gcc/testsuite/

	* gcc.target/i386/cf_check-1.c: New test.
	* gcc.target/i386/cf_check-2.c: Likewise.
	* gcc.target/i386/cf_check-3.c: Likewise.
	* gcc.target/i386/cf_check-4.c: Likewise.
	* gcc.target/i386/cf_check-5.c: Likewise.
---
 gcc/config/i386/i386.c |  6 ++
 gcc/config/i386/i386.opt   |  5 +
 gcc/doc/extend.texi|  7 +++
 gcc/doc/invoke.texi|  9 -
 gcc/testsuite/gcc.target/i386/cf_check-1.c | 11 +++
 gcc/testsuite/gcc.target/i386/cf_check-2.c | 11 +++
 gcc/testsuite/gcc.target/i386/cf_check-3.c | 11 +++
 gcc/testsuite/gcc.target/i386/cf_check-4.c | 10 ++
 gcc/testsuite/gcc.target/i386/cf_check-5.c |  9 +
 9 files changed, 78 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.target/i386/cf_check-1.c
 create mode 100644 gcc/testsuite/gcc.target/i386/cf_check-2.c
 create mode 100644 gcc/testsuite/gcc.target/i386/cf_check-3.c
 create mode 100644 gcc/testsuite/gcc.target/i386/cf_check-4.c
 create mode 100644 gcc/testsuite/gcc.target/i386/cf_check-5.c

diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
index 3e2fdfa86ff..b05c538c097 100644
--- a/gcc/config/i386/i386.c
+++ b/gcc/config/i386/i386.c
@@ -2638,6 +2638,9 @@ rest_of_insert_endbranch (void)
 
   if (!lookup_attribute ("nocf_check",
 			 TYPE_ATTRIBUTES (TREE_TYPE (cfun->decl)))
+  && (!flag_manual_endbr
+	  || lookup_attribute ("cf_check",
+			   DECL_ATTRIBUTES (cfun->decl)))
   && !cgraph_node::get (cfun->decl)->only_called_directly_p ())
 {
   /* Queue ENDBR insertion to x86_function_profiler.  */
@@ -45246,6 +45249,9 @@ static const struct attribute_spec ix86_attribute_table[] =
 ix86_handle_fentry_name, NULL },
   { "fentry_section", 1, 1, true, false, false, false,
 ix86_handle_fentry_name, NULL },
+  { "cf_check", 0, 0, true, false, false, false,
+ix86_handle_fndecl_attribute, NULL },
+
   /* End element.  */
   { NULL, 0, 0, false, false, false, false, NULL, NULL }
 };
diff --git a/gcc/config/i386/i386.opt b/gcc/config/i386/i386.opt
index b30b55b7826..007e88b57f9 100644
--- a/gcc/config/i386/i386.opt
+++ b/gcc/config/i386/i386.opt
@@ -1028,6 +1028,11 @@ Target Report Undocumented Var(flag_cet_switch) Init(0)
 Turn on CET instrumentation for switch statements that use a jump table and
 an indirect jump.
 
+mmanual-endbr
+Target Report Var(flag_manual_endbr) Init(0)
+Insert ENDBR instruction at function entry only via cf_check attribute
+for CET instrumentation.
+
 mforce-indirect-call
 Target Report Var(flag_force_indirect_call) Init(0)
 Make a

Re: [PATCH, ARM] Improve robustness of -mslow-flash-data

2018-12-11 Thread Thomas Preudhomme
Hi Kyrill,

I've tested on armeb-none-eabi with -mslow-flash-data for both
-mfloat-abi=hard and -mfloat-abi=soft. Both show no regression and the
former shows some new PASS.

Regarding the part you are hesitant about, the code was taken from
aarch64_reinterpret_float_as_int in config/aarch64/aarch64.c. I'm not
too keen on splitting the patch unless it's just for review (ie still
committed as one) since the changes really go together. The tighter
predicate and constraint are to prevent normal pattern to match when
-mslow-flash-data is in effect while the new splitter and expander is
to deal with load under those circumstances.

Best regards,

Thomas
On Fri, 30 Nov 2018 at 14:11, Kyrill Tkachov
 wrote:
>
> Hi Thomas,
>
> On 19/11/18 17:56, Thomas Preudhomme wrote:
> > Hi,
> >
> > Current code to handle -mslow-flash-data in machine description files
> > suffers from a number of issues which this patch fixes:
> >
> > 1) The insn_and_split in vfp.md to load a generic floating-point
> > constant via GPR first and move it to VFP register are guarded by
> > !reload_completed which is forbidden explicitely in the GCC internals
> > documentation section 17.2 point 3;
> >
> > 2) A number of testcase in the testsuite ICEs under -mslow-flash-data
> > when targeting the hardfloat ABI [1];
> >
> > 3) Instructions performing load from literal pool are not disabled.
> >
> > These problems are addressed by 2 separate actions:
> >
> > 1) Making the splitters take a clobber and changing the expanders
> > accordingly to generate a mov with clobber in cases where a literal
> > pool would be used. The splitter can thus be enabled after reload since
> > it does not call gen_reg_rtx anymore;
> >
> > 2) Adding new predicates and constraints to disable literal pool loads
> > in existing instructions when -mslow-flash-data is in effect.
> >
>
> Please split these into two separate patches so we can more clearly see which 
> changes address which problem
>
> > The patch also rework the splitter for DFmode slightly to generate an
> > intermediate DI load instead of 2 intermediate SI loads, thus relying on
> > the existing DI splitters instead of redoing their job. At last, the
> > patch adds some missing arm_fp_ok effective target to some of the
> > slow-flash-data testcases.
> >
> > [1]
> > c-c++-common/Wunused-var-3.c
> > gcc.c-torture/compile/pr72771.c
> > gcc.c-torture/compile/vector-5.c
> > gcc.c-torture/compile/vector-6.c
> > gcc.c-torture/execute/20030914-1.c
> > gcc.c-torture/execute/20050316-1.c
> > gcc.c-torture/execute/pr59643.c
> > gcc.dg/builtin-tgmath-1.c
> > gcc.dg/debug/pr55730.c
> > gcc.dg/graphite/interchange-7.c
> > gcc.dg/pr56890-2.c
> > gcc.dg/pr68474.c
> > gcc.dg/pr80286.c
> > gcc.dg/torture/pr35227.c
> > gcc.dg/torture/pr65077.c
> > gcc.dg/torture/pr86363.c
> > g++.dg/torture/pr81112.C
> > g++.dg/torture/pr82985.C
> > g++.dg/warn/Wunused-var-7.C
> > and a lot more in libstdc++ in special_functions/*_comp_ellint_* and
> > special_functions/*_ellint_* directories.
> >
> > ChangeLog entries are as follows:
> >
> > *** gcc/ChangeLog ***
> >
> > 2018-11-14  Thomas Preud'homme 
> >
> > * config/arm/arm.md (arm_movdi): Split if -mslow-flash-data and
> > source is a constant that would be loaded by literal pool.
> > (movsf expander): Generate a no_literal_pool_sf_immediate insn if
> > -mslow-flash-data is present, targeting hardfloat ABI and source is 
> > a
> > float constant that cannot be loaded via vmov.
> > (movdf expander): Likewise but generate a 
> > no_literal_pool_df_immediate
> > insn.
> > (arm_movsf_soft_insn): Split if -mslow-flash-data and source is a
> > float constant that would be loaded by literal pool.
> > (softfloat constant movsf splitter): Splitter for the above case.
> > (movdf_soft_insn): Split if -mslow-flash-data and source is a float
> > constant that would be loaded by literal pool.
> > (softfloat constant movdf splitter): Splitter for the above case.
> > * config/arm/constraints.md (Pz): Document existing constraint.
> > (Ha): Define constraint.
> > (Tu): Likewise.
> > * config/arm/predicates.md (hard_sf_operand): New predicate.
> > (hard_df_operand): Likewise.
> > * config/arm/thumb2.md (thumb2_movsi_insn): Split if
> > -mslow-flash-data and constant would be loaded by literal pool.
> > * constant/arm/vfp.md (thumb2_movsi_vfp): Likewise and disable 
> > constant
> > load in VFP register.
> > (movdi_vfp): Likewise.
> > (thumb2_movsf_vfp): Use hard_sf_operand as predicate for source to
> > prevent match for a constant load if -mslow-flash-data and constant
> > cannot be loaded via vmov.  Adapt constraint accordingly by
> > using Ha instead of E for generic floating-point constant load.
> > (thumb2_movdf_vfp): Likewise using hard_df_operand predicate 
> > instead.
> >   

Re: PR88346, Inconsistent list of CPUs supported by the rs6000 backend after r266502

2018-12-11 Thread David Edelsohn
On Mon, Dec 10, 2018 at 6:17 PM Segher Boessenkool
 wrote:
>
> Hi Alan,
>
> Let's ask David?  (Cc:ed).  Strange that no one noticed powerpc64 before;
> titan and rs64 aren't so strange though ;-)

The patch is okay with me. Thanks for catching the renaming and the
processor missing from the list. I don't think that there are any rs64
systems remaining in the field and AIX customers don't try to utilize
GCC processor options as aggressively as Linux and embedded users.

Thanks, David

>
>
> Segher
>
>
> On Fri, Dec 07, 2018 at 09:00:39PM +1030, Alan Modra wrote:
> > This patch removes the %e error for AIX, since it seems there has been
> > no attempt to keep ASM_CPU_SPEC cpu support up to date for AIX, and
> > adds missing entries to ASM_CPU_SPEC in rs6000.h.  Removing the %e
> > isn't ideal, but leaving it in and hitting a compiler error for -mcpu
> > cases where the AIX assembler works fine with default options, is
> > worse.
> >
> > The rs64a->rs64 name change happened a long time ago as a fix for
> > PR20813 (git commit c92b4c3f5b).
> >
> > Bootstrapped and regression tested powerpc64le-linux.  OK?
> >
> >   PR 88346
> >   * config/rs6000/rs6000.h (ASM_CPU_SPEC): Correct %e message.  Handle
> >   -mcpu=rs64, not -mcpu=rs64a.  Handle -mcpu=powerpc64 and -mcpu=titan.
> >   * config/rs6000/driver-rs6000.c (asm_names): Similarly.
> >   * config/rs6000/aix71.h (ASM_CPU_SPEC): Delete %e message.  Handle
> >   -mcpu=rs64, not -mcpu=rs64a.
> >   * config/rs6000/aix72.h (ASM_CPU_SPEC): Likewise.
> >
> > diff --git a/gcc/config/rs6000/aix71.h b/gcc/config/rs6000/aix71.h
> > index 2398ed64baa..d2fbba4f509 100644
> > --- a/gcc/config/rs6000/aix71.h
> > +++ b/gcc/config/rs6000/aix71.h
> > @@ -77,7 +77,7 @@ do {  
> >   \
> >mcpu=power4: -mpwr4; \
> >mcpu=power3: -m620; \
> >mcpu=powerpc: -mppc; \
> > -  mcpu=rs64a: -mppc; \
> > +  mcpu=rs64: -mppc; \
> >mcpu=603: -m603; \
> >mcpu=603e: -m603; \
> >mcpu=604: -m604; \
> > @@ -88,8 +88,7 @@ do {  
> >   \
> >!mcpu*: %{mvsx: -mpwr6; \
> >   maltivec: -m970; \
> >   maix64|mpowerpc64: -mppc64; \
> > - : %(asm_default)}; \
> > -  :%eMissing -mcpu option in ASM_SPEC_CPU?\n} \
> > + : %(asm_default)}} \
> >  -many"
> >
> >  #undef   ASM_DEFAULT_SPEC
> > diff --git a/gcc/config/rs6000/aix72.h b/gcc/config/rs6000/aix72.h
> > index cfb0258acce..211010748c6 100644
> > --- a/gcc/config/rs6000/aix72.h
> > +++ b/gcc/config/rs6000/aix72.h
> > @@ -77,7 +77,7 @@ do {  
> >   \
> >mcpu=power4: -mpwr4; \
> >mcpu=power3: -m620; \
> >mcpu=powerpc: -mppc; \
> > -  mcpu=rs64a: -mppc; \
> > +  mcpu=rs64: -mppc; \
> >mcpu=603: -m603; \
> >mcpu=603e: -m603; \
> >mcpu=604: -m604; \
> > @@ -88,8 +88,7 @@ do {  
> >   \
> >!mcpu*: %{mvsx: -mpwr6; \
> >   maltivec: -m970; \
> >   maix64|mpowerpc64: -mppc64; \
> > - : %(asm_default)}; \
> > -  :%eMissing -mcpu option in ASM_SPEC_CPU?\n} \
> > + : %(asm_default)}} \
> >  -many"
> >
> >  #undef   ASM_DEFAULT_SPEC
> > diff --git a/gcc/config/rs6000/driver-rs6000.c 
> > b/gcc/config/rs6000/driver-rs6000.c
> > index 0a48d46d658..51c6b79e741 100644
> > --- a/gcc/config/rs6000/driver-rs6000.c
> > +++ b/gcc/config/rs6000/driver-rs6000.c
> > @@ -449,7 +449,7 @@ static const struct asm_name asm_names[] = {
> >{ "power8","-mpwr8" },
> >{ "power9","-mpwr9" },
> >{ "powerpc",   "-mppc" },
> > -  { "rs64a", "-mppc" },
> > +  { "rs64",  "-mppc" },
> >{ "603",   "-m603" },
> >{ "603e",  "-m603" },
> >{ "604",   "-m604" },
> > @@ -477,8 +477,9 @@ static const struct asm_name asm_names[] = {
> >{ "power9","-mpower9" },
> >{ "a2","-ma2" },
> >{ "powerpc",   "-mppc" },
> > +  { "powerpc64", "-mppc64" },
> >{ "powerpc64le", "%{mpower9-vector:-mpower9;:-mpower8}" },
> > -  { "rs64a", "-mppc64" },
> > +  { "rs64",  "-mppc64" },
> >{ "401",   "-mppc" },
> >{ "403",   "-m403" },
> >{ "405",   "-m405" },
> > @@ -519,6 +520,7 @@ static const struct asm_name asm_names[] = {
> >{ "e500mc64",  "-me500mc64" },
> >{ "e5500", "-me5500" },
> >{ "e6500", "-me6500" },
> > +  { "titan", "-mtitan" },
> >{ NULL,"\
> >  %{mpower9-vector: -mpower9; \
> >mpower8-vector|mcrypto|mdirect-move|mhtm: -mpower8; \
> > diff --git a/gcc/config/rs6000/rs6000.h b/gcc/config/rs6000/rs6000.h
> > index 2a62679bdb8..e7e998d1492 100644
> > --- a/gcc/config/rs6000/rs6000.h
> > +++ b/gcc/config/rs6000/rs6000.h
> > @@ -87,9 +87,10 @@
> >mcpu=power4: -mpower4; \
> >mcpu=power3: -mppc64; \
> >mcpu=powerpc: -mppc; \
> > +  mcpu=powerpc64: -mppc64; \
> >mcpu=a2:

Re: [PATCH 1/3][GCC] Add new target hook asm_post_cfi_startproc

2018-12-11 Thread Sam Tebbs
On 11/5/18 10:18 AM, Sam Tebbs wrote:

> On 11/05/2018 07:54 AM, Richard Biener wrote:
>> On Fri, 2 Nov 2018, Sam Tebbs wrote:
>>
>>> On 11/02/2018 05:28 PM, Sam Tebbs wrote:
>>>
 Hi all,

 This patch adds a new target hook called "asm_post_cfi_startproc". This 
 hook is
 intended to be used by the aarch64 backend to emit a directive that enables
 support for unwinding frames signed with the pointer authentication B-key. 
 This
 hook is triggered after the ".cfi_startproc" directive is emitted in
 gcc/dwarf2out.c.

 Bootstrapped on aarch64-none-linux-gnu and tested on aarch64-none-elf with 
 no regressions.

 Ok for trunk?
>> Can you explain why existing prologue/cfi emission points are not
>> enough?
> I couldn't find any target hooks that were triggered at the
> assembly-printing level at the correct point in time (after
> .cfi_startproc is emitted), please do point me to one if that is not the
> case.
>
> An alternative could have been to implement a new reg_note but that
> would have meant adding target-specific code to target-agnostic files
> and wouldn't have been as flexible.
>
> Sam
>
 gcc/
 2018-11-02  Sam Tebbs

* doc/tm.texi (TARGET_ASM_POST_CFI_STARTPROC): Define.
* doc/tm.texi.in (TARGET_ASM_POST_CFI_STARTPROC): Define.
* dwarf2out.c (dwarf2out_do_cfi_startproc): Trigger the hook.
* hooks.c (hook_void_FILEptr_tree): Define.
* hooks.h (hook_void_FILEptr_tree): Define.
* target.def (post_cfi_startproc): Define.
>>> CCing global reviewers and dwarf maintainers.
>>>
>>>
>>>
ping 4. There are previous pings in another thread with more maintainers 
CC'ed, but pinging here as this is where the conversation has been.


[PATCH] Add TREE_CODE == SSA_NAME checks to register_edge_assert_for_2 (PR tree-optimization/88444)

2018-12-11 Thread Jakub Jelinek
Hi!

Most spots in vr-values* and tree-vrp* check if convert rhs1 is SSA_NAME,
but these 3 spots don't.  It can appear if some pass doesn't fold stmts
after changing them.

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

2018-12-11  Jakub Jelinek  

PR tree-optimization/88444
* tree-vrp.c (register_edge_assert_for_2): Only register assertions
for conversions if rhs1 is a SSA_NAME.

* gcc.dg/pr88444.c: New test.

--- gcc/tree-vrp.c.jj   2018-12-07 00:27:25.419941079 +0100
+++ gcc/tree-vrp.c  2018-12-11 09:39:27.994469666 +0100
@@ -2894,6 +2894,7 @@ register_edge_assert_for_2 (tree name, e
{
  name2 = gimple_assign_rhs1 (def_stmt);
  if (CONVERT_EXPR_CODE_P (rhs_code)
+ && TREE_CODE (name2) == SSA_NAME
  && INTEGRAL_TYPE_P (TREE_TYPE (name2))
  && TYPE_UNSIGNED (TREE_TYPE (name2))
  && prec == TYPE_PRECISION (TREE_TYPE (name2))
@@ -2990,6 +2991,7 @@ register_edge_assert_for_2 (tree name, e
  wide_int rmin, rmax;
  tree rhs1 = gimple_assign_rhs1 (def_stmt);
  if (INTEGRAL_TYPE_P (TREE_TYPE (rhs1))
+ && TREE_CODE (rhs1) == SSA_NAME
  /* Make sure the relation preserves the upper/lower boundary of
 the range conservatively.  */
  && (comp_code == NE_EXPR
@@ -3054,6 +3056,7 @@ register_edge_assert_for_2 (tree name, e
{
  names[1] = gimple_assign_rhs1 (def_stmt2);
  if (!CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (def_stmt2))
+ || TREE_CODE (names[1]) != SSA_NAME
  || !INTEGRAL_TYPE_P (TREE_TYPE (names[1]))
  || (TYPE_PRECISION (TREE_TYPE (name2))
  != TYPE_PRECISION (TREE_TYPE (names[1]
--- gcc/testsuite/gcc.dg/pr88444.c.jj   2018-12-11 09:43:50.062166005 +0100
+++ gcc/testsuite/gcc.dg/pr88444.c  2018-12-11 09:43:34.393423360 +0100
@@ -0,0 +1,30 @@
+/* PR tree-optimization/88444 */
+/* { dg-do compile } */
+/* { dg-options "-O1 -ftree-vrp -fno-tree-ccp -fno-tree-forwprop 
-fno-tree-fre" } */
+
+int v;
+
+int
+foo (int, int);
+
+static inline int
+bar (long int x)
+{
+  return !!x ? x : 1;
+}
+
+static inline void
+baz (int x)
+{
+  v += foo (0, 0) + bar (x);
+}
+
+void
+qux (void)
+{
+  int a = 0;
+  v = v || foo (0, 0);
+  v = v || foo (0, 0);
+  v = v || foo (0, 0);
+  baz (a);
+}

Jakub


Re: [PATCH] Add TREE_CODE == SSA_NAME checks to register_edge_assert_for_2 (PR tree-optimization/88444)

2018-12-11 Thread Richard Biener
On Tue, 11 Dec 2018, Jakub Jelinek wrote:

> Hi!
> 
> Most spots in vr-values* and tree-vrp* check if convert rhs1 is SSA_NAME,
> but these 3 spots don't.  It can appear if some pass doesn't fold stmts
> after changing them.
> 
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

OK.

> 2018-12-11  Jakub Jelinek  
> 
>   PR tree-optimization/88444
>   * tree-vrp.c (register_edge_assert_for_2): Only register assertions
>   for conversions if rhs1 is a SSA_NAME.
> 
>   * gcc.dg/pr88444.c: New test.
> 
> --- gcc/tree-vrp.c.jj 2018-12-07 00:27:25.419941079 +0100
> +++ gcc/tree-vrp.c2018-12-11 09:39:27.994469666 +0100
> @@ -2894,6 +2894,7 @@ register_edge_assert_for_2 (tree name, e
>   {
> name2 = gimple_assign_rhs1 (def_stmt);
> if (CONVERT_EXPR_CODE_P (rhs_code)
> +   && TREE_CODE (name2) == SSA_NAME
> && INTEGRAL_TYPE_P (TREE_TYPE (name2))
> && TYPE_UNSIGNED (TREE_TYPE (name2))
> && prec == TYPE_PRECISION (TREE_TYPE (name2))
> @@ -2990,6 +2991,7 @@ register_edge_assert_for_2 (tree name, e
> wide_int rmin, rmax;
> tree rhs1 = gimple_assign_rhs1 (def_stmt);
> if (INTEGRAL_TYPE_P (TREE_TYPE (rhs1))
> +   && TREE_CODE (rhs1) == SSA_NAME
> /* Make sure the relation preserves the upper/lower boundary of
>the range conservatively.  */
> && (comp_code == NE_EXPR
> @@ -3054,6 +3056,7 @@ register_edge_assert_for_2 (tree name, e
>   {
> names[1] = gimple_assign_rhs1 (def_stmt2);
> if (!CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (def_stmt2))
> +   || TREE_CODE (names[1]) != SSA_NAME
> || !INTEGRAL_TYPE_P (TREE_TYPE (names[1]))
> || (TYPE_PRECISION (TREE_TYPE (name2))
> != TYPE_PRECISION (TREE_TYPE (names[1]
> --- gcc/testsuite/gcc.dg/pr88444.c.jj 2018-12-11 09:43:50.062166005 +0100
> +++ gcc/testsuite/gcc.dg/pr88444.c2018-12-11 09:43:34.393423360 +0100
> @@ -0,0 +1,30 @@
> +/* PR tree-optimization/88444 */
> +/* { dg-do compile } */
> +/* { dg-options "-O1 -ftree-vrp -fno-tree-ccp -fno-tree-forwprop 
> -fno-tree-fre" } */
> +
> +int v;
> +
> +int
> +foo (int, int);
> +
> +static inline int
> +bar (long int x)
> +{
> +  return !!x ? x : 1;
> +}
> +
> +static inline void
> +baz (int x)
> +{
> +  v += foo (0, 0) + bar (x);
> +}
> +
> +void
> +qux (void)
> +{
> +  int a = 0;
> +  v = v || foo (0, 0);
> +  v = v || foo (0, 0);
> +  v = v || foo (0, 0);
> +  baz (a);
> +}
> 
>   Jakub
> 
> 

-- 
Richard Biener 
SUSE LINUX GmbH, GF: Felix Imendoerffer, Jane Smithard, Graham Norton, HRB 
21284 (AG Nuernberg)


[C++ PATCH] Fix up __builtin_is_constant_evaluated (PR c++/88449)

2018-12-11 Thread Jakub Jelinek
Hi!

While working on the libstdc++ patch for P0595R2, I've noticed that while
__builtin_is_constant_evaluated () directly works, when wrapped into
an constexpr inline noexcept function, it in some cases doesn't.  The
problem is that the constexpr call cache didn't take
ctx->pretend_const_required into account.

The following patch fixes it by just treating it like another magic
parameter.  Another option would be (but much more involved) to remember
during the constexpr.c processing whether we've seen during the evaluation
any calls to __builtin_is_constant_evaluated (that would require propagating
in all the spots that use a new context back to the old context).  Then
we could in the constexpr hash remember either that during the evaluation
of that constexpr call there was no __builtin_is_constant_evaluated seen,
or, if it has been seen, whether it was in ctx->pretend_const_required
mode or in !ctx->pretend_const_required mode.

I've bootstrapped/regtested on x86_64-linux and i686-linux the following
simpler version, ok for trunk?

2018-12-11  Jakub Jelinek  

PR c++/88449
* constexpr.c (struct constexpr_call): Add pretend_const_required
member.
(constexpr_call_hasher::equal): Return false if pretend_const_required
members differ.
(cxx_eval_call_expression): Adjust new_call initialization.  Hash in
ctx->pretend_const_required.

* g++.dg/cpp2a/is-constant-evaluated1.C: Change from dg-do compile
to dg-do run.
(e): Adjust comment with correct expected value.
(main): Expect e == 1.
* g++.dg/cpp2a/is-constant-evaluated2.C: New test.

--- gcc/cp/constexpr.c.jj   2018-12-07 16:18:42.481847741 +0100
+++ gcc/cp/constexpr.c  2018-12-11 12:01:27.968941683 +0100
@@ -973,6 +973,8 @@ struct GTY((for_user)) constexpr_call {
   /* The hash of this call; we remember it here to avoid having to
  recalculate it when expanding the hash table.  */
   hashval_t hash;
+  /* Whether __builtin_is_constant_evaluated() should evaluate to true.  */
+  bool pretend_const_required;
 };
 
 struct constexpr_call_hasher : ggc_ptr_hash
@@ -1052,6 +1054,8 @@ constexpr_call_hasher::equal (constexpr_
 return true;
   if (lhs->hash != rhs->hash)
 return false;
+  if (lhs->pretend_const_required != rhs->pretend_const_required)
+return false;
   if (!constexpr_fundef_hasher::equal (lhs->fundef, rhs->fundef))
 return false;
   lhs_bindings = lhs->bindings;
@@ -1500,7 +1504,8 @@ cxx_eval_call_expression (const constexp
 {
   location_t loc = cp_expr_loc_or_loc (t, input_location);
   tree fun = get_function_named_in_call (t);
-  constexpr_call new_call = { NULL, NULL, NULL, 0 };
+  constexpr_call new_call
+= { NULL, NULL, NULL, 0, ctx->pretend_const_required };
   bool depth_ok;
 
   if (fun == NULL_TREE)
@@ -1642,8 +1647,11 @@ cxx_eval_call_expression (const constexp
   constexpr_call *entry = NULL;
   if (depth_ok && !non_constant_args && ctx->strict)
 {
-  new_call.hash = iterative_hash_template_arg
-   (new_call.bindings, constexpr_fundef_hasher::hash (new_call.fundef));
+  new_call.hash = constexpr_fundef_hasher::hash (new_call.fundef);
+  new_call.hash
+   = iterative_hash_template_arg (new_call.bindings, new_call.hash);
+  new_call.hash
+   = iterative_hash_object (ctx->pretend_const_required, new_call.hash);
 
   /* If we have seen this call before, we are done.  */
   maybe_initialize_constexpr_call_table ();
--- gcc/testsuite/g++.dg/cpp2a/is-constant-evaluated1.C.jj  2018-08-26 
22:41:13.778935483 +0200
+++ gcc/testsuite/g++.dg/cpp2a/is-constant-evaluated1.C 2018-12-11 
11:57:55.027418581 +0100
@@ -1,5 +1,5 @@
 // P0595R1
-// { dg-do compile { target c++14 } }
+// { dg-do run { target c++14 } }
 
 template struct X { int v = N; };
 X<__builtin_is_constant_evaluated ()> x; // type X
@@ -8,7 +8,7 @@ int a = __builtin_is_constant_evaluated
 int b = __builtin_is_constant_evaluated () ? 2 : y; // initializes b to 2
 int c = y + (__builtin_is_constant_evaluated () ? 2 : y); // initializes c to 
2*y
 int d = __builtin_is_constant_evaluated (); // initializes d to 1
-int e = d + __builtin_is_constant_evaluated (); // initializes e to 0
+int e = d + __builtin_is_constant_evaluated (); // initializes e to 1 + 0
 
 struct false_type { static constexpr bool value = false; };
 struct true_type { static constexpr bool value = true; };
@@ -50,7 +50,7 @@ static_assert (is_same struct X { int v = N; };
+X x; // type X
+int y = 4;
+int a = is_constant_evaluated () ? y : 1; // initializes a to 1
+int b = is_constant_evaluated () ? 2 : y; // initializes b to 2
+int c = y + (is_constant_evaluated () ? 2 : y); // initializes c to 2*y
+int d = is_constant_evaluated (); // initializes d to 1
+int e = d + is_constant_evaluated (); // initializes e to 1 + 0
+
+struct false_type { static constexpr bool value = false; };
+struct true_type { static constexpr bool value = true; };
+template
+struct i

[PATCH] Add std::is_constant_evaluated wrapper around __builtin_is_constant_evaluated

2018-12-11 Thread Jakub Jelinek
Hi!

The following patch adds std::is_constant_evaluated to the library.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
(relies on the previously posted C++ FE patch).

2018-12-11  Jakub Jelinek  

P0595R2 - is_constant_evaluated
* include/bits/c++config (_GLIBCXX_HAVE_BUILTIN_IS_CONSTANT_EVALUATED):
Define if __builtin_is_constant_evaluated is available.
* include/std/type_traits (std::is_constant_evaluated): New constexpr
inline function.
* testsuite/20_util/is_constant_evaluated/1.cc: New test.
* testsuite/20_util/is_constant_evaluated/noexcept.cc: New test.

--- libstdc++-v3/include/bits/c++config.jj  2018-08-01 20:14:18.214540951 
+0200
+++ libstdc++-v3/include/bits/c++config 2018-12-11 12:23:21.417491141 +0100
@@ -627,6 +627,9 @@ namespace std
 # define _GLIBCXX_HAVE_BUILTIN_HAS_UNIQ_OBJ_REP 1
 # define _GLIBCXX_HAVE_BUILTIN_IS_AGGREGATE 1
 # define _GLIBCXX_HAVE_BUILTIN_LAUNDER 1
+# if __GNUC__ >= 9
+#  define _GLIBCXX_HAVE_BUILTIN_IS_CONSTANT_EVALUATED 1
+# endif
 #elif defined(__is_identifier)
 // For non-GNU compilers:
 # if ! __is_identifier(__has_unique_object_representations)
@@ -638,6 +641,9 @@ namespace std
 # if ! __is_identifier(__builtin_launder)
 #  define _GLIBCXX_HAVE_BUILTIN_LAUNDER 1
 # endif
+# if ! __is_identifier(__builtin_is_constant_evaluated)
+#  define _GLIBCXX_HAVE_BUILTIN_IS_CONSTANT_EVALUATED 1
+# endif
 #endif // GCC
 
 // End of prewritten config; the settings discovered at configure time follow.
--- libstdc++-v3/include/std/type_traits.jj 2018-11-29 14:39:27.231036940 
+0100
+++ libstdc++-v3/include/std/type_traits2018-12-11 12:24:44.713130332 
+0100
@@ -3029,6 +3029,12 @@ template 
   template
 using unwrap_ref_decay_t = typename unwrap_ref_decay<_Tp>::type;
 
+#ifdef _GLIBCXX_HAVE_BUILTIN_IS_CONSTANT_EVALUATED
+  constexpr inline bool
+  is_constant_evaluated() noexcept
+  { return __builtin_is_constant_evaluated(); }
+#endif
+
 #endif // C++2a
 
 _GLIBCXX_END_NAMESPACE_VERSION
--- libstdc++-v3/testsuite/20_util/is_constant_evaluated/1.cc.jj
2018-12-11 10:30:11.964508310 +0100
+++ libstdc++-v3/testsuite/20_util/is_constant_evaluated/1.cc   2018-12-11 
12:25:36.495284363 +0100
@@ -0,0 +1,80 @@
+// Copyright (C) 2018 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 
+
+template
+struct X { int v = N; };
+X x; // type X
+int y = 4;
+int a = std::is_constant_evaluated() ? y : 1; // initializes a to 1
+int b = std::is_constant_evaluated() ? 2 : y; // initializes b to 2
+int c = y + (std::is_constant_evaluated() ? 2 : y); // initializes c to 2*y
+int d = std::is_constant_evaluated(); // initializes d to 1
+int e = d + std::is_constant_evaluated(); // initializes e to 1 + 0
+
+constexpr int
+foo(int x)
+{
+  const int n = std::is_constant_evaluated() ? 13 : 17; // n == 13
+  int m = std::is_constant_evaluated() ? 13 : 17; // m might be 13 or 17 (see 
below)
+  char arr[n] = {}; // char[13]
+  return m + sizeof (arr) + x;
+}
+
+constexpr int
+bar()
+{
+  const int n = std::is_constant_evaluated() ? 13 : 17;
+  X x1;
+  X x2;
+  static_assert(std::is_same::value,
+   "x1/x2's type");
+  return x1.v + x2.v;
+}
+
+int p = foo(0); // m == 13; initialized to 26
+int q = p + foo(0); // m == 17 for this call; initialized to 56
+static_assert(bar() == 26, "bar");
+
+struct S { int a, b; };
+
+S s = { std::is_constant_evaluated() ? 2 : 3, y };
+S t = { std::is_constant_evaluated() ? 2 : 3, 4 };
+
+static_assert(std::is_same >::value, "x's type");
+
+void
+test01()
+{
+  VERIFY( a == 1 && b == 2 && c == 8 && d == 1 && e == 1 && p == 26 );
+  VERIFY( q == 56 && s.a == 3 && s.b == 4 && t.a == 2 && t.b == 4 );
+  VERIFY( foo (y) == 34 );
+  if constexpr (foo (0) != 26)
+VERIFY( 0 );
+  constexpr int w = foo (0);
+  VERIFY( w == 26 );
+}
+
+int main()
+{
+  test01();
+}
--- libstdc++-v3/testsuite/20_util/is_constant_evaluated/noexcept.cc.jj 
2018-12-11 10:48:27.923528892 +0100
+++ libstdc++-v3/testsuite/20_util/is_constant_evaluated/noexcept.cc
2018-12-11 12:25:45.138143167 +0100
@@ -0,0 +1,23 @@
+// { dg-options "-std=gnu++2a" }
+// { dg-do compile { target c++2a } }
+
+// Copyright (

[C++ PATCH] Fix up __builtin_is_constant_evaluated handling in array type sizes (PR c++/88446)

2018-12-11 Thread Jakub Jelinek
Hi!

As mentioned in the PR, while we allow VLAs in some contexts in C++ as
an extension, they aren't standard and the standard requires in those spots
constant expressions, thus __builtin_is_constant_evaluated () needs to be
true if those sizes are indeed constant expressions.

Fixed by calling cxx_eval_outermost_constant_expr with
pretend_const_required too in that case.

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

2018-12-11  Jakub Jelinek  

PR c++/88446
* cp-tree.h (maybe_constant_value): Add pretend_const_required
argument.
* constexpr.c (maybe_constant_value): Likewise.  If true, don't
cache and call cxx_eval_outermost_constant_expr with true as
pretend_const_required.
* decl.c (compute_array_index_type_loc): Call maybe_constant_value
with true as pretend_const_required.

* g++.dg/cpp2a/is-constant-evaluated3.C: New test.

--- gcc/cp/cp-tree.h.jj 2018-12-07 00:23:15.024998595 +0100
+++ gcc/cp/cp-tree.h2018-12-11 13:55:51.933845503 +0100
@@ -7663,7 +7663,7 @@ extern bool require_rvalue_constant_expr
 extern bool require_potential_rvalue_constant_expression (tree);
 extern tree cxx_constant_value (tree, tree = NULL_TREE);
 extern tree cxx_constant_init  (tree, tree = NULL_TREE);
-extern tree maybe_constant_value   (tree, tree = NULL_TREE);
+extern tree maybe_constant_value   (tree, tree = NULL_TREE, bool = 
false);
 extern tree maybe_constant_init(tree, tree = 
NULL_TREE, bool = false);
 extern tree fold_non_dependent_expr(tree, tsubst_flags_t = 
tf_warning_or_error);
 extern tree fold_simple(tree);
--- gcc/cp/constexpr.c.jj   2018-12-11 12:01:27.968941683 +0100
+++ gcc/cp/constexpr.c  2018-12-11 13:56:50.382890876 +0100
@@ -5244,7 +5244,7 @@ fold_simple (tree t)
 static GTY((deletable)) hash_map *cv_cache;
 
 tree
-maybe_constant_value (tree t, tree decl)
+maybe_constant_value (tree t, tree decl, bool pretend_const_required)
 {
   tree r;
 
@@ -5261,6 +5261,9 @@ maybe_constant_value (tree t, tree decl)
 /* No caching or evaluation needed.  */
 return t;
 
+  if (pretend_const_required)
+return cxx_eval_outermost_constant_expr (t, true, true, true, decl);
+
   if (cv_cache == NULL)
 cv_cache = hash_map::create_ggc (101);
   if (tree *cached = cv_cache->get (t))
--- gcc/cp/decl.c.jj2018-12-07 00:23:15.0 +0100
+++ gcc/cp/decl.c   2018-12-11 13:57:30.779231098 +0100
@@ -9645,7 +9645,10 @@ compute_array_index_type_loc (location_t
{
  size = instantiate_non_dependent_expr_sfinae (size, complain);
  size = build_converted_constant_expr (size_type_node, size, complain);
- size = maybe_constant_value (size);
+ /* Pedantically a constant expression is required here and so
+__builtin_is_constant_evaluated () should fold to true if it
+is successfully folded into a constant.  */
+ size = maybe_constant_value (size, NULL_TREE, true);
 
  if (!TREE_CONSTANT (size))
size = osize;
--- gcc/testsuite/g++.dg/cpp2a/is-constant-evaluated3.C.jj  2018-12-11 
14:11:34.235458615 +0100
+++ gcc/testsuite/g++.dg/cpp2a/is-constant-evaluated3.C 2018-12-11 
14:09:55.319073715 +0100
@@ -0,0 +1,26 @@
+// P0595R1
+// { dg-do run { target c++14 } }
+
+struct false_type { static constexpr bool value = false; };
+struct true_type { static constexpr bool value = true; };
+template
+struct is_same : false_type {};
+template
+struct is_same : true_type {};
+
+int a[__builtin_is_constant_evaluated () ? 1 : 2];
+int b[1];
+static_assert (is_same::value, "");
+
+int
+main ()
+{
+  int c[__builtin_is_constant_evaluated () ? 3 : 4];
+  int d[3];
+  static_assert (is_same::value, "");
+  int (*e)[7][9] = new int[__builtin_is_constant_evaluated () ? -1 : 5]
+ [__builtin_is_constant_evaluated () ? 7 : 8]
+ [__builtin_is_constant_evaluated () ? 9 : 10];
+  e[0][0][0] = 6;
+  delete[] e;
+}

Jakub


[PATCH] Fix cleanup_auto_inc_dec on x86 (PR rtl-optimization/88416)

2018-12-11 Thread Jakub Jelinek
Hi!

As mentioned in the PR, x86 (maybe a couple of other targets) isn't an
AUTO_INC_DEC target, it doesn't have REG_INC notes nor wants the generic
code to synthetize any pre/post inc/dec/modify, but does support push/pop
patterns that use those RTL codes.

If unlucky enough, as on the following testcase, we can end up with trying
to propagate such pre/post inc/dec into a DEBUG_INSN, which is invalid.

As cleanup_auto_inc_dec calls copy_rtx which is pretty much the same
function as cleanup_auto_inc_dec in the way how it performs deep copy of the
RTX, except that cleanup_auto_inc_dec also handles the pre/post
inc/dec/modify, I think the easiest fix is just to remove the special case,
it shouldn't make it any slower on !AUTO_INC_DEC targets.

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

2018-12-11  Jakub Jelinek  

PR rtl-optimization/88416
* valtrack.c (cleanup_auto_inc_dec): Handle pre/post-inc/dec/modify
even if !AUTO_INC_DEC.

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

--- gcc/valtrack.c.jj   2018-01-04 00:43:16.100702765 +0100
+++ gcc/valtrack.c  2018-12-11 15:39:05.746898166 +0100
@@ -56,8 +56,6 @@ static rtx
 cleanup_auto_inc_dec (rtx src, machine_mode mem_mode ATTRIBUTE_UNUSED)
 {
   rtx x = src;
-  if (!AUTO_INC_DEC)
-return copy_rtx (x);
 
   const RTX_CODE code = GET_CODE (x);
   int i;
--- gcc/testsuite/gcc.target/i386/pr88416.c.jj  2018-12-11 15:41:44.552308649 
+0100
+++ gcc/testsuite/gcc.target/i386/pr88416.c 2018-12-11 15:41:36.977432165 
+0100
@@ -0,0 +1,5 @@
+/* PR rtl-optimization/88416 */
+/* { dg-do compile } */
+/* { dg-options "-O1 -fvar-tracking-assignments -fno-forward-propagate --param 
max-cse-insns=1" } */
+
+#include "writeeflags-1.c"

Jakub


Re: [PATCH] accept all C integer types in function parameters referenced by alloc_align (PR 88363)

2018-12-11 Thread Martin Sebor

On 12/11/18 12:17 AM, Jakub Jelinek wrote:

On Mon, Dec 10, 2018 at 04:30:11PM -0700, Martin Sebor wrote:

Some of my testing exposed a minor problem in GCC 9's validation
of the type of function parameters referred to by attribute
positional arguments.  Whereas GCC 8 accepts all C integer types,
including enumerated types, such as:

   enum AllocAlign { Align16 = 16, Align32 = 32 };

   __attribute__ ((alloc_align (1))) void*
   alloc (size_t, enum AllocAlign)

GCC 9 only accepts signed and unsigned integer types.  This change
(introduced by myself) was unintentional, and a fix for it is in
the attached trivial patch.  I plan to commit it without approval
in the next day or so unless any concerns or suggestions come up.


There is nothing obvious about this, so please don't commit it without
approval.


See (*) below.


GCC 8 and older used to accept
even float or void * or struct arguments and just ignored them.
I think we need to discuss what types we want to allow without warnings and
what we should warn.


Silently accepting invalid arguments like void* or structs and
proceeding to ignore them is in my view a bug.  Clang diagnoses
both and that seems like the appropriate choice, so that's what
I implemented in r266195 back in November.  This patch doesn't
change that; rather, it accepts more of the things that were
accepted previously and that r266195 unintentionally rejected:
bool, enums, and wide characters.  I welcome feedback on this
decision which is why I posted the patch here before checking
it in.


As I wrote in the PR, I believe e.g. using alloc_align/alloc_size with
bool/_Bool is just a clear bug, you can store 0 or 1 in there, but e.g.
alignment 0 doesn't make sense.


I'm fine with being more restrictive and rejecting bool.  Clang
accepts it but I agree that it's far more likely a bug in user
code (and an oversight in Clang).


Enums are on the border line, I'll defer to C/C++ maintainers whether we
want to include that or not.


From Jason's and Marek's responses it sounds like accepting enums
here is appropriate.  (Clang also accepts them.)  I will go ahead
and make the change for bool alone then.



Jakub



[*] The change in the patch is obvious enough to me.  All it
does is accept more of the things that are accepted by GCC 8
(enums, bools, wchar_t, etc.) and that inadvertently started
to be rejected as a result of my prior change.   That the rules
can be made more restrictive is something different.

I recently brought up the question of the write w/o approval
policy on the gcc list:

  https://gcc.gnu.org/ml/gcc/2018-11/msg00165.html

looking for clarification.  Except for Jeff's comment (which
I'm afraid didn't really clarify things), didn't get any.

You (the maintainers) have put it in place.  If you don't intend
for the rest of us to make use of it, or if it's not meant to be
interpreted to give us the freedom to decide what is or isn't
obvious, then change it. But it's disingenuous to claim that "We
don't want to get overly restrictive about checkin policies" and
then chastise people each time they say they might check something
in on their own.


Re: [PATCH] Add std::is_constant_evaluated wrapper around __builtin_is_constant_evaluated

2018-12-11 Thread Jonathan Wakely

On 11/12/18 17:35 +0100, Jakub Jelinek wrote:

Hi!

The following patch adds std::is_constant_evaluated to the library.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
(relies on the previously posted C++ FE patch).

2018-12-11  Jakub Jelinek  

P0595R2 - is_constant_evaluated
* include/bits/c++config (_GLIBCXX_HAVE_BUILTIN_IS_CONSTANT_EVALUATED):
Define if __builtin_is_constant_evaluated is available.
* include/std/type_traits (std::is_constant_evaluated): New constexpr
inline function.
* testsuite/20_util/is_constant_evaluated/1.cc: New test.
* testsuite/20_util/is_constant_evaluated/noexcept.cc: New test.


OK, thanks.




[PATCH] Fix up split-path-11.c testcase (Re: [committed] [PR tree-optimization/80520] Throttle path splitting slightly.)

2018-12-11 Thread Jakub Jelinek
On Mon, Dec 10, 2018 at 09:56:46PM -0700, Jeff Law wrote:
> commit d90b13427e4940adabc4320c68ca88513dee2eef
> Author: Jeff Law 
> Date:   Mon Dec 10 21:46:41 2018 -0700
> 
> PR tree-optimization/80520
> * gimple-ssa-split-paths.c (is_feasible_trace): Recognize half
> diamonds that are likely if convertable.
> 
> * gcc.dg/tree-ssa/split-path-5.c: Update expected output.
> * gcc.dg/tree-ssa/split-path-11.c: New test.
> 
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/tree-ssa/split-path-11.c
> @@ -0,0 +1,14 @@
> +/* { dg-do compile } */
> +/* { dg-options "-O2 -fsplit-paths -fdump-tree-split-paths-details -w" } */
> +
> +void foo(unsigned long *M)
> +{
> +  for (unsigned long k = 0; k < 227; ++k)
> +{
> +  unsigned long y =
> + ((M[k] & 0x8000) | (M[k + 1] & 0x7fff));
> +  M[k] = (M[k + 397] ^ (y >> 1) ^ ((y & 1) ? 2567483615 : 0));
> +}
> +}
> +
> +/* { dg-final { scan-tree-dump-times "join point for if-convertable 
> half-diamond" 1 "split-paths" } } */

This testcase fails on ILP32 targets like i?86-linux*.

Fixed thusly, ok for trunk?

2018-12-11  Jakub Jelinek  

PR tree-optimization/80520
* gcc.dg/tree-ssa/split-path-11.c (foo): Make the test ilp32 target
clean.

--- gcc/testsuite/gcc.dg/tree-ssa/split-path-11.c.jj2018-12-11 
11:02:09.009065808 +0100
+++ gcc/testsuite/gcc.dg/tree-ssa/split-path-11.c   2018-12-11 
18:10:33.811169259 +0100
@@ -1,13 +1,13 @@
 /* { dg-do compile } */
 /* { dg-options "-O2 -fsplit-paths -fdump-tree-split-paths-details -w" } */
 
-void foo(unsigned long *M)
+void foo(unsigned long long *M)
 {
-  for (unsigned long k = 0; k < 227; ++k)
+  for (unsigned long long k = 0; k < 227; ++k)
 {
-  unsigned long y =
-   ((M[k] & 0x8000) | (M[k + 1] & 0x7fff));
-  M[k] = (M[k + 397] ^ (y >> 1) ^ ((y & 1) ? 2567483615 : 0));
+  unsigned long long y =
+   ((M[k] & 0x8000ULL) | (M[k + 1] & 0x7fffULL));
+  M[k] = (M[k + 397] ^ (y >> 1) ^ ((y & 1) ? 2567483615ULL : 0));
 }
 }
 


Jakub


Re: [PATCH 2/4] c/c++, asm: Use nicer error for duplicate asm qualifiers

2018-12-11 Thread Martin Sebor

+   {
+ error_at (loc, "duplicate asm qualifier %qE", token->value);


We have been making an effort to quote keywords, identifiers,
option names, and other such things in diagnostics.  In
the message above and all others like it in this patch kit
that mention "asm" the keyword should be quoted the same
way as the name of the qualifier.

Thanks
Martin


Re: [PATCH][libbacktrace] Add allocfail.sh test-case

2018-12-11 Thread Ian Lance Taylor via gcc-patches
On Wed, Nov 28, 2018 at 4:50 AM Tom de Vries  wrote:
>
> Add test-case that forces alloc.c functions to fail, and check whether fail
> handling is robust.
>
> This is the test-case for "[libbacktrace] Fix segfault upon allocation
> failure".  Without that patch, this test-case fails like this:
> ...
> allocfail.sh: line 71: 26041 Segmentation fault  (core dumped) \
>   ./allocfail $i > /dev/null 2>&1
> Unallowed fail found: 13
> FAIL allocfail.sh (exit status: 1)
> ...
>
> This is a seperate patch because the test-case is nontrivial.
>
> Bootstrapped and reg-tested on x86_64.
>
> OK for trunk?
>
> Thanks,
> - Tom
>
> [libbacktrace] Add allocfail.sh test-case
>
> 2018-11-27  Tom de Vries  
>
> * Makefile.am (TESTS): Add allocfail.sh.
> (check_PROGRAMS): Add allocfail.
> * Makefile.in: Regenerate.
> * instrumented_alloc.c: New file.  Redefine malloc and realloc.
> Include alloc.c.
> * allocfail.c: New file.
> * allocfail.sh: New file.

Can you redo this without using GNU make features like $(filter-out) ?

Ian


  1   2   >