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]

RFA (c-common): PATCH to add typeinfo for ARM fp16 type to libsupc++


The IEEE half-precision floating point type should also be among the built-in types in libsupc++. For some reason we currently only support it on the ARM target, so this patch just adds any target-specific built-in types to the list.

I tested that this patch had the desired effect on the testcase and on fundamental_type_info.cc in libsupc++ with an arm-elf cross-compiler; I did a full regression test on x86_64-pc-linux-gnu. Is the change to expose registered_builtin_types to the C++ front end OK for trunk?
commit e41802ba02a304ec8ec69d7dc0f19176ad6ea31a
Author: Jason Merrill <jason@redhat.com>
Date:   Wed Nov 11 11:50:19 2009 -0500

    gcc/
    	* c-common.c (registered_builtin_types): Not static.
    	* c-common.h: Declare it.
    gcc/cp/
    	* rtti.c: Include c-common.h.
    	(emit_one_support_tinfo): Split out from...
    	(emit_support_tinfos): ...here.  Emit tinfos for
    	target-specific builtins, too.
    	* Make-lang.in (cp/rtti.o): Depend on c-common.h.
    libstdc++-v3/
    	* config/abi/pre/gnu.ver: Add half-precision FP typeinfos.

diff --git a/gcc/c-common.c b/gcc/c-common.c
index 20b24f0..498b2f2 100644
--- a/gcc/c-common.c
+++ b/gcc/c-common.c
@@ -2891,9 +2891,9 @@ c_common_fixed_point_type_for_size (unsigned int ibit, unsigned int fbit,
   return c_common_type_for_mode (mode, satp);
 }
 
-/* Used for communication between c_common_type_for_mode and
-   c_register_builtin_type.  */
-static GTY(()) tree registered_builtin_types;
+/* Used for communication between c_common_type_for_mode,
+   c_register_builtin_type and C++ emit_support_tinfos.  */
+tree registered_builtin_types;
 
 /* Return a data type that has machine mode MODE.
    If the mode is an integer,
diff --git a/gcc/c-common.h b/gcc/c-common.h
index d91546f..078c391 100644
--- a/gcc/c-common.h
+++ b/gcc/c-common.h
@@ -761,6 +761,12 @@ extern int c_inhibit_evaluation_warnings;
 
 extern bool done_lexing;
 
+/* TREE_LIST of any target-specific builtin types in the TREE_VALUE field.
+   Used for communication between c_common_type_for_mode,
+   c_register_builtin_type and C++ emit_support_tinfos.  */
+
+extern GTY(()) tree registered_builtin_types;
+
 /* C types are partitioned into three subsets: object, function, and
    incomplete types.  */
 #define C_TYPE_OBJECT_P(type) \
diff --git a/gcc/cp/Make-lang.in b/gcc/cp/Make-lang.in
index 861c93d..c980c1e 100644
--- a/gcc/cp/Make-lang.in
+++ b/gcc/cp/Make-lang.in
@@ -284,7 +284,7 @@ cp/tree.o: cp/tree.c $(CXX_TREE_H) $(TM_H) $(FLAGS_H) toplev.h $(RTL_H) \
   $(TARGET_H) debug.h $(TREE_FLOW_H)
 cp/ptree.o: cp/ptree.c $(CXX_TREE_H) $(TM_H)
 cp/rtti.o: cp/rtti.c $(CXX_TREE_H) $(TM_H) $(FLAGS_H) toplev.h convert.h \
-  $(TARGET_H) $(C_PRAGMA_H) gt-cp-rtti.h
+  $(TARGET_H) $(C_PRAGMA_H) gt-cp-rtti.h $(C_COMMON_H)
 cp/except.o: cp/except.c $(CXX_TREE_H) $(TM_H) $(FLAGS_H) $(RTL_H) except.h \
   toplev.h cp/cfns.h $(EXPR_H) libfuncs.h $(TREE_INLINE_H) $(TARGET_H)
 cp/expr.o: cp/expr.c $(CXX_TREE_H) $(TM_H) $(RTL_H) $(FLAGS_H) $(EXPR_H) \
diff --git a/gcc/cp/rtti.c b/gcc/cp/rtti.c
index e96abcb..2464c1a 100644
--- a/gcc/cp/rtti.c
+++ b/gcc/cp/rtti.c
@@ -33,6 +33,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "convert.h"
 #include "target.h"
 #include "c-pragma.h"
+#include "c-common.h"
 
 /* C++ returns type information to the user in struct type_info
    objects. We also use type information to implement dynamic_cast and
@@ -1434,6 +1435,42 @@ create_tinfo_types (void)
    is being generated.  If std::__fundamental_type_info is defined, and its
    destructor is defined, then the runtime is being built.  */
 
+static void
+emit_one_support_tinfo (tree bltn)
+{
+  tree types[3];
+  int i;
+
+  types[0] = bltn;
+  types[1] = build_pointer_type (bltn);
+  types[2] = build_pointer_type (build_qualified_type (bltn,
+						       TYPE_QUAL_CONST));
+
+  for (i = 0; i < 3; ++i)
+    {
+      tree tinfo;
+
+      tinfo = get_tinfo_decl (types[i]);
+      TREE_USED (tinfo) = 1;
+      mark_needed (tinfo);
+      /* The C++ ABI requires that these objects be COMDAT.  But,
+	 On systems without weak symbols, initialized COMDAT
+	 objects are emitted with internal linkage.  (See
+	 comdat_linkage for details.)  Since we want these objects
+	 to have external linkage so that copies do not have to be
+	 emitted in code outside the runtime library, we make them
+	 non-COMDAT here.
+
+	 It might also not be necessary to follow this detail of the
+	 ABI.  */
+      if (!flag_weak || ! targetm.cxx.library_rtti_comdat ())
+	{
+	  gcc_assert (TREE_PUBLIC (tinfo) && !DECL_COMDAT (tinfo));
+	  DECL_INTERFACE_KNOWN (tinfo) = 1;
+	}
+    }
+}
+
 void
 emit_support_tinfos (void)
 {
@@ -1453,6 +1490,7 @@ emit_support_tinfos (void)
   };
   int ix;
   tree bltn_type, dtor;
+  tree t;
 
   push_abi_namespace ();
   bltn_type = xref_tag (class_type,
@@ -1466,40 +1504,9 @@ emit_support_tinfos (void)
     return;
   doing_runtime = 1;
   for (ix = 0; fundamentals[ix]; ix++)
-    {
-      tree bltn = *fundamentals[ix];
-      tree types[3];
-      int i;
-
-      types[0] = bltn;
-      types[1] = build_pointer_type (bltn);
-      types[2] = build_pointer_type (build_qualified_type (bltn,
-							   TYPE_QUAL_CONST));
-
-      for (i = 0; i < 3; ++i)
-	{
-	  tree tinfo;
-
-	  tinfo = get_tinfo_decl (types[i]);
-	  TREE_USED (tinfo) = 1;
-	  mark_needed (tinfo);
-	  /* The C++ ABI requires that these objects be COMDAT.  But,
-	     On systems without weak symbols, initialized COMDAT
-	     objects are emitted with internal linkage.  (See
-	     comdat_linkage for details.)  Since we want these objects
-	     to have external linkage so that copies do not have to be
-	     emitted in code outside the runtime library, we make them
-	     non-COMDAT here.  
-
-	     It might also not be necessary to follow this detail of the
-	     ABI.  */
-	  if (!flag_weak || ! targetm.cxx.library_rtti_comdat ())
-	    {
-	      gcc_assert (TREE_PUBLIC (tinfo) && !DECL_COMDAT (tinfo));
-	      DECL_INTERFACE_KNOWN (tinfo) = 1;
-	    }
-	}
-    }
+    emit_one_support_tinfo (*fundamentals[ix]);
+  for (t = registered_builtin_types; t; t = TREE_CHAIN (t))
+    emit_one_support_tinfo (TREE_VALUE (t));
 }
 
 /* Finish a type info decl. DECL_PTR is a pointer to an unemitted
diff --git a/gcc/testsuite/g++.dg/ext/arm-fp16/fp16-typeid-1.C b/gcc/testsuite/g++.dg/ext/arm-fp16/fp16-typeid-1.C
new file mode 100644
index 0000000..28467ce
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ext/arm-fp16/fp16-typeid-1.C
@@ -0,0 +1,13 @@
+/* { dg-do link { target arm*-*-* } } */
+/* { dg-options "-mfp16-format=ieee" } */
+
+/* The typeinfo should be defined in libstdc++, not here.  */
+/* { dg-final { scan-assembler-not "_ZTIDh:" } } */
+
+/* Test typeinfo linkage */
+
+#include <typeinfo>
+
+const std::type_info &r = typeid(__fp16);
+
+int main() { }
diff --git a/libstdc++-v3/config/abi/pre/gnu.ver b/libstdc++-v3/config/abi/pre/gnu.ver
index b0001ca..5850c27 100644
--- a/libstdc++-v3/config/abi/pre/gnu.ver
+++ b/libstdc++-v3/config/abi/pre/gnu.ver
@@ -1202,11 +1202,11 @@ CXXABI_1.3.3 {
 CXXABI_1.3.4 {
 
     # typeinfo for decimal floating point types
-    _ZTID[fde];
-    _ZTIPD[fde];
-    _ZTIPKD[fde];
-    _ZTID[fde];
-    _ZTIPD[fde];
-    _ZTIPKD[fde];
+    _ZTID[fdeh];
+    _ZTIPD[fdeh];
+    _ZTIPKD[fdeh];
+    _ZTID[fdeh];
+    _ZTIPD[fdeh];
+    _ZTIPKD[fdeh];
 
 } CXXABI_1.3.3;

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