From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 E663F3858423 for ; Fri, 27 Jan 2023 23:18:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E663F3858423 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1674861493; 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: in-reply-to:in-reply-to:references:references; bh=ALx3AIYzj+AUAeX+zCh+YO6AglH9LW3mpJeRjjWbICc=; b=Axk/dUpVMHnunvH3ChO2uYfqeY3V+OWKTpNAzdUD/wAebK6e/wpEn6j/P6DWv1jmpxdP35 HITKRozB4I5FdmuOwUkXvOXE+DMdTzAeu34hxmup+MWcyVJyCLIaPJGFp8+78mzgyaA8Dt eN1Y97w6n9g4PjjQu8u4y7gGMN+gtsM= Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-321-CMujgGtROcGyZ9PXjHqlDQ-1; Fri, 27 Jan 2023 18:18:11 -0500 X-MC-Unique: CMujgGtROcGyZ9PXjHqlDQ-1 Received: by mail-qv1-f69.google.com with SMTP id p14-20020a05621421ee00b005392216783aso1358941qvj.16 for ; Fri, 27 Jan 2023 15:18:11 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=mime-version:references:message-id:in-reply-to:subject:cc:to:date :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ALx3AIYzj+AUAeX+zCh+YO6AglH9LW3mpJeRjjWbICc=; b=JnGp0Pj5N58rXIr1CCxmPvoq/6RT/YR/7cwc4GksjWbcJaJxvV4jbbPcaNNJq2tEuf jRP1KL20sGOCPIaifD3D6XV+PzZFc783t+5RqiTyoSD0y3syZtCsqDhoMUQQliE0J+aP 1Md+b9YVeueT8uaktsFKey5fCS058/t/V/iQwPvViI2AKRP75RRloArBhBJh3Go9csuQ D4XeJWmGhu9A5DRMG6VfuRYTYrXvr4f/5R2p5PobWJFeiYKMzlZvsDW5rNjVYFs11F7A rIcwF0QaWaQnKjvIq5ThNbH4zYh4iMphz+oKUdH0YN8BalOHWkp80WEi1mFSFpThatNL HZhQ== X-Gm-Message-State: AO0yUKVX8P+/xtAZXGSuUCIDbN7Gdwimq4wDV2z6Ojggh6rCuCHfnMna ksbI+y824Yttk45m+PsIQClZfiP4pTDRt2txVGJgKlVZYKtKzVubhE7aDOdshuWRfM92rpZcSAm +5yfQKxtJsIvr7OiMeA== X-Received: by 2002:a0c:816b:0:b0:532:2d0e:7e3b with SMTP id 98-20020a0c816b000000b005322d0e7e3bmr504631qvc.37.1674861491141; Fri, 27 Jan 2023 15:18:11 -0800 (PST) X-Google-Smtp-Source: AK7set86xIf5maanHD/V9jCEYhVA4Km6cQ12/oOTuRaUFf1Xzn8xxQBHNLR3IZno3DjJ2zV4J+5Kfg== X-Received: by 2002:a0c:816b:0:b0:532:2d0e:7e3b with SMTP id 98-20020a0c816b000000b005322d0e7e3bmr504615qvc.37.1674861490882; Fri, 27 Jan 2023 15:18:10 -0800 (PST) Received: from [192.168.1.130] (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id e8-20020a05620a12c800b006fa22f0494bsm3734291qkl.117.2023.01.27.15.18.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Jan 2023 15:18:10 -0800 (PST) From: Patrick Palka X-Google-Original-From: Patrick Palka Date: Fri, 27 Jan 2023 18:18:09 -0500 (EST) To: Patrick Palka cc: Marek Polacek , Jason Merrill , GCC Patches Subject: Re: [PATCH] c++: fix ICE with -Wduplicated-cond [PR107593] In-Reply-To: Message-ID: References: <20230126221732.617749-1-polacek@redhat.com> <6cd96b09-828b-8820-e1f7-7f11a90e0f54@idea> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-13.9 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Fri, 27 Jan 2023, Patrick Palka wrote: > On Fri, 27 Jan 2023, Marek Polacek wrote: > > > On Fri, Jan 27, 2023 at 05:15:00PM -0500, Patrick Palka wrote: > > > 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? > > > > warn_duplicated_cond_add_or_warn lives in c-family/c-warn.cc so I can't > > use instantiation_dependent_expression_p there. Sure, I could write a > > C++ wrapper but with my patch we just won't add CONDITION to the chain > > which I thought would work just as well. > > Ah that's unfortunate :( ISTM desirable to conservatively assume an > inst-dep cond has side effects though (possibly directly from oops, "has side effects and clear the chain" rather > cp_parser_selection_statement), to avoid false positives as in: > > int n; > > template bool g() { n = 42; } > > template > void f() { > if (n) > ; > else if (g()) > ; > else if (n) > ; > } >