On Fri, 2014-10-03 at 10:54 -0400, Jason Merrill wrote:
> "user-declared" includes declarations that are defaulted in the class 
> body.  "user-provided" is the category that does not include such 
> declarations.

O. Then I was indeed wrong and defaulted does not impact ABI at all.
At least that is one worry less for the abi checkers :)

In that case I think we should indeed not distinguish between
DECL_DEFAULTED_IN_CLASS_P and DECL_DEFAULTED_OUTSIDE_CLASS_P and just
use DECL_DEFAULTED_FN. Then the information provided is just that the
source indicates that the special member function has the default
implementation. Which still is useful to know for a consumer. If only to
show the debug users what the intention of the original source code was.

The following variant of the patch does that (and removes any mention of
"out of class" definitions).

Thanks,

Mark
From f72525e11d08ad49d208ab75c806326871d881d7 Mon Sep 17 00:00:00 2001
From: Mark Wielaard <m...@redhat.com>
Date: Fri, 3 Oct 2014 14:44:27 +0200
Subject: [PATCH] PR debug/63240 Add DWARF representation for C++11 defaulted
 member function.

gcc/ChangeLog

	* dwarf2out.c (gen_subprogram_die): When a member function is
	declared default then add a DW_AT_GNU_defaulted attribute.
	* langhooks.h (struct lang_hooks_for_decls): Add
	function_decl_defaulted_p langhook.
	* langhooks-def.h (LANG_HOOKS_FUNCTION_DECL_DEFAULTED_P): Define.
	(LANG_HOOKS_DECLS): Add LANG_HOOKS_FUNCTION_DECL_DEFAULTED_P.

gcc/cp/ChangeLog

	* cp-objcp-common.h (LANG_HOOKS_FUNCTION_DECL_DEFAULTED_P): Define.
	(cp_function_decl_defaulted_p): New prototype.
	* cp-objcp-common.c (cp_function_defaulted_p): New function.

gcc/testsuite/ChangeLog

	* g++.dg/debug/dwarf2/defaulted-member-function.C: New testcase.

include/ChangeLog

	* dwarf2.def (DW_AT_GNU_defaulted): New attribute.
---
 gcc/ChangeLog                                           | 10 ++++++++++
 gcc/cp/ChangeLog                                        |  7 +++++++
 gcc/cp/cp-objcp-common.c                                | 10 ++++++++++
 gcc/cp/cp-objcp-common.h                                |  3 +++
 gcc/dwarf2out.c                                         |  6 ++++++
 gcc/langhooks-def.h                                     |  2 ++
 gcc/langhooks.h                                         |  3 +++
 gcc/testsuite/ChangeLog                                 |  5 +++++
 .../g++.dg/debug/dwarf2/defaulted-member-function.C     | 17 +++++++++++++++++
 include/ChangeLog                                       |  5 +++++
 include/dwarf2.def                                      |  2 ++
 11 files changed, 70 insertions(+)
 create mode 100644 gcc/testsuite/g++.dg/debug/dwarf2/defaulted-member-function.C

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index dc3287b..255b1b6 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,13 @@
+2014-10-03  Mark Wielaard  <m...@redhat.com>
+
+	PR debug/63240
+	* dwarf2out.c (gen_subprogram_die): When a member function is
+	declared default then add a DW_AT_GNU_defaulted attribute.
+	* langhooks.h (struct lang_hooks_for_decls): Add
+	function_decl_defaulted_p langhook.
+	* langhooks-def.h (LANG_HOOKS_FUNCTION_DECL_DEFAULTED_P): Define.
+	(LANG_HOOKS_DECLS): Add LANG_HOOKS_FUNCTION_DECL_DEFAULTED_P.
+
 2014-10-02  Mark Wielaard  <m...@redhat.com>
 
 	PR debug/63239
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 921f95c..d88bcd8 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,10 @@
+2014-10-03  Mark Wielaard  <m...@redhat.com>
+
+	PR debug/63240
+	* cp-objcp-common.h (LANG_HOOKS_FUNCTION_DECL_DEFAULTED_P): Define.
+	(cp_function_decl_defaulted_p): New prototype.
+	* cp-objcp-common.c (cp_function_defaulted_p): New function.
+
 2014-10-02  Mark Wielaard  <m...@redhat.com>
 
 	PR debug/63239
diff --git a/gcc/cp/cp-objcp-common.c b/gcc/cp/cp-objcp-common.c
index 0d144ef..e668183 100644
--- a/gcc/cp/cp-objcp-common.c
+++ b/gcc/cp/cp-objcp-common.c
@@ -178,6 +178,16 @@ cp_function_decl_deleted_p (tree decl)
 	  && DECL_DELETED_FN (decl));
 }
 
+/* Return true if DECL is defaulted special member function.  */
+
+bool
+cp_function_decl_defaulted_p (tree decl)
+{
+  return (decl
+	  && DECL_LANG_SPECIFIC (STRIP_TEMPLATE (decl))
+	  && DECL_DEFAULTED_FN (decl));
+}
+
 /* Stubs to keep c-opts.c happy.  */
 void
 push_file_scope (void)
diff --git a/gcc/cp/cp-objcp-common.h b/gcc/cp/cp-objcp-common.h
index c289774..348874f 100644
--- a/gcc/cp/cp-objcp-common.h
+++ b/gcc/cp/cp-objcp-common.h
@@ -28,6 +28,7 @@ extern tree objcp_tsubst_copy_and_build (tree, tree, tsubst_flags_t,
 
 extern bool cp_function_decl_explicit_p (tree decl);
 extern bool cp_function_decl_deleted_p (tree decl);
+extern bool cp_function_decl_defaulted_p (tree decl);
 extern void cp_common_init_ts (void);
 
 /* Lang hooks that are shared between C++ and ObjC++ are defined here.  Hooks
@@ -134,6 +135,8 @@ extern void cp_common_init_ts (void);
 #define LANG_HOOKS_FUNCTION_DECL_EXPLICIT_P cp_function_decl_explicit_p
 #undef LANG_HOOKS_FUNCTION_DECL_DELETED_P
 #define LANG_HOOKS_FUNCTION_DECL_DELETED_P cp_function_decl_deleted_p
+#undef LANG_HOOKS_FUNCTION_DECL_DEFAULTED_P
+#define LANG_HOOKS_FUNCTION_DECL_DEFAULTED_P cp_function_decl_defaulted_p
 #undef LANG_HOOKS_OMP_PREDETERMINED_SHARING
 #define LANG_HOOKS_OMP_PREDETERMINED_SHARING cxx_omp_predetermined_sharing
 #undef LANG_HOOKS_OMP_CLAUSE_DEFAULT_CTOR
diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c
index 11544d8..54c2ee2 100644
--- a/gcc/dwarf2out.c
+++ b/gcc/dwarf2out.c
@@ -18305,6 +18305,12 @@ gen_subprogram_die (tree decl, dw_die_ref context_die)
 	      && (! dwarf_strict))
 	    add_AT_flag (subr_die, DW_AT_GNU_deleted, 1);
 
+	  /* If this is a C++11 defaulted special function member then
+	     generate a DW_AT_GNU_defaulted attribute.  */
+	  if (lang_hooks.decls.function_decl_defaulted_p (decl)
+	      && (! dwarf_strict))
+	    add_AT_flag (subr_die, DW_AT_GNU_defaulted, 1);
+
 	  /* The first time we see a member function, it is in the context of
 	     the class to which it belongs.  We make sure of this by emitting
 	     the class first.  The next time is the definition, which is
diff --git a/gcc/langhooks-def.h b/gcc/langhooks-def.h
index e5ae3e3..190a803 100644
--- a/gcc/langhooks-def.h
+++ b/gcc/langhooks-def.h
@@ -204,6 +204,7 @@ extern tree lhd_make_node (enum tree_code);
 #define LANG_HOOKS_GETDECLS	getdecls
 #define LANG_HOOKS_FUNCTION_DECL_EXPLICIT_P hook_bool_tree_false
 #define LANG_HOOKS_FUNCTION_DECL_DELETED_P hook_bool_tree_false
+#define LANG_HOOKS_FUNCTION_DECL_DEFAULTED_P hook_bool_tree_false
 #define LANG_HOOKS_WARN_UNUSED_GLOBAL_DECL lhd_warn_unused_global_decl
 #define LANG_HOOKS_WRITE_GLOBALS write_global_declarations
 #define LANG_HOOKS_DECL_OK_FOR_SIBCALL	lhd_decl_ok_for_sibcall
@@ -226,6 +227,7 @@ extern tree lhd_make_node (enum tree_code);
   LANG_HOOKS_GETDECLS, \
   LANG_HOOKS_FUNCTION_DECL_EXPLICIT_P, \
   LANG_HOOKS_FUNCTION_DECL_DELETED_P, \
+  LANG_HOOKS_FUNCTION_DECL_DEFAULTED_P, \
   LANG_HOOKS_GENERIC_GENERIC_PARAMETER_DECL_P, \
   LANG_HOOKS_FUNCTION_PARM_EXPANDED_FROM_PACK_P, \
   LANG_HOOKS_GET_GENERIC_FUNCTION_DECL, \
diff --git a/gcc/langhooks.h b/gcc/langhooks.h
index 32e76f9..b1138a2 100644
--- a/gcc/langhooks.h
+++ b/gcc/langhooks.h
@@ -169,6 +169,9 @@ struct lang_hooks_for_decls
   /* Returns true if DECL is C++11 deleted special member function.  */
   bool (*function_decl_deleted_p) (tree);
 
+  /* Returns true if DECL is C++11 defaulted special member function.  */
+  bool (*function_decl_defaulted_p) (tree);
+
   /* Returns True if the parameter is a generic parameter decl
      of a generic type, e.g a template template parameter for the C++ FE.  */
   bool (*generic_generic_parameter_decl_p) (const_tree);
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 2a6fe3f..353a90e 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2014-10-03  Mark Wielaard  <m...@redhat.com>
+
+	PR debug/63240
+	* g++.dg/debug/dwarf2/defaulted-member-function.C: New testcase.
+
 2014-10-02  Mark Wielaard  <m...@redhat.com>
 
 	PR debug/63239
diff --git a/gcc/testsuite/g++.dg/debug/dwarf2/defaulted-member-function.C b/gcc/testsuite/g++.dg/debug/dwarf2/defaulted-member-function.C
new file mode 100644
index 0000000..635e5ba
--- /dev/null
+++ b/gcc/testsuite/g++.dg/debug/dwarf2/defaulted-member-function.C
@@ -0,0 +1,17 @@
+// { dg-do compile }
+// { dg-options "-O -std=c++11 -g -dA" }
+// { dg-final { scan-assembler-times "# DW_AT_GNU_defaulted" 2 } }
+
+struct Foo
+{
+  Foo () {}
+  // Make copyable
+  Foo (const Foo&) = default;
+  Foo & operator=(const Foo&) = default;
+};
+
+void
+bar ()
+{
+  Foo foo;
+}
diff --git a/include/ChangeLog b/include/ChangeLog
index fd6274f..e9a3a02 100644
--- a/include/ChangeLog
+++ b/include/ChangeLog
@@ -1,3 +1,8 @@
+2013-10-03  Mark Wielaard  <m...@redhat.com>
+
+	PR debug/63240
+	* dwarf2.def (DW_AT_GNU_defaulted): New attribute.
+
 2013-10-02  Mark Wielaard  <m...@redhat.com>
 
 	PR debug/63239
diff --git a/include/dwarf2.def b/include/dwarf2.def
index 42a8d4b..067454c 100644
--- a/include/dwarf2.def
+++ b/include/dwarf2.def
@@ -385,6 +385,8 @@ DW_AT (DW_AT_GNU_all_source_call_sites, 0x2118)
 DW_AT (DW_AT_GNU_macros, 0x2119)
 /* Attribute for C++ deleted special member functions (= delete;).  */
 DW_AT (DW_AT_GNU_deleted, 0x211a)
+/* Attribute for C++ defaulted function in class body (= default;).  */
+DW_AT (DW_AT_GNU_defaulted, 0x211b)
 /* Extensions for Fission.  See http://gcc.gnu.org/wiki/DebugFission.  */
 DW_AT (DW_AT_GNU_dwo_name, 0x2130)
 DW_AT (DW_AT_GNU_dwo_id, 0x2131)
-- 
1.8.3.1

Reply via email to