]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fix bootstrap on AIX by adding c-family/c-type-mismatch.cc [PR115167]
authorDavid Malcolm <dmalcolm@redhat.com>
Tue, 28 May 2024 17:04:25 +0000 (13:04 -0400)
committerDavid Malcolm <dmalcolm@redhat.com>
Tue, 28 May 2024 17:04:25 +0000 (13:04 -0400)
PR bootstrap/115167 reports a bootstrap failure on AIX triggered by
r15-636-g770657d02c986c whilst building f951 in stage 2, due to
the linker not being able to find symbols for:

  vtable for range_label_for_type_mismatch
  range_label_for_type_mismatch::get_text(unsigned int) const

The only users of the class range_label_for_type_mismatch are in the
C/C++ frontends, each of which supply their own implementation of:

  range_label_for_type_mismatch::get_text(unsigned int) const

i.e. we had a cluster of symbols that was disconnnected from any
users on f951.

The above patch added a new range_label::get_effects vfunc to the
base class.  My hunch is that we were getting away with not defining
the symbol for Fortran with AIX's linker before (since none of the
users are used), but adding the get_effects vfunc has somehow broken
things (possibly because there's an empty implementation in the base
class in the *header*).

The following patch moves all of the code in
gcc/gcc-rich-location.[cc,h,o} defining and using
range_label_for_type_mismatch to a new
gcc/c-family/c-type-mismatch.{cc,h,o}, to help the linker ignore this
cluster of symbols when it's disconnected from users.

I was able to reproduce the failure without the patch, and then
successfully bootstrap with this patch on powerpc-ibm-aix7.3.1.0
(cfarm119).

gcc/ChangeLog:
PR bootstrap/115167
* Makefile.in (C_COMMON_OBJS): Add c-family/c-type-mismatch.o.
* gcc-rich-location.cc
(maybe_range_label_for_tree_type_mismatch::get_text): Move to
c-family/c-type-mismatch.cc.
(binary_op_rich_location::binary_op_rich_location): Likewise.
(binary_op_rich_location::use_operator_loc_p): Likewise.
* gcc-rich-location.h (class range_label_for_type_mismatch):
Likewise.
(class maybe_range_label_for_tree_type_mismatch): Likewise.
(class op_location_t): Likewise for forward decl.
(class binary_op_rich_location): Likewise.

gcc/c-family/ChangeLog:
PR bootstrap/115167
* c-format.cc: Replace include of "gcc-rich-location.h" with
"c-family/c-type-mismatch.h".
* c-type-mismatch.cc: New file, taking material from
gcc-rich-location.cc.
* c-type-mismatch.h: New file, taking material from
gcc-rich-location.h.
* c-warn.cc: Replace include of "gcc-rich-location.h" with
"c-family/c-type-mismatch.h".

gcc/c/ChangeLog:
PR bootstrap/115167
* c-objc-common.cc: Replace include of "gcc-rich-location.h" with
"c-family/c-type-mismatch.h".
* c-typeck.cc: Likewise.

gcc/cp/ChangeLog:
PR bootstrap/115167
PR bootstrap/115167
* call.cc: Replace include of "gcc-rich-location.h" with
"c-family/c-type-mismatch.h".
* error.cc: Likewise.
* typeck.cc: Likewise.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
12 files changed:
gcc/Makefile.in
gcc/c-family/c-format.cc
gcc/c-family/c-type-mismatch.cc [new file with mode: 0644]
gcc/c-family/c-type-mismatch.h [new file with mode: 0644]
gcc/c-family/c-warn.cc
gcc/c/c-objc-common.cc
gcc/c/c-typeck.cc
gcc/cp/call.cc
gcc/cp/error.cc
gcc/cp/typeck.cc
gcc/gcc-rich-location.cc
gcc/gcc-rich-location.h

index a7f15694c34b0bcc57221872da3eac90384d2ec8..66d42cc41f8436e5374dc14b34a964c495d36ac9 100644 (file)
@@ -1301,7 +1301,8 @@ C_COMMON_OBJS = c-family/c-common.o c-family/c-cppbuiltin.o c-family/c-dump.o \
   c-family/c-ppoutput.o c-family/c-pragma.o c-family/c-pretty-print.o \
   c-family/c-semantics.o c-family/c-ada-spec.o \
   c-family/c-ubsan.o c-family/known-headers.o \
-  c-family/c-attribs.o c-family/c-warn.o c-family/c-spellcheck.o
+  c-family/c-attribs.o c-family/c-warn.o c-family/c-spellcheck.o \
+  c-family/c-type-mismatch.o
 
 # Analyzer object files
 ANALYZER_OBJS = \
index 9c4deabc10957bcf575084f3fc64ec826973616f..7a5ffc25602c8f6c41215a79d4e3e94e0d4b60c7 100644 (file)
@@ -35,7 +35,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "selftest-diagnostic.h"
 #include "builtins.h"
 #include "attribs.h"
-#include "gcc-rich-location.h"
+#include "c-family/c-type-mismatch.h"
 
 /* Handle attributes associated with format checking.  */
 
diff --git a/gcc/c-family/c-type-mismatch.cc b/gcc/c-family/c-type-mismatch.cc
new file mode 100644 (file)
index 0000000..fae3126
--- /dev/null
@@ -0,0 +1,127 @@
+/* Implementations of classes for reporting type mismatches.
+   Copyright (C) 2014-2024 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3.  If not see
+<http://www.gnu.org/licenses/>.  */
+
+#include "config.h"
+#include "system.h"
+#include "coretypes.h"
+#include "tm.h"
+#include "hash-set.h"
+#include "vec.h"
+#include "input.h"
+#include "alias.h"
+#include "symtab.h"
+#include "inchash.h"
+#include "tree-core.h"
+#include "tree.h"
+#include "diagnostic-core.h"
+#include "c-family/c-type-mismatch.h"
+#include "print-tree.h"
+#include "pretty-print.h"
+#include "intl.h"
+#include "cpplib.h"
+#include "diagnostic.h"
+
+/* Implementation of range_label::get_text for
+   maybe_range_label_for_tree_type_mismatch.
+
+   If both expressions are non-NULL, then generate text describing
+   the first expression's type (using the other expression's type
+   for comparison, analogous to %H and %I in the C++ frontend, but
+   on expressions rather than types).  */
+
+label_text
+maybe_range_label_for_tree_type_mismatch::get_text (unsigned range_idx) const
+{
+  if (m_expr == NULL_TREE
+      || !EXPR_P (m_expr))
+    return label_text::borrow (NULL);
+  tree expr_type = TREE_TYPE (m_expr);
+
+  tree other_type = NULL_TREE;
+  if (m_other_expr && EXPR_P (m_other_expr))
+    other_type = TREE_TYPE (m_other_expr);
+
+  range_label_for_type_mismatch inner (expr_type, other_type);
+  return inner.get_text (range_idx);
+}
+
+/* binary_op_rich_location's ctor.
+
+   If use_operator_loc_p (LOC, ARG0, ARG1), then attempt to make a 3-location
+   rich_location of the form:
+
+     arg_0 op arg_1
+     ~~~~~ ^~ ~~~~~
+       |        |
+       |        arg1 type
+       arg0 type
+
+   labelling the types of the arguments if SHOW_TYPES is true.
+
+   Otherwise, make a 1-location rich_location using the compound
+   location within LOC:
+
+     arg_0 op arg_1
+     ~~~~~~^~~~~~~~
+
+   for which we can't label the types.  */
+
+binary_op_rich_location::binary_op_rich_location (const op_location_t &loc,
+                                                 tree arg0, tree arg1,
+                                                 bool show_types)
+: gcc_rich_location (loc.m_combined_loc),
+  m_label_for_arg0 (arg0, arg1),
+  m_label_for_arg1 (arg1, arg0)
+{
+  /* Default (above) to using the combined loc.
+     Potentially override it here: if we have location information for the
+     operator and for both arguments, then split them all out.
+     Alternatively, override it if we don't have the combined location.  */
+  if (use_operator_loc_p (loc, arg0, arg1))
+    {
+      set_range (0, loc.m_operator_loc, SHOW_RANGE_WITH_CARET);
+      maybe_add_expr (arg0, show_types ? &m_label_for_arg0 : NULL);
+      maybe_add_expr (arg1, show_types ? &m_label_for_arg1 : NULL);
+    }
+}
+
+/* Determine if binary_op_rich_location's ctor should attempt to make
+   a 3-location rich_location (the location of the operator and of
+   the 2 arguments), or fall back to a 1-location rich_location showing
+   just the combined location of the operation as a whole.  */
+
+bool
+binary_op_rich_location::use_operator_loc_p (const op_location_t &loc,
+                                            tree arg0, tree arg1)
+{
+  /* If we don't have a combined location, then use the operator location,
+     and try to add ranges for the operators.  */
+  if (loc.m_combined_loc == UNKNOWN_LOCATION)
+    return true;
+
+  /* If we don't have the operator location, then use the
+     combined location.  */
+  if (loc.m_operator_loc == UNKNOWN_LOCATION)
+    return false;
+
+  /* We have both operator location and combined location: only use the
+     operator location if we have locations for both arguments.  */
+  return (EXPR_HAS_LOCATION (arg0)
+         && EXPR_HAS_LOCATION (arg1));
+}
diff --git a/gcc/c-family/c-type-mismatch.h b/gcc/c-family/c-type-mismatch.h
new file mode 100644 (file)
index 0000000..58fba5d
--- /dev/null
@@ -0,0 +1,126 @@
+/* Declarations relating to classes for reporting type mismatches.
+   Copyright (C) 2014-2024 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3.  If not see
+<http://www.gnu.org/licenses/>.  */
+
+#ifndef GCC_C_TYPE_MISMATCH_H
+#define GCC_C_TYPE_MISMATCH_H
+
+#include "gcc-rich-location.h"
+
+/* Concrete subclass of libcpp's range_label for use in
+   diagnostics involving mismatched types.
+
+   Each frontend that uses this should supply its own implementation.
+
+   Generate a label describing LABELLED_TYPE.  The frontend may use
+   OTHER_TYPE where appropriate for highlighting the differences between
+   the two types (analogous to C++'s use of %H and %I with
+   template types).
+
+   Either or both of LABELLED_TYPE and OTHER_TYPE may be NULL_TREE.
+   If LABELLED_TYPE is NULL_TREE, then there is no label.
+
+   For example, this rich_location could use two instances of
+   range_label_for_type_mismatch:
+
+      printf ("arg0: %i  arg1: %s arg2: %i",
+                               ^~
+                               |
+                               const char *
+              100, 101, 102);
+                   ~~~
+                   |
+                   int
+
+   (a) the label for "%s" with LABELLED_TYPE for "const char*" and
+   (b) the label for "101" with LABELLED TYPE for "int"
+   where each one uses the other's type as OTHER_TYPE.  */
+
+class range_label_for_type_mismatch : public range_label
+{
+ public:
+  range_label_for_type_mismatch (tree labelled_type, tree other_type)
+  : m_labelled_type (labelled_type), m_other_type (other_type)
+  {
+  }
+
+  label_text get_text (unsigned range_idx) const override;
+
+ protected:
+  tree m_labelled_type;
+  tree m_other_type;
+};
+
+/* Subclass of range_label for labelling the type of EXPR when reporting
+   a type mismatch between EXPR and OTHER_EXPR.
+   Either or both of EXPR and OTHER_EXPR could be NULL.  */
+
+class maybe_range_label_for_tree_type_mismatch : public range_label
+{
+ public:
+  maybe_range_label_for_tree_type_mismatch (tree expr, tree other_expr)
+  : m_expr (expr), m_other_expr (other_expr)
+  {
+  }
+
+  label_text get_text (unsigned range_idx) const final override;
+
+ private:
+  tree m_expr;
+  tree m_other_expr;
+};
+
+class op_location_t;
+
+/* A subclass of rich_location for showing problems with binary operations.
+
+   If enough location information is available, the ctor will make a
+   3-location rich_location of the form:
+
+     arg_0 op arg_1
+     ~~~~~ ^~ ~~~~~
+       |        |
+       |        arg1 type
+       arg0 type
+
+   labelling the types of the arguments if SHOW_TYPES is true.
+
+   Otherwise, it will fall back to a 1-location rich_location using the
+   compound location within LOC:
+
+     arg_0 op arg_1
+     ~~~~~~^~~~~~~~
+
+   for which we can't label the types.  */
+
+class binary_op_rich_location : public gcc_rich_location
+{
+ public:
+  binary_op_rich_location (const op_location_t &loc,
+                          tree arg0, tree arg1,
+                          bool show_types);
+
+ private:
+  static bool use_operator_loc_p (const op_location_t &loc,
+                                 tree arg0, tree arg1);
+
+  maybe_range_label_for_tree_type_mismatch m_label_for_arg0;
+  maybe_range_label_for_tree_type_mismatch m_label_for_arg1;
+};
+
+#endif /* GCC_C_TYPE_MISMATCH_H */
index 5b2d6805c7908654ccbee5521d771b052f332d98..7ddf6ea2ad8e8b5ab43cdd1af702bcb4b7d8a0cd 100644 (file)
@@ -32,7 +32,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "stringpool.h"
 #include "attribs.h"
 #include "asan.h"
-#include "gcc-rich-location.h"
+#include "c-family/c-type-mismatch.h"
 #include "gimplify.h"
 #include "c-family/c-indentation.h"
 #include "c-family/c-spellcheck.h"
index b7c72d2609c6e6d1972f37ea8393261c9248120b..42a62c84fe7c752840cf9619cb2f249adf580e0b 100644 (file)
@@ -27,7 +27,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "gimple-pretty-print.h"
 #include "langhooks.h"
 #include "c-objc-common.h"
-#include "gcc-rich-location.h"
+#include "c-family/c-type-mismatch.h"
 #include "stringpool.h"
 #include "attribs.h"
 #include "dwarf2.h"
index 2d092357e0f9c89b2e501268c66bf2bd3d23cf49..ad4c7add5627838b536ec30374988439b17d0f7f 100644 (file)
@@ -48,7 +48,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "c-family/c-ubsan.h"
 #include "gomp-constants.h"
 #include "spellcheck-tree.h"
-#include "gcc-rich-location.h"
+#include "c-family/c-type-mismatch.h"
 #include "stringpool.h"
 #include "attribs.h"
 #include "asan.h"
index ed68eb3c568418e4a17f16294e75d1ba363ef4c1..886760af699f1d62c2a928aa9477c0aef5085489 100644 (file)
@@ -42,7 +42,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "stringpool.h"
 #include "attribs.h"
 #include "decl.h"
-#include "gcc-rich-location.h"
+#include "c-family/c-type-mismatch.h"
 #include "tristate.h"
 
 /* The various kinds of conversion.  */
index 37987ccb570d3c66ec8b2e54396812ada4d2ff7c..0ff7f9d4c468ed2b87eb8ec1d7683ff8417f5ab1 100644 (file)
@@ -34,7 +34,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "c-family/c-objc.h"
 #include "ubsan.h"
 #include "internal-fn.h"
-#include "gcc-rich-location.h"
+#include "c-family/c-type-mismatch.h"
 #include "cp-name-hint.h"
 #include "attribs.h"
 
index d7fa6e0dd963ce39d4832db878a2c531d6c9a07d..4a153a8baf9e1beb78f202b93431c4fcb39a3b65 100644 (file)
@@ -35,7 +35,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "convert.h"
 #include "c-family/c-objc.h"
 #include "c-family/c-ubsan.h"
-#include "gcc-rich-location.h"
+#include "c-family/c-type-mismatch.h"
 #include "stringpool.h"
 #include "attribs.h"
 #include "asan.h"
index f83ba754ba423a924005d4290c2dff1b24818aa0..e9d753badfe0a08a5751f44d35de1922b76bb33e 100644 (file)
@@ -185,92 +185,3 @@ gcc_rich_location::add_fixit_insert_formatted (const char *content,
   else
     add_fixit_insert_before (insertion_point, content);
 }
-
-/* Implementation of range_label::get_text for
-   maybe_range_label_for_tree_type_mismatch.
-
-   If both expressions are non-NULL, then generate text describing
-   the first expression's type (using the other expression's type
-   for comparison, analogous to %H and %I in the C++ frontend, but
-   on expressions rather than types).  */
-
-label_text
-maybe_range_label_for_tree_type_mismatch::get_text (unsigned range_idx) const
-{
-  if (m_expr == NULL_TREE
-      || !EXPR_P (m_expr))
-    return label_text::borrow (NULL);
-  tree expr_type = TREE_TYPE (m_expr);
-
-  tree other_type = NULL_TREE;
-  if (m_other_expr && EXPR_P (m_other_expr))
-    other_type = TREE_TYPE (m_other_expr);
-
-  range_label_for_type_mismatch inner (expr_type, other_type);
-  return inner.get_text (range_idx);
-}
-
-/* binary_op_rich_location's ctor.
-
-   If use_operator_loc_p (LOC, ARG0, ARG1), then attempt to make a 3-location
-   rich_location of the form:
-
-     arg_0 op arg_1
-     ~~~~~ ^~ ~~~~~
-       |        |
-       |        arg1 type
-       arg0 type
-
-   labelling the types of the arguments if SHOW_TYPES is true.
-
-   Otherwise, make a 1-location rich_location using the compound
-   location within LOC:
-
-     arg_0 op arg_1
-     ~~~~~~^~~~~~~~
-
-   for which we can't label the types.  */
-
-binary_op_rich_location::binary_op_rich_location (const op_location_t &loc,
-                                                 tree arg0, tree arg1,
-                                                 bool show_types)
-: gcc_rich_location (loc.m_combined_loc),
-  m_label_for_arg0 (arg0, arg1),
-  m_label_for_arg1 (arg1, arg0)
-{
-  /* Default (above) to using the combined loc.
-     Potentially override it here: if we have location information for the
-     operator and for both arguments, then split them all out.
-     Alternatively, override it if we don't have the combined location.  */
-  if (use_operator_loc_p (loc, arg0, arg1))
-    {
-      set_range (0, loc.m_operator_loc, SHOW_RANGE_WITH_CARET);
-      maybe_add_expr (arg0, show_types ? &m_label_for_arg0 : NULL);
-      maybe_add_expr (arg1, show_types ? &m_label_for_arg1 : NULL);
-    }
-}
-
-/* Determine if binary_op_rich_location's ctor should attempt to make
-   a 3-location rich_location (the location of the operator and of
-   the 2 arguments), or fall back to a 1-location rich_location showing
-   just the combined location of the operation as a whole.  */
-
-bool
-binary_op_rich_location::use_operator_loc_p (const op_location_t &loc,
-                                            tree arg0, tree arg1)
-{
-  /* If we don't have a combined location, then use the operator location,
-     and try to add ranges for the operators.  */
-  if (loc.m_combined_loc == UNKNOWN_LOCATION)
-    return true;
-
-  /* If we don't have the operator location, then use the
-     combined location.  */
-  if (loc.m_operator_loc == UNKNOWN_LOCATION)
-    return false;
-
-  /* We have both operator location and combined location: only use the
-     operator location if we have locations for both arguments.  */
-  return (EXPR_HAS_LOCATION (arg0)
-         && EXPR_HAS_LOCATION (arg1));
-}
index 3741b2d2cb2348b24a5a3dabde392d81383aecbb..5664cb95f029a54bf56b5b25ae1ed3c3b036d398 100644 (file)
@@ -124,105 +124,4 @@ class text_range_label : public range_label
   const char *m_text;
 };
 
-/* Concrete subclass of libcpp's range_label for use in
-   diagnostics involving mismatched types.
-
-   Each frontend that uses this should supply its own implementation.
-
-   Generate a label describing LABELLED_TYPE.  The frontend may use
-   OTHER_TYPE where appropriate for highlighting the differences between
-   the two types (analogous to C++'s use of %H and %I with
-   template types).
-
-   Either or both of LABELLED_TYPE and OTHER_TYPE may be NULL_TREE.
-   If LABELLED_TYPE is NULL_TREE, then there is no label.
-
-   For example, this rich_location could use two instances of
-   range_label_for_type_mismatch:
-
-      printf ("arg0: %i  arg1: %s arg2: %i",
-                               ^~
-                               |
-                               const char *
-              100, 101, 102);
-                   ~~~
-                   |
-                   int
-
-   (a) the label for "%s" with LABELLED_TYPE for "const char*" and
-   (b) the label for "101" with LABELLED TYPE for "int"
-   where each one uses the other's type as OTHER_TYPE.  */
-
-class range_label_for_type_mismatch : public range_label
-{
- public:
-  range_label_for_type_mismatch (tree labelled_type, tree other_type)
-  : m_labelled_type (labelled_type), m_other_type (other_type)
-  {
-  }
-
-  label_text get_text (unsigned range_idx) const override;
-
- protected:
-  tree m_labelled_type;
-  tree m_other_type;
-};
-
-/* Subclass of range_label for labelling the type of EXPR when reporting
-   a type mismatch between EXPR and OTHER_EXPR.
-   Either or both of EXPR and OTHER_EXPR could be NULL.  */
-
-class maybe_range_label_for_tree_type_mismatch : public range_label
-{
- public:
-  maybe_range_label_for_tree_type_mismatch (tree expr, tree other_expr)
-  : m_expr (expr), m_other_expr (other_expr)
-  {
-  }
-
-  label_text get_text (unsigned range_idx) const final override;
-
- private:
-  tree m_expr;
-  tree m_other_expr;
-};
-
-class op_location_t;
-
-/* A subclass of rich_location for showing problems with binary operations.
-
-   If enough location information is available, the ctor will make a
-   3-location rich_location of the form:
-
-     arg_0 op arg_1
-     ~~~~~ ^~ ~~~~~
-       |        |
-       |        arg1 type
-       arg0 type
-
-   labelling the types of the arguments if SHOW_TYPES is true.
-
-   Otherwise, it will fall back to a 1-location rich_location using the
-   compound location within LOC:
-
-     arg_0 op arg_1
-     ~~~~~~^~~~~~~~
-
-   for which we can't label the types.  */
-
-class binary_op_rich_location : public gcc_rich_location
-{
- public:
-  binary_op_rich_location (const op_location_t &loc,
-                          tree arg0, tree arg1,
-                          bool show_types);
-
- private:
-  static bool use_operator_loc_p (const op_location_t &loc,
-                                 tree arg0, tree arg1);
-
-  maybe_range_label_for_tree_type_mismatch m_label_for_arg0;
-  maybe_range_label_for_tree_type_mismatch m_label_for_arg1;
-};
-
 #endif /* GCC_RICH_LOCATION_H */