Re: [PATCH] Add -fsanitize=pointer-{compare,subtract}.

2017-10-10 Thread Martin Liška
On 10/06/2017 03:33 PM, Jakub Jelinek wrote:
> On Fri, Oct 06, 2017 at 02:46:05PM +0200, Martin Liška wrote:
>> +  if (sanitize_comparison_p)
>> +{
>> +  if (is_gimple_assign (s)
>> +  && gimple_assign_rhs_class (s) == GIMPLE_BINARY_RHS
>> +  && POINTER_TYPE_P (TREE_TYPE (gimple_assign_rhs1 (s)))
>> +  && POINTER_TYPE_P (TREE_TYPE (gimple_assign_rhs2 (s)))
>> +  && is_pointer_compare_opcode (gimple_assign_rhs_code (s)))
> 

Hello.

> Isn't it better to test is_pointer_compare_opcode right after
> is_gimple_assign and leave the gimple_assign_rhs_class test out?

Yes, it is :)

> 
>> +{
>> +  ptr1 = gimple_assign_rhs1 (s);
>> +  ptr2 = gimple_assign_rhs2 (s);
>> +  fn = BUILT_IN_ASAN_POINTER_COMPARE;
>> +}
>> +  else if (gimple_code (s) == GIMPLE_COND
>> +   && POINTER_TYPE_P (TREE_TYPE (gimple_cond_lhs (s)))
>> +   && POINTER_TYPE_P (TREE_TYPE (gimple_cond_rhs (s)))
>> +   && is_pointer_compare_opcode (gimple_cond_code (s)))
>> +{
>> +  ptr1 = gimple_cond_lhs (s);
>> +  ptr2 = gimple_cond_rhs (s);
>> +  fn = BUILT_IN_ASAN_POINTER_COMPARE;
>> +}
> 
> You don't handle the case when there is a COND_EXPR with pointer comparison
> in the condition.

Good point, fixed.

> 
>> +}
>> +
>> +  if (sanitize_subtraction_p
>> +  && is_gimple_assign (s)
>> +  && gimple_assign_rhs_class (s) == GIMPLE_BINARY_RHS
> 
> The above isn't really needed.
> 
>> +  && gimple_assign_rhs_code (s) == MINUS_EXPR)
>> +{
>> +  tree rhs1 = gimple_assign_rhs1 (s);
>> +  tree rhs2 = gimple_assign_rhs2 (s);
>> +
>> +  if (TREE_CODE (rhs1) == SSA_NAME
>> +  || TREE_CODE (rhs2) == SSA_NAME)
>> +{
>> +  gassign *def1
>> += dyn_cast(SSA_NAME_DEF_STMT (rhs1));
>> +  gassign *def2
>> += dyn_cast(SSA_NAME_DEF_STMT (rhs2));
>> +
>> +  if (def1 && def2
>> +  && gimple_assign_rhs_class (def1) == GIMPLE_UNARY_RHS
>> +  && gimple_assign_rhs_class (def2) == GIMPLE_UNARY_RHS)
>> +{
>> +  if (POINTER_TYPE_P (TREE_TYPE (gimple_assign_rhs1 (def1)))
>> +  && POINTER_TYPE_P
>> +  (TREE_TYPE (gimple_assign_rhs1 (def2
> 
> Better add temporaries for rhs1/2 of def1, then you don't have issues with
> too long lines.

Yes.

> 
>> --- a/gcc/doc/invoke.texi
>> +++ b/gcc/doc/invoke.texi
>> @@ -10935,6 +10935,26 @@ Enable AddressSanitizer for Linux kernel.
>>  See @uref{https://github.com/google/kasan/wiki} for more details.
>>  The option cannot be combined with @option{-fcheck-pointer-bounds}.
>>  
>> +@item -fsanitize=pointer-compare
>> +@opindex fsanitize=pointer-compare
>> +Instrument comparison operation (<, <=, >, >=, -) with pointer operands.
> 
> Poiinter-compare doesn't instrument -, so ", -" should be left out.

That's typo.

> 
>> +The option cannot be combined with @option{-fsanitize=thread}
>> +and/or @option{-fcheck-pointer-bounds}.
>> +Note: By default the check is disabled at run time.  To enable it,
>> +add @code{detect_invalid_pointer_pairs=1} to the environment variable
>> +@env{ASAN_OPTIONS}.  The checking currently works only for pointers 
>> allocated
>> +on heap.
>> +
>> +@item -fsanitize=subtract
> 
> -fsanitize=pointer-subtract
> 
>> +@opindex fsanitize=pointer-compare
> 
> s/compare/subtract/

Likewise.

> 
>> +Instrument subtraction with pointer operands.
>> +The option cannot be combined with @option{-fsanitize=thread}
>> +and/or @option{-fcheck-pointer-bounds}.
>> +Note: By default the check is disabled at run time.  To enable it,
>> +add @code{detect_invalid_pointer_pairs=1} to the environment variable
>> +@env{ASAN_OPTIONS}.  The checking currently works only for pointers 
>> allocated
>> +on heap.
>> +
>>  @item -fsanitize=thread
>>  @opindex fsanitize=thread
>>  Enable ThreadSanitizer, a fast data race detector.
> 
> Conceptually, these two instrumentations rely on address sanitization,
> not really sure if we should supporting them for kernel sanitization (but I
> bet it is just going to be too costly for kernel).
> So, we also need to make sure at least parts of SANITIZE_ADDRESS is enabled
> when these options are on.
> That can be done by erroring out if -fsanitize=pointer-compare is requested
> without -fsanitize=address, or by implicitly enabling -fsanitize=address for
> these, or by adding yet another SANITIZE_* bit which would cover
> sanitization of memory accesses for asan, that bit would be set by
> -fsanitize={address,kernel-address} in addition to the current 2 bits, but
> pointer-{subtract,compare} would set its own bit and SANITIZE_ADDRESS and
> SANITIZE_USER_ADDRESS only.  Without the new bit we'd emit red zones,
> 

Re: Fix profile update in switch conversion

2017-10-10 Thread Martin Liška
On 10/10/2017 07:39 PM, Jan Hubicka wrote:
>> Hi Honza,
>>
>> The change here cause the following failures:
>>
>>> FAIL: gcc.dg/tree-prof/switch-case-1.c scan-rtl-dump-times expand ";; basic 
>>> block[^\\n]*count 2000" 1
>>> FAIL: gcc.dg/tree-prof/switch-case-2.c scan-rtl-dump-times expand ";; basic 
>>> block[^\\n]*count 2000" 1
>>
>>
>> I checked that, after the change, there are two matches in the dump file.
>>
>>
>>> ;; basic block 8, loop depth 0, count 2000 (adjusted), freq 2000, maybe hot
>>> ;; basic block 23, loop depth 0, count 2000, freq 2000, maybe hot
>>
>>
>> And without the change, there is only one match.
>>
>>> ;; basic block 23, loop depth 0, count 2000, freq 2000, maybe hot
> 
> I have also noticed that yesterday.  The problem was hidden previously 
> because there was
> edges with no counts.  There are some mismatches in profile constructed and I 
> hoped that
> perhaps Martin will know how to fix these right away?
> Otherwise I will take a look tomorrow ;)

Hi.

Yep, I'll fix that :)

Martin

> 
> Honza
>>
>> Regards,
>> Renlin
>>
>>
>> On 06/10/17 13:18, Jan Hubicka wrote:
>>> Hi,
>>> this patch fixes missing profile updat that triggers during 
>>> profiledbootstrap.
>>>
>>> Honza
>>>
>>> * tree-switch-conversion.c (do_jump_if_equal, emit_cmp_and_jump_insns):
>>> Update edge counts.
>>>
>>> Index: tree-switch-conversion.c
>>> ===
>>> --- tree-switch-conversion.c(revision 253444)
>>> +++ tree-switch-conversion.c(working copy)
>>> @@ -2248,10 +2248,12 @@ do_jump_if_equal (basic_block bb, tree o
>>>edge false_edge = split_block (bb, cond);
>>>false_edge->flags = EDGE_FALSE_VALUE;
>>>false_edge->probability = prob.invert ();
>>> +  false_edge->count = bb->count.apply_probability 
>>> (false_edge->probability);
>>>
>>>edge true_edge = make_edge (bb, label_bb, EDGE_TRUE_VALUE);
>>>fix_phi_operands_for_edge (true_edge, phi_mapping);
>>>true_edge->probability = prob;
>>> +  true_edge->count = bb->count.apply_probability (true_edge->probability);
>>>
>>>return false_edge->dest;
>>>  }
>>> @@ -2291,10 +2293,12 @@ emit_cmp_and_jump_insns (basic_block bb,
>>>edge false_edge = split_block (bb, cond);
>>>false_edge->flags = EDGE_FALSE_VALUE;
>>>false_edge->probability = prob.invert ();
>>> +  false_edge->count = bb->count.apply_probability 
>>> (false_edge->probability);
>>>
>>>edge true_edge = make_edge (bb, label_bb, EDGE_TRUE_VALUE);
>>>fix_phi_operands_for_edge (true_edge, phi_mapping);
>>>true_edge->probability = prob;
>>> +  true_edge->count = bb->count.apply_probability (true_edge->probability);
>>>
>>>return false_edge->dest;
>>>  }
>>>



Re: Fwd: [PATCH] scheduler bug fix for AArch64 insn fusing SCHED_GROUP usage

2017-10-10 Thread Jim Wilson
On Sun, 2017-09-10 at 19:45 +0200, Jim Wilson wrote:
> -- Forwarded message --
> From: Jim Wilson 
> Date: Tue, Sep 5, 2017 at 8:04 PM
> Subject: Re: [PATCH] scheduler bug fix for AArch64 insn fusing
> SCHED_GROUP usage
> To: "gcc-patches@gcc.gnu.org" 
> Cc: Jim Wilson 
> 
> 
> ping^2
> 
> On Fri, Jul 21, 2017 at 3:09 PM, Jim Wilson 
> wrote:
> > 
> > Ping.
> > 
> > https://gcc.gnu.org/ml/gcc-patches/2017-07/msg00779.html
> > 

Silly me.  I noticed that I am still listed as a sched maintainer,
which means I can self approve this.

I reverified it with x86_64 and aarch64 bootstraps and make checks.  I
also did a C only testsuite run for avr, which appears to be the best
maintained cc0 target.  There were no regressions for any of the 3
targets.

The patch was applied.

Jim
2017-10-10  Jim Wilson  

	PR rtl-optimization/81434
	* haifa-sched.c (prune_ready_list): Init min_cost_group to 0.  Update
	comment for main loop.  In sched_group_found if, also add checks for
	pass and min_cost_group.

Index: haifa-sched.c
===
--- haifa-sched.c	(revision 253627)
+++ haifa-sched.c	(revision 253628)
@@ -6303,7 +6303,7 @@ prune_ready_list (state_t temp_state, bool first_c
 {
   int i, pass;
   bool sched_group_found = false;
-  int min_cost_group = 1;
+  int min_cost_group = 0;
 
   if (sched_fusion)
 return;
@@ -6319,8 +6319,8 @@ prune_ready_list (state_t temp_state, bool first_c
 }
 
   /* Make two passes if there's a SCHED_GROUP_P insn; make sure to handle
- such an insn first and note its cost, then schedule all other insns
- for one cycle later.  */
+ such an insn first and note its cost.  If at least one SCHED_GROUP_P insn
+ gets queued, then all other insns get queued for one cycle later.  */
   for (pass = sched_group_found ? 0 : 1; pass < 2; )
 {
   int n = ready.n_ready;
@@ -6333,7 +6333,8 @@ prune_ready_list (state_t temp_state, bool first_c
 	  if (DEBUG_INSN_P (insn))
 	continue;
 
-	  if (sched_group_found && !SCHED_GROUP_P (insn))
+	  if (sched_group_found && !SCHED_GROUP_P (insn)
+	  && ((pass == 0) || (min_cost_group >= 1)))
 	{
 	  if (pass == 0)
 		continue;


Re: [PATCH] Add a warning for invalid function casts

2017-10-10 Thread Martin Sebor

On 10/10/2017 03:48 PM, Joseph Myers wrote:

On Tue, 10 Oct 2017, Martin Sebor wrote:


Calling a function that takes arguments via a void (*)(void)
is undefined not just on paper but also in practice, so the
resulting pointer from such a cast is unusable except to convert
to a compatible pointer.


That's the point of a generic pointer - it either gets cast to the actual
type (or something ABI-compatible with the actual type) for calls, or
called from non-C code which has the same effect.


Sure.  But (as you note below) any function pointer can be used
as a generic function pointer.  There's nothing unique or special
about void (*)(void) to make it particularly suitable for this
purpose.

But we're conflating two use cases: 1) converting to a generic
function pointer that's never used to call a function, and 2)
converting to a function pointer that's used to call a function
not strictly compatible with it but where the ABI obviates
the incompatibility.

The ideal solution for 1) would be a function pointer that can
never be used to call a function (i.e., the void* equivalent
for functions).[X]

I argue the ideal solution for 2) is void (*)() (or something
like it).  It's superior to void(*)(void) because it makes its
intent in a cast clear: ignore the types of the target function's
formal arguments.  Contrast that with void(*)(void) which could
mean one of two things: a) follow the type system rules, or b)
treat it as special and ignore the type system.  Accepting (b)
when (a) so clearly expresses the intent of this use case seems
like a clearly inferior choice to me.


PS It would be useful if modern C provided a clean mechanism to
support generic function pointers rather that forcing users leery
of relying on obsolescent features to invent workarounds.  One


You can use any function pointer type whatever as your generic pointer
(casting back to the original type for calls).  That you can cast from one
function pointer type to another and back to the original type is
guaranteed by ISO C.  That the result of the conversion is meaningful for
calls from non-C languages is part of the customary practices of C
implementations.  That the type used is void (*) (void) is a common
convention used in C code dealing with generic function pointers (another
convention, of course, is just using void * as in POSIX and relying on
conversions between function pointers and void *).


Right.  The problem Bernd and I are trying to solve is how to
distinguish the last one from the other two use cases on this
list:

1) a conversion of an arbitrary function to a generic pointer
   that's only used for storage but never to call the function
   directly, without converting it to the original function's
   type (see also [X] below),
2) a conversion of an arbitrary function to some strictly
   incompatible type that is nonetheless safe to use (by the
   ABI rules) to call the original function, and
3) all other conversions that are likely mistakes/bugs and
   that should be diagnosed.

My claim, again, is that using void(*)() for both (1) and (2)
above (or a moral equivalent of it, such as void(*)(...)) is
a superior solution than any other that we have seen, including
void(*)(void), because it clearly expresses the intent (no type
checking) and doesn't exclude any type from the set to check for
compatibility.

Incidentally, void(*)(void) in C++ is a poor choice for this
use case also because of the language's default function
arguments.  It's an easy mistake for a C++ programmer to make
to assume that given, say:

  void foo (const char *s = "...");

or for any other function that provides default values for all
its arguments, the function may be callable via void(*)(void):

  typedef void F (void);

  void (pf)(void) = (F*)foo;

by having the (default) function argument value(s) magically
substituted at the call site of:

   pf ();

Bu since that's not the case it would be helpful for the new
warning to detect this mistake.  By encouraging the use of

  typedef void F (...);

as the type of a pointer there is little chance of making such
a mistake.

Martin

[X] This can be function that takes an argument of an incomplete
type, such as:

  struct Incomplete;
  typedef void Uncallable (struct Incomplete);

Any function can safely be converted to Uncallable* without
the risk of being called with the wrong arguments.  The only
way to use an Uncallable* is to explicitly convert it to
a pointer to a function that can be called.


[PATCH] i386: Check red zone size in push peephole2

2017-10-10 Thread H.J. Lu
Check red zone size, instead of if red zone is available, in push
peephole2s.

Tested on i686 and x86-64.  OK for master?


H.J.
---
gcc/

PR target/82499
* config/i386/i386.h (x86_red_zone_size): New.
* config/i386/i386.md (push peephole2s): Replace
"!ix86_using_red_zone ()" with "ix86_red_zone_size == 0".

gcc/testsuite/

PR target/82499
* gcc.target/i386/pr82499-1.c: New file.
* gcc.target/i386/pr82499-2.c: Likewise.
* gcc.target/i386/pr82499-3.c: Likewise.
---
 gcc/config/i386/i386.h|  1 +
 gcc/config/i386/i386.md   |  8 
 gcc/testsuite/gcc.target/i386/pr82499-1.c | 21 +
 gcc/testsuite/gcc.target/i386/pr82499-2.c | 21 +
 gcc/testsuite/gcc.target/i386/pr82499-3.c | 21 +
 5 files changed, 68 insertions(+), 4 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/i386/pr82499-1.c
 create mode 100644 gcc/testsuite/gcc.target/i386/pr82499-2.c
 create mode 100644 gcc/testsuite/gcc.target/i386/pr82499-3.c

diff --git a/gcc/config/i386/i386.h b/gcc/config/i386/i386.h
index ef88d89cae2..197f4e22d91 100644
--- a/gcc/config/i386/i386.h
+++ b/gcc/config/i386/i386.h
@@ -2603,6 +2603,7 @@ struct GTY(()) machine_function {
 #define ix86_current_function_calls_tls_descriptor \
   (ix86_tls_descriptor_calls_expanded_in_cfun && df_regs_ever_live_p (SP_REG))
 #define ix86_static_chain_on_stack (cfun->machine->static_chain_on_stack)
+#define x86_red_zone_size (cfun->machine->frame.red_zone_size)
 
 /* Control behavior of x86_file_start.  */
 #define X86_FILE_START_VERSION_DIRECTIVE false
diff --git a/gcc/config/i386/i386.md b/gcc/config/i386/i386.md
index 1a794c0ae06..57d446857af 100644
--- a/gcc/config/i386/i386.md
+++ b/gcc/config/i386/i386.md
@@ -18827,7 +18827,7 @@
  (clobber (mem:BLK (scratch)))])]
   "(TARGET_SINGLE_PUSH || optimize_insn_for_size_p ())
&& INTVAL (operands[0]) == -GET_MODE_SIZE (word_mode)
-   && !ix86_using_red_zone ()"
+   && x86_red_zone_size == 0"
   [(clobber (match_dup 1))
(parallel [(set (mem:W (pre_dec:P (reg:P SP_REG))) (match_dup 1))
  (clobber (mem:BLK (scratch)))])])
@@ -18841,7 +18841,7 @@
  (clobber (mem:BLK (scratch)))])]
   "(TARGET_DOUBLE_PUSH || optimize_insn_for_size_p ())
&& INTVAL (operands[0]) == -2*GET_MODE_SIZE (word_mode)
-   && !ix86_using_red_zone ()"
+   && x86_red_zone_size == 0"
   [(clobber (match_dup 1))
(set (mem:W (pre_dec:P (reg:P SP_REG))) (match_dup 1))
(parallel [(set (mem:W (pre_dec:P (reg:P SP_REG))) (match_dup 1))
@@ -18856,7 +18856,7 @@
  (clobber (reg:CC FLAGS_REG))])]
   "(TARGET_SINGLE_PUSH || optimize_insn_for_size_p ())
&& INTVAL (operands[0]) == -GET_MODE_SIZE (word_mode)
-   && !ix86_using_red_zone ()"
+   && x86_red_zone_size == 0"
   [(clobber (match_dup 1))
(set (mem:W (pre_dec:P (reg:P SP_REG))) (match_dup 1))])
 
@@ -18868,7 +18868,7 @@
  (clobber (reg:CC FLAGS_REG))])]
   "(TARGET_DOUBLE_PUSH || optimize_insn_for_size_p ())
&& INTVAL (operands[0]) == -2*GET_MODE_SIZE (word_mode)
-   && !ix86_using_red_zone ()"
+   && x86_red_zone_size == 0"
   [(clobber (match_dup 1))
(set (mem:W (pre_dec:P (reg:P SP_REG))) (match_dup 1))
(set (mem:W (pre_dec:P (reg:P SP_REG))) (match_dup 1))])
diff --git a/gcc/testsuite/gcc.target/i386/pr82499-1.c 
b/gcc/testsuite/gcc.target/i386/pr82499-1.c
new file mode 100644
index 000..3aba62a466f
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr82499-1.c
@@ -0,0 +1,21 @@
+/* { dg-do compile } */
+/* The pic register save adds unavoidable stack pointer references.  */
+/* { dg-skip-if "" { ia32 && { ! nonpic } } } */
+/* These options are selected to ensure 1 word needs to be allocated
+   on the stack to maintain alignment for the call.  This should be
+   transformed to push+pop.  We also want to force unwind info updates.  */
+/* { dg-options "-Os -fomit-frame-pointer -fasynchronous-unwind-tables" } */
+/* { dg-additional-options "-mpreferred-stack-boundary=3" { target ia32 } } */
+/* { dg-additional-options "-mpreferred-stack-boundary=4" { target { ! ia32 } 
} } */
+/* ms_abi has reserved stack-region.  */
+/* { dg-skip-if "" { x86_64-*-mingw* } } */
+
+extern void g (void);
+int
+f (void)
+{
+  g ();
+  return 42;
+}
+
+/* { dg-final { scan-assembler-not "(sub|add)(l|q)\[\\t \]*\\$\[0-9\]*,\[\\t 
\]*%\[re\]?sp" } } */
diff --git a/gcc/testsuite/gcc.target/i386/pr82499-2.c 
b/gcc/testsuite/gcc.target/i386/pr82499-2.c
new file mode 100644
index 000..dde4d657e1a
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr82499-2.c
@@ -0,0 +1,21 @@
+/* { dg-do compile } */
+/* The pic register save adds unavoidable stack pointer references.  */
+/* { dg-skip-if "" { ia32 && { ! nonpic } } } */
+/* These options are selected to ensure 1 word needs to be allocated
+   on the stack to maintain alignment for the call.  This should be
+   transformed 

Re: [PATCH][mingw] Enable colorized diagnostics

2017-10-10 Thread Liu Hao

On 2017/10/11 5:04, Manuel López-Ibáñez wrote:

Ops! You're obviously right. What was I thinking?

I still believe that pretty-printer.c is not the right place for all 
this color-handling code (diagnostic-color.c or libiberty/ may be better 
places).
No and yes. The colors emerge only when those messages are sent to a 
terminal. Plain arrays of characters don't have colors. So it is _the_ 
printer that does colorization.


Indeed I hope this host-specific code could go elsewhere. My initial 
attempt to move it to a separated .c file failed, as I mentioned in the 
very first mail.


Also, your code handles a lot more ANSI codes than those needed 
for color output. The code in grep seems much simpler. Could your fputs 
replacement split the string as you suggest above, then if the chunk is 
an ANSI code, use grep's conversion function to transform the codes, 
otherwise use fputs to print text.


At the moment I implemented it, I knew GCC was making of coloring and 
erase-line codes, while still had no idea whether more codes should be 
needed in the future. Hence almost all codes viable have been implemented.


I hope one day GREP people will be copying my code from GCC. Don't tell 
them. XD



Cheers,

Manuel.





--
Best regards,
LH_Mouse



Re: [RFC] overflow safe scaling of 64bit values

2017-10-10 Thread David Edelsohn
> Any ideas for better version? If not I will go ahead with this variant and
> increase profile probability base.

Why not use GCC wide int?

- David


[PATCH] rs6000: insn_cost

2017-10-10 Thread Segher Boessenkool
This adds an implementation of the insn_cost hook to rs6000.

This implementations is very minimal (so far).  It is mostly based on
how many machine instructions are generated by an RTL insn, and it also
looks at the instruction type.  Floating point insns are costed as if
all machine instructions it generates are floating point; the other
insns are treated as if all but one are integer insns (and one is the
specified type).  Load instructions are treated as costing twice as
much, and load locked and sync insns as three times as much (just like
the original costs), and integer div and mul are handled as well.

Each define_insn (etc.) can set a "cost" attribute to override this
general cost.  With optimization for size, the cost is set equal to the
value of the "length" attribute.

With this, the majority of cost differences between old and new are
where the old was wrong.  Also, benchmarks show a slight win (if
anything).  Some refinements are obviously needed.

Tested on powerpc64-linux {-m32,-m64}; committing to trunk.


Segher


2017-10-10  Segher Boessenkool  

* config/rs6000/rs6000.c (TARGET_INSN_COST): New.
(rs6000_insn_cost): New function.
* config/rs6000/rs6000.md (cost): New attribute.

---
 gcc/config/rs6000/rs6000.c  | 84 +
 gcc/config/rs6000/rs6000.md |  4 +++
 2 files changed, 88 insertions(+)

diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c
index f98ef93..744533b 100644
--- a/gcc/config/rs6000/rs6000.c
+++ b/gcc/config/rs6000/rs6000.c
@@ -1728,6 +1728,8 @@ static const struct attribute_spec 
rs6000_attribute_table[] =
 #define TARGET_RTX_COSTS rs6000_rtx_costs
 #undef TARGET_ADDRESS_COST
 #define TARGET_ADDRESS_COST hook_int_rtx_mode_as_bool_0
+#undef TARGET_INSN_COST
+#define TARGET_INSN_COST rs6000_insn_cost
 
 #undef TARGET_INIT_DWARF_REG_SIZES_EXTRA
 #define TARGET_INIT_DWARF_REG_SIZES_EXTRA rs6000_init_dwarf_reg_sizes_extra
@@ -34932,6 +34934,88 @@ rs6000_debug_rtx_costs (rtx x, machine_mode mode, int 
outer_code,
   return ret;
 }
 
+static int
+rs6000_insn_cost (rtx_insn *insn, bool speed)
+{
+  if (recog_memoized (insn) < 0)
+return 0;
+
+  if (!speed)
+return get_attr_length (insn);
+
+  int cost = get_attr_cost (insn);
+  if (cost > 0)
+return cost;
+
+  int n = get_attr_length (insn) / 4;
+  enum attr_type type = get_attr_type (insn);
+
+  switch (type)
+{
+case TYPE_LOAD:
+case TYPE_FPLOAD:
+case TYPE_VECLOAD:
+  cost = COSTS_N_INSNS (n + 1);
+  break;
+
+case TYPE_MUL:
+  switch (get_attr_size (insn))
+   {
+   case SIZE_8:
+ cost = COSTS_N_INSNS (n - 1) + rs6000_cost->mulsi_const9;
+ break;
+   case SIZE_16:
+ cost = COSTS_N_INSNS (n - 1) + rs6000_cost->mulsi_const;
+ break;
+   case SIZE_32:
+ cost = COSTS_N_INSNS (n - 1) + rs6000_cost->mulsi;
+ break;
+   case SIZE_64:
+ cost = COSTS_N_INSNS (n - 1) + rs6000_cost->muldi;
+ break;
+   default:
+ gcc_unreachable ();
+   }
+  break;
+case TYPE_DIV:
+  switch (get_attr_size (insn))
+   {
+   case SIZE_32:
+ cost = COSTS_N_INSNS (n - 1) + rs6000_cost->divsi;
+ break;
+   case SIZE_64:
+ cost = COSTS_N_INSNS (n - 1) + rs6000_cost->divdi;
+ break;
+   default:
+ gcc_unreachable ();
+   }
+  break;
+
+case TYPE_FP:
+  cost = n * rs6000_cost->fp;
+  break;
+case TYPE_DMUL:
+  cost = n * rs6000_cost->dmul;
+  break;
+case TYPE_SDIV:
+  cost = n * rs6000_cost->sdiv;
+  break;
+case TYPE_DDIV:
+  cost = n * rs6000_cost->ddiv;
+  break;
+
+case TYPE_SYNC:
+case TYPE_LOAD_L:
+  cost = COSTS_N_INSNS (n + 2);
+  break;
+
+default:
+  cost = COSTS_N_INSNS (n);
+}
+
+  return cost;
+}
+
 /* Debug form of ADDRESS_COST that is selected if -mdebug=cost.  */
 
 static int
diff --git a/gcc/config/rs6000/rs6000.md b/gcc/config/rs6000/rs6000.md
index b10a999..2e1daf4 100644
--- a/gcc/config/rs6000/rs6000.md
+++ b/gcc/config/rs6000/rs6000.md
@@ -193,6 +193,10 @@ (define_attr "type"
 ;; This is used for insert, mul and others as necessary.
 (define_attr "size" "8,16,32,64,128" (const_string "32"))
 
+;; What is the insn_cost for this insn?  The target hook can still override
+;; this.  For optimizing for size the "length" attribute is used instead.
+(define_attr "cost" "" (const_int 0))
+
 ;; Is this instruction record form ("dot", signed compare to 0, writing CR0)?
 ;; This is used for add, logical, shift, exts, mul.
 (define_attr "dot" "no,yes" (const_string "no"))
-- 
1.8.3.1



Re: [PATCH] Add a warning for invalid function casts

2017-10-10 Thread Joseph Myers
On Tue, 10 Oct 2017, Martin Sebor wrote:

> Calling a function that takes arguments via a void (*)(void)
> is undefined not just on paper but also in practice, so the
> resulting pointer from such a cast is unusable except to convert
> to a compatible pointer.

That's the point of a generic pointer - it either gets cast to the actual 
type (or something ABI-compatible with the actual type) for calls, or 
called from non-C code which has the same effect.

> PS It would be useful if modern C provided a clean mechanism to
> support generic function pointers rather that forcing users leery
> of relying on obsolescent features to invent workarounds.  One

You can use any function pointer type whatever as your generic pointer 
(casting back to the original type for calls).  That you can cast from one 
function pointer type to another and back to the original type is 
guaranteed by ISO C.  That the result of the conversion is meaningful for 
calls from non-C languages is part of the customary practices of C 
implementations.  That the type used is void (*) (void) is a common 
convention used in C code dealing with generic function pointers (another 
convention, of course, is just using void * as in POSIX and relying on 
conversions between function pointers and void *).

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


Re: [PATCH][mingw] Enable colorized diagnostics

2017-10-10 Thread Manuel López-Ibáñez
On 10 Oct 2017 2:34 am, "Liu Hao"  wrote:

Since on *nix it is not when `colorize_start()` is called that the terminal
color is changed (it is when those ANSI escape codes are delivered to the
other peer which will translate them), and the string passed to `fputs()`
is free to deliver multiple escape codes, it is not an option unless we
output integral diagnostic messages using multiple fputs()` calls.

For example,
```
test.c:3:9: warning: 'a' is used uninitialized in this function
[-Wuninitialized]
```
The words 'warning' and '-Wuninitialized' should be magenta, so there are
four ANSI escape codes (two to set the color and another two to restore the
color), and this line of text must be output using five individual calls to
the `fputs()` function (one for each segment with the consistent color),
which is not the case (this whole line of text is delivered using a single
call), so all five segments have to be all in magenta or no color at all.
This is not a solution.


Ops! You're obviously right. What was I thinking?

I still believe that pretty-printer.c is not the right place for all this
color-handling code (diagnostic-color.c or libiberty/ may be better
places). Also, your code handles a lot more ANSI codes than those needed
for color output. The code in grep seems much simpler. Could your fputs
replacement split the string as you suggest above, then if the chunk is an
ANSI code, use grep's conversion function to transform the codes, otherwise
use fputs to print text.

Cheers,

Manuel.


Re: [gomp4] OpenACC async re-work

2017-10-10 Thread Cesar Philippidis
On 10/10/2017 11:08 AM, Thomas Schwinge wrote:

> Reported by Cesar for a test case similar to the one below, where we
> observe:
> 
> acc_prof-cuda-1.exe: [...]/libgomp/oacc-profiling.c:592: 
> goacc_profiling_dispatch_p: Assertion `thr->prof_info == NULL' failed.
> 
> This is because of:
> 
> On Tue, 25 Jul 2017 20:51:05 +0800, Chung-Lin Tang  
> wrote:
>> --- libgomp/oacc-cuda.c  (revision 250497)
>> +++ libgomp/oacc-cuda.c  (working copy)
>> @@ -99,17 +99,12 @@ acc_get_cuda_stream (int async)
>>prof_info.async_queue = prof_info.async;
>>  }
>>  
>> -  void *ret = NULL;
>>if (thr && thr->dev && thr->dev->openacc.cuda.get_stream_func)
>> -ret = thr->dev->openacc.cuda.get_stream_func (async);
>> - 
>> -  if (profiling_setup_p)
>>  {
>> -  thr->prof_info = NULL;
>> -  thr->api_info = NULL;
>> +  goacc_aq aq = lookup_goacc_asyncqueue (thr, false, async);
>> +  return aq ? thr->dev->openacc.cuda.get_stream_func (aq) : NULL;
>>  }
>> -
>> -  return ret;
>> +  return NULL;
>>  }
> 
> Pushed to openacc-gcc-7-branch:
> 
> commit db149741171147fa86a9bfe708a9082f508115ac
> Author: Thomas Schwinge 
> Date:   Tue Oct 10 19:25:19 2017 +0200
> 
> acc_get_cuda_stream: Clean up data of the OpenACC Profiling Interface
> 
> libgomp/
> * oacc-cuda.c (acc_get_cuda_stream): Clean up data of the OpenACC
> Profiling Interface.
> * testsuite/libgomp.oacc-c-c++-common/acc_prof-cuda-1.c: New file.
> ---
>  libgomp/oacc-cuda.c  | 13 +++--
>  .../libgomp.oacc-c-c++-common/acc_prof-cuda-1.c  | 16 
> 
>  2 files changed, 27 insertions(+), 2 deletions(-)
> 
> diff --git libgomp/oacc-cuda.c libgomp/oacc-cuda.c
> index 1fbe77d..0ac93e9 100644
> --- libgomp/oacc-cuda.c
> +++ libgomp/oacc-cuda.c
> @@ -99,12 +99,21 @@ acc_get_cuda_stream (int async)
>prof_info.async_queue = prof_info.async;
>  }
>  
> +  void *ret = NULL;
>if (thr && thr->dev && thr->dev->openacc.cuda.get_stream_func)
>  {
>goacc_aq aq = lookup_goacc_asyncqueue (thr, false, async);
> -  return aq ? thr->dev->openacc.cuda.get_stream_func (aq) : NULL;
> +  if (aq)
> + ret = thr->dev->openacc.cuda.get_stream_func (aq);
>  }
> -  return NULL;
> +
> +  if (profiling_setup_p)
> +{
> +  thr->prof_info = NULL;
> +  thr->api_info = NULL;
> +}
> +
> +  return ret;
>  }

Thanks!

I wonder if it makes sense to apply my patch to og7. It's the workaround
that I was using in case the async queue doesn't exist. Basically, in
that case, goacc_wait turns into a nop.

Cesar
diff --git a/libgomp/oacc-parallel.c b/libgomp/oacc-parallel.c
index 1172d739ec7..85ed2327795 100644
--- a/libgomp/oacc-parallel.c
+++ b/libgomp/oacc-parallel.c
@@ -855,6 +855,9 @@ goacc_wait (int async, int num_waits, va_list *ap)
 {
   int qid = va_arg (*ap, int);
   goacc_aq aq = get_goacc_asyncqueue (qid);
+  /* There's nothing to do if an async queue doesn't exit.  */
+  if (aq == NULL)
+	return;
   if (acc_dev->openacc.async.test_func (aq))
 	continue;
   if (async == acc_async_sync)


[C++ PATCH] Kill unneeded hash specialization

2017-10-10 Thread Nathan Sidwell
Now I've converted the identifier_>decl hash_maps to self-hashing 
hash_tables, there's no need for the lang_identifier specialization of 
default_hash_traits.


So killing it.

nathan
--
Nathan Sidwell
2017-10-10  Nathan Sidwell  

	* cp-tree.h (default_hash_traits ): Delete
	specialization.

Index: cp-tree.h
===
--- cp-tree.h	(revision 253605)
+++ cp-tree.h	(working copy)
@@ -572,30 +572,6 @@ identifier_p (tree t)
   return NULL;
 }
 
-/* Hash trait specialization for lang_identifiers.  This allows
-   PCH-safe maps keyed by DECL_NAME.  If it wasn't for PCH, we could
-   just use a regular tree key.  */
-
-template <>
-struct default_hash_traits 
-  : pointer_hash 
-{
-  /* Use a regular tree as the type, to make using the hash table
- simpler.  We'll get dynamic type checking with the hash function
- itself.  */
-  GTY((skip)) typedef tree value_type;
-  GTY((skip)) typedef tree compare_type;
-
-  static hashval_t hash (const value_type id)
-  {
-return IDENTIFIER_HASH_VALUE (id);
-  }
-
-  /* Nothing is deletable.  Everything is insertable.  */
-  static bool is_deleted (value_type) { return false; }
-  static void remove (value_type) { gcc_unreachable (); }
-};
-
 #define LANG_IDENTIFIER_CAST(NODE) \
 	((struct lang_identifier*)IDENTIFIER_NODE_CHECK (NODE))
 


[RFC] overflow safe scaling of 64bit values

2017-10-10 Thread Jan Hubicka
Hi,
in order to drop frequencies from basic blocks and counts from edges I need
to make probabilities more precise (so we do not get all those roundoff errors
from 1-base fixpoint arithmetics).  Increasing base is easy now, but it
means that in temporaries one can get overflows easily.

I need to compute (a*b)/c in a overflow safe way when a*b does not necessarily
need to fit into 64bit integer.  The following implement safe_scale_64bit for
it but I am not quite sure if that is most reasonable implementation.
(it uses builtins to detect overflows, inline 64bit computation if it is safe
and 128bit computation if it is not).

Any ideas for better version? If not I will go ahead with this variant and
increase profile probability base.

Honza

* profile-count.h (slow_safe_scale_64bit): New function.
(safe_scale_64bit): New inline.
(profile_count::max_safe_multiplier): Remove; use safe_scale_64bit.
Index: profile-count.h
===
--- profile-count.h (revision 253512)
+++ profile-count.h (working copy)
@@ -43,6 +43,35 @@ enum profile_quality {
 
 #define RDIV(X,Y) (((X) + (Y) / 2) / (Y))
 
+bool slow_safe_scale_64bit (uint64_t a, uint64_t b, uint64_t c, uint64_t *res);
+
+/* Compute RES=(a*b + c/2)/c capping and return false if overflow happened.  */
+
+inline bool
+safe_scale_64bit (uint64_t a, uint64_t b, uint64_t c, uint64_t *res)
+{
+#if (GCC_VERSION >= 5000)
+  uint64_t tmp;
+  if (!__builtin_mul_overflow (a, b, )
+  && !__builtin_add_overflow (tmp, c/2, ))
+{
+  *res = tmp / c;
+  return true;
+}
+  if (c == 1)
+{
+  *res = (uint64_t) -1;
+  return false;
+}
+#else
+  if (a < ((uint64_t)1 << 31)
+  && b < ((uint64_t)1 << 31)
+  && c < ((uint64_t)1 << 31))
+return (a * b + (c / 2)) / c;
+#endif
+  return slow_safe_scale_64bit (a, b, c, res);
+}
+
 /* Data type to hold probabilities.  It implements fixed point arithmetics
with capping so probability is always in range [0,1] and scaling requiring
values greater than 1 needs to be represented otherwise.
@@ -87,7 +116,8 @@ class GTY((user)) profile_probability
 
   static const int n_bits = 30;
   static const uint32_t max_probability = REG_BR_PROB_BASE;
-  static const uint32_t uninitialized_probability = ((uint32_t) 1 << n_bits) - 
1;
+  static const uint32_t uninitialized_probability
+= ((uint32_t) 1 << (n_bits - 1)) - 1;
 
   uint32_t m_val : 30;
   enum profile_quality m_quality : 2;
@@ -535,11 +565,6 @@ class GTY(()) profile_count
 
   uint64_t m_val : n_bits;
   enum profile_quality m_quality : 2;
-
-  /* Assume numbers smaller than this to multiply.  This is set to make
- testsuite pass, in future we may implement precise multiplication in higer
- rangers.  */
-  static const uint64_t max_safe_multiplier = 131072;
 public:
 
   /* Used for counters which are expected to be never executed.  */
@@ -790,12 +815,9 @@ public:
return *this;
 
   profile_count ret;
-  /* Take care for overflows!  */
-  if (num.m_val < max_safe_multiplier || m_val < max_safe_multiplier)
-   ret.m_val = RDIV (m_val * num.m_val, den.m_val);
-  else
-   ret.m_val = RDIV (m_val * RDIV (num.m_val * max_safe_multiplier,
-   den.m_val), max_safe_multiplier);
+  uint64_t val;
+  safe_scale_64bit (m_val, num.m_val, den.m_val, );
+  ret.m_val = MIN (val, max_count);
   ret.m_quality = MIN (m_quality, profile_adjusted);
   return ret;
 }
Index: profile-count.c
===
--- profile-count.c (revision 253512)
+++ profile-count.c (working copy)
@@ -30,6 +30,7 @@ along with GCC; see the file COPYING3.
 #include "gimple.h"
 #include "data-streamer.h"
 #include "cgraph.h"
+#include "wide-int.h"
 
 /* Dump THIS to F.  */
 
@@ -194,3 +195,21 @@ profile_probability::stream_out (struct
   streamer_write_uhwi_stream (ob, m_val);
   streamer_write_uhwi_stream (ob, m_quality);
 }
+
+/* Compute RES=(a*b + c/2)/c capping and return false if overflow happened.  */
+
+bool
+slow_safe_scale_64bit (uint64_t a, uint64_t b, uint64_t c, uint64_t *res)
+{
+  FIXED_WIDE_INT (128) tmp = a;
+  bool overflow;
+  tmp = wi::udiv_floor (wi::umul (tmp, b, ) + (c / 2), c);
+  gcc_checking_assert (!overflow);
+  if (wi::fits_uhwi_p (tmp))
+{
+  *res = tmp.to_uhwi ();
+  return true;
+}
+  *res = (uint64_t) -1;
+  return false;
+}


[PATCH] Add various testcases

2017-10-10 Thread Jakub Jelinek
Hi!

While going through still open [5 Regression] bugs manually, I've gathered
various testcases from PRs that were fixed by other changes and thus
IMHO the tests are worth being added.  I have some further PRs to go through
tomorrow, so I might add some further ones.

Regtested on x86_64-linux and i686-linux, committed to trunk. 

2017-10-10  Jakub Jelinek  

PR c++/68252
* g++.dg/other/pr68252.C: New test.

PR middle-end/70100
* g++.dg/opt/pr70100.C: New test.

PR c++/77578
* g++.dg/gomp/pr77578.C: New test.

PR c++/71875
* g++.dg/cpp1y/pr71875.C: New test.

PR c++/77786
* g++.dg/cpp1y/pr77786.C: New test.

PR c++/70338
* g++.dg/cpp0x/pr70338.C: New test.

PR middle-end/70887
* g++.dg/cpp0x/pr70887.C: New test.

PR c++/67625
* g++.dg/cpp0x/pr67625.C: New test.

PR rtl-optimization/68205
* gcc.c-torture/execute/20040709-3.c: New test.

--- gcc/testsuite/g++.dg/other/pr68252.C.jj 2017-10-10 16:14:47.735994894 
+0200
+++ gcc/testsuite/g++.dg/other/pr68252.C2017-10-10 16:14:41.433072970 
+0200
@@ -0,0 +1,5 @@
+// PR c++/68252
+
+struct Test {
+  static const int foo = (1 << sizeof (int)) * -3;
+};
--- gcc/testsuite/g++.dg/opt/pr70100.C.jj   2017-10-10 16:37:07.809387447 
+0200
+++ gcc/testsuite/g++.dg/opt/pr70100.C  2017-10-10 16:37:03.425441796 +0200
@@ -0,0 +1,21 @@
+// PR middle-end/70100
+// { dg-do compile { target c++11 } }
+// { dg-options "-O0" }
+
+void
+bar (int)
+{
+}
+
+template 
+void
+foo (Args && ... args)
+{
+  [&] { [&] { bar(args...); }; };
+}
+
+int
+main ()
+{
+  foo (2);
+}
--- gcc/testsuite/g++.dg/gomp/pr77578.C.jj  2017-10-10 17:57:44.029443215 
+0200
+++ gcc/testsuite/g++.dg/gomp/pr77578.C 2017-10-10 18:02:03.459239650 +0200
@@ -0,0 +1,31 @@
+// PR c++/77578
+// { dg-do compile }
+
+template 
+class A 
+{
+};
+
+template 
+struct B
+{
+};
+
+template 
+struct B  >
+{
+  typedef A  C;
+  typedef typename C::D D;
+ 
+  template 
+  static void
+  foo (const D x, const D y)
+  {
+U u;
+{
+  #pragma omp parallel for 
+  for (u.bar().y() = x.y(); u.bar().y() <= y.y(); u.bar().y()++) // { 
dg-error "expected" }
+   ;
+}
+  }
+};
--- gcc/testsuite/g++.dg/cpp1y/pr71875.C.jj 2017-10-10 17:50:04.473120255 
+0200
+++ gcc/testsuite/g++.dg/cpp1y/pr71875.C2017-10-10 17:50:48.204578368 
+0200
@@ -0,0 +1,24 @@
+// PR c++/71875
+// { dg-do link { target c++14 } }
+
+template 
+constexpr bool IsMatrix = false;
+
+template
+class Matrix {};
+
+template 
+constexpr bool IsMatrix = true;
+
+template
+class RowVecExpMatrix;
+
+template 
+constexpr bool IsMatrix = true;
+
+int
+main ()
+{
+  static_assert (IsMatrix>, "Matrix check error");
+  static_assert (IsMatrix, "Input type is not a matrix");
+}
--- gcc/testsuite/g++.dg/cpp1y/pr77786.C.jj 2017-10-10 18:06:07.985220123 
+0200
+++ gcc/testsuite/g++.dg/cpp1y/pr77786.C2017-10-10 18:06:26.489991618 
+0200
@@ -0,0 +1,21 @@
+// PR c++/77786
+// { dg-do compile { target c++14 } }
+
+#include 
+
+template
+void
+foo (std::vector a)
+{
+  auto const a_size = a.size();
+  auto bar = [&](auto y) -> void { int a_size_2 = a_size; };
+  double x = 0.0;
+  bar (x);
+}
+
+int
+main ()
+{
+  std::vector a(1);
+  foo<1>(a);
+}
--- gcc/testsuite/g++.dg/cpp0x/pr70338.C.jj 2017-10-10 17:04:04.641335439 
+0200
+++ gcc/testsuite/g++.dg/cpp0x/pr70338.C2017-10-10 17:03:49.0 
+0200
@@ -0,0 +1,17 @@
+// PR c++/70338
+// { dg-do compile { target c++11 } }
+// { dg-options "-g" }
+
+template
+void
+foo (int x)
+{
+  T a[x];
+  auto b = [&]() { for (auto : a) c = 0.; };
+}
+
+int
+main ()
+{
+  foo (3);
+}
--- gcc/testsuite/g++.dg/cpp0x/pr70887.C.jj 2017-10-10 17:30:11.667902426 
+0200
+++ gcc/testsuite/g++.dg/cpp0x/pr70887.C2017-10-10 17:30:03.433004543 
+0200
@@ -0,0 +1,31 @@
+// PR middle-end/70887
+// { dg-do compile { target { { i?86-*-* x86_64-*-* } && c++11 } } }
+// { dg-options "-O2 -msse2" }
+
+#include 
+
+enum R { S };
+template  struct C { static constexpr int value = 10; };
+template  class T, R... r>
+struct A {
+  template  struct B;
+  template 
+  struct B {
+static constexpr int d = T::value;
+static __m128i generate()
+{
+  __attribute__((__vector_size__(16))) long long
+  a = generate(),
+  b = _mm_bslli_si128 (a, 1),
+  c = _mm_bsrli_si128 (_mm_set1_epi32(d), 12);
+  return _mm_or_si128 (b, c);
+}
+  };
+  A () { B<0, r...>::generate(); }
+};
+
+int
+main () {
+  using RI = A;
+  RI ri;
+}
--- gcc/testsuite/g++.dg/cpp0x/pr67625.C.jj 2017-10-10 15:55:53.677013155 
+0200
+++ gcc/testsuite/g++.dg/cpp0x/pr67625.C2017-10-10 15:55:27.902331316 
+0200
@@ -0,0 +1,12 @@
+// PR c++/67625
+// { dg-do compile { target c++11 } }
+
+constexpr unsigned short
+bswap16 (unsigned short 

[C++ PATCH] Hash mangling alias

2017-10-10 Thread Nathan Sidwell
This patch changes the mangling alias hash_map to a hash_table, hashing 
by DECL_ASSEMBLER_NAME.  Thus halving its size.


It continues to use DECL_ASSEMBLER_NAME, not the new 
DECL_ASSEMBLER_NAME_RAW I posted earlier today.  When (if) that gets the 
ok, I'll adjust this fragment too.


Applying to trunk.

nathan
--
Nathan Sidwell
2017-10-10  Nathan Sidwell  

	* decl2.c (struct mangled_decl_hash): New hash traits.
	(mangled_decls): Make hash_table.
	(generate_mangling_alias, record_mangling): Adjust.

Index: decl2.c
===
--- decl2.c	(revision 253605)
+++ decl2.c	(working copy)
@@ -102,9 +102,35 @@ static GTY(()) vec *no_link
is to be an alias for the former if the former is defined.  */
 static GTY(()) vec *mangling_aliases;
 
-/* A hash table of mangled names to decls.  Used to figure out if we
-   need compatibility aliases.  */
-static GTY(()) hash_map *mangled_decls;
+/* hash traits for declarations.  Hashes single decls via
+   DECL_ASSEMBLER_NAME.  */
+
+struct mangled_decl_hash : ggc_remove 
+{
+  typedef tree value_type; /* A DECL.  */
+  typedef tree compare_type; /* An identifier.  */
+
+  static hashval_t hash (const value_type decl)
+  {
+return IDENTIFIER_HASH_VALUE (DECL_ASSEMBLER_NAME (decl));
+  }
+  static bool equal (const value_type existing, compare_type candidate)
+  {
+tree name = DECL_ASSEMBLER_NAME (existing);
+return candidate == name;
+  }
+
+  static inline void mark_empty (value_type ) {p = NULL_TREE;}
+  static inline bool is_empty (value_type p) {return !p;}
+
+  /* Nothing is deletable.  Everything is insertable.  */
+  static bool is_deleted (value_type) { return false; }
+  static void mark_deleted (value_type) { gcc_unreachable (); }
+};
+
+/* A hash table of decls keyed by mangled name.  Used to figure out if
+   we need compatibility aliases.  */
+static GTY(()) hash_table *mangled_decls;
 
 /* Nonzero if we're done parsing and into end-of-file activities.  */
 
@@ -4304,12 +4330,13 @@ generate_mangling_alias (tree decl, tree
 	return;
 }
 
-  bool existed;
-  tree *slot = _decls->get_or_insert (id2, );
+  tree *slot
+= mangled_decls->find_slot_with_hash (id2, IDENTIFIER_HASH_VALUE (id2),
+	  INSERT);
 
   /* If there's a declaration already using this mangled name,
  don't create a compatibility alias that conflicts.  */
-  if (existed)
+  if (*slot)
 return;
 
   tree alias = make_alias_for (decl, id2);
@@ -4369,24 +4396,25 @@ void
 record_mangling (tree decl, bool need_warning)
 {
   if (!mangled_decls)
-mangled_decls = hash_map::create_ggc (499);
+mangled_decls = hash_table::create_ggc (499);
 
   gcc_checking_assert (DECL_ASSEMBLER_NAME_SET_P (decl));
   tree id = DECL_ASSEMBLER_NAME (decl);
-  bool existed;
-  tree *slot = _decls->get_or_insert (id, );
+  tree *slot
+= mangled_decls->find_slot_with_hash (id, IDENTIFIER_HASH_VALUE (id),
+	  INSERT);
 
   /* If this is already an alias, remove the alias, because the real
  decl takes precedence.  */
-  if (existed && DECL_ARTIFICIAL (*slot) && DECL_IGNORED_P (*slot))
+  if (*slot && DECL_ARTIFICIAL (*slot) && DECL_IGNORED_P (*slot))
 if (symtab_node *n = symtab_node::get (*slot))
   if (n->cpp_implicit_alias)
 	{
 	  n->remove ();
-	  existed = false;
+	  *slot = NULL_TREE;
 	}
 
-  if (!existed)
+  if (!*slot)
 *slot = decl;
   else if (need_warning)
 {


Re: GCC 7 libbacktrace patch committed: Ignore compressed debug sections

2017-10-10 Thread Ian Lance Taylor
On Tue, Oct 10, 2017 at 12:47 PM, Paolo Carlini
 wrote:
>
> On 10/10/2017 18:55, Ian Lance Taylor wrote:
>>
>> Index: elf.c
>> ===
>> --- elf.c   (revision 253593)
>> +++ elf.c   (working copy)
>> @@ -103,6 +103,7 @@
>>   #undef SHT_SYMTAB
>>   #undef SHT_STRTAB
>>   #undef SHT_DYNSYM
>> +#undef SFH_COMPRESSED
>>   #undef STT_OBJECT
>>   #undef STT_FUNC
>
> You appear to have a typo here: SFH_COMPRESSED instead of SHF_COMPRESSED.
> That breaks the bootstrap for me:
>
> ../../../../gcc-7-branch/libsanitizer/libbacktrace/../../libbacktrace/elf.c:199:0:
> error: "SHF_COMPRESSED" redefined [-Werror]
>  #define SHF_COMPRESSED 0x800
>
> I'm going to test and commit the obvious fix, if nobody beats me to it.

Argh.  Sorry about that.  Please do commit the obvious fix.  Thanks.

Ian


Re: [C++ PATCH] hash-table for extern-c fns.

2017-10-10 Thread Jason Merrill
On Tue, Oct 10, 2017 at 3:11 PM, Nathan Sidwell  wrote:
> On 10/09/2017 06:15 PM, Nathan Sidwell wrote:
>>
>> On 10/09/2017 11:57 AM, Jason Merrill wrote:
>
>
>>> Hmm, why do we only check extern "C" conflicts for functions?
>>
>>
>> I suspect a bug.  I noticed it as existing behaviour and was puzzled the
>> first time around rearranging this code, but didn't want to get distracted
>> from the big picture.
>
>
> This patch checks both vars and fns (as typedefs don't have linkage, I don't
> think they can be extern C, but ICBW).
>
> I also tweaked the diagnostics, so that the first one is a pedwarn and the
> later ones are notes. (so we won't arbitrarily truncate the series of
> diagnostics.
>
> Look good to you?

Yes, thanks.


Re: GCC 7 libbacktrace patch committed: Ignore compressed debug sections

2017-10-10 Thread Paolo Carlini

Hi,

On 10/10/2017 18:55, Ian Lance Taylor wrote:

Index: elf.c
===
--- elf.c   (revision 253593)
+++ elf.c   (working copy)
@@ -103,6 +103,7 @@
  #undef SHT_SYMTAB
  #undef SHT_STRTAB
  #undef SHT_DYNSYM
+#undef SFH_COMPRESSED
  #undef STT_OBJECT
  #undef STT_FUNC
You appear to have a typo here: SFH_COMPRESSED instead of 
SHF_COMPRESSED. That breaks the bootstrap for me:


../../../../gcc-7-branch/libsanitizer/libbacktrace/../../libbacktrace/elf.c:199:0: 
error: "SHF_COMPRESSED" redefined [-Werror]

 #define SHF_COMPRESSED 0x800

I'm going to test and commit the obvious fix, if nobody beats me to it.

Paolo.


Re: [C++ PATCH] hash-table for extern-c fns.

2017-10-10 Thread Nathan Sidwell

On 10/09/2017 06:15 PM, Nathan Sidwell wrote:

On 10/09/2017 11:57 AM, Jason Merrill wrote:



Hmm, why do we only check extern "C" conflicts for functions?


I suspect a bug.  I noticed it as existing behaviour and was puzzled the 
first time around rearranging this code, but didn't want to get 
distracted from the big picture.


This patch checks both vars and fns (as typedefs don't have linkage, I 
don't think they can be extern C, but ICBW).


I also tweaked the diagnostics, so that the first one is a pedwarn and 
the later ones are notes. (so we won't arbitrarily truncate the series 
of diagnostics.


Look good to you?

nathan
--
Nathan Sidwell
2017-10-10  Nathan Sidwell  

	* name-lookup.c (extern_c_fns): Rename to ...
	(extern_c_decls): ... here.
	(check_extern_c_conflict, extern_c_linkage_bindings): Update.
	(do_pushdecl): Check extern-c fns and vars.

	* g++.dg/lookup/extern-c-redecl6.C: New.
	* g++.dg/lookup/extern-c-hidden.C: Adjust diagnostics.
	* g++.dg/lookup/extern-c-redecl.C: Likewise.
	* g++.old-deja/g++.other/using9.C: Likewise.

Index: cp/name-lookup.c
===
--- cp/name-lookup.c	(revision 253605)
+++ cp/name-lookup.c	(working copy)
@@ -2511,13 +2511,13 @@ update_binding (cp_binding_level *level,
   return decl;
 }
 
-/* Table of identifiers to extern C functions (or LISTS thereof).  */
+/* Table of identifiers to extern C declarations (or LISTS thereof).  */
 
-static GTY(()) hash_table *extern_c_fns;
+static GTY(()) hash_table *extern_c_decls;
 
-/* DECL has C linkage. If we have an existing instance, make sure it
-   has the same exception specification [7.5, 7.6].  If there's no
-   instance, add DECL to the map.  */
+/* DECL has C linkage. If we have an existing instance, make sure the
+   new one is compatible.  Make sure it has the same exception
+   specification [7.5, 7.6].  Add DECL to the map.  */
 
 static void
 check_extern_c_conflict (tree decl)
@@ -2526,10 +2526,10 @@ check_extern_c_conflict (tree decl)
   if (DECL_ARTIFICIAL (decl) || DECL_IN_SYSTEM_HEADER (decl))
 return;
 
-  if (!extern_c_fns)
-extern_c_fns = hash_table::create_ggc (127);
+  if (!extern_c_decls)
+extern_c_decls = hash_table::create_ggc (127);
 
-  tree *slot = extern_c_fns
+  tree *slot = extern_c_decls
 ->find_slot_with_hash (DECL_NAME (decl),
 			   IDENTIFIER_HASH_VALUE (DECL_NAME (decl)), INSERT);
   if (tree old = *slot)
@@ -2543,9 +2543,10 @@ check_extern_c_conflict (tree decl)
 	 about a (possible) mismatch, when inserting the decl.  */
   else if (!decls_match (decl, old))
 	mismatch = 1;
-  else if (!comp_except_specs (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (old)),
-   TYPE_RAISES_EXCEPTIONS (TREE_TYPE (decl)),
-   ce_normal))
+  else if (TREE_CODE (decl) == FUNCTION_DECL
+	   && !comp_except_specs (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (old)),
+  TYPE_RAISES_EXCEPTIONS (TREE_TYPE (decl)),
+  ce_normal))
 	mismatch = -1;
   else if (DECL_ASSEMBLER_NAME_SET_P (old))
 	SET_DECL_ASSEMBLER_NAME (decl, DECL_ASSEMBLER_NAME (old));
@@ -2553,12 +2554,12 @@ check_extern_c_conflict (tree decl)
   if (mismatch)
 	{
 	  pedwarn (input_location, 0,
-		   "declaration of %q#D with C language linkage", decl);
-	  pedwarn (DECL_SOURCE_LOCATION (old), 0,
-		   "conflicts with previous declaration %q#D", old);
+		   "conflicting C language linkage declaration %q#D", decl);
+	  inform (DECL_SOURCE_LOCATION (old),
+		  "previous declaration %q#D", old);
 	  if (mismatch < 0)
-	pedwarn (input_location, 0,
-		 "due to different exception specifications");
+	inform (input_location,
+		"due to different exception specifications");
 	}
   else
 	{
@@ -2587,8 +2588,8 @@ check_extern_c_conflict (tree decl)
 tree
 c_linkage_bindings (tree name)
 {
-  if (extern_c_fns)
-if (tree *slot = extern_c_fns
+  if (extern_c_decls)
+if (tree *slot = extern_c_decls
 	->find_slot_with_hash (name, IDENTIFIER_HASH_VALUE (name), NO_INSERT))
   {
 	tree result = *slot;
@@ -3030,9 +3031,8 @@ do_pushdecl (tree decl, bool is_friend)
 		else
 		  *slot = head;
 		  }
-		if (TREE_CODE (match) == FUNCTION_DECL
-		&& DECL_EXTERN_C_P (match))
-		  /* We need to check and register the fn now.  */
+		if (DECL_EXTERN_C_P (match))
+		  /* We need to check and register the decl now.  */
 		  check_extern_c_conflict (match);
 	  }
 	return match;
@@ -3113,7 +3113,9 @@ do_pushdecl (tree decl, bool is_friend)
 	}
   else if (VAR_P (decl))
 	maybe_register_incomplete_var (decl);
-  else if (TREE_CODE (decl) == FUNCTION_DECL && DECL_EXTERN_C_P (decl))
+
+  if ((VAR_P (decl) || TREE_CODE (decl) == FUNCTION_DECL)
+	  && DECL_EXTERN_C_P (decl))
 	check_extern_c_conflict (decl);
 }
   else
Index: testsuite/g++.dg/lookup/extern-c-hidden.C
===
--- testsuite/g++.dg/lookup/extern-c-hidden.C	

Re: [PATCH, ARM] correctly encode the CC reg data flow

2017-10-10 Thread Bernd Edlinger
On 10/09/17 15:02, Richard Earnshaw (lists) wrote:
> On 06/09/17 14:17, Bernd Edlinger wrote:
>> Index: gcc/doc/rtl.texi
>> ===
>> --- gcc/doc/rtl.texi (revision 251752)
>> +++ gcc/doc/rtl.texi (working copy)
>> @@ -2252,6 +2252,13 @@
>>   If one of the operands is a constant, it should be placed in the
>>   second operand and the comparison code adjusted as appropriate.
>>   
>> +There may be exceptions to this rule if the mode @var{m} does not
>> +carry enough information for the swapped comparison operator, or
>> +if we try to detect overflow from the subtraction.  That means, while
>> +0-X may overfow X-0 can never overflow.  Under these conditions

s/overfow/overflow/

>> +a compare may have the constant expression at the first operand.
>> +Examples are the ARM negdi2_compare pattern and similar.
>> +
>>   A @code{compare} specifying two @code{VOIDmode} constants is not valid
>>   since there is no way to know in what mode the comparison is to be
>>   performed; the comparison must either be folded during the compilation
>>
> 
> 
> Er, hold on.  Comparisons don't 'overflow'.  They compare two values and
> tell you something about their relationship.  If A cmp B doesn't tell me
> the same basic things as B swapped(cmp) A, then the world will fall
> apart big time.  So your documentation patch can't be right.
> 

Hi Richard,

I think a CC-mode like CC_NCV is inherently unsymmetrical
which means that it does in general not provide enough information for
the swapped(cmp), and I think the truth is that the N-flag
is the sign of A-B, and V-flag is 1 if A-B overflows otherwise 0.
And if you ask for Branch if less-than that is Branch if N ^ V.


But in the moment I have no idea how to proceed.


Thanks
Bernd.


Re: [patch, Fortran] Fix PR 82372

2017-10-10 Thread Thomas Koenig

Hi Steve,


the attached patch displays an error for characters which are
outside the normal Fortran character set, and includes a hex


If this  ^



corresponds to this statement,

  
+char valid_chars[] =

+  "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
+  "=+*-/^%[].,\n\t\r'\"();:<>_!$&0123456789";


then this is not correct.


You're correct, my statement above was misleading.

What I meant was the characters which can occur inside
normal Fortran syntax, plus a few more places, such as an
!$OMP statement.


From F2003, letters, digits,
underscore, and special characters (see Table 3.1) are
members of the Fortran character set.  Your string includes
\n, \t, and \r, which are not in the Fortran character set.

\t we warn about separetely. \n and \r can occur during parsing,
so we should not warn about them,


Your string is missing \, {, }, ~, `, |, #, and @.


AFAIK, none of these characters can come up in an normal Fortran
statement except for a comment, string, format or continuation
character in fixed form.

Regards

Thomas


[PATCH] preprocessor stringizing raw strings

2017-10-10 Thread Nathan Sidwell
This patch fixes PR 82506, where we fail to properly stringize a raw 
string literal, which can contain a raw LF character.


When we're not just preprocessing, there isn't a problem.  The string 
literal gets correctly escaped into the assembly file.  This is just a 
problem with preprocessing.


Applying to trunk.

nathan
--
Nathan Sidwell
2017-10-10  Nathan Sidwell  

	libcpp/
	PR preprocessor/82506
	* macro.c (cpp_quote_string): Escape raw LFs.

	gcc/testsuite/
	PR preprocessor/82506
	* g++.dg/cpp/string-3.C: New.

Index: gcc/testsuite/g++.dg/cpp/string-3.C
===
--- gcc/testsuite/g++.dg/cpp/string-3.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp/string-3.C	(working copy)
@@ -0,0 +1,9 @@
+// PR c++/82506
+// { dg-do preprocess { target c++11 } }
+
+#define STRINGIZE(A) #A
+
+BEGIN STRINGIZE(R"(
+)") END
+
+// { dg-final { scan-file string-3.ii "BEGIN \"R\\\"(\\n)\\\"\"\n END" } }
Index: libcpp/macro.c
===
--- libcpp/macro.c	(revision 253587)
+++ libcpp/macro.c	(working copy)
@@ -502,13 +502,21 @@ cpp_quote_string (uchar *dest, const uch
 {
   uchar c = *src++;
 
-  if (c == '\\' || c == '"')
+  switch (c)
 	{
+	case '\n':
+	  /* Naked LF can appear in raw string literals  */
+	  c = 'n';
+	  /* FALLTHROUGH */
+
+	case '\\':
+	case '"':
 	  *dest++ = '\\';
+	  /* FALLTHROUGH */
+
+	default:
 	  *dest++ = c;
 	}
-  else
-	  *dest++ = c;
 }
 
   return dest;


Re: [patch][arm][FreeBSD] gcc-6/5: add support for armv7*-*-freebsd*

2017-10-10 Thread Andreas Tobler

On 08.10.17 23:12, Andreas Tobler wrote:

Hi all,

and here is the patch for gcc-6/5 branch to add support for
armv7*-*-freebsd*

The difference towards trunk is the missing of target_cpu_cname which is
solved differently.

I'm aware of the gcc-5 branch status and I will not apply before gcc-5.5
is released. I'll also will not apply on the gcc-5 branch if the branch
gets closed.

If you have any objections, please speak up.


Committed _only_ on the gcc-6 branch: 253604

Andreas


2017-10-08  Andreas Tobler  

* config.gcc: (armv7*-*-freebsd*): New target.
Define TARGET_FREEBSD_ARMv7
* config/arm/freebsd.h: Use TARGET_FREEBSD_ARMv7 to define the
default cpu for armv7*-*-freebsd*.


Index: config/arm/freebsd.h
===
--- config/arm/freebsd.h(revision 253513)
+++ config/arm/freebsd.h(working copy)
@@ -112,6 +112,10 @@
   #undef  WCHAR_TYPE_SIZE
   #define WCHAR_TYPE_SIZE BITS_PER_WORD

+#if defined (TARGET_FREEBSD_ARMv7)
+#undef  SUBTARGET_CPU_DEFAULT
+#define SUBTARGET_CPU_DEFAULT TARGET_CPU_genericv7a
+#else
   #if defined (TARGET_FREEBSD_ARMv6)
   #undef  SUBTARGET_CPU_DEFAULT
   #define SUBTARGET_CPU_DEFAULT TARGET_CPU_arm1176jzs
@@ -119,6 +123,7 @@
   #undef  SUBTARGET_CPU_DEFAULT
   #define SUBTARGET_CPU_DEFAULT   TARGET_CPU_arm9
   #endif
+#endif

   /* FreeBSD 10 does not support unaligned access for armv6 and up.
  Unaligned access support was added in FreeBSD 11.  */
Index: config.gcc
===
--- config.gcc  (revision 253513)
+++ config.gcc  (working copy)
@@ -1072,6 +1072,10 @@
  tm_defines="${tm_defines} TARGET_FREEBSD_ARM_HARD_FLOAT=1"
   fi
;;
+   armv7*-*-freebsd*)
+   tm_defines="${tm_defines} TARGET_FREEBSD_ARMv7=1"
+   tm_defines="${tm_defines} TARGET_FREEBSD_ARM_HARD_FLOAT=1"
+   ;;
esac
with_tls=${with_tls:-gnu}
;;





Re: [patch][arm][FreeBSD] gcc-7 branch: add support for armv7*-*-freebsd*

2017-10-10 Thread Andreas Tobler

On 08.10.17 22:58, Andreas Tobler wrote:

Hi all,

here is the patch witch adds support for armv7*-*-freebsd* on the gcc-7
branch.

The difference towards trunk is the target_cpu_cname.

I'll commit this one if no objections pop up.


Committed in 253603

Andreas


2017-10-08  Andreas Tobler  

* config.gcc: (armv7*-*-freebsd*): New target.
(armv6*-*-freebsd*): Remove obsolete TARGET_FREEBSD_ARMv6 define.


Index: config.gcc
===
--- config.gcc  (revision 253528)
+++ config.gcc  (working copy)
@@ -1077,11 +1077,14 @@
case $target in
armv6*-*-freebsd*)
target_cpu_cname="arm1176jzfs"
-   tm_defines="${tm_defines} TARGET_FREEBSD_ARMv6=1"
   if test $fbsd_major -ge 11; then
  tm_defines="${tm_defines} TARGET_FREEBSD_ARM_HARD_FLOAT=1"
   fi
;;
+   armv7*-*-freebsd*)
+   target_cpu_cname="genericv7a"
+   tm_defines="${tm_defines} TARGET_FREEBSD_ARM_HARD_FLOAT=1"
+   ;;
*)
target_cpu_cname="arm9"
;;





Re: [patch][arm][FreeBSD] add support for armv7*-*-freebsd*

2017-10-10 Thread Andreas Tobler

On 08.10.17 22:51, Andreas Tobler wrote:

Hi all,

I'm going to commit this patch if no objections pop up.

We (FreeBSD folks) have added a new target tripplet for armv7*-*-freebsd*
To be able to build GCC we need the below changes.

Results will be posted to the usual place, once they completed

While here I remove an obsolete define.

I'll post similar patches for gcc-7, gcc-6 and gcc-5 branches.
They differ a bit...

Please speak up if you do not agree.



Commited in 253602

Andreas




Re: [PATCH] Fix PR80295[aarch64] [7/8 Regression] ICE in __builtin_update_setjmp_buf expander

2017-10-10 Thread Qing Zhao

On Oct 9, 2017, at 12:05 PM, Qing Zhao  wrote:
> 
 Thanks a lot for Wilco’s help on this bug. 
 
 Yes, Aarch64 does NOT do anything wrong.  
 
 The implementation of __builtin_update_setjmp_buf is not correct. It takes 
 a pointer
 as an operand and treats the Mode of the pointer as Pmode, which is not 
 correct.
 a conversion from ptr_mode to Pmode is needed for this pointer.
 
 bootstrapped on aarch64-unknown-linux-gnu.
 testing on aarch64-unknown-linux-gnu is running.
 
>>> 
>>> This is more believable for AArch64, but we need to be careful here.  I
>>> think this needs testing on at least one other target that has a
>>> ilp32-on-64-bit ABI, eg x86_64's x32 ABI.
>> 
>> I just built the latest upstream GCC on x86_64 Linux. and use it to compile 
>> the testing case in PR80295 with the following options:
>> 
>> [qinzhao@qzh-ol6-test 80295]$ cat t.c
>> void f (void *b) { __builtin_update_setjmp_buf (b); }
>> [qinzhao@qzh-ol6-test 80295]$ sh t
>> /home/qinzhao/Install/latest/bin/gcc -m32 t.c
>> 
>> it compiles successfully on x86_64.  no similar issue as aarch64. 
>> 
>> DId  I use the correct option on X86 (i.e -m32)?
> 
> I also tried -mx32,  the compilation had no issue. 
> 
> With the latest GCC + my patch, on X86,  the testing case still has No any 
> issue with -m32 or -mx32. 
> 
> my testing on aarch64-unknown-linux-gnu has finished, no any regression. 

More testing on x86_64-pc-linux-gnu, bootstrapped and gcc testing,  No any 
regression.

> 
> Is my patch Okay?
> 
> thanks.
Qing


Re: [gomp4] OpenACC async re-work

2017-10-10 Thread Thomas Schwinge
Hi!

Reported by Cesar for a test case similar to the one below, where we
observe:

acc_prof-cuda-1.exe: [...]/libgomp/oacc-profiling.c:592: 
goacc_profiling_dispatch_p: Assertion `thr->prof_info == NULL' failed.

This is because of:

On Tue, 25 Jul 2017 20:51:05 +0800, Chung-Lin Tang  
wrote:
> --- libgomp/oacc-cuda.c   (revision 250497)
> +++ libgomp/oacc-cuda.c   (working copy)
> @@ -99,17 +99,12 @@ acc_get_cuda_stream (int async)
>prof_info.async_queue = prof_info.async;
>  }
>  
> -  void *ret = NULL;
>if (thr && thr->dev && thr->dev->openacc.cuda.get_stream_func)
> -ret = thr->dev->openacc.cuda.get_stream_func (async);
> - 
> -  if (profiling_setup_p)
>  {
> -  thr->prof_info = NULL;
> -  thr->api_info = NULL;
> +  goacc_aq aq = lookup_goacc_asyncqueue (thr, false, async);
> +  return aq ? thr->dev->openacc.cuda.get_stream_func (aq) : NULL;
>  }
> -
> -  return ret;
> +  return NULL;
>  }

Pushed to openacc-gcc-7-branch:

commit db149741171147fa86a9bfe708a9082f508115ac
Author: Thomas Schwinge 
Date:   Tue Oct 10 19:25:19 2017 +0200

acc_get_cuda_stream: Clean up data of the OpenACC Profiling Interface

libgomp/
* oacc-cuda.c (acc_get_cuda_stream): Clean up data of the OpenACC
Profiling Interface.
* testsuite/libgomp.oacc-c-c++-common/acc_prof-cuda-1.c: New file.
---
 libgomp/oacc-cuda.c  | 13 +++--
 .../libgomp.oacc-c-c++-common/acc_prof-cuda-1.c  | 16 
 2 files changed, 27 insertions(+), 2 deletions(-)

diff --git libgomp/oacc-cuda.c libgomp/oacc-cuda.c
index 1fbe77d..0ac93e9 100644
--- libgomp/oacc-cuda.c
+++ libgomp/oacc-cuda.c
@@ -99,12 +99,21 @@ acc_get_cuda_stream (int async)
   prof_info.async_queue = prof_info.async;
 }
 
+  void *ret = NULL;
   if (thr && thr->dev && thr->dev->openacc.cuda.get_stream_func)
 {
   goacc_aq aq = lookup_goacc_asyncqueue (thr, false, async);
-  return aq ? thr->dev->openacc.cuda.get_stream_func (aq) : NULL;
+  if (aq)
+   ret = thr->dev->openacc.cuda.get_stream_func (aq);
 }
-  return NULL;
+
+  if (profiling_setup_p)
+{
+  thr->prof_info = NULL;
+  thr->api_info = NULL;
+}
+
+  return ret;
 }
 
 int
diff --git libgomp/testsuite/libgomp.oacc-c-c++-common/acc_prof-cuda-1.c 
libgomp/testsuite/libgomp.oacc-c-c++-common/acc_prof-cuda-1.c
new file mode 100644
index 000..63f5e49
--- /dev/null
+++ libgomp/testsuite/libgomp.oacc-c-c++-common/acc_prof-cuda-1.c
@@ -0,0 +1,16 @@
+/* TODO: This is to eventually test dispatch of events to callbacks.  */
+
+#include 
+
+int main()
+{
+  acc_init(acc_device_default);
+
+  (void) acc_get_cuda_stream(acc_async_default);
+  /* The following used to crash the runtime due to acc_get_cuda_stream not
+ cleaning up data of the OpenACC Profiling Interface.  */
+#pragma acc data
+  ;
+
+  return 0;
+}


Grüße
 Thomas


Re: [patch, Fortran] Fix PR 82372

2017-10-10 Thread Steve Kargl
On Tue, Oct 10, 2017 at 07:42:25PM +0200, Thomas Koenig wrote:
> Hello world,
> 
> the attached patch displays an error for characters which are
> outside the normal Fortran character set, and includes a hex

If this  ^

> code when it is not printable.
> 
> gfortran 4.9 did display unprintable characters in the file,
> so it might be argued that this bug is a regression.
> 
> Regression-tested. OK for trunk? What do people feel about backporting?
> 
> Regards
> 
>   Thomas
> 
> 2017-10-10  Thomas Koenig  
> 
>  PR fortran/82372
>  * fortran/scanner.c (valid_chars): String with all characters
>  which could be valid in Fortran.

corresponds to this statement,

>  (valid_table):  Boolean table to select valid characters.
>  (gfc_scanner_init_1): Set up valid_table from vaid_chars.
>  (gfc_gooble_whitespace): If a character not in the Fortran
>  character set appears, display error.
> 
> 2017-10-10  Thomas Koenig  
> 
>  PR fortran/82372
>  * gfortran.dg/illegal_char.f90: New test.

> Index: fortran/scanner.c
> ===
> --- fortran/scanner.c (Revision 253530)
> +++ fortran/scanner.c (Arbeitskopie)
> @@ -80,7 +80,14 @@ static struct gfc_file_change
>  size_t file_changes_cur, file_changes_count;
>  size_t file_changes_allocated;
>  
> +char valid_chars[] =
> +  "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
> +  "=+*-/^%[].,\n\t\r'\"();:<>_!$&0123456789";

then this is not correct.  From F2003, letters, digits, 
underscore, and special characters (see Table 3.1) are
members of the Fortran character set.  Your string includes
\n, \t, and \r, which are not in the Fortran character set.
Your string is missing \, {, }, ~, `, |, #, and @.

-- 
Steve
20170425 https://www.youtube.com/watch?v=VWUpyCsUKR4
20161221 https://www.youtube.com/watch?v=IbCHE-hONow


Re: C++ PATCH for c++/56973 (DR 696), lambda capture of const variables

2017-10-10 Thread Jason Merrill
On Thu, Sep 28, 2017 at 3:38 PM, Jason Merrill  wrote:
> The G++ lambda implementation previously implemented an early
> tentative resolution of DR 696, whereby mentions of an outer constant
> variable would immediately decay to the constant value of that
> variable.  But the final resolution specified that we should capture
> or not depending on how the variable is used: if we use it as an
> lvalue, it's captured; if we use it as an rvalue, it isn't.
>
> The first patch is some minor fixes discovered during this work.
> The second patch reworks how we find capture proxies to use
> local_specializations instead of name lookup.
> The third patch delays capture of constant variables until
> mark_rvalue_use/mark_lvalue_use.
>
> The third patch also adds calls to mark_*_use in a couple of places
> that needed it; I expect more will be necessary as well.

I tested using delayed capture for all variables, and these fixes are
the result.

The first two patches are fixes for generic issues that I came across
while looking at the capture issues.  The first adds checking within a
template definition for non-dependent return statements.  The second
fixes a few small issues.  The third patch implements generic lambda
capture in dependent full-expressions, and the fourth adds some
missing mark_*_use calls and fixes other issues with delayed capture.

Tested x86_64-pc-linux-gnu, applying to trunk.
commit 06873162a116c6629dea55a36f8b43f71c6c7880
Author: Jason Merrill 
Date:   Tue Oct 10 10:49:07 2017 -0400

Check non-dependent conversion in return from template fn.

* typeck.c (check_return_expr): Check non-dependent conversion in
templates.
* constraint.cc (check_function_concept): Don't complain about an
empty concept if seen_error.

diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc
index 64a8ea926d2..8b49455a526 100644
--- a/gcc/cp/constraint.cc
+++ b/gcc/cp/constraint.cc
@@ -2504,7 +2504,12 @@ check_function_concept (tree fn)
 {
   location_t loc = DECL_SOURCE_LOCATION (fn);
   if (TREE_CODE (body) == STATEMENT_LIST && !STATEMENT_LIST_HEAD (body))
-error_at (loc, "definition of concept %qD is empty", fn);
+   {
+ if (seen_error ())
+   /* The definition was probably erroneous, not empty.  */;
+ else
+   error_at (loc, "definition of concept %qD is empty", fn);
+   }
   else
 error_at (loc, "definition of concept %qD has multiple statements", 
fn);
 }
diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c
index c3310db7b3b..01647d04bc8 100644
--- a/gcc/cp/typeck.c
+++ b/gcc/cp/typeck.c
@@ -8957,10 +8957,14 @@ check_return_expr (tree retval, bool *no_warning)
   if (check_for_bare_parameter_packs (retval))
return error_mark_node;
 
-  if (WILDCARD_TYPE_P (TREE_TYPE (DECL_RESULT (current_function_decl)))
+  /* If one of the types might be void, we can't tell whether we're
+returning a value.  */
+  if ((WILDCARD_TYPE_P (TREE_TYPE (DECL_RESULT (current_function_decl)))
+  && !current_function_auto_return_pattern)
  || (retval != NULL_TREE
- && type_dependent_expression_p (retval)))
-return retval;
+ && (TREE_TYPE (retval) == NULL_TREE
+ || WILDCARD_TYPE_P (TREE_TYPE (retval)
+   goto dependent;
 }
 
   functype = TREE_TYPE (TREE_TYPE (current_function_decl));
@@ -9098,8 +9102,10 @@ check_return_expr (tree retval, bool *no_warning)
warning (OPT_Weffc__, 

Cleanup x86-tune.def

2017-10-10 Thread Jan Hubicka
Hi,
while looking into Zen tuning I noticed that some of the tunables
in x86-tune.def was added into section with obsolette flags, which does
not make much sense.

* x86-tune.def (X86_TUNE_AVOID_FALSE_DEP_FOR_BMI, 
X86_TUNE_ADJUST_UNROLL,
X86_TUNE_ONE_IF_CONV_INSN): Move to right spot in the file.
Index: x86-tune.def
===
--- x86-tune.def(revision 253524)
+++ x86-tune.def(working copy)
@@ -284,6 +284,22 @@ DEF_TUNE (X86_TUNE_USE_BT, "use_bt",
   m_CORE_ALL | m_BONNELL | m_SILVERMONT | m_KNL | m_KNM | m_INTEL
  | m_LAKEMONT | m_AMD_MULTIPLE | m_GENERIC)
 
+/* X86_TUNE_AVOID_FALSE_DEP_FOR_BMI: Avoid false dependency
+   for bit-manipulation instructions.  */
+DEF_TUNE (X86_TUNE_AVOID_FALSE_DEP_FOR_BMI, "avoid_false_dep_for_bmi",
+ m_SANDYBRIDGE | m_HASWELL | m_GENERIC)
+
+/* X86_TUNE_ADJUST_UNROLL: This enables adjusting the unroll factor based
+   on hardware capabilities. Bdver3 hardware has a loop buffer which makes
+   unrolling small loop less important. For, such architectures we adjust
+   the unroll factor so that the unrolled loop fits the loop buffer.  */
+DEF_TUNE (X86_TUNE_ADJUST_UNROLL, "adjust_unroll_factor", m_BDVER3 | m_BDVER4)
+
+/* X86_TUNE_ONE_IF_CONV_INSNS: Restrict a number of cmov insns in
+   if-converted sequence to one.  */
+DEF_TUNE (X86_TUNE_ONE_IF_CONV_INSN, "one_if_conv_insn",
+ m_SILVERMONT | m_KNL | m_KNM | m_INTEL | m_CORE_ALL | m_GENERIC)
+
 /*/
 /* 387 instruction selection tuning  */
 /*/
@@ -503,11 +519,6 @@ DEF_TUNE (X86_TUNE_NOT_VECTORMODE, "not_
 DEF_TUNE (X86_TUNE_AVOID_VECTOR_DECODE, "avoid_vector_decode",
   m_K8)
 
-/* X86_TUNE_AVOID_FALSE_DEP_FOR_BMI: Avoid false dependency
-   for bit-manipulation instructions.  */
-DEF_TUNE (X86_TUNE_AVOID_FALSE_DEP_FOR_BMI, "avoid_false_dep_for_bmi",
- m_SANDYBRIDGE | m_HASWELL | m_GENERIC)
-
 /*/
 /* This never worked well before.*/
 /*/
@@ -525,14 +536,3 @@ DEF_TUNE (X86_TUNE_QIMODE_MATH, "qimode_
arithmetic to 32bit via PROMOTE_MODE macro.  This code generation scheme
is usually used for RISC targets.  */
 DEF_TUNE (X86_TUNE_PROMOTE_QI_REGS, "promote_qi_regs", 0U)
-
-/* X86_TUNE_ADJUST_UNROLL: This enables adjusting the unroll factor based
-   on hardware capabilities. Bdver3 hardware has a loop buffer which makes
-   unrolling small loop less important. For, such architectures we adjust
-   the unroll factor so that the unrolled loop fits the loop buffer.  */
-DEF_TUNE (X86_TUNE_ADJUST_UNROLL, "adjust_unroll_factor", m_BDVER3 | m_BDVER4)
-
-/* X86_TUNE_ONE_IF_CONV_INSNS: Restrict a number of cmov insns in
-   if-converted sequence to one.  */
-DEF_TUNE (X86_TUNE_ONE_IF_CONV_INSN, "one_if_conv_insn",
- m_SILVERMONT | m_KNL | m_KNM | m_INTEL | m_CORE_ALL | m_GENERIC)


[patch, Fortran] Fix PR 82372

2017-10-10 Thread Thomas Koenig

Hello world,

the attached patch displays an error for characters which are
outside the normal Fortran character set, and includes a hex
code when it is not printable.

gfortran 4.9 did display unprintable characters in the file,
so it might be argued that this bug is a regression.

Regression-tested. OK for trunk? What do people feel about backporting?

Regards

Thomas

2017-10-10  Thomas Koenig  

PR fortran/82372
* fortran/scanner.c (valid_chars): String with all characters
which could be valid in Fortran.
(valid_table):  Boolean table to select valid characters.
(gfc_scanner_init_1): Set up valid_table from vaid_chars.
(gfc_gooble_whitespace): If a character not in the Fortran
character set appears, display error.

2017-10-10  Thomas Koenig  

PR fortran/82372
* gfortran.dg/illegal_char.f90: New test.
Index: fortran/scanner.c
===
--- fortran/scanner.c	(Revision 253530)
+++ fortran/scanner.c	(Arbeitskopie)
@@ -80,7 +80,14 @@ static struct gfc_file_change
 size_t file_changes_cur, file_changes_count;
 size_t file_changes_allocated;
 
+char valid_chars[] =
+  "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
+  "=+*-/^%[].,\n\t\r'\"();:<>_!$&0123456789";
 
+bool valid_table[256];
+
+/* Lookup table to see which characters are valid. */
+
 /* Functions dealing with our wide characters (gfc_char_t) and
sequences of such characters.  */
 
@@ -261,6 +268,9 @@ gfc_wide_strncasecmp (const gfc_char_t *s1, const
 void
 gfc_scanner_init_1 (void)
 {
+  char *p;
+  int i;
+
   file_head = NULL;
   line_head = NULL;
   line_tail = NULL;
@@ -269,6 +279,12 @@ gfc_scanner_init_1 (void)
   continue_line = 0;
 
   end_flag = 0;
+
+  for (p = valid_chars; *p; p++)
+{
+  i = *p;
+  valid_table[i] = true;
+}
 }
 
 
@@ -1680,6 +1696,8 @@ gfc_gobble_whitespace (void)
   static int linenum = 0;
   locus old_loc;
   gfc_char_t c;
+  static gfc_char_t dummy;
+  static gfc_char_t *last_error_char = 
 
   do
 {
@@ -1700,6 +1718,20 @@ gfc_gobble_whitespace (void)
 }
   while (gfc_is_whitespace (c));
 
+  if ((c > 256 || !valid_table[c])
+  && last_error_char != gfc_current_locus.nextc)
+{
+  if (ISPRINT (c))
+	gfc_error_now ("Invalid character '%c' at %C", c);
+  else
+	{
+	  char buf[20];
+	  snprintf (buf, 20, "%2.2X", c);
+	  gfc_error_now ("Invalid character 0x%s at %C", buf);
+	}
+  last_error_char = gfc_current_locus.nextc;
+}
+
   gfc_current_locus = old_loc;
 }
 
Index: testsuite/gfortran.dg/goacc/parallel-kernels-clauses.f95
===
--- testsuite/gfortran.dg/goacc/parallel-kernels-clauses.f95	(Revision 253530)
+++ testsuite/gfortran.dg/goacc/parallel-kernels-clauses.f95	(Arbeitskopie)
@@ -37,11 +37,11 @@ program test
   !$acc kernels async() { dg-error "Invalid character" }
   !$acc parallel async() { dg-error "Invalid character" }
 
-  !$acc kernels async("a") { dg-error "Unclassifiable" }
-  !$acc parallel async("a") { dg-error "Unclassifiable" }
+  !$acc kernels async("a") ! { dg-error "Unclassifiable" }
+  !$acc parallel async("a") ! { dg-error "Unclassifiable" }
 
-  !$acc kernels async(.true.) { dg-error "Unclassifiable" }
-  !$acc parallel async(.true.) { dg-error "Unclassifiable" }
+  !$acc kernels async(.true.) ! { dg-error "Unclassifiable" }
+  !$acc parallel async(.true.) ! { dg-error "Unclassifiable" }
 
   ! default(none)
   !$acc kernels default(none)
@@ -59,8 +59,8 @@ program test
   !$acc parallel default ( none )
   !$acc end parallel
 
-  !$acc kernels default { dg-error "Unclassifiable" }
-  !$acc parallel default { dg-error "Unclassifiable" }
+  !$acc kernels default ! { dg-error "Unclassifiable" }
+  !$acc parallel default ! { dg-error "Unclassifiable" }
 
   !$acc kernels default() { dg-error "Unclassifiable" }
   !$acc parallel default() { dg-error "Unclassifiable" }
Index: testsuite/gfortran.dg/typebound_proc_4.f03
===
--- testsuite/gfortran.dg/typebound_proc_4.f03	(Revision 253530)
+++ testsuite/gfortran.dg/typebound_proc_4.f03	(Arbeitskopie)
@@ -14,7 +14,7 @@ MODULE testmod
 PROCEDURE p1 => proc1 ! { dg-error "::" }
 PROCEDURE :: ! { dg-error "Expected binding name" }
 PROCEDURE ! { dg-error "Expected binding name" }
-PROCEDURE ? ! { dg-error "Expected binding name" }
+PROCEDURE ? ! { dg-error "Expected binding name|Invalid character" }
 PROCEDURE :: p2 => ! { dg-error "Expected binding target" }
 PROCEDURE :: p3 =>, ! { dg-error "Expected binding target" }
 PROCEDURE p4, ! { dg-error "Expected binding name" }
! { dg-do compile }
! PR 82372 - show hexcode of illegal, non-printable characters
program main
  tmp =È   1.0 ! { dg-error "Invalid character 0xC8" }
  print *,tmp
end


Re: Fix profile update in switch conversion

2017-10-10 Thread Jan Hubicka
> Hi Honza,
> 
> The change here cause the following failures:
> 
> >FAIL: gcc.dg/tree-prof/switch-case-1.c scan-rtl-dump-times expand ";; basic 
> >block[^\\n]*count 2000" 1
> >FAIL: gcc.dg/tree-prof/switch-case-2.c scan-rtl-dump-times expand ";; basic 
> >block[^\\n]*count 2000" 1
> 
> 
> I checked that, after the change, there are two matches in the dump file.
> 
> 
> >;; basic block 8, loop depth 0, count 2000 (adjusted), freq 2000, maybe hot
> >;; basic block 23, loop depth 0, count 2000, freq 2000, maybe hot
> 
> 
> And without the change, there is only one match.
> 
> >;; basic block 23, loop depth 0, count 2000, freq 2000, maybe hot

I have also noticed that yesterday.  The problem was hidden previously because 
there was
edges with no counts.  There are some mismatches in profile constructed and I 
hoped that
perhaps Martin will know how to fix these right away?
Otherwise I will take a look tomorrow ;)

Honza
> 
> Regards,
> Renlin
> 
> 
> On 06/10/17 13:18, Jan Hubicka wrote:
> >Hi,
> >this patch fixes missing profile updat that triggers during 
> >profiledbootstrap.
> >
> >Honza
> >
> > * tree-switch-conversion.c (do_jump_if_equal, emit_cmp_and_jump_insns):
> > Update edge counts.
> >
> >Index: tree-switch-conversion.c
> >===
> >--- tree-switch-conversion.c (revision 253444)
> >+++ tree-switch-conversion.c (working copy)
> >@@ -2248,10 +2248,12 @@ do_jump_if_equal (basic_block bb, tree o
> >edge false_edge = split_block (bb, cond);
> >false_edge->flags = EDGE_FALSE_VALUE;
> >false_edge->probability = prob.invert ();
> >+  false_edge->count = bb->count.apply_probability (false_edge->probability);
> >
> >edge true_edge = make_edge (bb, label_bb, EDGE_TRUE_VALUE);
> >fix_phi_operands_for_edge (true_edge, phi_mapping);
> >true_edge->probability = prob;
> >+  true_edge->count = bb->count.apply_probability (true_edge->probability);
> >
> >return false_edge->dest;
> >  }
> >@@ -2291,10 +2293,12 @@ emit_cmp_and_jump_insns (basic_block bb,
> >edge false_edge = split_block (bb, cond);
> >false_edge->flags = EDGE_FALSE_VALUE;
> >false_edge->probability = prob.invert ();
> >+  false_edge->count = bb->count.apply_probability (false_edge->probability);
> >
> >edge true_edge = make_edge (bb, label_bb, EDGE_TRUE_VALUE);
> >fix_phi_operands_for_edge (true_edge, phi_mapping);
> >true_edge->probability = prob;
> >+  true_edge->count = bb->count.apply_probability (true_edge->probability);
> >
> >return false_edge->dest;
> >  }
> >


Re: [PATCH] Add a warning for invalid function casts

2017-10-10 Thread Martin Sebor

On 10/10/2017 10:30 AM, Joseph Myers wrote:

On Tue, 10 Oct 2017, Martin Sebor wrote:


I know of pre-existing code-bases where a type-cast to type:
void (*) (void);

.. is already used as a generic function pointer: libffi and
libgo, I would not want to break these.


Why not fix them instead?  They're a part of GCC so it should
be straightforward.  It doesn't seem like a good tradeoff to


Sometimes an interface needs to store an arbitrary function type for which
an ABI-compliant call ends up being constructed at runtime from assembly
language (or from non-C, in general).  That's the sort of thing libffi
does - so it inherently needs to be able to take pointers to arbitrary
function types, which thus need to be converted to a generic function
type, and the de facto generic function pointer type in C is void (*)
(void).  (C11 6.11.6 says "The use of function declarators with empty
parentheses (not prototype-format parameter type declarators) is an
obsolescent feature.", so void (*) () is best avoided.)  Likewise
interfaces such as dlsym (which happens to return void * along with a
special case in POSIX requiring conversions between void * and function
pointers to work, but void (*) (void) is the natural type for such
interfaces to use).


I agree that unprototyped functions are best avoided in cases
where type checking is needed (i.e., in most use cases).  I also
agree that "generic function pointers") are not uncommon and are
worth accommodating.

But I don't think that adopting an inferior mechanism for it when
a better alternative exists is helpful.

Calling a function that takes arguments via a void (*)(void)
is undefined not just on paper but also in practice, so the
resulting pointer from such a cast is unusable except to convert
to a compatible pointer.

On the other hand, it is well-defined or safe to use a void (*)()
to call essentially any function, so it is a superior choice for
this use case.  Even if the pointer is only used for storage and
never to call a function, the syntax is elegant and the intent
clear.

Martin

PS It would be useful if modern C provided a clean mechanism to
support generic function pointers rather that forcing users leery
of relying on obsolescent features to invent workarounds.  One
alternative is to unobsolesce unprototyped functions for this
use case (i.e., for pointers to functions).  Another might be to
invent some other syntax (e.g., void (*)(...) since it's accepted
in C++).  But using void(*)(void) feels like a hack to me.


Re: [PATCH, rs6000] (v2) fix-up int128 fold vector multiply tests

2017-10-10 Thread Segher Boessenkool
On Tue, Oct 10, 2017 at 10:52:37AM -0500, Will Schmidt wrote:
> [PATCH, rs6000] fix-up int128 fold vector multiply tests
> 
> Fix up a few issues with the tests.
> - add -O2 to int128-p8 test, and firm up the -mcpu and 
> -mpower*-vector options
> - update the set of expected instructions for the int128-p9 test.
> - remove the float128_hw requirement from the int128-p9 test.
> 
> 2017-10-10  Will Schmidt 
>   * gcc.target/powerpc/fold-vec-mult-int128-p8.c: Update options
>   * gcc.target/powerpc/fold-vec-mult-int128-p9.c: Update expected
>   instruction list.

Thanks for the update.  This looks fine I think; okay for trunk.


Segher


GCC 7 libbacktrace patch committed: Ignore compressed debug sections

2017-10-10 Thread Ian Lance Taylor
This patch to the GCC 7 libbacktrace ignores compressed debug
sections.  If we don't, the DWARF reader reports an error.  Since the
GCC 7 libbacktrace does not support uncompressing the debug sections,
ignoring them is the best approach (on trunk, we uncompress).  This is
for PR 80914.  Bootstrapped and ran libbacktrace tests on
x86_64-pc-linux-gnu.  Committed to GCC 7 branch.

Ian

2017-10-10  Ian Lance Taylor  

PR go/80914
* elf.c (SHF_COMPRESSED): Define.
(elf_add): Ignore debug sections with SHF_COMPRESSED set.
Index: elf.c
===
--- elf.c   (revision 253593)
+++ elf.c   (working copy)
@@ -103,6 +103,7 @@
 #undef SHT_SYMTAB
 #undef SHT_STRTAB
 #undef SHT_DYNSYM
+#undef SFH_COMPRESSED
 #undef STT_OBJECT
 #undef STT_FUNC
 
@@ -195,6 +196,8 @@
 #define SHT_STRTAB 3
 #define SHT_DYNSYM 11
 
+#define SHF_COMPRESSED 0x800
+
 #if BACKTRACE_ELF_SIZE == 32
 
 typedef struct
@@ -700,7 +703,8 @@
 
   for (j = 0; j < (int) DEBUG_MAX; ++j)
{
- if (strcmp (name, debug_section_names[j]) == 0)
+ if (strcmp (name, debug_section_names[j]) == 0
+  && (shdr->sh_flags & SHF_COMPRESSED) == 0)
{
  sections[j].offset = shdr->sh_offset;
  sections[j].size = shdr->sh_size;


Re: [PATCH] Add a warning for invalid function casts

2017-10-10 Thread Joseph Myers
On Tue, 10 Oct 2017, Martin Sebor wrote:

> > I know of pre-existing code-bases where a type-cast to type:
> > void (*) (void);
> > 
> > .. is already used as a generic function pointer: libffi and
> > libgo, I would not want to break these.
> 
> Why not fix them instead?  They're a part of GCC so it should
> be straightforward.  It doesn't seem like a good tradeoff to

Sometimes an interface needs to store an arbitrary function type for which 
an ABI-compliant call ends up being constructed at runtime from assembly 
language (or from non-C, in general).  That's the sort of thing libffi 
does - so it inherently needs to be able to take pointers to arbitrary 
function types, which thus need to be converted to a generic function 
type, and the de facto generic function pointer type in C is void (*) 
(void).  (C11 6.11.6 says "The use of function declarators with empty 
parentheses (not prototype-format parameter type declarators) is an 
obsolescent feature.", so void (*) () is best avoided.)  Likewise 
interfaces such as dlsym (which happens to return void * along with a 
special case in POSIX requiring conversions between void * and function 
pointers to work, but void (*) (void) is the natural type for such 
interfaces to use).

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


Re: [PATCH, rs6000] (v2) fix-up int128 fold vector multiply tests

2017-10-10 Thread Will Schmidt
On Mon, 2017-10-09 at 17:22 -0500, Segher Boessenkool wrote:
> Hi Will,
> 
> On Mon, Oct 09, 2017 at 04:27:54PM -0500, Will Schmidt wrote:
> > Fix up a few issues with the tests.
> > - add -O2 to int128-p8 test, and firm up the -mcpu options
> > - update the set of expected instructions for the int128-p9 test.
> > - replace the float128_hw requirement with power8_vector_ok
> > for the int128-p9 test.
> 
> > -/* { dg-final { scan-assembler-times "\[ \t\]mulld " 6 } } */
> > +/* { dg-final { scan-assembler-times "\[ \t\]mulld" 6 } } */
> 
> Why this?  (Better/easier would be to use \m and \M btw.)

hmm, yeah, intended this to be a whitespace cleanup but that was in
error.  The dg-final section now reads as:

/* { dg-final { scan-assembler-times {\mmulld\M} 6 } } */
/* { dg-final { scan-assembler-times {\mmulhdu\M} 2 } } */

> 
> > diff --git a/gcc/testsuite/gcc.target/powerpc/fold-vec-mult-int128-p9.c 
> > b/gcc/testsuite/gcc.target/powerpc/fold-vec-mult-int128-p9.c
> > index e81ea5f..a226ae0 100644
> > --- a/gcc/testsuite/gcc.target/powerpc/fold-vec-mult-int128-p9.c
> > +++ b/gcc/testsuite/gcc.target/powerpc/fold-vec-mult-int128-p9.c
> > @@ -1,10 +1,10 @@
> >  /* Verify that overloaded built-ins for vec_mul with __int128
> > inputs produce the right results.  */
> >  
> >  /* { dg-do compile } */
> > -/* { dg-require-effective-target powerpc_float128_hw_ok } */
> > +/* { dg-require-effective-target powerpc_p8vector_ok } */
> >  /* { dg-require-effective-target int128 } */
> >  /* { dg-skip-if "do not override -mcpu" { powerpc*-*-* } { "-mcpu=*" } { 
> > "-mcpu=power9" } } */
> >  /* { dg-options "-mcpu=power9 -O2" } */
> >  /* { dg-additional-options "-maix64" { target powerpc-ibm-aix* } } */
> 
> This looks curious, too.  With the change it will no longer work if you
> built GCC with a version of binutils that doesn't support p9, I think?
> Not that people should do that.

Right.  On at least one (older) system i've got I do trigger an error,
before making this change.
cc1: warning: will not generate power9 instructions because
assembler lacks power9 support.

so the intent is to clear that one up.

The check on this one should probably be for p9 vector though. 
> +/* { dg-require-effective-target powerpc_p9vector_ok } */

So..   [v2].  :-)


---><---


[PATCH, rs6000] fix-up int128 fold vector multiply tests

Fix up a few issues with the tests.
- add -O2 to int128-p8 test, and firm up the -mcpu and -mpower*-vector 
options
- update the set of expected instructions for the int128-p9 test.
- remove the float128_hw requirement from the int128-p9 test.

2017-10-10  Will Schmidt 
* gcc.target/powerpc/fold-vec-mult-int128-p8.c: Update options
* gcc.target/powerpc/fold-vec-mult-int128-p9.c: Update expected
instruction list.

diff --git a/gcc/testsuite/gcc.target/powerpc/fold-vec-mult-int128-p8.c 
b/gcc/testsuite/gcc.target/powerpc/fold-vec-mult-int128-p8.c
index 97d6b945..b1cf0a7 100644
--- a/gcc/testsuite/gcc.target/powerpc/fold-vec-mult-int128-p8.c
+++ b/gcc/testsuite/gcc.target/powerpc/fold-vec-mult-int128-p8.c
@@ -3,11 +3,12 @@
 
 /* { dg-do compile } */
 /* { dg-require-effective-target powerpc_p8vector_ok } */
 /* { dg-require-effective-target int128 } */
 /* { dg-require-effective-target lp64 } */
-/* { dg-options "-mpower8-vector" } */
+/* { dg-skip-if "do not override -mcpu" { powerpc*-*-* } { "-mcpu=*" } { 
"-mcpu=power8" } } */
+/* { dg-options "-mpower8-vector -mcpu=power8 -O2" } */
 /* { dg-additional-options "-maix64" { target powerpc-ibm-aix* } } */
 
 #include "altivec.h"
 
 vector signed __int128
@@ -20,7 +21,7 @@ vector unsigned __int128
 test2 (vector unsigned __int128 x, vector unsigned __int128 y)
 {
   return vec_mul (x, y);
 }
 
-/* { dg-final { scan-assembler-times "\[ \t\]mulld " 6 } } */
-/* { dg-final { scan-assembler-times "\[ \t\]mulhdu" 2 } } */
+/* { dg-final { scan-assembler-times {\mmulld\M} 6 } } */
+/* { dg-final { scan-assembler-times {\mmulhdu\M} 2 } } */
diff --git a/gcc/testsuite/gcc.target/powerpc/fold-vec-mult-int128-p9.c 
b/gcc/testsuite/gcc.target/powerpc/fold-vec-mult-int128-p9.c
index e81ea5f..6571884 100644
--- a/gcc/testsuite/gcc.target/powerpc/fold-vec-mult-int128-p9.c
+++ b/gcc/testsuite/gcc.target/powerpc/fold-vec-mult-int128-p9.c
@@ -1,13 +1,13 @@
 /* Verify that overloaded built-ins for vec_mul with __int128
inputs produce the right results.  */
 
 /* { dg-do compile } */
-/* { dg-require-effective-target powerpc_float128_hw_ok } */
+/* { dg-require-effective-target powerpc_p9vector_ok } */
 /* { dg-require-effective-target int128 } */
 /* { dg-skip-if "do not override -mcpu" { powerpc*-*-* } { "-mcpu=*" } { 
"-mcpu=power9" } } */
-/* { dg-options "-mcpu=power9 -O2" } */
+/* { dg-options "-mpower9-vector -mcpu=power9 -O2" } */
 /* { dg-additional-options "-maix64" { target powerpc-ibm-aix* } } */

Re: Fix profile update in switch conversion

2017-10-10 Thread Renlin Li

Hi Honza,

The change here cause the following failures:


FAIL: gcc.dg/tree-prof/switch-case-1.c scan-rtl-dump-times expand ";; basic 
block[^\\n]*count 2000" 1
FAIL: gcc.dg/tree-prof/switch-case-2.c scan-rtl-dump-times expand ";; basic 
block[^\\n]*count 2000" 1



I checked that, after the change, there are two matches in the dump file.



;; basic block 8, loop depth 0, count 2000 (adjusted), freq 2000, maybe hot
;; basic block 23, loop depth 0, count 2000, freq 2000, maybe hot



And without the change, there is only one match.


;; basic block 23, loop depth 0, count 2000, freq 2000, maybe hot


Regards,
Renlin


On 06/10/17 13:18, Jan Hubicka wrote:

Hi,
this patch fixes missing profile updat that triggers during profiledbootstrap.

Honza

* tree-switch-conversion.c (do_jump_if_equal, emit_cmp_and_jump_insns):
Update edge counts.

Index: tree-switch-conversion.c
===
--- tree-switch-conversion.c(revision 253444)
+++ tree-switch-conversion.c(working copy)
@@ -2248,10 +2248,12 @@ do_jump_if_equal (basic_block bb, tree o
edge false_edge = split_block (bb, cond);
false_edge->flags = EDGE_FALSE_VALUE;
false_edge->probability = prob.invert ();
+  false_edge->count = bb->count.apply_probability (false_edge->probability);

edge true_edge = make_edge (bb, label_bb, EDGE_TRUE_VALUE);
fix_phi_operands_for_edge (true_edge, phi_mapping);
true_edge->probability = prob;
+  true_edge->count = bb->count.apply_probability (true_edge->probability);

return false_edge->dest;
  }
@@ -2291,10 +2293,12 @@ emit_cmp_and_jump_insns (basic_block bb,
edge false_edge = split_block (bb, cond);
false_edge->flags = EDGE_FALSE_VALUE;
false_edge->probability = prob.invert ();
+  false_edge->count = bb->count.apply_probability (false_edge->probability);

edge true_edge = make_edge (bb, label_bb, EDGE_TRUE_VALUE);
fix_phi_operands_for_edge (true_edge, phi_mapping);
true_edge->probability = prob;
+  true_edge->count = bb->count.apply_probability (true_edge->probability);

return false_edge->dest;
  }



Re: [PATCH] Add a warning for invalid function casts

2017-10-10 Thread Martin Sebor

On 10/09/2017 04:30 PM, Bernd Edlinger wrote:

On 10/09/17 20:34, Martin Sebor wrote:

On 10/09/2017 11:50 AM, Bernd Edlinger wrote:

On 10/09/17 18:44, Martin Sebor wrote:

On 10/07/2017 10:48 AM, Bernd Edlinger wrote:

Hi!

I think I have now something useful, it has a few more heuristics
added, to reduce the number of false-positives so that it
is able to find real bugs, for instance in openssl it triggers
at a function cast which has already a TODO on it.

The heuristics are:
- handle void (*)(void) as a wild-card function type.
- ignore volatile, const qualifiers on parameters/return.
- handle any pointers as equivalent.
- handle integral types, enums, and booleans of same precision
   and signedness as equivalent.
- stop parameter validation at the first "...".


These sound quite reasonable to me.  I have a reservation about
just one of them, and some comments about other aspects of the
warning.  Sorry if this seems like a lot.  I'm hoping you'll
find the feedback constructive.

I don't think using void(*)(void) to suppress the warning is
a robust solution because it's not safe to call a function that
takes arguments through such a pointer (especially not if one
or more of the arguments is a pointer).  Depending on the ABI,
calling a function that expects arguments with none could also
mess up the stack as the callee may pop arguments that were
never passed to it.



This is of course only a heuristic, and if there is no warning
that does not mean any guarantee that there can't be a problem
at runtime.  The heuristic is only meant to separate the
bad from the very bad type-cast.  In my personal opinion there
is not a single good type cast.


I agree.  Since the warning uses one kind of a cast as an escape
mechanism from the checking it should be one whose result can
the most likely be used to call the function without undefined
behavior.

Since it's possible to call any function through a pointer to
a function with no arguments (simply by providing arguments of
matching types) it's a reasonable candidate.

On the other hand, since it is not safe to call an arbitrary
function through void (*)(void), it's not as good a candidate.

Another reason why I think a protoype-less function is a good
choice is because the alias and ifunc attributes already use it
as an escape mechanism from their type incompatibility warning.



I know of pre-existing code-bases where a type-cast to type:
void (*) (void);

.. is already used as a generic function pointer: libffi and
libgo, I would not want to break these.


Why not fix them instead?  They're a part of GCC so it should
be straightforward.  It doesn't seem like a good tradeoff to
compromise the efficacy of the warning to accommodate a couple
of questionable use cases.



Actually when I have a type:
X (*) (...);

I would like to make sure that the warning checks that
only functions returning X are assigned.

and for X (*) (Y, );

I would like to check that anything returning X with
first argument of type Y is assigned.

There are code bases where such a scheme is used.
For instance one that I myself maintain: the OPC/UA AnsiC Stack,
where I have this type definition:

typedef OpcUa_StatusCode (OpcUa_PfnInvokeService)(OpcUa_Endpoint
hEndpoint, ...);


If GCC guarantees that a variadic function can safely be called
with a pointer to another variadic function it seems reasonable
to avoid warning on such conversions.  But I'm not sure I see
what bearing this use case has on the one with functions without
a prototype.  In C++, void (*)(...) is the equivalent of
void (*)() in C, and so any function can be cast to it with no
warning because it can be safely called by providing the right
arguments.  Ignoring the return type should likewise be safe.
This feels like a clean design, while using void (*)(void)
like an unnecessary exception.


And this plays well together with this warning, because only
functions are assigned that match up to the ...);
Afterwards this pointer is cast back to the original signature,
so everything is perfectly fine.


I tend to agree.


Regarding the cast from pointer to member to function, I see also a
warning without -Wpedantic:
Warnung: converting from »void (S::*)(int*)« to »void (*)(int*)«
[-Wpmf-conversions]
F *pf = (F*)::foo;
^~~

And this one is even default-enabled, so I think that should be
more than sufficient.


I agree.  It looks like this triggers -Wpedantic when -Wpedantic
is set and -Wpmf-conversions when it isn't.  (It seems odd but
adding it under yet another warning option wouldn't help.)

Warning on the other test case would, however, be useful:

  struct S { void foo (int*); };

  typedef void (S::*MF)(int);

  MF pmf = (MF)::foo;

Martin


GCC 5 branch is now closed

2017-10-10 Thread Jakub Jelinek
After the GCC 5.5 release the GCC 5 branch is now closed.  Please
refrain from committing to it from now on.

Thanks
Jakub


[C++ PATCH] set_global_binding tweak

2017-10-10 Thread Nathan Sidwell
It turns out that we no longer have to worry about the stat hack when 
pushing internal decls into the global namespace.  I think it was last 
week's change to record_builtin_type, which did have the habit of 
pushing duplicates before that.


Applying to trunk.

nathan
--
Nathan Sidwell
2017-10-10  Nathan Sidwell  

	* name-lookup.c (set_global_binding): Don't deal with STAT_HACK.

Index: name-lookup.c
===
--- name-lookup.c	(revision 253502)
+++ name-lookup.c	(working copy)
@@ -4858,22 +4858,13 @@ set_global_binding (tree decl)
   bool subtime = timevar_cond_start (TV_NAME_LOOKUP);
 
   tree *slot = find_namespace_slot (global_namespace, DECL_NAME (decl), true);
-  tree old = MAYBE_STAT_DECL (*slot);
 
-  if (!old)
-*slot = decl;
-  else if (old == decl)
-;
-  else if (!STAT_HACK_P (*slot)
-	   && TREE_CODE (decl) == TYPE_DECL && DECL_ARTIFICIAL (decl))
-*slot = stat_hack (old, decl);
-  else if (!STAT_HACK_P (*slot)
-	   && TREE_CODE (old) == TYPE_DECL && DECL_ARTIFICIAL (old))
-*slot = stat_hack (decl, old);
-  else
-/* The user's placed something in the implementor's
-   namespace.  */
-diagnose_name_conflict (decl, old);
+  if (*slot)
+/* The user's placed something in the implementor's namespace.  */
+diagnose_name_conflict (decl, MAYBE_STAT_DECL (*slot));
+
+  /* Force the binding, so compiler internals continue to work.  */
+  *slot = decl;
 
   timevar_cond_stop (TV_NAME_LOOKUP, subtime);
 }


Re: [PATCH,AIX] Fix issue with PRI*64 on AIX.

2017-10-10 Thread David Edelsohn
On Tue, Oct 10, 2017 at 10:31 AM, REIX, Tony  wrote:
> Hi David,
>
> Since the file ./gcc/go/go-system.h in GCC source code starts by:
>
> // go-system.h -- Go frontend inclusion of gcc header files   -*- C++ -*-
> // Copyright (C) 2009-2017 Free Software Foundation, Inc.
>
> // This file is part of GCC.
> ...
>
> I think it is SFS and not Google.
>
> Moreover, this file does not appear in my Google Git environment I use for 
> PolyGerrit (GCCGo/GITgofrontend/gofrontend directory on my PC).

I guess that it is part of GCC.  I was confused by the README.gcc file
in that directory, but refers to the gofrontend subdirectory.

It still is in Ian's court.

Thanks, David


RE:[PATCH,AIX] Fix issue with PRI*64 on AIX.

2017-10-10 Thread REIX, Tony
Hi David,

Since the file ./gcc/go/go-system.h in GCC source code starts by:

// go-system.h -- Go frontend inclusion of gcc header files   -*- C++ -*-
// Copyright (C) 2009-2017 Free Software Foundation, Inc.

// This file is part of GCC.
...

I think it is SFS and not Google.

Moreover, this file does not appear in my Google Git environment I use for 
PolyGerrit (GCCGo/GITgofrontend/gofrontend directory on my PC).

Unless I do not understand something...

Cordialement,

Tony Reix

Bull - ATOS
IBM Coop Architect & Technical Leader
Office : +33 (0) 4 76 29 72 67
1 rue de Provence - 38432 Échirolles - France
www.atos.net


De : David Edelsohn [dje@gmail.com]
Envoyé : mardi 10 octobre 2017 15:46
À : REIX, Tony
Cc : gcc-patches@gcc.gnu.org
Objet : Re: [PATCH,AIX] Fix issue with PRI*64 on AIX.

On Tue, Oct 10, 2017 at 5:09 AM, REIX, Tony  wrote:
> Description:
>  * This patch enables to build on AIX.
>
> Tests:
>  * AIX: Build: SUCCESS
>- build made by means of gmake within GCC 8 trunk.
>
> ChangeLog:
>   * go-system.h : Enable to build on AIX.
>   (fix issue with PRIx64 and PRIu64)

Tony,

This is the wrong forum to propose the patch.  The Go frontend is
imported from Golang upstream.  The patch must be proposed in
PolyGerrit, merged into the main repository, and then imported to GCC
Gofrontend.

Thanks, David


Re: X+Y < X iff Y<0 moved to match.pd

2017-10-10 Thread Marc Glisse

On Mon, 9 Oct 2017, Richard Biener wrote:


On Sun, Oct 8, 2017 at 1:22 PM, Marc Glisse  wrote:

Hello,

this moves (and extends a bit) one more transformation from fold-const.c to
match.pd. The single_use restriction is necessary for consistency with the
existing X+CST1 CMP CST2 transformation (if we do only one of the 2
transformations, gcc.dg/tree-ssa/vrp54.c regresses because DOM fails to
simplify 2 conditions based on different variables). The relaxation of the
condition to simplify (T) X == (T) Y is an easier way to avoid regressing
gcc.dg/tree-ssa/foldaddr-1.c than adding plenty of convert? in the patterns,
although that may still prove necessary at some point. I left a few odd
float cases in fold-const.c for later.


+/* X + Y < Y is the same as X < 0 when there is no overflow.  */
+(for op  (lt le ge gt)
+ rop (gt ge le lt)
+ (simplify
+  (op (plus:c@2 @0 @1) @1)
+  (if (ANY_INTEGRAL_TYPE_P (TREE_TYPE (@0))
+   && TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (@0))
+   && (CONSTANT_CLASS_P (@0) || single_use (@2)))
+   (op @0 { build_zero_cst (TREE_TYPE (@0)); })))
+ (simplify
+  (op @1 (plus:c@2 @0 @1))
+  (if (ANY_INTEGRAL_TYPE_P (TREE_TYPE (@0))
+   && TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (@0))
+   && (CONSTANT_CLASS_P (@0) || single_use (@2)))
+   (rop @0 { build_zero_cst (TREE_TYPE (@0)); }

any reason (op:c (plus... on the first of the two patterns wouldn't have catched
the second?  :c on comparison swaps the comparison code.


I had completely forgotten that you had added this cool feature.


+/* For equality, this is also true with wrapping overflow.  */
+(for op (eq ne)
+ (simplify
+  (op:c (plus:c@2 @0 @1) @1)
+  (if (ANY_INTEGRAL_TYPE_P (TREE_TYPE (@0))
+   && (TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (@0))
+  || TYPE_OVERFLOW_WRAPS (TREE_TYPE (@0)))
+   && (CONSTANT_CLASS_P (@0) || single_use (@2)))
+   (op @0 { build_zero_cst (TREE_TYPE (@0)); })))
+ (simplify
+  (op:c (convert?@3 (pointer_plus@2 @0 @1)) (convert? @0))
+  (if (CONSTANT_CLASS_P (@1) || (single_use (@2) && single_use (@3)))
+   (op @1 { build_zero_cst (TREE_TYPE (@1)); }

for consistency can you add the convert?s to the integer variant as well?


The only relevant case I could think of is, for unsigned u, 
(unsigned)((int)u+1)==u. All the other cases seem to be handled some other 
way. I still wrote it to allow conversions all over the place, but that's 
uglier than the MINUS_EXPR transformation below where I didn't.



I'm not sure you'll see the convers like you write them (with matching @0).


int f(char*p){
  char*q=p+5;
  return (long)q==(long)p;
}


Eventually on GENERIC when we still have pointer conversions around?


For generic we might want @@0 or pointers sometimes fail to match. At 
least in the POINTER_DIFF_EXPR experiment I had to do that in some 
transformations for constexpr.



You are allowing arbitrary conversions here - is that desired?  Isn't
a tree_nop_conversion_p missing?


I had the impression that casts from a pointer to whatever were always 
NOP, for instance when I try to cast char* to short, gcc produces 
(short)(long)p. But reading the comment in verify_gimple_assign_unary it 
is more complicated, so yes I should add a constraint.


/* Allow conversions from pointer type to integral type only if
   there is no sign or zero extension involved.
   For targets were the precision of ptrofftype doesn't match that
   of pointers we need to allow arbitrary conversions to ptrofftype.  */
if ((POINTER_TYPE_P (lhs_type)
 && INTEGRAL_TYPE_P (rhs1_type))
|| (POINTER_TYPE_P (rhs1_type)
&& INTEGRAL_TYPE_P (lhs_type)
&& (TYPE_PRECISION (rhs1_type) >= TYPE_PRECISION (lhs_type)
|| ptrofftype_p (sizetype
  return false;

The code "|| ptrofftype_p (sizetype)" doesn't seem to match the comment :-(


Here is a new version of the patch, same changelog/testing.

--
Marc GlisseIndex: gcc/fold-const.c
===
--- gcc/fold-const.c	(revision 253558)
+++ gcc/fold-const.c	(working copy)
@@ -10483,54 +10483,20 @@ fold_binary_loc (location_t loc,
   && code == EQ_EXPR)
 return fold_convert_loc (loc, type,
  fold_build1_loc (loc, TRUTH_NOT_EXPR,
 		  TREE_TYPE (arg0), arg0));
 
   /* !exp != 0 becomes !exp */
   if (TREE_CODE (arg0) == TRUTH_NOT_EXPR && integer_zerop (arg1)
 	  && code == NE_EXPR)
 return non_lvalue_loc (loc, fold_convert_loc (loc, type, arg0));
 
-  /* Transform comparisons of the form X +- Y CMP X to Y CMP 0.  */
-  if ((TREE_CODE (arg0) == PLUS_EXPR
-	   || TREE_CODE (arg0) == POINTER_PLUS_EXPR
-	   || TREE_CODE (arg0) == MINUS_EXPR)
-	  && operand_equal_p (tree_strip_nop_conversions (TREE_OPERAND (arg0,
-	0)),
-			  arg1, 0)
-	  && (INTEGRAL_TYPE_P (TREE_TYPE (arg0))
-	  || POINTER_TYPE_P (TREE_TYPE 

Re: [PATCH] libstdc++: istreambuf_iterator proxy (was: keep attached streambuf)

2017-10-10 Thread Jonathan Wakely

On 06/10/17 18:01 +0200, François Dumont wrote:

On 03/10/2017 22:39, Petr Ovtchenkov wrote:

On Thu, 28 Sep 2017 13:38:06 +0100
Jonathan Wakely  wrote:


On 28/09/17 15:06 +0300, Petr Ovtchenkov wrote:

On Thu, 28 Sep 2017 11:34:25 +0100
Jonathan Wakely  wrote:

+  VERIFY(i == std::istreambuf_iterator());
+
+  VERIFY(memcmp(b, r, 36) == 0);
+
+  s << q;
+  VERIFY(!s.fail());
+
+  copy_n(i, 36, r);

This is undefined behaviour. The end-of-stream iterator value cannot
be dereferenced.

Within this test istreambuf_iterator in eof state never dereferenced.

That is quite implementation dependent.

The libc++ and VC++ implementations fail this test, because once an
istreambuf_iterator has been detected to reach end-of-stream it
doesn't get "reset" by changes to the streambuf.

If we will keep even "unspecified" behaviour same, then bug fix/drawback
removing become extremely hard: it should be identified as drawback
in all libs almost simultaneously.


The libc++ implementation crashes, because operator== on an
end-of-stream iterator sets its streambuf* to null, and any further
increment or dereference will segfault.

So this is testing something that other implementations don't support,
and isn't justifiable from the standard.

I will use N4687 as reference.

27.2.3 par.2 Table 95:

++r

Requires: r is dereferenceable. Postconditions: r is dereferenceable or r is
past-the-end; any copies of the previous value of r are no longer required
either to be dereferenceable or to be in the domain of ==.

(void)r++ equivalent to (void)++r

*r++

{ T tmp = *r;
++r;
return tmp; }

[BTW, you see that r++ without dereference has no sense, and even more,

  copies of the previous
  value of r are no longer
  required either to be
  dereferenceable or to be in
  the domain of ==.


From this follow, that postfix increment operator shouldn't return

istreambuf_iterator.
]


The test itself simulate "stop and go" istream usage.
stringstream is convenient for behaviuor illustration, but in "real life"
I can assume socket or tty on this place.

At the very minimum we should have a comment in the test explaining
how it relies on non-standard, non-portable behaviour.

But I'd prefer to avoid introducing more divergence from other
implementations.

Standard itself say nothting about "stop and go" scenario.
At least I don't see any words pro or contra.
But current implementation block usage of istreambuf_iterator
with underlying streams like socket or tty, so istreambuf_iterator become
almost useless structure for practice.
Why not creating a new istreambuf_iterator each time you need to check 
that streambuf is not in eof anymore ?



We have three issues with istreambuf_iterator:
  - debug-dependent behaviour

Fixed.

  - EOL of istreambuf_iterator when it reach EOF (but this not mean
EOL of associated streambuf)

Controversial.

  - postfix increment operator return istreambuf_iterator, but here
expected restricted type, that accept only dereference, if it possible.

I agree that we need to fix this last point too.

Consider this code:

  std::istringstream inf("abc");
  std::istreambuf_iterator j(inf), eof;
  std::istreambuf_iterator i = j++;

  assert( *i == 'a' );

At this point it looks like i is pointing to 'a' but then when you do:

std::string str(i, eof);

you have:
assert( str == "ac" );

We jump other the 'b'.


Right, but this code isn't required to work. These are Input
Iterators. The fact that incrementing j affects other copies of the
iterator is expected.


We could improve the situation by adding a debug assertion that _M_c 
is eof when pre-increment is being used


Hmm, interesting idea.

or by changing semantic of 
pre-increment to only call sbumpc if _M_c is eof. But then we would 
need to consider _M_c in find overload and in some other places in the 
lib I think.


Rather than going through this complicated path I agree with Petr that 
we need to simply implement the solution advised by the Standard with 
the nested proxy type.


This is what I have done in the attached patch in a naive way. Do we 
need to have abi compatibility here ? If so I'll rework it.


This patch will make libstdc++ pass the llvm test. I even duplicate it 
on our side with a small refinement to check for the return value of 
the proxy::operator*().


I agree with the earlier analysis that the libc++ test is not required
to work (i've reported this to the libc++ maintainers and expect them
to move it to their nonportable test directory).  So we don't need to
change our implementation to make it pass.




Re: [PATCH] Enable ifunc attribute by default for ARM GNU/Linux

2017-10-10 Thread Joseph Myers
On Tue, 10 Oct 2017, Adhemerval Zanella wrote:

> On 09/10/2017 19:20, Joseph Myers wrote:
> > On Mon, 9 Oct 2017, Adhemerval Zanella wrote:
> > 
> >>  *-*-linux*)
> >>case ${target} in
> >> -  aarch64*-* | i[34567]86-* | powerpc*-* | s390*-* | sparc*-* | x86_64-*)
> >> +  aarch64*-* | i[34567]86-* | powerpc*-* | s390*-* | sparc*-* | x86_64-* 
> >> | arm*-*)
> > 
> > I think the cases here are meant to be in alphabetical order.
> > 
> 
> Ack, I will change.  Is it ok to commit with the change?

OK with that change in the absence of ARM architecture maintainer 
objections within 24 hours.

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


Re: [PATCH,AIX] Fix issue with PRI*64 on AIX.

2017-10-10 Thread David Edelsohn
On Tue, Oct 10, 2017 at 5:09 AM, REIX, Tony  wrote:
> Description:
>  * This patch enables to build on AIX.
>
> Tests:
>  * AIX: Build: SUCCESS
>- build made by means of gmake within GCC 8 trunk.
>
> ChangeLog:
>   * go-system.h : Enable to build on AIX.
>   (fix issue with PRIx64 and PRIu64)

Tony,

This is the wrong forum to propose the patch.  The Go frontend is
imported from Golang upstream.  The patch must be proposed in
PolyGerrit, merged into the main repository, and then imported to GCC
Gofrontend.

Thanks, David


[PATCH] More SCEV TLC

2017-10-10 Thread Richard Biener

This cuts the recursion in analyze_scalar_evolution_1 somewhat more
making the flow easier to understand.  In particular
no_evolution_in_loop_p is replaced with a positive test on
chrec_contains_symbols_defined_in_loop guarding further analysis
after skipping overall effects of loops.

I've also included minor optimization / simplification regarding to
default-defs and unhandled types so they do not pollute the cache.

Bootstrapped and tested with asserts in place verifying everything,
re-bootstrapping / testing with the actual patch below.

In case you're curious I'm trying to make SCEV analysis region
aware, replacing "loop" with "entry edge" in relevant APIs.
Those cleanups are to make it easier to understand what contexts
care about loops and which not.

Richard.

2017-10-10  Richard Biener  

* tree-scalar-evolution.c (get_scalar_evolution): Handle
default-defs and types we do not want to analyze.
(interpret_loop_phi): Replace unreachable code with an assert.
(compute_scalar_evolution_in_loop): Remove and inline ...
(analyze_scalar_evolution_1): ... here, replacing condition with
what makes the intent clearer.  Remove handling of cases
get_scalar_evolution now handles.

Index: gcc/tree-scalar-evolution.c
===
--- gcc/tree-scalar-evolution.c (revision 253585)
+++ gcc/tree-scalar-evolution.c (working copy)
@@ -564,22 +564,30 @@ get_scalar_evolution (basic_block instan
nb_get_scev++;
 }
 
-  switch (TREE_CODE (scalar))
-{
-case SSA_NAME:
-  res = *find_var_scev_info (instantiated_below, scalar);
-  break;
+  if (VECTOR_TYPE_P (TREE_TYPE (scalar))
+  || TREE_CODE (TREE_TYPE (scalar)) == COMPLEX_TYPE)
+/* For chrec_dont_know we keep the symbolic form.  */
+res = scalar;
+  else
+switch (TREE_CODE (scalar))
+  {
+  case SSA_NAME:
+if (SSA_NAME_IS_DEFAULT_DEF (scalar))
+ res = scalar;
+   else
+ res = *find_var_scev_info (instantiated_below, scalar);
+   break;
 
-case REAL_CST:
-case FIXED_CST:
-case INTEGER_CST:
-  res = scalar;
-  break;
+  case REAL_CST:
+  case FIXED_CST:
+  case INTEGER_CST:
+   res = scalar;
+   break;
 
-default:
-  res = chrec_not_analyzed_yet;
-  break;
-}
+  default:
+   res = chrec_not_analyzed_yet;
+   break;
+  }
 
   if (dump_file && (dump_flags & TDF_SCEV))
 {
@@ -1628,19 +1636,7 @@ interpret_loop_phi (struct loop *loop, g
   struct loop *phi_loop = loop_containing_stmt (loop_phi_node);
   tree init_cond;
 
-  if (phi_loop != loop)
-{
-  struct loop *subloop;
-  tree evolution_fn = analyze_scalar_evolution
-   (phi_loop, PHI_RESULT (loop_phi_node));
-
-  /* Dive one level deeper.  */
-  subloop = superloop_at_depth (phi_loop, loop_depth (loop) + 1);
-
-  /* Interpret the subloop.  */
-  res = compute_overall_effect_of_inner_loop (subloop, evolution_fn);
-  return res;
-}
+  gcc_assert (phi_loop == loop);
 
   /* Otherwise really interpret the loop phi.  */
   init_cond = analyze_initial_condition (loop_phi_node);
@@ -2016,29 +2012,6 @@ interpret_gimple_assign (struct loop *lo
- instantiate_parameters.
 */
 
-/* Compute and return the evolution function in WRTO_LOOP, the nearest
-   common ancestor of DEF_LOOP and USE_LOOP.  */
-
-static tree
-compute_scalar_evolution_in_loop (struct loop *wrto_loop,
- struct loop *def_loop,
- tree ev)
-{
-  bool val;
-  tree res;
-
-  if (def_loop == wrto_loop)
-return ev;
-
-  def_loop = superloop_at_depth (def_loop, loop_depth (wrto_loop) + 1);
-  res = compute_overall_effect_of_inner_loop (def_loop, ev);
-
-  if (no_evolution_in_loop_p (res, wrto_loop->num, ) && val)
-return res;
-
-  return analyze_scalar_evolution_1 (wrto_loop, res);
-}
-
 /* Helper recursive function.  */
 
 static tree
@@ -2050,20 +2023,14 @@ analyze_scalar_evolution_1 (struct loop
   struct loop *def_loop;
   tree res;
 
-  if (loop == NULL
-  || TREE_CODE (type) == VECTOR_TYPE
-  || TREE_CODE (type) == COMPLEX_TYPE)
-return chrec_dont_know;
-
   if (TREE_CODE (var) != SSA_NAME)
 return interpret_expr (loop, NULL, var);
 
   def = SSA_NAME_DEF_STMT (var);
   bb = gimple_bb (def);
-  def_loop = bb ? bb->loop_father : NULL;
+  def_loop = bb->loop_father;
 
-  if (bb == NULL
-  || !flow_bb_inside_loop_p (loop, bb))
+  if (!flow_bb_inside_loop_p (loop, bb))
 {
   /* Keep symbolic form, but look through obvious copies for constants.  */
   res = follow_copies_to_constant (var);
@@ -2073,8 +2040,11 @@ analyze_scalar_evolution_1 (struct loop
   if (loop != def_loop)
 {
   res = analyze_scalar_evolution_1 (def_loop, var);
-  res = compute_scalar_evolution_in_loop (loop, def_loop, res);
-
+  struct loop *loop_to_skip = 

Re: r253554 - in /trunk/gcc: ada/ChangeLog ada/exp_...

2017-10-10 Thread Pierre-Marie de Rodat

Hello Andreas,

On 10/10/2017 04:44 AM, Andreas Schwab wrote:

On Okt 09 2017, pmdero...@gcc.gnu.org wrote:


2017-10-09  Ed Schonberg  

* gnat.dg/class_wide4.adb, gnat.dg/class_wide4_pkg.ads,
gnat.dg/class_wide4_pkg2.ads: New testcase.


FAIL: gnat.dg/class_wide4.adb (test for excess errors)
Excess errors:
class_wide4.adb:8:32: "Object" not declared in "Class_Wide4_Pkg"
class_wide4.adb:14:04: invalid prefix in selected component "O"
class_wide4.adb:15:04: invalid prefix in selected component "O"
class_wide4.adb:15:05: prefixed call is only allowed for objects of a tagged 
type
class_wide4.adb:18:04: actual for "This" must be a variable
class_wide4.adb:19:04: actual for "This" must be a variable


Yes, sorry about this. I had the fix locally yesterday when I realized 
this, and I thought I committed it but I guess I got confused with my 
SVN setup. Anyway the fix is now in. Thank you for having reported this!


--
Pierre-Marie de Rodat


Re: [PATCH] Enable ifunc attribute by default for ARM GNU/Linux

2017-10-10 Thread Adhemerval Zanella


On 09/10/2017 19:20, Joseph Myers wrote:
> On Mon, 9 Oct 2017, Adhemerval Zanella wrote:
> 
>>  *-*-linux*)
>>  case ${target} in
>> -aarch64*-* | i[34567]86-* | powerpc*-* | s390*-* | sparc*-* | x86_64-*)
>> +aarch64*-* | i[34567]86-* | powerpc*-* | s390*-* | sparc*-* | x86_64-* 
>> | arm*-*)
> 
> I think the cases here are meant to be in alphabetical order.
> 

Ack, I will change.  Is it ok to commit with the change?


[PATCH] DECL_ASSEMBLER_NAME and friends

2017-10-10 Thread Nathan Sidwell
I have a patch cleaning up a bit of the C++ FE, which will involve 
hashing via DECL_ASSEMBLER_NAME.  however, all the items in that hash 
are known to have it set, so its mapping to a function call is undesirable.


This patch adds DECL_ASSEMBLER_NAME_RAW, which gets at the field 
directly.  I can then use that for my hash table.  The cleanup to use 
that is fairly trivial.


However, I also looked more deeply at DECL_ASSEMBLER_NAME_SET_P. It does 
more than the name suggests -- namely checking HAS_DECL_ASSEMBLER_NAME_P 
too.  There are about 72 uses of DECL_ASSEMBLER_NAME_SET_P and 
investigation showed only about 4 applying it to decls that are not 
HAS_DECL_ASSEMBLER_NAME_P.  So, I remove the HAS_DECL_ASSEMBLER_NAME_P 
from DECL_ASSEMBLER_NAME_SET_P and explicitly check it at the 4 
locations that need it.


In doing this I noticed a couple of items:

1) ipa-utils.h (type_in_anonymous_namespace_p) is applying 
HAS_DECL_ASSEMBLER_NAME_P to a type.  That's clearly wrong, It looks 
like a thinko for TYPE_NAME (t).  Making that change seems fine.


2) tree-ssa-structalias.c (alias_get_name) seemed overly complicated, so 
I reimplemented it.


I checked the target-specific code, and there are only two uses of 
DECL_ASSEMBLER_NAME_SET_P.  Both look safe to me (the avr one seems 
superfluous, and DECL_ASSEMBLER_NAME would be fine there.


booted on x86_64-linux

ok?

nathan
--
Nathan Sidwell
2017-10-10  Nathan Sidwell  

	* tree.h (DECL_ASSEMBLER_NAME_RAW): New.
	(SET_DECL_ASSEMBLER_NAME): Use it.
	(DECL_ASSEMBLER_NAME_SET_P): Likewise.  Don't check
	HAS_DECL_ASSEMBLER_NAME_P.
	* tree.c (decl_assembler_name): Use DECL_ASSEMBLER_NAME_RAW.
	* gimple-expr.c (gimple_decl_printable_name: Check
	HAS_DECL_ASSEMBLER_NAME_P too.
	* ipa-utils.h (type_in_anonymous_namespace_p): Check
	DECL_ASSEMBLER_NAME_SET_P of TYPE_NAME.
	(odr_type_p): No need to assert TYPE_NAME is a TYPE_DECL.
	* passes.c (rest_of_decl_compilation): Check
	HAS_DECL_ASSEMBLER_NAME_P too.
	* recog.c (verify_changes): Likewise.
	* tree-pretty-print.c (dump_decl_name): Likewise.
	* tree-ssa-structalias.c (alias_get_name): Likewise.  Reimplement.

	c/
	* c-decl.c (grokdeclarator): Check HAS_DECL_ASSEMBLER_NAME_P too.

	lto/
	* lto.c (mentions_vars_p_decl_with_vis): Use
	DECL_ASSEMBLER_NAME_RAW.
	(lto_fixup_prevailing_decls): Likewise.
	
Index: c/c-decl.c
===
--- c/c-decl.c	(revision 253502)
+++ c/c-decl.c	(working copy)
@@ -7011,7 +7011,8 @@ grokdeclarator (const struct c_declarato
 
   /* This is the earliest point at which we might know the assembler
  name of a variable.  Thus, if it's known before this, die horribly.  */
-gcc_assert (!DECL_ASSEMBLER_NAME_SET_P (decl));
+gcc_assert (!HAS_DECL_ASSEMBLER_NAME_P (decl)
+		|| !DECL_ASSEMBLER_NAME_SET_P (decl));
 
 if (warn_cxx_compat
 	&& VAR_P (decl)
Index: gimple-expr.c
===
--- gimple-expr.c	(revision 253502)
+++ gimple-expr.c	(working copy)
@@ -337,9 +337,8 @@ gimple_decl_printable_name (tree decl, i
   if (!DECL_NAME (decl))
 return NULL;
 
-  if (DECL_ASSEMBLER_NAME_SET_P (decl))
+  if (HAS_DECL_ASSEMBLER_NAME_P (decl) && DECL_ASSEMBLER_NAME_SET_P (decl))
 {
-  const char *str, *mangled_str;
   int dmgl_opts = DMGL_NO_OPTS;
 
   if (verbosity >= 2)
@@ -352,9 +351,10 @@ gimple_decl_printable_name (tree decl, i
 	dmgl_opts |= DMGL_PARAMS;
 	}
 
-  mangled_str = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
-  str = cplus_demangle_v3 (mangled_str, dmgl_opts);
-  return (str) ? str : mangled_str;
+  const char *mangled_str
+	= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME_RAW (decl));
+  const char *str = cplus_demangle_v3 (mangled_str, dmgl_opts);
+  return str ? str : mangled_str;
 }
 
   return IDENTIFIER_POINTER (DECL_NAME (decl));
Index: ipa-utils.h
===
--- ipa-utils.h	(revision 253502)
+++ ipa-utils.h	(working copy)
@@ -217,11 +217,11 @@ type_in_anonymous_namespace_p (const_tre
 {
   /* C++ FE uses magic  as assembler names of anonymous types.
  	 verify that this match with type_in_anonymous_namespace_p.  */
-  gcc_checking_assert (!in_lto_p || !DECL_ASSEMBLER_NAME_SET_P (t)
-			   || !strcmp
- ("",
-  IDENTIFIER_POINTER
- (DECL_ASSEMBLER_NAME (TYPE_NAME (t);
+  gcc_checking_assert (!in_lto_p
+			   || !DECL_ASSEMBLER_NAME_SET_P (TYPE_NAME (t))
+			   || !strcmp ("",
+   IDENTIFIER_POINTER
+   (DECL_ASSEMBLER_NAME (TYPE_NAME (t);
   return true;
 }
   return false;
@@ -245,14 +245,13 @@ odr_type_p (const_tree t)
   if (type_in_anonymous_namespace_p (t))
 return true;
 
-  if (TYPE_NAME (t) && TREE_CODE (TYPE_NAME (t)) == TYPE_DECL
-  && DECL_ASSEMBLER_NAME_SET_P (TYPE_NAME (t)))
+  if (TYPE_NAME (t) && DECL_ASSEMBLER_NAME_SET_P (TYPE_NAME (t)))
 {
  

Re: [PATCH] Fix ICEs with ss{e,e2,se3} builtins with -mno-mmx (PR target/82483, take 2)

2017-10-10 Thread Uros Bizjak
On Tue, Oct 10, 2017 at 1:11 PM, Jakub Jelinek  wrote:
> On Mon, Oct 09, 2017 at 09:47:49PM +0200, Jakub Jelinek wrote:
>> > Hm, I remember there was similar patch for PR79565 [1], which seems
>> > related. Does your patch also fix all builtins that HJ's patch touch?
>>
>> Ah, I wasn't aware of that patch.  Will look in detail tomorrow.
>>
>> > [1] https://gcc.gnu.org/ml/gcc-patches/2017-08/msg00751.html
>>
>> Just quick analysis, while -mno-mmx doesn't imply -mno-sse (that is
>> right), it implies -mno-3dnow and -mno-3dnow implies -mno-3dnowa.
>> So all the spots that were changed from OPTION_MASK_ISA_3DNOW
>> to OPTION_MASK_ISA_3DNOW | OPTION_MASK_ISA_MMX or from
>> OPTION_MASK_ISA_3DNOW_A to OPTION_MASK_ISA_3DNOW_A | OPTION_MASK_ISA_MMX
>> were useless, we can do what we did before.
>> It is just OPTION_MASK_ISA_SSE or higher with OPTION_MASK_ISA_MMX that
>> is needed.
>> I have no idea why __builtin_ia32_sfence or __builtin_ia32_movntq were
>> changed.
>> Nor I understand why any sse.md changes are needed, then the builtins
>> aren't available, those insns shouldn't be synthetized out of thin air.
>> And the i386.c def_builtin change IMNSHO isn't needed either, it is
>> a compile time speed/memory optimization not to declare everything
>> unconditionally, and the way it works right now is that any of the enabled
>> ISAs enables the builtin, meaning that MMX enabled will mean those
>> 35 will be declared, even when perhaps SSE isn't enabled, or for
>> SSE when MMX isn't enabled, but that isn't that big deal.
>
> Ok, so I went through the patches in detail now.
> The above mostly stands, we don't need | OPTION_MASK_ISA_MMX
> for OPTION_MASK_ISA_3DNOW or OPTION_MASK_ISA_3DNOW_A builtins, except
> those that have OPTION_MASK_ISA_SSE* | OPTION_MASK_ISA_3DNOW_A (because
> while 3dnowa implies mmx and no-mmx implies no-3dnowa, that is not the
> case for sse and we treat it as either sse* or 3dnowa).
>
> I indeed see no reason why __builtin_ia32_sfence should be only available
> if TARGET_MMX, the instruction has no operands and SSE or 3dnowa CPUID.
>
> I went in detail through all my and HJ's *.def changes and
> __builtin_ia32_movntq and __builtin_ia32_palignr were indeed missing
> in my patch, the following updated version adds them and adds testsuite
> coverage for them.  Both of these have "y" constraint only
> operands and thus ICE if -mno-mmx, because we can't reload them
> (missed them because they are using DImode or V1DImode operands).
> I've found also __builtin_ia32_p{add,sub}q that had V1DI operands/results,
> those also ICE, fixed those in the following patch too.
>
> HJ's patch didn't have also __builtin_ia32_{pmuludq,pabs{b,w,d}} which do
> ICE.
>
> As for the sse.md changes, I don't see it as 100% needed, and if we want
> it, it can be done incrementally.  In that case, we shouldn't change just
> the insns/expanders that have just "y" operands/results in sse.md, but
> also in mmx.md (there are many with TARGET_SSE* guards, all those would
> need to be adjusted).
>
> Regarding the other changes in HJ's patch, the 2 testsuite tweaks are
> related to the i386.c def_builtin change which IMHO is not needed.
> So I think the following patch covers everything but the possibly
> incrementally dealt && TARGET_MMX in {sse,mmx}.md.
>
> Ok for trunk?
>
> 2017-10-10  Jakub Jelinek  
> H.J. Lu  
>
> PR target/82483
> * config/i386/i386.c (ix86_init_mmx_sse_builtins): Add
> OPTION_MASK_ISA_MMX for __builtin_ia32_maskmovq,
> __builtin_ia32_vec_ext_v4hi and __builtin_ia32_vec_set_v4hi.
> (ix86_expand_builtin): Treat OPTION_MASK_ISA_MMX similarly
> to OPTION_MASK_ISA_AVX512VL - builtins that have both
> OPTION_MASK_ISA_MMX and some other bit set require both
> mmx and the ISAs without the mmx bit.
> * config/i386/i386-builtin.def (__builtin_ia32_cvtps2pi,
> __builtin_ia32_cvttps2pi, __builtin_ia32_cvtpi2ps,
> __builtin_ia32_pavgb, __builtin_ia32_pavgw, __builtin_ia32_pmulhuw,
> __builtin_ia32_pmaxub, __builtin_ia32_pmaxsw, __builtin_ia32_pminub,
> __builtin_ia32_pminsw, __builtin_ia32_psadbw, __builtin_ia32_pmovmskb,
> __builtin_ia32_pshufw, __builtin_ia32_cvtpd2pi,
> __builtin_ia32_cvttpd2pi, __builtin_ia32_cvtpi2pd,
> __builtin_ia32_pmuludq, __builtin_ia32_pabsb, __builtin_ia32_pabsw,
> __builtin_ia32_pabsd, __builtin_ia32_phaddw, __builtin_ia32_phaddd,
> __builtin_ia32_phaddsw, __builtin_ia32_phsubw, __builtin_ia32_phsubd,
> __builtin_ia32_phsubsw, __builtin_ia32_pmaddubsw,
> __builtin_ia32_pmulhrsw, __builtin_ia32_pshufb, __builtin_ia32_psignb,
> __builtin_ia32_psignw, __builtin_ia32_psignd, __builtin_ia32_movntq,
> __builtin_ia32_paddq, __builtin_ia32_psubq, __builtin_ia32_palignr):
> Add OPTION_MASK_ISA_MMX.
>
> * gcc.target/i386/pr82483-1.c: New 

Re: [PATCH GCC][3/7]Don't skip renaming PHIs in loop nest with only one inner loop

2017-10-10 Thread Bin.Cheng
On Mon, Oct 9, 2017 at 2:33 PM, Richard Biener
 wrote:
> On Thu, Oct 5, 2017 at 3:16 PM, Bin Cheng  wrote:
>> Hi,
>> Function rename_variables_in_bb skips renaming PHI nodes in loop nest if the
>> outer loop has only one inner loop.  This breaks loop nest distribution when
>> inner loop has PHI node initialized from outer loop's variable.  
>> Unfortunately,
>> I lost the original C code illustrating the issue.  Now it is only triggered
>> in building spec2006/416.gamess with loop nest distribution, but I failed to
>> reduce a test from it.
>
> Bah, can you re-try isolating a testcase?
Hi Richard,
Right, I managed a simple test with help of creduce.  Given the
simplicity of the test,
I assume previous approval still holds for this updated patch and will
apply it later.

Thanks,
bin

2017-10-10  Bin Cheng  

* tree-vect-loop-manip.c (rename_variables_in_bb): Rename PHI nodes
when copying loop nest with only one inner loop.

2017-10-10  Bin Cheng  

* gcc.dg/tree-ssa/ldist-34.c: New test.
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ldist-34.c 
b/gcc/testsuite/gcc.dg/tree-ssa/ldist-34.c
new file mode 100644
index 000..3d68a85
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/ldist-34.c
@@ -0,0 +1,15 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -ftree-loop-distribution" } */
+
+#define X (3.0)
+int b, c;
+double a[3];
+int foo () {
+  for (int i = 0; i < 100; ++i) {
+for (int j = 0; j < c; ++j)
+  if (b)
+a[0] = b;
+a[i * 100] = a[1] = X;
+  }
+  return 0;
+}
diff --git a/gcc/tree-vect-loop-manip.c b/gcc/tree-vect-loop-manip.c
index 2c724a2..9fd65a7 100644
--- a/gcc/tree-vect-loop-manip.c
+++ b/gcc/tree-vect-loop-manip.c
@@ -117,8 +117,6 @@ rename_variables_in_bb (basic_block bb, bool 
rename_from_outer_loop)
  || single_pred (e->src) != outer_loop->header)
continue;
}
- else
-   continue;
}
}
   for (gphi_iterator gsi = gsi_start_phis (bb); !gsi_end_p (gsi);


Re: Restore functional DONT_USE_BUILTIN_SETJMP support

2017-10-10 Thread Eric Botcazou
> After verification, you are right: the problem is older but requires the
> compiler to be configured with --enable-checking=yes.

Thanks for confirming.  The problem is present on x86-64/Linux too, I'll have 
a quick look later today.

-- 
Eric Botcazou


[PATCH] PR libstdc++/82417 do not include C99 in strict modes

2017-10-10 Thread Jonathan Wakely

As an extension the C++ version of  includes the C version,
but that defines macros with non-reserved names that should not be
defined in ISO C++. Only include the C header for non-strict modes, or
for pre-C++11 (because C++98 doesn't mention  at all).

PR libstdc++/59087
PR libstdc++/82417
* include/c_compatibility/complex.h [!C++98 && __STRICT_ANSI__]: Do
not include C library's .
* testsuite/26_numerics/complex/c99.cc: Depend on __STRICT_ANSI__.
* testsuite/26_numerics/headers/complex.h/std_c++11.h: New test.
* testsuite/26_numerics/headers/complex.h/std_gnu++11.h: New test.
* testsuite/26_numerics/headers/complex.h/std_c++98.h: New test.

Tested powerpc64le-linux, committed to trunk.

commit fb0385e979610a025d4b42e0b78f54447c799946
Author: redi 
Date:   Tue Oct 10 11:25:45 2017 +

PR libstdc++/82417 do not include C99  in strict modes

As an extension the C++ version of  includes the C version,
but that defines macros with non-reserved names that should not be
defined in ISO C++. Only include the C header for non-strict modes, or
for pre-C++11 (because C++98 doesn't mention  at all).

PR libstdc++/59087
PR libstdc++/82417
* include/c_compatibility/complex.h [!C++98 && __STRICT_ANSI__]: Do
not include C library's .
* testsuite/26_numerics/complex/c99.cc: Depend on __STRICT_ANSI__.
* testsuite/26_numerics/headers/complex.h/std_c++11.h: New test.
* testsuite/26_numerics/headers/complex.h/std_gnu++11.h: New test.
* testsuite/26_numerics/headers/complex.h/std_c++98.h: New test.

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

diff --git a/libstdc++-v3/include/c_compatibility/complex.h 
b/libstdc++-v3/include/c_compatibility/complex.h
index b9af8472562..4b2343926ef 100644
--- a/libstdc++-v3/include/c_compatibility/complex.h
+++ b/libstdc++-v3/include/c_compatibility/complex.h
@@ -32,7 +32,9 @@
 # include 
 #endif
 
-#if _GLIBCXX_HAVE_COMPLEX_H
+#if __cplusplus >= 201103L && defined(__STRICT_ANSI__)
+// For strict modes do not include the C library's , see PR 82417.
+#elif _GLIBCXX_HAVE_COMPLEX_H
 # include_next 
 # ifdef _GLIBCXX_COMPLEX
 // See PR56111, keep the macro in C++03 if possible.
diff --git a/libstdc++-v3/testsuite/26_numerics/complex/c99.cc 
b/libstdc++-v3/testsuite/26_numerics/complex/c99.cc
index 70189627ca2..9b0def408c8 100644
--- a/libstdc++-v3/testsuite/26_numerics/complex/c99.cc
+++ b/libstdc++-v3/testsuite/26_numerics/complex/c99.cc
@@ -26,7 +26,8 @@
 
 int main()
 {
-#if _GLIBCXX_HAVE_COMPLEX_H
+#if _GLIBCXX_HAVE_COMPLEX_H && !defined(__STRICT_ANSI__)
+  // This is a GNU extension.
   double _Complex x = .5;
   double _Complex y = cacos (x);
   (void)y;
diff --git a/libstdc++-v3/testsuite/26_numerics/headers/complex.h/std_c++11.h 
b/libstdc++-v3/testsuite/26_numerics/headers/complex.h/std_c++11.h
new file mode 100644
index 000..22d84b2f14e
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/headers/complex.h/std_c++11.h
@@ -0,0 +1,33 @@
+// 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
+// .
+
+// { dg-options "-std=c++11" }
+
+#include 
+
+// Should be equivalent to #include 
+template class std::complex;
+
+#ifdef complex
+# error "'complex' is defined as a macro by  for -std=c++11"
+#endif
+#ifdef imaginary
+# error "'imaginary' is defined as a macro by  for -std=c++11"
+#endif
+#ifdef I
+# error "'I' is defined as a macro by  for -std=c++11"
+#endif
diff --git a/libstdc++-v3/testsuite/26_numerics/headers/complex.h/std_c++98.h 
b/libstdc++-v3/testsuite/26_numerics/headers/complex.h/std_c++98.h
new file mode 100644
index 000..62674466c3d
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/headers/complex.h/std_c++98.h
@@ -0,0 +1,55 @@
+// 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 

[PATCH] Update comment referring to status of LWG issue 111

2017-10-10 Thread Jonathan Wakely

A small tweak to correct an old comment.

* include/bits/streambuf_iterator.h (istreambuf_iterator::equal):
Update comment about NAD issue.

Committed to trunk.

commit 952424a1d1947d77348754d90fee8f4b65248bd7
Author: Jonathan Wakely 
Date:   Tue Oct 10 12:24:24 2017 +0100

Update comment referring to status of LWG issue 111

* include/bits/streambuf_iterator.h (istreambuf_iterator::equal):
Update comment about NAD issue.

diff --git a/libstdc++-v3/include/bits/streambuf_iterator.h 
b/libstdc++-v3/include/bits/streambuf_iterator.h
index 64b8cfd7895..081afe59d84 100644
--- a/libstdc++-v3/include/bits/streambuf_iterator.h
+++ b/libstdc++-v3/include/bits/streambuf_iterator.h
@@ -165,7 +165,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
   // _GLIBCXX_RESOLVE_LIB_DEFECTS
   // 110 istreambuf_iterator::equal not const
-  // NB: there is also number 111 (NAD, Future) pending on this function.
+  // NB: there is also number 111 (NAD) relevant to this function.
   /// Return true both iterators are end or both are not end.
   bool
   equal(const istreambuf_iterator& __b) const


[PATCH] Fix ICEs with ss{e,e2,se3} builtins with -mno-mmx (PR target/82483, take 2)

2017-10-10 Thread Jakub Jelinek
On Mon, Oct 09, 2017 at 09:47:49PM +0200, Jakub Jelinek wrote:
> > Hm, I remember there was similar patch for PR79565 [1], which seems
> > related. Does your patch also fix all builtins that HJ's patch touch?
> 
> Ah, I wasn't aware of that patch.  Will look in detail tomorrow.
> 
> > [1] https://gcc.gnu.org/ml/gcc-patches/2017-08/msg00751.html
> 
> Just quick analysis, while -mno-mmx doesn't imply -mno-sse (that is
> right), it implies -mno-3dnow and -mno-3dnow implies -mno-3dnowa.
> So all the spots that were changed from OPTION_MASK_ISA_3DNOW
> to OPTION_MASK_ISA_3DNOW | OPTION_MASK_ISA_MMX or from
> OPTION_MASK_ISA_3DNOW_A to OPTION_MASK_ISA_3DNOW_A | OPTION_MASK_ISA_MMX
> were useless, we can do what we did before.
> It is just OPTION_MASK_ISA_SSE or higher with OPTION_MASK_ISA_MMX that
> is needed.
> I have no idea why __builtin_ia32_sfence or __builtin_ia32_movntq were
> changed.
> Nor I understand why any sse.md changes are needed, then the builtins
> aren't available, those insns shouldn't be synthetized out of thin air.
> And the i386.c def_builtin change IMNSHO isn't needed either, it is
> a compile time speed/memory optimization not to declare everything
> unconditionally, and the way it works right now is that any of the enabled
> ISAs enables the builtin, meaning that MMX enabled will mean those
> 35 will be declared, even when perhaps SSE isn't enabled, or for
> SSE when MMX isn't enabled, but that isn't that big deal.

Ok, so I went through the patches in detail now.
The above mostly stands, we don't need | OPTION_MASK_ISA_MMX
for OPTION_MASK_ISA_3DNOW or OPTION_MASK_ISA_3DNOW_A builtins, except
those that have OPTION_MASK_ISA_SSE* | OPTION_MASK_ISA_3DNOW_A (because
while 3dnowa implies mmx and no-mmx implies no-3dnowa, that is not the
case for sse and we treat it as either sse* or 3dnowa).

I indeed see no reason why __builtin_ia32_sfence should be only available
if TARGET_MMX, the instruction has no operands and SSE or 3dnowa CPUID.

I went in detail through all my and HJ's *.def changes and
__builtin_ia32_movntq and __builtin_ia32_palignr were indeed missing
in my patch, the following updated version adds them and adds testsuite
coverage for them.  Both of these have "y" constraint only
operands and thus ICE if -mno-mmx, because we can't reload them
(missed them because they are using DImode or V1DImode operands).
I've found also __builtin_ia32_p{add,sub}q that had V1DI operands/results,
those also ICE, fixed those in the following patch too.

HJ's patch didn't have also __builtin_ia32_{pmuludq,pabs{b,w,d}} which do
ICE.

As for the sse.md changes, I don't see it as 100% needed, and if we want
it, it can be done incrementally.  In that case, we shouldn't change just
the insns/expanders that have just "y" operands/results in sse.md, but
also in mmx.md (there are many with TARGET_SSE* guards, all those would
need to be adjusted).

Regarding the other changes in HJ's patch, the 2 testsuite tweaks are
related to the i386.c def_builtin change which IMHO is not needed.
So I think the following patch covers everything but the possibly
incrementally dealt && TARGET_MMX in {sse,mmx}.md.

Ok for trunk?

2017-10-10  Jakub Jelinek  
H.J. Lu  

PR target/82483
* config/i386/i386.c (ix86_init_mmx_sse_builtins): Add
OPTION_MASK_ISA_MMX for __builtin_ia32_maskmovq,
__builtin_ia32_vec_ext_v4hi and __builtin_ia32_vec_set_v4hi.
(ix86_expand_builtin): Treat OPTION_MASK_ISA_MMX similarly
to OPTION_MASK_ISA_AVX512VL - builtins that have both
OPTION_MASK_ISA_MMX and some other bit set require both
mmx and the ISAs without the mmx bit.
* config/i386/i386-builtin.def (__builtin_ia32_cvtps2pi,
__builtin_ia32_cvttps2pi, __builtin_ia32_cvtpi2ps,
__builtin_ia32_pavgb, __builtin_ia32_pavgw, __builtin_ia32_pmulhuw,
__builtin_ia32_pmaxub, __builtin_ia32_pmaxsw, __builtin_ia32_pminub,
__builtin_ia32_pminsw, __builtin_ia32_psadbw, __builtin_ia32_pmovmskb,
__builtin_ia32_pshufw, __builtin_ia32_cvtpd2pi,
__builtin_ia32_cvttpd2pi, __builtin_ia32_cvtpi2pd,
__builtin_ia32_pmuludq, __builtin_ia32_pabsb, __builtin_ia32_pabsw,
__builtin_ia32_pabsd, __builtin_ia32_phaddw, __builtin_ia32_phaddd,
__builtin_ia32_phaddsw, __builtin_ia32_phsubw, __builtin_ia32_phsubd,
__builtin_ia32_phsubsw, __builtin_ia32_pmaddubsw,
__builtin_ia32_pmulhrsw, __builtin_ia32_pshufb, __builtin_ia32_psignb,
__builtin_ia32_psignw, __builtin_ia32_psignd, __builtin_ia32_movntq,
__builtin_ia32_paddq, __builtin_ia32_psubq, __builtin_ia32_palignr):
Add OPTION_MASK_ISA_MMX.

* gcc.target/i386/pr82483-1.c: New test.
* gcc.target/i386/pr82483-2.c: New test.

--- gcc/config/i386/i386.c.jj   2017-10-10 11:54:08.192707473 +0200
+++ gcc/config/i386/i386.c  2017-10-10 11:56:33.836942065 +0200
@@ -32988,7 +32988,9 @@ 

Re: [PATCH][GCC] Simplification of 1U << (31 - x)

2017-10-10 Thread Sudi Das


Thanks, I have made the changes to the patch.
Also can someone please apply it for me. I do not have commit access.

2017-10-10  Sudakshina Das  

PR middle-end/80131
* match.pd: Simplify 1 << (C - x) where C = precision (x) - 1.

2017-10-10  Sudakshina Das  

PR middle-end/80131
* testsuite/gcc.dg/pr80131-1.c: New Test.


With regards to the existing missed optimizations needed to the x86 RTL 
expansion, I think the discussions can take place on the bug report that I 
created and maybe someone will pick it up.

Thanks
Sudi




From: Wilco Dijkstra
Sent: Monday, October 9, 2017 2:02 PM
To: Richard Biener; Sudi Das
Cc: Jakub Jelinek; GCC Patches; nd; Richard Earnshaw; James Greenhalgh
Subject: Re: [PATCH][GCC] Simplification of 1U << (31 - x)
    
Richard Biener wrote:

> I think the patch is ok with these changes but obviously we should try
> to address
> the code-generation issue on x86 at RTL expansion time.  They are sort-of
> existing missing optimizations.

Note the only x64 specific issue is the backend expansion of 64-bit immediates
which could be improved like I suggested. However what we're really missing
is a generic optimization pass that tries to simplify immediates using accurate
target costs. In eg. x >= C or x > C we can use either C or C-1 - on many 
targets
one option may be a single instruction, while the other might take 2 or even 3.

Wilcodiff --git a/gcc/match.pd b/gcc/match.pd
index e58a65a..7a25a1b 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -600,6 +600,19 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
&& tree_nop_conversion_p (type, TREE_TYPE (@1)))
(lshift @0 @2)))
 
+/* Fold (1 << (C - x)) where C = precision(type) - 1
+   into ((1 << C) >> x). */
+(simplify
+ (lshift integer_onep@0 (minus@1 INTEGER_CST@2 @3))
+  (if (INTEGRAL_TYPE_P (type)
+   && wi::eq_p (@2, TYPE_PRECISION (type) - 1)
+   && single_use (@1))
+   (if (TYPE_UNSIGNED (type))
+ (rshift (lshift @0 @2) @3)
+   (with
+{ tree utype = unsigned_type_for (type); }
+(convert (rshift (lshift (convert:utype @0) @2) @3))
+
 /* Fold (C1/X)*C2 into (C1*C2)/X.  */
 (simplify
  (mult (rdiv@3 REAL_CST@0 @1) REAL_CST@2)
diff --git a/gcc/testsuite/gcc.dg/pr80131-1.c b/gcc/testsuite/gcc.dg/pr80131-1.c
new file mode 100644
index 000..0bfe1f4
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr80131-1.c
@@ -0,0 +1,31 @@
+/* { dg-do compile } */
+/* { dg-require-effective-target int32plus } */
+/* { dg-options "-fdump-tree-gimple" } */
+
+/* Checks the simplification of:
+   1 << (C - x) to (1 << C) >> x, where C = precision (type) - 1
+   f1 is not simplified but f2, f3 and f4 are. */
+
+__INT64_TYPE__ f1 (__INT64_TYPE__ i)
+{
+  return (__INT64_TYPE__)1 << (31 - i);
+}
+
+__INT64_TYPE__ f2 (__INT64_TYPE__ i)
+{
+  return (__INT64_TYPE__)1 << (63 - i);
+}
+
+__UINT64_TYPE__ f3 (__INT64_TYPE__ i)
+{
+  return (__UINT64_TYPE__)1 << (63 - i);
+}
+
+__INT32_TYPE__ f4 (__INT32_TYPE__ i)
+{
+  return (__INT32_TYPE__)1 << (31 - i);
+}
+
+/* { dg-final { scan-tree-dump-times "= 31 -"  1 "gimple" } } */
+/* { dg-final { scan-tree-dump-times "9223372036854775808 >>" 2 "gimple" } } */
+/* { dg-final { scan-tree-dump "2147483648 >>" "gimple" } } */


Re: Restore functional DONT_USE_BUILTIN_SETJMP support

2017-10-10 Thread Dominique d'Humières

> Le 10 oct. 2017 à 11:53, Eric Botcazou  a écrit :
> 
>> This cause
>> 
>> % /opt/gcc/gcc8w/bin/g++ -std=c++11 -O2 -fnon-call-exceptions
>> /opt/gcc/work/gcc/testsuite/g++.dg/pr62079.C -c -m32
>> /opt/gcc/work/gcc/testsuite/g++.dg/pr62079.C: In function 'int main()':
>> /opt/gcc/work/gcc/testsuite/g++.dg/pr62079.C:78:1: error: non-cold basic
>> block 5 reachable only by paths crossing the cold partition }
>> ^
>> during RTL pass: split2
>> /opt/gcc/work/gcc/testsuite/g++.dg/pr62079.C:78:1: internal compiler error:
>> verify_flow_info failed
>> 
>> on x86_64-apple-darwin16.
> 
> Really sure?  The patch is a no-op except for IA-64 and Aarch64.

After verification, you are right: the problem is older but requires the 
compiler to be configured with 
--enable-checking=yes.

Sorry for the noise.

Dominique

> 
> -- 
> Eric Botcazou



[PATCH] Simplify SCEV entry

2017-10-10 Thread Richard Biener

This simplifies SCEV analyze_scalar_evolution_1 by removing what appeared
to be dead code for the case of res != chrec_not_analyzed_yet.  Adding
a gcc_unrechable () turned up a rather serious bug though as in the
loop pipeline we get a messed up SCEV cache if CFG cleanup renumbers 
blocks given SCEV uses BB indices in the cache.  Fixing that makes
bootstrapping with gcc_unreachable in the place of the removed code
below work:

Index: gcc/tree-scalar-evolution.c
===
--- gcc/tree-scalar-evolution.c (revision 253545)
+++ gcc/tree-scalar-evolution.c (working copy)
@@ -2072,8 +2072,11 @@ analyze_scalar_evolution_1 (struct loop
   if (res != chrec_not_analyzed_yet)
 {
   if (loop != bb->loop_father)
+   {
+ gcc_unreachable ();
res = compute_scalar_evolution_in_loop
(find_common_loop (loop, bb->loop_father), bb->loop_father, 
res);
+   }
 
   goto set_and_end;
 }

thus the following (which is really a bugfix plus code simplification).

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

I should probably backport that CFG cleanup hunk...

Richard.

2017-10-10  Richard Biener  

* tree-cfgcleanup.c (cleanup_tree_cfg_noloop): Avoid compacting
blocks if SCEV is active.
* tree-scalar-evolution.c (analyze_scalar_evolution_1): Remove
dead code.
(analyze_scalar_evolution): Handle cached evolutions the obvious way.
(scev_initialize): Assert we are not yet initialized.

Index: gcc/tree-cfgcleanup.c
===
--- gcc/tree-cfgcleanup.c   (revision 253580)
+++ gcc/tree-cfgcleanup.c   (working copy)
@@ -892,7 +892,11 @@ cleanup_tree_cfg_noloop (void)
   changed |= cleanup_tree_cfg_1 ();
 
   gcc_assert (dom_info_available_p (CDI_DOMINATORS));
-  compact_blocks ();
+
+  /* Do not renumber blocks if the SCEV cache is active, it is indexed by
+ basic-block numbers.  */
+  if (! scev_initialized_p ())
+compact_blocks ();
 
   checking_verify_flow_info ();
 
Index: gcc/tree-scalar-evolution.c
===
--- gcc/tree-scalar-evolution.c (revision 253580)
+++ gcc/tree-scalar-evolution.c (working copy)
@@ -281,7 +281,7 @@ along with GCC; see the file COPYING3.
 #include "tree-ssa-propagate.h"
 #include "gimple-fold.h"
 
-static tree analyze_scalar_evolution_1 (struct loop *, tree, tree);
+static tree analyze_scalar_evolution_1 (struct loop *, tree);
 static tree analyze_scalar_evolution_for_address_of (struct loop *loop,
 tree var);
 
@@ -2036,18 +2036,19 @@ compute_scalar_evolution_in_loop (struct
   if (no_evolution_in_loop_p (res, wrto_loop->num, ) && val)
 return res;
 
-  return analyze_scalar_evolution_1 (wrto_loop, res, chrec_not_analyzed_yet);
+  return analyze_scalar_evolution_1 (wrto_loop, res);
 }
 
 /* Helper recursive function.  */
 
 static tree
-analyze_scalar_evolution_1 (struct loop *loop, tree var, tree res)
+analyze_scalar_evolution_1 (struct loop *loop, tree var)
 {
   tree type = TREE_TYPE (var);
   gimple *def;
   basic_block bb;
   struct loop *def_loop;
+  tree res;
 
   if (loop == NULL
   || TREE_CODE (type) == VECTOR_TYPE
@@ -2069,18 +2070,9 @@ analyze_scalar_evolution_1 (struct loop
   goto set_and_end;
 }
 
-  if (res != chrec_not_analyzed_yet)
-{
-  if (loop != bb->loop_father)
-   res = compute_scalar_evolution_in_loop
-   (find_common_loop (loop, bb->loop_father), bb->loop_father, res);
-
-  goto set_and_end;
-}
-
   if (loop != def_loop)
 {
-  res = analyze_scalar_evolution_1 (def_loop, var, chrec_not_analyzed_yet);
+  res = analyze_scalar_evolution_1 (def_loop, var);
   res = compute_scalar_evolution_in_loop (loop, def_loop, res);
 
   goto set_and_end;
@@ -2144,7 +2136,8 @@ analyze_scalar_evolution (struct loop *l
 }
 
   res = get_scalar_evolution (block_before_loop (loop), var);
-  res = analyze_scalar_evolution_1 (loop, var, res);
+  if (res == chrec_not_analyzed_yet)
+res = analyze_scalar_evolution_1 (loop, var);
 
   if (dump_file && (dump_flags & TDF_SCEV))
 fprintf (dump_file, ")\n");
@@ -3264,6 +3257,8 @@ scev_initialize (void)
 {
   struct loop *loop;
 
+  gcc_assert (! scev_initialized_p ());
+
   scalar_evolution_info = hash_table::create_ggc (100);
 
   initialize_scalar_evolutions_analyzer ();


Re: Restore functional DONT_USE_BUILTIN_SETJMP support

2017-10-10 Thread Eric Botcazou
> This cause
> 
> % /opt/gcc/gcc8w/bin/g++ -std=c++11 -O2 -fnon-call-exceptions
> /opt/gcc/work/gcc/testsuite/g++.dg/pr62079.C -c -m32
> /opt/gcc/work/gcc/testsuite/g++.dg/pr62079.C: In function 'int main()':
> /opt/gcc/work/gcc/testsuite/g++.dg/pr62079.C:78:1: error: non-cold basic
> block 5 reachable only by paths crossing the cold partition }
>  ^
> during RTL pass: split2
> /opt/gcc/work/gcc/testsuite/g++.dg/pr62079.C:78:1: internal compiler error:
> verify_flow_info failed
> 
> on x86_64-apple-darwin16.

Really sure?  The patch is a no-op except for IA-64 and Aarch64.

-- 
Eric Botcazou


[PATCH,AIX] Fix issue with PRI*64 on AIX.

2017-10-10 Thread REIX, Tony
Description:
 * This patch enables to build on AIX.

Tests:
 * AIX: Build: SUCCESS
   - build made by means of gmake within GCC 8 trunk.

ChangeLog:
  * go-system.h : Enable to build on AIX.
  (fix issue with PRIx64 and PRIu64)

Cordialement,

Tony Reix

Bull - ATOS
IBM Coop Architect & Technical Leader

Office : +33 (0) 4 76 29 72 67
1 rue de Provence - 38432 Échirolles - France
www.atos.net--- ./gcc/go/go-system.h.ORIGIN	2017-10-06 09:36:56 -0500
+++ ./gcc/go/go-system.h	2017-10-06 15:51:26 -0500
@@ -22,6 +22,12 @@
 
 #include "config.h"
 
+// Define this so that inttypes.h defines the PRI?64 macros even
+// when compiling with a C++ compiler. Define it here so in the
+// event inttypes.h gets pulled in by another header it is already
+// defined.
+#define __STDC_FORMAT_MACROS
+
 // These must be included before the #poison declarations in system.h.
 
 #include 
--- ./gcc/go/ChangeLog.ORIGIN	2017-10-10 10:59:01 -0500
+++ ./gcc/go/ChangeLog	2017-10-10 10:59:16 -0500
@@ -1,3 +1,8 @@
+2017-10-09  Tony Reix  
+
+* go-system.h : Enable to build on AIX.
+(fix issue with PRIx64 and PRIu64)
+
 2017-08-30  Richard Sandiford  
 	Alan Hayward  
 	David Sherwood  


Re: r253554 - in /trunk/gcc: ada/ChangeLog ada/exp_...

2017-10-10 Thread Andreas Schwab
On Okt 09 2017, pmdero...@gcc.gnu.org wrote:

> 2017-10-09  Ed Schonberg  
>
>   * gnat.dg/class_wide4.adb, gnat.dg/class_wide4_pkg.ads,
>   gnat.dg/class_wide4_pkg2.ads: New testcase.

FAIL: gnat.dg/class_wide4.adb (test for excess errors)
Excess errors:
class_wide4.adb:8:32: "Object" not declared in "Class_Wide4_Pkg"
class_wide4.adb:14:04: invalid prefix in selected component "O"
class_wide4.adb:15:04: invalid prefix in selected component "O"
class_wide4.adb:15:05: prefixed call is only allowed for objects of a tagged 
type
class_wide4.adb:18:04: actual for "This" must be a variable
class_wide4.adb:19:04: actual for "This" must be a variable

Andreas.

-- 
Andreas Schwab, SUSE Labs, sch...@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."


Re: Restore functional DONT_USE_BUILTIN_SETJMP support

2017-10-10 Thread Dominique d'Humières
> The attached patch replaces it with an ad-hoc definition of setjmp, …

This cause

% /opt/gcc/gcc8w/bin/g++ -std=c++11 -O2 -fnon-call-exceptions 
/opt/gcc/work/gcc/testsuite/g++.dg/pr62079.C -c -m32
/opt/gcc/work/gcc/testsuite/g++.dg/pr62079.C: In function 'int main()':
/opt/gcc/work/gcc/testsuite/g++.dg/pr62079.C:78:1: error: non-cold basic block 
5 reachable only by paths crossing the cold partition
 }
 ^
during RTL pass: split2
/opt/gcc/work/gcc/testsuite/g++.dg/pr62079.C:78:1: internal compiler error: 
verify_flow_info failed

on x86_64-apple-darwin16.

TIA

Dominique




[committed] Fix return type on stack clash protection hook

2017-10-10 Thread Jeff Law
Pointed out in IRC.   The intent as well as the docs and prototype had
the return type as a bool, but the default implementation used
HOST_WIDE_INT.  Opps.

This fixes the default implementation to match the intent, docs &
prototype.  Bootstrapped and regression tested.  Installing on the trunk
as obvious.

Jeff
commit fdc63db3b0343eaa3cdde6d5c143fbd80a851da6
Author: Jeff Law 
Date:   Mon Oct 9 17:29:58 2017 -0400

* targhooks.c (default_stack_clash_protection_final_dynamic_probe): 
Fix
return type to match prototype and documentation.

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 202dd89b957..30bbeb5ad82 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,8 @@
+2017-10-09  Jeff Law  
+
+   * targhooks.c (default_stack_clash_protection_final_dynamic_probe): Fix
+   return type to match prototype and documentation.
+
 2010-10-09  Segher Boessenkool  
 
* config/rs6000/rs6000.c (processor_costs): Move to ...
diff --git a/gcc/targhooks.c b/gcc/targhooks.c
index d56f53d35d8..8dbf8a14970 100644
--- a/gcc/targhooks.c
+++ b/gcc/targhooks.c
@@ -2235,7 +2235,7 @@ default_excess_precision (enum excess_precision_type 
ATTRIBUTE_UNUSED)
   return FLT_EVAL_METHOD_PROMOTE_TO_FLOAT;
 }
 
-HOST_WIDE_INT
+bool
 default_stack_clash_protection_final_dynamic_probe (rtx residual 
ATTRIBUTE_UNUSED)
 {
   return 0;