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 A1A383835838 for ; Wed, 16 Jun 2021 15:06:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A1A383835838 Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-86-nE-q1remPYSo9RnJChyKJA-1; Wed, 16 Jun 2021 11:06:46 -0400 X-MC-Unique: nE-q1remPYSo9RnJChyKJA-1 Received: by mail-qk1-f198.google.com with SMTP id 14-20020a37060e0000b02903aad32851d2so2015256qkg.1 for ; Wed, 16 Jun 2021 08:06:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:subject:from:to:date:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=4lBeUhGHhMkC1o7vSgGHueZJ6J2CriLVIY70svYZYjs=; b=b+Wwj2vobvTFDYyRXLps5QIagnlTtUCAefe6+eh3Jr0ZlLJ+k+eRfT7JhXnFtYuD+6 XYlGWR2nAioznADTMWc84T70WjxExDVS0Fcs8dImLIwq2akYq8NPoKnBz2VpqzEe4U3R qH52dXumaLAWOCO6IVe1uJswRG5fq1vUbZjYuVrg6P3G15/wQeJjnkjEEFvlmil0ccTq z1AoyYNVAxjt6IgCgnweOWUk+AnT0hG1ivvr96lJx8il/VKX1TEa500kIT5eDbdvLLoP XzJWghFJI2TkV4EE/5Ao39N6x+WCSVeSzQNd1j34Sf68/uzZSiTSKwdD9zkJRAXBJfLd vW9g== X-Gm-Message-State: AOAM533PC1S1Fqbpigk+AYrYG++xixwXxApsQpdZHknowzkrJf6YqZ8t knRa8uwNY93HHWaKQ/DO9y0Wrfb0abjvtONJVY6Y4XTR5j+K/4GcQ/Rdx4socFps7owEZSeSKSU GEMZacdWyA6oNJCjxzQ== X-Received: by 2002:a37:e4d:: with SMTP id 74mr528714qko.6.1623856004843; Wed, 16 Jun 2021 08:06:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxoo27fUl5XRgr4cI1iGYWc+OI43Qs8HzvCRML9urodd0rrGjByvDMbBXUgOsmWo1SdH143gw== X-Received: by 2002:a37:e4d:: with SMTP id 74mr528616qko.6.1623856003954; Wed, 16 Jun 2021 08:06:43 -0700 (PDT) Received: from t14s.localdomain (c-73-69-212-193.hsd1.ma.comcast.net. [73.69.212.193]) by smtp.gmail.com with ESMTPSA id p199sm1756124qka.128.2021.06.16.08.06.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Jun 2021 08:06:43 -0700 (PDT) Message-ID: Subject: Re: [PATCH] make rich_location safe to copy From: David Malcolm To: Martin Sebor , gcc-patches Date: Wed, 16 Jun 2021 11:06:41 -0400 In-Reply-To: <0eb421c1-4a84-e776-8be7-9887aab36e81@gmail.com> References: <88448f63-87ad-c3a5-d38b-c94dd825e8d2@gmail.com> <0b9651cb91da83738060095f6adecd7f02392e55.camel@redhat.com> <0eb421c1-4a84-e776-8be7-9887aab36e81@gmail.com> User-Agent: Evolution 3.38.4 (3.38.4-1.fc33) MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-5.9 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, 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: Wed, 16 Jun 2021 15:06:49 -0000 On Wed, 2021-06-16 at 08:52 -0600, Martin Sebor wrote: > On 6/16/21 6:38 AM, David Malcolm wrote: > > On Tue, 2021-06-15 at 19:48 -0600, Martin Sebor wrote: > > > > Thanks for writing the patch. > > > > > While debugging locations I noticed the semi_embedded_vec template > > > in line-map.h doesn't declare a copy ctor or copy assignment, but > > > is being copied in a couple of places in the C++ parser (via > > > gcc_rich_location).  It gets away with it most likely because it > > > never grows beyond the embedded buffer. > > > > Where are these places?  I wasn't aware of this. > > They're in the attached file along with the diff to reproduce > the errors. Thanks. Looks like: gcc_rich_location richloc = tok->location; is implicitly constructing a gcc_rich_location, then copying it to richloc. This should instead be simply: gcc_rich_location richloc (tok->location); which directly constructs the richloc in place, as I understand it. Dave > > I was seeing strange behavior in my tests that led me to rich_location > and the m_ranges member.  The problem turned out to be unrelated but > before I figured it out I noticed the missing copy ctor and deleted > it to see if it was being used.  Since that's such a pervasive bug > in GCC code (and likely elsewhere as well) I'm thinking I should take > the time to develop the warning I've been thinking about to detect it. > > > > > The attached patch defines the copy ctor and also copy assignment > > > and adds the corresponding move functions. > > > > Note that rich_location::m_fixit_hints "owns" the fixit_hint > > instances, > > manually deleting them in rich_location's dtor, so simply doing a > > shallow copy of it would be wrong. > > > > Also, a rich_location stores other pointers (to range_labels and > > diagnostic_path), which are borrowed pointers, where their lifetime > > is > > assumed to outlive any (non-dtor) calls to the rich_location.  So I'm > > nervous about code that copies rich_location instances. > > > > I think I'd prefer to forbid copying them; what's the use-case for > > copying them?  Am I missing something here? > > I noticed and fixed just the one problem I uncovered by accident with > the missing copy ctor.  If there are others I don't know about them. > Preventing code from copying rich_location might make sense > independently of fixing the vec class to be safely copyable. > > Martin > > > > > > > > > Tested on x86_64-linux. > > > > > > Martin > > > > Thanks > > Dave > > >