From patchwork Tue May 28 17:11:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 1940663 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=EHrAYezC; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VpfFD6HJVz20Pb for ; Wed, 29 May 2024 03:11:43 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id AB691386C5B7 for ; Tue, 28 May 2024 17:11:41 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 89E033858431 for ; Tue, 28 May 2024 17:11:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 89E033858431 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 89E033858431 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716916278; cv=none; b=avIm1GLsxBLW7S6HNqzpP5G+cy2f+bAVE3+l5q/xQysuHSZFZZLvlilqVmZvIL1GEWPxrNQjvuK+gDAahNJOj2XLngatTxtgcsQT6Eg/jgPYljSgRLnOTo7KXebJsb+cjhYPwWeGBl5iyR5Uvk34CuHUTfgiOxCE0vvdQW6cVwU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716916278; c=relaxed/simple; bh=sXDud80zQfD1BnvjPrlqkWAoZj0KEbLV8wxS6AFsun4=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=Jdv1eqB2giwRh6wv0AQLaNRInaK97e9eAug7GLgtuhgjOmKKGZC355zoY3s2Y+AoUB4Nn7aXYv+MocgekNCWwBmu2Cp0tSMiC+EQaLjDDT2HcG8l5sOTKKRxT9MWX/fzQ2aGGQFAWE/WCi5wy+GtD2IBEUaqCgHVxjF73RWNkUk= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716916275; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=EyiP8+gqmzgrPBZLNBEaEmc5zZwzKBT4t5iS2KHBOrE=; b=EHrAYezCLUUQn6ovDoFeztyKdHZK2MRvWcyo0hLC83EFyh9OGuHCsooZFE/cAAoNSjE9fV IKgru0JRZPbd1HGWZvipBvSMdw0+3Ue1VafijPO/guZlmc9cgWbzSEEHEG5vylsZYXmmK9 b6CFjpUFzHqIiR/rA6+x9FQHW8CZ5mA= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-589-tD3oqQI0N_q-dD6dX6u6Xg-1; Tue, 28 May 2024 13:11:13 -0400 X-MC-Unique: tD3oqQI0N_q-dD6dX6u6Xg-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D4A7B380670C for ; Tue, 28 May 2024 17:11:12 +0000 (UTC) Received: from t14s.localdomain.com (unknown [10.22.10.48]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9D6BF401405; Tue, 28 May 2024 17:11:12 +0000 (UTC) From: David Malcolm To: gcc-patches@gcc.gnu.org Cc: David Malcolm Subject: [pushed] Fix bootstrap on AIX by adding c-family/c-type-mismatch.cc [PR115167] Date: Tue, 28 May 2024 13:11:10 -0400 Message-Id: <20240528171110.3777406-1-dmalcolm@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.10 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org 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). Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu. Pushed to trunk as r15-865-gb544ff88560e10. 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 --- gcc/Makefile.in | 3 +- gcc/c-family/c-format.cc | 2 +- gcc/c-family/c-type-mismatch.cc | 127 ++++++++++++++++++++++++++++++++ gcc/c-family/c-type-mismatch.h | 126 +++++++++++++++++++++++++++++++ gcc/c-family/c-warn.cc | 2 +- gcc/c/c-objc-common.cc | 2 +- gcc/c/c-typeck.cc | 2 +- gcc/cp/call.cc | 2 +- gcc/cp/error.cc | 2 +- gcc/cp/typeck.cc | 2 +- gcc/gcc-rich-location.cc | 89 ---------------------- gcc/gcc-rich-location.h | 101 ------------------------- 12 files changed, 262 insertions(+), 198 deletions(-) create mode 100644 gcc/c-family/c-type-mismatch.cc create mode 100644 gcc/c-family/c-type-mismatch.h diff --git a/gcc/Makefile.in b/gcc/Makefile.in index a7f15694c34b..66d42cc41f84 100644 --- a/gcc/Makefile.in +++ b/gcc/Makefile.in @@ -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 = \ diff --git a/gcc/c-family/c-format.cc b/gcc/c-family/c-format.cc index 9c4deabc1095..7a5ffc25602c 100644 --- a/gcc/c-family/c-format.cc +++ b/gcc/c-family/c-format.cc @@ -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 index 000000000000..fae31261d544 --- /dev/null +++ b/gcc/c-family/c-type-mismatch.cc @@ -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 +. */ + +#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 index 000000000000..58fba5d4d6ee --- /dev/null +++ b/gcc/c-family/c-type-mismatch.h @@ -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 +. */ + +#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 */ diff --git a/gcc/c-family/c-warn.cc b/gcc/c-family/c-warn.cc index 5b2d6805c790..7ddf6ea2ad8e 100644 --- a/gcc/c-family/c-warn.cc +++ b/gcc/c-family/c-warn.cc @@ -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" diff --git a/gcc/c/c-objc-common.cc b/gcc/c/c-objc-common.cc index b7c72d2609c6..42a62c84fe7c 100644 --- a/gcc/c/c-objc-common.cc +++ b/gcc/c/c-objc-common.cc @@ -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" diff --git a/gcc/c/c-typeck.cc b/gcc/c/c-typeck.cc index 7ecca9f58c68..7195adc0604e 100644 --- a/gcc/c/c-typeck.cc +++ b/gcc/c/c-typeck.cc @@ -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" diff --git a/gcc/cp/call.cc b/gcc/cp/call.cc index ed68eb3c5684..886760af699f 100644 --- a/gcc/cp/call.cc +++ b/gcc/cp/call.cc @@ -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. */ diff --git a/gcc/cp/error.cc b/gcc/cp/error.cc index 37987ccb570d..0ff7f9d4c468 100644 --- a/gcc/cp/error.cc +++ b/gcc/cp/error.cc @@ -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" diff --git a/gcc/cp/typeck.cc b/gcc/cp/typeck.cc index 5f16994300fd..8f751d546139 100644 --- a/gcc/cp/typeck.cc +++ b/gcc/cp/typeck.cc @@ -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" diff --git a/gcc/gcc-rich-location.cc b/gcc/gcc-rich-location.cc index f83ba754ba42..e9d753badfe0 100644 --- a/gcc/gcc-rich-location.cc +++ b/gcc/gcc-rich-location.cc @@ -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)); -} diff --git a/gcc/gcc-rich-location.h b/gcc/gcc-rich-location.h index 3741b2d2cb23..5664cb95f029 100644 --- a/gcc/gcc-rich-location.h +++ b/gcc/gcc-rich-location.h @@ -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 */