]> git.ipfire.org Git - thirdparty/gcc.git/blobdiff - gcc/cp/rtti.cc
Update copyright years.
[thirdparty/gcc.git] / gcc / cp / rtti.cc
index f5b43ec0fb258656980cfd7d72e5d68eb36f9a4b..ed69606f4ddcad6e980f3bcaa1f7245c021608c6 100644 (file)
@@ -1,5 +1,5 @@
 /* RunTime Type Identification
-   Copyright (C) 1995-2022 Free Software Foundation, Inc.
+   Copyright (C) 1995-2024 Free Software Foundation, Inc.
    Mostly written by Jason Merrill (jason@cygnus.com).
 
 This file is part of GCC.
@@ -787,6 +787,10 @@ build_dynamic_cast_1 (location_t loc, tree type, tree expr,
                               NULL_TREE));
              dcast_fn = (build_library_fn_ptr
                          (fn_name, fn_type, ECF_LEAF | ECF_PURE | ECF_NOTHROW));
+             /* As with __cxa_atexit in get_atexit_node.  */
+             DECL_CONTEXT (dcast_fn) = FROB_CONTEXT (current_namespace);
+             DECL_SOURCE_LOCATION (dcast_fn) = BUILTINS_LOCATION;
+             dcast_fn = pushdecl (dcast_fn, /*hiding=*/true);
              pop_abi_namespace (flags);
              dynamic_cast_node = dcast_fn;
            }
@@ -1573,6 +1577,24 @@ emit_support_tinfo_1 (tree bltn)
          gcc_assert (TREE_PUBLIC (tinfo) && !DECL_COMDAT (tinfo));
          DECL_INTERFACE_KNOWN (tinfo) = 1;
        }
+
+      /* Emit it right away if not emitted already.  */
+      if (DECL_INITIAL (tinfo) == NULL_TREE)
+       {
+         bool ok = emit_tinfo_decl (tinfo);
+         gcc_assert (ok);
+         /* When compiling libsupc++.a (fundamental_type_info.o),
+            unemitted_tinfo_decls->last () will be tinfo, so pop it
+            from the vector as it is emitted now.  If one uses typeid
+            etc. in the same TU as the definition of
+            ~fundamental_type_info (), the tinfo might be emitted
+            already earlier, in such case keep it in the vector
+            (as otherwise we'd need to walk the whole vector) and
+            let c_parse_final_cleanups ignore it when it will have
+            non-NULL DECL_INITIAL.  */
+         if (unemitted_tinfo_decls->last () == tinfo)
+           unemitted_tinfo_decls->pop ();
+       }
     }
 }
 
@@ -1598,8 +1620,16 @@ emit_support_tinfos (void)
     &long_integer_type_node, &long_unsigned_type_node,
     &long_long_integer_type_node, &long_long_unsigned_type_node,
     &float_type_node, &double_type_node, &long_double_type_node,
+    &bfloat16_type_node, &float16_type_node, &float32_type_node,
+    &float64_type_node, &float128_type_node, &float32x_type_node,
+    &float64x_type_node, &float128x_type_node, &nullptr_type_node,
+    0
+  };
+  /* Similar, but for floating point types only which should get type info
+     regardless whether they are non-NULL or NULL.  */
+  static tree *const fundamentals_with_fallback[] =
+  {
     &dfloat32_type_node, &dfloat64_type_node, &dfloat128_type_node,
-    &nullptr_type_node,
     0
   };
   int ix;
@@ -1621,8 +1651,20 @@ emit_support_tinfos (void)
   location_t saved_loc = input_location;
   input_location = BUILTINS_LOCATION;
   doing_runtime = 1;
+  tree fallback = NULL_TREE;
   for (ix = 0; fundamentals[ix]; ix++)
     emit_support_tinfo_1 (*fundamentals[ix]);
+  for (ix = 0; fundamentals_with_fallback[ix]; ix++)
+    if (*fundamentals_with_fallback[ix])
+      emit_support_tinfo_1 (*fundamentals_with_fallback[ix]);
+    else
+      {
+       if (fallback == NULL_TREE)
+         fallback = make_node (REAL_TYPE);
+       *fundamentals_with_fallback[ix] = fallback;
+       emit_support_tinfo_1 (fallback);
+       *fundamentals_with_fallback[ix] = NULL_TREE;
+      }
   for (ix = 0; ix < NUM_INT_N_ENTS; ix ++)
     if (int_n_enabled_p[ix])
       {
@@ -1631,20 +1673,10 @@ emit_support_tinfos (void)
       }
   for (tree t = registered_builtin_types; t; t = TREE_CHAIN (t))
     emit_support_tinfo_1 (TREE_VALUE (t));
-  /* For compatibility, emit DFP typeinfos even when DFP isn't enabled,
-     because we've emitted that in the past.  */
-  if (!targetm.decimal_float_supported_p ())
-    {
-      gcc_assert (dfloat32_type_node == NULL_TREE
-                 && dfloat64_type_node == NULL_TREE
-                 && dfloat128_type_node == NULL_TREE);
-      fallback_dfloat32_type = make_node (REAL_TYPE);
-      fallback_dfloat64_type = make_node (REAL_TYPE);
-      fallback_dfloat128_type = make_node (REAL_TYPE);
-      emit_support_tinfo_1 (fallback_dfloat32_type);
-      emit_support_tinfo_1 (fallback_dfloat64_type);
-      emit_support_tinfo_1 (fallback_dfloat128_type);
-    }
+
+  /* Emit additional typeinfos as requested by target.  */
+  targetm.emit_support_tinfos (emit_support_tinfo_1);
+
   input_location = saved_loc;
 }