[all-commits] [llvm/llvm-project] d5a612: [CIR] Fix cleanup of temporaries with null-checked...

Andy Kaylor via All-commits all-commits at lists.llvm.org
Mon Aug 3 11:56:20 PDT 2026


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: d5a6124259b55789bc49489632efa7c168a4f6cb
      https://github.com/llvm/llvm-project/commit/d5a6124259b55789bc49489632efa7c168a4f6cb
  Author: Andy Kaylor <akaylor at nvidia.com>
  Date:   2026-08-03 (Mon, 03 Aug 2026)

  Changed paths:
    M clang/lib/CIR/CodeGen/CIRGenCleanup.cpp
    M clang/lib/CIR/CodeGen/CIRGenExprCXX.cpp
    M clang/test/CIR/CodeGen/new-null.cpp

  Log Message:
  -----------
  [CIR] Fix cleanup of temporaries with null-checked new expr (#213376)

We had a problem where a new expression that required both a null check
of the allocated pointer and a cleanup of temporaries values created for
the initializer was causing us to generate an unterminated cleanup
scope. This was happening because we weren't pre-creating a cleanup
scope around the entire expression for the temporary and ended up
emitting it in an unexpected location.

This change adds a check for the null-checked new expression in
`ConditionalEvaluationFinder` and wraps the call to emit the initializer
with `ConditionEvalulation::begin/endEvaluation` calls.

Note that I have sunk the `begin/endEvaluation` into the `emitInit`
lambda so that it can surround just the `emitNewInitializer` call and
not the `enterNewDeleteCleanup` call, which creates a local cleanup
scope for the case where the allocation succeeded but the constructor
throws an exception. Classic codegen calls `begin/endEvaluation` at a
higher level and ends up using an active flag for the allocation delete
cleanup even though the flag is always true when that cleanup is
reached.

Assisted-by: Cursor / various models



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