From patchwork Tue Mar 28 11:32:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathaniel Shead X-Patchwork-Id: 7329 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2143304vqo; Tue, 28 Mar 2023 04:34:11 -0700 (PDT) X-Google-Smtp-Source: AKy350YGR6pagcbI+jifCh3XYlPmSqkghwLHv0wHeXAxkm/5Z2Faf74EUfDS6fPmyWS7W9DIX2TP X-Received: by 2002:aa7:c993:0:b0:500:4e0c:2b09 with SMTP id c19-20020aa7c993000000b005004e0c2b09mr13990740edt.7.1680003251032; Tue, 28 Mar 2023 04:34:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680003251; cv=none; d=google.com; s=arc-20160816; b=jDvyOGxxeSie6CFwpGE9xUEk8UkXVNOvN6yPz+lFIqK3N/4bg/GNAXyFdoAf2LJIaJ yhkRIibM/KTlM98nw4Pj9msob0d3NkCRm9jpVN3TkbUXmXPtK3QURMGcaZ0qqEu7D+9i JQx3zaCjPMUm3v/GDOBR75R7RxGL0gXut6eoMIcHYd2JZEdbel0VnyzrE2x9IrhHidpd SkW4/rQL/55cyX6Onrou3JT1ef4y/UuT2aAjhguZO1a7QsP2h4haSnvPlW73GwWqdyAQ 1N0OxNpH8AHLdZ/Lsl1D0Nvunh4CGsukn4jqe+Ea+3ZchHvshgNfmf0xkCdATfL2lEYs Ab3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=WbFcelKywPE+NB6QlowOJJGOb1fNbxNlXpi2M/QRnn8=; b=qPu4RuuUOaqyFHGoH0FHyAwVRkhY6H0avbCV7hx82ttDgxtOJ/QIIw7A3TZPTFoF8Y QyEeudrKVzKChqsHRiCW1LqdcvJnYuTG4U5kfg4Ozhn95mDci9qb5siQ+Mq/z5wXuR9K yAaGL/ZwzWUQL9wnwvbMjxQluNoF0idQ+GERgLGHI6Ls2o/Lcq4ibJmGEgjXlEPmrf7O KGYqJseJya/Oysd/vdDAdxJKKsZcJyoTXEtX2s0h9MEbEIm3/NPBvzIOIuxPtEIv/kNp 2TIVushwltr3nzWTSJhZ1Yer46gRp7MHS0bo0AkTaBX8p+/tZYfDlv4ZXNv8KGHAyk0y XtgA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=lbylNgUr; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id ca17-20020aa7cd71000000b004fb7ccf3b48si29121267edb.535.2023.03.28.04.34.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Mar 2023 04:34:11 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=lbylNgUr; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6F9CD38582AB for ; Tue, 28 Mar 2023 11:33:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6F9CD38582AB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1680003238; bh=WbFcelKywPE+NB6QlowOJJGOb1fNbxNlXpi2M/QRnn8=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=lbylNgUrlL8zohxk1Kk+GaQiniNQxTq8cn25KTpp7f/bvktUPoM4N4piG+DbAKc5j lQl0J1A98LjGAPCvjW5/gyTOskV4idM8e33uwrXcU42wdmPhk/OM5/QHrlhFjdtK8u gFg555xOFr+d+UTxWiBVL4rug5BpvgONFoZngvbo= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pf1-x42a.google.com (mail-pf1-x42a.google.com [IPv6:2607:f8b0:4864:20::42a]) by sourceware.org (Postfix) with ESMTPS id 5D1B63858D39 for ; Tue, 28 Mar 2023 11:33:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5D1B63858D39 Received: by mail-pf1-x42a.google.com with SMTP id dw14so7758423pfb.6 for ; Tue, 28 Mar 2023 04:33:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680003184; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=WbFcelKywPE+NB6QlowOJJGOb1fNbxNlXpi2M/QRnn8=; b=g25WJ2ISIRAx0RTnuYSVsWSO6Vs0vE8cmYmMSUbbzGQXModcisNrOeyQWlImSb3z1/ 1bPC4ub6TzOgReTN/CFkky5DxmRIOcTHG0xHByVfShCg08gFH3IBFctsJOck0AaEzKvN kUpfhRqG6/QFu/qRV0nnKeVUMnMqVqaWIblCN+B0V8Pw3lTUiOfi64ja2lTLrr1/dVbB n5frfy65GCpatFyn7Htk1xRGMTt5l7qvsbjTmg3C8FetFKYR5oW1Dhvt3R2RluGZc/5x oT6YqHIAnbrAQw5r1fnfN7FQ1iRSNAfaEBo597nBB2XRCKofJqzO+f7UwuVG6ttte+PD 34BA== X-Gm-Message-State: AAQBX9eetjv+KauBQ/dKOYfnSiSD20yS8Lsg7X3W05xit9ffU9WE7VMn Khl1dZdATtVsd647rlYjKQtyHHo6MXA= X-Received: by 2002:aa7:9696:0:b0:5a8:bcf2:125 with SMTP id f22-20020aa79696000000b005a8bcf20125mr15016479pfk.21.1680003183894; Tue, 28 Mar 2023 04:33:03 -0700 (PDT) Received: from Thaum.localdomain (125-209-144-50.tpgi.com.au. [125.209.144.50]) by smtp.gmail.com with ESMTPSA id e17-20020a62ee11000000b0062ce765b7afsm6097512pfi.162.2023.03.28.04.33.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Mar 2023 04:33:03 -0700 (PDT) To: gcc-patches@gcc.gnu.org Cc: Nathaniel Shead Subject: [PATCH 0/3] Track lifetimes in constant evaluation [PR70331,...] Date: Tue, 28 Mar 2023 22:32:27 +1100 Message-Id: <20230328113230.19975-1-nathanieloshead@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-4.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP 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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Nathaniel Shead via Gcc-patches From: Nathaniel Shead Reply-To: Nathaniel Shead Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1761611088926286520?= X-GMAIL-MSGID: =?utf-8?q?1761611088926286520?= The first patch fixes PR70331, PR96630, and PR98675 regarding constexpr evaluation not correctly diagnosing uses of dangling references and pointers. The following two patches clean up and improve some of the errors that are generated by this change, but aren't strictly necessary. This is my first change to the frontend, so any feedback is welcome. In particular, I'm not sure if the way I went about the fix was correct: for simplicity and efficiency's sake I added a new flag to tree_decl_common, but this feels somewhat overkill for what is otherwise a very locally useful property. Another option here would be to add a new lookup table to constexpr_global_ctx which tracks what decls are in lifetime, but I expect that to negatively impact performance. I haven't done any benchmarks on this however. Bootstrapped and regression tested on x86_64 linux. --- Nathaniel Shead (3): c++: Track lifetimes in constant evaluation [PR70331,PR96630,PR98675] c++: Improve constexpr error for dangling local variables c++: Improve location information in constexpr evaluation gcc/cp/constexpr.cc | 149 ++++++++++++------ gcc/cp/module.cc | 2 + gcc/cp/semantics.cc | 5 +- gcc/cp/typeck.cc | 5 +- gcc/print-tree.cc | 4 + gcc/testsuite/g++.dg/cpp0x/constexpr-48089.C | 10 +- gcc/testsuite/g++.dg/cpp0x/constexpr-diag3.C | 2 +- gcc/testsuite/g++.dg/cpp0x/constexpr-ice20.C | 2 +- gcc/testsuite/g++.dg/cpp1y/constexpr-89481.C | 3 +- .../g++.dg/cpp1y/constexpr-lifetime1.C | 14 ++ .../g++.dg/cpp1y/constexpr-lifetime2.C | 20 +++ .../g++.dg/cpp1y/constexpr-lifetime3.C | 13 ++ .../g++.dg/cpp1y/constexpr-lifetime4.C | 11 ++ .../g++.dg/cpp1y/constexpr-lifetime5.C | 11 ++ gcc/testsuite/g++.dg/cpp1y/constexpr-union5.C | 4 +- gcc/testsuite/g++.dg/cpp1y/pr68180.C | 4 +- .../g++.dg/cpp1z/constexpr-lambda6.C | 4 +- gcc/testsuite/g++.dg/cpp2a/bit-cast11.C | 10 +- gcc/testsuite/g++.dg/cpp2a/bit-cast12.C | 10 +- gcc/testsuite/g++.dg/cpp2a/bit-cast14.C | 14 +- gcc/testsuite/g++.dg/cpp2a/constexpr-98122.C | 4 +- .../g++.dg/cpp2a/constexpr-dynamic17.C | 5 +- gcc/testsuite/g++.dg/cpp2a/constexpr-init1.C | 5 +- gcc/testsuite/g++.dg/cpp2a/constexpr-new12.C | 6 +- gcc/testsuite/g++.dg/cpp2a/constexpr-new3.C | 10 +- gcc/testsuite/g++.dg/ext/constexpr-vla2.C | 4 +- gcc/testsuite/g++.dg/ext/constexpr-vla3.C | 4 +- gcc/testsuite/g++.dg/ubsan/pr63956.C | 4 +- .../g++.dg/warn/Wreturn-local-addr-6.C | 3 - gcc/tree-core.h | 5 +- gcc/tree.h | 6 + .../25_algorithms/equal/constexpr_neg.cc | 7 +- 32 files changed, 247 insertions(+), 113 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp1y/constexpr-lifetime1.C create mode 100644 gcc/testsuite/g++.dg/cpp1y/constexpr-lifetime2.C create mode 100644 gcc/testsuite/g++.dg/cpp1y/constexpr-lifetime3.C create mode 100644 gcc/testsuite/g++.dg/cpp1y/constexpr-lifetime4.C create mode 100644 gcc/testsuite/g++.dg/cpp1y/constexpr-lifetime5.C