]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Revert c, c++: Use c*_build_qualified_type instead of build_qualified_type from withi...
authorJakub Jelinek <jakub@redhat.com>
Thu, 5 Feb 2026 13:59:12 +0000 (14:59 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Thu, 5 Feb 2026 13:59:12 +0000 (14:59 +0100)
As seen in PR123882, this broke more than it fixed, a lot of
build_type_attribute_qual_variant including build_type_attribute_variant
just pass in TYPE_QUALS (type) as the last argument and for C/C++
when the code pushes the quals to the element type, it will effectively
make those unqualified.  The PR123882 ICE is then on the array_as_string
terrible hack if the FE calls get_aka_type on that, it wants to create
qualified attribute variant of that and errors on the restrict qual.

So, to fix both PR c/123882 and other unknown regressions caused by
PR c/101312 I'm reverting it now.

This reverts commit 3d2a91a3767982dde5a37abf45c12c08d4fdbf41.

12 files changed:
gcc/attribs.cc
gcc/c/c-objc-common.cc
gcc/c/c-objc-common.h
gcc/c/c-tree.h
gcc/cp/cp-objcp-common.h
gcc/cp/cp-tree.h
gcc/cp/tree.cc
gcc/langhooks-def.h
gcc/langhooks.cc
gcc/langhooks.h
gcc/testsuite/c-c++-common/pr101312-1.c [deleted file]
gcc/testsuite/c-c++-common/pr101312-2.c [deleted file]

index 9422737570101d9d7a8365c3f4e2ee8ebb28249d..29cf28af1639fdce53cca547139053d279e5b372 100644 (file)
@@ -1322,15 +1322,14 @@ build_type_attribute_qual_variant (tree otype, tree attribute, int quals)
          warning (OPT_Wattributes,
                   "ignoring attributes applied to %qT after definition",
                   TYPE_MAIN_VARIANT (ttype));
-         return lang_hooks.types.build_lang_qualified_type (ttype, NULL_TREE,
-                                                            quals);
+         return build_qualified_type (ttype, quals);
        }
 
-      tree mtype = NULL_TREE;
-      if (otype != TYPE_MAIN_VARIANT (otype))
-       mtype = TYPE_MAIN_VARIANT (otype);
-      ttype = lang_hooks.types.build_lang_qualified_type (ttype, mtype,
-                                                         TYPE_UNQUALIFIED);
+      ttype = build_qualified_type (ttype, TYPE_UNQUALIFIED);
+      if (lang_hooks.types.copy_lang_qualifiers
+         && otype != TYPE_MAIN_VARIANT (otype))
+       ttype = (lang_hooks.types.copy_lang_qualifiers
+                (ttype, TYPE_MAIN_VARIANT (otype)));
 
       tree dtype = ntype = build_distinct_type_copy (ttype);
 
@@ -1355,15 +1354,13 @@ build_type_attribute_qual_variant (tree otype, tree attribute, int quals)
       else if (TYPE_CANONICAL (ntype) == ntype)
        TYPE_CANONICAL (ntype) = TYPE_CANONICAL (ttype);
 
-      if (otype != TYPE_MAIN_VARIANT (otype))
-       mtype = otype;
-      else
-       mtype = NULL_TREE;
-      ttype = lang_hooks.types.build_lang_qualified_type (ntype, mtype, quals);
+      ttype = build_qualified_type (ntype, quals);
+      if (lang_hooks.types.copy_lang_qualifiers
+         && otype != TYPE_MAIN_VARIANT (otype))
+       ttype = lang_hooks.types.copy_lang_qualifiers (ttype, otype);
     }
   else if (TYPE_QUALS (ttype) != quals)
-    ttype = lang_hooks.types.build_lang_qualified_type (ttype, NULL_TREE,
-                                                       quals);
+    ttype = build_qualified_type (ttype, quals);
 
   return ttype;
 }
@@ -2655,7 +2652,6 @@ std::string
 attr_access::array_as_string (tree type) const
 {
   std::string typstr;
-  bool free_type = false;
 
   if (type == error_mark_node)
     return std::string ();
@@ -2701,30 +2697,7 @@ attr_access::array_as_string (tree type) const
 
       const int quals = TYPE_QUALS (type);
       type = build_array_type (eltype, index_type);
-      if (arat || TYPE_QUALS (type) != quals)
-       {
-         /* We create a new array type which is only used during
-            printing.  Can't use build_type_attribute_qual_variant
-            because it might with some lang hooks e.g. try to push
-            qualifiers to the element type, while for the printing
-            this wants the element type qualifiers to be unmodified
-            and ARRAY_TYPE qualifiers to be a copy of the pointer
-            type qualifiers.  Furthermore, a type with somtimes
-            weird qualifiers or artificial attribute should be
-            freed right after the use.  */
-         type = copy_node (type);
-         if (arat)
-           {
-             TREE_CHAIN (arat) = TYPE_ATTRIBUTES (type);
-             TYPE_ATTRIBUTES (type) = arat;
-           }
-         TYPE_READONLY (type) = (quals & TYPE_QUAL_CONST) != 0;
-         TYPE_VOLATILE (type) = (quals & TYPE_QUAL_VOLATILE) != 0;
-         TYPE_ATOMIC (type) = (quals & TYPE_QUAL_ATOMIC) != 0;
-         TYPE_RESTRICT (type) = (quals & TYPE_QUAL_RESTRICT) != 0;
-         TYPE_ADDR_SPACE (type) = DECODE_QUAL_ADDR_SPACE (quals);
-         free_type = true;
-       }
+      type = build_type_attribute_qual_variant (type, arat, quals);
     }
 
   /* Format the type using the current pretty printer.  The generic tree
@@ -2732,8 +2705,6 @@ attr_access::array_as_string (tree type) const
   std::unique_ptr<pretty_printer> pp (global_dc->clone_printer ());
   pp_printf (pp.get (), "%qT", type);
   typstr = pp_formatted_text (pp.get ());
-  if (free_type)
-    ggc_free (type);
 
   return typstr;
 }
index 49782d4eec8edde42ca12fbbb90e8e9b32d40748..38e88733b5098ba6e92c066deedf07e3c8970ab6 100644 (file)
@@ -70,17 +70,6 @@ c_register_features ()
     }
 }
 
-/* Langhook for building qualified types.  */
-
-tree
-c_build_lang_qualified_type (tree type, tree, int type_quals)
-{
-  if (TREE_CODE (type) == ARRAY_TYPE)
-    return c_build_qualified_type (type, type_quals);
-  else
-    return build_qualified_type (type, type_quals);
-}
-
 bool
 c_missing_noreturn_ok_p (tree decl)
 {
index 8a67f6d99aa7484b5ed5f601af1dca2977fce2f5..e103646b67e8ac8f157e3d1355d1040c2f890da2 100644 (file)
@@ -59,8 +59,6 @@ extern void c_register_features ();
 #define LANG_HOOKS_PRINT_IDENTIFIER c_print_identifier
 #undef LANG_HOOKS_TYPES_COMPATIBLE_P
 #define LANG_HOOKS_TYPES_COMPATIBLE_P c_types_compatible_p
-#undef LANG_HOOKS_BUILD_LANG_QUALIFIED_TYPE
-#define LANG_HOOKS_BUILD_LANG_QUALIFIED_TYPE c_build_lang_qualified_type
 #undef LANG_HOOKS_MISSING_NORETURN_OK_P
 #define LANG_HOOKS_MISSING_NORETURN_OK_P c_missing_noreturn_ok_p
 #undef LANG_HOOKS_BLOCK_MAY_FALLTHRU
index a63d1b674d64c2f5a9c7e92e8fcaa1c6b90373f5..167f50e900c785995c07e25c3fe8845d54c2d1fb 100644 (file)
@@ -780,7 +780,6 @@ extern tree c_finish_bc_name (location_t, tree, bool);
 
 /* in c-objc-common.cc */
 extern bool c_objc_common_init (void);
-extern tree c_build_lang_qualified_type (tree, tree, int);
 extern bool c_missing_noreturn_ok_p (tree);
 extern bool c_warn_unused_global_decl (const_tree);
 extern void c_initialize_diagnostics (diagnostics::context *);
index 441a250e8d3f4a0c372b8ae0effa11a265f9d138..2999b36a5ddce64f64b8ff28d540461fc668b27b 100644 (file)
@@ -112,8 +112,8 @@ extern tree cxx_simulate_record_decl (location_t, const char *,
   cxx_simulate_builtin_function_decl
 #undef LANG_HOOKS_TYPE_HASH_EQ
 #define LANG_HOOKS_TYPE_HASH_EQ        cxx_type_hash_eq
-#undef LANG_HOOKS_BUILD_LANG_QUALIFIED_TYPE
-#define LANG_HOOKS_BUILD_LANG_QUALIFIED_TYPE   cxx_build_lang_qualified_type
+#undef LANG_HOOKS_COPY_LANG_QUALIFIERS
+#define LANG_HOOKS_COPY_LANG_QUALIFIERS        cxx_copy_lang_qualifiers
 #undef LANG_HOOKS_MISSING_NORETURN_OK_P
 #define LANG_HOOKS_MISSING_NORETURN_OK_P cp_missing_noreturn_ok_p
 #undef LANG_HOOKS_BLOCK_MAY_FALLTHRU
index 1045dfd60143be73be2e01465190c181f66cc724..3867b7b0d2c925444cefb1e22299931914ef78fc 100644 (file)
@@ -7541,7 +7541,6 @@ extern tmpl_spec_kind current_tmpl_spec_kind      (int);
 extern tree cxx_builtin_function               (tree decl);
 extern tree cxx_builtin_function_ext_scope     (tree decl);
 extern tree cxx_simulate_builtin_function_decl (tree);
-extern tree cxx_build_lang_qualified_type      (tree, tree, int);
 extern tree check_elaborated_type_specifier    (enum tag_types, tree, bool);
 extern void warn_extern_redeclared_static      (tree, tree);
 extern tree cxx_comdat_group                   (tree);
index 761f7d8ff3dc3219bb46ac6e4b2ef685ca77a94b..f364d525f23eeee0fb847d3a786058f55badd025 100644 (file)
@@ -1470,27 +1470,6 @@ c_build_qualified_type (tree type, int type_quals, tree /* orig_qual_type */,
   return cp_build_qualified_type (type, type_quals);
 }
 
-/* Implementation of the build_lang_qualified_type langhook.  */
-tree
-cxx_build_lang_qualified_type (tree type, tree otype, int type_quals)
-{
-  /* Only handle ARRAY_TYPEs using cp_build_qualified_type, so that
-     quals are pushed to the element type.  That is needed for PR101312.
-     For other types just keep using build_qualified_type with
-     cxx_copy_lang_qualifiers if needed, otherwise we can run into
-     issues with FUNCTION_TYPEs with cv-qualifier-seq vs. type-specifier,
-     or REFERENCE_TYPE which will error on certain TYPE_QUALS.  */
-  if (TREE_CODE (type) == ARRAY_TYPE)
-    return cp_build_qualified_type (type, type_quals);
-  else
-    {
-      tree ret = build_qualified_type (type, type_quals);
-      if (otype)
-       ret = cxx_copy_lang_qualifiers (ret, otype);
-      return ret;
-    }
-}
-
 \f
 /* Make a variant of TYPE, qualified with the TYPE_QUALS.  Handles
    arrays correctly.  In particular, if TYPE is an array of T's, and
index 1603bd8e63e0dd5039302e5ef81b9270141a0d45..fc409ec08b96781064d5bf18a339335c7834f4ff 100644 (file)
@@ -63,7 +63,6 @@ extern tree lhd_type_for_size (unsigned precision, int unsignedp);
 extern void lhd_incomplete_type_error (location_t, const_tree, const_tree);
 extern tree lhd_type_promotes_to (tree);
 extern void lhd_register_builtin_type (tree, const char *);
-extern tree lhd_build_lang_qualified_type (tree, tree, int);
 extern bool lhd_decl_ok_for_sibcall (const_tree);
 extern size_t lhd_tree_size (enum tree_code);
 extern HOST_WIDE_INT lhd_to_target_charset (HOST_WIDE_INT);
@@ -213,7 +212,7 @@ extern tree lhd_unit_size_without_reusable_padding (tree);
 #define LANG_HOOKS_OMP_FIRSTPRIVATIZE_TYPE_SIZES \
   lhd_omp_firstprivatize_type_sizes
 #define LANG_HOOKS_TYPE_HASH_EQ                NULL
-#define LANG_HOOKS_BUILD_LANG_QUALIFIED_TYPE   lhd_build_lang_qualified_type
+#define LANG_HOOKS_COPY_LANG_QUALIFIERS NULL
 #define LANG_HOOKS_GET_ARRAY_DESCR_INFO        NULL
 #define LANG_HOOKS_GET_SUBRANGE_BOUNDS NULL
 #define LANG_HOOKS_GET_TYPE_BIAS       NULL
@@ -241,7 +240,7 @@ extern tree lhd_unit_size_without_reusable_padding (tree);
   LANG_HOOKS_TYPE_MAX_SIZE, \
   LANG_HOOKS_OMP_FIRSTPRIVATIZE_TYPE_SIZES, \
   LANG_HOOKS_TYPE_HASH_EQ, \
-  LANG_HOOKS_BUILD_LANG_QUALIFIED_TYPE, \
+  LANG_HOOKS_COPY_LANG_QUALIFIERS, \
   LANG_HOOKS_GET_ARRAY_DESCR_INFO, \
   LANG_HOOKS_GET_SUBRANGE_BOUNDS, \
   LANG_HOOKS_GET_TYPE_BIAS, \
index d17d60737ea727324bf8a7e3edbdb19bcdf3da3f..e2c7735596e08ccbc95e0ae9b0a56f6ec35027be 100644 (file)
@@ -202,16 +202,6 @@ lhd_register_builtin_type (tree ARG_UNUSED (type),
 {
 }
 
-/* Return a version of the TYPE, qualified as indicated by the
-   TYPE_QUALS, if one exists.  If no qualified version exists yet,
-   creates it and returns it.  */
-tree
-lhd_build_lang_qualified_type (tree type, tree ARG_UNUSED (otype),
-                              int type_quals)
-{
-  return build_qualified_type (type, type_quals);
-}
-
 /* Invalid use of an incomplete type.  */
 void
 lhd_incomplete_type_error (location_t ARG_UNUSED (loc),
index 47996ff19137dd3ca83d8c5bf55374883490768d..6eb5c1602f837ddaf5d7f2d0173d7417ec5173ad 100644 (file)
@@ -134,10 +134,9 @@ struct lang_hooks_for_types
      FUNCTION_TYPE or METHOD_TYPE.  */
   bool (*type_hash_eq) (const_tree, const_tree);
 
-  /* Return a version of the TYPE, qualified as indicated by the
-     TYPE_QUALS in a language-specific way, if one exists, otherwise create it.
-     If OTYPE is non-NULL, copy extra language modifiers from it too.  */
-  tree (*build_lang_qualified_type) (tree, tree, int);
+  /* If non-NULL, return TYPE1 with any language-specific modifiers copied from
+     TYPE2.  */
+  tree (*copy_lang_qualifiers) (const_tree, const_tree);
 
   /* Return TRUE if TYPE uses a hidden descriptor and fills in information
      for the debugger about the array bounds, strides, etc.  */
diff --git a/gcc/testsuite/c-c++-common/pr101312-1.c b/gcc/testsuite/c-c++-common/pr101312-1.c
deleted file mode 100644 (file)
index 8d312db..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-/* PR c/101312 */
-/* { dg-do compile } */
-
-volatile int a[1] __attribute__((may_alias));
diff --git a/gcc/testsuite/c-c++-common/pr101312-2.c b/gcc/testsuite/c-c++-common/pr101312-2.c
deleted file mode 100644 (file)
index 16d7794..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-/* PR c/101312 */
-/* { dg-do compile } */
-/* { dg-options "-g" } */
-
-volatile int a[1] __attribute__((may_alias));