[v5,0/3] c++: Track lifetimes in constant evaluation [PR70331, ...]

Message ID ZLvx7bNUL0KLo+Iq@Thaum.localdomain
Headers
Series c++: Track lifetimes in constant evaluation [PR70331, ...] |

Message

Nathaniel Shead July 22, 2023, 3:12 p.m. UTC
  This is an update of the patch series at
https://gcc.gnu.org/pipermail/gcc-patches/2023-July/625050.html

Changes since v4:

- Reordered patches to be more independent from each other (they don't need 
  to keep updating the new tests)
- Removed workaround for better locations in cxx_eval_store_expression
- Don't bother checking lifetime for CONST_DECLs
- Rewrite patch for dangling pointers to keep the transformation to
  `return (&x, nullptr)`, but only perform it when genericising. It turns out
  that implementing this wasn't as hard as I thought it might be, at least for
  this specific case.

Thanks very much for all the reviews and comments so far!

Bootstrapped and regtested on x86_64-pc-linux-gnu.

Nathaniel Shead (3):
  c++: Improve location information in constant evaluation
  c++: Prevent dangling pointers from becoming nullptr in constexpr
    [PR110619]
  c++: Track lifetimes in constant evaluation [PR70331,PR96630,PR98675]

 gcc/cp/constexpr.cc                           | 159 +++++++++++++-----
 gcc/cp/cp-gimplify.cc                         |  23 ++-
 gcc/cp/cp-tree.h                              |   8 +-
 gcc/cp/semantics.cc                           |   4 +-
 gcc/cp/typeck.cc                              |   9 +-
 gcc/testsuite/g++.dg/cpp0x/constexpr-48089.C  |  10 +-
 gcc/testsuite/g++.dg/cpp0x/constexpr-70323.C  |   8 +-
 gcc/testsuite/g++.dg/cpp0x/constexpr-70323a.C |   8 +-
 .../g++.dg/cpp0x/constexpr-delete2.C          |   5 +-
 gcc/testsuite/g++.dg/cpp0x/constexpr-diag3.C  |   2 +-
 gcc/testsuite/g++.dg/cpp0x/constexpr-ice20.C  |   1 +
 .../g++.dg/cpp0x/constexpr-recursion.C        |   6 +-
 gcc/testsuite/g++.dg/cpp0x/overflow1.C        |   2 +-
 gcc/testsuite/g++.dg/cpp1y/constexpr-110619.C |  10 ++
 gcc/testsuite/g++.dg/cpp1y/constexpr-89285.C  |   5 +-
 gcc/testsuite/g++.dg/cpp1y/constexpr-89481.C  |   3 +-
 .../g++.dg/cpp1y/constexpr-lifetime1.C        |  13 ++
 .../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 ++
 .../g++.dg/cpp1y/constexpr-lifetime6.C        |  15 ++
 .../g++.dg/cpp1y/constexpr-tracking-const14.C |   3 +-
 .../g++.dg/cpp1y/constexpr-tracking-const16.C |   3 +-
 .../g++.dg/cpp1y/constexpr-tracking-const18.C |   4 +-
 .../g++.dg/cpp1y/constexpr-tracking-const19.C |   4 +-
 .../g++.dg/cpp1y/constexpr-tracking-const21.C |   4 +-
 .../g++.dg/cpp1y/constexpr-tracking-const22.C |   4 +-
 .../g++.dg/cpp1y/constexpr-tracking-const3.C  |   3 +-
 .../g++.dg/cpp1y/constexpr-tracking-const4.C  |   3 +-
 .../g++.dg/cpp1y/constexpr-tracking-const7.C  |   3 +-
 gcc/testsuite/g++.dg/cpp1y/constexpr-union5.C |   4 +-
 gcc/testsuite/g++.dg/cpp1y/pr68180.C          |   4 +-
 .../g++.dg/cpp1z/constexpr-lambda6.C          |   4 +-
 .../g++.dg/cpp1z/constexpr-lambda8.C          |   5 +-
 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/cpp2a/constinit10.C      |   5 +-
 .../g++.dg/cpp2a/is-corresponding-member4.C   |   4 +-
 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          |  23 +--
 .../25_algorithms/equal/constexpr_neg.cc      |   7 +-
 .../testsuite/26_numerics/gcd/105844.cc       |  10 +-
 .../testsuite/26_numerics/lcm/105844.cc       |  14 +-
 51 files changed, 361 insertions(+), 168 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/cpp1y/constexpr-110619.C
 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
 create mode 100644 gcc/testsuite/g++.dg/cpp1y/constexpr-lifetime6.C
  

Comments

Jason Merrill July 26, 2023, 1:53 a.m. UTC | #1
On 7/22/23 11:12, Nathaniel Shead wrote:
> This is an update of the patch series at
> https://gcc.gnu.org/pipermail/gcc-patches/2023-July/625050.html

I applied the patches, with an addition to the first patch to fix 
constexpr-mutable3.C in C++11 mode, which was not part of the default 
std set.  And fixed the testsuite to run that test (and others that test 
c++11_only behavior) in C++11 mode.  Thanks!

FWIW, I test C++ patches with GXX_TESTSUITE_STDS=98,11,14,17,20,impcx 
for more coverage.

> Changes since v4:
> 
> - Reordered patches to be more independent from each other (they don't need
>    to keep updating the new tests)
> - Removed workaround for better locations in cxx_eval_store_expression
> - Don't bother checking lifetime for CONST_DECLs
> - Rewrite patch for dangling pointers to keep the transformation to
>    `return (&x, nullptr)`, but only perform it when genericising. It turns out
>    that implementing this wasn't as hard as I thought it might be, at least for
>    this specific case.
> 
> Thanks very much for all the reviews and comments so far!
> 
> Bootstrapped and regtested on x86_64-pc-linux-gnu.
> 
> Nathaniel Shead (3):
>    c++: Improve location information in constant evaluation
>    c++: Prevent dangling pointers from becoming nullptr in constexpr
>      [PR110619]
>    c++: Track lifetimes in constant evaluation [PR70331,PR96630,PR98675]
> 
>   gcc/cp/constexpr.cc                           | 159 +++++++++++++-----
>   gcc/cp/cp-gimplify.cc                         |  23 ++-
>   gcc/cp/cp-tree.h                              |   8 +-
>   gcc/cp/semantics.cc                           |   4 +-
>   gcc/cp/typeck.cc                              |   9 +-
>   gcc/testsuite/g++.dg/cpp0x/constexpr-48089.C  |  10 +-
>   gcc/testsuite/g++.dg/cpp0x/constexpr-70323.C  |   8 +-
>   gcc/testsuite/g++.dg/cpp0x/constexpr-70323a.C |   8 +-
>   .../g++.dg/cpp0x/constexpr-delete2.C          |   5 +-
>   gcc/testsuite/g++.dg/cpp0x/constexpr-diag3.C  |   2 +-
>   gcc/testsuite/g++.dg/cpp0x/constexpr-ice20.C  |   1 +
>   .../g++.dg/cpp0x/constexpr-recursion.C        |   6 +-
>   gcc/testsuite/g++.dg/cpp0x/overflow1.C        |   2 +-
>   gcc/testsuite/g++.dg/cpp1y/constexpr-110619.C |  10 ++
>   gcc/testsuite/g++.dg/cpp1y/constexpr-89285.C  |   5 +-
>   gcc/testsuite/g++.dg/cpp1y/constexpr-89481.C  |   3 +-
>   .../g++.dg/cpp1y/constexpr-lifetime1.C        |  13 ++
>   .../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 ++
>   .../g++.dg/cpp1y/constexpr-lifetime6.C        |  15 ++
>   .../g++.dg/cpp1y/constexpr-tracking-const14.C |   3 +-
>   .../g++.dg/cpp1y/constexpr-tracking-const16.C |   3 +-
>   .../g++.dg/cpp1y/constexpr-tracking-const18.C |   4 +-
>   .../g++.dg/cpp1y/constexpr-tracking-const19.C |   4 +-
>   .../g++.dg/cpp1y/constexpr-tracking-const21.C |   4 +-
>   .../g++.dg/cpp1y/constexpr-tracking-const22.C |   4 +-
>   .../g++.dg/cpp1y/constexpr-tracking-const3.C  |   3 +-
>   .../g++.dg/cpp1y/constexpr-tracking-const4.C  |   3 +-
>   .../g++.dg/cpp1y/constexpr-tracking-const7.C  |   3 +-
>   gcc/testsuite/g++.dg/cpp1y/constexpr-union5.C |   4 +-
>   gcc/testsuite/g++.dg/cpp1y/pr68180.C          |   4 +-
>   .../g++.dg/cpp1z/constexpr-lambda6.C          |   4 +-
>   .../g++.dg/cpp1z/constexpr-lambda8.C          |   5 +-
>   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/cpp2a/constinit10.C      |   5 +-
>   .../g++.dg/cpp2a/is-corresponding-member4.C   |   4 +-
>   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          |  23 +--
>   .../25_algorithms/equal/constexpr_neg.cc      |   7 +-
>   .../testsuite/26_numerics/gcd/105844.cc       |  10 +-
>   .../testsuite/26_numerics/lcm/105844.cc       |  14 +-
>   51 files changed, 361 insertions(+), 168 deletions(-)
>   create mode 100644 gcc/testsuite/g++.dg/cpp1y/constexpr-110619.C
>   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
>   create mode 100644 gcc/testsuite/g++.dg/cpp1y/constexpr-lifetime6.C
>