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 ESMTP id ABB2B385802D for ; Tue, 5 Oct 2021 18:47:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org ABB2B385802D Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-106-h_iNUQhdNIG1jrylm5dHkQ-1; Tue, 05 Oct 2021 14:47:55 -0400 X-MC-Unique: h_iNUQhdNIG1jrylm5dHkQ-1 Received: by mail-qk1-f197.google.com with SMTP id q5-20020a05620a0d8500b0045edb4779dbso2102408qkl.2 for ; Tue, 05 Oct 2021 11:47:55 -0700 (PDT) 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:cc:references:from:in-reply-to :content-transfer-encoding; bh=IdL14aadbXTm7vwxQOYLW9kLhxcHIICZ2Q9u7V9xo4k=; b=KharOluPGTOIF2l51ATh4e7Hc1uRQ/r/GYVgJIjxC/xU7W+gZUkhJWlAZH2+dh3PAE 27ITBa4oQepJnzvH9/ws68TEEGu93+2X5t+yjFADZfXAqfaz/xD/Cs80NahVJqwXUXUY GK6MkVLQvV9ViKi92DHjWFusezMChS5oOqaRSwEE+90E3Hw0JwJHhJ+Q8otzqow966yF 7uvG1B16/MvODxoOWIoh2G2HVqeaTyycy21MZ4S4sVoeVJkDPWI7+C4wvixmtxgqftDx glEg5i5pDADBxU0vVRcTxeGyrI8cjSGKYPpmKKWbBN/fKPAgAm741rxRvKn/9H6fy1u4 1/FA== X-Gm-Message-State: AOAM5312oCXR6lCHt+p/EFvBozHWPrIXAw/zRliZ06GSj9FL3k0vvJKt 6WpMKq+YYWkqGL7HoYdAvtcXHImVv8oD5C4WjbFnILXXYBmque9hYlReweMi4Yug2RgeWqQFpbH 436O92iXce6Y6Vki//Q== X-Received: by 2002:a05:622a:1191:: with SMTP id m17mr21231255qtk.405.1633459674638; Tue, 05 Oct 2021 11:47:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy9ECLtS3O6cpjCHfS8TO1egd6Bzxv/P1B3sw+n9FJo+0tk9V9yb/escXNxBX4lg1hQlxFQMQ== X-Received: by 2002:a05:622a:1191:: with SMTP id m17mr21231171qtk.405.1633459673557; Tue, 05 Oct 2021 11:47:53 -0700 (PDT) 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 m68sm10102727qkb.105.2021.10.05.11.47.52 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 05 Oct 2021 11:47:52 -0700 (PDT) Message-ID: Date: Tue, 5 Oct 2021 14:47:51 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.1.2 Subject: Re: [PATCH] c++: Fix apply_identity_attributes [PR102548] To: Jakub Jelinek Cc: gcc-patches@gcc.gnu.org References: <20211005075012.GA920498@tucnak> From: Jason Merrill In-Reply-To: <20211005075012.GA920498@tucnak> 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=-6.8 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_LOW, RCVD_IN_MSPIKE_H2, 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: Tue, 05 Oct 2021 18:48:00 -0000 On 10/5/21 03:50, Jakub Jelinek wrote: > Hi! > > The following testcase ICEs on x86_64-linux with -m32 due to a bug in > apply_identity_attributes. The function is being smart and attempts not > to duplicate the chain unnecessarily, if either there are no attributes > that affect type identity or there is possibly empty set of attributes > that do not affect type identity in the chain followed by attributes > that do affect type identity, it reuses that attribute chain. > > The function mishandles the cases where in the chain an attribute affects > type identity and is followed by one or more attributes that don't > affect type identity (and then perhaps some further ones that do). > > There are two bugs. One is that when we notice first attribute that > doesn't affect type identity after first attribute that does affect type > identity (with perhaps some further such attributes in the chain after it), > we want to put into the new chain just attributes starting from > (inclusive) first_ident and up to (exclusive) the current attribute a, > but the code puts into the chain all attributes starting with first_ident, > including the ones that do not affect type identity and if e.g. we have > doesn't0 affects1 doesn't2 affects3 affects4 sequence of attributes, the > resulting sequence would have > affects1 doesn't2 affects3 affects4 affects3 affects4 > attributes, i.e. one attribute that shouldn't be there and two attributes > duplicated. That is fixed by the a2 -> a2 != a change. > > The second one is that we ICE once we see second attribute that doesn't > affect type identity after an attribute that affects it. That is because > first_ident is set to error_mark_node after handling the first attribute > that doesn't affect type identity (i.e. after we've copied the > [first_ident, a) set of attributes to the new chain) to denote that from > that time on, each attribute that affects type identity should be copied > whenever it is seen (the if (as && as->affects_type_identity) code does > that correctly). But that condition is false and first_ident is > error_mark_node, we enter else if (first_ident) and use TREE_PURPOSE > /TREE_VALUE/TREE_CHAIN on error_mark_node, which ICEs. When > first_ident is error_mark_node and a doesn't affect type identity, > we want to do nothing. So that is the && first_ident != error_mark_node > chunk. > > Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk > and release branches? OK. > 2021-10-05 Jakub Jelinek > > PR c++/102548 > * tree.c (apply_identity_attributes): Fix handling of the > case where an attribute in the list doesn't affect type > identity but some attribute before it does. > > * g++.target/i386/pr102548.C: New test. > > --- gcc/cp/tree.c.jj 2021-10-01 18:06:54.603452541 +0200 > +++ gcc/cp/tree.c 2021-10-04 19:52:28.767457791 +0200 > @@ -1499,9 +1499,9 @@ apply_identity_attributes (tree result, > p = &TREE_CHAIN (*p); > } > } > - else if (first_ident) > + else if (first_ident && first_ident != error_mark_node) > { > - for (tree a2 = first_ident; a2; a2 = TREE_CHAIN (a2)) > + for (tree a2 = first_ident; a2 != a; a2 = TREE_CHAIN (a2)) > { > *p = tree_cons (TREE_PURPOSE (a2), TREE_VALUE (a2), NULL_TREE); > p = &TREE_CHAIN (*p); > --- gcc/testsuite/g++.target/i386/pr102548.C.jj 2021-10-04 20:06:19.314810708 +0200 > +++ gcc/testsuite/g++.target/i386/pr102548.C 2021-10-04 20:05:14.808717194 +0200 > @@ -0,0 +1,12 @@ > +// PR c++/102548 > +// { dg-do compile { target { c++14 && ia32 } } } > + > +typedef decltype(sizeof(0)) size_t; > +struct tm; > +extern "C" size_t __attribute__((__cdecl__)) strftime (char *, size_t, const char *, const struct tm *); > + > +auto > +foo (void) > +{ > + return strftime; > +} > > Jakub >