RE: [PATCH 5/6] [ARC] Add 'uncached' attribute.

2017-11-09 Thread Claudiu Zissulescu
Just for the record, here it is the updated documentation as suggested. And, 
indeed the description may very well be suited for NIOS io-variant as well.

Thank you Sandra,
Claudiu

---
 gcc/doc/extend.texi | 11 +++
 1 file changed, 11 insertions(+)

diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi
index a7a770f..3243494 100644
--- a/gcc/doc/extend.texi
+++ b/gcc/doc/extend.texi
@@ -6728,6 +6728,7 @@ attributes.
 
 @menu
 * Common Type Attributes::
+* ARC Type Attributes::
 * ARM Type Attributes::
 * MeP Type Attributes::
 * PowerPC Type Attributes::
@@ -7161,6 +7162,16 @@ To specify multiple attributes, separate them by commas 
within the
 double parentheses: for example, @samp{__attribute__ ((aligned (16),
 packed))}.
 
+@node ARC Type Attributes
+@subsection ARC Type Attributes
+
+@cindex @code{uncached} type attribute, ARC
+Declaring objects with @code{uncached} allows you to exclude
+data-cache participation in load and store operations on those objects
+without involving the additional semantic implications of
+@code{volatile}.  The @code{.di} instruction suffix is used for all
+loads and stores of data declared @code{uncached}.
+
 @node ARM Type Attributes
 @subsection ARM Type Attributes
 
-- 
1.9.1


Re: [PATCH 8/N][RFC][v3]: GCOV: support multiple functions per a line

2017-11-09 Thread Martin Liška
On 11/08/2017 03:57 PM, Nathan Sidwell wrote:
> On 11/08/2017 06:03 AM, Martin Liška wrote:
>> On 11/07/2017 03:49 PM, Nathan Sidwell wrote:
>>> On 11/07/2017 05:53 AM, Martin Liška wrote:
 Hello.

 This is slightly updated version from the previous. Various small issues 
 were fixed
 and I update documentation in order to reflect the changes.
>>>
 +  gcov_write_unsigned (DECL_ARTIFICIAL (current_function_decl));
     gcov_write_filename (xloc.file);
     gcov_write_unsigned (xloc.line);
 +  gcov_write_unsigned (expand_location (cfun->function_end_locus).line);
     gcov_write_length (offset);
>>>
>>> this is presuming the end line is in the same file as the start line.  A 
>>> reasonable assumption, but users can have exciting ideas!  What is the 
>>> failure mode if the function straddles a file boundary?
>>
>> Hi.
>>
>> I decided to fix that with change that set line_end = line_start if line_end 
>> < line_start.
>> That survives reasonably well with cases like this:
> 
>> +  gcov_write_unsigned (DECL_ARTIFICIAL (current_function_decl));
>>    gcov_write_filename (xloc.file);
>>    gcov_write_unsigned (xloc.line);
>> +  gcov_write_unsigned (xloc.column);
>> +
>> +  /* Function can start in a single file and end in another one.  */
>> +  int fn_end_line = expand_location (cfun->function_end_locus).line;
>> +  gcov_write_unsigned (fn_end_line > xloc.line ? fn_end_line : xloc.line);
> 
> sorry to be picky, but of course the end line could be greater than the 
> start. but in a different file.  Please check file too.

That's fine, thank you for good feedback!

> 
> 
>>> This isn't stable if they start on the same line.  Will output order depend 
>>> on the vaguaries of the sorting algorithm?
>>>
 +  vector &lines = (*it2)->lines;
 +  /* Print all lines covered by the function.  */
 +  for (unsigned i = 0; i < lines.size (); i++)
>>
>> So fixed by introduction of line column that is used for sorting as well.
> 
> thanks.
>> May I understand the reply as ACK?
> 
> Patch ok, with the above check for file names added.
> 
> nathan
> 

Just installed as r254562. I'm planning to apply some small code clean-up
and I'm done :)

Martin


Re: [PATCH PR82776]Exploit more undefined pointer overflow behavior in loop niter analysis

2017-11-09 Thread Richard Biener
On Wed, Nov 8, 2017 at 1:25 PM, Bin.Cheng  wrote:
> On Wed, Nov 8, 2017 at 11:55 AM, Richard Biener
>  wrote:
>> On Tue, Nov 7, 2017 at 1:44 PM, Bin.Cheng  wrote:
>>> On Tue, Nov 7, 2017 at 12:23 PM, Richard Biener
>>>  wrote:
 On Tue, Nov 7, 2017 at 1:17 PM, Bin.Cheng  wrote:
> On Tue, Nov 7, 2017 at 10:44 AM, Richard Biener
>  wrote:
>> On Fri, Nov 3, 2017 at 1:35 PM, Bin Cheng  wrote:
>>> Hi,
>>> This is a simple patch exploiting more undefined pointer overflow 
>>> behavior in
>>> loop niter analysis.  Originally, it only supports POINTER_PLUS_EXPR if 
>>> the
>>> offset part is IV.  This patch also handles the case if pointer is IV.  
>>> With
>>> this patch, the while(true) loop in test can be removed by cddce pass 
>>> now.
>>>
>>> Bootstrap and test on x86_64 and AArch64.  This patch introduces two 
>>> failures:
>>> FAIL: g++.dg/pr79095-1.C  -std=gnu++98 (test for excess errors)
>>> FAIL: g++.dg/pr79095-2.C  -std=gnu++11 (test for excess errors)
>>> I believe this exposes inaccurate value range information issue.  For 
>>> below code:
>>> /* { dg-do compile } */
>>> /* { dg-options "-Wall -O3" } */
>>>
>>> typedef long unsigned int size_t;
>>>
>>> inline void
>>> fill (int *p, size_t n, int)
>>> {
>>>   while (n--)
>>> *p++ = 0;
>>> }
>>>
>>> struct B
>>> {
>>>   int* p0, *p1, *p2;
>>>
>>>   size_t size () const {
>>> return size_t (p1 - p0);
>>>   }
>>>
>>>   void resize (size_t n) {
>>> if (n > size())
>>>   append (n - size());
>>>   }
>>>
>>>   void append (size_t n)
>>>   {
>>> if (size_t (p2 - p1) >= n)   {
>>>   fill (p1, n, 0);
>>> }
>>>   }
>>> };
>>>
>>> void foo (B &b)
>>> {
>>>   if (b.size () != 0)
>>> b.resize (b.size () - 1);
>>> }
>>>
>>> GCC gives below warning with this patch:
>>> pr79095-1.C: In function ‘void foo(B&)’:
>>> pr79095-1.C:10:7: warning: iteration 4611686018427387903 invokes 
>>> undefined behavior [-Waggressive-loop-optimizations]
>>>  *p++ = 0;
>>>   ~^~
>>> pr79095-1.C:9:11: note: within this loop
>>>while (n--)
>>>^~
>>>
>>> Problem is VRP should understand that it's never the case with 
>>> condition:
>>>   (size_t (p2 - p1) >= n)
>>> in function B::append.
>>>
>>> So, any comment?

 Does it warn when not inlining fill()?  Isn't the issue that one test
>>> With this patch, yes.
 tests p2 - p1 and
 the loop goes from p1 to p1 + (p1 - p0)?
>>> don't follow here.  so the code is:
>>>
>>> inline void
>>> fill (int *p, size_t n, int)
>>> {
>>>   while (n--)
>>> *p++ = 0;
>>> }
>>>
>>>   void append (size_t n)
>>>   {
>>> if (size_t (p2 - p1) >= n)   {
>>>   fill (p1, n, 0);
>>> }
>>>
>>> fill is only called if size_t (p2 - p1) >= n, so while loop in fill
>>> can only zero-out memory range [p1, p2)?
>>
>> what happens if p1 is before p0?  The compare
>> p2 - p1 >= p1 - p0 doesn't tell us much when
>> iterating from p1 to p1 + ((p1 - p0) - 1), no?
> I double thought on this.  Looks like the warning message is not
> spurious when p2 is before p1, in which case we have no information
> about argument "n" to the call of fill.
> Otherwise, if p1 is before p2, we can always assume n has value that
> *p++ never overflow.  In this case it has nothing to do with p0,
> right?
>>
>>>

 What kind of optimization do we apply to the loop in fill?
>>> Depends on some conditions, the loop could be distributed into memset.
>>> Anyway, the warning message is issued as long as niter analysis
>>> believes it takes advantage of undefined pointer overflow behavior.
>>
>> Hmm, yes.
>>
>> Not sure if the warning will be too noisy in the end.  I'd say go ahead
> I guess it could be too noisy.  And as above, the warning looks like correct?

Yes, it does.

Richard.

> Thanks,
> bin
>> and add a dg-warning for the testcase for the moment.
>>
>> Thanks,
>> Richard.
>>
>>> Thanks,
>>> bin

>> I'm looking hard but I can't see you changed anything in
>> infer_loop_bounds_from_pointer_arith
>> besides adding a expr_invariant_in_loop_p (loop, rhs2) check.
> yes, that's enough for this fix?
>
> -  ptr = gimple_assign_rhs1 (stmt);
> -  if (!expr_invariant_in_loop_p (loop, ptr))
> +  rhs2 = gimple_assign_rhs2 (stmt);
> +  if (TYPE_PRECISION (type) != TYPE_PRECISION (TREE_TYPE (rhs2)))
>  return;
>
> -  var = gimple_assign_rhs2 (stmt);
> -  if (TYPE_PRECISION (type) != TYPE_PRECISION (TREE_TYPE (var)))
> +  rhs1 = gimple_assign_rhs1 (stmt);
> +  if (!expr_invariant_in_loop_p (loop, rhs1)
> +  && !expr_invariant_in_loop_p (loop, rhs2))
>  return;
>
> Before this change, the function 

[PATCH][i386,AVX] Enable VPCLMULQDQ support

2017-11-09 Thread Koval, Julia
Hi, this patch enables VPCLMULQDQ instruction from VPCLMULQDQ isaset, defined 
here: 
https://software.intel.com/sites/default/files/managed/c5/15/architecture-instruction-set-extensions-programming-reference.pdf

Ok for trunk?
Thanks,
Julia

gcc/
* common/config/i386/i386-common.c (OPTION_MASK_ISA_VPCLMULQDQ_SET,
OPTION_MASK_ISA_VPCLMULQDQ_UNSET): New.
(ix86_handle_option): Handle -mvpclmulqdq, move cx6 to flags2.
* config.gcc: Include vpclmulqdqintrin.h.
* config/i386/cpuid.h: Handle bit_VPCLMULQDQ.
* config/i386/driver-i386.c (host_detect_local_cpu): Handle 
-mvpclmulqdq.
* config/i386/i386-builtin.def (__builtin_ia32_vpclmulqdq_v2di,
__builtin_ia32_vpclmulqdq_v4di, __builtin_ia32_vpclmulqdq_v8di): New.
* config/i386/i386-c.c (__VPCLMULQDQ__): New.
* config/i386/i386.c (isa2_opts): Add -mcx16.
(isa_opts): Add -mpclmulqdq, remove -mcx16.
(ix86_option_override_internal): Move mcx16 to flags2.
(ix86_valid_target_attribute_inner_p): Add vpclmulqdq.
(ix86_expand_builtin): Handle OPTION_MASK_ISA_VPCLMULQDQ.
* config/i386/i386.h (TARGET_VPCLMULQDQ, TARGET_VPCLMULQDQ_P): New.
* config/i386/i386.opt: Add mvpclmulqdq, move mcx16 to flags2.
* config/i386/immintrin.h: Include vpclmulqdqintrin.h.
* config/i386/sse.md (vpclmulqdq_): New pattern.
* config/i386/vpclmulqdqintrin.h (_mm512_clmulepi64_epi128,
_mm_clmulepi64_epi128, _mm256_clmulepi64_epi128): New intrinsics.
* doc/invoke.texi: Add -mvpclmulqdq.

gcc/testsuite/
* gcc.target/i386/avx-1.c: Handle new intrinsics.
* gcc.target/i386/sse-13.c: Ditto.
* gcc.target/i386/sse-23.c: Ditto.
* gcc.target/i386/avx512-check.h: Handle bit_VPCLMULQDQ.
* gcc.target/i386/avx512f-vpclmulqdq-2.c: New test.
* gcc.target/i386/avx512vl-vpclmulqdq-2.c: Ditto.
* gcc.target/i386/vpclmulqdq.c: Ditto.
* gcc.target/i386/i386.exp (check_effective_target_vpclmulqdq): New.


0001-mvpclmulqdq-option.patch
Description: 0001-mvpclmulqdq-option.patch


[PATCH 0/7] GCOV: infrastructure clean-up

2017-11-09 Thread marxin
Hello.

Following patch series is quite mechanical, it adds usage of STL
containers and it removes many typedefs that are with C++ not needed
in my oppinion.

Patch survives gcov.exp test-suite.

Thanks,
Martin

marxin (7):
  GCOV: introduce global vector of functions
  GCOV: simplify usage of function_info::artificial.
  GCOV: introduce vector for function_info::counts.
  GCOV: remove typedef for function_t
  GCOV: remove typedef for arc_t
  GCOV: remove typedef for block_t
  GCOV: remove typedef of coverage_t.

 gcc/gcov.c | 365 ++---
 1 file changed, 177 insertions(+), 188 deletions(-)

-- 
2.14.3



[PATCH 2/7] GCOV: simplify usage of function_info::artificial.

2017-11-09 Thread marxin
gcc/ChangeLog:

2017-11-09  Martin Liska  

* gcov.c (is_artificial): New function.
(process_file): Erase all artificial early.
(generate_results): Skip as all artificial are already
removed.
---
 gcc/gcov.c | 66 +-
 1 file changed, 40 insertions(+), 26 deletions(-)

diff --git a/gcc/gcov.c b/gcc/gcov.c
index 83239639247..3dc159726c7 100644
--- a/gcc/gcov.c
+++ b/gcc/gcov.c
@@ -1088,6 +1088,14 @@ struct function_start_pair_hash : typed_noop_remove 

   }
 };
 
+/* Function filter based on function_info::artificial variable.  */
+
+static bool
+is_artificial (function_info *fn)
+{
+  return fn->artificial;
+}
+
 /* Process a single input file.  */
 
 static void
@@ -1122,33 +1130,40 @@ process_file (const char *file_name)
  fn_map.put (needle, *it);
   }
 
+  /* Remove all artificial function.  */
+  functions.erase (remove_if (functions.begin (), functions.end (),
+ is_artificial), functions.end ());
+
   for (vector::iterator it = functions.begin ();
it != functions.end (); it++)
 {
   function_t *fn = *it;
+  unsigned src = fn->src;
 
   if (fn->counts || no_data_file)
{
- unsigned src = fn->src;
- unsigned block_no;
+ source_info *s = &sources[src];
+ s->functions.push_back (fn);
 
- /* Process only non-artificial functions.  */
- if (!fn->artificial)
+ /* Mark last line in files touched by function.  */
+ for (unsigned block_no = 0; block_no != fn->blocks.size ();
+  block_no++)
{
- source_info *s = &sources[src];
- s->functions.push_back (fn);
-
- /* Mark last line in files touched by function.  */
- for (block_no = 0; block_no != fn->blocks.size (); block_no++)
+ block_t *block = &fn->blocks[block_no];
+ for (unsigned i = 0; i < block->locations.size (); i++)
{
- block_t *block = &fn->blocks[block_no];
- for (unsigned i = 0; i < block->locations.size (); i++)
+ /* Sort lines of locations.  */
+ sort (block->locations[i].lines.begin (),
+   block->locations[i].lines.end ());
+
+ if (!block->locations[i].lines.empty ())
{
- /* Sort lines of locations.  */
- sort (block->locations[i].lines.begin (),
-   block->locations[i].lines.end ());
+ s = &sources[block->locations[i].source_file_idx];
+ unsigned last_line
+   = block->locations[i].lines.back ();
 
- if (!block->locations[i].lines.empty ())
+ /* Record new lines for the function.  */
+ if (last_line >= s->lines.size ())
{
  s = &sources[block->locations[i].source_file_idx];
  unsigned last_line
@@ -1162,17 +1177,18 @@ process_file (const char *file_name)
}
}
}
-
- /* Allocate lines for group function, following start_line
-and end_line information of the function.  */
- if (fn->is_group)
-   fn->lines.resize (fn->end_line - fn->start_line + 1);
}
-
- solve_flow_graph (fn);
- if (fn->has_catch)
-   find_exception_blocks (fn);
}
+
+ /* Allocate lines for group function, following start_line
+and end_line information of the function.  */
+ if (fn->is_group)
+   fn->lines.resize (fn->end_line - fn->start_line + 1);
+
+
+ solve_flow_graph (fn);
+ if (fn->has_catch)
+   find_exception_blocks (fn);
}
   else
{
@@ -1221,8 +1237,6 @@ generate_results (const char *file_name)
 {
   function_t *fn = *it;
   coverage_t coverage;
-  if (fn->artificial)
-   continue;
 
   memset (&coverage, 0, sizeof (coverage));
   coverage.name = flag_demangled_names ? fn->demangled_name : fn->name;
-- 
2.14.3




[PATCH 1/7] GCOV: introduce global vector of functions

2017-11-09 Thread marxin
gcc/ChangeLog:

2017-11-09  Martin Liska  

* gcov.c (read_graph_file): Store to global vector of functions.
(read_count_file): Iterate the vector.
(process_file): Likewise.
(generate_results): Likewise.
(release_structures): Likewise.
---
 gcc/gcov.c | 108 +
 1 file changed, 44 insertions(+), 64 deletions(-)

diff --git a/gcc/gcov.c b/gcc/gcov.c
index 846a2326196..83239639247 100644
--- a/gcc/gcov.c
+++ b/gcc/gcov.c
@@ -392,10 +392,8 @@ public:
   unsigned src;  /* Source file */
 };
 
-/* Holds a list of function basic block graphs.  */
-

-static function_t *functions;
-static function_t **fn_end = &functions;
+/* Vector of all functions.  */
+static vector functions;
 
 /* Vector of source files.  */
 static vector sources;
@@ -532,8 +530,8 @@ static void generate_results (const char *);
 static void create_file_names (const char *);
 static char *canonicalize_name (const char *);
 static unsigned find_source (const char *);
-static function_t *read_graph_file (void);
-static int read_count_file (function_t *);
+static void read_graph_file (void);
+static int read_count_file (void);
 static void solve_flow_graph (function_t *);
 static void find_exception_blocks (function_t *);
 static void add_branch_counts (coverage_t *, const arc_t *);
@@ -1095,42 +1093,40 @@ struct function_start_pair_hash : typed_noop_remove 

 static void
 process_file (const char *file_name)
 {
-  function_t *fns;
-
   create_file_names (file_name);
-  fns = read_graph_file ();
-  if (!fns)
+  read_graph_file ();
+  if (functions.empty ())
 return;
 
-  read_count_file (fns);
+  read_count_file ();
 
   hash_map fn_map;
 
   /* Identify group functions.  */
-  for (function_t *f = fns; f; f = f->next)
-if (!f->artificial)
+  for (vector::iterator it = functions.begin ();
+   it != functions.end (); it++)
+if (!(*it)->artificial)
   {
function_start needle;
-   needle.source_file_idx = f->src;
-   needle.start_line = f->start_line;
+   needle.source_file_idx = (*it)->src;
+   needle.start_line = (*it)->start_line;
 
function_t **slot = fn_map.get (needle);
if (slot)
  {
-   gcc_assert ((*slot)->end_line == f->end_line);
+   gcc_assert ((*slot)->end_line == (*it)->end_line);
(*slot)->is_group = 1;
-   f->is_group = 1;
+   (*it)->is_group = 1;
  }
else
- fn_map.put (needle, f);
+ fn_map.put (needle, *it);
   }
 
-  while (fns)
+  for (vector::iterator it = functions.begin ();
+   it != functions.end (); it++)
 {
-  function_t *fn = fns;
+  function_t *fn = *it;
 
-  fns = fn->next;
-  fn->next = NULL;
   if (fn->counts || no_data_file)
{
  unsigned src = fn->src;
@@ -1177,14 +1173,12 @@ process_file (const char *file_name)
  if (fn->has_catch)
find_exception_blocks (fn);
}
-
- *fn_end = fn;
- fn_end = &fn->next;
}
   else
-   /* The function was not in the executable -- some other
-  instance must have been selected.  */
-   delete fn;
+   {
+ /* The function was not in the executable -- some other
+instance must have been selected.  */
+   }
 }
 }
 
@@ -1222,10 +1216,10 @@ output_gcov_file (const char *file_name, source_info 
*src)
 static void
 generate_results (const char *file_name)
 {
-  function_t *fn;
-
-  for (fn = functions; fn; fn = fn->next)
+  for (vector::iterator it = functions.begin ();
+   it != functions.end (); it++)
 {
+  function_t *fn = *it;
   coverage_t coverage;
   if (fn->artificial)
continue;
@@ -1291,13 +1285,11 @@ generate_results (const char *file_name)
 static void
 release_structures (void)
 {
-  function_t *fn;
+  for (vector::iterator it = functions.begin ();
+   it != functions.end (); it++)
+delete (*it);
 
-  while ((fn = functions))
-{
-  functions = fn->next;
-  delete fn;
-}
+  functions.resize (0);
 }
 
 /* Generate the names of the graph and data files.  If OBJECT_DIRECTORY
@@ -1455,29 +1447,26 @@ find_source (const char *file_name)
   return idx;
 }
 
-/* Read the notes file.  Return list of functions read -- in reverse order.  */
+/* Read the notes file.  Save functions to FUNCTIONS global vector.  */
 
-static function_t *
+static void
 read_graph_file (void)
 {
   unsigned version;
   unsigned current_tag = 0;
-  function_t *fn = NULL;
-  function_t *fns = NULL;
-  function_t **fns_end = &fns;
   unsigned tag;
 
   if (!gcov_open (bbg_file_name, 1))
 {
   fnotice (stderr, "%s:cannot open notes file\n", bbg_file_name);
-  return fns;
+  return;
 }
   bbg_file_time = gcov_time ();
   if (!gcov_magic (gcov_read_unsigned (), GCOV_NOTE_MAGIC))
 {
   fnotice (stderr, "%s:not a gcov notes file\n", bbg_file_name);
  

[PATCH 5/7] GCOV: remove typedef for arc_t

2017-11-09 Thread marxin
gcc/ChangeLog:

2017-11-09  Martin Liska  

* gcov.c (struct arc_info): Remove typedef for arc_t.
(struct line_info): Likewise.
(add_branch_counts): Likewise.
(output_branch_count): Likewise.
(function_info::~function_info): Likewise.
(circuit): Likewise.
(output_intermediate_line): Likewise.
(read_graph_file): Likewise.
(solve_flow_graph): Likewise.
(find_exception_blocks): Likewise.
(add_line_counts): Likewise.
(accumulate_line_info): Likewise.
(output_line_details): Likewise.
(output_function_details): Likewise.
---
 gcc/gcov.c | 58 +-
 1 file changed, 29 insertions(+), 29 deletions(-)

diff --git a/gcc/gcov.c b/gcc/gcov.c
index a1c489bccdc..e33c7b6f8cd 100644
--- a/gcc/gcov.c
+++ b/gcc/gcov.c
@@ -79,7 +79,7 @@ struct source_info;
 
 /* Describes an arc between two basic blocks.  */
 
-typedef struct arc_info
+struct arc_info
 {
   /* source and destination blocks.  */
   struct block_info *src;
@@ -113,7 +113,7 @@ typedef struct arc_info
   /* Links to next arc on src and dst lists.  */
   struct arc_info *succ_next;
   struct arc_info *pred_next;
-} arc_t;
+};
 
 /* Describes which locations (lines and files) are associated with
a basic block.  */
@@ -137,8 +137,8 @@ typedef struct block_info
   block_info ();
 
   /* Chain of exit and entry arcs.  */
-  arc_t *succ;
-  arc_t *pred;
+  arc_info *succ;
+  arc_info *pred;
 
   /* Number of unprocessed exit and entry arcs.  */
   gcov_type num_succ;
@@ -166,7 +166,7 @@ typedef struct block_info
   {
 /* Single line graph cycle workspace.  Used for all-blocks
mode.  */
-arc_t *arc;
+arc_info *arc;
 unsigned ident;
   } cycle; /* Used in all-blocks mode, after blocks are linked onto
 lines.  */
@@ -200,7 +200,7 @@ struct line_info
   gcov_type count;
 
   /* Branches from blocks that end on this line.  */
-  vector branches;
+  vector branches;
 
   /* blocks which start on this line.  Used in all-blocks mode.  */
   vector blocks;
@@ -533,14 +533,14 @@ static void read_graph_file (void);
 static int read_count_file (void);
 static void solve_flow_graph (function_info *);
 static void find_exception_blocks (function_info *);
-static void add_branch_counts (coverage_t *, const arc_t *);
+static void add_branch_counts (coverage_t *, const arc_info *);
 static void add_line_counts (coverage_t *, function_info *);
 static void executed_summary (unsigned, unsigned);
 static void function_summary (const coverage_t *, const char *);
 static const char *format_gcov (gcov_type, gcov_type, int);
 static void accumulate_line_counts (source_info *);
 static void output_gcov_file (const char *, source_info *);
-static int output_branch_count (FILE *, int, const arc_t *);
+static int output_branch_count (FILE *, int, const arc_info *);
 static void output_lines (FILE *, const source_info *);
 static char *make_gcov_file_name (const char *, const char *);
 static char *mangle_name (const char *, char *);
@@ -559,7 +559,7 @@ function_info::~function_info ()
 {
   for (int i = blocks.size () - 1; i >= 0; i--)
 {
-  arc_t *arc, *arc_n;
+  arc_info *arc, *arc_n;
 
   for (arc = blocks[i].succ; arc; arc = arc_n)
{
@@ -589,7 +589,7 @@ bool function_info::group_line_p (unsigned n, unsigned 
src_idx)
simple paths)--the node is unblocked only when it participates in a cycle.
*/
 
-typedef vector arc_vector_t;
+typedef vector arc_vector_t;
 typedef vector block_vector_t;
 
 /* Enum with types of loop in CFG.  */
@@ -671,7 +671,7 @@ circuit (block_t *v, arc_vector_t &path, block_t *start,
   blocked.push_back (v);
   block_lists.push_back (block_vector_t ());
 
-  for (arc_t *arc = v->succ; arc; arc = arc->succ_next)
+  for (arc_info *arc = v->succ; arc; arc = arc->succ_next)
 {
   block_t *w = arc->dst;
   if (w < start || !linfo.has_block (w))
@@ -690,7 +690,7 @@ circuit (block_t *v, arc_vector_t &path, block_t *start,
   if (result != NO_LOOP)
 unblock (v, blocked, block_lists);
   else
-for (arc_t *arc = v->succ; arc; arc = arc->succ_next)
+for (arc_info *arc = v->succ; arc; arc = arc->succ_next)
   {
block_t *w = arc->dst;
if (w < start || !linfo.has_block (w))
@@ -960,7 +960,7 @@ output_intermediate_line (FILE *f, line_info *line, 
unsigned line_num)
   format_gcov (line->count, 0, -1),
   line->has_unexecuted_block);
 
-  vector::const_iterator it;
+  vector::const_iterator it;
   if (flag_branches)
 for (it = line->branches.begin (); it != line->branches.end ();
 it++)
@@ -1563,7 +1563,7 @@ read_graph_file (void)
 
  if (dest >= fn->blocks.size ())
goto corrupt;
- arc = XCNEW (arc_t);
+ arc = XCNEW (arc_info);
 
  arc->dst = &fn->blocks[dest];
  arc->src = src_blk;
@@ -1782,7 +1782,7 @@ static

[PATCH 3/7] GCOV: introduce vector for function_info::counts.

2017-11-09 Thread marxin
gcc/ChangeLog:

2017-11-09  Martin Liska  

* gcov.c (function_info::function_info): Remove num_counts
and add vector.
(function_info::~function_info): Use the vector.
(process_file): Likewise.
(read_graph_file): Likewise.
(read_count_file): Likewise.
(solve_flow_graph): Likewise.
---
 gcc/gcov.c | 21 -
 1 file changed, 8 insertions(+), 13 deletions(-)

diff --git a/gcc/gcov.c b/gcc/gcov.c
index 3dc159726c7..02a01b51763 100644
--- a/gcc/gcov.c
+++ b/gcc/gcov.c
@@ -257,8 +257,7 @@ typedef struct function_info
   unsigned blocks_executed;
 
   /* Raw arc coverage counts.  */
-  gcov_type *counts;
-  unsigned num_counts;
+  vector counts;
 
   /* First line number.  */
   unsigned start_line;
@@ -551,8 +550,8 @@ extern int main (int, char **);
 function_info::function_info (): name (NULL), demangled_name (NULL),
   ident (0), lineno_checksum (0), cfg_checksum (0), has_catch (0),
   artificial (0), is_group (0),
-  blocks (), blocks_executed (0), counts (NULL), num_counts (0),
-  start_line (0), start_column (0), end_line (0), src (0), lines (), next 
(NULL)
+  blocks (), blocks_executed (0), counts (),
+  start_line (0), start_column (), end_line (0), src (0), lines (), next (NULL)
 {
 }
 
@@ -568,7 +567,6 @@ function_info::~function_info ()
  free (arc);
}
 }
-  free (counts);
   if (flag_demangled_names && demangled_name != name)
 free (demangled_name);
   free (name);
@@ -1140,7 +1138,7 @@ process_file (const char *file_name)
   function_t *fn = *it;
   unsigned src = fn->src;
 
-  if (fn->counts || no_data_file)
+  if (!fn->counts.empty () || no_data_file)
{
  source_info *s = &sources[src];
  s->functions.push_back (fn);
@@ -1604,7 +1602,7 @@ read_graph_file (void)
}
 
  if (!arc->on_tree)
-   fn->num_counts++;
+   fn->counts.push_back (0);
}
 
  if (mark_catches)
@@ -1755,13 +1753,10 @@ read_count_file (void)
}
   else if (tag == GCOV_TAG_FOR_COUNTER (GCOV_COUNTER_ARCS) && fn)
{
- if (length != GCOV_TAG_COUNTER_LENGTH (fn->num_counts))
+ if (length != GCOV_TAG_COUNTER_LENGTH (fn->counts.size ()))
goto mismatch;
 
- if (!fn->counts)
-   fn->counts = XCNEWVEC (gcov_type, fn->num_counts);
-
- for (ix = 0; ix != fn->num_counts; ix++)
+ for (ix = 0; ix != fn->counts.size (); ix++)
fn->counts[ix] += gcov_read_counter ();
}
   gcov_sync (base, length);
@@ -1788,7 +1783,7 @@ solve_flow_graph (function_t *fn)
 {
   unsigned ix;
   arc_t *arc;
-  gcov_type *count_ptr = fn->counts;
+  gcov_type *count_ptr = &fn->counts.front ();
   block_t *blk;
   block_t *valid_blocks = NULL;/* valid, but unpropagated blocks.  */
   block_t *invalid_blocks = NULL;  /* invalid, but inferable blocks.  */
-- 
2.14.3




[PATCH 7/7] GCOV: remove typedef of coverage_t.

2017-11-09 Thread marxin
gcc/ChangeLog:

2017-11-09  Martin Liska  

* gcov.c (struct coverage_info): Remove typedef of coverage_t.
(struct source_info): Likewise.
(add_branch_counts): Likewise.
(add_line_counts): Likewise.
(function_summary): Likewise.
(output_intermediate_line): Likewise.
(generate_results): Likewise.
---
 gcc/gcov.c | 24 
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/gcc/gcov.c b/gcc/gcov.c
index 0e5ae8110ad..0669fd9deab 100644
--- a/gcc/gcov.c
+++ b/gcc/gcov.c
@@ -294,7 +294,7 @@ struct function_line_start_cmp
 
 /* Describes coverage of a file or function.  */
 
-typedef struct coverage_info
+struct coverage_info
 {
   int lines;
   int lines_executed;
@@ -307,7 +307,7 @@ typedef struct coverage_info
   int calls_executed;
 
   char *name;
-} coverage_t;
+};
 
 /* Describes a file mentioned in the block graph.  Contains an array
of line info.  */
@@ -329,7 +329,7 @@ struct source_info
   /* Vector of line information.  */
   vector lines;
 
-  coverage_t coverage;
+  coverage_info coverage;
 
   /* Functions in this source file.  These are in ascending line
  number order.  */
@@ -533,10 +533,10 @@ static void read_graph_file (void);
 static int read_count_file (void);
 static void solve_flow_graph (function_info *);
 static void find_exception_blocks (function_info *);
-static void add_branch_counts (coverage_t *, const arc_info *);
-static void add_line_counts (coverage_t *, function_info *);
+static void add_branch_counts (coverage_info *, const arc_info *);
+static void add_line_counts (coverage_info *, function_info *);
 static void executed_summary (unsigned, unsigned);
-static void function_summary (const coverage_t *, const char *);
+static void function_summary (const coverage_info *, const char *);
 static const char *format_gcov (gcov_type, gcov_type, int);
 static void accumulate_line_counts (source_info *);
 static void output_gcov_file (const char *, source_info *);
@@ -968,8 +968,8 @@ output_intermediate_line (FILE *f, line_info *line, 
unsigned line_num)
if (!(*it)->is_unconditional && !(*it)->is_call_non_return)
  {
const char *branch_type;
-   /* branch:,
-  branch_coverage_type
+   /* branch:,
+  branch_coverage_infoype
   : notexec (Branch not executed)
   : taken (Branch executed and taken)
   : nottaken (Branch executed, but not taken)
@@ -1234,7 +1234,7 @@ generate_results (const char *file_name)
it != functions.end (); it++)
 {
   function_info *fn = *it;
-  coverage_t coverage;
+  coverage_info coverage;
 
   memset (&coverage, 0, sizeof (coverage));
   coverage.name = flag_demangled_names ? fn->demangled_name : fn->name;
@@ -2072,7 +2072,7 @@ find_exception_blocks (function_info *fn)
 /* Increment totals in COVERAGE according to arc ARC.  */
 
 static void
-add_branch_counts (coverage_t *coverage, const arc_info *arc)
+add_branch_counts (coverage_info *coverage, const arc_info *arc)
 {
   if (arc->is_call_non_return)
 {
@@ -2184,7 +2184,7 @@ executed_summary (unsigned lines, unsigned executed)
 /* Output summary info for a function or file.  */
 
 static void
-function_summary (const coverage_t *coverage, const char *title)
+function_summary (const coverage_info *coverage, const char *title)
 {
   fnotice (stdout, "%s '%s'\n", title, coverage->name);
   executed_summary (coverage->lines, coverage->lines_executed);
@@ -2421,7 +2421,7 @@ mangle_name (char const *base, char *ptr)
the appropriate basic block.  */
 
 static void
-add_line_counts (coverage_t *coverage, function_info *fn)
+add_line_counts (coverage_info *coverage, function_info *fn)
 {
   bool has_any_line = false;
   /* Scan each basic block.  */
-- 
2.14.3



[PATCH 6/7] GCOV: remove typedef for block_t

2017-11-09 Thread marxin
gcc/ChangeLog:

2017-11-09  Martin Liska  

* gcov.c (struct block_info): Remove typedef for block_t.
(struct line_info): Likewise.
(line_info::has_block): Likewise.
(EXIT_BLOCK): Likewise.
(unblock): Likewise.
(circuit): Likewise.
(get_cycles_count): Likewise.
(process_file): Likewise.
(read_graph_file): Likewise.
(solve_flow_graph): Likewise.
(find_exception_blocks): Likewise.
(add_line_counts): Likewise.
(accumulate_line_info): Likewise.
(output_line_details): Likewise.
---
 gcc/gcov.c | 52 ++--
 1 file changed, 26 insertions(+), 26 deletions(-)

diff --git a/gcc/gcov.c b/gcc/gcov.c
index e33c7b6f8cd..0e5ae8110ad 100644
--- a/gcc/gcov.c
+++ b/gcc/gcov.c
@@ -131,7 +131,7 @@ struct block_location_info
 /* Describes a basic block. Contains lists of arcs to successor and
predecessor blocks.  */
 
-typedef struct block_info
+struct block_info
 {
   /* Constructor.  */
   block_info ();
@@ -175,7 +175,7 @@ typedef struct block_info
  line.  */
   struct block_info *chain;
 
-} block_t;
+};
 
 block_info::block_info (): succ (NULL), pred (NULL), num_succ (0), num_pred 
(0),
   id (0), count (0), count_valid (0), valid_chain (0), invalid_chain (0),
@@ -194,7 +194,7 @@ struct line_info
   line_info ();
 
   /* Return true when NEEDLE is one of basic blocks the line belongs to.  */
-  bool has_block (block_t *needle);
+  bool has_block (block_info *needle);
 
   /* Execution count.  */
   gcov_type count;
@@ -203,7 +203,7 @@ struct line_info
   vector branches;
 
   /* blocks which start on this line.  Used in all-blocks mode.  */
-  vector blocks;
+  vector blocks;
 
   unsigned exists : 1;
   unsigned unexceptional : 1;
@@ -216,7 +216,7 @@ line_info::line_info (): count (0), branches (), blocks (), 
exists (false),
 }
 
 bool
-line_info::has_block (block_t *needle)
+line_info::has_block (block_info *needle)
 {
   return std::find (blocks.begin (), blocks.end (), needle) != blocks.end ();
 }
@@ -253,7 +253,7 @@ struct function_info
  at blocks[0] and the exit block is at blocks[1].  */
 #define ENTRY_BLOCK (0)
 #define EXIT_BLOCK (1)
-  vector blocks;
+  vector blocks;
   unsigned blocks_executed;
 
   /* Raw arc coverage counts.  */
@@ -590,7 +590,7 @@ bool function_info::group_line_p (unsigned n, unsigned 
src_idx)
*/
 
 typedef vector arc_vector_t;
-typedef vector block_vector_t;
+typedef vector block_vector_t;
 
 /* Enum with types of loop in CFG.  */
 
@@ -635,7 +635,7 @@ handle_cycle (const arc_vector_t &edges, int64_t &count)
blocked by U in BLOCK_LISTS.  */
 
 static void
-unblock (const block_t *u, block_vector_t &blocked,
+unblock (const block_info *u, block_vector_t &blocked,
 vector &block_lists)
 {
   block_vector_t::iterator it = find (blocked.begin (), blocked.end (), u);
@@ -660,7 +660,7 @@ unblock (const block_t *u, block_vector_t &blocked,
Returns what type of loop it contains.  */
 
 static loop_type
-circuit (block_t *v, arc_vector_t &path, block_t *start,
+circuit (block_info *v, arc_vector_t &path, block_info *start,
 block_vector_t &blocked, vector &block_lists,
 line_info &linfo, int64_t &count)
 {
@@ -673,7 +673,7 @@ circuit (block_t *v, arc_vector_t &path, block_t *start,
 
   for (arc_info *arc = v->succ; arc; arc = arc->succ_next)
 {
-  block_t *w = arc->dst;
+  block_info *w = arc->dst;
   if (w < start || !linfo.has_block (w))
continue;
 
@@ -692,7 +692,7 @@ circuit (block_t *v, arc_vector_t &path, block_t *start,
   else
 for (arc_info *arc = v->succ; arc; arc = arc->succ_next)
   {
-   block_t *w = arc->dst;
+   block_info *w = arc->dst;
if (w < start || !linfo.has_block (w))
  continue;
 
@@ -721,7 +721,7 @@ get_cycles_count (line_info &linfo, bool 
handle_negative_cycles = true)
 
   loop_type result = NO_LOOP;
   gcov_type count = 0;
-  for (vector::iterator it = linfo.blocks.begin ();
+  for (vector::iterator it = linfo.blocks.begin ();
it != linfo.blocks.end (); it++)
 {
   arc_vector_t path;
@@ -1147,7 +1147,7 @@ process_file (const char *file_name)
  for (unsigned block_no = 0; block_no != fn->blocks.size ();
   block_no++)
{
- block_t *block = &fn->blocks[block_no];
+ block_info *block = &fn->blocks[block_no];
  for (unsigned i = 0; i < block->locations.size (); i++)
{
  /* Sort lines of locations.  */
@@ -1549,7 +1549,7 @@ read_graph_file (void)
  unsigned src = gcov_read_unsigned ();
  fn->blocks[src].id = src;
  unsigned num_dests = GCOV_TAG_ARCS_NUM (length);
- block_t *src_blk = &fn->blocks[src];
+ block_info *src_blk = &fn->blocks[src];
  unsigned mark_catches = 0;
  struct arc_info *arc;
 
@@ -1622,7 +1622,7 @@ read_graph_file (void)

[Ada] Spurious warning about unreferenced formal with implicit dereference

2017-11-09 Thread Pierre-Marie de Rodat
This patch removes a spurious warning about an unused formal parameter when
the type of the psrameter has an Implicit_Dereference aspect and the parameter
is used in a call wthin the subbprogram body.

The following must compile quietly:

   gcc -c -gnatwa tr.adb

---
with Con;
package Tr is
   procedure P (R : Con.R_Type);
end;
---
package body Tr is
   procedure Q (R : Con.R_Type) is
   begin
  Con.Foo (R);
   end;
   procedure P (R : Con.R_Type) is
   begin
  Q (R);
   end;
end Tr;
---
package Con is
   type C_Type is record
  X : Integer;
   end record;

   procedure Foo (X : in out C_Type);

   type R_Type (C : not null access C_Type)
  is tagged limited null record
with Implicit_Dereference => C;
end;

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

2017-11-09  Ed Schonberg  

* sem_res.adb (Resolve): If expression is an entity whose type has
implicit dereference, generate reference to it, because no reference is
generated for an overloaded entity during analysis, given that its
identity may not be known.

Index: sem_res.adb
===
--- sem_res.adb (revision 254563)
+++ sem_res.adb (working copy)
@@ -2448,11 +2448,18 @@
 
--  AI05-0139-2: Expression is overloaded because type has
--  implicit dereference. If type matches context, no implicit
-   --  dereference is involved.
+   --  dereference is involved. If the expression is an entity,
+   --  generate a reference to it, as this is not done for an
+   --  overloaded construct during analysis.
 
elsif Has_Implicit_Dereference (Expr_Type) then
   Set_Etype (N, Expr_Type);
   Set_Is_Overloaded (N, False);
+
+  if Is_Entity_Name (N) then
+ Generate_Reference (Entity (N), N);
+  end if;
+
   exit Interp_Loop;
 
elsif Is_Overloaded (N)


[Ada] Improve layout ABI compatibility with C++

2017-11-09 Thread Pierre-Marie de Rodat
This patch modifies the initialization of the offset_to_top field of
secondary dispatch tables to store negative offsets, thus improving
the layout compatibility of secondary dispatch tables with C++.

No functionality change.

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

2017-11-09  Javier Miranda  

* exp_disp.adb (Expand_Interface_Thunk): Replace substraction of
offset-to-top field by addition.
(Make_Secondary_DT): Initialize the offset-to-top field with a negative
offset.
* exp_ch3.adb (Build_Offset_To_Top_Function): Build functions that
return a negative offset-to-top value.
(Initialize_Tag): Invoke runtime services Set_Dynamic_Offset_To_Top and
Set_Static_Offset_To_Top passing a negative offet-to-top value;
initialize also the offset-to-top field with a negative offset.
* libgnat/a-tags.adb (Base_Address): Displace the pointer by means of
an addition since the offset-to-top field is now a negative value.
(Displace): Displace the pointer to the object means of a substraction
since it is now a negative value.
(Set_Dynamic_Offset_to_top): Displace the pointer to the object by
means of a substraction since it is now a negative value.

Index: libgnat/a-tags.adb
===
--- libgnat/a-tags.adb  (revision 254563)
+++ libgnat/a-tags.adb  (working copy)
@@ -332,7 +332,7 @@
 
function Base_Address (This : System.Address) return System.Address is
begin
-  return This - Offset_To_Top (This);
+  return This + Offset_To_Top (This);
end Base_Address;
 
---
@@ -412,14 +412,14 @@
--  Case of Static value of Offset_To_Top
 
if Iface_Table.Ifaces_Table (Id).Static_Offset_To_Top then
-  Obj_Base := Obj_Base +
+  Obj_Base := Obj_Base -
 Iface_Table.Ifaces_Table (Id).Offset_To_Top_Value;
 
--  Otherwise call the function generated by the expander to
--  provide the value.
 
else
-  Obj_Base := Obj_Base +
+  Obj_Base := Obj_Base -
 Iface_Table.Ifaces_Table (Id).Offset_To_Top_Func.all
   (Obj_Base);
end if;
@@ -1046,7 +1046,7 @@
   --  Save the offset to top field in the secondary dispatch table
 
   if Offset_Value /= 0 then
- Sec_Base := This + Offset_Value;
+ Sec_Base := This - Offset_Value;
  Sec_DT := DT (To_Tag_Ptr (Sec_Base).all);
  Sec_DT.Offset_To_Top := SSE.Storage_Offset'Last;
   end if;
Index: exp_disp.adb
===
--- exp_disp.adb(revision 254563)
+++ exp_disp.adb(working copy)
@@ -1884,7 +1884,7 @@
 --  Generate:
 -- type T is access all <>
 -- S : Storage_Offset := Storage_Offset!(Formal)
---- Offset_To_Top (address!(Formal))
+--+ Offset_To_Top (address!(Formal))
 
 Decl_2 :=
   Make_Full_Type_Declaration (Loc,
@@ -1918,7 +1918,7 @@
 Object_Definition   =>
   New_Occurrence_Of (RTE (RE_Storage_Offset), Loc),
 Expression  =>
-  Make_Op_Subtract (Loc,
+  Make_Op_Add (Loc,
 Left_Opnd  =>
   Unchecked_Convert_To
 (RTE (RE_Storage_Offset),
@@ -1942,7 +1942,7 @@
 
 --  Generate:
 -- S1 : Storage_Offset := Storage_Offset!(Formal'Address)
--- - Offset_To_Top (Formal'Address)
+-- + Offset_To_Top (Formal'Address)
 -- S2 : Addr_Ptr := Addr_Ptr!(S1)
 
 New_Arg :=
@@ -1969,7 +1969,7 @@
 Object_Definition   =>
   New_Occurrence_Of (RTE (RE_Storage_Offset), Loc),
 Expression  =>
-  Make_Op_Subtract (Loc,
+  Make_Op_Add (Loc,
 Left_Opnd =>
   Unchecked_Convert_To
 (RTE (RE_Storage_Offset),
@@ -4234,14 +4234,15 @@
 
  else
 Append_To (DT_Aggr_List,
-  Make_Attribute_Reference (Loc,
-Prefix =>
-  Make_Selected_Component (Loc,
-Prefix=>
-  New_Occurrence_Of (Dummy_Object, Loc),
-Selector_Name =>
-  New_Occurrence_Of (Iface_Comp, Loc)),
-Attribute_Name => Name_Position));
+  Make_Op_Minus (Loc,
+Make_Attribute_Reference (Loc,
+  Prefix =>
+Make_Selected_Compon

[PATCH 4/7] GCOV: remove typedef for function_t

2017-11-09 Thread marxin
gcc/ChangeLog:

2017-11-09  Martin Liska  

* gcov.c (struct function_info): Remove typedef for function_t.
(struct source_info): Likewise.
(source_info::get_functions_at_location): Likewise.
(solve_flow_graph): Likewise.
(find_exception_blocks): Likewise.
(add_line_counts): Likewise.
(output_intermediate_file): Likewise.
(process_file): Likewise.
(generate_results): Likewise.
(release_structures): Likewise.
(read_graph_file): Likewise.
(read_count_file): Likewise.
(accumulate_line_counts): Likewise.
(output_lines): Likewise.
---
 gcc/gcov.c | 70 +++---
 1 file changed, 35 insertions(+), 35 deletions(-)

diff --git a/gcc/gcov.c b/gcc/gcov.c
index 02a01b51763..a1c489bccdc 100644
--- a/gcc/gcov.c
+++ b/gcc/gcov.c
@@ -223,7 +223,7 @@ line_info::has_block (block_t *needle)
 
 /* Describes a single function. Contains an array of basic blocks.  */
 
-typedef struct function_info
+struct function_info
 {
   function_info ();
   ~function_info ();
@@ -276,7 +276,7 @@ typedef struct function_info
 
   /* Next function.  */
   struct function_info *next;
-} function_t;
+};
 
 /* Function info comparer that will sort functions according to starting
line.  */
@@ -317,7 +317,7 @@ struct source_info
   /* Default constructor.  */
   source_info ();
 
-  vector get_functions_at_location (unsigned line_num) const;
+  vector get_functions_at_location (unsigned line_num) const;
 
   /* Index of the source_info in sources vector.  */
   unsigned index;
@@ -333,7 +333,7 @@ struct source_info
 
   /* Functions in this source file.  These are in ascending line
  number order.  */
-  vector  functions;
+  vector  functions;
 };
 
 source_info::source_info (): index (0), name (NULL), file_time (),
@@ -341,12 +341,12 @@ source_info::source_info (): index (0), name (NULL), 
file_time (),
 {
 }
 
-vector
+vector
 source_info::get_functions_at_location (unsigned line_num) const
 {
-  vector r;
+  vector r;
 
-  for (vector::const_iterator it = functions.begin ();
+  for (vector::const_iterator it = functions.begin ();
it != functions.end (); it++)
 {
   if ((*it)->start_line == line_num && (*it)->src == index)
@@ -392,7 +392,7 @@ public:
 };
 
 /* Vector of all functions.  */
-static vector functions;
+static vector functions;
 
 /* Vector of source files.  */
 static vector sources;
@@ -531,10 +531,10 @@ static char *canonicalize_name (const char *);
 static unsigned find_source (const char *);
 static void read_graph_file (void);
 static int read_count_file (void);
-static void solve_flow_graph (function_t *);
-static void find_exception_blocks (function_t *);
+static void solve_flow_graph (function_info *);
+static void find_exception_blocks (function_info *);
 static void add_branch_counts (coverage_t *, const arc_t *);
-static void add_line_counts (coverage_t *, function_t *);
+static void add_line_counts (coverage_t *, function_info *);
 static void executed_summary (unsigned, unsigned);
 static void function_summary (const coverage_t *, const char *);
 static const char *format_gcov (gcov_type, gcov_type, int);
@@ -1001,7 +1001,7 @@ output_intermediate_file (FILE *gcov_file, source_info 
*src)
 
   std::sort (src->functions.begin (), src->functions.end (),
 function_line_start_cmp ());
-  for (vector::iterator it = src->functions.begin ();
+  for (vector::iterator it = src->functions.begin ();
it != src->functions.end (); it++)
 {
   /* function:,, */
@@ -1012,10 +1012,10 @@ output_intermediate_file (FILE *gcov_file, source_info 
*src)
 
   for (unsigned line_num = 0; line_num <= src->lines.size (); line_num++)
 {
-  vector fns = src->get_functions_at_location (line_num);
+  vector fns = src->get_functions_at_location (line_num);
 
   /* Print first group functions that begin on the line.  */
-  for (vector::iterator it2 = fns.begin ();
+  for (vector::iterator it2 = fns.begin ();
   it2 != fns.end (); it2++)
{
  vector &lines = (*it2)->lines;
@@ -1106,10 +1106,10 @@ process_file (const char *file_name)
 
   read_count_file ();
 
-  hash_map fn_map;
+  hash_map fn_map;
 
   /* Identify group functions.  */
-  for (vector::iterator it = functions.begin ();
+  for (vector::iterator it = functions.begin ();
it != functions.end (); it++)
 if (!(*it)->artificial)
   {
@@ -1117,7 +1117,7 @@ process_file (const char *file_name)
needle.source_file_idx = (*it)->src;
needle.start_line = (*it)->start_line;
 
-   function_t **slot = fn_map.get (needle);
+   function_info **slot = fn_map.get (needle);
if (slot)
  {
gcc_assert ((*slot)->end_line == (*it)->end_line);
@@ -1132,10 +1132,10 @@ process_file (const char *file_name)
   functions.erase (remove_if (functions.begin (), functions.end (),
 

[Ada] pragma Warnings (Off) disabled if warning treated as error

2017-11-09 Thread Pierre-Marie de Rodat
The filtering of warnings set by pragma Warnings (Off) may be disabled if an
unfiltered warning is issued by the compiler and this warning is treated as
an error, e.g. by means of -gnatwe.

This behavior clearly goes against the Principle of Least Surprise and is
therefore changed.  The following package must be compiled with the same
single warning about the value not in range, with or without -gnatwe:

with Ada.Unchecked_Conversion;

package P is

  pragma Warnings (Off,"types for unchecked conversion have different sizes");

  function F is new Ada.Unchecked_Conversion (Character, Integer);

  A : Positive := -1;

end P;

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

2017-11-09  Eric Botcazou  

* gnat1drv.adb (Gnat1drv): Call Errout.Finalize (Last_Call => True)
before Errout.Output_Messages also in the case of compilation errors.

Index: gnat1drv.adb
===
--- gnat1drv.adb(revision 254563)
+++ gnat1drv.adb(working copy)
@@ -1180,6 +1180,7 @@
   if Compilation_Errors then
  Treepr.Tree_Dump;
  Post_Compilation_Validation_Checks;
+ Errout.Finalize (Last_Call => True);
  Errout.Output_Messages;
  Namet.Finalize;
 
@@ -1190,7 +1191,6 @@
 Tree_Gen;
  end if;
 
- Errout.Finalize (Last_Call => True);
  Exit_Program (E_Errors);
   end if;
 


Re: [PATCH] combine: Fix bug in giving up placing REG_DEAD notes (PR82683)

2017-11-09 Thread Segher Boessenkool
Hi!

On Wed, Nov 01, 2017 at 04:35:52PM +, Segher Boessenkool wrote:
> When we have a REG_DEAD note for a reg that is set in the new I2, we
> drop the note on the floor (we cannot find whether to place it on I2
> or on I3).  But the code I added to do this has a bug and does not
> always actually drop it.  This patch fixes it.
> 
> But that on its own is too pessimistic, it turns out, and we generate
> worse code.  One case where we do know where to place the note is if
> it came from I3 (it should go to I3 again).  Doing this fixes all of
> the regressions.
> 
> Tested on an aarch64 cross-compiler with the PR82683 test; tested on
> powerpc64-linux {-m32,-m64}.  Committing to trunk, will backport later.

I now backported this to 7 and 6.


Segher


> 2017-11-01  Segher Boessenkool  
> 
>   PR rtl-optimization/64682
>   PR rtl-optimization/69567
>   PR rtl-optimization/69737
>   PR rtl-optimization/82683
>   * combine.c (distribute_notes) : If the new I2 sets the same
>   register mentioned in the note, drop the note, unless it came from I3,
>   in which case it should go to I3 again.
> 
> ---
>  gcc/combine.c | 16 +++-
>  1 file changed, 11 insertions(+), 5 deletions(-)
> 
> diff --git a/gcc/combine.c b/gcc/combine.c
> index 4fba2c1..5782013 100644
> --- a/gcc/combine.c
> +++ b/gcc/combine.c
> @@ -14388,6 +14388,17 @@ distribute_notes (rtx notes, rtx_insn *from_insn, 
> rtx_insn *i3, rtx_insn *i2,
> && CALL_P (from_insn)
> && find_reg_fusage (from_insn, USE, XEXP (note, 0)))
>   place = from_insn;
> +   else if (i2 && reg_set_p (XEXP (note, 0), PATTERN (i2)))
> + {
> +   /* If the new I2 sets the same register that is marked
> +  dead in the note, we do not in general know where to
> +  put the note.  One important case we _can_ handle is
> +  when the note comes from I3.  */
> +   if (from_insn == i3)
> + place = i3;
> +   else
> + break;
> + }
> else if (reg_referenced_p (XEXP (note, 0), PATTERN (i3)))
>   place = i3;
> else if (i2 != 0 && next_nonnote_nondebug_insn (i2) == i3
> @@ -14401,11 +14412,6 @@ distribute_notes (rtx notes, rtx_insn *from_insn, 
> rtx_insn *i3, rtx_insn *i2,
>  || rtx_equal_p (XEXP (note, 0), elim_i0))
>   break;
> tem_insn = i3;
> -   /* If the new I2 sets the same register that is marked dead
> -  in the note, we do not know where to put the note.
> -  Give up.  */
> -   if (i2 != 0 && reg_set_p (XEXP (note, 0), PATTERN (i2)))
> - break;
>   }
>  
> if (place == 0)
> -- 
> 1.8.3.1


[PATCH] Initialize split_branch_probability (PR target/82863).

2017-11-09 Thread Martin Liška
Hi.

Following patch initializes global profile_probability.

Ready for trunk after tests?
Thanks,
Martin

gcc/ChangeLog:

2017-11-09  Martin Liska  

PR target/82863
* emit-rtl.c: Initialize split_branch_probability to
uninitialized.

gcc/testsuite/ChangeLog:

2017-11-09  Martin Liska  

* gcc.dg/pr82863.c: New test.
---
 gcc/emit-rtl.c |  3 ++-
 gcc/testsuite/gcc.dg/pr82863.c | 12 
 2 files changed, 14 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.dg/pr82863.c


diff --git a/gcc/emit-rtl.c b/gcc/emit-rtl.c
index cfe0fcec8e2..4ec3723ef9d 100644
--- a/gcc/emit-rtl.c
+++ b/gcc/emit-rtl.c
@@ -191,7 +191,8 @@ static rtx gen_const_vector (machine_mode, int);
 static void copy_rtx_if_shared_1 (rtx *orig);
 
 /* Probability of the conditional branch currently proceeded by try_split.  */
-profile_probability split_branch_probability;
+profile_probability split_branch_probability
+  = profile_probability::uninitialized ();
 
 /* Returns a hash code for X (which is a really a CONST_INT).  */
 
diff --git a/gcc/testsuite/gcc.dg/pr82863.c b/gcc/testsuite/gcc.dg/pr82863.c
new file mode 100644
index 000..b4028169a96
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr82863.c
@@ -0,0 +1,12 @@
+/* PR c/82167 */
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+
+typedef long long a;
+a b;
+float
+c ()
+{
+  float d = b > 0;
+  return d;
+}



Re: [PATCH] Add LVAL argument to c_fully_fold* and propagate it through (PR c/66618, PR c/69960)

2017-11-09 Thread Jakub Jelinek
On Wed, Nov 08, 2017 at 06:57:55PM +0100, Jakub Jelinek wrote:
> On Wed, Nov 08, 2017 at 06:51:34PM +0100, Marek Polacek wrote:
> > > Ok, so like this if it passes bootstrap/regtest?
> > > 
> > > Changes from the last patch:
> > > 1) false instead of lval for COMPOUND_EXPR and *COND_EXPR op1/op2
> > 
> > So...
> 
> Oops, I've hand-edited it in the patch and then regenerated the patch
> after doing there more changes.
> 
> Here is updated patch with that in again:

FYI, bootstrapped/regtested on x86_64-linux and i686-linux successfully.

Jakub


[PATCH] rs6000: Separate shrink-wrapping for the TOC register

2017-11-09 Thread Segher Boessenkool
This makes the TOC register save a component.  If -msave-toc-indirect
is not explicitly disabled, it enables it, and then moves the prologue
code generated for that to a better place.  So far this only matters
for indirect calls (for direct calls the save is done in the PLT stub).
The restore is always done directly after the bl insn (the compiler
generates a nop there, the linker replaces it with a load).

Tested on powerpc64-linux {-m32,-m64}; will also test on LE, and then
commit.


Segher


2017-11-09  Segher Boessenkool  

* config/rs6000/rs6000.c (machine_function): Add a bool,
"toc_is_wrapped_separately".
(rs6000_option_override_internal): Enable OPTION_MASK_SAVE_TOC_INDIRECT
if it wasn't explicitly set or unset, we are optimizing for speed, and
doing separate shrink-wrapping.
(rs6000_get_separate_components): Enable the TOC component if
saving the TOC register in the prologue.
(rs6000_components_for_bb): Handle the TOC component.
(rs6000_emit_prologue_components): Store the TOC register where needed.
(rs6000_set_handled_components): Mark TOC as handled, if handled.
(rs6000_emit_prologue): Don't save the TOC if that is already done.

---
 gcc/config/rs6000/rs6000.c | 33 -
 1 file changed, 32 insertions(+), 1 deletion(-)

diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c
index aacf3f1..2c80a2f 100644
--- a/gcc/config/rs6000/rs6000.c
+++ b/gcc/config/rs6000/rs6000.c
@@ -171,6 +171,7 @@ typedef struct GTY(()) machine_function
   bool gpr_is_wrapped_separately[32];
   bool fpr_is_wrapped_separately[32];
   bool lr_is_wrapped_separately;
+  bool toc_is_wrapped_separately;
 } machine_function;
 
 /* Support targetm.vectorize.builtin_mask_for_load.  */
@@ -4426,6 +4427,13 @@ rs6000_option_override_internal (bool global_init_p)
   && ((rs6000_isa_flags_explicit & OPTION_MASK_QUAD_MEMORY_ATOMIC) == 0))
 rs6000_isa_flags |= OPTION_MASK_QUAD_MEMORY_ATOMIC;
 
+  /* If we can shrink-wrap the TOC register save separately, then use
+ -msave-toc-indirect unless explicitly disabled.  */
+  if ((rs6000_isa_flags_explicit & OPTION_MASK_SAVE_TOC_INDIRECT) == 0
+  && flag_shrink_wrap_separate
+  && optimize_function_for_speed_p (cfun))
+rs6000_isa_flags |= OPTION_MASK_SAVE_TOC_INDIRECT;
+
   /* Enable power8 fusion if we are tuning for power8, even if we aren't
  generating power8 instructions.  */
   if (!(rs6000_isa_flags_explicit & OPTION_MASK_P8_FUSION))
@@ -26721,6 +26729,7 @@ rs6000_get_separate_components (void)
  && !(info->savres_strategy & REST_MULTIPLE));
 
   /* Component 0 is the save/restore of LR (done via GPR0).
+ Component 2 is the save of the TOC (GPR2).
  Components 13..31 are the save/restore of GPR13..GPR31.
  Components 46..63 are the save/restore of FPR14..FPR31.  */
 
@@ -26795,6 +26804,10 @@ rs6000_get_separate_components (void)
bitmap_set_bit (components, 0);
 }
 
+  /* Optimize saving the TOC.  This is component 2.  */
+  if (cfun->machine->save_toc_in_prologue)
+bitmap_set_bit (components, 2);
+
   return components;
 }
 
@@ -26833,6 +26846,12 @@ rs6000_components_for_bb (basic_block bb)
   || bitmap_bit_p (kill, LR_REGNO))
 bitmap_set_bit (components, 0);
 
+  /* The TOC save.  */
+  if (bitmap_bit_p (in, TOC_REGNUM)
+  || bitmap_bit_p (gen, TOC_REGNUM)
+  || bitmap_bit_p (kill, TOC_REGNUM))
+bitmap_set_bit (components, 2);
+
   return components;
 }
 
@@ -26887,6 +26906,14 @@ rs6000_emit_prologue_components (sbitmap components)
   add_reg_note (insn, REG_CFA_OFFSET, gen_rtx_SET (mem, lr));
 }
 
+  /* Prologue for TOC.  */
+  if (bitmap_bit_p (components, 2))
+{
+  rtx reg = gen_rtx_REG (reg_mode, TOC_REGNUM);
+  rtx sp_reg = gen_rtx_REG (Pmode, STACK_POINTER_REGNUM);
+  emit_insn (gen_frame_store (reg, sp_reg, RS6000_TOC_SAVE_SLOT));
+}
+
   /* Prologue for the GPRs.  */
   int offset = info->gp_save_offset;
   if (info->push_p)
@@ -27011,6 +27038,9 @@ rs6000_set_handled_components (sbitmap components)
 
   if (bitmap_bit_p (components, 0))
 cfun->machine->lr_is_wrapped_separately = true;
+
+  if (bitmap_bit_p (components, 2))
+cfun->machine->toc_is_wrapped_separately = true;
 }
 
 /* VRSAVE is a bit vector representing which AltiVec registers
@@ -27968,7 +27998,8 @@ rs6000_emit_prologue (void)
  unwinder to interpret it.  R2 changes, apart from the
  calls_eh_return case earlier in this function, are handled by
  linux-unwind.h frob_update_context.  */
-  if (rs6000_save_toc_in_prologue_p ())
+  if (rs6000_save_toc_in_prologue_p ()
+  && !cfun->machine->toc_is_wrapped_separately)
 {
   rtx reg = gen_rtx_REG (reg_mode, TOC_REGNUM);
   emit_insn (gen_frame_store (reg, sp_reg_rtx, RS6000_TOC_SAVE_SLOT));
-- 
1.8.3.1



Re: [001/nnn] poly_int: add poly-int.h

2017-11-09 Thread Richard Sandiford
Martin Sebor  writes:
> On 11/08/2017 11:28 AM, Richard Sandiford wrote:
>> Martin Sebor  writes:
>>> On 11/08/2017 09:51 AM, Richard Sandiford wrote:
 Martin Sebor  writes:
> On 11/08/2017 02:32 AM, Richard Sandiford wrote:
>> Martin Sebor  writes:
>>> I haven't done nearly a thorough review but the dtor followed by
>>> the placement new in the POLY_SET_COEFF() macro caught my eye so
>>> I thought I'd ask sooner rather than later.  Given the macro
>>> definition:
>>>
>>> +   The dummy comparison against a null C * is just a way of checking
>>> +   that C gives the right type.  */
>>> +#define POLY_SET_COEFF(C, RES, I, VALUE) \
>>> +  ((void) (&(RES).coeffs[0] == (C *) 0), \
>>> +   wi::int_traits::precision_type == wi::FLEXIBLE_PRECISION \
>>> +   ? (void) ((RES).coeffs[I] = VALUE) \
>>> +   : (void) ((RES).coeffs[I].~C (), new (&(RES).coeffs[I]) C (VALUE)))
>>>
>>> is the following use well-defined?
>>>
>>> +template
>>> +inline poly_int_pod&
>>> +poly_int_pod::operator <<= (unsigned int a)
>>> +{
>>> +  POLY_SET_COEFF (C, *this, 0, this->coeffs[0] << a);
>>>
>>> It looks to me as though the VALUE argument in the ctor invoked
>>> by the placement new expression is evaluated after the dtor has
>>> destroyed the very array element the VALUE argument expands to.
>>
>> Good catch!  It should simply have been doing <<= on each coefficient --
>> I must have got carried away when converting to POLY_SET_COEFF.
>>
>> I double-checked the other uses and think that's the only one.
>>
>>> Whether or not is, in fact, a problem, it seems to me that using
>>> a function template rather than a macro would be a clearer and
>>> safer way to do the same thing.  (Safer in that the macro also
>>> evaluates its arguments multiple times, which is often a source
>>> of subtle bugs.)
>>
>> That would slow down -O0 builds though, by introducing an extra
>> function call and set of temporaries even when the coefficients
>> are primitive integers.
>
> Would decorating the function template with attribute always_inline
> help?

 It would remove the call itself, but we'd still have the extra temporary
 objects that were the function argument and return value.
>>>
>>> Sorry, I do not want to get into another long discussion about
>>> trade-offs between safety and efficiency but I'm not sure I see
>>> what extra temporaries it would create.  It seems to me that
>>> an inline function template that took arguments of user-defined
>>> types by reference and others by value should be just as efficient
>>> as a macro.
>>>
>>>  From GCC's own manual:
>>>
>>>6.43 An Inline Function is As Fast As a Macro
>>>https://gcc.gnu.org/onlinedocs/gcc/Inline.html
>>
>> You can see the difference with something like:
>>
>>   inline
>>   void __attribute__((always_inline))
>>   f(int &dst, const int &src) { dst = src; }
>>
>>   int g1(const int &y) { int x; f(x, y); return x; }
>>   int g2(const int &y) { int x; x = y; return x; }
>
> Let me say at the outset that I struggle to comprehend that a few
> instructions is even a consideration when not optimizing, especially
> in light of the bug the macro caused that would have been prevented
> by using a function instead.  But...

Many people still build at -O0 though.  One of the things I was asked
for was the time it takes to build stage 2 with an -O0 stage 1
(where stage 1 would usually be built by the host compiler).

> ...I don't think your example above is representative of using
> the POLY_SET_COEFF macro.  The function template I'm suggesting
> might look something to this:
>
>template 
>inline void __attribute__ ((always_inline))
>poly_set_coeff (poly_int_pod *p, unsigned idx, C val)
>{
>  ((void) (&(*p).coeffs[0] == (C *) 0), 
> wi::int_traits::precision_type == wi::FLEXIBLE_PRECISION ? (void) 
> ((*p).coeffs[0] = val) : (void) ((*p).coeffs[0].~C (), new 
> (&(*p).coeffs[0]) C (val)));
>
>  if (N >= 2)
>for (unsigned int i = 1; i < N; i++)
>  ((void) (&(*p).coeffs[0] == (C *) 0), 
> wi::int_traits::precision_type == wi::FLEXIBLE_PRECISION ? (void) 
> ((*p).coeffs[i] = val) : (void) ((*p).coeffs[i].~C (), new 
> (&(*p).coeffs[i]) C (val)));
>}

That ignores the idx parameter and sets all coefficents to val.  Did you
mean somnething like:

   template 
   inline void __attribute__ ((always_inline))
   poly_set_coeff (poly_int_pod *p, unsigned idx, C2 val)
   {
 wi::int_traits::precision_type == wi::FLEXIBLE_PRECISION ? (void) 
((*p).coeffs[idx] = val) : (void) ((*p).coeffs[idx].~C1 (), new 
(&(*p).coeffs[idx]) C1 (val));
   }

?  If so...

> To compare apples to apples I suggest to instead compare the shift
> operator (or any other poly_int function that uses the macro) that
> doesn't suffer from the bug vs one that makes use of the function
> template.  I s

Re: Add support for adjusting the number of units in a mode

2017-11-09 Thread Richard Sandiford
Jeff Law  writes:
> On 10/25/2017 09:57 AM, Richard Sandiford wrote:
>> We already allow the target to change the size and alignment of a mode.
>> This patch does the same thing for the number of units, which is needed
>> to give command-line control of the SVE vector length.
>> 
>> Tested on aarch64-linux-gnu, x86_64-linux-gnu and powerpc64le-linux-gnu,
>> on top of the poly_int series.  I think I can approve this under the
>> gen* maintainership, so if there are no comments in the menatime,
>> I'll apply it if the prerequisites are approved.
>> 
>> Thanks,
>> Richard
>> 
>> 
>> 2017-10-25  Richard Sandiford  
>>  Alan Hayward  
>>  David Sherwood  
>> 
>> gcc/
>>  * machmode.h (mode_precision): Prefix with CONST_MODE_PRECISION.
>>  (mode_nunits): Likewise CONST_MODE_NUNITS.
>>  * machmode.def (ADJUST_NUNITS): Document.
>>  * genmodes.c (mode_data::need_nunits_adj): New field.
>>  (blank_mode): Update accordingly.
>>  (adj_nunits): New variable.
>>  (print_maybe_const_decl): Replace CATEGORY with a NEEDS_ADJ
>>  parameter.
>>  (emit_mode_size_inline): Set need_bytesize_adj for all modes
>>  listed in adj_nunits.
>>  (emit_mode_nunits_inline): Set need_nunits_adj for all modes
>>  listed in adj_nunits.  Don't emit case statements for such modes.
>>  (emit_insn_modes_h): Emit definitions of CONST_MODE_NUNITS
>>  and CONST_MODE_PRECISION.  Make CONST_MODE_SIZE expand to
>>  nothing if adj_nunits is nonnull.
>>  (emit_mode_precision, emit_mode_nunits): Use print_maybe_const_decl.
>>  (emit_mode_unit_size, emit_mode_base_align, emit_mode_ibit)
>>  (emit_mode_fbit): Update use of print_maybe_const_decl.
>>  (emit_move_size): Likewise.  Treat the array as non-const
>>  if adj_nunits.
>>  (emit_mode_adjustments): Handle adj_nunits.
> Were all the prereqs here approved?  Or does this depend on the poly_int
> stuff?

Yeah, it depends on the poly_int stuff.  Not in a major way though --
I could reorder it if necessary.

Thanks,
Richard


[Ada] Spurious warning on elaboration issue in dead code

2017-11-09 Thread Pierre-Marie de Rodat
This patch updates the new ABE mechanism to fully remove a recorded top level
elaboration scenario from its data structures when the scenario appears in dead
code. Previously the mechanism suppressed the generation of checks for such a
scenario, but still produced warnings.

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

gcc/ada/

2017-11-09  Hristian Kirtchev  

* sem_elab.adb: Update the documentation on adding a new elaboration
schenario. Add new hash table Recorded_Top_Level_Scenarios.
(Is_Check_Emitting_Scenario): Removed.
(Is_Recorded_Top_Level_Scenario): New routine.
(Kill_Elaboration_Scenario): Reimplemented.
(Record_Elaboration_Scenario): Mark the scenario as recorded.
(Set_Is_Recorded_Top_Level_Scenario): New routine.
(Update_Elaboration_Scenario): Reimplemented.
* sinfo.adb (Is_Recorded_Scenario): Removed.
(Set_Is_Recorded_Scenario): Removed.
* sinfo.ads: Remove attribute Is_Recorded_Scenario along with
occurrences in nodes.
(Is_Recorded_Scenario): Removed along with pragma Inline.
(Set_Is_Recorded_Scenario): Removed along with pragma Inline.

gcc/testsuite/

2017-11-09  Hristian Kirtchev  

* gnat.dg/elab3.adb, gnat.dg/elab3.ads, gnat.dg/elab3_pkg.adb,
gnat.dg/elab3_pkg.ads: New testcase.
Index: sinfo.adb
===
--- sinfo.adb   (revision 254563)
+++ sinfo.adb   (working copy)
@@ -2098,17 +2098,6 @@
   return Flag1 (N);
end Is_Read;
 
-   function Is_Recorded_Scenario
-  (N : Node_Id) return Boolean is
-   begin
-  pragma Assert (False
-or else NT (N).Nkind = N_Call_Marker
-or else NT (N).Nkind = N_Function_Instantiation
-or else NT (N).Nkind = N_Package_Instantiation
-or else NT (N).Nkind = N_Procedure_Instantiation);
-  return Flag6 (N);
-   end Is_Recorded_Scenario;
-
function Is_Source_Call
   (N : Node_Id) return Boolean is
begin
@@ -5537,17 +5526,6 @@
   Set_Flag1 (N, Val);
end Set_Is_Read;
 
-   procedure Set_Is_Recorded_Scenario
-  (N : Node_Id; Val : Boolean := True) is
-   begin
-  pragma Assert (False
-or else NT (N).Nkind = N_Call_Marker
-or else NT (N).Nkind = N_Function_Instantiation
-or else NT (N).Nkind = N_Package_Instantiation
-or else NT (N).Nkind = N_Procedure_Instantiation);
-  Set_Flag6 (N, Val);
-   end Set_Is_Recorded_Scenario;
-
procedure Set_Is_Source_Call
   (N : Node_Id; Val : Boolean := True) is
begin
Index: sinfo.ads
===
--- sinfo.ads   (revision 254563)
+++ sinfo.ads   (working copy)
@@ -1867,12 +1867,6 @@
--Present in variable reference markers. Set when the original variable
--reference constitues a read of the variable.
 
-   --  Is_Recorded_Scenario (Flag6-Sem)
-   --Present in call marker and instantiation nodes. Set when the scenario
-   --was saved by the ABE Recording phase. This flag aids the ABE machinery
-   --to keep its internal data up-to-date in case the node is transformed
-   --by Atree.Rewrite.
-
--  Is_Source_Call (Flag4-Sem)
--Present in call marker nodes. Set when the related call came from
--source.
@@ -7045,7 +7039,6 @@
   --  Is_Elaboration_Checks_OK_Node (Flag1-Sem)
   --  Is_SPARK_Mode_On_Node (Flag2-Sem)
   --  Is_Declaration_Level_Node (Flag5-Sem)
-  --  Is_Recorded_Scenario (Flag6-Sem)
   --  Is_Known_Guaranteed_ABE (Flag18-Sem)
 
   --  N_Procedure_Instantiation
@@ -7059,7 +7052,6 @@
   --  Is_Elaboration_Checks_OK_Node (Flag1-Sem)
   --  Is_SPARK_Mode_On_Node (Flag2-Sem)
   --  Is_Declaration_Level_Node (Flag5-Sem)
-  --  Is_Recorded_Scenario (Flag6-Sem)
   --  Must_Override (Flag14) set if overriding indicator present
   --  Must_Not_Override (Flag15) set if not_overriding indicator present
   --  Is_Known_Guaranteed_ABE (Flag18-Sem)
@@ -7075,7 +7067,6 @@
   --  Is_Elaboration_Checks_OK_Node (Flag1-Sem)
   --  Is_SPARK_Mode_On_Node (Flag2-Sem)
   --  Is_Declaration_Level_Node (Flag5-Sem)
-  --  Is_Recorded_Scenario (Flag6-Sem)
   --  Must_Override (Flag14) set if overriding indicator present
   --  Must_Not_Override (Flag15) set if not_overriding indicator present
   --  Is_Known_Guaranteed_ABE (Flag18-Sem)
@@ -7833,7 +7824,6 @@
   --  Is_Dispatching_Call (Flag3-Sem)
   --  Is_Source_Call (Flag4-Sem)
   --  Is_Declaration_Level_Node (Flag5-Sem)
-  --  Is_Recorded_Scenario (Flag6-Sem)
   --  Is_Known_Guaranteed_ABE (Flag18-Sem)
 
   
@@ -9777,9 +9767,6 @@
function Is_Read
  (N : Node_Id) return Boolean;-- Flag1
 
-   function Is_Recorded_Scenario
- (N : Node_Id) return Boolean;-- Flag6
-
function Is_Source_Call
  (N : Node_Id) return Boolean;-- Flag

[Ada] Adjust wording of error message to match the SPARK RM wording

2017-11-09 Thread Pierre-Marie de Rodat
Rule 7.2.6(2) of the SPARK RM uses the word "denote". Now the error message
that implements this rule also uses word "denote" and not "designate".

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

2017-11-09  Piotr Trojanek  

* sem_prag.adb (Analyze_Part_Of): Change "designate" to "denote" in
error message.

Index: sem_elab.adb
===
--- sem_elab.adb(revision 254566)
+++ sem_elab.adb(working copy)
@@ -68,7 +68,7 @@
--* Diagnose at compile-time or install run-time checks to prevent ABE
--  access to data and behaviour.
--
-   --  The high level idea is to accurately diagnose ABE issues within a
+   --  The high-level idea is to accurately diagnose ABE issues within a
--  single unit because the ABE mechanism can inspect the whole unit.
--  As soon as the elaboration graph extends to an external unit, the
--  diagnostics stop because the body of the unit may not be available.
@@ -146,8 +146,8 @@
--the library level if it appears in a package library unit, ignoring
--enclosng packages.
--
-   --  * Non-library level encapsulator - A construct that cannot be elaborated
-   --on its own and requires elaboration by a top level scenario.
+   --  * Non-library-level encapsulator - A construct that cannot be elaborated
+   --on its own and requires elaboration by a top-level scenario.
--
--  * Scenario - A construct or context which may be elaborated or executed
--by elaboration code. The scenarios recognized by the ABE mechanism are
@@ -181,7 +181,7 @@
--
--  - For task activation, the target is the task body
--
-   --  * Top level scenario - A scenario which appears in a non-generic main
+   --  * Top-level scenario - A scenario which appears in a non-generic main
--unit. Depending on the elaboration model is in effect, the following
--addotional restrictions apply:
--
@@ -198,7 +198,7 @@
--  The Recording phase coincides with the analysis/resolution phase of the
--  compiler. It has the following objectives:
--
-   --* Record all top level scenarios for examination by the Processing
+   --* Record all top-level scenarios for examination by the Processing
--  phase.
--
--  Saving only a certain number of nodes improves the performance of
@@ -231,9 +231,9 @@
--  and/or inlining of bodies, but before the removal of Ghost code. It has
--  the following objectives:
--
-   --* Examine all top level scenarios saved during the Recording phase
+   --* Examine all top-level scenarios saved during the Recording phase
--
-   --  The top level scenarios act as roots for depth-first traversal of
+   --  The top-level scenarios act as roots for depth-first traversal of
--  the call/instantiation/task activation graph. The traversal stops
--  when an outgoing edge leaves the main unit.
--
@@ -420,8 +420,7 @@
--  The following steps describe how to add a new elaboration scenario and
--  preserve the existing architecture.
--
-   --1) If necessary, update predicates Is_Check_Emitting_Scenario and
-   --   Is_Scenario.
+   --1) If necessary, update predicate Is_Scenario
--
--2) Add predicate Is_Suitable_xxx. Include a call to it in predicate
--   Is_Suitable_Scenario.
@@ -712,8 +711,28 @@
   Hash   => Elaboration_Context_Hash,
   Equal  => "=");
 
+   --  The following table stores a status flag for each top-level scenario
+   --  recorded in table Top_Level_Scenarios.
+
+   Recorded_Top_Level_Scenarios_Max : constant := 503;
+
+   type Recorded_Top_Level_Scenarios_Index is
+ range 0 .. Recorded_Top_Level_Scenarios_Max - 1;
+
+   function Recorded_Top_Level_Scenarios_Hash
+ (Key : Node_Id) return Recorded_Top_Level_Scenarios_Index;
+   --  Obtain the hash value of entity Key
+
+   package Recorded_Top_Level_Scenarios is new Simple_HTable
+ (Header_Num => Recorded_Top_Level_Scenarios_Index,
+  Element=> Boolean,
+  No_Element => False,
+  Key=> Node_Id,
+  Hash   => Recorded_Top_Level_Scenarios_Hash,
+  Equal  => "=");
+
--  The following table stores all active scenarios in a recursive traversal
-   --  starting from a top level scenario. This table must be maintained in a
+   --  starting from a top-level scenario. This table must be maintained in a
--  FIFO fashion.
 
package Scenario_Stack is new Table.Table
@@ -724,7 +743,7 @@
   Table_Increment  => 100,
   Table_Name   => "Scenario_Stack");
 
-   --  The following table stores all top level scenario saved during the
+   --  The following table stores all top-level scenario saved during the
--  Recording phase. The contents of this table act as traversal roots
--  later in the Processing phase. This table must be

[Ada] Warn on missing finalization of anonymous access-to-controlled

2017-11-09 Thread Pierre-Marie de Rodat
This patch adds a warning to alert the user to the fact that GNAT currently
mishandles finalization of anonymous access-to-controlled objects and that
they may not be finalized or deallocated within their respective scope.


-- Source --


--  main.adb

with Ada.Text_IO;  use Ada.Text_IO;
with Sessions;

procedure Main is
   procedure Nested is
  package S is new Sessions;
  C : access S.C_Type := new S.C_Type;

  --  Workaround:
  --type Ptr is access all S.C_Type;
  --C : Ptr := new S.C_Type;
   begin
  null;
   end Nested;
begin
   Nested;
   Put_Line ("After nested, before global finalize");
end Main;

--  sessions.ads

with Ada.Finalization;

generic
package Sessions is
   type C_Type is new Ada.Finalization.Controlled with null record;
   procedure Finalize (Self : in out C_Type);
end Sessions;

--  sessions.adb

with Ada.Text_IO; use Ada.Text_IO;

package body Sessions is
   procedure Finalize (Self : in out C_Type) is
   begin
  Put_Line ("Finalize called");
   end Finalize;
end Sessions;


-- Compilation and output --


& gnatmake -gnatws -q main.adb
& main
main.adb:7:30: warning: anonymous access-to-controlled object will be
  finalized when its enclosing unit goes out of scope
After nested, before global finalize

raised PROGRAM_ERROR : main.adb:4 finalize/adjust raised exception

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

gcc/ada/

2017-11-09  Justin Squirek  

* sem_res.adb (Resolve_Allocator): Add warning messages corresponding
to the allocation of an anonymous access-to-controlled object.

gcc/testsuite/

2017-11-09  Pierre-Marie de Rodat  

* gnat.dg/controlled2.adb, gnat.dg/controlled4.adb, gnat.dg/finalized.adb:
Disable the new warning from GNAT.
Index: sem_res.adb
===
--- sem_res.adb (revision 254566)
+++ sem_res.adb (working copy)
@@ -5161,11 +5161,11 @@
  (Parent (Associated_Node_For_Itype (Typ
   then
  Error_Msg_N
-   ("info: coextension will not be finalized when its "
+   ("??coextension will not be finalized when its "
 & "associated owner is finalized", N);
   else
  Error_Msg_N
-   ("info: coextension will not be finalized when its "
+   ("??coextension will not be finalized when its "
 & "associated owner is deallocated", N);
   end if;
else
@@ -5174,12 +5174,12 @@
   (Parent (Associated_Node_For_Itype (Typ
   then
  Error_Msg_N
-   ("info: coextension will not be deallocated when its "
-& "associated owner is finalized", N);
+   ("??coextension will not be deallocated when "
+& "its associated owner is finalized", N);
   else
  Error_Msg_N
-   ("info: coextension will not be deallocated when its "
-& "associated owner is deallocated", N);
+   ("??coextension will not be deallocated when "
+& "its associated owner is deallocated", N);
   end if;
end if;
 end if;
@@ -5189,6 +5189,19 @@
  else
 Set_Is_Dynamic_Coextension (N, False);
 Set_Is_Static_Coextension  (N, False);
+
+--  ??? It seems we also do not properly finalize anonymous
+--  access-to-controlled objects within their declared scope and
+--  instead finalize them with their associated unit. Warn the
+--  user about it here.
+
+if Ekind (Typ) = E_Anonymous_Access_Type
+   and then Is_Controlled_Active (Desig_T)
+then
+   Error_Msg_N ("??anonymous access-to-controlled object will "
+& "be finalized when its enclosing unit goes out "
+& "of scope", N);
+end if;
  end if;
   end if;
 
Index: ../testsuite/gnat.dg/controlled2.adb
===
--- ../testsuite/gnat.dg/controlled2.adb(revision 254563)
+++ ../testsuite/gnat.dg/controlled2.adb(working copy)
@@ -1,5 +1,8 @@
 --  { dg-do compile }
 
+pragma Warnings
+  (Off, "anonymous access-to-controlled object will be finalized when its 
enclosing unit goes out of scope");
+
 with controlled1; use controlled1;
 package body controlled2 is
procedure Test_Suite is
Index: ../testsuite/gnat.dg/controlled4.adb
===
--- ../testsuite/gnat.dg/controlled4.adb(revision 2

Re: [PATCH] Initialize split_branch_probability (PR target/82863).

2017-11-09 Thread Jan Hubicka
> Hi.
> 
> Following patch initializes global profile_probability.
> 
> Ready for trunk after tests?
> Thanks,
> Martin
> 
> gcc/ChangeLog:
> 
> 2017-11-09  Martin Liska  
> 
>   PR target/82863
>   * emit-rtl.c: Initialize split_branch_probability to
>   uninitialized.
> 
> gcc/testsuite/ChangeLog:
> 
> 2017-11-09  Martin Liska  
> 
>   * gcc.dg/pr82863.c: New test.

Please move initialization to init_emit so we do not introduce new static 
constructor
for no good reason. OK with this change.

Honza


[Ada] Crash on SPARK_Mode with illegal mode

2017-11-09 Thread Pierre-Marie de Rodat
This patch modifies the processing of aspect or pragma SPARK_Mode to avoid a
crash when the annotation appears with an illegal mode.


-- Source --


--  pack.ads

package Pack is
   package Nested_1 with SPARK_Mode => False is
   end Nested_1;

   Obj : constant String := "Illegal";

   package Nested_2 with SPARK_Mode => Obj is
   end Nested_2;

   package Nested_3 is
  pragma SPARK_Mode (True);
   end Nested_3;

   package Nested_4 is
  pragma SPARK_Mode (1.2);
   end Nested_4;
end Pack;

-
-- Compilation --
-

$ gcc -c pack.ads
$ gcc -c pack.ads -gnatd.F
pack.ads:2:40: entity for aspect "Spark_Mode" must be "On" or "Off"
pack.ads:7:40: entity for aspect "Spark_Mode" must be "On" or "Off"
pack.ads:11:26: argument for pragma "Spark_Mode" must be "On" or "Off"
pack.ads:15:26: argument for pragma "Spark_Mode" must be identifier
pack.ads:2:40: entity for aspect "Spark_Mode" must be "On" or "Off"
pack.ads:7:40: entity for aspect "Spark_Mode" must be "On" or "Off"
pack.ads:11:26: argument for pragma "Spark_Mode" must be "On" or "Off"
pack.ads:15:26: argument for pragma "Spark_Mode" must be identifier

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

2017-11-09  Piotr Trojanek  

* sem_prag.adb (Analyze_Part_Of): Reword error message.
(Get_SPARK_Mode_Type): Do not raise Program_Error in case pragma
SPARK_Mode appears with an illegal mode, treat this as a non-existent
mode.

Index: sem_prag.adb
===
--- sem_prag.adb(revision 254568)
+++ sem_prag.adb(working copy)
@@ -3287,8 +3287,8 @@
 
if not Is_Child_Or_Sibling (Pack_Id, Scope (Encap_Id)) then
   SPARK_Msg_NE
-("indicator Part_Of must denote abstract state or public "
- & "descendant of & (SPARK RM 7.2.6(3))",
+("indicator Part_Of must denote abstract state of & "
+ & "or of its public descendant (SPARK RM 7.2.6(3))",
  Indic, Parent_Unit);
   return;
 
@@ -3301,8 +3301,8 @@
 
else
   SPARK_Msg_NE
-("indicator Part_Of must denote abstract state or public "
- & "descendant of & (SPARK RM 7.2.6(3))",
+("indicator Part_Of must denote abstract state of & "
+ & "or of its public descendant (SPARK RM 7.2.6(3))",
  Indic, Parent_Unit);
   return;
end if;
@@ -29364,10 +29364,11 @@
   elsif N = Name_Off then
  return Off;
 
-  --  Any other argument is illegal
+  --  Any other argument is illegal. Assume that no SPARK mode applies to
+  --  avoid potential cascaded errors.
 
   else
- raise Program_Error;
+ return None;
   end if;
end Get_SPARK_Mode_Type;
 


[Ada] Misleading error or crash on illegal call with limited view

2017-11-09 Thread Pierre-Marie de Rodat
This patch provides a proper diagnostic on an illegal call to a function
whose return type is a limited view, when the call appears in a unit whose
context does not include the non-limited view of the type. Prior to this
patch the compiler reports a misleading error about a missing discriminant,
or aborts if compiler assertions are enabled.

Compiling check.adb must yield:

   check.adb:7:26: cannot call function that returns limited view of
  type "Object" defined at set.ads:7
   check.adb:7:26: there must be a regular with_clause for package "Set"
  in the current unit, or in some unit in its context

with View;
procedure Check is
   procedure Test  is
  Thing : View.Object;
   begin

  for Source of Thing.Sources loop
 null;
  end loop;
   end Test;

begin
   Null;
end Check;
ilimited with Set;

package view is

   type Object is tagged private;

   subtype Project_View is Object;

   Undefined : constant Object;

   function Sources (Self : Object) return Set.Object
 with Pre => Self /= Undefined;

private

   type Object is tagged record
  Id : Integer := 0;
   end record;
   Undefined : constant Object := (Id => -1);
end View;
---
with Ada.Iterator_Interfaces;
with Ada.Containers; 
private with Ada.Containers.Ordered_Sets;
package Set is

   type Object is tagged private
 with Constant_Indexing => Constant_Reference,
  Default_Iterator  => Iterate,
  Iterator_Element  => Integer;

   subtype Source_Set is Object;
   type Cursor is private;

   No_Element : constant Cursor;

   function Element (Position : Cursor) return Integer
 with Post =>
   (if Has_Element (Position)
 then Element'Result /= 0 else True);

   function Has_Element (Position : Cursor) return Boolean;

   package Source_Iterator is
 new Ada.Iterator_Interfaces (Cursor, Has_Element);

   type Constant_Reference_Type
 (Source : not null access constant Integer) is private
 with Implicit_Dereference => Source;

   function Constant_Reference
 (Self : aliased Object;
  Position : Cursor) return Constant_Reference_Type;

   type Source_Filter is mod 2 ** 8;

   S_All: constant Source_Filter;

   function Iterate
 (Self   : Object;
  Filter : Source_Filter := S_All)
  return Source_Iterator.Forward_Iterator'Class;

private

   package Set is new Ada.Containers.Ordered_Sets (Integer);

   type Object is tagged record
  S : Set.Set;
   end record;

   type Cursor is record
  Current : Set.Cursor;
   end record;

   No_Element : constant Cursor := (Current => Set.No_Element);

   type Constant_Reference_Type
 (Source : not null access constant Integer) is null record;

   S_All: constant Source_Filter := 111;
end Set;

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

2017-11-09  Ed Schonberg  

* sem_ch4.adb (Analyze_Call): Reject a call to a function that returns
a limited view of a type T declared in unit U1, when the function is
declared in another unit U2 and the call appears in a procedure within
another unit.

Index: sem_ch4.adb
===
--- sem_ch4.adb (revision 254563)
+++ sem_ch4.adb (working copy)
@@ -1520,6 +1520,27 @@
   and then Present (Non_Limited_View (Etype (N)))
 then
Set_Etype (N, Non_Limited_View (Etype (N)));
+
+--  If there is no completion for the type, this may be because
+--  there is only a limited view of it and there is nothing in
+--  the context of the current unit that has required a regular
+--  compilation of the unit containing the type. We recognize
+--  this unusual case by the fact that that unit is not analyzed.
+--  Note that the call being analyzed is in a different unit from
+--  the function declaration, and nothing indicates that the type
+--  is a limited view.
+
+elsif Ekind (Scope (Etype (N))) = E_Package
+  and then Present (Limited_View (Scope (Etype (N
+  and then not Analyzed (Unit_Declaration_Node (Scope (Etype (N
+then
+   Error_Msg_NE ("cannot call function that returns "
+ & "limited view of}", N, Etype (N));
+   Error_Msg_NE
+ ("\there must be a regular with_clause for package& "
+   & "in the current unit, or in some unit in its context",
+N, Scope (Etype (N)));
+   Set_Etype (N, Any_Type);
 end if;
  end if;
   end if;
@@ -8681,7 +8702,8 @@
  else
 --  The type of the subprogram may be a limited view obtained
 --  transitively from another unit. If full view is available,
---  use it to analyze call.
+--  use it to analyze call. If there is no nonlimited view, then
+--  this is dia

[Ada] use_clauses sometimes ignored in generic template

2017-11-09 Thread Pierre-Marie de Rodat
This patch prevents spurious visibility errors due to use_clauses being ignored
when analyzing entities within a generic instance's template.


-- Source --


--  gnatcoll-json-support-test-test_vectors-integer_vectors-json.ads

with GNATCOLL.JSON.Support.Ada.Containers.Vectors;
with GNATCOLL.JSON.Support.Test.Test_Vectors.Integer_Vectors;
package GNATCOLL.JSON.Support.Test.Test_Vectors.Integer_Vectors.JSON is new
  GNATCOLL.JSON.Support.Ada.Containers.Vectors
(V  => GNATCOLL.JSON.Support.Test.Test_Vectors.Integer_Vectors,
 Create => GNATCOLL.JSON.Create,
 Get=> GNATCOLL.JSON.Get);

--  gnatcoll-json-support-ada-containers-vectors.ads

with Ada.Containers.Vectors;
generic
   with package V is new Standard.Ada.Containers.Vectors (<>);

   use V; --  Ignored in instance leaving Element_Type invisible

   with function Create (Val : Element_Type) return JSON_Value is <>;
   with function Get (Val : JSON_Value) return Element_Type is <>;
package GNATCOLL.JSON.Support.Ada.Containers.Vectors is
end;

--  ... Additional files required


-- Compilation and output --


& gnatmake -q gnatcoll-json-support-test-test_vectors-integer_vectors-json.ads
cannot generate code for file gnatcoll-atomic.ads (package spec)
gnatmake: "gnatcoll-atomic.ads" compilation error

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

2017-11-09  Justin Squirek  

* sem_ch8.adb (Analyze_Use_Package): Force installation of use_clauses
when processing generic instances.

Index: sem_ch8.adb
===
--- sem_ch8.adb (revision 254563)
+++ sem_ch8.adb (working copy)
@@ -3821,8 +3821,11 @@
 Check_In_Previous_With_Clause (N, Name (N));
  end if;
 
- Use_One_Package (N, Name (N));
+ --  Force the use_clause when we are in a generic instance because the
+ --  scope of the package has changed and we must ensure visibility.
 
+ Use_One_Package (N, Name (N), Force => In_Instance);
+
  --  Capture the first Ghost package and the first living package
 
  if Is_Entity_Name (Name (N)) then


[Ada] Cleanup of Namet

2017-11-09 Thread Pierre-Marie de Rodat
CodePeer detected some questionable code in the Namet package.
This patch cleans it up. No actual bugs, but some dead code
was detected. The main impact of this patch is to clarify
which subprogram parameters are allowed to be the special
"null"-ish Name_Id values (almost none). No change in
compiler behavior; no test available.

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

2017-11-09  Bob Duff  

* namet.ads, namet.adb (Valid_Name_Id): New subtype that excludes
Error_Name and No_Name.  Use this (versus Name_Id) to indicate which
objects can have those special values. Valid_Name_Id could usefully be
used all over the compiler front end, but that's too much trouble for
now. If we did that, we might want to rename:
Name_Id --> Optional_Name_Id, Valid_Name_Id --> Name_Id.
For parameters of type Valid_Name_Id, remove some redundant tests,
including the ones found by CodePeer.  Use Is_Valid_Name instead of
membership test when appropriate.
(Error_Name_Or_No_Name): Delete this; it's no longer needed.
* sem_ch2.adb (Analyze_Identifier): Use "not Is_Valid_Name" instead of
"in Error_Name_Or_No_Name".
(Check_Parameterless_Call): Use "not Is_Valid_Name" instead of "in
Error_Name_Or_No_Name".

Index: sem_res.adb
===
--- sem_res.adb (revision 254568)
+++ sem_res.adb (working copy)
@@ -1030,7 +1030,7 @@
  if Nkind (N) in N_Has_Etype and then Etype (N) = Any_Type then
 return;
  elsif Nkind (N) in N_Has_Chars
-   and then Chars (N) in Error_Name_Or_No_Name
+   and then not Is_Valid_Name (Chars (N))
  then
 return;
  end if;
Index: namet.adb
===
--- namet.adb   (revision 254563)
+++ namet.adb   (working copy)
@@ -159,8 +159,8 @@
   Append (Buf, Buf2.Chars (1 .. Buf2.Length));
end Append;
 
-   procedure Append (Buf : in out Bounded_String; Id : Name_Id) is
-  pragma Assert (Id in Name_Entries.First .. Name_Entries.Last);
+   procedure Append (Buf : in out Bounded_String; Id : Valid_Name_Id) is
+  pragma Assert (Is_Valid_Name (Id));
 
   Index : constant Int   := Name_Entries.Table (Id).Name_Chars_Index;
   Len   : constant Short := Name_Entries.Table (Id).Name_Len;
@@ -174,7 +174,9 @@
-- Append_Decoded --

 
-   procedure Append_Decoded (Buf : in out Bounded_String; Id : Name_Id) is
+   procedure Append_Decoded
+ (Buf : in out Bounded_String; Id : Valid_Name_Id)
+   is
   C: Character;
   P: Natural;
   Temp : Bounded_String;
@@ -449,7 +451,7 @@
 
procedure Append_Decoded_With_Brackets
  (Buf : in out Bounded_String;
-  Id  : Name_Id)
+  Id  : Valid_Name_Id)
is
   P : Natural;
 
@@ -596,7 +598,9 @@
-- Append_Unqualified --

 
-   procedure Append_Unqualified (Buf : in out Bounded_String; Id : Name_Id) is
+   procedure Append_Unqualified
+ (Buf : in out Bounded_String; Id : Valid_Name_Id)
+   is
   Temp : Bounded_String;
begin
   Append (Temp, Id);
@@ -610,7 +614,7 @@
 
procedure Append_Unqualified_Decoded
  (Buf : in out Bounded_String;
-  Id  : Name_Id)
+  Id  : Valid_Name_Id)
is
   Temp : Bounded_String;
begin
@@ -773,7 +777,7 @@
-- Get_Decoded_Name_String --
-
 
-   procedure Get_Decoded_Name_String (Id : Name_Id) is
+   procedure Get_Decoded_Name_String (Id : Valid_Name_Id) is
begin
   Global_Name_Buffer.Length := 0;
   Append_Decoded (Global_Name_Buffer, Id);
@@ -783,7 +787,7 @@
-- Get_Decoded_Name_String_With_Brackets --
---
 
-   procedure Get_Decoded_Name_String_With_Brackets (Id : Name_Id) is
+   procedure Get_Decoded_Name_String_With_Brackets (Id : Valid_Name_Id) is
begin
   Global_Name_Buffer.Length := 0;
   Append_Decoded_With_Brackets (Global_Name_Buffer, Id);
@@ -794,7 +798,7 @@

 
procedure Get_Last_Two_Chars
- (N  : Name_Id;
+ (N  : Valid_Name_Id;
   C1 : out Character;
   C2 : out Character)
is
@@ -815,13 +819,13 @@
-- Get_Name_String --
-
 
-   procedure Get_Name_String (Id : Name_Id) is
+   procedure Get_Name_String (Id : Valid_Name_Id) is
begin
   Global_Name_Buffer.Length := 0;
   Append (Global_Name_Buffer, Id);
end Get_Name_String;
 
-   function Get_Name_String (Id : Name_Id) return String is
+   function Get_Name_String (Id : Valid_Name_Id) return String is
   Buf : Bounded_String (Max_Length => Natural (Length_Of_Name (Id)));
begin
   Append (Buf, Id);
@@ -832,7 +836,7 @@
-- Get_Name_String_And_Append --

 
-   procedure Get_Name_String_And_Append (Id : Name_Id

[Ada] Fix code quality issues reported by CodePeer

2017-11-09 Thread Pierre-Marie de Rodat
Running CodePeer on GNAT frontend codebase revealed a number of code
quality issues. For the most part, these are not bugs, but could lead to
bugs during maintenance. A few could lead to reads of uninitialized
variables.

This patch fixes these issues in various ways:

- add initialization in cases where this decreases the risk to read an
  uninitialized variable one day (and a few where an uninitialized seem
  actually doable)
- type more tightly variables
- mark procedures which do not return normally as No_Return
- mark IN OUT parameters which are not modified as Unmodified
- rescope more tightly declarations and statements to make it simpler
  for CodePeer to analyze

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

2017-11-09  Yannick Moy  

* binde.adb (Diagnose_Elaboration_Problem): Mark procedure No_Return.
* checks.adb (Apply_Scalar_Range_Check): Rescope variable OK closer to
use.  Default initialize Hi, Lo.
(Selected_Range_Checks): Retype Num_Checks more precisely.
(Determine_Range, Determine_Range_R): Default initialize Hi_Right,
Lo_Right.
* contracts.adb (Process_Contract_Cases): Mark parameter Stmts as
Unmodified.
(Process_Postconditions): Mark parameter Stmts as Unmodified.
* exp_attr.adb (Expand_Loop_Entry_Attribute): Default initialize Blk.
* exp_ch4.adb (Expand_N_Allocator): Default initialize Typ.
(Expand_Concatenate): Default initialize High_Bound.
(Optimize_Length_Comparison): Default initialize Ent, Index.
* exp_ch5.adb (Expand_Predicated_Loop): Default initialize L_Hi and
L_Lo.
* exp_ch6.adb (Expand_N_Extended_Return_Statement): Default initialize
Return_Stmt.
* exp_ch9.adb (Expand_Entry_Barrier): Default initialize Func_Body and
remove pragma Warnings(Off).
* exp_imgv.adb (Expand_Image_Attribute): Default initialize Tent.
* exp_util.adb (Find_Interface_Tag): Default initialize AI_Tag.
* freeze.adb (Check_Component_Storage_Order): Default initialize
Comp_Byte_Aligned rather than silencing messages with pragma
Warnings(Off), which does not work for CodePeer initialization
messages, and given that here the possible read of an unitialized value
depends on a proper use of parameters by the caller.
* inline.adb (Expand_Inlined_Call): Default initialize Lab_Decl, Targ.
* sem_ch12.adb (Build_Operator_Wrapper): Default initialize Expr.
* sem_ch3.adb (Build_Derived_Array_Type): Default initialize
Implicit_Base.
* sem_ch4.adb (List_Operand_Interps): Default initialize Nam and remove
pragma Warnings(Off).
(Analyze_Case_Expression): Rescope checking block within branch where
Others_Present is set by the call to Check_Choices.
* sem_ch5.adb (Analyze_Assignment): Default initialize
Save_Full_Analysis.
* sem_ch6.adb (Analyze_Function_Return): Default initialize Obj_Decl,
and restructure code to defend against previous errors, so that, in
that case, control does not flow to the elsif condition which read an
uninitialized Obj_Decl.
* sem_ch9.adb (Analyze_Requeue): Default initialize Synch_Type.
(Check_Interfaces): Default initialize Full_T_Ifaces and Priv_T_Ifaces,
which seem to be left uninitialized and possibly read in some cases.
* sem_dim.adb (Analyze_Aspect_Dimension_System): Retype Position more
precisely.  This requires to exchange the test for exiting in case of
too many positions and the increment to Position, inside the loop.
* sem_eval.adb (Eval_Concatenation): Default initialize Folded_Val,
which cannot be read uninitialized, but the reasons for that are quite
subtle.
* sem_intr.adb (Check_Intrinsic_Call): Default initialize Rtyp.
* sem_prag.adb (Collect_Subprogram_Inputs_Outputs): Default initialize
Spec_Id.
* sem_res.adb (Make_Call_Into_Operator): Default initialize Opnd_Type,
and test for presence of non-null Opnd_Type before testing its scope,
in a test which would read its value uninitialized, and is very rarely
exercized (it depends on the presence of an extension of System).
* sem_spark.ads: Update comment to fix name of main analysis procedure.
* sem_warn.adb (Warn_On_Known_Condition): Default initialize
Test_Result.
* set_targ.adb (FailN): Mark procedure with No_Return.
* stylesw.adb (Save_Style_Check_Options): Delete useless code to
initialize all array Options to white space, as there is already code
doing the same for the remaining positions in Options at the end of the
procedure.

Index: exp_ch5.adb
===
--- exp_ch5.adb (revision 254563)
+++ exp_ch5.adb (working copy)
@@ -4769,8 +4769,8 @@
 
 --  If

[Ada] Fix false positive of -gnatw.x on trivial instantiation

2017-11-09 Thread Pierre-Marie de Rodat
As for calls, issuing the -gnatw.x warning on every generic instantiation
results in way too many false positives and thus needs to be stopped.

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

2017-11-09  Eric Botcazou  

* exp_ch11.adb (Possible_Local_Raise): Do not issue the warning for
generic instantiations either.

Index: exp_ch11.adb
===
--- exp_ch11.adb(revision 254563)
+++ exp_ch11.adb(working copy)
@@ -1855,11 +1855,13 @@
  --  and the warning is enabled, generate the appropriate warnings.
 
  --  ??? Do not do it for the Call_Marker nodes inserted by the ABE
- --  mechanism because this generates too many false positives.
+ --  mechanism because this generates too many false positives, or
+ --  for generic instantiations for the same reason.
 
  elsif Warn_On_Non_Local_Exception
and then Restriction_Active (No_Exception_Propagation)
and then Nkind (N) /= N_Call_Marker
+   and then Nkind (N) not in N_Generic_Instantiation
  then
 Warn_No_Exception_Propagation_Active (N);
 


[PATCH,doc] Fix latency in pipeline description example

2017-11-09 Thread Luis Machado
While reading through section 16.19.9 of the internals manual, i ran into this
example that looked slightly odd:

(define_insn_reservation "div" 8 (eq_attr "type" "div")
 "i1_pipeline, div*7, div + (port0 | port1)")

Am i missing something or is this example incorrect and this should either
have a latency of 9 (patch attached) or a different resource utilization
description, say, containing "div*6" instead?

Regards,
Luis

2017-11-09  Luis Machado  
 
PR tree-optimization/82669
diff --git a/gcc/doc/md.texi b/gcc/doc/md.texi
index c4c1138..9806b65 100644
--- a/gcc/doc/md.texi
+++ b/gcc/doc/md.texi
@@ -9617,7 +9617,7 @@ their result is ready in two cycles.  The simple integer 
insns are
 issued into the first pipeline unless it is reserved, otherwise they
 are issued into the second pipeline.  Integer division and
 multiplication insns can be executed only in the second integer
-pipeline and their results are ready correspondingly in 8 and 4
+pipeline and their results are ready correspondingly in 9 and 4
 cycles.  The integer division is not pipelined, i.e.@: the subsequent
 integer division insn can not be issued until the current division
 insn finished.  Floating point insns are fully pipelined and their
@@ -9634,7 +9634,7 @@ incurred.  To describe all of this we could specify
 (define_insn_reservation "mult" 4 (eq_attr "type" "mult")
  "i1_pipeline, nothing*2, (port0 | port1)")
 
-(define_insn_reservation "div" 8 (eq_attr "type" "div")
+(define_insn_reservation "div" 9 (eq_attr "type" "div")
  "i1_pipeline, div*7, div + (port0 | port1)")
 
 (define_insn_reservation "float" 3 (eq_attr "type" "float")
-- 
2.7.4



[Ada] Spurious error on read of out parameter in Ada_83 mode

2017-11-09 Thread Pierre-Marie de Rodat
This patch fixes a regression in the handling of out parameters that appear
as the prefix of an attribute, when compiling in Ada_83 mode. Such implicit
read operations are legal in Ada_83 when the parameter is of an array type
and the attribute yields bound information.

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

gcc/ada/

2017-11-09  Ed Schonberg  

* exp_ch3.adb, gnat1drv.adb, namet.adb, namet.ads, sem_aggr.adb,
sem_ch2.adb, sem_ch4.adb: Minor reformatting.
* sem_res.adb (Resolve_Entity_Name): Suppress spurious error on read of
out parameter when in Ada_83 mode, the oarameter is of a composite
type, and it appears as the prefix of an attribute.

gcc/testsuite/

2017-11-09  Ed Schonberg  

* gnat.dg/out_param.adb: New testcase.
Index: exp_ch3.adb
===
--- exp_ch3.adb (revision 254566)
+++ exp_ch3.adb (working copy)
@@ -8717,10 +8717,11 @@
 --  Initialize secondary tags
 
 else
-   Initialize_Tag (Full_Typ,
- Iface => Node (Iface_Elmt),
- Tag_Comp  => Tag_Comp,
- Iface_Tag => Node (Iface_Tag_Elmt));
+   Initialize_Tag
+ (Typ   => Full_Typ,
+  Iface => Node (Iface_Elmt),
+  Tag_Comp  => Tag_Comp,
+  Iface_Tag => Node (Iface_Tag_Elmt));
 end if;
 
  --  Otherwise generate code to initialize the tag
@@ -8729,10 +8730,11 @@
 if (In_Variable_Pos and then Variable_Comps)
   or else (not In_Variable_Pos and then Fixed_Comps)
 then
-   Initialize_Tag (Full_Typ,
- Iface => Node (Iface_Elmt),
- Tag_Comp  => Tag_Comp,
- Iface_Tag => Node (Iface_Tag_Elmt));
+   Initialize_Tag
+ (Typ   => Full_Typ,
+  Iface => Node (Iface_Elmt),
+  Tag_Comp  => Tag_Comp,
+  Iface_Tag => Node (Iface_Tag_Elmt));
 end if;
  end if;
 
Index: gnat1drv.adb
===
--- gnat1drv.adb(revision 254568)
+++ gnat1drv.adb(working copy)
@@ -384,9 +384,10 @@
  Relaxed_RM_Semantics := True;
 
  if not Generate_CodePeer_Messages then
+
 --  Suppress compiler warnings by default when generating SCIL for
---  CodePeer, except when combined with -gnateC where we do want
---  to emit GNAT warnings.
+--  CodePeer, except when combined with -gnateC where we do want to
+--  emit GNAT warnings.
 
 Warning_Mode := Suppress;
  end if;
Index: namet.adb
===
--- namet.adb   (revision 254569)
+++ namet.adb   (working copy)
@@ -175,7 +175,8 @@

 
procedure Append_Decoded
- (Buf : in out Bounded_String; Id : Valid_Name_Id)
+ (Buf : in out Bounded_String;
+  Id  : Valid_Name_Id)
is
   C: Character;
   P: Natural;
@@ -599,7 +600,8 @@

 
procedure Append_Unqualified
- (Buf : in out Bounded_String; Id : Valid_Name_Id)
+ (Buf : in out Bounded_String;
+  Id  : Valid_Name_Id)
is
   Temp : Bounded_String;
begin
@@ -1476,7 +1478,10 @@
-- Name_Equals --
-
 
-   function Name_Equals (N1, N2 : Valid_Name_Id) return Boolean is
+   function Name_Equals
+ (N1 : Valid_Name_Id;
+  N2 : Valid_Name_Id) return Boolean
+   is
begin
   return N1 = N2 or else Get_Name_String (N1) = Get_Name_String (N2);
end Name_Equals;
Index: namet.ads
===
--- namet.ads   (revision 254569)
+++ namet.ads   (working copy)
@@ -358,7 +358,9 @@
--  names, since these are efficiently located without hashing by Name_Find
--  in any case.
 
-   function Name_Equals (N1, N2 : Valid_Name_Id) return Boolean;
+   function Name_Equals
+ (N1 : Valid_Name_Id;
+  N2 : Valid_Name_Id) return Boolean;
--  Return whether N1 and N2 denote the same character sequence
 
function Get_Name_String (Id : Valid_Name_Id) return String;
Index: sem_aggr.adb
===
--- sem_aggr.adb(revision 254563)
+++ sem_aggr.adb(working copy)
@@ -2765,7 +2765,7 @@
-
 
procedure Resolve_Delta_Aggregate (N : Node_Id; Typ : Entity_Id) is
-  Base   : constant Node_Id := Expression (N);
+  Base : constant Node_Id := Expression (N);
 
begin
   if not Is_Composite_Type (Typ) then
@@ -2789,12 +2789,14 @@
 
procedure Resolve_Delta_Array_Aggregate (N : Node_Id; Typ : Entity_Id) is
   Deltas : constant List_Id := Component_Associations (N);
+
  

[Ada] Spurious error on pragma Unreferenced

2017-11-09 Thread Pierre-Marie de Rodat
This patch suppresses the light expansion of references denoting renamings
that act as arguments in pragmas Unmodified and Unreferenced for GNATprove.
In general, the compiler replaces references to renamings with the renamed
name, however certain references are left as is for GNATprove. This does
not interfere with the analysis performed by the tool.


-- Source --


--  main.adb

procedure Main is
   X : aliased Integer;
   Y : access  Integer := X'Access;
   Z : Integer renames Y.all;
   pragma Unreferenced (Z);
begin null; end Main;

-
-- Compilation --
-

$ gcc -c -gnatd.F main.adb

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

gcc/ada/

2017-11-09  Hristian Kirtchev  

* sem_prag.ads: Add pragmas Unmodified and Unreferenced to table
Pragma_Significant_In_SPARK.

gcc/testsuite/

2017-11-09  Hristian Kirtchev  

* gnat.dg/unreferenced.adb: New testcase.
Index: sem_prag.ads
===
--- sem_prag.ads(revision 254563)
+++ sem_prag.ads(working copy)
@@ -191,6 +191,8 @@
   Pragma_Remote_Types  => False,
   Pragma_Shared_Passive=> False,
   Pragma_Task_Dispatching_Policy   => False,
+  Pragma_Unmodified=> False,
+  Pragma_Unreferenced  => False,
   Pragma_Warnings  => False,
   others   => True);
 
Index: ../testsuite/gnat.dg/unreferenced.adb
===
--- ../testsuite/gnat.dg/unreferenced.adb   (revision 0)
+++ ../testsuite/gnat.dg/unreferenced.adb   (revision 0)
@@ -0,0 +1,11 @@
+--  { dg-do compile }
+--  { dg-options "-gnatd.F" }
+
+procedure Unreferenced is
+   X : aliased Integer;
+   Y : access  Integer := X'Access;
+   Z : Integer renames Y.all;
+   pragma Unreferenced (Z);
+begin
+   null;
+end Unreferenced;


[Ada] Restriction Static_Dispatch_Tables

2017-11-09 Thread Pierre-Marie de Rodat
This patch implements a new GNAT restriction named Static_Dispatch_Tables,
which is intented to prevent the creation of tagged types whose dispatch
tables cannot be placed in read-only memory.

The following test now compiles with errors.

pragma Restrictions (Static_Dispatch_Tables);

procedure Test_Static_DT is
   package Local is
  type Typ is tagged null record;--  Test
  procedure Prim (Obj : Typ);
   end;
   package body Local is 
  procedure Prim (Obj : Typ) is
  begin
 null;
  end;
   end;

   Obj : Local.Typ;
begin
   Obj.Prim;
end;

Command: gcc -c test_static_dt.adb
test_static_dt.adb:5:12: violation of restriction
  "Static_Dispatch_Tables" at line 1

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

2017-11-09  Javier Miranda  

* libgnat/s-rident.ads (Static_Dispatch_Tables): New restriction name.
* exp_disp.adb (Building_Static_DT): Check restriction.
(Building_Static_Secondary_DT): Check restriction.
(Make_DT): Initialize the HT_Link to No_Tag.
* opt.ads (Static_Dispatch_Tables): Rename flag...
(Building_Static_Dispatch_Tables): ... into this.  This will avoid
conflict with the restriction name.
* gnat1drv.adb: Update.
* exp_aggr.adb (Is_Static_Dispatch_Table_Aggregate): Update.
* exp_ch3.adb (Expand_N_Object_Declaration): Update.

Index: exp_aggr.adb
===
--- exp_aggr.adb(revision 254563)
+++ exp_aggr.adb(working copy)
@@ -7533,7 +7533,7 @@
   Typ : constant Entity_Id := Base_Type (Etype (N));
 
begin
-  return Static_Dispatch_Tables
+  return Building_Static_Dispatch_Tables
 and then Tagged_Type_Expansion
 and then RTU_Loaded (Ada_Tags)
 
Index: libgnat/s-rident.ads
===
--- libgnat/s-rident.ads(revision 254563)
+++ libgnat/s-rident.ads(working copy)
@@ -183,6 +183,7 @@
   No_Elaboration_Code,   -- GNAT
   No_Obsolescent_Features,   -- Ada 2005 AI-368
   No_Wide_Characters,-- GNAT
+  Static_Dispatch_Tables,-- GNAT
   SPARK_05,  -- GNAT
 
   --  The following cases require a parameter value
Index: exp_disp.adb
===
--- exp_disp.adb(revision 254566)
+++ exp_disp.adb(working copy)
@@ -281,7 +281,8 @@

 
function Building_Static_DT (Typ : Entity_Id) return Boolean is
-  Root_Typ : Entity_Id := Root_Type (Typ);
+  Root_Typ  : Entity_Id := Root_Type (Typ);
+  Static_DT : Boolean;
 
begin
   --  Handle private types
@@ -290,7 +291,7 @@
  Root_Typ := Full_View (Root_Typ);
   end if;
 
-  return Static_Dispatch_Tables
+  Static_DT := Building_Static_Dispatch_Tables
 and then Is_Library_Level_Tagged_Type (Typ)
 
  --  If the type is derived from a CPP class we cannot statically
@@ -298,6 +299,12 @@
  --  from the CPP side.
 
 and then not Is_CPP_Class (Root_Typ);
+
+  if not Static_DT then
+ Check_Restriction (Static_Dispatch_Tables, Typ);
+  end if;
+
+  return Static_DT;
end Building_Static_DT;
 
--
@@ -305,8 +312,9 @@
--
 
function Building_Static_Secondary_DT (Typ : Entity_Id) return Boolean is
-  Full_Typ : Entity_Id := Typ;
-  Root_Typ : Entity_Id := Root_Type (Typ);
+  Full_Typ  : Entity_Id := Typ;
+  Root_Typ  : Entity_Id := Root_Type (Typ);
+  Static_DT : Boolean;
 
begin
   --  Handle private types
@@ -319,11 +327,20 @@
  Root_Typ := Full_View (Root_Typ);
   end if;
 
-  return Building_Static_DT (Full_Typ)
+  Static_DT := Building_Static_DT (Full_Typ)
 and then not Is_Interface (Full_Typ)
 and then Has_Interfaces (Full_Typ)
 and then (Full_Typ = Root_Typ
or else not Is_Variable_Size_Record (Etype (Full_Typ)));
+
+  if not Static_DT
+and then not Is_Interface (Full_Typ)
+and then Has_Interfaces (Full_Typ)
+  then
+ Check_Restriction (Static_Dispatch_Tables, Typ);
+  end if;
+
+  return Static_DT;
end Building_Static_Secondary_DT;
 
--
@@ -5103,7 +5120,8 @@
  Append_To (Result,
Make_Object_Declaration (Loc,
  Defining_Identifier => HT_Link,
- Object_Definition   => New_Occurrence_Of (RTE (RE_Tag), Loc)));
+ Object_Definition   => New_Occurrence_Of (RTE (RE_Tag), Loc),
+ Expression  => New_Occurrence_Of (RTE (RE_No_Tag), Loc)));
   end if;
 
   --  Generate code to create the storage for the type specific data object
Index: gna

[Ada] Fix code quality issues reported by CodePeer at level 3

2017-11-09 Thread Pierre-Marie de Rodat
Rerunning CodePeer at level 3 revealed further missing
initializations (not errors, but good to add for maintenance and
to improve analysis results) and missing No_Return pragmas. Now fixed.

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

2017-11-09  Yannick Moy  

* sem_attr.adb (Analyze_Attribute): Default initialize P_Type,
P_Base_Type.
(Error_Attr_P): Fix name in pragma No_Return.
(Unexpected_Argument): Add pragma No_Return.
(Placement_Error): Add pragma No_Return.

Index: sem_attr.adb
===
--- sem_attr.adb(revision 254563)
+++ sem_attr.adb(working copy)
@@ -231,10 +231,10 @@
   E1  : Node_Id;
   E2  : Node_Id;
 
-  P_Type : Entity_Id;
+  P_Type : Entity_Id := Empty;
   --  Type of prefix after analysis
 
-  P_Base_Type : Entity_Id;
+  P_Base_Type : Entity_Id := Empty;
   --  Base type of prefix after analysis
 
   ---
@@ -419,7 +419,7 @@
   --  required error messages.
 
   procedure Error_Attr_P (Msg : String);
-  pragma No_Return (Error_Attr);
+  pragma No_Return (Error_Attr_P);
   --  Like Error_Attr, but error is posted at the start of the prefix
 
   procedure Legal_Formal_Attribute;
@@ -446,7 +446,9 @@
   --  node in the aspect case).
 
   procedure Unexpected_Argument (En : Node_Id);
-  --  Signal unexpected attribute argument (En is the argument)
+  pragma No_Return (Unexpected_Argument);
+  --  Signal unexpected attribute argument (En is the argument), and then
+  --  raises Bad_Attribute to avoid any further semantic processing.
 
   procedure Validate_Non_Static_Attribute_Function_Call;
   --  Called when processing an attribute that is a function call to a
@@ -1108,8 +1110,10 @@
  --  node Nod is within enclosing node Encl_Nod.
 
  procedure Placement_Error;
+ pragma No_Return (Placement_Error);
  --  Emit a general error when the attributes does not appear in a
- --  postcondition-like aspect or pragma.
+ --  postcondition-like aspect or pragma, and then raises Bad_Attribute
+ --  to avoid any further semantic processing.
 
  --
  -- Check_Placement_In_Check --


[Ada] Rewrite code and add justifications for static analysis

2017-11-09 Thread Pierre-Marie de Rodat
CodePeer static analyzer issues messages that can be avoided by
simpliflying the code, or justifying the false positives.
There is no test, as this does no impact the behavior of the compiler.

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

2017-11-09  Yannick Moy  

* erroutc.adb (Output_Error_Msgs): Justify CodePeer false positive
message.
* gnatbind.adb (Scan_Bind_Arg): Simplify test to remove always true
condition.
* namet.adb (Copy_One_Character): Add assumption for static analysis,
as knowledge that Hex(2) is in the range 0..255 is too complex for
CodePeer.
(Finalize): Add assumption for static analysis, as the fact that there
are symbols in the table depends on a global invariant at this point in
the program.
* set_targ.adb (Check_Spaces): Justify CodePeer false positive message.
* stylesw.adb (Save_Style_Check_Options): Rewrite to avoid test always
true.

Index: set_targ.adb
===
--- set_targ.adb(revision 254570)
+++ set_targ.adb(working copy)
@@ -604,6 +604,10 @@
   procedure Check_Spaces is
   begin
  if N > Buflen or else Buffer (N) /= ' ' then
+pragma Annotate
+  (CodePeer, False_Positive, "condition predetermined",
+   "N may be less than Buflen when calling Check_Spaces");
+
 FailN ("missing space for");
  end if;
 
Index: erroutc.adb
===
--- erroutc.adb (revision 254563)
+++ erroutc.adb (working copy)
@@ -512,6 +512,9 @@
   --  so now we output a tab to match up with the text.
 
   if Src (P) = ASCII.HT then
+ pragma Annotate
+   (CodePeer, False_Positive, "validity check",
+"Src(P) is initialized at this point");
  Write_Char (ASCII.HT);
  P := P + 1;
 
Index: gnatbind.adb
===
--- gnatbind.adb(revision 254563)
+++ gnatbind.adb(working copy)
@@ -330,9 +330,7 @@
   then
  Output_File_Name_Seen := True;
 
- if Argv'Length = 0
-   or else (Argv'Length >= 1 and then Argv (1) = '-')
- then
+ if Argv'Length = 0 or else Argv (1) = '-' then
 Fail ("output File_Name missing after -o");
 
  else
Index: namet.adb
===
--- namet.adb   (revision 254571)
+++ namet.adb   (working copy)
@@ -258,7 +258,13 @@
   --  simply use their normal representation.
 
else
-  Insert_Character (Character'Val (Hex (2)));
+  declare
+ W2 : constant Word := Hex (2);
+  begin
+ pragma Assume (W2 <= 255);
+ --  Add assumption to facilitate static analysis
+ Insert_Character (Character'Val (W2));
+  end;
end if;
 
 --  WW (wide wide character insertion)
@@ -753,6 +759,9 @@
 
   Write_Eol;
   Write_Str ("Average number of probes for lookup = ");
+  pragma Assume (Nsyms /= 0);
+  --  Add assumption to facilitate static analysis. Here Nsyms cannot be
+  --  zero because many symbols are added to the table by default.
   Probes := Probes / Nsyms;
   Write_Int (Probes / 200);
   Write_Char ('.');
Index: stylesw.adb
===
--- stylesw.adb (revision 254570)
+++ stylesw.adb (working copy)
@@ -161,7 +161,8 @@
   if Style_Check_Comments then
  if Style_Check_Comments_Spacing = 2 then
 Add ('c', Style_Check_Comments);
- elsif Style_Check_Comments_Spacing = 1 then
+ else
+pragma Assert (Style_Check_Comments_Spacing = 1);
 Add ('C', Style_Check_Comments);
  end if;
   end if;


[PATCH] Fix PR82902

2017-11-09 Thread Richard Biener

The following fixes PR82902.

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

Richard.

2017-11-09  Richard Biener  

PR tree-optimization/82902
* tree-ssa-phiprop.c (propagate_with_phi): Test proper type.

* g++.dg/torture/pr82902.C: New testcase.

Index: gcc/tree-ssa-phiprop.c
===
--- gcc/tree-ssa-phiprop.c  (revision 254560)
+++ gcc/tree-ssa-phiprop.c  (working copy)
@@ -354,7 +354,7 @@ propagate_with_phi (basic_block bb, gphi
 
   /* Found a proper dereference with an aggregate copy.  Just
  insert aggregate copies on the edges instead.  */
-  if (!is_gimple_reg_type (TREE_TYPE (TREE_TYPE (ptr
+  if (!is_gimple_reg_type (TREE_TYPE (gimple_assign_lhs (use_stmt
{
  if (!gimple_vdef (use_stmt))
goto next;
Index: gcc/testsuite/g++.dg/torture/pr82902.C
===
--- gcc/testsuite/g++.dg/torture/pr82902.C  (nonexistent)
+++ gcc/testsuite/g++.dg/torture/pr82902.C  (working copy)
@@ -0,0 +1,21 @@
+// { dg-do compile }
+
+typedef struct el_t {
+el_t *next;
+int elem[];
+} EL;
+el_t a, c;
+void *b;
+void *fn1() {
+if (b)
+  return a.elem;
+return c.elem;
+}
+typedef struct {
+int x;
+} EV_T;
+EV_T *d;
+void fn2() {
+EV_T *e = (EV_T *)fn1();
+d[0] = *e;
+}


[Ada] Get rid of warnings about uninitialized variables

2017-11-09 Thread Pierre-Marie de Rodat
This patch cleans up the code to get rid of warnings about uninitialized
variables.  No change in behavior; no test available.

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

2017-11-09  Bob Duff  

* exp_ch4.adb, exp_ch9.adb, exp_prag.adb, par-ch3.adb, sem_aggr.adb,
sem_ch12.adb, sem_ch13.adb, sem_ch4.adb, sem_disp.adb, sem_prag.adb,
sem_res.adb, sem_util.adb: Get rid of warnings about uninitialized
variables.

Index: sem_aggr.adb
===
--- sem_aggr.adb(revision 254573)
+++ sem_aggr.adb(working copy)
@@ -2882,7 +2882,7 @@
   --  Variables used to verify that discriminant-dependent components
   --  appear in the same variant.
 
-  Comp_Ref : Entity_Id;
+  Comp_Ref : Entity_Id := Empty; -- init to avoid warning
   Variant  : Node_Id;
 
   procedure Check_Variant (Id : Entity_Id);
@@ -2941,6 +2941,7 @@
 or else
   (D2 > D1 and then not Nested_In (Comp_Variant, Variant))
   then
+ pragma Assert (Present (Comp_Ref));
  Error_Msg_Node_2 := Comp_Ref;
  Error_Msg_NE
("& and & appear in different variants", Id, Comp);
@@ -3025,7 +3026,7 @@
 
   Assoc : Node_Id;
   Choice: Node_Id;
-  Comp_Type : Entity_Id;
+  Comp_Type : Entity_Id := Empty; -- init to avoid warning
 
--  Start of processing for Resolve_Delta_Record_Aggregate
 
@@ -3045,6 +3046,7 @@
 Next (Choice);
  end loop;
 
+ pragma Assert (Present (Comp_Type));
  Analyze_And_Resolve (Expression (Assoc), Comp_Type);
  Next (Assoc);
   end loop;
Index: exp_prag.adb
===
--- exp_prag.adb(revision 254563)
+++ exp_prag.adb(working copy)
@@ -1090,7 +1090,7 @@
   Conseq_Checks : Node_Id   := Empty;
   Count : Entity_Id;
   Count_Decl: Node_Id;
-  Error_Decls   : List_Id;
+  Error_Decls   : List_Id := No_List; -- init to avoid warning
   Flag  : Entity_Id;
   Flag_Decl : Node_Id;
   If_Stmt   : Node_Id;
Index: sem_prag.adb
===
--- sem_prag.adb(revision 254570)
+++ sem_prag.adb(working copy)
@@ -5817,8 +5817,8 @@
 
 procedure Check_Grouping (L : List_Id) is
HSS  : Node_Id;
-   Prag : Node_Id;
Stmt : Node_Id;
+   Prag : Node_Id := Empty; -- init to avoid warning
 
 begin
--  Inspect the list of declarations or statements looking for
@@ -5872,16 +5872,15 @@
 
  else
 while Present (Stmt) loop
-
--  The current pragma is either the first pragma
-   --  of the group or is a member of the group. Stop
-   --  the search as the placement is legal.
+   --  of the group or is a member of the group.
+   --  Stop the search as the placement is legal.
 
if Stmt = N then
   raise Stop_Search;
 
-   --  Skip group members, but keep track of the last
-   --  pragma in the group.
+   --  Skip group members, but keep track of the
+   --  last pragma in the group.
 
elsif Is_Loop_Pragma (Stmt) then
   Prag := Stmt;
@@ -11390,6 +11389,7 @@
 SPARK_Msg_N
   ("expression of external state property must be "
& "static", Expr);
+return;
  end if;
 
   --  The lack of expression defaults the property to True
@@ -16474,6 +16474,20 @@
   return;
end if;
 
+   --  Ada 2012 (AI05-0030): Cannot apply the implementation_kind
+   --  By_Protected_Procedure to the primitive procedure of a task
+   --  interface.
+
+   if Chars (Arg2) = Name_By_Protected_Procedure
+ and then Is_Interface (Typ)
+ and then Is_Task_Interface (Typ)
+   then
+  Error_Pragma_Arg
+("implementation kind By_Protected_Procedure cannot be "
+ & "applied to a task interface primitive", Arg2);
+  return;
+   end if;
+
 --  Procedures declared inside a protected type must be accepted
 
 elsif Ekind (Proc_Id) = E_Procedure
@@ -16489,20 +16503,6 @@
return;
 end if;
 
---  Ada 2012 (AI05-0030): Cannot apply t

Re: [PATCH] Replace has_single_use guards in store-merging

2017-11-09 Thread Richard Biener
On Wed, 8 Nov 2017, Jakub Jelinek wrote:

> On Wed, Nov 08, 2017 at 04:20:15PM +0100, Richard Biener wrote:
> > Can't you simply use
> > 
> >unsigned ret = 0;
> >FOR_EACH_SSA_TREE_OPERAND (op, stmt, iter, SSA_OP_USE)
> >  if (!has_single_use (op))
> >++ret;
> >return ret;
> > 
> > ?  Not sure if the bit_not_p handling is required.
> 
> Consider the case with most possible statements:
>   _1 = load1;
>   _2 = load2;
>   _3 = ~_1;
>   _4 = ~_2;
>   _5 = _3 ^ _4;
>   store0 = _5;
> All these statements construct the value for the store, and if we remove
> the old stores and add new stores we'll need similar statements for each
> of the new stores.  What the function is attempting to compute how many
> of these original statements will be not DCEd.
> If _5 has multiple uses, then we'll need all of them, so 5 stmts not
> being DCEd.  If _5 has single use, but _3 (and/or _4) has multiple uses,
> we'll need the corresponding loads in addition to the BIT_NOT_EXPR
> statement(s).  If only _1 (and/or _2) has multiple uses, we'll need
> the load(s) but nothing else.
> So, there isn't a single stmt I could FOR_EACH_SSA_TREE_OPERAND on.
> For BIT_{AND,IOR,XOR}_EXPR doing it just on that stmt would be too rough
> approximation and would miss the case when the bitwise binary op result
> is used.

Hmm, I see.

> > It doesn't seem you handle multi-uses of the BIT_*_EXPR results
> > itself?  Or does it only handle multi-uses of the BIT_*_EXPR
> > but not the feeding loads?
> 
> I believe I handle all those precisely above (the only reason I've talked
> about aproximation is that bit field loads/stores are counted as one stmt
> and the masking added for handling multiple semi-adjacent bitfield
> loads/stores aren't counted either).
> 
> Given the above example:
>   if (!has_single_use (gimple_assign_rhs1 (stmt)))
>   {
> ret += 1 + info->ops[0].bit_not_p;
> if (info->ops[1].base_addr)
>   ret += 1 + info->ops[1].bit_not_p;
> return ret + 1;
>   }
> Above should handle the _5 multiple uses case (the first operand is guaranteed
> by the discovery code to be a possibly negated load).
>   stmt = SSA_NAME_DEF_STMT (gimple_assign_rhs1 (stmt));
>   /* stmt is now the BIT_*_EXPR.  */
>   if (!has_single_use (gimple_assign_rhs1 (stmt)))
>   ret += 1 + info->ops[0].bit_not_p;
> Above should handle the _3 multiple uses.
>   else if (info->ops[0].bit_not_p)
>   {
> gimple *stmt2 = SSA_NAME_DEF_STMT (gimple_assign_rhs1 (stmt));
> if (!has_single_use (gimple_assign_rhs1 (stmt2)))
>   ++ret;
>   }
> Above should handle multiple uses of _1.
>   if (info->ops[1].base_addr == NULL_TREE)
>   return ret;
> is an early return for the case when second argument to BIT_*_EXPR is
> constant.
>   if (!has_single_use (gimple_assign_rhs2 (stmt)))
>   ret += 1 + info->ops[1].bit_not_p;
> Above should handle the _4 multiple uses.
>   else if (info->ops[1].bit_not_p)
>   {
> gimple *stmt2 = SSA_NAME_DEF_STMT (gimple_assign_rhs2 (stmt));
> if (!has_single_use (gimple_assign_rhs1 (stmt2)))
>   ++ret;
>   }
> Above should handle the _2 multiple uses.
> 
> And for another example like:
>   _6 = load1;
>   _7 = ~_6;
>   store0 = _7;
>   if (!has_single_use (gimple_assign_rhs1 (stmt)))
>   return 1 + info->ops[0].bit_not_p;
> Above should handle _7 multiple uses
>   else if (info->ops[0].bit_not_p)
>   {
> stmt = SSA_NAME_DEF_STMT (gimple_assign_rhs1 (stmt));
> if (!has_single_use (gimple_assign_rhs1 (stmt)))
>   return 1;
>   }
> Above should handle _6 multiple uses.

Thanks for the explanation, it's now more clear what the code does.

The patch is ok.  (and hopefully makes the PGO bootstrap issue latent
again - heh)

Thanks,
Richard.


[PATCH] Fix up store_merging_13.c FAIL

2017-11-09 Thread Jakub Jelinek
Hi!

The gcc.dg/store_merging_13.c testcase worked when I was bootstrapping the
patch that introduced it, but doesn't anymore, because match.pd had
a ~X ^ Y -> ~(X ^ Y) transformation, the code was handling only ~ on
the loads (== arguments of &/|/^) but not on the result of the bitwise
binary operation.  The following patch handles inversion of the result
too, after all even ~X & ~Y is ~(X | Y) and ~X | ~Y is ~(X & Y).
In addition to this, I've added just in case some earlier passes wouldn't
do good enough job a check that we don't recognize
_1 = load; _2 = ~1; _3 = ~1; store = _3; and similar (or arbitrarily more
chained BIT_NOT_EXPRs), while we'd emit a working code, the has_single_use
accounting wouldn't be prepared for more than one BIT_NOT_EXPR on one
operand.

Ok for trunk if it passes bootstrap/regtest?

Just managed to reproduce the profiledbootstrap issue, so working on that
next.

2017-11-09  Jakub Jelinek  

* gimple-ssa-store-merging.c (struct store_immediate_info): Add
bit_not_p field.
(store_immediate_info::store_immediate_info): Add bitnotp argument,
set bit_not_p to it.
(imm_store_chain_info::coalesce_immediate_stores): Break group
if bit_not_p is different.
(count_multiple_uses, split_group,
imm_store_chain_info::output_merged_store): Handle info->bit_not_p.
(handled_load): Avoid multiple chained BIT_NOT_EXPRs.
(pass_store_merging::process_store): Handle BIT_{AND,IOR,XOR}_EXPR
result inverted using BIT_NOT_EXPR, compute bit_not_p, pass it
to store_immediate_info ctor.

--- gcc/gimple-ssa-store-merging.c.jj   2017-11-09 12:40:27.0 +0100
+++ gcc/gimple-ssa-store-merging.c  2017-11-09 14:00:46.269673305 +0100
@@ -209,12 +209,13 @@ struct store_immediate_info
   /* INTEGER_CST for constant stores, MEM_REF for memory copy or
  BIT_*_EXPR for logical bitwise operation.  */
   enum tree_code rhs_code;
+  bool bit_not_p;
   /* Operands.  For BIT_*_EXPR rhs_code both operands are used, otherwise
  just the first one.  */
   store_operand_info ops[2];
   store_immediate_info (unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT,
unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT,
-   gimple *, unsigned int, enum tree_code,
+   gimple *, unsigned int, enum tree_code, bool,
const store_operand_info &,
const store_operand_info &);
 };
@@ -226,10 +227,11 @@ store_immediate_info::store_immediate_in
gimple *st,
unsigned int ord,
enum tree_code rhscode,
+   bool bitnotp,
const store_operand_info &op0r,
const store_operand_info &op1r)
   : bitsize (bs), bitpos (bp), bitregion_start (brs), bitregion_end (bre),
-stmt (st), order (ord), rhs_code (rhscode)
+stmt (st), order (ord), rhs_code (rhscode), bit_not_p (bitnotp)
 #if __cplusplus >= 201103L
 , ops { op0r, op1r }
 {
@@ -1169,7 +1171,8 @@ imm_store_chain_info::coalesce_immediate
 Merge it into the current store group.  There can be gaps in between
 the stores, but there can't be gaps in between bitregions.  */
   else if (info->bitregion_start <= merged_store->bitregion_end
-  && info->rhs_code == merged_store->stores[0]->rhs_code)
+  && info->rhs_code == merged_store->stores[0]->rhs_code
+  && info->bit_not_p == merged_store->stores[0]->bit_not_p)
{
  store_immediate_info *infof = merged_store->stores[0];
 
@@ -1386,6 +1389,17 @@ count_multiple_uses (store_immediate_inf
 case BIT_AND_EXPR:
 case BIT_IOR_EXPR:
 case BIT_XOR_EXPR:
+  if (info->bit_not_p)
+   {
+ if (!has_single_use (gimple_assign_rhs1 (stmt)))
+   ret = 1; /* Fall through below to return
+   the BIT_NOT_EXPR stmt and then
+   BIT_{AND,IOR,XOR}_EXPR and anything it
+   uses.  */
+ else
+   /* stmt is after this the BIT_NOT_EXPR.  */
+   stmt = SSA_NAME_DEF_STMT (gimple_assign_rhs1 (stmt));
+   }
   if (!has_single_use (gimple_assign_rhs1 (stmt)))
{
  ret += 1 + info->ops[0].bit_not_p;
@@ -1479,6 +1493,8 @@ split_group (merged_store_group *group,
case BIT_AND_EXPR:
case BIT_IOR_EXPR:
case BIT_XOR_EXPR:
+ if (info->bit_not_p)
+   total_orig[0]++; /* The orig BIT_NOT_EXPR stmt.  */
  total_orig[0]++; /* The orig BIT_*_EXPR stmt.  */
  break;
default:
@@ -1649,6 +1665,8 @@ split_group (merged_store_group *group,
case BIT_AND_EXPR:
case BIT_IOR_EXPR:
case BIT_XOR_EXPR:
+ if (info->bit_not_p)
+   total

[Ada] Crash on use of Compile_Time_Error in a generic package

2017-11-09 Thread Pierre-Marie de Rodat
An expanded name used within a generic package declaration must be handled
specially because the prefix may denote a parent unit that will have a
different name in an instance. We introduce a renaming of the generic unit
and replace the expanded name with a reference to that renaming, The
renaming declaaration must be intruduced after the leading pragmas in the
current declarative part, which may be library unit pragmas. The pragma
Compile_Time_Error is not in this category, and the renaming declaration must
preceed it.

Compiling main.adb must yield:

   main.adb:4:04: instantiation error at parent-gen.ads:7
   main.adb:4:04: Error

---
with Parent.Gen;
procedure Main is
   package G is new Parent.Gen;
begin
   null;
end Main;
---
package Parent is
  pragma Pure;
end Parent;
---
generic
package Parent.Gen is
   pragma Compile_Time_Error
  (not Parent.Gen'Library_Level, "Error");
end Parent.Gen;

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

2017-11-09  Ed Schonberg  

* sem_ch12.adb (Analyze_Generic_Package_Declaration): Handle properly
the pragma Compile_Time_Error when it appears in a generic package
declaration and uses an expanded name to denote the current unit.

Index: sem_ch12.adb
===
--- sem_ch12.adb(revision 254579)
+++ sem_ch12.adb(revision 254580)
@@ -3466,9 +3466,9 @@
--
 
procedure Analyze_Generic_Package_Declaration (N : Node_Id) is
-  Loc : constant Source_Ptr := Sloc (N);
-  Decls   : constant List_Id :=
-  Visible_Declarations (Specification (N));
+  Decls : constant List_Id:= Visible_Declarations (Specification (N));
+  Loc   : constant Source_Ptr := Sloc (N);
+
   Decl: Node_Id;
   Id  : Entity_Id;
   New_N   : Node_Id;
@@ -3492,9 +3492,20 @@
   Name   =>
 Make_Identifier (Loc, Chars (Defining_Entity (N;
 
+  --  The declaration is inserted before other declarations, but before
+  --  pragmas that may be library-unit pragmas and must appear before other
+  --  declarations. The pragma Compile_Time_Error is not in this class, and
+  --  may contain an expression that includes such a qualified name, so the
+  --  renaming declaration must appear before it.
+
+  --  Are there other pragmas that require this special handling ???
+
   if Present (Decls) then
  Decl := First (Decls);
- while Present (Decl) and then Nkind (Decl) = N_Pragma loop
+ while Present (Decl)
+   and then Nkind (Decl) = N_Pragma
+   and then Get_Pragma_Id (Decl) /= Pragma_Compile_Time_Error
+ loop
 Next (Decl);
  end loop;
 


[Ada] Bump size limit for large static aggregates

2017-11-09 Thread Pierre-Marie de Rodat
For historical reasons, the compiler caps the size of large static aggregates
that are emitted as static data in the object file.  If they exceed the cap,
then elaboration code is generated instead, but this is in most cases slower,
yields bigger and unoptimizable code with poor run-time performance.

This change bumps the limit by an order of magnitude to account for larger
aggregates used in modern software.  No functional changes.

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

2017-11-09  Eric Botcazou  

* exp_aggr.adb (Aggr_Size_OK): Bump base limit from 5 to 50.

Index: exp_aggr.adb
===
--- exp_aggr.adb(revision 254579)
+++ exp_aggr.adb(revision 254580)
@@ -428,7 +428,7 @@
--  Start of processing for Aggr_Size_OK
 
begin
-  --  The normal aggregate limit is 5, but we increase this limit to
+  --  The normal aggregate limit is 50, but we increase this limit to
   --  2**24 (about 16 million) if Restrictions (No_Elaboration_Code) or
   --  Restrictions (No_Implicit_Loops) is specified, since in either case
   --  we are at risk of declaring the program illegal because of this
@@ -448,7 +448,7 @@
   --  Finally, we use a small limit in CodePeer mode where we favor loops
   --  instead of thousands of single assignments (from large aggregates).
 
-  Max_Aggr_Size := 5;
+  Max_Aggr_Size := 50;
 
   if CodePeer_Mode then
  Max_Aggr_Size := 100;


[Ada] Fix bootstrap issue with CodePeer justifications

2017-11-09 Thread Pierre-Marie de Rodat
The use of pragma Annotate to justify CodePeer messages breaks compiler
bootstrap. Fix this by removing these justifications.

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

2017-11-09  Yannick Moy  

* erroutc.adb, set_targ.adb: Remove pragma Annotate for CodePeer
justification.

Index: set_targ.adb
===
--- set_targ.adb(revision 254579)
+++ set_targ.adb(revision 254580)
@@ -604,10 +604,6 @@
   procedure Check_Spaces is
   begin
  if N > Buflen or else Buffer (N) /= ' ' then
-pragma Annotate
-  (CodePeer, False_Positive, "condition predetermined",
-   "N may be less than Buflen when calling Check_Spaces");
-
 FailN ("missing space for");
  end if;
 
Index: erroutc.adb
===
--- erroutc.adb (revision 254579)
+++ erroutc.adb (revision 254580)
@@ -512,9 +512,6 @@
   --  so now we output a tab to match up with the text.
 
   if Src (P) = ASCII.HT then
- pragma Annotate
-   (CodePeer, False_Positive, "validity check",
-"Src(P) is initialized at this point");
  Write_Char (ASCII.HT);
  P := P + 1;
 


[Ada] Quadratic explosion caused by freezing of contracts

2017-11-09 Thread Pierre-Marie de Rodat
This patch reimplements the "freezing of contracts" semantic because it caused
a quadratic exlosion in the number of subprogram bodies in declarative lists.
The "freezing of constracts" semantic is carried out when an entry, package,
protected, subprogram [stub], or task body is processed.

Prior to the patch, the semantic would analyze the contracts of all eligible
constructs within the same list as the freezing body, upto that body. This
approach would result in the exact same constructs being reanalyzed as each
new freezing body is seen, thus causing a quadratic explostion.

The patch changes the freezing mechanism to perform the freezing in reverse
declarative order, starting from the freezing body. Once the declarative list
is exhausted, or another freezing body is encountered, the processing stops.
This keeps the amount of contract freezing linear with respect to the number
of freezing bodies.

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

2017-11-09  Hristian Kirtchev  

* contracts.adb (Analyze_Contracts): Remove the three parameter
version. This routine now only analyzes contracts and does not perform
any freezing actions.
(Analyze_Previous_Contracts): Removed.
(Freeze_Previous_Contracts): New routine.
* contracts.ads (Analyze_Previous_Contracts): Removed.
(Freeze_Previous_Contracts): New routine.
* sem_ch3.adb (Analyze_Declarations): Analyze the contract of an
enclosing package spec regardless of whether the list denotes the
visible or private declarations.  Fix the removal of partial state
refinements when the context is a package spec.
* sem_ch6.adb (Analyze_Subprogram_Body_Helper): Freeze previous
contracts.
* sem_ch7.adb (Analyze_Package_Body_Helper): Freeze previous contracts.
* sem_ch9.adb (Analyze_Entry_Body): Freeze previous contracts.
(Analyze_Protected_Body): Freeze previous contracts.
(Analyze_Task_Body): Freeze previous contracts.
* sem_prag.adb: Comment reformatting.

Index: contracts.adb
===
--- contracts.adb   (revision 254579)
+++ contracts.adb   (revision 254580)
@@ -53,16 +53,6 @@
 
 package body Contracts is
 
-   procedure Analyze_Contracts
- (L  : List_Id;
-  Freeze_Nod : Node_Id;
-  Freeze_Id  : Entity_Id);
-   --  Subsidiary to the one parameter version of Analyze_Contracts and routine
-   --  Analyze_Previous_Constracts. Analyze the contracts of all constructs in
-   --  the list L. If Freeze_Nod is set, then the analysis stops when the node
-   --  is reached. Freeze_Id is the entity of some related context which caused
-   --  freezing up to node Freeze_Nod.
-
procedure Build_And_Analyze_Contract_Only_Subprograms (L : List_Id);
--  (CodePeer): Subsidiary procedure to Analyze_Contracts which builds the
--  contract-only subprogram body of eligible subprograms found in L, adds
@@ -351,32 +341,16 @@
---
 
procedure Analyze_Contracts (L : List_Id) is
+  Decl : Node_Id;
+
begin
   if CodePeer_Mode and then Debug_Flag_Dot_KK then
  Build_And_Analyze_Contract_Only_Subprograms (L);
   end if;
 
-  Analyze_Contracts (L, Freeze_Nod => Empty, Freeze_Id => Empty);
-   end Analyze_Contracts;
-
-   procedure Analyze_Contracts
- (L  : List_Id;
-  Freeze_Nod : Node_Id;
-  Freeze_Id  : Entity_Id)
-   is
-  Decl : Node_Id;
-
-   begin
   Decl := First (L);
   while Present (Decl) loop
 
- --  The caller requests that the traversal stops at a particular node
- --  that causes contract "freezing".
-
- if Present (Freeze_Nod) and then Decl = Freeze_Nod then
-exit;
- end if;
-
  --  Entry or subprogram declarations
 
  if Nkind_In (Decl, N_Abstract_Subprogram_Declaration,
@@ -388,7 +362,7 @@
Subp_Id : constant Entity_Id := Defining_Entity (Decl);
 
 begin
-   Analyze_Entry_Or_Subprogram_Contract (Subp_Id, Freeze_Id);
+   Analyze_Entry_Or_Subprogram_Contract (Subp_Id);
 
--  If analysis of a class-wide pre/postcondition indicates
--  that a class-wide clone is needed, analyze its declaration
@@ -410,9 +384,7 @@
  --  Objects
 
  elsif Nkind (Decl) = N_Object_Declaration then
-Analyze_Object_Contract
-  (Obj_Id=> Defining_Entity (Decl),
-   Freeze_Id => Freeze_Id);
+Analyze_Object_Contract (Defining_Entity (Decl));
 
  --  Protected units
 
@@ -433,8 +405,9 @@
  then
 Analyze_Task_Contract (Defining_Entity (Decl));
 
- --  For type declarations, we need to do the pre-analysis of
- --  Iterable aspect specifications.
+ --  For type declarations, we need to do the pre-analysis of Iterable
+ --  

[Ada] Export Make_Independent from GNAT.Threads

2017-11-09 Thread Pierre-Marie de Rodat
This patch exports Make_Independent from GNAT.Threads. No simple test
available.

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

2017-11-09  Bob Duff  

* libgnarl/g-thread.ads, libgnarl/g-thread.adb: (Make_Independent):
Export this so users can use it without importing
System.Tasking.Utilities.
* libgnarl/s-tassta.adb (Vulnerable_Complete_Task): Relax assertion
that fails when Make_Independent is called on a user task.
* libgnarl/s-taskin.ads (Master_Of_Task): Avoid unusual
capitalization style ((style) bad casing of "Master_of_Task").

Index: libgnat/g-altive.ads
===
--- libgnat/g-altive.ads(revision 254579)
+++ libgnat/g-altive.ads(revision 254580)
@@ -668,18 +668,18 @@
 --  type of A.  The quad-word operations are only implemented by one
 --  Altivec primitive operation.  That means that, if QW_Operation is a
 --  quad-word operation, we should have:
---  QW_Operation (To_Type_of_A (B)) = QW_Operation (A)
+--  QW_Operation (To_Type_Of_A (B)) = QW_Operation (A)
 
 --  That is true iff:
---  To_Quad_Word (To_Type_of_A (B)) = To_Quad_Word (A)
+--  To_Quad_Word (To_Type_Of_A (B)) = To_Quad_Word (A)
 
 --  As To_Quad_Word is a bijection. we have:
---  To_Type_of_A (B) = A
+--  To_Type_Of_A (B) = A
 
 --  resp. any combination of A, B, C:
---  To_Type_of_A (C) = A
---  To_Type_of_B (A) = B
---  To_Type_of_C (B) = C
+--  To_Type_Of_A (C) = A
+--  To_Type_Of_B (A) = B
+--  To_Type_Of_C (B) = C
 --  ...
 
 --  Making sure that the properties described above are verified by the
Index: libgnat/s-spsufi.adb
===
--- libgnat/s-spsufi.adb(revision 254579)
+++ libgnat/s-spsufi.adb(revision 254580)
@@ -71,9 +71,9 @@
   --  requires that "The subpool no longer belongs to any pool" BEFORE
   --  calling Deallocate_Subpool. The actual dispatching call required is:
   --
-  -- Deallocate_Subpool(Pool_of_Subpool(Subpool).all, Subpool);
+  -- Deallocate_Subpool(Pool_Of_Subpool(Subpool).all, Subpool);
   --
-  --  but that can't be taken literally, because Pool_of_Subpool will
+  --  but that can't be taken literally, because Pool_Of_Subpool will
   --  return null.
 
   declare
Index: libgnarl/s-tassta.adb
===
--- libgnarl/s-tassta.adb   (revision 254579)
+++ libgnarl/s-tassta.adb   (revision 254580)
@@ -151,7 +151,7 @@
   --  duplicate master ids. For example, suppose we have three nested
   --  task bodies T1,T2,T3. And suppose T1 also calls P which calls Q (and
   --  both P and Q are task masters). Q will have the same master id as
-  --  Master_of_Task of T3. Previous versions of this would abort T3 when
+  --  Master_Of_Task of T3. Previous versions of this would abort T3 when
   --  Q calls Complete_Master, which was completely wrong.
 
begin
@@ -160,7 +160,7 @@
  P := C.Common.Parent;
 
  if P = Self_ID then
-if C.Master_of_Task = Self_ID.Master_Within then
+if C.Master_Of_Task = Self_ID.Master_Within then
pragma Debug
  (Debug.Trace (Self_ID, "Aborting", 'X', C));
Utilities.Abort_One_Task (Self_ID, C);
@@ -304,7 +304,7 @@
P.Alive_Count := P.Alive_Count + 1;
 
if P.Common.State = Master_Completion_Sleep and then
- C.Master_of_Task = P.Master_Within
+ C.Master_Of_Task = P.Master_Within
then
   pragma Assert (Self_ID /= P);
   P.Common.Wait_Count := P.Common.Wait_Count + 1;
@@ -498,7 +498,7 @@
   --  has already awaited its dependent tasks. This raises Program_Error,
   --  by 4.8(10.3/2). See AI-280. Ignore this check for foreign threads.
 
-  if Self_ID.Master_of_Task /= Foreign_Task_Level
+  if Self_ID.Master_Of_Task /= Foreign_Task_Level
 and then Master > Self_ID.Master_Within
   then
  raise Program_Error with
@@ -559,10 +559,10 @@
 
   P := Self_ID;
 
-  if P.Master_of_Task <= Independent_Task_Level then
+  if P.Master_Of_Task <= Independent_Task_Level then
  P := Environment_Task;
   else
- while P /= null and then P.Master_of_Task >= Master loop
+ while P /= null and then P.Master_Of_Task >= Master loop
 P := P.Common.Parent;
  end loop;
   end if;
@@ -621,13 +621,13 @@
  --  a regular library level task, otherwise the run-time will get
  --  confused when waiting for these tasks to terminate.
 
- T.Master_of_Task := Library_Task_Level;
+ T.Master_Of_Task := Library_Task_Level;
 
   else
- T.Master_of_Task := Master;
+ T.Master_Of_Task := Master;
   end if;
 
-  T.Master_Within := T.Master_of_Tas

Add optabs for common types of permutation

2017-11-09 Thread Richard Sandiford
...so that we can use them for variable-length vectors.  For now
constant-length vectors continue to use VEC_PERM_EXPR and the
vec_perm_const optab even for cases that the new optabs could
handle.

The vector optabs are inconsistent about whether there should be
an underscore before the mode part of the name, but the other lo/hi
optabs have one.

Doing this means that we're able to optimise some SLP tests using
non-SLP (for now) on targets with variable-length vectors, so the
patch needs to add a few XFAILs.  Most of these go away with later
patches.

Tested on aarch64-linux-gnu (with and without SVE), x86_64-linux-gnu
and powerpc64le-linus-gnu.  OK to install?

Richard


2017-11-09  Richard Sandiford  
Alan Hayward  
David Sherwood  

gcc/
* doc/md.texi (vec_reverse, vec_interleave_lo, vec_interleave_hi)
(vec_extract_even, vec_extract_odd): Document new optabs.
* internal-fn.def (VEC_INTERLEAVE_LO, VEC_INTERLEAVE_HI)
(VEC_EXTRACT_EVEN, VEC_EXTRACT_ODD, VEC_REVERSE): New internal
functions.
* optabs.def (vec_interleave_lo_optab, vec_interleave_hi_optab)
(vec_extract_even_optab, vec_extract_odd_optab, vec_reverse_optab):
New optabs.
* tree-vect-data-refs.c: Include internal-fn.h.
(vect_grouped_store_supported): Try using IFN_VEC_INTERLEAVE_{LO,HI}.
(vect_permute_store_chain): Use them here too.
(vect_grouped_load_supported): Try using IFN_VEC_EXTRACT_{EVEN,ODD}.
(vect_permute_load_chain): Use them here too.
* tree-vect-stmts.c (can_reverse_vector_p): New function.
(get_negative_load_store_type): Use it.
(reverse_vector): New function.
(vectorizable_store, vectorizable_load): Use it.
* config/aarch64/iterators.md (perm_optab): New iterator.
* config/aarch64/aarch64-sve.md (_): New expander.
(vec_reverse_): Likewise.

gcc/testsuite/
* gcc.dg/vect/no-vfa-vect-depend-2.c: Remove XFAIL.
* gcc.dg/vect/no-vfa-vect-depend-3.c: Likewise.
* gcc.dg/vect/pr33953.c: XFAIL for vect_variable_length.
* gcc.dg/vect/pr68445.c: Likewise.
* gcc.dg/vect/slp-12a.c: Likewise.
* gcc.dg/vect/slp-13-big-array.c: Likewise.
* gcc.dg/vect/slp-13.c: Likewise.
* gcc.dg/vect/slp-14.c: Likewise.
* gcc.dg/vect/slp-15.c: Likewise.
* gcc.dg/vect/slp-42.c: Likewise.
* gcc.dg/vect/slp-multitypes-2.c: Likewise.
* gcc.dg/vect/slp-multitypes-4.c: Likewise.
* gcc.dg/vect/slp-multitypes-5.c: Likewise.
* gcc.dg/vect/slp-reduc-4.c: Likewise.
* gcc.dg/vect/slp-reduc-7.c: Likewise.
* gcc.target/aarch64/sve_vec_perm_2.c: New test.
* gcc.target/aarch64/sve_vec_perm_2_run.c: Likewise.
* gcc.target/aarch64/sve_vec_perm_3.c: New test.
* gcc.target/aarch64/sve_vec_perm_3_run.c: Likewise.
* gcc.target/aarch64/sve_vec_perm_4.c: New test.
* gcc.target/aarch64/sve_vec_perm_4_run.c: Likewise.

Index: gcc/doc/md.texi
===
--- gcc/doc/md.texi 2017-11-09 13:21:01.989917982 +
+++ gcc/doc/md.texi 2017-11-09 13:21:02.323463345 +
@@ -5017,6 +5017,46 @@ There is no need for a target to supply
 and @samp{vec_perm_const@var{m}} if the former can trivially implement
 the operation with, say, the vector constant loaded into a register.
 
+@cindex @code{vec_reverse_@var{m}} instruction pattern
+@item @samp{vec_reverse_@var{m}}
+Reverse the order of the elements in vector input operand 1 and store
+the result in vector output operand 0.  Both operands have mode @var{m}.
+
+This pattern is provided mainly for targets with variable-length vectors.
+Targets with fixed-length vectors can instead handle any reverse-specific
+optimizations in @samp{vec_perm_const@var{m}}.
+
+@cindex @code{vec_interleave_lo_@var{m}} instruction pattern
+@item @samp{vec_interleave_lo_@var{m}}
+Take the lowest-indexed halves of vector input operands 1 and 2 and
+interleave the elements, so that element @var{x} of operand 1 is followed by
+element @var{x} of operand 2.  Store the result in vector output operand 0.
+All three operands have mode @var{m}.
+
+This pattern is provided mainly for targets with variable-length
+vectors.  Targets with fixed-length vectors can instead handle any
+interleave-specific optimizations in @samp{vec_perm_const@var{m}}.
+
+@cindex @code{vec_interleave_hi_@var{m}} instruction pattern
+@item @samp{vec_interleave_hi_@var{m}}
+Like @samp{vec_interleave_lo_@var{m}}, but operate on the highest-indexed
+halves instead of the lowest-indexed halves.
+
+@cindex @code{vec_extract_even_@var{m}} instruction pattern
+@item @samp{vec_extract_even_@var{m}}
+Concatenate vector input operands 1 and 2, extract the elements with
+even-numbered indices, and store the result in vector output operand 0.
+All three operands have mode @var{m}.
+
+This pattern is provided ma

Re: [PATCH 21/22] Add extra field to gtm_jmpbuf on x86 only

2017-11-09 Thread H.J. Lu
On Wed, Nov 8, 2017 at 2:57 PM, H.J. Lu  wrote:
> On Wed, Nov 8, 2017 at 2:26 PM, Tsimbalist, Igor V
>  wrote:
>>> -Original Message-
>>> From: gcc-patches-ow...@gcc.gnu.org [mailto:gcc-patches-
>>> ow...@gcc.gnu.org] On Behalf Of Jeff Law
>>> Sent: Wednesday, November 8, 2017 7:31 PM
>>> To: Tsimbalist, Igor V ; gcc-
>>> patc...@gcc.gnu.org
>>> Cc: trie...@redhat.com; Jakub Jelinek 
>>> Subject: Re: [PATCH 21/22] Add extra field to gtm_jmpbuf on x86 only
>>>
>>> On 11/07/2017 09:22 AM, Tsimbalist, Igor V wrote:
>>> > I decided to split my previous patch "Enable building libitm with Intel 
>>> > CET "
>>> > into two different patches. The first patch will add a new field to 
>>> > sjlj.S and
>>> > target.h  files. The second one will add Intel CET support on the top of 
>>> > the
>>> > first one. In this case the further changes for adding Intel CET support 
>>> > are
>>> > seen clearly.
>>> >
>>> > Ok for trunk?
>>> >
>>>
>>> [ ... snip ... ]
>>>
>>> >
>>> >
>>> > 0021-Add-extra-field-to-gtm_jmpbuf-on-x86-only.patch
>>> >
>>> >
>>> > From a6361c78bf774f2b4dbeeaf4147c286cff4ae5a4 Mon Sep 17 00:00:00
>>> 2001
>>> > From: Igor Tsimbalist 
>>> > Date: Tue, 7 Nov 2017 17:00:24 +0300
>>> > Subject: [PATCH 21/22] Add extra field to gtm_jmpbuf on x86 only
>>> >
>>> > Expand the gtm_jmpbuf structure by one word field to add
>>> > Intel CET support further. The code in sjlj.S already
>>> > allocates more space on the stack then gtm_jmpbuf needs.
>>> > Use this extra space to absorb the new field.
>>> >
>>> > The structure is allocated on the stack in such a way
>>> > that eip/rsp field is overlapped with return address on
>>> > the stack. Locate the new field right before eip/rsp so
>>> > code that accesses buffer fields relative to address of
>>> > gtm_jmpbuf has its offsets unchanged.
>>> >
>>> > The libtool_VERSION is updated for x86 due to extending
>>> > the gtm_jmpbuf structure.
>>> >
>>> > * libitm/config/x86/target.h: Add new field (ssp).
>>> > * libitm/config/x86/sjlj.S: Change offsets.
>>> > * libitm/configure.tgt: Update libtool_VERSION.
>>> So if I understand correctly, given the desire to to have the eip/rip
>>> field overlap with the return address on the stack offset changes are
>>> inevitable if we add fields.
>>
>> Yes, that's exactly the case.
>>
>>> >  esac
>>> > +
>>> > +# Update libtool_VERSION since the size of struct gtm_jmpbuf is
>>> > +# changed for x86.
>>> > +case "${host}" in
>>> > +
>>> > +  # For x86, we use slots in the TCB head for most of our TLS.
>>> > +  # The setup of those slots in beginTransaction can afford to
>>> > +  # use the global-dynamic model.
>>> > +  i[456]86-*-* | x86_64-*-*)
>>> > +   libtool_VERSION=2:0:0
>>> What's the plan for supporting existing code that may have linked
>>> dynamically against libitm?
>>
>> This should just work.
>>
>>> One approach is to force the distros to carry the old libitm DSO.
>>>
>>> THe other would be to try and support both within the same DSO using
>>> symbol versioning.  That would seem to imply that we'd need to the
>>> before/after code to build that single library that supported both.
>>>
>>> Thoughts?  Jakub, any interest in chiming in here?
>>
>> My thought is that the buffer is encapsulated in the library, only sjlj.S
>> functions allocate the buffer and access the fields of the buffer, it's
>> sort of a black box. If an app loads the library it will work with the
>> buffer through the library's functions from sjlj.S , which are compiled
>> together.
>
> It isn't the black box since gtm_jmpbuf is used in:
>
> struct gtm_transaction_cp
> {
>   gtm_jmpbuf jb;
>   size_t undolog_size;
>
> If we don't want to change libtool_VERSION, we need to add symbol
> versioning to libitm.so.  But from what I can see,  libitm.so wasn't designed
> with symbol versioning.  Instead, it changes libtool_VERSION when
> ABI is changed.
>

I was wrong on 2 counts:

1. libitm does have symbol versioning.
2. libitm does look like a black box since there is no installed header
and internal is opaque.

Igor, please do

1. Build libitm with the old gtm_jmpbuf.
2. Build libitm with the new gtm_jmpbuf and the same libtool_VERSION.
3. Replace the the old libitm with the new libitm.
4. Run libitm tetsts in the old libitm build tree.

If there are no regressions, we don't need to change libtool_VERSION.

-- 
H.J.


[PATCH], Enable fminf and fmaxf

2017-11-09 Thread Michael Meissner
In my previous patch enabling some of the built-in functions for _Float and
_FloatX datatypes, I missed making fminf128 and fmaxf128 generate the
minimum and maximum inline code when -ffast-math is used.  This patch to
match.pd enables the code generation using if-then-else if the machine does not
have an appropriate min/max instruction (the power9 hardware does not have
min/max instructions for quad floating point).

I have done builds on x86-64, little endian power8, and little endian power9
prototype systems.  All builds bootstrapped and had no regressions.  Can I
check this patch into the trunk?

[gcc]
2017-11-09  Michael Meissner  

* match.pd: Convert fminf, fminfx, fmax, and fmaxx
into the min/max operations for _Float and _FloatX types.

[gcc/testsuite]
2017-11-09  Michael Meissner  

* gcc.target/powerpc/float128-minmax.c: New test.

-- 
Michael Meissner, IBM
IBM, M/S 2506R, 550 King Street, Littleton, MA 01460-6245, USA
email: meiss...@linux.vnet.ibm.com, phone: +1 (978) 899-4797
Index: gcc/match.pd
===
--- gcc/match.pd(revision 254473)
+++ gcc/match.pd(working copy)
@@ -1723,7 +1723,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
 
 /* Simplifications of MIN_EXPR, MAX_EXPR, fmin() and fmax().  */
 
-(for minmax (min max FMIN FMAX)
+(for minmax (min max FMIN FMIN_FN FMAX FMAX_FN)
  (simplify
   (minmax @0 @0)
   @0))
@@ -1801,7 +1801,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
&& TYPE_PRECISION (TREE_TYPE (@0)) > TYPE_PRECISION (type))
(minmax @1 (convert @2)
 
-(for minmax (FMIN FMAX)
+(for minmax (FMIN FMIN_FN FMAX FMAX_FN)
  /* If either argument is NaN, return the other one.  Avoid the
 transformation if we get (and honor) a signalling NaN.  */
  (simplify
@@ -1819,11 +1819,17 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
   (FMIN @0 @1)
   (min @0 @1))
  (simplify
+  (FMIN_FN @0 @1)
+  (min @0 @1))
+ (simplify
   (FMAX @0 @1)
+  (max @0 @1))
+ (simplify
+  (FMAX_FN @0 @1)
   (max @0 @1)))
 /* min (-A, -B) -> -max (A, B)  */
-(for minmax (min max FMIN FMAX)
- maxmin (max min FMAX FMIN)
+(for minmax (min max FMIN FMIN_FN FMAX FMAX_FN)
+ maxmin (max min FMAX FMAX_FN FMIN FMAX_FN)
  (simplify
   (minmax (negate:s@2 @0) (negate:s@3 @1))
   (if (FLOAT_TYPE_P (TREE_TYPE (@0))
Index: gcc/testsuite/gcc.target/powerpc/float128-minmax.c
===
--- gcc/testsuite/gcc.target/powerpc/float128-minmax.c  (revision 0)
+++ gcc/testsuite/gcc.target/powerpc/float128-minmax.c  (revision 0)
@@ -0,0 +1,15 @@
+/* { dg-do compile { target { powerpc*-*-* && lp64 } } } */
+/* { dg-require-effective-target powerpc_p9vector_ok } */
+/* { dg-options "-mpower9-vector -O2 -ffast-math" } */
+
+#ifndef TYPE
+#define TYPE _Float128
+#endif
+
+/* Test that the fminf128/fmaxf128 functions generate if/then/else and not a
+   call.  */
+TYPE f128_min (TYPE a, TYPE b) { return __builtin_fminf128 (a, b); }
+TYPE f128_max (TYPE a, TYPE b) { return __builtin_fmaxf128 (a, b); }
+
+/* { dg-final { scan-assembler {\mxscmpuqp\M} } } */
+/* { dg-final { scan-assembler-not {\mbl\M}   } } */


Fix mismatched profile type

2017-11-09 Thread Jan Hubicka
Hi,
the testcase triggers yet another case where we do not update profile
type correctly when inter-proceduraly inlining because of 0 in the
entry_block_ptr count.

Bootstrapped/regtested x86_64-linux, will commit it shortly.

Honza

* ipa-inline-transform.c (update_noncloned_frequencies): Use
profile_count::adjust_for_ipa_scaling.
* tree-inline.c (copy_bb, copy_cfg_body): Likewise.
* profile-count.c (profile_count::adjust_for_ipa_scaling): New member
function.
* profile-count.h (profile_count::adjust_for_ipa_scaling): Declare.

* gcc.c-torture/compile/pr82879.c: New testcase.
Index: ipa-inline-transform.c
===
--- ipa-inline-transform.c  (revision 254567)
+++ ipa-inline-transform.c  (working copy)
@@ -60,17 +60,7 @@ update_noncloned_frequencies (struct cgr
 {
   struct cgraph_edge *e;
 
-  /* We always must scale to be sure counters end up compatible.
- If den is zero, just force it nonzero and hope for reasonable
- approximation.
- When num is forced nonzero, also update den, so we do not scale profile
- to 0.   */
-  if (!(num == den)
-  && !(den.force_nonzero () == den))
-{
-  den = den.force_nonzero ();
-  num = num.force_nonzero ();
-}
+  profile_count::adjust_for_ipa_scaling (&num, &den);
 
   /* We do not want to ignore high loop nest after freq drops to 0.  */
   if (!freq_scale)
Index: profile-count.c
===
--- profile-count.c (revision 254567)
+++ profile-count.c (working copy)
@@ -255,3 +255,29 @@ profile_count::to_cgraph_frequency (prof
 return CGRAPH_FREQ_MAX;
   return MIN (scale, CGRAPH_FREQ_MAX);
 }
+
+/* We want to scale profile across function boundary from NUM to DEN.
+   Take care of the side case when DEN is zeros.  We still want to behave
+   sanely here which means
+ - scale to profile_count::zero () if NUM is profile_count::zero
+ - do not affect anything if NUM == DEN
+ - preserve counter value but adjust quality in other cases.  */
+
+void
+profile_count::adjust_for_ipa_scaling (profile_count *num,
+  profile_count *den)
+{
+  /* Scaling is no-op if NUM and DEN are the same.  */
+  if (*num == *den)
+return;
+  /* Scaling to zero is always zeor.  */
+  if (*num == profile_count::zero ())
+return;
+  /* If den is non-zero we are safe.  */
+  if (den->force_nonzero () == *den)
+return;
+  /* Force both to non-zero so we do not push profiles to 0 when
+ both num == 0 and den == 0.  */
+  *den = den->force_nonzero ();
+  *num = num->force_nonzero ();
+}
Index: profile-count.h
===
--- profile-count.h (revision 254567)
+++ profile-count.h (working copy)
@@ -1044,6 +1044,11 @@ public:
   /* Return true if THIS is known to differ significantly from OTHER.  */
   bool differs_from_p (profile_count other) const;
 
+  /* We want to scale profile across function boundary from NUM to DEN.
+ Take care of the side case when NUM and DEN are zeros of incompatible
+ kinds.  */
+  static void adjust_for_ipa_scaling (profile_count *num, profile_count *den);
+
   /* LTO streaming support.  */
   static profile_count stream_in (struct lto_input_block *);
   void stream_out (struct output_block *);
Index: testsuite/gcc.c-torture/compile/pr82879.c
===
--- testsuite/gcc.c-torture/compile/pr82879.c   (revision 0)
+++ testsuite/gcc.c-torture/compile/pr82879.c   (working copy)
@@ -0,0 +1,11 @@
+int a, b;
+static __attribute__((cold)) void fn1() {
+  for (;;)
+for (; a;)
+  ;
+}
+void fn2() {
+  if (b)
+fn1();
+}
+
Index: tree-inline.c
===
--- tree-inline.c   (revision 254567)
+++ tree-inline.c   (working copy)
@@ -1771,17 +1771,7 @@ copy_bb (copy_body_data *id, basic_block
   tree decl;
   basic_block prev;
 
-  /* We always must scale to be sure counters end up compatible.
- If den is zero, just force it nonzero and hope for reasonable
- approximation.
- When num is forced nonzero, also update den, so we do not scale profile
- to 0.   */
-  if (!(num == den)
-  && !(den.force_nonzero () == den))
-{
-  den = den.force_nonzero ();
-  num = num.force_nonzero ();
-}
+  profile_count::adjust_for_ipa_scaling (&num, &den);
 
   /* Search for previous copied basic block.  */
   prev = bb->prev_bb;
@@ -2698,17 +2688,7 @@ copy_cfg_body (copy_body_data * id, prof
   profile_count den = ENTRY_BLOCK_PTR_FOR_FN (src_cfun)->count;
   profile_count num = entry_block_map->count;
 
-  /* We always must scale to be sure counters end up compatible.
- If den is zero, just force it nonzero and hope for reasonable
- approximation.
- When num is forced nonzero, al

[Ada] Variable reads and writes

2017-11-09 Thread Pierre-Marie de Rodat
This patch adds processing for N_Variable_Reference_Marker nodes to the
transformation phase of gigi.

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

2017-11-09  Hristian Kirtchev  

* gcc-interface/trans.c (gnat_to_gnu): Add processing for
N_Variable_Reference_Marker nodes.

Index: gcc-interface/trans.c
===
--- gcc-interface/trans.c   (revision 254580)
+++ gcc-interface/trans.c   (working copy)
@@ -7695,12 +7695,12 @@
 /* Added Nodes  */
 //
 
-/* Call markers are created by the ABE mechanism to capture the target of
-   a call along with other elaboration-related attributes which are either
-   unavailable of expensive to recompute.  Call markers do not have static
-   and runtime semantics, and should be ignored. */
+/* Markers are created by the ABE mechanism to capture information which
+   is either unavailable of expensive to recompute.  Markers do not have
+   and runtime semantics, and should be ignored.  */
 
 case N_Call_Marker:
+case N_Variable_Reference_Marker:
   gnu_result = alloc_stmt_list ();
   break;
 


Handle more SLP constant and extern definitions for variable VF

2017-11-09 Thread Richard Sandiford
This patch adds support for vectorising SLP definitions that are
constant or external (i.e. from outside the loop) when the vectorisation
factor isn't known at compile time.  It can only handle cases where the
number of SLP statements is a power of 2.

Tested on aarch64-linux-gnu (with and without SVE), x86_64-linux-gnu
and powerpc64le-linux-gnu.  OK to install?

Richard


2017-11-09  Richard Sandiford  
Alan Hayward  
David Sherwood  

gcc/
* tree-vect-slp.c: Include gimple-fold.h and internal-fn.h
(can_duplicate_and_interleave_p): New function.
(vect_get_and_check_slp_defs): Take the vector of statements
rather than just the current one.  Remove excess parentheses.
Restriction rejectinon of vect_constant_def and vect_external_def
for variable-length vectors to boolean types, or types for which
can_duplicate_and_interleave_p is false.
(vect_build_slp_tree_2): Update call to vect_get_and_check_slp_defs.
(duplicate_and_interleave): New function.
(vect_get_constant_vectors): Use gimple_build_vector for
constant-length vectors and duplicate_and_interleave for
variable-length vectors.  Don't defer the update when
inserting new statements.

gcc/testsuite/
* gcc.dg/vect/no-scevccp-slp-30.c: Don't XFAIL for vect_variable_length
&& vect_load_lanes
* gcc.dg/vect/slp-1.c: Likewise.
* gcc.dg/vect/slp-10.c: Likewise.
* gcc.dg/vect/slp-12b.c: Likewise.
* gcc.dg/vect/slp-12c.c: Likewise.
* gcc.dg/vect/slp-17.c: Likewise.
* gcc.dg/vect/slp-19b.c: Likewise.
* gcc.dg/vect/slp-20.c: Likewise.
* gcc.dg/vect/slp-21.c: Likewise.
* gcc.dg/vect/slp-22.c: Likewise.
* gcc.dg/vect/slp-24-big-array.c: Likewise.
* gcc.dg/vect/slp-24.c: Likewise.
* gcc.dg/vect/slp-28.c: Likewise.
* gcc.dg/vect/slp-39.c: Likewise.
* gcc.dg/vect/slp-6.c: Likewise.
* gcc.dg/vect/slp-7.c: Likewise.
* gcc.dg/vect/slp-cond-1.c: Likewise.
* gcc.dg/vect/slp-cond-2-big-array.c: Likewise.
* gcc.dg/vect/slp-cond-2.c: Likewise.
* gcc.dg/vect/slp-multitypes-1.c: Likewise.
* gcc.dg/vect/slp-multitypes-8.c: Likewise.
* gcc.dg/vect/slp-multitypes-9.c: Likewise.
* gcc.dg/vect/slp-multitypes-10.c: Likewise.
* gcc.dg/vect/slp-multitypes-12.c: Likewise.
* gcc.dg/vect/slp-perm-6.c: Likewise.
* gcc.dg/vect/slp-widen-mult-half.c: Likewise.
* gcc.dg/vect/vect-live-slp-1.c: Likewise.
* gcc.dg/vect/vect-live-slp-2.c: Likewise.
* gcc.dg/vect/pr33953.c: Don't XFAIL for vect_variable_length.
* gcc.dg/vect/slp-12a.c: Likewise.
* gcc.dg/vect/slp-14.c: Likewise.
* gcc.dg/vect/slp-15.c: Likewise.
* gcc.dg/vect/slp-multitypes-2.c: Likewise.
* gcc.dg/vect/slp-multitypes-4.c: Likewise.
* gcc.dg/vect/slp-multitypes-5.c: Likewise.
* gcc.target/aarch64/sve_slp_1.c: New test.
* gcc.target/aarch64/sve_slp_1_run.c: Likewise.
* gcc.target/aarch64/sve_slp_2.c: Likewise.
* gcc.target/aarch64/sve_slp_2_run.c: Likewise.
* gcc.target/aarch64/sve_slp_3.c: Likewise.
* gcc.target/aarch64/sve_slp_3_run.c: Likewise.
* gcc.target/aarch64/sve_slp_4.c: Likewise.
* gcc.target/aarch64/sve_slp_4_run.c: Likewise.

Index: gcc/tree-vect-slp.c
===
--- gcc/tree-vect-slp.c 2017-11-09 14:16:43.320866086 +
+++ gcc/tree-vect-slp.c 2017-11-09 14:16:43.816866116 +
@@ -41,6 +41,8 @@ Software Foundation; either version 3, o
 #include "langhooks.h"
 #include "gimple-walk.h"
 #include "dbgcnt.h"
+#include "gimple-fold.h"
+#include "internal-fn.h"
 
 
 /* Recursively free the memory allocated for the SLP tree rooted at NODE.  */
@@ -206,24 +208,69 @@ vect_get_place_in_interleaving_chain (gi
   return -1;
 }
 
+/* Check whether it is possible to load COUNT elements of type ELT_MODE
+   using the method implemented by duplicate_and_interleave.  Return true
+   if so, returning the number of intermediate vectors in *NVECTORS_OUT
+   (if nonnull) and the type of each intermediate vector in *VECTOR_TYPE_OUT
+   (if nonnull).  */
+
+static bool
+can_duplicate_and_interleave_p (unsigned int count, machine_mode elt_mode,
+   unsigned int *nvectors_out = NULL,
+   tree *vector_type_out = NULL)
+{
+  poly_int64 elt_bytes = count * GET_MODE_SIZE (elt_mode);
+  poly_int64 nelts;
+  unsigned int nvectors = 1;
+  for (;;)
+{
+  scalar_int_mode int_mode;
+  poly_int64 elt_bits = elt_bytes * BITS_PER_UNIT;
+  if (multiple_p (current_vector_size, elt_bytes, &nelts)
+ && int_mode_for_size (elt_bits, 0).exists (&int_mode))
+   {
+ tree int_type = build_nonstandard_integer_type
+   (GET_MODE_BITSIZE (int_

Re: [PATCH] Fix up store_merging_13.c FAIL

2017-11-09 Thread Marc Glisse

On Thu, 9 Nov 2017, Jakub Jelinek wrote:


The gcc.dg/store_merging_13.c testcase worked when I was bootstrapping the
patch that introduced it, but doesn't anymore, because match.pd had
a ~X ^ Y -> ~(X ^ Y) transformation, the code was handling only ~ on
the loads (== arguments of &/|/^) but not on the result of the bitwise
binary operation.


Sorry about that. If this canonicalization causes too much trouble, we 
could revert it (it isn't important to me). Although it looks like you 
managed to extend the store merging code nicely instead :-)


--
Marc Glisse


Re: [PATCH, GCC/ARM] Fix cmse_nonsecure_entry return insn size

2017-11-09 Thread Kyrill Tkachov

Hi Thomas,

On 08/11/17 09:50, Thomas Preudhomme wrote:

Hi,

A number of instructions are output in assembler form by
output_return_instruction () when compiling a function with the
cmse_nonsecure_entry attribute for Armv8-M Mainline with hardfloat float
ABI. However, the corresponding thumb2_cmse_entry_return insn pattern
does not account for all these instructions in its computing of the
length of the instruction.

This may lead GCC to use the wrong branching instruction due to
incorrect computation of the offset between the branch instruction's
address and the target address.

This commit fixes the mismatch between what output_return_instruction ()
does and what the pattern think it does and adds a note warning about
mismatch in the affected functions' heading comments to ensure code does
not get out of sync again.

Note: no test is provided because the C testcase is fragile (only works
on GCC 6) and the extracted RTL test fails to compile due to bugs in the
RTL frontend (PR82815 and PR82817)

ChangeLog entries are as follows:

*** gcc/ChangeLog ***

2017-10-30  Thomas Preud'homme 

* config/arm/arm.c (output_return_instruction): Add comments to
indicate requirement for cmse_nonsecure_entry return to account
for the size of clearing instruction output here.
(thumb_exit): Likewise.
* config/arm/thumb2.md (thumb2_cmse_entry_return): Fix length for
return in hardfloat mode.

Testing: Bootstrapped on arm-linux-gnueabihf and testsuite shows no
regression.

Is this ok for trunk?



Ok for trunk and for the branches after a few days.
Thanks,
Kyrill


Best regards,

Thomas




Re: [GCC-6.4][ARM][PATCH v2] enable FL_LPAE flag for armv7ve cores

2017-11-09 Thread Kyrill Tkachov


On 08/11/17 19:21, Andre McCurdy wrote:

The following commit added the FL_LPAE flag to FL_FOR_ARCH7VE, but
neglected to also add it to the armv7ve compatible cores defined in
arm-cores.def.

https://github.com/gcc-mirror/gcc/commit/af2d9b9e58e8be576c53d94f30c48c68146b0c98

The result is that gcc 6.4 now refuses to allow -march=armv7ve and
-mcpu=XXX to be used together, even when -mcpu is set to an armv7ve
compatible core:

  arm-linux-gnueabi-gcc -march=armv7ve -mcpu=cortex-a7 -Werror ...
  error: switch -mcpu=cortex-a7 conflicts with -march=armv7ve switch 
[-Werror]


This is a regression relative to gcc 6.3.

Fix by defining flags for armv7ve compatible cores directly from
FL_FOR_ARCH7VE, rather than re-creating the armv7ve flags
independently by combining FL_FOR_ARCH7A with the armv7ve specific
FL_THUMB_DIV and FL_ARM_DIV flags.



Thanks Andre. I have bootstrapped and tested your patch on 
arm-none-linux-gnueabihf

and committed it to the GCC 6 branch on your behalf with r254584 [1].

If you expect to contribute more to GCC in the future I recommend
you consider going through the FSF copyright assignment process [2].
This patch is small enough to not need a copyright assignment, but more
substantial changes will require one.

Thank you for the patch!
Kyrill

[1] https://gcc.gnu.org/viewcvs/gcc?view=revision&revision=254584
[2] https://gcc.gnu.org/contribute.html



Re: [PATCH 1/2] Moving parameter manipulation into its own file

2017-11-09 Thread Jan Hubicka

Dne 2017-11-08 21:54, Martin Jambor napsal:

Hi,

the following patch moves all function and call parameter manipulation
(as opposed to analysis) data structures and functions from ipa-prop.h
and ipa-prop.c to new files ipa-param-manipulation.h and
ipa-param-manipulation.c respectively.  It does no functional change.

Please look at the followup patch if you'd like to see where I am
heading with this.  While I am willing to hold up the followup patch
for GCC 9, I would like to commit this now because it increases
modularity in an area where it is needed.

Bootstrapped and teste on x86_64-linux.  OK for trunk?

Martin


2017-08-23  Martin Jambor  

* ipa-param-manipulation.c: New file.
* ipa-param-manipulation.h: Likewise.
* Makefile.in (OBJS): Add ipa-param-manipulation.o.
(PLUGIN_HEADERS): Addded ipa-param-manipulation.h
* ipa-param.h (ipa_parm_op): Moved to ipa-param-manipulation.h.
(ipa_parm_adjustment): Likewise.
(ipa_parm_adjustment_vec): Likewise.
(ipa_get_vector_of_formal_parms): Moved declaration to
ipa-param-manipulation.h.
(ipa_get_vector_of_formal_parm_types): Likewise.
(ipa_modify_formal_parameters): Likewise.
(ipa_modify_call_arguments): Likewise.
(ipa_combine_adjustments): Likewise.
(ipa_dump_param_adjustments): Likewise.
(ipa_modify_expr): Likewise.
(ipa_get_adjustment_candidate): Likewise.
* ipa-prop.c (ipa_get_vector_of_formal_parms): Moved to
ipa-param-manipulation.c.
(ipa_get_vector_of_formal_parm_types): Likewise.
(ipa_modify_formal_parameters): Likewise.
(ipa_modify_call_arguments): Likewise.
(ipa_modify_expr): Likewise.
(get_ssa_base_param): Likewise.
(ipa_get_adjustment_candidate): Likewise.
(index_in_adjustments_multiple_times_p): Likewise.
(ipa_combine_adjustments): Likewise.
(ipa_dump_param_adjustments): Likewise.
* tree-sra.c: Also include ipa-param-manipulation.h
* omp-simd-clone.c: Include ipa-param-manipulation.h instead of
ipa-param.h.


OK,
thanks!
Honza



Re: [PATCH 1/7] GCOV: introduce global vector of functions

2017-11-09 Thread Nathan Sidwell

On 11/09/2017 05:24 AM, marxin wrote:

gcc/ChangeLog:

2017-11-09  Martin Liska  

* gcov.c (read_graph_file): Store to global vector of functions.
(read_count_file): Iterate the vector.
(process_file): Likewise.
(generate_results): Likewise.
(release_structures): Likewise.



ok


--
Nathan Sidwell


Re: [PATCH 2/7] GCOV: simplify usage of function_info::artificial.

2017-11-09 Thread Nathan Sidwell

On 11/09/2017 05:24 AM, marxin wrote:

gcc/ChangeLog:

2017-11-09  Martin Liska  

* gcov.c (is_artificial): New function.
(process_file): Erase all artificial early.
(generate_results): Skip as all artificial are already
removed.
---
  gcc/gcov.c | 66 +-
  1 file changed, 40 insertions(+), 26 deletions(-)

diff --git a/gcc/gcov.c b/gcc/gcov.c
index 83239639247..3dc159726c7 100644
--- a/gcc/gcov.c
+++ b/gcc/gcov.c
@@ -1088,6 +1088,14 @@ struct function_start_pair_hash : typed_noop_remove 

}
  };
  
+/* Function filter based on function_info::artificial variable.  */

+
+static bool
+is_artificial (function_info *fn)
+{
+  return fn->artificial;
+}


couldn't this be a member fn of function_info?


--
Nathan Sidwell


Re: [PATCH 3/7] GCOV: introduce vector for function_info::counts.

2017-11-09 Thread Nathan Sidwell

On 11/09/2017 05:24 AM, marxin wrote:

gcc/ChangeLog:

2017-11-09  Martin Liska  

* gcov.c (function_info::function_info): Remove num_counts
and add vector.
(function_info::~function_info): Use the vector.
(process_file): Likewise.
(read_graph_file): Likewise.
(read_count_file): Likewise.
(solve_flow_graph): Likewise.


ok


--
Nathan Sidwell


Re: [PATCH 4/7] GCOV: remove typedef for function_t

2017-11-09 Thread Nathan Sidwell

On 11/09/2017 05:24 AM, marxin wrote:

gcc/ChangeLog:

2017-11-09  Martin Liska  

* gcov.c (struct function_info): Remove typedef for function_t.
(struct source_info): Likewise.
(source_info::get_functions_at_location): Likewise.
(solve_flow_graph): Likewise.
(find_exception_blocks): Likewise.
(add_line_counts): Likewise.
(output_intermediate_file): Likewise.
(process_file): Likewise.
(generate_results): Likewise.
(release_structures): Likewise.
(read_graph_file): Likewise.
(read_count_file): Likewise.
(accumulate_line_counts): Likewise.
(output_lines): Likewise.


ok


--
Nathan Sidwell


Re: [PATCH 5/7] GCOV: remove typedef for arc_t

2017-11-09 Thread Nathan Sidwell

On 11/09/2017 05:24 AM, marxin wrote:

gcc/ChangeLog:

2017-11-09  Martin Liska  

* gcov.c (struct arc_info): Remove typedef for arc_t.
(struct line_info): Likewise.
(add_branch_counts): Likewise.
(output_branch_count): Likewise.
(function_info::~function_info): Likewise.
(circuit): Likewise.
(output_intermediate_line): Likewise.
(read_graph_file): Likewise.
(solve_flow_graph): Likewise.
(find_exception_blocks): Likewise.
(add_line_counts): Likewise.
(accumulate_line_info): Likewise.
(output_line_details): Likewise.
(output_function_details): Likewise.


ok


--
Nathan Sidwell


Re: [PATCH] Fix up store_merging_13.c FAIL

2017-11-09 Thread Richard Biener
On Thu, 9 Nov 2017, Jakub Jelinek wrote:

> Hi!
> 
> The gcc.dg/store_merging_13.c testcase worked when I was bootstrapping the
> patch that introduced it, but doesn't anymore, because match.pd had
> a ~X ^ Y -> ~(X ^ Y) transformation, the code was handling only ~ on
> the loads (== arguments of &/|/^) but not on the result of the bitwise
> binary operation.  The following patch handles inversion of the result
> too, after all even ~X & ~Y is ~(X | Y) and ~X | ~Y is ~(X & Y).
> In addition to this, I've added just in case some earlier passes wouldn't
> do good enough job a check that we don't recognize
> _1 = load; _2 = ~1; _3 = ~1; store = _3; and similar (or arbitrarily more
> chained BIT_NOT_EXPRs), while we'd emit a working code, the has_single_use
> accounting wouldn't be prepared for more than one BIT_NOT_EXPR on one
> operand.
> 
> Ok for trunk if it passes bootstrap/regtest?

Nice.

Ok.
Thanks,
Richard.

> Just managed to reproduce the profiledbootstrap issue, so working on that
> next.
> 
> 2017-11-09  Jakub Jelinek  
> 
>   * gimple-ssa-store-merging.c (struct store_immediate_info): Add
>   bit_not_p field.
>   (store_immediate_info::store_immediate_info): Add bitnotp argument,
>   set bit_not_p to it.
>   (imm_store_chain_info::coalesce_immediate_stores): Break group
>   if bit_not_p is different.
>   (count_multiple_uses, split_group,
>   imm_store_chain_info::output_merged_store): Handle info->bit_not_p.
>   (handled_load): Avoid multiple chained BIT_NOT_EXPRs.
>   (pass_store_merging::process_store): Handle BIT_{AND,IOR,XOR}_EXPR
>   result inverted using BIT_NOT_EXPR, compute bit_not_p, pass it
>   to store_immediate_info ctor.
> 
> --- gcc/gimple-ssa-store-merging.c.jj 2017-11-09 12:40:27.0 +0100
> +++ gcc/gimple-ssa-store-merging.c2017-11-09 14:00:46.269673305 +0100
> @@ -209,12 +209,13 @@ struct store_immediate_info
>/* INTEGER_CST for constant stores, MEM_REF for memory copy or
>   BIT_*_EXPR for logical bitwise operation.  */
>enum tree_code rhs_code;
> +  bool bit_not_p;
>/* Operands.  For BIT_*_EXPR rhs_code both operands are used, otherwise
>   just the first one.  */
>store_operand_info ops[2];
>store_immediate_info (unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT,
>   unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT,
> - gimple *, unsigned int, enum tree_code,
> + gimple *, unsigned int, enum tree_code, bool,
>   const store_operand_info &,
>   const store_operand_info &);
>  };
> @@ -226,10 +227,11 @@ store_immediate_info::store_immediate_in
>   gimple *st,
>   unsigned int ord,
>   enum tree_code rhscode,
> + bool bitnotp,
>   const store_operand_info &op0r,
>   const store_operand_info &op1r)
>: bitsize (bs), bitpos (bp), bitregion_start (brs), bitregion_end (bre),
> -stmt (st), order (ord), rhs_code (rhscode)
> +stmt (st), order (ord), rhs_code (rhscode), bit_not_p (bitnotp)
>  #if __cplusplus >= 201103L
>  , ops { op0r, op1r }
>  {
> @@ -1169,7 +1171,8 @@ imm_store_chain_info::coalesce_immediate
>Merge it into the current store group.  There can be gaps in between
>the stores, but there can't be gaps in between bitregions.  */
>else if (info->bitregion_start <= merged_store->bitregion_end
> -&& info->rhs_code == merged_store->stores[0]->rhs_code)
> +&& info->rhs_code == merged_store->stores[0]->rhs_code
> +&& info->bit_not_p == merged_store->stores[0]->bit_not_p)
>   {
> store_immediate_info *infof = merged_store->stores[0];
>  
> @@ -1386,6 +1389,17 @@ count_multiple_uses (store_immediate_inf
>  case BIT_AND_EXPR:
>  case BIT_IOR_EXPR:
>  case BIT_XOR_EXPR:
> +  if (info->bit_not_p)
> + {
> +   if (!has_single_use (gimple_assign_rhs1 (stmt)))
> + ret = 1; /* Fall through below to return
> + the BIT_NOT_EXPR stmt and then
> + BIT_{AND,IOR,XOR}_EXPR and anything it
> + uses.  */
> +   else
> + /* stmt is after this the BIT_NOT_EXPR.  */
> + stmt = SSA_NAME_DEF_STMT (gimple_assign_rhs1 (stmt));
> + }
>if (!has_single_use (gimple_assign_rhs1 (stmt)))
>   {
> ret += 1 + info->ops[0].bit_not_p;
> @@ -1479,6 +1493,8 @@ split_group (merged_store_group *group,
>   case BIT_AND_EXPR:
>   case BIT_IOR_EXPR:
>   case BIT_XOR_EXPR:
> +   if (info->bit_not_p)
> + total_orig[0]++; /* The orig BIT_NOT_EXPR stmt.  */
> total_orig[0]++; /* The orig BIT_*_EXPR stmt.  */
> break;
>   default:
> @@ -1649,6 +1665,8 @

Re: [PATCH 7/7] GCOV: remove typedef of coverage_t.

2017-11-09 Thread Nathan Sidwell

On 11/09/2017 05:24 AM, marxin wrote:

gcc/ChangeLog:

2017-11-09  Martin Liska  

* gcov.c (struct coverage_info): Remove typedef of coverage_t.
(struct source_info): Likewise.
(add_branch_counts): Likewise.
(add_line_counts): Likewise.
(function_summary): Likewise.
(output_intermediate_line): Likewise.
(generate_results): Likewise.


ok


--
Nathan Sidwell


Re: [PATCH 6/7] GCOV: remove typedef for block_t

2017-11-09 Thread Nathan Sidwell

On 11/09/2017 05:24 AM, marxin wrote:

gcc/ChangeLog:

2017-11-09  Martin Liska  

* gcov.c (struct block_info): Remove typedef for block_t.
(struct line_info): Likewise.
(line_info::has_block): Likewise.
(EXIT_BLOCK): Likewise.
(unblock): Likewise.
(circuit): Likewise.
(get_cycles_count): Likewise.
(process_file): Likewise.
(read_graph_file): Likewise.
(solve_flow_graph): Likewise.
(find_exception_blocks): Likewise.
(add_line_counts): Likewise.
(accumulate_line_info): Likewise.
(output_line_details): Likewise.


ok


--
Nathan Sidwell


[PATCH] GCOV: create one intermediate file per a gcno file (PR gcov-profile/82702).

2017-11-09 Thread Nathan Sidwell

https://gcc.gnu.org/ml/gcc-patches/2017-10/msg02337.html

sorry for dropping this one.

looks good, except:

-  for (; argno != argc; argno++)
+  if (flag_intermediate_format)
 {
-  if (flag_display_progress)
-   printf ("Processing file %d out of %d\n", argno - first_arg + 1,
-   argc - first_arg);
-  process_file (argv[argno]);
+  for (; argno != argc; argno++)
+   {
+ if (flag_display_progress)
+   printf ("Processing file %d out of %d\n", argno - first_arg + 1,
+   argc - first_arg);
+ process_file (argv[argno]);
+ generate_results (argv[argno]);
+ release_structures ();
+   }
 }
+  else
+{
+  for (; argno != argc; argno++)
+   {
+ if (flag_display_progress)
+   printf ("Processing file %d out of %d\n", argno - first_arg + 1,
+   argc - first_arg);
+ process_file (argv[argno]);
+   }


looks like a manually unswitched loop.  Isn't

for (... )
  {
if (...)
  printf ...
process_file (...)
if (flag_intermediate_files)
  {
 generate_results (...);
 release_structures ();
  }
}

clearer?
--
Nathan Sidwell


Re: Adjust empty class parameter passing ABI (PR c++/60336)

2017-11-09 Thread Marek Polacek
On Wed, Nov 08, 2017 at 09:06:51AM +0100, Richard Biener wrote:
> > >> >> > + if (TREE_CODE (field) == FIELD_DECL
> > >> >> > + && (DECL_NAME (field)
> > >> >> > + || RECORD_OR_UNION_TYPE_P (TREE_TYPE (field)))
> > >> >> > + && !default_is_empty_type (TREE_TYPE (field)))
> > >> >> > +return false;
> > >> >> > +  return true;
> > >> >>
> > >> >> Hmm, this assumes that any unnamed field can be ignored; I'm concerned
> > >> >> that some front end might clear DECL_NAME for a reason that doesn't
> > >> >> imply that the field is just padding.
> > >> >
> > >> > In that case I guess we need a new lang hook, right?  Because in
> > >> > default_is_empty_type we can't check FE-specific flags such as
> > >> > DECL_C_BIT_FIELD.  For C++, should that lang hook be just
> > >> > is_really_empty_class?  Or is there anything else I can do?
> > >>
> > >> Hmm, maybe leave it as it is and just document this assumption about
> > >> FIELD_DECL with null DECL_NAME, both here and in tree.def.
> > >
> > > But are you sure you are not changing the ABI for a language other
> > > than C++ then?
> > 
> > No, that is the concern, we'd need to check that.
> > 
> > > I don't think DECL_NAME has any special meaning - why
> > > not check DECL_ARTIFICIAL or another flag that has appropriate
> > > semantic - _what_ semantic are you looking for after all?
> > 
> > That a struct consisting only of padding is considered empty.
> > 
> > Perhaps we could use decl_flag_3 on FIELD_DECL for DECL_PADDING_P to
> > indicate that a field isn't really data.  Or perhaps we should remove
> > such things from TYPE_FIELDS after layout is done.
> 
> Both works for me.  As said I'd rather not use NULL DECL_NAME - backends
> might build record types without names for va_list.  There's no
> technical reason to have a DECL_NAME for sth the user cannot access -
> which means every DECL_ARTIFICIAL entity.  This patch would 
> retroactively introduce one and thus we'd have to audit each and
> every piece of code building record types...

Done in the below, hopefully.  I only had to set DECL_PADDING_P on unnamed
bit-fields.  I've added testcases for zero-sized unnamed bit-fields as well
as for classes with virtual functions.

Moving TYPE_EMPTY_P to finalize_type_size revealed a bug in Cilk+, it was
bogusly (I believe) setting TREE_ADDRESSABLE, so the assert fired.  Since
Cilk+ is being deprecated and the Cilk+ testsuite still passes, I'm not
too worried about this change.

So if you're fine with the DECL_PADDING_P change, all that remains is to
check whether this patch is not changing the ABI for other languages than
C++.  I suppose one way to check that could be to do sth like

  if (strncmp (lang_hooks.name, "GNU C++", 7))
{FILE *f=fopen("/tmp/A", 
"a");fprintf(f,"%s\n",main_input_filename);fclose(f);}

and compare the assembly of the files it prints?  But there were thousands of
them I think :(.

Bootstrapped/regtested on x86_64-linux and ppc64-linux.

2017-11-09  Marek Polacek  
H.J. Lu  
Jason Merrill  

PR c++/60336
PR middle-end/67239
PR target/68355
* c-decl.c (grokdeclarator): Set DECL_PADDING_P on unnamed bit-fields.

* class.c (layout_class_type): Set DECL_PADDING_P on padding.
* decl.c (cxx_init_decl_processing): Set TRANSLATION_UNIT_WARN_EMPTY_P.
(grokdeclarator): Set DECL_PADDING_P on unnamed bit-fields.

* lto.c (compare_tree_sccs_1): Compare TYPE_EMPTY_P and DECL_PADDING_P.

* calls.c (initialize_argument_information): Call
warn_parameter_passing_abi target hook.
(store_one_arg): Use 0 for empty record size.  Don't push 0 size
argument onto stack.
(must_pass_in_stack_var_size_or_pad): Return false for empty types.
* cilk-common.c (cilk_init_builtins): Don't set TREE_ADDRESSABLE.
* common.opt: Update -fabi-version description.
* config/i386/i386.c (init_cumulative_args): Set cum->warn_empty.
(ix86_return_in_memory): Return false for empty types.
(ix86_gimplify_va_arg): Call arg_int_size_in_bytes instead of
int_size_in_bytes.
(ix86_is_empty_record): New function.
(ix86_warn_parameter_passing_abi): New function.
(TARGET_EMPTY_RECORD_P): Redefine.
(TARGET_WARN_PARAMETER_PASSING_ABI): Redefine.
* config/i386/i386.h (CUMULATIVE_ARGS): Add warn_empty.
* doc/tm.texi: Regenerated.
* doc/tm.texi.in (TARGET_EMPTY_RECORD_P,
TARGET_WARN_PARAMETER_PASSING_ABI): Add.
* explow.c (hard_function_value): Call arg_int_size_in_bytes
instead of int_size_in_bytes.
* expr.c (copy_blkmode_to_reg): Likewise.
* function.c (assign_parm_find_entry_rtl): Call
warn_parameter_passing_abi target hook.
(locate_and_pad_parm): Call arg size_in_bytes instead
size_in_bytes.
* lto-streamer-out.c (hash_tree): Hash TYPE_EMPTY_P and DECL_PADDING_P.
* stor-layout.

Re: [PATCH] 1/n Refactoring tree-vrp.c, step one introducing vr_values class

2017-11-09 Thread Richard Biener
On Wed, Nov 8, 2017 at 1:53 PM, Trevor Saunders  wrote:
> On Tue, Nov 07, 2017 at 02:03:19PM -0700, Jeff Law wrote:
>> So this is the first step in pulling apart tree-vrp.c.  As outlined in
>> an earlier message the goal of this patch is just to get the vr_values
>> class introduced.  I've tried (and mostly succeeded) in avoiding doing
>> significant cleanups/rewrites at this point to make reviewing this step
>> easier.
>>
>> The vast majority of this patch is just changing functions from free
>> functions to member functions in the appropriate class (primarily
>> vr_values), pulling the appropriate static objects into that class and
>> adding the temporary delegators to minimize diffs at this stage.
>> Exceptions to this:
>>
>> set_value_range changes how we get at the obstack for allocating
>> bitmaps.  This was discussed on-list recently.  Similarly in
>> vrp_intersect_ranges_1.
>>
>> extract_range_from_unary_expr has two implementations.  One is within
>> the vr_values class which calls out to the freestanding function.  Hence
>> the ::extract_range_from_unary_expr.
>>
>> We drop debug_all_value_ranges.  It doesn't make sense in a world where
>> the value ranges are attached to a class instance.  There is still a
>> method to dump all the value ranges within the class instance.
>>
>> The vrp_prop and vrp_folder class definitions have to move to earlier
>> points in the file.
>>
>> We pass a vrp_prop class instance through the gimple walkers using the
>> wi->info field.  check_all_array_refs sets that up and we recover the
>> class instance pointer in the check_array_bounds callback.
>>
>> I wasn't up to converting the gimple folder to classes at this time.  So
>> we set/wipe x_vr_values (file scoped static) around the calls into the
>> gimple walkers and recover the vr_values class instance from x_vr_values
>> within vrp_valueize and vrp_valueize_1.
>>
>> I use a similar hack to recover the vr_values instance in the callback
>> to simplify a statement for jump threading.  This code is on the
>> chopping block -- I expect it all to just disappear shortly.  Similarly
>> I just pass in vr_values to identify_jump_threads.  Again, I expect to
>> be removing all this code shortly and wanted to keep this as simple as
>> possible rather than waste time cleaning up code I'm just going to remove.
>>
>> I did do some simplifications in vrp_finalize.  It wanted to access
>> vr_value and num_vr_values directly.  Now it goes through the
>> get_value_range interface.
>>
>> I introduced a set_value_range_ member function in vr_values, then
>> twiddled a couple evrp routines to use that rather than access vr_value
>> directly.
>>
>> In a few places I didn't bother creating delegators.  The delegators
>> wouldn't have simplified anything.  See execute_vrp and execute_early_vrp.
>>
>> You'll note the vr_values class is large.  I've tried to avoid the
>> temptation to start simplifying stuff and instead try to stick with
>> moving routines into the appropriate class based on the code as it
>> stands right now.  The size of vr_values is probably a good indicator
>> that it's doing too much.
>>
>> As suggested yesterday, I've added various delegator methods to the
>> classes to minimize code churn at this time.  I suspect we're going to
>> want to remove most, if not all of them.  But again, the goal in this
>> patch is to get the class structure in place with minimal amount of
>> collateral damage to make this step easy to review.
>
> Yeah, this all looks pretty reasonable, ime breaking things also helps
> when writing the patch and you break something since there's less to
> undo before getting to a working state.  If anything I would have broken
> this up even more, moving the existing classes up can probably be its
> own thing, as well as the use of equiv->obstack.

Patch looks good to me.  I saw

+  void set_value_range_ (tree, value_range *);

and when seeing uses I thought temporary hack because of that
"SSA_NAME_VERSION > length" check but then there's no
set_value_range () function (without _) (or I missed it).  Can you just
remove the _ or add a comment?

There's excess vertical space at the end of the vr_values class.

Otherwise ok.  No need to split up further.

Thanks,
Richard.

> Trev
>


Re: Adjust empty class parameter passing ABI (PR c++/60336)

2017-11-09 Thread Richard Biener
On Thu, 9 Nov 2017, Marek Polacek wrote:

> On Wed, Nov 08, 2017 at 09:06:51AM +0100, Richard Biener wrote:
> > > >> >> > + if (TREE_CODE (field) == FIELD_DECL
> > > >> >> > + && (DECL_NAME (field)
> > > >> >> > + || RECORD_OR_UNION_TYPE_P (TREE_TYPE (field)))
> > > >> >> > + && !default_is_empty_type (TREE_TYPE (field)))
> > > >> >> > +return false;
> > > >> >> > +  return true;
> > > >> >>
> > > >> >> Hmm, this assumes that any unnamed field can be ignored; I'm 
> > > >> >> concerned
> > > >> >> that some front end might clear DECL_NAME for a reason that doesn't
> > > >> >> imply that the field is just padding.
> > > >> >
> > > >> > In that case I guess we need a new lang hook, right?  Because in
> > > >> > default_is_empty_type we can't check FE-specific flags such as
> > > >> > DECL_C_BIT_FIELD.  For C++, should that lang hook be just
> > > >> > is_really_empty_class?  Or is there anything else I can do?
> > > >>
> > > >> Hmm, maybe leave it as it is and just document this assumption about
> > > >> FIELD_DECL with null DECL_NAME, both here and in tree.def.
> > > >
> > > > But are you sure you are not changing the ABI for a language other
> > > > than C++ then?
> > > 
> > > No, that is the concern, we'd need to check that.
> > > 
> > > > I don't think DECL_NAME has any special meaning - why
> > > > not check DECL_ARTIFICIAL or another flag that has appropriate
> > > > semantic - _what_ semantic are you looking for after all?
> > > 
> > > That a struct consisting only of padding is considered empty.
> > > 
> > > Perhaps we could use decl_flag_3 on FIELD_DECL for DECL_PADDING_P to
> > > indicate that a field isn't really data.  Or perhaps we should remove
> > > such things from TYPE_FIELDS after layout is done.
> > 
> > Both works for me.  As said I'd rather not use NULL DECL_NAME - backends
> > might build record types without names for va_list.  There's no
> > technical reason to have a DECL_NAME for sth the user cannot access -
> > which means every DECL_ARTIFICIAL entity.  This patch would 
> > retroactively introduce one and thus we'd have to audit each and
> > every piece of code building record types...
> 
> Done in the below, hopefully.  I only had to set DECL_PADDING_P on unnamed
> bit-fields.  I've added testcases for zero-sized unnamed bit-fields as well
> as for classes with virtual functions.
> 
> Moving TYPE_EMPTY_P to finalize_type_size revealed a bug in Cilk+, it was
> bogusly (I believe) setting TREE_ADDRESSABLE, so the assert fired.  Since
> Cilk+ is being deprecated and the Cilk+ testsuite still passes, I'm not
> too worried about this change.
> 
> So if you're fine with the DECL_PADDING_P change, all that remains is to
> check whether this patch is not changing the ABI for other languages than
> C++.  I suppose one way to check that could be to do sth like
> 
>   if (strncmp (lang_hooks.name, "GNU C++", 7))
> {FILE *f=fopen("/tmp/A", 
> "a");fprintf(f,"%s\n",main_input_filename);fclose(f);}
> 
> and compare the assembly of the files it prints?  But there were thousands of
> them I think :(.

Shouldn't most of GCCs own object files (and target library object files)
compare 1:1 before and after the patch?  After all it should _only_ affect
parameter passing of empty aggregates (and the files the patch changes
of course)?

Richard.

> Bootstrapped/regtested on x86_64-linux and ppc64-linux.
> 
> 2017-11-09  Marek Polacek  
>   H.J. Lu  
>   Jason Merrill  
> 
>   PR c++/60336
>   PR middle-end/67239
>   PR target/68355
>   * c-decl.c (grokdeclarator): Set DECL_PADDING_P on unnamed bit-fields.
> 
>   * class.c (layout_class_type): Set DECL_PADDING_P on padding.
>   * decl.c (cxx_init_decl_processing): Set TRANSLATION_UNIT_WARN_EMPTY_P.
>   (grokdeclarator): Set DECL_PADDING_P on unnamed bit-fields.
> 
>   * lto.c (compare_tree_sccs_1): Compare TYPE_EMPTY_P and DECL_PADDING_P.
> 
>   * calls.c (initialize_argument_information): Call
>   warn_parameter_passing_abi target hook.
>   (store_one_arg): Use 0 for empty record size.  Don't push 0 size
>   argument onto stack.
>   (must_pass_in_stack_var_size_or_pad): Return false for empty types.
>   * cilk-common.c (cilk_init_builtins): Don't set TREE_ADDRESSABLE.
>   * common.opt: Update -fabi-version description.
>   * config/i386/i386.c (init_cumulative_args): Set cum->warn_empty.
>   (ix86_return_in_memory): Return false for empty types.
>   (ix86_gimplify_va_arg): Call arg_int_size_in_bytes instead of
>   int_size_in_bytes.
>   (ix86_is_empty_record): New function.
>   (ix86_warn_parameter_passing_abi): New function.
>   (TARGET_EMPTY_RECORD_P): Redefine.
>   (TARGET_WARN_PARAMETER_PASSING_ABI): Redefine.
>   * config/i386/i386.h (CUMULATIVE_ARGS): Add warn_empty.
>   * doc/tm.texi: Regenerated.
>   * doc/tm.texi.in (TARGET_EMPTY_RECORD_P,
>   TARGET_WARN_PARAMETER_PASSING_ABI): Add.
>   * expl

[PATCH] GCOV: do not support unexecuted blocks in Ada

2017-11-09 Thread Nathan Sidwell



+  /* support for unexecuted basic blocks */


comment is not a sentence.


+  unsigned support_unexecuted_blocks = gcov_read_unsigned ();
+  if (!support_unexecuted_blocks)
+printf ("%s: has_unexecuted_block is not supported\n", filename);


otherwise Ok.  Just fix that formatting and commit.

nathan
--
Nathan Sidwell


Re: [PATCH 9/9] [IEPM] Introduce inline entry point markers

2017-11-09 Thread Jeff Law
On 11/01/2017 12:35 PM, Alexandre Oliva wrote:
> On Oct 31, 2017, Jeff Law  wrote:
> 
>>> @@ -5691,6 +5691,15 @@ expand_gimple_basic_block (basic_block bb, bool 
>>> disable_tail_calls)
>>> goto delink_debug_stmt;
>>> else if (gimple_debug_begin_stmt_p (stmt))
>>> val = gen_rtx_DEBUG_MARKER (VOIDmode);
>>> + else if (gimple_debug_inline_entry_p (stmt))
>>> +   {
>>> + tree block = gimple_block (stmt);
>>> +
>>> + if (block)
>>> +   val = gen_rtx_DEBUG_MARKER (BLKmode);
>>> + else
>>> +   goto delink_debug_stmt;
>>> +   }
>>> else
>>> gcc_unreachable ();
>> So again, I haven't looked at prior patches.  It seems to me like we're
>> abusing the mode of the debug marker rtx here.
> 
> It is still abuse if it's documented in INSN_DEBUG_MARKER_KIND and
> rtl.texi?  :-)
It's just documented abuse, but it's still abuse.  Though there's
certainly other cases where we've used modes to carry odd information
(reload was notorious for that, which I think we fixed a little while
back with some of David M's work).





> 
> We need some way to tell the (currently) two kinds of markers apart. 
I figured out that much.

> I
> didn't want yet another rtl code that would have to be added to cases
> all over; the distinction between markers matters at only very few
> points in the compiler.  
Is it fair to say one is just a variant of the other?


I considered adding an operand to the debug
> marker, to reference a const_int that could tell them apart with room
> for growth to other kinds of markers, or using any of the flag bits, but
> the mode was the most visibly unused mandatory rtl field in debug
> markers, so I went for it.
Is there a bit we could use in the rtx flags?  Yes, it's harder to prove
correct, but I would be a bit surprised if there wasn't a free one for
the debug rtxs.

>
> 
> Changing that would make for a very localized patch, touching only this
> creation point, the macro that tells the kinds apart, and the
> documentation, so if you'd rather have something else, I'll be glad to
> comply.
Alternately, let's at least abstract things via a macro or getter/setter
type function so that we can change the implementation in the future
without having to do searches on mode twiddling.


> 
> 
> 
>>> +/* Check whether BLOCK, a lexical block, is nested within OUTER, or is
>>> +   OUTER itself.  */
>>> +static bool
>>> +block_within_block_p (tree block, tree outer)
>>> +{
>>> +  if (block == outer)
>>> +return true;
>>> +
>>> +  /* Quickly check that OUTER is up BLOCK's supercontext chain.  */
>>> +  for (tree context = BLOCK_SUPERCONTEXT (block);
>>> +   context != outer;
>>> +   context = BLOCK_SUPERCONTEXT (context))
>>> +if (!context || TREE_CODE (context) != BLOCK)
>>> +  return false;
>>> +
>>> +  /* Now check that each block is actually referenced by its
>>> + parent.  */
>> So this seemed reasonable up to here.  Based on the name and function
>> comment, I'd think at this point you'd be able to return true.  We found
>> OUTER in BLOCK's supercontext chain.
> 
> The part you quoted looks at only at child-to-parent links; the other
> part looks at parent-to-children links, to make sure they match.  The
> function is a consistency check, used only in a checking assert.  It's
> intended to check both links, that the parent is reachable by the child,
> and that the child is reachable by the parent.  At some point, I had
> blocks that had been disconnected and discarded from the lexical block
> tree, but that remained pointed-to by markers; they still pointed to
> their parents, but their parents no longer pointed to them.
Ah, if it's just a consistency check then it makes perfect sense.

Jeff



[patch] Fix EH breakage in LTO mode

2017-11-09 Thread Eric Botcazou
Hi,

the patch

2017-07-06  Jan Hubicka  

* lto-wrapper.c (merge_and_complain): Do not merge
fexceptions, fnon_call_exceptions, ftrapv, ffp_contract_, fmath_errno,
fsigned_zeros, ftrapping_math, fwrapv.
(append_compiler_options): Do not track these options.
(append_linker_options): Likewie

has broken exception handling in LTO mode for targets which don't force either 
-funwind-tables or -fasynchronous-unwind-tables (i.e not x86) and do not 
default to -fdwarf2-cfi-asm (i.e. not Linux), for example SPARC/Solaris.

The problem is that the eh_frame section is no longer generated because it is 
emitted from compile_file:

#if defined DWARF2_DEBUGGING_INFO || defined DWARF2_UNWIND_INFO
  if (dwarf2out_do_frame ())
dwarf2out_frame_finish ();
#endif

and this requires that either flag_unwind_tables or flag_exceptions be set.

But both -funwind-tables and -fexceptions are optimization options defaulting 
to 0 and they are reset to 0 through optimization_default_node after the last 
function is processed by the cgraph machinery.

Note that flag_exceptions is generally set to 1 in lto_init_eh very early, but 
the above mechanism overrides it.  However, flag_exceptions may *never* be set 
to 1 for a specific partition if it contains only EH-neutral functions; that's 
why I think that there is no other way than restoring the build-wide handling 
of -fexceptions before Jan's patch (hopefully it's the only affected switch).

Tested (lightly for now) on x86-64/Linux and SPARC/Solaris, OK for mainline?


2017-11-09  Eric Botcazou  

* lto-opts.c (lto_write_options): Do not save -fnon-call-exceptions,
-ffp-contract, -fmath-errno, -fsigned-zeros, -ftrapping-math, -ftrapv
and -fwrapv.
* lto-wrapper.c (merge_and_complain): Merge again -fexceptions.
(append_compiler_options): Pass again -fexceptions.

-- 
Eric BotcazouIndex: lto-opts.c
===
--- lto-opts.c	(revision 254560)
+++ lto-opts.c	(working copy)
@@ -82,61 +82,10 @@ lto_write_options (void)
   && global_options.x_flag_exceptions)
 append_to_collect_gcc_options (&temporary_obstack, &first_p,
    "-fexceptions");
-  /* -fnon-call-exceptions changes the generation of exception
-  regions.  It is enabled implicitly by the Go frontend.  */
-  if (!global_options_set.x_flag_non_call_exceptions
-  && global_options.x_flag_non_call_exceptions)
-append_to_collect_gcc_options (&temporary_obstack, &first_p,
-   "-fnon-call-exceptions");
-  /* The default -ffp-contract changes depending on the language
- standard.  Pass thru conservative standard settings.  */
-  if (!global_options_set.x_flag_fp_contract_mode)
-switch (global_options.x_flag_fp_contract_mode)
-  {
-  case FP_CONTRACT_OFF:
-	append_to_collect_gcc_options (&temporary_obstack, &first_p,
-   "-ffp-contract=off");
-	break;
-  case FP_CONTRACT_ON:
-	append_to_collect_gcc_options (&temporary_obstack, &first_p,
-   "-ffp-contract=on");
-	break;
-  case FP_CONTRACT_FAST:
-	/* Nothing.  That merges conservatively and is the default for LTO.  */
-	break;
-  default:
-	gcc_unreachable ();
-  }
-  /* The default -fmath-errno, -fsigned-zeros and -ftrapping-math change
- depending on the language (they can be disabled by the Ada front-end).
- Pass thru conservative standard settings.  */
-  if (!global_options_set.x_flag_errno_math)
-append_to_collect_gcc_options (&temporary_obstack, &first_p,
-   global_options.x_flag_errno_math
-   ? "-fmath-errno"
-   : "-fno-math-errno");
-  if (!global_options_set.x_flag_signed_zeros)
-append_to_collect_gcc_options (&temporary_obstack, &first_p,
-   global_options.x_flag_signed_zeros
-   ? "-fsigned-zeros"
-   : "-fno-signed-zeros");
-  if (!global_options_set.x_flag_trapping_math)
-append_to_collect_gcc_options (&temporary_obstack, &first_p,
-   global_options.x_flag_trapping_math
-   ? "-ftrapping-math"
-   : "-fno-trapping-math");
-  /* We need to merge -f[no-]strict-overflow, -f[no-]wrapv and -f[no-]trapv
- conservatively, so stream out their defaults.  */
-  if (!global_options_set.x_flag_wrapv
-  && global_options.x_flag_wrapv)
-append_to_collect_gcc_options (&temporary_obstack, &first_p, "-fwrapv");
-  if (!global_options_set.x_flag_trapv
-  && !global_options.x_flag_trapv)
-append_to_collect_gcc_options (&temporary_obstack, &first_p, "-fno-trapv");
-
   if (!global_options_set.x_flag_openmp
   && !global_options.x_flag_openmp)
-append_to_collect_gcc_options (&temporary_obstack, &first_p, "-fno-openmp");
+append_to_collect_gcc_options (&temporary_obstack, &first_p,
+   "-fno-openmp");
   if (!global_options_set.x_flag_openacc
   && !global_options.x_flag_openacc)
 append_to_collect_gcc_options (&temporary_obstack, &first_p,
Index: lto-wrapper.c
==

Cleanup bb-reorder after conversion to profile-counts

2017-11-09 Thread Jan Hubicka
Hi,
this patch cleans up bb reorder pass after conversion to profile counts.
All the duplicated logic between frequencies and counts can go.

Bootstrapped/regtested x86_64-linux, will commit it shortly.

Honza

* bb-reorder.c (max_entry_frequency): Remove.
(find_traces, rotate_loop, mark_bb_visited, connect_better_edge_p,
connect_traces, push_to_next_round_p): Remove prototypes.
(find_traces_1_round): Use counts only.
(push_to_next_round_p): Likewise.
(find_traces): Likewise.
(rotate_loop): Likewise.
(find_traces_1_round): Likewise.
(connect_traces): Likewise.
(edge_order): Likewise.
Index: bb-reorder.c
===
--- bb-reorder.c(revision 254587)
+++ bb-reorder.c(working copy)
@@ -197,24 +197,16 @@ struct trace
 };
 
 /* Maximum frequency and count of one of the entry blocks.  */
-static int max_entry_frequency;
 static profile_count max_entry_count;
 
 /* Local function prototypes.  */
-static void find_traces (int *, struct trace *);
-static basic_block rotate_loop (edge, struct trace *, int);
-static void mark_bb_visited (basic_block, int);
-static void find_traces_1_round (int, int, gcov_type, struct trace *, int *,
+static void find_traces_1_round (int, profile_count, struct trace *, int *,
 int, bb_heap_t **, int);
 static basic_block copy_bb (basic_block, edge, basic_block, int);
 static long bb_to_key (basic_block);
 static bool better_edge_p (const_basic_block, const_edge, profile_probability,
   int, profile_probability, int, const_edge);
-static bool connect_better_edge_p (const_edge, bool, int, const_edge,
-  struct trace *);
-static void connect_traces (int, struct trace *);
 static bool copy_bb_p (const_basic_block, int);
-static bool push_to_next_round_p (const_basic_block, int, int, int, gcov_type);
 
 /* Return the trace number in which BB was visited.  */
 
@@ -249,15 +241,14 @@ mark_bb_visited (basic_block bb, int tra
 
 static bool
 push_to_next_round_p (const_basic_block bb, int round, int number_of_rounds,
- int exec_th, gcov_type count_th)
+ profile_count count_th)
 {
   bool there_exists_another_round;
   bool block_not_hot_enough;
 
   there_exists_another_round = round < number_of_rounds - 1;
 
-  block_not_hot_enough = (bb->count.to_frequency (cfun) < exec_th
- || bb->count.ipa () < count_th
+  block_not_hot_enough = (bb->count < count_th
  || probably_never_executed_bb_p (cfun, bb));
 
   if (there_exists_another_round
@@ -287,33 +278,26 @@ find_traces (int *n_traces, struct trace
   number_of_rounds = N_ROUNDS - 1;
 
   /* Insert entry points of function into heap.  */
-  max_entry_frequency = 0;
   max_entry_count = profile_count::zero ();
   FOR_EACH_EDGE (e, ei, ENTRY_BLOCK_PTR_FOR_FN (cfun)->succs)
 {
   bbd[e->dest->index].heap = heap;
   bbd[e->dest->index].node = heap->insert (bb_to_key (e->dest), e->dest);
-  if (e->dest->count.to_frequency (cfun) > max_entry_frequency)
-   max_entry_frequency = e->dest->count.to_frequency (cfun);
-  if (e->dest->count.ipa_p () && e->dest->count > max_entry_count)
+  if (e->dest->count > max_entry_count)
max_entry_count = e->dest->count;
 }
 
   /* Find the traces.  */
   for (i = 0; i < number_of_rounds; i++)
 {
-  gcov_type count_threshold;
+  profile_count count_threshold;
 
   if (dump_file)
fprintf (dump_file, "STC - round %d\n", i + 1);
 
-  if (max_entry_count < INT_MAX / 1000)
-   count_threshold = max_entry_count.to_gcov_type () * exec_threshold[i] / 
1000;
-  else
-   count_threshold = max_entry_count.to_gcov_type () / 1000 * 
exec_threshold[i];
+  count_threshold = max_entry_count.apply_scale (exec_threshold[i], 1000);
 
   find_traces_1_round (REG_BR_PROB_BASE * branch_threshold[i] / 1000,
-  max_entry_frequency * exec_threshold[i] / 1000,
   count_threshold, traces, n_traces, i, &heap,
   number_of_rounds);
 }
@@ -349,7 +333,6 @@ rotate_loop (edge back_edge, struct trac
   /* Information about the best end (end after rotation) of the loop.  */
   basic_block best_bb = NULL;
   edge best_edge = NULL;
-  int best_freq = -1;
   profile_count best_count = profile_count::uninitialized ();
   /* The best edge is preferred when its destination is not visited yet
  or is a start block of some trace.  */
@@ -375,12 +358,9 @@ rotate_loop (edge back_edge, struct trac
  || bbd[e->dest->index].start_of_trace >= 0)
{
  /* The current edge E is also preferred.  */
- int freq = EDGE_FREQUENCY (e);
- if (freq > best_freq || e->count () > best_count)
+ if (e

[PATCH, rs6000 V4] Fixes for commit 254464

2017-11-09 Thread Carl Love

GCC Maintainers:

The recent commit 254464 to add Power 8 support for the vec_revb()
builtin had a couple of issues that I missed on my testing of the
original patch.  First, on Power 8 BE the le_swap1 permute vector value
was wrong in function swap_endian_selector_for_mode(). This issue caused
the test case builtins-revb-runnable.c to fail on Power 8 BE. Originally
the function was used for all of the various modes including V16QI.
However, a revision of the patch mapped the V16QI case to a move as the
permute is actually a NOP.  Hence this case is not needed in the
function.  With these changes, the function values for
{l,b}e_swap{1,2,4,8} are identical.  Thus the if statement for LE and BE
can be collapsed.  

The additional issues were found with an existing testcase p9-xxbr-1.c
on AIX and Power 9 LE.  The test case was not being properly limited to
run on Power 9 with the new Power 8 support.  Additionally, the change
to map the V16QI to a move results means the test no longer generates
the xxbrq instructions.  The dg directive lp64 is needed on AIX.

I have tested the attached patch to address the above issues.  I have
tested the patch on

 powerpc64-unknown-linux-gnu (Power 8 BE), 
 powerpc64le-unknown-linux-gnu (Power 8 LE),   
 powerpc64le-unknown-linux-gnu (Power 9 LE) 

To verify the issues with two testcases are fixed and no new issues were
created.  My apologies for missing these issues on the original patch.

Please let me know if the following patch is acceptable.  Thanks.

   Carl Love
-

gcc/ChangeLog:

2017-11-09  Carl Love  

* config/rs6000/rs6000.c (swap_endian_selector_for_mode): Remove
le_ and be_ prefixes to swap* variables.  Remove
if (VECTOR_ELT_ORDER_BIG) statement. Remove E_V16QImode case statements.

gcc/testsuite/ChangeLog:

2017-11-09  Carl Love  

* builtins-revb-runnable.c (dg-do run): Add lp64 directive. Fix
indentation of printf and abort statements.
* p9-xxbr-1.c (dg-do compile): Add lp64 && p9vector_h directives.
---
 gcc/config/rs6000/rs6000.c | 81 +++---
 .../gcc.target/powerpc/builtins-revb-runnable.c| 68 +-
 gcc/testsuite/gcc.target/powerpc/p9-xxbr-1.c   | 11 ++-
 3 files changed, 62 insertions(+), 98 deletions(-)

diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c
index aacf3f1..fa2c551 100644
--- a/gcc/config/rs6000/rs6000.c
+++ b/gcc/config/rs6000/rs6000.c
@@ -14296,66 +14296,33 @@ swap_selector_for_mode (machine_mode mode)
 rtx
 swap_endian_selector_for_mode (machine_mode mode)
 {
-  unsigned int le_swap1[16] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
-  unsigned int le_swap2[16] = {7,6,5,4,3,2,1,0,15,14,13,12,11,10,9,8};
-  unsigned int le_swap4[16] = {3,2,1,0,7,6,5,4,11,10,9,8,15,14,13,12};
-  unsigned int le_swap8[16] = {1,0,3,2,5,4,7,6,9,8,11,10,13,12,15,14};
-  unsigned int le_swap16[16] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
-
-  unsigned int be_swap1[16] = {15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0};
-  unsigned int be_swap2[16] = {7,6,5,4,3,2,1,0,15,14,13,12,11,10,9,8};
-  unsigned int be_swap4[16] = {3,2,1,0,7,6,5,4,11,10,9,8,15,14,13,12};
-  unsigned int be_swap8[16] = {1,0,3,2,5,4,7,6,9,8,11,10,13,12,15,14};
-  unsigned int be_swap16[16] = {15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0};
+  unsigned int swap1[16] = {15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0};
+  unsigned int swap2[16] = {7,6,5,4,3,2,1,0,15,14,13,12,11,10,9,8};
+  unsigned int swap4[16] = {3,2,1,0,7,6,5,4,11,10,9,8,15,14,13,12};
+  unsigned int swap8[16] = {1,0,3,2,5,4,7,6,9,8,11,10,13,12,15,14};
+
   unsigned int *swaparray, i;
   rtx perm[16];
 
-  if (VECTOR_ELT_ORDER_BIG)
-switch (mode)
-  {
-  case E_V1TImode:
-   swaparray = le_swap1;
-   break;
-  case E_V2DFmode:
-  case E_V2DImode:
-   swaparray = le_swap2;
-   break;
-  case E_V4SFmode:
-  case E_V4SImode:
-   swaparray = le_swap4;
-   break;
-  case E_V8HImode:
-   swaparray = le_swap8;
-   break;
-  case E_V16QImode:
-   swaparray = le_swap16;
-   break;
-  default:
-   gcc_unreachable ();
-  }
-  else
-switch (mode)
-  {
-  case E_V1TImode:
-   swaparray = be_swap1;
-   break;
-  case E_V2DFmode:
-  case E_V2DImode:
-   swaparray = be_swap2;
-   break;
-  case E_V4SFmode:
-  case E_V4SImode:
-   swaparray = be_swap4;
-   break;
-  case E_V8HImode:
-   swaparray = be_swap8;
-   break;
-  case E_V16QImode:
-   swaparray = be_swap16;
-   break;
-  default:
-   gcc_unreachable ();
-  }
+  switch (mode)
+{
+case E_V1TImode:
+  swaparray = swap1;
+  break;
+case E_V2DFmode:
+case E_V2DImode:
+  swaparray = swap2;
+  break;
+case E_V4SFmode:
+case E_V4SImode:
+  swaparray = swap4;
+  break;
+case E_V8HImode:
+  swaparray =

Re: [patch] Fix EH breakage in LTO mode

2017-11-09 Thread Richard Biener
On November 9, 2017 5:11:39 PM GMT+01:00, Eric Botcazou  
wrote:
>Hi,
>
>the patch
>
>2017-07-06  Jan Hubicka  
>
>   * lto-wrapper.c (merge_and_complain): Do not merge
>   fexceptions, fnon_call_exceptions, ftrapv, ffp_contract_, fmath_errno,
>   fsigned_zeros, ftrapping_math, fwrapv.
>   (append_compiler_options): Do not track these options.
>   (append_linker_options): Likewie
>
>has broken exception handling in LTO mode for targets which don't force
>either 
>-funwind-tables or -fasynchronous-unwind-tables (i.e not x86) and do
>not 
>default to -fdwarf2-cfi-asm (i.e. not Linux), for example
>SPARC/Solaris.
>
>The problem is that the eh_frame section is no longer generated because
>it is 
>emitted from compile_file:
>
>#if defined DWARF2_DEBUGGING_INFO || defined DWARF2_UNWIND_INFO
>  if (dwarf2out_do_frame ())
>   dwarf2out_frame_finish ();
>#endif
>
>and this requires that either flag_unwind_tables or flag_exceptions be
>set.
>
>But both -funwind-tables and -fexceptions are optimization options
>defaulting 
>to 0 and they are reset to 0 through optimization_default_node after
>the last 
>function is processed by the cgraph machinery.
>
>Note that flag_exceptions is generally set to 1 in lto_init_eh very
>early, but 
>the above mechanism overrides it.  However, flag_exceptions may *never*
>be set 
>to 1 for a specific partition if it contains only EH-neutral functions;
>that's 
>why I think that there is no other way than restoring the build-wide
>handling 
>of -fexceptions before Jan's patch (hopefully it's the only affected
>switch).
>
>Tested (lightly for now) on x86-64/Linux and SPARC/Solaris, OK for
>mainline?

OK. 

Richard. 

>
>2017-11-09  Eric Botcazou  
>
>   * lto-opts.c (lto_write_options): Do not save -fnon-call-exceptions,
>   -ffp-contract, -fmath-errno, -fsigned-zeros, -ftrapping-math, -ftrapv
>   and -fwrapv.
>   * lto-wrapper.c (merge_and_complain): Merge again -fexceptions.
>   (append_compiler_options): Pass again -fexceptions.



Re: [patch] Fix EH breakage in LTO mode

2017-11-09 Thread Jan Hubicka
> Hi,
> 
> the patch
> 
> 2017-07-06  Jan Hubicka  
> 
>   * lto-wrapper.c (merge_and_complain): Do not merge
>   fexceptions, fnon_call_exceptions, ftrapv, ffp_contract_, fmath_errno,
>   fsigned_zeros, ftrapping_math, fwrapv.
>   (append_compiler_options): Do not track these options.
>   (append_linker_options): Likewie
> 
> has broken exception handling in LTO mode for targets which don't force 
> either 
> -funwind-tables or -fasynchronous-unwind-tables (i.e not x86) and do not 
> default to -fdwarf2-cfi-asm (i.e. not Linux), for example SPARC/Solaris.
> 
> The problem is that the eh_frame section is no longer generated because it is 
> emitted from compile_file:
> 
> #if defined DWARF2_DEBUGGING_INFO || defined DWARF2_UNWIND_INFO
>   if (dwarf2out_do_frame ())
>   dwarf2out_frame_finish ();
> #endif
> 
> and this requires that either flag_unwind_tables or flag_exceptions be set.
> 
> But both -funwind-tables and -fexceptions are optimization options defaulting 
> to 0 and they are reset to 0 through optimization_default_node after the last 
> function is processed by the cgraph machinery.
> 
> Note that flag_exceptions is generally set to 1 in lto_init_eh very early, 
> but 
> the above mechanism overrides it.  However, flag_exceptions may *never* be 
> set 
> to 1 for a specific partition if it contains only EH-neutral functions; 
> that's 
> why I think that there is no other way than restoring the build-wide handling 
> of -fexceptions before Jan's patch (hopefully it's the only affected switch).

I am not sure I follow your argumentation here.  flag_exceptions is optimization
which means that one should not test it globally. For that reason I would just
change dwarf2out to simply trigger dwarf2out_frame_finish if any of the compiled
functions needed it (had flag_exceptions set).

My readon of lto-wrapper is that it will set flag_exceptions for whole 
compilation
unit when one of compilation units were copmiled with flag_exceptions.

How that helps the neutral functions?
Honza


Re: [patch] Fix EH breakage in LTO mode

2017-11-09 Thread Eric Botcazou
> I am not sure I follow your argumentation here.  flag_exceptions is
> optimization which means that one should not test it globally. For that
> reason I would just change dwarf2out to simply trigger
> dwarf2out_frame_finish if any of the compiled functions needed it (had
> flag_exceptions set).

That's not sufficient for a partition with only EH-neutral functions.

> My readon of lto-wrapper is that it will set flag_exceptions for whole
> compilation unit when one of compilation units were copmiled with
> flag_exceptions.
> 
> How that helps the neutral functions?

flag_exceptions is never set in a partition with only EH-neutral functions.

-- 
Eric Botcazou


C++ runtime library selection via -stdlib=libstdc++/libc++ (WIP)

2017-11-09 Thread René J . V . Bertin
Hi,

A while back I filed a feature request for a build option to use the libc++ 
runtime, with a mostly PoC patch attached.
Such a feature would increase GCC's usability on platforms like Apple's OS for 
Mac, but possibly on FreeBSD too. (And if it's technically possible to use 
Microsoft's runtime that could become another option down the road.)

I've since had the time to test this feature more thoroughly, and have begun 
bringing it into a form where it might be considerable for inclusion. I'm 
attaching a first draft, including only the changes to the driver but none of 
the required changes to the build system yet. I'm doing this in my local 7.2.0 
build, so the patch is against that source, for now. I'm hoping the modified 
files evolve little enough that the patch also applies to the current 
development branch, and that it's thus useful enough to get some constructive 
feedback telling me I'm on the right path here.

I'd also really like to rally some "coworkers" on this, esp. if they're 
familiar with the (rather daunting) configure-and-build system and the 
procedure of "getting a new feature in"!

About the attached patch and approach:

I've copied the clang option syntax for selecting the C++ runtime: 
`-stdlib=libstdc++` or `-stdlib=libc++`, this is to maximise compiler 
compatibility. I think the compiler should be configured to use the platform 
runtime by default, i.e. libc++ on Mac OS X 10.9 and later. Currently this is 
hardwired with #ifdefs but that should probably become a configure setting.

The C++ runtime headerfiles for libc++ will have to found in the appropriate 
location, which will need to be configurable as on Mac they typically live 
inside the Xcode app bundle which is freely relocatable.

There is a catch with using libc++: older versions don't contain the sized 
C++14 new/delete operators (those were provided implicitly by clang). The 
operators are there in the libc++ from LLVM 3.9 and newer, but it appears that 
means that the system libc++ only contains them in Mac OS 10.12 and newer. It 
is of course possible to install a newer version, link to it and run it via 
DYLD_INSERT_LIBRARIES . The other option that appears to work is to use 
libsupc++ as the provider for those operators by including it as the last link 
library, in line with the procedure on llvm.org how to use libc++ on Linux. My 
patch currently adds libsupc++ on 10.11 and earlier; this should also be done 
more properly (though I presume libsupc++ will only be used if it provides 
symbols not already provided by the libraries linked before it).

Thanks,
René Bertindiff --git gcc/incpath.c
--- gcc/orig.incpath.c	2017-02-20 12:38:16.0 +0100
+++ gcc/incpath.c	2017-05-11 19:02:37.0 +0200
@@ -129,6 +129,10 @@
   int relocated = cpp_relocated ();
   size_t len;
 
+  if (cxx_stdinc == 2)
+{
+  add_path (xstrdup ("@LLVMHEADERPATH@"), SYSTEM, true, false);
+}
   if (iprefix && (len = cpp_GCC_INCLUDE_DIR_len) != 0)
 {
   /* Look for directories that start with the standard prefix.
@@ -136,7 +140,7 @@
 	 IPREFIX and search them first.  */
   for (p = cpp_include_defaults; p->fname; p++)
 	{
-	  if (!p->cplusplus || cxx_stdinc)
+	  if (!p->cplusplus || cxx_stdinc == 1)
 	{
 	  /* Should we be translating sysrooted dirs too?  Assume
 		 that iprefix and sysroot are mutually exclusive, for
@@ -167,7 +171,7 @@
 
   for (p = cpp_include_defaults; p->fname; p++)
 {
-  if (!p->cplusplus || cxx_stdinc)
+  if (!p->cplusplus || cxx_stdinc == 1)
 	{
 	  char *str;
 
@@ -474,6 +478,9 @@
   /* CPATH and language-dependent environment variables may add to the
  include chain.  */
   add_env_var_paths ("CPATH", BRACKET);
+  /* cxx_stdinc is no longer a bool but also indicates which C++ headers to include */
+  if (stdinc && cxx_stdinc == 2)
+add_env_var_paths ("LIBCPP_INCLUDE_PATH", SYSTEM);
   add_env_var_paths (lang_env_vars[idx], SYSTEM);
 
   target_c_incpath.extra_pre_includes (sysroot, iprefix, stdinc);
diff --git gcc/cp/g++spec.c
--- gcc/cp/orig.g++spec.c	2017-09-07 22:30:27.0 +0200
+++ gcc/cp/g++spec.c	2017-10-31 20:44:58.0 +0100
@@ -23,6 +23,10 @@
 #include "tm.h"
 #include "opts.h"
 
+#ifdef __APPLE__
+#include 
+#endif
+
 /* This bit is set if we saw a `-xfoo' language specification.  */
 #define LANGSPEC	(1<<1)
 /* This bit is set if they did `-lm' or `-lmath'.  */
@@ -48,9 +52,18 @@
 #ifndef LIBSTDCXX
 #define LIBSTDCXX "stdc++"
 #endif
+/* libc++ support: */
+#ifndef LIBCXX
+#define LIBCXX "c++"
+#define LIBCXXABI "c++abi"
+/* using libsupc++ is a hack, probably to be dropped on systems that have a new enough libc++
+   which has `operator delete(void*, unsigned long)` (introduced in libcxx rev. 229281) */
+#define LIBSUPCXX "supc++"
+#endif
 #ifndef LIBSTDCXX_PROFILE
 #define LIBSTDCXX_PROFILE LIBSTDCXX
 #endif
+
 #ifndef LIBSTDCXX_STATIC
 #define LIBSTDCXX_STATIC NULL
 #endif
@@ -65,7 +78,14 @@
   /* If nonzero, the user gave us the

Re: [001/nnn] poly_int: add poly-int.h

2017-11-09 Thread Martin Sebor

On 11/09/2017 04:06 AM, Richard Sandiford wrote:

Martin Sebor  writes:

On 11/08/2017 11:28 AM, Richard Sandiford wrote:

Martin Sebor  writes:

On 11/08/2017 09:51 AM, Richard Sandiford wrote:

Martin Sebor  writes:

On 11/08/2017 02:32 AM, Richard Sandiford wrote:

Martin Sebor  writes:

I haven't done nearly a thorough review but the dtor followed by
the placement new in the POLY_SET_COEFF() macro caught my eye so
I thought I'd ask sooner rather than later.  Given the macro
definition:

+   The dummy comparison against a null C * is just a way of checking
+   that C gives the right type.  */
+#define POLY_SET_COEFF(C, RES, I, VALUE) \
+  ((void) (&(RES).coeffs[0] == (C *) 0), \
+   wi::int_traits::precision_type == wi::FLEXIBLE_PRECISION \
+   ? (void) ((RES).coeffs[I] = VALUE) \
+   : (void) ((RES).coeffs[I].~C (), new (&(RES).coeffs[I]) C (VALUE)))

is the following use well-defined?

+template
+inline poly_int_pod&
+poly_int_pod::operator <<= (unsigned int a)
+{
+  POLY_SET_COEFF (C, *this, 0, this->coeffs[0] << a);

It looks to me as though the VALUE argument in the ctor invoked
by the placement new expression is evaluated after the dtor has
destroyed the very array element the VALUE argument expands to.


Good catch!  It should simply have been doing <<= on each coefficient --
I must have got carried away when converting to POLY_SET_COEFF.

I double-checked the other uses and think that's the only one.


Whether or not is, in fact, a problem, it seems to me that using
a function template rather than a macro would be a clearer and
safer way to do the same thing.  (Safer in that the macro also
evaluates its arguments multiple times, which is often a source
of subtle bugs.)


That would slow down -O0 builds though, by introducing an extra
function call and set of temporaries even when the coefficients
are primitive integers.


Would decorating the function template with attribute always_inline
help?


It would remove the call itself, but we'd still have the extra temporary
objects that were the function argument and return value.


Sorry, I do not want to get into another long discussion about
trade-offs between safety and efficiency but I'm not sure I see
what extra temporaries it would create.  It seems to me that
an inline function template that took arguments of user-defined
types by reference and others by value should be just as efficient
as a macro.

 From GCC's own manual:

   6.43 An Inline Function is As Fast As a Macro
   https://gcc.gnu.org/onlinedocs/gcc/Inline.html


You can see the difference with something like:

  inline
  void __attribute__((always_inline))
  f(int &dst, const int &src) { dst = src; }

  int g1(const int &y) { int x; f(x, y); return x; }
  int g2(const int &y) { int x; x = y; return x; }


Let me say at the outset that I struggle to comprehend that a few
instructions is even a consideration when not optimizing, especially
in light of the bug the macro caused that would have been prevented
by using a function instead.  But...


Many people still build at -O0 though.  One of the things I was asked
for was the time it takes to build stage 2 with an -O0 stage 1
(where stage 1 would usually be built by the host compiler).


Yes, of course.  I do all my development and basic testing at
-O0.  But I don't expect the performance to be comparable to
-O2.  I'd be surprised if anyone did.  What I do expect at -O0
(and what I'm grateful for) is GCC to make it easier to find
bugs in my code by enabling extra checks, even if they come at
the expense of slower execution.

That said, if your enhancement has such dramatic performance
implications at -O0 that the only way to avoid them is by using
macros then I would say it's not appropriate.


...I don't think your example above is representative of using
the POLY_SET_COEFF macro.  The function template I'm suggesting
might look something to this:

   template 
   inline void __attribute__ ((always_inline))
   poly_set_coeff (poly_int_pod *p, unsigned idx, C val)
   {
 ((void) (&(*p).coeffs[0] == (C *) 0),
wi::int_traits::precision_type == wi::FLEXIBLE_PRECISION ? (void)
((*p).coeffs[0] = val) : (void) ((*p).coeffs[0].~C (), new
(&(*p).coeffs[0]) C (val)));

 if (N >= 2)
   for (unsigned int i = 1; i < N; i++)
 ((void) (&(*p).coeffs[0] == (C *) 0),
wi::int_traits::precision_type == wi::FLEXIBLE_PRECISION ? (void)
((*p).coeffs[i] = val) : (void) ((*p).coeffs[i].~C (), new
(&(*p).coeffs[i]) C (val)));
   }


That ignores the idx parameter and sets all coefficents to val.  Did you
mean somnething like:

   template 
   inline void __attribute__ ((always_inline))
   poly_set_coeff (poly_int_pod *p, unsigned idx, C2 val)
   {
 wi::int_traits::precision_type == wi::FLEXIBLE_PRECISION ? (void) 
((*p).coeffs[idx] = val) : (void) ((*p).coeffs[idx].~C1 (), new (&(*p).coeffs[idx]) 
C1 (val));
   }

?  If so...


Yes, I didn't have it quite right.  With the above there's
a difference of three x86_64 mov instructions at -

Re: C++ runtime library selection via -stdlib=libstdc++/libc++ (WIP)

2017-11-09 Thread Joseph Myers
Your __APPLE__ conditional would appear to condition something on whether 
the *host* is an Apple system.  If you wish to change the default for 
Apple systems, presumably that should be a matter of whether the *target* 
is an Apple system.  (In general we want to avoid host conditionals as 
much as possible, and if needed, limit them to places such as system.h if 
possible, and handle target conditionals via target hooks not target 
macros.)

All options should be accessible by names starting with "--", meaning the 
new options should have such aliases added as well.

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


Re: [patch] Fix EH breakage in LTO mode

2017-11-09 Thread Rainer Orth
Hi Eric,

> the patch
>
> 2017-07-06  Jan Hubicka  
>
>   * lto-wrapper.c (merge_and_complain): Do not merge
>   fexceptions, fnon_call_exceptions, ftrapv, ffp_contract_, fmath_errno,
>   fsigned_zeros, ftrapping_math, fwrapv.
>   (append_compiler_options): Do not track these options.
>   (append_linker_options): Likewie
>
> has broken exception handling in LTO mode for targets which don't force 
> either 
> -funwind-tables or -fasynchronous-unwind-tables (i.e not x86) and do not 
> default to -fdwarf2-cfi-asm (i.e. not Linux), for example SPARC/Solaris.

this is PR lto/81351.

Rainer

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


[PATCH, GCC/testsuite] Fix retrieval of testname

2017-11-09 Thread Thomas Preudhomme

When gcc-dg-runtest is used to run a test the test is run several times
with different options. For clarity of the log, the test infrastructure
then append the options to the testname. This means that all the code
that must deal with the testcase itself (eg. removing the output files
after the test has run) needs to remove the option name.

There is already a pattern (see below) for this in several place of the
testsuite framework but it is also missing in many places. This patch
fixes all of these places. The pattern is as follows:

set testcase [testname-for-summary]
; The name might include a list of options; extract the file name.
set testcase [lindex $testcase 0]

ChangeLog entry is as follows:

*** gcc/testsuite/ChangeLog ***

2017-11-08  Thomas Preud'homme  

* lib/scanasm.exp (scan-assembler): Extract filename from testname used
in summary.
(scan-assembler-not): Likewise.
(scan-hidden): Likewise.
(scan-not-hidden): Likewise.
(scan-stack-usage): Likewise.
(scan-stack-usage-not): Likewise.
(scan-assembler-times): Likewise.
(scan-assembler-dem): Likewise.
(scan-assembler-dem-not): Likewise.
(object-size): Likewise.
(scan-lto-assembler): Likewise.
* lib/scandump.exp (scan-dump): Likewise.
(scan-dump-times): Likewise.
(scan-dump-not): Likewise.
(scan-dump-dem): Likewise.
(scan-dump-dem-not): Likewise

Testing: Ran testsuite on bootstrap aarch64-linux-gnu and
x86_64-linux-gnu compiled with C, fortran and ada support without any 
regression.

Is this ok for trunk?

Best regards,

Thomas
diff --git a/gcc/testsuite/lib/scanasm.exp b/gcc/testsuite/lib/scanasm.exp
index a66bb28253196410554405facefa8641d1020c1d..33286152f30df959a4bffa81634d0bfe7b898e8f 100644
--- a/gcc/testsuite/lib/scanasm.exp
+++ b/gcc/testsuite/lib/scanasm.exp
@@ -78,7 +78,9 @@ proc dg-scan { name positive testcase output_file orig_args } {
 
 proc scan-assembler { args } {
 set testcase [testname-for-summary]
-set output_file "[file rootname [file tail $testcase]].s"
+# The name might include a list of options; extract the file name.
+set filename [lindex $testcase 0]
+set output_file "[file rootname [file tail $filename]].s"
 dg-scan "scan-assembler" 1 $testcase $output_file $args
 }
 
@@ -89,7 +91,9 @@ force_conventional_output_for scan-assembler
 
 proc scan-assembler-not { args } {
 set testcase [testname-for-summary]
-set output_file "[file rootname [file tail $testcase]].s"
+# The name might include a list of options; extract the file name.
+set filename [lindex $testcase 0]
+set output_file "[file rootname [file tail $filename]].s"
 
 dg-scan "scan-assembler-not" 0 $testcase $output_file $args
 }
@@ -117,7 +121,9 @@ proc hidden-scan-for { symbol } {
 
 proc scan-hidden { args } {
 set testcase [testname-for-summary]
-set output_file "[file rootname [file tail $testcase]].s"
+# The name might include a list of options; extract the file name.
+set filename [lindex $testcase 0]
+set output_file "[file rootname [file tail $filename]].s"
 
 set symbol [lindex $args 0]
 
@@ -133,7 +139,9 @@ proc scan-hidden { args } {
 
 proc scan-not-hidden { args } {
 set testcase [testname-for-summary]
-set output_file "[file rootname [file tail $testcase]].s"
+# The name might include a list of options; extract the file name.
+set filename [lindex $testcase 0]
+set output_file "[file rootname [file tail $filename]].s"
 
 set symbol [lindex $args 0]
 set hidden_scan [hidden-scan-for $symbol]
@@ -163,7 +171,9 @@ proc scan-file-not { output_file args } {
 
 proc scan-stack-usage { args } {
 set testcase [testname-for-summary]
-set output_file "[file rootname [file tail $testcase]].su"
+# The name might include a list of options; extract the file name.
+set filename [lindex $testcase 0]
+set output_file "[file rootname [file tail $filename]].su"
 
 dg-scan "scan-file" 1 $testcase $output_file $args
 }
@@ -173,7 +183,9 @@ proc scan-stack-usage { args } {
 
 proc scan-stack-usage-not { args } {
 set testcase [testname-for-summary]
-set output_file "[file rootname [file tail $testcase]].su"
+# The name might include a list of options; extract the file name.
+set filename [lindex $testcase 0]
+set output_file "[file rootname [file tail $filename]].su"
 
 dg-scan "scan-file-not" 0 $testcase $output_file $args
 }
@@ -230,12 +242,14 @@ proc scan-assembler-times { args } {
 }
 
 set testcase [testname-for-summary]
+# The name might include a list of options; extract the file name.
+set filename [lindex $testcase 0]
 set pattern [lindex $args 0]
 set times [lindex $args 1]
 set pp_pattern [make_pattern_printable $pattern]
 
 # This must match the rule in gcc-dg.exp.
-set output_file "[file rootname [file tail $testcase]].s"
+set output_file "[fi

Re: [patch] Fix EH breakage in LTO mode

2017-11-09 Thread Jan Hubicka
> > I am not sure I follow your argumentation here.  flag_exceptions is
> > optimization which means that one should not test it globally. For that
> > reason I would just change dwarf2out to simply trigger
> > dwarf2out_frame_finish if any of the compiled functions needed it (had
> > flag_exceptions set).
> 
> That's not sufficient for a partition with only EH-neutral functions.
> 
> > My readon of lto-wrapper is that it will set flag_exceptions for whole
> > compilation unit when one of compilation units were copmiled with
> > flag_exceptions.
> > 
> > How that helps the neutral functions?
> 
> flag_exceptions is never set in a partition with only EH-neutral functions.

Hmm, I am still not following. By EH-neutral you mean function compiled
with -fno-exceptions so it has no unwind info at all or one that has unwind
info but does not do anything with EH?

Honza
> 
> -- 
> Eric Botcazou


[PATCH] Remove obsolete ECOFF support.

2017-11-09 Thread Jim Wilson
While looking at the collect2 COFF support, I noticed that there were two uses
of EXTENDED_COFF which is for the obsolete ECOFF support.  The last define for
EXTENDED_COFF was removed 2012-03-14, so these uses are obsolete and can be
removed.

Tested with Power AIX C/C++ bootstrap and make check, as this is the only
target using the collect2 COFF support.  There were no regressions.

Applied as obvious.

gcc/
* collect2.c (OBJECT_FORMAT_COFF): Remove EXTENDED_COFF support.
(scan_prog_file): Likewise.
---
 gcc/collect2.c | 19 ---
 1 file changed, 19 deletions(-)

diff --git a/gcc/collect2.c b/gcc/collect2.c
index 7fccf12cf09..d25b75697c0 100644
--- a/gcc/collect2.c
+++ b/gcc/collect2.c
@@ -2641,17 +2641,6 @@ scan_libraries (const char *prog_name)
 
 #ifdef OBJECT_FORMAT_COFF
 
-#if defined (EXTENDED_COFF)
-
-#   define GCC_SYMBOLS(X)  (SYMHEADER (X).isymMax + SYMHEADER (X).iextMax)
-#   define GCC_SYMENT  SYMR
-#   define GCC_OK_SYMBOL(X)((X).st == stProc || (X).st == stGlobal)
-#   define GCC_SYMINC(X)   (1)
-#   define GCC_SYMZERO(X)  (SYMHEADER (X).isymMax)
-#   define GCC_CHECK_HDR(X)(PSYMTAB (X) != 0)
-
-#else
-
 #   define GCC_SYMBOLS(X)  (HEADER (ldptr).f_nsyms)
 #   define GCC_SYMENT  SYMENT
 #   if defined (C_WEAKEXT)
@@ -2690,8 +2679,6 @@ scan_libraries (const char *prog_name)
   && !(HEADER (X).f_flags & F_LOADONLY))
 #endif
 
-#endif
-
 #ifdef COLLECT_EXPORT_LIST
 /* Array of standard AIX libraries which should not
be scanned for ctors/dtors.  */
@@ -2920,16 +2907,10 @@ scan_prog_file (const char *prog_name, scanpass 
which_pass,
}
 
  if (debug)
-#if !defined(EXTENDED_COFF)
fprintf (stderr, "\tsec=%d class=%d type=%s%o %s\n",
 symbol.n_scnum, symbol.n_sclass,
 (symbol.n_type ? "0" : ""), symbol.n_type,
 name);
-#else
-   fprintf (stderr,
-"\tiss = %5d, value = %5ld, index = %5d, name 
= %s\n",
-symbol.iss, (long) symbol.value, symbol.index, 
name);
-#endif
}
}
}
-- 
2.14.1



Re: [PATCH] 1/n Refactoring tree-vrp.c, step one introducing vr_values class

2017-11-09 Thread Martin Sebor

On 11/07/2017 02:03 PM, Jeff Law wrote:

So this is the first step in pulling apart tree-vrp.c.  As outlined in
an earlier message the goal of this patch is just to get the vr_values
class introduced.  I've tried (and mostly succeeded) in avoiding doing
significant cleanups/rewrites at this point to make reviewing this step
easier.

The vast majority of this patch is just changing functions from free
functions to member functions in the appropriate class (primarily
vr_values), pulling the appropriate static objects into that class and
adding the temporary delegators to minimize diffs at this stage.
Exceptions to this:

set_value_range changes how we get at the obstack for allocating
bitmaps.  This was discussed on-list recently.  Similarly in
vrp_intersect_ranges_1.

extract_range_from_unary_expr has two implementations.  One is within
the vr_values class which calls out to the freestanding function.  Hence
the ::extract_range_from_unary_expr.

We drop debug_all_value_ranges.  It doesn't make sense in a world where
the value ranges are attached to a class instance.  There is still a
method to dump all the value ranges within the class instance.

The vrp_prop and vrp_folder class definitions have to move to earlier
points in the file.

We pass a vrp_prop class instance through the gimple walkers using the
wi->info field.  check_all_array_refs sets that up and we recover the
class instance pointer in the check_array_bounds callback.

I wasn't up to converting the gimple folder to classes at this time.  So
we set/wipe x_vr_values (file scoped static) around the calls into the
gimple walkers and recover the vr_values class instance from x_vr_values
within vrp_valueize and vrp_valueize_1.

I use a similar hack to recover the vr_values instance in the callback
to simplify a statement for jump threading.  This code is on the
chopping block -- I expect it all to just disappear shortly.  Similarly
I just pass in vr_values to identify_jump_threads.  Again, I expect to
be removing all this code shortly and wanted to keep this as simple as
possible rather than waste time cleaning up code I'm just going to remove.

I did do some simplifications in vrp_finalize.  It wanted to access
vr_value and num_vr_values directly.  Now it goes through the
get_value_range interface.

I introduced a set_value_range_ member function in vr_values, then
twiddled a couple evrp routines to use that rather than access vr_value
directly.

In a few places I didn't bother creating delegators.  The delegators
wouldn't have simplified anything.  See execute_vrp and execute_early_vrp.

You'll note the vr_values class is large.  I've tried to avoid the
temptation to start simplifying stuff and instead try to stick with
moving routines into the appropriate class based on the code as it
stands right now.  The size of vr_values is probably a good indicator
that it's doing too much.

As suggested yesterday, I've added various delegator methods to the
classes to minimize code churn at this time.  I suspect we're going to
want to remove most, if not all of them.  But again, the goal in this
patch is to get the class structure in place with minimal amount of
collateral damage to make this step easy to review.

It's worth noting you see no changes that bleed out of tree-vrp.c and
the vast majority of the patch is just changing the function signature
so that they're part of the newly created class.  I consider that a
positive :-)


FWIW, I like the "C++-ification" of the API.

Just a few high-level suggestions:

If class vr_values is meant to be copyable and assignable it
should define a copy ctor and assignment operator.  Otherwise
it should make them private/deleted (whatever is the convention).
As it is, it looks to me that if a copy is created by accident
the dtor will have undefined behavior.

Also in vr_values, should all the data members really be public?
(If the class maintains any invariants I would expect the members
to be private and accessors provided for them to prevent clients
from inadvertently breaking the invariants).

Consider defining constructors and destructors for the classes
instead of providing initialize and finialize member functions.
(If a dtor takes an argument make it a member of the class.)

Consider renaming the vrp_prop::vr_values data member so that
it doesn't clash with the class name.  Same in vrp_folder.  There,
I would also suggest to use a different name than in vrp_prop since
the former is a pointer and the latter is an object of the type so
it could get confusing.

Martin


Bootstrapped and regression tested on x86_64.

OK for the trunk?


Jeff

ps. Next step is to pull the class methods into their own files without
changing *any* parts of their implementation.  As a bit of a preview,
tree-vrp.c is currently around 12000 lines.  After moving methods it'll
be about 7k.  vr-values.c will have around 5k lines.  The split out EVRP
pass is ~600 which will be further split roughly in half between the
core of evrp and the

Re: [PATCH] 1/n Refactoring tree-vrp.c, step one introducing vr_values class

2017-11-09 Thread Jeff Law
On 11/09/2017 08:24 AM, Richard Biener wrote:
> On Wed, Nov 8, 2017 at 1:53 PM, Trevor Saunders  wrote:
>> On Tue, Nov 07, 2017 at 02:03:19PM -0700, Jeff Law wrote:
>>> So this is the first step in pulling apart tree-vrp.c.  As outlined in
>>> an earlier message the goal of this patch is just to get the vr_values
>>> class introduced.  I've tried (and mostly succeeded) in avoiding doing
>>> significant cleanups/rewrites at this point to make reviewing this step
>>> easier.
>>>
>>> The vast majority of this patch is just changing functions from free
>>> functions to member functions in the appropriate class (primarily
>>> vr_values), pulling the appropriate static objects into that class and
>>> adding the temporary delegators to minimize diffs at this stage.
>>> Exceptions to this:
>>>
>>> set_value_range changes how we get at the obstack for allocating
>>> bitmaps.  This was discussed on-list recently.  Similarly in
>>> vrp_intersect_ranges_1.
>>>
>>> extract_range_from_unary_expr has two implementations.  One is within
>>> the vr_values class which calls out to the freestanding function.  Hence
>>> the ::extract_range_from_unary_expr.
>>>
>>> We drop debug_all_value_ranges.  It doesn't make sense in a world where
>>> the value ranges are attached to a class instance.  There is still a
>>> method to dump all the value ranges within the class instance.
>>>
>>> The vrp_prop and vrp_folder class definitions have to move to earlier
>>> points in the file.
>>>
>>> We pass a vrp_prop class instance through the gimple walkers using the
>>> wi->info field.  check_all_array_refs sets that up and we recover the
>>> class instance pointer in the check_array_bounds callback.
>>>
>>> I wasn't up to converting the gimple folder to classes at this time.  So
>>> we set/wipe x_vr_values (file scoped static) around the calls into the
>>> gimple walkers and recover the vr_values class instance from x_vr_values
>>> within vrp_valueize and vrp_valueize_1.
>>>
>>> I use a similar hack to recover the vr_values instance in the callback
>>> to simplify a statement for jump threading.  This code is on the
>>> chopping block -- I expect it all to just disappear shortly.  Similarly
>>> I just pass in vr_values to identify_jump_threads.  Again, I expect to
>>> be removing all this code shortly and wanted to keep this as simple as
>>> possible rather than waste time cleaning up code I'm just going to remove.
>>>
>>> I did do some simplifications in vrp_finalize.  It wanted to access
>>> vr_value and num_vr_values directly.  Now it goes through the
>>> get_value_range interface.
>>>
>>> I introduced a set_value_range_ member function in vr_values, then
>>> twiddled a couple evrp routines to use that rather than access vr_value
>>> directly.
>>>
>>> In a few places I didn't bother creating delegators.  The delegators
>>> wouldn't have simplified anything.  See execute_vrp and execute_early_vrp.
>>>
>>> You'll note the vr_values class is large.  I've tried to avoid the
>>> temptation to start simplifying stuff and instead try to stick with
>>> moving routines into the appropriate class based on the code as it
>>> stands right now.  The size of vr_values is probably a good indicator
>>> that it's doing too much.
>>>
>>> As suggested yesterday, I've added various delegator methods to the
>>> classes to minimize code churn at this time.  I suspect we're going to
>>> want to remove most, if not all of them.  But again, the goal in this
>>> patch is to get the class structure in place with minimal amount of
>>> collateral damage to make this step easy to review.
>>
>> Yeah, this all looks pretty reasonable, ime breaking things also helps
>> when writing the patch and you break something since there's less to
>> undo before getting to a working state.  If anything I would have broken
>> this up even more, moving the existing classes up can probably be its
>> own thing, as well as the use of equiv->obstack.
> 
> Patch looks good to me.  I saw
> 
> +  void set_value_range_ (tree, value_range *);
There's a set_value_range free function I didn't want to conflict with:

/* Set value range VR to {T, MIN, MAX, EQUIV}.  */

void
set_value_range (value_range *vr, enum value_range_type t, tree min,
 tree max, bitmap equiv)

The free function is passed in a VR we want to initialize/set.

THe set_value_range_ member function is used to set an entry in the
vr_values array.  I'll choose a better name for the member function.

> and when seeing uses I thought temporary hack because of that
> "SSA_NAME_VERSION > length" check but then there's no
> set_value_range () function (without _) (or I missed it).  Can you just
> remove the _ or add a comment?
> 
> There's excess vertical space at the end of the vr_values class.
Will fix.

> 
> Otherwise ok.  No need to split up further.
Funny, I'd split out the two hunks Trevor suggested yesterday.  It's a
nice mindless little task I can have running while I look at other
stuff.  GIven I've already spl

Re: [PATCH, GCC/testsuite] Fix retrieval of testname

2017-11-09 Thread Mike Stump
On Nov 9, 2017, at 10:00 AM, Thomas Preudhomme  
wrote:
> 
> When gcc-dg-runtest is used to run a test the test is run several times
> with different options. For clarity of the log, the test infrastructure
> then append the options to the testname. This means that all the code
> that must deal with the testcase itself (eg. removing the output files
> after the test has run) needs to remove the option name.

> Is this ok for trunk?

Ok.  Little scary the code is repeated so many time.  If someone wants to 
refactor it some, I could see the beauty in that.


[PATCH,committed] Fix PR fortran/78814

2017-11-09 Thread Steve Kargl
Here's another small, obvious fix where a pointer was not
to see that it was non-NULL.  Committed after regression
testing on x86_64-*-freebsd.

2017-11-09  Steven G. Kargl  

PR fortran/78814
* interface.c (symbol_rank): Check for NULL pointer.

2017-11-09  Steven G. Kargl  

PR fortran/78814
* gfortran.dg/interface_40.f90: New testcase.

-- 
Steve
Index: gcc/fortran/interface.c
===
--- gcc/fortran/interface.c	(revision 254554)
+++ gcc/fortran/interface.c	(working copy)
@@ -1262,8 +1262,13 @@ generic_correspondence (gfc_formal_arglist *f1, gfc_fo
 static int
 symbol_rank (gfc_symbol *sym)
 {
-  gfc_array_spec *as;
-  as = (sym->ts.type == BT_CLASS) ? CLASS_DATA (sym)->as : sym->as;
+  gfc_array_spec *as = NULL;
+
+  if (sym->ts.type == BT_CLASS && CLASS_DATA (sym) && CLASS_DATA (sym)->as)
+as = CLASS_DATA (sym)->as;
+  else
+as = sym->as;
+
   return as ? as->rank : 0;
 }
 
Index: gcc/testsuite/gfortran.dg/interface_40.f90
===
--- gcc/testsuite/gfortran.dg/interface_40.f90	(nonexistent)
+++ gcc/testsuite/gfortran.dg/interface_40.f90	(working copy)
@@ -0,0 +1,8 @@
+! { dg-do compile }
+! PR fortran/78814
+! Code contributed by Gerhard Steinmetz
+program p
+   class(*) :: x  ! { dg-error " must be dummy, allocatable or pointer" }
+   print *, f(x)
+end
+


Re: [PATCH] 1/n Refactoring tree-vrp.c, step one introducing vr_values class

2017-11-09 Thread Jeff Law
On 11/09/2017 11:12 AM, Martin Sebor wrote:
> On 11/07/2017 02:03 PM, Jeff Law wrote:
>> So this is the first step in pulling apart tree-vrp.c.  As outlined in
>> an earlier message the goal of this patch is just to get the vr_values
>> class introduced.  I've tried (and mostly succeeded) in avoiding doing
>> significant cleanups/rewrites at this point to make reviewing this step
>> easier.
>>
>> The vast majority of this patch is just changing functions from free
>> functions to member functions in the appropriate class (primarily
>> vr_values), pulling the appropriate static objects into that class and
>> adding the temporary delegators to minimize diffs at this stage.
>> Exceptions to this:
>>
>> set_value_range changes how we get at the obstack for allocating
>> bitmaps.  This was discussed on-list recently.  Similarly in
>> vrp_intersect_ranges_1.
>>
>> extract_range_from_unary_expr has two implementations.  One is within
>> the vr_values class which calls out to the freestanding function.  Hence
>> the ::extract_range_from_unary_expr.
>>
>> We drop debug_all_value_ranges.  It doesn't make sense in a world where
>> the value ranges are attached to a class instance.  There is still a
>> method to dump all the value ranges within the class instance.
>>
>> The vrp_prop and vrp_folder class definitions have to move to earlier
>> points in the file.
>>
>> We pass a vrp_prop class instance through the gimple walkers using the
>> wi->info field.  check_all_array_refs sets that up and we recover the
>> class instance pointer in the check_array_bounds callback.
>>
>> I wasn't up to converting the gimple folder to classes at this time.  So
>> we set/wipe x_vr_values (file scoped static) around the calls into the
>> gimple walkers and recover the vr_values class instance from x_vr_values
>> within vrp_valueize and vrp_valueize_1.
>>
>> I use a similar hack to recover the vr_values instance in the callback
>> to simplify a statement for jump threading.  This code is on the
>> chopping block -- I expect it all to just disappear shortly.  Similarly
>> I just pass in vr_values to identify_jump_threads.  Again, I expect to
>> be removing all this code shortly and wanted to keep this as simple as
>> possible rather than waste time cleaning up code I'm just going to
>> remove.
>>
>> I did do some simplifications in vrp_finalize.  It wanted to access
>> vr_value and num_vr_values directly.  Now it goes through the
>> get_value_range interface.
>>
>> I introduced a set_value_range_ member function in vr_values, then
>> twiddled a couple evrp routines to use that rather than access vr_value
>> directly.
>>
>> In a few places I didn't bother creating delegators.  The delegators
>> wouldn't have simplified anything.  See execute_vrp and
>> execute_early_vrp.
>>
>> You'll note the vr_values class is large.  I've tried to avoid the
>> temptation to start simplifying stuff and instead try to stick with
>> moving routines into the appropriate class based on the code as it
>> stands right now.  The size of vr_values is probably a good indicator
>> that it's doing too much.
>>
>> As suggested yesterday, I've added various delegator methods to the
>> classes to minimize code churn at this time.  I suspect we're going to
>> want to remove most, if not all of them.  But again, the goal in this
>> patch is to get the class structure in place with minimal amount of
>> collateral damage to make this step easy to review.
>>
>> It's worth noting you see no changes that bleed out of tree-vrp.c and
>> the vast majority of the patch is just changing the function signature
>> so that they're part of the newly created class.  I consider that a
>> positive :-)
> 
> FWIW, I like the "C++-ification" of the API.
> 
> Just a few high-level suggestions:
> 
> If class vr_values is meant to be copyable and assignable it
> should define a copy ctor and assignment operator.  Otherwise
> it should make them private/deleted (whatever is the convention).
> As it is, it looks to me that if a copy is created by accident
> the dtor will have undefined behavior.
I'd actually like to defer finalizing this until a little bit later
(measured in days, not weeks or months).

Ideally we'd be using C++11 and rvalue references so that we could
transfer ownership of the array within the vr_values class as we move
from (in traditional vrp) propagation through the lattice to propagation
into the IL.

What I've got here in another branch slightly different in that the
ctors expect to be passed in the underlying array and we want to define
a private, empty copy ctor.

I'm still pondering whether to push C++11, go with what I've done on a
private branch or something else.  It also plays into generally cleaning
up initialization and finalization.


> 
> Also in vr_values, should all the data members really be public?
> (If the class maintains any invariants I would expect the members
> to be private and accessors provided for them to prevent clients
> from inadvertently bre

Re: C++ runtime library selection via -stdlib=libstdc++/libc++ (WIP)

2017-11-09 Thread René J . V . Bertin
On Thursday November 09 2017 17:41:39 Joseph Myers wrote:

>Your __APPLE__ conditional would appear to condition something on whether 
>the *host* is an Apple system.  If you wish to change the default for 

Evidently. As I said, there are a number of settings that will (probably) need 
to be determined at the configure stage.
I must admit I hadn't thought about cross-compiling (or cross-building) at all. 
My first concern has been to get the feature working so I can test it.
(I, and potentially other Mac users; my patch is currently set up to integrate 
with the MacPorts package for gcc7; a bit of wide-spread testing in the wild 
cannot be a bad thing before incorporating this, right? :))

I wouldn't particularly mind in fact if making libc++ the default runtime 
library were made through an explicit configure option. That might even be 
better for users of libc++-based systems who have integrated g++ and its 
incompatible runtime into their workflows. I expect the powers that be on here 
will have a better educated opinion on this.

>All options should be accessible by names starting with "--", meaning the 
>new options should have such aliases added as well.

Ok, I'll have a look how that would work, I was expecting that the check for 
"this option with an extra dash" would be done in code.

I hope I'm not violating any rules in processing the same options in 2 
locations (once to know where to look for C++ headers, once to know which 
runtime lib to link)?

R.


Re: [patch] Fix EH breakage in LTO mode

2017-11-09 Thread Richard Biener
On November 9, 2017 7:03:18 PM GMT+01:00, Jan Hubicka  wrote:
>> > I am not sure I follow your argumentation here.  flag_exceptions is
>> > optimization which means that one should not test it globally. For
>that
>> > reason I would just change dwarf2out to simply trigger
>> > dwarf2out_frame_finish if any of the compiled functions needed it
>(had
>> > flag_exceptions set).
>> 
>> That's not sufficient for a partition with only EH-neutral functions.
>> 
>> > My readon of lto-wrapper is that it will set flag_exceptions for
>whole
>> > compilation unit when one of compilation units were copmiled with
>> > flag_exceptions.
>> > 
>> > How that helps the neutral functions?
>> 
>> flag_exceptions is never set in a partition with only EH-neutral
>functions.
>
>Hmm, I am still not following. By EH-neutral you mean function compiled
>with -fno-exceptions so it has no unwind info at all or one that has
>unwind
>info but does not do anything with EH?

The latter. We choose a 'neutral' EH personality for those and thus if all 
behave that way we fail to init EH. 

I suppose we could record a TU wide setting of options attached to the 
TRANSLATION_UNIT_DECL and read global flags from that? 

Richard. 

>Honza
>> 
>> -- 
>> Eric Botcazou



[PATCH] Fix compare-elim.c ICE (PR rtl-optimization/82913)

2017-11-09 Thread Jakub Jelinek
Hi!

My recent changes to compare-elim.c introduced ICE on the following
testcase.
When computing cmp->in_a_setter, I've made sure it is single_set
and therefore I've left the if (!set) return false; stuff out.
That usually works, but doesn't if an earlier try_eliminate_compare or
try_merge_compare turns that cmp->in_a_setter instruction into
a cmp + arith parallel.  In that case, previously we'd give up and
with the following patch we do as well.

In theory, in some cases we could do better than that, e.g. on this
testcase there is a SImode comparison of %eax and 0 merged by
try_eliminate_compare and then there is a DImode comparison of %rax and 0
that we ICE on.  The insn has a zero_extend of plus, and the user
of the comparison looks only at the zero flag, so in this case we could
leave the second comparison out, as zero extension shouldn't affect the zero
flag.  If the comparison user looked at some other flags like sign,
overflow, carry etc., that wouldn't be the case, so in order to optimize
away the second comparison we'd need to use some specialized CC mode like
CCZ.

Anyway, this patch doesn't do those smarts, just restores previous behavior.
Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2017-11-09  Jakub Jelinek  

PR rtl-optimization/82913
* compare-elim.c (try_merge_compare): Punt if def_insn is not
single set.

* gcc.c-torture/compile/pr82913.c: New test.

--- gcc/compare-elim.c.jj   2017-11-01 22:51:37.0 +0100
+++ gcc/compare-elim.c  2017-11-09 11:44:18.996213647 +0100
@@ -683,6 +683,8 @@ try_merge_compare (struct comparison *cm
 
   rtx_insn *def_insn = cmp->in_a_setter;
   rtx set = single_set (def_insn);
+  if (!set)
+return false;
 
   if (!can_merge_compare_into_arith (cmp_insn, def_insn))
 return false;
--- gcc/testsuite/gcc.c-torture/compile/pr82913.c.jj2017-11-09 
11:47:18.779031240 +0100
+++ gcc/testsuite/gcc.c-torture/compile/pr82913.c   2017-11-09 
11:46:59.0 +0100
@@ -0,0 +1,23 @@
+/* PR rtl-optimization/82913 */
+
+unsigned int a;
+unsigned long int b;
+
+int
+foo (void)
+{
+  ++a;
+  b = 0;
+}
+
+unsigned long int
+bar (int x)
+{
+  if (!foo () || !a)
+{
+  int c = a != b;
+  if (c != x)
+return a;
+}
+  return 0;
+}

Jakub


[PATCH] Fix profiledbootstrap - store-merging aliasing issue (PR bootstrap/82916)

2017-11-09 Thread Jakub Jelinek
Hi!

We want to terminate a chain if a chain with different base (or insn
outside of any chain) has a store that the current stmt might use, or
overwrite.  The functions it used didn't cover the store after store
case which in the middle-end aliasing model needs to avoid tbaa, because
the latter store might be after a placement new or might otherwise change
the dynamic object type of the object.

The following patch does that.  Bootstrapped/regtested on x86_64-linux and
i686-linux, additionally profiledbootstrapped with the configure options
Markus mentioned in the PR.  Ok for trunk?

2017-11-09  Jakub Jelinek  

PR bootstrap/82916
* gimple-ssa-store-merging.c
(pass_store_merging::terminate_all_aliasing_chains): For
gimple_store_p stmts also call refs_output_dependent_p.

* gcc.dg/store_merging_2.c: Only expect 2 successful mergings instead
of 3.
* gcc.dg/pr82916.c: New test.

--- gcc/gimple-ssa-store-merging.c.jj   2017-11-09 15:51:08.0 +0100
+++ gcc/gimple-ssa-store-merging.c  2017-11-09 18:01:20.789236951 +0100
@@ -945,6 +945,7 @@ pass_store_merging::terminate_all_aliasi
   if (!gimple_vuse (stmt))
 return false;
 
+  tree store_lhs = gimple_store_p (stmt) ? gimple_get_lhs (stmt) : NULL_TREE;
   for (imm_store_chain_info *next = m_stores_head, *cur = next; cur; cur = 
next)
 {
   next = cur->next;
@@ -958,8 +959,10 @@ pass_store_merging::terminate_all_aliasi
   unsigned int i;
   FOR_EACH_VEC_ELT (cur->m_store_info, i, info)
{
- if (ref_maybe_used_by_stmt_p (stmt, gimple_assign_lhs (info->stmt))
- || stmt_may_clobber_ref_p (stmt, gimple_assign_lhs (info->stmt)))
+ tree lhs = gimple_assign_lhs (info->stmt);
+ if (ref_maybe_used_by_stmt_p (stmt, lhs)
+ || stmt_may_clobber_ref_p (stmt, lhs)
+ || (store_lhs && refs_output_dependent_p (store_lhs, lhs)))
{
  if (dump_file && (dump_flags & TDF_DETAILS))
{
--- gcc/testsuite/gcc.dg/store_merging_2.c.jj   2017-11-08 16:46:19.0 
+0100
+++ gcc/testsuite/gcc.dg/store_merging_2.c  2017-11-09 18:16:33.482344795 
+0100
@@ -77,4 +77,4 @@ main (void)
   return 0;
 }
 
-/* { dg-final { scan-tree-dump-times "Merging successful" 3 "store-merging" } 
} */
+/* { dg-final { scan-tree-dump-times "Merging successful" 2 "store-merging" } 
} */
--- gcc/testsuite/gcc.dg/pr82916.c.jj   2017-11-09 18:12:40.707128841 +0100
+++ gcc/testsuite/gcc.dg/pr82916.c  2017-11-09 18:12:19.0 +0100
@@ -0,0 +1,47 @@
+/* PR bootstrap/82916 */
+/* { dg-do run } */
+/* { dg-options "-O2 -fno-tree-dse" } */
+
+struct A { struct A *next; };
+struct C
+{
+  int *of;
+  struct C *parent, *prev, *next;
+  int depth;
+  int min;
+  struct C *min_occ;
+};
+
+__attribute__((noipa)) struct C *
+foo (int *node)
+{
+  struct A *p = __builtin_malloc (sizeof (struct C));
+  if (!p)
+return 0;
+  p->next = 0;
+  /* Originally placement new.  */
+  struct C *nw = (struct C *)(void *)p;
+  nw->of = node;
+  nw->parent = 0;
+  nw->prev = 0;
+  nw->next = 0;
+  nw->depth = 0;
+  nw->min_occ = nw;
+  nw->min = 0;
+  return nw;
+}
+
+int
+main ()
+{
+  int o;
+  struct C *p = foo (&o);
+  if (p)
+{
+  if (p->of != &o || p->parent || p->prev || p->next || p->depth
+ || p->min || p->min_occ != p)
+   __builtin_abort ();
+}
+  __builtin_free (p);
+  return 0;
+}

Jakub


std::advance istreambuf_iterator overload

2017-11-09 Thread François Dumont

Hi

    Working on istreambuf_iterator I realized that this iterator would 
really benefit from an std::advance overload so here it is.


    Tested under Linux x86_64 normal and debug modes, ok to commit ?

François

diff --git a/libstdc++-v3/include/bits/streambuf_iterator.h b/libstdc++-v3/include/bits/streambuf_iterator.h
index 0a6c7f9..b60626a 100644
--- a/libstdc++-v3/include/bits/streambuf_iterator.h
+++ b/libstdc++-v3/include/bits/streambuf_iterator.h
@@ -86,6 +86,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	find(istreambuf_iterator<_CharT2>, istreambuf_iterator<_CharT2>,
 	 const _CharT2&);
 
+  template
+	friend void _GLIBCXX17_CONSTEXPR
+	advance(istreambuf_iterator<_CharT2>&, _Distance);
+
 private:
   // 24.5.3 istreambuf_iterator
   // p 1
@@ -417,6 +421,55 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   return __last;
 }
 
+  template
+inline _GLIBCXX17_CONSTEXPR void
+advance(istreambuf_iterator<_CharT>& __i, _Distance __n)
+{
+  if (__n == 0)
+	return;
+
+  __glibcxx_assert(__n > 0);
+  __glibcxx_requires_cond(!__i._M_at_eof(),
+			  _M_message(__gnu_debug::__msg_inc_istreambuf)
+			  ._M_iterator(__i));
+
+  typedef istreambuf_iterator<_CharT>		   __is_iterator_type;
+  typedef typename __is_iterator_type::traits_type	   traits_type;
+  typedef typename __is_iterator_type::streambuf_type  streambuf_type;
+  typedef typename traits_type::int_type		   int_type;
+  const int_type __eof = traits_type::eof();
+
+  streambuf_type* __sb = __i._M_sbuf;
+  int_type __c = __sb->sgetc();
+  while (__n && !traits_type::eq_int_type(__c, __eof))
+	{
+	  streamsize __size = __sb->egptr() - __sb->gptr();
+	  if (__size > __n)
+	{
+	  __sb->__safe_gbump(__n);
+	  __n = 0;
+	}
+	  else if (__size > 1)
+	{
+	  __sb->__safe_gbump(__size);
+	  __n -= __size;
+	  __c = __sb->underflow();
+	}
+	  else
+	{
+	  --__n;
+	  __c = __sb->snextc();
+	}
+	}
+
+  __glibcxx_requires_cond(__n == 0,
+			  _M_message(__gnu_debug::__msg_inc_istreambuf)
+			  ._M_iterator(__i));
+  __i._M_c = __eof;
+  if (traits_type::eq_int_type(__c, __eof))
+	__i._M_sbuf = 0;
+}
+
 // @} group iterators
 
 _GLIBCXX_END_NAMESPACE_VERSION
diff --git a/libstdc++-v3/include/std/streambuf b/libstdc++-v3/include/std/streambuf
index a05b46e..da92199 100644
--- a/libstdc++-v3/include/std/streambuf
+++ b/libstdc++-v3/include/std/streambuf
@@ -159,6 +159,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 find(istreambuf_iterator<_CharT2>, istreambuf_iterator<_CharT2>,
 	 const _CharT2&);
 
+  template
+friend _GLIBCXX17_CONSTEXPR void
+advance(istreambuf_iterator<_CharT2>&, _Distance);
+
   template
 friend basic_istream<_CharT2, _Traits2>&
 operator>>(basic_istream<_CharT2, _Traits2>&, _CharT2*);
diff --git a/libstdc++-v3/testsuite/25_algorithms/advance/istreambuf_iterators/char/1.cc b/libstdc++-v3/testsuite/25_algorithms/advance/istreambuf_iterators/char/1.cc
new file mode 100644
index 000..7c3f882
--- /dev/null
+++ b/libstdc++-v3/testsuite/25_algorithms/advance/istreambuf_iterators/char/1.cc
@@ -0,0 +1,56 @@
+// Copyright (C) 2017 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// .
+
+#include 
+#include 
+#include 
+#include 
+
+void test01()
+{
+  using namespace std;
+
+  typedef istreambuf_iterator in_iterator_type;
+
+  const char data1[] = "Drei Phantasien nach Friedrich Holderlin";
+  const string str1(data1);
+  istringstream iss1(str1);
+  in_iterator_type beg1(iss1);
+  in_iterator_type end1;
+
+  VERIFY( *beg1 == 'D' );
+
+  advance(beg1, 1);
+
+  VERIFY( beg1 != end1 );
+  VERIFY( *beg1 == 'r' );
+
+  advance(beg1, 0);
+  VERIFY( *beg1 == 'r' );
+
+  advance(beg1, 38);
+  VERIFY( *beg1 == 'n' );
+
+  advance(beg1, 1);
+  VERIFY( beg1 == end1 );
+}
+
+int main()
+{
+  test01();
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/25_algorithms/advance/istreambuf_iterators/char/1_neg.cc b/libstdc++-v3/testsuite/25_algorithms/advance/istreambuf_iterators/char/1_neg.cc
new file mode 100644
index 000..d1b8cde
--- /dev/null
+++ b/libstdc++-v3/testsuite/25_algorithms/advance/istreambuf_iterators/char/1_neg.cc
@@ -0,0 +1,38 @@
+// Copyright (C) 2017 Free Sof

[PATCH], PR middle_end/82333, Make long double/_Float128 constants not hash to the same value on the PowerPC

2017-11-09 Thread Michael Meissner
This patch fixes PR middle_end/82333.

The bug is due to compare_constant thinking two floating point constants are
the same if the floating point size and the internal value are the same.  On
the PowerPC, long double and _Float128 both are 128-bits, but they have
different internal representations.

The bug shows up when you try to inline two functions, one that returns 0
converted to long double _Complex and the other that returns 0 converted to
_Float128 _Complex.

The function compare_constant in varasm.c thinks that these two constants are
the same, and assigns them to the same hash.  When inliner tries to replace the
inline function (that returns 0) with the constant, it does moves of the real
part and the imaginary part.  In the second function, the real/imaginary parts
have type KFmode, while the first function (that has the saved constant) the
real/imaginary parts have type TFmode.

The fix is to consider the type along with the precision when doing hash of the
constants.

I have done bootstraps on x86-64 and little endian power8 systems.  Both
systems bootstrapped fine and there were no regressions in the test suite.  I
verified that the new test case in the powerpc test directory passes.  Can I
check this into the trunk?  Can I also check this info the active branches (gcc
6/7) providing it causes no regressions?

[gcc]
2017-11-09  Michael Meissner  

PR middle_end/82333
* varasm.c (compare_constant): Take the mode of the constants into
account when comparing floating point constants.

[gcc/testsuite]
2017-11-09  Michael Meissner  

PR middle_end/82333
* gcc.target/powerpc/pr82333.c: New test.

-- 
Michael Meissner, IBM
IBM, M/S 2506R, 550 King Street, Littleton, MA 01460-6245, USA
email: meiss...@linux.vnet.ibm.com, phone: +1 (978) 899-4797
Index: gcc/varasm.c
===
--- gcc/varasm.c(revision 254556)
+++ gcc/varasm.c(working copy)
@@ -3118,10 +3118,16 @@ compare_constant (const tree t1, const t
   return tree_int_cst_equal (t1, t2);
 
 case REAL_CST:
-  /* Real constants are the same only if the same width of type.  */
+  /* Real constants are the same only if the same width of type.  In
+addition to the same width, we need to check whether the modes are the
+same.  There might be two floating point modes that are the same size
+but have different representations, such as the PowerPC that has 2
+different 128-bit floating point types (IBM extended double and IEEE
+128-bit floating point).  */
   if (TYPE_PRECISION (TREE_TYPE (t1)) != TYPE_PRECISION (TREE_TYPE (t2)))
return 0;
-
+  if (TYPE_MODE (TREE_TYPE (t1)) != TYPE_MODE (TREE_TYPE (t2)))
+   return 0;
   return real_identical (&TREE_REAL_CST (t1), &TREE_REAL_CST (t2));
 
 case FIXED_CST:
Index: gcc/testsuite/gcc.target/powerpc/pr82333.c
===
--- gcc/testsuite/gcc.target/powerpc/pr82333.c  (revision 0)
+++ gcc/testsuite/gcc.target/powerpc/pr82333.c  (revision 0)
@@ -0,0 +1,34 @@
+/* { dg-do compile { target { powerpc*-*-linux* } } } */
+/* { dg-require-effective-target ppc_float128_sw } */
+/* { dg-require-effective-target vsx_hw } */
+/* { dg-options "-mvsx -O2 -mabi=ibmlongdouble -Wno-psabi" } */
+
+/* PR 82333 was an internal compiler abort where the compiler thought that a
+   long double _Complex constant was the same as __float128 _Complex.  */
+
+_Complex long double vld;
+_Complex _Float128 vf128;
+
+_Complex long double
+fld (_Complex long double arg0)
+{
+  return 0;
+}
+
+_Complex _Float128
+ff128 (_Complex _Float128 arg0)
+{
+  return 0;
+}
+
+void
+tld (void)
+{
+  vld = fld (vld);
+}
+
+void
+tf128 (void)
+{
+  vf128 = ff128 (vf128);
+}


libgo patch committed: Don't assume that reads from address 0 crash

2017-11-09 Thread Ian Lance Taylor
This libgo patch from Tony Reix fixes libgo on AIX, where reads from
address 0 simply return 0 rather than crashing with a segmentation
violation.  The libgo code was expecting the latter, which caused some
tests to fail.  Bootstrapped and ran Go testsuite on
x86_64-pc-linux-gnu.  Committed to mainline.

Ian
Index: gcc/go/gofrontend/MERGE
===
--- gcc/go/gofrontend/MERGE (revision 254504)
+++ gcc/go/gofrontend/MERGE (working copy)
@@ -1,4 +1,4 @@
-7fd845bd9414c348bfa30bd24aa0bb8e4eebf83a
+b03c5dc36d6d0c0d3bef434936e8b924d253595b
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
Index: libgo/go/runtime/internal/atomic/atomic.c
===
--- libgo/go/runtime/internal/atomic/atomic.c   (revision 254090)
+++ libgo/go/runtime/internal/atomic/atomic.c   (working copy)
@@ -34,7 +34,7 @@ uint64_t
 Load64 (uint64_t *ptr)
 {
   if (((uintptr_t) ptr & 7) != 0)
-ptr = NULL;
+panicmem ();
   return __atomic_load_n (ptr, __ATOMIC_ACQUIRE);
 }
 
@@ -66,7 +66,7 @@ int64_t
 Loadint64 (int64_t *ptr)
 {
   if (((uintptr_t) ptr & 7) != 0)
-ptr = NULL;
+panicmem ();
   return __atomic_load_n (ptr, __ATOMIC_ACQUIRE);
 }
 
@@ -88,7 +88,7 @@ uint64_t
 Xadd64 (uint64_t *ptr, int64_t delta)
 {
   if (((uintptr_t) ptr & 7) != 0)
-ptr = NULL;
+panicmem ();
   return __atomic_add_fetch (ptr, (uint64_t) delta, __ATOMIC_SEQ_CST);
 }
 
@@ -110,7 +110,7 @@ int64_t
 Xaddint64 (int64_t *ptr, int64_t delta)
 {
   if (((uintptr_t) ptr & 7) != 0)
-ptr = NULL;
+panicmem ();
   return __atomic_add_fetch (ptr, delta, __ATOMIC_SEQ_CST);
 }
 
@@ -132,7 +132,7 @@ uint64_t
 Xchg64 (uint64_t *ptr, uint64_t new)
 {
   if (((uintptr_t) ptr & 7) != 0)
-ptr = NULL;
+panicmem ();
   return __atomic_exchange_n (ptr, new, __ATOMIC_SEQ_CST);
 }
 
@@ -184,7 +184,7 @@ _Bool
 Cas64 (uint64_t *ptr, uint64_t old, uint64_t new)
 {
   if (((uintptr_t) ptr & 7) != 0)
-ptr = NULL;
+panicmem ();
   return __atomic_compare_exchange_n (ptr, &old, new, false, __ATOMIC_SEQ_CST, 
__ATOMIC_RELAXED);
 }
 
@@ -226,7 +226,7 @@ void
 Store64 (uint64_t *ptr, uint64_t val)
 {
   if (((uintptr_t) ptr & 7) != 0)
-ptr = NULL;
+panicmem ();
   __atomic_store_n (ptr, val, __ATOMIC_SEQ_CST);
 }
 
Index: libgo/go/runtime/panic.go
===
--- libgo/go/runtime/panic.go   (revision 254090)
+++ libgo/go/runtime/panic.go   (working copy)
@@ -22,6 +22,7 @@ import (
 //go:linkname makefuncreturning runtime.makefuncreturning
 //go:linkname gorecover runtime.gorecover
 //go:linkname deferredrecover runtime.deferredrecover
+//go:linkname panicmem runtime.panicmem
 // Temporary for C code to call:
 //go:linkname throw runtime.throw
 
Index: libgo/go/sync/atomic/atomic.c
===
--- libgo/go/sync/atomic/atomic.c   (revision 254090)
+++ libgo/go/sync/atomic/atomic.c   (working copy)
@@ -26,7 +26,7 @@ int64_t
 SwapInt64 (int64_t *addr, int64_t new)
 {
   if (((uintptr_t) addr & 7) != 0)
-addr = NULL;
+panicmem ();
   return __atomic_exchange_n (addr, new, __ATOMIC_SEQ_CST);
 }
 
@@ -48,7 +48,7 @@ uint64_t
 SwapUint64 (uint64_t *addr, uint64_t new)
 {
   if (((uintptr_t) addr & 7) != 0)
-addr = NULL;
+panicmem ();
   return __atomic_exchange_n (addr, new, __ATOMIC_SEQ_CST);
 }
 
@@ -215,7 +215,7 @@ LoadInt64 (int64_t *addr)
   int64_t v;
 
   if (((uintptr_t) addr & 7) != 0)
-addr = NULL;
+panicmem ();
   v = *addr;
   while (! __sync_bool_compare_and_swap (addr, v, v))
 v = *addr;
@@ -247,7 +247,7 @@ LoadUint64 (uint64_t *addr)
   uint64_t v;
 
   if (((uintptr_t) addr & 7) != 0)
-addr = NULL;
+panicmem ();
   v = *addr;
   while (! __sync_bool_compare_and_swap (addr, v, v))
 v = *addr;
@@ -308,7 +308,7 @@ StoreInt64 (int64_t *addr, int64_t val)
   int64_t v;
 
   if (((uintptr_t) addr & 7) != 0)
-addr = NULL;
+panicmem ();
   v = *addr;
   while (! __sync_bool_compare_and_swap (addr, v, val))
 v = *addr;
@@ -338,7 +338,7 @@ StoreUint64 (uint64_t *addr, uint64_t va
   uint64_t v;
 
   if (((uintptr_t) addr & 7) != 0)
-addr = NULL;
+panicmem ();
   v = *addr;
   while (! __sync_bool_compare_and_swap (addr, v, val))
 v = *addr;
Index: libgo/runtime/runtime.h
===
--- libgo/runtime/runtime.h (revision 254090)
+++ libgo/runtime/runtime.h (working copy)
@@ -211,6 +211,8 @@ extern  uint32  runtime_panicking(void)
 extern boolruntime_isstarted;
 extern boolruntime_isarchive;
 
+extern voidpanicmem(void) __asm__ (GOSYM_PREFIX "runtime.panicmem");
+
 /*
  * common functions and data
  */


[PATCH] PR fortran/78240 -- kludge of the day

2017-11-09 Thread Steve Kargl
The following patch fixes PR fortran/78240.  It seems
to me to be inelegant, but it does pass regression
testing.  The kludgy portion occurs in decl.c.
march_clist_expr is clearly expecting an array with
constant dimension due to gcc_assert.  When -fdec
is used and one takes Gerhard code (see testcase),
the assertion is raised.  The patch checks for 
-fdec and failure of spec_size(), and then goes
to cleanup.  The second part in resolve.c is needed
to avoid a NULL pointer dereference when one forgets
to use -fdec with Gerhard's code.  I did not write a
testcase for this, because the dereference occurs in
the 5th error message emitted.  OK to commit?


2017-11-09  Steven G. Kargl  

PR fortran/78240
* decl.c (match_clist_expr): Reject malformed DEC structure.
* resolve.c (match_clist_expr): Avoid NULL pointer deference.

2017-11-09  Steven G. Kargl  

PR fortran/78240
* gfortran.dg/dec_structure_23.f90: new test.

Index: gcc/fortran/decl.c
===
--- gcc/fortran/decl.c  (revision 254603)
+++ gcc/fortran/decl.c  (working copy)
@@ -735,6 +735,8 @@ match_clist_expr (gfc_expr **result, gfc_typespec *ts,
 
   /* Validate sizes. */
   gcc_assert (gfc_array_size (expr, &size));
+  if (flag_dec && !spec_size (as, &repeat))
+   goto cleanup;
   gcc_assert (spec_size (as, &repeat));
   cmp = mpz_cmp (size, repeat);
   if (cmp < 0)
Index: gcc/fortran/resolve.c
===
--- gcc/fortran/resolve.c   (revision 254603)
+++ gcc/fortran/resolve.c   (working copy)
@@ -15284,7 +15290,7 @@ check_data_variable (gfc_data_variable *var, locus *wh
   if (!gfc_array_size (e, &size))
{
  gfc_error ("Nonconstant array section at %L in DATA statement",
-&e->where);
+where);
  mpz_clear (offset);
  return false;
}
Index: gcc/testsuite/gfortran.dg/dec_structure_23.f90
===
--- gcc/testsuite/gfortran.dg/dec_structure_23.f90  (nonexistent)
+++ gcc/testsuite/gfortran.dg/dec_structure_23.f90  (working copy)
@@ -0,0 +1,9 @@
+! { dg-do compile }
+! { dg-options "-fdec" }
+! PR fortran/78240
+! Contributed by Gerhard Steinmetz
+program p
+   structure /s/
+  integer x(n) /1/  ! { dg-error "Unclassifiable statement" }
+   end structure
+end

-- 
Steve


Re: [PING][patch] PR81794: have "would be stringified in traditional C" warning in libcpp/macro.c be controlled by -Wtraditional

2017-11-09 Thread Eric Gallager
Ping again: https://gcc.gnu.org/ml/gcc-patches/2017-11/msg00123.html

On 11/2/17, Eric Gallager  wrote:
> Ping: https://gcc.gnu.org/ml/gcc-patches/2017-10/msg01834.html
>
> On 10/25/17, Eric Gallager  wrote:
>> On Sat, Sep 30, 2017 at 8:05 PM, Eric Gallager 
>> wrote:
>>> On Fri, Sep 29, 2017 at 11:15 AM, David Malcolm 
>>> wrote:
 On Sun, 2017-09-17 at 20:00 -0400, Eric Gallager wrote:
> Attached is a version of
> https://gcc.gnu.org/ml/gcc-patches/2017-05/msg00481.html that
> contains
> a combination of both the fix and the testcase update, as requested
> in
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81794#c2
>
> I had to use a different computer than I usually use to send this
> email, as the hard drive that originally had this patch is currently
> unresponsive. Since it's also the one with my ssh keys on it, I can't
> commit with it. Sorry if the ChangeLogs get mangled.

 Thanks for putting this together; sorry about the delay in reviewing
 it.

 The patch mostly looks good.

 Did you perform a full bootstrap and run of the testsuite with this
 patch?  If so, it's best to state this in the email, so that we know
 that the patch has survived this level of testing.
>>>
>>> Yes, I bootstrapped with it, but I haven't done a full run of the
>>> testsuite with it yet; just the one testcase I updated.
>>
>> Update: I've now run the testsuite with it; test results are here:
>> https://gcc.gnu.org/ml/gcc-testresults/2017-10/msg01751.html
>> I'm pretty sure all the FAILs are unrelated to this patch.
>>
>>>

 Some nits below:

> libcpp/ChangeLog:
>
> 2017-03-24  Eric Gallager  
>
>  * macro.c (check_trad_stringification): Have warning be
> controlled by
>  -Wtraditional.
>
> gcc/testsuite/ChangeLog:
>
> 2017-09-17  Eric Gallager  
>
> PR preprocessor/81794
> * gcc.dg/pragma-diag-7.c: Update to include check for
> stringification.
>
> On Sat, May 6, 2017 at 11:33 AM, Eric Gallager 
> wrote:
> > Pinging this: https://gcc.gnu.org/ml/gcc-patches/2017-03/msg01325.h
> > tml
> >
> > On 3/24/17, Eric Gallager  wrote:
> > > It seemed odd to me that gcc was issuing a warning about
> > > compatibility
> > > with traditional C that I couldn't turn off by pushing/popping
> > > -Wtraditional over the problem area, so I made the attached
> > > (minor)
> > > patch to fix it. Survives bootstrap, but the only testing I've
> > > done
> > > with it has been compiling the one file that was giving me issues
> > > previously, which I'd need to reduce further to turn it into a
> > > proper
> > > test case.
> > >
> > > Thanks,
> > > Eric Gallager
> > >
> > > libcpp/ChangeLog:
> > >
> > > 2017-03-24  Eric Gallager  
> > >
> > >   * macro.c (check_trad_stringification): Have warning be
> > > controlled by
> > >   -Wtraditional.
> > >
> >
> > So I did the reducing I mentioned above and now have a testcase for
> > it; it was pretty similar to the one from here:
> > https://gcc.gnu.org/ml/gcc-patches/2017-03/msg01319.html
> > so I combined them into a single testcase and have attached the
> > combined version. I can confirm that the testcase passes with my
> > patch
> > applied.

 [...]

> diff --git a/gcc/testsuite/gcc.dg/pragma-diag-7.c
> b/gcc/testsuite/gcc.dg/pragma-diag-7.c
> index 402ee56..e06c410 100644
> --- a/gcc/testsuite/gcc.dg/pragma-diag-7.c
> +++ b/gcc/testsuite/gcc.dg/pragma-diag-7.c
> @@ -7,3 +7,16 @@ unsigned long bad = 1UL; /* { dg-warning "suffix" }
> */
>  /* Note the extra space before the pragma on this next line: */
>   #pragma GCC diagnostic pop
>  unsigned long ok_again = 2UL; /* { dg-bogus "suffix" } */
> +
> +/* Redundant with the previous pop, but just shows that it fails to
> stop the
> + * following warning with an unpatched GCC: */
> +#pragma GCC diagnostic ignored "-Wtraditional"
> +
> +/* { dg-bogus "would be stringified" .+1 } */

 As far as I can tell, this dg-bogus line doesn't actually get matched;
 when I run the testsuite without the libcpp fix, I get:

   FAIL: gcc.dg/pragma-diag-7.c (test for excess errors)

 If I update the dg-bogus line to read:

   /* { dg-bogus "would be stringified" "" { target *-*-* } .+1 } */

 then it's matched, and I get:

   FAIL: gcc.dg/pragma-diag-7.c  (test for bogus messages, line 16)

 I believe that as written the ".+1" 2nd argument is interpreted as a
 human-readable description of the problem, rather than as a line
 offset; I believe you would need to add positional args for the
 description and filter so that the line offset is argument 4.

 That said, I think the dg-bogus her

[committed][PATCH] Avoid references to vrp_equiv_obstack

2017-11-09 Thread Jeff Law

This was broken out of the first tree-vrp refactoring patch.  This patch
avoids a couple references to vrp_equiv_obstack.  This makes the
subsequent refactoring work easier.

Richi approved this as part of the larger patch.  But since I had it
pulled out, I'm going to commit it individually.  I'm posting the patch
here for archival purposes.

Bootstrapped and regression tested on x86_64.

Jeff

commit f5b45b9dac2b7b793998d2b70ce8f5b7a1cffbf4
Author: Jeff Law 
Date:   Wed Nov 8 11:59:54 2017 -0500

* tree-vrp.c (set_value_range): Do not reference vrp_equiv_obstack.
Get it from the existing bitmap instead.
(vrp_intersect_ranges_1): Likewise.

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 0dc2057c08d..16bec6ec00b 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,9 @@
+2017-11-09  Jeff Law  
+
+   * tree-vrp.c (set_value_range): Do not reference vrp_equiv_obstack.
+   Get it from the existing bitmap instead.
+   (vrp_intersect_ranges_1): Likewise.
+
 2017-11-09  Jakub Jelinek  
 
* gimple-ssa-store-merging.c (struct store_immediate_info): Add
diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c
index 2b7d9622f69..8e86b060ae7 100644
--- a/gcc/tree-vrp.c
+++ b/gcc/tree-vrp.c
@@ -272,10 +272,13 @@ set_value_range (value_range *vr, enum value_range_type 
t, tree min,
   vr->max = max;
 
   /* Since updating the equivalence set involves deep copying the
- bitmaps, only do it if absolutely necessary.  */
+ bitmaps, only do it if absolutely necessary.
+
+ All equivalence bitmaps are allocated from the same obstack.  So
+ we can use the obstack associated with EQUIV to allocate vr->equiv.  */
   if (vr->equiv == NULL
   && equiv != NULL)
-vr->equiv = BITMAP_ALLOC (&vrp_equiv_obstack);
+vr->equiv = BITMAP_ALLOC (equiv->obstack);
 
   if (equiv != vr->equiv)
 {
@@ -8828,7 +8831,9 @@ vrp_intersect_ranges_1 (value_range *vr0, value_range 
*vr1)
 bitmap_ior_into (vr0->equiv, vr1->equiv);
   else if (vr1->equiv && !vr0->equiv)
 {
-  vr0->equiv = BITMAP_ALLOC (&vrp_equiv_obstack);
+  /* All equivalence bitmaps are allocated from the same obstack.  So
+we can use the obstack associated with VR to allocate vr0->equiv.  */
+  vr0->equiv = BITMAP_ALLOC (vr1->equiv->obstack);
   bitmap_copy (vr0->equiv, vr1->equiv);
 }
 }


[committed][PATCH] Move classes to earlier point in file

2017-11-09 Thread Jeff Law

This was broken out of the first tree-vrp refactoring patch.  This patch
just moves two classes to earlier points in the file.

Richi approved this as part of the larger patch.  But since I had it
pulled out, I'm going to commit it individually.  I'm posting the patch
here for archival purposes.

Bootstrapped and regression tested on x86_64.

Jeff
commit 03a28fc2e61f529be691f5b3f884b25d79044864
Author: law 
Date:   Thu Nov 9 23:04:20 2017 +

* tree-vrp.c (vrp_prop): Move class to earlier point in the file.
(vrp_folder): Likewise.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@254612 
138bc75d-0d04-0410-961f-82ee72b054a4

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 16bec6ec00b..9b93a852099 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,5 +1,8 @@
 2017-11-09  Jeff Law  
 
+   * tree-vrp.c (vrp_prop): Move class to earlier point in the file.
+   (vrp_folder): Likewise.
+
* tree-vrp.c (set_value_range): Do not reference vrp_equiv_obstack.
Get it from the existing bitmap instead.
(vrp_intersect_ranges_1): Likewise.
diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c
index 8e86b060ae7..fc9ad4adebe 100644
--- a/gcc/tree-vrp.c
+++ b/gcc/tree-vrp.c
@@ -6635,6 +6635,13 @@ insert_range_assertions (void)
   BITMAP_FREE (need_assert_for);
 }
 
+class vrp_prop : public ssa_propagation_engine
+{
+ public:
+  enum ssa_prop_result visit_stmt (gimple *, edge *, tree *) FINAL OVERRIDE;
+  enum ssa_prop_result visit_phi (gphi *) FINAL OVERRIDE;
+};
+
 /* Checks one ARRAY_REF in REF, located at LOCUS. Ignores flexible arrays
and "struct" hacks. If VRP can determine that the
array subscript is a constant, check if it is outside valid
@@ -8066,13 +8073,6 @@ extract_range_from_stmt (gimple *stmt, edge 
*taken_edge_p,
 vrp_visit_switch_stmt (as_a  (stmt), taken_edge_p);
 }
 
-class vrp_prop : public ssa_propagation_engine
-{
- public:
-  enum ssa_prop_result visit_stmt (gimple *, edge *, tree *) FINAL OVERRIDE;
-  enum ssa_prop_result visit_phi (gphi *) FINAL OVERRIDE;
-};
-
 /* Evaluate statement STMT.  If the statement produces a useful range,
return SSA_PROP_INTERESTING and record the SSA name with the
interesting range into *OUTPUT_P.
@@ -10450,6 +10450,13 @@ simplify_stmt_using_ranges (gimple_stmt_iterator *gsi)
   return false;
 }
 
+class vrp_folder : public substitute_and_fold_engine
+{
+ public:
+  tree get_value (tree) FINAL OVERRIDE;
+  bool fold_stmt (gimple_stmt_iterator *) FINAL OVERRIDE;
+};
+
 /* If the statement pointed by SI has a predicate whose value can be
computed using the value range information computed by VRP, compute
its value and return true.  Otherwise, return false.  */
@@ -10512,13 +10519,6 @@ fold_predicate_in (gimple_stmt_iterator *si)
   return false;
 }
 
-class vrp_folder : public substitute_and_fold_engine
-{
- public:
-  tree get_value (tree) FINAL OVERRIDE;
-  bool fold_stmt (gimple_stmt_iterator *) FINAL OVERRIDE;
-};
-
 /* Callback for substitute_and_fold folding the stmt at *SI.  */
 
 bool


Re: [patch] Fix EH breakage in LTO mode

2017-11-09 Thread Eric Botcazou
> this is PR lto/81351.

Totally missed it...  Do not hesitate to CC me for SPARC regressions.

-- 
Eric Botcazou


  1   2   >