From patchwork Wed May 1 04:30:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathaniel Shead X-Patchwork-Id: 89218 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BF0873858414 for ; Wed, 1 May 2024 04:31:28 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pg1-x52b.google.com (mail-pg1-x52b.google.com [IPv6:2607:f8b0:4864:20::52b]) by sourceware.org (Postfix) with ESMTPS id 4276F3858D20 for ; Wed, 1 May 2024 04:30:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4276F3858D20 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 4276F3858D20 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::52b ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714537861; cv=none; b=ht9APM1dz1eLFmncjAJdL9JL6U8d2xs2gEiYQ6zRlaMpzg0EPlUO+vSP+BzRTamnHwH78w1HeWosnSPNc/yCHI11pq2H2EAmJTZTGEryhavQOwTgRpG64SpJ/vwwHrRSh7aZ9E6cIPkr0mWdSclegRD3JNfe8PtWu6ouk5lQuRk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714537861; c=relaxed/simple; bh=gTWSgxdPXGrbjGmRT/veFYV6q1Y6lujAEG0X3iTe/vU=; h=DKIM-Signature:Message-ID:Date:From:To:Subject:MIME-Version; b=azralvouLUV8bqICePcE28fS3itCzaV4sIx+aK6NPyEONOxtnXFIBJ1qhudYXaD/ghfgi2uq2UDMz6p+skUoiWpCzWgDk+MfGVcuHTsts83++NXvdoVGLJV09j7mTvOv3LrDTaF+VQE47ehATecEoHGHx3ULHeIUsrMHkFKrMHs= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pg1-x52b.google.com with SMTP id 41be03b00d2f7-5c6bd3100fcso4387429a12.3 for ; Tue, 30 Apr 2024 21:30:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714537858; x=1715142658; darn=gcc.gnu.org; h=content-disposition:mime-version:subject:cc:to:from:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=9LqtKqArGraqkbS0r/IwxJ27PZOeKxHPJ7bDcySjvmk=; b=gEBoP4ac/5su8OcY6Hw2MuY+zNbG2cNaZQgtvdJ+Ly0ReT1qkEML2U5shUPktC8cHf kaBIzJ4Q49b5xytt0URkImw/uqvbkzFizpFwxMlBCV2t4VSNWvv64Gtoe/GwOx/ah7WJ pBhBp6nSgfUzm88Flpzv73wSREZ3ONprjHJXwahBzZTnEvE12ThLWvm+KvDRGyXiM2LB 8AYU+rbhraoFpXIuE4liiIdufc5bpshXc7hag6f51yNc34iiscrHyiH6pyCoURRor12Q 2RoffLNugwsXwXRL66Aoq8eaP5d/Mnsf9t8vdGOfTnYt+1/BNQEPtCo+5NNmJKJMb87l hhlg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714537858; x=1715142658; h=content-disposition:mime-version:subject:cc:to:from:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=9LqtKqArGraqkbS0r/IwxJ27PZOeKxHPJ7bDcySjvmk=; b=gdRaP2QJrqRrDHHxNSXHrmrvWSePl1FsOse1WqUXDdsZNXS7DzToIghD+Ae8rAgODZ k0TE1ahLkCSos8TrHw57FRSxMTZ2E9TYmMvkA/P/PVpeO98j40xHrY3mS4mGIk76VXJf tpyZehIzI/K3UwkuQtQCN+PP7vvA6P/krDVksw1msAmUwWZHzf8btdFmWB1MRauvkYQo 8wATiaVP7qkY+XxGQfaX3PvGD6C/O9+NSuYe4lol0lo6qEMLt/UQinqLEZPtaUOL2xts i2wal830h3UgF9eHlvSnlfG/XImh3DJ8I6pfiGrZFJqWLv18ozZ4Obqe03f+S/9Itlcj ffzg== X-Gm-Message-State: AOJu0Yxyp/Mjmt1U1YrEtbl07ZRwIIftNOIl2E7dmjgOpy74m9J24Y/r Xc0BoGAdDy0HeGhbPZaP6V7Bll2GLxZgwP/XK4HcnNvvy/W/c/k/Ca+c3g== X-Google-Smtp-Source: AGHT+IEpgV+tiNVFqsj7FRSdZXx3SAXr6fUysu4UgPtYWXHvxvOLQjJpzJOCPIYfOCw7euC+Y/axfg== X-Received: by 2002:a05:6a21:1f1e:b0:1ad:9150:631f with SMTP id ry30-20020a056a211f1e00b001ad9150631fmr1182415pzb.36.1714537858067; Tue, 30 Apr 2024 21:30:58 -0700 (PDT) Received: from Thaum. (121-44-11-123.tpgi.com.au. [121.44.11.123]) by smtp.gmail.com with ESMTPSA id pm11-20020a17090b3c4b00b002b27c52dfaesm466646pjb.35.2024.04.30.21.30.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Apr 2024 21:30:57 -0700 (PDT) Message-ID: <6631c581.170a0220.3b821.1e9d@mx.google.com> X-Google-Original-Message-ID: Date: Wed, 1 May 2024 14:30:53 +1000 From: Nathaniel Shead To: gcc-patches@gcc.gnu.org Cc: Jason Merrill , Nathan Sidwell Subject: [PATCH] c++/modules: Fix dangling pointer with imported_temploid_friends MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-11.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, URIBL_BLACK autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Bootstrapped and regtested on x86_64-pc-linux-gnu, OK for trunk (and later 14.2)? I don't think making it a GTY root is necessary but I felt perhaps better to be safe than sorry. Potentially another approach would be to use DECL_UID instead like how entity_map does; would that be preferable? -- >8 -- I got notified by Linaro CI and by checking testresults that there seems to be some occasional failures in tpl-friend-4_b.C on some architectures and standards modes since r15-59-gb5f6a56940e708. I haven't been able to reproduce but looking at the backtrace I suspect the issue is that we're adding to the 'imported_temploid_friend' map a decl that is ultimately discarded, which then has its address reused by a later decl causing a failure in the assert in 'set_originating_module'. This patch attempts to fix the issue in two ways: by ensuring that we only store the decl if we know it's a new decl (and hence won't be discarded), and by making the imported_temploid_friends map a GTY root so that even if the decl does get discarded later the address isn't reused. gcc/cp/ChangeLog: * module.cc (imported_temploid_friends): Mark GTY, and... (init_modules): ...allocate from GGC. (trees_in::decl_value): Only write to imported_temploid_friends for new decls. Signed-off-by: Nathaniel Shead --- gcc/cp/module.cc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc index 5b8ff5bc483..37d38bb9654 100644 --- a/gcc/cp/module.cc +++ b/gcc/cp/module.cc @@ -2731,7 +2731,7 @@ static keyed_map_t *keyed_table; need to be attached to the same module as the temploid. This maps these decls to the temploid they are instantiated them, as there is no other easy way to get this information. */ -static hash_map *imported_temploid_friends; +static GTY(()) hash_map *imported_temploid_friends; /********************************************************************/ /* Tree streaming. The tree streaming is very specific to the tree @@ -8327,7 +8327,8 @@ trees_in::decl_value () if (TREE_CODE (inner) == FUNCTION_DECL || TREE_CODE (inner) == TYPE_DECL) if (tree owner = tree_node ()) - imported_temploid_friends->put (decl, owner); + if (is_new) + imported_temploid_friends->put (decl, owner); /* Regular typedefs will have a NULL TREE_TYPE at this point. */ unsigned tdef_flags = 0; @@ -20523,7 +20524,7 @@ init_modules (cpp_reader *reader) entity_map = new entity_map_t (EXPERIMENT (1, 400)); vec_safe_reserve (entity_ary, EXPERIMENT (1, 400)); imported_temploid_friends - = new hash_map (EXPERIMENT (1, 400)); + = hash_map::create_ggc (EXPERIMENT (1, 400)); } #if CHECKING_P