[all-commits] [llvm/llvm-project] 0d98eb: [CIR] Fix ordering of lifetime-extended cleanups (...

Andy Kaylor via All-commits all-commits at lists.llvm.org
Mon Jun 1 11:39:46 PDT 2026


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 0d98eb6e872811bdfd0545e46bdfd4251b493e2d
      https://github.com/llvm/llvm-project/commit/0d98eb6e872811bdfd0545e46bdfd4251b493e2d
  Author: Andy Kaylor <akaylor at nvidia.com>
  Date:   2026-06-01 (Mon, 01 Jun 2026)

  Changed paths:
    M clang/lib/CIR/CodeGen/CIRGenCleanup.cpp
    M clang/lib/CIR/CodeGen/CIRGenFunction.h
    M clang/test/CIR/CodeGen/cleanup-conditional.cpp
    M clang/test/CIR/CodeGen/loop-cond-cleanup.cpp

  Log Message:
  -----------
  [CIR] Fix ordering of lifetime-extended cleanups (#200874)

We had a bug that was causing any lifetime-extended cleanups that
occurred within a full-expression cleanup scope to be emitted
prematurely when the expression also required deferred conditional
cleanups. This was, in some cases, causing a dangling reference to
temporaries that had already been destructed. Luckily, it was also
causing us to not emit a return at the end of the function in one case,
leading the verifier to draw attention to this problem.

This change introduces new functions in RunCleanupsScope to allow
"ordinary" EH stack cleanups to be force-emitted separately from
lifetime-extended cleanups. Classic codegen doesn't need this capability
because it handles deferred conditional cleanups very differently than
CIR due to its flat/branching approach.

The testing for this fix did uncover a significant issue wherein CIR is
calling destructors in the wrong order even after the fix in this PR.
However, that's a pre-existing issue that will require changes beyond
the scope of this fix, so I'll handle it in a follow-up.

Assisted-by: Cursor / claude-opus-4.7



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