Re: [RFC] Handle unary pass-through jump functions for ipa-vrp

2016-11-13 Thread kugan

Hi Honza,

I reverted this patch after it was reported that it resulted in 
bootstrap compare failure in some targets.


I reproduced it and tracked to a mistake in the patch that introduced it.

That is, in propagate_vr_accross_jump_function, I had:

  if (src_lats->m_value_range.bottom_p ())
return false;

which should have been:

  if (src_lats->m_value_range.bottom_p ())
return dest_lat->set_to_bottom ();


I also fixed update_jump_functions_after_inlining as reported in pr78268.

I now bootstrapped the patch (lto and normal) on two affected targets 
aarch64-none-linux-gnu and powerpc64le-unknown-linux-gnu. I also tested 
it on x86_64-linux-gnu with no new regressions. Is this OK?



Thanks,
Kugan


gcc/testsuite/ChangeLog:

2016-11-13  Kugan Vivekanandarajah  

* g++.dg/torture/pr78268.C: New test.


gcc/ChangeLog:

2016-11-13  Kugan Vivekanandarajah  

* ipa-cp.c (ipa_get_jf_pass_through_result): Skip unary expressions.
(propagate_vr_accross_jump_function): Handle unary expressions.
* ipa-prop.c (ipa_set_jf_unary_pass_through): New.
(load_from_param_1): New.
(load_from_unmodified_param): Factor common part into load_from_param_1.
(load_from_param): New.
(compute_complex_assign_jump_func): Handle unary expressions.
(update_jump_functions_after_inlining): Likewise.
(ipa_write_jump_function): Likewise.
(ipa_read_jump_function): Likewise.

diff --git a/gcc/ipa-cp.c b/gcc/ipa-cp.c
index 79e621a..2ec671f 100644
--- a/gcc/ipa-cp.c
+++ b/gcc/ipa-cp.c
@@ -1219,13 +1219,19 @@ ipa_get_jf_pass_through_result (struct ipa_jump_func 
*jfunc, tree input)
 return NULL_TREE;
 
   if (TREE_CODE_CLASS (ipa_get_jf_pass_through_operation (jfunc))
-  == tcc_comparison)
-restype = boolean_type_node;
+  == tcc_unary)
+res = fold_unary (ipa_get_jf_pass_through_operation (jfunc),
+ TREE_TYPE (input), input);
   else
-restype = TREE_TYPE (input);
-  res = fold_binary (ipa_get_jf_pass_through_operation (jfunc), restype,
-input, ipa_get_jf_pass_through_operand (jfunc));
-
+{
+  if (TREE_CODE_CLASS (ipa_get_jf_pass_through_operation (jfunc))
+ == tcc_comparison)
+   restype = boolean_type_node;
+  else
+   restype = TREE_TYPE (input);
+  res = fold_binary (ipa_get_jf_pass_through_operation (jfunc), restype,
+input, ipa_get_jf_pass_through_operand (jfunc));
+}
   if (res && !is_gimple_ip_invariant (res))
 return NULL_TREE;
 
@@ -1857,13 +1863,32 @@ propagate_vr_accross_jump_function (cgraph_edge *cs,
   if (jfunc->type == IPA_JF_PASS_THROUGH)
 {
   struct ipa_node_params *caller_info = IPA_NODE_REF (cs->caller);
-  if (dest_lat->bottom_p ())
-   return false;
   int src_idx = ipa_get_jf_pass_through_formal_id (jfunc);
   src_lats = ipa_get_parm_lattices (caller_info, src_idx);
 
   if (ipa_get_jf_pass_through_operation (jfunc) == NOP_EXPR)
return dest_lat->meet_with (src_lats->m_value_range);
+  else if (param_type
+  && (TREE_CODE_CLASS (ipa_get_jf_pass_through_operation (jfunc))
+  == tcc_unary))
+   {
+ value_range vr;
+ memset (&vr, 0, sizeof (vr));
+ tree operand_type = ipa_get_type (caller_info, src_idx);
+ enum tree_code operation = ipa_get_jf_pass_through_operation (jfunc);
+
+ if (src_lats->m_value_range.bottom_p ())
+   return dest_lat->set_to_bottom ();
+
+ extract_range_from_unary_expr (&vr,
+operation,
+param_type,
+&src_lats->m_value_range.m_vr,
+operand_type);
+ if (vr.type == VR_RANGE
+ || vr.type == VR_ANTI_RANGE)
+   return dest_lat->meet_with (&vr);
+   }
 }
   else if (jfunc->type == IPA_JF_CONST)
 {
diff --git a/gcc/ipa-prop.c b/gcc/ipa-prop.c
index 74fe199..6321fdd 100644
--- a/gcc/ipa-prop.c
+++ b/gcc/ipa-prop.c
@@ -446,6 +446,18 @@ ipa_set_jf_simple_pass_through (struct ipa_jump_func 
*jfunc, int formal_id,
   jfunc->value.pass_through.agg_preserved = agg_preserved;
 }
 
+/* Set JFUNC to be an unary pass through jump function.  */
+
+static void
+ipa_set_jf_unary_pass_through (struct ipa_jump_func *jfunc, int formal_id,
+  enum tree_code operation)
+{
+  jfunc->type = IPA_JF_PASS_THROUGH;
+  jfunc->value.pass_through.operand = NULL_TREE;
+  jfunc->value.pass_through.formal_id = formal_id;
+  jfunc->value.pass_through.operation = operation;
+  jfunc->value.pass_through.agg_preserved = false;
+}
 /* Set JFUNC to be an arithmetic pass through jump function.  */
 
 static void
@@ -849,21 +861,19 @@ parm_preserved_before_stmt_p (struct ipa_func_body_info 
*fbi, int index,
   return !modified;
 }
 
-/* If STMT is

Re: [Patch, Fortran, OOP] PR 66366: ICE on invalid with non-allocatable CLASS variable

2016-11-13 Thread Janus Weil
2016-11-13 0:57 GMT+01:00 Steve Kargl :
> On Sat, Nov 12, 2016 at 09:13:26PM +0100, Janus Weil wrote:
>>
>> this patch fixes an ICE on invalid code involving class component
>> declarations. The ICE is avoided by moving forward the error check
>> from resolution to parsing stage. For class components this is
>> possible, because the attributes have to be specified in the same line
>> (in contrast to class variables, where the attributes can be specified
>> in multiple statements, so that checking can only be done during
>> resolution).
>>
>> Note that this fixes only the original example, but not comment 2
>> (which is a different issue).
>>
>> Regtests cleanly on x86_64-linux-gnu. Ok for trunk?
>>
>
> Looks good to me.  Thanks.

Thanks! Committed as r242351.

Cheers,
Janus


Re: [fixincludes] Fix macOS 10.12 and (PR sanitizer/78267)

2016-11-13 Thread Rainer Orth
Hi Jack,

> On darwin15, the proposed patch is insufficient to restore the bootstrap
> (after running genfixes in the fixincludes directory) unless I also apply
> the previously proposed change...

no wonder: it's only been tested on darwin16.  Care to explain what
error you're seeing?

Rainer

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


[Patch, Fortran, committed] PR 60952: [F03] Problem using "end" as a type bound procedure and contained procedures

2016-11-13 Thread Janus Weil
Hi all,

I have just committed an obvious fix for a rejects-valid problem,
where a procedure named 'end' was not properly flagged as a procedure:

https://gcc.gnu.org/viewcvs?rev=242352&root=gcc&view=rev

Cheers,
Janus
Index: gcc/fortran/decl.c
===
--- gcc/fortran/decl.c  (Revision 242341)
+++ gcc/fortran/decl.c  (Arbeitskopie)
@@ -9615,6 +9615,8 @@ match_procedure_in_type (void)
false))
return MATCH_ERROR;
   gfc_set_sym_referenced (stree->n.tb->u.specific->n.sym);
+  gfc_add_flavor(&stree->n.tb->u.specific->n.sym->attr, FL_PROCEDURE,
+target, &stree->n.tb->u.specific->n.sym->declared_at);
 
   if (gfc_match_eos () == MATCH_YES)
return MATCH_YES;


Re: [RFC] Handle unary pass-through jump functions for ipa-vrp

2016-11-13 Thread Jan Hubicka
> Hi Honza,
> 
> I reverted this patch after it was reported that it resulted in
> bootstrap compare failure in some targets.
> 
> I reproduced it and tracked to a mistake in the patch that introduced it.
> 
> That is, in propagate_vr_accross_jump_function, I had:
> 
> if (src_lats->m_value_range.bottom_p ())
>   return false;
> 
> which should have been:
> 
> if (src_lats->m_value_range.bottom_p ())
>   return dest_lat->set_to_bottom ();

Oops, sorry for missing that :)
> 
> 
> I also fixed update_jump_functions_after_inlining as reported in pr78268.
> 
> I now bootstrapped the patch (lto and normal) on two affected
> targets aarch64-none-linux-gnu and powerpc64le-unknown-linux-gnu. I
> also tested it on x86_64-linux-gnu with no new regressions. Is this
> OK?

Yes, thanks for fixing the issue!

Can you, please, also send patch to https://gcc.gnu.org/gcc-7/changes.html
which mention the new features and command line options?

Honza

> 
> 
> Thanks,
> Kugan
> 
> 
> gcc/testsuite/ChangeLog:
> 
> 2016-11-13  Kugan Vivekanandarajah  
> 
>   * g++.dg/torture/pr78268.C: New test.
> 
> 
> gcc/ChangeLog:
> 
> 2016-11-13  Kugan Vivekanandarajah  
> 
>   * ipa-cp.c (ipa_get_jf_pass_through_result): Skip unary expressions.
>   (propagate_vr_accross_jump_function): Handle unary expressions.
>   * ipa-prop.c (ipa_set_jf_unary_pass_through): New.
>   (load_from_param_1): New.
>   (load_from_unmodified_param): Factor common part into load_from_param_1.
>   (load_from_param): New.
>   (compute_complex_assign_jump_func): Handle unary expressions.
>   (update_jump_functions_after_inlining): Likewise.
>   (ipa_write_jump_function): Likewise.
>   (ipa_read_jump_function): Likewise.
> 

> diff --git a/gcc/ipa-cp.c b/gcc/ipa-cp.c
> index 79e621a..2ec671f 100644
> --- a/gcc/ipa-cp.c
> +++ b/gcc/ipa-cp.c
> @@ -1219,13 +1219,19 @@ ipa_get_jf_pass_through_result (struct ipa_jump_func 
> *jfunc, tree input)
>  return NULL_TREE;
>  
>if (TREE_CODE_CLASS (ipa_get_jf_pass_through_operation (jfunc))
> -  == tcc_comparison)
> -restype = boolean_type_node;
> +  == tcc_unary)
> +res = fold_unary (ipa_get_jf_pass_through_operation (jfunc),
> +   TREE_TYPE (input), input);
>else
> -restype = TREE_TYPE (input);
> -  res = fold_binary (ipa_get_jf_pass_through_operation (jfunc), restype,
> -  input, ipa_get_jf_pass_through_operand (jfunc));
> -
> +{
> +  if (TREE_CODE_CLASS (ipa_get_jf_pass_through_operation (jfunc))
> +   == tcc_comparison)
> + restype = boolean_type_node;
> +  else
> + restype = TREE_TYPE (input);
> +  res = fold_binary (ipa_get_jf_pass_through_operation (jfunc), restype,
> +  input, ipa_get_jf_pass_through_operand (jfunc));
> +}
>if (res && !is_gimple_ip_invariant (res))
>  return NULL_TREE;
>  
> @@ -1857,13 +1863,32 @@ propagate_vr_accross_jump_function (cgraph_edge *cs,
>if (jfunc->type == IPA_JF_PASS_THROUGH)
>  {
>struct ipa_node_params *caller_info = IPA_NODE_REF (cs->caller);
> -  if (dest_lat->bottom_p ())
> - return false;
>int src_idx = ipa_get_jf_pass_through_formal_id (jfunc);
>src_lats = ipa_get_parm_lattices (caller_info, src_idx);
>  
>if (ipa_get_jf_pass_through_operation (jfunc) == NOP_EXPR)
>   return dest_lat->meet_with (src_lats->m_value_range);
> +  else if (param_type
> +&& (TREE_CODE_CLASS (ipa_get_jf_pass_through_operation (jfunc))
> +== tcc_unary))
> + {
> +   value_range vr;
> +   memset (&vr, 0, sizeof (vr));
> +   tree operand_type = ipa_get_type (caller_info, src_idx);
> +   enum tree_code operation = ipa_get_jf_pass_through_operation (jfunc);
> +
> +   if (src_lats->m_value_range.bottom_p ())
> + return dest_lat->set_to_bottom ();
> +
> +   extract_range_from_unary_expr (&vr,
> +  operation,
> +  param_type,
> +  &src_lats->m_value_range.m_vr,
> +  operand_type);
> +   if (vr.type == VR_RANGE
> +   || vr.type == VR_ANTI_RANGE)
> + return dest_lat->meet_with (&vr);
> + }
>  }
>else if (jfunc->type == IPA_JF_CONST)
>  {
> diff --git a/gcc/ipa-prop.c b/gcc/ipa-prop.c
> index 74fe199..6321fdd 100644
> --- a/gcc/ipa-prop.c
> +++ b/gcc/ipa-prop.c
> @@ -446,6 +446,18 @@ ipa_set_jf_simple_pass_through (struct ipa_jump_func 
> *jfunc, int formal_id,
>jfunc->value.pass_through.agg_preserved = agg_preserved;
>  }
>  
> +/* Set JFUNC to be an unary pass through jump function.  */
> +
> +static void
> +ipa_set_jf_unary_pass_through (struct ipa_jump_func *jfunc, int formal_id,
> +enum tree_code operation)
> +{
> +  jfunc->type = IPA_JF_PASS_THROUGH;
> +  jfunc->value.pass_through.operand

Re: [PATCH], Add PowerPC ISA 3.0 support for xxinsertw, vinserth, and vinsertb instructions

2016-11-13 Thread Segher Boessenkool
Hi Mike,

On Sun, Nov 13, 2016 at 01:03:29AM -0500, Michael Meissner wrote:
>   * gcc.target/powerpc/vec-set-short.c: Likesie.

Typo here.

> --- gcc/config/rs6000/rs6000.c
> (svn+ssh://meiss...@gcc.gnu.org/svn/gcc/trunk/gcc/config/rs6000)
> (revision 242318)
> +++ gcc/config/rs6000/rs6000.c(.../gcc/config/rs6000) (working copy)
> @@ -7095,12 +7095,32 @@ rs6000_expand_vector_set (rtx target, rt
>int width = GET_MODE_SIZE (inner_mode);
>int i;
>  
> -  if (VECTOR_MEM_VSX_P (mode) && (mode == V2DFmode || mode == V2DImode))
> +  if (VECTOR_MEM_VSX_P (mode))
>  {
> -  rtx (*set_func) (rtx, rtx, rtx, rtx)
> - = ((mode == V2DFmode) ? gen_vsx_set_v2df : gen_vsx_set_v2di);
> -  emit_insn (set_func (target, target, val, GEN_INT (elt)));
> -  return;
> +  rtx (*set_func) (rtx, rtx, rtx, rtx) = (rtx (*) (rtx, rtx, rtx, rtx))0;

Space after a cast.  But, do you need a function pointer at all?  I.e.
instead of

> +  if (mode == V2DFmode)
> + set_func = gen_vsx_set_v2df;
> +
> +  else if (mode == V2DImode)
> + set_func = gen_vsx_set_v2di;

do

  rtx_insn *insn = NULL;

  if (mode == V2DFmode)
insn = gen_vsx_set_v2df (target, target, val, GEN_INT (elt));

  else if (mode == V2DImode)
insn = gen_vsx_set_v2di (target, target, val, GEN_INT (elt));

[ snip ]

> +  if (set_func)
> + {
> +   emit_insn (set_func (target, target, val, GEN_INT (elt)));
> +   return;

  if (insn)
{
  emit_insn (insn);
  return;
}

(and maybe do that GEN_INT to a var as well).  Much more readable.


Segher


Fix ICE in initialize_inlined_parameters with LTO

2016-11-13 Thread Eric Botcazou
This is a regression present on the mainline and 6 branch: for the attached 
Ada testcase compiled in LTO mode, the following assertion triggers in 
initialize_inlined_parameters during inlining:

  if (p)
{
  /* No static chain?  Seems like a bug in tree-nested.c.  */
  gcc_assert (static_chain);

  setup_one_parameter (id, p, static_chain, fn, bb, &vars);
}

So we have a callee expecting a static chain but the caller doesn't pass one.
It turns out that the caller is a thunk created by the ICF pass (as a wrapper 
in ICF's terminology) so it definitely cannot pass a static chain.  Now ICF 
already makes sure that it doesn't create a wrapper in the opposite situation 
(alias expecting a static chain instead of original function) so the fixlet 
simply makes the test symmetric.

Tested on x86_64-suse-linux, applied on the mainline and 6 branch as obvious.


2016-11-13  Eric Botcazou  

* ipa-icf.c (sem_function::merge): Do not create a wrapper also if the
original function needs a static chain.


2016-11-13  Eric Botcazou  

* gnat.dg/lto21.adb: New test.
* gnat.dg/lto21_pkg1.ads: New helper.
* gnat.dg/lto21_pkg2.ad[sb]: Likewise.

-- 
Eric BotcazouIndex: ipa-icf.c
===
--- ipa-icf.c	(revision 242334)
+++ ipa-icf.c	(working copy)
@@ -1186,11 +1186,12 @@ sem_function::merge (sem_item *alias_ite
 	fprintf (dump_file,
 		 "Wrapper cannot be created because of COMDAT\n");
 	}
-  else if (DECL_STATIC_CHAIN (alias->decl))
+  else if (DECL_STATIC_CHAIN (alias->decl)
+	   || DECL_STATIC_CHAIN (original->decl))
 {
 	  if (dump_file)
 	fprintf (dump_file,
-		 "Can not create wrapper of nested functions.\n");
+		 "Cannot create wrapper of nested function.\n");
 }
   /* TODO: We can also deal with variadic functions never calling
 	 VA_START.  */
-- { dg-do run }
-- { dg-options "-O3 -flto" { target lto } }

with Lto21_Pkg1;
with Lto21_Pkg2; use Lto21_Pkg2;

procedure Lto21 is
begin
   Proc;
end;
with Ada.Containers.Vectors;
with Lto21_Pkg2;

package Lto21_Pkg1 is

   pragma Suppress (Tampering_Check);

   package Vect1 is new Ada.Containers.Vectors (Positive, Natural);

end Lto21_Pkg1;
with Ada.Containers; use Ada.Containers;
with Ada.Containers.Hashed_Maps;
with Ada.Containers.Vectors;

package body Lto21_Pkg2 is

   pragma Suppress (Tampering_Check);

   procedure Proc is

  function Hash (Syd : Natural) return Hash_Type is (Hash_Type'Mod (Syd));

  package Vect2 is new Vectors (Positive, Natural);

  package Maps is
new Hashed_Maps (Natural, Vect2.Vector, Hash, "=", Vect2."=");

  procedure Nested (M : Maps.Map) is
 use Maps;
 procedure Inner (Position : Cursor) is null;
  begin
 Iterate (M, Inner'Access);
  end;

  M : Maps.Map;
   begin
  Nested (M);
   end;

end Lto21_Pkg2;
package Lto21_Pkg2 is

   procedure Proc;

end Lto21_Pkg2;


Fix segfault on double typedef for enum with -fdump-ada-spec

2016-11-13 Thread Eric Botcazou
This happens with the C++ compiler only.

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


2016-11-13  Eric Botcazou  

c-family/
* c-ada-spec.c (print_ada_declaration): For typedef declarations, look
for nested types only if the type is a record or union and dump SLOC.


2016-11-13  Eric Botcazou  

* c-c++-common/dump-ada-spec-6.c: New test.

-- 
Eric Botcazou/* { dg-do compile } */
/* { dg-options "-fdump-ada-spec" } */

typedef enum {
Zero
} MyEnum;

typedef MyEnum SomethingElse; 

/* { dg-final { cleanup-ada-spec } } */
Index: c-ada-spec.c
===
--- c-ada-spec.c	(revision 242334)
+++ c-ada-spec.c	(working copy)
@@ -2813,7 +2813,7 @@ print_ada_declaration (pretty_printer *b
 		}
 	  else
 		{
-		  if (!TREE_VISITED (stub)
+		  if (RECORD_OR_UNION_TYPE_P (typ)
 		  && DECL_SOURCE_FILE (stub) == source_file_base)
 		dump_nested_types (buffer, stub, stub, true, spc);
 
@@ -2821,7 +2821,8 @@ print_ada_declaration (pretty_printer *b
 		  dump_generic_ada_node (buffer, t, type, spc, false, true);
 		  pp_string (buffer, " is ");
 		  dump_generic_ada_node (buffer, typ, type, spc, false, true);
-		  pp_semicolon (buffer);
+		  pp_string (buffer, ";  -- ");
+		  dump_sloc (buffer, t);
 		}
 
 	  TREE_VISITED (t) = 1;


Re: [www-patch] Document new -Wshadow= variants in gcc-7/changes.html

2016-11-13 Thread Mark Wielaard
On Sat, Nov 05, 2016 at 10:50:57PM +0100, Mark Wielaard wrote:
> The attached patch adds an explanation of the new
> -Wshadow=(global|local|compatible-local) to gcc-7/changes.html.
> 
> OK to commit?

Ping?

> Index: htdocs/gcc-7/changes.html
> ===
> RCS file: /cvs/gcc/wwwdocs/htdocs/gcc-7/changes.html,v
> retrieving revision 1.21
> diff -u -r1.21 changes.html
> --- htdocs/gcc-7/changes.html 26 Oct 2016 19:08:10 -  1.21
> +++ htdocs/gcc-7/changes.html 5 Nov 2016 20:41:35 -
> @@ -119,6 +119,60 @@
>~^
> ~
>%d
>  
> +
> +The -Wshadow warning has been split into 3
> +variants. -Wshadow=global warns for any shadowing.  This
> +is the default when using -Wshadow without any
> +argument.  -Wshadow=local only warns for a local variable
> +shadowing another local variable or
> +parameter. -Wshadow=compatible-local only warns for a
> +local variable shadowing another local variable or parameter whose
> +type is compatible (in C++ compatible means that the type of the
> +shadowing variable can be converted to that of the shadowed variable).
> +
> +The following example shows the different kinds of shadow
> +warnings:
> +enum operation { add, count };
> +struct container { int nr; };
> +
> +int
> +container_count (struct container c, int count)
> +{
> +  int r = 0;
> +  for (int count = 0; count > 0; count--)
> +{
> +  struct container count = c;
> +  r += count.nr;
> +}
> +  return r;
> +}
> +
> +-Wshadow=compatible-local will warn for the parameter being
> +shadowed with the same type:
> +warn-test.c:8:12: warning: 
> declaration of 'count' shadows a parameter [ class="boldmagenta">-Wshadow=compatible-local]
> +   for (int count = 0; count > 0; count--)
> +^
> +warn-test.c:5:42: note: shadowed 
> declaration is here
> + container_count (struct container c, int  class="boldcyan">count)
> +   class="boldcyan">^
> +
> +-Wshadow=local will warn for the above and for the shadowed
> +declaration with incompatible type:
> +warn-test.c:10:24: warning: 
> declaration of 'count' shadows a previous local [ class="boldmagenta">-Wshadow=local]
> +   struct container count = c;
> +^
> +warn-test.c:8:12: note: shadowed 
> declaration is here
> +   for (int count = 0; count > 0; count--)
> +^
> +
> +-Wshadow=global will warn for all of the above and the shadowing
> +of the global declaration: 
> +warn-test.c:5:42: warning: 
> declaration of 'count' shadows a global declaration [ class="boldmagenta">-Wshadow]
> + container_count (struct container c, int  class="boldmagenta">count)
> +   class="boldmagenta">^
> +warn-test.c:1:23: note: shadowed 
> declaration is here
> + enum operation { add, count };
> +class="boldcyan">^
>  
>  
>  C



Re: [PATCH] Fix -Wshadow warning in libiberty/cp-demangle.c

2016-11-13 Thread Mark Wielaard
On Sun, Nov 06, 2016 at 07:03:34PM +0100, Mark Wielaard wrote:
> On Sat, 2016-09-10 at 09:51 -0400, Eric Gallager wrote:
> > On 9/10/16, Ian Lance Taylor  wrote:
> > > I'm not sure about the patch to configure.ac/configure.  The last I
> > > looked -Wshadow would warn if a local variable shadows a global
> > > variable.  That can cause a pointless build break if some system
> > > header file defines a global variable that happens to have the same
> > > name as a local variable.  It's not a likely scenario but I don't see
> > > a need to court a build breakage.
> > >
> > Maybe if the patch to add -Wshadow-local went in, the configure script
> > could use that instead?
> 
> We now have -Wshadow=local. So the attached patch uses that for
> libiberty. Is the attached patch OK to commit?

Ping?

> From f6f938e8053b6caf393c35c6f96c946073ca9373 Mon Sep 17 00:00:00 2001
> From: Mark Wielaard 
> Date: Sun, 6 Nov 2016 17:36:06 +0100
> Subject: [PATCH] libiberty: Add -Wshadow=local to warning flags (if
>  supported).
> 
> libiberty/ChangeLog:
> 
>* configure.ac (ac_libiberty_warn_cflags): Add -Wshadow=local.
>* configure: Regenerated.
> ---
> diff --git a/libiberty/configure b/libiberty/configure
> index 0f8e9b9..5c4dda5 100755
> --- a/libiberty/configure
> +++ b/libiberty/configure
> @@ -4398,7 +4398,8 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu
>  ac_libiberty_warn_cflags=
>  save_CFLAGS="$CFLAGS"
>  for real_option in -W -Wall -Wwrite-strings -Wc++-compat \
> -   -Wstrict-prototypes; do
> +   -Wstrict-prototypes \
> +   -Wshadow=local; do
># Do the check with the no- prefix removed since gcc silently
># accepts any -Wno-* option on purpose
>case $real_option in
> diff --git a/libiberty/configure.ac b/libiberty/configure.ac
> index 9d3f298..1aa0c7c 100644
> --- a/libiberty/configure.ac
> +++ b/libiberty/configure.ac
> @@ -160,7 +160,8 @@ AC_SYS_LARGEFILE
>  AC_PROG_CPP_WERROR
>  
>  ACX_PROG_CC_WARNING_OPTS([-W -Wall -Wwrite-strings -Wc++-compat \
> -   -Wstrict-prototypes], [ac_libiberty_warn_cflags])
> +   -Wstrict-prototypes \
> +   -Wshadow=local], [ac_libiberty_warn_cflags])
>  ACX_PROG_CC_WARNING_ALMOST_PEDANTIC([], [ac_libiberty_warn_cflags])
>  
>  AC_PROG_CC_C_O
> -- 
> 1.8.3.1
> 



[Ada] Fix ICE on double renaming with chain of access types

2016-11-13 Thread Eric Botcazou
This is a regression present on the mainline and 6 branch: the compiler ICEs 
in the gimplifier on a double renaming with a chain of access types because 
there is a orphaned PLACEHOLDER_EXPR.

Tested on x86_64-suse-linux, applied on the mainline and 6 branch.


2016-11-13  Eric Botcazou  

* gcc-interface/utils2.c (gnat_protect_expr): Also protect only the
address if the expression is the component of a dereference.
Do not use a reference type for the final temporary reference.


2016-11-13  Eric Botcazou  

* gnat.dg/renaming11.ad[sb]: New test.

-- 
Eric BotcazouIndex: gcc-interface/utils2.c
===
--- gcc-interface/utils2.c	(revision 242334)
+++ gcc-interface/utils2.c	(working copy)
@@ -2586,6 +2586,12 @@ gnat_protect_expr (tree exp)
   return t;
 }
 
+  /* Likewise if we're indirectly referencing part of something.  */
+  if (code == COMPONENT_REF
+  && TREE_CODE (TREE_OPERAND (exp, 0)) == INDIRECT_REF)
+return build3 (code, type, gnat_protect_expr (TREE_OPERAND (exp, 0)),
+		   TREE_OPERAND (exp, 1), NULL_TREE);
+
   /* If this is a COMPONENT_REF of a fat pointer, save the entire fat pointer.
  This may be more efficient, but will also allow us to more easily find
  the match for the PLACEHOLDER_EXPR.  */
@@ -2605,9 +2611,7 @@ gnat_protect_expr (tree exp)
   /* Otherwise reference, protect the address and dereference.  */
   return
 build_unary_op (INDIRECT_REF, type,
-		save_expr (build_unary_op (ADDR_EXPR,
-	   build_reference_type (type),
-	   exp)));
+		save_expr (build_unary_op (ADDR_EXPR, NULL_TREE, exp)));
 }
 
 /* This is equivalent to stabilize_reference_1 in tree.c but we take an extra
-- { dg-do compile }

package body Renaming11 is

   function F (Arg: Ptr3) return Integer is
  V : Ptr1 renames Arg.all.all;
  I : Integer renames V.A(1);
   begin
  return I;
   end;

end Renaming11;
package Renaming11 is

   subtype Index_Type is Integer range 1..10;

   type Arr is array (Index_Type range <>) of Integer;

   type Rec (Min : Index_Type; Max : Index_Type) is record
  A : Arr (Min .. Max);
   end record;

   type Ptr1 is access Rec;

   type Ptr2 is access Ptr1;

   type Ptr3 is access Ptr2;

   function F (Arg : Ptr3) return Integer;

end Renaming11;


[Ada] Correctly annotate negative values for the front-end

2016-11-13 Thread Eric Botcazou
gigi cannot back-annotate negative values in expressions for the front-end 
directly because only non-negative values are supported directly.

Fixed thusly, tested on x86_64-suse-linux, applied on the mainline.


2016-11-13  Eric Botcazou  

* gcc-interface/decl.c (annotate_value) : Deal specially
with negative constants.

-- 
Eric BotcazouIndex: gcc-interface/decl.c
===
--- gcc-interface/decl.c	(revision 242334)
+++ gcc-interface/decl.c	(working copy)
@@ -8022,6 +8022,14 @@ annotate_value (tree gnu_size)
   switch (TREE_CODE (gnu_size))
 {
 case INTEGER_CST:
+  /* For negative values, build NEGATE_EXPR of the opposite.  Such values
+	 can appear for discriminants in expressions for variants.  */
+  if (tree_int_cst_sgn (gnu_size) < 0)
+	{
+	  tree t = wide_int_to_tree (sizetype, wi::neg (gnu_size));
+	  return annotate_value (build1 (NEGATE_EXPR, sizetype, t));
+	}
+
   return TREE_OVERFLOW (gnu_size) ? No_Uint : UI_From_gnu (gnu_size);
 
 case COMPONENT_REF:


Fwd: [fixincludes] Fix macOS 10.12 and (PR sanitizer/78267)

2016-11-13 Thread Jack Howarth
-- Forwarded message --
From: Jack Howarth 
Date: Sun, Nov 13, 2016 at 1:19 PM
Subject: Re: [fixincludes] Fix macOS 10.12 
and  (PR sanitizer/78267)
To: Rainer Orth 
Cc: GCC Patches , Bruce Korb 




On Sun, Nov 13, 2016 at 5:53 AM, Rainer Orth
 wrote:
>
> Hi Jack,
>
> > On darwin15, the proposed patch is insufficient to restore the bootstrap
> > (after running genfixes in the fixincludes directory) unless I also apply
> > the previously proposed change...
>
> no wonder: it's only been tested on darwin16.  Care to explain what
> error you're seeing?
>

The failure that I see on darwin15 using your proposed patches and
executing genfixes in fixincludes  before the build is...

libtool: compile:
/sw/src/fink.build/gcc7-7.0.0-1/darwin_objdir/./gcc/xgcc
-shared-libgcc -B/sw/src/fink.build/gcc7-7.0.0-1/darwin_objdir/./gcc
-nostdinc++ 
-L/sw/src/fink.build/gcc7-7.0.0-1/darwin_objdir/x86_64-apple-darwin15.6.0/libstdc++-v3/src
-L/sw/src/fink.build/gcc7-7.0.0-1/darwin_objdir/x86_64-apple-darwin15.6.0/libstdc++-v3/src/.libs
-L/sw/src/fink.build/gcc7-7.0.0-1/darwin_objdir/x86_64-apple-darwin15.6.0/libstdc++-v3/libsupc++/.libs
-B/sw/lib/gcc7/x86_64-apple-darwin15.6.0/bin/
-B/sw/lib/gcc7/x86_64-apple-darwin15.6.0/lib/ -isystem
/sw/lib/gcc7/x86_64-apple-darwin15.6.0/include -isystem
/sw/lib/gcc7/x86_64-apple-darwin15.6.0/sys-include -D_GNU_SOURCE
-D_DEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS
-D__STDC_LIMIT_MACROS -DHAVE_RPC_XDR_H=0 -DHAVE_TIRPC_RPC_XDR_H=0 -I.
-I../../../../gcc-7-20161113/libsanitizer/sanitizer_common -I.. -I
../../../../gcc-7-20161113/libsanitizer/include -isystem
../../../../gcc-7-20161113/libsanitizer/include/system -Wall -W
-Wno-unused-parameter -Wwrite-strings -pedantic -Wno-long-long -fPIC
-fno-builtin -fno-exceptions -fno-rtti -fomit-frame-pointer
-funwind-tables -fvisibility=hidden -Wno-variadic-macros
-I../../libstdc++-v3/include
-I../../libstdc++-v3/include/x86_64-apple-darwin15.6.0
-I../../../../gcc-7-20161113/libsanitizer/../libstdc++-v3/libsupc++
-std=gnu++11 -g -O2 -MT sanitizer_mac.lo -MD -MP -MF
.deps/sanitizer_mac.Tpo -c
../../../../gcc-7-20161113/libsanitizer/sanitizer_common/sanitizer_mac.cc
 -fno-common -DPIC -o .libs/sanitizer_mac.o
../../../../gcc-7-20161113/libsanitizer/sanitizer_common/sanitizer_mac.cc:497:0:
warning: ignoring #pragma clang diagnostic [-Wunknown-pragmas]
   os_trace("Address Sanitizer reported a failure.");

../../../../gcc-7-20161113/libsanitizer/sanitizer_common/sanitizer_mac.cc:497:0:
warning: ignoring #pragma clang diagnostic [-Wunknown-pragmas]
../../../../gcc-7-20161113/libsanitizer/sanitizer_common/sanitizer_mac.cc:497:0:
warning: ignoring #pragma clang diagnostic [-Wunknown-pragmas]
../../../../gcc-7-20161113/libsanitizer/sanitizer_common/sanitizer_mac.cc:500:0:
warning: ignoring #pragma clang diagnostic [-Wunknown-pragmas]
   os_trace("Undefined Behavior Sanitizer reported a failure.");

../../../../gcc-7-20161113/libsanitizer/sanitizer_common/sanitizer_mac.cc:500:0:
warning: ignoring #pragma clang diagnostic [-Wunknown-pragmas]
../../../../gcc-7-20161113/libsanitizer/sanitizer_common/sanitizer_mac.cc:500:0:
warning: ignoring #pragma clang diagnostic [-Wunknown-pragmas]
../../../../gcc-7-20161113/libsanitizer/sanitizer_common/sanitizer_mac.cc:503:0:
warning: ignoring #pragma clang diagnostic [-Wunknown-pragmas]
   os_trace("Thread Sanitizer reported a failure.");

../../../../gcc-7-20161113/libsanitizer/sanitizer_common/sanitizer_mac.cc:503:0:
warning: ignoring #pragma clang diagnostic [-Wunknown-pragmas]
../../../../gcc-7-20161113/libsanitizer/sanitizer_common/sanitizer_mac.cc:503:0:
warning: ignoring #pragma clang diagnostic [-Wunknown-pragmas]
../../../../gcc-7-20161113/libsanitizer/sanitizer_common/sanitizer_mac.cc:505:0:
warning: ignoring #pragma clang diagnostic [-Wunknown-pragmas]
   os_trace("Sanitizer tool reported a failure.");

../../../../gcc-7-20161113/libsanitizer/sanitizer_common/sanitizer_mac.cc:505:0:
warning: ignoring #pragma clang diagnostic [-Wunknown-pragmas]
../../../../gcc-7-20161113/libsanitizer/sanitizer_common/sanitizer_mac.cc:505:0:
warning: ignoring #pragma clang diagnostic [-Wunknown-pragmas]
../../../../gcc-7-20161113/libsanitizer/sanitizer_common/sanitizer_mac.cc:508:0:
warning: ignoring #pragma clang diagnostic [-Wunknown-pragmas]
   os_trace("Consult syslog for more information.");

../../../../gcc-7-20161113/libsanitizer/sanitizer_common/sanitizer_mac.cc:508:0:
warning: ignoring #pragma clang diagnostic [-Wunknown-pragmas]
../../../../gcc-7-20161113/libsanitizer/sanitizer_common/sanitizer_mac.cc:508:0:
warning: ignoring #pragma clang diagnostic [-Wunknown-pragmas]
In file included from
../../../../gcc-7-20161113/libsanitizer/sanitizer_common/sanitizer_mac.cc:39:0:
/sw/src/fink.build/gcc7-7.0.0-1/darwin_objdir/gcc/include-fixed/os/trace.h:56:47:
error: attributes are not al

[Ada] Fix bogus warning on address conversion

2016-11-13 Thread Eric Botcazou
This occurs because System.Address is a private type so you need to invoke 
Underlying_Type before testing whether it is unsigned.

Fixed thusly, tested on x86_64-suse-linux, applied on the mainline.


2016-11-13  Eric Botcazou  

* gcc-interface/decl.c (gnat_to_gnu_entity):
Look at the underlying type for the signedness of the type.


2016-11-13  Eric Botcazou  

* gnat.dg/address_conv.adb: New test.

-- 
Eric BotcazouIndex: gcc-interface/decl.c
===
--- gcc-interface/decl.c	(revision 242360)
+++ gcc-interface/decl.c	(working copy)
@@ -1836,7 +1836,7 @@ gnat_to_gnu_entity (Entity_Id gnat_entit
 	  && esize == CHAR_TYPE_SIZE
 	  && flag_signed_char)
 	gnu_type = make_signed_type (CHAR_TYPE_SIZE);
-  else if (Is_Unsigned_Type (Etype (gnat_entity))
+  else if (Is_Unsigned_Type (Underlying_Type (Etype (gnat_entity)))
 	   || (Esize (Etype (gnat_entity)) != Esize (gnat_entity)
 		   && Is_Unsigned_Type (gnat_entity))
 	   || Has_Biased_Representation (gnat_entity))
--  { dg-do compile }

with System.Storage_Elements; use System.Storage_Elements;

procedure Address_Conv is

  subtype My_Address is System.Address;

  type Rec is record
A : My_Address;
  end record;

  Addr : constant My_Address := To_Address (16#FACEFACE#);

  R : constant Rec := (A => Addr);

begin
  null;
end;


PATCH, testsuite]: Add test for PR 78248 (aka 78232)

2016-11-13 Thread Uros Bizjak
Attached patch adds the testcase from (fixed) PR 78248.

2016-11-13  Uros Bizjak  

PR rtl-optimization/78232
PR rtl-optimization/78248
* gcc.dg/ubsan/pr78248.c: New test.

Tested on x86_64-linux-gnu {,-m32} and committed to mainline SVN.

Uros.
Index: gcc.dg/ubsan/pr78248.c
===
--- gcc.dg/ubsan/pr78248.c  (nonexistent)
+++ gcc.dg/ubsan/pr78248.c  (working copy)
@@ -0,0 +1,31 @@
+/* PR rtl-optimization/78232 */
+/* PR rtl-optimization/78248 */
+/* { dg-do run } */
+/* { dg-options "-fsanitize=undefined" } */
+
+static struct S
+{
+  int f0:15;
+} a;
+
+int b[1], c = 2, d, e, f, g;
+
+int main ()
+{
+  struct S h = { -2 };
+  for (; e < 640; e++)
+for (; f < 1; f++)
+  {
+if (c < 2)
+  {
+d = b[e];
+h = a;
+  }
+g = c;
+c = 1;
+if (!h.f0)
+  break;
+c = g;
+  }
+  return 0; 
+}


[Ada] Fix problematic assertion

2016-11-13 Thread Eric Botcazou
Tested on x86_64-suse-linux, applied on all active branches.


2016-11-13  Bob Duff  

* gcc-interface/decl.c (gnat_to_gnu_entity): In assertion about known
Esize, protect with !is_type and change !Unknown_Esize to Known_Esize.

-- 
Eric BotcazouIndex: gcc-interface/decl.c
===
--- gcc-interface/decl.c	(revision 324888)
+++ gcc-interface/decl.c	(revision 324889)
@@ -388,7 +388,8 @@ gnat_to_gnu_entity (Entity_Id gnat_entit
  must be specified unless it was specified by the programmer.  Exceptions
  are for access-to-protected-subprogram types and all access subtypes, as
  another GNAT type is used to lay out the GCC type for them.  */
-  gcc_assert (!Unknown_Esize (gnat_entity)
+  gcc_assert (!is_type
+	  || Known_Esize (gnat_entity)
 	  || Has_Size_Clause (gnat_entity)
 	  || (!IN (kind, Numeric_Kind)
 		  && !IN (kind, Enumeration_Kind)


Re: [ping * 4] PR35503 - warn for restrict

2016-11-13 Thread Prathamesh Kulkarni
On 2 November 2016 at 23:17, Prathamesh Kulkarni
 wrote:
> On 2 November 2016 at 23:07, Jason Merrill  wrote:
>> On Wed, Nov 2, 2016 at 1:08 PM, Prathamesh Kulkarni
>>  wrote:
>>> On 2 November 2016 at 18:29, Jason Merrill  wrote:
 Then I'll approve the whole patch.
>>> Thanks!
>>> Trying the patch on kernel build (allmodconfig) reveals the following
>>> couple of warnings:
>>> http://pastebin.com/Sv2HFDUv
>>>
>>> I think warning for str_error_r() is correct
>>
>> It's accurate, but unhelpful; snprintf isn't going to use the contents
>> of buf via the variadic argument, so this warning is just noise.
> Ah, indeed, it's just printing address of buf, not using the contents.
>>
>>> however I am not sure if
>>> warning for pager_preexec() is legit or a false positive:
>>>
>>> pager.c: In function 'pager_preexec':
>>> pager.c:35:12: warning: passing argument 2 to restrict-qualified
>>> parameter aliases with argument 4 [-Wrestrict]
>>>   select(1, &in, NULL, &in, NULL);
>>>  ^~~~~~
>>> Is the warning correct for  the above call to select() syscall ?
>>
>> The warning looks correct based on the prototype
>>
>> extern int select (int __nfds, fd_set *__restrict __readfds,
>>fd_set *__restrict __writefds,
>>fd_set *__restrict __exceptfds,
>>struct timeval *__restrict __timeout);
>>
>> But passing the same fd_set to both readfds and exceptfds seems
>> reasonable to me, so this also seems like a false positive.
>>
>> Looking at C11, I see this example:
>>
>> EXAMPLE 3 The function parameter declarations
>> void h(int n, int * restrict p, int * restrict q, int * restrict r)
>> {
>>   int i;
>>   for (i = 0; i < n; i++)
>> p[i] = q[i] + r[i];
>> }
>>
>> illustrate how an unmodified object can be aliased through two
>> restricted pointers. In particular, if a and b
>> are disjoint arrays, a call of the form h(100, a, b, b) has defined
>> behavior, because array b is not
>> modified within function h.
>>
>> This is is another example of well-defined code that your warning will
>> complain about.
> Yes, that's a limitation of the patch, it just looks at the prototype, and
> not how the arguments are used in the function.
>>
>>> Should we instead keep it in Wextra, or continue keeping it in Wall ?
>>
>> It seems that it doesn't belong in -Wall.  I don't feel strongly about 
>> -Wextra.
> Should I commit the patch by keeping Wrestrict "standalone",
> ie, not including it in either Wall or Wextra ?
Hi,
After Joseph and Jason's approval, I have committed a rebased version
of patch as r242366
after bootstrap+test on x86_64-unknown-linux-gnu, cross-test on
arm*-*-*, aarch64*-*-* and
verifying no warning is triggered on kernel build with make
allmodconfig && make all.
Because the patch only looks at function prototype, there could be
false positives with the warning (restrict example 3 in C11 std),
and hence the warning isn't enabled by default, and neither by Wall or Wextra.
The warning is only enabled with -Wrestrict option.

Thanks,
Prathamesh
>
> Thanks,
> Prathamesh
>>
>> Jason


[v3 PATCH] Implement P0403R1, Literal suffixes for basic_string_view.

2016-11-13 Thread Ville Voutilainen
Tested on Linux-x64.

2016-11-13  Ville Voutilainen  

Implement P0403R1, Literal suffixes for basic_string_view.
* include/std/string_view
(operator""sv(const char*, size_t)): New.
(operator""sv(const wchar_t*, size_t)): Likewise.
(operator""sv(const char16_t*, size_t)): Likewise.
(operator""sv(const char32_t*, size_t)): Likewise.
* testsuite/21_strings/basic_string_view/literals/types.cc: New.
* testsuite/21_strings/basic_string_view/literals/values.cc: Likewise.
* testsuite/experimental/string_view/literals/values.cc: Add
tests for literals with embedded NULs.
diff --git a/libstdc++-v3/include/std/string_view 
b/libstdc++-v3/include/std/string_view
index b2d2a29..cf728dd 100644
--- a/libstdc++-v3/include/std/string_view
+++ b/libstdc++-v3/include/std/string_view
@@ -640,6 +640,36 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 { };
 #endif
 
+  inline namespace literals
+  {
+  inline namespace string_view_literals
+  {
+  _GLIBCXX_BEGIN_NAMESPACE_VERSION
+
+inline constexpr basic_string_view
+operator""sv(const char* __str, size_t __len)
+{ return basic_string_view{__str, __len}; }
+
+#ifdef _GLIBCXX_USE_WCHAR_T
+inline constexpr basic_string_view
+operator""sv(const wchar_t* __str, size_t __len)
+{ return basic_string_view{__str, __len}; }
+#endif
+
+#ifdef _GLIBCXX_USE_C99_STDINT_TR1
+inline constexpr basic_string_view
+operator""sv(const char16_t* __str, size_t __len)
+{ return basic_string_view{__str, __len}; }
+
+inline constexpr basic_string_view
+operator""sv(const char32_t* __str, size_t __len)
+{ return basic_string_view{__str, __len}; }
+#endif
+
+  _GLIBCXX_END_NAMESPACE_VERSION
+  } // namespace string_literals
+  } // namespace literals
+
 _GLIBCXX_END_NAMESPACE_VERSION
 } // namespace std
 
diff --git 
a/libstdc++-v3/testsuite/21_strings/basic_string_view/literals/types.cc 
b/libstdc++-v3/testsuite/21_strings/basic_string_view/literals/types.cc
new file mode 100644
index 000..42e8b16
--- /dev/null
+++ b/libstdc++-v3/testsuite/21_strings/basic_string_view/literals/types.cc
@@ -0,0 +1,45 @@
+// { dg-options "-std=gnu++17" }
+// { dg-do compile }
+
+// Copyright (C) 2013-2016 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// .
+
+#include 
+#include 
+
+void
+test01()
+{
+  using namespace std::literals::string_view_literals;
+
+  static_assert(std::is_same::value,
+   "\"Hello\"s is std::string_view");
+
+  static_assert(std::is_same::value,
+   "u8\"Hello\"s is std::string_view");
+
+#ifdef _GLIBCXX_USE_WCHAR_T
+  static_assert(std::is_same::value,
+   "L\"Hello\"s is std::wstring_view");
+#endif
+
+  static_assert(std::is_same::value,
+   "u\"Hello\"s is std::u16string_view");
+
+  static_assert(std::is_same::value,
+   "U\"Hello\"s is std::u32string_view");
+}
diff --git 
a/libstdc++-v3/testsuite/21_strings/basic_string_view/literals/values.cc 
b/libstdc++-v3/testsuite/21_strings/basic_string_view/literals/values.cc
new file mode 100644
index 000..bbaa70e
--- /dev/null
+++ b/libstdc++-v3/testsuite/21_strings/basic_string_view/literals/values.cc
@@ -0,0 +1,72 @@
+// { dg-options "-std=gnu++17" }
+
+// Copyright (C) 2013-2016 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// .
+
+#include 
+#include 
+
+void
+test01()
+{
+  using namespace std::literals::string_view_literals;
+
+  std::string_view planet = "Mercury"sv;
+#ifdef _GLIBCXX_USE_WCHAR_T
+  std::wstring_view wplanet = L"Venus"sv;
+#endif
+  std::string_view u8planet = u8"Mars"sv;
+  std::u16string_view u16planet 

Re: [v3 PATCH] Implement P0403R1, Literal suffixes for basic_string_view.

2016-11-13 Thread Jonathan Wakely

On 13/11/16 22:41 +0200, Ville Voutilainen wrote:

   Implement P0403R1, Literal suffixes for basic_string_view.
   * include/std/string_view
   (operator""sv(const char*, size_t)): New.
   (operator""sv(const wchar_t*, size_t)): Likewise.
   (operator""sv(const char16_t*, size_t)): Likewise.
   (operator""sv(const char32_t*, size_t)): Likewise.
   * testsuite/21_strings/basic_string_view/literals/types.cc: New.
   * testsuite/21_strings/basic_string_view/literals/values.cc: Likewise.
   * testsuite/experimental/string_view/literals/values.cc: Add
   tests for literals with embedded NULs.


OK for trunk, thanks.




Re: [v3 PATCH] Implement P0504R0 (Revisiting in-place tag types for any/optional/variant).

2016-11-13 Thread Jonathan Wakely

On 12/11/16 21:24 +0200, Ville Voutilainen wrote:

+  inline in_place_t in_place{};
+
+  template struct in_place_type_t
+  {
+explicit in_place_type_t() = default;
+  };
+
+  template
+in_place_type_t<_Tp> in_place_type{};
+
+  template struct in_place_index_t
+  {
+explicit in_place_index_t() = default;
+  };
+
+  template
+in_place_index_t<_Idx> in_place_index{};


I was told there's a Core issue that says these are not actually
inline variables unless they say "inline". Not sure which issue that
is, but G++ does the right thing and makes them globally unique,
rather than having internal linkage.

(At LWG's request P0504R0 marked them inline just to be safe.)

OK for trunk, thanks.



Re: [v3 PATCH] Use constexpr addressof in optional, SFINAE housekeeping for any, optional and tuple.

2016-11-13 Thread Jonathan Wakely

On 26/10/16 20:10 +0300, Ville Voutilainen wrote:

   Use constexpr addressof in optional, SFINAE housekeeping
   for any, optional and tuple.
   * include/std/any (__do_emplace(_Args&&...)): New.
   (__do_emplace(initializer_list<_Up>, _Args&&...)): Likewise.
   (__any_constructible): Likewise.
   (__any_constructible_t): Use __any_constructible.
   (operator=(_ValueType&&)): SFINAE in the return type.
   (emplace(_Args&&...)): Likewise.
   (emplace(initializer_list<_Up>, _Args&&...)): Likewise.
   * include/std/optional (_Has_addressof_mem): Remove.
   (_Has_addressof_free): Likewise.
   (_Has_addressof): Likewise.
   (__constexpr_addressof(_Tp&)): Likewise.
   (operator->): Use std::__addressof.
   * include/std/tuple (operator=(const tuple<_UElements...>&)):
   SFINAE in return type.
   (operator=(tuple<_UElements...>&&)): Likewise.
   * testsuite/20_util/any/misc/any_cast_neg.cc: Adjust.


OK for trunk, thanks.



Re: [v3 PATCH] Implement P0504R0 (Revisiting in-place tag types for any/optional/variant).

2016-11-13 Thread Jonathan Wakely

On 13/11/16 21:02 +, Jonathan Wakely wrote:

On 12/11/16 21:24 +0200, Ville Voutilainen wrote:

+  inline in_place_t in_place{};
+
+  template struct in_place_type_t
+  {
+explicit in_place_type_t() = default;
+  };
+
+  template
+in_place_type_t<_Tp> in_place_type{};
+
+  template struct in_place_index_t
+  {
+explicit in_place_index_t() = default;
+  };
+
+  template
+in_place_index_t<_Idx> in_place_index{};


I was told there's a Core issue that says these are not actually
inline variables unless they say "inline". Not sure which issue that
is, but G++ does the right thing and makes them globally unique,
rather than having internal linkage.

(At LWG's request P0504R0 marked them inline just to be safe.)

OK for trunk, thanks.


Oh, they aren't actually constexpr in your patch, so non-const, and so
don't get internal linkage. But they *should* be constexpr, please add
that to all three, and add inline to the two variable templates.




[PATCH] PR fortran/78300 -- class procedure as actual arg

2016-11-13 Thread Steve Kargl
The attach patch allows a procedure with a class result to
be an actual argument to subprogram where the dummy argument
expected to be a class.  OK to commit?

2016-11-14  Steven G. Kargl  

PR fortran/78300
* resolve.c (resolve_fl_var_and_proc): Allow class procedure an
actual argument.


2016-11-14  Steven G. Kargl  

PR fortran/78300
* gfortran.dg/pr78300.f90: New test.

-- 
Steve
Index: gcc/fortran/resolve.c
===
--- gcc/fortran/resolve.c	(revision 242362)
+++ gcc/fortran/resolve.c	(working copy)
@@ -11705,7 +11705,8 @@ resolve_fl_var_and_proc (gfc_symbol *sym
   /* Assume that use associated symbols were checked in the module ns.
 	 Class-variables that are associate-names are also something special
 	 and excepted from the test.  */
-  if (!sym->attr.class_ok && !sym->attr.use_assoc && !sym->assoc)
+  if (!sym->attr.class_ok && !sym->attr.use_assoc && !sym->attr.dummy
+	  && !sym->assoc)
 	{
 	  gfc_error ("CLASS variable %qs at %L must be dummy, allocatable "
 		 "or pointer", sym->name, &sym->declared_at);
Index: gcc/testsuite/gfortran.dg/pr78300.f90
===
--- gcc/testsuite/gfortran.dg/pr78300.f90	(nonexistent)
+++ gcc/testsuite/gfortran.dg/pr78300.f90	(working copy)
@@ -0,0 +1,38 @@
+! { dg-do compile }
+module gfc_base
+
+   implicit none
+
+   integer, parameter:: INTD=4
+   integer, parameter:: INTL=8
+   integer(INTD), parameter :: GFC_FALSE=0
+
+   type gfc_cont_elem_t
+  class(*), pointer, private:: value_p=>NULL()
+  integer(INTD), private:: alloc=GFC_FALSE
+  contains
+ procedure, public:: construct=>ContElemConstruct
+   end type gfc_cont_elem_t
+
+   abstract interface
+  function gfc_copy_i(obj,ierr) result(clone)
+ import:: INTD
+ class(*), pointer:: clone
+ class(*), intent(in):: obj
+ integer(INTD), intent(out), optional:: ierr
+  end function gfc_copy_i
+   end interface
+
+   private ContElemConstruct
+
+   contains
+
+  subroutine ContElemConstruct(this,obj,ierr,assoc_only,copy_constr_func)
+ class(gfc_cont_elem_t), intent(inout):: this
+ class(*), target, intent(in):: obj
+ integer(INTD), intent(out), optional:: ierr
+ logical, intent(in), optional:: assoc_only
+ procedure(gfc_copy_i), optional:: copy_constr_func
+  end subroutine ContElemConstruct
+
+ end module gfc_base


[Aarch64] Enable descriptors for nested functions in Ada

2016-11-13 Thread Eric Botcazou
Similarly to x86, PowerPC and SPARC, this enables the use of custom run-time 
descriptors in Ada, thus eliminating the need for trampolines and executable 
stack in presence of pointers to nested functions.

Tested on Aarch64/Linux, OK for the mainline?


2016-11-13  Eric Botcazou  

PR ada/67205
* config/aarch64/aarch64.c (TARGET_CUSTOM_FUNCTION_DESCRIPTORS):
Define.

-- 
Eric BotcazouIndex: config/aarch64/aarch64.c
===
--- config/aarch64/aarch64.c	(revision 242334)
+++ config/aarch64/aarch64.c	(working copy)
@@ -14502,6 +14502,10 @@ aarch64_optab_supported_p (int op, machi
 #undef TARGET_OMIT_STRUCT_RETURN_REG
 #define TARGET_OMIT_STRUCT_RETURN_REG true
 
+/* The architecture reserves bits 0 and 1 so use bit 2 for descriptors.  */
+#undef TARGET_CUSTOM_FUNCTION_DESCRIPTORS
+#define TARGET_CUSTOM_FUNCTION_DESCRIPTORS 4
+
 struct gcc_target targetm = TARGET_INITIALIZER;
 
 #include "gt-aarch64.h"


[MIPS] Enable descriptors for nested functions in Ada

2016-11-13 Thread Eric Botcazou
Similarly to x86, PowerPC and SPARC, this enables the use of custom run-time 
descriptors in Ada, thus eliminating the need for trampolines and executable 
stack in presence of pointers to nested functions.

Unfortunately I don't have access to MIPS hardware any more, but the scheme 
was tested on the architecture at some point.  OK for the mainline?


2016-11-13  Eric Botcazou  

PR ada/67205
* config/mips/mips.c (TARGET_CUSTOM_FUNCTION_DESCRIPTORS): Define.

-- 
Eric BotcazouIndex: config/mips/mips.c
===
--- config/mips/mips.c	(revision 242334)
+++ config/mips/mips.c	(working copy)
@@ -22387,6 +22387,10 @@ mips_promote_function_mode (const_tree t
 #undef TARGET_HARD_REGNO_SCRATCH_OK
 #define TARGET_HARD_REGNO_SCRATCH_OK mips_hard_regno_scratch_ok
 
+/* The architecture reserves bit 0 for MIPS16 so use bit 1 for descriptors.  */
+#undef TARGET_CUSTOM_FUNCTION_DESCRIPTORS
+#define TARGET_CUSTOM_FUNCTION_DESCRIPTORS 2
+
 struct gcc_target targetm = TARGET_INITIALIZER;
 
 #include "gt-mips.h"


[ARM] Enable descriptors for nested functions in Ada

2016-11-13 Thread Eric Botcazou
Similarly to x86, PowerPC and SPARC, this enables the use of custom run-time 
descriptors in Ada, thus eliminating the need for trampolines and executable 
stack in presence of pointers to nested functions.

This still uses bit 1 for the run-time identification scheme because bumping 
the function alignment to 64 bits seems undesirable in Thumb mode.

Tested on ARM/Linux, OK for the mainline?


2016-11-13  Eric Botcazou  

PR ada/67205
* config/arm/arm.c (TARGET_CUSTOM_FUNCTION_DESCRIPTORS): Define.
(arm_function_ok_for_sibcall): Return false for an indirect call by
descriptor if all the argument registers are used.
(arm_relayout_function): Use FUNCTION_ALIGNMENT macro to adjust the
alignment of the function.

-- 
Eric BotcazouIndex: config/arm/arm.c
===
--- config/arm/arm.c	(revision 242334)
+++ config/arm/arm.c	(working copy)
@@ -738,6 +738,11 @@ static const struct attribute_spec arm_a
 #undef TARGET_EXPAND_DIVMOD_LIBFUNC
 #define TARGET_EXPAND_DIVMOD_LIBFUNC arm_expand_divmod_libfunc
 
+/* Although the architecture reserves bits 0 and 1, only the former is
+   used for ARM/Thumb ISA selection in v7 and earlier versions.  */
+#undef TARGET_CUSTOM_FUNCTION_DESCRIPTORS
+#define TARGET_CUSTOM_FUNCTION_DESCRIPTORS 2
+
 struct gcc_target targetm = TARGET_INITIALIZER;
 
 /* Obstack for minipool constant handling.  */
@@ -6810,6 +6815,29 @@ arm_function_ok_for_sibcall (tree decl,
   && DECL_WEAK (decl))
 return false;
 
+  /* We cannot do a tailcall for an indirect call by descriptor if all the
+ argument registers are used because the only register left to load the
+ address is IP and it will already contain the static chain.  */
+  if (!decl && CALL_EXPR_BY_DESCRIPTOR (exp) && !flag_trampolines)
+{
+  tree fntype = TREE_TYPE (TREE_TYPE (CALL_EXPR_FN (exp)));
+  CUMULATIVE_ARGS cum;
+  cumulative_args_t cum_v;
+
+  arm_init_cumulative_args (&cum, fntype, NULL_RTX, NULL_TREE);
+  cum_v = pack_cumulative_args (&cum);
+
+  for (tree t = TYPE_ARG_TYPES (fntype); t; t = TREE_CHAIN (t))
+	{
+	  tree type = TREE_VALUE (t);
+	  if (!VOID_TYPE_P (type))
+	arm_function_arg_advance (cum_v, TYPE_MODE (type), type, true);
+	}
+
+  if (!arm_function_arg (cum_v, SImode, integer_type_node, true))
+	return false;
+}
+
   /* Everything else is ok.  */
   return true;
 }
@@ -29101,7 +29129,9 @@ arm_relayout_function (tree fndecl)
 callee_tree = target_option_default_node;
 
   struct cl_target_option *opts = TREE_TARGET_OPTION (callee_tree);
-  SET_DECL_ALIGN (fndecl, FUNCTION_BOUNDARY_P (opts->x_target_flags));
+  SET_DECL_ALIGN
+(fndecl,
+ FUNCTION_ALIGNMENT (FUNCTION_BOUNDARY_P (opts->x_target_flags)));
 }
 
 /* Inner function to process the attribute((target(...))), take an argument and


[patch] Disable LTO note about strict aliasing

2016-11-13 Thread Eric Botcazou
It's the note issued by the -Wlto-type-mismatch warning:

q.ads:7:13: warning: type of 'q__proc' does not match original declaration [-
Wlto-type-mismatch]
   procedure Proc (A : Arr);
 ^
q.adb:7:3: note: 'q__proc' was previously declared here
   procedure Proc (A : Arr) is begin null; end;
   ^
q.adb:7:3: note: code may be misoptimized unless -fno-strict-aliasing is used

and it's a bit surprising that -fno-strict-aliasing cannot silence it.


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


2016-11-13  Eric Botcazou  

lto/
* lto-symtab.c (lto_symtab_merge_decls_2): Only issue note on strict
aliasing if -fstrict-aliasing is enabled.

-- 
Eric Botcazoucommit 934002ff6d710418af4b7f993f6216e9406d82c2
Author: Eric Botcazou 
Date:   Sun Nov 13 11:36:32 2016 +0100

Fix for PB12-008 (disable LTO note on misoptimization with strict aliasing).

diff --git a/gcc/lto/lto-symtab.c b/gcc/lto/lto-symtab.c
index 94b919b..c8848a5 100644
--- a/gcc/lto/lto-symtab.c
+++ b/gcc/lto/lto-symtab.c
@@ -698,7 +698,7 @@ lto_symtab_merge_decls_2 (symtab_node *first, bool diagnosed_p)
   if (diagnosed_p)
 inform (DECL_SOURCE_LOCATION (prevailing->decl),
 	"%qD was previously declared here", prevailing->decl);
-  if (tbaa_p)
+  if (tbaa_p && flag_strict_aliasing)
 inform (DECL_SOURCE_LOCATION (prevailing->decl),
 	"code may be misoptimized unless "
 	"-fno-strict-aliasing is used");


Re: [v3 PATCH] Implement P0504R0 (Revisiting in-place tag types for any/optional/variant).

2016-11-13 Thread Jonathan Wakely

On 13/11/16 21:10 +, Jonathan Wakely wrote:

On 13/11/16 21:02 +, Jonathan Wakely wrote:

On 12/11/16 21:24 +0200, Ville Voutilainen wrote:

+  inline in_place_t in_place{};
+
+  template struct in_place_type_t
+  {
+explicit in_place_type_t() = default;
+  };
+
+  template
+in_place_type_t<_Tp> in_place_type{};
+
+  template struct in_place_index_t
+  {
+explicit in_place_index_t() = default;
+  };
+
+  template
+in_place_index_t<_Idx> in_place_index{};


I was told there's a Core issue that says these are not actually
inline variables unless they say "inline". Not sure which issue that
is, but G++ does the right thing and makes them globally unique,
rather than having internal linkage.

(At LWG's request P0504R0 marked them inline just to be safe.)

OK for trunk, thanks.


Oh, they aren't actually constexpr in your patch, so non-const, and so
don't get internal linkage. But they *should* be constexpr, please add
that to all three, and add inline to the two variable templates.



P.S. OK with those changes.



[v3 PATCH] Implement P0513R0, Poisoning the Hash.

2016-11-13 Thread Ville Voutilainen
Tested on Linux-x64.

2016-11-13  Ville Voutilainen  

Implement P0513R0, Poisoning the Hash.
* include/bits/functional_hash.h (__poison_hash): New.
* include/bits/unique_ptr.h
(hash>): Derive from __poison_hash.
* include/std/optional (hash>): Likewise.
* include/std/variant (hash>): Likewise.
* testsuite/20_util/optional/hash.cc: New.
* testsuite/20_util/unique_ptr/hash/1.cc: Add tests for
poisoned fancy pointer hashes.
* testsuite/20_util/variant/hash.cc: New.
diff --git a/libstdc++-v3/include/bits/functional_hash.h 
b/libstdc++-v3/include/bits/functional_hash.h
index def35f5..dc09683 100644
--- a/libstdc++-v3/include/bits/functional_hash.h
+++ b/libstdc++-v3/include/bits/functional_hash.h
@@ -57,6 +57,20 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   template
 struct hash;
 
+  template
+struct __poison_hash
+{
+private:
+  // Private rather than deleted to be non-trivially-copyable.
+  __poison_hash(__poison_hash&&);
+  ~__poison_hash();
+};
+
+  template
+struct __poison_hash<_Tp, __void_t()(declval<_Tp>()))>>
+{
+};
+
   // Helper struct for SFINAE-poisoning non-enum types.
   template::value>
 struct __hash_enum
diff --git a/libstdc++-v3/include/bits/unique_ptr.h 
b/libstdc++-v3/include/bits/unique_ptr.h
index 996c9ea..f9ec60f 100644
--- a/libstdc++-v3/include/bits/unique_ptr.h
+++ b/libstdc++-v3/include/bits/unique_ptr.h
@@ -36,6 +36,7 @@
 #include 
 #include 
 #include 
+#include 
 
 namespace std _GLIBCXX_VISIBILITY(default)
 {
@@ -763,7 +764,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   /// std::hash specialization for unique_ptr.
   template
 struct hash>
-: public __hash_base>
+: public __hash_base>,
+private __poison_hash::pointer>
 {
   size_t
   operator()(const unique_ptr<_Tp, _Dp>& __u) const noexcept
diff --git a/libstdc++-v3/include/std/optional 
b/libstdc++-v3/include/std/optional
index f272876..69aa54d 100644
--- a/libstdc++-v3/include/std/optional
+++ b/libstdc++-v3/include/std/optional
@@ -990,7 +990,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
   // Hash.
   template
-struct hash>
+struct hash> : private __poison_hash>
 {
   using result_type = size_t;
   using argument_type = optional<_Tp>;
diff --git a/libstdc++-v3/include/std/variant b/libstdc++-v3/include/std/variant
index 314f5f2..004d667 100644
--- a/libstdc++-v3/include/std/variant
+++ b/libstdc++-v3/include/std/variant
@@ -41,6 +41,7 @@
 #include 
 #include 
 #include 
+#include 
 
 namespace std _GLIBCXX_VISIBILITY(default)
 {
@@ -1337,6 +1338,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
   template
 struct hash>
+: private __poison_hash>...
 {
   using result_type = size_t;
   using argument_type = variant<_Types...>;
diff --git a/libstdc++-v3/testsuite/20_util/optional/hash.cc 
b/libstdc++-v3/testsuite/20_util/optional/hash.cc
new file mode 100644
index 000..294a617
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/optional/hash.cc
@@ -0,0 +1,38 @@
+// { dg-options "-std=gnu++17" }
+
+// Copyright (C) 2016 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 moved_to of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// .
+
+#include 
+#include 
+
+class S{}; // No hash specialization
+
+template
+auto f(int) -> decltype(std::hash>(), std::true_type());
+
+template
+auto f(...) -> decltype(std::false_type());
+
+static_assert(!decltype(f(0))::value, "");
+
+int main()
+{
+  int x = 42;
+  std::optional x2 = 42;
+  VERIFY(std::hash()(x) == std::hash>()(x2));
+}
diff --git a/libstdc++-v3/testsuite/20_util/unique_ptr/hash/1.cc 
b/libstdc++-v3/testsuite/20_util/unique_ptr/hash/1.cc
index 6fc4fdc..ae73a43 100644
--- a/libstdc++-v3/testsuite/20_util/unique_ptr/hash/1.cc
+++ b/libstdc++-v3/testsuite/20_util/unique_ptr/hash/1.cc
@@ -21,6 +21,29 @@
 
 #include 
 #include 
+#include 
+
+// User-defined pointer type that throws if a null pointer is dereferenced.
+template
+struct Pointer : __gnu_test::PointerBase, T>
+{
+};
+
+template
+struct PointerDeleter : std::default_delete
+{
+  typedef Pointer pointer;
+  void operator()(pointer) const;
+};
+
+template
+auto f(int) -> decltype(std::hash>>(), std::true_type());
+
+template
+auto f(...) -> decltype(std::false_type());
+
+static_assert(!decltype(f>(0))::value, "");
 
 void test01()
 {
diff --git a/libstdc++-v3/tests

Re: [v3 PATCH] Implement P0513R0, Poisoning the Hash.

2016-11-13 Thread Ville Voutilainen
On 14 November 2016 at 00:48, Ville Voutilainen
 wrote:
> Tested on Linux-x64.


Ah, negative tests incomplete, sending a follow-up soon...


Re: [v3 PATCH] Implement P0513R0, Poisoning the Hash.

2016-11-13 Thread Ville Voutilainen
On 14 November 2016 at 00:49, Ville Voutilainen
 wrote:
> On 14 November 2016 at 00:48, Ville Voutilainen
>  wrote:
>> Tested on Linux-x64.
>
>
> Ah, negative tests incomplete, sending a follow-up soon...

Here:

2016-11-13  Ville Voutilainen  

Implement P0513R0, Poisoning the Hash.
* include/bits/functional_hash.h (__poison_hash): New.
* include/bits/unique_ptr.h
(hash>): Derive from __poison_hash.
* include/std/optional (hash>): Likewise.
* include/std/variant (hash>): Likewise.
* testsuite/20_util/optional/hash.cc: New.
* testsuite/20_util/unique_ptr/assign/48635_neg.cc: Adjust.
* testsuite/20_util/unique_ptr/cons/cv_qual_neg.cc: Adjust.
* testsuite/20_util/unique_ptr/hash/1.cc: Add tests for
poisoned fancy pointer hashes.
* testsuite/20_util/variant/hash.cc: New.
diff --git a/libstdc++-v3/include/bits/functional_hash.h 
b/libstdc++-v3/include/bits/functional_hash.h
index def35f5..dc09683 100644
--- a/libstdc++-v3/include/bits/functional_hash.h
+++ b/libstdc++-v3/include/bits/functional_hash.h
@@ -57,6 +57,20 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   template
 struct hash;
 
+  template
+struct __poison_hash
+{
+private:
+  // Private rather than deleted to be non-trivially-copyable.
+  __poison_hash(__poison_hash&&);
+  ~__poison_hash();
+};
+
+  template
+struct __poison_hash<_Tp, __void_t()(declval<_Tp>()))>>
+{
+};
+
   // Helper struct for SFINAE-poisoning non-enum types.
   template::value>
 struct __hash_enum
diff --git a/libstdc++-v3/include/bits/unique_ptr.h 
b/libstdc++-v3/include/bits/unique_ptr.h
index 996c9ea..f9ec60f 100644
--- a/libstdc++-v3/include/bits/unique_ptr.h
+++ b/libstdc++-v3/include/bits/unique_ptr.h
@@ -36,6 +36,7 @@
 #include 
 #include 
 #include 
+#include 
 
 namespace std _GLIBCXX_VISIBILITY(default)
 {
@@ -763,7 +764,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   /// std::hash specialization for unique_ptr.
   template
 struct hash>
-: public __hash_base>
+: public __hash_base>,
+private __poison_hash::pointer>
 {
   size_t
   operator()(const unique_ptr<_Tp, _Dp>& __u) const noexcept
diff --git a/libstdc++-v3/include/std/optional 
b/libstdc++-v3/include/std/optional
index f272876..69aa54d 100644
--- a/libstdc++-v3/include/std/optional
+++ b/libstdc++-v3/include/std/optional
@@ -990,7 +990,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
   // Hash.
   template
-struct hash>
+struct hash> : private __poison_hash>
 {
   using result_type = size_t;
   using argument_type = optional<_Tp>;
diff --git a/libstdc++-v3/include/std/variant b/libstdc++-v3/include/std/variant
index 314f5f2..004d667 100644
--- a/libstdc++-v3/include/std/variant
+++ b/libstdc++-v3/include/std/variant
@@ -41,6 +41,7 @@
 #include 
 #include 
 #include 
+#include 
 
 namespace std _GLIBCXX_VISIBILITY(default)
 {
@@ -1337,6 +1338,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
   template
 struct hash>
+: private __poison_hash>...
 {
   using result_type = size_t;
   using argument_type = variant<_Types...>;
diff --git a/libstdc++-v3/testsuite/20_util/optional/hash.cc 
b/libstdc++-v3/testsuite/20_util/optional/hash.cc
new file mode 100644
index 000..294a617
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/optional/hash.cc
@@ -0,0 +1,38 @@
+// { dg-options "-std=gnu++17" }
+
+// Copyright (C) 2016 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 moved_to of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// .
+
+#include 
+#include 
+
+class S{}; // No hash specialization
+
+template
+auto f(int) -> decltype(std::hash>(), std::true_type());
+
+template
+auto f(...) -> decltype(std::false_type());
+
+static_assert(!decltype(f(0))::value, "");
+
+int main()
+{
+  int x = 42;
+  std::optional x2 = 42;
+  VERIFY(std::hash()(x) == std::hash>()(x2));
+}
diff --git a/libstdc++-v3/testsuite/20_util/unique_ptr/assign/48635_neg.cc 
b/libstdc++-v3/testsuite/20_util/unique_ptr/assign/48635_neg.cc
index 9d24826..e9655f1 100644
--- a/libstdc++-v3/testsuite/20_util/unique_ptr/assign/48635_neg.cc
+++ b/libstdc++-v3/testsuite/20_util/unique_ptr/assign/48635_neg.cc
@@ -42,10 +42,10 @@ void f()
   std::unique_ptr ud(nullptr, d);
   ub = std::move(ud); // { dg-error "no match" }
   ub2 = ud; // { dg-error "no match" }
-// { dg-error "no type" "" { target

Re: [PATCH] Prepare shared_ptr for array support

2016-11-13 Thread Jonathan Wakely

On 20/10/16 15:41 +0100, Jonathan Wakely wrote:

On 20/10/16 13:08 +0100, Jonathan Wakely wrote:

This patch doesn't change very much, except for adding
std::reinterpret_pointer_cast, but it makes it very easy to add array
support to shared_ptr, as defined for the Library Fundamentals TS by
https://wg21.link/n3920 and in the process of being added to C++17 by
https://wg21.link/p0414r1

The main change is to consistently constrain all template constructors
and assignment operators. In std::shared_ptr we just forward the
checks to the std::__shared_ptr base class, so all the hard work is
done there. The base uses traits that can easily be extended to handle
array types without touching the uses of those traits (I have that
patch ready).


Here's the patch to add array support, which is as simple as:

- adding new __shared_count ctor that will result in delete[];
- adjusting the two __sp_xxx traits to handle the array cases;
- moving operator* and operator-> into a new base class, and then
specializing it so shared_ptr has operator[] instead;
- changing element_type to be remove_extent::type instead of T;
- disabling the __has_esft_base detection for array types.

That allows us to remove 650 lines from the experimental::shared_ptr
definition and just inherit directly from __shared_ptr.

Note that the *only* change needed to std::shared_ptr or std::weak_ptr
is to add an extension constructor (see below). My changes to trunk
earlier today mean they are ready to suport arrays now. The code
changes are all to the __shared_ptr and __weak_ptr base classes.

Officially this isn't in the C++17 draft yet, but LWG already approved
P0414R1 and it will be in the straw polls at the end of the Issaquah
meeting next month. I'm not committing it to trunk yet, but I probably
will do before the meeting, as I don't anticipate C++17 being
published without this feature.

The bigger question is whether we want to enable array support
unconditionally, or only for C++17. In C++14 today shared_ptr
and shared_ptr are valid ... although they're weird and not
very usable. My preference (as shown in the patch) is to enable it
unconditionally, but add some non-standard member functions for
pre-C++17 to help transition. Specifically operator* and operator->
are defined for shared_ptr pre-C++17, and you can do this
pre-C++17:

shared_ptr p( unique_ptr(new int[1]) );
p.get()[0] = 1;
assert( *p == 1 );

This is valid today, and we even have a test checking it works. The
default_delete is copied into the shared_ptr and does delete[]
when the refcount drops to zero. C++17 says this is ill-formed. This
patch adds a non-standard constructor that allows this conversion, and
the dereference, for C++11 and C++14 only.

For C++17 the code needs to be changed to:

shared_ptr p( unique_ptr(new int[1]) );
p.get()[0] = 1;
assert( p[0] == 1 );


Here's what I'm committing, now that we've voted array support into
the WP (again).

Tested powerpc64le-linux, committed to trunk.


commit fc1957b66af979b174d7120c9311479842a6aefb
Author: Jonathan Wakely 
Date:   Sun Nov 13 20:41:17 2016 +

Add array support to std::shared_ptr for C++17

	* doc/xml/manual/status_cxx2017.xml: Update status.
	* doc/html/manual/status.html: Regenerate.
	* include/bits/shared_ptr.h (shared_ptr(unique_ptr<_Yp, _Del>)): Add
	extension constructor to maintain C++14 behaviour.
	* include/bits/shared_ptr_base.h (__sp_array_delete): Add new struct.
	(__shared_count(_Ptr, false_type), __shared_count(_Ptr, true_type)):
	New constructors.
	(__sp_compatible_with, __sp_is_constructible): Add specializations
	for array support.
	(__sp_is_constructible_arr, __sp_is_constructible_arrN): New helpers.
	(__shared_ptr_access): New base class for observer member functions.
	(__shared_ptr::element_type): Use remove_extent.
	(__shared_ptr::_UniqCompatible): Add __sp_compatible_with check.
	(__shared_ptr(_Yp*)): Use tag dispatching to call new __shared_count
	constructor.
	(__shared_ptr(unique_ptr<_Yp, _Del>)): Add extension constructor.
	(__shared_ptr::operator*, __shared_ptr::operator->): Remove and
	inherit from __shared_ptr_access base class.
	(__shared_ptr::__has_esft_base): Return false for array types.
	(__weak_ptr::element_type): Use remove_extent.
	* include/experimental/bits/shared_ptr.h (__libfund_v1): Remove.
	(__shared_ptr<__libfund_v1<_Tp>>): Remove specializations.
	(__wak_ptr<__libfund_v1<_Tp>>): Likewise.
	(experimental::__sp_compatible_v): Redefine using
	__sp_compatible_with.
	(experimental::__sp_is_constructible_v): Redefine using
	__sp_is_constructible.
	(get_deleter, operator<<): Change argument from __shared_ptr to
	shared_ptr.
	* testsuite/20_util/shared_ptr/cons/array.cc: New test.
	* testsuite/20_util/shared_ptr/cons/unique_ptr_array.cc: Adjust for
	new behaviour.
	* testsuite/20_util/shared_ptr/observers/array.cc: Test observers for
 

[PATCH 0/4] Merge from HSA branch to trunk

2016-11-13 Thread Martin Jambor
Hello,

this series is a merge from what is ready for trunk in the HSA
branch.

The first patch is self-contained and I intend to commit it
separately, the other three need to be committed together but I split
the change into these pieces, because I believe they will be easier to
review that way and because I have the authority to self-approve the
last one so although any comments are of course welcome, review of it
is not strictly required.

More details are in the individual email messages.

Thanks,

Martin


Martin Jambor (4):
  Remove HSA build dependence
  HSA specific built-ins
  OpenMP lowering changes from the hsa branch
  Back-end and IPA bits of hsa branch merge

 gcc/Makefile.in   |3 +-
 gcc/builtins.def  |   16 +
 gcc/doc/install.texi  |6 -
 gcc/doc/optinfo.texi  |3 +
 gcc/dumpfile.c|1 +
 gcc/dumpfile.h|3 +-
 gcc/fortran/f95-lang.c|   11 +
 gcc/gimple.h  |   57 +
 gcc/hsa-brig.c|  140 ++-
 gcc/hsa-builtins.def  |   39 +
 gcc/hsa-dump.c|  107 +-
 gcc/hsa-gen.c |  914 ---
 gcc/hsa.c |   60 +-
 gcc/hsa.h |  157 ++-
 gcc/ipa-hsa.c |   14 +-
 gcc/omp-low.c | 1543 ++---
 gcc/testsuite/c-c++-common/gomp/gridify-2.c   |   66 ++
 gcc/testsuite/c-c++-common/gomp/gridify-3.c   |   68 ++
 libgomp/config.h.in   |3 +
 libgomp/configure |   56 +-
 libgomp/plugin/configfrag.ac  |   32 +-
 libgomp/plugin/hsa.h  |  630 ++
 libgomp/plugin/hsa_ext_finalize.h |  265 +
 libgomp/plugin/plugin-hsa.c   |  471 ++--
 libgomp/testsuite/lib/libgomp.exp |4 -
 libgomp/testsuite/libgomp-test-support.exp.in |1 -
 libgomp/testsuite/libgomp.hsa.c/bits-insns.c  |   73 ++
 libgomp/testsuite/libgomp.hsa.c/tiling-1.c|  212 
 libgomp/testsuite/libgomp.hsa.c/tiling-2.c|  258 +
 29 files changed, 3992 insertions(+), 1221 deletions(-)
 create mode 100644 gcc/hsa-builtins.def
 create mode 100644 gcc/testsuite/c-c++-common/gomp/gridify-2.c
 create mode 100644 gcc/testsuite/c-c++-common/gomp/gridify-3.c
 create mode 100644 libgomp/plugin/hsa.h
 create mode 100644 libgomp/plugin/hsa_ext_finalize.h
 create mode 100644 libgomp/testsuite/libgomp.hsa.c/bits-insns.c
 create mode 100644 libgomp/testsuite/libgomp.hsa.c/tiling-1.c
 create mode 100644 libgomp/testsuite/libgomp.hsa.c/tiling-2.c

-- 
2.10.1


[PATCH 1/4] Remove build dependence on HSA run-time

2016-11-13 Thread Martin Jambor
Hi,

over the last year there have been only two changes to the HSA libgomp
plugin, both are in the following patch.  The first change allows
running kernels in HSA grid with multiple dimensions.  The second one
changes the way the plugin calls hsa run-time to dynamic shared object
loading, which has the benefit that the run-time does not need to be a
build dependence, which should make life considerably easier for
people allowing HSA offloading in packaged gccs.  We actually carry a
very similar patch in openSUSE Tumbleweed gcc to achieve just that.

I'm not sure whether I can approve this change as the HSA maintainer
or not but since Richi has seen the patch he put into the SUSE
package, I hope it is not controversial.  The patch has passed
bootstrap and checking on x86_64-linux.  OK for trunk?

Thanks


Martin


2016-11-11  Martin Liska  
 Martin Jambor  

gcc/
* doc/install.texi: Remove entry about --with-hsa-kmt-lib.

libgomp/
* config.h.in: Introduce HSA_RUNTIME_LIB.
* configure: Regerenated.
* plugin/hsa.h: New file.
* plugin/hsa_ext_finalize.h: New file.
* plugin/configfrag.ac: Remove hsa-kmt-lib test.
* plugin/plugin-hsa.c: Include config.h, inttypes.h and stdbool.h.
(struct hsa_runtime_fn_info): New structure.
(hsa_runtime_fn_info hsa_fns): New variable.
(hsa_runtime_lib): Likewise.
(support_cpu_devices): Likewise.
(init_enviroment_variables): Load newly introduced ENV
variables.
(hsa_warn): Call hsa run-time functions via hsa_fns structure.
(hsa_fatal): Likewise.
(DLSYM_FN): New macro.
(init_hsa_runtime_functions): New function.
(suitable_hsa_agent_p): Call hsa run-time functions via hsa_fns
structure.  Depending on environment, also allow CPU devices.
(init_hsa_context): Call hsa run-time functions via hsa_fns structure.
(get_kernarg_memory_region): Likewise.
(GOMP_OFFLOAD_init_device): Likewise.
(destroy_hsa_program): Likewise.
(init_basic_kernel_info): New function.
(GOMP_OFFLOAD_load_image): Use it.
(create_and_finalize_hsa_program): Call hsa run-time functions via
hsa_fns structure.
(create_single_kernel_dispatch): Likewise.
(release_kernel_dispatch): Likewise.
(init_single_kernel): Likewise.
(parse_target_attributes): Allow up multiple HSA grid dimensions.
(get_group_size): New function.
(run_kernel): Likewise.
(GOMP_OFFLOAD_run): Outline most functionality to run_kernel.
(GOMP_OFFLOAD_fini_device): Call hsa run-time functions via hsa_fns
structure.
* testsuite/lib/libgomp.exp: Remove hsa_kmt_lib support.
* testsuite/libgomp-test-support.exp.in: Likewise.
---
 gcc/doc/install.texi  |   6 -
 libgomp/config.h.in   |   3 +
 libgomp/configure |  56 +--
 libgomp/plugin/configfrag.ac  |  32 +-
 libgomp/plugin/hsa.h  | 630 ++
 libgomp/plugin/hsa_ext_finalize.h | 265 +++
 libgomp/plugin/plugin-hsa.c   | 471 ++-
 libgomp/testsuite/lib/libgomp.exp |   4 -
 libgomp/testsuite/libgomp-test-support.exp.in |   1 -
 9 files changed, 1281 insertions(+), 187 deletions(-)
 create mode 100644 libgomp/plugin/hsa.h
 create mode 100644 libgomp/plugin/hsa_ext_finalize.h

diff --git a/gcc/doc/install.texi b/gcc/doc/install.texi
index e4c686e..eef7aab 100644
--- a/gcc/doc/install.texi
+++ b/gcc/doc/install.texi
@@ -2021,12 +2021,6 @@ explicitly specify the directory where they are 
installed.  The
 shorthand for
 @option{--with-hsa-runtime-lib=@/@var{hsainstalldir}/lib} and
 @option{--with-hsa-runtime-include=@/@var{hsainstalldir}/include}.
-
-@item --with-hsa-kmt-lib=@var{pathname}
-
-If you configure GCC with HSA offloading but do not have the HSA
-KMT library installed in a standard location then you can
-explicitly specify the directory where it resides.
 @end table
 
 @subheading Cross-Compiler-Specific Options
diff --git a/libgomp/config.h.in b/libgomp/config.h.in
index 226ac53..4483a84 100644
--- a/libgomp/config.h.in
+++ b/libgomp/config.h.in
@@ -125,6 +125,9 @@
 /* Define to 1 if the HSA plugin is built, 0 if not. */
 #undef PLUGIN_HSA
 
+/* Define path to HSA runtime.  */
+#undef HSA_RUNTIME_LIB
+
 /* Define to 1 if the NVIDIA plugin is built, 0 if not. */
 #undef PLUGIN_NVPTX
 
diff --git a/libgomp/configure b/libgomp/configure
index 8d03eb6..6b3e639 100755
--- a/libgomp/configure
+++ b/libgomp/configure
@@ -637,7 +637,6 @@ PLUGIN_HSA_LIBS
 PLUGIN_HSA_LDFLAGS
 PLUGIN_HSA_CPPFLAGS
 PLUGIN_HSA
-HSA_KMT_LIB
 HSA_RUNTIME_LIB
 HSA_RUNTIME_INCLUDE
 PLUGIN_NVPTX_LIBS
@@ -794,7 +793,6 @@ with_cuda_driver_lib
 with_hsa_runtime
 with_hsa_runtime_include
 with_hsa_runtime_lib
-with_hsa_kmt_lib
 enable_lin

[PATCH 3/4] OpenMP lowering changes from the hsa branch

2016-11-13 Thread Martin Jambor
Hello,

this email contains the OpenMP bits of the HSA branch merge.  I have
covered the new functionality in my talk at cauldron and in the email
messages announcing commits to the branch, but in short, the patch
below allows gridification standalone distribute constructs if their
step is as big as iteration space of the normal parallel loop
constructs in it, it implements the lastprivate clause and hides away
simds because the HSA model does not really benefit from them.  It
also puts OpenMP passes into its own optimization group so that users
can request optimization info about gridification alone.

Early in stage three I'd like to divide omp-low.c into multiple files
and put the gridification-specific ones into one of them, hopefully
making it more easy to follow.

I expect feedback and comments but I'd really be greateful if these
changes make it to gcc7, despite this rather late submission, they
should not affect non-HSA code generation in any way (and apart from
the optimization group stuff, really only two hunks even touch it, I
believe).

Thanks,

Martin


2016-11-11  Martin Jambor  

gcc/
* dumpfile.h (OPTGROUP_OPENMP): Define.
* dumpfile.c (optgroup_options): Added OPTGROUP_OPENMP.
* gimple.h (gf_mask): Added elements GF_OMP_FOR_GRID_INTRA_GROUP and
GF_OMP_FOR_GRID_GROUP_ITER.
(gimple_omp_for_grid_phony): Added checking assert.
(gimple_omp_for_set_grid_phony): Likewise.
(gimple_omp_for_grid_intra_group): New function.
(gimple_omp_for_set_grid_intra_group): Likewise.
(gimple_omp_for_grid_group_iter): Likewise.
(gimple_omp_for_set_grid_group_iter): Likewise.
* omp-low.c (check_omp_nesting_restrictions): Allow GRID loop where
previosuly only distribute loop was permitted.
(lower_lastprivate_clauses): Allow non tcc_comparison predicates.
(grid_get_kernel_launch_attributes): Support multiple HSA grid
dimensions.
(grid_expand_omp_for_loop): Likewise and also support standalone
distribute constructs.  New parameter INTRA_GROUP, updated both users.
(grid_expand_target_grid_body): Support standalone distribute
constructs.
(pass_data_expand_omp): Changed optinfo_flags to OPTGROUP_OPENMP.
(pass_data_expand_omp_ssa): Likewise.
(pass_data_lower_omp): Likewise.
(grid_lastprivate_predicate): New function.
(lower_omp_for_lastprivate): Call grid_lastprivate_predicate for
gridified loops.
(lower_omp_for): Support standalone distribute constructs.
(grid_prop): New type.
(grid_safe_assignment_p): Check for assignments to group_sizes, new
parameter GRID.
(grid_seq_only_contains_local_assignments): New parameter GRID, pass
it to callee.
(grid_find_single_omp_among_assignments_1): Likewise, improve missed
optimization info messages.
(grid_find_single_omp_among_assignments): Likewise.
(grid_find_ungridifiable_statement): Do not bail out for SIMDs.
(grid_parallel_clauses_gridifiable): New function.
(grid_inner_loop_gridifiable_p): Likewise.
(grid_dist_follows_simple_pattern): Likewise.
(grid_gfor_follows_tiling_pattern): Likewise.
(grid_call_permissible_in_distribute_p): Likewise.
(grid_handle_call_in_distribute): Likewise.
(grid_dist_follows_tiling_pattern): Likewise.
(grid_target_follows_gridifiable_pattern): Support standalone distribute
constructs.
(grid_var_segment): New enum.
(grid_mark_variable_segment): New function.
(grid_copy_leading_local_assignments): Call grid_mark_variable_segment
if a new argument says so.
(grid_process_grid_body): New function.
(grid_eliminate_combined_simd_part): Likewise.
(grid_mark_tiling_loops): Likewise.
(grid_mark_tiling_parallels_and_loops): Likewise.
(grid_process_kernel_body_copy): Support standalone distribute
constructs.
(grid_attempt_target_gridification): New grid variable holding overall
gridification state.  Support standalone distribute constructs and
collapse clauses.
* doc/optinfo.texi (Optimization groups): Document OPTGROUP_OPENMP.

gcc/testsuite/
* c-c++-common/gomp/gridify-2.c: New test.
* c-c++-common/gomp/gridify-3.c: Likewise.

libgomp/
* testsuite/libgomp.hsa.c/tiling-1.c: New test.
* testsuite/libgomp.hsa.c/tiling-2.c: Likewise.
---
 gcc/doc/optinfo.texi|3 +
 gcc/dumpfile.c  |1 +
 gcc/dumpfile.h  |3 +-
 gcc/gimple.h|   57 +
 gcc/omp-low.c   | 1543 ---
 gcc/testsuite/c-c++-common/gomp/gridify-2.c |   66 ++
 gcc/testsuite/c-c++-common/gomp/gridify-3.c |   68 ++
 libgomp/testsuite/libgomp.hsa.c/tiling-1.c

[PATCH 2/4] HSA specific built-ins

2016-11-13 Thread Martin Jambor
Hello,

this patch adds a small file hsa-builtins.def which defines a few
builtins that I then use in OpenMP lowering and expansion.

After we split gridification stuff in omp-low.c to a separate file, we
should be able to only conditionally include the file and remove the
weird conditional ifdef.

OK for trunk?

Thanks,

Martin


2016-11-11  Martin Jambor  

gcc/
* hsa-builtins.def: New file.
* Makefile.in (BUILTINS_DEF): Add hsa-builtins.def dependency.
* builtins.def: Include hsa-builtins.def.
(DEF_HSA_BUILTIN): New macro.

fortran/
* f95-lang.c (DEF_HSA_BUILTIN): New macro.
---
 gcc/Makefile.in|  3 ++-
 gcc/builtins.def   | 16 
 gcc/fortran/f95-lang.c | 11 +++
 gcc/hsa-builtins.def   | 39 +++
 4 files changed, 68 insertions(+), 1 deletion(-)
 create mode 100644 gcc/hsa-builtins.def

diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index 7ecd1e4..4e64960 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -911,7 +911,8 @@ RTL_H = $(RTL_BASE_H) $(FLAGS_H) genrtl.h
 READ_MD_H = $(OBSTACK_H) $(HASHTAB_H) read-md.h
 PARAMS_H = params.h params-enum.h params.def
 BUILTINS_DEF = builtins.def sync-builtins.def omp-builtins.def \
-   gtm-builtins.def sanitizer.def cilkplus.def cilk-builtins.def
+   gtm-builtins.def sanitizer.def cilkplus.def cilk-builtins.def \
+   hsa-builtins.def
 INTERNAL_FN_DEF = internal-fn.def
 INTERNAL_FN_H = internal-fn.h $(INTERNAL_FN_DEF)
 TREE_CORE_H = tree-core.h coretypes.h all-tree.def tree.def \
diff --git a/gcc/builtins.def b/gcc/builtins.def
index 219feeb..4e8f140 100644
--- a/gcc/builtins.def
+++ b/gcc/builtins.def
@@ -201,6 +201,19 @@ along with GCC; see the file COPYING3.  If not see
|| flag_cilkplus \
|| flag_offload_abi != OFFLOAD_ABI_UNSET))
 
+#undef DEF_HSA_BUILTIN
+#ifdef ENABLE_HSA
+#define DEF_HSA_BUILTIN(ENUM, NAME, TYPE, ATTRS)   \
+  DEF_BUILTIN (ENUM, "__builtin_" NAME, BUILT_IN_NORMAL, TYPE, TYPE,\
+   false, false, true, ATTRS, false, \
+  (!flag_disable_hsa))
+#else
+#define DEF_HSA_BUILTIN(ENUM, NAME, TYPE, ATTRS)   \
+  DEF_BUILTIN (ENUM, "__builtin_" NAME, BUILT_IN_NORMAL, TYPE, TYPE,\
+   false, false, true, ATTRS, false, \
+  (false))
+#endif
+
 /* Builtin used by implementation of Cilk Plus.  Most of these are decomposed
by the compiler but a few are implemented in libcilkrts.  */ 
 #undef DEF_CILK_BUILTIN_STUB
@@ -968,6 +981,9 @@ DEF_GCC_BUILTIN (BUILT_IN_LINE, "LINE", BT_FN_INT, 
ATTR_NOTHROW_LEAF_LIST)
 /* Offloading and Multi Processing builtins.  */
 #include "omp-builtins.def"
 
+/* Heterogeneous Systems Architecture.  */
+#include "hsa-builtins.def"
+
 /* Cilk keywords builtins.  */
 #include "cilk-builtins.def"
 
diff --git a/gcc/fortran/f95-lang.c b/gcc/fortran/f95-lang.c
index cea6675..22d29da 100644
--- a/gcc/fortran/f95-lang.c
+++ b/gcc/fortran/f95-lang.c
@@ -1224,6 +1224,17 @@ gfc_init_builtin_functions (void)
 #undef DEF_GOMP_BUILTIN
 }
 
+#ifdef ENABLE_HSA
+  if (!flag_disable_hsa)
+{
+#undef DEF_HSA_BUILTIN
+#define DEF_HSA_BUILTIN(code, name, type, attr) \
+  gfc_define_builtin ("__builtin_" name, builtin_types[type], \
+ code, name, attr);
+#include "../hsa-builtins.def"
+}
+#endif
+
   gfc_define_builtin ("__builtin_trap", builtin_types[BT_FN_VOID],
  BUILT_IN_TRAP, NULL, ATTR_NOTHROW_LEAF_LIST);
   TREE_THIS_VOLATILE (builtin_decl_explicit (BUILT_IN_TRAP)) = 1;
diff --git a/gcc/hsa-builtins.def b/gcc/hsa-builtins.def
new file mode 100644
index 000..cc0409e
--- /dev/null
+++ b/gcc/hsa-builtins.def
@@ -0,0 +1,39 @@
+/* This file contains the definitions and documentation for the
+   Offloading and Multi Processing builtins used in the GNU compiler.
+   Copyright (C) 2005-2015 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC 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.
+
+GCC 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 GCC; see the file COPYING3.  If not see
+.  */
+
+/* Before including this file, you should define a macro:
+
+ DEF_HSA_BUILTIN (ENUM, NAME, TYPE, ATTRS)
+
+   See builtins.def for details.  */
+
+/* The reason why they aren't in gcc/builtins.def is that the Fortran front end
+   doesn't source those.  */
+
+DEF_HSA_BUILTIN (BUILT_IN_HSA_WORKGROUPID, "hsa_workgroupid",
+BT_FN_UINT_UINT, ATTR_CONST_NOTHROW_LEAF_LIST)
+DEF

[PATCH 4/4] Back-end and IPA bits of hsa branch merge

2016-11-13 Thread Martin Jambor
Hi,

so this patch bundles together all the various fixes, cleanups and
improvements to the HSAIL generation itself which are far too many to
list here individually, more details can be found in the email
messages that i sent when committing a given change to the branch.

As the HSA maintainer I am going to approve this after the previous
two patches are approved by others, but if anybody has any comment or
suggestion, I will be glad to know.

Thanks,

Martin



2016-11-11  Martin Jambor  
Martin Liska  

* hsa.h (hsa_bb): Add method method append_phi.
(hsa_insn_br): Renamed to hsa_insn_cbr, renamed all
occurences in all files too.
(hsa_insn_br): New class, now the ancestor of hsa_incn_cbr.
(is_a_helper ::test): New function.
(is_a_helper ::test): Adjust to only cover conditional
branch instructions.
(hsa_insn_signal): Make a direct descendant of
hsa_insn_basic.  Add memorder constructor parameter and
m_memory_order and m_signalop member variables.
(hsa_insn_queue): Changed constructor parameters to common form.
Added m_segment and m_memory_order member variables.
(hsa_summary_t): Add private member function
process_gpu_implementation_attributes.
(hsa_function_summary): Rename m_binded_function to
m_bound_function.
(hsa_insn_basic_p): Remove typedef.
(hsa_op_with_type): Change hsa_insn_basic_p into plain pointers.
(hsa_op_reg_p): Remove typedef.
(hsa_function_representation): Change hsa_op_reg_p into plain
pointers.
(hsa_insn_phi): Removed new and delete operators.
(hsa_insn_br): Likewise.
(hsa_insn_cbr): Likewise.
(hsa_insn_sbr): Likewise.
(hsa_insn_cmp): Likewise.
(hsa_insn_mem): Likewise.
(hsa_insn_atomic): Likewise.
(hsa_insn_signal): Likewise.
(hsa_insn_seg): Likewise.
(hsa_insn_call): Likewise.
(hsa_insn_arg_block): Likewise.
(hsa_insn_comment): Likewise.
(hsa_insn_srctype): Likewise.
(hsa_insn_packed): Likewise.
(hsa_insn_cvt): Likewise.
(hsa_insn_alloca): Likewise.

* hsa.c (hsa_destroy_insn): Also handle instances of hsa_insn_br.
(process_gpu_implementation_attributes): New function.
(link_functions): Move some functionality into it.  Adjust after
renaming m_binded_functions to m_bound_functions.
(hsa_insn_basic::op_output_p): Add BRIG_OPCODE_DEBUGTRAP
to the list of instructions with no output registers.
(get_in_type): Return this if it is a register of
matching size.
(hsa_get_declaration_name): Moved to...

* hsa-gen.c (hsa_get_declaration_name): ...here.  Allocate
temporary string on an obstack instead from ggc.
(query_hsa_grid): Renamed to query_hsa_grid_dim, reimplemented, cut
down to two overloads.
(hsa_allocp_operand_address): Removed.
(hsa_allocp_operand_immed): Likewise.
(hsa_allocp_operand_reg): Likewise.
(hsa_allocp_operand_code_list): Likewise.
(hsa_allocp_operand_operand_list): Likewise.
(hsa_allocp_inst_basic): Likewise.
(hsa_allocp_inst_phi): Likewise.
(hsa_allocp_inst_mem): Likewise.
(hsa_allocp_inst_atomic): Likewise.
(hsa_allocp_inst_signal): Likewise.
(hsa_allocp_inst_seg): Likewise.
(hsa_allocp_inst_cmp): Likewise.
(hsa_allocp_inst_br): Likewise.
(hsa_allocp_inst_sbr): Likewise.
(hsa_allocp_inst_call): Likewise.
(hsa_allocp_inst_arg_block): Likewise.
(hsa_allocp_inst_comment): Likewise.
(hsa_allocp_inst_queue): Likewise.
(hsa_allocp_inst_srctype): Likewise.
(hsa_allocp_inst_packed): Likewise.
(hsa_allocp_inst_cvt): Likewise.
(hsa_allocp_inst_alloca): Likewise.
(hsa_allocp_bb): Likewise.
(hsa_obstack): New.
(hsa_init_data_for_cfun): Initialize obstack.
(hsa_deinit_data_for_cfun): Release memory of the obstack.
(hsa_op_immed::operator new): Use obstack instead of object_allocator.
(hsa_op_reg::operator new): Likewise.
(hsa_op_address::operator new): Likewise.
(hsa_op_code_list::operator new): Likewise.
(hsa_op_operand_list::operator new): Likewise.
(hsa_insn_basic::operator new): Likewise.
(hsa_insn_phi::operator new): Likewise.
(hsa_insn_br::operator new): Likewise.
(hsa_insn_sbr::operator new): Likewise.
(hsa_insn_cmp::operator new): Likewise.
(hsa_insn_mem::operator new): Likewise.
(hsa_insn_atomic::operator new): Likewise.
(hsa_insn_signal::operator new): Likewise.
(hsa_insn_seg::operator new): Likewise.
(hsa_insn_call::operator new): Likewise.
(hsa_insn_arg_block::operator new): Likewise.
(hsa_insn_comment::operator new): Likewise.
 

[PATCH] PR78326 fix incorrect access of data member in base class

2016-11-13 Thread Jonathan Wakely

PR libstdc++/78326
* include/experimental/memory_resource (memory_resource::_S_max_align):
Change access to protected.

Tested powerpc64le-linux, committed to trunk. Will backport to
gcc-6-branch too.


commit 8d23f8efca6d181b26f8766a96b081c0e280e434
Author: Jonathan Wakely 
Date:   Sun Nov 13 23:11:25 2016 +

PR78326 fix incorrect access of data member in base class

PR libstdc++/78326
* include/experimental/memory_resource (memory_resource::_S_max_align):
Change access to protected.

diff --git a/libstdc++-v3/include/experimental/memory_resource 
b/libstdc++-v3/include/experimental/memory_resource
index 39187c5..52e0b03 100644
--- a/libstdc++-v3/include/experimental/memory_resource
+++ b/libstdc++-v3/include/experimental/memory_resource
@@ -72,6 +72,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   // 8.5 Class memory_resource
   class memory_resource
   {
+  protected:
 static constexpr size_t _S_max_align = alignof(max_align_t);
 
   public:


Re: [patch,libgfortran] PR51119 - MATMUL slow for large matrices

2016-11-13 Thread Steve Kargl
On Sun, Nov 13, 2016 at 04:08:50PM -0800, Jerry DeLisle wrote:
> Hi all,
> 
> Attached patch implements a fast blocked matrix multiply. The basic algorithm 
> is 
> derived from netlib.org tuned blas dgemm. See matmul.m4 for reference.
> 
> The matmul() function is compiled with -Ofast -funroll-loops. This can be 
> customized further if there is an undesired optimization being used. This is 
> accomplished using #pragma optimize ( string ).
> 

Did you run any tests with '--param max-unroll-times=4' where
the 4 could be something other than 4.  On troutmask, with my
code I've found that 4 seems to work the best with -funroll-loops.

-- 
Steve


Re: [patch,libgfortran] PR51119 - MATMUL slow for large matrices

2016-11-13 Thread Jerry DeLisle

On 11/13/2016 04:55 PM, Steve Kargl wrote:

On Sun, Nov 13, 2016 at 04:08:50PM -0800, Jerry DeLisle wrote:

Hi all,

Attached patch implements a fast blocked matrix multiply. The basic algorithm is
derived from netlib.org tuned blas dgemm. See matmul.m4 for reference.

The matmul() function is compiled with -Ofast -funroll-loops. This can be
customized further if there is an undesired optimization being used. This is
accomplished using #pragma optimize ( string ).



Did you run any tests with '--param max-unroll-times=4' where
the 4 could be something other than 4.  On troutmask, with my
code I've found that 4 seems to work the best with -funroll-loops.



Have not tried this, will give it a try. Also, I have not tested on your FreeBSD 
machine yet.


Jerry


Re: [v3 PATCH] Implement P0513R0, Poisoning the Hash.

2016-11-13 Thread Jonathan Wakely

On 14/11/16 00:55 +0200, Ville Voutilainen wrote:

   Implement P0513R0, Poisoning the Hash.
   * include/bits/functional_hash.h (__poison_hash): New.
   * include/bits/unique_ptr.h
   (hash>): Derive from __poison_hash.
   * include/std/optional (hash>): Likewise.
   * include/std/variant (hash>): Likewise.
   * testsuite/20_util/optional/hash.cc: New.
   * testsuite/20_util/unique_ptr/assign/48635_neg.cc: Adjust.
   * testsuite/20_util/unique_ptr/cons/cv_qual_neg.cc: Adjust.
   * testsuite/20_util/unique_ptr/hash/1.cc: Add tests for
   poisoned fancy pointer hashes.
   * testsuite/20_util/variant/hash.cc: New.


OK, thanks.



[PATCH] warn on overflow in calls to allocation functions (bugs 77531 and 78284)

2016-11-13 Thread Martin Sebor

Bug 77531 requests a new warning for calls to allocation functions
(those declared with attribute alloc_size(X, Y)) that overflow the
computation X * Z of the size of the allocated object.

Bug 78284 suggests that detecting and diagnosing other common errors
in calls to allocation functions, such as allocating more space than
SIZE_MAX / 2 bytes, would help prevent subsequent buffer overflows.

The attached patch adds two new warning options, -Walloc-zero and
-Walloc-larger-than=bytes that implement these two enhancements.
The patch is not 100% finished because, as it turns out, the GCC
allocation built-ins (malloc et al.) do not make use of the
attribute and so don't benefit from the warnings.  The tests are
also incomplete, and there's at least one bug in the implementation
I know about.

I'm posting the patch while stage 1 is still open and to give
a heads up on it and to get early feedback.  I expect completing
it will be straightforward.

Martin

PS The alloc_max_size function added in the patch handles sizes
specified using suffixes like KB, MB, etc.  I added that to make
it possible to specify sizes in excess of the maximum of INT_MAX
that (AFAIK) options that take integer arguments handle out of
the box.  It only belatedly occurred to me that the suffixes
are unnecessary if the option argument is handled using strtoull.
I can remove the suffix (as I suspect it will raise objections)
but I think that a general solution along these lines would be
useful to let users specify large byte sizes in other options
as well (such -Walloca-larger-than, -Wvla-larger-then).  Are
there any suggestions or preferences?
PR c/77531 - __attribute__((alloc_size(1,2))) could also warn on multiplication overflow
PR c/78284 - warn on malloc with very large arguments

gcc/c-family/ChangeLog:

	PR c/77531
	PR c/78284
	* c.opt (-Walloc-zero, -Walloc-larger-than): New options.

gcc/testsuite/ChangeLog:

	PR c/77531
	PR c/78284
	* gcc.dg/attr-alloc_size-3.c: New test.

gcc/ChangeLog:

	PR c/77531
	PR c/78284
	* calls.c (alloc_max_size): New function.
	(maybe_warn_alloc_args_overflow): Same.
	(initialize_argument_information): Diagnose overflow in functions
	declared with attaribute alloc_size.
	* doc/invoke.texi (Warning Options): Document -Walloc-zero and
	-Walloc-larger-than.

diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt
index 213353b..72c1e14 100644
--- a/gcc/c-family/c.opt
+++ b/gcc/c-family/c.opt
@@ -299,6 +299,15 @@ Walloca
 C ObjC C++ ObjC++ Var(warn_alloca) Warning
 Warn on any use of alloca.
 
+Walloc-larger-than=
+C ObjC C++ ObjC++ Var(warn_alloc_limit) Warning Joined
+-Walloc-larger-than= Warn for calls to allocation functions that attempt
+to allocate objects larger than the specified number of bytes.
+
+Walloc-zero
+C ObjC C++ ObjC++ Var(warn_alloc_zero) Warning EnabledBy(Wextra)
+-Walloc-zero Warn for calls to allocation functions that specify zero bytes.
+
 Walloca-larger-than=
 C ObjC C++ ObjC++ Var(warn_alloca_limit) Warning Joined RejectNegative UInteger
 -Walloca-larger-than= Warn on unbounded uses of
diff --git a/gcc/calls.c b/gcc/calls.c
index c916e07..dfeb5fe 100644
--- a/gcc/calls.c
+++ b/gcc/calls.c
@@ -48,6 +48,8 @@ along with GCC; see the file COPYING3.  If not see
 #include "dbgcnt.h"
 #include "rtl-iter.h"
 #include "tree-chkp.h"
+#include "tree-vrp.h"
+#include "tree-ssanames.h"
 #include "rtl-chkp.h"
 
 
@@ -1181,6 +1183,192 @@ store_unaligned_arguments_into_pseudos (struct arg_data *args, int num_actuals)
   }
 }
 
+static tree alloc_object_size_limit;
+
+/* Initialize ALLOC_OBJECT_SIZE_LIMIT based on the -Walloc-larger-than=limit
+   setting if the option is specified, or to the maximum object size if it
+   is not.  Return the initialized value.  */
+
+static tree
+alloc_max_size (void)
+{
+  if (!alloc_object_size_limit)
+{
+  alloc_object_size_limit = TYPE_MAX_VALUE (ssizetype);
+
+  unsigned HOST_WIDE_INT unit = 1;
+
+  char *end;
+  errno = 0;
+  unsigned HOST_WIDE_INT limit
+	= warn_alloc_limit ? strtoull (warn_alloc_limit, &end, 10) : 0;
+
+  if (limit && !errno)
+	{
+	  if (end && *end)
+	{
+	  /* Numeric option arguments are at most INT_MAX.  Make it
+		 possible to specify a larger value by accepting common
+		 suffixes.  */
+	  if (!strcmp (end, "kB"))
+		unit = 1000;
+	  else if (!strcasecmp (end, "KiB") || strcmp (end, "KB"))
+		unit = 1024;
+	  else if (!strcmp (end, "MB"))
+		unit = 1000LU * 1000;
+	  else if (!strcasecmp (end, "MiB"))
+		unit = 1024LU * 1024;
+	  else if (!strcasecmp (end, "GB"))
+		unit = 1000LU * 1000 * 1000;
+	  else if (!strcasecmp (end, "GiB"))
+		unit = 1024LU * 1024 * 1024;
+	  else if (!strcasecmp (end, "TB"))
+		unit = 1000LU * 1000 * 1000 * 1000;
+	  else if (!strcasecmp (end, "TiB"))
+		unit = 1024LU * 1024 * 1024 * 1024;
+	  else if (!strcasecmp (end, "PB"))
+		unit = 1000LU * 1000 * 1000 * 1000 * 1000;
+	  else if (!strcasecmp (end, "PiB"))
+		unit = 1024LU * 1024

[PATCH 0/4] MIPS16/GCC: `casesi_internal_mips16_' insn fixes and improvements

2016-11-13 Thread Maciej W. Rozycki
Hi,

 This small patch series addresses a small number of issues around the 
`casesi_internal_mips16_' insn discovered in the course of recent 
development.

 I have also made an attempt to factor the preparatory comparison and 
branch out as proper RTL operations from this insn, which is a relatively 
large assembly block.  That however turned out to trigger an apparent bug 
elsewhere if the default case calls `__builtin_unreachable', causing both 
the branch and all the following instructions starting from the table jump 
to be optimized away, as if both legs of the branch were unreachable 
rather than just one.  So I have backed out that fifth change until the 
nature of the problem has been investigated, however I do think we want to 
have it eventually as it should improve code scheduling in some cases.

 These changes have been successfully regression-tested all at once with 
the `mips-mti-linux-gnu' target and the little-endian MIPS16 o32 multilib 
only.  Since the pattern is only ever used with MIPS16 code generation the 
changes do not apply to non-MIPS16 multilibs.

 See individual patch descriptions for details.

  Maciej


[PATCH 1/4] MIPS16/GCC: Fix DImode `casesi_internal_mips16_' assembly instructions

2016-11-13 Thread Maciej W. Rozycki
Use 64-bit operations consistently for jump table address calculations 
across the assembly produced by the `casesi_internal_mips16_' insn 
where Pmode and consequently  is DImode.  Currently we have a 
mixture of 64-bit and 32-bit operations, which causes address truncation 
or undefined behaviour, depending on how the resulting binary is mapped.

gcc/
config/mips/mips.md (casesi_internal_mips16_): Add missing 
 instruction prefixes throughout.  Correct formatting.

gcc/testsuite/
* gcc.target/mips/code-readable-4.c (dg-final): Expect `dla' 
rather than `la'.
---
 OK to apply?

  Maciej

gcc-mips16-casesi-di.diff
Index: gcc/gcc/config/mips/mips.md
===
--- gcc.orig/gcc/config/mips/mips.md2016-11-12 10:51:56.0 +
+++ gcc/gcc/config/mips/mips.md 2016-11-14 02:05:52.853669422 +
@@ -6424,14 +6424,14 @@
 {
 case HImode:
   output_asm_insn ("sll\t%5, %0, 1", operands);
-  output_asm_insn ("la\t%4, %2", operands);
+  output_asm_insn ("la\t%4, %2", operands);
   output_asm_insn ("addu\t%5, %4, %5", operands);
   output_asm_insn ("lh\t%5, 0(%5)", operands);
   break;
 
 case SImode:
   output_asm_insn ("sll\t%5, %0, 2", operands);
-  output_asm_insn ("la\t%4, %2", operands);
+  output_asm_insn ("la\t%4, %2", operands);
   output_asm_insn ("addu\t%5, %4, %5", operands);
   output_asm_insn ("lw\t%5, 0(%5)", operands);
   break;
@@ -6439,9 +6439,9 @@
 default:
   gcc_unreachable ();
 }
-  
-  output_asm_insn ("addu\t%4, %4, %5", operands);
-  
+
+  output_asm_insn ("addu\t%4, %4, %5", operands);
+
   return "j\t%4";
 }
   [(set_attr "insn_count" "16")])
Index: gcc/gcc/testsuite/gcc.target/mips/code-readable-4.c
===
--- gcc.orig/gcc/testsuite/gcc.target/mips/code-readable-4.c2015-05-17 
22:30:27.0 +0100
+++ gcc/gcc/testsuite/gcc.target/mips/code-readable-4.c 2016-11-14 
02:11:31.384173468 +
@@ -41,7 +41,7 @@ bar (void)
   return k;
 }
 
-/* { dg-final { scan-assembler "\tla\t" } } */
+/* { dg-final { scan-assembler "\tdla\t" } } */
 /* { dg-final { scan-assembler "\t\\.half\t" } } */
 /* { dg-final { scan-assembler-not "%hi\\(\[^)\]*L" } } */
 /* { dg-final { scan-assembler-not "%lo\\(\[^)\]*L" } } */


[PATCH] Make std::future::share() noexcept (LWG 2556)

2016-11-13 Thread Jonathan Wakely

* include/std/future (future::share(), future::share())
(future::share()): Add noexcept, as per LWG 2556.

Tested powerpc64le-linux, committed to trunk.

commit a1f6a58629e8ebb02366266790bf5ab748846f4f
Author: Jonathan Wakely 
Date:   Mon Nov 14 03:17:50 2016 +

Make std::future::share() noexcept (LWG 2556)

* include/std/future (future::share(), future::share())
(future::share()): Add noexcept, as per LWG 2556.

diff --git a/libstdc++-v3/include/std/future b/libstdc++-v3/include/std/future
index cb42830..8ba1306 100644
--- a/libstdc++-v3/include/std/future
+++ b/libstdc++-v3/include/std/future
@@ -778,7 +778,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 return std::move(this->_M_get_result()._M_value());
   }
 
-  shared_future<_Res> share();
+  shared_future<_Res> share() noexcept;
 };
 
   /// Partial specialization for future
@@ -821,7 +821,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 return this->_M_get_result()._M_get();
   }
 
-  shared_future<_Res&> share();
+  shared_future<_Res&> share() noexcept;
 };
 
   /// Explicit specialization for future
@@ -864,7 +864,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 this->_M_get_result();
   }
 
-  shared_future share();
+  shared_future share() noexcept;
 };
 
 
@@ -1004,18 +1004,20 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 : _M_state(std::move(__uf._M_state))
 { }
 
+  // _GLIBCXX_RESOLVE_LIB_DEFECTS
+  // 2556. Wide contract for future::share()
   template
 inline shared_future<_Res>
-future<_Res>::share()
+future<_Res>::share() noexcept
 { return shared_future<_Res>(std::move(*this)); }
 
   template
 inline shared_future<_Res&>
-future<_Res&>::share()
+future<_Res&>::share() noexcept
 { return shared_future<_Res&>(std::move(*this)); }
 
   inline shared_future
-  future::share()
+  future::share() noexcept
   { return shared_future(std::move(*this)); }
 
   /// Primary template for promise


[PATCH 2/4] MIPS16/GCC: Correct `casesi_internal_mips16_'s RTL pattern

2016-11-13 Thread Maciej W. Rozycki
The machine operation performed in `casesi_internal_mips16_'s 
assembly is SLTU, which just like the `ltu' RTL operation expresses the 
less-than operation rather than less-than-or-equal usually performed by 
`casesi' patterns.  This is because there is no suitable single MIPS16 
hardware instruction for the less-than-or-equal operation.  This however 
is already taken into account by the caller, `casesi', by incrementing 
operand 1 before calling `casesi_internal_mips16_', so the overall 
calculation is equivalent.

So the generated assembly and consequently hardware operations are right 
and it is only the `casesi_internal_mips16_' insn whose RTL 
pattern does not match code produced.  Also this insn is only ever 
emitted with an explicit call to `emit_jump_insn' from `casesi' and it 
is a solid assembly code block, so the mismatch does not affect code 
produced.

Correct the RTL pattern then and use `ltu' rather than `leu' here.

gcc/
* config/mips/mips.md (casesi_internal_mips16_): Use the
`ltu' rather than `leu' operation in the RTL pattern
---
 OK to apply?

  Maciej

gcc-mips16-casesi-ltu.diff
Index: gcc/gcc/config/mips/mips.md
===
--- gcc.orig/gcc/config/mips/mips.md2016-11-09 18:57:01.883156298 +
+++ gcc/gcc/config/mips/mips.md 2016-11-09 20:15:10.392159385 +
@@ -6401,7 +6401,7 @@
 (define_insn "casesi_internal_mips16_"
   [(set (pc)
  (if_then_else
-   (leu (match_operand:SI 0 "register_operand" "d")
+   (ltu (match_operand:SI 0 "register_operand" "d")
(match_operand:SI 1 "arith_operand" "dI"))
(unspec:P
 [(match_dup 0)


[PATCH] Delete addressof for temporaries (LWG 2598)

2016-11-13 Thread Jonathan Wakely

* include/bits/move.h (addressof(const _Tp&&)): Add deleted overload,
as per LWG 2598.

Tested powerpc64le-linux, committed to trunk.

commit 5eb75d53b4575e736bf295dbdad313a66839bd9b
Author: Jonathan Wakely 
Date:   Mon Nov 14 03:28:38 2016 +

Delete addressof for temporaries (LWG 2598)

* include/bits/move.h (addressof(const _Tp&&)): Add deleted overload,
as per LWG 2598.

diff --git a/libstdc++-v3/include/bits/move.h b/libstdc++-v3/include/bits/move.h
index a5002fc..d0aefe7 100644
--- a/libstdc++-v3/include/bits/move.h
+++ b/libstdc++-v3/include/bits/move.h
@@ -137,6 +137,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 addressof(_Tp& __r) noexcept
 { return std::__addressof(__r); }
 
+  // _GLIBCXX_RESOLVE_LIB_DEFECTS
+  // 2598. addressof works on temporaries
+  template
+const _Tp* addressof(const _Tp&&) = delete;
+
   // C++11 version of std::exchange for internal use.
   template 
 inline _Tp


[PATCH 3/4] MIPS16/GCC: Improve `casesi_internal_mips16_'s instruction count estimate

2016-11-13 Thread Maciej W. Rozycki
A typical code sequence produced by the `casesi_internal_mips16_' 
insn is like this:

sltu$3, 11   # 16   casesi_internal_mips16_si   [length = 32]
bteqz   $L2
sll $5, $3, 1
la  $3, $L4
addu$5, $3, $5
lh  $5, 0($5)
addu$3, $3, $5
j   $3
.align  1
.align  2
.type   __jump_foo_4, @object
__jump_foo_4:
$L4:

which in turn assembles to this binary code:

   a:   5b0bsltiu   v1,11
   c:   601dbteqz   48 <__pool_foo_12>
   e:   3564sll a1,v1,1
  10:   0b03la  v1,1c <__jump_foo_4>
  12:   e3b5addua1,v1,a1
  14:   8da0lh  a1,0(a1)
  16:   e3adadduv1,a1
  18:   eb80jrc v1
  1a:   6500nop

001c <__jump_foo_4>:

As you can see the code length estimate is 32, which in turn comes from 
the instruction count being set to 16 for the insn, telling the compiler 
that the pattern will produce the equivalent of 16 regular (16-bit or 
unextended) MIPS16 instructions, as per the attribute's definition.

This estimate is too pessimistic as this pattern will never actually 
reach so many instructions.  Taking the instructions produced one by one 
we have:

1.  sltu$3, 11 => 1 or 2 depending on the immediate  => 2

2.  bteqz   $L2=> 1 or 2 depending on label distance => 2

3.  sll $5, $3, 1  => (HImode) fixed 1
sll $5, $3, 2  => (SImode) fixed 1   => 1

4.  la  $3, $L4=> (Pmode == SImode) fixed 1 as $L4
  is close and word-aligned
dla $3, $L4=> (Pmode == DImode) fixed 1 as $L4
  is close and word-aligned  => 1

5.  addu$5, $3, $5 => (Pmode == SImode) fixed 1
daddu   $5, $3, $5 => (Pmode == DImode) fixed 1  => 1

6.  lh  $5, 0($5)  => (HImode) fixed 1
lw  $5, 0($5)  => (SImode) fixed 1   => 1

7.  addu$3, $3, $5 => (Pmode == SImode) fixed 1
daddu   $3, $3, $5 => (Pmode == SImode) fixed 1  => 1

8.  j   $3 => 1 if JRC is used or 2 if JR/NOP is => 2
 
   11

Word alignment of the jump table start is explicitly arranged by 
ASM_OUTPUT_BEFORE_CASE_LABEL and is beneficial as we can use the short 
encoding of LH at no loss in code size, because any 2-byte padding
produced by the `.align 2' pseudo-op would otherwise be consumed by the 
extended form of LH required to encode a PC-relative offset which is not 
a multiple of 4, possibly at some performance loss required for the 
extra instruction halfword fetch.

Set the instruction count to 11 then.

gcc/
* config/mips/mips.md (casesi_internal_mips16_): Set 
`insn_count' to 11 rather than 16.
---
 OK to apply?

  Maciej

gcc-mips16-casesi-insn-count.diff
Index: gcc/gcc/config/mips/mips.md
===
--- gcc.orig/gcc/config/mips/mips.md2016-11-12 10:57:12.544746018 +
+++ gcc/gcc/config/mips/mips.md 2016-11-12 10:57:13.972699749 +
@@ -6444,7 +6444,7 @@
 
   return "j\t%4";
 }
-  [(set_attr "insn_count" "16")])
+  [(set_attr "insn_count" "11")])
 
 ;; For TARGET_USE_GOT, we save the gp in the jmp_buf as well.
 ;; While it is possible to either pull it off the stack (in the


[PATCH 4/4] MIPS16/GCC: Emit explicit JRC from`casesi_internal_mips16_' insn

2016-11-13 Thread Maciej W. Rozycki
Explicitly switch between the JR and JRC instructions for the table jump 
in `casesi_internal_mips16_', depending on their availability in 
the ISA level chosen, taking away the reliance on assembler relaxation.  
Adjust the instruction count accordingly now that we control the length
of this code piece ourselves.

gcc/
* config/mips/mips.md (casesi_internal_mips16_):
Explicitly switch between JR and JRC for the table jump.  Adjust 
instruction count.
---
 OK to apply?

  Maciej

gcc-mips16-casesi-ret.diff
Index: gcc/gcc/config/mips/mips.md
===
--- gcc.orig/gcc/config/mips/mips.md2016-11-12 10:57:13.0 +
+++ gcc/gcc/config/mips/mips.md 2016-11-12 10:57:30.158107981 +
@@ -6442,9 +6442,15 @@
 
   output_asm_insn ("addu\t%4, %4, %5", operands);
 
-  return "j\t%4";
+  if (GENERATE_MIPS16E)
+return "jrc\t%4";
+  else
+return "jr\t%4";
 }
-  [(set_attr "insn_count" "11")])
+  [(set (attr "insn_count")
+   (if_then_else (match_test "GENERATE_MIPS16E")
+ (const_string "10")
+ (const_string "11")))])
 
 ;; For TARGET_USE_GOT, we save the gp in the jmp_buf as well.
 ;; While it is possible to either pull it off the stack (in the


Unroll and Jam loop transformation

2016-11-13 Thread Michael Matz
Hi,

I'm working on this since some time; I have various extensions to it in 
the works (hinted at in the comments), but haven't yet stabilized them.  
But this is useful on its own as is, so lets get it out before midnight at 
UTC-12 (hey, that's still 7 hours to go) ;)  Basically unroll-and-jam 
deals with such loops:

  unsigned long i, j;
  for (i = 0; i < m; i++) {
  for (j = 0; j < n; j++) {
  a[j*m+i] = b[j*m+i] + b[j*m+i+1];
  }
  }

Ignore the fact that this nest could also be switched to improve 
performance, note that there's data reuse going on for the 'i' index of 
the outer loop (the [i+1] load will be the [i] load in the next 
iteration).  Unroll-and-jam deals with this by effectively unrolling the 
outer loop and then fusing the now adjacent copies of the inner loop:

  for (i = 0; i < m; i+=2) {
  for (j = 0; j < n; j++) {
  a[j*m+i] = b[j*m+i] + b[j*m+i+1];
  a[j*m+i+1] = b[j*m+i+1] + b[j*m+i+1+1];
  }
  }

Now the two b[...i+1] loads are trivial to see and reuse.  Obviously this 
is only valid in certain circumstances.

So, see patch.  For now I've tacked it to the loop splitting pass (when no 
splitting happens unroll-and-jam is tried).  Probably I should then also 
rename the pass (suggestions?).  The changes in chrec and data-ref 
routines are necessary to fix some ICEs in the testsuite that already 
occur when simply doing the existing data-dep analysis as the patch does 
(i.e. on a two-loop nest), without any transformations.

The patch was tested with regstrapping on x86-64-linux with a change to 
force it active with -O2 already (so that the bootstrap excercises it).  
As proposed it would be -O3.

There are no regressions except some changes in excpected info output: 
it's sometimes the case that the unrolling creates an epilogue loop that 
can be vectorized when the fused loop can, so the number of vectorized 
loops (or similar dump info) doubles; i.e. some testsuite churn.  Should 
I disable this pass for those testcases or should I adjust the expected 
output?

I'd like to get this into GCC 7 if possible (and will continue to work on 
the further improvements).

Comments?  Okay for trunk with the nits fixed in which way? :)


Ciao,
Michael.
* tree-chrec.c (chrec_fold_plus_poly_poly): Accept subtracting
two pointers.
* tree-data-ref.c (analyze_miv_subscript): If subtracting two
pointers the target type is sizetype.

* tree-ssa-loop-split.c (fix_loop_structure): New function.
(bb_prevents_fusion_p): Ditto.
(unroll_jam_possible_p): Ditto.
(fuse_loops): Ditto.
(determine_reuse): Ditto.
(reverse_list): Ditto.
(tree_loop_unroll_and_jam): Ditto.
(pass_loop_split::execute): Call new pass.

diff --git a/gcc/tree-chrec.c b/gcc/tree-chrec.c
index cefac2c..6b900f2 100644
--- a/gcc/tree-chrec.c
+++ b/gcc/tree-chrec.c
@@ -106,8 +106,11 @@ chrec_fold_plus_poly_poly (enum tree_code code,
   gcc_assert (TREE_CODE (poly0) == POLYNOMIAL_CHREC);
   gcc_assert (TREE_CODE (poly1) == POLYNOMIAL_CHREC);
   if (POINTER_TYPE_P (chrec_type (poly0)))
-gcc_checking_assert (ptrofftype_p (chrec_type (poly1))
-&& useless_type_conversion_p (type, chrec_type 
(poly0)));
+gcc_checking_assert ((POINTER_TYPE_P (chrec_type (poly1))
+ && code == MINUS_EXPR)
+|| (ptrofftype_p (chrec_type (poly1))
+&& useless_type_conversion_p (type,
+  chrec_type 
(poly0;
   else
 gcc_checking_assert (useless_type_conversion_p (type, chrec_type (poly0))
 && useless_type_conversion_p (type, chrec_type 
(poly1)));
diff --git a/gcc/tree-data-ref.c b/gcc/tree-data-ref.c
index 8152da3..85454ad 100644
--- a/gcc/tree-data-ref.c
+++ b/gcc/tree-data-ref.c
@@ -2932,9 +2932,15 @@ analyze_miv_subscript (tree chrec_a,
   if (dump_file && (dump_flags & TDF_DETAILS))
 fprintf (dump_file, "(analyze_miv_subscript \n");
 
-  type = signed_type_for_types (TREE_TYPE (chrec_a), TREE_TYPE (chrec_b));
-  chrec_a = chrec_convert (type, chrec_a, NULL);
-  chrec_b = chrec_convert (type, chrec_b, NULL);
+  type = TREE_TYPE (chrec_a);
+  if (type != TREE_TYPE (chrec_b))
+{
+  type = signed_type_for_types (TREE_TYPE (chrec_a), TREE_TYPE (chrec_b));
+  chrec_a = chrec_convert (type, chrec_a, NULL);
+  chrec_b = chrec_convert (type, chrec_b, NULL);
+}
+  else if (POINTER_TYPE_P (type))
+type = sizetype;
   difference = chrec_fold_minus (type, chrec_a, chrec_b);
 
   if (eq_evolutions_p (chrec_a, chrec_b))
diff --git a/gcc/tree-ssa-loop-split.c b/gcc/tree-ssa-loop-split.c
index dac68e6..118a203 100644
--- a/gcc/tree-ssa-loop-split.c
+++ b/gcc/tree-ssa-loop-split.c
@@ -39,6 +39,9 @@ along with GCC; see the file COPYING3.  If not see
 #include "cfghooks.h"
 #include "gimple-fold.h"
 #include "gimplify-me.h"
+#inc

Re: [WIP C++ PATCH] P0217R3 - C++17 structured bindings

2016-11-13 Thread Jason Merrill
On Wed, Nov 9, 2016 at 8:05 AM, Jakub Jelinek  wrote:
> On Wed, Nov 09, 2016 at 01:24:22PM +0100, Jakub Jelinek wrote:
>> The following patch is a WIP on P0217R3 - decomposition declarations.
>> It contains various FIXMEs, Jason, do you think you could finish it up?

Here's what I'm checking in, as a delta from from your patch.  More
testcases would still be welcome.
commit cb763ca9dafb0aa6847bcfcc8ee776dcd78e1abb
Author: Jason Merrill 
Date:   Sat Nov 12 00:15:35 2016 -0800

Implement P0217R3 - C++17 structured bindings

gcc/cp/
* cp-tree.h (struct lang_decl_base): Add decomposition_p.
(DECL_DECOMPOSITION_P): New
(enum auto_deduction_context): Add adc_decomp_type.
(enum cp_declarator_kind): Add cdk_decomp.
* constexpr.c (cxx_eval_constant_expression): Look through
DECL_VALUE_EXPR.
(potential_constant_expression_1): Likewise.
* decl.c (reshape_init): Preserve CONSTRUCTOR_IS_DIRECT_INIT.
(check_initializer): Use build_aggr_init for DECL_DECOMPOSITION_P.
(cp_finish_decl): Pass adc_decomp_type for decomposition.
(find_decomp_class_base, get_tuple_size, get_tuple_element_type)
(get_tuple_decomp_init, cp_finish_decomp): New.
(grokdeclarator): Handle decomposition.
* init.c (build_aggr_init): Handle decomposition array.
(build_vec_init): Handle initialization from { array }.
* name-lookup.c (add_function): Always wrap TEMPLATE_DECL in
OVERLOAD.
* parser.c (declarator_can_be_parameter_pack): Handle cdk_decomp.
(function_declarator_p, strip_declarator_types)
(cp_parser_check_declarator_template_parameters): Likewise.
(cp_parser_range_for, cp_convert_range_for): Handle decomposition.
(cp_parser_simple_declaration): Parse decomposition.
(cp_parser_decomposition_declaration): New.
* pt.c (tsubst_decomp_names): New.
(subst_expr) [DECL_EXPR, RANGE_FOR_STMT]: Handle decomposition.
(do_auto_deduction): Handle adc_decomp_type.
* semantics.c (finish_decltype_type): Look through DECL_VALUE_EXPR.
* typeck.c (is_bitfield_expr_with_lowered_type): Likewise.
* tree.c (lvalue_kind): Likewise.
(cp_build_reference_type): Handle reference collapsing.

diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c
index 739e902..e8c7702 100644
--- a/gcc/cp/constexpr.c
+++ b/gcc/cp/constexpr.c
@@ -3770,7 +3770,7 @@ cxx_eval_constant_expression (const constexpr_ctx *ctx, 
tree t,
   return (*ctx->values->get (t));
 
 case VAR_DECL:
-  if (is_capture_proxy (t))
+  if (DECL_HAS_VALUE_EXPR_P (t))
return cxx_eval_constant_expression (ctx, DECL_VALUE_EXPR (t),
 lval, non_constant_p, overflow_p);
   /* fall through */
@@ -5037,6 +5037,8 @@ potential_constant_expression_1 (tree t, bool want_rval, 
bool strict,
   return RECUR (TREE_OPERAND (t, 0), rval);
 
 case VAR_DECL:
+  if (DECL_HAS_VALUE_EXPR_P (t))
+   return RECUR (DECL_VALUE_EXPR (t), rval);
   if (want_rval
  && !var_in_maybe_constexpr_fn (t)
  && !type_dependent_expression_p (t)
diff --git a/gcc/cp/cp-gimplify.c b/gcc/cp/cp-gimplify.c
index f44bd32..9b9b511 100644
--- a/gcc/cp/cp-gimplify.c
+++ b/gcc/cp/cp-gimplify.c
@@ -617,14 +617,6 @@ cp_gimplify_expr (tree *expr_p, gimple_seq *pre_p, 
gimple_seq *post_p)
int from_array = (init && TREE_CODE (TREE_TYPE (init)) == ARRAY_TYPE);
gcc_assert (EXPR_HAS_LOCATION (*expr_p));
input_location = EXPR_LOCATION (*expr_p);
-   if (VAR_P (VEC_INIT_EXPR_SLOT (*expr_p))
-   && DECL_DECOMPOSITION_P (VEC_INIT_EXPR_SLOT (*expr_p))
-   && init
-   && DIRECT_LIST_INIT_P (init)
-   && CONSTRUCTOR_NELTS (init) == 1
-   && (TREE_CODE (TREE_TYPE (CONSTRUCTOR_ELT (init, 0)->value))
-   == ARRAY_TYPE))
- from_array = 1;
*expr_p = build_vec_init (VEC_INIT_EXPR_SLOT (*expr_p), NULL_TREE,
  init, VEC_INIT_EXPR_VALUE_INIT (*expr_p),
  from_array,
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index e684996..f142c1f 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -6074,6 +6074,10 @@ reshape_init (tree type, tree init, tsubst_flags_t 
complain)
return error_mark_node;
 }
 
+  if (CONSTRUCTOR_IS_DIRECT_INIT (init)
+  && BRACE_ENCLOSED_INITIALIZER_P (new_init))
+CONSTRUCTOR_IS_DIRECT_INIT (new_init) = true;
+
   return new_init;
 }
 
@@ -6194,15 +6198,6 @@ check_initializer (tree decl, tree init, int flags, 
vec **cleanups)
   gcc_assert (init != NULL_TREE);
   init = NULL_TREE;
 }
-  else if (VAR_P (decl)
-  && DECL_DECOMPOSITION_P (decl)
-  && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
-{

C++ PATCH to improve various small diagnostic issues

2016-11-13 Thread Jason Merrill
A few things I noticed while working on C++17 decomposition.

* We were omitting any explicit template arguments in the "no match" error.
* We were complaining about a missing nested type rather than an
incomplete enclosing type.
* We weren't printing the new type when an alias-declaration is
redeclared to a different type.

Tested x86_64-pc-linux-gnu, applying to trunk.
commit d221ee0ac4e748bfa910d95bbaf994d803154589
Author: Jason Merrill 
Date:   Fri Nov 11 16:54:03 2016 -0800

Improve various diagnostic issues.

  * decl.c (make_typename_type): Call cxx_incomplete_type_error.
  * parser.c (cp_parser_diagnose_invalid_type_name): Likewise.
  * error.c (dump_decl): Fix printing of alias declaration.
  * call.c (build_new_method_call_1): Include template arguments in error.

diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index 0dcf322..f6f4590 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -4146,8 +4146,16 @@ static void
 print_error_for_call_failure (tree fn, vec *args,
  struct z_candidate *candidates)
 {
+  tree targs = NULL_TREE;
+  if (TREE_CODE (fn) == TEMPLATE_ID_EXPR)
+{
+  targs = TREE_OPERAND (fn, 1);
+  fn = TREE_OPERAND (fn, 0);
+}
   tree name = DECL_NAME (OVL_CURRENT (fn));
   location_t loc = location_of (name);
+  if (targs)
+name = lookup_template_function (name, targs);
 
   if (!any_strictly_viable (candidates))
 error_at (loc, "no matching function for call to %<%D(%A)%>",
@@ -4215,8 +4223,6 @@ build_new_function_call (tree fn, vec 
**args, bool koenig_p,
return cp_build_function_call_vec (candidates->fn, args, complain);
 
  // Otherwise, emit notes for non-viable candidates.
- if (TREE_CODE (fn) == TEMPLATE_ID_EXPR)
-   fn = TREE_OPERAND (fn, 0);
  print_error_for_call_failure (fn, *args, candidates);
}
   result = error_mark_node;
@@ -8649,19 +8655,20 @@ build_new_method_call_1 (tree instance, tree fns, 
vec **args,
   TREE_TYPE (instance));
  else
{
- char *pretty_name;
- bool free_p;
- tree arglist;
-
- pretty_name = name_as_c_string (name, basetype, &free_p);
- arglist = build_tree_list_vec (user_args);
+ tree arglist = build_tree_list_vec (user_args);
+ tree errname = name;
+ if (IDENTIFIER_CTOR_OR_DTOR_P (errname))
+   {
+ tree fn = DECL_ORIGIN (get_first_fn (fns));
+ errname = DECL_NAME (fn);
+   }
+ if (explicit_targs)
+   errname = lookup_template_function (errname, explicit_targs);
  if (skip_first_for_error)
arglist = TREE_CHAIN (arglist);
- error ("no matching function for call to %<%T::%s(%A)%#V%>",
-basetype, pretty_name, arglist,
+ error ("no matching function for call to %<%T::%E(%A)%#V%>",
+basetype, errname, arglist,
 TREE_TYPE (instance));
- if (free_p)
-   free (pretty_name);
}
  print_z_candidates (location_of (name), candidates);
}
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 6101504..ccd65b1 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -3756,8 +3756,13 @@ make_typename_type (tree context, tree name, enum 
tag_types tag_type,
   if (!t)
 {
   if (complain & tf_error)
-   error (want_template ? G_("no class template named %q#T in %q#T")
-  : G_("no type named %q#T in %q#T"), name, context);
+   {
+ if (!COMPLETE_TYPE_P (context))
+   cxx_incomplete_type_error (NULL_TREE, context);
+ else
+   error (want_template ? G_("no class template named %q#T in %q#T")
+  : G_("no type named %q#T in %q#T"), name, context);
+   }
   return error_mark_node;
 }
   
diff --git a/gcc/cp/error.c b/gcc/cp/error.c
index aa92a7e..fe1f751 100644
--- a/gcc/cp/error.c
+++ b/gcc/cp/error.c
@@ -1049,7 +1049,9 @@ dump_decl (cxx_pretty_printer *pp, tree t, int flags)
  pp_cxx_whitespace (pp);
  pp_cxx_ws_string (pp, "=");
  pp_cxx_whitespace (pp);
- dump_type (pp, DECL_ORIGINAL_TYPE (t), flags);
+ dump_type (pp, (DECL_ORIGINAL_TYPE (t)
+ ? DECL_ORIGINAL_TYPE (t) : TREE_TYPE (t)),
+flags);
  break;
}
   if ((flags & TFF_DECL_SPECIFIERS)
diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c
index 8db6cfd..172ec82 100644
--- a/gcc/cp/name-lookup.c
+++ b/gcc/cp/name-lookup.c
@@ -565,7 +565,8 @@ supplement_binding_1 (cxx_binding *binding, tree decl)
 }
   else
 {
-  diagnose_name_conflict (decl, bval);
+  if (!error_operand_p (bval))
+   diagnose_name_conflict (decl, bval);
   ok = false;
 }
 
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index b3b69b3..4204fa5 100644
--- 

Re: Fix PR77881: combine improvement

2016-11-13 Thread Michael Matz
Hi,

On Sat, 12 Nov 2016, Segher Boessenkool wrote:

> Hi Michael,
> 
> On Thu, Oct 20, 2016 at 04:20:09PM +0200, Michael Matz wrote:
> > PR missed-optimization/77881
> > * combine.c (simplify_comparison): Remove useless subregs
> > also inside the loop, not just after it.
> > 
> > testsuite/
> > * gcc.target/i386/pr77881.c: New test.
> 
> This isn't checked in yet, do you still want it?

Gnah, fell through the cracks.  I had to fix something else in combine to 
make it not regress in the testsuite.  The problem is that removing the 
subregs enables further simplifications which in turn might not be 
expected down-stream.  The particular problem was that originally the loop 
was left with an (subreg:QI (and:SI (lrshift X 24) 255) 0), whose inner op 
in turn was recognized by make_compound_operation and transformed into an 
extract.

With the patch we leave the loop now with essentially
  (subreg:QI (lrshift X 24) 0)
which of course is just the same masking and hence extract, but 
make_compound_operation didn't know.  With the amended patch it does.  I 
didn't come around making the AND and SUBREG handling a bit more common 
(which I initially wanted to do before posting), so for now I'm handling 
only the specific case I hit.

With this patch there are now no regressions on x86-64-linux (bootstrapped 
with all languages+ada).  Okay for trunk?


Ciao,
Michael.
PR missed-optimization/77881
* combine.c (simplify_comparison): Remove useless subregs
also inside the loop, not just after it.
(make_compound_operation): Recognize some subregs as being
masking as well.

testsuite/
* gcc.target/i386/pr77881.c: New test.

diff --git a/gcc/combine.c b/gcc/combine.c
index 6ffa387..0210685 100644
--- a/gcc/combine.c
+++ b/gcc/combine.c
@@ -8102,6 +8102,18 @@ make_compound_operation (rtx x, enum rtx_code in_code)
rtx inner = SUBREG_REG (x), simplified;
enum rtx_code subreg_code = in_code;
 
+   /* If the SUBREG is masking of a logical right shift,
+  make an extraction.  */
+   if (GET_CODE (inner) == LSHIFTRT
+   && GET_MODE_SIZE (mode) < GET_MODE_SIZE (GET_MODE (inner))
+   && subreg_lowpart_p (x))
+ {
+   new_rtx = make_compound_operation (XEXP (inner, 0), next_code);
+   new_rtx = make_extraction (mode, new_rtx, 0, XEXP (inner, 1),
+  mode_width, 1, 0, in_code == COMPARE);
+   break;
+ }
+
/* If in_code is COMPARE, it isn't always safe to pass it through
   to the recursive make_compound_operation call.  */
if (subreg_code == COMPARE
@@ -11994,6 +12006,29 @@ simplify_comparison (enum rtx_code code, rtx *pop0, 
rtx *pop1)
  if (subreg_lowpart_p (op0)
  && GET_MODE_PRECISION (GET_MODE (SUBREG_REG (op0))) < mode_width)
;
+ else if (subreg_lowpart_p (op0)
+  && GET_MODE_CLASS (GET_MODE (op0)) == MODE_INT
+  && GET_MODE_CLASS (GET_MODE (SUBREG_REG (op0))) == MODE_INT
+  && (code == NE || code == EQ)
+  && (GET_MODE_PRECISION (GET_MODE (SUBREG_REG (op0)))
+  <= HOST_BITS_PER_WIDE_INT)
+  && !paradoxical_subreg_p (op0)
+  && (nonzero_bits (SUBREG_REG (op0),
+GET_MODE (SUBREG_REG (op0)))
+  & ~GET_MODE_MASK (GET_MODE (op0))) == 0)
+   {
+ /* Remove outer subregs that don't do anything.  */
+ tem = gen_lowpart (GET_MODE (SUBREG_REG (op0)), op1);
+ 
+ if ((nonzero_bits (tem, GET_MODE (SUBREG_REG (op0)))
+  & ~GET_MODE_MASK (GET_MODE (op0))) == 0)
+   {
+ op0 = SUBREG_REG (op0);
+ op1 = tem;
+ continue;
+   }
+ break;
+   }
  else
break;
 
diff --git a/gcc/testsuite/gcc.target/i386/pr77881.c 
b/gcc/testsuite/gcc.target/i386/pr77881.c
new file mode 100644
index 000..80d143f
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr77881.c
@@ -0,0 +1,12 @@
+/* { dg-do compile } */
+/* { dg-require-effective-target pie } */
+/* { dg-options "-O2" } */
+extern void baz(void);
+int
+foo (long long int a, long long int a2, int b)
+{
+if (a < 0 || b)
+  baz ();
+}
+/* { dg-final { scan-assembler "js\[ \t\]\.L" } } */
+/* { dg-final { scan-assembler "jne\[ \t\]\.L" } } */


Re: [WIP C++ PATCH] P0217R3 - C++17 structured bindings

2016-11-13 Thread Jason Merrill
On Wed, Nov 9, 2016 at 7:24 AM, Jakub Jelinek  wrote:
> The match.pd hunk is needed, otherwise the generic folding happily folds
> int arr[2];
> ...
> auto [ x, y ] = arr;
> &x == &arr[0]
> into 0, because it thinks x and arr are distinct VAR_DECLs.  Though, if
> such comparisons are required to be folded in constexpr contexts under
> certain conditions, we'd need to handle the DECL_VALUE_EXPRs in constexpr.c
> somehow.

What do you think of this approach instead?
commit 7aa4bc14bdd8f01937ce2dc148722f0468d66d1b
Author: Jason Merrill 
Date:   Sun Nov 13 19:17:40 2016 -0500

addr_base

diff --git a/gcc/match.pd b/gcc/match.pd
index 79a418f..29ddcd8 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -2547,15 +2547,8 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
 (with
  {
int equal = 2;
-   /* Punt in GENERIC on variables with value expressions;
- the value expressions might point to fields/elements
- of other vars etc.  */
-   if (GENERIC
-  && ((VAR_P (base0) && DECL_HAS_VALUE_EXPR_P (base0))
-  || (VAR_P (base1) && DECL_HAS_VALUE_EXPR_P (base1
-;
-   else if (decl_in_symtab_p (base0)
-   && decl_in_symtab_p (base1))
+   if (decl_in_symtab_p (base0)
+  && decl_in_symtab_p (base1))
  equal = symtab_node::get_create (base0)
   ->equal_address_to (symtab_node::get_create (base1));
else if ((DECL_P (base0)
diff --git a/gcc/tree-dfa.c b/gcc/tree-dfa.c
index 0396feb..0a8523b 100644
--- a/gcc/tree-dfa.c
+++ b/gcc/tree-dfa.c
@@ -673,6 +673,15 @@ get_addr_base_and_unit_offset_1 (tree exp, HOST_WIDE_INT 
*poffset,
 {
   switch (TREE_CODE (exp))
{
+   case VAR_DECL:
+ if (DECL_HAS_VALUE_EXPR_P (exp))
+   {
+ exp = DECL_VALUE_EXPR (exp);
+ continue;
+   }
+ else
+   goto done;
+
case BIT_FIELD_REF:
  {
HOST_WIDE_INT this_off = TREE_INT_CST_LOW (TREE_OPERAND (exp, 2));


Re: [patch,libgfortran] PR51119 - MATMUL slow for large matrices

2016-11-13 Thread Thomas Koenig

Hi Jerry,

I think this

+  /* Parameter adjustments */
+  c_dim1 = m;
+  c_offset = 1 + c_dim1;

should be

+  /* Parameter adjustments */
+  c_dim1 = rystride;
+  c_offset = 1 + c_dim1;

Regarding options for matmul:  It is possible to add the
options to the lines in Makefile.in

# Turn on vectorization and loop unrolling for matmul.
$(patsubst %.c,%.lo,$(notdir $(i_matmul_c))): AM_CFLAGS += 
-ftree-vectorize -funroll-loops


This is a great step forward.  I think we can close most matmul-related
PRs once this patch has been applied.

Regards

Thomas



Re: [WIP C++ PATCH] P0217R3 - C++17 structured bindings

2016-11-13 Thread Jakub Jelinek
On Sun, Nov 13, 2016 at 11:53:10PM -0500, Jason Merrill wrote:
> On Wed, Nov 9, 2016 at 8:05 AM, Jakub Jelinek  wrote:
> > On Wed, Nov 09, 2016 at 01:24:22PM +0100, Jakub Jelinek wrote:
> >> The following patch is a WIP on P0217R3 - decomposition declarations.
> >> It contains various FIXMEs, Jason, do you think you could finish it up?
> 
> Here's what I'm checking in, as a delta from from your patch.  More
> testcases would still be welcome.

Thanks, I'll try to add some more testsuite coverage in stage3.
But, it seems you haven't checked the testcases (except for the modification
of existing one).

Jakub


Re: [WIP C++ PATCH] P0217R3 - C++17 structured bindings

2016-11-13 Thread Jakub Jelinek
On Mon, Nov 14, 2016 at 08:11:25AM +0100, Jakub Jelinek wrote:
> On Sun, Nov 13, 2016 at 11:53:10PM -0500, Jason Merrill wrote:
> > On Wed, Nov 9, 2016 at 8:05 AM, Jakub Jelinek  wrote:
> > > On Wed, Nov 09, 2016 at 01:24:22PM +0100, Jakub Jelinek wrote:
> > >> The following patch is a WIP on P0217R3 - decomposition declarations.
> > >> It contains various FIXMEs, Jason, do you think you could finish it up?
> > 
> > Here's what I'm checking in, as a delta from from your patch.  More
> > testcases would still be welcome.
> 
> Thanks, I'll try to add some more testsuite coverage in stage3.
> But, it seems you haven't checked the testcases (except for the modification
> of existing one).

I've checked them in now after retesting them.

Jakub