Re: [PATCH] Use VAR_P and/or VAR_OR_FUNCTION_DECL_P macros

2016-10-08 Thread Richard Biener
On October 8, 2016 9:11:22 PM GMT+02:00, Jakub Jelinek  wrote:
>Hi!
>
>This patch changes various TREE_CODE (xyz) == VAR_DECL into VAR_P
>(xyz),
>TREE_CODE (xyz) != VAR_DECL into !VAR_P (xyz) and
>TREE_CODE (xyz) == VAR_DECL || TREE_CODE (xyz) == FUNCTION_DECL
>into VAR_OR_FUNCTION_DECL_P (xyz).
>
>Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

OK.

Richard.

>2016-10-08  Jakub Jelinek  
>
>   * tree-ssa.c (target_for_debug_bind, verify_phi_args,
>   ssa_undefined_value_p, maybe_optimize_var): Use VAR_P and/or
>   VAR_OR_FUNCTION_DECL_P macros.
>   * tree-chkp.c (chkp_register_var_initializer, chkp_make_static_bounds,
>   chkp_get_bounds_for_decl_addr, chkp_parse_array_and_component_ref,
>   chkp_find_bounds_1): Likewise.
>   * ipa-polymorphic-call.c (decl_maybe_in_construction_p): Likewise.
>   * hsa-gen.c (get_symbol_for_decl): Likewise.
>   * cgraphunit.c (check_global_declaration, analyze_functions,
>   handle_alias_pairs, thunk_adjust, cgraph_node::expand_thunk):
>   Likewise.
>   * gimple-fold.c (can_refer_decl_in_current_unit_p,
>   canonicalize_constructor_val, gimple_get_virt_method_for_vtable):
>   Likewise.
>   * tree.c (set_decl_section_name, copy_node_stat,
>   need_assembler_name_p, free_lang_data_in_decl, find_decls_types_r,
>   merge_dllimport_decl_attributes, handle_dll_attribute,
>   decl_init_priority_insert, auto_var_in_fn_p, array_at_struct_end_p,
>   verify_type): Likewise.
>   * gimple-ssa-isolate-paths.c (find_implicit_erroneous_behavior,
>   find_explicit_erroneous_behavior): Likewise.
>   * sdbout.c (sdbout_toplevel_data, sdbout_late_global_decl): Likewise.
>   * ipa.c (process_references): Likewise.
>   * tree-chkp-opt.c (chkp_get_check_result): Likewise.
>   * varasm.c (get_block_for_decl, use_blocks_for_decl_p, make_decl_rtl,
>   notice_global_symbol, assemble_variable, mark_decl_referenced,
>   build_constant_desc, output_constant_def_contents, do_assemble_alias,
>   make_decl_one_only, default_section_type_flags,
>   categorize_decl_for_section, default_encode_section_info): Likewise.
>   * trans-mem.c (requires_barrier): Likewise.
>   * gimple-expr.c (mark_addressable): Likewise.
>   * cfgexpand.c (add_scope_conflicts_1, expand_one_var,
>   expand_used_vars_for_block, clear_tree_used, stack_protect_decl_p,
>   expand_debug_expr): Likewise.
>   * tree-dump.c (dequeue_and_dump): Likewise.
>   * ubsan.c (instrument_bool_enum_load): Likewise.
>   * tree-pretty-print.c (print_declaration): Likewise.
>   * simplify-rtx.c (delegitimize_mem_from_attrs): Likewise.
>   * tree-ssa-uninit.c (warn_uninitialized_vars): Likewise.
>   * asan.c (asan_protect_global, instrument_derefs): Likewise.
>   * tree-into-ssa.c (rewrite_stmt, maybe_register_def,
>   pass_build_ssa::execute): Likewise.
>   * var-tracking.c (var_debug_decl, track_expr_p): Likewise.
>   * tree-ssa-loop-ivopts.c (force_expr_to_var_cost, split_address_cost):
>   Likewise.
>   * ipa-split.c (test_nonssa_use, consider_split, mark_nonssa_use):
>   Likewise.
>   * tree-inline.c (insert_debug_decl_map, remap_ssa_name,
>   can_be_nonlocal, remap_decls, copy_debug_stmt,
>   initialize_inlined_parameters, add_local_variables,
>   reset_debug_binding, replace_locals_op): Likewise.
>   * dse.c (can_escape): Likewise.
>   * ipa-devirt.c (compare_virtual_tables, referenced_from_vtable_p):
>   Likewise.
>   * tree-diagnostic.c (default_tree_printer): Likewise.
>   * tree-streamer-in.c (unpack_ts_decl_common_value_fields,
>   unpack_ts_decl_with_vis_value_fields,
>   lto_input_ts_decl_common_tree_pointers): Likewise.
>   * builtins.c (builtin_save_expr, fold_builtin_expect,
>   readonly_data_expr): Likewise.
>   * tree-ssa-structalias.c (new_var_info, get_constraint_for_ssa_var,
>   create_variable_info_for, set_uids_in_ptset, visit_loadstore):
>   Likewise.
>   * gimple-streamer-out.c (output_gimple_stmt): Likewise.
>   * gimplify.c (force_constant_size, gimplify_bind_expr,
>   gimplify_decl_expr, gimplify_var_or_parm_decl,
>   gimplify_compound_lval, gimplify_init_constructor,
>   gimplify_modify_expr, gimplify_asm_expr, gimplify_oacc_declare,
>   gimplify_type_sizes): Likewise.
>   * cgraphbuild.c (record_reference, record_type_list, mark_address,
>   mark_load, mark_store, pass_build_cgraph_edges::execute): Likewise.
>   * tree-ssa-live.c (mark_all_vars_used_1, remove_unused_scope_block_p,
>   remove_unused_locals): Likewise.
>   * tree-ssa-alias.c (ptr_deref_may_alias_decl_p, ptrs_compare_unequal,
>   ref_maybe_used_by_call_p_1, call_may_clobber_ref_p_1): Likewise.
>   * function.c (instantiate_expr, instantiate_decls_1,
>   setjmp_vars_warning, add_local_decl): Likewise.
>   * alias.c (ao_ref_from_mem, 

Re: [PATCH] Fix optimize_range_tests_var_bound (PR tree-optimization/77901)

2016-10-08 Thread Richard Biener
On October 8, 2016 9:09:43 PM GMT+02:00, Jakub Jelinek  wrote:
>Hi!
>
>I forgot to take into account that ranges[i].exp might not be just NULL
>or
>SSA_NAME, but it can be e.g. BIT_AND_EXPR etc. when optimized by
>earlier
>optimize_range_tests* optimizations.  We only care about SSA_NAMEs or
>the
>a < b comparisons that can be ranges[i].exp == NULL if they are in
>GIMPLE_COND.
>
>Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

OK.

Richard.

>2016-10-08  Jakub Jelinek  
>
>   PR tree-optimization/77901
>   * tree-ssa-reassoc.c (optimize_range_tests_var_bound): Only optimize
>   if ranges[i].exp is SSA_NAME when looking for >= and only when
>   ranges[i].exp is NULL or SSA_NAME when looking for the other
>   comparison.
>
>   * gcc.c-torture/compile/pr77901.c: New test.
>
>--- gcc/tree-ssa-reassoc.c.jj  2016-10-07 11:32:51.0 +0200
>+++ gcc/tree-ssa-reassoc.c 2016-10-08 18:01:32.773394195 +0200
>@@ -2846,7 +2846,9 @@ optimize_range_tests_var_bound (enum tre
> 
>   for (i = first; i < length; i++)
> {
>-  if (ranges[i].exp == NULL_TREE || !ranges[i].in_p)
>+  if (ranges[i].exp == NULL_TREE
>+|| TREE_CODE (ranges[i].exp) != SSA_NAME
>+|| !ranges[i].in_p)
>   continue;
> 
>   tree type = TREE_TYPE (ranges[i].exp);
>@@ -2878,6 +2880,8 @@ optimize_range_tests_var_bound (enum tre
>   tree rhs1, rhs2;
>   if (ranges[i].exp)
>   {
>+if (TREE_CODE (ranges[i].exp) != SSA_NAME)
>+  continue;
> stmt = SSA_NAME_DEF_STMT (ranges[i].exp);
> if (!is_gimple_assign (stmt))
>   continue;
>--- gcc/testsuite/gcc.c-torture/compile/pr77901.c.jj   2016-10-08
>18:05:47.590172355 +0200
>+++ gcc/testsuite/gcc.c-torture/compile/pr77901.c  2016-10-08
>18:05:31.0 +0200
>@@ -0,0 +1,10 @@
>+/* PR tree-optimization/77901 */
>+
>+void bar (void);
>+
>+void
>+foo (int *x, long *y)
>+{
>+  if (*y && *x != 10 && *x != 12 && *y >= 0)
>+bar ();
>+}
>
>   Jakub




Re: [PATCH] Make -Wint-in-bool-context warn on suspicious shift ops

2016-10-08 Thread Jason Merrill
On Sat, Oct 8, 2016 at 4:05 PM, Bernd Edlinger
 wrote:
> On 10/08/16 19:40, Jason Merrill wrote:
>> On Fri, Sep 30, 2016 at 1:07 AM, Bernd Edlinger
>>  wrote:
>>> On 09/29/16 22:38, Jason Merrill wrote:
 On Thu, Sep 29, 2016 at 3:58 PM, Bernd Edlinger
  wrote:
> Unfortunately, without that exception there is a false positive:
>
> In file included from ../../gcc-trunk/gcc/ada/gcc-interface/decl.c:30:0:
> ../../gcc-trunk/gcc/ada/gcc-interface/decl.c: In function 'int
> adjust_packed(tree, tree, int)':
> ../../gcc-trunk/gcc/tree.h:1874:22: error: << on signed integer in
> boolean context [-Werror=int-in-bool-context]
>  ? ((unsigned)1) << ((NODE)->type_common.align - 1) : 0)
>~~^~

 Ah, this issue again: the shift isn't in boolean context, it's in
 integer context.  I think we want to be a lot more conservative about
 these warnings in the arms of a COND_EXPR.  In fact, I think the
 entire

 /* Distribute the conversion into the arms of a COND_EXPR.  */

 section is wrong now that we're doing delayed folding.
>>>
>>> Could you take care of this ?
>>
>> Done thus:
>>
>
> Thanks.
>
> But I have one question:
>
> --- a/gcc/cp/cp-gimplify.c
> +++ b/gcc/cp/cp-gimplify.c
> @@ -2253,6 +2253,15 @@ cp_fold (tree x)
> op1 = cp_fold (TREE_OPERAND (x, 1));
> op2 = cp_fold (TREE_OPERAND (x, 2));
>
> +  if (TREE_CODE (TREE_TYPE (x)) == BOOLEAN_TYPE)
> +   {
> + warning_sentinel (warn_int_in_bool_context);
>
>
> Yes, it compiles, but ...
> how can this compile at all?
>
> Doesn't it miss a name of a local?
> like warning_sentinel c (warn_int_in_bool_context);

Oops, yes, thanks.  What I wrote is an expression that creates a
temporary warning_sentinel that is then immediately destroyed.

Jason
commit 5df6967f5f787f8da43b0122a7d01542ea70adad
Author: Jason Merrill 
Date:   Sat Oct 8 17:51:51 2016 -0400

* cp-gimplify.c (cp_fold): Add variable name.

diff --git a/gcc/cp/cp-gimplify.c b/gcc/cp/cp-gimplify.c
index 4879632..b085f3a 100644
--- a/gcc/cp/cp-gimplify.c
+++ b/gcc/cp/cp-gimplify.c
@@ -2255,7 +2255,7 @@ cp_fold (tree x)
 
   if (TREE_CODE (TREE_TYPE (x)) == BOOLEAN_TYPE)
{
- warning_sentinel (warn_int_in_bool_context);
+ warning_sentinel s (warn_int_in_bool_context);
  if (!VOID_TYPE_P (TREE_TYPE (op1)))
op1 = cp_truthvalue_conversion (op1);
  if (!VOID_TYPE_P (TREE_TYPE (op2)))


Re: [PATCH] Extend -Wint-in-bool-context to suspicious enum values (PR 77700)

2016-10-08 Thread Trevor Saunders
On Fri, Oct 07, 2016 at 03:18:07PM +, Bernd Edlinger wrote:
> Hi!
> 
> This extends -Wint-in-bool-context to uses of enum values in boolean
> context, and fixes one place where accidentally an enum value was
> passed to a bool parameter.
> 
> I excluded enum values 0 and 1 because that is used in
> gimple-ssa-strength-reduction.c, where we have enums
> which are passed in bool function arguments:
> 
> enum stride_status
> {
>UNKNOWN_STRIDE = 0,
>KNOWN_STRIDE = 1
> };
> 
> enum phi_adjust_status
> {
>NOT_PHI_ADJUST = 0,
>PHI_ADJUST = 1
> };
> 
> enum count_phis_status
> {
>DONT_COUNT_PHIS = 0,
>COUNT_PHIS = 1
> };
> 
> I would'nt use an enum in that way, but I think it is
> at least not completely wrong to do it like that...

Using enums here seems reasonable see the discussion here
http://gcc.gnu.org/ml/gcc/2016-10/msg6.html however I don't
understand why that code makes the argument type bool instead of the
enum type.  Here's an untested patch to change those functions to take
the enum type.  It might make sense to change naming some, but I think
this is somewhat of an improvement as it is.

Trev

diff --git a/gcc/gimple-ssa-strength-reduction.c 
b/gcc/gimple-ssa-strength-reduction.c
index 7b14b91..f61805c 100644
--- a/gcc/gimple-ssa-strength-reduction.c
+++ b/gcc/gimple-ssa-strength-reduction.c
@@ -2135,7 +2135,7 @@ incr_vec_index (const widest_int &increment)
 static tree
 create_add_on_incoming_edge (slsr_cand_t c, tree basis_name,
 widest_int increment, edge e, location_t loc,
-bool known_stride)
+stride_status known_stride)
 {
   basic_block insert_bb;
   gimple_stmt_iterator gsi;
@@ -2151,7 +2151,7 @@ create_add_on_incoming_edge (slsr_cand_t c, tree 
basis_name,
   basis_type = TREE_TYPE (basis_name);
   lhs = make_temp_ssa_name (basis_type, NULL, "slsr");
 
-  if (known_stride)
+  if (known_stride == KNOWN_STRIDE)
 {
   tree bump_tree;
   enum tree_code code = PLUS_EXPR;
@@ -2218,7 +2218,7 @@ create_add_on_incoming_edge (slsr_cand_t c, tree 
basis_name,
 
 static tree
 create_phi_basis (slsr_cand_t c, gimple *from_phi, tree basis_name,
- location_t loc, bool known_stride)
+ location_t loc, stride_status known_stride)
 {
   int i;
   tree name, phi_arg;
@@ -2451,7 +2451,8 @@ count_candidates (slsr_cand_t c)
candidates with the same increment, also record T_0 for subsequent use.  */
 
 static void
-record_increment (slsr_cand_t c, widest_int increment, bool is_phi_adjust)
+record_increment (slsr_cand_t c, widest_int increment,
+ phi_adjust_status is_phi_adjust)
 {
   bool found = false;
   unsigned i;
@@ -2491,7 +2492,8 @@ record_increment (slsr_cand_t c, widest_int increment, 
bool is_phi_adjust)
 the count to zero.  We're only processing it so it can possibly
 provide an initializer for other candidates.  */
   incr_vec[incr_vec_len].incr = increment;
-  incr_vec[incr_vec_len].count = c->basis || is_phi_adjust ? 1 : 0;
+  incr_vec[incr_vec_len].count
+   = c->basis || (is_phi_adjust == PHI_ADJUST) ? 1 : 0;
   incr_vec[incr_vec_len].cost = COST_INFINITE;
   
   /* Optimistically record the first occurrence of this increment
@@ -2500,7 +2502,7 @@ record_increment (slsr_cand_t c, widest_int increment, 
bool is_phi_adjust)
  Exception:  increments of -1, 0, 1 never need initializers;
 and phi adjustments don't ever provide initializers.  */
   if (c->kind == CAND_ADD
- && !is_phi_adjust
+ && is_phi_adjust == NOT_PHI_ADJUST
  && c->index == increment
  && (increment > 1 || increment < -1)
  && (gimple_assign_rhs_code (c->cand_stmt) == PLUS_EXPR
@@ -2702,7 +2704,7 @@ optimize_cands_for_speed_p (slsr_cand_t c)
 
 static int
 lowest_cost_path (int cost_in, int repl_savings, slsr_cand_t c,
- const widest_int &incr, bool count_phis)
+ const widest_int &incr, count_phis_status count_phis)
 {
   int local_cost, sib_cost, savings = 0;
   widest_int cand_incr = cand_abs_increment (c);
@@ -2714,7 +2716,7 @@ lowest_cost_path (int cost_in, int repl_savings, 
slsr_cand_t c,
   else
 local_cost = cost_in - c->dead_savings;
 
-  if (count_phis
+  if (count_phis == COUNT_PHIS
   && phi_dependent_cand_p (c)
   && !cand_already_replaced (c))
 {
@@ -2749,7 +2751,7 @@ lowest_cost_path (int cost_in, int repl_savings, 
slsr_cand_t c,
 
 static int
 total_savings (int repl_savings, slsr_cand_t c, const widest_int &incr,
-  bool count_phis)
+  count_phis_status count_phis)
 {
   int savings = 0;
   widest_int cand_incr = cand_abs_increment (c);
@@ -2757,7 +2759,7 @@ total_savings (int repl_savings, slsr_cand_t c, const 
widest_int &incr,
   if (incr == cand_incr && !cand_already_replaced (c))
 savings += repl_savings + c->dead_savings;
 
-  if (count_phis
+  if (cou

Re: [rs6000] Fix reload failures in 64-bit mode with no special constant pool

2016-10-08 Thread Segher Boessenkool
Hi!

On Sat, Oct 08, 2016 at 07:53:42PM +0200, Eric Botcazou wrote:
> this fixes reload failures in 64-bit mode with -mcmodel=medium for targets 
> that define ASM_OUTPUT_SPECIAL_POOL_ENTRY_P to 0; that's the case for the 
> VxWorks port we'll submit because of the compatibility with the system 
> linker, 
> which rejects .got sections in object files.
> 
> When reload ends up calling rs6000_emit_move on a register on the LHS and 
> (const (symbol_ref) (const_int)) on the RHS, the function invokes:
> 
> operands[1] = force_const_mem (mode, operands[1]);
> 
> creating (mem (symbol_ref)), which then needs to be legitimized on TARGET_TOC 
> targets.  That's done by the immediately following block:
> 
> if (TARGET_TOC
> && GET_CODE (XEXP (operands[1], 0)) == SYMBOL_REF
> && constant_pool_expr_p (XEXP (operands[1], 0))
> && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (
>   get_pool_constant (XEXP (operands[1], 0)),
>   get_pool_mode (XEXP (operands[1], 0
>   {
> rtx tocref = create_TOC_reference (XEXP (operands[1], 0),
>operands[0]);
> operands[1] = gen_const_mem (mode, tocref);
> set_mem_alias_set (operands[1], get_TOC_alias_set ());
>   }
> 
> on most targets, but is disabled if ASM_OUTPUT_SPECIAL_POOL_ENTRY_P is 0.

Why does this not fail on darwin?  It can reach this code afaics, and
it has ASM_OUTPUT_SPECIAL_POOL_ENTRY_P always 0.

> Now you don't need to have a special pool to call create_TOC_reference, you 
> can call it for regular TOC references as well, as done a few lines above:
> 
>   /* If this is a SYMBOL_REF that refers to a constant pool entry,
>and we have put it in the TOC, we just need to make a TOC-relative
>reference to it.  */
>   if (TARGET_TOC
> && GET_CODE (operands[1]) == SYMBOL_REF
> && use_toc_relative_ref (operands[1], mode))
>   operands[1] = create_TOC_reference (operands[1], operands[0]);
> 
> So the attached patch does it there too.
> 
> Tested on PowerPC64/Linux (LRA) and VxWorks (reload), OK for the mainline?

Not sure yet, will get back to you.  One comment in the meantime...

> --- config/rs6000/rs6000.c(revision 240888)
> +++ config/rs6000/rs6000.c(working copy)
> @@ -10590,10 +10590,7 @@ rs6000_emit_move (rtx dest, rtx source,
>  
> if (TARGET_TOC
> && GET_CODE (XEXP (operands[1], 0)) == SYMBOL_REF
> -   && constant_pool_expr_p (XEXP (operands[1], 0))
> -   && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (
> - get_pool_constant (XEXP (operands[1], 0)),
> - get_pool_mode (XEXP (operands[1], 0
> +   && use_toc_relative_ref (XEXP (operands[1], 0), Pmode))

Use "mode" instead of "Pmode" here?


Segher


Re: [PATCH] 77864 Fix noexcept conditions for map/set default constructors

2016-10-08 Thread François Dumont

On 06/10/2016 23:34, Jonathan Wakely wrote:

On 06/10/16 22:17 +0200, François Dumont wrote:
Another approach is to rely on existing compiler ability to compute 
conditional noexcept when defaulting implementations. This is what I 
have done in this patch.


The new default constructor on _Rb_tree_node_base is not a problem as 
it is not used to build _Rb_tree_node.


Why not?


_Rb_tree_node_base is used in 2 context. As member of _Rb_tree_impl in 
which case we need the new default constructor. And also as base class 
of _Rb_tree_node which is never constructed. Nodes are being allocated 
and then associated value is being constructed through the allocator, 
the node default constructor itself is never invoked.


If you think it is cleaner to create an intermediate type that will 
take care of this initialization through its default constructor I can 
do that.




I'll try to do the same for copy constructor/assignment and move 
constructor/assignment.


We need to make sure we don't change whether any of those operations
are trivial (which shouldn't be a problem for copy/move, because they
are definitely very non-trivial and will stay that way!)

Does this change the default constructors from non-trivial to trivial?
It would be a major compiler bug if making a constructor default was 
making it trivial.




--- a/libstdc++-v3/include/bits/stl_tree.h
+++ b/libstdc++-v3/include/bits/stl_tree.h
@@ -108,6 +108,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
_Base_ptr_M_left;
_Base_ptr_M_right;

+_Rb_tree_node_base() _GLIBCXX_NOEXCEPT
+  : _M_color(_S_red), _M_parent(0), _M_left(this), _M_right(this)
+{ }
+
static _Base_ptr
_S_minimum(_Base_ptr __x) _GLIBCXX_NOEXCEPT
{


Another option would be:

   struct _Head_node : _Rb_tree_node_base {
 _Head_node() {
   _M_color = _S_red;
   _M_parent = _Base_ptr();
   _M_left = _M_right = this;
 }
   };

If you want something like that I would rather do:

_Rb_tree_node_base() = default;
_Rb_tree_node_base(int) _GLIBCXX_NO_EXCEPT
  : _M_color(_S_red), _M_parent(0), _M_left(this), _M_right(this)
{ }

and then:

struct _Head_node : _Rb_tree_node_base {
_Head_node() _GLIBCXX_NO_EXCEPT
: _Rb_tree_node_base(0)
{ }
};

but as I already said the default constructor on _Rb_tree_node_base 
works just fine.





@@ -603,23 +607,33 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{
  _Key_compare_M_key_compare;
  _Rb_tree_node_base _M_header;


 _Head_node _M_header;

That way *only* this node gets the zero-initialization, not all node
bases.

With either solution we can get rid of _M_header() in every
ctor-initializer-list.

I am already preparing another patch, I will add this simplification.




+#if __cplusplus < 201103L
  size_type _M_node_count; // Keeps track of size of tree.
+#else
+  size_type _M_node_count = 0; // Keeps track of size of 
tree.

+#endif

+#if __cplusplus < 201103L
  _Rb_tree_impl()
  : _Node_allocator(), _M_key_compare(), _M_header(),
_M_node_count(0)
-  { _M_initialize(); }
+  { }
+#else
+  _Rb_tree_impl() = default;
+#endif

  _Rb_tree_impl(const _Key_compare& __comp, const 
_Node_allocator& __a)

-  : _Node_allocator(__a), _M_key_compare(__comp), _M_header(),
-_M_node_count(0)
-  { _M_initialize(); }
+  : _Node_allocator(__a), _M_key_compare(__comp), _M_header()
+#if __cplusplus < 201103L
+  , _M_node_count(0)
+#endif


Doing this conditionally seems pointless, why not just set it here
unconditionally
I wasn't sure about this one, just seemed clearner to not do this 0 
initialization again as already done at class definition level. If 
compiler just moved it away then ok, I can remove the check.


François



Re: [PATCH] Make -Wint-in-bool-context warn on suspicious shift ops

2016-10-08 Thread Bernd Edlinger
On 10/08/16 19:40, Jason Merrill wrote:
> On Fri, Sep 30, 2016 at 1:07 AM, Bernd Edlinger
>  wrote:
>> On 09/29/16 22:38, Jason Merrill wrote:
>>> On Thu, Sep 29, 2016 at 3:58 PM, Bernd Edlinger
>>>  wrote:
 Unfortunately, without that exception there is a false positive:

 In file included from ../../gcc-trunk/gcc/ada/gcc-interface/decl.c:30:0:
 ../../gcc-trunk/gcc/ada/gcc-interface/decl.c: In function 'int
 adjust_packed(tree, tree, int)':
 ../../gcc-trunk/gcc/tree.h:1874:22: error: << on signed integer in
 boolean context [-Werror=int-in-bool-context]
  ? ((unsigned)1) << ((NODE)->type_common.align - 1) : 0)
~~^~
>>>
>>> Ah, this issue again: the shift isn't in boolean context, it's in
>>> integer context.  I think we want to be a lot more conservative about
>>> these warnings in the arms of a COND_EXPR.  In fact, I think the
>>> entire
>>>
>>> /* Distribute the conversion into the arms of a COND_EXPR.  */
>>>
>>> section is wrong now that we're doing delayed folding.
>>
>> Could you take care of this ?
>
> Done thus:
>

Thanks.

But I have one question:

--- a/gcc/cp/cp-gimplify.c
+++ b/gcc/cp/cp-gimplify.c
@@ -2253,6 +2253,15 @@ cp_fold (tree x)
op1 = cp_fold (TREE_OPERAND (x, 1));
op2 = cp_fold (TREE_OPERAND (x, 2));

+  if (TREE_CODE (TREE_TYPE (x)) == BOOLEAN_TYPE)
+   {
+ warning_sentinel (warn_int_in_bool_context);


Yes, it compiles, but ...
how can this compile at all?

Doesn't it miss a name of a local?
like warning_sentinel c (warn_int_in_bool_context);

If I disassemble this function I see a constructor of
warning_sentinel directly followed by a destuctor.

And apparently warn_int_in_bool_context is not zero
in the block, thus:

   if (TREE_CODE (TREE_TYPE (x)) == BOOLEAN_TYPE)
{
  warning_sentinel (warn_int_in_bool_context);
  gcc_assert (!warn_int_in_bool_context);
  if (!VOID_TYPE_P (TREE_TYPE (op1)))
op1 = cp_truthvalue_conversion (op1);


fails the assertion.


Bernd.


Re: [RFC][VRP] Improve intersect_ranges

2016-10-08 Thread kugan

Hi Richard,

Thanks for the review.
On 07/10/16 20:11, Richard Biener wrote:

On Fri, Oct 7, 2016 at 12:00 AM, kugan
 wrote:

Hi,

In vrp intersect_ranges, Richard recently changed it to create integer value
ranges when it is integer singleton.

Maybe we should do the same when the other range is a complex ranges with
SSA_NAME (like [x+2, +INF])?

Attached patch tries to do this. There are cases where it will be beneficial
as the  testcase in the patch. (For this testcase to work with Early VRP, we
need the patch posted at
https://gcc.gnu.org/ml/gcc-patches/2016-10/msg00413.html)

Bootstrapped and regression tested on x86_64-linux-gnu with no new
regressions.


This is not clearly a win, in fact it can completely lose an ASSERT_EXPR
because there is no way to add its effect back as an equivalence.  The
current choice of always using the "left" keeps the ASSERT_EXPR range
and is able to record the other range via an equivalence.


How about changing the order in Early VRP when we are dealing with the 
same SSA_NAME in inner and outer scope. Here is a patch that does this. 
Is this OK if no new regressions?


Thanks,
Kugan





My thought on this was that we need to separate "ranges" and associated
SSA names so we can introduce new ranges w/o the need for an SSA name
(and thus we can create an equivalence to the ASSERT_EXPR range).
IIRC I started on this at some point but never finished it ...

Richard.


Thanks,
Kugan


gcc/testsuite/ChangeLog:

2016-10-07  Kugan Vivekanandarajah  

* gcc.dg/tree-ssa/evrp6.c: New test.

gcc/ChangeLog:

2016-10-07  Kugan Vivekanandarajah  

* tree-vrp.c (intersect_ranges): If we failed to handle
the intersection and the other range involves computation with
symbolic values, choose integer range if available.



>From 54e92b7ddc47f6986e4dc79402d6808bb9c30c69 Mon Sep 17 00:00:00 2001
From: Kugan Vivekanandarajah 
Date: Sat, 8 Oct 2016 15:09:09 +1100
Subject: [PATCH 4/7] Revese value range before calling interset_range

---
 gcc/testsuite/gcc.dg/tree-ssa/evrp6.c | 22 ++
 gcc/tree-vrp.c| 16 +++-
 2 files changed, 37 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/evrp6.c

diff --git a/gcc/testsuite/gcc.dg/tree-ssa/evrp6.c b/gcc/testsuite/gcc.dg/tree-ssa/evrp6.c
new file mode 100644
index 000..35d4d74
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/evrp6.c
@@ -0,0 +1,22 @@
+
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-evrp" } */
+
+extern void abort (void);
+
+int
+foo (int k, int j)
+{
+  if (j >= 10)
+{
+  if (j < k)
+	{
+	  k++;
+	  if (k < 10)
+	abort ();
+	}
+}
+
+  return j;
+}
+/* { dg-final { scan-tree-dump "\\\[12, \\+INF" "evrp" } } */
diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c
index 160adb5..c18c86f 100644
--- a/gcc/tree-vrp.c
+++ b/gcc/tree-vrp.c
@@ -10664,7 +10664,21 @@ evrp_dom_walker::try_add_new_range (tree op, tree_code code, tree limit)
   extract_range_for_var_from_comparison_expr (op, code, op,
 	  limit, &vr);
   if (old_vr->type == VR_RANGE || old_vr->type == VR_ANTI_RANGE)
-vrp_intersect_ranges (&vr, old_vr);
+{
+  if (range_int_cst_p (old_vr)
+	  && !range_int_cst_p (&vr))
+	{
+	  /* intersect_range will use the left value range to keeps the
+	 ASSERT_EXPR range and record the other range via an equivalence.
+	 In this case, we are tracking value_ranges for same SSA_NAME in
+	 different scope, so reverse it for better result. */
+	  value_range other_vr = vr;
+	  vr = *old_vr;
+	  vrp_intersect_ranges (&vr, &other_vr);
+	}
+  else
+	vrp_intersect_ranges (&vr, old_vr);
+}
   /* If we found any usable VR, set the VR to ssa_name and create a
  PUSH old value in the stack with the old VR.  */
   if (vr.type == VR_RANGE || vr.type == VR_ANTI_RANGE)
-- 
2.7.4



[VRP] Allocate bitmap before copying

2016-10-08 Thread kugan

Hi,

In vrp_intersect_ranges_1, when !vr0->equiv, we are copying vr1->equiv 
without allocating bitmap. This patch fixes this.


Bootstrap and regression testing are ongoing. Is this OK if no new 
regressions?


Thanks,
Kugan

gcc/ChangeLog:

2016-10-09  Kugan Vivekanandarajah  

* tree-vrp.c (vrp_intersect_ranges_1): Allocate bitmap before
  copying.
>From ccd2fcb909f54f85858f18652abc3a387321f9a1 Mon Sep 17 00:00:00 2001
From: Kugan Vivekanandarajah 
Date: Sat, 8 Oct 2016 20:23:28 +1100
Subject: [PATCH 2/7] Alloc bitmap

---
 gcc/tree-vrp.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c
index 46bbd82..e758ae4 100644
--- a/gcc/tree-vrp.c
+++ b/gcc/tree-vrp.c
@@ -8622,7 +8622,10 @@ vrp_intersect_ranges_1 (value_range *vr0, value_range *vr1)
   if (vr0->equiv && vr1->equiv && vr0->equiv != vr1->equiv)
 bitmap_ior_into (vr0->equiv, vr1->equiv);
   else if (vr1->equiv && !vr0->equiv)
-bitmap_copy (vr0->equiv, vr1->equiv);
+{
+  vr0->equiv = BITMAP_ALLOC (&vrp_equiv_obstack);
+  bitmap_copy (vr0->equiv, vr1->equiv);
+}
 }
 
 void
-- 
2.7.4



[PATCH] Use VAR_P and/or VAR_OR_FUNCTION_DECL_P macros

2016-10-08 Thread Jakub Jelinek
Hi!

This patch changes various TREE_CODE (xyz) == VAR_DECL into VAR_P (xyz),
TREE_CODE (xyz) != VAR_DECL into !VAR_P (xyz) and
TREE_CODE (xyz) == VAR_DECL || TREE_CODE (xyz) == FUNCTION_DECL
into VAR_OR_FUNCTION_DECL_P (xyz).

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

2016-10-08  Jakub Jelinek  

* tree-ssa.c (target_for_debug_bind, verify_phi_args,
ssa_undefined_value_p, maybe_optimize_var): Use VAR_P and/or
VAR_OR_FUNCTION_DECL_P macros.
* tree-chkp.c (chkp_register_var_initializer, chkp_make_static_bounds,
chkp_get_bounds_for_decl_addr, chkp_parse_array_and_component_ref,
chkp_find_bounds_1): Likewise.
* ipa-polymorphic-call.c (decl_maybe_in_construction_p): Likewise.
* hsa-gen.c (get_symbol_for_decl): Likewise.
* cgraphunit.c (check_global_declaration, analyze_functions,
handle_alias_pairs, thunk_adjust, cgraph_node::expand_thunk):
Likewise.
* gimple-fold.c (can_refer_decl_in_current_unit_p,
canonicalize_constructor_val, gimple_get_virt_method_for_vtable):
Likewise.
* tree.c (set_decl_section_name, copy_node_stat,
need_assembler_name_p, free_lang_data_in_decl, find_decls_types_r,
merge_dllimport_decl_attributes, handle_dll_attribute,
decl_init_priority_insert, auto_var_in_fn_p, array_at_struct_end_p,
verify_type): Likewise.
* gimple-ssa-isolate-paths.c (find_implicit_erroneous_behavior,
find_explicit_erroneous_behavior): Likewise.
* sdbout.c (sdbout_toplevel_data, sdbout_late_global_decl): Likewise.
* ipa.c (process_references): Likewise.
* tree-chkp-opt.c (chkp_get_check_result): Likewise.
* varasm.c (get_block_for_decl, use_blocks_for_decl_p, make_decl_rtl,
notice_global_symbol, assemble_variable, mark_decl_referenced,
build_constant_desc, output_constant_def_contents, do_assemble_alias,
make_decl_one_only, default_section_type_flags,
categorize_decl_for_section, default_encode_section_info): Likewise.
* trans-mem.c (requires_barrier): Likewise.
* gimple-expr.c (mark_addressable): Likewise.
* cfgexpand.c (add_scope_conflicts_1, expand_one_var,
expand_used_vars_for_block, clear_tree_used, stack_protect_decl_p,
expand_debug_expr): Likewise.
* tree-dump.c (dequeue_and_dump): Likewise.
* ubsan.c (instrument_bool_enum_load): Likewise.
* tree-pretty-print.c (print_declaration): Likewise.
* simplify-rtx.c (delegitimize_mem_from_attrs): Likewise.
* tree-ssa-uninit.c (warn_uninitialized_vars): Likewise.
* asan.c (asan_protect_global, instrument_derefs): Likewise.
* tree-into-ssa.c (rewrite_stmt, maybe_register_def,
pass_build_ssa::execute): Likewise.
* var-tracking.c (var_debug_decl, track_expr_p): Likewise.
* tree-ssa-loop-ivopts.c (force_expr_to_var_cost, split_address_cost):
Likewise.
* ipa-split.c (test_nonssa_use, consider_split, mark_nonssa_use):
Likewise.
* tree-inline.c (insert_debug_decl_map, remap_ssa_name,
can_be_nonlocal, remap_decls, copy_debug_stmt,
initialize_inlined_parameters, add_local_variables,
reset_debug_binding, replace_locals_op): Likewise.
* dse.c (can_escape): Likewise.
* ipa-devirt.c (compare_virtual_tables, referenced_from_vtable_p):
Likewise.
* tree-diagnostic.c (default_tree_printer): Likewise.
* tree-streamer-in.c (unpack_ts_decl_common_value_fields,
unpack_ts_decl_with_vis_value_fields,
lto_input_ts_decl_common_tree_pointers): Likewise.
* builtins.c (builtin_save_expr, fold_builtin_expect,
readonly_data_expr): Likewise.
* tree-ssa-structalias.c (new_var_info, get_constraint_for_ssa_var,
create_variable_info_for, set_uids_in_ptset, visit_loadstore):
Likewise.
* gimple-streamer-out.c (output_gimple_stmt): Likewise.
* gimplify.c (force_constant_size, gimplify_bind_expr,
gimplify_decl_expr, gimplify_var_or_parm_decl,
gimplify_compound_lval, gimplify_init_constructor,
gimplify_modify_expr, gimplify_asm_expr, gimplify_oacc_declare,
gimplify_type_sizes): Likewise.
* cgraphbuild.c (record_reference, record_type_list, mark_address,
mark_load, mark_store, pass_build_cgraph_edges::execute): Likewise.
* tree-ssa-live.c (mark_all_vars_used_1, remove_unused_scope_block_p,
remove_unused_locals): Likewise.
* tree-ssa-alias.c (ptr_deref_may_alias_decl_p, ptrs_compare_unequal,
ref_maybe_used_by_call_p_1, call_may_clobber_ref_p_1): Likewise.
* function.c (instantiate_expr, instantiate_decls_1,
setjmp_vars_warning, add_local_decl): Likewise.
* alias.c (ao_ref_from_mem, get_alias_set, compare_base_symbol_refs):
Likewise.
* tree-stdarg.c (find

[PATCH] Fix optimize_range_tests_var_bound (PR tree-optimization/77901)

2016-10-08 Thread Jakub Jelinek
Hi!

I forgot to take into account that ranges[i].exp might not be just NULL or
SSA_NAME, but it can be e.g. BIT_AND_EXPR etc. when optimized by earlier
optimize_range_tests* optimizations.  We only care about SSA_NAMEs or the
a < b comparisons that can be ranges[i].exp == NULL if they are in
GIMPLE_COND.

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

2016-10-08  Jakub Jelinek  

PR tree-optimization/77901
* tree-ssa-reassoc.c (optimize_range_tests_var_bound): Only optimize
if ranges[i].exp is SSA_NAME when looking for >= and only when
ranges[i].exp is NULL or SSA_NAME when looking for the other
comparison.

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

--- gcc/tree-ssa-reassoc.c.jj   2016-10-07 11:32:51.0 +0200
+++ gcc/tree-ssa-reassoc.c  2016-10-08 18:01:32.773394195 +0200
@@ -2846,7 +2846,9 @@ optimize_range_tests_var_bound (enum tre
 
   for (i = first; i < length; i++)
 {
-  if (ranges[i].exp == NULL_TREE || !ranges[i].in_p)
+  if (ranges[i].exp == NULL_TREE
+ || TREE_CODE (ranges[i].exp) != SSA_NAME
+ || !ranges[i].in_p)
continue;
 
   tree type = TREE_TYPE (ranges[i].exp);
@@ -2878,6 +2880,8 @@ optimize_range_tests_var_bound (enum tre
   tree rhs1, rhs2;
   if (ranges[i].exp)
{
+ if (TREE_CODE (ranges[i].exp) != SSA_NAME)
+   continue;
  stmt = SSA_NAME_DEF_STMT (ranges[i].exp);
  if (!is_gimple_assign (stmt))
continue;
--- gcc/testsuite/gcc.c-torture/compile/pr77901.c.jj2016-10-08 
18:05:47.590172355 +0200
+++ gcc/testsuite/gcc.c-torture/compile/pr77901.c   2016-10-08 
18:05:31.0 +0200
@@ -0,0 +1,10 @@
+/* PR tree-optimization/77901 */
+
+void bar (void);
+
+void
+foo (int *x, long *y)
+{
+  if (*y && *x != 10 && *x != 12 && *y >= 0)
+bar ();
+}

Jakub


[patch] Fix GC issue triggered by arithmetic overflow checking

2016-10-08 Thread Eric Botcazou
Hi,

adding patterns for unsigned arithmetic overflow checking in a back-end can 
have unexpected fallout because of a latent GC issue: when they are present, 
GIMPLE optimization passes can create complex (math. sense) types at will by 
invoking build_complex_type.  Now build_complex_type goes through the type 
caonicalization hashtable, which is GC-ed, so its behavior depends on the 
actual collection points.

The other type-building functions present in tree.c do the same so no big deal 
but build_complex_type is special because it also does:

  /* We need to create a name, since complex is a fundamental type.  */
  if (! TYPE_NAME (t))
{
  const char *name;
  if (component_type == char_type_node)
name = "complex char";
  else if (component_type == signed_char_type_node)
name = "complex signed char";
  else if (component_type == unsigned_char_type_node)
name = "complex unsigned char";
  else if (component_type == short_integer_type_node)
name = "complex short int";
  else if (component_type == short_unsigned_type_node)
name = "complex short unsigned int";
  else if (component_type == integer_type_node)
name = "complex int";
  else if (component_type == unsigned_type_node)
name = "complex unsigned int";
  else if (component_type == long_integer_type_node)
name = "complex long int";
  else if (component_type == long_unsigned_type_node)
name = "complex long unsigned int";
  else if (component_type == long_long_integer_type_node)
name = "complex long long int";
  else if (component_type == long_long_unsigned_type_node)
name = "complex long long unsigned int";
  else
name = 0;

  if (name != 0)
TYPE_NAME (t) = build_decl (UNKNOWN_LOCATION, TYPE_DECL,
get_identifier (name), t);
}

so it creates a DECL node every time a new canonical complex type is created, 
bumping the DECL_UID counter in the process.  Which means that the DECL_UID 
counter is sensitive to the collection points, which in turn means that the 
result of algorithms depending on the DECL_UID counter also is.

This for example resulted in a bootstrap comparison failure on a SPARC/Solaris 
machine doing a strict stage2/stage3 comparison because the contents of the 
.debug_loc section were different: location lists computed by var-tracking 
were slightly different because of a different hashing.

I'm not sure whether the hashing done by var-tracking should be sensitive to 
the DECL_UID of nodes or not, but I think that having the DECL_UID counter 
depend on the collection points is highly undesirable, so the attached patch 
attempts to prevent it; it at least fixed the bootstrap comparison failure.

Tested on x86_64-suse-linux, OK for the mainline?


2016-10-08  Eric Botcazou  

* tree.h (build_complex_type): Add second parameter with default.
* builtins.c (expand_builtin_cexpi): Pass false in call to above.
(fold_builtin_sincos): Likewise.
(fold_builtin_arith_overflow): Likewise.
* gimple-fold.c (fold_builtin_atomic_compare_exchange): Likewise.
(gimple_fold_call): Likewise.
* stor-layout.c (bitwise_type_for_mode): Likewise.
* tree-ssa-dce.c (maybe_optimize_arith_overflow): Likewise.
* tree-ssa-math-opts.c (match_uaddsub_overflow): Likewise.
* tree.c (build_complex): Likewise.
(build_complex_type): Add NAMED second parameter and adjust recursive
call.  Create a TYPE_DECL only if NAMED is true.

-- 
Eric BotcazouIndex: builtins.c
===
--- builtins.c	(revision 240888)
+++ builtins.c	(working copy)
@@ -2356,7 +2356,7 @@ expand_builtin_cexpi (tree exp, rtx targ
   else
 {
   tree call, fn = NULL_TREE, narg;
-  tree ctype = build_complex_type (type);
+  tree ctype = build_complex_type (type, false);
 
   if (DECL_FUNCTION_CODE (fndecl) == BUILT_IN_CEXPIF)
 	fn = builtin_decl_explicit (BUILT_IN_CEXPF);
@@ -2396,7 +2396,7 @@ expand_builtin_cexpi (tree exp, rtx targ
 }
 
   /* Now build the proper return type.  */
-  return expand_expr (build2 (COMPLEX_EXPR, build_complex_type (type),
+  return expand_expr (build2 (COMPLEX_EXPR, build_complex_type (type, false),
 			  make_tree (TREE_TYPE (arg), op2),
 			  make_tree (TREE_TYPE (arg), op1)),
 		  target, VOIDmode, EXPAND_NORMAL);
@@ -7226,7 +7226,7 @@ fold_builtin_sincos (location_t loc,
   /* Canonicalize sincos to cexpi.  */
   if (TREE_CODE (arg0) == REAL_CST)
 {
-  tree complex_type = build_complex_type (type);
+  tree complex_type = build_complex_type (type, false);
   call = fold_const_call (as_combined_fn (fn), complex_type, arg0);
 }
   if (!call)
@@ -8137,7 +8137,7 @@ fold_builtin_arith_overflow (location_t
  ? boolean_true_node : boolean_false_node,
  arg2);
 
-  tree ctype = b

[rs6000] Fix reload failures in 64-bit mode with no special constant pool

2016-10-08 Thread Eric Botcazou
Hi,

this fixes reload failures in 64-bit mode with -mcmodel=medium for targets 
that define ASM_OUTPUT_SPECIAL_POOL_ENTRY_P to 0; that's the case for the 
VxWorks port we'll submit because of the compatibility with the system linker, 
which rejects .got sections in object files.

When reload ends up calling rs6000_emit_move on a register on the LHS and 
(const (symbol_ref) (const_int)) on the RHS, the function invokes:

  operands[1] = force_const_mem (mode, operands[1]);

creating (mem (symbol_ref)), which then needs to be legitimized on TARGET_TOC 
targets.  That's done by the immediately following block:

  if (TARGET_TOC
  && GET_CODE (XEXP (operands[1], 0)) == SYMBOL_REF
  && constant_pool_expr_p (XEXP (operands[1], 0))
  && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (
get_pool_constant (XEXP (operands[1], 0)),
get_pool_mode (XEXP (operands[1], 0
{
  rtx tocref = create_TOC_reference (XEXP (operands[1], 0),
 operands[0]);
  operands[1] = gen_const_mem (mode, tocref);
  set_mem_alias_set (operands[1], get_TOC_alias_set ());
}

on most targets, but is disabled if ASM_OUTPUT_SPECIAL_POOL_ENTRY_P is 0.

Now you don't need to have a special pool to call create_TOC_reference, you 
can call it for regular TOC references as well, as done a few lines above:

  /* If this is a SYMBOL_REF that refers to a constant pool entry,
 and we have put it in the TOC, we just need to make a TOC-relative
 reference to it.  */
  if (TARGET_TOC
  && GET_CODE (operands[1]) == SYMBOL_REF
  && use_toc_relative_ref (operands[1], mode))
operands[1] = create_TOC_reference (operands[1], operands[0]);

So the attached patch does it there too.

Tested on PowerPC64/Linux (LRA) and VxWorks (reload), OK for the mainline?


2016-10-08  Eric Botcazou  

* config/rs6000/rs6000.c (rs6000_emit_move): Also use a TOC reference
after forcing to constant memory when the code model is medium.

-- 
Eric BotcazouIndex: config/rs6000/rs6000.c
===
--- config/rs6000/rs6000.c	(revision 240888)
+++ config/rs6000/rs6000.c	(working copy)
@@ -10590,10 +10590,7 @@ rs6000_emit_move (rtx dest, rtx source,
 
 	  if (TARGET_TOC
 	  && GET_CODE (XEXP (operands[1], 0)) == SYMBOL_REF
-	  && constant_pool_expr_p (XEXP (operands[1], 0))
-	  && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (
-			get_pool_constant (XEXP (operands[1], 0)),
-			get_pool_mode (XEXP (operands[1], 0
+	  && use_toc_relative_ref (XEXP (operands[1], 0), Pmode))
 	{
 	  rtx tocref = create_TOC_reference (XEXP (operands[1], 0),
 		 operands[0]);


Re: [PATCH] Make -Wint-in-bool-context warn on suspicious shift ops

2016-10-08 Thread Jason Merrill
On Fri, Sep 30, 2016 at 1:07 AM, Bernd Edlinger
 wrote:
> On 09/29/16 22:38, Jason Merrill wrote:
>> On Thu, Sep 29, 2016 at 3:58 PM, Bernd Edlinger
>>  wrote:
>>> Unfortunately, without that exception there is a false positive:
>>>
>>> In file included from ../../gcc-trunk/gcc/ada/gcc-interface/decl.c:30:0:
>>> ../../gcc-trunk/gcc/ada/gcc-interface/decl.c: In function 'int
>>> adjust_packed(tree, tree, int)':
>>> ../../gcc-trunk/gcc/tree.h:1874:22: error: << on signed integer in
>>> boolean context [-Werror=int-in-bool-context]
>>> ? ((unsigned)1) << ((NODE)->type_common.align - 1) : 0)
>>>   ~~^~
>>
>> Ah, this issue again: the shift isn't in boolean context, it's in
>> integer context.  I think we want to be a lot more conservative about
>> these warnings in the arms of a COND_EXPR.  In fact, I think the
>> entire
>>
>>/* Distribute the conversion into the arms of a COND_EXPR.  */
>>
>> section is wrong now that we're doing delayed folding.
>
> Could you take care of this ?

Done thus:
commit 0a124bbb6f0598345c98e3a91f8c69548518d4c3
Author: Jason Merrill 
Date:   Fri Sep 30 17:52:21 2016 -0400

Delay folding of bool conversion into COND_EXPR.

gcc/c-family/
* c-common.c (c_common_truthvalue_conversion): Don't distribute
into COND_EXPR in C++.
gcc/cp/
* cp-gimplify.c (cp_fold): Distribute cp_truthvalue_conversion
into COND_EXPR.

diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c
index f7a5d62..dbdb276 100644
--- a/gcc/c-family/c-common.c
+++ b/gcc/c-family/c-common.c
@@ -4694,21 +4694,8 @@ c_common_truthvalue_conversion (location_t location, 
tree expr)
}
   /* Distribute the conversion into the arms of a COND_EXPR.  */
   if (c_dialect_cxx ())
-   {
- tree op1 = TREE_OPERAND (expr, 1);
- tree op2 = TREE_OPERAND (expr, 2);
- int w = warn_int_in_bool_context;
- warn_int_in_bool_context = 0;
- /* In C++ one of the arms might have void type if it is throw.  */
- if (!VOID_TYPE_P (TREE_TYPE (op1)))
-   op1 = c_common_truthvalue_conversion (location, op1);
- if (!VOID_TYPE_P (TREE_TYPE (op2)))
-   op2 = c_common_truthvalue_conversion (location, op2);
- expr = fold_build3_loc (location, COND_EXPR, truthvalue_type_node,
- TREE_OPERAND (expr, 0), op1, op2);
- warn_int_in_bool_context = w;
- goto ret;
-   }
+   /* Avoid premature folding.  */
+   break;
   else
{
  int w = warn_int_in_bool_context;
diff --git a/gcc/cp/cp-gimplify.c b/gcc/cp/cp-gimplify.c
index 5aca8f2..4879632 100644
--- a/gcc/cp/cp-gimplify.c
+++ b/gcc/cp/cp-gimplify.c
@@ -2253,6 +2253,15 @@ cp_fold (tree x)
   op1 = cp_fold (TREE_OPERAND (x, 1));
   op2 = cp_fold (TREE_OPERAND (x, 2));
 
+  if (TREE_CODE (TREE_TYPE (x)) == BOOLEAN_TYPE)
+   {
+ warning_sentinel (warn_int_in_bool_context);
+ if (!VOID_TYPE_P (TREE_TYPE (op1)))
+   op1 = cp_truthvalue_conversion (op1);
+ if (!VOID_TYPE_P (TREE_TYPE (op2)))
+   op2 = cp_truthvalue_conversion (op2);
+   }
+
   if (op0 != TREE_OPERAND (x, 0)
  || op1 != TREE_OPERAND (x, 1)
  || op2 != TREE_OPERAND (x, 2))


Re: [PATCH] Implement new hook for max_align_t_align

2016-10-08 Thread John David Anglin
On 2016-10-08, at 1:01 PM, Bernd Edlinger wrote:

> I think your callback should also directly control the
> alignment of max_align_t in stddef.h:
> 
> typedef struct {
>   long long __max_align_ll __attribute__((__aligned__(__alignof__(long 
> long;
>   long double __max_align_ld 
> __attribute__((__aligned__(__alignof__(long double;
>   /* _Float128 is defined as a basic type, so max_align_t must be
>  sufficiently aligned for it.  This code must work in C++, so we
>  use __float128 here; that is only available on some
>  architectures, but only on i386 is extra alignment needed for
>  __float128.  */
> #ifdef __i386__
>   __float128 __max_align_f128 
> __attribute__((__aligned__(__alignof(__float128;
> #endif
> } max_align_t;
> 
> 
> otherwise these will not match.

Yes, i missed a hunk in the submission.  On hpux, the alignment is determined 
by the long
double field.  With glibc, we need 16 byte alignment for max_align_t.

Dave
--
John David Anglin   dave.ang...@bell.net


2016-10-08  John David Anglin  

gcc/c-family/
* c-common.c (max_align_t_align): Move to targhooks.c.
* c-common.h (max_align_t_align): Delete.
gcc/
* target.def (max_align_t_align): New target hook.
* targhooks.c (default_max_align_t_align): New.
* targhooks.h (default_max_align_t_align): Declare.
* config/pa/pa.h (BIGGEST_ALIGNMENT): Adjust comment.
(MALLOC_ABI_ALIGNMENT): Define.
* config/pa/pa.c (pa_max_align_t_align): New.
(TARGET_MAX_ALIGN_T_ALIGN): Define.
* ginclude/stddef.h (max_align_t): Align to 16 bytes on non-hpux hppa.
* doc/tm.texi.in (TARGET_MAX_ALIGN_T_ALIGN): Add documentation hook.
* doc/tm.texi: Update.
gcc/cp/
* decl.c (cxx_init_decl_processing): Use max_align_t_align target hook.
* init.c (build_new_1): Likewise.

Index: c-family/c-common.c
===
--- c-family/c-common.c (revision 240688)
+++ c-family/c-common.c (working copy)
@@ -12899,22 +12899,6 @@
   return stv_nothing;
 }
 
-/* Return the alignment of std::max_align_t.
-
-   [support.types.layout] The type max_align_t is a POD type whose alignment
-   requirement is at least as great as that of every scalar type, and whose
-   alignment requirement is supported in every context.  */
-
-unsigned
-max_align_t_align ()
-{
-  unsigned int max_align = MAX (TYPE_ALIGN (long_long_integer_type_node),
-   TYPE_ALIGN (long_double_type_node));
-  if (float128_type_node != NULL_TREE)
-max_align = MAX (max_align, TYPE_ALIGN (float128_type_node));
-  return max_align;
-}
-
 /* Return true iff ALIGN is an integral constant that is a fundamental
alignment, as defined by [basic.align] in the c++-11
specifications.
@@ -12928,7 +12912,7 @@
 bool
 cxx_fundamental_alignment_p (unsigned align)
 {
-  return (align <= max_align_t_align ());
+  return (align <= targetm.max_align_t_align ());
 }
 
 /* Return true if T is a pointer to a zero-sized aggregate.  */
Index: c-family/c-common.h
===
--- c-family/c-common.h (revision 240688)
+++ c-family/c-common.h (working copy)
@@ -864,7 +864,6 @@
 extern bool keyword_is_storage_class_specifier (enum rid);
 extern bool keyword_is_type_qualifier (enum rid);
 extern bool keyword_is_decl_specifier (enum rid);
-extern unsigned max_align_t_align (void);
 extern bool cxx_fundamental_alignment_p (unsigned);
 extern bool pointer_to_zero_sized_aggr_p (tree);
 extern bool diagnose_mismatched_attributes (tree, tree);
Index: config/pa/pa.c
===
--- config/pa/pa.c  (revision 240688)
+++ config/pa/pa.c  (working copy)
@@ -194,6 +194,7 @@
 static bool pa_legitimate_constant_p (machine_mode, rtx);
 static unsigned int pa_section_type_flags (tree, const char *, int);
 static bool pa_legitimate_address_p (machine_mode, rtx, bool);
+static unsigned int pa_max_align_t_align (void);
 
 /* The following extra sections are only used for SOM.  */
 static GTY(()) section *som_readonly_data_section;
@@ -400,6 +401,9 @@
 #undef TARGET_LRA_P
 #define TARGET_LRA_P hook_bool_void_false
 
+#undef TARGET_MAX_ALIGN_T_ALIGN
+#define TARGET_MAX_ALIGN_T_ALIGN pa_max_align_t_align
+
 struct gcc_target targetm = TARGET_INITIALIZER;
 
 /* Parse the -mfixed-range= option string.  */
@@ -10719,4 +10723,16 @@
   return NULL_RTX;
 }
 
+/* The maximimum alignment in bits for the POD type std:max_align_t.
+   This is set to 128 on 32-bit non HP-UX systems to suppress warnings
+   about new with extended alignment.  This arises because various POSIX
+   types such as pthread_mutex_t have for historical reasons 128-bit
+   alignment but the default alignment of std:max_align_t is 64 bits.  */
+
+static unsigned int
+pa_max_align_t_align (void)
+{
+  return TARGET_HPUX && !TARGET_64BIT ? 64 : 128;
+}
+
 #include

[SPARC] Make %icc a formally fixed register

2016-10-08 Thread Eric Botcazou
It de facto was fixed already, since it belongs to no register class, so there 
is no functional change.

Tested on SPARC/Solaris, applied on the mainline.


2016-10-08  Eric Botcazou  

* config/sparc/sparc.h (FIXED_REGISTERS): Add %icc.

-- 
Eric BotcazouIndex: config/sparc/sparc.h
===
--- config/sparc/sparc.h	(revision 240888)
+++ config/sparc/sparc.h	(working copy)
@@ -603,7 +603,8 @@ extern enum cmodel sparc_cmodel;
(e.g.: in CLASS_MAX_NREGS).  There are also 4 fp condition code registers, so
32+32+32+4 == 100.
Register 100 is used as the integer condition code register.
-   Register 101 is used as the soft frame pointer register.  */
+   Register 101 is used as the soft frame pointer register.
+   Register 102 is used as the general status register by VIS instructions.  */
 
 #define FIRST_PSEUDO_REGISTER 103
 
@@ -678,7 +679,7 @@ extern enum cmodel sparc_cmodel;
   0, 0, 0, 0, 0, 0, 0, 0,	\
   0, 0, 0, 0, 0, 0, 0, 0,	\
 \
-  0, 0, 0, 0, 0, 1, 1}
+  0, 0, 0, 0, 1, 1, 1}
 
 /* 1 for registers not available across function calls.
These must include the FIXED_REGISTERS and also any
@@ -885,12 +886,7 @@ extern int sparc_mode_class[];
have a class that is the union of FPCC_REGS with either of the others,
it is important that it appear first.  Otherwise the compiler will die
trying to compile _fixunsdfsi because fix_truncdfsi2 won't match its
-   constraints.
-
-   It is important that SPARC_ICC_REG have class NO_REGS.  Otherwise combine
-   may try to use it to hold an SImode value.  See register_operand.
-   ??? Should %fcc[0123] be handled similarly?
-*/
+   constraints.  */
 
 enum reg_class { NO_REGS, FPCC_REGS, I64_REGS, GENERAL_REGS, FP_REGS,
 		 EXTRA_FP_REGS, GENERAL_OR_FP_REGS, GENERAL_OR_EXTRA_FP_REGS,


Re: [RFC] Extend ipa-bitwise-cp with pointer alignment propagation

2016-10-08 Thread Jan Hubicka
> On 6 October 2016 at 18:51, Jan Hubicka  wrote:
> >> >
> >> > What do you mean by "for instance?"  What are the other cases when it
> >> > happens?
> >> Well ipa_get_type() returned NULL for 481.wrf, and I assumed it was a
> >> fortran-only
> >> code-base but apparently it's a mix of C and fortran.
> >
> > Yep, I also have expreinece that the K&R style declarations are more common
> > than one would expect 30 years after the language was obsoletted.
> >> ipa_get_type() returned NULL for param 'n' in
> >> get_initial_data_value_() which is defined
> >> as K&R style function in wrf_num_bytes_between.c, so it seems K&R is the
> >> only case where ipa_get_type() returns NULL.
> >>
> >> I have a question though on how to reduce fortran test-cases or a mix
> >> of fortran/C
> >> like 481.wrf ? For C/C++ only tests-cases, I use creduce.
> >
> > I use delta/multidelta
> > https://gcc.gnu.org/wiki/A_guide_to_testcase_reduction
> >
> > It works pretty well and one can reduce first list of files and then file 
> > at a
> > time.
> Thanks! I will try to reduce 481.wrf assert ICE for practice -;)
> Is the alignment propagation patch OK to commit ?
OK,
Honza
> 
> Thanks,
> Prathamesh
> >
> > Honza


Re: PR35503 - warn for restrict pointer

2016-10-08 Thread Prathamesh Kulkarni
On 7 October 2016 at 17:49, David Malcolm  wrote:
> On Fri, 2016-10-07 at 10:33 +0530, Prathamesh Kulkarni wrote:
>> On 22 September 2016 at 23:15, Joseph Myers 
>> wrote:
>> > On Thu, 22 Sep 2016, Prathamesh Kulkarni wrote:
>> >
>> > > Would that be acceptable ? I am not sure how to make %Z check if
>> > > the
>> > > argument has type vec *
>> > > since vec is not really a builtin C type.
>> > > Could you suggest me a better solution so that the format checker
>> > > will check
>> > > if arg has type vec * instead of checking if it's just a
>> > > pointer ?
>> > > Also for testing, should I create a testcase in g++.dg since
>> > > gcc.dg/format/ tests are C-only ?
>> >
>> > If it's C++-only then it would need to be in g++.dg.
>> >
>> > The way we handle GCC-specific types in checking these formats is
>> > that the
>> > code using these formats has to define typedefs which the format
>> > -checking
>> > code then looks up.  In most cases it can just look up names like
>> > location_t or tree, but for HOST_WIDE_INT it looks up
>> > __gcc_host_wide_int__ which the user must have defined as a
>> > typedef.
>> > Probably that's the way to go in this case: the user must do
>> > "typedef
>> > vec __gcc_vec_int__;" or similar, and the code looks up
>> > __gcc_vec_int__.
>> Thanks for the suggestions. To keep it simple, instead of vec,
>> I made %Z take two args: int *v, unsigned len, and prints elements in
>> v having length == len.
>> Is that OK ?
>>
>> Bootstrapped+tested on x86_64-unknown-linux-gnu.
>> As pointed out earlier in the thread, the patch can give false
>> positives because
>> it only checks whether parameters are qualified with restrict, not
>> how
>> parameters
>> are used inside the function. For instance it warned for example 10
>> mentioned in n1570
>> under section 6.7.3.1 - "Formal definition of restrict".
>> Should we keep the warning in Wall or keep it in Wextra ?
>> The attached patch enables it with Wall.
>>
>> Thanks,
>> Prathamesh
>
> This needs a ChangeLog.
>
> The changes to diagnostic-core.h and diagnostic.c are OK for trunk,
> given a suitable ChangeLog (and could be split into a separate patch if
> you like).
Thanks, I committed diagnostic.c and diagnostic-core.h changes (with ChangeLog)
in r240891.

Thanks,
Prathamesh


Re: [PATCH] Revert commit r235318

2016-10-08 Thread John David Anglin
On 2016-10-08, at 12:53 PM, John David Anglin wrote:

> 
> It doesn't look as if the change was reviewed.

For reference, the submission is here:
https://gcc.gnu.org/ml/gcc-patches/2016-04/msg00796.html

Dave
--
John David Anglin   dave.ang...@bell.net





Re: Implement -Wimplicit-fallthrough (version 9)

2016-10-08 Thread Eric Botcazou
> testing completed successfully, so I've installed the patch with this
> ChangeLog entry:
> 
> 2016-09-26  Rainer Orth  
> 
>   gcc:
>   * config/i386/i386.c (ix86_print_operand)
>   [HAVE_AS_IX86_CMOV_SUN_SYNTAX]: Add gcc_fallthrough.
>   * config/sparc/sparc.c (check_pic): Add fallthrough comment.
>   (epilogue_renumber): Likewise.
> 
>   gcc/ada:
>   * gcc-interface/decl.c: Fix fall through comment formatting.
>   * gcc-interface/misc.c: Likewise.
>   * gcc-interface/trans.c: Likewise.
>   * gcc-interface/utils.c: Likewise.
>   * gcc-interface/utils2.c: Likewise.

This is a revealing example of how excessive pickiness in warnings can be 
counter-productive: after Jakub's latest patches (thanks!) accepting the 
original formatting of gcc-interface, I reverted part #2 of the above patch... 
only to discover that bootstrap was still broken because of a -Wimplicit-
fallthrough warning, but this time for a missing break:

Index: gcc-interface/utils.c
===
--- gcc-interface/utils.c   (revision 324591)
+++ gcc-interface/utils.c   (working copy)
@@ -4289,6 +4289,7 @@ convert (tree type, tree expr)
  TREE_TYPE (expr) = type;
  return expr;
}
+  break;
 
 case CONSTRUCTOR:
   /* If we are converting a CONSTRUCTOR to a mere type variant, or to

So the issue went unnoticed among the slew of false positives the first time 
and a genuine error was overlooked...

Tested on x86_64-suse-linux, applied on the mainline.


2016-10-08  Eric Botcazou  

* gcc-interface/utils.c (convert) : Add missing break.

Revert
2016-09-26  Rainer Orth  

* gcc-interface/decl.c: Fix fall through comment formatting.
* gcc-interface/misc.c: Likewise.
* gcc-interface/trans.c: Likewise.
* gcc-interface/utils.c: Likewise.
* gcc-interface/utils2.c: Likewise.


-- 
Eric BotcazouIndex: gcc-interface/decl.c
===
--- gcc-interface/decl.c	(revision 240888)
+++ gcc-interface/decl.c	(working copy)
@@ -596,7 +596,7 @@ gnat_to_gnu_entity (Entity_Id gnat_entit
 	gnu_expr
 	  = gnat_to_gnu_external (Expression (Declaration_Node (gnat_entity)));
 
-  /* fall through */
+  /* ... fall through ... */
 
 case E_Exception:
 case E_Loop_Parameter:
@@ -3369,7 +3369,7 @@ gnat_to_gnu_entity (Entity_Id gnat_entit
 	  break;
 	}
 
-  /* fall through */
+  /* ... fall through ... */
 
 case E_Record_Subtype:
   /* If Cloned_Subtype is Present it means this record subtype has
@@ -3804,7 +3804,7 @@ gnat_to_gnu_entity (Entity_Id gnat_entit
 	break;
 	}
 
-  /* fall through */
+  /* ... fall through ... */
 
 case E_Allocator_Type:
 case E_Access_Type:
@@ -6882,7 +6882,7 @@ choices_to_gnu (tree operand, Node_Id ch
 	  break;
 	}
 
-	  /* fall through */
+	  /* ... fall through ... */
 
 	case N_Character_Literal:
 	case N_Integer_Literal:
@@ -8089,7 +8089,7 @@ annotate_value (tree gnu_size)
   else
 	return Uint_Minus_1;
 
-  /* fall through */
+  /* Fall through... */
 
 default:
   return No_Uint;
Index: gcc-interface/misc.c
===
--- gcc-interface/misc.c	(revision 240888)
+++ gcc-interface/misc.c	(working copy)
@@ -157,7 +157,7 @@ gnat_handle_option (size_t scode, const
 case OPT_gant:
   warning (0, "%<-gnat%> misspelled as %<-gant%>");
 
-  /* fall through */
+  /* ... fall through ... */
 
 case OPT_gnat:
 case OPT_gnatO:
@@ -485,13 +485,13 @@ gnat_print_type (FILE *file, tree node,
   else
 	print_node (file, "index type", TYPE_INDEX_TYPE (node), indent + 4);
 
-  /* fall through */
+  /* ... fall through ... */
 
 case ENUMERAL_TYPE:
 case BOOLEAN_TYPE:
   print_node_brief (file, "RM size", TYPE_RM_SIZE (node), indent + 4);
 
-  /* fall through */
+  /* ... fall through ... */
 
 case REAL_TYPE:
   print_node_brief (file, "RM min", TYPE_RM_MIN_VALUE (node), indent + 4);
Index: gcc-interface/trans.c
===
--- gcc-interface/trans.c	(revision 240888)
+++ gcc-interface/trans.c	(working copy)
@@ -844,7 +844,7 @@ lvalue_required_p (Node_Id gnat_node, tr
 		 && Ekind (Entity (gnat_temp)) == E_Enumeration_Literal))
 	  return 1;
 
-  /* fall through */
+  /* ... fall through ... */
 
 case N_Slice:
   /* Only the array expression can require an lvalue.  */
@@ -890,7 +890,7 @@ lvalue_required_p (Node_Id gnat_node, tr
 	if (!constant)
 	  return 1;
 
-  /* fall through */
+  /* ... fall through ... */
 
 case N_Type_Conversion:
 case N_Qualified_Expression:
@@ -914,7 +914,7 @@ lvalue_required_p (Node_Id gnat_node, tr
   get_unpadded_type (Etype (gnat_parent)),
   true, false, true);
 
-  /* fa

Re: [PATCH] Implement new hook for max_align_t_align

2016-10-08 Thread Bernd Edlinger
bounced, resent...

Hi,

I think your callback should also directly control the
alignment of max_align_t in stddef.h:

typedef struct {
   long long __max_align_ll __attribute__((__aligned__(__alignof__(long 
long;
   long double __max_align_ld 
__attribute__((__aligned__(__alignof__(long double;
   /* _Float128 is defined as a basic type, so max_align_t must be
  sufficiently aligned for it.  This code must work in C++, so we
  use __float128 here; that is only available on some
  architectures, but only on i386 is extra alignment needed for
  __float128.  */
#ifdef __i386__
   __float128 __max_align_f128 
__attribute__((__aligned__(__alignof(__float128;
#endif
} max_align_t;


otherwise these will not match.

I think is __alignof(max_aling_t) == max_align_t_align ()
on your target?


Bernd.


[PATCH] Revert commit r235318

2016-10-08 Thread John David Anglin
The attached patch reverts commit r235318.  It caused an ICE in 
binds_to_current_def_p building java.
Although java is now gone, the change broke bootstrap and the handling of 
_GLOBAL constructors on
32-bit hpux targets.

See PR 70795:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70795

In as much as there has been no comment regarding the PR, I believe the change 
should be reverted.
It doesn't look as if the change was reviewed.

Okay for trunk?  The hppa2.0w-hp-hpux11.11 and hppa64-hp-hpux11.11 targets 
build successfully with
change reverted.

Dave
--
John David Anglin   dave.ang...@bell.net


2016-10-08  John David Anglin  

PR ipa/70018
* cgraph.c: Revert commit r235318.
* cgraph.h: Likewise.
* ipa-pure-const.c: Likewise.

Index: cgraph.c
===
--- cgraph.c(revision 240816)
+++ cgraph.c(working copy)
@@ -2383,65 +2383,27 @@
 
 /* Worker to set nothrow flag.  */
 
-static void
-set_nothrow_flag_1 (cgraph_node *node, bool nothrow, bool non_call,
-   bool *changed)
+static bool
+cgraph_set_nothrow_flag_1 (cgraph_node *node, void *data)
 {
   cgraph_edge *e;
 
-  if (nothrow && !TREE_NOTHROW (node->decl))
-{
-  /* With non-call exceptions we can't say for sure if other function body
-was not possibly optimized to stil throw.  */
-  if (!non_call || node->binds_to_current_def_p ())
-   {
- TREE_NOTHROW (node->decl) = true;
- *changed = true;
- for (e = node->callers; e; e = e->next_caller)
-   e->can_throw_external = false;
-   }
-}
-  else if (!nothrow && TREE_NOTHROW (node->decl))
-{
-  TREE_NOTHROW (node->decl) = false;
-  *changed = true;
-}
-  ipa_ref *ref;
-  FOR_EACH_ALIAS (node, ref)
-{
-  cgraph_node *alias = dyn_cast  (ref->referring);
-  if (!nothrow || alias->get_availability () > AVAIL_INTERPOSABLE)
-   set_nothrow_flag_1 (alias, nothrow, non_call, changed);
-}
-  for (cgraph_edge *e = node->callers; e; e = e->next_caller)
-if (e->caller->thunk.thunk_p
-   && (!nothrow || e->caller->get_availability () > AVAIL_INTERPOSABLE))
-  set_nothrow_flag_1 (e->caller, nothrow, non_call, changed);
+  TREE_NOTHROW (node->decl) = data != NULL;
+
+  if (data != NULL)
+for (e = node->callers; e; e = e->next_caller)
+  e->can_throw_external = false;
+  return false;
 }
 
 /* Set TREE_NOTHROW on NODE's decl and on aliases of NODE
if any to NOTHROW.  */
 
-bool
+void
 cgraph_node::set_nothrow_flag (bool nothrow)
 {
-  bool changed = false;
-  bool non_call = opt_for_fn (decl, flag_non_call_exceptions);
-
-  if (!nothrow || get_availability () > AVAIL_INTERPOSABLE)
-set_nothrow_flag_1 (this, nothrow, non_call, &changed);
-  else
-{
-  ipa_ref *ref;
-
-  FOR_EACH_ALIAS (this, ref)
-   {
- cgraph_node *alias = dyn_cast  (ref->referring);
- if (!nothrow || alias->get_availability () > AVAIL_INTERPOSABLE)
-   set_nothrow_flag_1 (alias, nothrow, non_call, &changed);
-   }
-}
-  return changed;
+  call_for_symbol_thunks_and_aliases (cgraph_set_nothrow_flag_1,
+ (void *)(size_t)nothrow, nothrow == true);
 }
 
 /* Worker to set_const_flag.  */
@@ -2580,7 +2542,8 @@
 
 /* Info used by set_pure_flag_1.  */
 
-struct set_pure_flag_info
+struct
+set_pure_flag_info
 {
   bool pure;
   bool looping;
Index: cgraph.h
===
--- cgraph.h(revision 240816)
+++ cgraph.h(working copy)
@@ -,7 +,7 @@
 
   /* Set TREE_NOTHROW on cgraph_node's decl and on aliases of the node
  if any to NOTHROW.  */
-  bool set_nothrow_flag (bool nothrow);
+  void set_nothrow_flag (bool nothrow);
 
   /* If SET_CONST is true, mark function, aliases and thunks to be ECF_CONST.
 If SET_CONST if false, clear the flag.
Index: ipa-pure-const.c
===
--- ipa-pure-const.c(revision 240816)
+++ ipa-pure-const.c(working copy)
@@ -1167,10 +1167,7 @@
   enum availability avail;
   cgraph_node *n = e->callee->function_or_virtual_thunk_symbol (&avail,
e->caller);
-  if (avail <= AVAIL_INTERPOSABLE || TREE_NOTHROW (n->decl))
-return true;
-  return opt_for_fn (e->callee->decl, flag_non_call_exceptions)
-&& !e->callee->binds_to_current_def_p (e->caller);
+  return (avail <= AVAIL_INTERPOSABLE || TREE_NOTHROW (n->decl));
 }
 
 /* Return true if NODE is self recursive function.
@@ -1601,20 +1598,14 @@
continue;
 
  struct cgraph_node *y = e->callee->
-  function_or_virtual_thunk_symbol (&avail,
-e->caller);
+   function_or_virtual_thunk_symbol (&ava

Re: [PATCH] Implement new hook for max_align_t_align

2016-10-08 Thread Bernd Edlinger
Hi,

I think your callback should also directly control the
alignment of max_align_t in stddef.h:

typedef struct {
   long long __max_align_ll __attribute__((__aligned__(__alignof__(long 
long;
   long double __max_align_ld 
__attribute__((__aligned__(__alignof__(long double;
   /* _Float128 is defined as a basic type, so max_align_t must be
  sufficiently aligned for it.  This code must work in C++, so we
  use __float128 here; that is only available on some
  architectures, but only on i386 is extra alignment needed for
  __float128.  */
#ifdef __i386__
   __float128 __max_align_f128 
__attribute__((__aligned__(__alignof(__float128;
#endif
} max_align_t;


otherwise these will not match.


Bernd.


Re: C++ PATCH for P0135, C++17 guaranteed copy elision

2016-10-08 Thread Jason Merrill
On Thu, Oct 6, 2016 at 5:26 PM, Jason Merrill  wrote:
> Here's an update that handles more cases.

And a further update that handles direct-initialization, which the
actual proposal doesn't specify at all.  I'm dealing with
direct-initialization from a type with a conversion operator that
produces a prvalue of the type being initialized by treating
direct-initialization from an unrelated type like copy-initialization
with access to explicit conversions.  And relatedly, for conversion
from a braced-init-list with a single element: we look for
constructors as normal, but also consider conversion functions from
the element type.  I should probably write up some wording for this
for Issaquah.

Tested x86_64-pc-linux-gnu, applied to trunk.
commit b04f46b73da7ca43b04a5521144c60aa0ceaf8bf
Author: Jason Merrill 
Date:   Thu Oct 6 17:28:40 2016 -0400

Further P0135 refinement.

* call.c (build_user_type_conversion_1): Consider conversions from
a single element in an initializer-list.
(build_temp): Undo early_elide_copy change.
(build_over_call): Check that we don't try to copy a TARGET_EXPR
in C++17 mode.  Set user_conv_p here.
(convert_like_real): Not here.
(check_self_delegation): Split out from...
(build_special_member_call): ...here.  Handle C++17 copy elision.
* cvt.c (early_elide_copy): Remove.
(ocp_convert): Undo early_elide_copy change.
* except.c (build_throw): Likewise.
* init.c (expand_default_init): Likewise.
* typeck.c (cp_build_modify_expr): Likewise.

diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index 6feaf7e..4bee487 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -3671,6 +3671,14 @@ build_user_type_conversion_1 (tree totype, tree expr, 
int flags,
creating a garbage BASELINK; constructors can't be inherited.  */
 ctors = lookup_fnfields_slot (totype, complete_ctor_identifier);
 
+  /* FIXME P0135 doesn't say what to do in C++17 about list-initialization from
+ a single element.  For now, let's handle constructors as before and also
+ consider conversion operators from the element.  */
+  if (cxx_dialect >= cxx1z
+  && BRACE_ENCLOSED_INITIALIZER_P (expr)
+  && CONSTRUCTOR_NELTS (expr) == 1)
+fromtype = TREE_TYPE (CONSTRUCTOR_ELT (expr, 0)->value);
+
   if (MAYBE_CLASS_TYPE_P (fromtype))
 {
   tree to_nonref = non_reference (totype);
@@ -3745,7 +3753,13 @@ build_user_type_conversion_1 (tree totype, tree expr, 
int flags,
 }
 
   if (conv_fns)
-first_arg = expr;
+{
+  if (BRACE_ENCLOSED_INITIALIZER_P (expr))
+   /* FIXME see above about C++17.  */
+   first_arg = CONSTRUCTOR_ELT (expr, 0)->value;
+  else
+   first_arg = expr;
+}
 
   for (; conv_fns; conv_fns = TREE_CHAIN (conv_fns))
 {
@@ -6367,11 +6381,6 @@ build_temp (tree expr, tree type, int flags,
 
   *diagnostic_kind = DK_UNSPECIFIED;
 
-  if (TREE_CODE (expr) == CONSTRUCTOR)
-expr = get_target_expr_sfinae (expr, complain);
-  if (early_elide_copy (type, expr))
-return expr;
-
   /* If the source is a packed field, calling the copy constructor will require
  binding the field to the reference parameter to the copy constructor, and
  we'll end up with an infinite loop.  If we can use a bitwise copy, then
@@ -6563,7 +6572,6 @@ convert_like_real (conversion *convs, tree expr, tree fn, 
int argnum,
   {
struct z_candidate *cand = convs->cand;
tree convfn = cand->fn;
-   unsigned i;
 
/* When converting from an init list we consider explicit
   constructors, but actually trying to call one is an error.  */
@@ -6609,12 +6617,10 @@ convert_like_real (conversion *convs, tree expr, tree 
fn, int argnum,
 
expr = mark_rvalue_use (expr);
 
-   /* Set user_conv_p on the argument conversions, so rvalue/base
-  handling knows not to allow any more UDCs.  */
-   for (i = 0; i < cand->num_convs; ++i)
- cand->convs[i]->user_conv_p = true;
-
-   expr = build_over_call (cand, LOOKUP_NORMAL, complain);
+   /* Pass LOOKUP_NO_CONVERSION so rvalue/base handling knows not to allow
+  any more UDCs.  */
+   expr = build_over_call (cand, LOOKUP_NORMAL|LOOKUP_NO_CONVERSION,
+   complain);
 
/* If this is a constructor or a function returning an aggr type,
   we need to build up a TARGET_EXPR.  */
@@ -6792,6 +6798,10 @@ convert_like_real (conversion *convs, tree expr, tree 
fn, int argnum,
flags |= LOOKUP_ONLYCONVERTING;
   if (convs->rvaluedness_matches_p)
flags |= LOOKUP_PREFER_RVALUE;
+  if (TREE_CODE (expr) == TARGET_EXPR
+ && TARGET_EXPR_LIST_INIT_P (expr))
+   /* Copy-list-initialization doesn't actually involve a copy.  */
+   return expr;
   expr = build_temp (expr, totype, flags, &diag_kind, complain);
   if (diag_kind

[PATCH] Implement new hook for max_align_t_align

2016-10-08 Thread John David Anglin
Various pthread types on hppa-linux require an alignment of 16 bytes for ABI 
reasons.  This is larger
than the current implementations of max_align_t and max_align_t_align.  As a 
result, the patch to
implement C++17 over-aligned new  causes warnings on hppa.  The thread here 
discusses the problem:
https://gcc.gnu.org/ml/gcc-patches/2016-09/msg01593.html

The attached patch implements a new hook to allow overriding the default 
implementation of max_align_t_align
in the PA backend.  It changes the max_align_t alignment to 16 bytes on 32-bit 
hppa-linux.  I added an additional
comment to BIGGEST_ALIGNMENT in pa.h to document the alignment choices for long 
double on hpux.  I also
defined MALLOC_ABI_ALIGNMENT so that it reflects the behaviour of the glibc and 
hpux malloc implementations.

Tested on hppa2.0w-hp-hpux11.11, hppa64-hp-hpux11.11 and hppa-unknown-linux-gnu 
with no observed
regressions.

Okay for trunk?

Dave
--
John David Anglin   dave.ang...@bell.net

2016-10-08  John David Anglin  

gcc/c-family/
* c-common.c (max_align_t_align): Move to targhooks.c.
* c-common.h (max_align_t_align): Delete.
gcc/
* target.def (max_align_t_align): New target hook.
* targhooks.c (default_max_align_t_align): New.
* targhooks.h (default_max_align_t_align): Declare.
* config/pa/pa.h (BIGGEST_ALIGNMENT): Adjust comment.
(MALLOC_ABI_ALIGNMENT): Define.
* config/pa/pa.c (pa_max_align_t_align): New.
(TARGET_MAX_ALIGN_T_ALIGN): Define.
* doc/tm.texi.in (TARGET_MAX_ALIGN_T_ALIGN): Add documentation hook.
* doc/tm.texi: Update.
gcc/cp/
* decl.c (cxx_init_decl_processing): Use max_align_t_align target hook.
* init.c (build_new_1): Likewise.

Index: c-family/c-common.c
===
--- c-family/c-common.c (revision 240688)
+++ c-family/c-common.c (working copy)
@@ -12899,22 +12899,6 @@
   return stv_nothing;
 }
 
-/* Return the alignment of std::max_align_t.
-
-   [support.types.layout] The type max_align_t is a POD type whose alignment
-   requirement is at least as great as that of every scalar type, and whose
-   alignment requirement is supported in every context.  */
-
-unsigned
-max_align_t_align ()
-{
-  unsigned int max_align = MAX (TYPE_ALIGN (long_long_integer_type_node),
-   TYPE_ALIGN (long_double_type_node));
-  if (float128_type_node != NULL_TREE)
-max_align = MAX (max_align, TYPE_ALIGN (float128_type_node));
-  return max_align;
-}
-
 /* Return true iff ALIGN is an integral constant that is a fundamental
alignment, as defined by [basic.align] in the c++-11
specifications.
@@ -12928,7 +12912,7 @@
 bool
 cxx_fundamental_alignment_p (unsigned align)
 {
-  return (align <= max_align_t_align ());
+  return (align <= targetm.max_align_t_align ());
 }
 
 /* Return true if T is a pointer to a zero-sized aggregate.  */
Index: c-family/c-common.h
===
--- c-family/c-common.h (revision 240688)
+++ c-family/c-common.h (working copy)
@@ -864,7 +864,6 @@
 extern bool keyword_is_storage_class_specifier (enum rid);
 extern bool keyword_is_type_qualifier (enum rid);
 extern bool keyword_is_decl_specifier (enum rid);
-extern unsigned max_align_t_align (void);
 extern bool cxx_fundamental_alignment_p (unsigned);
 extern bool pointer_to_zero_sized_aggr_p (tree);
 extern bool diagnose_mismatched_attributes (tree, tree);
Index: config/pa/pa.c
===
--- config/pa/pa.c  (revision 240688)
+++ config/pa/pa.c  (working copy)
@@ -194,6 +194,7 @@
 static bool pa_legitimate_constant_p (machine_mode, rtx);
 static unsigned int pa_section_type_flags (tree, const char *, int);
 static bool pa_legitimate_address_p (machine_mode, rtx, bool);
+static unsigned int pa_max_align_t_align (void);
 
 /* The following extra sections are only used for SOM.  */
 static GTY(()) section *som_readonly_data_section;
@@ -400,6 +401,9 @@
 #undef TARGET_LRA_P
 #define TARGET_LRA_P hook_bool_void_false
 
+#undef TARGET_MAX_ALIGN_T_ALIGN
+#define TARGET_MAX_ALIGN_T_ALIGN pa_max_align_t_align
+
 struct gcc_target targetm = TARGET_INITIALIZER;
 
 /* Parse the -mfixed-range= option string.  */
@@ -10719,4 +10723,16 @@
   return NULL_RTX;
 }
 
+/* The maximimum alignment in bits for the POD type std:max_align_t.
+   This is set to 128 on 32-bit non HP-UX systems to suppress warnings
+   about new with extended alignment.  This arises because various POSIX
+   types such as pthread_mutex_t have for historical reasons 128-bit
+   alignment but the default alignment of std:max_align_t is 64 bits.  */
+
+static unsigned int
+pa_max_align_t_align (void)
+{
+  return TARGET_HPUX && !TARGET_64BIT ? 64 : 128;
+}
+
 #include "gt-pa.h"
Index: config/pa/pa.h
===
--- config/pa/pa.h 

[v3 PATCH] Make any's copy assignment operator exception-safe, don't copy the underlying value when any is moved, make in_place constructors explicit.

2016-10-08 Thread Ville Voutilainen
Tested on Linux-x64.

2016-10-08  Ville Voutilainen  

Make any's copy assignment operator exception-safe,
don't copy the underlying value when any is moved,
make in_place constructors explicit.
* include/std/any (any(in_place_type_t<_ValueType>, _Args&&...)):
Make explicit.
(any(in_place_type_t<_ValueType>, initializer_list<_Up>, _Args&&...)):
Likewise.
(operator=(const any&)): Make strongly exception-safe.
(operator=(any&&)): Reset the manager when resetting the value.
This makes the state saner if an exception is thrown during the move.
(_Manager_internal<_Tp>::_S_manage): Move in _Op_xfer, don't copy.
* testsuite/20_util/any/assign/2.cc: Adjust.
* testsuite/20_util/any/assign/exception.cc: New.
* testsuite/20_util/any/cons/2.cc: Adjust.
* testsuite/20_util/any/cons/explicit.cc: New.
* testsuite/20_util/any/misc/any_cast_neg.cc: Ajust.
diff --git a/libstdc++-v3/include/std/any b/libstdc++-v3/include/std/any
index 9160035..78bdf89 100644
--- a/libstdc++-v3/include/std/any
+++ b/libstdc++-v3/include/std/any
@@ -179,7 +179,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
  typename _Tp = _Decay<_ValueType>,
  typename _Mgr = _Manager<_Tp>,
   __any_constructible_t<_Tp, _Args&&...> = false>
-  any(in_place_type_t<_ValueType>, _Args&&... __args)
+  explicit any(in_place_type_t<_ValueType>, _Args&&... __args)
   : _M_manager(&_Mgr::_S_manage)
   {
 _Mgr::_S_create(_M_storage, std::forward<_Args>(__args)...);
@@ -192,8 +192,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
  typename _Mgr = _Manager<_Tp>,
   __any_constructible_t<_Tp, initializer_list<_Up>,
_Args&&...> = false>
-  any(in_place_type_t<_ValueType>,
- initializer_list<_Up> __il, _Args&&... __args)
+  explicit any(in_place_type_t<_ValueType>,
+  initializer_list<_Up> __il, _Args&&... __args)
   : _M_manager(&_Mgr::_S_manage)
   {
 _Mgr::_S_create(_M_storage, __il, std::forward<_Args>(__args)...);
@@ -211,11 +211,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
reset();
   else if (this != &__rhs)
{
- if (has_value())
-   _M_manager(_Op_destroy, this, nullptr);
- _Arg __arg;
- __arg._M_any = this;
- __rhs._M_manager(_Op_clone, &__rhs, &__arg);
+ any(__rhs).swap(*this);
}
   return *this;
 }
@@ -232,7 +228,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   else if (this != &__rhs)
{
  if (has_value())
-   _M_manager(_Op_destroy, this, nullptr);
+   reset();
  _Arg __arg;
  __arg._M_any = this;
  __rhs._M_manager(_Op_xfer, &__rhs, &__arg);
@@ -556,7 +552,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
__ptr->~_Tp();
break;
   case _Op_xfer:
-   ::new(&__arg->_M_any->_M_storage._M_buffer) _Tp(*__ptr);
+   ::new(&__arg->_M_any->_M_storage._M_buffer) _Tp
+ (std::move(*const_cast<_Tp*>(__ptr)));
__ptr->~_Tp();
__arg->_M_any->_M_manager = __any->_M_manager;
const_cast(__any)->_M_manager = nullptr;
diff --git a/libstdc++-v3/testsuite/20_util/any/assign/2.cc 
b/libstdc++-v3/testsuite/20_util/any/assign/2.cc
index b333e5d..28f06a0 100644
--- a/libstdc++-v3/testsuite/20_util/any/assign/2.cc
+++ b/libstdc++-v3/testsuite/20_util/any/assign/2.cc
@@ -24,28 +24,69 @@
 using std::any;
 using std::any_cast;
 
+bool moved = false;
+bool copied = false;
+
 struct X
 {
-  bool moved = false;
-  bool moved_from = false;
   X() = default;
-  X(const X&) = default;
-  X(X&& x) : moved(true) { x.moved_from = true; }
+  X(const X&) { copied = true; }
+  X(X&& x) { moved = true; }
+};
+
+struct X2
+{
+  X2() = default;
+  X2(const X2&) { copied = true; }
+  X2(X2&& x) noexcept { moved = true; }
 };
 
 void test01()
 {
+  moved = false;
   X x;
   any a1;
   a1 = x;
-  VERIFY(x.moved_from == false);
+  VERIFY(moved == false);
   any a2;
+  copied = false;
   a2 = std::move(x);
-  VERIFY(x.moved_from == true);
-  VERIFY(any_cast(a2).moved == true );
+  VERIFY(moved == true);
+  VERIFY(copied == false);
+}
+
+void test02()
+{
+  moved = false;
+  X x;
+  any a1;
+  a1 = x;
+  VERIFY(moved == false);
+  any a2;
+  copied = false;
+  a2 = std::move(a1);
+  VERIFY(moved == false);
+  VERIFY(copied == false);
+}
+
+void test03()
+{
+  moved = false;
+  X2 x;
+  any a1;
+  a1 = x;
+  VERIFY(copied && moved);
+  any a2;
+  moved = false;
+  copied = false;
+  a2 = std::move(a1);
+  VERIFY(moved == true);
+  VERIFY(copied == false);
 }
 
 int main()
 {
   test01();
+  test02();
+  test03();
 }
diff --git a/libstdc++-v3/testsuite/20_util/any/assign/exception.cc 
b/libstdc++-v3/testsuite/20_util/any/assign/exception.cc
new file mode 100644
index 000..11a1a55
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/any/assign/exception.cc
@@ -0,0 +1,77 @@
+// { dg-options "-std=gnu++17" }
+// { dg-do run }
+
+// Co

Re: [PATCH] gcc: Fix sysroot relative paths for MinGW

2016-10-08 Thread Tadek Kijkowski

Prevent paths relative to sysroot directory from being transformed to Windows 
form with MSYS prefix.

Second attempt:
Moved most changes to x-mingw32. Only thing added to Makefile.in are new 
variables to ease overriding in included file.
Disabled overriding standard lib and include paths (with /mingw/lib and 
/mingw/include) in mingw32.h when TARGET_SYSTEM_ROOT is defined.

Side notes:

I've tested the patch together with patches from 
github.com/Alexpux/MINGW-packages. One of those patches disables overriding 
NATIVE_SYSTEM_HEADER_DIR in config scripts, so it's complement to this patch.

Target s-selftest in gcc fails on MinGW:
/home/tadek/gcc/gcc-build-mingw32-sysroot/./gcc/xgcc 
-B/home/tadek/gcc/gcc-build-mingw32-sysroot/./gcc/ -xc -S -c /dev/null 
-fself-test
cc1.exe: fatal error: input file 'nul.s' is the same as output file
It's enough to specify any output file, like '-o self-test-result.s' to fix the 
issue. Specifying '-o /dev/null' works as well, but I'm not sure if it's safe 
on all systems. It's a topic for separate patch.

Manual at "https://gcc.gnu.org/install/configure.html"; does mention that path specified with|--with-native-system-header-dir is located within sysroot, but it fails 
to mention that the same applies to ||--with-local-prefix. Changelog: 2016-10-08 Tadek Kijkowski 
 * gcc/Makefile.in, gcc/config/i386/x-mingw32: |Fix sysroot relative paths for MinGW

* gcc/config/i386/mingw32.h: Disable overriding default library and 
include paths when sysroot is defined

Index: gcc/Makefile.in
===
--- gcc/Makefile.in (revision 240805)
+++ gcc/Makefile.in (working copy)
@@ -680,6 +680,15 @@
 exeext = @host_exeext@
 build_exeext = @build_exeext@
 
+

+# This allows overriding include paths in host specific Makefile
+# (config/i386/x-mingw32 overrides those variables and local_includedir).
+gplusplus_includedir = $(gcc_gxx_include_dir)
+gplusplus_tool_includedir = $(gcc_gxx_include_dir)/$(target_noncanonical)
+gplusplus_backward_includedir = $(gcc_gxx_include_dir)/backward
+native_system_includedir = $(NATIVE_SYSTEM_HEADER_DIR)
+
+
 # Directory in which to put man pages.
 mandir = @mandir@
 man1dir = $(mandir)/man1
@@ -2757,14 +2766,14 @@
 PREPROCESSOR_DEFINES = \
   -DGCC_INCLUDE_DIR=\"$(libsubdir)/include\" \
   -DFIXED_INCLUDE_DIR=\"$(libsubdir)/include-fixed\" \
-  -DGPLUSPLUS_INCLUDE_DIR=\"$(gcc_gxx_include_dir)\" \
+  -DGPLUSPLUS_INCLUDE_DIR=\"$(gplusplus_includedir)\" \
   -DGPLUSPLUS_INCLUDE_DIR_ADD_SYSROOT=$(gcc_gxx_include_dir_add_sysroot) \
-  
-DGPLUSPLUS_TOOL_INCLUDE_DIR=\"$(gcc_gxx_include_dir)/$(target_noncanonical)\" \
-  -DGPLUSPLUS_BACKWARD_INCLUDE_DIR=\"$(gcc_gxx_include_dir)/backward\" \
+  -DGPLUSPLUS_TOOL_INCLUDE_DIR=\"$(gplusplus_tool_includedir)\" \
+  -DGPLUSPLUS_BACKWARD_INCLUDE_DIR=\"$(gplusplus_backward_includedir)\" \
   -DLOCAL_INCLUDE_DIR=\"$(local_includedir)\" \
   -DCROSS_INCLUDE_DIR=\"$(CROSS_SYSTEM_HEADER_DIR)\" \
   -DTOOL_INCLUDE_DIR=\"$(gcc_tooldir)/include\" \
-  -DNATIVE_SYSTEM_HEADER_DIR=\"$(NATIVE_SYSTEM_HEADER_DIR)\" \
+  -DNATIVE_SYSTEM_HEADER_DIR=\"$(native_system_includedir)\" \
   -DPREFIX=\"$(prefix)/\" \
   -DSTANDARD_EXEC_PREFIX=\"$(libdir)/gcc/\" \
   @TARGET_SYSTEM_ROOT_DEFINE@
Index: gcc/config/i386/mingw32.h
===
--- gcc/config/i386/mingw32.h   (revision 240805)
+++ gcc/config/i386/mingw32.h   (working copy)
@@ -157,6 +161,8 @@
 fvtable-verify=std:vtv_end.o%s} \
   crtend.o%s"
 
+#if !defined(TARGET_SYSTEM_ROOT)

+
 /* Override startfile prefix defaults.  */
 #ifndef STANDARD_STARTFILE_PREFIX_1
 #define STANDARD_STARTFILE_PREFIX_1 "/mingw/lib/"
@@ -170,6 +176,8 @@
 #undef NATIVE_SYSTEM_HEADER_DIR
 #define NATIVE_SYSTEM_HEADER_DIR "/mingw/include"
 
+#endif /* !defined(TARGET_SYSTEM_ROOT) */

+
 /* Output STRING, a string representing a filename, to FILE.
We canonicalize it to be in Unix format (backslashes are replaced
forward slashes.  */
Index: gcc/config/i386/x-mingw32
===
--- gcc/config/i386/x-mingw32   (revision 240805)
+++ gcc/config/i386/x-mingw32   (working copy)
@@ -16,11 +16,45 @@
 # along with GCC; see the file COPYING3.  If not see
 # .
 #
+
+# MSYS will zealously translate all paths to Windows form, so /usr/include 
becomes c:/msysX/usr/include.
+# This is undesirable when TARGET_SYSTEM_ROOT is specified, so this function 
converts /usr/include to //usr\include,
+# which will become /usr/include again when passed to gcc.
+
+# This function takes two parameters: first parameter is include directory 
path, second parameter tells
+# if the path is relative to TARGET_SYSTEM_ROOT.
+# If TARGET_SYSTEM_ROOT is not configured, or
+#   this function always expands to the unmodified first parameter
+# if TARGET_SYSTEM_ROOT is configured, but second parameter is not 1,
+#   this function ag

Re: [PATCH] Fix -Wimplicit-fallthrough -C, handle some more comment styles and comments in between FALLTHRU comment and label

2016-10-08 Thread Marek Polacek
On Fri, Sep 30, 2016 at 10:05:57PM +0200, Jakub Jelinek wrote:
> On Fri, Sep 30, 2016 at 11:26:27AM +0200, Marek Polacek wrote:
> > I haven't gone over the patch in detail yet, but I wonder if we should
> > also accept /* Else, fall through.  */ (to be found e.g. in 
> > aarch64-simd.md).
> 
> Here is the patch split into a series of 3 patches (the later patches depend
> on the earlier ones):
> 1) the first patch fixes some bugs and fixes also -Wimplicit-fallthrough -C
> 2) the second patch adds the else and intentional/ly etc.
> 3) the third one adds the optional comma between else and fall
> 
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok?
> 
>   Jakub

> 2016-09-30  Jakub Jelinek  
> 
>   * c-lex.c (c_lex_with_flags) : For CPP_COMMENT
>   token with PREV_FALLTHROUGH, skip all following CPP_PADDING and
>   CPP_COMMENT tokens and set add_flags to PREV_FALLTHROUGH afterwards.
> 
>   * doc/invoke.texi (-Wimplicit-fallthrough): Document the accepted
>   FALLTHRU comment styles.
> 
>   * lex.c (fallthrough_comment_p): Fix off-by-one size comparison
>   errors, cleanup.
>   (_cpp_lex_direct): Allow arbitrary comments in between
>   fallthrough_comment_p comment and following token.
> 
>   * c-c++-common/Wimplicit-fallthrough-22.c: New test.
>   * c-c++-common/Wimplicit-fallthrough-23.c: New test.
> 
> --- gcc/c-family/c-lex.c.jj   2016-09-30 18:16:26.303336781 +0200
> +++ gcc/c-family/c-lex.c  2016-09-30 18:26:14.650999215 +0200
> @@ -598,7 +598,18 @@ c_lex_with_flags (tree *value, location_
>  
>  /* CPP_COMMENT will appear when compiling with -C and should be
> ignored.  */
> - case CPP_COMMENT:
> +case CPP_COMMENT:
> +  if (tok->flags & PREV_FALLTHROUGH)
> + {
> +   do
> + {
> +   tok = cpp_get_token_with_location (parse_in, loc);
> +   type = tok->type;
> + }
> +   while (type == CPP_PADDING || type == CPP_COMMENT);
> +   add_flags = PREV_FALLTHROUGH;

Wouldn't |= be safer?

> +   goto retry_after_at;
> + }

And the comment is not really true anymore; I think let's say that we
want to set PREV_FALLTHROUGH on the token following the comment.

Otherwise I'm ok with the first patch, just please rename the 
-22 test to -24, since I've added -22.c and -23.c.

Marek