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 8876A385701A for ; Tue, 16 May 2023 19:37:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8876A385701A 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=1684265833; 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=qN/NqSUAo5LsfxMdN0zJ/2uTLK4bHVrFoeFzSvwgffY=; b=h2lVcNqLy9QYKWdT/m3PMws0gz+KMhPBZyBAy7ynYoIqR+GN4auKMGEEhuEBei8mb10jAd V59UXN7TKDq/s4yNEwX4FKRI+E9iOFw1hNLdvQm152avoOhuCuZ7GiZsMSqAF7UnLGVkbD QD7IdExnERJtNaNqBhQaBppjbnhlY3Q= 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_256_GCM_SHA384) id us-mta-460-ib5OXcWQM7a5k0G2sV5Nqg-1; Tue, 16 May 2023 15:37:11 -0400 X-MC-Unique: ib5OXcWQM7a5k0G2sV5Nqg-1 Received: by mail-qv1-f70.google.com with SMTP id 6a1803df08f44-61acaf012f0so85722146d6.1 for ; Tue, 16 May 2023 12:37:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684265831; x=1686857831; 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=qN/NqSUAo5LsfxMdN0zJ/2uTLK4bHVrFoeFzSvwgffY=; b=fG090bSECfg7+TgAitbady2bp4u+AmzhoMPyBdt69u7NzqOI4tzhsmiUek/4g/u1fp LWvMC09I4c79t73PdHZtHNNOEO5lwATzJFEhN/8Cwg2tGryFZIp5UF9kBUzqrihRKbyp thr0Q57dZ7uU9B7sZgF8jgJbBoLEkct4uDanuiEpZonUf9dak0rsW+rZ7/EP77ichE6e hXmf5jF+Flu8K5dHzKfyNhhbRpzTFXJhQe6xPHV2+ksfpCXBOzT0p3lA8HptashA45rp ap7muQ9bdwljXg7Dy2U3e1Vw0bWOYTUUnPIlzqTt6Ul6eKy6J4+3ZbMRQdwNgPQrYSgL 78jg== X-Gm-Message-State: AC+VfDyuJV+Y7deOawKWuczMzGiSOojN9DdQh7/J9pl4PMUtWQW5FnNV 5qsoUqX1/wGeepaR1UpeFFkiiq8pN0kpqpdA0WsJPRm6tnFttFgsjmwXVRRJBygjWGAXrWs4SL+ LVi1Rlz3+DVts1bp6Cm6vV8leug== X-Received: by 2002:a05:6214:c2e:b0:621:2478:f75a with SMTP id a14-20020a0562140c2e00b006212478f75amr45962576qvd.45.1684265831214; Tue, 16 May 2023 12:37:11 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4eE7Y1fhg+5RXfsxSBwJpHRcIwAKonJfxkFIQTGzOSZU2PEdjTsTQ/nNcJItpoxQv4EZqcZQ== X-Received: by 2002:a05:6214:c2e:b0:621:2478:f75a with SMTP id a14-20020a0562140c2e00b006212478f75amr45962547qvd.45.1684265830871; Tue, 16 May 2023 12:37:10 -0700 (PDT) Received: from [192.168.1.108] (130-44-146-16.s12558.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.146.16]) by smtp.gmail.com with ESMTPSA id q2-20020a05620a038200b00757882b0224sm90618qkm.49.2023.05.16.12.37.09 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 16 May 2023 12:37:10 -0700 (PDT) Message-ID: <533e2227-9fa5-3fe2-7d87-2a7d1282cd73@redhat.com> Date: Tue, 16 May 2023 15:37:08 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.10.1 Subject: Re: [PATCH] c++: Don't try to initialize zero width bitfields in zero initialization [PR109868] 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=-8.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE 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 5/16/23 15:34, Jakub Jelinek wrote: > Hi! > > My GCC 12 change to avoid removing zero-sized bitfields as they are > important for ABI and are needed for layout compatibility traits > apparently causes zero sized bitfields to be initialized in the IL, > which at least in 13+ results in ICEs in the ranger which is upset > about zero precision types. > > I think we could even avoid initializing other unnamed bitfields, but > unfortunately !CONSTRUCTOR_NO_CLEARING doesn't mean in the middle-end > clearing of padding bits and until we have some new flag that represents > the request to clear padding bits, I think it is better to keep zeroing > non-zero sized unnamed bitfields. > > In addition to skipping those fields, I have changed the logic how > UNION_TYPEs are handled, the current code was a little bit weird in that > e.g. if first non-static data member had error_mark_node type, we'd happily > zero initialize the second non-static data member, etc. > > Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk/13, > perhaps even 12? OK back to 12, I think. > 2023-05-16 Jakub Jelinek > > PR c++/109868 > * init.cc (build_zero_init_1): Don't initialize zero-width bitfields. > For unions only initialize the first FIELD_DECL. > > * g++.dg/init/pr109868.C: New test. > > --- gcc/cp/init.cc.jj 2023-05-01 23:07:05.147417750 +0200 > +++ gcc/cp/init.cc 2023-05-16 10:01:14.512489727 +0200 > @@ -189,15 +189,21 @@ build_zero_init_1 (tree type, tree nelts > init = build_zero_cst (type); > else if (RECORD_OR_UNION_CODE_P (TREE_CODE (type))) > { > - tree field; > + tree field, next; > vec *v = NULL; > > /* Iterate over the fields, building initializations. */ > - for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field)) > + for (field = TYPE_FIELDS (type); field; field = next) > { > + next = DECL_CHAIN (field); > + > if (TREE_CODE (field) != FIELD_DECL) > continue; > > + /* For unions, only the first field is initialized. */ > + if (TREE_CODE (type) == UNION_TYPE) > + next = NULL_TREE; > + > if (TREE_TYPE (field) == error_mark_node) > continue; > > @@ -212,6 +218,11 @@ build_zero_init_1 (tree type, tree nelts > continue; > } > > + /* Don't add zero width bitfields. */ > + if (DECL_C_BIT_FIELD (field) > + && integer_zerop (DECL_SIZE (field))) > + continue; > + > /* Note that for class types there will be FIELD_DECLs > corresponding to base classes as well. Thus, iterating > over TYPE_FIELDs will result in correct initialization of > @@ -230,10 +241,6 @@ build_zero_init_1 (tree type, tree nelts > if (value) > CONSTRUCTOR_APPEND_ELT(v, field, value); > } > - > - /* For unions, only the first field is initialized. */ > - if (TREE_CODE (type) == UNION_TYPE) > - break; > } > > /* Build a constructor to contain the initializations. */ > --- gcc/testsuite/g++.dg/init/pr109868.C.jj 2023-05-16 09:43:54.706278293 +0200 > +++ gcc/testsuite/g++.dg/init/pr109868.C 2023-05-16 09:44:16.581966894 +0200 > @@ -0,0 +1,13 @@ > +// PR c++/109868 > +// { dg-do compile } > +// { dg-options "-O2" } > + > +struct A { virtual void foo (); }; > +struct B { long b; int : 0; }; > +struct C : A { B c; }; > + > +void > +bar (C *p) > +{ > + *p = C (); > +} > > Jakub >