From 5742fba8b43d1ada136f01efd05b03276e1bcc04 Mon Sep 17 00:00:00 2001 From: Arthur O'Dwyer Date: Sun, 10 Dec 2023 18:44:25 -0500 Subject: [PATCH] [gcc] Implement a stub version of `__is_trivially_relocatable(T)` It's just a synonym for `__is_trivially_copyable(T)`, but it's enough to get started with. --- gcc/cp/constraint.cc | 3 +++ gcc/cp/cp-trait.def | 1 + gcc/cp/cp-tree.h | 1 + gcc/cp/semantics.cc | 3 +++ gcc/cp/tree.cc | 11 +++++++++++ 5 files changed, 19 insertions(+) diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index eeacead52a5af..ad8861362369f 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3822,6 +3822,9 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_TRIVIALLY_COPYABLE: inform (loc, " %qT is not trivially copyable", t1); break; + case CPTK_IS_TRIVIALLY_RELOCATABLE: + inform (loc, " %qT is not trivially relocatable", t1); + break; case CPTK_IS_UNION: inform (loc, " %qT is not a union", t1); break; diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index 394f006f20f2f..b063fc7a35b78 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -90,6 +90,7 @@ DEFTRAIT_EXPR (IS_TRIVIAL, "__is_trivial", 1) DEFTRAIT_EXPR (IS_TRIVIALLY_ASSIGNABLE, "__is_trivially_assignable", 2) DEFTRAIT_EXPR (IS_TRIVIALLY_CONSTRUCTIBLE, "__is_trivially_constructible", -1) DEFTRAIT_EXPR (IS_TRIVIALLY_COPYABLE, "__is_trivially_copyable", 1) +DEFTRAIT_EXPR (IS_TRIVIALLY_RELOCATABLE, "__is_trivially_relocatable", 1) DEFTRAIT_EXPR (IS_UNION, "__is_union", 1) DEFTRAIT_EXPR (REF_CONSTRUCTS_FROM_TEMPORARY, "__reference_constructs_from_temporary", 2) DEFTRAIT_EXPR (REF_CONVERTS_FROM_TEMPORARY, "__reference_converts_from_temporary", 2) diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index 85adebedeebbb..748b55361a2d3 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -7951,6 +7951,7 @@ extern bool layout_pod_type_p (const_tree); extern bool std_layout_type_p (const_tree); extern bool trivial_type_p (const_tree); extern bool trivially_copyable_p (const_tree); +extern bool trivially_relocatable_p (const_tree); extern bool type_has_unique_obj_representations (const_tree); extern bool scalarish_type_p (const_tree); extern bool structural_type_p (tree, bool = false); diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index e6dba29ee81e9..7cf408660155a 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12495,6 +12495,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_TRIVIALLY_COPYABLE: return trivially_copyable_p (type1); + case CPTK_IS_TRIVIALLY_RELOCATABLE: + return trivially_relocatable_p (type1); + case CPTK_IS_UNION: return type_code1 == UNION_TYPE; diff --git a/gcc/cp/tree.cc b/gcc/cp/tree.cc index d17b9b348910c..7f18fb9de531d 100644 --- a/gcc/cp/tree.cc +++ b/gcc/cp/tree.cc @@ -4635,6 +4635,17 @@ trivially_copyable_p (const_tree t) return scalarish_type_p (t); } +/* Returns 1 iff type T is a trivially relocatable type, as defined in + [basic.types] and [class.prop]. For now, this just reports trivially + copyable types, and ignores anything to do with transitivity or + attributes. TODO FIXME BUG HACK. */ + +bool +trivially_relocatable_p (const_tree t) +{ + return trivially_copyable_p (t); +} + /* Returns 1 iff type T is a trivial type, as defined in [basic.types] and [class]. */