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 C3752384FE93 for ; Thu, 15 Dec 2022 16:55:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C3752384FE93 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=1671123315; 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=bF/QWR/Eaj+gRmoRb/1bWyrMsfHc/IC4oEUG9OqYl2E=; b=b/O8VRyOLrn1UphNlDUwIqubValw8sTvS9J2/KrlitFvFI2Xh6sEIRx6J7Fmx63x2YuukN sD4zKD+wBeQVWqyx2X0DIIMDOrWLH5bgRw7Xpo2/xiI1A+eqtuwr6PkIxoqy7Ph0XaiMyL L9sTruud2og0BUatnpUOfvodOVlagyA= Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-230-yAwK6nKHM1q9wzxNKLt6Qw-1; Thu, 15 Dec 2022 11:55:14 -0500 X-MC-Unique: yAwK6nKHM1q9wzxNKLt6Qw-1 Received: by mail-qv1-f70.google.com with SMTP id ks19-20020a056214311300b004df5465b26eso2377852qvb.17 for ; Thu, 15 Dec 2022 08:55:14 -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:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=bF/QWR/Eaj+gRmoRb/1bWyrMsfHc/IC4oEUG9OqYl2E=; b=fdVnHNCITitsZfj2zjsgYhbG9mM7Jd+VUo8+LN0o7ARDKwMNF/hmynh4tOyQu6iIsb g+lx6N5TFdvBNXk21M5EjHLYQBWrBgszmgNt/7J13a8zXvVU8p6o8Bq1Ypk3D4G+yFqH zXTOno6kDdjmqMjc+6Bo0jICLdtFQcpg8lIlqd93sLV0atWJGgHniW/uh2qU7IYmL1qI e0vW/WcD+6dfi/H30LUX152UyIaeGe3e2KZ+roV4epH0z+ZXoy8MJOMKIEnKo1wsev0s BAgzUFbWX+X7LN++wi1Td7a4m/Sn0cCn8w4T4in1HHvxcEYtOpZRdX2X+i8Zn60Zfs4z x8Rg== X-Gm-Message-State: ANoB5pkrj0ppiJFtdhASoxqgbEqfZ5XAHwkqQr4nttHP7Oo19jU8IreI ssMqh6m8abqWHYpMQtleggKD21l1J2eJ4AB8Gn4ztt1CTaMslD/OoleVYL9taMcihAYDwdesFgC 8BmlNTEeT0ium2rCNlw== X-Received: by 2002:ac8:51cf:0:b0:3a5:7a7c:25ba with SMTP id d15-20020ac851cf000000b003a57a7c25bamr17846724qtn.38.1671123313194; Thu, 15 Dec 2022 08:55:13 -0800 (PST) X-Google-Smtp-Source: AA0mqf6m8IAAC1hGZ3aE7W9SN0mk6pBAvSkKmpFuG92TTR+svVYAylw6ysWeuf3frbUdOa6mvhjE4A== X-Received: by 2002:ac8:51cf:0:b0:3a5:7a7c:25ba with SMTP id d15-20020ac851cf000000b003a57a7c25bamr17846686qtn.38.1671123312838; Thu, 15 Dec 2022 08:55:12 -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 h7-20020a05620a284700b006f9c2be0b4bsm12043390qkp.135.2022.12.15.08.55.12 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 15 Dec 2022 08:55:12 -0800 (PST) Message-ID: Date: Thu, 15 Dec 2022 11:55:11 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.5.1 Subject: Re: [PATCH] c++: Ensure !!var is not an lvalue [PR107065] To: Jakub Jelinek Cc: gcc-patches@gcc.gnu.org References: From: Jason Merrill In-Reply-To: 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=-5.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,KAM_TRUTHINESS,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=no 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 12/10/22 04:33, Jakub Jelinek wrote: > Hi! > > The TRUTH_NOT_EXPR case in cp_build_unary_op is one of the spots where > we somewhat fold immediately using invert_truthvalue_loc. > I've tried using > return build1_loc (location, TRUTH_NOT_EXPR, boolean_type_node, arg); > in there instead, but unfortunately that regressed > Wlogical-not-parentheses-*.c pr49706.c pr62199.c pr65120.c sequence-pt-1.C > tests, so at least for backporting that doesn't seem to be a way to go. > > So, this patch instead wraps it into NON_LVALUE_EXPR if needed (which also > need a tweak for some tests in the pr47906.c test, but nothing major), > with the intent to make it backportable, and later I'll try to do further > steps to avoid folding here prematurely. Most of the problems with > build1 TRUTH_NOT_EXPR are that it doesn't even invert comparisons as most > common case and lots of warning code isn't able to deal with ! around > comparisons; so perhaps one way to do this would be fold by hand only > invertable comparisons and for the rest create TRUTH_NOT_EXPR. > > Anyway, bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk > (for now) and for release branches (after a while on the trunk)? OK. > 2022-12-10 Jakub Jelinek > > PR c++/107065 > gcc/cp/ > * typeck.cc (cp_build_unary_op) : If > invert_truthvalue_loc returns obvalue_p, wrap it into NON_LVALUE_EXPR. > * parser.cc (cp_parser_binary_expression): Don't call > warn_logical_not_parentheses if current.lhs is a NON_LVALUE_EXPR > of a decl with boolean type. > gcc/testsuite/ > * g++.dg/cpp0x/pr107065.C: New test. > > --- gcc/cp/typeck.cc.jj 2022-11-30 10:29:42.024701797 +0100 > +++ gcc/cp/typeck.cc 2022-12-09 17:47:54.132856233 +0100 > @@ -7396,9 +7396,13 @@ cp_build_unary_op (enum tree_code code, > build_zero_cst (TREE_TYPE (arg)), complain); > arg = perform_implicit_conversion (boolean_type_node, arg, > complain); > - val = invert_truthvalue_loc (location, arg); > if (arg != error_mark_node) > - return val; > + { > + val = invert_truthvalue_loc (location, arg); > + if (obvalue_p (val)) > + val = non_lvalue_loc (location, val); > + return val; > + } > errstring = _("in argument to unary !"); > break; > > --- gcc/cp/parser.cc.jj 2022-12-09 11:02:35.871444993 +0100 > +++ gcc/cp/parser.cc 2022-12-09 19:14:26.698847734 +0100 > @@ -10224,7 +10224,10 @@ cp_parser_binary_expression (cp_parser* > || (TREE_CODE (TREE_TYPE (TREE_OPERAND (current.lhs, 0))) > != BOOLEAN_TYPE)))) > /* Avoid warning for !!b == y where b is boolean. */ > - && (!DECL_P (tree_strip_any_location_wrapper (current.lhs)) > + && (!(DECL_P (tree_strip_any_location_wrapper (current.lhs)) > + || (TREE_CODE (current.lhs) == NON_LVALUE_EXPR > + && DECL_P (tree_strip_any_location_wrapper > + (TREE_OPERAND (current.lhs, 0))))) > || TREE_TYPE (current.lhs) == NULL_TREE > || TREE_CODE (TREE_TYPE (current.lhs)) != BOOLEAN_TYPE)) > warn_logical_not_parentheses (current.loc, current.tree_type, > --- gcc/testsuite/g++.dg/cpp0x/pr107065.C.jj 2022-12-09 16:22:59.686548071 +0100 > +++ gcc/testsuite/g++.dg/cpp0x/pr107065.C 2022-12-09 16:22:59.686548071 +0100 > @@ -0,0 +1,14 @@ > +// PR c++/107065 > +// { dg-do compile { target c++11 } } > + > +template struct is_same { static constexpr bool value = false; }; > +template struct is_same { static constexpr bool value = true; }; > + > +int > +main () > +{ > + bool b = true; > + static_assert (is_same::value, ""); > + auto bb = (!(!b)); > + static_assert (is_same::value, ""); > +} > > Jakub >