This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH, c++]: Fix PR c++/31488 by Introducing LANG_HOOKS_SET_IS_AGGR_TYPE language hook.


Hello!

There is currently no way to communicate from target backend to the frontend that certain RECORD_TYPE structure is an aggregate. An example is alpha backend that creates RECORD_TYPE to pass variable arguments. Since this structure is not considered as non-POD by c++ frontend, several java testcases fail (please see PR c++/31488 and a classpath bug it blocks for more info):

FAIL: natgetargssize.cc compilation
FAIL: natgetlocalvartable.cc compilation
FAIL: natgetstacktrace.cc compilation
FAIL: natevents.cc compilation
FAIL: natgetallthreads.cc compilation
FAIL: natgeterrorname.cc compilation
FAIL: natgetmethodname.cc compilation

Attached patch introduces LANG_HOOKS_SET_IS_AGGR_TYPE language hook to give backends the ability to mark certain structures as POD.

2008-12-30 Uros Bizjak <ubizjak@gmail.com>

   PR c++/31488
   * langhooks-def.h (LANG_HOOKS_SET_IS_AGGR_TYPE): New language hook.
   (LANG_HOOKS_FOR_TYPES_INITIALIZER): Add LANG_HOOKS_SET_IS_AGGR_TYPE.
   * langhooks.h (struct lang_hooks_for_types): Add (*set_is_aggr_type).

   * config/alpha/alpha.c (alpha_build_builtin_va_list):
   Call set_is_aggr_type language hook.

cp/ChangeLog:

2008-12-30 Uros Bizjak <ubizjak@gmail.com>

   PR c++/31488
   * cp-objcp-common.h (LANG_HOOKS_SET_IS_AGGR_TYPE): New language hook.
   * cp-tree.h (set_is_aggr_type): New prototype.
   * lex.c (set_is_aggr_type): New function.

testsuite/ChangeLog:

2008-12-30 Uros Bizjak <ubizjak@gmail.com>

   PR c++/31488
   * g++.dg/other/vararg-3.C: New test.

Patch was bootstrapped and regression tested on x86_64-pc-linux-gnu {,-m32} and alphaev56-unknown-linux-gnu.

The patch fixes above compilation failures. OK for 4.3/4.4?

Uros.
Index: testsuite/g++.dg/other/vararg-3.C
===================================================================
--- testsuite/g++.dg/other/vararg-3.C	(revision 0)
+++ testsuite/g++.dg/other/vararg-3.C	(revision 0)
@@ -0,0 +1,17 @@
+// PR c++/31488: va_list considered non-POD on alpha
+// { dg-do compile }
+
+typedef __builtin_va_list __gnuc_va_list;
+typedef __gnuc_va_list va_list;
+
+extern int foo (int a, int b, ...);
+
+int bar (int a, int b, ...)
+{
+  va_list args;
+  __builtin_va_start(args,b);
+  int result = foo (a, b, args);
+  __builtin_va_end(args);
+  return result;
+}
+
Index: cp/cp-objcp-common.h
===================================================================
--- cp/cp-objcp-common.h	(revision 142960)
+++ cp/cp-objcp-common.h	(working copy)
@@ -115,6 +115,8 @@ extern tree objcp_tsubst_copy_and_build 
 
 #undef LANG_HOOKS_MAKE_TYPE
 #define LANG_HOOKS_MAKE_TYPE cxx_make_type
+#undef LANG_HOOKS_SET_IS_AGGR_TYPE
+#define  LANG_HOOKS_SET_IS_AGGR_TYPE set_is_aggr_type
 #undef LANG_HOOKS_TYPE_FOR_MODE
 #define LANG_HOOKS_TYPE_FOR_MODE c_common_type_for_mode
 #undef LANG_HOOKS_TYPE_FOR_SIZE
Index: cp/cp-tree.h
===================================================================
--- cp/cp-tree.h	(revision 142960)
+++ cp/cp-tree.h	(working copy)
@@ -4498,6 +4498,7 @@ extern void retrofit_lang_decl			(tree);
 extern tree copy_decl				(tree);
 extern tree copy_type				(tree);
 extern tree cxx_make_type			(enum tree_code);
+extern void set_is_aggr_type			(tree);
 extern tree make_class_type			(enum tree_code);
 extern void yyerror				(const char *);
 extern void yyhook				(int);
Index: cp/lex.c
===================================================================
--- cp/lex.c	(revision 142960)
+++ cp/lex.c	(working copy)
@@ -661,6 +661,12 @@ cxx_make_type (enum tree_code code)
   return t;
 }
 
+void
+set_is_aggr_type (tree t)
+{
+  SET_CLASS_TYPE_P (t, 1);
+}
+
 tree
 make_class_type (enum tree_code code)
 {
Index: langhooks.h
===================================================================
--- langhooks.h	(revision 142960)
+++ langhooks.h	(working copy)
@@ -74,6 +74,10 @@ struct lang_hooks_for_types
      language-specific processing is required.  */
   tree (*make_type) (enum tree_code);
 
+  /* For C++ family of languages, Set CLASS_TYPE_P for T.  T must be
+     a class, struct, or union type.  */
+  void (*set_is_aggr_type) (tree);
+
   /* Return what kind of RECORD_TYPE this is, mainly for purposes of
      debug information.  If not defined, record types are assumed to
      be structures.  */
Index: config/alpha/alpha.c
===================================================================
--- config/alpha/alpha.c	(revision 142960)
+++ config/alpha/alpha.c	(working copy)
@@ -5779,7 +5779,7 @@ alpha_build_builtin_va_list (void)
   TREE_CHAIN (record) = type_decl;
   TYPE_NAME (record) = type_decl;
 
-  /* C++? SET_IS_AGGR_TYPE (record, 1); */
+  (*lang_hooks.types.set_is_aggr_type) (record);
 
   /* Dummy field to prevent alignment warnings.  */
   space = build_decl (FIELD_DECL, NULL_TREE, integer_type_node);
Index: langhooks-def.h
===================================================================
--- langhooks-def.h	(revision 142960)
+++ langhooks-def.h	(working copy)
@@ -155,6 +155,7 @@ extern tree lhd_make_node (enum tree_cod
 /* Types hooks.  There are no reasonable defaults for most of them,
    so we create a compile-time error instead.  */
 #define LANG_HOOKS_MAKE_TYPE lhd_make_node
+#define LANG_HOOKS_SET_IS_AGGR_TYPE	lhd_do_nothing_t
 #define LANG_HOOKS_CLASSIFY_RECORD	NULL
 #define LANG_HOOKS_INCOMPLETE_TYPE_ERROR lhd_incomplete_type_error
 #define LANG_HOOKS_GENERIC_TYPE_P	hook_bool_const_tree_false
@@ -170,6 +171,7 @@ extern tree lhd_make_node (enum tree_cod
 
 #define LANG_HOOKS_FOR_TYPES_INITIALIZER { \
   LANG_HOOKS_MAKE_TYPE, \
+  LANG_HOOKS_SET_IS_AGGR_TYPE, \
   LANG_HOOKS_CLASSIFY_RECORD, \
   LANG_HOOKS_TYPE_FOR_MODE, \
   LANG_HOOKS_TYPE_FOR_SIZE, \

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]