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: 55625 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 DC9B7385B506 for ; Tue, 28 Mar 2023 11:33:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DC9B7385B506 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1680003222; 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=ddQ3nrw3SM4G+pvHShB7WGkeMwiQxz1DgjmOZQ+n7lnnzd7Pcr55agyWIrPuqC1b3 F89GJtW5jA6lQp1/lUbWnDcpMbbQhL4ILPpvcZ+9L+K7itErDOoCHjw+Y/qE5q86m5 gYwqCCDciSFcXBzwoDb/Agxj88d0t8cppTwdR8/o= 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-Google-Smtp-Source: AKy350YwFFJ8Tnc7NRq2Ign8AZ9s9shWWZvk066eCAlaJQ8osWJLSPyP3Zh/pF6bXA/ANB9rIU3YaQ== 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+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" 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