[all-commits] [llvm/llvm-project] d65c56: [clang] Use uniform lifetime bounds under exceptions

Paul Kirth via All-commits all-commits at lists.llvm.org
Thu Apr 2 18:09:46 PDT 2026


  Branch: refs/heads/users/ilovepi/clang-lifetime-exceptions
  Home:   https://github.com/llvm/llvm-project
  Commit: d65c56bf1a2030e7359eb0e0a02b5612495b53ad
      https://github.com/llvm/llvm-project/commit/d65c56bf1a2030e7359eb0e0a02b5612495b53ad
  Author: Paul Kirth <paulkirth at google.com>
  Date:   2026-04-02 (Thu, 02 Apr 2026)

  Changed paths:
    M clang/lib/CodeGen/CGCall.cpp
    M clang/lib/Sema/SemaExprCXX.cpp
    M clang/test/CodeGenCXX/aggregate-lifetime-invoke.cpp

  Log Message:
  -----------
  [clang] Use uniform lifetime bounds under exceptions

To do this we have to slightly modify how some expressions are handled
in Sema. Principally, we need to ensure that calls to new for
non-trivial types still have their destructors run. Generally this isn't
an issue, since these just get sunk into the surrounding scope. With
more lifetime annotations being produced for the expressions, we found
that some calls to `new` in an unreachable switch arm would not be
wrapped in ExprWithCleanups. As a result, they remain on the EhStack
when processing the default label, and since the dead arm doesn't
dominate the default label, we can end up with a case where the def-use
chain is broken (e.g. the def doesn't dominate all uses). Technically
this path would be impossible to reach due to the active bit, but it
still failed to satisfy a dominance relationship.

With that in place, we can remove the constraint on only using tighter
lifetimes when exceptions are disabled.


  Commit: a8d3a1ae5f7d3b6ac0b7ecd9286f569ec714244e
      https://github.com/llvm/llvm-project/commit/a8d3a1ae5f7d3b6ac0b7ecd9286f569ec714244e
  Author: Paul Kirth <paulkirth at google.com>
  Date:   2026-04-02 (Thu, 02 Apr 2026)

  Changed paths:
    M clang/lib/AST/ExprConstant.cpp
    M clang/lib/Sema/SemaExprCXX.cpp

  Log Message:
  -----------
  Use setExprNeedsCleanups in BuildCXXNew and avoid breaking c++98

This approach is much cleaner, but broke checkICE reporting in c++98.
Stepping through a debugger shows that this happend because the
static_assert test didn not recognize ExprWithCleanups as transparent to
constant evaluation. To addresse this, we update CheckICE to recurse
into the sub-expression, and keep the old behavior.


  Commit: 0dad12d255a215f8b1ad605b1479377ab0d78b19
      https://github.com/llvm/llvm-project/commit/0dad12d255a215f8b1ad605b1479377ab0d78b19
  Author: Paul Kirth <paulkirth at google.com>
  Date:   2026-04-02 (Thu, 02 Apr 2026)

  Changed paths:
    M clang/lib/AST/ExprConstant.cpp

  Log Message:
  -----------
  Use more restrictive condition for adding ExprWithCleanups


Compare: https://github.com/llvm/llvm-project/compare/decdf1c4375b...0dad12d255a2

To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list