[PATCH] Fix for PR63587

2014-10-29 Thread Martin Liška

Hello.

Following patch fixes PR63587, where we put DECL_RESULT in 
cgraph_node::expand_thunk to local_decls.
Patch has been tested on x86_64-linux-pc without any regression and boostrap 
works correctly.

Ready for thunk?
Thanks,
Martin
gcc/testsuite/ChangeLog:

2014-10-29  Martin Liska  mli...@suse.cz

* g++.dg/ipa/pr63587-1.C: New test.
* g++.dg/ipa/pr63587-2.C: New test.


gcc/ChangeLog:

2014-10-29  Martin Liska  mli...@suse.cz

* cgraphunit.c (cgraph_node::expand_thunk): Only VAR_DECLs are put
to local declarations.
* function.c (add_local_decl): Implementation moved from header
file, assert introduced for tree type.
* function.h: Likewise.

diff --git a/gcc/cgraphunit.c b/gcc/cgraphunit.c
index a86bd1b..6f61f5c 100644
--- a/gcc/cgraphunit.c
+++ b/gcc/cgraphunit.c
@@ -1550,7 +1550,9 @@ cgraph_node::expand_thunk (bool output_asm_thunks, bool force_gimple_thunk)
 	  else if (!is_gimple_reg_type (restype))
 	{
 	  restmp = resdecl;
-	  add_local_decl (cfun, restmp);
+
+	  if (TREE_CODE (restmp) == VAR_DECL)
+		add_local_decl (cfun, restmp);
 	  BLOCK_VARS (DECL_INITIAL (current_function_decl)) = restmp;
 	}
 	  else
diff --git a/gcc/function.c b/gcc/function.c
index ee229ad..893ca6f 100644
--- a/gcc/function.c
+++ b/gcc/function.c
@@ -6441,6 +6441,15 @@ match_asm_constraints_1 (rtx_insn *insn, rtx *p_sets, int noutputs)
 df_insn_rescan (insn);
 }
 
+/* Add the decl D to the local_decls list of FUN.  */
+
+void
+add_local_decl (struct function *fun, tree d)
+{
+  gcc_assert (TREE_CODE (d) == VAR_DECL);
+  vec_safe_push (fun-local_decls, d);
+}
+
 namespace {
 
 const pass_data pass_data_match_asm_constraints =
diff --git a/gcc/function.h b/gcc/function.h
index 66384e5..aa47018 100644
--- a/gcc/function.h
+++ b/gcc/function.h
@@ -668,11 +668,7 @@ struct GTY(()) function {
 
 /* Add the decl D to the local_decls list of FUN.  */
 
-static inline void
-add_local_decl (struct function *fun, tree d)
-{
-  vec_safe_push (fun-local_decls, d);
-}
+void add_local_decl (struct function *fun, tree d);
 
 #define FOR_EACH_LOCAL_DECL(FUN, I, D)		\
   FOR_EACH_VEC_SAFE_ELT_REVERSE ((FUN)-local_decls, I, D)
diff --git a/gcc/testsuite/g++.dg/ipa/pr63587-1.C b/gcc/testsuite/g++.dg/ipa/pr63587-1.C
new file mode 100644
index 000..cbf872e
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ipa/pr63587-1.C
@@ -0,0 +1,92 @@
+// PR ipa/63587
+// { dg-do compile { target c++11 } }
+// { dg-options -O2 -fno-strict-aliasing }
+
+template class struct A
+{
+};
+template typename struct B
+{
+  template typename struct C;
+};
+class D;
+template typename class F;
+struct G
+{
+  void operator()(const D , D);
+};
+class D
+{
+public:
+  D (int);
+};
+struct H
+{
+  H (int);
+};
+template typename _Key, typename, typename, typename _Compare, typename
+class I
+{
+  typedef _Key key_type;
+  template typename _Key_compare struct J
+  {
+_Key_compare _M_key_compare;
+  };
+  J_Compare _M_impl;
+
+public:
+  Aint _M_get_insert_unique_pos (const key_type );
+  Aint _M_get_insert_hint_unique_pos (H );
+  template typename... _Args int _M_emplace_hint_unique (H, _Args ...);
+};
+template typename _Key, typename _Tp, typename _Compare = G,
+	  typename _Alloc = FA_Tp  
+class K
+{
+  typedef _Key key_type;
+  typedef _Key value_type;
+  typedef typename B_Alloc::template Cvalue_type _Pair_alloc_type;
+  Ikey_type, value_type, int, _Compare, _Pair_alloc_type _M_t;
+
+public:
+  void operator[](key_type)
+  {
+_M_t._M_emplace_hint_unique (0);
+  }
+};
+template typename _Key, typename _Val, typename _KeyOfValue,
+	  typename _Compare, typename _Alloc
+Aint
+I_Key, _Val, _KeyOfValue, _Compare, _Alloc::_M_get_insert_unique_pos (
+  const key_type p1)
+{
+  _M_impl._M_key_compare (p1, 0);
+}
+template typename _Key, typename _Val, typename _KeyOfValue,
+	  typename _Compare, typename _Alloc
+Aint
+I_Key, _Val, _KeyOfValue, _Compare, _Alloc::_M_get_insert_hint_unique_pos (
+  H )
+{
+  _M_get_insert_unique_pos (0);
+}
+template typename _Key, typename _Val, typename _KeyOfValue,
+	  typename _Compare, typename _Alloc
+template typename... _Args
+int
+I_Key, _Val, _KeyOfValue, _Compare, _Alloc::_M_emplace_hint_unique (
+  H p1, _Args ...)
+{
+  _M_get_insert_hint_unique_pos (p1);
+}
+namespace {
+struct L;
+}
+void
+fn1 ()
+{
+  KD, L a;
+  a[0];
+  KD, int b;
+  b[0];
+}
diff --git a/gcc/testsuite/g++.dg/ipa/pr63587-2.C b/gcc/testsuite/g++.dg/ipa/pr63587-2.C
new file mode 100644
index 000..f31c5bd
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ipa/pr63587-2.C
@@ -0,0 +1,250 @@
+// PR ipa/63587
+// { dg-do compile { target c++11 } }
+// { dg-options -O2 }
+
+namespace boost {
+class basic_cstring
+{
+public:
+  basic_cstring (char *);
+};
+template typename struct identity
+{
+};
+struct make_identity;
+struct function_buffer
+{
+};
+template typename FunctionObj struct function_obj_invoker0
+{
+  static int
+  invoke (function_buffer )
+  {
+FunctionObj f;
+  

Re: [PATCH] Fix for PR63587

2014-10-29 Thread Richard Biener
On Wed, Oct 29, 2014 at 3:14 PM, Martin Liška mli...@suse.cz wrote:
 Hello.

 Following patch fixes PR63587, where we put DECL_RESULT in
 cgraph_node::expand_thunk to local_decls.
 Patch has been tested on x86_64-linux-pc without any regression and boostrap
 works correctly.

 Ready for thunk?

Ok.

Thanks,
Richard.

 Thanks,
 Martin