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 A9F843858D28 for ; Mon, 6 Dec 2021 21:35:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A9F843858D28 Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-57-jF0DLCPJPieDJ5K78uXrvw-1; Mon, 06 Dec 2021 16:35:35 -0500 X-MC-Unique: jF0DLCPJPieDJ5K78uXrvw-1 Received: by mail-qv1-f72.google.com with SMTP id h14-20020a0562140dae00b003ae664126e9so14181246qvh.3 for ; Mon, 06 Dec 2021 13:35:35 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:references:from:in-reply-to :content-transfer-encoding; bh=Kbf9gdneZIecDotH0FxJn47ieuHitdixyptnXKu5S7w=; b=LAeWxr703q4rHmUJcfanUUZPQBQ8dfKk6Csdj+Xm/IYwXtRtdStVeIFtj1LU7Mbf8C btb377V5nZUoLLL+1sR1q74tte/KVs53Es7PnsYSm5egrMt57w4SyBXjFfMiheu/TBQn xO5jfLI3Ya/T+WUHbUDc3ZFQsuMECdBndTkmDDkztMW7qJPzNWbzSn/DunlHrvWKSHo0 lKN6qq5kymQO12HpRPtgymO/OQ0dMExKHEcGaLT+gcMc1+jJvVy6fP7m+li/SPbNG1fi C0IfyffJIlu77vAo8Lw9bPCsDNfOFyVXqtZBgJPYYRDqWup25eT1RKphizjZRpQrQcZY HhrQ== X-Gm-Message-State: AOAM531Q8LfhTv9lQof57lDO+b8iwhvehR+Y8c6F+10Kzz1RZj7ZlAPL ZOhbmH2G/tM806dnbJpHYnN6YhvKze5ZcJZ/vvzhbTC5cUBVLyTqqFwDO1k++jUIro+X7ErKV2q +zs8okrdqhKi4G6YWnw== X-Received: by 2002:a05:620a:2a02:: with SMTP id o2mr36902619qkp.549.1638826534217; Mon, 06 Dec 2021 13:35:34 -0800 (PST) X-Google-Smtp-Source: ABdhPJxgDmXT6zZeZMeLRVM3NMoc+Q1cJks5BygKHNg9SAp5W3PzYkLzkQVW0RRI3hwX4I/LKTHWSg== X-Received: by 2002:a05:620a:2a02:: with SMTP id o2mr36902590qkp.549.1638826533822; Mon, 06 Dec 2021 13:35:33 -0800 (PST) Received: from [192.168.1.149] (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 o10sm8441301qtx.33.2021.12.06.13.35.32 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 06 Dec 2021 13:35:33 -0800 (PST) Message-ID: Date: Mon, 6 Dec 2021 16:35:31 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.3.2 Subject: Re: [PATCH] c++: Fix for decltype and bit-fields [PR95009] To: Marek Polacek , GCC Patches References: <20211204202617.362235-1-polacek@redhat.com> From: Jason Merrill In-Reply-To: <20211204202617.362235-1-polacek@redhat.com> 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=-14.1 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_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: Mon, 06 Dec 2021 21:35:38 -0000 On 12/4/21 15:26, Marek Polacek wrote: > Here, decltype deduces the wrong type for certain expressions involving > bit-fields. Unlike in C, in C++ bit-field width is explicitly not part > of the type, so I think decltype should never deduce to 'int:N'. The > problem isn't that we're not calling unlowered_expr_type--we are--it's > that is_bitfield_expr_with_lowered_type only handles certain codes, but > not others. For example, += works fine but ++ does not. > > This also fixes decltype-bitfield2.C where we were crashing (!), but > unfortunately it does not fix 84516 or 70733 where the problem is likely > a missing call to unlowered_expr_type. It occurs to me now that typeof > likely has had the same issue, but this patch should fix that too. > > Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk/11? OK. > PR c++/95009 > > gcc/cp/ChangeLog: > > * typeck.c (is_bitfield_expr_with_lowered_type) : > Handle UNARY_PLUS_EXPR, NEGATE_EXPR, NON_LVALUE_EXPR, BIT_NOT_EXPR, > *CREMENT_EXPR too. > > gcc/testsuite/ChangeLog: > > * g++.dg/cpp0x/decltype-bitfield1.C: New test. > * g++.dg/cpp0x/decltype-bitfield2.C: New test. > --- > gcc/cp/typeck.c | 14 +++- > .../g++.dg/cpp0x/decltype-bitfield1.C | 65 +++++++++++++++++++ > .../g++.dg/cpp0x/decltype-bitfield2.C | 18 +++++ > 3 files changed, 94 insertions(+), 3 deletions(-) > create mode 100644 gcc/testsuite/g++.dg/cpp0x/decltype-bitfield1.C > create mode 100644 gcc/testsuite/g++.dg/cpp0x/decltype-bitfield2.C > > diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c > index 5ed9a5ab9ee..4e60db40c76 100644 > --- a/gcc/cp/typeck.c > +++ b/gcc/cp/typeck.c > @@ -2209,9 +2209,9 @@ invalid_nonstatic_memfn_p (location_t loc, tree expr, tsubst_flags_t complain) > return false; > } > > -/* If EXP is a reference to a bitfield, and the type of EXP does not > - match the declared type of the bitfield, return the declared type > - of the bitfield. Otherwise, return NULL_TREE. */ > +/* If EXP is a reference to a bit-field, and the type of EXP does not > + match the declared type of the bit-field, return the declared type > + of the bit-field. Otherwise, return NULL_TREE. */ > > tree > is_bitfield_expr_with_lowered_type (const_tree exp) > @@ -2230,6 +2230,14 @@ is_bitfield_expr_with_lowered_type (const_tree exp) > > case MODIFY_EXPR: > case SAVE_EXPR: > + case UNARY_PLUS_EXPR: > + case PREDECREMENT_EXPR: > + case PREINCREMENT_EXPR: > + case POSTDECREMENT_EXPR: > + case POSTINCREMENT_EXPR: > + case NEGATE_EXPR: > + case NON_LVALUE_EXPR: > + case BIT_NOT_EXPR: > return is_bitfield_expr_with_lowered_type (TREE_OPERAND (exp, 0)); > > case COMPONENT_REF: > diff --git a/gcc/testsuite/g++.dg/cpp0x/decltype-bitfield1.C b/gcc/testsuite/g++.dg/cpp0x/decltype-bitfield1.C > new file mode 100644 > index 00000000000..2d8d8e81bff > --- /dev/null > +++ b/gcc/testsuite/g++.dg/cpp0x/decltype-bitfield1.C > @@ -0,0 +1,65 @@ > +// PR c++/95009 > +// { dg-do compile { target c++11 } } > + > +struct false_type { static constexpr bool value = false; }; > +struct true_type { static constexpr bool value = true; }; > +template > +struct is_same : false_type {}; > +template > +struct is_same : true_type {}; > + > +struct A { > + int i : 31; > + unsigned long l : 37; > +} a; > + > +void > +g () > +{ > + // Careful: pre{in,de}crements are lvalues -> deduce T&. */ > + static_assert (is_same::value, ""); > + static_assert (is_same::value, ""); > + static_assert (is_same::value, ""); > + static_assert (is_same::value, ""); > + static_assert (is_same::value, ""); > + static_assert (is_same::value, ""); > + static_assert (is_same::value, ""); > + static_assert (is_same::value, ""); > + static_assert (is_same::value, ""); > + static_assert (is_same::value, ""); > + static_assert (is_same::value, ""); > + static_assert (is_same::value, ""); > + static_assert (is_same::value, ""); > + static_assert (is_same::value, ""); > + static_assert (is_same::value, ""); > + static_assert (is_same::value, ""); > + static_assert (is_same::value, ""); > + static_assert (is_same::value, ""); > + static_assert (is_same::value, ""); > + static_assert (is_same::value, ""); > + static_assert (is_same::value, ""); > + static_assert (is_same::value, ""); > + > + static_assert (is_same::value, ""); > + static_assert (is_same::value, ""); > + static_assert (is_same::value, ""); > + static_assert (is_same::value, ""); > + static_assert (is_same::value, ""); > + static_assert (is_same::value, ""); > + static_assert (is_same::value, ""); > + static_assert (is_same::value, ""); > + static_assert (is_same::value, ""); > + static_assert (is_same::value, ""); > + static_assert (is_same::value, ""); > + static_assert (is_same::value, ""); > + static_assert (is_same::value, ""); > + static_assert (is_same::value, ""); > + static_assert (is_same::value, ""); > + static_assert (is_same::value, ""); > + static_assert (is_same::value, ""); > + static_assert (is_same::value, ""); > + static_assert (is_same::value, ""); > + static_assert (is_same::value, ""); > + static_assert (is_same::value, ""); > + static_assert (is_same::value, ""); > +} > diff --git a/gcc/testsuite/g++.dg/cpp0x/decltype-bitfield2.C b/gcc/testsuite/g++.dg/cpp0x/decltype-bitfield2.C > new file mode 100644 > index 00000000000..4bf9c7682ff > --- /dev/null > +++ b/gcc/testsuite/g++.dg/cpp0x/decltype-bitfield2.C > @@ -0,0 +1,18 @@ > +// PR c++/95009 > +// { dg-do compile { target c++11 } } > + > +struct A { > + int i:31; > +}; > + > +template > +void f () > +{ > +} > + > +int main () > +{ > + A a; > + f(); > + f(); > +} > > base-commit: 689407ef916503b2f5a3c8c07fe7d5ab1913f956 >