From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-x441.google.com (mail-wr1-x441.google.com [IPv6:2a00:1450:4864:20::441]) by sourceware.org (Postfix) with ESMTPS id AF2BF3858C2B for ; Sat, 31 Oct 2020 10:09:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org AF2BF3858C2B Received: by mail-wr1-x441.google.com with SMTP id m13so9019186wrj.7 for ; Sat, 31 Oct 2020 03:09:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=r/DFp/IWJI6iCTl/OSUYV8bHW4rb05RcXWiHK0Zmi10=; b=kHcPdn1twh9QmJV0IWv/pu0DkCzfTigWGdmSk3TqBz+gfzHZ+bMcYawqhls75Oa3g4 0j/Su2Pp1HmI8V12pCE4Sx7FaIEneIJMDI1PkH+tNVxiEfij2YPcvarPS0bnd4RSXQty ldk6EfCtHQIOlRjlRACrlruReIXrmEvdsPoimzUCX+rHj5/Zok3NLmU7IPRWg/xUs6P2 haJixSeZhfpwZfy+4qnkPT+RLfQ3y4an8N/CosFFFJ8+gh+NBIplRe96b4YKgS7D5djA 8GG3QItLhpPG44gP6tEex8M4ZeM2jmafSNr8B9cZYMwKLuxoVlWmlthhFLwYzUCbk7Zh vt/w== X-Gm-Message-State: AOAM530aNBPRQoNv1wUuPaVefwsTfXRcayxGDE/h55EAlSmLiXmdy2Ie qo671MPzMj9LiybmEvDqY30= X-Google-Smtp-Source: ABdhPJyLOPCewwsWU6R3Yr4z66iDRYnREFEEuKQdxbFz7weAGTAf3l6UpiZActTH/wP+DivF7xPUtQ== X-Received: by 2002:adf:fdc7:: with SMTP id i7mr9080354wrs.198.1604138974063; Sat, 31 Oct 2020 03:09:34 -0700 (PDT) Received: from [192.168.1.212] (host81-138-1-83.in-addr.btopenworld.com. [81.138.1.83]) by smtp.googlemail.com with ESMTPSA id s2sm8047270wmf.45.2020.10.31.03.09.32 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 31 Oct 2020 03:09:33 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 10.3 \(3273\)) Subject: Re: [PATCH v2] c++: Prevent warnings for value-dependent exprs [PR96742] From: Iain Sandoe In-Reply-To: <20201028212947.GC26929@redhat.com> Date: Sat, 31 Oct 2020 10:09:32 +0000 Cc: GCC Patches Content-Transfer-Encoding: 8bit Message-Id: References: <20201024225231.2369564-1-polacek@redhat.com> <20201028180029.GB26929@redhat.com> <4c9889ae-8f4e-5b8b-9c8e-0aa3ccacd40a@redhat.com> <20201028212947.GC26929@redhat.com> To: Marek Polacek X-Mailer: Apple Mail (2.3273) X-Spam-Status: No, score=-9.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 31 Oct 2020 10:09:37 -0000 Hi Marek, Marek Polacek via Gcc-patches wrote: > On Wed, Oct 28, 2020 at 02:46:36PM -0400, Jason Merrill wrote: >> On 10/28/20 2:00 PM, Marek Polacek wrote: >>> On Tue, Oct 27, 2020 at 01:36:30PM -0400, Jason Merrill wrote: >>>> On 10/24/20 6:52 PM, Marek Polacek wrote: >>>>> Here, in r11-155, I changed the call to uses_template_parms to >>>>> type_dependent_expression_p_push to avoid a crash in C++98 in >>>>> value_dependent_expression_p on a non-constant expression. But that >>>>> prompted a host of complaints that we now warn for value-dependent >>>>> expressions in templates. Those warnings are technically valid, but >>>>> people still don't want them because they're awkward to avoid. So let's >>>>> partially revert my earlier fix and make sure that we don't ICE in >>>>> value_dependent_expression_p by checking potential_constant_expression >>>>> first. >>>>> >>>>> Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk/10? >>>>> >>>>> gcc/cp/ChangeLog: >>>>> >>>>> PR c++/96675 >>>>> PR c++/96742 >>>>> * pt.c (tsubst_copy_and_build): Call uses_template_parms instead of >>>>> type_dependent_expression_p_push. Only call uses_template_parms >>>>> for expressions that are potential_constant_expression. >>>>> >>>>> gcc/testsuite/ChangeLog: >>>>> >>>>> PR c++/96675 >>>>> PR c++/96742 >>>>> * g++.dg/warn/Wdiv-by-zero-3.C: Turn dg-warning into dg-bogus. >>>>> * g++.dg/warn/Wtautological-compare3.C: New test. >>>>> * g++.dg/warn/Wtype-limits5.C: New test. >>>>> * g++.old-deja/g++.pt/crash10.C: Remove dg-warning. >>>>> — > >>> Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk/10? >> >> OK. > > Thanks, This regresses Objective-C++ template-4.mm with an ICE (because we don’t have a check for message_send_expr, which can’t be constexpr). I am testing the following fix (which is mostly Objective-C-local), but open to alternate solutions. Personally, I prefer to avoid double-negatives in code but because of the fallthrough to the sorry case, it seems hard to avoid. OK for master if testing is sucessful? (I assume we will also need to do the same on 10.x if you backported already) cheers Iain ======== [PATCH] Objective-C++ : Fix ICE in potential_constant_expression_1. We cannot, as things stand, handle Objective-C tree codes in the switch and deal with this by calling out to a function that has a dummy version when Objective-C is not enabled. Because of the way the logic works (with a fall through to a 'sorry' in case of unhandled expressions), the function reports cases that are known to be unsuitable for constant exprs. The dummy function always reports 'false' and thus will fall through to the 'sorry'. gcc/c-family/ChangeLog: * c-objc.h (objc_non_constant_expr_p): New. * stub-objc.c (objc_non_constant_expr_p): New. gcc/cp/ChangeLog: * constexpr.c (potential_constant_expression_1): Handle expressions known to be non-constant for Objective-C. gcc/objc/ChangeLog: * objc-act.c (objc_non_constant_expr_p): New. --- gcc/c-family/c-objc.h | 1 + gcc/c-family/stub-objc.c | 6 ++++++ gcc/cp/constexpr.c | 2 +- gcc/objc/objc-act.c | 16 +++++++++++++++- 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/gcc/c-family/c-objc.h b/gcc/c-family/c-objc.h index 6025283e5cf..4577e4f1c7f 100644 --- a/gcc/c-family/c-objc.h +++ b/gcc/c-family/c-objc.h @@ -101,6 +101,7 @@ extern void objc_add_synthesize_declaration (location_t, tree); extern void objc_add_dynamic_declaration (location_t, tree); extern const char * objc_maybe_printable_name (tree, int); extern bool objc_is_property_ref (tree); +extern bool objc_non_constant_expr_p (tree); extern bool objc_string_ref_type_p (tree); extern void objc_check_format_arg (tree, tree); extern void objc_finish_function (void); diff --git a/gcc/c-family/stub-objc.c b/gcc/c-family/stub-objc.c index c30f0b3c67d..9ced68b2b3e 100644 --- a/gcc/c-family/stub-objc.c +++ b/gcc/c-family/stub-objc.c @@ -331,6 +331,12 @@ objc_is_property_ref (tree ARG_UNUSED (node)) return 0; } +bool +objc_non_constant_expr_p (tree ARG_UNUSED (node)) +{ + return 0; +} + tree objc_maybe_build_component_ref (tree ARG_UNUSED (datum), tree ARG_UNUSED (component)) { diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c index b46824f128d..03a826ba250 100644 --- a/gcc/cp/constexpr.c +++ b/gcc/cp/constexpr.c @@ -8410,7 +8410,7 @@ potential_constant_expression_1 (tree t, bool want_rval, bool strict, bool now, return false; default: - if (objc_is_property_ref (t)) + if (objc_non_constant_expr_p (t)) return false; sorry ("unexpected AST of kind %s", get_tree_code_name (TREE_CODE (t))); diff --git a/gcc/objc/objc-act.c b/gcc/objc/objc-act.c index 0393bc44500..c0d07ae9182 100644 --- a/gcc/objc/objc-act.c +++ b/gcc/objc/objc-act.c @@ -1720,7 +1720,6 @@ objc_build_class_component_ref (tree class_name, tree property_ident) } - /* This is used because we don't want to expose PROPERTY_REF to the C/C++ frontends. Maybe we should! */ bool @@ -1732,6 +1731,21 @@ objc_is_property_ref (tree node) return false; } +/* We use this to report tree codes that are known to be invalid in const- + expression contexts. */ +bool +objc_non_constant_expr_p (tree node) +{ + switch (TREE_CODE (node)) + { + default: + return false; + case MESSAGE_SEND_EXPR: + case PROPERTY_REF: + return true; + } +} + /* This function builds a setter call for a PROPERTY_REF (real, for a declared property, or artificial, for a dot-syntax accessor which is not corresponding to a property). 'lhs' must be a PROPERTY_REF -- 2.24.1