From: Patrick Palka <ppalka@redhat.com>
To: Marek Polacek <polacek@redhat.com>
Cc: Jason Merrill <jason@redhat.com>, GCC Patches <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH] c++: fix ICE with -Wduplicated-cond [PR107593]
Date: Fri, 27 Jan 2023 17:15:00 -0500 (EST) [thread overview]
Message-ID: <6cd96b09-828b-8820-e1f7-7f11a90e0f54@idea> (raw)
In-Reply-To: <20230126221732.617749-1-polacek@redhat.com>
On Thu, 26 Jan 2023, Marek Polacek via Gcc-patches wrote:
> Here we crash because a CAST_EXPR, representing T(), doesn't have
> its operand, and operand_equal_p's STRIP_ANY_LOCATION_WRAPPER doesn't
> expect that. (o_e_p is called from warn_duplicated_cond_add_or_warn.)
>
> In the past we've adjusted o_e_p to better cope with template codes,
> but in this case I think we just want to avoid attempting to warn
> about inst-dependent expressions; I don't think I've ever envisioned
> -Wduplicated-cond to warn about them.
>
> The ICE started with r12-6022, two-stage name lookup for overloaded
> operators, which gave dependent operators a TREE_TYPE (in particular,
> DEPENDENT_OPERATOR_TYPE), so we no longer bail out here in o_e_p:
>
> /* Similar, if either does not have a type (like a template id),
> they aren't equal. */
> if (!TREE_TYPE (arg0) || !TREE_TYPE (arg1))
> return false;
>
> Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?
>
> PR c++/107593
>
> gcc/cp/ChangeLog:
>
> * parser.cc (cp_parser_selection_statement): Don't do
> -Wduplicated-cond when the condition is dependent.
>
> gcc/testsuite/ChangeLog:
>
> * g++.dg/warn/Wduplicated-cond3.C: New test.
> ---
> gcc/cp/parser.cc | 3 +-
> gcc/testsuite/g++.dg/warn/Wduplicated-cond3.C | 38 +++++++++++++++++++
> 2 files changed, 40 insertions(+), 1 deletion(-)
> create mode 100644 gcc/testsuite/g++.dg/warn/Wduplicated-cond3.C
>
> diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
> index 4cdc1cd472f..3df85d49e16 100644
> --- a/gcc/cp/parser.cc
> +++ b/gcc/cp/parser.cc
> @@ -13209,7 +13209,8 @@ cp_parser_selection_statement (cp_parser* parser, bool *if_p,
> /* Add the condition. */
> condition = finish_if_stmt_cond (condition, statement);
>
> - if (warn_duplicated_cond)
> + if (warn_duplicated_cond
> + && !instantiation_dependent_expression_p (condition))
> warn_duplicated_cond_add_or_warn (token->location, condition,
> &chain);
I noticed warn_duplicated_cond_add_or_warn already has logic to handle
TREE_SIDE_EFFECTS conditions by invaliding the entire chain. I wonder
if we'd want to do the same for instantiation-dep conditions?
>
> diff --git a/gcc/testsuite/g++.dg/warn/Wduplicated-cond3.C b/gcc/testsuite/g++.dg/warn/Wduplicated-cond3.C
> new file mode 100644
> index 00000000000..3da054e5485
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/warn/Wduplicated-cond3.C
> @@ -0,0 +1,38 @@
> +// PR c++/107593
> +// { dg-do compile }
> +// { dg-options "-Wduplicated-cond" }
> +
> +template <typename T>
> +void
> +foo ()
> +{
> + if (T() && T() && int())
> + ;
> + else if (T() && T() && int())
> + ;
> +}
> +
> +template <typename T>
> +void bar(T a)
> +{
> + if (a)
> + ;
> + else if (a)
> + ;
> +}
> +
> +template <typename>
> +void baz(int a)
> +{
> + if (a)
> + ;
> + else if (a) // { dg-warning "duplicated" }
> + ;
> +}
> +void
> +f ()
> +{
> + foo<int>();
> + bar(1);
> + baz<int>(1);
> +}
>
> base-commit: 94673a121cfc7f9d51c9d05e31795477f4dc8dc7
> --
> 2.39.1
>
>
next prev parent reply other threads:[~2023-01-27 22:15 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-26 22:17 Marek Polacek
2023-01-27 22:15 ` Patrick Palka [this message]
2023-01-27 22:49 ` Jason Merrill
2023-01-27 22:56 ` Marek Polacek
2023-01-27 23:17 ` Patrick Palka
2023-01-27 23:18 ` Patrick Palka
2023-01-30 16:00 ` [PATCH v2] " Marek Polacek
2023-01-30 18:12 ` Jason Merrill
2023-01-31 2:34 ` [PATCH v3] " Marek Polacek
2023-01-31 16:30 ` Jason Merrill
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=6cd96b09-828b-8820-e1f7-7f11a90e0f54@idea \
--to=ppalka@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=jason@redhat.com \
--cc=polacek@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).