PR47805: Use a single object for a function parameter in the caller and
authorRichard Smith <richard@metafoo.co.uk>
Tue, 13 Oct 2020 17:03:02 +0000 (10:03 -0700)
committerRichard Smith <richard@metafoo.co.uk>
Wed, 14 Oct 2020 01:50:46 +0000 (18:50 -0700)
commit8f8b9f2cca0b73314342c721186ae9c860ca273c
tree96b46d0b2ffb5ed5cfc4c40e554cc702d2160d99
parent498c7fa48a02a5e0c12bbb90ef8c0d8468affcdd
PR47805: Use a single object for a function parameter in the caller and
callee in constant evaluation.

We previously made a deep copy of function parameters of class type when
passing them, resulting in the destructor for the parameter applying to
the original argument value, ignoring any modifications made in the
function body. This also meant that the 'this' pointer of the function
parameter could be observed changing between the caller and the callee.

This change completely reimplements how we model function parameters
during constant evaluation. We now model them roughly as if they were
variables living in the caller, albeit with an artificially reduced
scope that covers only the duration of the function call, instead of
modeling them as temporaries in the caller that we partially "reparent"
into the callee at the point of the call. This brings some minor
diagnostic improvements, as well as significantly reduced stack usage
during constant evaluation.
30 files changed:
clang/lib/AST/ExprConstant.cpp
clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p6.cpp
clang/test/CXX/except/except.spec/p1.cpp
clang/test/CXX/expr/expr.const/p2-0x.cpp
clang/test/OpenMP/critical_messages.cpp
clang/test/OpenMP/distribute_parallel_for_simd_safelen_messages.cpp
clang/test/OpenMP/distribute_simd_safelen_messages.cpp
clang/test/OpenMP/distribute_simd_simdlen_messages.cpp
clang/test/OpenMP/target_teams_distribute_parallel_for_simd_safelen_messages.cpp
clang/test/OpenMP/target_teams_distribute_parallel_for_simd_simdlen_messages.cpp
clang/test/OpenMP/target_teams_distribute_simd_safelen_messages.cpp
clang/test/OpenMP/target_teams_distribute_simd_simdlen_messages.cpp
clang/test/OpenMP/teams_distribute_parallel_for_simd_safelen_messages.cpp
clang/test/OpenMP/teams_distribute_parallel_for_simd_simdlen_messages.cpp
clang/test/OpenMP/teams_distribute_simd_safelen_messages.cpp
clang/test/OpenMP/teams_distribute_simd_simdlen_messages.cpp
clang/test/Sema/builtin-expect-with-probability-avr.cpp
clang/test/Sema/builtin-expect-with-probability.cpp
clang/test/Sema/c89.c
clang/test/SemaCUDA/constexpr-variables.cu
clang/test/SemaCXX/c99-variable-length-array-cxx11.cpp
clang/test/SemaCXX/c99-variable-length-array.cpp
clang/test/SemaCXX/constant-expression-cxx11.cpp
clang/test/SemaCXX/constant-expression-cxx2a.cpp
clang/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp
clang/test/SemaCXX/cxx2a-consteval.cpp
clang/test/SemaCXX/integer-overflow.cpp
clang/test/SemaCXX/vla-construct.cpp
clang/test/SemaCXX/warn-vla.cpp
clang/test/SemaTemplate/typo-dependent-name.cpp