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

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

OK, I agree that the cleanup makes sense these days and can probably also be 
backported onto the 10 branch without too much risk.

-- 
Eric Botcazou


[PATCH] Fortran : ICE in maybe_canonicalize_comparison_1 PR92993

2020-06-05 Thread Mark Eggleston

OK to commit?

Commit message:

Fortran  : ICE in maybe_canonicalize_comparison_1 PR92993

This issue has been fixed by PR94090.  Add test case to ensure that
this does not re-occur.

2020-06-04  Mark Eggleston 

gcc/fortran/

    PR fortran/92993
    * gfortran.dg/pr92993.f90: New test.

--
https://www.codethink.co.uk/privacy.html



Re: [PATCH] Fortran : ICE in maybe_canonicalize_comparison_1 PR92993

2020-06-05 Thread Mark Eggleston

This time with actual patch.

On 05/06/2020 09:04, Mark Eggleston wrote:

OK to commit?

Commit message:

Fortran  : ICE in maybe_canonicalize_comparison_1 PR92993

This issue has been fixed by PR94090.  Add test case to ensure that
this does not re-occur.

2020-06-04  Mark Eggleston 

gcc/fortran/

    PR fortran/92993
    * gfortran.dg/pr92993.f90: New test.


--
https://www.codethink.co.uk/privacy.html

>From c259b574633c140b2ca477099f4eade239eee1f3 Mon Sep 17 00:00:00 2001
From: Mark Eggleston 
Date: Thu, 4 Jun 2020 05:53:31 +0100
Subject: [PATCH] Fortran  : ICE in maybe_canonicalize_comparison_1 PR92993

This issue has been fixed by PR94090.  Add test case to ensure that
this does not re-occur.

2020-06-04  Mark Eggleston  

gcc/fortran/

	PR fortran/92993
	* gfortran.dg/pr92993.f90: New test.
---
 gcc/testsuite/gfortran.dg/pr92993.f90 | 21 +
 1 file changed, 21 insertions(+)
 create mode 100644 gcc/testsuite/gfortran.dg/pr92993.f90

diff --git a/gcc/testsuite/gfortran.dg/pr92993.f90 b/gcc/testsuite/gfortran.dg/pr92993.f90
new file mode 100644
index 000..08bba91e258
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr92993.f90
@@ -0,0 +1,21 @@
+! { dg-do compile }
+!
+! Original by G. Steinmetz
+
+function f(x)
+  integer, intent(in) :: x
+  integer :: f
+  f = x
+end
+
+program p
+  interface
+function f(x)
+  integer, intent(in) :: x
+  integer, pointer :: f
+end
+  end interface
+  integer :: a(2) = [1, 2]
+  if ( a(2) .ne. f(a(2)) ) stop 1 ! { dg-error "POINTER attribute mismatch in function result" }
+end
+
-- 
2.11.0



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

2020-06-05 Thread Andrea Corallo
Richard Sandiford  writes:

> Andrea Corallo  writes:
>> Hi all,
>>
>> I'd like to submit this patch introducing the following 64bit builtins
>> variants as FPCR and FPSR registers getter/setter:
>>
>> unsigned long long __builtin_aarch64_get_fpcr64 ()
>> void __builtin_aarch64_set_fpcr64 (unsigned long long)
>> unsigned long long __builtin_aarch64_get_fpsr64 ()
>> void __builtin_aarch64_set_fpsr64 (unsigned long long)
>
> Sound like this part is uncontroversial.  At least, if anyone objects
> to it, they should have said so earlier :-)
>
>> @@ -1240,33 +1245,65 @@ aarch64_init_memtag_builtins (void)
>>  #undef AARCH64_INIT_MEMTAG_BUILTINS_DECL
>>  }
>>  
>> -/* Initialize all builtins in the AARCH64_BUILTIN_GENERAL group.  */
>> +/* Initialize fpsr fpcr getter and setters.  */
>
> “getters”
>
>> @@ -1871,6 +1908,40 @@ aarch64_expand_builtin_memtag (int fcode, tree exp, 
>> rtx target)
>>return target;
>>  }
>>  
>> +static rtx
>> +aarch64_expand_fcr_fpsr_builtin (tree exp, machine_mode mode, bool getter,
>> + bool fpsr)
>> +{
>> +  int icode;
>> +  rtx pat;
>> +  rtx target = NULL_RTX;
>> +
>> +  gcc_assert (mode == SImode || (mode == DImode));
>> +
>> +  if (getter)
>> +{
>> +  if (mode == SImode)
>> +icode = fpsr ? CODE_FOR_get_fpsr : CODE_FOR_get_fpcr;
>> +  else
>> +icode = fpsr ? CODE_FOR_get_fpsr64 : CODE_FOR_get_fpcr64;
>> +  target = gen_reg_rtx (mode);
>> +  pat = GEN_FCN (icode) (target);
>> +}
>> +  else
>> +{
>> +  target = NULL_RTX;
>> +  if (mode == SImode)
>> +icode = fpsr ? CODE_FOR_set_fpsr : CODE_FOR_set_fpcr;
>> +  else
>> +icode = fpsr ? CODE_FOR_set_fpsr64 : CODE_FOR_set_fpcr64;
>> +  tree arg = CALL_EXPR_ARG (exp, 0);
>> +  rtx op = force_reg (mode, expand_normal (arg));
>> +  pat = GEN_FCN (icode) (op);
>> +}
>> +  emit_insn (pat);
>> +  return target;
>> +}
>> +
>>  /* Expand an expression EXP that calls built-in function FCODE,
>> with result going to TARGET if that's convenient.  IGNORE is true
>> if the result of the builtin is ignored.  */
>> @@ -1879,35 +1950,27 @@ aarch64_general_expand_builtin (unsigned int fcode, 
>> tree exp, rtx target,
>>  int ignore)
>>  {
>>int icode;
>> -  rtx pat, op0;
>> +  rtx op0;
>>tree arg0;
>>  
>>switch (fcode)
>>  {
>>  case AARCH64_BUILTIN_GET_FPCR:
>> +  return aarch64_expand_fcr_fpsr_builtin (exp, SImode, true, false);
>>  case AARCH64_BUILTIN_SET_FPCR:
>> +  return aarch64_expand_fcr_fpsr_builtin (exp, SImode, false, false);
>>  case AARCH64_BUILTIN_GET_FPSR:
>> +  return aarch64_expand_fcr_fpsr_builtin (exp, SImode, true, true);
>>  case AARCH64_BUILTIN_SET_FPSR:
>> -  if ((fcode == AARCH64_BUILTIN_GET_FPCR)
>> -  || (fcode == AARCH64_BUILTIN_GET_FPSR))
>> -{
>> -  icode = (fcode == AARCH64_BUILTIN_GET_FPSR) ?
>> -CODE_FOR_get_fpsr : CODE_FOR_get_fpcr;
>> -  target = gen_reg_rtx (SImode);
>> -  pat = GEN_FCN (icode) (target);
>> -}
>> -  else
>> -{
>> -  target = NULL_RTX;
>> -  icode = (fcode == AARCH64_BUILTIN_SET_FPSR) ?
>> -CODE_FOR_set_fpsr : CODE_FOR_set_fpcr;
>> -  arg0 = CALL_EXPR_ARG (exp, 0);
>> -  op0 = force_reg (SImode, expand_normal (arg0));
>> -  pat = GEN_FCN (icode) (op0);
>> -}
>> -  emit_insn (pat);
>> -  return target;
>> -
>> +  return aarch64_expand_fcr_fpsr_builtin (exp, SImode, false, true);
>> +case AARCH64_BUILTIN_GET_FPCR64:
>> +  return aarch64_expand_fcr_fpsr_builtin (exp, DImode, true, false);
>> +case AARCH64_BUILTIN_SET_FPCR64:
>> +  return aarch64_expand_fcr_fpsr_builtin (exp, DImode, false, false);
>> +case AARCH64_BUILTIN_GET_FPSR64:
>> +  return aarch64_expand_fcr_fpsr_builtin (exp, DImode, true, true);
>> +case AARCH64_BUILTIN_SET_FPSR64:
>> +  return aarch64_expand_fcr_fpsr_builtin (exp, DImode, false, true);
>>  case AARCH64_PAUTH_BUILTIN_AUTIA1716:
>>  case AARCH64_PAUTH_BUILTIN_PACIA1716:
>>  case AARCH64_PAUTH_BUILTIN_AUTIB1716:
>> diff --git a/gcc/config/aarch64/aarch64.md b/gcc/config/aarch64/aarch64.md
>> index 7ad4e918578b..b6836710c9c2 100644
>> --- a/gcc/config/aarch64/aarch64.md
>> +++ b/gcc/config/aarch64/aarch64.md
>> @@ -289,6 +289,10 @@
>>  UNSPECV_SET_FPCR; Represent assign of FPCR content.
>>  UNSPECV_GET_FPSR; Represent fetch of FPSR content.
>>  UNSPECV_SET_FPSR; Represent assign of FPSR content.
>> +UNSPECV_GET_FPCR64  ; Represent fetch of 64 bits FPCR 
>> content.
>> +UNSPECV_SET_FPCR64  ; Represent assign of 64 bits FPCR 
>> content.
>> +UNSPECV_GET_FPSR64  ; Represent fetch of 64 bits FPSR 
>> content.
>> +UNSPECV_SET_FPSR64  ; Represent assign of 64 bits FPSR 
>> content.
>>  UNSPECV_BLOCKAGE; Represent a blockage
>>  UNS

Re: [PATCH] Fortran : ICE in maybe_canonicalize_comparison_1 PR92993

2020-06-05 Thread Thomas Koenig via Gcc-patches

Hi Mark,


OK to commit?


Yes. As a general rule, I think that committing test cases for PRs
that have been fixed by something else falls under the "obvious
and simple" rule - no approval required.

Thanks!

Regards

Thomas


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

2020-06-05 Thread Richard Biener
On Fri, 5 Jun 2020, Eric Botcazou wrote:

> > The patch ends up recording the whole Array ref with variable index. All
> > alias analysis code deals with this just fine. IIRC historically we tried
> > to save memory with stripping and dropping of MEM_EXPRs.
> 
> OK, I agree that the cleanup makes sense these days and can probably also be 
> backported onto the 10 branch without too much risk.

I've installed it on trunk but will give it quite a while there before
backporting.  I'm still somewhat worried about the

  /* ???  If we end up with a constant or a descriptor do not
 record a MEM_EXPR.  */
  else if (CONSTANT_CLASS_P (t)
   || TREE_CODE (t) == CONSTRUCTOR)
;

case, maybe we should assert that bitpos == 0 here since we're
dropping it on the floor but eventually inherit offset_known_p == true
from the already present MEM_ATTRs.  I guess 
set_mem_attributes_minus_bitpos should be an all-or-nothing with
regard to the inherited MEM_ATTRs - take them unmodified or override
them completely.  But even then - can we simply ignore the passed
in bitpos?  shall we at least set offset_known_p to false if we do?
We're also happily ignoring an inherited attrs.offset.  Still this
all suggests the take it all or nothing approach.

Also for the one case I've seen (through expand_debug_expr
though - "semantically" irreleveant thus) where we end up being called
for a MEM that was generated for a completely different object,
for example a stack slot, but we'll still apply things like alignment
analysis on the passed in tree which might be unrelated enough to
make the derived alignment invalid for the actual MEM.

Richard.


Fix ICE with typeless storage

2020-06-05 Thread Jan Hubicka
Hi,
this patch fixes ICE while bulding Firefox on assert in
record_component_aliases which checks that the alias set did not change
while peeling off vector and array types.
This is done so we can translate notice references to pointers.

If array is TYPE_TYPELESS_STORAGE then it is not true that array type
woud have same alias set as its elements since its alias set is 0, so we
need to watch for this. (And it is safe to miss pointer here once we add
alias set 0 as a component)

Honza

* alias.c (record_component_aliases): Watch for typeless storage while
skipping the ARRAY_TREE wrappers.

diff --git a/gcc/alias.c b/gcc/alias.c
index 49bd7b37966..2bed5e78c62 100644
--- a/gcc/alias.c
+++ b/gcc/alias.c
@@ -1273,8 +1273,12 @@ record_component_aliases (tree type, alias_set_type 
superset)
{
  /* VECTOR_TYPE and ARRAY_TYPE share the alias set with their
 element type and that type has to be normalized to void *,
-too, in the case it is a pointer. */
- while (!canonical_type_used_p (t) && !POINTER_TYPE_P (t))
+too, in the case it is a pointer.
+An exception is array with TYPE_TYPELESS_STORAGE which
+has alias set 0.  */
+ while (!canonical_type_used_p (t) && !POINTER_TYPE_P (t)
+&& (!AGGREGATE_TYPE_P (t)
+|| !TYPE_TYPELESS_STORAGE (t)))
{
  gcc_checking_assert (TYPE_STRUCTURAL_EQUALITY_P (t));
  t = TREE_TYPE (t);


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

2020-06-05 Thread Feng Xue OS via Gcc-patches
As Marc suggested, removed the new pointer_diff rule, and add another rule to 
fold
convert-add expression. This new rule is:

  (T)(A * C) +- (T)(B * C) -> (T) ((A +- B) * C)

Regards,
Feng

---
2020-06-01  Feng Xue  

gcc/
PR tree-optimization/94234
* match.pd ((T)(A * C) +- (T)(B * C)) -> (T)((A +- B) * C): New
simplification.
* ((PTR_A + OFF) - (PTR_B + OFF)) -> (PTR_A - PTR_B): New
simplification.

gcc/testsuite/
PR tree-optimization/94234
* gcc.dg/pr94234.c: New test.
---
 gcc/match.pd   | 28 
 gcc/testsuite/gcc.dg/pr94234.c | 24 
 2 files changed, 52 insertions(+)
 create mode 100644 gcc/testsuite/gcc.dg/pr94234.c

diff --git a/gcc/match.pd b/gcc/match.pd
index 33ee1a920bf..4f340bfe40a 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -2515,6 +2515,9 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
 && TREE_CODE (@2) == INTEGER_CST
 && tree_int_cst_sign_bit (@2) == 0))
  (minus (convert @1) (convert @2)
+   (simplify
+(pointer_diff (pointer_plus @0 @2) (pointer_plus @1 @2))
+ (pointer_diff @0 @1))
(simplify
 (pointer_diff (pointer_plus @@0 @1) (pointer_plus @0 @2))
 /* The second argument of pointer_plus must be interpreted as signed, and
@@ -2526,6 +2529,31 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
  (minus (convert (view_convert:stype @1))
(convert (view_convert:stype @2)))

+/* (T)(A * C) +- (T)(B * C) -> (T)((A +- B) * C) and
+   (T)(A * C) +- (T)(A) -> (T)(A * (C +- 1)). */
+(if (INTEGRAL_TYPE_P (type))
+ (for plusminus (plus minus)
+  (simplify
+   (plusminus (convert:s (mult:cs @0 @1)) (convert:s (mult:cs @0 @2)))
+   (if (element_precision (type) <= element_precision (TREE_TYPE (@0))
+   && (TYPE_OVERFLOW_UNDEFINED (type) || TYPE_OVERFLOW_WRAPS (type))
+   && TYPE_OVERFLOW_WRAPS (TREE_TYPE (@0)))
+(convert (mult (plusminus @1 @2) @0
+  (simplify
+   (plusminus (convert @0) (convert@2 (mult:c@3 @0 @1)))
+   (if (element_precision (type) <= element_precision (TREE_TYPE (@0))
+   && (TYPE_OVERFLOW_UNDEFINED (type) || TYPE_OVERFLOW_WRAPS (type))
+   && TYPE_OVERFLOW_WRAPS (TREE_TYPE (@0))
+   && single_use (@2) && single_use (@3))
+(convert (mult (plusminus { build_one_cst (TREE_TYPE (@1)); } @1) @0
+  (simplify
+   (plusminus (convert@2 (mult:c@3 @0 @1)) (convert @0))
+   (if (element_precision (type) <= element_precision (TREE_TYPE (@0))
+   && (TYPE_OVERFLOW_UNDEFINED (type) || TYPE_OVERFLOW_WRAPS (type))
+   && TYPE_OVERFLOW_WRAPS (TREE_TYPE (@0))
+   && single_use (@2) && single_use (@3))
+(convert (mult (plusminus @1 { build_one_cst (TREE_TYPE (@1)); }) @0))
+
 /* (A * C) +- (B * C) -> (A+-B) * C and (A * C) +- A -> A * (C+-1).
 Modeled after fold_plusminus_mult_expr.  */
 (if (!TYPE_SATURATING (type)
diff --git a/gcc/testsuite/gcc.dg/pr94234.c b/gcc/testsuite/gcc.dg/pr94234.c
new file mode 100644
index 000..3f7c7a5e58f
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr94234.c
@@ -0,0 +1,24 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-forwprop1" } */
+
+typedef __SIZE_TYPE__ size_t;
+typedef __PTRDIFF_TYPE__ ptrdiff_t;
+
+ptrdiff_t foo (char *a, size_t n)
+{
+  char *b1 = a + 8 * n;
+  char *b2 = a + 8 * (n - 1);
+
+  return b1 - b2;
+}
+
+ptrdiff_t goo (char *a, size_t n, size_t m)
+{
+  char *b1 = a + 8 * n;
+  char *b2 = a + 8 * (n + 1);
+
+  return (b1 + m) - (b2 + m);
+}
+
+/* { dg-final { scan-tree-dump-times "return 8;" 1 "forwprop1" } } */
+/* { dg-final { scan-tree-dump-times "return -8;" 1 "forwprop1" } } */
--



From: Richard Biener 
Sent: Thursday, June 4, 2020 4:30 PM
To: gcc-patches@gcc.gnu.org
Cc: Feng Xue OS
Subject: Re: [PATCH] Add pattern for pointer-diff on addresses with same 
base/offset (PR 94234)

On Wed, Jun 3, 2020 at 4:33 PM Marc Glisse  wrote:
>
> On Wed, 3 Jun 2020, Feng Xue OS via Gcc-patches wrote:
>
> >> Ah, looking at the PR, you decided to perform the operation as unsigned
> >> because that has fewer NOP conversions, which, in that particular testcase
> >> where the offsets are originally unsigned, means we simplify better. But I
> >> would expect it to regress other testcases (in particular if the offsets
> >> were originally signed). Also, changing the second argument of
> >> pointer_plus to be signed, as is supposed to eventually happen, would
> >> break your testcase again.
> > The old rule might produce overflow result (offset_a = (signed_int_max)UL,
> > offset_b = 1UL).
>
> signed_int_max-1 does not overflow. But the point is that pointer_plus /
> pointer_diff are defined in a way that if that subtraction would overflow,
> then one of the pointer_plus or pointed_diff would have been undefined
> already. In particular, you cannot have objects larger than half the
> address space, and pointer_plus/pointer_diff have to remain inside an
> object. Doing the su

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

2020-06-05 Thread Richard Sandiford
Richard Sandiford  writes:
> "Yangfei (Felix)"  writes:
>> Hi,
>>
>>> -Original Message-
>>> From: Richard Sandiford [mailto:richard.sandif...@arm.com]
>>> Sent: Monday, June 1, 2020 4:47 PM
>>> To: Yangfei (Felix) 
>>> Cc: gcc-patches@gcc.gnu.org; Uros Bizjak ; Jakub
>>> Jelinek ; Hongtao Liu ; H.J. Lu
>>> 
>>> Subject: Re: [PATCH PR95254] aarch64: gcc generate inefficient code with
>>> fixed sve vector length
>>
>> Snip...
>>  
>>> Sounds good.  Maybe at this point the x_inner and y_inner code is getting
>>> complicated enough to put into a lambda too:
>>> 
>>>   x_inner = ... (x);
>>>   y_inner = ... (y);
>>> 
>>> Just a suggestion though.
>>
>> Yes, that's a good suggestion.  I see the code becomes more cleaner with 
>> another lambda.
>>  
>>> Yeah, looks good.
>>> 
>>> Formatting nit though: multi-line conditions should be wrapped in (...),
>>> i.e.:
>>> 
>>> return (...
>>> && ...
>>> && ...);
>>> 
>>
>> Done.  v6 patch is based on trunk 20200601.
>> Bootstrapped and tested on aarch64-linux-gnu. 
>> Also bootstrapped on x86-64-linux-gnu with --enable-multilib (for building 
>> -m32 x86 libgcc).
>> Regresssion test on x86-64-linux-gnu looks good except for the following 
>> failures which has been confirmed by x86 devs: 
>>
>>> FAIL: gcc.target/i386/avx512f-vcvtps2ph-2.c (test for excess errors)
>>> UNRESOLVED: gcc.target/i386/avx512f-vcvtps2ph-2.c compilation failed to 
>>> produce executable
>> 154803c154803
>
> Looks good.  (I know I said that last time too :-))  I've also tested
> it on arm-linux-gnueabihf and powerpc64le-linux-gnu without problems.
>
> As before, I'll hold off applying until the AVX512 problem is fixed.

Now pushed.  In summary, the patch has now been tested on:

  aarch64-linux-gnu (with and without SVE)
  arm-linus-gnueabihf
  armeb-eabi
  powerpc64le-linux-gnu
  x86_64-linux-gnu (including -m32)

Hopefully Jeff and Christophe's testers will pick up any other
lurking problems.

Thanks,
Richard


[PATCH] tree-optimization/95539 - fix SLP_TREE_REPRESENTATIVE vs. dr_info

2020-06-05 Thread Richard Biener
This fixes a disconnect between the stmt_info used for dr_info
analysis and the one in SLP_TREE_REPRESENTATIVE with a temporary
workaround.

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

2020-06-05  Richard Biener  

PR tree-optimization/95539
* tree-vect-data-refs.c
(vect_slp_analyze_and_verify_instance_alignment): Use
SLP_TREE_REPRESENTATIVE for the data-ref check.
* tree-vect-stmts.c (vectorizable_load): Reset stmt_info
back to the first scalar stmt rather than the
SLP_TREE_REPRESENTATIVE to match previous behavior.

* gcc.dg/vect/pr95539.c: New testcase.
---
 gcc/testsuite/gcc.dg/vect/pr95539.c | 29 +
 gcc/tree-vect-data-refs.c   |  2 +-
 gcc/tree-vect-stmts.c   | 19 +++
 3 files changed, 45 insertions(+), 5 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/vect/pr95539.c

diff --git a/gcc/testsuite/gcc.dg/vect/pr95539.c 
b/gcc/testsuite/gcc.dg/vect/pr95539.c
new file mode 100644
index 000..de3b393879e
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/vect/pr95539.c
@@ -0,0 +1,29 @@
+/* { dg-do compile } */
+
+typedef unsigned short uint16_t;
+typedef short __v8hi __attribute__ ((__vector_size__ (16)));
+typedef long long __m128i __attribute__ ((__vector_size__ (16), 
__may_alias__));
+extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__))
+_mm_set_epi16 (short __q7, short __q6, short __q5, short __q4,
+  short __q3, short __q2, short __q1, short __q0)
+{
+  return __extension__ (__m128i)(__v8hi){
+  __q0, __q1, __q2, __q3, __q4, __q5, __q6, __q7 };
+}
+void gcm_HashMult_hw(__m128i *x, const unsigned char *buf, unsigned int count)
+{
+  unsigned i;
+  __m128i bin __attribute__((aligned(16)));
+  for (i = 0; i < count; i++, buf += 16)
+{
+  bin = _mm_set_epi16(((uint16_t)buf[0] << 8) | buf[1],
+ ((uint16_t)buf[2] << 8) | buf[3],
+ ((uint16_t)buf[4] << 8) | buf[5],
+ ((uint16_t)buf[6] << 8) | buf[7],
+ ((uint16_t)buf[8] << 8) | buf[9],
+ ((uint16_t)buf[10] << 8) | buf[11],
+ ((uint16_t)buf[12] << 8) | buf[13],
+ ((uint16_t)buf[14] << 8) | buf[15]);
+  *(x++) = bin;
+}
+}
diff --git a/gcc/tree-vect-data-refs.c b/gcc/tree-vect-data-refs.c
index b950aa9e50d..fe543606a52 100644
--- a/gcc/tree-vect-data-refs.c
+++ b/gcc/tree-vect-data-refs.c
@@ -2471,7 +2471,7 @@ vect_slp_analyze_and_verify_instance_alignment (vec_info 
*vinfo,
   return false;
 
   node = SLP_INSTANCE_TREE (instance);
-  if (STMT_VINFO_DATA_REF (SLP_TREE_SCALAR_STMTS (node)[0])
+  if (STMT_VINFO_DATA_REF (SLP_TREE_REPRESENTATIVE (node))
   && ! vect_slp_analyze_and_verify_node_alignment
 (vinfo, SLP_INSTANCE_TREE (instance)))
 return false;
diff --git a/gcc/tree-vect-stmts.c b/gcc/tree-vect-stmts.c
index c0be6ef502c..b24b0fe4304 100644
--- a/gcc/tree-vect-stmts.c
+++ b/gcc/tree-vect-stmts.c
@@ -8661,6 +8661,20 @@ vectorizable_load (vec_info *vinfo,
   && ! vec_stmt)
 return false;
 
+  if (!STMT_VINFO_DATA_REF (stmt_info))
+return false;
+
+  /* ???  Alignment analysis for SLP looks at SLP_TREE_SCALAR_STMTS[0]
+ for unpermuted loads but we get passed SLP_TREE_REPRESENTATIVE
+ which can be different when reduction chains were re-ordered.
+ Now that we figured we're a dataref reset stmt_info back to
+ SLP_TREE_SCALAR_STMTS[0].  When we're SLP only things should be
+ refactored in a way to maintain the dr_vec_info pointer for the
+ relevant access explicitely.  */
+  stmt_vec_info orig_stmt_info = stmt_info;
+  if (slp_node)
+stmt_info = SLP_TREE_SCALAR_STMTS (slp_node)[0];
+
   tree mask = NULL_TREE, mask_vectype = NULL_TREE;
   if (gassign *assign = dyn_cast  (stmt_info->stmt))
 {
@@ -8703,9 +8717,6 @@ vectorizable_load (vec_info *vinfo,
}
 }
 
-  if (!STMT_VINFO_DATA_REF (stmt_info))
-return false;
-
   tree vectype = STMT_VINFO_VECTYPE (stmt_info);
   poly_uint64 nunits = TYPE_VECTOR_SUBPARTS (vectype);
 
@@ -8876,7 +8887,7 @@ vectorizable_load (vec_info *vinfo,
check_load_store_masking (loop_vinfo, vectype, VLS_LOAD, group_size,
  memory_access_type, &gs_info, mask);
 
-  STMT_VINFO_TYPE (stmt_info) = load_vec_info_type;
+  STMT_VINFO_TYPE (orig_stmt_info) = load_vec_info_type;
   vect_model_load_cost (vinfo, stmt_info, ncopies, vf, memory_access_type,
slp_node, cost_vec);
   return true;
-- 
2.26.2


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

2020-06-05 Thread Thomas Schwinge
Hi Julian!

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

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

> @@ -1018,6 +1033,33 @@ goacc_exit_data_internal (struct gomp_device_descr 
> *acc_dev, size_t mapnum,
>  {
>gomp_mutex_lock (&acc_dev->lock);
>
> +  /* Handle "detach" before copyback/deletion of mapped data.  */
> +  for (size_t i = 0; i < mapnum; ++i)
> +{
> +  unsigned char kind = kinds[i] & 0xff;
> +  switch (kind)
> + {
> + case GOMP_MAP_DETACH:
> + case GOMP_MAP_FORCE_DETACH:
> +   {
> + struct splay_tree_key_s cur_node;
> + uintptr_t hostaddr = (uintptr_t) hostaddrs[i];
> + cur_node.host_start = hostaddr;
> + cur_node.host_end = cur_node.host_start + sizeof (void *);
> + splay_tree_key n
> +   = splay_tree_lookup (&acc_dev->mem_map, &cur_node);
> +
> + if (n == NULL)
> +   gomp_fatal ("struct not mapped for detach operation");
> +
> + gomp_detach_pointer (acc_dev, aq, n, hostaddr, finalize, NULL);
> +   }
> +   break;
> + default:
> +   ;
> + }
> +}
> +
>for (size_t i = 0; i < mapnum; ++i)
>  {
>unsigned char kind = kinds[i] & 0xff;

What's the reason that we're not instead emitting any 'detach' mappings
in the expected order (that is, first), which would avoid this
double-traversal here?  Given that 'mapnum' typically won't exceed the
dozens, the code we now got doesn't have a big run-time cost, of course,
but it's still a bit ugly, conceptually, for no apparent reason, unless
I'm confused?

> --- a/libgomp/target.c
> +++ b/libgomp/target.c

> @@ -1534,6 +1571,18 @@ gomp_unmap_vars_internal (struct target_mem_desc *tgt, 
> bool do_copyfrom,
>  }
>
>size_t i;
> +
> +  /* We must perform detachments before any copies back to the host.  */
> +  for (i = 0; i < tgt->list_count; i++)
> +{
> +  splay_tree_key k = tgt->list[i].key;
> +
> +  if (k != NULL && tgt->list[i].do_detach)
> + gomp_detach_pointer (devicep, aq, k, tgt->list[i].key->host_start
> +  + tgt->list[i].offset,
> +  k->refcount == 1, NULL);
> +}
> +
>for (i = 0; i < tgt->list_count; i++)
>  {
>splay_tree_key k = tgt->list[i].key;

Similarly, isn't it sufficient if any 'detach' for 'tgt->list[i].key' is
done (directly) before the copy-back/unmap of 'tgt->list[i].key', again
to avoid the double-traversal here?


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


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

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

Hi,

This is causing a regression in fortran tests:
FAIL: gfortran.dg/goacc/uninit-use-device-clause.f95   -O   (test for
warnings, line 7)
FAIL: gfortran.dg/goacc/uninit-use-device-clause.f95   -O  (test for
excess errors)
Excess errors:
/gcc/testsuite/gfortran.dg/goacc/uninit-use-device-clause.f95:7:0:
Warning: 'p' is used uninitialized [-Wuninitialized]

Christophe

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


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

2020-06-05 Thread Thomas Schwinge
Hi Julian!

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

> --- a/libgomp/target.c
> +++ b/libgomp/target.c

> @@ -1203,6 +1211,32 @@ gomp_map_vars_internal (struct gomp_device_descr 
> *devicep,

> +   case GOMP_MAP_ATTACH:
> + {
> +   cur_node.host_start = (uintptr_t) hostaddrs[i];
> +   cur_node.host_end = cur_node.host_start + sizeof (void *);
> +   splay_tree_key n = splay_tree_lookup (mem_map, &cur_node);
> +   if (n != NULL)
> + {
> +   tgt->list[i].key = n;
> +   tgt->list[i].offset = cur_node.host_start - n->host_start;
> +   tgt->list[i].length = n->host_end - n->host_start;
> +   tgt->list[i].copy_from = false;
> +   tgt->list[i].always_copy_from = false;
> +   tgt->list[i].do_detach
> + = (pragma_kind != GOMP_MAP_VARS_OPENACC_ENTER_DATA);
> +   n->refcount++;
> + }
> +   else
> + {
> +   gomp_mutex_unlock (&devicep->lock);
> +   gomp_fatal ("outer struct not mapped for attach");
> + }
> +   gomp_attach_pointer (devicep, aq, mem_map, n,
> +(uintptr_t) hostaddrs[i], sizes[i],
> +cbufp);
> +   continue;
> + }

For the OpenACC runtime API 'acc_attach' etc. routines they don't, so
what's the conceptual reason that for the corresponding OpenACC directive
variants, 'GOMP_MAP_ATTACH' etc. here participate in reference counting
('n->refcount++' above)?  I understand OpenACC 'attach'/'detach' clauses
to be simple "executable clauses", which just update some values
somewhere (say, like 'GOMP_MAP_ALWAYS_POINTER'), but they don't alter any
mapping state, thus wouldn't appear to need reference counting?


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


[committed] d: Merge upstream dmd 6d5bffa54

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

This patch merges the D front-end implementation with upstream dmd
6d5bffa54.  Removes an unused parameter from Condition::include(), all
callers have been updated in the front-end.

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

Regards
Iain.


gcc/d/ChangeLog:

* dmd/MERGE: Merge upstream dmd 6d5bffa54.
* d-builtins.cc (maybe_set_builtin_1): Update call to
Condition::include().
* decl.cc (DeclVisitor::visit(AttribDeclaration *)): Likewise.
* types.cc (layout_aggregate_members): Likewise.
---
 gcc/d/d-builtins.cc   |  2 +-
 gcc/d/decl.cc |  2 +-
 gcc/d/dmd/MERGE   |  2 +-
 gcc/d/dmd/attrib.c| 50 +++
 gcc/d/dmd/attrib.h|  8 +++
 gcc/d/dmd/canthrow.c  |  2 +-
 gcc/d/dmd/cond.c  |  7 +++---
 gcc/d/dmd/cond.h  |  8 +++
 gcc/d/dmd/doc.c   |  4 ++--
 gcc/d/dmd/dscope.c|  2 --
 gcc/d/dmd/dsymbol.c   |  2 +-
 gcc/d/dmd/expressionsem.c |  6 +
 gcc/d/dmd/json.c  |  2 +-
 gcc/d/dmd/scope.h |  2 --
 gcc/d/dmd/statement.c |  8 +++
 gcc/d/dmd/statementsem.c  |  2 +-
 gcc/d/dmd/traits.c|  2 +-
 gcc/d/types.cc|  2 +-
 18 files changed, 52 insertions(+), 61 deletions(-)

diff --git a/gcc/d/d-builtins.cc b/gcc/d/d-builtins.cc
index c18287a2025..61014cbea51 100644
--- a/gcc/d/d-builtins.cc
+++ b/gcc/d/d-builtins.cc
@@ -668,7 +668,7 @@ maybe_set_builtin_1 (Dsymbol *d)
   if (ad != NULL)
 {
   /* Recursively search through attribute decls.  */
-  Dsymbols *decls = ad->include (NULL, NULL);
+  Dsymbols *decls = ad->include (NULL);
   if (decls && decls->length)
{
  for (size_t i = 0; i < decls->length; i++)
diff --git a/gcc/d/decl.cc b/gcc/d/decl.cc
index 11e66483b8f..d5f8797b55e 100644
--- a/gcc/d/decl.cc
+++ b/gcc/d/decl.cc
@@ -232,7 +232,7 @@ public:
 
   void visit (AttribDeclaration *d)
   {
-Dsymbols *ds = d->include (NULL, NULL);
+Dsymbols *ds = d->include (NULL);
 
 if (!ds)
   return;
diff --git a/gcc/d/dmd/MERGE b/gcc/d/dmd/MERGE
index a742bd096fa..0a4fb767396 100644
--- a/gcc/d/dmd/MERGE
+++ b/gcc/d/dmd/MERGE
@@ -1,4 +1,4 @@
-48d704f082ebe8b199a9ef7712c223216cd70d3a
+6d5bffa54f7da21d388de586fd8a11ebcdb1
 
 The first line of this file holds the git revision number of the last
 merge done from the dlang/dmd repository.
diff --git a/gcc/d/dmd/attrib.c b/gcc/d/dmd/attrib.c
index 6f176ef096d..02761ab0355 100644
--- a/gcc/d/dmd/attrib.c
+++ b/gcc/d/dmd/attrib.c
@@ -41,7 +41,7 @@ AttribDeclaration::AttribDeclaration(Dsymbols *decl)
 this->decl = decl;
 }
 
-Dsymbols *AttribDeclaration::include(Scope *, ScopeDsymbol *)
+Dsymbols *AttribDeclaration::include(Scope *)
 {
 if (errors)
 return NULL;
@@ -51,7 +51,7 @@ Dsymbols *AttribDeclaration::include(Scope *, ScopeDsymbol *)
 
 int AttribDeclaration::apply(Dsymbol_apply_ft_t fp, void *param)
 {
-Dsymbols *d = include(_scope, NULL);
+Dsymbols *d = include(_scope);
 
 if (d)
 {
@@ -111,7 +111,7 @@ Scope *AttribDeclaration::newScope(Scope *sc)
 
 void AttribDeclaration::addMember(Scope *sc, ScopeDsymbol *sds)
 {
-Dsymbols *d = include(sc, sds);
+Dsymbols *d = include(sc);
 
 if (d)
 {
@@ -131,7 +131,7 @@ void AttribDeclaration::addMember(Scope *sc, ScopeDsymbol 
*sds)
 
 void AttribDeclaration::setScope(Scope *sc)
 {
-Dsymbols *d = include(sc, NULL);
+Dsymbols *d = include(sc);
 
 //printf("\tAttribDeclaration::setScope '%s', d = %p\n",toChars(), d);
 if (d)
@@ -151,7 +151,7 @@ void AttribDeclaration::setScope(Scope *sc)
 
 void AttribDeclaration::importAll(Scope *sc)
 {
-Dsymbols *d = include(sc, NULL);
+Dsymbols *d = include(sc);
 
 //printf("\tAttribDeclaration::importAll '%s', d = %p\n", toChars(), d);
 if (d)
@@ -174,7 +174,7 @@ void AttribDeclaration::semantic(Scope *sc)
 if (semanticRun != PASSinit)
 return;
 semanticRun = PASSsemantic;
-Dsymbols *d = include(sc, NULL);
+Dsymbols *d = include(sc);
 
 //printf("\tAttribDeclaration::semantic '%s', d = %p\n",toChars(), d);
 if (d)
@@ -195,7 +195,7 @@ void AttribDeclaration::semantic(Scope *sc)
 
 void AttribDeclaration::semantic2(Scope *sc)
 {
-Dsymbols *d = include(sc, NULL);
+Dsymbols *d = include(sc);
 
 if (d)
 {
@@ -214,7 +214,7 @@ void AttribDeclaration::semantic2(Scope *sc)
 
 void AttribDeclaration::semantic3(Scope *sc)
 {
-Dsymbols *d = include(sc, NULL);
+Dsymbols *d = include(sc);
 
 if (d)
 {
@@ -236,7 +236,7 @@ void AttribDeclaration::addComment(const utf8_t *comment)
 //printf("AttribDeclaration::addComment %s\n", comment);
 if (comment)
 {
-Dsymbols *d = include(NULL, NULL);
+Dsymbols *d = include(NULL);
 
 if (d)
 {
@@ -252,7 +252,7 @@ void AttribDeclaration::addComment(const utf8_t *comment)
 
 void AttribDeclaration::s

[Ada] AI12-0144 Make Discrete_Random more flexible

2020-06-05 Thread Pierre-Marie de Rodat
A new version of Random is provided to provide more flexibility on the
range of values returned, see the Ada AI for more details.

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

2020-06-05  Arnaud Charlet  

gcc/ada/

* libgnat/a-nudira.ads, libgnat/a-nudira.adb (Random): New
function.--- gcc/ada/libgnat/a-nudira.adb
+++ gcc/ada/libgnat/a-nudira.adb
@@ -56,6 +56,17 @@ is
   return Random (SRN.Generator (Gen));
end Random;
 
+   function Random
+ (Gen   : Generator;
+  First : Result_Subtype;
+  Last  : Result_Subtype) return Result_Subtype
+   is
+  subtype Local_Subtype is Result_Subtype range First .. Last;
+  function Random is new SRN.Random_Discrete (Local_Subtype, First);
+   begin
+  return Random (SRN.Generator (Gen));
+   end Random;
+
---
-- Reset --
---

--- gcc/ada/libgnat/a-nudira.ads
+++ gcc/ada/libgnat/a-nudira.ads
@@ -51,6 +51,12 @@ is
 
function Random (Gen : Generator) return Result_Subtype;
 
+   function Random
+ (Gen   : Generator;
+  First : Result_Subtype;
+  Last  : Result_Subtype) return Result_Subtype
+ with Post => Random'Result in First .. Last;
+
procedure Reset (Gen : Generator; Initiator : Integer);
procedure Reset (Gen : Generator);
 



[Ada] Add No_Truncation flag on view conversion for GNAT-LLVM

2020-06-05 Thread Pierre-Marie de Rodat
This puts the No_Truncation flag on the unchecked conversion built for
converting between the prefix of 'Valid_Scalars and the view of its type
as returned by Validated_View for scalar types.  This is needed in order
to prevent GNAT-LLVM from masking out the bits outside the RM size of
the prefix, which is required here.

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

2020-06-05  Eric Botcazou  

gcc/ada/

* exp_attr.adb (Expand_N_Attribute_Reference) :
Set the No_Truncation flag on the unchecked conversion built for
scalar types.--- gcc/ada/exp_attr.adb
+++ gcc/ada/exp_attr.adb
@@ -7185,6 +7185,12 @@ package body Exp_Attr is
   Unchecked_Convert_To (Val_Typ, New_Copy_Tree (Pref)),
 Attribute_Name => Name_Valid);
 
+--  Required by LLVM although the sizes are the same???
+
+if Nkind (Prefix (Expr)) = N_Unchecked_Type_Conversion then
+   Set_No_Truncation (Prefix (Expr));
+end if;
+
  --  Validate the scalar components of an array by iterating over all
  --  dimensions of the array while checking individual components.
 



[Ada] Assertion_Policy (Ignore) ignores invariants

2020-06-05 Thread Pierre-Marie de Rodat
Previous check-in for this ticket was incomplete.  It did not properly
cover invariants inherited from one type to another.

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

2020-06-05  Bob Duff  

gcc/ada/

* einfo.adb, einfo.ads, exp_util.adb: Remove Invariants_Ignored
flag.
* sem_prag.adb (Invariant): Instead of setting a flag to be
checked elsewhere, remove the pragma as soon as it is analyzed
and checked for legality.--- gcc/ada/einfo.adb
+++ gcc/ada/einfo.adb
@@ -629,8 +629,8 @@ package body Einfo is
--Is_Activation_RecordFlag305
--Needs_Activation_Record Flag306
--Is_Loop_Parameter   Flag307
-   --Invariants_Ignored  Flag308
 
+   --(unused)Flag308
--(unused)Flag309
 
--  Note: Flag310-317 are defined in atree.ads/adb, but not yet in atree.h
@@ -2077,12 +2077,6 @@ package body Einfo is
   return Node21 (Id);
end Interface_Name;
 
-   function Invariants_Ignored (Id : E) return B is
-   begin
-  pragma Assert (Is_Type (Id));
-  return Flag308 (Id);
-   end Invariants_Ignored;
-
function Is_Abstract_Subprogram (Id : E) return B is
begin
   pragma Assert (Is_Overloadable (Id));
@@ -5284,12 +5278,6 @@ package body Einfo is
   Set_Node21 (Id, V);
end Set_Interface_Name;
 
-   procedure Set_Invariants_Ignored (Id : E; V : B := True) is
-   begin
-  pragma Assert (Is_Type (Id));
-  Set_Flag308 (Id, V);
-   end Set_Invariants_Ignored;
-
procedure Set_Is_Abstract_Subprogram (Id : E; V : B := True) is
begin
   pragma Assert (Is_Overloadable (Id));
@@ -9797,7 +9785,6 @@ package body Einfo is
   W ("In_Package_Body", Flag48  (Id));
   W ("In_Private_Part", Flag45  (Id));
   W ("In_Use",  Flag8   (Id));
-  W ("Invariants_Ignored",  Flag308 (Id));
   W ("Is_Abstract_Subprogram",  Flag19  (Id));
   W ("Is_Abstract_Type",Flag146 (Id));
   W ("Is_Access_Constant",  Flag69  (Id));

--- gcc/ada/einfo.ads
+++ gcc/ada/einfo.ads
@@ -2269,11 +2269,6 @@ package Einfo is
 --   implemented by a tagged type that are not already implemented by the
 --   ancestors (Ada 2005: AI-251).
 
---Invariants_Ignored (Flag308)
---   Defined on all types. Indicates whether the type declaration is in
---   a context where Assertion_Policy is Ignore, in which case no checks
---   (static or dynamic) must be generated for objects of the type.
-
 --Invariant_Procedure (synthesized)
 --   Defined in types and subtypes. Set for private types and their full
 --   views if one or more [class-wide] invariants apply to the type, or
@@ -7289,7 +7284,6 @@ package Einfo is
function Interface_Alias (Id : E) return E;
function Interface_Name  (Id : E) return N;
function Interfaces  (Id : E) return L;
-   function Invariants_Ignored  (Id : E) return B;
function Is_Abstract_Subprogram  (Id : E) return B;
function Is_Abstract_Type(Id : E) return B;
function Is_Access_Constant  (Id : E) return B;
@@ -7993,7 +7987,6 @@ package Einfo is
procedure Set_Interface_Alias (Id : E; V : E);
procedure Set_Interface_Name  (Id : E; V : N);
procedure Set_Interfaces  (Id : E; V : L);
-   procedure Set_Invariants_Ignored  (Id : E; V : B := True);
procedure Set_Is_Abstract_Subprogram  (Id : E; V : B := True);
procedure Set_Is_Abstract_Type(Id : E; V : B := True);
procedure Set_Is_Access_Constant  (Id : E; V : B := True);
@@ -8826,7 +8819,6 @@ package Einfo is
pragma Inline (Interface_Alias);
pragma Inline (Interface_Name);
pragma Inline (Interfaces);
-   pragma Inline (Invariants_Ignored);
pragma Inline (Is_Abstract_Subprogram);
pragma Inline (Is_Abstract_Type);
pragma Inline (Is_Access_Constant);
@@ -9364,7 +9356,6 @@ package Einfo is
pragma Inline (Set_Interface_Alias);
pragma Inline (Set_Interface_Name);
pragma Inline (Set_Interfaces);
-   pragma Inline (Set_Invariants_Ignored);
pragma Inline (Set_Is_Abstract_Subprogram);
pragma Inline (Set_Is_Abstract_Type);
pragma Inline (Set_Is_Access_Constant);

--- gcc/ada/exp_util.adb
+++ gcc/ada/exp_util.adb
@@ -9331,16 +9331,10 @@ package body Exp_Util is
   Proc_Id := Invariant_Procedure (Typ);
   pragma Assert (Present (Proc_Id));
 
-  --  Ignore the invariant if that policy is in effect
-
-  if Invariants_Ignored (Typ) then
- return Make_Null_Statement (Loc);
-  else
- return
-   Make_Procedure_Call_Statement (Loc,
- Name   => New_Occurrence_Of

[Ada] AI12-0207 Convention of anonymous access types

2020-06-05 Thread Pierre-Marie de Rodat
This AI was already implemented except for the case of array components
which is done here.

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

2020-06-05  Arnaud Charlet  

gcc/ada/

* sem_prag.adb (Set_Convention_From_Pragma): Set the convention
of anonymous access array components.--- gcc/ada/sem_prag.adb
+++ gcc/ada/sem_prag.adb
@@ -8020,26 +8020,38 @@ package body Sem_Prag is
 --  For the case of a record base type, also set the convention of
 --  any anonymous access types declared in the record which do not
 --  currently have a specified convention.
+--  Similarly for an array base type and anonymous access types
+--  components.
 
-if Is_Record_Type (E) and then Is_Base_Type (E) then
-   declare
-  Comp : Node_Id;
+if Is_Base_Type (E) then
+   if Is_Record_Type (E) then
+  declare
+ Comp : Node_Id;
 
-   begin
-  Comp := First_Component (E);
-  while Present (Comp) loop
- if Present (Etype (Comp))
-   and then Ekind_In (Etype (Comp),
-  E_Anonymous_Access_Type,
-  E_Anonymous_Access_Subprogram_Type)
-   and then not Has_Convention_Pragma (Comp)
- then
-Set_Convention (Comp, C);
- end if;
+  begin
+ Comp := First_Component (E);
+ while Present (Comp) loop
+if Present (Etype (Comp))
+  and then
+Ekind_In (Etype (Comp),
+  E_Anonymous_Access_Type,
+  E_Anonymous_Access_Subprogram_Type)
+  and then not Has_Convention_Pragma (Comp)
+then
+   Set_Convention (Comp, C);
+end if;
 
- Next_Component (Comp);
-  end loop;
-   end;
+Next_Component (Comp);
+ end loop;
+  end;
+
+   elsif Is_Array_Type (E)
+ and then Ekind_In (Component_Type (E),
+E_Anonymous_Access_Type,
+E_Anonymous_Access_Subprogram_Type)
+   then
+  Set_Convention (Designated_Type (Component_Type (E)), C);
+   end if;
 end if;
 
 --  Deal with incomplete/private type case, where underlying type



[Ada] AI12-0237 Getting the representation of an enumeration value

2020-06-05 Thread Pierre-Marie de Rodat
Attributes Enum_Rep/Enum_Val are now standard in Ada 202x, so adjust
their handling accordingly.

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

2020-06-05  Arnaud Charlet  

gcc/ada/

* sem_attr.ads (Attribute_Impl_Def): Remove Enum_Rep/Val.
* sem_attr.adb (Attribute_20): New, move Enum_Rep/Val here.
(Analyze_Attribute): Take Attribute_20 into account.--- gcc/ada/sem_attr.adb
+++ gcc/ada/sem_attr.adb
@@ -164,6 +164,15 @@ package body Sem_Attr is
   Attribute_Max_Alignment_For_Allocation => True,
   others => False);
 
+   --  The following array is the list of attributes defined in the Ada 2020
+   --  RM which are not defined in Ada 2012. These are recognized in Ada
+   --  95/2005/2012 modes, but are considered to be implementation defined.
+
+   Attribute_20 : constant Attribute_Class_Array := Attribute_Class_Array'(
+  Attribute_Enum_Rep |
+  Attribute_Enum_Val => True,
+  others => False);
+
--  The following array contains all attributes that imply a modification
--  of their prefixes or result in an access value. Such prefixes can be
--  considered as lvalues.
@@ -2867,12 +2876,14 @@ package body Sem_Attr is
   end if;
 
   --  Deal with Ada 2005 attributes that are implementation attributes
-  --  because they appear in a version of Ada before Ada 2005, and
-  --  similarly for Ada 2012 attributes appearing in an earlier version.
+  --  because they appear in a version of Ada before Ada 2005, ditto for
+  --  Ada 2012 and Ada 2020 attributes appearing in an earlier version.
 
   if (Attribute_05 (Attr_Id) and then Ada_Version < Ada_2005)
 or else
  (Attribute_12 (Attr_Id) and then Ada_Version < Ada_2012)
+or else
+ (Attribute_20 (Attr_Id) and then Ada_Version < Ada_2020)
   then
  Check_Restriction (No_Implementation_Attributes, N);
   end if;

--- gcc/ada/sem_attr.ads
+++ gcc/ada/sem_attr.ads
@@ -212,36 +212,6 @@ package Sem_Attr is
   --  value indicating whether or not the body of the designated library
   --  unit has been elaborated yet.
 
-  --
-  -- Enum_Rep --
-  --
-
-  Attribute_Enum_Rep => True,
-  --  For every enumeration subtype S, S'Enum_Rep denotes a function
-  --  with the following specification:
-  --
-  --function S'Enum_Rep (Arg : S'Base) return universal_integer;
-  --
-  --  The function returns the representation value for the given
-  --  enumeration value. This will be equal to the 'Pos value in the
-  --  absence of an enumeration representation clause. This is a static
-  --  attribute (i.e. the result is static if the argument is static).
-
-  --
-  -- Enum_Val --
-  --
-
-  Attribute_Enum_Val => True,
-  --  For every enumeration subtype S, S'Enum_Val denotes a function with
-  --  the following specification:
-  --
-  --function S'Enum_Val (Arg : universal_integer) return S'Base;
-  --
-  --  This function performs the inverse transformation to Enum_Rep. Given
-  --  a representation value for the type, it returns the corresponding
-  --  enumeration value. Constraint_Error is raised if no value of the
-  --  enumeration type corresponds to the given integer value.
-
   ---
   -- Finalization_Size --
   ---



[Ada] Add missing Global contract to Ada.Containers.Functional_Vectors

2020-06-05 Thread Pierre-Marie de Rodat
While annotating Ada.Containers.Functional_Vectors unit with
Global/Pre/Post contracts we omitted its First function. This was most
likely because it is an expression function and we though that Global
will be generated, while Pre/Post will be effectively provided by
inlining.

However, GNATprove still emits a warning on calls to First about
assuming Global to be null, just like it does for any predefined
subprogram without an explicit Global/Depends/Pure contracts.

There is no impact on compilation, so no test provided.

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

2020-06-05  Piotr Trojanek  

gcc/ada/

* libgnat/a-cofuve.ads (First): Add Global contract.--- gcc/ada/libgnat/a-cofuve.ads
+++ gcc/ada/libgnat/a-cofuve.ads
@@ -92,7 +92,8 @@ package Ada.Containers.Functional_Vectors with SPARK_Mode is
Length (Container));
pragma Annotate (GNATprove, Inline_For_Proof, Last);
 
-   function First return Extended_Index is (Index_Type'First);
+   function First return Extended_Index is (Index_Type'First) with
+ Global => null;
--  First index of a sequence
 




[Ada] Fix assertion failure on double rederivation of private type

2020-06-05 Thread Pierre-Marie de Rodat
As shown by the testcase, Build_Derived_Private_Type still does not
handle properly multiple rederivations of a private type initially
derived as a completion.

In order to address this, this changes factors out the retrieval of
the full and underlying full views of the parent type into an helper
function and uses it throughout the procedure.

It also deals with derivations from completions of derived private
types (as opposed to derivations from their private view).

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

2020-06-05  Eric Botcazou  

gcc/ada/

* sem_ch3.adb (Available_Full_View): New function returning
either the full or the underlying full view.
(Build_Full_Derivation): Add guard for the full view.
(Copy_And_Build): Retrieve the underlying full view, if any,
also if deriving a completion.
(Build_Derived_Private_Type): Use Available_Full_View throughout
to decide whether a full derivation must be done.--- gcc/ada/sem_ch3.adb
+++ gcc/ada/sem_ch3.adb
@@ -7612,6 +7612,10 @@ package body Sem_Ch3 is
   Full_Der  : Entity_Id   := New_Copy (Derived_Type);
   Full_P: Entity_Id;
 
+  function Available_Full_View (Typ : Entity_Id) return Entity_Id;
+  --  Return the Full_View or Underlying_Full_View of Typ, whichever is
+  --  present (they cannot be both present for the same type), or Empty.
+
   procedure Build_Full_Derivation;
   --  Build full derivation, i.e. derive from the full view
 
@@ -7619,6 +7623,32 @@ package body Sem_Ch3 is
   --  Copy derived type declaration, replace parent with its full view,
   --  and build derivation
 
+  -
+  -- Available_Full_View --
+  -
+
+  function Available_Full_View (Typ : Entity_Id) return Entity_Id is
+  begin
+ if Present (Full_View (Typ)) then
+return Full_View (Typ);
+
+ elsif Present (Underlying_Full_View (Typ)) then
+
+--  We should be called on a type with an underlying full view
+--  only by means of the recursive call made in Copy_And_Build
+--  through the first call to Build_Derived_Type, or else if
+--  the parent scope is being analyzed because we are deriving
+--  a completion.
+
+pragma Assert (Is_Completion or else In_Private_Part (Par_Scope));
+
+return Underlying_Full_View (Typ);
+
+ else
+return Empty;
+ end if;
+  end Available_Full_View;
+
   ---
   -- Build_Full_Derivation --
   ---
@@ -7638,7 +7668,9 @@ package body Sem_Ch3 is
  --  part of a child unit. In that case retrieve the full view of
  --  the parent momentarily.
 
- elsif not In_Same_Source_Unit (N, Parent_Type) then
+ elsif not In_Same_Source_Unit (N, Parent_Type)
+   and then Present (Full_View (Parent_Type))
+ then
 Full_P := Full_View (Parent_Type);
 Exchange_Declarations (Parent_Type);
 Copy_And_Build;
@@ -7674,11 +7706,13 @@ package body Sem_Ch3 is
  --  completion, i.e. to build the underlying full view of the type,
  --  then use this underlying full view. We cannot do that if this
  --  is not a completion, i.e. to build the full view of the type,
- --  because this would break the privacy status of the parent.
+ --  because this would break the privacy of the parent type, except
+ --  if the parent scope is being analyzed because we are deriving a
+ --  completion.
 
  if Is_Private_Type (Full_Parent)
and then Present (Underlying_Full_View (Full_Parent))
-   and then Is_Completion
+   and then (Is_Completion or else In_Private_Part (Par_Scope))
  then
 Full_Parent := Underlying_Full_View (Full_Parent);
  end if;
@@ -7929,9 +7963,7 @@ package body Sem_Ch3 is
  --  case (see point 5. of its head comment) since we build it for the
  --  derived subtype.
 
- if (Present (Full_View (Parent_Type))
- or else (Present (Underlying_Full_View (Parent_Type))
-   and then Is_Completion))
+ if Present (Available_Full_View (Parent_Type))
and then not Is_Itype (Derived_Type)
  then
 declare
@@ -7983,14 +8015,8 @@ package body Sem_Ch3 is
 end;
  end if;
 
-  elsif (Present (Full_View (Parent_Type))
-  and then
- Has_Discriminants (Full_View (Parent_Type)))
-or else (Present (Underlying_Full_View (Parent_Type))
-  and then
- Has_Discriminants (Underlying_Full_View (Parent_Type))
-  and then
- Is_Completion)
+  elsif Present (Available_Full_View (Parent_Type))
+and then Has_Discriminants (Ava

[Ada] Move routine for detecting special Text_IO packages from GNATprove

2020-06-05 Thread Pierre-Marie de Rodat
In GNATprove we were detecting special Text_IO packages by looking at
the Ada[_Wide[_Wide]]_Text_IO_Child subtypes provided by the frontend
Rtsfind spec. However, it seems more elegant to hide those subtypes in
the Rtsfind body and only expose a single query routine. This patch
implements this routine; another patch will move the subtype declaration
into body.

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

2020-06-05  Piotr Trojanek  

gcc/ada/

* rtsfind.ads, rtsfind.adb (Is_Text_IO_Special_Package): Moved
from the GNATprove backend to the frontend.--- gcc/ada/rtsfind.adb
+++ gcc/ada/rtsfind.adb
@@ -759,6 +759,37 @@ package body Rtsfind is
   return Present (E) and then E = Ent;
end Is_RTU;
 
+   
+   -- Is_Text_IO_Special_Package --
+   
+
+   function Is_Text_IO_Special_Package (E : Entity_Id) return Boolean is
+   begin
+  pragma Assert (Is_Package_Or_Generic_Package (E));
+
+  --  ??? detection with a scope climbing might be more efficient
+
+  for U in Ada_Text_IO_Child loop
+ if Is_RTU (E, U) then
+return True;
+ end if;
+  end loop;
+
+  for U in Ada_Wide_Text_IO_Child loop
+ if Is_RTU (E, U) then
+return True;
+ end if;
+  end loop;
+
+  for U in Ada_Wide_Wide_Text_IO_Child loop
+ if Is_RTU (E, U) then
+return True;
+ end if;
+  end loop;
+
+  return False;
+   end Is_Text_IO_Special_Package;
+
-
-- Is_Text_IO_Special_Unit --
-

--- gcc/ada/rtsfind.ads
+++ gcc/ada/rtsfind.ads
@@ -3188,6 +3188,12 @@ package Rtsfind is
--  Wide_Wide_Text_IO.xxx, where xxx is one of the subpackages of Text_IO
--  that is specially handled as described for Check_Text_IO_Special_Unit.
 
+   function Is_Text_IO_Special_Package (E : Entity_Id) return Boolean;
+   --  Return True iff E is one of the special generic Text_IO packages, which
+   --  Ada RM defines to be nested in Ada.Text_IO, but GNAT defines as its
+   --  private children. This is similar to Is_Text_IO_Special_Unit, but is
+   --  meant to be used on a fully resolved AST, especially in the backends.
+
function RTE (E : RE_Id) return Entity_Id;
--  Given the entity defined in the above tables, as identified by the
--  corresponding value in the RE_Id enumeration type, returns the Id of the



[Ada] Put_Image attribute

2020-06-05 Thread Pierre-Marie de Rodat
Misc cleanup in preparation for further work on Put_Image and Image.
Mostly removal of redundant or obvious comments.

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

2020-06-05  Bob Duff  

gcc/ada/

* exp_attr.adb, exp_ch11.adb, exp_imgv.adb, exp_tss.ads,
par-ch4.adb, sem_attr.adb, sem_util.ads: Misc cleanup.--- gcc/ada/exp_attr.adb
+++ gcc/ada/exp_attr.adb
@@ -3732,8 +3732,6 @@ package body Exp_Attr is
   -- Image --
   ---
 
-  --  Image attribute is handled in separate unit Exp_Imgv
-
   when Attribute_Image =>
 
  --  Leave attribute unexpanded in CodePeer mode: the gnat2scil
@@ -3743,7 +3741,7 @@ package body Exp_Attr is
 return;
  end if;
 
- Expand_Image_Attribute (N);
+ Exp_Imgv.Expand_Image_Attribute (N);
 
   -
   -- Img --
@@ -3752,7 +3750,7 @@ package body Exp_Attr is
   --  X'Img is expanded to typ'Image (X), where typ is the type of X
 
   when Attribute_Img =>
- Expand_Image_Attribute (N);
+ Exp_Imgv.Expand_Image_Attribute (N);
 
   ---
   -- Input --
@@ -7243,8 +7241,6 @@ package body Exp_Attr is
   -- Value --
   ---
 
-  --  Value attribute is handled in separate unit Exp_Imgv
-
   when Attribute_Value =>
  Exp_Imgv.Expand_Value_Attribute (N);
 
@@ -7264,8 +7260,6 @@ package body Exp_Attr is
   -- Wide_Image --
   
 
-  --  Wide_Image attribute is handled in separate unit Exp_Imgv
-
   when Attribute_Wide_Image =>
  --  Leave attribute unexpanded in CodePeer mode: the gnat2scil
  --  back-end knows how to handle this attribute directly.
@@ -7280,8 +7274,6 @@ package body Exp_Attr is
   -- Wide_Wide_Image --
   -
 
-  --  Wide_Wide_Image attribute is handled in separate unit Exp_Imgv
-
   when Attribute_Wide_Wide_Image =>
  --  Leave attribute unexpanded in CodePeer mode: the gnat2scil
  --  back-end knows how to handle this attribute directly.
@@ -7374,8 +7366,6 @@ package body Exp_Attr is
   -- Wide_Wide_Width --
   -
 
-  --  Wide_Wide_Width attribute is handled in separate unit Exp_Imgv
-
   when Attribute_Wide_Wide_Width =>
  Exp_Imgv.Expand_Width_Attribute (N, Wide_Wide);
 
@@ -7383,8 +7373,6 @@ package body Exp_Attr is
   -- Wide_Width --
   
 
-  --  Wide_Width attribute is handled in separate unit Exp_Imgv
-
   when Attribute_Wide_Width =>
  Exp_Imgv.Expand_Width_Attribute (N, Wide);
 
@@ -7392,8 +7380,6 @@ package body Exp_Attr is
   -- Width --
   ---
 
-  --  Width attribute is handled in separate unit Exp_Imgv
-
   when Attribute_Width =>
  Exp_Imgv.Expand_Width_Attribute (N, Normal);
 

--- gcc/ada/exp_ch11.adb
+++ gcc/ada/exp_ch11.adb
@@ -1505,7 +1505,7 @@ package body Exp_Ch11 is
  Actions => New_List (
Make_Simple_Return_Statement (Loc,
  Expression => New_Occurrence_Of (Standard_False, Loc))),
-  Expression => RCE));
+   Expression => RCE));
 
   else
  Rewrite (N,
@@ -1514,7 +1514,7 @@ package body Exp_Ch11 is
Make_Raise_Statement (Loc,
  Name   => Name (N),
  Expression => Expression (N))),
-  Expression => RCE));
+   Expression => RCE));
   end if;
 
   Analyze_And_Resolve (N, Typ);

--- gcc/ada/exp_imgv.adb
+++ gcc/ada/exp_imgv.adb
@@ -58,7 +58,7 @@ package body Exp_Imgv is
   Pref  : Entity_Id;
   Attr_Name : Name_Id;
   Str_Typ   : Entity_Id);
-   --  AI12-00124: Rewrite attribute 'Image when it is applied to an object
+   --  AI12-0124: Rewrite attribute 'Image when it is applied to an object
--  reference as an attribute applied to a type. N denotes the node to be
--  rewritten, Pref denotes the prefix of the 'Image attribute, and Name
--  and Str_Typ specify which specific string type and 'Image attribute to
@@ -263,7 +263,7 @@ package body Exp_Imgv is
--  tv = Long_Long_Integer?(Expr) [convert with no scaling]
--  pm = typ'Scale (typ = subtype of expression)
 
-   --  For enumeration types other than those declared packages Standard
+   --  For enumeration types other than those declared in package Standard
--  or System, Snn, Pnn, are expanded as above, but the call looks like:
 
--Image_Enumeration_NN (rt'Pos (X), Snn, Pnn, typS, typI'Address)
@@ -474,23 +474,24 @@ package body Exp_Imgv is
   if Is_Object_Image (Pref) then
  Rewrite_Object_Image (N, Pref, Name_Image, Standard_String);
  return;
+  end if;
+
+  Ptyp := Entity (Pref);
+  Rtyp := Root_Type (Ptyp);
 
   --  Enable speed-optimized expansion of user-defined enumeration types
   --  if we are compiling with optimizations enabled and enumeration type
  

[Ada] Do not create an empty list of nodes that confuses GNATprove

2020-06-05 Thread Pierre-Marie de Rodat
Frontend typically expands record aggregates to an N_Aggregate node with
Expressions field set to No_List; for example, in Step_8 of the
Sem_Aggr.Resolve_Record_Aggregate routine. In the GNATprove backend we
never traverse this field, but we have an assertion to confirm that the
Expressions field is indeed set to No_List.

However, record aggregates created in the Capture_Discriminants block of
the Sem_Aggr.Resolve_Record_Aggregate routine have their Expressions
field set to an empty list. This list is created by a call to New_List
but is never populated with any elements. Such an empty list is both
unnecessary and causes GNATprove to crash on its seemingly reasonable
assertion when processing this code:

   procedure Test is
  type Discriminated_Record (Discriminant : Boolean := False) is record
 case Discriminant is
when True =>
   Component : Integer;
when False =>
   null;
 end case;
  end record;

  type Enclosing_Record is record
 DR : Discriminated_Record;
  end record;

  ER : Enclosing_Record := (others => <>);
  --  The initialization expression is expanded into:
  --"(DR => (Discriminants => False))"
  --  and the inner aggregate had Expressions set to an empty list.

   begin
  null;
   end Test;

Also, this empty list seems to violate the description of N_Aggregate in
sinfo.ads, which says:

  --  Expressions (List1) (set to No_List if none or null record case)

and then

  --  In particular, for a record aggregate, the expressions
  --  field will be set if there are positional associations.

Aggregates created in Resolve_Record_Aggregate have no positional
associations, so according to the above comments, their Expressions
field should be set to No_List.

This patch doesn't seem to affect the compiler, as apparently it
doesn't care whether the Expressions field is No_List or an empty list.

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

2020-06-05  Piotr Trojanek  

gcc/ada/

* sem_aggr.adb (Resolve_Record_Aggregate): Create the
N_Aggregate node with its Expressions field set to No_List and
not to an empty list.--- gcc/ada/sem_aggr.adb
+++ gcc/ada/sem_aggr.adb
@@ -147,9 +147,10 @@ package body Sem_Aggr is
--
--  Once this new Component_Association_List is built and all the semantic
--  checks performed, the original aggregate subtree is replaced with the
-   --  new named record aggregate just built. Note that subtree substitution is
-   --  performed with Rewrite so as to be able to retrieve the original
-   --  aggregate.
+   --  new named record aggregate just built. This new record aggregate has no
+   --  positional associations, so its Expressions field is set to No_List.
+   --  Note that subtree substitution is performed with Rewrite so as to be
+   --  able to retrieve the original aggregate.
--
--  The aggregate subtree manipulation performed by Resolve_Record_Aggregate
--  yields the aggregate format expected by Gigi. Typically, this kind of
@@ -3990,7 +3991,7 @@ package body Sem_Aggr is
 
  begin
 if Is_Record_Type (T) and then Has_Discriminants (T) then
-   New_Aggr := Make_Aggregate (Loc, New_List, New_List);
+   New_Aggr := Make_Aggregate (Loc, No_List, New_List);
Set_Etype (New_Aggr, T);
 
Add_Association
@@ -5043,7 +5044,7 @@ package body Sem_Aggr is
 Expr : Node_Id;
 
  begin
-Expr := Make_Aggregate (Loc, New_List, New_List);
+Expr := Make_Aggregate (Loc, No_List, New_List);
 Set_Etype (Expr, Ctyp);
 
 --  If the enclosing type has discriminants, they have



[Ada] Rename parameter of routines in Checks

2020-06-05 Thread Pierre-Marie de Rodat
This renames the Ck_Node parameter of some routines in Checks to the
more consistent Expr, which is used and documented by other routines.

In order to avoid any shadowing, parameters of a few child procedures
are also renamed (although no actual shadowing would have occurred).

No functional changes.

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

2020-06-05  Eric Botcazou  

gcc/ada/

* checks.ads (Apply_Length_Check): Rename Ck_Node parameter to
Expr.
(Apply_Range_Check): Likewise.
(Get_Range_Checks): Likewise.
* checks.adb (Apply_Float_Conversion_Check): Likewise.
(Apply_Selected_Length_Checks): Likewise.
(Apply_Selected_Range_Checks): Likewise.
(Guard_Access): Likewise.
(Selected_Length_Checks): Likewise.  Also avoid shadowing in
child procedures.
(Selected_Range_Checks): Likewise.

patch.diff.gz
Description: application/gzip


[Ada] Optimize Normalize_Pathname

2020-06-05 Thread Pierre-Marie de Rodat
No need to get current directory if Directory parameter is absolute
pathname.  No need to convert Windows drive letter to upper case and
slash to backslash in Normalize_Pathname.Get_Directory on Windows
because it is alredy done in Normalize_Pathname body processing. Avoid
recursion together with repeat of Get_Current_Dir call.

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

2020-06-05  Dmitriy Anisimkov  

gcc/ada/

* libgnat/s-os_lib.adb (Is_Dirsep): Moved from Build_Path to
package level to reuse.
(Normalize_Pathname.Final_Value): Reduce 2 'if' statements to
one.
(Normalize_Pathname.Fill_Directory): New procedure instead of
function Get_Directory. Remove slash to backslash conversion and
drive letter uppercasing on Windows.--- gcc/ada/libgnat/s-os_lib.adb
+++ gcc/ada/libgnat/s-os_lib.adb
@@ -63,6 +63,11 @@ package body System.OS_Lib is
--  Mode = 1 - copy time stamps and read/write/execute attributes
--  Mode = 2 - copy read/write/execute attributes
 
+   function Is_Dirsep (C : Character) return Boolean;
+   pragma Inline (Is_Dirsep);
+   --  Returns True if C is a directory separator. On Windows we
+   --  accept both \ and / as a directory separator.
+
On_Windows : constant Boolean := Directory_Separator = '\';
--  An indication that we are on Windows. Used in Normalize_Pathname, to
--  deal with drive letters in the beginning of absolute paths.
@@ -336,22 +341,6 @@ package body System.OS_Lib is
   
 
   function Build_Path (Dir : String; File : String) return String is
- function Is_Dirsep (C : Character) return Boolean;
- pragma Inline (Is_Dirsep);
- --  Returns True if C is a directory separator. On Windows we
- --  handle both styles of directory separator.
-
- ---
- -- Is_Dirsep --
- ---
-
- function Is_Dirsep (C : Character) return Boolean is
- begin
-return C = Directory_Separator or else C = '/';
- end Is_Dirsep;
-
- --  Local variables
-
  Base_File_Ptr : Integer;
  --  The base file name is File (Base_File_Ptr + 1 .. File'Last)
 
@@ -1472,6 +1461,15 @@ package body System.OS_Lib is
   return Is_Absolute_Path (Name'Address, Name'Length) /= 0;
end Is_Absolute_Path;
 
+   ---
+   -- Is_Dirsep --
+   ---
+
+   function Is_Dirsep (C : Character) return Boolean is
+   begin
+  return C = Directory_Separator or else C = '/';
+   end Is_Dirsep;
+
--
-- Is_Directory --
--
@@ -2085,17 +2083,61 @@ package body System.OS_Lib is
 
   Fold_To_Lower_Case : constant Boolean :=
  not Case_Sensitive
-   and then Get_File_Names_Case_Sensitive = 0;
+ and then Get_File_Names_Case_Sensitive = 0;
+
+  Cur_Dir_Len : Natural  := 0;
+  End_Path: Natural  := Name'Length;
+  Last: Positive := 1;
+  Path_Buffer : String (1 .. End_Path + 2 * Max_Path + 4);
+  --  We need to potentially store in this buffer the following elements:
+  --  the path itself, the current directory if the path is relative,
+  --  and additional fragments up to Max_Path in length in case
+  --  there are any symlinks.
 
   function Final_Value (S : String) return String;
   --  Make final adjustment to the returned string. This function strips
   --  trailing directory separators, and folds returned string to lower
   --  case if required.
 
-  function Get_Directory  (Dir : String) return String;
-  --  If Dir is not empty, return it, adding a directory separator
-  --  if not already present, otherwise return current working directory
-  --  with terminating directory separator.
+  procedure Fill_Directory (Drive_Only : Boolean := False);
+  --  Fill Cur_Dir and Cur_Dir_Len with Directory and ending directory
+  --  separator or with current directory if Directory is not defined.
+  --  If Drive_Only is True takes only Drive letter with colon and
+  --  directory separator from Directory parameter or from current
+  --  directory if Directory parameter is empty.
+
+  function Is_With_Drive (Name : String) return Boolean;
+  pragma Inline (Is_With_Drive);
+  --  Returns True only if the Name is including a drive
+  --  letter at start.
+
+  function Missed_Drive_Letter (Name : String) return Boolean;
+  --  Missed drive letter at start of the normalized pathname
+
+  ---
+  -- Is_With_Drive --
+  ---
+
+  function Is_With_Drive (Name : String) return Boolean is
+  begin
+ return Name'Length > 1
+   and then Name (Name'First + 1) = ':'
+   and then (Name (Name'First) in 'a' .. 'z'
+ or else Name (Name'First) in 'A' .. 'Z

[Ada] Support 'Reduce under -gnatX

2020-06-05 Thread Pierre-Marie de Rodat
There are still ongoing discussions about the usefulness of this as a
language attribute, so keep it under -gnatX for now.

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

2020-06-05  Arnaud Charlet  

gcc/ada/

* scng.adb (Scan): Fix typo to take into account all future
versions of Ada.
* sem_attr.ads (Attribute_Impl_Def): Add Attribute_Reduce for
now.
* sem_attr.adb (Analyze_Attribute): Only allow 'Reduce under
-gnatX.
* snames.ads-tmpl (Name_Reduce): Update comment.--- gcc/ada/scng.adb
+++ gcc/ada/scng.adb
@@ -1701,7 +1701,7 @@ package body Scng is
 if Source (Scan_Ptr + 1) = '"' then
goto Scan_Wide_Character;
 
-elsif Ada_Version = Ada_2020 then
+elsif Ada_Version >= Ada_2020 then
Scan_Ptr := Scan_Ptr + 1;
Token := Tok_Left_Bracket;
return;

--- gcc/ada/sem_attr.adb
+++ gcc/ada/sem_attr.adb
@@ -5572,6 +5572,11 @@ package body Sem_Attr is
   when Attribute_Reduce =>
  Check_E2;
 
+ if not Extensions_Allowed then
+Error_Attr
+  ("% attribute only supported under -gnatX", P);
+ end if;
+
  declare
 Stream : constant Node_Id := Prefix (N);
 Typ: Entity_Id;

--- gcc/ada/sem_attr.ads
+++ gcc/ada/sem_attr.ads
@@ -397,6 +397,13 @@ package Sem_Attr is
   --  as Range applied to the array itself. The result is of type universal
   --  integer.
 
+  
+  -- Reduce --
+  
+
+  Attribute_Reduce => True,
+  --  See AI12-0262-1
+
   -
   -- Ref --
   -

--- gcc/ada/snames.ads-tmpl
+++ gcc/ada/snames.ads-tmpl
@@ -976,7 +976,7 @@ package Snames is
Name_Priority   : constant Name_Id := N + $; -- Ada 05
Name_Range  : constant Name_Id := N + $;
Name_Range_Length   : constant Name_Id := N + $; -- GNAT
-   Name_Reduce : constant Name_Id := N + $;
+   Name_Reduce : constant Name_Id := N + $; -- GNAT
Name_Ref: constant Name_Id := N + $; -- GNAT
Name_Restriction_Set: constant Name_Id := N + $; -- GNAT
Name_Result : constant Name_Id := N + $; -- GNAT



[Ada] Fix punctuation in description of Enum_Rep attribute

2020-06-05 Thread Pierre-Marie de Rodat
Style guides might disagree whether "i.e." should be followed by a
comma, but certainly it should not be followed by a comma and a colon.
Also, this colon was inconsistent with how the same phrase is punctuated
when describing Enum_Val.

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

2020-06-05  Piotr Trojanek  

gcc/ada/

* doc/gnat_rm/implementation_defined_attributes.rst (Enum_Rep):
Remove extra colon.
* gnat_rm.texi: Regenerate.--- gcc/ada/doc/gnat_rm/implementation_defined_attributes.rst
+++ gcc/ada/doc/gnat_rm/implementation_defined_attributes.rst
@@ -353,7 +353,7 @@ enumeration literal or object.
 The function returns the representation value for the given enumeration
 value.  This will be equal to value of the ``Pos`` attribute in the
 absence of an enumeration representation clause.  This is a static
-attribute (i.e.,:the result is static if the argument is static).
+attribute (i.e., the result is static if the argument is static).
 
 ``S'Enum_Rep`` can also be used with integer types and objects,
 in which case it simply returns the integer value.  The reason for this

--- gcc/ada/gnat_rm.texi
+++ gcc/ada/gnat_rm.texi
@@ -21,7 +21,7 @@
 
 @copying
 @quotation
-GNAT Reference Manual , May 04, 2020
+GNAT Reference Manual , May 05, 2020
 
 AdaCore
 
@@ -10469,7 +10469,7 @@ enumeration literal or object.
 The function returns the representation value for the given enumeration
 value.  This will be equal to value of the @code{Pos} attribute in the
 absence of an enumeration representation clause.  This is a static
-attribute (i.e.,:the result is static if the argument is static).
+attribute (i.e., the result is static if the argument is static).
 
 @code{S'Enum_Rep} can also be used with integer types and objects,
 in which case it simply returns the integer value.  The reason for this



[Ada] Fix incorrect initialization for array of non-standard enumeration type

2020-06-05 Thread Pierre-Marie de Rodat
This prevents the compiler from generating an incorrect call to a
memset primitive for the initialization of an array, whose component
type is an enumeration type with a non-standard representation, by
means of an aggregate with a single Others choice.

The predicate Aggr_Assignment_OK_For_Backend is supposed to filter
out the unsuitable values for the single choice in the aggregate,
but it uses Expr_Value to obtain the equivalent integer value, which
doesn't work for enumeration types with non-standard representation.

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

2020-06-05  Eric Botcazou  

gcc/ada/

* exp_aggr.adb (Aggr_Assignment_OK_For_Backend): Use
Expr_Rep_Value instead of Expr_Value to obtain the equivalent
integer value.
* sem_eval.ads (Expr_Value): Document more supported cases.
* sem_eval.adb (Expr_Rep_Value): Copy missing cases from
Exp_Value.--- gcc/ada/exp_aggr.adb
+++ gcc/ada/exp_aggr.adb
@@ -5390,9 +5390,10 @@ package body Exp_Aggr is
 return Expr_Value_R (Expr) = Ureal_0;
  end if;
 
- --  For other types, we can look into the value as an integer
+ --  For other types, we can look into the value as an integer, which
+ --  means the representation value for enumeration literals.
 
- Value := Expr_Value (Expr);
+ Value := Expr_Rep_Value (Expr);
 
  if Has_Biased_Representation (Ctyp) then
 Value := Value - Expr_Value (Type_Low_Bound (Ctyp));

--- gcc/ada/sem_eval.adb
+++ gcc/ada/sem_eval.adb
@@ -4203,10 +4203,16 @@ package body Sem_Eval is
  pragma Assert (Is_Fixed_Point_Type (Underlying_Type (Etype (N;
  return Corresponding_Integer_Value (N);
 
-  --  Otherwise must be character literal
+  --  The NULL access value
 
-  else
- pragma Assert (Kind = N_Character_Literal);
+  elsif Kind = N_Null then
+ pragma Assert (Is_Access_Type (Underlying_Type (Etype (N)))
+   or else Error_Posted (N));
+ return Uint_0;
+
+  --  Character literal
+
+  elsif Kind = N_Character_Literal then
  Ent := Entity (N);
 
  --  Since Character literals of type Standard.Character don't have any
@@ -4220,6 +4226,15 @@ package body Sem_Eval is
  else
 return Enumeration_Rep (Ent);
  end if;
+
+  --  Unchecked conversion, which can come from System'To_Address (X)
+  --  where X is a static integer expression. Recursively evaluate X.
+
+  elsif Kind = N_Unchecked_Type_Conversion then
+ return Expr_Rep_Value (Expression (N));
+
+  else
+ raise Program_Error;
   end if;
end Expr_Rep_Value;
 

--- gcc/ada/sem_eval.ads
+++ gcc/ada/sem_eval.ads
@@ -276,7 +276,9 @@ package Sem_Eval is
--  or character literals. In the latter two cases, the value returned is
--  the Pos value in the relevant enumeration type. It can also be used for
--  fixed-point values, in which case it returns the corresponding integer
-   --  value. It cannot be used for floating-point values.
+   --  value, but it cannot be used for floating-point values. Finally, it can
+   --  also be used for the Null access value, as well as for the result of an
+   --  unchecked conversion of the aforementioned handled values.
 
function Expr_Value_E (N : Node_Id) return Entity_Id;
--  Returns the folded value of the expression. This function is called in



[Ada] Add note about gnatcov reliance on thunk names

2020-06-05 Thread Pierre-Marie de Rodat
Add a note indicating that the names generated for interface thunks
should not be changed without reflecting the change in gnatcoverage, as
it relies on that information to exclude thunks from source coverage.

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

2020-06-05  Thomas Quinot  

gcc/ada/

* exp_disp.adb (Expand_Interface_Thunk): Add comment about
gnatcov reliance on specific name used for thunks.--- gcc/ada/exp_disp.adb
+++ gcc/ada/exp_disp.adb
@@ -2137,6 +2137,11 @@ package body Exp_Disp is
   end loop;
 
   Thunk_Id := Make_Temporary (Loc, 'T');
+
+  --  Note: any change to this symbol name needs to be coordinated
+  --  with GNATcoverage, as that tool relies on it to identify
+  --  thunks and exclude them from source coverage analysis.
+
   Set_Ekind (Thunk_Id, Ekind (Prim));
   Set_Is_Thunk (Thunk_Id);
   Set_Convention (Thunk_Id, Convention (Prim));



[Ada] Simplify iteration over components

2020-06-05 Thread Pierre-Marie de Rodat
Instead of iterating with First_Entity/Next_Entity and then detecting
components with Ekind, it feels simpler to iterate with First_Component/
Next_Component.

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

2020-06-05  Piotr Trojanek  

gcc/ada/

* einfo.adb: Minor reformatting.
* sem_util.adb (Has_Full_Default_Initialization,
Is_Partially_Initialized_Type, Caller_Known_Size_Record,
Large_Max_Size_Mutable): Iterate with
First_Component/Next_Component; rename Ent to Comp.--- gcc/ada/einfo.adb
+++ gcc/ada/einfo.adb
@@ -9599,7 +9599,7 @@ package body Einfo is
 return Empty;
  end if;
 
-  --  For non-incomplete, non-private types, return the type itself Also
+  --  For non-incomplete, non-private types, return the type itself. Also
   --  for entities that are not types at all return the entity itself.
 
   else

--- gcc/ada/sem_util.adb
+++ gcc/ada/sem_util.adb
@@ -11288,17 +11288,16 @@ package body Sem_Util is
  --  Inspect all entities defined in the scope of the type, looking for
  --  uninitialized components.
 
- Comp := First_Entity (Typ);
+ Comp := First_Component (Typ);
  while Present (Comp) loop
-if Ekind (Comp) = E_Component
-  and then Comes_From_Source (Comp)
+if Comes_From_Source (Comp)
   and then No (Expression (Parent (Comp)))
   and then not Has_Full_Default_Initialization (Etype (Comp))
 then
return False;
 end if;
 
-Next_Entity (Comp);
+Next_Component (Comp);
  end loop;
 
  --  Ensure that the parent type of a type extension is fully default
@@ -16966,7 +16965,7 @@ package body Sem_Util is
 
  else
 declare
-   Ent : Entity_Id;
+   Comp : Entity_Id;
 
Component_Present : Boolean := False;
--  Set True if at least one component is present. If no
@@ -16976,30 +16975,28 @@ package body Sem_Util is
 begin
--  Loop through components
 
-   Ent := First_Entity (Typ);
-   while Present (Ent) loop
-  if Ekind (Ent) = E_Component then
- Component_Present := True;
+   Comp := First_Component (Typ);
+   while Present (Comp) loop
+  Component_Present := True;
 
- --  If a component has an initialization expression then
- --  the enclosing record type is partially initialized
+  --  If a component has an initialization expression then the
+  --  enclosing record type is partially initialized
 
- if Present (Parent (Ent))
-   and then Present (Expression (Parent (Ent)))
- then
-return True;
+  if Present (Parent (Comp))
+and then Present (Expression (Parent (Comp)))
+  then
+ return True;
 
- --  If a component is of a type which is itself partially
- --  initialized, then the enclosing record type is also.
+  --  If a component is of a type which is itself partially
+  --  initialized, then the enclosing record type is also.
 
- elsif Is_Partially_Initialized_Type
- (Etype (Ent), Include_Implicit)
- then
-return True;
- end if;
+  elsif Is_Partially_Initialized_Type
+  (Etype (Comp), Include_Implicit)
+  then
+ return True;
   end if;
 
-  Next_Entity (Ent);
+  Next_Component (Comp);
end loop;
 
--  No initialized components found. If we found any components
@@ -22067,36 +22064,34 @@ package body Sem_Util is
 Comp : Entity_Id;
 
  begin
-Comp := First_Entity (Typ);
+Comp := First_Component (Typ);
 while Present (Comp) loop
 
--  Only look at E_Component entities. No need to look at
--  E_Discriminant entities, and we must ignore internal
--  subtypes generated for constrained components.
 
-   if Ekind (Comp) = E_Component then
-  declare
- Comp_Type : constant Entity_Id :=
-   Underlying_Type (Etype (Comp));
+   declare
+  Comp_Type : constant Entity_Id :=
+Underlying_Type (Etype (Comp));
 
-  begin
- if Is_Record_Type (Comp_Type)
-   or else
-Is_Protected_Type (Co

[Ada] Make the Has_Dynamic_Range_Check flag obsolete

2020-06-05 Thread Pierre-Marie de Rodat
This flag is set on N_Subtype_Declaration nodes and on all expression
nodes to prevent checks from being generated multiple times for the
same node.  It was probably deemed necessary because semantic analysis
and expansion for Ch3 tread on each other's toes and can generate the
same check twice, in particular through Process_Range_Expr_In_Decl.

However its usage is awkward and, in particular, it is also set on
N_Subtype_Declaration nodes, which causes Analyze_Subtype_Declaration
to do a little dance around it so as to be able to generate the checks
required for declarations of array subtypes with multiple dimensions.

It turns out that preventing the front-end from generating or inserting
the duplicate checks beforehand is straightforward and requires only a
couple of adjustments in Exp_Ch3 and Sem_Ch3.  The patch does that and
also adds an assertion that a duplicate check is never avoided anymore
by means of the flag; it's the last step before the complete removal.

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

2020-06-05  Eric Botcazou  

gcc/ada/

* atree.adb (New_Copy): Clear Has_Dynamic_Range_Check on
subexpression nodes.
* checks.adb (Append_Range_Checks): Assert that the node
doesn't have the Has_Dynamic_Range_Check flag set.
(Insert_Range_Checks): Likewise.
* exp_ch3.adb (Expand_N_Subtype_Indication): Do not apply
range checks for a full type or object declaration.
* sem_ch3.ads: Move with and use clauses for Nlists to...
(Process_Range_Expr_In_Decl): Change default to No_List for
the Check_List parameter.
* sem_ch3.adb: ...here.
(Process_Range_Expr_In_Decl): Likewise.  When the insertion
node is a declaration, only insert on the list if is present
when the declaration involves discriminants, and only insert
on the node when there is no list otherwise.--- gcc/ada/atree.adb
+++ gcc/ada/atree.adb
@@ -1659,6 +1659,12 @@ package body Atree is
  Nodes.Table (New_Id).Rewrite_Ins := False;
  pragma Debug (New_Node_Debugging_Output (New_Id));
 
+ --  Clear Has_Dynamic_Range_Check since it doesn't apply anymore
+
+ if Nkind (Source) in N_Subexpr then
+Set_Has_Dynamic_Range_Check (New_Id, False);
+ end if;
+
  --  Clear Is_Overloaded since we cannot have semantic interpretations
  --  of this new node.
 

--- gcc/ada/checks.adb
+++ gcc/ada/checks.adb
@@ -514,7 +514,11 @@ package body Checks is
  if Nkind (Checks (J)) = N_Raise_Constraint_Error
and then Present (Condition (Checks (J)))
  then
-if not Has_Dynamic_Range_Check (Internal_Flag_Node) then
+if Has_Dynamic_Range_Check (Internal_Flag_Node) then
+   pragma Assert (False);
+   null;
+
+else
Append_To (Stmts, Checks (J));
Set_Has_Dynamic_Range_Check (Internal_Flag_Node);
 end if;
@@ -7470,7 +7474,11 @@ package body Checks is
  if Nkind (Checks (J)) = N_Raise_Constraint_Error
and then Present (Condition (Checks (J)))
  then
-if not Has_Dynamic_Range_Check (Internal_Flag_Node) then
+if Has_Dynamic_Range_Check (Internal_Flag_Node) then
+   pragma Assert (False);
+   null;
+
+else
Check_Node := Checks (J);
Mark_Rewrite_Insertion (Check_Node);
 

--- gcc/ada/exp_ch3.adb
+++ gcc/ada/exp_ch3.adb
@@ -7294,10 +7294,7 @@ package body Exp_Ch3 is
-- Expand_N_Subtype_Indication --
-
 
-   --  Add a check on the range of the subtype. The static case is partially
-   --  duplicated by Process_Range_Expr_In_Decl in Sem_Ch3, but we still need
-   --  to check here for the static case in order to avoid generating
-   --  extraneous expanded code. Also deal with validity checking.
+   --  Add a check on the range of the subtype and deal with validity checking
 
procedure Expand_N_Subtype_Indication (N : Node_Id) is
   Ran : constant Node_Id   := Range_Expression (Constraint (N));
@@ -7308,7 +7305,12 @@ package body Exp_Ch3 is
  Validity_Check_Range (Range_Expression (Constraint (N)));
   end if;
 
-  if Nkind_In (Parent (N), N_Constrained_Array_Definition, N_Slice) then
+  --  Do not duplicate the work of Process_Range_Expr_In_Decl in Sem_Ch3
+
+  if Nkind_In (Parent (N), N_Constrained_Array_Definition, N_Slice)
+and then Nkind (Parent (Parent (N))) /= N_Full_Type_Declaration
+and then Nkind (Parent (Parent (N))) /= N_Object_Declaration
+  then
  Apply_Range_Check (Ran, Typ);
   end if;
end Expand_N_Subtype_Indication;

--- gcc/ada/sem_ch3.adb
+++ gcc/ada/sem_ch3.adb
@@ -45,6 +45,7 @@ with Layout;use Layout;
 with Lib;   use Lib;
 with Lib.Xref;  use Lib.Xref;
 with Namet; use Namet;
+with Nlists;use Nlists;
 with

[Ada] Spurious error on address clause in task body

2020-06-05 Thread Pierre-Marie de Rodat
Compiler rejects an aspect specification for Address on a local variable
in a task body, when the expression for the address is the address of a
previous local object in the same task body.

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

2020-06-05  Ed Schonberg  

gcc/ada/

* sem_ch9.adb, (Analyze_Task_Body): After analying the task
body, indicate that all local variables have no delayed aspects.
This prevents improper later calls to
Check_Aspect_At_End_Of_Declarations, that would happen when the
constructed task_procedure body (generated during expansion) is
analyzed. The legality of aspect specifications that may appear
on local declarations has already been established, and it is in
general not possible to recheck them properly during expansion,
when visibility may not be fully established.--- gcc/ada/sem_ch9.adb
+++ gcc/ada/sem_ch9.adb
@@ -2993,6 +2993,24 @@ package body Sem_Ch9 is
  else
 Set_First_Private_Entity (Spec_Id, First_Entity (Spec_Id));
  end if;
+
+ --  The entity list of the current scope now includes entities in
+ --  the spec as well as the body. Their declarations will become
+ --  part of the statement sequence of the task body procedure that
+ --  is built during expansion. Indicate that aspect specifications
+ --  for these entities need not be rechecked. The guards on
+ --  Check_Aspect_At_End_Of_Declarations are not sufficient to
+ --  suppress these checks, because the declarations come from source.
+
+ declare
+Priv : Entity_Id := First_Private_Entity (Spec_Id);
+
+ begin
+while Present (Priv) loop
+   Set_Has_Delayed_Aspects (Priv, False);
+   Next_Entity (Priv);
+end loop;
+ end;
   end if;
 
   --  Mark all handlers as not suitable for local raise optimization,



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

2020-06-05 Thread Tom Tromey
My earlier patch to add case handling to the spell checker caused a
Fortran regression.  I believe I must have misread the test results.

This patch fixes the problem by changing the cutoff.  I chose this
value because the previous patch effectively multiplied the result of
get_edit_distance by 2 (unless a case change is involved).

gcc/fortran/ChangeLog:

PR fortran/95509
* misc.c (gfc_closest_fuzzy_match):
---
 gcc/fortran/misc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/fortran/misc.c b/gcc/fortran/misc.c
index 0fc25df8a22..46c6277c2b9 100644
--- a/gcc/fortran/misc.c
+++ b/gcc/fortran/misc.c
@@ -397,7 +397,7 @@ gfc_closest_fuzzy_match (const char *typo, char 
**candidates)
  likely to be meaningless.  */
   if (best)
 {
-  unsigned int cutoff = MAX (tl, strlen (best)) / 2;
+  unsigned int cutoff = MAX (tl, strlen (best));
 
   if (best_distance > cutoff)
{
-- 
2.21.3



[PR51447] restore the global reg var before returning from main

2020-06-05 Thread Alexandre Oliva
The testcase for PR51447, on x86_64, uses rbx as a global register
variable for the global PTR variable.

A runtime system might legitimately hold in rbx a value expected to be
preserved across the call to main, but its use as a global register
variable stops main from preserving it.

We've observed failures of this test on x86_64-wrs-vxworks7r2, because
of this problem, and this patch fixes them.  I've also tested it on
x86_64-linux-gnu, -m64 and -m32.  Ok to install?

Since main is not supposed to be callable, I suppose we might instead
prevent global register variables from affecting the registers saved or
restored by main, but I don't have a patch for that.  I could give it a
shot, if there's consensus that that would be a better fix.


for  gcc/testsuite/ChangeLog

PR rtl-optimization/51447
* gcc.c-torture/execute/pr51447.c (main): Preserve call-saved
register.
---
 gcc/testsuite/gcc.c-torture/execute/pr51447.c |6 ++
 1 file changed, 6 insertions(+)

diff --git a/gcc/testsuite/gcc.c-torture/execute/pr51447.c 
b/gcc/testsuite/gcc.c-torture/execute/pr51447.c
index 887ddb7..1d00953 100644
--- a/gcc/testsuite/gcc.c-torture/execute/pr51447.c
+++ b/gcc/testsuite/gcc.c-torture/execute/pr51447.c
@@ -14,6 +14,9 @@ int
 main (void)
 {
   __label__ nonlocal_lab;
+#ifdef __x86_64__
+  void *save = ptr;
+#endif
   __attribute__((noinline, noclone)) void
 bar (void *func)
   {
@@ -25,5 +28,8 @@ main (void)
 nonlocal_lab:
   if (ptr != &&nonlocal_lab)
 abort ();
+#ifdef __x86_64__
+  ptr = save; /* Restore the call-saved register.  */
+#endif
   return 0;
 }

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


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

2020-06-05 Thread Joseph Myers
This patch is OK.

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


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

2020-06-05 Thread Thomas Koenig via Gcc-patches

Hi Tom,


My earlier patch to add case handling to the spell checker caused a
Fortran regression.  I believe I must have misread the test results.

This patch fixes the problem by changing the cutoff.  I chose this
value because the previous patch effectively multiplied the result of
get_edit_distance by 2 (unless a case change is involved).


OK.  Thanks for the patch!

Regards

Thomas


Re: [PATCH] Enable CET in cross compiler if possible

2020-06-05 Thread H.J. Lu via Gcc-patches
On Tue, May 12, 2020 at 10:28 AM Jeff Law  wrote:
>
> On Fri, 2020-05-08 at 06:11 -0700, H.J. Lu via Gcc-patches wrote:
> > Don't perform CET run-time check for host when cross compiling.  Instead,
> > enable CET in cross compiler if possible so that it will run on both CET
> > and non-CET hosts.
> >
> > config/
> >
> >   PR bootstrap/94998
> >   * cet.m4 (GCC_CET_HOST_FLAGS): Enable CET in cross compiler if
> >   possible.
> >
> > libiberty/
> >
> >   PR bootstrap/94998
> >   * configure: Regenerated.
> >
> > lto-plugin/
> >
> >   PR bootstrap/94998
> >   * configure: Regenerated.
> OK
> jeff

OK for backport to GCC 10?

Thanks.

-- 
H.J.


[committed] d: Merge upstream dmd 56f0a65c4.

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

This patch merges the D front-end implementation with upstream dmd
56f0a65c4.  Updates the Target interface, removing static from all
members, so all field accesses and member function calls go through a
a single global 'target'.  Information relating to extern ABI are now
in TargetC, TargetCPP, and TargetObjC for each supported language
respectively.

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

Regards
Iain.


gcc/d/ChangeLog:

* dmd/MERGE: Merge upstream dmd 56f0a65c4.
* d-builtins.cc (build_frontend_type): Remove static.
(d_build_builtins_module): Use target.va_listType() to get front-end
type for va_list.
(d_init_builtins): Move creation of va_list to Target::va_listType.
* d-codegen.cc (build_interface_binfo): Use new target global.
(build_vindex_ref): Likewise.
(identity_compare_p): Likewise.
* d-ctfloat.cc (CTFloat::parse): Likewise.
* d-lang.cc (d_init): Likewise.
* d-port.cc (Port::isFloat32LiteralOutOfRange): Likewise.
(Port::isFloat64LiteralOutOfRange): Likewise.
* d-target.cc (define_float_constants): Initialize constants through a
reference, instead of setting globals.
(Target::_init): Initialize new fields instead of setting globals.
(Target::va_listType): Build front-end type from va_list_type_node.
(Target::toCppMangle): Renamed to ...
(TargetCPP::toMangle): ... this.
(Target::cppTypeInfoMangle): Renamed to ...
(TargetCPP::typeInfoMangle): ... this.
(Target::cppTypeMangle): Renamed to ...
(TargetCPP::typeMangle): this.
(Target::cppParameterType): Renamed to ...
(TargetCPP::parameterType): ... this.  Use target.va_listType() to get
front-end type for va_list.
(Target::cppFundamentalType): Renamed to ...
(TargetCPP::fundamentalType): ... this.
* d-tree.h (build_frontend_type): Declare.
* decl.cc (base_vtable_offset): Use new target global.
* typeinfo.cc (layout_classinfo_interfaces): Likewise.
(layout_cpp_typeinfo): Likewise.
* types.cc (valist_array_p): Use target.va_listType() to get front-end
type for va_list.
(layout_aggregate_type): Use new target global.
---
 gcc/d/d-builtins.cc   |  25 ++-
 gcc/d/d-codegen.cc|   6 +-
 gcc/d/d-ctfloat.cc|   2 +-
 gcc/d/d-lang.cc   |   2 +-
 gcc/d/d-port.cc   |   4 +-
 gcc/d/d-target.cc | 136 ++
 gcc/d/d-tree.h|   1 +
 gcc/d/decl.cc |   6 +-
 gcc/d/dmd/MERGE   |   2 +-
 gcc/d/dmd/attrib.c|   2 +-
 gcc/d/dmd/constfold.c |   2 +-
 gcc/d/dmd/cppmangle.c |  14 ++--
 gcc/d/dmd/dclass.c|  12 ++--
 gcc/d/dmd/declaration.c   |   4 +-
 gcc/d/dmd/dmangle.c   |   2 +-
 gcc/d/dmd/dstruct.c   |   4 +-
 gcc/d/dmd/expression.c|   6 +-
 gcc/d/dmd/expressionsem.c |  42 ++--
 gcc/d/dmd/func.c  |   4 +-
 gcc/d/dmd/hdrgen.c|   8 +--
 gcc/d/dmd/mtype.c | 112 ++-
 gcc/d/dmd/mtype.h |   4 --
 gcc/d/dmd/safe.c  |   4 +-
 gcc/d/dmd/statementsem.c  |  10 +--
 gcc/d/dmd/target.h| 112 ---
 gcc/d/typeinfo.cc |   6 +-
 gcc/d/types.cc|   7 +-
 27 files changed, 269 insertions(+), 270 deletions(-)

diff --git a/gcc/d/d-builtins.cc b/gcc/d/d-builtins.cc
index 61014cbea51..cbc74558106 100644
--- a/gcc/d/d-builtins.cc
+++ b/gcc/d/d-builtins.cc
@@ -27,6 +27,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "dmd/identifier.h"
 #include "dmd/module.h"
 #include "dmd/mtype.h"
+#include "dmd/target.h"
 
 #include "tree.h"
 #include "fold-const.h"
@@ -67,7 +68,7 @@ static vec builtin_converted_decls;
as casting from `C char' to `D char', which also means that `char *`
needs to be specially handled.  */
 
-static Type *
+Type *
 build_frontend_type (tree type)
 {
   Type *dtype;
@@ -598,14 +599,12 @@ d_build_builtins_module (Module *m)
}
 }
 
-  /* va_list should already be built, so no need to convert to D type again.  
*/
-  StructDeclaration *sd = (Type::tvalist->ty == Tstruct)
-? ((TypeStruct *) Type::tvalist)->sym : NULL;
+  /* Expose target-specific va_list type.  */
+  Type *tvalist = target.va_listType (Loc (), NULL);
+  StructDeclaration *sd = (tvalist->ty == Tstruct)
+? ((TypeStruct *) tvalist)->sym : NULL;
   if (sd == NULL || !sd->isAnonymous ())
-{
-  members->push (build_alias_declaration ("__builtin_va_list",
- Type::tvalist));
-}
+members->push (build_alias_declaration ("__builtin_va_list", tvalist));
   else
 {
   sd->ident = Identifier::idPool ("__builtin_va_list");
@@ -1152,16 +1151,6 @@ d_define_builtins (tree va_list_ref_type_node 
ATTRIBUTE_UNUSED,
 void
 d_init_builtins (vo

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

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

On 6/5/20 5:07 AM, Christophe Lyon wrote:

On Thu, 4 Jun 2020 at 18:59, Jeff Law via Gcc-patches
 wrote:


On Fri, 2020-05-15 at 17:31 -0600, Martin Sebor via Gcc-patches wrote:

Besides better buffer overflow checking, the new GCC 10 attribute
access also provides an opportunity to detect other kinds of bugs,
including uninitialized accesses by user-defined functions.
The attached patch implements this enhancement.

In addition, the closely related PR 10138 requests that GCC warn when
passing the address of an uninitialized variable to a const-qualified
pointer function argument.  Const pointers almost always imply a read
access of the object, so the patch also enables the warning in these
cases.  (There are situations when a const pointer doesn't imply it
and the warning takes care not to trigger overly enthusiastically.)
Since pointers often point to allocated objects it seemed natural
(and was surprisingly easy) to also detect uninitialized reads from
those.

For optimum results I slightly enhanced the detection of the referenced
decls and allocations.  In the process, I also noticed and fixed a small
bug in the existing code.   This helps both find more uninitialized
variables and reduce the rate of false positives in existing warnings.

Besides the usual GCC bootstrap/regtest I validated the changes by
building a number of packages, including Binutils/GDB, Glibc, and
the Linux kernel.  It found a decent number of likely bugs (about
half a doze by my count) but also triggered a few false positives.
One class of such problems was due to the kernel's function

__check_object_size (const void*, unsigned, bool)

used to validate the sizes of objects without ever accessing them.
To accommodate this idiom the patch adds a new  mode to attribute
access: none.

There's a minor typo in a comment within initialize_argument_information
s/accewss/access/

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


Hi,

This is causing a regression in fortran tests:
FAIL: gfortran.dg/goacc/uninit-use-device-clause.f95   -O   (test for
warnings, line 7)
FAIL: gfortran.dg/goacc/uninit-use-device-clause.f95   -O  (test for
excess errors)
Excess errors:
/gcc/testsuite/gfortran.dg/goacc/uninit-use-device-clause.f95:7:0:
Warning: 'p' is used uninitialized [-Wuninitialized]


That's probably because not all tests always run.  I grepped
the testsuite for the warning string, adjusted the remaining few that
still had the " in this function" part in them, and committed r11-999.

Double checking that commit, I also checked in a work-in-progress test
that I shouldn't have, so it's going to fail.

Martin



Christophe



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

jeff








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

2020-06-05 Thread Christophe Lyon via Gcc-patches
On Fri, 15 May 2020 at 23:54, Jason Merrill via Gcc-patches
 wrote:
>
> On 5/15/20 2:21 PM, Richard Biener wrote:
> > On May 15, 2020 7:30:38 PM GMT+02:00, Jason Merrill  
> > wrote:
> >> On Fri, May 15, 2020 at 3:15 AM Richard Biener
> >> 
> >> wrote:
> >>
>  +# When bootstrapping with GCC, build stage 1 in C++11 mode to
> >> ensure
> >>> that a
>  +# C++11 compiler can still start the bootstrap.
>    if test "$enable_bootstrap:$GXX" = "yes:yes"; then
>  +  CXX="$CXX -std=gnu++11"
> >>>
> >>> So I just spotted this - since we're requiring a ISO C++11 compiler 
> >>> shouldn't
> >>> we build stage1 with -std=c++11 rather than gnu++11 (whatever the detailed
> >>> differences are here)?  Also not sure what level of -pedantic we'd need to
> >>> avoid GNU extensions even with -std=c++11.  Of course there are (I hope)
> >>> a lot less GNU extensions for C++ than there were for C and hopefully
> >>> no extra in gnu++11 compared to gnu++98 which we checked previously.
>
> Building stage 1 with -std=c++11 -pedantic-errors works with 8.3.1, but
> fails pretty badly with 4.8.5,
>
> >> When we first moved to C++ I tried using -std=c++98, but there were too
> >> many places where we were assuming that if we're building with GCC, we can
> >> use GNU C extensions.
> >>
> >> I'll see if that's still a problem for -std=c++11.
>
> It doesn't seem to be, so I've made that change.
>
> >>> There also does not seem to be a configure check which may present
> >>> users with a more useful error message than later cryptic fail of build?
> >>> I suppose we cannot simply check __cplusplus for this, can we?  Do
> >>> other common host compilers need additional options to enable C++11?
> >>
> >> Good point, I'll add that.
>
> This patch uses a test from the autoconf archive to add any needed
> flags.  Tested with GCC 4.8.5 and clang 3.4.2 (with the above stage 1
> -std=c++11 disabled).
>
> >>> Should we try to second guess such flags via configury?  For example
> >>> GCC 4.8 defaults to -std=gnu++98 and the above only seems to apply
> >>> to the bootstrap case so GCC 4.8 cannot be used to build cross
> >> compilers
> >>> without adjusting CC and CXX?
> >>
> >> Older GCC is still GCC and will get the flag automatically.
> >
> > But yes:yes suggests that when building a cross compiler this doesn't apply?
>
> True, but the new test should cover that case.
>
> OK for trunk?

Hi,

After recent commits on trunk that make use of c++11 features, I'm now
unable to build cross-compilers (x86_64 host, arm/aarch64 targets)
/gcc/tree-ssa-math-opts.c:124:32: warning: non-static data member
initializers only available with -std=c++11 or -std=gnu++11
   basic_block bb = basic_block();

I am using gcc-5.4.0, and this happens because although gcc/configure correctly:
checking whether g++ supports C++11 features by default... no
checking whether g++ supports C++11 features with -std=gnu++11... yes
the actual CXXFLAGS used during the build are set by the toplevel Makefile,
which does not include -std=c++11 or -std=gnu++11

IIUC this patch forces c++11 when during bootstrap to make sure that
even with a compiler with more recent defaults, we can still build
with as low as c++11 requirements.
It is not meant to raise the default level of the build compiler. So
we probably want a proper fix to force/upgrade the minimal CXXFLAGS
required in gcc/configure (to c++11) and have the
top-level configure set it down to the minimal CXXFLAGS we want to
guarantee? Do we really want to make this distinction? Or is it OK to
always force c++11 ?

The immediate problem for me is that all my validations for trunk fail
during the build stage.

FWIW, I removed the check on enable_bootstrap so that -std=c++11 is
used for my non-bootstrap cross-compiler, and the build goes further,
but still fails when compiling arm-common.c:
from 
/home/christophe.lyon/src/GCC/sources/gcc-fsf-git/trunk/gcc/common/config/arm/arm-common.c:34:
/usr/lib/gcc/x86_64-linux-gnu/5/include/mm_malloc.h:42:12: error:
attempt to use poisoned "malloc"
 return malloc (size);

Christophe


Add 'libgomp.oacc-c-c++-common/struct-copyout-{1, 2}.c' (was: [PATCH 1/3] OpenACC "exit data" copyout for struct members)

2020-06-05 Thread Thomas Schwinge
Hi!

On 2020-06-04T06:40:53-0700, Julian Brown  wrote:
> [...] I've added a couple of new testcases to verify the behaviour
> (which fail without the patch).

Thanks.  Given the preparational patches pushed yesterday, these now PASS
already.

>   * testsuite/libgomp.oacc-c-c++-common/struct-copyout-1.c: New test.
>   * testsuite/libgomp.oacc-c-c++-common/struct-copyout-2.c: New test.

Pushed "Add 'libgomp.oacc-c-c++-common/struct-copyout-{1,2}.c'" to master
branch in commit 9643f5bbe237764cbefc975e934d1281f47ee3c2, and
releases/gcc-10 branch in commit
52d737058897eb438099b57234d41330147d0b6f, see attached.


Grüße
 Thomas


-
Mentor Graphics (Deutschland) GmbH, Arnulfstraße 201, 80634 München / Germany
Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Alexander 
Walter
>From 9643f5bbe237764cbefc975e934d1281f47ee3c2 Mon Sep 17 00:00:00 2001
From: Julian Brown 
Date: Thu, 4 Jun 2020 06:40:53 -0700
Subject: [PATCH] Add 'libgomp.oacc-c-c++-common/struct-copyout-{1,2}.c'

	libgomp/
	* testsuite/libgomp.oacc-c-c++-common/struct-copyout-1.c: New test.
	* testsuite/libgomp.oacc-c-c++-common/struct-copyout-2.c: New test.

Reviewed-by: Thomas Schwinge 
---
 .../struct-copyout-1.c| 38 
 .../struct-copyout-2.c| 44 +++
 2 files changed, 82 insertions(+)
 create mode 100644 libgomp/testsuite/libgomp.oacc-c-c++-common/struct-copyout-1.c
 create mode 100644 libgomp/testsuite/libgomp.oacc-c-c++-common/struct-copyout-2.c

diff --git a/libgomp/testsuite/libgomp.oacc-c-c++-common/struct-copyout-1.c b/libgomp/testsuite/libgomp.oacc-c-c++-common/struct-copyout-1.c
new file mode 100644
index ..b86f1c921a98
--- /dev/null
+++ b/libgomp/testsuite/libgomp.oacc-c-c++-common/struct-copyout-1.c
@@ -0,0 +1,38 @@
+#include 
+
+struct str1 {
+  int a;
+  int b;
+};
+
+struct str2 {
+  int c;
+  int d;
+  struct str1 s;
+};
+
+int
+main (int argc, char *argv[])
+{
+  struct str2 t;
+
+  t.c = 1;
+  t.d = 2;
+  t.s.a = 3;
+  t.s.b = 4;
+
+  #pragma acc enter data copyin(t.s)
+
+  #pragma acc serial present(t.s) /* { dg-warning "using vector_length \\(32\\), ignoring 1" "" { target openacc_nvidia_accel_selected } } */
+  {
+t.s.a = 5;
+t.s.b = 6;
+  }
+
+  #pragma acc exit data copyout(t.s)
+
+  assert (t.s.a == 5);
+  assert (t.s.b == 6);
+
+  return 0;
+}
diff --git a/libgomp/testsuite/libgomp.oacc-c-c++-common/struct-copyout-2.c b/libgomp/testsuite/libgomp.oacc-c-c++-common/struct-copyout-2.c
new file mode 100644
index ..4dd8a3a7e175
--- /dev/null
+++ b/libgomp/testsuite/libgomp.oacc-c-c++-common/struct-copyout-2.c
@@ -0,0 +1,44 @@
+#include 
+#include 
+
+struct str1 {
+  int a;
+  int b;
+  int *c;
+};
+
+#define N 1024
+
+int
+main (int argc, char *argv[])
+{
+  struct str1 s;
+
+  s.a = 1;
+  s.b = 2;
+  s.c = (int *) malloc (sizeof (int) * N);
+
+  for (int i = 0; i < N; i++)
+s.c[i] = i + 10;
+
+  #pragma acc enter data copyin(s.a, s.b, s.c[0:N])
+
+  #pragma acc serial present(s.a, s.b, s.c[0:N]) /* { dg-warning "using vector_length \\(32\\), ignoring 1" "" { target openacc_nvidia_accel_selected } } */
+  {
+s.a = 3;
+s.b = 4;
+for (int i = 0; i < N; i++)
+  s.c[i] = i + 20;
+  }
+
+  #pragma acc exit data copyout(s.a, s.b, s.c[0:N])
+
+  assert (s.a == 3);
+  assert (s.b == 4);
+  for (int i = 0; i < N; i++)
+assert (s.c[i] == i + 20);
+
+  free (s.c);
+
+  return 0;
+}
-- 
2.26.2

>From 52d737058897eb438099b57234d41330147d0b6f Mon Sep 17 00:00:00 2001
From: Julian Brown 
Date: Thu, 4 Jun 2020 06:40:53 -0700
Subject: [PATCH] Add 'libgomp.oacc-c-c++-common/struct-copyout-{1,2}.c'

	libgomp/
	* testsuite/libgomp.oacc-c-c++-common/struct-copyout-1.c: New test.
	* testsuite/libgomp.oacc-c-c++-common/struct-copyout-2.c: New test.

Reviewed-by: Thomas Schwinge 
(cherry picked from commit 9643f5bbe237764cbefc975e934d1281f47ee3c2)
---
 .../struct-copyout-1.c| 38 
 .../struct-copyout-2.c| 44 +++
 2 files changed, 82 insertions(+)
 create mode 100644 libgomp/testsuite/libgomp.oacc-c-c++-common/struct-copyout-1.c
 create mode 100644 libgomp/testsuite/libgomp.oacc-c-c++-common/struct-copyout-2.c

diff --git a/libgomp/testsuite/libgomp.oacc-c-c++-common/struct-copyout-1.c b/libgomp/testsuite/libgomp.oacc-c-c++-common/struct-copyout-1.c
new file mode 100644
index ..b86f1c921a98
--- /dev/null
+++ b/libgomp/testsuite/libgomp.oacc-c-c++-common/struct-copyout-1.c
@@ -0,0 +1,38 @@
+#include 
+
+struct str1 {
+  int a;
+  int b;
+};
+
+struct str2 {
+  int c;
+  int d;
+  struct str1 s;
+};
+
+int
+main (int argc, char *argv[])
+{
+  struct str2 t;
+
+  t.c = 1;
+  t.d = 2;
+  t.s.a = 3;
+  t.s.b = 4;
+
+  #pragma acc enter data copyin(t.s)
+
+  #pragma acc serial present(t.s) /* { dg-warning "using vector_length \\(32\\), ignoring 1" "" { target openacc_nvidia_accel_selected } } */
+

[OpenACC 'exit data'] Simplify 'GOMP_MAP_STRUCT' handling (was: [PATCH 07/13] OpenACC 2.6 deep copy: libgomp parts)

2020-06-05 Thread Thomas Schwinge
Hi!

On 2020-05-20T11:37:35+0200, I wrote:
> Moving this over, from the "Fix component mappings with derived types for
> OpenACC" thread,
> , where
> you propose to change this 'GOMP_MAP_STRUCT' handling code:
>
> On 2019-12-17T22:03:47-0800, Julian Brown  wrote:
>> --- a/libgomp/oacc-mem.c
>> +++ b/libgomp/oacc-mem.c
>
>> @@ -1075,6 +1119,39 @@ goacc_exit_data_internal (struct gomp_device_descr 
>> *acc_dev, size_t mapnum,
>>gomp_remove_var_async (acc_dev, n, aq);
>>}
>>break;
>> +
>> +case GOMP_MAP_STRUCT:
>> +  {
>> +int elems = sizes[i];
>> +for (int j = 1; j <= elems; j++)
>> +  {
>> +struct splay_tree_key_s k;
>> +k.host_start = (uintptr_t) hostaddrs[i + j];
>> +k.host_end = k.host_start + sizes[i + j];
>> +splay_tree_key str;
>> +str = splay_tree_lookup (&acc_dev->mem_map, &k);
>> +if (str)
>> +  {
>> +if (finalize)
>> +  {
>> +str->refcount -= str->virtual_refcount;
>> +str->virtual_refcount = 0;
>> +  }
>> +if (str->virtual_refcount > 0)
>> +  {
>> +str->refcount--;
>> +str->virtual_refcount--;
>> +  }
>> +else if (str->refcount > 0)
>> +  str->refcount--;
>> +if (str->refcount == 0)
>> +  gomp_remove_var_async (acc_dev, str, aq);
>> +  }
>> +  }
>> +i += elems;
>> +  }
>> +  break;
>> +
>>  default:
>>gomp_fatal (" goacc_exit_data_internal UNHANDLED kind 0x%.2x",
>>kind);
>
> ... into an "empty 'case GOMP_MAP_STRUCT:' as a no-op [...]

> I suppose we still need to unmap the "'GOMP_MAP_STRUCT' components", but
> can do that individually, outside of the 'GOMP_MAP_STRUCT' context.

You've answered my question with the
<6538c388d22e016bd01737e8c2f80437f432c70f.1591276990.git.julian@codesourcery.com">http://mid.mail-archive.com/6538c388d22e016bd01737e8c2f80437f432c70f.1591276990.git.julian@codesourcery.com>
patch submission; I've now pushed "[OpenACC 'exit data'] Simplify
'GOMP_MAP_STRUCT' handling" to master branch in commit
1809628fcff6f512206efd0ae03a3faccc4096f2, and releases/gcc-10 branch in
commit 96d8d068f3d6f3efebdca65f0a7b86e0609ee66f, see attached.


Grüße
 Thomas


-
Mentor Graphics (Deutschland) GmbH, Arnulfstraße 201, 80634 München / Germany
Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Alexander 
Walter
>From 1809628fcff6f512206efd0ae03a3faccc4096f2 Mon Sep 17 00:00:00 2001
From: Thomas Schwinge 
Date: Wed, 20 May 2020 10:53:33 +0200
Subject: [PATCH] [OpenACC 'exit data'] Simplify 'GOMP_MAP_STRUCT' handling

	libgomp/
	* oacc-mem.c (goacc_exit_data_internal) :
	Simplify.

Co-Authored-By: Julian Brown 
---
 libgomp/oacc-mem.c | 83 ++
 1 file changed, 3 insertions(+), 80 deletions(-)

diff --git a/libgomp/oacc-mem.c b/libgomp/oacc-mem.c
index 11419e692aa2..1e3685a073da 100644
--- a/libgomp/oacc-mem.c
+++ b/libgomp/oacc-mem.c
@@ -1180,86 +1180,9 @@ goacc_exit_data_internal (struct gomp_device_descr *acc_dev, size_t mapnum,
 	  break;
 
 	case GOMP_MAP_STRUCT:
-	  {
-	int elems = sizes[i];
-	for (int j = 1; j <= elems; j++)
-	  {
-		assert (i + j < mapnum);
-
-		kind = kinds[i + j] & 0xff;
-
-		finalize = false;
-		if (kind == GOMP_MAP_FORCE_FROM
-		|| kind == GOMP_MAP_DELETE
-		|| kind == GOMP_MAP_FORCE_DETACH)
-		  finalize = true;
-
-		copyfrom = false;
-		if (kind == GOMP_MAP_FROM
-		|| kind == GOMP_MAP_FORCE_FROM
-		|| kind == GOMP_MAP_ALWAYS_FROM)
-		  copyfrom = true;
-
-		struct splay_tree_key_s k;
-		k.host_start = (uintptr_t) hostaddrs[i + j];
-		k.host_end = k.host_start + sizes[i + j];
-		splay_tree_key str;
-		str = splay_tree_lookup (&acc_dev->mem_map, &k);
-		if (str)
-		  {
-		if (finalize)
-		  {
-			if (str->refcount != REFCOUNT_INFINITY)
-			  str->refcount -= str->virtual_refcount;
-			str->virtual_refcount = 0;
-		  }
-		if (str->virtual_refcount > 0)
-		  {
-			if (str->refcount != REFCOUNT_INFINITY)
-			  str->refcount--;
-			str->virtual_refcount--;
-		  }
-		else if (str->refcount > 0
-			 && str->refcount != REFCOUNT_INFINITY)
-		  str->refcount--;
-
-		if (copyfrom
-			&& (kind != GOMP_MAP_FROM || str->refcount == 0))
-		  gomp_copy_dev2host (acc_dev, aq, (void *) k.host_start,
-	  (void *) (str->tgt->tgt_start
-		+ str->tgt_offset
-		+ k.host_start
-		- str->host_start),
-	  k.host_end - k.host_start);
-
-		if (str->refcount == 0)
-		  {
-			if (aq)
-			  /* TODO We can't do the 'is_tgt_unmapped' checking --
-			 see the 'gomp_unref_tgt' comment in
-			

[OpenACC 'exit data'] Strip 'GOMP_MAP_STRUCT' mappings (was: [PATCH 07/13] OpenACC 2.6 deep copy: libgomp parts)

2020-06-05 Thread Thomas Schwinge
Hi!

On 2020-05-20T11:37:35+0200, I wrote:
> Moving this over, from the "Fix component mappings with derived types for
> OpenACC" thread,
> , where
> you propose to change this 'GOMP_MAP_STRUCT' handling code:
>
> On 2019-12-17T22:03:47-0800, Julian Brown  wrote:
>> --- a/libgomp/oacc-mem.c
>> +++ b/libgomp/oacc-mem.c
>
>> @@ -1075,6 +1119,39 @@ goacc_exit_data_internal (struct gomp_device_descr 
>> *acc_dev, size_t mapnum,
>>gomp_remove_var_async (acc_dev, n, aq);
>>}
>>break;
>> +
>> +case GOMP_MAP_STRUCT:
>> +  {
>> +int elems = sizes[i];
>> +for (int j = 1; j <= elems; j++)
>> +  {
>> +struct splay_tree_key_s k;
>> +k.host_start = (uintptr_t) hostaddrs[i + j];
>> +k.host_end = k.host_start + sizes[i + j];
>> +splay_tree_key str;
>> +str = splay_tree_lookup (&acc_dev->mem_map, &k);
>> +if (str)
>> +  {
>> +if (finalize)
>> +  {
>> +str->refcount -= str->virtual_refcount;
>> +str->virtual_refcount = 0;
>> +  }
>> +if (str->virtual_refcount > 0)
>> +  {
>> +str->refcount--;
>> +str->virtual_refcount--;
>> +  }
>> +else if (str->refcount > 0)
>> +  str->refcount--;
>> +if (str->refcount == 0)
>> +  gomp_remove_var_async (acc_dev, str, aq);
>> +  }
>> +  }
>> +i += elems;
>> +  }
>> +  break;
>> +
>>  default:
>>gomp_fatal (" goacc_exit_data_internal UNHANDLED kind 0x%.2x",
>>kind);
>
> ... into an "empty 'case GOMP_MAP_STRUCT:' as a no-op [...]

> Further citing myself,
> <87ftbw9kqh.fsf@euler.schwinge.homeip.net">http://mid.mail-archive.com/87ftbw9kqh.fsf@euler.schwinge.homeip.net>:
>
> | Is my understanding correct that "fixed" GCC won't generate such
> | 'GOMP_MAP_STRUCT' anymore (I have't studied in detail), and this empty
> | 'case GOMP_MAP_STRUCT:' only remains in here for backwards compatibility?
> | In this case, please add a comment to the code, stating this.
>
> My guess was wrong: running a quick test, I do see that we still generate
> 'GOMP_MAP_STRUCT' for OpenACC unmap: [...]

> But one step back.  Why generate 'GOMP_MAP_STRUCT' for unmap, if we then
> just skip it in libgomp handling?  Cross checking, OpenMP
> 'libgomp/target.c:gomp_exit_data' also doesn't expect to see any
> 'GOMP_MAP_STRUCT'.
>
> For example, [...]
>
> I haven't studied 'GOMP_MAP_STRUCT' in detail (so it may be easy to prove
> me wrong), but for OpenACC 'exit data' etc., these 'map(struct:[...])'
> seem "pointless" to me, given that in libgomp we (intend to) just skip
> them?
>
> Well, and quickly I find that's exactly what OpenMP 'target exit data' is
> doing, and doing the same for OpenACC 'exit data': [...]

> ..., 'deep-copy-7.c.005t.gimple' gets simplified as expected: [...]

> [...] and so 'GOMP_MAP_STRUCT' handling could be removed from
> 'libgomp/oacc-mem.c:goacc_exit_data_internal' (and 'default:'
> 'gomp_fatal' would then catch any such cases).
>
> But of course, given that GCC 10.1 now does generate these
> 'GOMP_MAP_STRUCT's, we do have to support them in one way or another...

You've picked that up in your
http://mid.mail-archive.com/cf6237ce3f7cad564e2581e450c7d0346f53365f.1591276990.git.julian@codesourcery.com>
patch submission.  Thanks for the test case you've included, I changed
that one just a bit: '-fdump-tree-gimple' scanning (as that's where the
processing happens), removed the 'stdlib.h' dependency, made the 'struct'
(and thus the 'GOMP_MAP_STRUCT' that's generated) a bit more interesting.
I've pushed "[OpenACC 'exit data'] Strip 'GOMP_MAP_STRUCT' mappings" to
master branch in commit 1afc4672561a41dfbf4e3f2c1f35f7a5b7a20339, and
releases/gcc-10 branch in commit
27e985479e931771472663cad34f8b99c6f62627, see attached.


Grüße
 Thomas


-
Mentor Graphics (Deutschland) GmbH, Arnulfstraße 201, 80634 München / Germany
Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Alexander 
Walter
>From 1afc4672561a41dfbf4e3f2c1f35f7a5b7a20339 Mon Sep 17 00:00:00 2001
From: Thomas Schwinge 
Date: Wed, 20 May 2020 10:56:55 +0200
Subject: [PATCH] [OpenACC 'exit data'] Strip 'GOMP_MAP_STRUCT' mappings

These are not itself necessary for OpenACC 'exit data' directives, and are
skipped over (now) in libgomp.  We might as well not emit them to start with,
in line with the equivalent OpenMP directive.  We keep the no-op handling in
libgomp for the reason of backward compatibility.

	gcc/
	* gimplify.c (gimplify_adjust_omp_clauses): Remove
	'GOMP_MAP_STRUCT' mapping from OpenACC 'exit data' directi

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

2020-06-05 Thread Eric Botcazou
> I've installed it on trunk but will give it quite a while there before
> backporting.  I'm still somewhat worried about the
> 
>   /* ???  If we end up with a constant or a descriptor do not
>  record a MEM_EXPR.  */
>   else if (CONSTANT_CLASS_P (t)
> 
>|| TREE_CODE (t) == CONSTRUCTOR)
> 
> ;
> 
> case, maybe we should assert that bitpos == 0 here since we're
> dropping it on the floor but eventually inherit offset_known_p == true
> from the already present MEM_ATTRs.

It's hard to imagine without a testcase how you can end up inheriting anything 
for CONSTANT_CLASS_P or CONSTRUCTOR though: where do the MEM_ATTRs come from? 

-- 
Eric Botcazou


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

2020-06-05 Thread Jason Merrill via Gcc-patches
On Fri, Jun 5, 2020 at 12:01 PM Christophe Lyon 
wrote:

> On Fri, 15 May 2020 at 23:54, Jason Merrill via Gcc-patches
>  wrote:
> >
> > On 5/15/20 2:21 PM, Richard Biener wrote:
> > > On May 15, 2020 7:30:38 PM GMT+02:00, Jason Merrill 
> wrote:
> > >> On Fri, May 15, 2020 at 3:15 AM Richard Biener
> > >> 
> > >> wrote:
> > >>
> >  +# When bootstrapping with GCC, build stage 1 in C++11 mode to
> > >> ensure
> > >>> that a
> >  +# C++11 compiler can still start the bootstrap.
> >    if test "$enable_bootstrap:$GXX" = "yes:yes"; then
> >  +  CXX="$CXX -std=gnu++11"
> > >>>
> > >>> So I just spotted this - since we're requiring a ISO C++11 compiler
> shouldn't
> > >>> we build stage1 with -std=c++11 rather than gnu++11 (whatever the
> detailed
> > >>> differences are here)?  Also not sure what level of -pedantic we'd
> need to
> > >>> avoid GNU extensions even with -std=c++11.  Of course there are (I
> hope)
> > >>> a lot less GNU extensions for C++ than there were for C and hopefully
> > >>> no extra in gnu++11 compared to gnu++98 which we checked previously.
> >
> > Building stage 1 with -std=c++11 -pedantic-errors works with 8.3.1, but
> > fails pretty badly with 4.8.5,
> >
> > >> When we first moved to C++ I tried using -std=c++98, but there were
> too
> > >> many places where we were assuming that if we're building with GCC,
> we can
> > >> use GNU C extensions.
> > >>
> > >> I'll see if that's still a problem for -std=c++11.
> >
> > It doesn't seem to be, so I've made that change.
> >
> > >>> There also does not seem to be a configure check which may present
> > >>> users with a more useful error message than later cryptic fail of
> build?
> > >>> I suppose we cannot simply check __cplusplus for this, can we?  Do
> > >>> other common host compilers need additional options to enable C++11?
> > >>
> > >> Good point, I'll add that.
> >
> > This patch uses a test from the autoconf archive to add any needed
> > flags.  Tested with GCC 4.8.5 and clang 3.4.2 (with the above stage 1
> > -std=c++11 disabled).
> >
> > >>> Should we try to second guess such flags via configury?  For example
> > >>> GCC 4.8 defaults to -std=gnu++98 and the above only seems to apply
> > >>> to the bootstrap case so GCC 4.8 cannot be used to build cross
> > >> compilers
> > >>> without adjusting CC and CXX?
> > >>
> > >> Older GCC is still GCC and will get the flag automatically.
> > >
> > > But yes:yes suggests that when building a cross compiler this doesn't
> apply?
> >
> > True, but the new test should cover that case.
> >
> > OK for trunk?
>
> Hi,
>
> After recent commits on trunk that make use of c++11 features, I'm now
> unable to build cross-compilers (x86_64 host, arm/aarch64 targets)
> /gcc/tree-ssa-math-opts.c:124:32: warning: non-static data member
> initializers only available with -std=c++11 or -std=gnu++11
>basic_block bb = basic_block();
>
> I am using gcc-5.4.0, and this happens because although gcc/configure
> correctly:
> checking whether g++ supports C++11 features by default... no
> checking whether g++ supports C++11 features with -std=gnu++11... yes
> the actual CXXFLAGS used during the build are set by the toplevel Makefile,
> which does not include -std=c++11 or -std=gnu++11
>

Configure adds the -std=gnu++11 to CXX, not CXXFLAGS, but the problem is
the same; we only actually get the flag if you run 'make' in the gcc
subdirectory.  I guess I need to move that test to toplevel.

Jason


[PATCH] PR fortran/95530, PR fortran/95537 - Buffer overflows with long symbols

2020-06-05 Thread Harald Anlauf
The testcases for fixes of buffer overflows did show some fallout in
the testsuite that occurred only with suitably instrumented compilers.
Bill Seurer provided useful backtraces on powerpc64 that helped to nail
down the issues.  To verifiy that the newly chosen buffer size is now
sufficent, a check is put into place.

Regtested on x86_64-pc-linux-gnu, and confirmed in the PRs by Bill.

OK for master?

In case the fixes for PR95090 or PR95106 are backported, this one will be
needed, too.

Thanks,
Harald


PR fortran/95530, PR fortran/95537 - Buffer overflows with long symbols

The testcases for PR95090 and PR95106 trigger buffer overflows with long
symbols that were found with an instrumented compiler.  Enlarge the
affected buffers, and add checks that the buffers will suffice.

2020-06-05  Harald Anlauf  

gcc/fortran/
PR fortran/95530
PR fortran/95537
* decl.c (gfc_match_decl_type_spec): Enlarge buffer, and enhance
string copy to detect buffer overflow.
* gfortran.h (gfc_common_head): Enlarge buffer.
* trans-common.c (finish_equivalences): Enhance string copy to
detect buffer overflow.

diff --git a/gcc/fortran/decl.c b/gcc/fortran/decl.c
index 3ad5559c3ec..1c1626d3fa4 100644
--- a/gcc/fortran/decl.c
+++ b/gcc/fortran/decl.c
@@ -4094,7 +4094,8 @@ match_byte_typespec (gfc_typespec *ts)
 match
 gfc_match_decl_type_spec (gfc_typespec *ts, int implicit_flag)
 {
-  char name[GFC_MAX_SYMBOL_LEN + 1];
+  /* Provide sufficient space to hold "pdtsymbol".  */
+  char name[GFC_MAX_SYMBOL_LEN + 1 + 3];
   gfc_symbol *sym, *dt_sym;
   match m;
   char c;
@@ -4284,7 +4285,11 @@ gfc_match_decl_type_spec (gfc_typespec *ts, int implicit_flag)
 	return m;
 	  gcc_assert (!sym->attr.pdt_template && sym->attr.pdt_type);
 	  ts->u.derived = sym;
-	  strcpy (name, gfc_dt_lower_string (sym->name));
+	  const char* lower = gfc_dt_lower_string (sym->name);
+	  size_t len = strnlen (lower, sizeof (name));
+	  gcc_assert (len < sizeof (name));
+	  memcpy (name, lower, len);
+	  name[len] = '\0';
 	}

   if (sym && sym->attr.flavor == FL_STRUCT)
diff --git a/gcc/fortran/gfortran.h b/gcc/fortran/gfortran.h
index 5af44847f9b..0ef7b1b0eff 100644
--- a/gcc/fortran/gfortran.h
+++ b/gcc/fortran/gfortran.h
@@ -1677,7 +1677,8 @@ typedef struct gfc_common_head
   char use_assoc, saved, threadprivate;
   unsigned char omp_declare_target : 1;
   unsigned char omp_declare_target_link : 1;
-  char name[GFC_MAX_SYMBOL_LEN + 1];
+  /* Provide sufficient space to hold "symbol.eq.1234567890".  */
+  char name[GFC_MAX_SYMBOL_LEN + 1 + 14];
   struct gfc_symbol *head;
   const char* binding_label;
   int is_bind_c;
diff --git a/gcc/fortran/trans-common.c b/gcc/fortran/trans-common.c
index 3775a8bea74..1acc336eacf 100644
--- a/gcc/fortran/trans-common.c
+++ b/gcc/fortran/trans-common.c
@@ -1314,7 +1314,11 @@ finish_equivalences (gfc_namespace *ns)
 	  c->where = ns->proc_name->declared_at;
 	else if (ns->is_block_data)
 	  c->where = ns->sym_root->n.sym->declared_at;
-	strcpy (c->name, z->module);
+
+	size_t len = strlen (z->module);
+	gcc_assert (len < sizeof (c->name));
+	memcpy (c->name, z->module, len);
+	c->name[len] = '\0';
 	  }
 	else
 	  c = NULL;


[PATCH 0/4] aarch64: avoid exposing signed return addresses [PR94891]

2020-06-05 Thread Szabolcs Nagy
I'm not familiar with gcc internals enough to fix this the
right way, this is a big hammer fix to avoid exposing mangled
pointer representation to user code when pointer signing is
used on aarch64. I.e. this is not an optimal fix just to show
how i would want the ABI to work.

This touches unwinder ABI, unwinder debugger hook ABI (patch 3/4),
__builtin_return_address (1/4), __builtin_eh_return (2/4) usage and
updates the documentation a bit in this area (4/4).

Tests are still running. (I expect some existing target tests will
need to be updated.) The last patch is same as I sent before
(just with changelog this time).

Szabolcs Nagy (4):
  aarch64: fix return address access with pac [PR94891][PR94791]
  aarch64: fix __builtin_eh_return with pac-ret [PR94891]
  libgcc: fix the handling of return address mangling [PR94891]
  doc: Clarify __builtin_return_address [PR94891]

 gcc/config/aarch64/aarch64-protos.h|  1 +
 gcc/config/aarch64/aarch64.c   | 24 +-
 gcc/config/aarch64/aarch64.h   |  2 +-
 gcc/doc/extend.texi| 16 ++--
 libgcc/config/aarch64/aarch64-unwind.h | 34 --
 libgcc/unwind-dw2.c| 34 ++
 6 files changed, 52 insertions(+), 59 deletions(-)

-- 
2.17.1



[PATCH 2/4] aarch64: fix __builtin_eh_return with pac-ret [PR94891]

2020-06-05 Thread Szabolcs Nagy
The handler argument must not be signed since that may come from
outside the current module and exposing signed addresses is a pointer
ABI break. (The signed address also may not be representable as void *
which is why pac-ret is currently broken on ilp32.)

There is no point protecting the eh return path with pointer auth
since arbitrary target can be reached with the instruction sequence
in the caller function anyway, however this is a big hammer solution
that turns off pac-ret for the caller completely not just on the eh
return path.

2020-06-04  Szabolcs Nagy  

* config/aarch64/aarch64.c (aarch64_return_address_signing_enabled):
Disable return address signing if __builtin_eh_return is used.
---
 gcc/config/aarch64/aarch64.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/gcc/config/aarch64/aarch64.c b/gcc/config/aarch64/aarch64.c
index 6a2f85c4af7..d9557f7c0a2 100644
--- a/gcc/config/aarch64/aarch64.c
+++ b/gcc/config/aarch64/aarch64.c
@@ -6954,6 +6954,10 @@ aarch64_return_address_signing_enabled (void)
   /* This function should only be called after frame laid out.   */
   gcc_assert (cfun->machine->frame.laid_out);
 
+  /* TODO: Big hammer handling of __builtin_eh_return.  */
+  if (crtl->calls_eh_return)
+return false;
+
   /* If signing scope is AARCH64_FUNCTION_NON_LEAF, we only sign a leaf 
function
  if its LR is pushed onto stack.  */
   return (aarch64_ra_sign_scope == AARCH64_FUNCTION_ALL
-- 
2.17.1



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

2020-06-05 Thread Szabolcs Nagy
Mangling, currently only used on AArch64 for return address signing,
is an internal representation that should not be exposed via

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

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

This patch changes the unwinder hooks as follows:

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

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

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

libgcc/ChangeLog:

2020-06-04  Szabolcs Nagy  

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

diff --git a/libgcc/config/aarch64/aarch64-unwind.h 
b/libgcc/config/aarch64/aarch64-unwind.h
index ed84a96db41..b1d732e0b2d 100644
--- a/libgcc/config/aarch64/aarch64-unwind.h
+++ b/libgcc/config/aarch64/aarch64-unwind.h
@@ -27,11 +27,8 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If 
not, see
 
 #define DWARF_REGNUM_AARCH64_RA_STATE 34
 
-#define MD_POST_EXTRACT_ROOT_ADDR(addr)  __builtin_aarch64_xpaclri (addr)
-#define MD_POST_EXTRACT_FRAME_ADDR(context, fs, addr) \
-  aarch64_post_extract_frame_addr (context, fs, addr)
-#define MD_POST_FROB_EH_HANDLER_ADDR(current, target, addr) \
-  aarch64_post_frob_eh_handler_addr (current, target, addr)
+#define MD_DEMANGLE_RETURN_ADDR(context, fs, addr) \
+  aarch64_demangle_return_addr (context, fs, addr)
 #define MD_FROB_UPDATE_CONTEXT(context, fs) \
   aarch64_frob_update_context (context, fs)
 
@@ -57,9 +54,10 @@ aarch64_cie_signed_with_b_key (struct _Unwind_Context 
*context)
using CFA of current frame.  */
 
 static inline void *
-aarch64_post_extract_frame_addr (struct _Unwind_Context *context,
-_Unwind_FrameState *fs, void *addr)
+aarch64_demangle_return_addr (struct _Unwind_Context *context,
+ _Unwind_FrameState *fs, _Unwind_Word addr_word)
 {
+  void *addr = (void *)addr_word;
   if (context->flags & RA_SIGNED_BIT)
 {
   _Unwind_Word salt = (_Unwind_Word) context->cfa;
@@ -71,28 +69,6 @@ aarch64_post_extract_frame_addr (struct _Unwind_Context 
*context,
 return addr;
 }
 
-/* Do AArch64 private frob on exception handler's address HANDLER_ADDR before
-   installing it into current context CURRENT.  TARGET is currently not used.
-   We need to sign exception handler's address if CURRENT itself is signed.  */
-
-static inline void *
-aarch64_post_frob_eh_handler_addr (struct _Unwind_Context *current,
-  struct _Unwind_Context *target
-  ATTRIBUTE_UNUSED,
-  void *handler_addr)
-{
-  if (current->flags & RA_SIGNED_BIT)
-{
-  if (aarch64_cie_signed_with_b_key (current))
-   return __builtin_aarch64_pacib1716 (handler_addr,
-   (_Unwind_Word) current->cfa);
-  return __builtin_aarch64_pacia1716 (handler_addr,
-   (_Unwind_Word) current->cfa);
-}
-  else
-return handler_addr;
-}
-
 /* Do AArch64 private initialization on CONTEXT based on frame info FS.  Mark
CONTEXT as return address signed if bit 0 of DWARF_REGNUM_AARCH64_RA_STATE 
is
set.  */
diff --git a/libgcc/unwind-dw2.c b/libgcc/unwind-dw2.c
index 62d4a3d29a2..fe896565d2e 100644
--- a/libgcc/unwind-dw2.c
+++ b/libgcc/unwind-dw2.c
@@ -1538,11 +1538,14 @@ uw_update_context (struct _Unwind_Context *context, 
_Unwind_FrameState *fs)
 {
   /* Compute the return address now, since the return address column
 can change from frame to frame.  */
-  context->ra = __builtin_extract_return_addr
-   (_Unwind_GetPtr (context, fs->retaddr_column));
-#ifdef MD_POST_EXTRACT_FRAME_ADDR
-  context->ra = MD_POST_EXTRACT_FRAME_ADDR (context, fs, context->ra);
+  voi

[PATCH 1/4] aarch64: fix return address access with pac [PR94891][PR94791]

2020-06-05 Thread Szabolcs Nagy
This is a big hammer fix for __builtin_return_address (PR target/94891)
returning signed addresses (sometimes, depending on wether lr happens
to be signed or not at the time of call which depends on optimizations),
and similarly -pg may pass signed return address to _mcount
(PR target/94791).

At the time of return address expansion we don't know if it's signed or
not so it is done unconditionally.

I wonder if allocate_initial_value for the lr reg may solve this better
such that get_hard_reg_initial_val just gives the right (unsigned) value?

2020-06-04  Szabolcs Nagy  

* config/aarch64/aarch64-protos.h (aarch64_return_addr_rtx): Declare.
* config/aarch64/aarch64.c (aarch64_return_addr_rtx): New.
(aarch64_return_addr): Use aarch64_return_addr_rtx.
* config/aarch64/aarch64.h (PROFILE_HOOK): Likewise.
---
 gcc/config/aarch64/aarch64-protos.h |  1 +
 gcc/config/aarch64/aarch64.c| 20 +++-
 gcc/config/aarch64/aarch64.h|  2 +-
 3 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/gcc/config/aarch64/aarch64-protos.h 
b/gcc/config/aarch64/aarch64-protos.h
index 9e43adb7db0..723d9ba6ac6 100644
--- a/gcc/config/aarch64/aarch64-protos.h
+++ b/gcc/config/aarch64/aarch64-protos.h
@@ -578,6 +578,7 @@ int aarch64_vec_fpconst_pow_of_2 (rtx);
 rtx aarch64_eh_return_handler_rtx (void);
 rtx aarch64_mask_from_zextract_ops (rtx, rtx);
 const char *aarch64_output_move_struct (rtx *operands);
+rtx aarch64_return_addr_rtx (void);
 rtx aarch64_return_addr (int, rtx);
 rtx aarch64_simd_gen_const_vector_dup (machine_mode, HOST_WIDE_INT);
 bool aarch64_simd_mem_operand_p (rtx);
diff --git a/gcc/config/aarch64/aarch64.c b/gcc/config/aarch64/aarch64.c
index 6352d4ff78a..6a2f85c4af7 100644
--- a/gcc/config/aarch64/aarch64.c
+++ b/gcc/config/aarch64/aarch64.c
@@ -10819,6 +10819,24 @@ aarch64_initial_elimination_offset (unsigned from, 
unsigned to)
   return cfun->machine->frame.frame_size;
 }
 
+
+/* Get return address without mangling.  */
+
+rtx
+aarch64_return_addr_rtx (void)
+{
+  rtx val = get_hard_reg_initial_val (Pmode, LR_REGNUM);
+  /* Note: aarch64_return_address_signing_enabled only
+ works after cfun->machine->frame.laid_out is set,
+ so here we don't know if the return address will
+ be signed or not.  */
+  rtx lr = gen_rtx_REG (Pmode, LR_REGNUM);
+  emit_move_insn (lr, val);
+  emit_insn (GEN_FCN (CODE_FOR_xpaclri) ());
+  return lr;
+}
+
+
 /* Implement RETURN_ADDR_RTX.  We do not support moving back to a
previous frame.  */
 
@@ -10827,7 +10845,7 @@ aarch64_return_addr (int count, rtx frame 
ATTRIBUTE_UNUSED)
 {
   if (count != 0)
 return const0_rtx;
-  return get_hard_reg_initial_val (Pmode, LR_REGNUM);
+  return aarch64_return_addr_rtx ();
 }
 
 
diff --git a/gcc/config/aarch64/aarch64.h b/gcc/config/aarch64/aarch64.h
index 2be52fd4d73..f11941bbc86 100644
--- a/gcc/config/aarch64/aarch64.h
+++ b/gcc/config/aarch64/aarch64.h
@@ -1112,7 +1112,7 @@ typedef struct
 #define PROFILE_HOOK(LABEL)\
   {\
 rtx fun, lr;   \
-lr = get_hard_reg_initial_val (Pmode, LR_REGNUM);  \
+lr = aarch64_return_addr_rtx ();   \
 fun = gen_rtx_SYMBOL_REF (Pmode, MCOUNT_NAME); \
 emit_library_call (fun, LCT_NORMAL, VOIDmode, lr, Pmode);  \
   }
-- 
2.17.1



[PATCH 4/4] doc: Clarify __builtin_return_address [PR94891]

2020-06-05 Thread Szabolcs Nagy
The expected semantics and valid usage of __builtin_return_address is
not clear since it exposes implementation internals that are normally
not meaningful to portable c code.

This documentation change tries to clarify the semantics in case the
return address is stored in a mangled form. This affects AArch64 when
pointer authentication is used for the return address signing (i.e.
-mbranch-protection=pac-ret).

gcc/ChangeLog:

2020-06-04  Szabolcs Nagy  

* doc/extend.texi: Update the text for  __builtin_return_address.
---
 gcc/doc/extend.texi | 16 ++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi
index cced19d2018..0fd32a22599 100644
--- a/gcc/doc/extend.texi
+++ b/gcc/doc/extend.texi
@@ -11151,18 +11151,30 @@ The @var{level} argument must be a constant integer.
 
 On some machines it may be impossible to determine the return address of
 any function other than the current one; in such cases, or when the top
-of the stack has been reached, this function returns @code{0} or a
-random value.  In addition, @code{__builtin_frame_address} may be used
+of the stack has been reached, this function returns an unspecified
+value.  In addition, @code{__builtin_frame_address} may be used
 to determine if the top of the stack has been reached.
 
 Additional post-processing of the returned value may be needed, see
 @code{__builtin_extract_return_addr}.
 
+The stored representation of the return address in memory may be different
+from the address returned by @code{__builtin_return_address}.  For example
+on AArch64 the stored address may be mangled with return address signing.
+
 Calling this function with a nonzero argument can have unpredictable
 effects, including crashing the calling program.  As a result, calls
 that are considered unsafe are diagnosed when the @option{-Wframe-address}
 option is in effect.  Such calls should only be made in debugging
 situations.
+
+On targets where code addresses are representable as @code{void *},
+@smallexample
+void *addr = __builtin_extract_return_addr (__builtin_return_address (0))
+@end smallexample
+gives the code address where the current function would return.  For example
+such address may be used with @code{dladdr} or other interfaces that work
+with code addresses.
 @end deftypefn
 
 @deftypefn {Built-in Function} {void *} __builtin_extract_return_addr (void 
*@var{addr})
-- 
2.17.1



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

2020-06-05 Thread Thomas Schwinge
Hi Julian!

On 2020-06-04T06:40:55-0700, Julian Brown  wrote:
> This patch provides the same fix for Fortran derived type component
> mappings with derived types as the patch posted previously:
>
>   https://gcc.gnu.org/legacy-ml/gcc-patches/2020-01/msg00512.html
>
> IIUC this part was previously approved by Tobias.  OK?

I don't have in-depth knowledge of these Fortran front end OMP parts.
Tobias had reviewed and approved your patch in January, and I'll assume
his approval still holds.  Or are you asking for further review of the
patch?

I suppose we want this backported to releases/gcc-10 branch, too?

> --- /dev/null
> +++ b/gcc/testsuite/gfortran.dg/goacc/mapping-tests-3.f90
> @@ -0,0 +1,15 @@
> +! { dg-options "-fopenacc -fdump-tree-omplower" }

As '-fopenacc' is the default for 'gfortran.dg/goacc/', you can avoid to
repeat it by using '{ dg-additional-options "-fdump-tree-omplower" }'.

Just curious: specific reason to scan '-fdump-tree-omplower' -- wouldn't
the problem be visible in '-fdump-tree-original' or
'-fdump-tree-gimplify' already?

> +
> +subroutine foo
> +  type one
> +integer i, j
> +  end type
> +  type two
> +type(one) A, B
> +  end type
> +
> +  type(two) x
> +
> +  !$acc enter data copyin(x%A)
> +! { dg-final { scan-tree-dump-times "omp target oacc_enter_exit_data 
> map\\(struct:x \\\[len: 1\\\]\\) map\\(to:x.a \\\[len: \[0-9\]+\\\]\\)" 1 
> "omplower" } }
> +end

> --- /dev/null
> +++ b/gcc/testsuite/gfortran.dg/goacc/mapping-tests-4.f90
> @@ -0,0 +1,17 @@
> +subroutine foo
> +  type one
> +integer i, j
> +  end type
> +  type two
> +type(one) A, B
> +  end type
> +
> +  type(two) x
> +
> +! This is accepted at present, although it represents a 
> probably-unintentional
> +! overlapping subcopy.
> +  !$acc enter data copyin(x%A, x%A%i)

Should that missing diagnostic get a PR filed, and that one be referenced
here?

> +! But this raises an error.
> +  !$acc enter data copyin(x%A, x%A%i, x%A%i)
> +! { dg-error ".x.a.i. appears more than once in map clauses" "" { target 
> "*-*-*" } 15 }
> +end

Not a problem, but unusual to see '"*-*-*"' quoted.  Preferable to use
relative '.-1' instead of absolute '15'.


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


[pushed] c++: Fix pretty-print of pointer minus integer.

2020-06-05 Thread Jason Merrill via Gcc-patches
For whatever reason, GCC internally represents a pointer minus an integer as
a pointer plus a very large unsigned integer.  But exposing that to users is
unsightly, and it's easy enough to show the real value.

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

gcc/cp/ChangeLog:

* error.c (dump_binary_op): Handle negative operand to
POINTER_PLUS_EXPR.

gcc/c-family/ChangeLog:

* c-pretty-print.c (pp_c_additive_expression): Handle negative
operand to POINTER_PLUS_EXPR.

gcc/testsuite/ChangeLog:

* g++.dg/cpp0x/constexpr-ptrsub2.C: New test.
---
 gcc/c-family/c-pretty-print.c  | 11 ++-
 gcc/cp/error.c |  9 -
 gcc/testsuite/g++.dg/cpp0x/constexpr-ptrsub2.C |  4 
 3 files changed, 22 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/cpp0x/constexpr-ptrsub2.C

diff --git a/gcc/c-family/c-pretty-print.c b/gcc/c-family/c-pretty-print.c
index 32f30f2d452..71baf5e2ede 100644
--- a/gcc/c-family/c-pretty-print.c
+++ b/gcc/c-family/c-pretty-print.c
@@ -1898,7 +1898,16 @@ pp_c_additive_expression (c_pretty_printer *pp, tree e)
   else
pp_minus (pp);
   pp_c_whitespace (pp);
-  pp->multiplicative_expression (TREE_OPERAND (e, 1));
+  {
+   tree op1 = TREE_OPERAND (e, 1);
+   if (code == POINTER_PLUS_EXPR
+   && TREE_CODE (op1) == INTEGER_CST
+   && tree_int_cst_sign_bit (op1))
+ /* A pointer minus an integer is represented internally as plus a very
+large number, don't expose that to users.  */
+ op1 = convert (ssizetype, op1);
+   pp->multiplicative_expression (op1);
+  }
   break;
 
 default:
diff --git a/gcc/cp/error.c b/gcc/cp/error.c
index 46970f9b699..0d6375e5e14 100644
--- a/gcc/cp/error.c
+++ b/gcc/cp/error.c
@@ -2909,7 +2909,14 @@ dump_binary_op (cxx_pretty_printer *pp, const char 
*opstring, tree t,
   else
 pp_string (pp, M_(""));
   pp_cxx_whitespace (pp);
-  dump_expr (pp, TREE_OPERAND (t, 1), flags | TFF_EXPR_IN_PARENS);
+  tree op1 = TREE_OPERAND (t, 1);
+  if (TREE_CODE (t) == POINTER_PLUS_EXPR
+  && TREE_CODE (op1) == INTEGER_CST
+  && tree_int_cst_sign_bit (op1))
+/* A pointer minus an integer is represented internally as plus a very
+   large number, don't expose that to users.  */
+op1 = convert (ssizetype, op1);
+  dump_expr (pp, op1, flags | TFF_EXPR_IN_PARENS);
   pp_cxx_right_paren (pp);
 }
 
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-ptrsub2.C 
b/gcc/testsuite/g++.dg/cpp0x/constexpr-ptrsub2.C
new file mode 100644
index 000..fd644ad7854
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-ptrsub2.C
@@ -0,0 +1,4 @@
+// { dg-do compile { target c++11 } }
+
+char c;
+constexpr char p2 = *(&c - 1); // { dg-error "-1" }

base-commit: 5905cbdbcf6d760303ca87f27e04824f26976de4
-- 
2.18.1



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

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

On 6/5/20 12:39 PM, Jason Merrill wrote:
On Fri, Jun 5, 2020 at 12:01 PM Christophe Lyon 
mailto:christophe.l...@linaro.org>> wrote:


On Fri, 15 May 2020 at 23:54, Jason Merrill via Gcc-patches
mailto:gcc-patches@gcc.gnu.org>> wrote:
 >
 > On 5/15/20 2:21 PM, Richard Biener wrote:
 > > On May 15, 2020 7:30:38 PM GMT+02:00, Jason Merrill
mailto:ja...@redhat.com>> wrote:
 > >> On Fri, May 15, 2020 at 3:15 AM Richard Biener
 > >> mailto:richard.guent...@gmail.com>>
 > >> wrote:
 > >>
 >  +# When bootstrapping with GCC, build stage 1 in C++11 mode to
 > >> ensure
 > >>> that a
 >  +# C++11 compiler can still start the bootstrap.
 >    if test "$enable_bootstrap:$GXX" = "yes:yes"; then
 >  +  CXX="$CXX -std=gnu++11"
 > >>>
 > >>> So I just spotted this - since we're requiring a ISO C++11
compiler shouldn't
 > >>> we build stage1 with -std=c++11 rather than gnu++11 (whatever
the detailed
 > >>> differences are here)?  Also not sure what level of -pedantic
we'd need to
 > >>> avoid GNU extensions even with -std=c++11.  Of course there
are (I hope)
 > >>> a lot less GNU extensions for C++ than there were for C and
hopefully
 > >>> no extra in gnu++11 compared to gnu++98 which we checked
previously.
 >
 > Building stage 1 with -std=c++11 -pedantic-errors works with
8.3.1, but
 > fails pretty badly with 4.8.5,
 >
 > >> When we first moved to C++ I tried using -std=c++98, but there
were too
 > >> many places where we were assuming that if we're building with
GCC, we can
 > >> use GNU C extensions.
 > >>
 > >> I'll see if that's still a problem for -std=c++11.
 >
 > It doesn't seem to be, so I've made that change.
 >
 > >>> There also does not seem to be a configure check which may
present
 > >>> users with a more useful error message than later cryptic
fail of build?
 > >>> I suppose we cannot simply check __cplusplus for this, can
we?  Do
 > >>> other common host compilers need additional options to enable
C++11?
 > >>
 > >> Good point, I'll add that.
 >
 > This patch uses a test from the autoconf archive to add any needed
 > flags.  Tested with GCC 4.8.5 and clang 3.4.2 (with the above stage 1
 > -std=c++11 disabled).
 >
 > >>> Should we try to second guess such flags via configury?  For
example
 > >>> GCC 4.8 defaults to -std=gnu++98 and the above only seems to
apply
 > >>> to the bootstrap case so GCC 4.8 cannot be used to build cross
 > >> compilers
 > >>> without adjusting CC and CXX?
 > >>
 > >> Older GCC is still GCC and will get the flag automatically.
 > >
 > > But yes:yes suggests that when building a cross compiler this
doesn't apply?
 >
 > True, but the new test should cover that case.
 >
 > OK for trunk?

Hi,

After recent commits on trunk that make use of c++11 features, I'm now
unable to build cross-compilers (x86_64 host, arm/aarch64 targets)
/gcc/tree-ssa-math-opts.c:124:32: warning: non-static data member
initializers only available with -std=c++11 or -std=gnu++11
    basic_block bb = basic_block();

I am using gcc-5.4.0, and this happens because although
gcc/configure correctly:
checking whether g++ supports C++11 features by default... no
checking whether g++ supports C++11 features with -std=gnu++11... yes
the actual CXXFLAGS used during the build are set by the toplevel
Makefile,
which does not include -std=c++11 or -std=gnu++11


Configure adds the -std=gnu++11 to CXX, not CXXFLAGS, but the problem is 
the same; we only actually get the flag if you run 'make' in the gcc 
subdirectory.  I guess I need to move that test to toplevel.


Like so.  OK for trunk?

commit e9a1dcaf78f7316a771cc6c3a4800784bb18d8e2
Author: Jason Merrill 
Date:   Fri Jun 5 12:45:11 2020 -0400

c++: Fix --disable-bootstrap with older g++.

Previously I had AX_CXX_COMPILE_STDCXX in the gcc directory configure, which
added -std=c++11 to CXX if needed, but then CXX is overridden from the
toplevel directory, so it didn't have the desired effect.  Fixed by moving
the check to the toplevel.  Currently it is only used when building GCC
without bootstrapping; other packages that share the toplevel directory
can adjust the condition if they also want to require C++11 support.

ChangeLog:

* configure.ac: Check AX_CXX_COMPILE_STDCXX if not bootstrapping.
* configure: Regenerate.

gcc/ChangeLog:

* aclocal.m4: Remove ax_cxx_compile_stdcxx.m4.
* configure.ac: Remove AX_CXX_COMPILE_STDCXX.
* configure: Regenerate.

diff --git a/configure.ac b/configure.ac
index 59bd92a3e53..1a53ed418e4 100644
--- a/configure.ac
+++ b/configure.ac
@@ -23,6 +23,7 @@ m4_include(

Re: [PATCH 4/6] rs6000, Add vector shift double builtin support

2020-06-05 Thread Segher Boessenkool
Hi!

On Mon, Jun 01, 2020 at 09:14:54AM -0700, Carl Love wrote:
> * config/rs6000/altivec.h: Add define for vec_sldb and
> vec_srdb.

(vec_sldb, vec_srdb): New defines.

(Etc.)

> * testsuite/gcc.target/powerpc/vec-shift-double-runnable.c: Add
> runnable test case.

gcc/testsuite/ has its own changelog.

> + /* Check whether the 3rd argument is an integer constant in the
> range
> + 0 to 7 inclusive.  */
> + STRIP_NOPS (arg2);
> + if (TREE_CODE (arg2) != INTEGER_CST
> +  || !IN_RANGE(TREE_INT_CST_LOW(arg2), 0, 7))

Space before ( please (twice).

The rest looks fine -- either repost this with a better changelog, or
immediately commit it with that (and the nit fixed), whichever you
prefer.  Thanks!


Segher


Re: [PATCH] PR fortran/95530, PR fortran/95537 - Buffer overflows with long symbols

2020-06-05 Thread Thomas Koenig via Gcc-patches

Am 05.06.20 um 18:45 schrieb Harald Anlauf:

The testcases for fixes of buffer overflows did show some fallout in
the testsuite that occurred only with suitably instrumented compilers.
Bill Seurer provided useful backtraces on powerpc64 that helped to nail
down the issues.  To verifiy that the newly chosen buffer size is now
sufficent, a check is put into place.

Regtested on x86_64-pc-linux-gnu, and confirmed in the PRs by Bill.

OK for master?


OK.


In case the fixes for PR95090 or PR95106 are backported, this one will be
needed, too.


They are safe enough for a backport, so if you want to, please feel
free.

Thanks for the patch!

Regards

Thomas



[committed] d: Merge upstream dmd f5638c7b8.

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

This patch merges the D front-end implementation with upstream dmd
f5638c7b8.  Adds a CHECKENABLE enum, uses it for all contract parameters
for consistency in state checking.

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

Regards
Iain.


gcc/d/ChangeLog:

* dmd/MERGE: Merge upstream dmd f5638c7b8.
* d-builtins.cc (d_init_versions): Use new CHECKENABLE enum.
* d-codegen.cc (array_bounds_check): Likewise.
(build_frame_type): Likewise.
(get_frameinfo): Likewise.
* d-lang.cc (d_init_options): Likewise.
(d_init_options_struct): Don't initialize x_flag_bounds_check.
(d_handle_option): Use new CHECKENABLE enum.
(d_post_options): Likewise.  Set flag_bounds_check here.
* expr.cc (ExprVisitor::visit(AssertExp *)): Use new CHECKENABLE enum.
---
 gcc/d/d-builtins.cc   |  4 +-
 gcc/d/d-codegen.cc| 14 +++
 gcc/d/d-lang.cc   | 83 ++-
 gcc/d/dmd/MERGE   |  2 +-
 gcc/d/dmd/expressionsem.c |  2 +-
 gcc/d/dmd/func.c  | 18 -
 gcc/d/dmd/globals.h   | 25 ++--
 gcc/d/dmd/statementsem.c  |  4 +-
 gcc/d/expr.cc |  6 +--
 9 files changed, 87 insertions(+), 71 deletions(-)

diff --git a/gcc/d/d-builtins.cc b/gcc/d/d-builtins.cc
index cbc74558106..bd7e3eb15d7 100644
--- a/gcc/d/d-builtins.cc
+++ b/gcc/d/d-builtins.cc
@@ -472,10 +472,10 @@ d_init_versions (void)
   if (global.params.useUnitTests)
 VersionCondition::addPredefinedGlobalIdent ("unittest");
 
-  if (global.params.useAssert)
+  if (global.params.useAssert == CHECKENABLEon)
 VersionCondition::addPredefinedGlobalIdent ("assert");
 
-  if (global.params.useArrayBounds == BOUNDSCHECKoff)
+  if (global.params.useArrayBounds == CHECKENABLEoff)
 VersionCondition::addPredefinedGlobalIdent ("D_NoBoundsChecks");
 
   if (global.params.betterC)
diff --git a/gcc/d/d-codegen.cc b/gcc/d/d-codegen.cc
index cf98d4be7e9..301793f1b74 100644
--- a/gcc/d/d-codegen.cc
+++ b/gcc/d/d-codegen.cc
@@ -1749,13 +1749,13 @@ array_bounds_check (void)
 
   switch (global.params.useArrayBounds)
 {
-case BOUNDSCHECKoff:
+case CHECKENABLEoff:
   return false;
 
-case BOUNDSCHECKon:
+case CHECKENABLEon:
   return true;
 
-case BOUNDSCHECKsafeonly:
+case CHECKENABLEsafeonly:
   /* For D2 safe functions only.  */
   fd = d_function_chain->function;
   if (fd && fd->type->ty == Tfunction)
@@ -2376,8 +2376,8 @@ build_frame_type (tree ffi, FuncDeclaration *fd)
  of the calling function non-locally.  So we add all parameters with nested
  refs to the function frame, this should also mean overriding methods will
  have the same frame layout when inheriting a contract.  */
-  if ((global.params.useIn && fd->frequire)
-  || (global.params.useOut && fd->fensure))
+  if ((global.params.useIn == CHECKENABLEon && fd->frequire)
+  || (global.params.useOut == CHECKENABLEon && fd->fensure))
 {
   if (fd->parameters)
{
@@ -2563,8 +2563,8 @@ get_frameinfo (FuncDeclaration *fd)
 
   /* In checkNestedReference, references from contracts are not added to 
the
 closureVars array, so assume all parameters referenced.  */
-  if ((global.params.useIn && fd->frequire)
- || (global.params.useOut && fd->fensure))
+  if ((global.params.useIn == CHECKENABLEon && fd->frequire)
+ || (global.params.useOut == CHECKENABLEon && fd->fensure))
FRAMEINFO_CREATES_FRAME (ffi) = 1;
 
   /* If however `fd` is nested (deeply) in a function that creates a
diff --git a/gcc/d/d-lang.cc b/gcc/d/d-lang.cc
index 51a87a01813..203039e9ecf 100644
--- a/gcc/d/d-lang.cc
+++ b/gcc/d/d-lang.cc
@@ -279,12 +279,12 @@ d_init_options (unsigned int, cl_decoded_option 
*decoded_options)
   global.vendor = lang_hooks.name;
   global.params.argv0 = xstrdup (decoded_options[0].arg);
   global.params.link = true;
-  global.params.useAssert = true;
-  global.params.useInvariants = true;
-  global.params.useIn = true;
-  global.params.useOut = true;
-  global.params.useArrayBounds = BOUNDSCHECKdefault;
-  global.params.useSwitchError = true;
+  global.params.useAssert = CHECKENABLEdefault;
+  global.params.useInvariants = CHECKENABLEdefault;
+  global.params.useIn = CHECKENABLEdefault;
+  global.params.useOut = CHECKENABLEdefault;
+  global.params.useArrayBounds = CHECKENABLEdefault;
+  global.params.useSwitchError = CHECKENABLEdefault;
   global.params.useModuleInfo = true;
   global.params.useTypeInfo = true;
   global.params.useExceptions = true;
@@ -339,9 +339,6 @@ d_init_options_struct (gcc_options *opts)
   opts->x_flag_errno_math = 0;
   opts->frontend_set_flag_errno_math = true;
 
-  /* Keep in sync with existing -fbounds-check flag.  */
-  opts->x_flag_bounds_check = global.params.useArrayBounds;
-
   /* D says that signed overflow is precisely defined.  */
   opts->x_flag_wrapv = 1;
 }
@@ -424,17 

Re: [PATCH] Prefer simple case changes in spelling suggestions

2020-06-05 Thread Pip Cet via Gcc-patches
David Malcolm  writes:

> On Sat, 2020-05-30 at 18:51 +, Pip Cet wrote:
>> How's this?
>
> Thanks; looks good to me.  Hopefully this doesn't clash with Tom's
> patch.

It doesn't, but I hope I got the commit message right this time.

(I don't have git access, so if someone could commit this if it's
approved, that would be great).

>From 7e89a6be601b268b134e20c2702bd55945388a22 Mon Sep 17 00:00:00 2001
From: Pip Cet 
Date: Sat, 30 May 2020 13:39:09 +
Subject: [PATCH] Don't test the triangle inequality in the spellcheck.c
 self-test

The variant of editing distance we use doesn't satisfy the triangle
inequality.

gcc/ChangeLog:

	* spellcheck.c (test_data): Add problematic strings.
	(test_metric_conditions): Don't test the triangle inequality
	condition, which our distance function does not satisfy.
---
 gcc/spellcheck.c | 22 --
 1 file changed, 8 insertions(+), 14 deletions(-)

diff --git a/gcc/spellcheck.c b/gcc/spellcheck.c
index 9f7351f364f..45c41d7cef9 100644
--- a/gcc/spellcheck.c
+++ b/gcc/spellcheck.c
@@ -474,13 +474,17 @@ static const char * const test_data[] = {
   "food",
   "boo",
   "1234567890123456789012345678901234567890123456789012345678901234567890"
+  "abc",
+  "ac",
+  "ca",
 };
 
 /* Verify that get_edit_distance appears to be a sane distance function,
-   i.e. the conditions for being a metric.  This is done directly for a
-   small set of examples, using test_data above.  This is O(N^3) in the size
-   of the array, due to the test for the triangle inequality, so we keep the
-   array small.  */
+   even though it doesn't satisfy the conditions for being a metric.  (This
+   is because the triangle inequality fails to hold: the distance between
+   "ca" and "ac" is 1, and so is the distance between "abc" and "ac", but
+   the distance between "abc" and "ca" is 3. Algorithms that calculate the
+   true Levenshtein-Damerau metric are much more expensive.)  */
 
 static void
 test_metric_conditions ()
@@ -504,16 +508,6 @@ test_metric_conditions ()
 	  edit_distance_t dist_ji
 	= get_edit_distance (test_data[j], test_data[i]);
 	  ASSERT_EQ (dist_ij, dist_ji);
-
-	  /* Triangle inequality.  */
-	  for (int k = 0; k < num_test_cases; k++)
-	{
-	  edit_distance_t dist_ik
-		= get_edit_distance (test_data[i], test_data[k]);
-	  edit_distance_t dist_jk
-		= get_edit_distance (test_data[j], test_data[k]);
-	  ASSERT_TRUE (dist_ik <= dist_ij + dist_jk);
-	}
 	}
 }
 }
-- 
2.27.0.rc0



Re: [PATCH v2] c++: Make braced-init-list as template arg work with aggr init [PR95369]

2020-06-05 Thread Marek Polacek via Gcc-patches
On Fri, May 29, 2020 at 03:17:51PM -0400, Jason Merrill via Gcc-patches wrote:
> On 5/28/20 7:23 PM, Marek Polacek wrote:
> > Barry pointed out to me that our braced-init-list as a template-argument
> > extension doesn't work as expected when we aggregate-initialize.  Thus
> > fixed by calling digest_init in convert_nontype_argument so that we can
> > actually convert the CONSTRUCTOR.
> > 
> > I don't think we can call digest_init any earlier, and it needs to
> > happen before the call to build_converted_constant_expr.
> 
> Or we could fix build_converted_constant_expr to allow it; aggregate
> list-initialization is a user-defined conversion sequence, so I tihnk it
> should be allowed as part of a converted constant expression.

Ah, nice.  It works just fine.  Here's the complete patch:

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

-- >8 --
Barry pointed out to me that our braced-init-list as a template-argument
extension doesn't work as expected when we aggregate-initialize.  Since
aggregate list-initialization is a user-defined conversion sequence, we
allow it as part of a converted constant expression.

Co-authored-by: Jason Merrill 

gcc/cp/ChangeLog:

PR c++/95369
* call.c (build_converted_constant_expr_internal): Allow
list-initialization.

gcc/testsuite/ChangeLog:

PR c++/95369
* g++.dg/cpp2a/nontype-class38.C: New test.
---
 gcc/cp/call.c|  4 ++-
 gcc/testsuite/g++.dg/cpp2a/nontype-class38.C | 30 
 2 files changed, 33 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.dg/cpp2a/nontype-class38.C

diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index 2b393f96e5b..3c97b9846e2 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -4348,7 +4348,7 @@ build_converted_constant_expr_internal (tree type, tree 
expr,
  and where the reference binding (if any) binds directly.  */
 
   for (conversion *c = conv;
-   conv && c->kind != ck_identity;
+   c && c->kind != ck_identity;
c = next_conversion (c))
 {
   switch (c->kind)
@@ -4356,6 +4356,8 @@ build_converted_constant_expr_internal (tree type, tree 
expr,
  /* A conversion function is OK.  If it isn't constexpr, we'll
 complain later that the argument isn't constant.  */
case ck_user:
+ /* List-initialization is OK.  */
+   case ck_aggr:
  /* The lvalue-to-rvalue conversion is OK.  */
case ck_rvalue:
  /* Array-to-pointer and function-to-pointer.  */
diff --git a/gcc/testsuite/g++.dg/cpp2a/nontype-class38.C 
b/gcc/testsuite/g++.dg/cpp2a/nontype-class38.C
new file mode 100644
index 000..5b440fd1c9e
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/nontype-class38.C
@@ -0,0 +1,30 @@
+// PR c++/95369
+// { dg-do compile { target c++20 } }
+
+struct S {
+  int a;
+  int b;
+};
+
+struct W {
+  int i;
+  S s;
+};
+
+template 
+void fnc()
+{
+}
+
+template struct X { };
+template struct Y { };
+
+void f()
+{
+  fnc<{ .a = 10, .b = 20 }>();
+  fnc<{ 10, 20 }>();
+  X<{ .a = 1, .b = 2 }> x;
+  X<{ 1, 2 }> x2;
+  // Brace elision is likely to be allowed.
+  Y<{ 1, 2, 3 }> x3;
+}

base-commit: 640e05e02b567fa5ccf4c207e6fc6c3e9a93b17c
-- 
Marek Polacek • Red Hat, Inc. • 300 A St, Boston, MA



[PATCH] underline null argument in -Wnonnull (PR c++/86568)

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

The caret location C++ -Wnonnull warnings is in the wrong place:
either under the closing parenthesis of a call to a function
declared nonnull, or under the whole call (when issued from
the middle end).  In addition, for member functions, the one-based
argument number mentioned in the warning starts with the implicit
this pointer, while in non-members it starts with the first argument.
That makes it difficult to tell which argument the warning is
complaining about (see the test + output below).

The attached patch improves things in a few minor ways:

1) by using the argument location when it has one to underline it
   (the location isn't always available at this point but that
   can be improved in a followup)
2) by using 1 for the first explicit argument, and by mentioning
   'this' for the this pointer
3) by changing the message issued by the front-end (and the C++
   member function handling) to match the corresponding message
   (and handling) in the middle end.

Finally, the patch also arranges to treat the C++ this pointer
as implicitly nonnull, regardless of whether the member function
is declared with the attribute.

Tested on x86_64-linux.

Martin

PS For this test case:

__attribute__ ((nonnull)) void f (const char*);

struct S
{
  __attribute__ ((nonnull)) void g (const char*) const;
};

void g (void)
{
  {
const char* const null = 0;
f (null);
  }

  {
const S* const null = 0;
null->g ("");
  }
}

GCC trunk outputs:

t.C: In function ‘void g()’:
t.C:12:12: warning: null argument where non-null required (argument 1) 
[-Wnonnull]

   12 | f (null);
  |^
t.C:17:16: warning: null argument where non-null required (argument 1) 
[-Wnonnull]

   17 | null->g ("");
  |^


With the patch the output is:

t.C: In function ‘void g()’:
t.C:12:8: warning: argument 1 null where non-null expected [-Wnonnull]
   12 | f (null);
  |^~~~
t.C:1:32: note: in a call to function ‘void f(const char*)’ declared 
‘nonnull’

1 | __attribute__ ((nonnull)) void f (const char*);
  |^
t.C:17:5: warning: ‘this’ pointer null [-Wnonnull]
   17 | null->g ("");
  | ^~~~
t.C:5:34: note: in a call to non-static member function ‘void S::g(const 
char*) const’

5 |   __attribute__ ((nonnull)) void g (const char*) const;
  |  ^

PR c++/86568 - -Wnonnull warnings should highlight the relevant argument not the closing parenthesis

gcc/c-family/ChangeLog:

	PR c++/86568
	* c-common.c (struct nonnull_arg_ctx): Add members.
	(check_function_nonnull): Use nonnull_arg_ctx as argument.  Handle
	C++ member functions specially.  Consider the this pointer implicitly
	nonnull.
	(check_nonnull_arg): Use location of argument when available.
	(check_function_arguments): Use nonnull_arg_ctx as argument.

gcc/ChangeLog:

	PR c++/86568
	* calls.c (maybe_warn_rdwr_sizes): Use location of argument if
	available.
	* tree-ssa-ccp.c (pass_post_ipa_warn::execute): Same.  Adjust
	indentation.
	* tree.c (get_nonnull_args): Consider the this pointer implicitly
	nonnull.
	* gcc/var-tracking.c (deps_vec): New type.
	(var_loc_dep_vec): New function.
	(VAR_LOC_DEP_VEC): Use it.

gcc/testsuite/ChangeLog:

	PR c++/86568
	* g++.dg/warn/Wnonnull5.C: New test.
	* c-c++-common/pr28656.c: Adjust text of expected warning.
	* c-c++-common/pr66208.c: Same.
	* g++.dg/cpp0x/nullptr22.C: Same.
	* g++.dg/ext/attr-nonnull.C: Same.
	* g++.dg/ext/attrib49.C: Same.
	* g++.dg/pr71973-2.C: Same.
	* g++.dg/warn/Wnonnull3.C: Same.
	* g++.dg/warn/Wnonnull4.C: Same.
	* obj-c++.dg/attributes/method-nonnull-1.mm: Same.
	* objc.dg/attributes/method-nonnull-1.m: Same.

diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c
index b1379faa412..8bedd9dc910 100644
--- a/gcc/c-family/c-common.c
+++ b/gcc/c-family/c-common.c
@@ -5288,26 +5288,39 @@ c_determine_visibility (tree decl)
 
 struct nonnull_arg_ctx
 {
+  /* Location of the call.  */
   location_t loc;
+  /* The function whose arguments are being checked and its type (used
+ for calls through function pointers).  */
+  const_tree fndecl, fntype;
+  /* True if a warning has been issued.  */
   bool warned_p;
 };
 
-/* Check the argument list of a function call for null in argument slots
-   that are marked as requiring a non-null pointer argument.  The NARGS
-   arguments are passed in the array ARGARRAY.  Return true if we have
-   warned.  */
+/* Check the argument list of a function call to CTX.FNDECL of CTX.FNTYPE
+   for null in argument slots that are marked as requiring a non-null
+   pointer argument.  The NARGS arguments are passed in the array ARGARRAY.
+   Return true if we have warned.  */
 
 static bool
-check_function_nonnull (location_t loc, tree attrs, int nargs, tree *argarray)
+check_function_nonnull (nonnull_arg_ctx &ctx, int nargs, tree *argarray)
 {
-  tree a;
-  int i;
+  int firstarg = 0;
+  if (TREE_CODE (ctx.fntype) == METHOD_TYPE)
+{

Re: [PATCH v2] c++: Make braced-init-list as template arg work with aggr init [PR95369]

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

On 6/5/20 3:13 PM, Marek Polacek wrote:

On Fri, May 29, 2020 at 03:17:51PM -0400, Jason Merrill via Gcc-patches wrote:

On 5/28/20 7:23 PM, Marek Polacek wrote:

Barry pointed out to me that our braced-init-list as a template-argument
extension doesn't work as expected when we aggregate-initialize.  Thus
fixed by calling digest_init in convert_nontype_argument so that we can
actually convert the CONSTRUCTOR.

I don't think we can call digest_init any earlier, and it needs to
happen before the call to build_converted_constant_expr.


Or we could fix build_converted_constant_expr to allow it; aggregate
list-initialization is a user-defined conversion sequence, so I tihnk it
should be allowed as part of a converted constant expression.


Ah, nice.  It works just fine.  Here's the complete patch:

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


OK.


-- >8 --
Barry pointed out to me that our braced-init-list as a template-argument
extension doesn't work as expected when we aggregate-initialize.  Since
aggregate list-initialization is a user-defined conversion sequence, we
allow it as part of a converted constant expression.

Co-authored-by: Jason Merrill 

gcc/cp/ChangeLog:

PR c++/95369
* call.c (build_converted_constant_expr_internal): Allow
list-initialization.

gcc/testsuite/ChangeLog:

PR c++/95369
* g++.dg/cpp2a/nontype-class38.C: New test.
---
  gcc/cp/call.c|  4 ++-
  gcc/testsuite/g++.dg/cpp2a/nontype-class38.C | 30 
  2 files changed, 33 insertions(+), 1 deletion(-)
  create mode 100644 gcc/testsuite/g++.dg/cpp2a/nontype-class38.C

diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index 2b393f96e5b..3c97b9846e2 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -4348,7 +4348,7 @@ build_converted_constant_expr_internal (tree type, tree 
expr,
   and where the reference binding (if any) binds directly.  */
  
for (conversion *c = conv;

-   conv && c->kind != ck_identity;
+   c && c->kind != ck_identity;
 c = next_conversion (c))
  {
switch (c->kind)
@@ -4356,6 +4356,8 @@ build_converted_constant_expr_internal (tree type, tree 
expr,
  /* A conversion function is OK.  If it isn't constexpr, we'll
 complain later that the argument isn't constant.  */
case ck_user:
+ /* List-initialization is OK.  */
+   case ck_aggr:
  /* The lvalue-to-rvalue conversion is OK.  */
case ck_rvalue:
  /* Array-to-pointer and function-to-pointer.  */
diff --git a/gcc/testsuite/g++.dg/cpp2a/nontype-class38.C 
b/gcc/testsuite/g++.dg/cpp2a/nontype-class38.C
new file mode 100644
index 000..5b440fd1c9e
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/nontype-class38.C
@@ -0,0 +1,30 @@
+// PR c++/95369
+// { dg-do compile { target c++20 } }
+
+struct S {
+  int a;
+  int b;
+};
+
+struct W {
+  int i;
+  S s;
+};
+
+template 
+void fnc()
+{
+}
+
+template struct X { };
+template struct Y { };
+
+void f()
+{
+  fnc<{ .a = 10, .b = 20 }>();
+  fnc<{ 10, 20 }>();
+  X<{ .a = 1, .b = 2 }> x;
+  X<{ 1, 2 }> x2;
+  // Brace elision is likely to be allowed.
+  Y<{ 1, 2, 3 }> x3;
+}

base-commit: 640e05e02b567fa5ccf4c207e6fc6c3e9a93b17c





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

2020-06-05 Thread François Dumont via Gcc-patches

Hi

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


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


Tested under Linux x86_64 normal and debug modes.

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

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

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

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

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

    New test.

Ok to commit ?

François


diff --git a/libstdc++-v3/include/bits/deque.tcc b/libstdc++-v3/include/bits/deque.tcc
index 1d32a1691c7..d7dbe64f3e1 100644
--- a/libstdc++-v3/include/bits/deque.tcc
+++ b/libstdc++-v3/include/bits/deque.tcc
@@ -1261,6 +1261,98 @@ _GLIBCXX_END_NAMESPACE_CONTAINER
   return true;
 }
 
+  template
+int
+__lex_cmp_dit(
+	const _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Ref, _Ptr>& __first1,
+	const _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Ref, _Ptr>& __last1,
+	_II __first2, _II __last2)
+{
+  typedef _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Ref, _Ptr> _Iter;
+  typedef typename _Iter::difference_type difference_type;
+
+  if (__first1._M_node != __last1._M_node)
+	{
+	  difference_type __len = __last2 - __first2;
+	  difference_type __flen
+	= std::min(__len, __first1._M_last - __first1._M_cur);
+	  if (int __ret = std::__lexicographical_compare_aux1(
+	  __first1._M_cur, __first1._M_last, __first2, __first2 + __flen))
+	return __ret;
+
+	  __first2 += __flen;
+	  __len -= __flen;
+	  __flen = std::min(__len, _Iter::_S_buffer_size());
+	  for (typename _Iter::_Map_pointer __node = __first1._M_node + 1;
+	   __node != __last1._M_node;
+	   __first2 += __flen, __len -= __flen,
+	   __flen = std::min(__len, _Iter::_S_buffer_size()),
+	   ++__node)
+	if (int __ret = std::__lexicographical_compare_aux1(
+		  *__node, *__node + _Iter::_S_buffer_size(),
+		  __first2, __first2 + __flen))
+	  return __ret;
+
+	  return std::__lexicographical_compare_aux1(
+	__last1._M_first, __last1._M_cur, __first2, __last2);
+	}
+
+  return std::__lexicographical_compare_aux1(
+	  __first1._M_cur, __last1._M_cur, __first2, __last2);
+}
+
+  template
+typename __gnu_cxx::__enable_if<
+  __is_random_access_iter<_II2>::__value, int>::__type
+__lexicographical_compare_aux1(
+		_GLIBCXX_STD_C::_Deque_iterator<_Tp1, _Ref1, _Ptr1> __first1,
+		_GLIBCXX_STD_C::_Deque_iterator<_Tp1, _Ref1, _Ptr1> __last1,
+		_II2 __first2, _II2 __last2)
+{ return std::__lex_cmp_dit(__first1, __last1, __first2, __last2); }
+
+  template
+int
+__lexicographical_compare_aux1(
+		_GLIBCXX_STD_C::_Deque_iterator<_Tp1, _Ref1, _Ptr1> __first1,
+		_GLIBCXX_STD_C::_Deque_iterator<_Tp1, _Ref1, _Ptr1> __last1,
+		_GLIBCXX_STD_C::_Deque_iterator<_Tp2, _Ref2, _Ptr2> __first2,
+		_GLIBCXX_STD_C::_Deque_iterator<_Tp2, _Ref2, _Ptr2> __last2)
+{ return std::__lex_cmp_dit(__first1, __last1, __first2, __last2); }
+
+  template
+typename __gnu_cxx::__enable_if<
+  __is_random_access_iter<_II1>::__value, int>::__type
+__lexicographical_compare_aux1(
+		_II1 __first1, _II1 __last1,
+		_GLIBCXX_STD_C::_Deque_iterator<_Tp2, _Ref2, _Ptr2> __first2,
+		_GLIBCXX_STD_C::_Deque_iterator<_Tp2, _Ref2, _Ptr2> __last2)
+{
+  typedef _G

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

2020-06-05 Thread Julian Brown
On Fri, 5 Jun 2020 12:39:46 +0200
Thomas Schwinge  wrote:

> Hi Julian!
> 
> On 2019-12-17T22:03:47-0800, Julian Brown 
> wrote:
> > This part contains the libgomp runtime support for the
> > GOMP_MAP_ATTACH and GOMP_MAP_DETACH mapping kinds  
> 
> > --- a/libgomp/oacc-mem.c
> > +++ b/libgomp/oacc-mem.c  
> 
> > @@ -1018,6 +1033,33 @@ goacc_exit_data_internal (struct
> > gomp_device_descr *acc_dev, size_t mapnum, {
> >gomp_mutex_lock (&acc_dev->lock);
> >  
> > +  /* Handle "detach" before copyback/deletion of mapped data.  */
> > +  for (size_t i = 0; i < mapnum; ++i)
> > +{
> > +  unsigned char kind = kinds[i] & 0xff;
> > +  switch (kind)
> > +   {
> > +   case GOMP_MAP_DETACH:
> > +   case GOMP_MAP_FORCE_DETACH:
> > + {
> > +   struct splay_tree_key_s cur_node;
> > +   uintptr_t hostaddr = (uintptr_t) hostaddrs[i];
> > +   cur_node.host_start = hostaddr;
> > +   cur_node.host_end = cur_node.host_start + sizeof (void
> > *);
> > +   splay_tree_key n
> > + = splay_tree_lookup (&acc_dev->mem_map, &cur_node);
> > +
> > +   if (n == NULL)
> > + gomp_fatal ("struct not mapped for detach
> > operation"); +
> > +   gomp_detach_pointer (acc_dev, aq, n, hostaddr,
> > finalize, NULL);
> > + }
> > + break;
> > +   default:
> > + ;
> > +   }
> > +}
> > +
> >for (size_t i = 0; i < mapnum; ++i)
> >  {
> >unsigned char kind = kinds[i] & 0xff;  
> 
> What's the reason that we're not instead emitting any 'detach'
> mappings in the expected order (that is, first), which would avoid
> this double-traversal here?  Given that 'mapnum' typically won't
> exceed the dozens, the code we now got doesn't have a big run-time
> cost, of course, but it's still a bit ugly, conceptually, for no
> apparent reason, unless I'm confused?

This is a weakness in the implementation -- the existing code in
gimplify.c that reorders clauses for GOMP_MAP_STRUCT, etc. is
sufficiently fiddly that I didn't want to mess with it. (I suppose
there's no reason the reordering needs to be done entirely in one pass,
though.)

Unfortunately that means (I now realise) that we're locked in
to supporting unordered detach clauses in libgomp going forwards anyway,
even if we fix the ordering in gimplify.c now.

Julian


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

2020-06-05 Thread Julian Brown
On Fri, 5 Jun 2020 13:17:09 +0200
Thomas Schwinge  wrote:

> Hi Julian!
> 
> On 2019-12-17T21:03:47-0800, Julian Brown 
> wrote:
> > This part contains the libgomp runtime support for the
> > GOMP_MAP_ATTACH and GOMP_MAP_DETACH mapping kinds  
> 
> > --- a/libgomp/target.c
> > +++ b/libgomp/target.c  
> 
> > @@ -1203,6 +1211,32 @@ gomp_map_vars_internal (struct
> > gomp_device_descr *devicep,  
> 
> > + case GOMP_MAP_ATTACH:
> > +   {
> > + cur_node.host_start = (uintptr_t) hostaddrs[i];
> > + cur_node.host_end = cur_node.host_start + sizeof
> > (void *);
> > + splay_tree_key n = splay_tree_lookup (mem_map,
> > &cur_node);
> > + if (n != NULL)
> > +   {
> > + tgt->list[i].key = n;
> > + tgt->list[i].offset = cur_node.host_start -
> > n->host_start;
> > + tgt->list[i].length = n->host_end -
> > n->host_start;
> > + tgt->list[i].copy_from = false;
> > + tgt->list[i].always_copy_from = false;
> > + tgt->list[i].do_detach
> > +   = (pragma_kind !=
> > GOMP_MAP_VARS_OPENACC_ENTER_DATA);
> > + n->refcount++;
> > +   }
> > + else
> > +   {
> > + gomp_mutex_unlock (&devicep->lock);
> > + gomp_fatal ("outer struct not mapped for
> > attach");
> > +   }
> > + gomp_attach_pointer (devicep, aq, mem_map, n,
> > +  (uintptr_t) hostaddrs[i],
> > sizes[i],
> > +  cbufp);
> > + continue;
> > +   }  
> 
> For the OpenACC runtime API 'acc_attach' etc. routines they don't, so
> what's the conceptual reason that for the corresponding OpenACC
> directive variants, 'GOMP_MAP_ATTACH' etc. here participate in
> reference counting ('n->refcount++' above)?  I understand OpenACC
> 'attach'/'detach' clauses to be simple "executable clauses", which
> just update some values somewhere (say, like
> 'GOMP_MAP_ALWAYS_POINTER'), but they don't alter any mapping state,
> thus wouldn't appear to need reference counting?

IIUC, n->refcount is not directly the "structural reference count" as
seen at source level, but rather counts the number of target_var_descs
in the lists appended to each target_mem_desc -- and GOMP_MAP_ATTACH
have variable entries in those lists. That's not the case for the API
routines.

Julian


[PATCH 1/2] c++: Improve access checking inside templates [PR41437]

2020-06-05 Thread Patrick Palka via Gcc-patches
This patch generalizes our existing functionality for deferring access
checking of typedefs when parsing a function or class template to now
defer all kinds of access checks until template instantiation time,
including member function and member object accesses.

Since all access checks eventually go through enforce_access, the main
component of this patch is new handling inside enforce_access to defer
the current access check if we're inside a template.  The bulk of the
rest of the patch consists of removing now-unneeded code pertaining to
suppressing access checks inside templates or pertaining to
typedef-specific access handling.  Renamings and other changes with no
functional impact have been split off into the followup patch.

Bootstrapped and regtested on x86_64-pc-linux-gnu, and also tested by
building parts of boost, cmcstl2 and other libraries.

gcc/cp/ChangeLog:

PR c++/41437
PR c++/47346
* call.c (enforce_access): Move to semantics.c.
* cp-tree.h (enforce_access): Delete.
(get_types_needing_access_check): Delete.
(add_typedef_to_current_template_for_access_check): Delete.
* decl.c (make_typename_type): Adjust accordingly.  Use
check_accessibility_of_qualified_id instead of directly using
perform_or_defer_access_check.
* parser.c (cp_parser_template_declaration_after_parameters):
Don't push a dk_no_check access state when parsing a template.
* pt.c (get_types_needing_access_check): Delete.
(append_type_to_template_for_access_check_1): Delete.
(perform_typedefs_access_check): Adjust.  If type_decl is a
FIELD_DECL, also check its DECL_CONTEXT for dependence. Use
tsubst_copy instead of tsubst to substitute into type_decl so
that we substitute into the DECL_CONTEXT of a FIELD_DECL.
(append_type_to_template_for_access_check): Delete.
* search.c (accessible_p): Remove the processing_template_decl
early exit.
* semantics.c (enforce_access): Moved from call.c.  If we're
parsing a template and the access check failed, add the check to
TI_TYPEDEFS_NEEDING_ACCESS_CHECKING.
(perform_or_defer_access_check): Adjust comment.
(add_typedef_to_current_template_for_access_check): Delete.
(check_accessibility_of_qualified_id):  Adjust accordingly.
Guard use of DECL_NONSTATIC_MEMBER_P so that we don't use it on
a USING_DECL with empty TREE_TYPE.  If the scope of the accessed
decl is not dependent but the qualifying scope, then still
proceed with the access check so that we defer it.

gcc/testsuite/ChangeLog:

PR c++/41437
PR c++/47346
* g++.dg/cpp2a/concepts-using2.C: Adjust.
* g++.dg/lto/20081219_1.C: Adjust.
* g++.dg/lto/20091002-1_0.C: Adjust.
* g++.dg/lto/pr65475c_0.C: Adjust.
* g++.dg/opt/dump1.C: Adjust.
* g++.dg/other/pr53574.C: Adjust.
* g++.dg/template/access30.C: New test.
* g++.dg/template/access31.C: New test.
* g++.dg/wrappers/wrapper-around-type-pack-expansion.C: Adjust.

libstdc++-v3/ChangeLog:

PR libstdc++/94003
* testsuite/20_util/is_constructible/94003.cc: New test.
---
 gcc/cp/call.c |  36 --
 gcc/cp/cp-tree.h  |   6 -
 gcc/cp/decl.c |   8 +-
 gcc/cp/parser.c   |   4 -
 gcc/cp/pt.c   | 120 +-
 gcc/cp/search.c   |  15 ---
 gcc/cp/semantics.c| 112 +---
 gcc/testsuite/g++.dg/cpp2a/concepts-using2.C  |   4 +-
 gcc/testsuite/g++.dg/lto/20081219_1.C |   2 +-
 gcc/testsuite/g++.dg/lto/20091002-1_0.C   |   2 +-
 gcc/testsuite/g++.dg/lto/pr65475c_0.C |   3 +
 gcc/testsuite/g++.dg/opt/dump1.C  |   2 +-
 gcc/testsuite/g++.dg/other/pr53574.C  |   2 +-
 gcc/testsuite/g++.dg/template/access30.C  |  10 ++
 gcc/testsuite/g++.dg/template/access31.C  |  29 +
 .../wrapper-around-type-pack-expansion.C  |   2 +-
 .../20_util/is_constructible/94003.cc |  28 
 17 files changed, 150 insertions(+), 235 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/template/access30.C
 create mode 100644 gcc/testsuite/g++.dg/template/access31.C
 create mode 100644 libstdc++-v3/testsuite/20_util/is_constructible/94003.cc

diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index 2b393f96e5b..24888f0f712 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -7081,42 +7081,6 @@ complain_about_access (tree decl, tree diag_decl, bool 
issue_error)
 }
 }
 
-/* If the current scope isn't allowed to access DECL along
-   BASETYPE_PATH, give an error.  The most derived class in
-   BASETYPE_PATH is the one used to qualify DECL. DIAG_DECL is
-   the declaration to use in the error diagnostic.  */
-
-bool
-enfor

Re: [PATCH 5/6] rs6000, Add vector splat builtin support

2020-06-05 Thread Segher Boessenkool
Hi!

On Mon, Jun 01, 2020 at 09:15:00AM -0700, Carl Love wrote:
> The following patch adds support for the vec_splati, vec_splatid and
> vec_splati_ins builtins.

> * config/rs6000/altivec.h: Add define for vec_splati,
> vec_splatid
> and vec_splati_ins.

* config/rs6000/altivec.h (vec_splati, vec_splatid, vec_splati_ins):
New defines.

Etc.


> +(define_insn "vxxspltiw_v4si"
> +  [(set (match_operand:V4SI 0 "register_operand" "=wa")
> + (unspec:V4SI [(match_operand:SI 1 "s32bit_cint_operand" "n")]
> +  UNSPEC_XXSPLTIW))]
> + "TARGET_FUTURE"
> + "xxspltiw %x0,%1"
> + [(set_attr "type" "vecsimple")])

I think we can do a nicer name than "vxx"?  The mode is part of the name
already, so that says it is vector?  And the exact insn used is not
usually something you want in the name.

Maybe just "splat_imm_v4si" or similar?  What do we do for the existing
immediate splats, hrm.  ...  Yeah, similar to what you do, so let's
just go with that for now...  But "xx", not "vxx"?

> +  /* Instruction uses destination as a source.  Do not overwrite
> source.  */

(Your patches line-wrapped in the mail, btw.)

> +   emit_move_insn (operands[0], operands[1]);
> +   emit_insn (gen_vxxsplti32dx_v4sf_inst (operands[0], GEN_INT( index
> ),

No spaces around "index" please.  But there should be a space before the
opening parenthesis.

> +;; Return 1 if op is a 32-bit constant signed integer
> +(define_predicate "s32bit_cint_operand"
> +  (and (match_code "const_int")
> +   (match_test "INTVAL (op) >= -2147483648
> +  && INTVAL (op) <= 2147483647")))

There probably is a nicer way to write this than with big decimal
numbers.  (I'll not suggest one here because I'll just make a fool of
myself with overflow or signed/unsigned etc. :-) )

> +;; Return 1 if op is a constant 32-bit signed or unsigned integer
> +(define_predicate "c32bit_cint_operand"
> +  (and (match_code "const_int")
> +   (match_test "((INTVAL (op) >> 32) == 0)")))

This does not work for negative 32-bit numbers?  In GCC the LHS
expression is -1 for those...  Not sure what it is for the C++11 we now
require, but in C11 it is implementation-defined, so not good either.

> +;; Return 1 if op is a constant 32-bit floating point value
> +(define_predicate "f32bit_const_operand"
> +  (match_code "const_double"))

Either the predicate name is misleading (if you do allow all
const_double values), or there should be some test for the alloed values
here.

> +extern long long rs6000_constF32toI32 (rtx operand);

Please use rs6000_const_f32_to_i32 or similar, or a more meaningful
name (neither "f32" nor "i32" means anything in GCC).

const_float_as_integer?  Something like that?

> +long long
> +rs6000_constF32toI32 (rtx operand)
> +{
> +  long long value;
> +  const struct real_value *rv = CONST_DOUBLE_REAL_VALUE (operand);
> +
> +  if (GET_MODE (operand) != SFmode)
> +{
> +  printf("ERROR, rs6000_constF32toI32 mode not equal to
> SFmode.\n");

Let's not have the printf :-)

> +  gcc_unreachable ();

Is the gcc_unreachable still useful?  If so, write it as

  gcc_assert (GET_MODE (operand) == SFmode);

?  And if not, just drop it :-)

> +@smallexample
> +@exdent vector double vec_splatid (const float);
> +@end smallexample
> +
> +Convert a floating-point value to double-precision and splat the
> result to a
> +vector of double-precision floats.

You probably should say the floating-point value you start with is
single precision.


Segher


[PATCH 2/2] c++: Clean up previous change [PR41437]

2020-06-05 Thread Patrick Palka via Gcc-patches
The previous patch mostly avoided making any changes that had no
functional impact, such as adjusting now-outdated comments and
performing renamings.  Such changes have been consolidated to this
followup patch for easier review.

The main change here is that we now reuse struct deferred_access_check
as the element type of the vector TI_TYPEDEFS_NEEDING_ACCESS_CHECKING
(now renamed to TI_DEFERRED_ACCESS_CHECKS, since it now may contain all
kinds of access checks).

gcc/cp/ChangeLog:

PR c++/41437
PR c++/47346
* cp-tree.h (qualified_typedef_usage_s): Delete.
(qualified_typedef_usage_t): Delete.
(deferred_access_check): Move up in file.
(tree_template_info::typedefs_needing_access_checking): Delete.
(tree_template_info::deferred_access_checks): New field.
(TI_TYPEDEFS_NEEDING_ACCESS_CHECKING): Rename to ...
(TI_DEFERRED_ACCESS_CHECKS): ... this, and adjust accordingly.
* pt.c (perform_typedefs_access_check): Rename to ...
(perform_instantiation_time_access_checks): ... this, and adjust
accordingly.  Remove unnecessary tree tests.
(instantiate_class_template_1): Adjust accordingly.
(instantiate_decl): Likewise.
* semantics.c (enforce_access): Adjust to build up a
deferred_access_check.
---
 gcc/cp/cp-tree.h   | 58 +++
 gcc/cp/pt.c| 61 +-
 gcc/cp/semantics.c | 12 -
 3 files changed, 48 insertions(+), 83 deletions(-)

diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index 771d51cc283..50d83add458 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -1449,27 +1449,6 @@ struct GTY (()) tree_lambda_expr
   int discriminator;
 };
 
-/* A (typedef,context,usage location) triplet.
-   It represents a typedef used through a
-   context at a given source location.
-   e.g.
-   struct foo {
- typedef int myint;
-   };
-
-   struct bar {
-foo::myint v; // #1<-- this location.
-   };
-
-   In bar, the triplet will be (myint, foo, #1).
-   */
-struct GTY(()) qualified_typedef_usage_s {
-  tree typedef_decl;
-  tree context;
-  location_t locus;
-};
-typedef struct qualified_typedef_usage_s qualified_typedef_usage_t;
-
 /* Non-zero if this template specialization has access violations that
should be rechecked when the function is instantiated outside argument
deduction.  */
@@ -1489,11 +1468,24 @@ typedef struct qualified_typedef_usage_s 
qualified_typedef_usage_t;
 #define TINFO_VAR_DECLARED_CONSTINIT(NODE) \
   (TREE_LANG_FLAG_2 (TEMPLATE_INFO_CHECK (NODE)))
 
+/* The representation of a deferred access check.  */
+
+struct GTY(()) deferred_access_check {
+  /* The base class in which the declaration is referenced. */
+  tree binfo;
+  /* The declaration whose access must be checked.  */
+  tree decl;
+  /* The declaration that should be used in the error message.  */
+  tree diag_decl;
+  /* The location of this access.  */
+  location_t loc;
+};
+
 struct GTY(()) tree_template_info {
   struct tree_base base;
   tree tmpl;
   tree args;
-  vec *typedefs_needing_access_checking;
+  vec *deferred_access_checks;
 };
 
 // Constraint information for a C++ declaration. Constraint information is
@@ -3532,14 +3524,15 @@ struct GTY(()) lang_decl {
   ? int_cst_value (NON_DEFAULT_TEMPLATE_ARGS_COUNT (NODE)) \
   : TREE_VEC_LENGTH (INNERMOST_TEMPLATE_ARGS (NODE))
 #endif
-/* The list of typedefs - used in the template - that need
-   access checking at template instantiation time.
+
+/* The list of access checks that were deferred during parsing
+   which need to be performed at template instantiation time.
 
FIXME this should be associated with the TEMPLATE_DECL, not the
TEMPLATE_INFO.  */
-#define TI_TYPEDEFS_NEEDING_ACCESS_CHECKING(NODE) \
+#define TI_DEFERRED_ACCESS_CHECKS(NODE) \
   ((struct tree_template_info*)TEMPLATE_INFO_CHECK \
- (NODE))->typedefs_needing_access_checking
+ (NODE))->deferred_access_checks
 
 /* We use TREE_VECs to hold template arguments.  If there is only one
level of template arguments, then the TREE_VEC contains the
@@ -7090,19 +7083,6 @@ extern int shared_member_p   (tree);
 extern bool any_dependent_bases_p (tree = current_nonlambda_class_type ());
 extern bool maybe_check_overriding_exception_spec (tree, tree);
 
-/* The representation of a deferred access check.  */
-
-struct GTY(()) deferred_access_check {
-  /* The base class in which the declaration is referenced. */
-  tree binfo;
-  /* The declaration whose access must be checked.  */
-  tree decl;
-  /* The declaration that should be used in the error message.  */
-  tree diag_decl;
-  /* The location of this access.  */
-  location_t loc;
-};
-
 /* in semantics.c */
 extern void push_deferring_access_checks   (deferring_kind);
 extern void resume_deferring_access_checks (void);
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index be319c50783..142392224c6 10064

[committed] d: Merge upstream dmd 740f3d1ea.

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

This patch merges the D front-end implementation with upstream dmd
740f3d1ea.  Backports the conversion of the parameter fields debugids
and versionids to Identifiers.  The idea is that Identifiers should be
used instead of C strings where ever possible.

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

Regards
Iain.


gcc/d/ChangeLog:

* dmd/MERGE: Merge upstream dmd 740f3d1ea.
* d-lang.cc (d_handle_option): Use new fields to save debug and
version levels passed over command-line.
(d_post_options): Add them to front-end here.
---
 gcc/d/d-lang.cc  | 31 +++
 gcc/d/dmd/MERGE  |  2 +-
 gcc/d/dmd/cond.c | 40 +++-
 gcc/d/dmd/cond.h |  4 +---
 gcc/d/dmd/dversion.c |  8 
 gcc/d/dmd/globals.h  |  3 +++
 gcc/d/dmd/module.h   |  8 
 7 files changed, 55 insertions(+), 41 deletions(-)

diff --git a/gcc/d/d-lang.cc b/gcc/d/d-lang.cc
index 203039e9ecf..54d5799e59c 100644
--- a/gcc/d/d-lang.cc
+++ b/gcc/d/d-lang.cc
@@ -443,14 +443,16 @@ d_handle_option (size_t scode, const char *arg, 
HOST_WIDE_INT value,
  int level = integral_argument (arg);
  if (level != -1)
{
- DebugCondition::setGlobalLevel (level);
+ global.params.debuglevel = level;
  break;
}
}
 
   if (Identifier::isValidIdentifier (CONST_CAST (char *, arg)))
{
- DebugCondition::addGlobalIdent (arg);
+ if (!global.params.debugids)
+   global.params.debugids = new Strings ();
+ global.params.debugids->push (arg);
  break;
}
 
@@ -582,14 +584,16 @@ d_handle_option (size_t scode, const char *arg, 
HOST_WIDE_INT value,
  int level = integral_argument (arg);
  if (level != -1)
{
- VersionCondition::setGlobalLevel (level);
+ global.params.versionlevel = level;
  break;
}
}
 
   if (Identifier::isValidIdentifier (CONST_CAST (char *, arg)))
{
- VersionCondition::addGlobalIdent (arg);
+ if (!global.params.versionids)
+   global.params.versionids = new Strings ();
+ global.params.versionids->push (arg);
  break;
}
 
@@ -812,6 +816,25 @@ d_post_options (const char ** fn)
   /* Has no effect yet.  */
   global.params.pic = flag_pic != 0;
 
+  /* Add in versions given on the command line.  */
+  if (global.params.versionids)
+{
+  for (size_t i = 0; i < global.params.versionids->length; i++)
+   {
+ const char *s = (*global.params.versionids)[i];
+ VersionCondition::addGlobalIdent (s);
+   }
+}
+
+  if (global.params.debugids)
+{
+  for (size_t i = 0; i < global.params.debugids->length; i++)
+   {
+ const char *s = (*global.params.debugids)[i];
+ DebugCondition::addGlobalIdent (s);
+   }
+}
+
   if (warn_return_type == -1)
 warn_return_type = 0;
 
diff --git a/gcc/d/dmd/MERGE b/gcc/d/dmd/MERGE
index 3248bf7c982..540801d1d44 100644
--- a/gcc/d/dmd/MERGE
+++ b/gcc/d/dmd/MERGE
@@ -1,4 +1,4 @@
-f5638c7b8a6912858a9b51987df6a725e6796dc9
+740f3d1eab81d88d11451083d955d5075f60d4e0
 
 The first line of this file holds the git revision number of the last
 merge done from the dlang/dmd repository.
diff --git a/gcc/d/dmd/cond.c b/gcc/d/dmd/cond.c
index 88febdf5e1e..53c5499f158 100644
--- a/gcc/d/dmd/cond.c
+++ b/gcc/d/dmd/cond.c
@@ -29,15 +29,15 @@
 Expression *semantic(Expression *e, Scope *sc);
 bool evalStaticCondition(Scope *sc, Expression *exp, Expression *e, bool 
&errors);
 
-int findCondition(Strings *ids, Identifier *ident)
+int findCondition(Identifiers *ids, Identifier *ident)
 {
 if (ids)
 {
 for (size_t i = 0; i < ids->length; i++)
 {
-const char *id = (*ids)[i];
+Identifier *id = (*ids)[i];
 
-if (strcmp(id, ident->toChars()) == 0)
+if (id == ident)
 return true;
 }
 }
@@ -391,16 +391,11 @@ Condition *DVCondition::syntaxCopy()
 
 /*  */
 
-void DebugCondition::setGlobalLevel(unsigned level)
-{
-global.params.debuglevel = level;
-}
-
 void DebugCondition::addGlobalIdent(const char *ident)
 {
-if (!global.params.debugids)
-global.params.debugids = new Strings();
-global.params.debugids->push(ident);
+if (!global.debugids)
+global.debugids = new Identifiers();
+global.debugids->push(Identifier::idPool(ident));
 }
 
 
@@ -444,12 +439,12 @@ int DebugCondition::include(Scope *sc)
 inc = 1;
 definedInModule = true;
 }
-else if (findCondition(global.params.debugids, ident))
+else if (findCondition(global.debugids, ident))
 inc = 1;
 else
 {   if (!mod->debugid

Re: [PATCH 2/7] [OpenACC] Adjust dynamic reference count semantics

2020-06-05 Thread Julian Brown
On Wed, 3 Jun 2020 17:19:47 +0200
Thomas Schwinge  wrote:

> Hi Julian!
> 
> On 2020-06-03T14:36:14+0200, I wrote:
> > On 2020-05-22T15:16:05-0700, Julian Brown 
> > wrote:  
> >> This patch adjusts the semantics of dynamic reference counts, as
> >> described in the parent email.  
> >
> > Thanks!
> >
> > A few questions, but no need to send an updated patch.
> >  
> >> --- a/libgomp/oacc-mem.c
> >> +++ b/libgomp/oacc-mem.c  
> >  
> >> @@ -1018,13 +1036,102 @@ goacc_enter_data_internal (struct
> >> gomp_device_descr *acc_dev, size_t mapnum, {
> >>for (size_t i = 0; i < mapnum; i++)
> >>  {
> >> -  int group_last = find_group_last (i, mapnum, sizes, kinds);
> >> +  splay_tree_key n;
> >> +  size_t group_last = find_group_last (i, mapnum, sizes,
> >> kinds);
> >> +  bool struct_p = false;
> >> +  size_t size, groupnum = (group_last - i) + 1;
> >>  
> >> -  gomp_map_vars_async (acc_dev, aq,
> >> - (group_last - i) + 1,
> >> - &hostaddrs[i], NULL,
> >> - &sizes[i], &kinds[i], true,
> >> - GOMP_MAP_VARS_OPENACC_ENTER_DATA);
> >> +  switch (kinds[i] & 0xff)
> >> +  {
> >> +  case GOMP_MAP_STRUCT:
> >> +{
> >> +  int last = i + sizes[i];  
> >
> > The 'last' calculated here must always equal the 'group_last'
> > calculated above.  ;-) (... so we might just use 'group_last'
> > instead of 'last' in the following.)
> >  
> >> +  size = (uintptr_t) hostaddrs[last] + sizes[last]
> >> + - (uintptr_t) hostaddrs[i];
> >> +  struct_p = true;
> >> +}
> >> +break;
> >> +
> >> +  case GOMP_MAP_ATTACH:
> >> +size = sizeof (void *);
> >> +break;
> >> +
> >> +  default:
> >> +size = sizes[i];
> >> +  }
> >> +
> >> +  n = lookup_host (acc_dev, hostaddrs[i], size);
> >> +  
> >  
> >> +  if (n && struct_p)
> >> +  {
> >> +if (n->refcount != REFCOUNT_INFINITY)
> >> +  n->refcount += groupnum - 1;
> >> +n->dynamic_refcount += groupnum - 1;
> >> +gomp_mutex_unlock (&acc_dev->lock);
> >> +  }  
> >
> > Is the 'GOMP_MAP_STRUCT' handling here specifically necessary, or
> > is that just an optimization of the 'n && groupnum > 1' case below?
> >  
> 
> Eh, OK, I think I see where this is going; the 'n && groupnum > 1'
> case below might not necessarily take care of the 'groupnum - 1'
> refcounts that we're filing here?

Right. GOMP_MAP_STRUCT is a little special in this case.

> >> +  else if (n && groupnum == 1)
> >> +  {
> >> +void *h = hostaddrs[i];
> >> +size_t s = sizes[i];
> >> +
> >> +/* A standalone attach clause.  */
> >> +if ((kinds[i] & 0xff) == GOMP_MAP_ATTACH)
> >> +  gomp_attach_pointer (acc_dev, aq, &acc_dev->mem_map,
> >> n,
> >> +   (uintptr_t) h, s, NULL);
> >> +else if (h + s > (void *) n->host_end)
> >> +  {
> >> +gomp_mutex_unlock (&acc_dev->lock);
> >> +gomp_fatal ("[%p,+%d] not mapped", (void *)h,
> >> (int)s);
> >> +  }
> >> +
> >> +assert (n->refcount != REFCOUNT_LINK);
> >> +if (n->refcount != REFCOUNT_INFINITY)
> >> +  n->refcount++;
> >> +n->dynamic_refcount++;
> >> +
> >> +gomp_mutex_unlock (&acc_dev->lock);
> >> +  }  
> >  
> >> +  else if (n && groupnum > 1)
> >> +  {
> >> +assert (n->refcount != REFCOUNT_INFINITY
> >> +&& n->refcount != REFCOUNT_LINK);
> >> +
> >> +bool processed = false;
> >> +
> >> +struct target_mem_desc *tgt = n->tgt;
> >> +for (size_t j = 0; j < tgt->list_count; j++)
> >> +  if (tgt->list[j].key == n)
> >> +{
> >> +  for (size_t k = 0; k < groupnum; k++)
> >> +if (j + k < tgt->list_count && tgt->list[j +
> >> k].key)
> >> +  {
> >> +tgt->list[j + k].key->refcount++;
> >> +tgt->list[j + k].key->dynamic_refcount++;
> >> +  }
> >> +  processed = true;
> >> +}
> >> +
> >> +gomp_mutex_unlock (&acc_dev->lock);
> >> +if (!processed)
> >> +  gomp_fatal ("dynamic refcount incrementing failed for
> >> "
> >> +  "pointer/pset");
> >> +  }  
> >
> > Please add some text to explain the nested 'j', 'k' loops and their
> > 'if' conditionals, and the 'groupnum' usage in the 'k' loop
> > boundary.  Should the 'k' loop maybe run 'for (size_t k = j; k <
> > tgt->list_count; ++k)' (..., or is 'groupnum' relevant?), and in
> > the loop body then use 'k' instead of 'j + k'?  (Maybe I've now
> > confused myself, staring at this for a while...)  
> 
> Audacious as I am sometimes, I did put a '__builtin_abort' right after
> 'tgt->list[j].key == n' -- and it doesn't trigger one single time for
> the current libgomp test cases, meaning this is all dead code?  I'm
> confused.

Huh, I didn't expect that! Indeed that stanza appears to be dead code
(at least with mapping clauses generated from current GCC). The reason
is a late bug-fix to the manual deep copy code that str

Re: [PATCH 6/6] rs6000 Add vector blend, permute builtin support

2020-06-05 Thread Segher Boessenkool
Hi!

On Mon, Jun 01, 2020 at 09:15:06AM -0700, Carl Love wrote:
> The following patch adds support for the vec_blendv and vec_permx
> builtins.

Pretty interesting insns ;-)

> * config/rs6000/altivec.h: Add define for vec_blendv and
> vec_permx.
> * config/rs6000/altivec.md: Add unspec UNSPEC_XXBLEND,
> UNSPEC_XXPERMX.

Similar as the other patches.

> New define_mode VM3.

(VM3): New mode iterator.

(Etc.)

>   * config/rs6000/rs6000-c.c:
> (altivecaltivec_resolve_overloaded_builtin):

Duplicated "altivec".

> +  /* Need vec char with each element = 255, is there a better
> way?  */

Yes, just splat -1 (in any mode, vplti*), or byte 0xff (xxspltib).
There probably are some utility functions to create those?

> +  /* Reverse value of byte element index eidx by subracting bits
> [3:7] of
> +  each operand[3] element from 31.  Swap order of operands so
> indexing
> +  will be correct.  Reverse the 32-byte section identifier match
> by
> +  subracting bits [0:2] of elemet from 7.  */

Hrm, you could xor every index with 0x1f?  That can often simplify with
whatever sets the mask...

> +   emit_insn (gen_altivec_vsubsbs (tmp, vreg, operands[3]));

... but this cannot, it is an unspec (saturating subtract).

> +  else if (icode == CODE_FOR_xxpermx)
> +{
> +  /* Only allow 8-bit unsigned literals.  */
> +  STRIP_NOPS (arg3);
> +  if (TREE_CODE (arg3) != INTEGER_CST
> +   || TREE_INT_CST_LOW (arg3) & ~0xff)
> + {
> +   error ("argument 4 must be an 8-bit unsigned literal");
> +   return CONST0_RTX (tmode);
> + }
> +}

I think it should be a 3-bit constant, instead?

> +Vector Blend Variable

> +Blend the first and second argument vectors according to the sign bits
> of the
> +corresponding elements of the third argument vector.

Maybe it should say it is related to vsel/xxsel, but per bigger element?

> +@findex vec_vlendv

(typo).

> +Vector Permute Extendedextracth

Stray "extracth"?

> +Perform a partial permute of the first two arguments, which form a 32-
> byte
> +section of an emulated vector up to 256 bytes wide, using the partial
> permute
> +control vector in the third argument.  The fourth argument
> (constrained to
> +values of 0-7) identifies which 32-byte section of the emulated vector
> is
> +contained in the first two arguments.
> +@findex vec_permx

Maybe say that the elements not corresponding to that section are set
to 0?

> +++ b/gcc/testsuite/gcc.target/powerpc/vec-blend-runnable.c

> +/* { dg-final { scan-assembler-times {\msplati\M} 6 } } */
> +/* { dg-final { scan-assembler-times {\msrdbi\M} 6 } } */

These do not work like this?  Some v or xx splti*, and vsrdbi?

Thanks!


Segher


Re: [PATCH] PowerPC: Add future hwcap2 bits

2020-06-05 Thread Segher Boessenkool
Hi!

On Thu, Jun 04, 2020 at 10:11:29PM -0400, Michael Meissner wrote:
> This patch adds support for the two new HWCAP2 fields used by the
> __builtin_cpu_supports function.  It adds support in the target_clones
> attribute for -mcpu=future.

> --- a/gcc/config/rs6000/rs6000-call.c
> +++ b/gcc/config/rs6000/rs6000-call.c
> @@ -172,7 +172,9 @@ static const struct
>{ "arch_3_00", PPC_FEATURE2_ARCH_3_00, 1 },
>{ "ieee128",   PPC_FEATURE2_HAS_IEEE128,   1 },
>{ "darn",  PPC_FEATURE2_DARN,  1 },
> -  { "scv",   PPC_FEATURE2_SCV,   1 }
> +  { "scv",   PPC_FEATURE2_SCV,   1 },
> +  { "arch_3_1",  PPC_FEATURE2_ARCH_3_1,  1 },
> +  { "mma",   PPC_FEATURE2_MMA,   1 },
>  };

Does the trailing comma not warn?  Okay if not.

> diff --git a/gcc/testsuite/gcc.target/powerpc/clone3.c 
> b/gcc/testsuite/gcc.target/powerpc/clone3.c
> new file mode 100644
> index 000..93ee41d
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/powerpc/clone3.c
> @@ -0,0 +1,33 @@
> +/* { dg-do compile { target { powerpc*-*-linux* && lp64 } } } */
> +/* { dg-options "-mdejagnu-cpu=power8 -O2" } */
> +/* { dg-require-effective-target powerpc_pcrel } */
> +/* { dg-require-effective-target ppc_cpu_supports_hw } */
> +
> +/* Power9 (aka, ISA 3.0) has a MODSD instruction to do modulus, while Power8
> +   (aka, ISA 2.07) has to do modulus with divide and multiply.  Make sure
> +   both clone functions are generated.
> +
> +   FUTURE has pc-relative instructions to access static values, while earlier
> +   systems used TOC addressing.
> +
> +   Restrict ourselves to Linux, since IFUNC might not be supported in other
> +   operating systems.  */
> +
> +static long s;
> +long *p = &s;
> +
> +__attribute__((target_clones("cpu=future,cpu=power9,default")))
> +long mod_func (long a, long b)
> +{
> +  return (a % b) + s;
> +}
> +
> +long mod_func_or (long a, long b, long c)
> +{
> +  return mod_func (a, b) | c;
> +}
> +
> +/* { dg-final { scan-assembler-times {\mdivd\M}  1 } } */
> +/* { dg-final { scan-assembler-times {\mmulld\M} 1 } } */
> +/* { dg-final { scan-assembler-times {\mmodsd\M} 2 } } */
> +/* { dg-final { scan-assembler-times {\mpld\M}   1 } } */

This needs some more documentation what it tests, and how.

And/or maybe the  dg-require-effective-target powerpc_pcrel  shouldn't
be there?

Okay for trunk with those two things cleared up.  Thanks!


Segher


[PATCH] Add C++2a synchronization support

2020-06-05 Thread Thomas Rodgers
Add support for -
atomic wait/notify_one/notify_all
counting_semaphore
binary_semaphore
latch

* include/Makefile.am (bits_headers): Add new header.
* include/Makefile.in: Regenerate.
* include/bits/atomic_base.h (__atomic_base<_Itp>::wait): Define.
(__atomic_base<_Itp>::notify_one): Likewise.
(__atomic_base<_Itp>::notify_all): Likewise.
(__atomic_base<_Ptp*>::wait): Likewise.
(__atomic_base<_Ptp*>::notify_one): Likewise.
(__atomic_base<_Ptp*>::notify_all): Likewise.
(__atomic_impl::wait): Likewise.
(__atomic_impl::notify_one): Likewise.
(__atomic_impl::notify_all): Likewise.
(__atomic_float<_Fp>::wait): Likewise.
(__atomic_float<_Fp>::notify_one): Likewise.
(__atomic_float<_Fp>::notify_all): Likewise.
(__atomic_ref<_Tp>::wait): Likewise.
(__atomic_ref<_Tp>::notify_one): Likewise.
(__atomic_ref<_Tp>::notify_all): Likewise.
(atomic_wait<_Tp>): Likewise.
(atomic_wait_explicit<_Tp>): Likewise.
(atomic_notify_one<_Tp>): Likewise.
(atomic_notify_all<_Tp>): Likewise.
* include/bits/atomic_wait.h: New file.
* include/bits/atomic_timed_wait.h: New file.
* include/bits/semaphore_base.h: New file.
* include/std/atomic (atomic::wait): Define.
(atomic::wait_one): Likewise.
(atomic::wait_all): Likewise.
(atomic<_Tp>::wait): Likewise.
(atomic<_Tp>::wait_one): Likewise.
(atomic<_Tp>::wait_all): Likewise.
(atomic<_Tp*>::wait): Likewise.
(atomic<_Tp*>::wait_one): Likewise.
(atomic<_Tp*>::wait_all): Likewise.
* include/std/latch: New file.
* include/std/semaphore: New file.
* include/std/version: Add __cpp_lib_semaphore and
__cpp_lib_latch defines.
* testsuite/29_atomic/atomic/wait_notify/atomic_refs.cc: New test.
* testsuite/29_atomic/atomic/wait_notify/bool.cc: Likewise.
* testsuite/29_atomic/atomic/wait_notify/integrals.cc: Likewise.
* testsuite/29_atomic/atomic/wait_notify/floats.cc: Likewise.
* testsuite/29_atomic/atomic/wait_notify/pointers.cc: Likewise.
* testsuite/29_atomic/atomic/wait_notify/generic.h: New File.
* testsuite/30_thread/semaphore/1.cc: New test.
* testsuite/30_thread/semaphore/2.cc: Likewise.
* testsuite/30_thread/semaphore/least_max_value_neg.cc: Likewise.
* testsuite/30_thread/semaphore/try_acquire.cc: Likewise.
* testsuite/30_thread/semaphore/try_acquire_for.cc: Likewise.
* testsuite/30_thread/semaphore/try_acquire_futex.cc: Likewise.
* testsuite/30_thread/semaphore/try_acquire_posix.cc: Likewise.
* testsuite/30_thread/semaphore/try_acquire_until.cc: Likewise.
* testsuite/30_thread/latch/1.cc: New test.
* testsuite/30_thread/latch/2.cc: New test.
* testsuite/30_thread/latch/3.cc: New test.
---
 libstdc++-v3/include/Makefile.am  |   5 +
 libstdc++-v3/include/Makefile.in  |   5 +
 libstdc++-v3/include/bits/atomic_base.h   | 161 +-
 libstdc++-v3/include/bits/atomic_timed_wait.h | 282 +
 libstdc++-v3/include/bits/atomic_wait.h   | 291 ++
 libstdc++-v3/include/bits/semaphore_base.h| 272 
 libstdc++-v3/include/std/atomic   |  61 
 libstdc++-v3/include/std/latch|  90 ++
 libstdc++-v3/include/std/semaphore|  86 ++
 libstdc++-v3/include/std/version  |   2 +
 .../atomic/wait_notify/atomic_refs.cc | 103 +++
 .../29_atomics/atomic/wait_notify/bool.cc |  59 
 .../29_atomics/atomic/wait_notify/floats.cc   |  32 ++
 .../29_atomics/atomic/wait_notify/generic.h   |  88 ++
 .../atomic/wait_notify/integrals.cc   |  56 
 .../29_atomics/atomic/wait_notify/pointers.cc |  59 
 libstdc++-v3/testsuite/30_threads/latch/1.cc  |  27 ++
 libstdc++-v3/testsuite/30_threads/latch/2.cc  |  27 ++
 libstdc++-v3/testsuite/30_threads/latch/3.cc  |  50 +++
 .../testsuite/30_threads/semaphore/1.cc   |  27 ++
 .../testsuite/30_threads/semaphore/2.cc   |  27 ++
 .../semaphore/least_max_value_neg.cc  |  28 ++
 .../30_threads/semaphore/try_acquire.cc   |  55 
 .../30_threads/semaphore/try_acquire_for.cc   |  85 +
 .../30_threads/semaphore/try_acquire_futex.cc |  51 +++
 .../30_threads/semaphore/try_acquire_posix.cc | 169 ++
 .../30_threads/semaphore/try_acquire_until.cc |  94 ++
 27 files changed, 2291 insertions(+), 1 deletion(-)
 create mode 100644 libstdc++-v3/include/bits/atomic_timed_wait.h
 create mode 100644 libstdc++-v3/include/bits/atomic_wait.h
 create mode 100644 libstdc++-v3/include/bits/semaphore_base.h
 create mode 100644 libstdc++-v3/include/std/latch
 create mode 100644 libstdc++-v3/include/std/semaphore
 create mode 100644 
libstdc++-v3/

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

2020-06-05 Thread Jason Merrill via Gcc-patches
The problem in this testcase comes from cloning the constructor into
complete and base variants.  When we clone the body the first time,
walk_tree_1 calls copy_tree_body_r on the type of the artificial TYPE_DECL
we made for the VLA type without calling it on the decl itself, so we
overwrite the type of the TYPE_DECL without copying the decl first.

This has been broken since we started inserting a TYPE_DECL for anonymous
VLAs in r7-457.

This patch fixes walk_tree_1 to call the function on the TYPE_DECL, as we do
for other decls of a DECL_EXPR.

Tested x86_64-pc-linux-gnu.  OK for trunk?  Release branches?

gcc/ChangeLog:

PR c++/95552
* tree.c (walk_tree_1): Call func on the TYPE_DECL of a DECL_EXPR.

gcc/testsuite/ChangeLog:

PR c++/95552
* g++.dg/ext/vla23.C: New test.
---
 gcc/testsuite/g++.dg/ext/vla23.C | 14 ++
 gcc/tree.c   |  5 +
 2 files changed, 19 insertions(+)
 create mode 100644 gcc/testsuite/g++.dg/ext/vla23.C

diff --git a/gcc/testsuite/g++.dg/ext/vla23.C b/gcc/testsuite/g++.dg/ext/vla23.C
new file mode 100644
index 000..317a824b2f3
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ext/vla23.C
@@ -0,0 +1,14 @@
+// PR c++/95552
+// Test for VLA and cloned constructor.
+// { dg-additional-options -Wno-vla }
+// { dg-require-effective-target alloca }
+
+struct VB { };
+struct ViewDom: virtual VB
+{
+  ViewDom(int i) { char (*a)[i]; }
+};
+void element( )
+{
+  ViewDom a(2);
+}
diff --git a/gcc/tree.c b/gcc/tree.c
index 7197b4720ce..c8e9680b06c 100644
--- a/gcc/tree.c
+++ b/gcc/tree.c
@@ -12212,6 +12212,11 @@ walk_tree_1 (tree *tp, walk_tree_fn func, void *data,
 Note that DECLs get walked as part of processing the BIND_EXPR.  */
   if (TREE_CODE (DECL_EXPR_DECL (*tp)) == TYPE_DECL)
{
+ /* Call the function for the decl so e.g. inlining can remap it.  */
+ result = (*func) (&DECL_EXPR_DECL (*tp), &walk_subtrees, data);
+ if (result || !walk_subtrees)
+   return result;
+
  tree *type_p = &TREE_TYPE (DECL_EXPR_DECL (*tp));
  if (TREE_CODE (*type_p) == ERROR_MARK)
return NULL_TREE;

base-commit: 5bc13e5217f687f5d08a7022b4c6081befc54402
-- 
2.18.1



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

2020-06-05 Thread Richard Biener
On June 5, 2020 6:38:10 PM GMT+02:00, Eric Botcazou  
wrote:
>> I've installed it on trunk but will give it quite a while there
>before
>> backporting.  I'm still somewhat worried about the
>> 
>>   /* ???  If we end up with a constant or a descriptor do not
>>  record a MEM_EXPR.  */
>>   else if (CONSTANT_CLASS_P (t)
>> 
>>|| TREE_CODE (t) == CONSTRUCTOR)
>> 
>> ;
>> 
>> case, maybe we should assert that bitpos == 0 here since we're
>> dropping it on the floor but eventually inherit offset_known_p ==
>true
>> from the already present MEM_ATTRs.
>
>It's hard to imagine without a testcase how you can end up inheriting
>anything 
>for CONSTANT_CLASS_P or CONSTRUCTOR though: where do the MEM_ATTRs come
>from? 

For constructor it was constant descriptors seen during ada bootstrap. I can 
imagine constants are similar for constant pool entries. 

Richard. 



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

2020-06-05 Thread Richard Biener via Gcc-patches
On June 6, 2020 6:17:49 AM GMT+02:00, Jason Merrill via Gcc-patches 
 wrote:
>The problem in this testcase comes from cloning the constructor into
>complete and base variants.  When we clone the body the first time,
>walk_tree_1 calls copy_tree_body_r on the type of the artificial
>TYPE_DECL
>we made for the VLA type without calling it on the decl itself, so we
>overwrite the type of the TYPE_DECL without copying the decl first.
>
>This has been broken since we started inserting a TYPE_DECL for
>anonymous
>VLAs in r7-457.
>
>This patch fixes walk_tree_1 to call the function on the TYPE_DECL, as
>we do
>for other decls of a DECL_EXPR.
>
>Tested x86_64-pc-linux-gnu.  OK for trunk?  Release branches?

Looks reasonable. Please make sure to bootstrap and test with Ada enabled. Eric 
may also have comments here. 

In any case please wait a while before backporting. 

Thanks, 
Richard. 

>gcc/ChangeLog:
>
>   PR c++/95552
>   * tree.c (walk_tree_1): Call func on the TYPE_DECL of a DECL_EXPR.
>
>gcc/testsuite/ChangeLog:
>
>   PR c++/95552
>   * g++.dg/ext/vla23.C: New test.
>---
> gcc/testsuite/g++.dg/ext/vla23.C | 14 ++
> gcc/tree.c   |  5 +
> 2 files changed, 19 insertions(+)
> create mode 100644 gcc/testsuite/g++.dg/ext/vla23.C
>
>diff --git a/gcc/testsuite/g++.dg/ext/vla23.C
>b/gcc/testsuite/g++.dg/ext/vla23.C
>new file mode 100644
>index 000..317a824b2f3
>--- /dev/null
>+++ b/gcc/testsuite/g++.dg/ext/vla23.C
>@@ -0,0 +1,14 @@
>+// PR c++/95552
>+// Test for VLA and cloned constructor.
>+// { dg-additional-options -Wno-vla }
>+// { dg-require-effective-target alloca }
>+
>+struct VB { };
>+struct ViewDom: virtual VB
>+{
>+  ViewDom(int i) { char (*a)[i]; }
>+};
>+void element( )
>+{
>+  ViewDom a(2);
>+}
>diff --git a/gcc/tree.c b/gcc/tree.c
>index 7197b4720ce..c8e9680b06c 100644
>--- a/gcc/tree.c
>+++ b/gcc/tree.c
>@@ -12212,6 +12212,11 @@ walk_tree_1 (tree *tp, walk_tree_fn func, void
>*data,
>Note that DECLs get walked as part of processing the BIND_EXPR.  */
>   if (TREE_CODE (DECL_EXPR_DECL (*tp)) == TYPE_DECL)
>   {
>+/* Call the function for the decl so e.g. inlining can remap it. 
>*/
>+result = (*func) (&DECL_EXPR_DECL (*tp), &walk_subtrees, data);
>+if (result || !walk_subtrees)
>+  return result;
>+
> tree *type_p = &TREE_TYPE (DECL_EXPR_DECL (*tp));
> if (TREE_CODE (*type_p) == ERROR_MARK)
>   return NULL_TREE;
>
>base-commit: 5bc13e5217f687f5d08a7022b4c6081befc54402