Fix bootstrap on AIX by adding c-family/c-type-mismatch.cc [PR115167]

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>
This commit is contained in:
David Malcolm 2024-05-28 13:04:25 -04:00
parent 2361160681
commit b544ff8856
12 changed files with 262 additions and 198 deletions

View 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 = \

View 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. */

View File

@ -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));
}

View File

@ -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 */

View 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"

View 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"

View 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"

View 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. */

View 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"

View 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"

View 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));
}

View 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 */