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.133.124]) by sourceware.org (Postfix) with ESMTPS id D03C23858D28 for ; Fri, 27 Jan 2023 22:49:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D03C23858D28 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=1674859775; 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: in-reply-to:in-reply-to:references:references; bh=AoWopV6kmpEWTKBvvpHHt2bL6VMjrjHwnNbEVpP/uwA=; b=ZKccTquyvgP8ICUHKuXdWESlbtASSevTCR0ARjZNOH2W8S3z5Ggz8h508o3wqv3WsYCBs+ aJbEjW2zqNjvw2TNcoXQpw3XTpVJEtXkGhuNTxehh1/0o3armoj3UO11wInWAES+Fg+2Og TQ6JNd3rsrntWEQf6bOI3aIT6Q0VZvI= Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-340-bkXN3TDuMiykAg8xrfE8DQ-1; Fri, 27 Jan 2023 17:49:34 -0500 X-MC-Unique: bkXN3TDuMiykAg8xrfE8DQ-1 Received: by mail-qt1-f199.google.com with SMTP id hf20-20020a05622a609400b003abcad051d2so2800983qtb.12 for ; Fri, 27 Jan 2023 14:49:34 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=AoWopV6kmpEWTKBvvpHHt2bL6VMjrjHwnNbEVpP/uwA=; b=MXi6zOZFT+hbE6mMwosofCS1Xh1eublYUA14b3q2GF1Da8IJx6Gu5qwfXz77nmW3Ud uo6iMYnjTCoVh0a6dzcuboA0GTbEc1FocapHVAU/zIZltfI8A+jOv/quR8aFIznrCFK3 W+uOFA2bY0aMEL7labtBDPPgJrTd094VGNN8rIct6h2uBf5mX4Fh6A8476Pd/UVcwPDm dBsSww8WSJvbLXra6IAyh39rg2KAfNfEHBoXmJw7TR/JK5N+jVJ3DpvHtiql2YNgpajn oayF2+9I75+tzlN6aiAkXsm8+cgIyZVBlK7A3kIcfuCTmFV3RK+EWe7gwZVrCKQV3BmA bszw== X-Gm-Message-State: AFqh2koqJVX7cjNtwhaUTGljMW+byNo8ILFB+sObKjS9SX5nSOUGiUEs DD2D2jXVOZWgUN2czE4r8TGcelhKqliewBY20WdarImkJ5u0gFYdL5uJLDk1ez7iZwJI70/xFNo gjFziyNkqWZfu4heg6A== X-Received: by 2002:ac8:60d7:0:b0:3b1:2604:634b with SMTP id i23-20020ac860d7000000b003b12604634bmr60493995qtm.30.1674859773746; Fri, 27 Jan 2023 14:49:33 -0800 (PST) X-Google-Smtp-Source: AMrXdXtFcAv27fT36MlHPnrJiWe1q55UGPFx0ONl0Y/vawU2XD5C/g354nj+qsYqH2kbdHH4my+Arg== X-Received: by 2002:ac8:60d7:0:b0:3b1:2604:634b with SMTP id i23-20020ac860d7000000b003b12604634bmr60493973qtm.30.1674859773452; Fri, 27 Jan 2023 14:49:33 -0800 (PST) Received: from [192.168.1.108] (130-44-159-43.s15913.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.159.43]) by smtp.gmail.com with ESMTPSA id br9-20020a05622a1e0900b003b62e8b77e7sm3510588qtb.68.2023.01.27.14.49.32 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 27 Jan 2023 14:49:32 -0800 (PST) Message-ID: <36837d2d-5c87-0f72-603b-aa976ed021bb@redhat.com> Date: Fri, 27 Jan 2023 17:49:32 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.6.1 Subject: Re: [PATCH] c++: fix ICE with -Wduplicated-cond [PR107593] To: Patrick Palka , Marek Polacek Cc: GCC Patches References: <20230126221732.617749-1-polacek@redhat.com> <6cd96b09-828b-8820-e1f7-7f11a90e0f54@idea> From: Jason Merrill In-Reply-To: <6cd96b09-828b-8820-e1f7-7f11a90e0f54@idea> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,NICE_REPLY_A,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 1/27/23 17:15, 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? Makes sense. >> >> 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 >> +void >> +foo () >> +{ >> + if (T() && T() && int()) >> + ; >> + else if (T() && T() && int()) >> + ; >> +} >> + >> +template >> +void bar(T a) >> +{ >> + if (a) >> + ; >> + else if (a) >> + ; >> +} >> + >> +template >> +void baz(int a) >> +{ >> + if (a) >> + ; >> + else if (a) // { dg-warning "duplicated" } >> + ; >> +} >> +void >> +f () >> +{ >> + foo(); >> + bar(1); >> + baz(1); >> +} >> >> base-commit: 94673a121cfc7f9d51c9d05e31795477f4dc8dc7 >> -- >> 2.39.1 >> >> >