[all-commits] [llvm/llvm-project] 76d164: [CIR] Fix the order of temporary object cleanup (#...

Andy Kaylor via All-commits all-commits at lists.llvm.org
Wed Sep 23 16:33:05 PDT 2026


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 76d164c48a5076c160285765df23749b9bab1ebc
      https://github.com/llvm/llvm-project/commit/76d164c48a5076c160285765df23749b9bab1ebc
  Author: Andy Kaylor <akaylor at nvidia.com>
  Date:   2026-09-23 (Wed, 23 Sep 2026)

  Changed paths:
    M clang/lib/CIR/CodeGen/CIRGenCleanup.cpp
    M clang/lib/CIR/CodeGen/CIRGenExpr.cpp
    M clang/lib/CIR/CodeGen/CIRGenExprAggregate.cpp
    M clang/lib/CIR/CodeGen/CIRGenExprCXX.cpp
    M clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp
    M clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
    M clang/lib/CIR/CodeGen/CIRGenFunction.h
    M clang/test/CIR/CodeGen/cleanup-conditional-eh.cpp
    M clang/test/CIR/CodeGen/cleanup-conditional-with-wrapper-eh.cpp
    M clang/test/CIR/CodeGen/cleanup-conditional-with-wrapper.cpp
    M clang/test/CIR/CodeGen/cleanup-conditional.cpp
    M clang/test/CIR/CodeGen/dtors.cpp
    M clang/test/CIR/CodeGen/new-null.cpp

  Log Message:
  -----------
  [CIR] Fix the order of temporary object cleanup (#225560)

We had a problem in CIR where we were performing cleanups in the wrong
order when conditional and unconditional cleanups were needed for
temporary objects created in a single expression. The unconditional
cleanups were being emitted as they occur, while the conditional
cleanups were deferred until the entire expression had been emitted. The
result was that conditional cleanups were performed after unconditional
cleanups, even if the unconditionally destroyed object was created
first.

This change fixes that problem by reorganizing the way conditional
cleanups are handled. A cir.cleanup.scope operation is now created
eagerly where a conditional begins rather than at the start of the full
expression, so that it nests inside the cleanup scopes of temporaries
created before the conditional and outside those created after it. Scope
nesting determines the order in which the cleanup regions run, so this
yields reverse-of-construction order. A ConditionalCleanupScope object
tracks the scope and the conditional cleanups waiting to be emitted into
it. If the eagerly created cleanup scope operation ends up not having
been needed, the canonicalization pass will remove it.

Assisted-by: Cursor / claude-opus-5



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