Re: [PATCH] Perform case-insensitive comparison when decoding register names (PR target/70320)

2019-07-04 Thread Segher Boessenkool
On Thu, Jul 04, 2019 at 01:32:59PM +0100, Jozef Lawrynowicz wrote:
> The attached patch allows the case of register names used in an asm statement
> clobber list to be disregarded when checking the validity of the register 
> names.
> 
> Currently, the register name used in asm statement clobber list must exactly
> match those defined in the targets REGISTER_NAMES macro.

> All the register names defined in the msp430 REGISTER_NAMES macro use an
> upper case 'R', so use of lower case 'r' gets rejected.
> 
> I guess this could also be fixed by defining all the registers in
> ADDITIONAL_REGISTER_NAMES using a lower case r, but I prefer this generic
> solution and I cannot think of any negative side effects to what is proposed.

It isn't obviously safe either.  Are there any targets that have names
for different registers that differ only in case?  You could say that
such a design deserves what is coming for it, but :-)

> --- a/gcc/varasm.c
> +++ b/gcc/varasm.c
> @@ -947,7 +947,7 @@ decode_reg_name_and_count (const char *asmspec, int 
> *pnregs)

This is used for more than just clobber lists.  Is this change safe, and
a good thing, in the other contexts where it changes things?

> -  if (!strcmp (asmspec, "memory"))
> +  if (!strcasecmp (asmspec, "memory"))
>   return -4;
>  
> -  if (!strcmp (asmspec, "cc"))
> +  if (!strcasecmp (asmspec, "cc"))
>   return -3;

You don't need to change these.


Segher


Re: [PATCH,RFC,V3 0/5] Support for CTF in GCC

2019-07-04 Thread Indu Bhagat

On 07/04/2019 03:43 AM, Richard Biener wrote:

On Thu, Jul 4, 2019 at 2:36 AM Indu Bhagat  wrote:

[...]
RE subset of C : It is true that CTF format currently does leave out a very
small subset of C like FIXED_POINT as you noted ( CTF does have representation
for COMPLEX_TYPE, if my code paths culminate to gcc_unreachable () for that, I
should fix them ).  The end goal is to make it support all of C, and not just a
subset.

What about other languages?  GCC supports C++, Ada, Objective-C, Go, D,
Fortran, Modula-2, BRIG (this list is not necessarily complete and may change
in the future).


The format supports C only at this time. Other languages are not on the radar
yet. However, we have no intrinsic objection to them. Although, languages
that already have fully-fledged type introspection and interpreted/
managed languages are probably out of scope, since they already have
what CTF provides.






Given it appears to generate only debug info for symbols and no locations
or whatnot it should be sufficient to introspect the compilation to generate
the CTF info on the side and then merge it in at link-time.  Which makes
me wonder if this shouldn't be a plugin for now until it is more complete
and can be evaluated better (comments in the patches indicate even the
on-disk format is in flux?).  Adding plugin hook invocations to the three
places the CTF info generation hooks off should be easy.

Yes, some bits of the on-disk format are being adapted to make it easier to
adopt the CTF format across the board. E.g., we recently added CU name in the
CTF header. As another example, we added CTF_K_SLICE type because there existed
no way in CTF to represent enum bitfields. For the most part though, CTF format
has stayed as is.

I hope the format is versioned at least.


Yes, the format is versioned. The current version is CTF_VERSION_3.  All these
format changes I talked about above are a part of CTF_VERSION_3.

libctf handles backward compatibility for users of CTF in the toolchain; all
transparently to the user. This means that, in future, when CTF version needs
to be bumped, libctf will either support older version and/or transparently
upgrade to the new version for further consumers.

It also means that the compiler does not always need to change merely because
the format has changed: (depending on the change) the linker can transparently
adjust, as will all consumers if they try to read unlinked object files.




That said, the patch series isn't ready for integration since it will
crash left and right -- did you bootstrap and run the testsuite
with -gt?



Bootstrap and Testsuite : Yes, I have.  On x86_64/linux, sparc64/linux,
aarch64/linux.
Run testsuite with -gt : Not yet. Believe me, it's on my plate. And I already
   regret not having done it sooner :)
Bootstrap with -gt : Not yet. I should try soon.

(I have compiled libdtrace-ctf with -gt and parsed the .ctf sections with the
patch set.)

About the patch being not ready for integration : Yes, you're right.
That's why I chose to retain 'RFC' for this patch series as well. I am working
on issues, testing the compiler, and closing on the open ends in the
implementation.

I will refresh the patch series when I have made a meaningful stride ahead. Any
further suggestions on functional/performance testing will be helpful too.

What's the functional use of CTF?  Print nice backtraces (without showing
function argument values)?


CTF, at this time, is type information for entities at global or file scope.
This can be used by online debuggers, program tracers (dynamic tracing); More
generally, it provides type introspection for C programs, with an optional
library API to allow them to get at their own types quite more easily than
DWARF. So, the umbrella usecases are - all C programs that want to introspect
their own types quickly; and applications that want to introspect other
programs's types quickly.

(Even with the exception of its embedded string table, it is already small
 enough to  be kept around in stripped binaries so that it can be relied upon
 to be present.)

We are also extending the format so it is useful for other on-line debugging
tools, such as backtracers.

Indu



Re: [PATCH 1/2] Come up with function_decl_type and use it in tree_function_decl.

2019-07-04 Thread Marc Glisse

On Wed, 3 Jul 2019, Richard Biener wrote:


On July 3, 2019 4:53:30 PM GMT+02:00, "Martin Liška"  wrote:

On 7/2/19 7:15 PM, Marc Glisse wrote:

On Tue, 2 Jul 2019, Martin Liška wrote:


After the discussion with Richi and Nathan, I made a place in

tree_function_decl

and I rebased the original Dominik's patch on top of that.


So, last time there were some questions about the legality of this

transformation. Did you change the exact set of functions on which this
is applied?

Yes. I was not included in the original discussion, but I hope the
transformation is valid.
Btw. clang also removes the new/delete pairs and I guess it was the
original motivation of the patch.


We also remove malloc/free pairs which the C standard does not explicitly allow 
(but also doesn't explicitly forbid). I don't think standards need to enumerate 
everything allowed and I don't know any explicit wording in the C++ standard 
that forbids this.


The C++ standard has explicit wording allowing to remove new-delete pairs 
in some circumstances (expr.new, allocator.members), so I would assume 
that other circumstances are forbidden (not that I care much, I am just 
afraid someone might).


The patch apparently has DECL_IS_OPERATOR_DELETE only on the replaceable 
global deallocation functions, not all delete operators, contrary to 
DECL_IS_OPERATOR_NEW, so the name is misleading. On the other hand, those 
seem to be the ones for which the optimization is legal (well, not quite, 
the rules are in terms of operator new, and I am not sure how well 
operator delete has to match, but close enough).


It's only that users can override the allocation functions (but so can 
they in C) and it was suggested we need to preserve side effects unknown 
to the compiler.


--
Marc Glisse


[committed] Fix gimplification ICE with local VLA inside of simd body (PR middle-end/78884)

2019-07-04 Thread Jakub Jelinek
Hi!

This fixes an ICE in the gimplifier, for VLAs we really can't call
omp_add_variable with GOVD_PRIVATE before the DECL_EXPR is actually
gimplified.
Furthermore, there is really no hope in actually vectorizing such loops and
when we make it just GOVD_LOCAL, we shouldn't mark the loop as loop->safelen
> 1.

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

2019-07-04  Jakub Jelinek  

PR middle-end/78884
* gimplify.c (struct gimplify_omp_ctx): Add add_safelen1 member.
(gimplify_bind_expr): If seeing TREE_ADDRESSABLE VLA inside of simd
loop body, set ctx->add_safelen1 instead of making it GOVD_PRIVATE.
(gimplify_adjust_omp_clauses): Add safelen (1) clause if
ctx->add_safelen1 is set.

* gcc.dg/gomp/pr78884.c: New test.

--- gcc/gimplify.c.jj   2019-07-03 06:55:33.562493081 +0200
+++ gcc/gimplify.c  2019-07-04 21:23:32.295352338 +0200
@@ -221,6 +221,7 @@ struct gimplify_omp_ctx
   bool combined_loop;
   bool distribute;
   bool target_firstprivatize_array_bases;
+  bool add_safelen1;
   int defaultmap[4];
 };
 
@@ -1331,12 +1332,17 @@ gimplify_bind_expr (tree *expr_p, gimple
  || splay_tree_lookup (ctx->variables,
(splay_tree_key) t) == NULL)
{
+ int flag = GOVD_LOCAL;
  if (ctx->region_type == ORT_SIMD
  && TREE_ADDRESSABLE (t)
  && !TREE_STATIC (t))
-   omp_add_variable (ctx, t, GOVD_PRIVATE | GOVD_SEEN);
- else
-   omp_add_variable (ctx, t, GOVD_LOCAL | GOVD_SEEN);
+   {
+ if (TREE_CODE (DECL_SIZE_UNIT (t)) != INTEGER_CST)
+   ctx->add_safelen1 = true;
+ else
+   flag = GOVD_PRIVATE;
+   }
+ omp_add_variable (ctx, t, flag | GOVD_SEEN);
}
  /* Static locals inside of target construct or offloaded
 routines need to be "omp declare target".  */
@@ -9801,6 +9807,18 @@ gimplify_adjust_omp_clauses (gimple_seq
}
 }
 
+  if (ctx->add_safelen1)
+{
+  /* If there are VLAs in the body of simd loop, prevent
+vectorization.  */
+  gcc_assert (ctx->region_type == ORT_SIMD);
+  c = build_omp_clause (UNKNOWN_LOCATION, OMP_CLAUSE_SAFELEN);
+  OMP_CLAUSE_SAFELEN_EXPR (c) = integer_one_node;
+  OMP_CLAUSE_CHAIN (c) = *list_p;
+  *list_p = c;
+  list_p = &OMP_CLAUSE_CHAIN (c);
+}
+
   if (ctx->region_type == ORT_WORKSHARE
   && ctx->outer_context
   && ctx->outer_context->region_type == ORT_COMBINED_PARALLEL)
--- gcc/testsuite/gcc.dg/gomp/pr78884.c.jj  2019-07-04 21:25:36.142391446 
+0200
+++ gcc/testsuite/gcc.dg/gomp/pr78884.c 2019-07-04 21:25:06.370862824 +0200
@@ -0,0 +1,16 @@
+/* PR middle-end/78884 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -fopenmp" } */
+
+void bar (int *);
+
+void
+foo (int n)
+{
+#pragma omp simd
+  for (int i = 0; i < 1024; i++)
+{
+  int vla[n];
+  bar (vla);
+}
+}

Jakub


Re: [PATCH] Add generic support for "noinit" attribute

2019-07-04 Thread Jozef Lawrynowicz
Hi,

> diff --git a/gcc/config/msp430/msp430.c b/gcc/config/msp430/msp430.c
> index 365e9eb..8266fa0 100644
> --- a/gcc/config/msp430/msp430.c
> +++ b/gcc/config/msp430/msp430.c
> @@ -1807,7 +1807,6 @@ const char * const  ATTR_CRIT   = "critical";
>  const char * const  ATTR_LOWER  = "lower";
>  const char * const  ATTR_UPPER  = "upper";
>  const char * const  ATTR_EITHER = "either";
> -const char * const  ATTR_NOINIT = "noinit";
>  const char * const  ATTR_PERSIST = "persistent";
>  
>  static inline bool

With this change removed so that ATTR_NOINIT is still defined, your patch is
ok for msp430 - the attribute still behaves as expected.

I'm holding off using default_elf_select_section instead of
default_select_section in msp430.c since there could be some possible conflicts
with the MSPABI introduced by using elf_select_section that need to be properly
considered before making the change.

I think default_select_section is supposed to be very terse, so I'm not sure 
if it would be even be suitable to extend it to handle noinit.

With that said, could you please add the following FIXME to your patch:

diff --git a/gcc/config/msp430/msp430.c b/gcc/config/msp430/msp430.c
index 365e9eba747..b403b1f5a42 100644
--- a/gcc/config/msp430/msp430.c
+++ b/gcc/config/msp430/msp430.c
@@ -2338,6 +2336,8 @@ msp430_select_section (tree decl, int reloc, unsigned
HOST_WIDE_INT align) {
   if (TREE_CODE (decl) == FUNCTION_DECL)
return text_section;
+  /* FIXME: ATTR_NOINIT is handled generically in
+ default_elf_select_section.  */
   else if (has_attr (ATTR_NOINIT, decl))
return noinit_section;
   else if (has_attr (ATTR_PERSIST, decl))

Also, the gcc.target/arm/noinit-attribute.c test works with msp430.
Why not create a effective-target keyword which checks for noinit support, so
the test can be gated on that condition and put in a generic part of the
testsuite?

After doing some further testing, I noticed the attribute does not work on
static variables. The attribute handling code allows the attribute to be set on
a static variable, but then that variable does not get placed in the .noinit
section.

What are your thoughts on this?

Does it even makes sense for a static local variable to be declared as "noinit"?
One should want a static local variable to be initialized, as having it not
initialized and hold a random value could cause problems.
Perhaps a user could think of some use for this, but I can't.

Finally, I would point out that "contrib/check_GNU_style.sh" reports some style
issues with your patch.

Thanks and regards,
Jozef


[committed] Fix inscan reduction and conditional lastprivate interaction

2019-07-04 Thread Jakub Jelinek
Hi!

This patch fixes worksharing loops containing both conditional lastprivate
and inscan reduction(s).  Furthermore, it for nowait omp for ensures there
is GOMP_loop_end_nowait call at the end after the second loop in scan
and not after the first one.

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

2019-07-04  Jakub Jelinek  

* omp-expand.c (expand_omp_for_static_nochunk): Don't emit
GOMP_loop_start at the start of second worksharing loop in a scan.
For nowait, don't emit GOMP_loop_end_nowait at the end of first
worksharing loop in a scan even if there are conditional lastprivates,
and do emit GOMP_loop_end_nowait at the end of second worksharing loop.

* testsuite/libgomp.c/scan-9.c: New test.
* testsuite/libgomp.c/scan-10.c: New test.

--- gcc/omp-expand.c.jj 2019-07-03 07:02:16.511989061 +0200
+++ gcc/omp-expand.c2019-07-04 11:54:22.576366802 +0200
@@ -3744,7 +3744,9 @@ expand_omp_for_static_nochunk (struct om
   cond_var = OMP_CLAUSE_DECL (c);
 }
   if (fd->have_reductemp
-  || fd->have_pointer_condtemp
+  /* For scan, we don't want to reinitialize condtemp before the
+second loop.  */
+  || (fd->have_pointer_condtemp && !fd->have_scantemp)
   || fd->have_nonctrl_scantemp)
 {
   tree t1 = build_int_cst (long_integer_type_node, 0);
@@ -4235,7 +4237,8 @@ expand_omp_for_static_nochunk (struct om
   else
gsi_insert_after (&gsi, omp_build_barrier (t), GSI_SAME_STMT);
 }
-  else if (fd->have_pointer_condtemp)
+  else if ((fd->have_pointer_condtemp || fd->have_scantemp)
+  && !fd->have_nonctrl_scantemp)
 {
   tree fn = builtin_decl_explicit (BUILT_IN_GOMP_LOOP_END_NOWAIT);
   gcall *g = gimple_build_call (fn, 0);
--- libgomp/testsuite/libgomp.c/scan-9.c.jj 2019-07-04 12:04:48.235360731 
+0200
+++ libgomp/testsuite/libgomp.c/scan-9.c2019-07-04 11:08:54.038069390 
+0200
@@ -0,0 +1,116 @@
+/* { dg-require-effective-target size32plus } */
+
+extern void abort (void);
+int r, a[1024], b[1024], x, y, z;
+
+__attribute__((noipa)) void
+foo (int *a, int *b)
+{
+  #pragma omp for reduction (inscan, +:r) lastprivate (conditional: z) 
firstprivate (x) private (y)
+  for (int i = 0; i < 1024; i++)
+{
+  { y = a[i]; r += y + x + 12; }
+  #pragma omp scan inclusive(r)
+  { b[i] = r; if ((i & 1) == 0 && i < 937) z = r; }
+}
+}
+
+__attribute__((noipa)) int
+bar (void)
+{
+  int s = 0;
+  #pragma omp parallel
+  #pragma omp for reduction (inscan, +:s) firstprivate (x) private (y) 
lastprivate (z)
+  for (int i = 0; i < 1024; i++)
+{
+  { y = 2 * a[i]; s += y; z = y; }
+  #pragma omp scan inclusive(s)
+  { y = s; b[i] = y + x + 12; }
+}
+  return s;
+}
+
+__attribute__((noipa)) void
+baz (int *a, int *b)
+{
+  #pragma omp parallel for reduction (inscan, +:r) firstprivate (x) 
lastprivate (x)
+  for (int i = 0; i < 1024; i++)
+{
+  { r += a[i] + x + 12; if (i == 1023) x = 29; }
+  #pragma omp scan inclusive(r)
+  b[i] = r;
+}
+}
+
+__attribute__((noipa)) int
+qux (void)
+{
+  int s = 0;
+  #pragma omp parallel for reduction (inscan, +:s) lastprivate (conditional: 
x, y)
+  for (int i = 0; i < 1024; i++)
+{
+  { s += 2 * a[i]; if ((a[i] & 1) == 1 && i < 825) x = a[i]; }
+  #pragma omp scan inclusive(s)
+  { b[i] = s; if ((a[i] & 1) == 0 && i < 829) y = a[i]; }
+}
+  return s;
+}
+
+int
+main ()
+{
+  int s = 0;
+  x = -12;
+  for (int i = 0; i < 1024; ++i)
+{
+  a[i] = i;
+  b[i] = -1;
+  asm ("" : "+g" (i));
+}
+  #pragma omp parallel
+  foo (a, b);
+  if (r != 1024 * 1023 / 2 || x != -12 || z != b[936])
+abort ();
+  for (int i = 0; i < 1024; ++i)
+{
+  s += i;
+  if (b[i] != s)
+   abort ();
+  else
+   b[i] = 25;
+}
+  if (bar () != 1024 * 1023 || x != -12 || z != 2 * 1023)
+abort ();
+  s = 0;
+  for (int i = 0; i < 1024; ++i)
+{
+  s += 2 * i;
+  if (b[i] != s)
+   abort ();
+  else
+   b[i] = -1;
+}
+  r = 0;
+  baz (a, b);
+  if (r != 1024 * 1023 / 2 || x != 29)
+abort ();
+  s = 0;
+  for (int i = 0; i < 1024; ++i)
+{
+  s += i;
+  if (b[i] != s)
+   abort ();
+  else
+   b[i] = -25;
+}
+  if (qux () != 1024 * 1023 || x != 823 || y != 828)
+abort ();
+  s = 0;
+  for (int i = 0; i < 1024; ++i)
+{
+  s += 2 * i;
+  if (b[i] != s)
+   abort ();
+}
+  return 0;
+}
--- libgomp/testsuite/libgomp.c/scan-10.c.jj2019-07-04 12:09:44.171630459 
+0200
+++ libgomp/testsuite/libgomp.c/scan-10.c   2019-07-04 12:11:12.169224358 
+0200
@@ -0,0 +1,116 @@
+/* { dg-require-effective-target size32plus } */
+
+extern void abort (void);
+int r, a[1024], b[1024], x, y, z;
+
+__attribute__((noipa)) void
+foo (int *a, int *b)
+{
+  #pragma omp for reduction (inscan, +:r) lastprivate (conditional: z) 
firstprivate (x) private (y)
+  for (int i 

New Ukrainian PO file for 'gcc' (version 9.1.0)

2019-07-04 Thread Translation Project Robot
Hello, gentle maintainer.

This is a message from the Translation Project robot.

A revised PO file for textual domain 'gcc' has been submitted
by the Ukrainian team of translators.  The file is available at:

https://translationproject.org/latest/gcc/uk.po

(This file, 'gcc-9.1.0.uk.po', has just now been sent to you in
a separate email.)

All other PO files for your package are available in:

https://translationproject.org/latest/gcc/

Please consider including all of these in your next release, whether
official or a pretest.

Whenever you have a new distribution with a new version number ready,
containing a newer POT file, please send the URL of that distribution
tarball to the address below.  The tarball may be just a pretest or a
snapshot, it does not even have to compile.  It is just used by the
translators when they need some extra translation context.

The following HTML page has been updated:

https://translationproject.org/domain/gcc.html

If any question arises, please contact the translation coordinator.

Thank you for all your work,

The Translation Project robot, in the
name of your translation coordinator.




Re: [PATCH][gcc] libgccjit: check result_type in gcc_jit_context_new_binary_op

2019-07-04 Thread Andrea Corallo


Andrea Corallo writes:

> David Malcolm writes:
>
>>> Hi David,
>>> I can work on to get the SVN commit access.
>>> As a maintainer has to sponsor it would you mind being the one?
>>
>> https://www.gnu.org/software/gcc/svnwrite.html says:
>> "a well-established GCC maintainer (including reviewers) can approve
>> for write access any person with GNU copyright assignment papers in
>> place and known to submit good patches."
>>
>> Thanks for your patches so far.
>>
>> I approve of you getting "Write after approval" access to GCC svn,
>> provided the copyright assignment paperwork is in place (which I'm
>> assuming is, based on your @arm.com email address).
>>
>> I'm not quite sure what the next steps are.
>>
>> Dave
>
> Hi David,
> great thanks.
> I'll proceed with the following steps.
>
> Bests
>   Andrea

Hi,
I've pushed this patch into trunk as revision r273089.
Thanks again for all the feedbacks on both patches.

Bests
  Andrea


Fix my previous change in nonoverlapping_component_refs_since_match_p

2019-07-04 Thread Jan Hubicka
Hi,
while working on subsetquent changes I noticed that I got worng
the boundary condition while we collect refs.

We know that match1 and match2 are the same which means that we want
to start disambiguating until the last ref that reach the match.
For example when one is MEM_REF and other COMPONENT_REF the ref stacks
can get out of sync this way. This makes the function to give up in its
current form byt with followup change we get wrong code.

Bootstrapped/regtested x86_64-linux, comitted.

Honza

* tree-ssa-alias.c (nonoverlapping_component_refs_since_match_p):
Fix check for match in the ref walk.
Index: tree-ssa-alias.c
===
--- tree-ssa-alias.c(revision 273084)
+++ tree-ssa-alias.c(working copy)
@@ -1153,15 +1153,13 @@ nonoverlapping_component_refs_since_matc
   auto_vec component_refs2;
 
   /* Create the stack of handled components for REF1.  */
-  while (handled_component_p (ref1))
+  while (handled_component_p (ref1) && ref1 != match1)
 {
   if (TREE_CODE (ref1) == VIEW_CONVERT_EXPR
  || TREE_CODE (ref1) == BIT_FIELD_REF)
component_refs1.truncate (0);
   else
 component_refs1.safe_push (ref1);
-  if (ref1 == match1)
-   break;
   ref1 = TREE_OPERAND (ref1, 0);
 }
   if (TREE_CODE (ref1) == MEM_REF && ref1 != match1)
@@ -1180,15 +1178,13 @@ nonoverlapping_component_refs_since_matc
 }
 
   /* Create the stack of handled components for REF2.  */
-  while (handled_component_p (ref2))
+  while (handled_component_p (ref2) && ref2 != match2)
 {
   if (TREE_CODE (ref2) == VIEW_CONVERT_EXPR
  || TREE_CODE (ref2) == BIT_FIELD_REF)
component_refs2.truncate (0);
   else
 component_refs2.safe_push (ref2);
-  if (ref2 == match2)
-   break;
   ref2 = TREE_OPERAND (ref2, 0);
 }
   if (TREE_CODE (ref2) == MEM_REF && ref2 != match2)


Re: Call for testers: improve move2add_use_add2_insn for targets with HAVE_POST_MODIFY_DISP and/or clobber-encumbered add

2019-07-04 Thread Joern Wolfgang Rennecke
Never mind, if the target has reg+offset addressing, the add should be 
tried in preference to post_modify, since this enables 
reload_combine_recognize_const_pattern .


Re: [PATCH] Support __builtin_expect_with_probability for analysis of # of loop iterations.

2019-07-04 Thread Jan Hubicka
> Hi.
> 
> The patch makes a loop upper bound estimation based on 
> __builtin_expect_with_probability.
> 
> Patch can bootstrap on x86_64-linux-gnu and survives regression tests.
> 
> The patch is pre-approved by Honza.
> Thanks,
> Martin
> 
> gcc/ChangeLog:
> 
> 2019-07-04  Martin Liska  
> 
>   * tree-ssa-loop-niter.c 
> (get_upper_bound_based_on_builtin_expr_with_prob):
>   New function.
>   (estimate_numbers_of_iterations):
>   Support __builtin_expect_with_probability for analysis
>   of # of loop iterations.

perhaps we want to also document that builtin-expect can be used this way?
It owuld be also nice to have a testcase.

Honza
> ---
>  gcc/tree-ssa-loop-niter.c | 66 +++
>  1 file changed, 66 insertions(+)
> 
> 

> diff --git a/gcc/tree-ssa-loop-niter.c b/gcc/tree-ssa-loop-niter.c
> index f51385900ed..5e75a412d93 100644
> --- a/gcc/tree-ssa-loop-niter.c
> +++ b/gcc/tree-ssa-loop-niter.c
> @@ -4183,6 +4183,55 @@ maybe_lower_iteration_bound (struct loop *loop)
>delete not_executed_last_iteration;
>  }
>  
> +/* Get expected upper bound for number of loop iterations for
> +   BUILT_IN_EXPECT_WITH_PROBABILITY for a condition COND.  */
> +
> +static tree
> +get_upper_bound_based_on_builtin_expr_with_prob (gcond *cond)
> +{
> +  if (cond == NULL)
> +return NULL_TREE;
> +
> +  tree lhs = gimple_cond_lhs (cond);
> +  if (TREE_CODE (lhs) != SSA_NAME)
> +return NULL_TREE;
> +
> +  gimple *stmt = SSA_NAME_DEF_STMT (gimple_cond_lhs (cond));
> +  gcall *def = dyn_cast (stmt);
> +  if (def == NULL)
> +return NULL_TREE;
> +
> +  tree decl = gimple_call_fndecl (def);
> +  if (!decl
> +  || !fndecl_built_in_p (decl, BUILT_IN_EXPECT_WITH_PROBABILITY)
> +  || gimple_call_num_args (stmt) != 3)
> +return NULL_TREE;
> +
> +  tree c = gimple_call_arg (def, 1);
> +  tree condt = TREE_TYPE (lhs);
> +  tree res = fold_build2 (gimple_cond_code (cond),
> +   condt, c,
> +   gimple_cond_rhs (cond));
> +  if (TREE_CODE (res) != INTEGER_CST)
> +return NULL_TREE;
> +
> +
> +  tree prob = gimple_call_arg (def, 2);
> +  tree t = TREE_TYPE (prob);
> +  tree one
> += build_real_from_int_cst (t,
> +integer_one_node);
> +  if (integer_zerop (res))
> +prob = fold_build2 (MINUS_EXPR, t, one, prob);
> +  tree r = fold_build2 (RDIV_EXPR, t, one, prob);
> +  if (TREE_CODE (r) != REAL_CST)
> +return NULL_TREE;
> +
> +  HOST_WIDE_INT probi
> += real_to_integer (TREE_REAL_CST_PTR (r));
> +  return build_int_cst (condt, probi);
> +}
> +
>  /* Records estimates on numbers of iterations of LOOP.  If USE_UNDEFINED_P
> is true also use estimates derived from undefined behavior.  */
>  
> @@ -4231,6 +4280,23 @@ estimate_numbers_of_iterations (struct loop *loop)
>likely_exit = single_likely_exit (loop);
>FOR_EACH_VEC_ELT (exits, i, ex)
>  {
> +  if (ex == likely_exit)
> + {
> +   gimple *stmt = last_stmt (ex->src);
> +   if (stmt != NULL)
> + {
> +   gcond *cond = dyn_cast (stmt);
> +   tree niter_bound
> + = get_upper_bound_based_on_builtin_expr_with_prob (cond);
> +   if (niter_bound != NULL_TREE)
> + {
> +   widest_int max = derive_constant_upper_bound (niter_bound);
> +   record_estimate (loop, niter_bound, max, cond,
> +true, true, false);
> + }
> + }
> + }
> +
>if (!number_of_iterations_exit (loop, ex, &niter_desc, false, false))
>   continue;
>  
> 



[COMMITTED] Fix arm XFAIL in cunroll-15.c

2019-07-04 Thread Wilco Dijkstra
Remove the XFAIL on arm in cunroll-15.c since the test passes on trunk.
Committed as obvious.

ChangeLog:
2019-07-04  Wilco Dijkstra  

testsuite/
* gcc.dg/tree-ssa/cunroll-15.c: Remove XFAIL on arm.

--

diff --git a/gcc/testsuite/gcc.dg/tree-ssa/cunroll-15.c 
b/gcc/testsuite/gcc.dg/tree-ssa/cunroll-15.c
index 
55cdcff7674ae01bdc4ae819dc72738f305bec9a..a68145068f2fb833ad42d19c4daeeff8a894dd5a
 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/cunroll-15.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/cunroll-15.c
@@ -20,4 +20,4 @@ int Test(void)
 /* When SLP vectorization is enabled the following will fail because DOM
doesn't know how to deal with the vectorized initializer of in.  */
 /* DOM also doesn't know to CSE in[1] with in = *.LC0 thus the list of targets 
this fails.  */
-/* { dg-final { scan-tree-dump "return 1;" "optimized" { xfail { arm*-*-* 
powerpc-*-* } } } } */
+/* { dg-final { scan-tree-dump "return 1;" "optimized" { xfail { powerpc-*-* } 
} } } */


[PATCH] Support __builtin_expect_with_probability for analysis of # of loop iterations.

2019-07-04 Thread Martin Liška
Hi.

The patch makes a loop upper bound estimation based on 
__builtin_expect_with_probability.

Patch can bootstrap on x86_64-linux-gnu and survives regression tests.

The patch is pre-approved by Honza.
Thanks,
Martin

gcc/ChangeLog:

2019-07-04  Martin Liska  

* tree-ssa-loop-niter.c 
(get_upper_bound_based_on_builtin_expr_with_prob):
New function.
(estimate_numbers_of_iterations):
Support __builtin_expect_with_probability for analysis
of # of loop iterations.
---
 gcc/tree-ssa-loop-niter.c | 66 +++
 1 file changed, 66 insertions(+)


diff --git a/gcc/tree-ssa-loop-niter.c b/gcc/tree-ssa-loop-niter.c
index f51385900ed..5e75a412d93 100644
--- a/gcc/tree-ssa-loop-niter.c
+++ b/gcc/tree-ssa-loop-niter.c
@@ -4183,6 +4183,55 @@ maybe_lower_iteration_bound (struct loop *loop)
   delete not_executed_last_iteration;
 }
 
+/* Get expected upper bound for number of loop iterations for
+   BUILT_IN_EXPECT_WITH_PROBABILITY for a condition COND.  */
+
+static tree
+get_upper_bound_based_on_builtin_expr_with_prob (gcond *cond)
+{
+  if (cond == NULL)
+return NULL_TREE;
+
+  tree lhs = gimple_cond_lhs (cond);
+  if (TREE_CODE (lhs) != SSA_NAME)
+return NULL_TREE;
+
+  gimple *stmt = SSA_NAME_DEF_STMT (gimple_cond_lhs (cond));
+  gcall *def = dyn_cast (stmt);
+  if (def == NULL)
+return NULL_TREE;
+
+  tree decl = gimple_call_fndecl (def);
+  if (!decl
+  || !fndecl_built_in_p (decl, BUILT_IN_EXPECT_WITH_PROBABILITY)
+  || gimple_call_num_args (stmt) != 3)
+return NULL_TREE;
+
+  tree c = gimple_call_arg (def, 1);
+  tree condt = TREE_TYPE (lhs);
+  tree res = fold_build2 (gimple_cond_code (cond),
+			  condt, c,
+			  gimple_cond_rhs (cond));
+  if (TREE_CODE (res) != INTEGER_CST)
+return NULL_TREE;
+
+
+  tree prob = gimple_call_arg (def, 2);
+  tree t = TREE_TYPE (prob);
+  tree one
+= build_real_from_int_cst (t,
+			   integer_one_node);
+  if (integer_zerop (res))
+prob = fold_build2 (MINUS_EXPR, t, one, prob);
+  tree r = fold_build2 (RDIV_EXPR, t, one, prob);
+  if (TREE_CODE (r) != REAL_CST)
+return NULL_TREE;
+
+  HOST_WIDE_INT probi
+= real_to_integer (TREE_REAL_CST_PTR (r));
+  return build_int_cst (condt, probi);
+}
+
 /* Records estimates on numbers of iterations of LOOP.  If USE_UNDEFINED_P
is true also use estimates derived from undefined behavior.  */
 
@@ -4231,6 +4280,23 @@ estimate_numbers_of_iterations (struct loop *loop)
   likely_exit = single_likely_exit (loop);
   FOR_EACH_VEC_ELT (exits, i, ex)
 {
+  if (ex == likely_exit)
+	{
+	  gimple *stmt = last_stmt (ex->src);
+	  if (stmt != NULL)
+	{
+	  gcond *cond = dyn_cast (stmt);
+	  tree niter_bound
+		= get_upper_bound_based_on_builtin_expr_with_prob (cond);
+	  if (niter_bound != NULL_TREE)
+		{
+		  widest_int max = derive_constant_upper_bound (niter_bound);
+		  record_estimate (loop, niter_bound, max, cond,
+   true, true, false);
+		}
+	}
+	}
+
   if (!number_of_iterations_exit (loop, ex, &niter_desc, false, false))
 	continue;
 



Re: [PATCH][gcc] libgccjit: add bitfield support

2019-07-04 Thread Andrea Corallo


Andrea Corallo writes:

> Hi Dave,
> last version for this patch addressing the suggestion about the
> JIT_BIT_FIELD macros comment description.
>
> Thank you for all the suggestions.
>
> Regarding the write access please see my previous answer into the binary
> op patch thread.
>
> Bests
>   Andrea
>
>
> 2019-06-20  Andrea Corallo andrea.cora...@arm.com
>
> * docs/topics/compatibility.rst (LIBGCCJIT_ABI_12): New ABI tag.
> * docs/topics/types.rst: Add gcc_jit_context_new_bitfield.
> * jit-common.h (namespace recording): Add class bitfield.
> * jit-playback.c:
> (DECL_JIT_BIT_FIELD, SET_DECL_JIT_BIT_FIELD): Add macros.
> (playback::context::new_bitfield): New method.
> (playback::compound_type::set_fields): Add bitfield support.
> (playback::lvalue::mark_addressable): Was jit_mark_addressable make this
> a method of lvalue plus return a bool to communicate success.
> (playback::lvalue::get_address): Check for jit_mark_addressable return
> value.
> * jit-playback.h (new_bitfield): New method.
> (class bitfield): New class.
> (class lvalue): Add jit_mark_addressable method.
> * jit-recording.c (recording::context::new_bitfield): New method.
> (recording::bitfield::replay_into): New method.
> (recording::bitfield::write_to_dump): Likewise.
> (recording::bitfield::make_debug_string): Likewise.
> (recording::bitfield::write_reproducer): Likewise.
> * jit-recording.h (class context): Add new_bitfield method.
> (class field): Make it derivable by class bitfield.
> (class bitfield): Add new class.
> * libgccjit++.h (class context): Add new_bitfield method.
> * libgccjit.c (struct gcc_jit_bitfield): New structure.
> (gcc_jit_context_new_bitfield): New function.
> * libgccjit.h
> (LIBGCCJIT_HAVE_gcc_jit_context_new_bitfield) New macro.
> (gcc_jit_context_new_bitfield): New function.
> * libgccjit.map (LIBGCCJIT_ABI_12) New ABI tag.
>
>
> 2019-06-20  Andrea Corallo andrea.cora...@arm.com
>
> * jit.dg/all-non-failing-tests.h: Add test-accessing-bitfield.c.
> * jit.dg/test-accessing-bitfield.c: New testcase.
> * jit.dg/test-error-gcc_jit_context_new_bitfield-invalid-type.c:
> Likewise.
> * jit.dg/test-error-gcc_jit_context_new_bitfield-invalid-width.c:
> Likewise.
> * jit.dg/test-error-gcc_jit_lvalue_get_address-bitfield.c:
> Likewise.

Hi all,
committed into trunk as r273086.

Bests

  Andrea


Re: [PATCH,RFC] collect2 LTO for AIX

2019-07-04 Thread Martin Liška
On 7/4/19 5:03 PM, David Edelsohn wrote:
> On Thu, Jul 4, 2019 at 10:38 AM Martin Liška  wrote:
>>
>> Hi.
>>
>> Recently I've introduced a new .gnu.lto_.lto section that
>> is supposed to provide meta information about a LTO bytecode.
>>
>> As a further step, I'm planning to teach binutils about
>> existence of the section and I'll remove in the future
>> emission of __gnu_lto_slim and __gnu_lto_v1 symbols.
>> The former one is used by binutils to identify if
>> an object is a slim LTO object. The later one is currently
>> used only in gcc/collect2.c and was added by David's patch.
>>
>> My question is: Can we remove __gnu_lto_v1 right now and
>> XCOFF will use something similar to ELF (has_lto_section)?
>> Can you David help me with that please?
> 
> LTO currently does not work on AIX. I added the __gnu_lto_v1 as a
> test. You can rip it out and XCOFF will follow a different path when
> implementing LTO.

Great. Then I'm sending revert of the patch.

Ready to be installed?
Thanks,
Martin

> 
> Thanks David
> 

>From d34a25ca594e9b8c41af56b812faf2f8cdafd010 Mon Sep 17 00:00:00 2001
From: Martin Liska 
Date: Thu, 4 Jul 2019 17:38:33 +0200
Subject: [PATCH] Revert r254460 (collect2 LTO for AIX).

gcc/ChangeLog:

2019-07-04  Martin Liska  

	* collect2.c (defined): Revert to before r254460.
	(scan_prog_file): Revert to before r254460.
---
 gcc/collect2.c | 22 +++---
 1 file changed, 3 insertions(+), 19 deletions(-)

diff --git a/gcc/collect2.c b/gcc/collect2.c
index d6a7355e218..e25e33962fb 100644
--- a/gcc/collect2.c
+++ b/gcc/collect2.c
@@ -616,7 +616,7 @@ static const char *const target_machine = TARGET_MACHINE;
 
Return 0 if not found, otherwise return its name, allocated with malloc.  */
 
-#if defined (OBJECT_FORMAT_NONE) || defined (OBJECT_FORMAT_COFF)
+#ifdef OBJECT_FORMAT_NONE
 
 /* Add an entry for the object file NAME to object file list LIST.
New entries are added at the end of the list. The original pointer
@@ -636,7 +636,7 @@ add_lto_object (struct lto_object_list *list, const char *name)
 
   list->last = n;
 }
-#endif
+#endif /* OBJECT_FORMAT_NONE */
 
 
 /* Perform a link-time recompilation and relink if any of the object
@@ -2799,10 +2799,8 @@ scan_prog_file (const char *prog_name, scanpass which_pass,
   LDFILE *ldptr = NULL;
   int sym_index, sym_count;
   int is_shared = 0;
-  int found_lto = 0;
 
-  if (which_pass != PASS_FIRST && which_pass != PASS_OBJ
-  && which_pass != PASS_LTOINFO)
+  if (which_pass != PASS_FIRST && which_pass != PASS_OBJ)
 return;
 
 #ifdef COLLECT_EXPORT_LIST
@@ -2815,7 +2813,6 @@ scan_prog_file (const char *prog_name, scanpass which_pass,
  eliminate scan_libraries() function.  */
   do
 {
-  found_lto = 0;
 #endif
   /* Some platforms (e.g. OSF4) declare ldopen as taking a
 	 non-const char * filename parameter, even though it will not
@@ -2858,19 +2855,6 @@ scan_prog_file (const char *prog_name, scanpass which_pass,
 			++name;
 #endif
 
-  if (which_pass == PASS_LTOINFO)
-{
-			  if (found_lto)
-			continue;
-			  if (strncmp (name, "__gnu_lto_v1", 12) == 0)
-			{
-			  add_lto_object (

Re: [PATCH] Add generic support for "noinit" attribute

2019-07-04 Thread Jozef Lawrynowicz
On Thu, 4 Jul 2019 17:27:28 +0200
Christophe Lyon  wrote:

> Finally, I tested on arm-eabi, but not on msp430 for which I do not
> have the environment, so advice from msp430 maintainers is
> appreciated. Since msp430 does not use the same default helpers as
> arm, I left the "noinit" handling code in place, to avoid changing
> other generic functions which I don't know how to test
> (default_select_section, default_section_type_flags).
> 

I'll take a look at the MSP430 case soon.

Thanks,
Jozef


[PATCH] Add generic support for "noinit" attribute

2019-07-04 Thread Christophe Lyon
Hi,

Similar to what already exists for TI msp430 or in TI compilers for
arm, this patch adds support for the "noinit" attribute.

It is convenient for embedded targets where the user wants to keep the
value of some data when the program is restarted: such variables are
not zero-initialized. It is mostly a helper/shortcut to placing
variables in a dedicated section.

It's probably desirable to add the following chunk to the GNU linker:
diff --git a/ld/emulparams/armelf.sh b/ld/emulparams/armelf.sh
index 272a8bc..9555cec 100644
--- a/ld/emulparams/armelf.sh
+++ b/ld/emulparams/armelf.sh
@@ -10,7 +10,19 @@ OTHER_TEXT_SECTIONS='*(.glue_7t) *(.glue_7)
*(.vfp11_veneer) *(.v4_bx)'
 OTHER_BSS_SYMBOLS="${CREATE_SHLIB+PROVIDE (}__bss_start__ =
.${CREATE_SHLIB+)};"
 OTHER_BSS_END_SYMBOLS="${CREATE_SHLIB+PROVIDE (}_bss_end__ =
.${CREATE_SHLIB+)}; ${CREATE_SHLIB+PROVIDE (}__bss_end__ =
.${CREATE_SHLIB+)};"
 OTHER_END_SYMBOLS="${CREATE_SHLIB+PROVIDE (}__end__ = .${CREATE_SHLIB+)};"
 -OTHER_SECTIONS='.note.gnu.arm.ident 0 : { KEEP (*(.note.gnu.arm.ident)) }'
 +OTHER_SECTIONS='
 +.note.gnu.arm.ident 0 : { KEEP (*(.note.gnu.arm.ident)) }
 +  /* This section contains data that is not initialised during load
 + *or* application reset.  */
 +   .noinit (NOLOAD) :
 +   {
 + . = ALIGN(2);
 + PROVIDE (__noinit_start = .);
 + *(.noinit)
 + . = ALIGN(2);
 + PROVIDE (__noinit_end = .);
 +   }
 +'

so that the noinit section has the "NOLOAD" flag.

I'll submit that part separately to the binutils project if OK.

However, I'm not sure for which other targets (beyond arm), I should
update the linker scripts.

I left the new testcase in gcc.target/arm, guarded by
dg-do run { target { *-*-eabi } }
but since this attribute is now generic, I suspect I should move the
test to some other place. But then, which target selector should I
use?

Finally, I tested on arm-eabi, but not on msp430 for which I do not
have the environment, so advice from msp430 maintainers is
appreciated. Since msp430 does not use the same default helpers as
arm, I left the "noinit" handling code in place, to avoid changing
other generic functions which I don't know how to test
(default_select_section, default_section_type_flags).

Thanks,

Christophe

gcc/ChangeLog:

2019-07-04  Christophe Lyon  

* doc/extend.texi: Add "noinit" attribute documentation.
* varasm.c
(default_section_type_flags): Add support for "noinit" section.
(default_elf_select_section): Add support for "noinit" attribute.

gcc/c-family/ChangeLog:

2019-07-04  Christophe Lyon  

* c-attribs.c (c_common_attribute_table): Add "noinit" entry.
(handle_section_attribute): Add support for "noinit" attribute.
(handle_noinit_attribute): New function.

gcc/config/ChangeLog:

2019-07-04  Christophe Lyon  

* msp430/msp430.c (msp430_attribute_table): Remove "noinit" entry.

gcc/testsuite/ChangeLog:

2019-07-04  Christophe Lyon  

* gcc.target/arm/noinit-attribute.c: New test.
diff --git a/gcc/c-family/c-attribs.c b/gcc/c-family/c-attribs.c
index 48819e7..3aefe84 100644
--- a/gcc/c-family/c-attribs.c
+++ b/gcc/c-family/c-attribs.c
@@ -92,6 +92,7 @@ static tree handle_section_attribute (tree *, tree, tree, 
int, bool *);
 static tree handle_aligned_attribute (tree *, tree, tree, int, bool *);
 static tree handle_warn_if_not_aligned_attribute (tree *, tree, tree,
  int, bool *);
+static tree handle_noinit_attribute (tree *, tree, tree, int, bool *);
 static tree handle_weak_attribute (tree *, tree, tree, int, bool *) ;
 static tree handle_noplt_attribute (tree *, tree, tree, int, bool *) ;
 static tree handle_alias_ifunc_attribute (bool, tree *, tree, tree, bool *);
@@ -458,6 +459,8 @@ const struct attribute_spec c_common_attribute_table[] =
  handle_nocf_check_attribute, NULL },
   { "copy",   1, 1, false, false, false, false,
  handle_copy_attribute, NULL },
+  { "noinit", 0, 0, true,  false, false, false,
+ handle_noinit_attribute, NULL },
   { NULL, 0, 0, false, false, false, false, NULL, NULL }
 };
 
@@ -1912,6 +1915,13 @@ handle_section_attribute (tree *node, tree ARG_UNUSED 
(name), tree args,
   goto fail;
 }
 
+  if (DECL_P (decl) && lookup_attribute ("noinit", DECL_ATTRIBUTES (decl)) != 
NULL_TREE)
+{
+  warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wattributes,
+   "section attribute cannot be applied to variables with noinit 
attribute");
+  goto fail;
+}
+
   set_decl_section_name (decl, TREE_STRING_POINTER (TREE_VALUE (args)));
   return NULL_TREE;
 
@@ -2224,6 +2234,48 @@ handle_weak_attribute (tree *node, tree name,
   return NULL_TREE;
 }
 
+/* Handle a "noinit" attribute; arguments as in struct
+   attribute_spec.handler. Check whether the attribute is allowed here
+   and add the attribute to the variable decl tree or otherwise issue
+   a diagnostic. Th

Re: [PATCH,RFC] collect2 LTO for AIX

2019-07-04 Thread David Edelsohn
On Thu, Jul 4, 2019 at 10:38 AM Martin Liška  wrote:
>
> Hi.
>
> Recently I've introduced a new .gnu.lto_.lto section that
> is supposed to provide meta information about a LTO bytecode.
>
> As a further step, I'm planning to teach binutils about
> existence of the section and I'll remove in the future
> emission of __gnu_lto_slim and __gnu_lto_v1 symbols.
> The former one is used by binutils to identify if
> an object is a slim LTO object. The later one is currently
> used only in gcc/collect2.c and was added by David's patch.
>
> My question is: Can we remove __gnu_lto_v1 right now and
> XCOFF will use something similar to ELF (has_lto_section)?
> Can you David help me with that please?

LTO currently does not work on AIX. I added the __gnu_lto_v1 as a
test. You can rip it out and XCOFF will follow a different path when
implementing LTO.

Thanks David


Re: [PATCH,RFC] collect2 LTO for AIX

2019-07-04 Thread Martin Liška
Hi.

Recently I've introduced a new .gnu.lto_.lto section that
is supposed to provide meta information about a LTO bytecode.

As a further step, I'm planning to teach binutils about
existence of the section and I'll remove in the future
emission of __gnu_lto_slim and __gnu_lto_v1 symbols.
The former one is used by binutils to identify if
an object is a slim LTO object. The later one is currently
used only in gcc/collect2.c and was added by David's patch.

My question is: Can we remove __gnu_lto_v1 right now and
XCOFF will use something similar to ELF (has_lto_section)?
Can you David help me with that please?

Thank you,
Martin




[OG9] Improve diagnostics for unmappable types

2019-07-04 Thread Andrew Stubbs

This patch has now been backported to openacc-gcc-9-branch (git).

Andre

On 01/07/2019 12:16, Andrew Stubbs wrote:

Improve OpenMP map diagnostics.

2019-07-01  Andrew Stubbs

gcc/cp/
* cp-tree.h (cp_omp_emit_unmappable_type_notes): New prototype.
* decl.c (cp_finish_decl): Call cp_omp_emit_unmappable_type_notes.
* decl2.c (cp_omp_mappable_type): Move contents to ...
(cp_omp_mappable_type_1):  ... here and add note output.
(cp_omp_emit_unmappable_type_notes): New function.
* semantics.c (finish_omp_clauses): Call
cp_omp_emit_unmappable_type_notes in four places.

gcc/testsuite/
* g++.dg/gomp/unmappable-1.C: New file.

===

diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index bf47f67721e..a7b2151e6dd 100644

--- a/gcc/cp/cp-tree.h

+++ b/gcc/cp/cp-tree.h

@@ -6533,6 +6533,7 @@

  extern int parm_index   (tree);

extern tree vtv_start_verification_constructor_init_function (void);
extern tree vtv_finish_verification_constructor_init_function (tree);
extern bool cp_omp_mappable_type (tree);
+extern bool cp_omp_emit_unmappable_type_notes (tree);
extern void cp_check_const_attributes (tree);
/* in error.c */

===

diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 5d49535b0d9..74343bc1ec4 100644

--- a/gcc/cp/decl.c

+++ b/gcc/cp/decl.c

@@ -7433,8 +7433,11 @@

  cp_finish_decl (tree decl, tree init, bool init_const_expr_p,

DECL_ATTRIBUTES (decl));
complete_type (TREE_TYPE (decl));
if (!cp_omp_mappable_type (TREE_TYPE (decl)))
- error ("%q+D in declare target directive does not have mappable type",
- decl);
+ {
+ error ("%q+D in declare target directive does not have mappable"
+ " type", decl);
+ cp_omp_emit_unmappable_type_notes (TREE_TYPE (decl));
+ }
else if (!lookup_attribute ("omp declare target",
DECL_ATTRIBUTES (decl))
&& !lookup_attribute ("omp declare target link",

===

diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c
index 206f04c6320..b415716c7dd 100644

--- a/gcc/cp/decl2.c

+++ b/gcc/cp/decl2.c

@@ -1406,32 +1406,68 @@

  cp_check_const_attributes (tree attributes)

}
}
-/* Return true if TYPE is an OpenMP mappable type. */
-bool
-cp_omp_mappable_type (tree type)
+/* Return true if TYPE is an OpenMP mappable type.
+ If NOTES is non-zero, emit a note message for each problem. */
+static bool
+cp_omp_mappable_type_1 (tree type, bool notes)
{
+ bool result = true;
+
/* Mappable type has to be complete. */
if (type == error_mark_node || !COMPLETE_TYPE_P (type))
- return false;
+ {
+ if (notes)
+ {
+ tree decl = TYPE_MAIN_DECL (type);
+ inform ((decl ? DECL_SOURCE_LOCATION (decl) : input_location),
+ "incomplete type %qT is not mappable", type);
+ }
+ result = false;
+ }
/* Arrays have mappable type if the elements have mappable type. */
while (TREE_CODE (type) == ARRAY_TYPE)
type = TREE_TYPE (type);
/* A mappable type cannot contain virtual members. */
if (CLASS_TYPE_P (type) && CLASSTYPE_VTABLES (type))
- return false;
+ {
+ if (notes)
+ inform (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (type)),
+ "type %qT with virtual members is not mappable", type);
+ result = false;
+ }
/* All data members must be non-static. */
if (CLASS_TYPE_P (type))
{
tree field;
for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
if (VAR_P (field))
- return false;
+ {
+ if (notes)
+ inform (DECL_SOURCE_LOCATION (field),
+ "static field %qD is not mappable", field);
+ result = false;
+ }
/* All fields must have mappable types. */
else if (TREE_CODE (field) == FIELD_DECL
- && !cp_omp_mappable_type (TREE_TYPE (field)))
- return false;
+ && !cp_omp_mappable_type_1 (TREE_TYPE (field), notes))
+ result = false;
}
- return true;
+ return result;
+}
+
+/* Return true if TYPE is an OpenMP mappable type. */
+bool
+cp_omp_mappable_type (tree type)
+{
+ return cp_omp_mappable_type_1 (type, false);
+}
+
+/* Return true if TYPE is an OpenMP mappable type.
+ Emit an error messages if not. */
+bool
+cp_omp_emit_unmappable_type_notes (tree type)
+{
+ return cp_omp_mappable_type_1 (type, true);
}
/* Return the last pushed declaration for the symbol DECL or NULL

===

diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index 92c48753d42..8f019580d0f 100644

--- a/gcc/cp/semantics.c

+++ b/gcc/cp/semantics.c

@@ -7090,6 +7090,7 @@

  finish_omp_clauses (tree clauses, enum c_omp_region_type ort)

"array section does not have mappable type "
"in %qs clause",
omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
+ cp_omp_emit_unmappable_type_notes (TREE_TYPE (t));
remove = true;
}
while (TREE_CODE (t) == ARRAY_REF)

@@ -7158,6 +7159,7 @@

  finish_omp_clauses (tree clauses, enum c_omp_region_type ort)

error_at (OMP_CLAUSE_LOCATION (c),
"%qE does not have a mappable type in %qs clause",
t, omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
+ cp_omp_emit_unmappable_type_notes (TREE_TYPE (t));
remove = true;
}
w

Re: [PATCH] [Ada] Make clockid_t type public on GNU/kFreeBSD

2019-07-04 Thread Arnaud Charlet
> checked in. Ok for the gcc-9 branch as well?

Yes.


Re: [PATCH] [Ada] Make clockid_t type public on GNU/kFreeBSD

2019-07-04 Thread Matthias Klose
On 04.07.19 08:50, Arnaud Charlet wrote:
> OK, thanks.

checked in. Ok for the gcc-9 branch as well?

Matthias

>> From: James Clarke 
>>
>> Monotonic_Clock and RT_Resolution in the recently-added s-tpopmo.adb
>> call clock_gettime/clock_getres with the integral constants from OSC and
>> thus rely on clockid_t being an integral type, so we cannot hide it on
>> GNU/kFreeBSD. Instead, make the definition public to match all the other
>> implementations.
>>
>> gcc/ada
>>  * libgnarl/s-osinte__kfreebsd-gnu.ads (clockid_t): Make type
>>  definition public.
>>  (CLOCK_REALTIME): Make value public.
>> ---
>>  gcc/ada/libgnarl/s-osinte__kfreebsd-gnu.ads | 8 ++--
>>  1 file changed, 2 insertions(+), 6 deletions(-)
>>
>> diff --git a/gcc/ada/libgnarl/s-osinte__kfreebsd-gnu.ads 
>> b/gcc/ada/libgnarl/s-osinte__kfreebsd-gnu.ads
>> index 408187314..b60ffd2c0 100644
>> --- a/gcc/ada/libgnarl/s-osinte__kfreebsd-gnu.ads
>> +++ b/gcc/ada/libgnarl/s-osinte__kfreebsd-gnu.ads
>> @@ -206,9 +206,8 @@ package System.OS_Interface is
>> function nanosleep (rqtp, rmtp : access timespec) return int;
>> pragma Import (C, nanosleep, "nanosleep");
>>
>> -   type clockid_t is private;
>> -
>> -   CLOCK_REALTIME : constant clockid_t;
>> +   type clockid_t is new int;
>> +   CLOCK_REALTIME : constant clockid_t := 0;
>>
>> function clock_gettime
>>   (clock_id : clockid_t;
>> @@ -607,9 +606,6 @@ private
>> end record;
>> pragma Convention (C, timespec);
>>
>> -   type clockid_t is new int;
>> -   CLOCK_REALTIME : constant clockid_t := 0;
>> -
>> type pthread_attr_t is record
>>detachstate   : int;
>>schedpolicy   : int;
>> --
>> 2.17.1
>>



Re: [C++ Patch] PR 90909 ("[10 Regression] call devirtualized to pure virtual")

2019-07-04 Thread Paolo Carlini

Hi,

On 27/06/19 23:19, Jason Merrill wrote:
Ah, thanks.  Then perhaps we want to change the CLASSTYPE_FINAL in 
build_over_call to resolves_to_fixed_type_p (arg), to also handle the 
other reasons we might know the dynamic type of the argument, and 
remove the related code from build_new_method_call_1?


You could avoid needing to move the conditional lower by comparing 
DECL_CONTEXT (fn) and BINFO_TYPE (cand->conversion_path) rather than 
parmtype and TREE_TYPE (converted_arg).


Sorry for late replying, a few days off.

Anyway, great, it looks like we are reaching a nice synthesis. I must 
admit that until yesterday I hadn't noticed that Fabien dealt precisely 
with using declarations in order to fix c++/11750, thus the existing 
check in build_new_method_call_1 is exactly what we need. The below does 
that and passes testing, in it I didn't keep the checks of DECL_VINDEX 
(fn) && ! (flags & LOOKUP_NONVIRTUAL) which don't seem necessary, might 
avoid function calls, though. Let me know...


Thanks, Paolo.




Index: cp/call.c
===
--- cp/call.c   (revision 273076)
+++ cp/call.c   (working copy)
@@ -8241,10 +8241,17 @@ build_over_call (struct z_candidate *cand, int fla
return error_mark_node;
}
 
-  /* See if the function member or the whole class type is declared
-final and the call can be devirtualized.  */
+  /* Optimize away vtable lookup if we know that this
+function can't be overridden.  We need to check if
+the context and the type where we found fn are the same,
+actually FN might be defined in a different class
+type because of a using-declaration. In this case, we
+do not want to perform a non-virtual call.  Note that
+resolves_to_fixed_type_p checks CLASSTYPE_FINAL too.  */
   if (DECL_FINAL_P (fn)
- || CLASSTYPE_FINAL (TYPE_METHOD_BASETYPE (TREE_TYPE (fn
+ || (resolves_to_fixed_type_p (arg, 0)
+ && same_type_ignoring_top_level_qualifiers_p
+ (DECL_CONTEXT (fn), BINFO_TYPE (cand->conversion_path 
flags |= LOOKUP_NONVIRTUAL;
 
   /* [class.mfct.nonstatic]: If a nonstatic member function of a class
@@ -9845,17 +9852,6 @@ build_new_method_call_1 (tree instance, tree fns,
 
  if (call != error_mark_node)
{
- /* Optimize away vtable lookup if we know that this
-function can't be overridden.  We need to check if
-the context and the type where we found fn are the same,
-actually FN might be defined in a different class
-type because of a using-declaration. In this case, we
-do not want to perform a non-virtual call.  */
- if (DECL_VINDEX (fn) && ! (flags & LOOKUP_NONVIRTUAL)
- && same_type_ignoring_top_level_qualifiers_p
- (DECL_CONTEXT (fn), BINFO_TYPE (binfo))
- && resolves_to_fixed_type_p (instance, 0))
-   flags |= LOOKUP_NONVIRTUAL;
   if (explicit_targs)
 flags |= LOOKUP_EXPLICIT_TMPL_ARGS;
  /* Now we know what function is being called.  */
Index: testsuite/g++.dg/other/final4.C
===
--- testsuite/g++.dg/other/final4.C (nonexistent)
+++ testsuite/g++.dg/other/final4.C (working copy)
@@ -0,0 +1,16 @@
+// PR c++/67184
+// { dg-do compile { target c++11 } }
+// { dg-options "-fdump-tree-original"  }
+
+struct B
+{
+  virtual void operator()();
+  virtual operator int();
+  virtual int operator++();
+};
+
+struct D final : B { };
+
+void foo(D& d) { d(); int t = d; ++d; }
+
+// { dg-final { scan-tree-dump-times "OBJ_TYPE_REF" 0 "original" } }


Re: Enable nonoverallping_component_refs even after the base pointers are equivalent

2019-07-04 Thread Jan Hubicka
> 
> Why does this only happen in fre3?!
After fre1 we have

test (int i, int j, int k, int l)
{ 
  struct c * cptr.0_1;
  struct c * cptr2.1_2;
  int _11;

   :
  cptr.0_1 = cptr;
  cptr.0_1->b[i_5(D)].a[j_6(D)].val = 123;
  cptr2.1_2 = cptr2;
  cptr2.1_2->b[k_8(D)].a2[l_9(D)].val = 2;
  _11 = cptr.0_1->b[i_5(D)].a[j_6(D)].val;
  return _11;
}

I think it is the same issue with AO querries not being valueized
you fixed for the other testcase and later reverted.

Honza


Re: [PATCH] [Ada] Make clockid_t type public on GNU/kFreeBSD

2019-07-04 Thread Arnaud Charlet
> I don't have commit access so could you please do so on my behalf?

No, I won't be able to do that unfortunately.

By the way do you have a copyright assignment in place?

Arno


[PATCH] Perform case-insensitive comparison when decoding register names (PR target/70320)

2019-07-04 Thread Jozef Lawrynowicz
The attached patch allows the case of register names used in an asm statement
clobber list to be disregarded when checking the validity of the register names.

Currently, the register name used in asm statement clobber list must exactly
match those defined in the targets REGISTER_NAMES macro.

This means that, for example, for msp430-elf the following code emits an
ambiguous error:

> void
> foo (void)
> {
>   __asm__ ("" : : : "r4", "R6");
> }

> asm-register-names.c:8:3: error: unknown register name 'r4' in 'asm'

All the register names defined in the msp430 REGISTER_NAMES macro use an
upper case 'R', so use of lower case 'r' gets rejected.

I guess this could also be fixed by defining all the registers in
ADDITIONAL_REGISTER_NAMES using a lower case r, but I prefer this generic
solution and I cannot think of any negative side effects to what is proposed.
Using the wrong case of a register name does not make its use ambiguous, and
allows users to stylize the clobber list with upper/lower case register names
as they wish.

Successfully bootstrapped and regtested for x86_64-pc-linux-gnu, and regtested
for msp430-elf.

Ok for trunk?
>From 6275eb1c915b574f415c4adaf241d2d200c42cce Mon Sep 17 00:00:00 2001
From: Jozef Lawrynowicz 
Date: Thu, 4 Jul 2019 11:25:04 +0100
Subject: [PATCH] Perform case-insensitive comparison when decoding register
 names

gcc/ChangeLog:

2019-07-04  Jozef Lawrynowicz  

	PR target/70320
	* varasm.c (decode_reg_name_and_count): Use strcasecmp when comparing
	register names with asmspec.

gcc/testsuite/ChangeLog:

2019-07-04  Jozef Lawrynowicz  

	PR target/70320
	* gcc.target/msp430/asm-register-names.c: New test.
---
 .../gcc.target/msp430/asm-register-names.c  | 13 +
 gcc/varasm.c| 10 +-
 2 files changed, 18 insertions(+), 5 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/msp430/asm-register-names.c

diff --git a/gcc/testsuite/gcc.target/msp430/asm-register-names.c b/gcc/testsuite/gcc.target/msp430/asm-register-names.c
new file mode 100644
index 000..5c31c23d9db
--- /dev/null
+++ b/gcc/testsuite/gcc.target/msp430/asm-register-names.c
@@ -0,0 +1,13 @@
+/* { dg-do compile } */
+/* { dg-final { scan-assembler "PUSH.*R4" } } */
+/* { dg-final { scan-assembler "PUSH.*R6" } } */
+
+/* PR target/70320
+   Check that both lower and upper case "r" is accepted in asm statement
+   clobber list.  */
+
+void
+foo (void)
+{
+  __asm__ ("" : : : "r4", "R6");
+}
diff --git a/gcc/varasm.c b/gcc/varasm.c
index 626a4c9f9a0..892f678e9e9 100644
--- a/gcc/varasm.c
+++ b/gcc/varasm.c
@@ -947,7 +947,7 @@ decode_reg_name_and_count (const char *asmspec, int *pnregs)
 
   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
 	if (reg_names[i][0]
-	&& ! strcmp (asmspec, strip_reg_name (reg_names[i])))
+	&& ! strcasecmp (asmspec, strip_reg_name (reg_names[i])))
 	  return i;
 
 #ifdef OVERLAPPING_REGISTER_NAMES
@@ -961,7 +961,7 @@ decode_reg_name_and_count (const char *asmspec, int *pnregs)
 
 	for (i = 0; i < (int) ARRAY_SIZE (table); i++)
 	  if (table[i].name[0]
-	  && ! strcmp (asmspec, table[i].name))
+	  && ! strcasecmp (asmspec, table[i].name))
 	{
 	  *pnregs = table[i].nregs;
 	  return table[i].number;
@@ -976,16 +976,16 @@ decode_reg_name_and_count (const char *asmspec, int *pnregs)
 
 	for (i = 0; i < (int) ARRAY_SIZE (table); i++)
 	  if (table[i].name[0]
-	  && ! strcmp (asmspec, table[i].name)
+	  && ! strcasecmp (asmspec, table[i].name)
 	  && reg_names[table[i].number][0])
 	return table[i].number;
   }
 #endif /* ADDITIONAL_REGISTER_NAMES */
 
-  if (!strcmp (asmspec, "memory"))
+  if (!strcasecmp (asmspec, "memory"))
 	return -4;
 
-  if (!strcmp (asmspec, "cc"))
+  if (!strcasecmp (asmspec, "cc"))
 	return -3;
 
   return -2;
-- 
2.17.1



Re: [PATCH] Try fix PR90911

2019-07-04 Thread Jan Hubicka
> On Tue, 25 Jun 2019, Richard Biener wrote:
> 
> > 
> > PR90911 reports a slowdown of 456.hmmer with the recent introduction
> > of vectorizer versioning of outer loops, more specifically the case
> > of re-using if-conversion created versions.
> > 
> > The patch below fixes things up to adjust the edge probability
> > and scale the loop bodies in two steps, delaying scalar_loop
> > scaling until all peeling is done.  This restores profile-mismatches
> > to the same state as it was on the GCC 9 branch and seems to
> > fix the observed slowdown of 456.hmmer.
> > 
> > Boostrap & regtest running on x86_64-unknown-linux-gnu.
> > 
> > Honza, does this look OK?
> 
> Ping.
Sorry for taking time - i meant to look into what is happening here.
hmmer works faster with your patch w/o PGO however we now have 20%
improvement on PGO runs this week (as seen in LNT)
https://lnt.opensuse.org/db_default/v4/SPEC/graph?plot.0=7.180.0
So the long standing issue of hmmer with PGO seems to be related to this
update.
> 
> > Thanks,
> > Richard.
> > 
> > 2019-06-25  Richard Biener  
> > 
> > * tree-vectorizer.h (_loop_vec_info::scalar_loop_scaling): New field.
> > (LOOP_VINFO_SCALAR_LOOP_SCALING): new.
> > * tree-vect-loop.c (_loop_vec_info::_loop_vec_info): Initialize
> > scalar_loop_scaling.
> > (vect_transform_loop): Scale scalar loop profile if needed.
> > * tree-vect-loop-manip.c (vect_loop_versioning): When re-using
> > the loop copy from if-conversion adjust edge probabilities
> > and scale the vectorized loop body profile, queue the scalar
> > profile for updating after peeling.
> > 
> > Index: gcc/tree-vectorizer.h
> > ===
> > --- gcc/tree-vectorizer.h   (revision 272636)
> > +++ gcc/tree-vectorizer.h   (working copy)
> > @@ -548,6 +548,9 @@ typedef struct _loop_vec_info : public v
> >/* Mark loops having masked stores.  */
> >bool has_mask_store;
> >  
> > +  /* Queued scaling factor for the scalar loop.  */
> > +  profile_probability scalar_loop_scaling;
> > +
> >/* If if-conversion versioned this loop before conversion, this is the
> >   loop version without if-conversion.  */
> >struct loop *scalar_loop;
> > @@ -603,6 +606,7 @@ typedef struct _loop_vec_info : public v
> >  #define LOOP_VINFO_PEELING_FOR_NITER(L)(L)->peeling_for_niter
> >  #define LOOP_VINFO_NO_DATA_DEPENDENCIES(L) (L)->no_data_dependencies
> >  #define LOOP_VINFO_SCALAR_LOOP(L) (L)->scalar_loop
> > +#define LOOP_VINFO_SCALAR_LOOP_SCALING(L)  (L)->scalar_loop_scaling
> >  #define LOOP_VINFO_HAS_MASK_STORE(L)   (L)->has_mask_store
> >  #define LOOP_VINFO_SCALAR_ITERATION_COST(L) (L)->scalar_cost_vec
> >  #define LOOP_VINFO_SINGLE_SCALAR_ITERATION_COST(L) 
> > (L)->single_scalar_iteration_cost
> > Index: gcc/tree-vect-loop.c
> > ===
> > --- gcc/tree-vect-loop.c(revision 272636)
> > +++ gcc/tree-vect-loop.c(working copy)
> > @@ -835,6 +835,7 @@ _loop_vec_info::_loop_vec_info (struct l
> >  operands_swapped (false),
> >  no_data_dependencies (false),
> >  has_mask_store (false),
> > +scalar_loop_scaling (profile_probability::uninitialized ()),
> >  scalar_loop (NULL),
> >  orig_loop_info (NULL)
> >  {
> > @@ -8562,6 +8563,10 @@ vect_transform_loop (loop_vec_info loop_
> >epilogue = vect_do_peeling (loop_vinfo, niters, nitersm1, &niters_vector,
> >   &step_vector, &niters_vector_mult_vf, th,
> >   check_profitability, niters_no_overflow);
> > +  if (LOOP_VINFO_SCALAR_LOOP (loop_vinfo)
> > +  && LOOP_VINFO_SCALAR_LOOP_SCALING (loop_vinfo).initialized_p ())
> > +scale_loop_frequencies (LOOP_VINFO_SCALAR_LOOP (loop_vinfo),
> > +   LOOP_VINFO_SCALAR_LOOP_SCALING (loop_vinfo));
> >  
> >if (niters_vector == NULL_TREE)
> >  {
> > Index: gcc/tree-vect-loop-manip.c
> > ===
> > --- gcc/tree-vect-loop-manip.c  (revision 272636)
> > +++ gcc/tree-vect-loop-manip.c  (working copy)
> > @@ -3114,8 +3114,17 @@ vect_loop_versioning (loop_vec_info loop
> >  GSI_SAME_STMT);
> > }
> >  
> > -  /* ???  if-conversion uses profile_probability::always () but
> > - prob below is profile_probability::likely ().  */
> > +  /* if-conversion uses profile_probability::always () for both paths,
> > +reset the paths probabilities appropriately.  */
> > +  edge te, fe;
> > +  extract_true_false_edges_from_block (condition_bb, &te, &fe);
> > +  te->probability = prob;
> > +  fe->probability = prob.invert ();
> > +  /* We can scale loops counts immediately but have to postpone
> > + scaling the scalar loop because we re-use it during peeling.  */
> > +  scale_loop_frequencies (loop_to_version, prob);
> > +  LOOP_VINFO_SCALAR

Re: [PATCH] Fix PR91062

2019-07-04 Thread Jan Hubicka
> 
> The following avoids GC collecting during pass execution when a pass
> calls cgraph::get_body.
> 
> Bootstrapped / tested on x86_64-unknown-linux-gnu.
> 
> OK?
> 
> Thanks,
> Richard.
> 
> 2019-07-03  Richard Biener  
> 
>   PR ipa/91062
>   * tree-pass.h (execute_all_ipa_transforms): Add a flag
>   parameter whether to disable GC collection.
>   * passes.c (execute_one_ipa_transform_pass): Likewise, and
>   honor it.
>   (execute_all_ipa_transforms): Likewise and pass it down.
>   * cgraph.c (cgraph_node::get_body): Do not invoke garbage
>   collection from applying IPA transforms.
>   * cgraphunit.c (cgraph_node::expand): Allow garbage collection
>   from applying IPA transforms.

OK, thanks!
I am not sure how much the garbage collectin between individual
transforms is necessary - i suspect the ggc_collect call there is just
result of copying code executing normal passes, but it is fine to
disable it selectively for sure.

Honza


Re: [patch, c++ openmp] Improve diagnostics for unmappable types

2019-07-04 Thread Andrew Stubbs

On 03/07/2019 18:58, Jason Merrill wrote:

OK, thanks.


Committed.

Thanks for the reviews.

Andrew



Re: [PATCH] [Ada] Make clockid_t type public on GNU/kFreeBSD

2019-07-04 Thread James Clarke
I don't have commit access so could you please do so on my behalf?

This bug applies to the 9 branch too, so please consider backporting it.

Thanks,
James

> On 4 Jul 2019, at 07:50, Arnaud Charlet  wrote:
> 
> OK, thanks.
> 
>> From: James Clarke 
>> 
>> Monotonic_Clock and RT_Resolution in the recently-added s-tpopmo.adb
>> call clock_gettime/clock_getres with the integral constants from OSC and
>> thus rely on clockid_t being an integral type, so we cannot hide it on
>> GNU/kFreeBSD. Instead, make the definition public to match all the other
>> implementations.
>> 
>> gcc/ada
>>  * libgnarl/s-osinte__kfreebsd-gnu.ads (clockid_t): Make type
>>  definition public.
>>  (CLOCK_REALTIME): Make value public.
>> ---
>> gcc/ada/libgnarl/s-osinte__kfreebsd-gnu.ads | 8 ++--
>> 1 file changed, 2 insertions(+), 6 deletions(-)
>> 
>> diff --git a/gcc/ada/libgnarl/s-osinte__kfreebsd-gnu.ads 
>> b/gcc/ada/libgnarl/s-osinte__kfreebsd-gnu.ads
>> index 408187314..b60ffd2c0 100644
>> --- a/gcc/ada/libgnarl/s-osinte__kfreebsd-gnu.ads
>> +++ b/gcc/ada/libgnarl/s-osinte__kfreebsd-gnu.ads
>> @@ -206,9 +206,8 @@ package System.OS_Interface is
>>function nanosleep (rqtp, rmtp : access timespec) return int;
>>pragma Import (C, nanosleep, "nanosleep");
>> 
>> -   type clockid_t is private;
>> -
>> -   CLOCK_REALTIME : constant clockid_t;
>> +   type clockid_t is new int;
>> +   CLOCK_REALTIME : constant clockid_t := 0;
>> 
>>function clock_gettime
>>  (clock_id : clockid_t;
>> @@ -607,9 +606,6 @@ private
>>end record;
>>pragma Convention (C, timespec);
>> 
>> -   type clockid_t is new int;
>> -   CLOCK_REALTIME : constant clockid_t := 0;
>> -
>>type pthread_attr_t is record
>>   detachstate   : int;
>>   schedpolicy   : int;
>> --
>> 2.17.1
>> 



Re: [PATCH] S/390: Improve storing asan frame_pc

2019-07-04 Thread Ilya Leoshkevich
> Am 03.07.2019 um 22:47 schrieb Richard Sandiford :
> 
> Segher Boessenkool  writes:
>> On Tue, Jul 02, 2019 at 03:55:56PM +0200, Ilya Leoshkevich wrote:
 Am 02.07.2019 um 15:39 schrieb Jakub Jelinek :
 On Tue, Jul 02, 2019 at 03:33:28PM +0200, Ilya Leoshkevich wrote:
>> Am 02.07.2019 um 15:19 schrieb Segher Boessenkool 
>> :
>> 
>> On Tue, Jul 02, 2019 at 08:02:16AM -0500, Segher Boessenkool wrote:
>>> On Tue, Jul 02, 2019 at 10:51:54AM +0200, Ilya Leoshkevich wrote:
 +#undef TARGET_INSN_ALIGNMENT
 +#define TARGET_INSN_ALIGNMENT 16
>>> 
>>> There already is FUNCTION_BOUNDARY for something similar, which fits in
>>> well with STACK_BOUNDARY, PARM_BOUNDARY, many more *_BOUNDARY.  I 
>>> realise
>>> you may prefer a hook, but as long as we aren't getting rid of all the
>>> other macros, what's the point?
>> 
>> And maybe LABEL_BOUNDARY is bettter for this than INSN_BOUNDARY as well?
> 
> Can’t we just use FUNCTION_BOUNDARY then?
> I think .LASANPC is always emitted at the beginning of a function.
 
 Isn't e.g. the hotpatch sequence emitted before it?
>>> 
>>> You are right, with -fpatchable-function-entry it’s moved.
>>> 
>>> So, I guess I should stick with the current approach.
>>> I could change TARGET_INSN_ALIGNMENT hook to INSN_BOUNDARY macro if that
>>> would better match the current design.  I would still call it INSN, and
>>> not LABEL, because LABEL can refer to data.
>> 
>> On some archs LABEL_BOUNDARY can be bigger than INSN_BOUNDARY (just like
>> FUNCTION_BOUNDARY can be even bigger, like on 390 :-) )
>> 
>> Either will work for your purposes afaics.
>> 
>> LABEL in RTL is always a CODE_LABEL I think?  Maybe CODE_LABEL_BOUNDARY
>> would make it clearer, it's not like a short name for this is useful
>> anyway.
> 
> IIUC the new value is effectively a mandatory/guaranteed minimum value of
> align_labels/LABEL_ALIGN that applies even in blocks optimized for size.
> So IMO sticking with *_ALIGNMENT would be better.

The new value should definitely be consistent with LABEL_ALIGN.  Still,
it is supposed to be applied primarily to trees, not rtxes, and I think
that in this regard it groups nicer with *_BOUNDARY macros.

Best regards,
Ilya


Re: [PATCH] Fix loading of lto_section on strict alignment targets (PR lto/91078).

2019-07-04 Thread Richard Biener
On Thu, Jul 4, 2019 at 9:01 AM Martin Liška  wrote:
>
> Hi.
>
> The patch fixes wrong assignment from a char * to lto_section_header
> that is seen on strict alignment targets.
>
> I verified it fixes the problem with -fsanitize=undefined:
>
> gcc main.o -flto
> ../../gcc/lto/lto-common.c:2202:36: runtime error: reference binding to 
> misaligned address 0x7f64dac090a7 for type 'const struct lto_section', which 
> requires 4 byte alignment
> 0x7f64dac090a7: note: pointer points here
>  00 1b c0 02 09  00 00 00 03 00 00 00 28  b5 2f fd 60 77 00 d5 08  00 e6 d1 
> 3d 37 20 01 09  00 bf 53
>  ^
> ../../gcc/lto/lto-common.c:2202:33: runtime error: load of misaligned address 
> 0x7f64dac090a7 for type 'const struct lto_section', which requires 4 byte 
> alignment
> 0x7f64dac090a7: note: pointer points here
>  00 1b c0 02 09  00 00 00 03 00 00 00 28  b5 2f fd 60 77 00 d5 08  00 e6 d1 
> 3d 37 20 01 09  00 bf 53
>  ^
>
> Ready for trunk?

OK.

> Thanks,
> Martin
>
> gcc/lto/ChangeLog:
>
> 2019-07-04  Martin Liska  
>
> PR lto/91078
> * lto-common.c (lto_file_finalize): Use memcpy to set
> file_data->lto_section_header.
> ---
>  gcc/lto/lto-common.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
>


Re: allow EH to escape from GIMPLE_EH_ELSE ELSE block

2019-07-04 Thread Richard Biener
On Thu, Jul 4, 2019 at 10:29 AM Alexandre Oliva  wrote:
>
> On Jul  2, 2019, Richard Biener  wrote:
>
> > Yeah, it's on trunk.  The parser is ontop of the C frontend and resides
> > in gcc/c/gimple-parser.c while testcases are in gcc.dg/gimplefe-*.c
>
> > The parsing is incomplete, there's no support for parsing try/catch/finally
>
> I'm afraid I haven't got very far, but I tried.  It didn't recognize try
> and finally as keywords, and since the parser is integrated with the C
> parser IIUC, I wasn't sure how to enable the keywords only within gimple
> functions.

Yeah.  For other stuff we're simply looking at CPP_NAME and
string-matching, see c_parser_gimple_compound_statement
where you'd probably hook this into.



> As mentioned in another message, I chose try/finally/else as the
> notation for TRY_FINALLY_EXPR <..., EH_ELSE_EXPR <..., ...> >, to avoid
> introducing yet another keyword such as eh_finally.
>
> I also considered try/noexcept/finally, or try/noexcept finally/finally,
> but...  else seems to be a lot more closely related with EH_ELSE_EXPR,
> and at least in gimple it's non-ambiguous.
>
>
> introduce try/finally/else in gimplefe (WIP FTR)
>
> From: Alexandre Oliva 
>
>
> ---
>  gcc/c/gimple-parser.c  |   49 
> 
>  gcc/testsuite/gcc.dg/gimplefe-43.c |   13 ++
>  2 files changed, 62 insertions(+)
>  create mode 100644 gcc/testsuite/gcc.dg/gimplefe-43.c
>
> diff --git a/gcc/c/gimple-parser.c b/gcc/c/gimple-parser.c
> index b2b364cc41a3..91f2499bb1cc 100644
> --- a/gcc/c/gimple-parser.c
> +++ b/gcc/c/gimple-parser.c
> @@ -115,6 +115,7 @@ static struct c_expr 
> c_parser_gimple_postfix_expression_after_primary
>  static void c_parser_gimple_declaration (gimple_parser &);
>  static void c_parser_gimple_goto_stmt (gimple_parser &, location_t,
>tree, gimple_seq *);
> +static void c_parser_gimple_try_stmt (gimple_parser &, gimple_seq *);
>  static void c_parser_gimple_if_stmt (gimple_parser &, gimple_seq *);
>  static void c_parser_gimple_switch_stmt (gimple_parser &, gimple_seq *);
>  static void c_parser_gimple_return_stmt (gimple_parser &, gimple_seq *);
> @@ -405,6 +406,9 @@ c_parser_gimple_compound_statement (gimple_parser 
> &parser, gimple_seq *seq)
> case CPP_KEYWORD:
>   switch (c_parser_peek_token (parser)->keyword)
> {
> +   case RID_AT_TRY:
> + c_parser_gimple_try_stmt (parser, seq);
> + break;
> case RID_IF:
>   c_parser_gimple_if_stmt (parser, seq);
>   break;
> @@ -2088,6 +2092,51 @@ c_parser_gimple_paren_condition (gimple_parser &parser)
>return cond;
>  }
>
> +/* Parse gimple try statement.
> +
> +   try-statement:
> + try { ... } finally { ... }
> + try { ... } finally { ... } else { ... }
> +
> +   This could support try/catch as well, but it's not implemented yet.
> + */
> +
> +static void
> +c_parser_gimple_try_stmt (gimple_parser &parser, gimple_seq *seq)
> +{
> +  gimple_seq tryseq = NULL;
> +  c_parser_consume_token (parser);
> +  c_parser_gimple_compound_statement (parser, &tryseq);
> +
> +  if (c_parser_next_token_is (parser, CPP_KEYWORD)
> +  && c_parser_peek_token (parser)->keyword == RID_AT_FINALLY)
> +{
> +  gimple_seq finseq = NULL;
> +  c_parser_consume_token (parser);
> +  c_parser_gimple_compound_statement (parser, &finseq);
> +
> +  if (c_parser_next_token_is (parser, CPP_KEYWORD)
> + && c_parser_peek_token (parser)->keyword == RID_ELSE)
> +   {
> + gimple_seq elsseq = NULL;
> + c_parser_consume_token (parser);
> + c_parser_gimple_compound_statement (parser, &finseq);
> +
> + geh_else *stmt = gimple_build_eh_else (finseq, elsseq);
> + finseq = NULL;
> + gimple_seq_add_stmt_without_update (&finseq, stmt);
> +   }
> +
> +  gtry *stmt = gimple_build_try (tryseq, finseq, GIMPLE_TRY_FINALLY);
> +  gimple_seq_add_stmt_without_update (seq, stmt);
> +}
> +  else if (c_parser_next_token_is (parser, CPP_KEYWORD)
> +  && c_parser_peek_token (parser)->keyword == RID_AT_CATCH)
> +c_parser_error (parser, "% is not supported");
> +  else
> +c_parser_error (parser, "expected % or %");
> +}
> +
>  /* Parse gimple if-else statement.
>
> if-statement:
> diff --git a/gcc/testsuite/gcc.dg/gimplefe-43.c 
> b/gcc/testsuite/gcc.dg/gimplefe-43.c
> new file mode 100644
> index ..c740e06a78e1
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/gimplefe-43.c
> @@ -0,0 +1,13 @@
> +/* { dg-do compile } */
> +/* { dg-options "-fgimple" } */
> +
> +void __GIMPLE foo()
> +{
> +  try {
> +;
> +  } finally {
> +;
> +  } else {
> +;
> +  }
> +}
>
>
> --
> Alexandre Oliva, freedom fighter  he/him   https://FSFLA.org/blogs/lxo
> Be the change, be Free! FSF Latin America board member
> GNU Toolchain EngineerFree Software Evangelist
> 

Re: introduce EH_ELSE tree and gimplifier

2019-07-04 Thread Richard Biener
On Thu, Jul 4, 2019 at 10:19 AM Alexandre Oliva  wrote:
>
> On Jul  1, 2019, Richard Biener  wrote:
>
> > On Fri, Jun 28, 2019 at 5:21 AM Alexandre Oliva  wrote:
> >>
> >> On Jun 27, 2019, Richard Biener  wrote:
> >>
> >> > On Thu, Jun 27, 2019 at 10:18 AM Alexandre Oliva  
> >> > wrote:
> >>
> >> >> @@ -909,6 +909,13 @@ DEFTREECODE (TRY_CATCH_EXPR, "try_catch_expr", 
> >> >> tcc_statement, 2)
> >> >> The second operand is a cleanup expression which is evaluated
> >> >> on any exit (normal, exception, or jump out) from this expression.  */
> >> >> DEFTREECODE (TRY_FINALLY_EXPR, "try_finally", tcc_statement, 2)
> >> >> +
> >> >> +/* Evaluate either the normal or the exceptional cleanup.  This must
> >> >> +   only be present as the cleanup expression in a TRY_FINALLY_EXPR.
> >> >> +   If the TRY_FINALLY_EXPR completes normally, the first operand of
> >> >> +   EH_ELSE is used as a cleanup, otherwise the second operand is
> >> >> +   used.  */
> >> >> +DEFTREECODE (EH_ELSE, "eh_else", tcc_statement, 2)
> >>
> >> > It's a bit weird that this is a tcc_statement as opposed to 
> >> > tcc_expression,
>
> >> Erhm...  What's weird about it?  It is not something that belongs in an
> >> arbitrary expr, it's a lot more like a top-level statement, like
> >> try_finally, having side effects but no useful value.
>
> > It's weird because it appears in a TRY_FINALLY statement operand.
>
> The other operand could be a nested TRY_FINALLY, but that doesn't make
> TRY_FINALLY a tcc_expression.
>
> > But I guess the line between statements and expressions in GENERIC
> > is muddy...
>
> My understanding of the general rule is that tcc_expressions have
> values, whereas tcc_statements don't.

Oh, that makes sense indeed.

> >> > also I'd have called it EH_ELSE_EXPR for clarity.
>
> >> Now *that* would be weird IMHO.  No offense intended, but I'd have
> >> dropped the _EXPR from TRY_FINALLY_EXPR to make it match the
> >> "try_finally" string.
>
> > OK, let me say for consistency then ...
>
> Ok, I like that one ;-) I've adjusted the "try_finally" string, and
> changed EH_ELSE to EH_ELSE_EXPR all over (but not in GIMPLE_EH_ELSE).
>
> I've also changed the way TRY_FINALLY_EXPR/EH_ELSE_EXPR are output in
> generic and gimple dumps, using the notation try/finally/else (this is
> the notation I started using in my unfinished gimplefe attempt, to avoid
> adding more keywords; more in another message).  I've retained the
> ability to dump GIMPLE_EH_EXPR separately, because I'm not entirely sure
> it could never be separated from the enclosing TRY_FINALLY_EXPR.
>
>
> introduce EH_ELSE_EXPR tree and gimplifier
>
> I found GIMPLE_EH_ELSE offered exactly the semantics I needed for some
> Ada changes yet to be contributed, but GIMPLE_EH_ELSE was only built
> by GIMPLE passes, and I needed to build earlier something that
> eventually became GIMPLE_EH_ELSE.
>
> This patch does that, introducing an EH_ELSE_EXPR tree, and logic to
> dump it and to gimplify it.
>
> Regstrapped on x86_64-linux-gnu.  Ok to install?

OK.

Thanks,
Richard.

>
>
> for  gcc/ChangeLog
>
> * doc/generic.texi (Cleanups): Document EH_ELSE_EXPR.
> * except.c: Likewise.
> * expr.c (expand_expr_real_1): Reject it.
> * gimplify.c (gimplify_expr): Gimplify it, within
> TRY_FINALLY_EXPR.
> * tree-dump.c (dequeue_and_dump): Dump it.
> * tree-pretty-print.c (dump_generic_node): Likewise.
> * tree.c (block_may_fallthru): Handle it.
> * tree.def (EH_ELSE_EXPR): Introduce it.
> * gimple-pretty-print.c (dump_gimple_try): Dump TRY_FINALLY
> with GIMPLE_EH_ELSE as try/finally/else.
> ---
>  gcc/doc/generic.texi  |5 +
>  gcc/except.c  |   12 ++--
>  gcc/expr.c|1 +
>  gcc/gimple-pretty-print.c |   20 +++-
>  gcc/gimplify.c|   18 +-
>  gcc/tree-dump.c   |1 +
>  gcc/tree-pretty-print.c   |   28 +---
>  gcc/tree.c|3 +++
>  gcc/tree.def  |9 -
>  9 files changed, 85 insertions(+), 12 deletions(-)
>
> diff --git a/gcc/doc/generic.texi b/gcc/doc/generic.texi
> index 67f7ad53af6b..8901d5f357e2 100644
> --- a/gcc/doc/generic.texi
> +++ b/gcc/doc/generic.texi
> @@ -2180,6 +2180,11 @@ After the second sequence is executed, if it completes 
> normally by
>  falling off the end, execution continues wherever the first sequence
>  would have continued, by falling off the end, or doing a goto, etc.
>
> +If the second sequence is an @code{EH_ELSE_EXPR} selector, then the
> +sequence in its first operand is used when the first sequence completes
> +normally, and that in its second operand is used for exceptional
> +cleanups, i.e., when an exception propagates out of the first sequence.
> +
>  @code{TRY_FINALLY_EXPR} complicates the flow graph, since the cleanup
>  needs to appear on every edge out of the controlled block; this
>  reduces the freed

Re: [PATCH,RFC,V3 0/5] Support for CTF in GCC

2019-07-04 Thread Richard Biener
On Thu, Jul 4, 2019 at 2:36 AM Indu Bhagat  wrote:
>
>
> On 07/03/2019 05:31 AM, Richard Biener wrote:
> > On Wed, Jul 3, 2019 at 5:18 AM Jeff Law  wrote:
> >> On 7/2/19 11:54 AM, Indu Bhagat wrote:
> >>> Ping.
> >>> Can someone please review these patches ? We would like to get the
> >>> support for CTF integrated soon.
> >> I'm not sure there's really even consensus that we want CTF support in
> >> GCC.  Though I think that the changes you've made in the last several
> >> weeks do make it somewhat more palatable.  But ultimately the first step
> >> is to get that consensus.
> >>
> >> I'd hazard a guess that Jakub in particular isn't on board as he's been
> >> pushing to some degree for post-processing or perhaps doing it via a
> >> plug in.
> >>
> >> Richi has been guiding you a bit through how to make the changes easier
> >> to integrate, but I haven't seen him state one way or the other his
> >> preference on whether or not CTF support is something we want.
> > I'm mostly worried about the lack of a specification and the appearant
> > restriction on a subset of C (the patches have gcc_unreachable ()
> > in paths that can be reached by VECTOR_TYPE or COMPLEX_TYPE
> > not to mention FIXED_POINT_TYPE, etc...).
>
> RE lack of specification : I cannot agree more; This does need to absolutely 
> exist
> if we envision CTF support in toolchain to be useful to the community.
> We plan on getting to this task once the Linker changes are scoped and closer
> to done (~ a couple of weeks from now). Will this work ?

Sure - just keep in mind that it's difficult to give feedback to
something without
a specification.

> RE subset of C : It is true that CTF format currently does leave out a very
> small subset of C like FIXED_POINT as you noted ( CTF does have representation
> for COMPLEX_TYPE, if my code paths culminate to gcc_unreachable () for that, I
> should fix them ).  The end goal is to make it support all of C, and not just 
> a
> subset.

What about other languages?  GCC supports C++, Ada, Objective-C, Go, D,
Fortran, Modula-2, BRIG (this list is not necessarily complete and may change
in the future).

> Meanwhile, I intend to make the compiler skip types when a C construct is not
> supported instead of crashing because of gcc_unreachable (). (You may have 
> also
> noted stubs with "TBD WARN instead" notes in the patch series I sent.)
>
>
> >
> > While CTF might be easy and fast to parse and small I fear it will
> > go the STABS way of being not extensible and bitrotten.
>
> FWIW, I can understand this. We will maintain it. And I hope it will also be a
> community effort thereafter with active consumers, so there is a positive
> feedback loop.
>
> >
> > Given it appears to generate only debug info for symbols and no locations
> > or whatnot it should be sufficient to introspect the compilation to generate
> > the CTF info on the side and then merge it in at link-time.  Which makes
> > me wonder if this shouldn't be a plugin for now until it is more complete
> > and can be evaluated better (comments in the patches indicate even the
> > on-disk format is in flux?).  Adding plugin hook invocations to the three
> > places the CTF info generation hooks off should be easy.
>
> Yes, some bits of the on-disk format are being adapted to make it easier to
> adopt the CTF format across the board. E.g., we recently added CU name in the
> CTF header. As another example, we added CTF_K_SLICE type because there 
> existed
> no way in CTF to represent enum bitfields. For the most part though, CTF 
> format
> has stayed as is.

I hope the format is versioned at least.

> Hmm...a GCC plugin for CTF generation at compile-time may work out for a 
> single
> compilation unit.  But I am not sure how will LTO be supported in that case.
> Basically, for LTO and -gtLEVEL to work together, I need the lto-wrapper to be
> aware of the presence of .ctf sections (so I think). I will need to combine 
> the
> .ctf sections from multiple compilation units into a CTF archive, which the
> linker can then de-duplicate.

True.  lto-wrapper does this kind of dancing for the much more complex set of
DWARF sections already.

> Even if I assume that the technical hurdle in the above paragraph is solvable
> within the purview of a plugin, I fear worse problems of adoption, maintenance
> and distribution in the long run, if CTF support unfortunately ever remains 
> to be
> done via a plugin for reasons unforeseen.
>
> Going the plugin route for the short term, will continue to suffer similar
> problems of distribution and support.
>
> - Is the plugin infrastructure supported on most platforms ? Also, I see that
>the plugin infrastructure supports all gcc versions from 4.5 onwards.
>Can someone confirm ? ( We minimally want the toolchain support with
>GCC 4.8.5 and GCC 8 and later, for now. )

The infrastructure is quite old but you'd need new invocation hooks so this
won't help.

> - How will the plugin be distributed for a variety of pl

Re: [committed] Add scan support for OpenMP worksharing loops

2019-07-04 Thread Christophe Lyon
On Thu, 4 Jul 2019 at 12:29, Jakub Jelinek  wrote:
>
> On Thu, Jul 04, 2019 at 12:28:12PM +0200, Christophe Lyon wrote:
> > This patch leads to new failures on arm:
> > FAIL: c-c++-common/gomp/scan-3.c (internal compiler error)
> > FAIL: c-c++-common/gomp/scan-5.c (internal compiler error)
>
> PR91074, already fixed?
>

Ha yes, sorry for the noise.
For some reason, the messages related to this PR didn't pop up when I
checked my mailbox for such reports to avoid duplication.

Christophe


> Jakub


Re: [range-ops] patch 01/04: types for VR_UNDEFINED and VR_VARYING

2019-07-04 Thread Richard Biener
On Wed, Jul 3, 2019 at 2:17 PM Aldy Hernandez  wrote:
>
> On 7/3/19 7:08 AM, Richard Biener wrote:
> > On Wed, Jul 3, 2019 at 11:19 AM Aldy Hernandez  wrote:
> >>
> >>
> >>
> >> On 7/3/19 4:28 AM, Richard Biener wrote:
> >>> On Mon, Jul 1, 2019 at 10:52 AM Aldy Hernandez  wrote:
> 
>  As discussed before, this enforces types on undefined and varying, which
>  makes everything more regular, and removes some special casing
>  throughout range handling.
> >>>
> >>> I don't like it too much given you need to introduce that "cache".
> >>>
> >>> Why do VARYING or UNDEFINED need a type?  Nobody should ever need
> >>> to ask for the type of a range anyhow - the type should be always that 
> >>> from
> >>> the context we're looking at (the SSA name the range is associated with,
> >>> the operation we are performing on one or two ranges, etc.).
> >>>
> >>> Thinking again about this it looks fundamentally wrong to associate
> >>> a type with the VARYING or UNDEFINED lattice states.
> >>
> >> We discussed this 2 weeks ago, and it was my understanding that we had
> >> an reached an agreement on the general approach.  Types on varying and
> >> undefined was the *first* thing I brought up.  Explanation quoted below.
> >
> > Yes, and I asked how you handled that const static node for VARYING
> > which you answered, well - we could do some caching per type and I
> > replied I didn't like that very much.
> >
> > So - I see why it might be "convenient" but I still see no actual
> > technical requirement to have a type for them.  I see you have
> > canonicalization for symbolic ranges to integer ranges so
> > you can have one for varying/undefined to integer ranges as well;
> > just make that canonicalization take a type argument.
> >
> >> By the way, the type for varying/undefined requires no space in the
> >> value_range_base structure, as it is kept in the min/max fields which we
> >> already use for VR_RANGE/VR_ANTI_RANGE.
> >
> > You can as well populate those with actual canonical integer range values
> > then.  [MIN, MAX] and [MAX, MIN] (or whatever we'd consider canonical for
> > the empty range).
> >
> > But as said, point me to the place where you need the type of VARYING.
> > It should already exist since the current code does away without.
> >
> > I refuse to uglify the current VRP with a not needed type-indexed cache
> > for VARYING nodes just to make ranger intergation more happy.   Just
> > ignore that extra 'type' argument in the ranger API then?
>
> Ok, I see.  Your main beef is with the type cache.

yes.

> How about we keep VARYING and UNDEFINED typeless until right before we
> call into the ranger.  At which point, we have can populate min/max
> because we have the tree_code and the type handy.  So right before we
> call into the ranger do:
>
> if (varying_p ())
>   foo->set_varying(TYPE);
>
> This would avoid the type cache, and keep the ranger happy.

you cannot do set_varying on the static const range but instead you'd do

  value_range tem (*foo);
  if (varying_p ())
   tem->set_full_range (TYPE);

which I think we already do in some places.  Thus my question _where_
you actually need this.

> Another option, as you've hinted, would be to normalize VARYING into
> [MIN, MAX] before calling into the ranger.  The problem with this
> approach is that we would then need to change varying_p() to something like:
>
> value_range_base::varying_p()
> {
>return (m_kind == VR_VARYING ||
>   (vrp_val_is_min (m_min) && vrp_val_is_max (m_max));
> }
>
> Thus slowing everyone down (remember both range-ops and tree-vrp will
> share the implementation for varying_p).  Plus, I'd prefer to keep one
> representation for VARYING, that is m_kind == VR_VARYING.

Yes, I wasn't really suggesting the above but have m_kind == VR_VARYING
and for ranges we want to support [MIN, MAX] on have those pre-populated
when we drop sth to varying.  For pointers this range is pointless for example
and the static const could simply leave it unset as well.

> Perhaps this last alternative would be more consistent-- never allowing
> types for VARYING, at the expense of the calls to vrp_val_is*.

It doesn't work for the static const varying though.

Another way to circumvent the issue is to make get_value_range
return NULL if it doesn't have any range in the lattice (thus the
static const varying goes away).  Then callers need to deal with this
of course.

Just teach ranger about different kind of ranges?

Richard.

> Thoughts?
>
> Aldy


Re: [committed] Add scan support for OpenMP worksharing loops

2019-07-04 Thread Jakub Jelinek
On Thu, Jul 04, 2019 at 12:28:12PM +0200, Christophe Lyon wrote:
> This patch leads to new failures on arm:
> FAIL: c-c++-common/gomp/scan-3.c (internal compiler error)
> FAIL: c-c++-common/gomp/scan-5.c (internal compiler error)

PR91074, already fixed?

Jakub


Re: [committed] Add scan support for OpenMP worksharing loops

2019-07-04 Thread Christophe Lyon
On Wed, 3 Jul 2019 at 07:11, Jakub Jelinek  wrote:
>
> Hi!
>
> The following patch implements roughly the
> https://gcc.gnu.org/ml/gcc-patches/2019-06/msg01330.html
> design for worksharing loops (so far not for composite for simd, that will
> be the next larger task).
>
> Bootstrapped/regtested on x86_64-linux and i686-linux, committed to trunk.
>
> 2019-07-03  Jakub Jelinek  
>
> * tree-core.h (enum omp_clause_code): Add OMP_CLAUSE__SCANTEMP_
> clause.
> * tree.h (OMP_CLAUSE_DECL): Use OMP_CLAUSE__SCANTEMP_ instead of
> OMP_CLAUSE__CONDTEMP_ as range's upper bound.
> (OMP_CLAUSE__SCANTEMP__ALLOC, OMP_CLAUSE__SCANTEMP__CONTROL): Define.
> * tree.c (omp_clause_num_ops, omp_clause_code_name): Add
> OMP_CLAUSE__SCANTEMP_ entry.
> (walk_tree_1): Handle OMP_CLAUSE__SCANTEMP_.
> * tree-pretty-print.c (dump_omp_clause): Likewise.
> * tree-nested.c (convert_nonlocal_omp_clauses,
> convert_local_omp_clauses): Likewise.
> * omp-general.h (struct omp_for_data): Add have_scantemp and
> have_nonctrl_scantemp members.
> * omp-general.c (omp_extract_for_data): Initialize them.
> * omp-low.c (struct omp_context): Add scan_exclusive member.
> (scan_omp_1_stmt): Don't unnecessarily mask gimple_omp_for_kind
> result again with GF_OMP_FOR_KIND_MASK.  Initialize also
> ctx->scan_exclusive.
> (lower_rec_simd_input_clauses): Use ctx->scan_exclusive instead
> of !ctx->scan_inclusive.
> (lower_rec_input_clauses): Simplify gimplification of dtors using
> gimplify_and_add.  For non-is_simd test OMP_CLAUSE_REDUCTION_INSCAN
> rather than rvarp.  Handle OMP_CLAUSE_REDUCTION_INSCAN in worksharing
> loops.  Don't add barrier for reduction_omp_orig_ref if
> ctx->scan_??xclusive.
> (lower_reduction_clauses): Don't do anything for ctx->scan_??xclusive.
> (lower_omp_scan): Use ctx->scan_exclusive instead
> of !ctx->scan_inclusive.  Handle worksharing loops with inscan
> reductions.  Use new_vard != new_var instead of repeated
> omp_is_reference calls.
> (omp_find_scan, lower_omp_for_scan): New functions.
> (lower_omp_for): Call lower_omp_for_scan for worksharing loops with
> inscan reductions.
> * omp-expand.c (expand_omp_scantemp_alloc): New function.
> (expand_omp_for_static_nochunk): Handle fd->have_nonctrl_scantemp
> and fd->have_scantemp.
>
> * c-c++-common/gomp/scan-3.c (f1): Don't expect a sorry message.
> * c-c++-common/gomp/scan-5.c (foo): Likewise.
>

Hi Jakub,

This patch leads to new failures on arm:
FAIL: c-c++-common/gomp/scan-3.c (internal compiler error)
FAIL: c-c++-common/gomp/scan-5.c (internal compiler error)


The logs say:
spawn -ignore SIGHUP
/aci-gcc-fsf/builds/gcc-fsf-gccsrc/obj-arm-none-linux-gnueabi/gcc3/gcc/xgcc
-B/aci-gcc-fsf/builds/gcc-fsf-gccsrc/obj-arm-none-linux-gnueabi/gcc3/gcc/
/gcc/testsuite/c-c++-common/gomp/scan-3.c -fno-diagnostics-show-caret
-fno-diagnostics-show-line-numbers -fdiagnostics-color=never -fopenmp
-Wno-hsa -S -o scan-3.s
during RTL pass: expand
/gcc/testsuite/c-c++-common/gomp/scan-3.c: In function 'f1':
/gcc/testsuite/c-c++-common/gomp/scan-3.c:4:1: internal compiler
error: tree check: expected ssa_name, have var_decl in single_imm_use,
at ssa-iterators.h:421
0x5b43ad tree_check_failed(tree_node const*, char const*, int, char const*, ...)
/gcc/tree.c:9902
0x9c18c5 tree_check(tree_node const*, char const*, int, char const*, tree_code)
/gcc/tree.h:3473
0x9c18c5 single_imm_use
/gcc/ssa-iterators.h:421
0x9c18c5 expand_mul_overflow
/gcc/internal-fn.c:1590
0x9c209b expand_arith_overflow
/gcc/internal-fn.c:2318
0x75f807 expand_call_stmt
/gcc/cfgexpand.c:2638
0x75f807 expand_gimple_stmt_1
/gcc/cfgexpand.c:3708
0x75f807 expand_gimple_stmt
/gcc/cfgexpand.c:3867
0x765c73 expand_gimple_basic_block
/gcc/cfgexpand.c:5907
0x7682b6 execute
/gcc/cfgexpand.c:6530
Please submit a full bug report,


Christophe


> * testsuite/libgomp.c++/scan-1.C: New test.
> * testsuite/libgomp.c++/scan-2.C: New test.
> * testsuite/libgomp.c++/scan-3.C: New test.
> * testsuite/libgomp.c++/scan-4.C: New test.
> * testsuite/libgomp.c++/scan-5.C: New test.
> * testsuite/libgomp.c++/scan-6.C: New test.
> * testsuite/libgomp.c++/scan-7.C: New test.
> * testsuite/libgomp.c++/scan-8.C: New test.
> * testsuite/libgomp.c/scan-1.c: New test.
> * testsuite/libgomp.c/scan-2.c: New test.
> * testsuite/libgomp.c/scan-3.c: New test.
> * testsuite/libgomp.c/scan-4.c: New test.
> * testsuite/libgomp.c/scan-5.c: New test.
> * testsuite/libgomp.c/scan-6.c: New test.
> * testsuite/libgomp.c/scan-7.c: New test.
> * testsuite/libgomp.c/scan-8.

Re: [PATCH] Fix loading of lto_section on strict alignment targets (PR lto/91078).

2019-07-04 Thread Rainer Orth
Hi Martin,

> The patch fixes wrong assignment from a char * to lto_section_header
> that is seen on strict alignment targets.
>
> I verified it fixes the problem with -fsanitize=undefined:
>
> gcc main.o -flto
> ../../gcc/lto/lto-common.c:2202:36: runtime error: reference binding to 
> misaligned address 0x7f64dac090a7 for type 'const struct lto_section', which 
> requires 4 byte alignment
> 0x7f64dac090a7: note: pointer points here
>  00 1b c0 02 09  00 00 00 03 00 00 00 28  b5 2f fd 60 77 00 d5 08  00 e6 d1 
> 3d 37 20 01 09  00 bf 53
>  ^ 
> ../../gcc/lto/lto-common.c:2202:33: runtime error: load of misaligned address 
> 0x7f64dac090a7 for type 'const struct lto_section', which requires 4 byte 
> alignment
> 0x7f64dac090a7: note: pointer points here
>  00 1b c0 02 09  00 00 00 03 00 00 00 28  b5 2f fd 60 77 00 d5 08  00 e6 d1 
> 3d 37 20 01 09  00 bf 53
>  ^ 
>
> Ready for trunk?

I've just tested the patch on sparc-sun-solaris2.11: testsuite results
are back to normal again.

Thanks.
Rainer

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


Re: GCC 8 backports

2019-07-04 Thread Martin Liška
I'm sending one more patch that I've tested.

Martin
>From 44e3202c0416fcaa5a145c32118f0d08ff8ea0a2 Mon Sep 17 00:00:00 2001
From: marxin 
Date: Wed, 3 Jul 2019 08:31:35 +
Subject: [PATCH] Backport r272992

gcc/ChangeLog:

2019-07-03  Martin Liska  

	PR middle-end/90899
	* multiple_target.c (create_dispatcher_calls): Add to comdat
	group only if set for ifunc.

gcc/testsuite/ChangeLog:

2019-07-03  Martin Liska  

	PR middle-end/90899
	* gcc.target/i386/pr90899.c: New test.
---
 gcc/multiple_target.c   | 3 ++-
 gcc/testsuite/gcc.target/i386/pr90899.c | 6 ++
 2 files changed, 8 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.target/i386/pr90899.c

diff --git a/gcc/multiple_target.c b/gcc/multiple_target.c
index 87000dba214..97d2268663f 100644
--- a/gcc/multiple_target.c
+++ b/gcc/multiple_target.c
@@ -158,7 +158,8 @@ create_dispatcher_calls (struct cgraph_node *node)
 	{
 	  symtab_node *source = ref->referring;
 	  source->create_reference (inode, IPA_REF_ALIAS);
-	  source->add_to_same_comdat_group (inode);
+	  if (inode->get_comdat_group ())
+		source->add_to_same_comdat_group (inode);
 	}
 	  else
 	gcc_unreachable ();
diff --git a/gcc/testsuite/gcc.target/i386/pr90899.c b/gcc/testsuite/gcc.target/i386/pr90899.c
new file mode 100644
index 000..e0e2d5ac6bb
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr90899.c
@@ -0,0 +1,6 @@
+/* PR middle-end/90899 */
+/* { dg-do compile } */
+/* { dg-require-ifunc "" } */
+
+__attribute__ ((target_clones ("default", "arch=slm"))) static int f () { return 0; }
+__attribute__ ((alias ("f"))) __typeof (f) g;
-- 
2.22.0



Re: GCC 9 backports

2019-07-04 Thread Martin Liška
Hi.

There are 2 more patches that I've just tested.

Martin
>From ae7d66dad2e43e18cf2889803e30e57bc00f88ad Mon Sep 17 00:00:00 2001
From: marxin 
Date: Wed, 3 Jul 2019 08:32:25 +
Subject: [PATCH 2/2] Backport r272993

gcc/ChangeLog:

2019-07-03  Martin Liska  

	PR tree-optimization/90892
	* builtins.c (inline_expand_builtin_string_cmp): Handle '\0'
	in string constants.

gcc/testsuite/ChangeLog:

2019-07-03  Martin Liska  

	PR tree-optimization/90892
	* gcc.dg/pr90892.c: New test.
---
 gcc/builtins.c | 17 ++---
 gcc/testsuite/gcc.dg/pr90892.c | 14 ++
 2 files changed, 28 insertions(+), 3 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/pr90892.c

diff --git a/gcc/builtins.c b/gcc/builtins.c
index d37d73fc4a0..9bcb310c015 100644
--- a/gcc/builtins.c
+++ b/gcc/builtins.c
@@ -7124,8 +7124,19 @@ inline_expand_builtin_string_cmp (tree exp, rtx target)
 return NULL_RTX;
 
   /* For strncmp, if the length is not a const, not qualify.  */
-  if (is_ncmp && !tree_fits_uhwi_p (len3_tree))
-return NULL_RTX;
+  if (is_ncmp)
+{
+  if (!tree_fits_uhwi_p (len3_tree))
+	return NULL_RTX;
+  else
+	len3 = tree_to_uhwi (len3_tree);
+}
+
+  if (src_str1 != NULL)
+len1 = strnlen (src_str1, len1) + 1;
+
+  if (src_str2 != NULL)
+len2 = strnlen (src_str2, len2) + 1;
 
   int const_str_n = 0;
   if (!len1)
@@ -7140,7 +7151,7 @@ inline_expand_builtin_string_cmp (tree exp, rtx target)
   gcc_checking_assert (const_str_n > 0);
   length = (const_str_n == 1) ? len1 : len2;
 
-  if (is_ncmp && (len3 = tree_to_uhwi (len3_tree)) < length)
+  if (is_ncmp && len3 < length)
 length = len3;
 
   /* If the length of the comparision is larger than the threshold,
diff --git a/gcc/testsuite/gcc.dg/pr90892.c b/gcc/testsuite/gcc.dg/pr90892.c
new file mode 100644
index 000..e4b5310807a
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr90892.c
@@ -0,0 +1,14 @@
+/* PR tree-optimization/90892 */
+/* { dg-do run } */
+/* { dg-options "-O2" } */
+
+const char *a = "A\0b";
+
+int
+main()
+{
+  if (__builtin_strncmp(a, "A\0", 2) != 0)
+__builtin_abort ();
+
+  return 0;
+}
-- 
2.22.0

>From 7a9894e91edfff690db6d9e5935585952a025327 Mon Sep 17 00:00:00 2001
From: marxin 
Date: Wed, 3 Jul 2019 08:31:35 +
Subject: [PATCH 1/2] Backport r272992

gcc/ChangeLog:

2019-07-03  Martin Liska  

	PR middle-end/90899
	* multiple_target.c (create_dispatcher_calls): Add to comdat
	group only if set for ifunc.

gcc/testsuite/ChangeLog:

2019-07-03  Martin Liska  

	PR middle-end/90899
	* gcc.target/i386/pr90899.c: New test.
---
 gcc/multiple_target.c   | 3 ++-
 gcc/testsuite/gcc.target/i386/pr90899.c | 6 ++
 2 files changed, 8 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.target/i386/pr90899.c

diff --git a/gcc/multiple_target.c b/gcc/multiple_target.c
index 0a87241b251..e93c60e7adb 100644
--- a/gcc/multiple_target.c
+++ b/gcc/multiple_target.c
@@ -158,7 +158,8 @@ create_dispatcher_calls (struct cgraph_node *node)
 	{
 	  symtab_node *source = ref->referring;
 	  source->create_reference (inode, IPA_REF_ALIAS);
-	  source->add_to_same_comdat_group (inode);
+	  if (inode->get_comdat_group ())
+		source->add_to_same_comdat_group (inode);
 	}
 	  else
 	gcc_unreachable ();
diff --git a/gcc/testsuite/gcc.target/i386/pr90899.c b/gcc/testsuite/gcc.target/i386/pr90899.c
new file mode 100644
index 000..e0e2d5ac6bb
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr90899.c
@@ -0,0 +1,6 @@
+/* PR middle-end/90899 */
+/* { dg-do compile } */
+/* { dg-require-ifunc "" } */
+
+__attribute__ ((target_clones ("default", "arch=slm"))) static int f () { return 0; }
+__attribute__ ((alias ("f"))) __typeof (f) g;
-- 
2.22.0



[Ada] Spurious error on non-default C++ constructor

2019-07-04 Thread Pierre-Marie de Rodat
The frontend reports spurious errors on C++ non-default constructors
that have formals whose type is an access to subprogram.

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

2019-07-04  Javier Miranda  

gcc/ada/

* exp_tss.adb (Init_Proc): Adding missing support for access to
subprograms and access to protected subprograms of non-default
C++ constructors.

gcc/testsuite/

* gnat.dg/cpp_constructor.adb, gnat.dg/cpp_constructor_fp.ads,
gnat.dg/cpp_constructor_useit.ads: New testcase.--- gcc/ada/exp_tss.adb
+++ gcc/ada/exp_tss.adb
@@ -32,6 +32,7 @@ with Lib;  use Lib;
 with Restrict; use Restrict;
 with Rident;   use Rident;
 with Sem_Aux;  use Sem_Aux;
+with Sem_Ch6;  use Sem_Ch6;
 with Sem_Util; use Sem_Util;
 with Sinfo;use Sinfo;
 
@@ -275,8 +276,8 @@ package body Exp_Tss is
   then
  exit;
 
-  elsif Ekind (Etype (E1)) /= E_Anonymous_Access_Type
-and then Ekind (Etype (E2)) /= E_Anonymous_Access_Type
+  elsif not Is_Anonymous_Access_Type (Etype (E1))
+and then not Is_Anonymous_Access_Type (Etype (E2))
 and then Etype (E1) /= Etype (E2)
   then
  exit;
@@ -287,6 +288,17 @@ package body Exp_Tss is
/= Directly_Designated_Type (Etype (E2))
   then
  exit;
+
+  elsif Ekind_In (Etype (E1),
+  E_Anonymous_Access_Subprogram_Type,
+  E_Anonymous_Access_Protected_Subprogram_Type)
+and then Ekind_In (Etype (E2),
+   E_Anonymous_Access_Subprogram_Type,
+   E_Anonymous_Access_Protected_Subprogram_Type)
+and then not Conforming_Types
+   (Etype (E1), Etype (E2), Fully_Conformant)
+  then
+ exit;
   end if;
 
   E1 := Next_Formal (E1);

--- /dev/null
new file mode 100644
+++ gcc/testsuite/gnat.dg/cpp_constructor.adb
@@ -0,0 +1,12 @@
+--  { dg-do compile }
+
+with Interfaces.C; use Interfaces.C;
+with Cpp_Constructor_FP;
+with Cpp_Constructor_Useit;
+
+procedure Cpp_Constructor is
+   F : Cpp_Constructor_FP.Class :=
+ Cpp_Constructor_FP.Constructor (Cpp_Constructor_Useit.My_Fn'Access);
+begin
+   null;
+end Cpp_Constructor;

--- /dev/null
new file mode 100644
+++ gcc/testsuite/gnat.dg/cpp_constructor_fp.ads
@@ -0,0 +1,10 @@
+with Interfaces.C; use Interfaces.C;
+
+package Cpp_Constructor_FP is
+   type Class is limited record null; end record
+   with Convention => Cpp, Import;
+
+   function Constructor
+ (Fn : access function (Val : int) return int) return Class;
+   pragma Cpp_Constructor (Constructor, External_Name => "foo");
+end Cpp_Constructor_FP;

--- /dev/null
new file mode 100644
+++ gcc/testsuite/gnat.dg/cpp_constructor_useit.ads
@@ -0,0 +1,8 @@
+with Interfaces.C; use Interfaces.C;
+
+package Cpp_Constructor_Useit is
+   function My_Fn (Val : int) return int
+   with Convention => Cpp;
+
+   function My_Fn (Val : int) return int is (Val + 1);
+end Cpp_Constructor_Useit;



[Ada] SPARK_Mode Off now allowed inside subprogram

2019-07-04 Thread Pierre-Marie de Rodat
The rule on SPARK_Mode have been modified so that it is now possible to
have a subprogram or package declared with SPARK_Mode Off inside a
subprogram.

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

2019-07-04  Yannick Moy  

gcc/ada/

* sem_prag.adb (Check_Library_Level_Entity): Update for new rule
on SPARK_Mode.

gcc/testsuite/

* gnat.dg/spark3.adb: New testcase.--- gcc/ada/sem_prag.adb
+++ gcc/ada/sem_prag.adb
@@ -23189,7 +23189,16 @@ package body Sem_Prag is
 --  Start of processing for Check_Library_Level_Entity
 
 begin
-   if not Is_Library_Level_Entity (E) then
+   --  A SPARK_Mode of On shall only apply to library-level
+   --  entities, except for those in generic instances, which are
+   --  ignored (even if the entity gets SPARK_Mode pragma attached
+   --  in the AST, its effect is not taken into account unless the
+   --  context already provides SPARK_Mode of On in GNATprove).
+
+   if Get_SPARK_Mode_From_Annotation (N) = On
+ and then not Is_Library_Level_Entity (E)
+ and then Instantiation_Location (Sloc (N)) = No_Location
+   then
   Error_Msg_Name_1 := Pname;
   Error_Msg_N (Fix_Error (Msg_1), N);
 

--- /dev/null
new file mode 100644
+++ gcc/testsuite/gnat.dg/spark3.adb
@@ -0,0 +1,20 @@
+--  { dg-do compile }
+
+procedure SPARK3 (X : in out Integer) with SPARK_Mode is
+
+   procedure Q (X : in out Integer) with SPARK_Mode => Off is
+   begin
+  X := X + 1;
+   end Q;
+
+   procedure R (X : in out Integer);
+
+   procedure R (X : in out Integer) with SPARK_Mode => Off is
+   begin
+  Q (X);
+   end R;
+
+begin
+   R (X);
+   X := X + 1;
+end SPARK3;



[Ada] Missing actual for generated initialization procedure

2019-07-04 Thread Pierre-Marie de Rodat
This patch fixes an issue whereby the use of an allocator with a
composite type containing null-excluding components may lead to a
compile time error due to incorrect code generation.

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

2019-07-04  Justin Squirek  

gcc/ada/

* exp_ch3.adb (Build_Initialization_Call): Fixup
*_skip_null_excluding_check argument to handle new default.
(Init_Formals): Make *_skip_null_excluding_check formal default
to False
* exp_ch4.adb (Expand_N_Allocator): Add comment to note heavy
code duplication

gcc/testsuite/

* gnat.dg/allocator.adb: New testcase.--- gcc/ada/exp_ch3.adb
+++ gcc/ada/exp_ch3.adb
@@ -1555,23 +1555,19 @@ package body Exp_Ch3 is
 
   --  Handle the optionally generated formal *_skip_null_excluding_checks
 
-  if Needs_Conditional_Null_Excluding_Check (Full_Init_Type) then
-
- --  Look at the associated node for the object we are referencing
- --  and verify that we are expanding a call to an Init_Proc for an
- --  internally generated object declaration before passing True and
- --  skipping the relevant checks.
-
- if Nkind (Id_Ref) in N_Has_Entity
-   and then Comes_From_Source (Associated_Node (Id_Ref))
- then
-Append_To (Args, New_Occurrence_Of (Standard_True, Loc));
-
- --  Otherwise, we pass False to perform null-excluding checks
-
- else
-Append_To (Args, New_Occurrence_Of (Standard_False, Loc));
- end if;
+  --  Look at the associated node for the object we are referencing and
+  --  verify that we are expanding a call to an Init_Proc for an internally
+  --  generated object declaration before passing True and skipping the
+  --  relevant checks.
+
+  if Needs_Conditional_Null_Excluding_Check (Full_Init_Type)
+and then Nkind (Id_Ref) in N_Has_Entity
+and then (Comes_From_Source (Id_Ref)
+   or else (Present (Associated_Node (Id_Ref))
+ and then Comes_From_Source
+(Associated_Node (Id_Ref
+  then
+ Append_To (Args, New_Occurrence_Of (Standard_True, Loc));
   end if;
 
   --  Add discriminant values if discriminants are present
@@ -8695,6 +8691,7 @@ package body Exp_Ch3 is
Make_Defining_Identifier (Loc,
  New_External_Name (Chars
(Component_Type (Typ)), "_skip_null_excluding_check")),
+ Expression  => New_Occurrence_Of (Standard_False, Loc),
  In_Present  => True,
  Parameter_Type  =>
New_Occurrence_Of (Standard_Boolean, Loc)));

--- gcc/ada/exp_ch4.adb
+++ gcc/ada/exp_ch4.adb
@@ -4751,6 +4751,9 @@ package body Exp_Ch4 is
 
  --  Case of initialization procedure present, must be called
 
+ --  NOTE: There is a *huge* amount of code duplication here from
+ --  Build_Initialization_Call. We should probably refactor???
+
  else
 Check_Restriction (No_Default_Initialization, N);
 

--- /dev/null
new file mode 100644
+++ gcc/testsuite/gnat.dg/allocator.adb
@@ -0,0 +1,11 @@
+--  { dg-do compile }
+
+procedure Allocator is
+   type Object_Type  is not null access all Integer;
+   type Object_Array is array (Positive range <>) of Object_Type;
+   type Object_Array_Ptr is access Object_Array;
+   type Data_Ptr is access Object_Array_Ptr;
+   Copy : Data_Ptr := new Object_Array_Ptr;
+begin
+   Copy.all := new Object_Array (1..2);
+end;



[Ada] Expr. func. with private formal rejected in nested Ghost package

2019-07-04 Thread Pierre-Marie de Rodat
The compiler prematurely freezes a private type that is the type of a
formal parameter of an expression function declared within a nested,
inactivated Ghost package, resulting is an error complaining that the
private type must be fully defined at that point. This is fixed by
testing for Ignored_Ghost_Entity in the condition guarding the code that
performs Mask_Unfrozen_Types for an expression function without a
separate declaration, ensuring that the expression function's profile
isn't frozen prematurely.

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

2019-07-04  Gary Dismukes  

gcc/ada/

* sem_ch6.adb (Analyze_Subprogram_Body_Helper): The special
treatment of calling Mask_Unfrozen_Types must also be done in
the case of an Ignored_Ghost_Entity, because Expander_Active is
False in that case.

gcc/testsuite/

* gnat.dg/ghost5.adb, gnat.dg/ghost5.ads,
gnat.dg/ghost5_parent.ads: New testcase.--- gcc/ada/sem_ch6.adb
+++ gcc/ada/sem_ch6.adb
@@ -3689,7 +3689,7 @@ package body Sem_Ch6 is
  --  generated. Freeze nodes, if any, are inserted before the current
  --  body. These freeze actions are also needed in ASIS mode and in
  --  Compile_Only mode to enable the proper back-end type annotations.
- --  They are necessary in any case to insure order of elaboration
+ --  They are necessary in any case to ensure proper elaboration order
  --  in gigi.
 
  if Nkind (N) = N_Subprogram_Body
@@ -3698,13 +3698,16 @@ package body Sem_Ch6 is
and then Serious_Errors_Detected = 0
and then (Expander_Active
   or else ASIS_Mode
-  or else Operating_Mode = Check_Semantics)
+  or else Operating_Mode = Check_Semantics
+  or else Is_Ignored_Ghost_Entity (Spec_Id))
  then
 --  The body generated for an expression function that is not a
 --  completion is a freeze point neither for the profile nor for
 --  anything else. That's why, in order to prevent any freezing
 --  during analysis, we need to mask types declared outside the
 --  expression (and in an outer scope) that are not yet frozen.
+--  This also needs to be done in the case of an ignored Ghost
+--  expression function, where the expander isn't active.
 
 Set_Is_Frozen (Spec_Id);
 Mask_Types := Mask_Unfrozen_Types (Spec_Id);

--- /dev/null
new file mode 100644
+++ gcc/testsuite/gnat.dg/ghost5.adb
@@ -0,0 +1,5 @@
+--  { dg-do compile }
+
+package body Ghost5 is
+   procedure Foo is null;
+end Ghost5;

--- /dev/null
new file mode 100644
+++ gcc/testsuite/gnat.dg/ghost5.ads
@@ -0,0 +1,5 @@
+with Ghost5_Parent;
+generic
+package Ghost5 is
+   procedure Foo;
+end Ghost5;

--- /dev/null
new file mode 100644
+++ gcc/testsuite/gnat.dg/ghost5_parent.ads
@@ -0,0 +1,14 @@
+package Ghost5_Parent is
+
+   type Priv is private;
+
+   package Nested with Ghost is
+  function Func1 (X : Priv) return Boolean is (True); -- Error flagged here
+  function Func2 (X : Priv) return Boolean is (False);
+   end Nested;
+
+private
+
+type Priv is new Integer;
+
+end Ghost5_Parent;



[Ada] Spurious error on incomplete tagged formal parameter

2019-07-04 Thread Pierre-Marie de Rodat
This patch fixes an issue whereby a check for competing controlling
formals led to a spurious dispatching error due to an incomplete type
being used within a subprogram specification.

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

2019-07-04  Justin Squirek  

gcc/ada/

* sem_disp.adb (Check_Controlling_Formals): Obtain the full view
before type comparison.

gcc/testsuite/

* gnat.dg/tagged2.adb, gnat.dg/tagged2.ads: New testcase.--- gcc/ada/sem_disp.adb
+++ gcc/ada/sem_disp.adb
@@ -210,6 +210,14 @@ package body Sem_Disp is
  Ctrl_Type := Check_Controlling_Type (Etype (Formal), Subp);
 
  if Present (Ctrl_Type) then
+--  Obtain the full type in case we are looking at an incomplete
+--  view.
+
+if Ekind (Ctrl_Type) = E_Incomplete_Type
+  and then Present (Full_View (Ctrl_Type))
+then
+   Ctrl_Type := Full_View (Ctrl_Type);
+end if;
 
 --  When controlling type is concurrent and declared within a
 --  generic or inside an instance use corresponding record type.

--- /dev/null
new file mode 100644
+++ gcc/testsuite/gnat.dg/tagged2.adb
@@ -0,0 +1,9 @@
+--  { dg-do compile }
+
+package body Tagged2 is
+
+   procedure Get_Parent
+ (DeviceX : Device;
+  Parent  : out Device) is null;
+
+end Tagged2;

--- /dev/null
new file mode 100644
+++ gcc/testsuite/gnat.dg/tagged2.ads
@@ -0,0 +1,9 @@
+package Tagged2 is
+   type Device;
+
+   procedure Get_Parent
+ (DeviceX : Device;
+  Parent  : out Device);
+
+   type Device is tagged null record;
+end Tagged2;



[Ada] Spurious error on 'First in a generic context

2019-07-04 Thread Pierre-Marie de Rodat
This patch fixes a spurious error on an attribute reference within an
aspect specification for an unconstrained array type when the
corresponding type  declaration appears within a generic unit.

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

2019-07-04  Ed Schonberg  

gcc/ada/

* sem_attr.adb (Check_Array_Type): An array type attribute such
as 'First can be applied to an unconstrained array tyope when
the attribute reference appears within an aspect specification
and the prefix is a current instance, given that the prefix of
the attribute will become a formal of the subprogram that
implements the aspect (typically a predicate check).

gcc/testsuite/

* gnat.dg/aspect2.adb, gnat.dg/aspect2.ads: New testcase.--- gcc/ada/sem_attr.adb
+++ gcc/ada/sem_attr.adb
@@ -1634,7 +1634,9 @@ package body Sem_Attr is
 raise Bad_Attribute;
  end if;
 
- --  Normal case of array type or subtype
+ --  Normal case of array type or subtype. Note that if the
+ --  prefix is a current instance of a type declaration it
+ --  appears within an aspect specification and is legal.
 
  Check_Either_E0_Or_E1;
  Check_Dereference;
@@ -1643,6 +1645,7 @@ package body Sem_Attr is
 if not Is_Constrained (P_Type)
   and then Is_Entity_Name (P)
   and then Is_Type (Entity (P))
+  and then not Is_Current_Instance (P)
 then
--  Note: we do not call Error_Attr here, since we prefer to
--  continue, using the relevant index type of the array,

--- /dev/null
new file mode 100644
+++ gcc/testsuite/gnat.dg/aspect2.adb
@@ -0,0 +1,5 @@
+--  { dg-do compile }
+
+package body Aspect2 is
+procedure Foo is null;
+end Aspect2;

--- /dev/null
new file mode 100644
+++ gcc/testsuite/gnat.dg/aspect2.ads
@@ -0,0 +1,30 @@
+with Ada.Containers.Functional_Vectors;
+with Ada.Containers; use Ada.Containers;
+
+generic
+   type Element_Type (<>) is private;
+   type Element_Model (<>) is private;
+   with function Model (X : Element_Type) return Element_Model is <>;
+   with function Copy (X : Element_Type) return Element_Type is <>;
+package Aspect2 with SPARK_Mode is
+   pragma Unevaluated_Use_Of_Old (Allow);
+
+   type Vector is private;
+
+   function Length (V : Vector) return Natural;
+
+   procedure Foo;
+
+private
+   type Element_Access is access Element_Type;
+   type Element_Array is array (Positive range <>) of Element_Access with
+ Dynamic_Predicate => Element_Array'First = 1;
+   type Element_Array_Access is access Element_Array;
+   type Vector is record
+  Top : Natural := 0;
+  Content : Element_Array_Access;
+   end record;
+
+   function Length (V : Vector) return Natural is
+ (V.Top);
+end Aspect2;



[Ada] Bug in composition of equality for variant records

2019-07-04 Thread Pierre-Marie de Rodat
This patch fixes an omission in the construction of equality routines
for variant records, to take into account user-defined equality
functions for components of the record. Previously the constructed
equality routine for variant records used the predefined equality for
all components, When composavility of equality was introduced for
untagged records, expansion of record equality was modified properly,
but not for the case of variant records, which use a different and more
complex process to build the equality function.

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

2019-07-04  Ed Schonberg  

gcc/ada/

* exp_ch4.ads, exp_ch4.adb (Build_Eq_Call): New visible
subprogram, extracted from Expand_Composite_Equality, to handle
properly the composition of equality for variant record types.
* exp_ch3.adb (MAke_Eq_If): Use Build_Eq_Call for each
component, to handle properly the case of a component with a
user-defined equality. Revert to predefined equality if the
user-defined operation is abstract, to maintain compatibility
with older versions,

gcc/testsuite/

* gnat.dg/equal6.adb, gnat.dg/equal6_types.adb,
gnat.dg/equal6_types.ads: New testcase.--- gcc/ada/exp_ch3.adb
+++ gcc/ada/exp_ch3.adb
@@ -9477,6 +9477,11 @@ package body Exp_Ch3 is
 
--  or a null statement if the list L is empty
 
+   --  Equality may be user-defined for a given component type, in which case
+   --  a function call is constructed instead of an operator node. This is an
+   --  Ada 2012 change in the composability of equality for untagged composite
+   --  types.
+
function Make_Eq_If
  (E : Entity_Id;
   L : List_Id) return Node_Id
@@ -9485,6 +9490,8 @@ package body Exp_Ch3 is
   C  : Node_Id;
   Field_Name : Name_Id;
   Cond   : Node_Id;
+  Next_Test  : Node_Id;
+  Typ: Entity_Id;
 
begin
   if No (L) then
@@ -9495,6 +9502,7 @@ package body Exp_Ch3 is
 
  C := First_Non_Pragma (L);
  while Present (C) loop
+Typ:= Etype (Defining_Identifier (C));
 Field_Name := Chars (Defining_Identifier (C));
 
 --  The tags must not be compared: they are not part of the value.
@@ -9507,22 +9515,55 @@ package body Exp_Ch3 is
 --  discriminants could be picked up in the private type case.
 
 if Field_Name = Name_uParent
-  and then Is_Interface (Etype (Defining_Identifier (C)))
+  and then Is_Interface (Typ)
 then
null;
 
 elsif Field_Name /= Name_uTag then
-   Evolve_Or_Else (Cond,
- Make_Op_Ne (Loc,
-   Left_Opnd =>
- Make_Selected_Component (Loc,
-   Prefix=> Make_Identifier (Loc, Name_X),
-   Selector_Name => Make_Identifier (Loc, Field_Name)),
+   declare
+  Lhs : constant Node_Id :=
+Make_Selected_Component (Loc,
+  Prefix=> Make_Identifier (Loc, Name_X),
+  Selector_Name => Make_Identifier (Loc, Field_Name));
 
-   Right_Opnd =>
- Make_Selected_Component (Loc,
-   Prefix=> Make_Identifier (Loc, Name_Y),
-   Selector_Name => Make_Identifier (Loc, Field_Name;
+  Rhs : constant Node_Id :=
+Make_Selected_Component (Loc,
+  Prefix=> Make_Identifier (Loc, Name_Y),
+  Selector_Name => Make_Identifier (Loc, Field_Name));
+  Eq_Call : Node_Id;
+
+   begin
+  --  Build equality code with a user-defined operator, if
+  --  available, and with the predefined "=" otherwise.
+  --  For compatibility with older Ada versions, and preserve
+  --  the workings of some ASIS tools, we also use the
+  --  predefined operation if the component-type equality
+  --  is abstract, rather than raising Program_Error.
+
+  if Ada_Version < Ada_2012 then
+ Next_Test := Make_Op_Ne (Loc, Lhs, Rhs);
+
+  else
+ Eq_Call := Build_Eq_Call (Typ, Loc, Lhs, Rhs);
+
+ if No (Eq_Call) then
+Next_Test := Make_Op_Ne (Loc, Lhs, Rhs);
+
+ --  If a component has a defined abstract equality,
+ --  its application raises Program_Error on that
+ --  component and therefore on the current variant.
+
+ elsif Nkind (Eq_Call) = N_Raise_Program_Error then
+Set_Etype (Eq_Call, Standard_Boolean);
+Next_Test := Make_Op_Not (Loc, Eq_Call);
+
+ else
+  

[Ada] Hang on expansion of library-level instantiation

2019-07-04 Thread Pierre-Marie de Rodat
This patch fixes an issue whereby instantiation of a generic at the
library-level may cause a hang or crash during compilation due to
inappropriate expansion of generic actuals.

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

2019-07-04  Justin Squirek  

gcc/ada/

* sem_ch12.adb (Perform_Appropriate_Analysis): Added for
selecting which type of analysis based on wheither the
instantiation is a generic at the library-level. In which case
expansion during analysis.
(Preanalyze_Actuals): Modify calls to Analyze to use the new
routine.

gcc/testsuite/

* gnat.dg/generic_inst4.adb, gnat.dg/generic_inst4_gen.ads,
gnat.dg/generic_inst4_inst.ads, gnat.dg/generic_inst4_typ.ads:
New testcase.--- gcc/ada/sem_ch12.adb
+++ gcc/ada/sem_ch12.adb
@@ -14103,6 +14103,29 @@ package body Sem_Ch12 is

 
procedure Preanalyze_Actuals (N : Node_Id; Inst : Entity_Id := Empty) is
+
+  procedure Perform_Appropriate_Analysis (N : Node_Id);
+  --  Determine if the actuals we are analyzing come from a generic
+  --  instantiation that is a library unit and dispatch accordingly.
+
+  --
+  -- Perform_Appropriate_Analysis --
+  --
+
+  procedure Perform_Appropriate_Analysis (N : Node_Id) is
+  begin
+ --  When we have a library instantiation we cannot allow any expansion
+ --  to occur, since there may be no place to put it. Instead, in that
+ --  case we perform a preanalysis of the actual.
+
+ if Present (Inst) and then Is_Compilation_Unit (Inst) then
+Preanalyze (N);
+
+ else
+Analyze (N);
+ end if;
+  end Perform_Appropriate_Analysis;
+
   Assoc : Node_Id;
   Act   : Node_Id;
   Errs  : constant Nat := Serious_Errors_Detected;
@@ -14113,6 +14136,8 @@ package body Sem_Ch12 is
   Vis : Boolean := False;
   --  Saved visibility status of the current homograph
 
+   --  Start of processing for Preanalyze_Actuals
+
begin
   Assoc := First (Generic_Associations (N));
 
@@ -14154,10 +14179,10 @@ package body Sem_Ch12 is
null;
 
 elsif Nkind (Act) = N_Attribute_Reference then
-   Analyze (Prefix (Act));
+   Perform_Appropriate_Analysis (Prefix (Act));
 
 elsif Nkind (Act) = N_Explicit_Dereference then
-   Analyze (Prefix (Act));
+   Perform_Appropriate_Analysis (Prefix (Act));
 
 elsif Nkind (Act) = N_Allocator then
declare
@@ -14165,7 +14190,7 @@ package body Sem_Ch12 is
 
begin
   if Nkind (Expr) = N_Subtype_Indication then
- Analyze (Subtype_Mark (Expr));
+ Perform_Appropriate_Analysis (Subtype_Mark (Expr));
 
  --  Analyze separately each discriminant constraint, when
  --  given with a named association.
@@ -14177,9 +14202,10 @@ package body Sem_Ch12 is
 Constr := First (Constraints (Constraint (Expr)));
 while Present (Constr) loop
if Nkind (Constr) = N_Discriminant_Association then
-  Analyze (Expression (Constr));
+  Perform_Appropriate_Analysis
+(Expression (Constr));
else
-  Analyze (Constr);
+  Perform_Appropriate_Analysis (Constr);
end if;
 
Next (Constr);
@@ -14187,12 +14213,12 @@ package body Sem_Ch12 is
  end;
 
   else
- Analyze (Expr);
+ Perform_Appropriate_Analysis (Expr);
   end if;
end;
 
 elsif Nkind (Act) /= N_Operator_Symbol then
-   Analyze (Act);
+   Perform_Appropriate_Analysis (Act);
 
--  Within a package instance, mark actuals that are limited
--  views, so their use can be moved to the body of the
@@ -14213,7 +14239,7 @@ package body Sem_Ch12 is
--  warnings complaining about the generic being unreferenced,
--  before abandoning the instantiation.
 
-   Analyze (Name (N));
+   Perform_Appropriate_Analysis (Name (N));
 
if Is_Entity_Name (Name (N))
  and then Etype (Name (N)) /= Any_Type

--- /dev/null
new file mode 100644
+++ gcc/testsuite/gnat.dg/generic_inst4.adb
@@ -0,0 +1,7 @@
+--  { dg-do compile }
+
+with Generic_Inst4_Inst;
+procedure Generic_Inst4 is
+begin
+   null;
+end;

--- /dev/null
new file mode 100644
+++ gcc/testsuite/gnat.dg/generic_inst4_gen.ads
@@ -0,0 +1,3 @@
+generic
+  Param : String;
+package Generic_Inst4_

[Ada] Clean up support for validity checks in the compiler

2019-07-04 Thread Pierre-Marie de Rodat
This removes old code in the parser that serves no useful purpose and
fixes minor issues in the Validsw package.  No functional changes.

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

2019-07-04  Eric Botcazou  

gcc/ada/

* gnat1drv.adb (Adjust_Global_Switches): Use proper interface to
set the validity settings in CodePeer mode.
* par-load.adb (Load): Remove all code dealing with validity
settings.
* validsw.ads (Validity_Check_Copies): Alphabetize.
* validsw.adb (Reset_Validity_Check_Options): Set all options to
off.
(Save_Validity_Check_Options): Save all options.--- gcc/ada/gnat1drv.adb
+++ gcc/ada/gnat1drv.adb
@@ -379,8 +379,7 @@ procedure Gnat1drv is
  --  enough useful info.
 
  Reset_Validity_Check_Options;
- Validity_Check_Default   := True;
- Validity_Check_Copies:= True;
+ Set_Validity_Check_Options ("dc");
  Check_Validity_Of_Parameters := False;
 
  --  Turn off style check options and ignore any style check pragmas

--- gcc/ada/par-load.adb
+++ gcc/ada/par-load.adb
@@ -36,7 +36,6 @@ with Uname;use Uname;
 with Osint;use Osint;
 with Sinput.L; use Sinput.L;
 with Stylesw;  use Stylesw;
-with Validsw;  use Validsw;
 
 with GNAT.Spelling_Checker; use GNAT.Spelling_Checker;
 
@@ -61,10 +60,6 @@ procedure Load is
Save_Style_Checks : Style_Check_Options;
--  Save style check so it can be restored later
 
-   Save_Validity_Check  : Boolean;
-   Save_Validity_Checks : Validity_Check_Options;
-   --  Save validity check so it can be restored later
-
With_Cunit : Node_Id;
--  Compilation unit node for withed unit
 
@@ -134,9 +129,6 @@ begin
Save_Style_Check_Options (Save_Style_Checks);
Save_Style_Check := Opt.Style_Check;
 
-   Save_Validity_Check_Options (Save_Validity_Checks);
-   Save_Validity_Check := Opt.Validity_Checks_On;
-
--  If main unit, set Main_Unit_Entity (this will get overwritten if
--  the main unit has a separate spec, that happens later on in Load)
 
@@ -318,11 +310,10 @@ begin
  or else Nkind (Unit (Curunit)) in N_Generic_Instantiation
  or else Nkind (Unit (Curunit)) in N_Renaming_Declaration
then
-  --  Turn style and validity checks off for parent unit
+  --  Turn style checks off for parent unit
 
   if not GNAT_Mode then
  Reset_Style_Check_Options;
- Reset_Validity_Check_Options;
   end if;
 
   Spec_Name := Get_Parent_Spec_Name (Unit_Name (Cur_Unum));
@@ -356,11 +347,10 @@ begin
   end if;
end if;
 
-   --  Now we load with'ed units, with style/validity checks turned off
+   --  Now we load with'ed units, with style checks turned off
 
if not GNAT_Mode then
   Reset_Style_Check_Options;
-  Reset_Validity_Check_Options;
end if;
 
--  Load the context items in two rounds: the first round handles normal
@@ -470,6 +460,4 @@ begin
 
Set_Style_Check_Options (Save_Style_Checks);
Opt.Style_Check := Save_Style_Check;
-   Set_Validity_Check_Options (Save_Validity_Checks);
-   Opt.Validity_Checks_On := Save_Validity_Check;
 end Load;

--- gcc/ada/validsw.adb
+++ gcc/ada/validsw.adb
@@ -36,11 +36,12 @@ package body Validsw is
begin
   Validity_Check_Components := False;
   Validity_Check_Copies := False;
-  Validity_Check_Default:= True;
+  Validity_Check_Default:= False;
   Validity_Check_Floating_Point := False;
   Validity_Check_In_Out_Params  := False;
   Validity_Check_In_Params  := False;
   Validity_Check_Operands   := False;
+  Validity_Check_Parameters := False;
   Validity_Check_Returns:= False;
   Validity_Check_Subscripts := False;
   Validity_Check_Tests  := False;
@@ -73,14 +74,14 @@ package body Validsw is
  Options (K) := ' ';
   end loop;
 
-  Add ('n', not Validity_Check_Default);
-
-  Add ('c', Validity_Check_Copies);
   Add ('e', Validity_Check_Components);
+  Add ('c', Validity_Check_Copies);
+  Add ('d', Validity_Check_Default);
   Add ('f', Validity_Check_Floating_Point);
   Add ('i', Validity_Check_In_Params);
   Add ('m', Validity_Check_In_Out_Params);
   Add ('o', Validity_Check_Operands);
+  Add ('p', Validity_Check_Parameters);
   Add ('r', Validity_Check_Returns);
   Add ('s', Validity_Check_Subscripts);
   Add ('t', Validity_Check_Tests);

--- gcc/ada/validsw.ads
+++ gcc/ada/validsw.ads
@@ -40,33 +40,33 @@ package Validsw is
--  or in the argument of a Validity_Checks pragma to activate the option.
--  The corresponding upper case letter deactivates the option.
 
+   Validity_Check_Components : Boolean := False;
+   --  Controls validity checking for assignment to elementary components of
+   --  records. If this switch is set to True using -gnatVe, or an 'e' in the
+   --  argument of Validity_Checks pragma, then the rig

[Ada] Synchronized object definition in SPARK updated

2019-07-04 Thread Pierre-Marie de Rodat
The definition of what types yield synchronized objected in SPARK has
been updated to see through the privacy boundary.

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

2019-07-04  Yannick Moy  

gcc/ada/

* sem_util.adb (Yields_Synchronized_Object): Adapt to new SPARK
rule.

gcc/testsuite/

* gnat.dg/synchronized2.adb, gnat.dg/synchronized2.ads,
gnat.dg/synchronized2_pkg.ads: New testcase.--- gcc/ada/sem_util.adb
+++ gcc/ada/sem_util.adb
@@ -26442,6 +26442,7 @@ package body Sem_Util is
  --  synchronized object.
 
  if Etype (Typ) /= Typ
+   and then not Is_Private_Type (Etype (Typ))
and then not Yields_Synchronized_Object (Etype (Typ))
  then
 return False;
@@ -26457,11 +26458,19 @@ package body Sem_Util is
   elsif Is_Synchronized_Interface (Typ) then
  return True;
 
-  --  A task type yelds a synchronized object by default
+  --  A task type yields a synchronized object by default
 
   elsif Is_Task_Type (Typ) then
  return True;
 
+  --  A private type yields a synchronized object if its underlying type
+  --  does.
+
+  elsif Is_Private_Type (Typ)
+and then Present (Underlying_Type (Typ))
+  then
+ return Yields_Synchronized_Object (Underlying_Type (Typ));
+
   --  Otherwise the type does not yield a synchronized object
 
   else

--- /dev/null
new file mode 100644
+++ gcc/testsuite/gnat.dg/synchronized2.adb
@@ -0,0 +1,5 @@
+with Synchronized2_Pkg;
+package body Synchronized2 with SPARK_Mode, Refined_State => (State => C) is
+   C : Synchronized2_Pkg.T;
+   procedure Dummy is null;
+end;

--- /dev/null
new file mode 100644
+++ gcc/testsuite/gnat.dg/synchronized2.ads
@@ -0,0 +1,4 @@
+--  { dg-do compile }
+package Synchronized2 with SPARK_Mode, Abstract_State => (State with Synchronous) is
+   procedure Dummy;
+end;

--- /dev/null
new file mode 100644
+++ gcc/testsuite/gnat.dg/synchronized2_pkg.ads
@@ -0,0 +1,5 @@
+package Synchronized2_Pkg with SPARK_Mode is
+   type T is limited private;
+private
+   task type T;
+end;



[Ada] Spurious error on instantiation and limited_with_clause

2019-07-04 Thread Pierre-Marie de Rodat
This patch fixes a spurious error during the construction of an instance
body in the inlining phase of the frontend, when the package declaration
for the main unit has a limited_with_clause on some unit P, and the main
unit itself does not have a corresponding regular with_clause, but some
other unit in the context has with_clause that has compiled P.  P must
be removed from visibility to prevent conflicts with homonyms in the
generic body to be instantiated.

The following must compile quietly:

   gcc -c gpr2-project-view.adb


package GNATCOLL is
end GNATCOLL;
package GNATCOLL.Refcount is

   generic
  type Element_Type (<>) is private;
   package Shared_Pointers is
  type Ref is tagged private;

  type Element_Access is access all Element_Type;

  type Reference_Type (Element : access Element_Type)
 is limited null record;

  function Unchecked_Get (Self : Ref'Class) return Element_Access;

  function Get (Self : Ref'Class) return Reference_Type
 is ((Element => Unchecked_Get (Self)));
   private
  type Ref is tagged null record;
   end Shared_Pointers;

   type Refcounted is abstract tagged null record;

   generic
  type Encapsulated is abstract new Refcounted with private;
   package Smart_Pointers is
  type Encapsulated_Access is access all Encapsulated'Class;

  type Ref is tagged private;

  procedure Set (Self : in out Ref; Data : Encapsulated'Class);
  procedure Set (Self : in out Ref; Data : access Encapsulated'Class);
   private
  type Ref is tagged null record;
   end Smart_Pointers;

end GNATCOLL.Refcount;

package body GNATCOLL.Refcount is

   package body Shared_Pointers is

  function Unchecked_Get (Self : Ref'Class) return Element_Access is
  begin
 return null;
  end Unchecked_Get;

   end Shared_Pointers;

   package body Smart_Pointers is

  procedure Set (Self : in out Ref; Data : access Encapsulated'Class) is
  begin
 null;
  end Set;

  procedure Set (Self : in out Ref; Data : Encapsulated'Class) is
 Tmp : constant Encapsulated_Access := new Encapsulated'Class'(Data);
  begin
 Set (Self, Tmp);
  end Set;

   end Smart_Pointers;
end GNATCOLL.Refcount;

package GPR2 is
end GPR2;

package GPR2.Parser is
end GPR2.Parser;

with GPR_Parser.Analysis;
package GPR2.Parser.Project is
end GPR2.Parser.Project;

package GPR2.Project is
end GPR2.Project;

with GPR2.Parser.Project;
package GPR2.Project.Configuration is
end GPR2.Project.Configuration;

with GPR2.Project.Configuration;
with GPR2.Unit.Set;
package GPR2.Project.Definition is
end GPR2.Project.Definition;

limited with GPR2.Unit.Set;
package GPR2.Project.View is
   procedure Require_Body;
end GPR2.Project.View;

with GPR2.Project.Definition;
package body GPR2.Project.View is
   procedure Require_Body is null;
end GPR2.Project.View;

package GPR2.Unit is
end GPR2.Unit;

package GPR2.Unit.Set is
end GPR2.Unit.Set;
...
package GPR_Parser is
end GPR_Parser;

with GNATCOLL.Refcount;
package GPR_Parser.Analysis is

   type Unit_Provider_Interface is null record;

   package Unit_Provider_References is new GNATCOLL.Refcount.Shared_Pointers
 (Unit_Provider_Interface);

end GPR_Parser.Analysis;

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

2019-07-04  Ed Schonberg  

gcc/ada/

* sem_ch10.adb (Remove_Context_Clauses): Handle properly the
removal of a limited_with_clause which appears in the library
unit oF the main unit, when some other unit in the context has a
regular with_clause on the same unit, to prevent spurious
visibility errors in the subsequent analysis of pending instance
bodies.--- gcc/ada/sem_ch10.adb
+++ gcc/ada/sem_ch10.adb
@@ -6379,22 +6379,38 @@ package body Sem_Ch10 is
 
begin
   --  Ada 2005 (AI-50217): We remove the context clauses in two phases:
-  --  limited-views first and regular-views later (to maintain the
-  --  stack model).
+  --  limited-views first and regular-views later (to maintain the stack
+  --  model).
 
   --  First Phase: Remove limited_with context clauses
 
   Item := First (Context_Items (N));
   while Present (Item) loop
 
- --  We are interested only in with clauses which got installed
- --  on entry.
+ --  We are interested only in with clauses that got installed on entry
 
  if Nkind (Item) = N_With_Clause
and then Limited_Present (Item)
-   and then Limited_View_Installed (Item)
  then
-Remove_Limited_With_Clause (Item);
+if Limited_View_Installed (Item) then
+   Remove_Limited_With_Clause (Item);
+
+--  An unusual case: If the library unit of the Main_Unit has
+--  a limited with_clause on some unit P and the context somewhere
+--  includes a with_clause on P, P has been analyzed. The entity
+

[Ada] Management of internal data structures in Sem_Elab

2019-07-04 Thread Pierre-Marie de Rodat
This patch modifies the timing of Sem_Elab's internal data structure
creation and destruction, and adds the concept of "active" elaboration
compiler phase.

The elaboration phase of the compiler is active after the frontend
initializes Sem_Elab. It is at this point that all internal data
structures of Sem_Elab are created and become ready to accept data.

The elaboration phase of the compiler is completed after all elaboration
scenarios are examined, all ABE checks are intalled, and diagnostics are
emitted. It is at this point that all internal data structures of
Sem_Elab are destroyed. Further attempts to reintroduce data into
Sem_Elab by subsequent compiler phases are cut off.

Compilation using GCC unaffected.

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

2019-07-04  Hristian Kirtchev  

gcc/ada/

* sem_elab.adb: Add new type Elaboration_Phase_Status along with
a global to keep track of the elaboration phase status.
Initialize all internal data structures to Nil for services
Elaborated_Units, Internal_Representation, and Scenario_Storage.
(Build_Call_Marker): Do not create a call marker when the
elaboration phase is not active.
(Build_Variable_Reference_Marker): Do not create a call marker
when the elaboration phase is not active.
(Check_Elaboration_Scenarios): Destroy all internal structures
when the elaboration phase does not have to run. Do not execute
when the elaboration phase is not active.
(Elaboration_Phase_Active): New routine.
(Finalize_All_Data_Structures): New routine.
(Initialize): Initialize all internal data structures and signal
that the elaboration phase has started.
(Initialize_All_Data_Structures): New routine.
(Initialize_Elaborated_Units): Initialize all internal data
structures.
(Initialize_Internal_Representation): Initialize all internal
data structures.
(Initialize_Scenario_Storage): Initialize all internal data
structures.
(Kill_Elaboration_Scenario): Do not execute when the elaboration
phase is not active.
(Set_Elaboration_Phase): New routine.
(Update_Elaboration_Scenario): Do not execute when the
elaboration phase is not active.--- gcc/ada/sem_elab.adb
+++ gcc/ada/sem_elab.adb
@@ -676,6 +676,22 @@ package body Sem_Elab is
-- Kinds --
---
 
+   --  The following type enumerates all possible elaboration phase statutes
+
+   type Elaboration_Phase_Status is
+ (Inactive,
+  --  The elaboration phase of the compiler has not started yet
+
+  Active,
+  --  The elaboration phase of the compiler is currently in progress
+
+  Completed);
+  --  The elaboration phase of the compiler has finished
+
+   Elaboration_Phase : Elaboration_Phase_Status := Inactive;
+   --  The status of the elaboration phase. Use routine Set_Elaboration_Phase
+   --  to alter its value.
+
--  The following type enumerates all subprogram body traversal modes
 
type Body_Traversal_Kind is
@@ -1958,6 +1974,14 @@ package body Sem_Elab is
--  Return the type of subprogram Subp_Id's first formal parameter. If the
--  subprogram lacks formal parameters, return Empty.
 
+   function Elaboration_Phase_Active return Boolean;
+   pragma Inline (Elaboration_Phase_Active);
+   --  Determine whether the elaboration phase of the compilation has started
+
+   procedure Finalize_All_Data_Structures;
+   pragma Inline (Finalize_All_Data_Structures);
+   --  Destroy all internal data structures
+
function Has_Body (Pack_Decl : Node_Id) return Boolean;
pragma Inline (Has_Body);
--  Determine whether package declaration Pack_Decl has a corresponding body
@@ -1984,6 +2008,10 @@ package body Sem_Elab is
--  context ignoring enclosing library levels. Nested_OK should be set when
--  the context of N1 can enclose that of N2.
 
+   procedure Initialize_All_Data_Structures;
+   pragma Inline (Initialize_All_Data_Structures);
+   --  Create all internal data structures
+
function Instantiated_Generic (Inst : Node_Id) return Entity_Id;
pragma Inline (Instantiated_Generic);
--  Obtain the generic instantiated by instance Inst
@@ -2027,6 +2055,10 @@ package body Sem_Elab is
pragma Inline (Scenario);
--  Return the appropriate scenario node for scenario N
 
+   procedure Set_Elaboration_Phase (Status : Elaboration_Phase_Status);
+   pragma Inline (Set_Elaboration_Phase);
+   --  Change the status of the elaboration phase of the compiler to Status
+
procedure Spec_And_Body_From_Entity
  (Id: Node_Id;
   Spec_Decl : out Node_Id;
@@ -3572,6 +3604,12 @@ package body Sem_Elab is
   elsif Preanalysis_Active then
  return;
 
+  --  Nothing to do when the elaboration phase of the compiler is not
+  --  active.
+
+  elsif not Elaboration_Phase_Active then
+ return;
+
   --  Nothing 

[Ada] Better error messages for ownership errors in SPARK

2019-07-04 Thread Pierre-Marie de Rodat
When SPARK code does not follow the ownership rules of SPARK RM 3.10,
the error message now points to a location explaining why the object has
a more restricted permission than the expected one.

There is no impact on compilation.

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

2019-07-04  Yannick Moy  

gcc/ada/

* sem_spark.adb (Explanation, Get_Expl): New functions to get
the explanation for a permission mismatch.
(Perm_Error, Perm_Mismatch, Perm_Error_Loop_Exit): Take
explanation into account for issuing a more precise error
message.
(Set_Perm_Prefixes, Set_Perm_Extensions,
Set_Perm_Extensions_Move): Pass suitable argument for the
explanation node.--- gcc/ada/sem_spark.adb
+++ gcc/ada/sem_spark.adb
@@ -137,6 +137,9 @@ package body Sem_SPARK is
  --  corresponds to both "observing" and "owning" types in SPARK RM
  --  3.10. To be used when moving the path.
 
+ Explanation : Node_Id;
+ --  Node that can be used in an explanation for a permission mismatch
+
  case Kind is
 --  An entire object is either a leaf (an object which cannot be
 --  extended further in a path) or a subtree in folded form (which
@@ -217,6 +220,7 @@ package body Sem_SPARK is
 
   function Children_Permission (T : Perm_Tree_Access) return Perm_Kind;
   function Component (T : Perm_Tree_Access) return Perm_Tree_Maps.Instance;
+  function Explanation (T : Perm_Tree_Access) return Node_Id;
   function Get_All (T : Perm_Tree_Access) return Perm_Tree_Access;
   function Get_Elem (T : Perm_Tree_Access) return Perm_Tree_Access;
   function Is_Node_Deep (T : Perm_Tree_Access) return Boolean;
@@ -257,6 +261,7 @@ package body Sem_SPARK is
 (N  : Node_Id;
  Exp_Perm   : Perm_Kind;
  Act_Perm   : Perm_Kind;
+ Expl   : Node_Id;
  Forbidden_Perm : Boolean := False);
   --  Issues a continuation error message about a mismatch between a
   --  desired permission Exp_Perm and a permission obtained Act_Perm. N
@@ -428,6 +433,15 @@ package body Sem_SPARK is
  Free_Perm_Tree_Dealloc (PT);
   end Free_Tree;
 
+  -
+  -- Explanation --
+  -
+
+  function Explanation (T : Perm_Tree_Access) return Node_Id is
+  begin
+ return T.all.Tree.Explanation;
+  end Explanation;
+
   -
   -- Get_All --
   -
@@ -503,22 +517,34 @@ package body Sem_SPARK is
 (N  : Node_Id;
  Exp_Perm   : Perm_Kind;
  Act_Perm   : Perm_Kind;
+ Expl   : Node_Id;
  Forbidden_Perm : Boolean := False)
   is
   begin
+ Error_Msg_Sloc := Sloc (Expl);
+
  if Forbidden_Perm then
-if Exp_Perm = Act_Perm then
-   Error_Msg_N ("\got forbidden state `"
-& Perm_Kind'Image (Exp_Perm), N);
+if Exp_Perm = No_Access then
+   Error_Msg_N ("\object was moved #", N);
 else
-   Error_Msg_N ("\forbidden state `"
-& Perm_Kind'Image (Exp_Perm) & "`, got `"
-& Perm_Kind'Image (Act_Perm) & "`", N);
+   raise Program_Error;
 end if;
  else
-Error_Msg_N ("\expected state `"
- & Perm_Kind'Image (Exp_Perm) & "` at least, got `"
- & Perm_Kind'Image (Act_Perm) & "`", N);
+case Exp_Perm is
+   when Write_Perm =>
+  if Act_Perm = Read_Only then
+ Error_Msg_N
+   ("\object was declared as not writeable #", N);
+  else
+ Error_Msg_N ("\object was moved #", N);
+  end if;
+
+   when Read_Only =>
+  Error_Msg_N ("\object was moved #", N);
+
+   when No_Access =>
+  raise Program_Error;
+end case;
  end if;
   end Perm_Mismatch;
 
@@ -575,8 +601,11 @@ package body Sem_SPARK is
 
type Perm_Or_Tree (R : Result_Kind) is record
   case R is
- when Folded   => Found_Permission : Perm_Kind;
- when Unfolded => Tree_Access  : Perm_Tree_Access;
+ when Folded   =>
+Found_Permission : Perm_Kind;
+Explanation  : Node_Id;
+ when Unfolded =>
+Tree_Access  : Perm_Tree_Access;
   end case;
end record;
 
@@ -650,6 +679,10 @@ package body Sem_SPARK is
--  Check that type Typ is either not deep, or that it is an observing or
--  owning type according to SPARK RM 3.10
 
+   function Get_Expl (N : Node_Or_Entity_Id) return Node_Id;
+   --  The function that takes a name as input and returns an explanation node
+   --  for the permission associated with it.
+
fu

[Ada] Assertion failure on Default_Initial_Condition

2019-07-04 Thread Pierre-Marie de Rodat
This patch prevents the association of a Default_Initial_Condition with
an incomplete type whose full view is the private type or private
extension subject to the aspect/pragma.

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

2019-07-04  Hristian Kirtchev  

gcc/ada/

* sem_util.adb (Propagate_DIC_Attributes): Do not propagate the
Default_Initial_Condition attributes to an incomplete type.

gcc/testsuite/

* gnat.dg/default_initial_condition.adb,
gnat.dg/default_initial_condition_pack.adb,
gnat.dg/default_initial_condition_pack.ads: New testcase.--- gcc/ada/sem_util.adb
+++ gcc/ada/sem_util.adb
@@ -23327,6 +23327,13 @@ package body Sem_Util is
 
  if From_Typ = Typ then
 return;
+
+ --  Nothing to do when the destination denotes an incomplete type
+ --  because the DIC is associated with the current instance of a
+ --  private type, thus it can never apply to an incomplete type.
+
+ elsif Is_Incomplete_Type (Typ) then
+return;
  end if;
 
  DIC_Proc := DIC_Procedure (From_Typ);

--- /dev/null
new file mode 100644
+++ gcc/testsuite/gnat.dg/default_initial_condition.adb
@@ -0,0 +1,12 @@
+--  { dg-do run }
+--  { dg-options "-gnata" }
+
+with Default_Initial_Condition_Pack; use Default_Initial_Condition_Pack;
+
+procedure Default_Initial_Condition is
+   Obj : T;
+begin
+   if not DIC_Called then
+  raise Program_Error;
+   end if;
+end Default_Initial_Condition;

--- /dev/null
new file mode 100644
+++ gcc/testsuite/gnat.dg/default_initial_condition_pack.adb
@@ -0,0 +1,7 @@
+package body Default_Initial_Condition_Pack is
+   function Is_OK (Val : T) return Boolean is
+   begin
+  DIC_Called := True;
+  return True;
+   end Is_OK;
+end Default_Initial_Condition_Pack;

--- /dev/null
new file mode 100644
+++ gcc/testsuite/gnat.dg/default_initial_condition_pack.ads
@@ -0,0 +1,12 @@
+package Default_Initial_Condition_Pack is
+   type T;
+   type T is private
+ with Default_Initial_Condition => Is_OK (T);
+
+   function Is_OK (Val : T) return Boolean;
+
+   DIC_Called : Boolean := False;
+
+private
+   type T is null record;
+end Default_Initial_Condition_Pack;



[Ada] Spurious dimensionality error on aggregate with "others" assoc.

2019-07-04 Thread Pierre-Marie de Rodat
This patch fixes a spurious dimensionality error on an array aggregate
with a single "others' clause whose expression is a dimensioned entity,
The expansion of the aggregate may create copies of the expression, and
the dimensionality check must use the type of the expression to retrieve
the proper dimension information to check against the dimensions of the
array component type.

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

2019-07-04  Ed Schonberg  

gcc/ada/

* sem_dim.adb (Analyze_Dimension_Array_Aggregate): If the
component is an entity name, its dimensions are those of its
type.

gcc/testsuite/

* gnat.dg/dimensions2.adb, gnat.dg/dimensions2_phys.ads,
gnat.dg/dimensions2_real_numbers.ads: New testcase.--- gcc/ada/sem_dim.adb
+++ gcc/ada/sem_dim.adb
@@ -1233,8 +1233,9 @@ package body Sem_Dim is
   Dims_Of_Comp_Typ : constant Dimension_Type := Dimensions_Of (Comp_Typ);
   Exps : constant List_Id:= Expressions (N);
 
-  Comp : Node_Id;
-  Expr : Node_Id;
+  Comp : Node_Id;
+  Dims_Of_Expr : Dimension_Type;
+  Expr : Node_Id;
 
   Error_Detected : Boolean := False;
   --  This flag is used in order to indicate if an error has been detected
@@ -1281,11 +1282,19 @@ package body Sem_Dim is
  --  (may happen when an aggregate is converted into a positional
  --  aggregate). We also must verify that this is a scalar component,
  --  and not a subaggregate of a multidimensional aggregate.
+ --  The expression may be an identifier that has been copied several
+ --  times during expansion, its dimensions are those of its type.
+
+ if Is_Entity_Name (Expr) then
+Dims_Of_Expr := Dimensions_Of (Etype (Expr));
+ else
+Dims_Of_Expr := Dimensions_Of (Expr);
+ end if;
 
  if Comes_From_Source (Original_Node (Expr))
and then Present (Etype (Expr))
and then Is_Numeric_Type (Etype (Expr))
-   and then Dimensions_Of (Expr) /= Dims_Of_Comp_Typ
+   and then Dims_Of_Expr /= Dims_Of_Comp_Typ
and then Sloc (Comp) /= Sloc (Prev (Comp))
  then
 --  Check if an error has already been encountered so far

--- /dev/null
new file mode 100644
+++ gcc/testsuite/gnat.dg/dimensions2.adb
@@ -0,0 +1,20 @@
+--  { dg-do compile }
+
+with Dimensions2_phys; use Dimensions2_phys;
+
+procedure Dimensions2 is
+
+   zero_flow : constant Volumetric_Flow := 0.0 * m**3 / h;
+   type Node_Flow_Scenario_T is array (Positive range <>)
+  of Volumetric_Flow with
+default_component_value => zero_flow;
+   subtype Max_Node_Flow_Scenario_T
+   is Node_Flow_Scenario_T (Natural (1) .. 48);
+   flow_value_array : Max_Node_Flow_Scenario_T  := (1..48 => zero_flow);
+   flow_value_array1 : Max_Node_Flow_Scenario_T
+:= (Max_Node_Flow_Scenario_T'Range=> zero_flow);
+   flow_value_array2 : Max_Node_Flow_Scenario_T  := (others => zero_flow);
+
+begin
+null;
+end Dimensions2;

--- /dev/null
new file mode 100644
+++ gcc/testsuite/gnat.dg/dimensions2_phys.ads
@@ -0,0 +1,80 @@
+with ada.numerics.generic_elementary_functions;
+with Dimensions2_real_numbers;
+
+package Dimensions2_Phys is
+
+   type si_type is new Dimensions2_real_numbers.Real with
+  dimension_system =>
+  ((unit_name => meter, unit_symbol => 'm', dim_symbol => 'L'),
+   (unit_name => kilogram, unit_symbol => "kg", dim_symbol => 'M'),
+   (unit_name => second, unit_symbol => 's', dim_symbol => 'T'),
+   (unit_name => ampere, unit_symbol => 'A', dim_symbol => 'I'),
+   (unit_name => kelvin, unit_symbol => 'K', dim_symbol => "Theta"),
+   (unit_name => mole, unit_symbol => "mol", dim_symbol => 'N'),
+   (unit_name => euro, unit_symbol => "EUR", dim_symbol => 'E'));
+
+   subtype distance is Si_Type with
+dimension => (symbol => 'm', meter => 1, others => 0);
+
+   subtype mass is Si_Type with
+dimension => (symbol => "kg", kilogram => 1, others => 0);
+
+   subtype time is Si_Type with
+dimension => (symbol => 's', second => 1, others => 0);
+
+   subtype electric_current is Si_Type with
+dimension => (symbol => 'A', ampere => 1, others => 0);
+
+   subtype temperature is Si_Type with
+dimension => (symbol => 'K', kelvin => 1, others => 0);
+
+   subtype amount_of_substance is Si_Type with
+dimension => (symbol => "mol", mole => 1, others => 0);
+
+   pragma warnings (off, "*assumed to be*");
+   subtype pressure_barg is Dimensions2_real_numbers.Real;
+   m : constant Distance := 1.0;
+   kg : constant Mass := 1.0;
+   s : constant Time := 1.0;
+   a : constant Electric_Current := 1.0;
+   k : constant Temperature := 1.0;
+   mol : constant Amount_Of_Substance := 1.0;
+   min : constant Time := 1.0;
+   h : constant Time := 60.0 * min;
+
+   subtype frequency is Si_Type with
+dimension => (symbol => "Hz", s

[Ada] Fix crash in SPARK ownership checking

2019-07-04 Thread Pierre-Marie de Rodat
Analysis could crash on extended return of a non-deep type, now fixed.
This has no impact on compilation.

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

2019-07-04  Yannick Moy  

gcc/ada/

* sem_spark.adb (Check_Statement): Only check permission of
object in extended return when it is of a deep type.--- gcc/ada/sem_spark.adb
+++ gcc/ada/sem_spark.adb
@@ -2902,10 +2902,13 @@ package body Sem_SPARK is
Check_List (Return_Object_Declarations (Stmt));
Check_Node (Handled_Statement_Sequence (Stmt));
 
-   Perm := Get_Perm (Obj);
+   if Is_Deep (Etype (Obj)) then
+  Perm := Get_Perm (Obj);
 
-   if Perm /= Read_Write then
-  Perm_Error (Decl, Read_Write, Perm, Expl => Get_Expl (Obj));
+  if Perm /= Read_Write then
+ Perm_Error (Decl, Read_Write, Perm,
+ Expl => Get_Expl (Obj));
+  end if;
end if;
 
if Ekind_In (Subp, E_Procedure, E_Entry)



[Ada] Keep assertions in internal units enabled for GNATprove

2019-07-04 Thread Pierre-Marie de Rodat
In GNATprove mode the assertion policy is now always enabled, even when
analysing internal units. Otherwise, assertion expressions (e.g.
Default_Initial_Condition) in internal units (e.g. Ada.Text_IO)
disappear in the semantic analysis phase of the frontend and the
GNATprove backend can't see them.

No frontend test provided, because only the GNATprove backend is
affected (and there appear to be no difference in the output with -gnatG
switch, because the expansion of Default_Initial_Condition is not
attached to the AST).

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

2019-07-04  Piotr Trojanek  

gcc/ada/

* opt.adb (Set_Config_Switches): Keep assertions policy as
enabled when analysing internal units in GNATprove mode.--- gcc/ada/opt.adb
+++ gcc/ada/opt.adb
@@ -248,7 +248,13 @@ package body Opt is
 SPARK_Mode_Pragma:= SPARK_Mode_Pragma_Config;
 
  else
-if GNAT_Mode_Config then
+--  In GNATprove mode assertions should be always enabled, even
+--  when analysing internal units.
+
+if GNATprove_Mode then
+   pragma Assert (Assertions_Enabled);
+   null;
+elsif GNAT_Mode_Config then
Assertions_Enabled:= Assertions_Enabled_Config;
 else
Assertions_Enabled:= False;



[Ada] Skip code not in SPARK for ownership analysis

2019-07-04 Thread Pierre-Marie de Rodat
Ownership rules for pointer support should only apply to code marked in
SPARK. There is no impact on compilation.

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

2019-07-04  Yannick Moy  

gcc/ada/

* sem_spark.adb (Check_Package_Spec, Check_Package_Body): Only
analyze parts of the code marked in SPARK.--- gcc/ada/sem_spark.adb
+++ gcc/ada/sem_spark.adb
@@ -2364,39 +2364,43 @@ package body Sem_SPARK is
   Save_In_Elab : constant Boolean := Inside_Elaboration;
   Spec : constant Node_Id :=
 Package_Specification (Corresponding_Spec (Pack));
-  Prag : constant Node_Id := SPARK_Pragma (Defining_Entity (Pack));
+  Id   : constant Entity_Id := Defining_Entity (Pack);
+  Prag : constant Node_Id := SPARK_Pragma (Id);
+  Aux_Prag : constant Node_Id := SPARK_Aux_Pragma (Id);
   Saved_Env: Perm_Env;
 
begin
-  --  Only SPARK bodies are analyzed
-
-  if No (Prag)
-or else Get_SPARK_Mode_From_Annotation (Prag) /= Opt.On
+  if Present (Prag)
+and then Get_SPARK_Mode_From_Annotation (Prag) = Opt.On
   then
- return;
-  end if;
+ Inside_Elaboration := True;
 
-  Inside_Elaboration := True;
+ --  Save environment and put a new one in place
 
-  --  Save environment and put a new one in place
+ Move_Env (Current_Perm_Env, Saved_Env);
 
-  Move_Env (Current_Perm_Env, Saved_Env);
+ --  Reanalyze package spec to have its variables in the environment
 
-  --  Reanalyze package spec to have its variables in the environment
+ Check_List (Visible_Declarations (Spec));
+ Check_List (Private_Declarations (Spec));
 
-  Check_List (Visible_Declarations (Spec));
-  Check_List (Private_Declarations (Spec));
+ --  Check declarations and statements in the special mode for
+ --  elaboration.
 
-  --  Check declarations and statements in the special mode for elaboration
+ Check_List (Declarations (Pack));
 
-  Check_List (Declarations (Pack));
-  Check_Node (Handled_Statement_Sequence (Pack));
+ if Present (Aux_Prag)
+   and then Get_SPARK_Mode_From_Annotation (Aux_Prag) = Opt.On
+ then
+Check_Node (Handled_Statement_Sequence (Pack));
+ end if;
 
-  --  Restore the saved environment and free the current one
+ --  Restore the saved environment and free the current one
 
-  Move_Env (Saved_Env, Current_Perm_Env);
+ Move_Env (Saved_Env, Current_Perm_Env);
 
-  Inside_Elaboration := Save_In_Elab;
+ Inside_Elaboration := Save_In_Elab;
+  end if;
end Check_Package_Body;
 

@@ -2406,25 +2410,37 @@ package body Sem_SPARK is
procedure Check_Package_Spec (Pack : Node_Id) is
   Save_In_Elab : constant Boolean := Inside_Elaboration;
   Spec : constant Node_Id := Specification (Pack);
+  Id   : constant Entity_Id := Defining_Entity (Pack);
+  Prag : constant Node_Id := SPARK_Pragma (Id);
+  Aux_Prag : constant Node_Id := SPARK_Aux_Pragma (Id);
   Saved_Env: Perm_Env;
 
begin
-  Inside_Elaboration := True;
+  if Present (Prag)
+and then Get_SPARK_Mode_From_Annotation (Prag) = Opt.On
+  then
+ Inside_Elaboration := True;
 
-  --  Save environment and put a new one in place
+ --  Save environment and put a new one in place
 
-  Move_Env (Current_Perm_Env, Saved_Env);
+ Move_Env (Current_Perm_Env, Saved_Env);
 
-  --  Check declarations in the special mode for elaboration
+ --  Check declarations in the special mode for elaboration
 
-  Check_List (Visible_Declarations (Spec));
-  Check_List (Private_Declarations (Spec));
+ Check_List (Visible_Declarations (Spec));
 
-  --  Restore the saved environment and free the current one
+ if Present (Aux_Prag)
+   and then Get_SPARK_Mode_From_Annotation (Aux_Prag) = Opt.On
+ then
+Check_List (Private_Declarations (Spec));
+ end if;
 
-  Move_Env (Saved_Env, Current_Perm_Env);
+ --  Restore the saved environment and free the current one
 
-  Inside_Elaboration := Save_In_Elab;
+ Move_Env (Saved_Env, Current_Perm_Env);
+
+ Inside_Elaboration := Save_In_Elab;
+  end if;
end Check_Package_Spec;
 
---



Re: allow EH to escape from GIMPLE_EH_ELSE ELSE block

2019-07-04 Thread Alexandre Oliva
On Jul  2, 2019, Richard Biener  wrote:

> Yeah, it's on trunk.  The parser is ontop of the C frontend and resides
> in gcc/c/gimple-parser.c while testcases are in gcc.dg/gimplefe-*.c

> The parsing is incomplete, there's no support for parsing try/catch/finally

I'm afraid I haven't got very far, but I tried.  It didn't recognize try
and finally as keywords, and since the parser is integrated with the C
parser IIUC, I wasn't sure how to enable the keywords only within gimple
functions.

As mentioned in another message, I chose try/finally/else as the
notation for TRY_FINALLY_EXPR <..., EH_ELSE_EXPR <..., ...> >, to avoid
introducing yet another keyword such as eh_finally.

I also considered try/noexcept/finally, or try/noexcept finally/finally,
but...  else seems to be a lot more closely related with EH_ELSE_EXPR,
and at least in gimple it's non-ambiguous.


introduce try/finally/else in gimplefe (WIP FTR)

From: Alexandre Oliva 


---
 gcc/c/gimple-parser.c  |   49 
 gcc/testsuite/gcc.dg/gimplefe-43.c |   13 ++
 2 files changed, 62 insertions(+)
 create mode 100644 gcc/testsuite/gcc.dg/gimplefe-43.c

diff --git a/gcc/c/gimple-parser.c b/gcc/c/gimple-parser.c
index b2b364cc41a3..91f2499bb1cc 100644
--- a/gcc/c/gimple-parser.c
+++ b/gcc/c/gimple-parser.c
@@ -115,6 +115,7 @@ static struct c_expr 
c_parser_gimple_postfix_expression_after_primary
 static void c_parser_gimple_declaration (gimple_parser &);
 static void c_parser_gimple_goto_stmt (gimple_parser &, location_t,
   tree, gimple_seq *);
+static void c_parser_gimple_try_stmt (gimple_parser &, gimple_seq *);
 static void c_parser_gimple_if_stmt (gimple_parser &, gimple_seq *);
 static void c_parser_gimple_switch_stmt (gimple_parser &, gimple_seq *);
 static void c_parser_gimple_return_stmt (gimple_parser &, gimple_seq *);
@@ -405,6 +406,9 @@ c_parser_gimple_compound_statement (gimple_parser &parser, 
gimple_seq *seq)
case CPP_KEYWORD:
  switch (c_parser_peek_token (parser)->keyword)
{
+   case RID_AT_TRY:
+ c_parser_gimple_try_stmt (parser, seq);
+ break;
case RID_IF:
  c_parser_gimple_if_stmt (parser, seq);
  break;
@@ -2088,6 +2092,51 @@ c_parser_gimple_paren_condition (gimple_parser &parser)
   return cond;
 }
 
+/* Parse gimple try statement.
+
+   try-statement:
+ try { ... } finally { ... }
+ try { ... } finally { ... } else { ... }
+
+   This could support try/catch as well, but it's not implemented yet.
+ */
+
+static void
+c_parser_gimple_try_stmt (gimple_parser &parser, gimple_seq *seq)
+{
+  gimple_seq tryseq = NULL;
+  c_parser_consume_token (parser);
+  c_parser_gimple_compound_statement (parser, &tryseq);
+
+  if (c_parser_next_token_is (parser, CPP_KEYWORD)
+  && c_parser_peek_token (parser)->keyword == RID_AT_FINALLY)
+{
+  gimple_seq finseq = NULL;
+  c_parser_consume_token (parser);
+  c_parser_gimple_compound_statement (parser, &finseq);
+
+  if (c_parser_next_token_is (parser, CPP_KEYWORD)
+ && c_parser_peek_token (parser)->keyword == RID_ELSE)
+   {
+ gimple_seq elsseq = NULL;
+ c_parser_consume_token (parser);
+ c_parser_gimple_compound_statement (parser, &finseq);
+
+ geh_else *stmt = gimple_build_eh_else (finseq, elsseq);
+ finseq = NULL;
+ gimple_seq_add_stmt_without_update (&finseq, stmt);
+   }
+
+  gtry *stmt = gimple_build_try (tryseq, finseq, GIMPLE_TRY_FINALLY);
+  gimple_seq_add_stmt_without_update (seq, stmt);
+}
+  else if (c_parser_next_token_is (parser, CPP_KEYWORD)
+  && c_parser_peek_token (parser)->keyword == RID_AT_CATCH)
+c_parser_error (parser, "% is not supported");
+  else
+c_parser_error (parser, "expected % or %");
+}
+
 /* Parse gimple if-else statement.
 
if-statement:
diff --git a/gcc/testsuite/gcc.dg/gimplefe-43.c 
b/gcc/testsuite/gcc.dg/gimplefe-43.c
new file mode 100644
index ..c740e06a78e1
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/gimplefe-43.c
@@ -0,0 +1,13 @@
+/* { dg-do compile } */
+/* { dg-options "-fgimple" } */
+
+void __GIMPLE foo()
+{
+  try {
+;
+  } finally {
+;
+  } else {
+;
+  }
+}


-- 
Alexandre Oliva, freedom fighter  he/him   https://FSFLA.org/blogs/lxo
Be the change, be Free! FSF Latin America board member
GNU Toolchain EngineerFree Software Evangelist
Hay que enGNUrecerse, pero sin perder la terGNUra jamás - Che GNUevara


Re: [PR other/79543] Fix GNU ld --version scanning to conform to the GNU Coding Standards

2019-07-04 Thread Chung-Lin Tang

On 2017/10/31 8:17 AM, Joseph Myers wrote:

Specifically,*non-release*  versions of binutils predating my patch

commit 066c2a57f5858310c9f12518317aecd4b54e753d
Author: Joseph Myers
Date:   Thu Mar 1 15:48:36 2007 +

would have had a space between the binutils version number and the BFD
datestamp and the end of the first line of --version output.  That would
not have been an issue for release versions, and the stray word "version"
before the version number before that patch would not cause problems for
the simplified sed expressions.


Applying the following patch (that is, simplying the sed command), makes
the problem go away:

 -sed -e 's/GNU gold /GNU ld /;s/GNU ld version /GNU ld /;s/GNU ld ([^)]*) 
/GNU ld /;s/GNU ld \([0-9.][0-9.]*\).*/\1/; q'`
 +sed -e 's/GNU gold /GNU ld /;s/GNU ld .* \(.*\)/\1/; q'`

While I think working properly for binutils versions in the past ten years
matters more than any issues with old non-release versions that probably
wouldn't work with current GCC anyway, it seems to me that this patch
would require*something*  surrounded by spaces between "GNU ld" and the
version number.  If you configure with --without-pkgversion, you get e.g.

GNU ld 2.28

as the complete first line of the output, and that doesn't look like it
would match the above pattern, as there's only one space not two between
"GNU ld" and the version number.  So I think you need a pattern that does
allow the --without-pkgversion form of output.


Bringing back this issue, as this is still bothering our OpenACC toolchains.

If the main variance in format was the 2007 ' ' to '.' change for non-release
binutils builds, then is the attached patch okay?

What the patch does is to first look for an 8-digit part at the end
(preceded by either a space or '.'), chop it off if it exists, and then take 
the last
space-preceded string.

This matching logic does appear to be more reliant on the aforementioned
GNU standard of 'everything after the last space on the first line of the 
output'.
OTOH, not sure if all the testing for GNU gold, GNU ld, etc. in the current
sed pattern means much since this is already under $with_gnu_ld=yes.

(seeking approval for trunk and all active release branches)

Thanks,
Chung-Lin

2019-07-04  Chung-Lin Tang 

libatomic/
PR other/79543
* acinclude.m4 (LIBAT_CHECK_LINKER_FEATURES): Fix GNU ld --version
scanning to conform to the GNU Coding Standards.
* configure: Regenerate.

libffi/
PR other/79543
* acinclude.m4 (LIBAT_CHECK_LINKER_FEATURES): Fix GNU ld --version
scanning to conform to the GNU Coding Standards.
* configure: Regenerate.

libgomp/
PR other/79543
* acinclude.m4 (LIBGOMP_CHECK_LINKER_FEATURES): Fix GNU ld --version
scanning to conform to the GNU Coding Standards.
* configure: Regenerate.

libitm/
PR other/79543
* acinclude.m4 (LIBITM_CHECK_LINKER_FEATURES): Fix GNU ld --version
scanning to conform to the GNU Coding Standards.
* configure: Regenerate.

libstdc++-v3/
PR other/79543
* acinclude.m4 (GLIBCXX_CHECK_LINKER_FEATURES): Fix GNU ld --version
scanning to conform to the GNU Coding Standards.
* configure: Regenerate.
Index: libatomic/acinclude.m4
===
--- libatomic/acinclude.m4  (revision 273041)
+++ libatomic/acinclude.m4  (working copy)
@@ -336,7 +336,7 @@ AC_DEFUN([LIBAT_CHECK_LINKER_FEATURES], [
   fi
   changequote(,)
   ldver=`$LD --version 2>/dev/null |
- sed -e 's/GNU gold /GNU ld /;s/GNU ld version /GNU ld /;s/GNU ld 
([^)]*) /GNU ld /;s/GNU ld \([0-9.][0-9.]*\).*/\1/; q'`
+ sed -e 's/[. ][0-9]\{8\}$//;s/.* \([^ ]\+\)$/\1/; q'`
   changequote([,])
   libat_gnu_ld_version=`echo $ldver | \
  $AWK -F. '{ if (NF<3) [$]3=0; print ([$]1*100+[$]2)*100+[$]3 }'`
@@ -438,7 +438,7 @@ AC_DEFUN([LIBAT_CHECK_LINKER_FEATURES], [
   fi
   changequote(,)
   ldver=`$LD --version 2>/dev/null |
- sed -e 's/GNU gold /GNU ld /;s/GNU ld version /GNU ld /;s/GNU ld 
([^)]*) /GNU ld /;s/GNU ld \([0-9.][0-9.]*\).*/\1/; q'`
+ sed -e 's/[. ][0-9]\{8\}$//;s/.* \([^ ]\+\)$/\1/; q'`
   changequote([,])
   libat_gnu_ld_version=`echo $ldver | \
  $AWK -F. '{ if (NF<3) [$]3=0; print ([$]1*100+[$]2)*100+[$]3 }'`
Index: libatomic/configure
===
--- libatomic/configure (revision 273041)
+++ libatomic/configure (working copy)
@@ -15177,7 +15177,7 @@ with_gnu_ld=$lt_cv_prog_gnu_ld
   fi
 
   ldver=`$LD --version 2>/dev/null |
- sed -e 's/GNU gold /GNU ld /;s/GNU ld version /GNU ld /;s/GNU ld 
([^)]*) /GNU ld /;s/GNU ld \([0-9.][0-9.]*\).*/\1/; q'`
+ sed -e 's/[. ][0-9]\{8\}$//;s/.* \([^ ]\+\)$/\1/; q'`
 
   libat_gnu_ld_version=`echo $ldver | \
  $AWK -F. '{ if (NF<3) $3=0; print ($1*100+$2)*10

Re: [PATH] Patch to fix -finstrument-functions-exclude-function-list handling of namespaces and escaped commas

2019-07-04 Thread Oliver Browne
See below for modified patch, indentation and newline for curly braces
style applied, and commented out chunk removed. Apologies, indentation
and newline for scope are not they way I normally write things, habits
got the better of me, and I forgot to remove the commented out chunk
before submission.

Adding the scope braces and writing the for loop in ordinary C instead
of relying on a macro are changes made for the sake of
maintainability. This feature is rarely touched (as evidenced by it
having the bugs I'm fixing for so long) and so it is more likely any
patches submitted to it will be submitted by people who a) are not
maintainers of GCC, and so are not familiar with the various macros
etc "normally" used and b) don't have the time / patience to
familiarize themselves with the code base before fixing just the bit
they need to work for whatever they're doing. For people like that
(people like me), having the code be written in as obvious a way as
possible and clearly marking scope of branches makes making fixes
easier (adding a quick printf for debugging is painless, etc), which
is important for low usage features.

Index: gimplify.c
===
--- gimplify.c  2019-06-12 19:07:26.872077000 +0100
+++ gimplify.c  2019-07-04 08:53:08.76842 +0100
@@ -13987,11 +13987,16 @@ flag_instrument_functions_exclude_p (tre
 {
   const char *name;
-  int i;
+  unsigned int i;
   char *s;

-  name = lang_hooks.decl_printable_name (fndecl, 0);
-  FOR_EACH_VEC_ELT (*v, i, s)
-   if (strstr (name, s) != NULL)
- return true;
+  name = lang_hooks.decl_printable_name (fndecl, 1);
+ for(i = 0; i < v->length(); i++)
+ {
+   s = (*v)[i];
+   if(strstr(name, s) != NULL)
+   {
+ return(true);
+   }
+ }
 }
Index: opts.c
===
--- opts.c  2019-06-12 19:10:04.354612000 +0100
+++ opts.c  2019-07-04 08:55:25.287523000 +0100
@@ -263,7 +263,9 @@ add_comma_separated_to_vector (void **pv
*w++ = *r++;
 }
+  *w = '\0';
   if (*token_start != '\0')
+  {
 v->safe_push (token_start);
-
+  }
   *pvec = v;
 }

On Thu, Jul 4, 2019 at 12:31 AM Jeff Law  wrote:
>
> On 6/12/19 12:25 PM, Oliver Browne wrote:
> > Patch fixes following PRs:
> > c++/90816 - -finstrument-functions-exclude-function-list improperly
> > handles namespace/class definitions
> > c++/90809 - -finstrument-functions-exclude-function-list mishandles
> > comma escaping
> >
> > Fixes as follows:
> > At flag_instrument_functions_exclude_p [gimplify.c]
> > Using lang_hooks.decl_printable_name (fndecl, 1) to get namespace /
> > class information as part of printable name to allow for
> > inclusion of namespace / class specification when passing symbols to
> > -finstrument-functions-exclude-function-list. Was
> > previously lang_hooks.decl_printable_name (fndecl, 0).
> >
> > At add_comma_separated_to_vector [opts.c]
> > Added writing of a null character to w after primary loop finishes, to
> > account for offset between r and w when r reaches end of
> > passed string.
> >
> > from Oliver Browne 
> > PR c++/90816
> > PR c++/90809
> >  * gimplify.c (flag_instrument_functions_exclude_p): include namespace
> >information as part of decl name
> >  * opts.c (add_comma_separated_to_vector): add null character to correct
> >position in last token added to token vector
> > Index: gimplify.c
> > ===
> > --- gimplify.c 2019-06-12 19:07:26.872077000 +0100
> > +++ gimplify.c 2019-06-12 18:55:10.609255000 +0100
> > @@ -13987,11 +13987,17 @@ flag_instrument_functions_exclude_p (tre
> >  {
> >const char *name;
> > -  int i;
> > +  unsigned int i;
> >char *s;
> >
> > -  name = lang_hooks.decl_printable_name (fndecl, 0);
> > -  FOR_EACH_VEC_ELT (*v, i, s)
> > +  name = lang_hooks.decl_printable_name (fndecl, 1);
> > +   for(i = 0; i < v->length(); i++){
> > + s = (*v)[i];
> > + if(strstr(name, s) != NULL){
> > +   return(true);
> > + }
> > +   }
> > +/*  FOR_EACH_VEC_ELT (*v, i, s)
> >   if (strstr (name, s) != NULL)
> > -   return true;
> > + return true;*/
> >  }
> So why did you drop the FOR_EACH_VEC_ELT and open-code the loop?  I
> don't see that as being a necessary change.  Leaving the
> FOR_EACH_VEC_ELT in place would also avoid the mis-formatting you've
> introduced as well as removing clutter of a commented-out hunk of code.
>
> >
> > @@ -14278,3 +14284,3 @@ gimplify_hasher::equal (const elt_t *p1,
> >
> >return true;
> > -}
> > \ No newline at end of file
> > +}
> > Index: opts.c
> > ===
> > --- opts.c 2019-06-12 19:10:04.354612000 +0100
> > +++ opts.c 2019-06-12 18:53:43.675852000 +0100
> > @@ -263,7 +263,8 @@ add_comma_separated_t

Re: introduce EH_ELSE tree and gimplifier

2019-07-04 Thread Alexandre Oliva
On Jul  1, 2019, Richard Biener  wrote:

> On Fri, Jun 28, 2019 at 5:21 AM Alexandre Oliva  wrote:
>> 
>> On Jun 27, 2019, Richard Biener  wrote:
>> 
>> > On Thu, Jun 27, 2019 at 10:18 AM Alexandre Oliva  wrote:
>> 
>> >> @@ -909,6 +909,13 @@ DEFTREECODE (TRY_CATCH_EXPR, "try_catch_expr", 
>> >> tcc_statement, 2)
>> >> The second operand is a cleanup expression which is evaluated
>> >> on any exit (normal, exception, or jump out) from this expression.  */
>> >> DEFTREECODE (TRY_FINALLY_EXPR, "try_finally", tcc_statement, 2)
>> >> +
>> >> +/* Evaluate either the normal or the exceptional cleanup.  This must
>> >> +   only be present as the cleanup expression in a TRY_FINALLY_EXPR.
>> >> +   If the TRY_FINALLY_EXPR completes normally, the first operand of
>> >> +   EH_ELSE is used as a cleanup, otherwise the second operand is
>> >> +   used.  */
>> >> +DEFTREECODE (EH_ELSE, "eh_else", tcc_statement, 2)
>> 
>> > It's a bit weird that this is a tcc_statement as opposed to tcc_expression,

>> Erhm...  What's weird about it?  It is not something that belongs in an
>> arbitrary expr, it's a lot more like a top-level statement, like
>> try_finally, having side effects but no useful value.

> It's weird because it appears in a TRY_FINALLY statement operand.

The other operand could be a nested TRY_FINALLY, but that doesn't make
TRY_FINALLY a tcc_expression.

> But I guess the line between statements and expressions in GENERIC
> is muddy...

My understanding of the general rule is that tcc_expressions have
values, whereas tcc_statements don't.

>> > also I'd have called it EH_ELSE_EXPR for clarity.

>> Now *that* would be weird IMHO.  No offense intended, but I'd have
>> dropped the _EXPR from TRY_FINALLY_EXPR to make it match the
>> "try_finally" string.

> OK, let me say for consistency then ...

Ok, I like that one ;-) I've adjusted the "try_finally" string, and
changed EH_ELSE to EH_ELSE_EXPR all over (but not in GIMPLE_EH_ELSE).

I've also changed the way TRY_FINALLY_EXPR/EH_ELSE_EXPR are output in
generic and gimple dumps, using the notation try/finally/else (this is
the notation I started using in my unfinished gimplefe attempt, to avoid
adding more keywords; more in another message).  I've retained the
ability to dump GIMPLE_EH_EXPR separately, because I'm not entirely sure
it could never be separated from the enclosing TRY_FINALLY_EXPR.


introduce EH_ELSE_EXPR tree and gimplifier

I found GIMPLE_EH_ELSE offered exactly the semantics I needed for some
Ada changes yet to be contributed, but GIMPLE_EH_ELSE was only built
by GIMPLE passes, and I needed to build earlier something that
eventually became GIMPLE_EH_ELSE.

This patch does that, introducing an EH_ELSE_EXPR tree, and logic to
dump it and to gimplify it.

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



for  gcc/ChangeLog

* doc/generic.texi (Cleanups): Document EH_ELSE_EXPR.
* except.c: Likewise.
* expr.c (expand_expr_real_1): Reject it.
* gimplify.c (gimplify_expr): Gimplify it, within
TRY_FINALLY_EXPR.
* tree-dump.c (dequeue_and_dump): Dump it.
* tree-pretty-print.c (dump_generic_node): Likewise.
* tree.c (block_may_fallthru): Handle it.
* tree.def (EH_ELSE_EXPR): Introduce it.
* gimple-pretty-print.c (dump_gimple_try): Dump TRY_FINALLY
with GIMPLE_EH_ELSE as try/finally/else.
---
 gcc/doc/generic.texi  |5 +
 gcc/except.c  |   12 ++--
 gcc/expr.c|1 +
 gcc/gimple-pretty-print.c |   20 +++-
 gcc/gimplify.c|   18 +-
 gcc/tree-dump.c   |1 +
 gcc/tree-pretty-print.c   |   28 +---
 gcc/tree.c|3 +++
 gcc/tree.def  |9 -
 9 files changed, 85 insertions(+), 12 deletions(-)

diff --git a/gcc/doc/generic.texi b/gcc/doc/generic.texi
index 67f7ad53af6b..8901d5f357e2 100644
--- a/gcc/doc/generic.texi
+++ b/gcc/doc/generic.texi
@@ -2180,6 +2180,11 @@ After the second sequence is executed, if it completes 
normally by
 falling off the end, execution continues wherever the first sequence
 would have continued, by falling off the end, or doing a goto, etc.
 
+If the second sequence is an @code{EH_ELSE_EXPR} selector, then the
+sequence in its first operand is used when the first sequence completes
+normally, and that in its second operand is used for exceptional
+cleanups, i.e., when an exception propagates out of the first sequence.
+
 @code{TRY_FINALLY_EXPR} complicates the flow graph, since the cleanup
 needs to appear on every edge out of the controlled block; this
 reduces the freedom to move code across these edges.  Therefore, the
diff --git a/gcc/except.c b/gcc/except.c
index edaeeb4cfd1b..29f333912d15 100644
--- a/gcc/except.c
+++ b/gcc/except.c
@@ -27,14 +27,14 @@ along with GCC; see the file COPYING3.  If not see
the compilation process:
 
In the beginning, in the front end, we have the

[PATCH] Refactor VN state during reference walking

2019-07-04 Thread Richard Biener


I'm working on a patch that needs to keep track of more state
during the walk_non_aliased_vuses walks in VN.  This refactors
the existing code to avoid using global variables, introducing
a state structure that I will extend later.

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

Richard.

2019-07-04  Richard Biener  

* tree-ssa-sccvn.h (vn_reference_lookup): Add last_vuse_ptr
argument.
* tree-ssa-sccvn.c (last_vuse_ptr, vn_walk_kind): Move
globals into...
(struct vn_walk_cb_data): New callback data struct.
(vn_reference_lookup_2): Adjust.
(vn_reference_lookup_3): Likewise.
(vn_reference_lookup_pieces): Likewise.
(vn_reference_lookup): Likewise, get last_vuse_ptr argument.
(visit_reference_op_load): Adjust.

Index: gcc/tree-ssa-sccvn.c
===
--- gcc/tree-ssa-sccvn.c(revision 273000)
+++ gcc/tree-ssa-sccvn.c(working copy)
@@ -131,8 +131,6 @@ along with GCC; see the file COPYING3.
 /* There's no BB_EXECUTABLE but we can use BB_VISITED.  */
 #define BB_EXECUTABLE BB_VISITED
 
-static tree *last_vuse_ptr;
-static vn_lookup_kind vn_walk_kind;
 static vn_lookup_kind default_vn_walk_kind;
 
 /* vn_nary_op hashtable helpers.  */
@@ -1648,18 +1646,26 @@ vn_reference_lookup_1 (vn_reference_t vr
   return NULL_TREE;
 }
 
+struct vn_walk_cb_data
+{
+  vn_reference_t vr;
+  tree *last_vuse_ptr;
+  vn_lookup_kind vn_walk_kind;
+};
+
 /* Callback for walk_non_aliased_vuses.  Adjusts the vn_reference_t VR_
with the current VUSE and performs the expression lookup.  */
 
 static void *
-vn_reference_lookup_2 (ao_ref *op ATTRIBUTE_UNUSED, tree vuse, void *vr_)
+vn_reference_lookup_2 (ao_ref *op ATTRIBUTE_UNUSED, tree vuse, void *data_)
 {
-  vn_reference_t vr = (vn_reference_t)vr_;
+  vn_walk_cb_data *data = (vn_walk_cb_data *)data_;
+  vn_reference_t vr = data->vr;
   vn_reference_s **slot;
   hashval_t hash;
 
-  if (last_vuse_ptr)
-*last_vuse_ptr = vuse;
+  if (data->last_vuse_ptr)
+*data->last_vuse_ptr = vuse;
 
   /* Fixup vuse and hash.  */
   if (vr->vuse)
@@ -1929,10 +1935,11 @@ basic_block vn_context_bb;
*DISAMBIGUATE_ONLY is set to true.  */
 
 static void *
-vn_reference_lookup_3 (ao_ref *ref, tree vuse, void *vr_,
+vn_reference_lookup_3 (ao_ref *ref, tree vuse, void *data_,
   bool *disambiguate_only)
 {
-  vn_reference_t vr = (vn_reference_t)vr_;
+  vn_walk_cb_data *data = (vn_walk_cb_data *)data_;
+  vn_reference_t vr = data->vr;
   gimple *def_stmt = SSA_NAME_DEF_STMT (vuse);
   tree base = ao_ref_base (ref);
   HOST_WIDE_INT offseti, maxsizei;
@@ -1979,7 +1986,7 @@ vn_reference_lookup_3 (ao_ref *ref, tree
 accesses as we then can use TBAA to disambiguate against the
 clobbering statement when looking up a load (thus the
 VN_WALKREWRITE guard).  */
-  if (vn_walk_kind == VN_WALKREWRITE
+  if (data->vn_walk_kind == VN_WALKREWRITE
  && is_gimple_reg_type (TREE_TYPE (lhs))
  && types_compatible_p (TREE_TYPE (lhs), vr->type)
  /* The overlap restriction breaks down when either access
@@ -1992,16 +1999,16 @@ vn_reference_lookup_3 (ao_ref *ref, tree
  || (get_alias_set (lhs) != 0
  && ao_ref_alias_set (ref) != 0)))
{
- tree *saved_last_vuse_ptr = last_vuse_ptr;
+ tree *saved_last_vuse_ptr = data->last_vuse_ptr;
  /* Do not update last_vuse_ptr in vn_reference_lookup_2.  */
- last_vuse_ptr = NULL;
+ data->last_vuse_ptr = NULL;
  tree saved_vuse = vr->vuse;
  hashval_t saved_hashcode = vr->hashcode;
- void *res = vn_reference_lookup_2 (ref, gimple_vuse (def_stmt), vr);
+ void *res = vn_reference_lookup_2 (ref, gimple_vuse (def_stmt), data);
  /* Need to restore vr->vuse and vr->hashcode.  */
  vr->vuse = saved_vuse;
  vr->hashcode = saved_hashcode;
- last_vuse_ptr = saved_last_vuse_ptr;
+ data->last_vuse_ptr = saved_last_vuse_ptr;
  if (res && res != (void *)-1)
{
  vn_reference_t vnresult = (vn_reference_t) res;
@@ -2306,7 +2313,7 @@ vn_reference_lookup_3 (ao_ref *ref, tree
 
   /* 5) For aggregate copies translate the reference through them if
  the copy kills ref.  */
-  else if (vn_walk_kind == VN_WALKREWRITE
+  else if (data->vn_walk_kind == VN_WALKREWRITE
   && gimple_assign_single_p (def_stmt)
   && (DECL_P (gimple_assign_rhs1 (def_stmt))
   || TREE_CODE (gimple_assign_rhs1 (def_stmt)) == MEM_REF
@@ -2426,7 +2433,7 @@ vn_reference_lookup_3 (ao_ref *ref, tree
   *ref = r;
 
   /* Do not update last seen VUSE after translating.  */
-  last_vuse_ptr = NULL;
+  data->last_vuse_ptr = NULL;
 
   /* Keep looking for the adjusted *REF / VR pair.  */
   return NULL;
@@ -2434,7 +2441,7 @@ vn_reference_lookup_3 (ao_ref *ref, tree

Re: [PATCH] Fix PR91069

2019-07-04 Thread Richard Biener
On Thu, 4 Jul 2019, Jakub Jelinek wrote:

> On Wed, Jul 03, 2019 at 12:49:34PM +0200, Richard Biener wrote:
> > 2019-07-03  Richard Biener  
> > 
> > PR middle-end/91069
> > * match.pd (vec_perm -> bit_insert): Fix element read from
> > first vector.
> > 
> > * gcc.dg/pr91069.c: New testcase.
> 
> I've noticed the testcase FAILs on ia32, the problem is that long is
> 32-bit and so v2di type isn't v2di we are expecting, but v4si and mismatches
> the v2df in number of elements and element precision.
> 
> Fixed thusly, regtested on x86_64-linux and i686-linux, committed to trunk.
> 
> Note, still not truly portable, if double and long long have different
> sizes on some target, this will still fail.

Hmm, yeah.  I guess some #if on __SIZEOF_LONG_LONG__ != __SIZEOF_DOUBLE__
might do the trick.  OTOH it would be nice if we'd not need to
spell out the vector type for constant shuffles but have the FE
autodetect them, thus make

 __builtin_shuffle ((v2df) { 1.0, 0.0 }, x, { 1, 3 })

work magically.

Richard.

> 2019-07-04  Jakub Jelinek  
> 
>   PR middle-end/91069
>   * gcc.dg/pr91069.c (v2df): Use 2 * sizeof (double) instead of
>   hardcoded 16 for better portability.
>   (v2di): Change from long vector to long long vector.  Use
>   2 * sizeof (long long) instead of hardcoded 16.
> 
> --- gcc/testsuite/gcc.dg/pr91069.c.jj 2019-07-04 00:18:31.510099301 +0200
> +++ gcc/testsuite/gcc.dg/pr91069.c2019-07-04 07:08:24.944046933 +0200
> @@ -1,8 +1,8 @@
>  /* { dg-do run } */
>  /* { dg-options "-std=gnu11" } */
>  
> -typedef double v2df __attribute__((vector_size(16)));
> -typedef long v2di __attribute__((vector_size(16)));
> +typedef double v2df __attribute__((vector_size(2 * sizeof (double;
> +typedef long long v2di __attribute__((vector_size(2 * sizeof (long long;
>  
>  void foo (v2df *res, v2df *src)
>  {
> 


Re: [PATCH] Fix vect_init_vector regression (PR tree-optimization/91063)

2019-07-04 Thread Richard Biener
On Thu, 4 Jul 2019, Jakub Jelinek wrote:

> Hi!
> 
> A recent change in vect_init_vector emits new statements into a gimple_seq
> stmts and then calls vect_init_vector_1 on each of those statements.
> 
> This doesn't work well, because vect_init_vector_1 places the given
> statement into another sequence (body of some bb, on the edge, ...),
> and when the caller holds a gimple_stmt_iterator pointing to that statement
> across its insertion into another sequence the ->prev/->next bookkeeping may
> go wrong, such as on the testcase where stmt == stmt->prev == stmt->next
> because of that.

Whoops...  probably worked as long as there was only a single
stmt in the sequence...

> Fixed by first removing the statement from the stmts sequence (thus
> gsi_remove already updates the iterator to the next statement).
> 
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

OK.

Thanks,
Richard.

> 2019-07-04  Jakub Jelinek  
> 
>   PR tree-optimization/91063
>   * tree-vect-stmts.c (vect_init_vector): Call gsi_remove to remove
>   stmt from stmts sequence before calling vect_init_vector_1.
>   Formatting fix.
> 
>   * gcc.dg/gomp/pr91063.c: New test.
> 
> --- gcc/tree-vect-stmts.c.jj  2019-07-03 10:24:33.463768431 +0200
> +++ gcc/tree-vect-stmts.c 2019-07-03 12:35:48.998435660 +0200
> @@ -1496,15 +1496,19 @@ vect_init_vector (stmt_vec_info stmt_inf
>  promotion of invariant/external defs.  */
>   val = gimple_convert (&stmts, TREE_TYPE (type), val);
> for (gimple_stmt_iterator gsi2 = gsi_start (stmts);
> -!gsi_end_p (gsi2); gsi_next (&gsi2))
> - vect_init_vector_1 (stmt_info, gsi_stmt (gsi2), gsi);
> +!gsi_end_p (gsi2); )
> + {
> +   init_stmt = gsi_stmt (gsi2);
> +   gsi_remove (&gsi2, false);
> +   vect_init_vector_1 (stmt_info, init_stmt, gsi);
> + }
>   }
>   }
>val = build_vector_from_val (type, val);
>  }
>  
>new_temp = vect_get_new_ssa_name (type, vect_simple_var, "cst_");
> -  init_stmt = gimple_build_assign  (new_temp, val);
> +  init_stmt = gimple_build_assign (new_temp, val);
>vect_init_vector_1 (stmt_info, init_stmt, gsi);
>return new_temp;
>  }
> --- gcc/testsuite/gcc.dg/gomp/pr91063.c.jj2019-07-03 12:50:55.123799217 
> +0200
> +++ gcc/testsuite/gcc.dg/gomp/pr91063.c   2019-07-03 12:50:43.320989864 
> +0200
> @@ -0,0 +1,17 @@
> +/* PR tree-optimization/91063 */
> +/* { dg-do compile } */
> +/* { dg-options "-O2 -fopenmp-simd" } */
> +/* { dg-additional-options "-mavx512f" { target { i?86-*-* x86_64-*-* } } } 
> */
> +
> +struct S { void *s; };
> +
> +int
> +foo (struct S *x)
> +{
> +  int r = 0;
> +  int i;
> +#pragma omp simd reduction (+ : r)
> +  for (i = 0; i < 64; ++i)
> +r += (int) (x->s != 0);
> +  return r;
> +}


[PATCH] Fix loading of lto_section on strict alignment targets (PR lto/91078).

2019-07-04 Thread Martin Liška
Hi.

The patch fixes wrong assignment from a char * to lto_section_header
that is seen on strict alignment targets.

I verified it fixes the problem with -fsanitize=undefined:

gcc main.o -flto
../../gcc/lto/lto-common.c:2202:36: runtime error: reference binding to 
misaligned address 0x7f64dac090a7 for type 'const struct lto_section', which 
requires 4 byte alignment
0x7f64dac090a7: note: pointer points here
 00 1b c0 02 09  00 00 00 03 00 00 00 28  b5 2f fd 60 77 00 d5 08  00 e6 d1 3d 
37 20 01 09  00 bf 53
 ^ 
../../gcc/lto/lto-common.c:2202:33: runtime error: load of misaligned address 
0x7f64dac090a7 for type 'const struct lto_section', which requires 4 byte 
alignment
0x7f64dac090a7: note: pointer points here
 00 1b c0 02 09  00 00 00 03 00 00 00 28  b5 2f fd 60 77 00 d5 08  00 e6 d1 3d 
37 20 01 09  00 bf 53
 ^ 

Ready for trunk?
Thanks,
Martin

gcc/lto/ChangeLog:

2019-07-04  Martin Liska  

PR lto/91078
* lto-common.c (lto_file_finalize): Use memcpy to set
file_data->lto_section_header.
---
 gcc/lto/lto-common.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)


diff --git a/gcc/lto/lto-common.c b/gcc/lto/lto-common.c
index bc8c2b40387..3c6d7b25ddb 100644
--- a/gcc/lto/lto-common.c
+++ b/gcc/lto/lto-common.c
@@ -2199,7 +2199,7 @@ lto_file_finalize (struct lto_file_decl_data *file_data, lto_file *file)
   return;
 }
 
-  file_data->lto_section_header = *(const lto_section *)data;
+  memcpy (&file_data->lto_section_header, data, sizeof (lto_section));
   lto_check_version (file_data->lto_section_header.major_version,
 		 file_data->lto_section_header.minor_version,
 		 file_data->file_name);