[clang] [CIR] Implement support for delete after new in a conditional branch (PR #192544)

Andy Kaylor via cfe-commits cfe-commits at lists.llvm.org
Fri Apr 17 11:50:50 PDT 2026


================
@@ -25,6 +25,18 @@ namespace clang::CIRGen {
 
 class CIRGenFunction;
 
+template <class T> struct InvariantValue {
+  using type = T;
+  using saved_type = T;
----------------
andykaylor wrote:

This class, as well as `DominatingValue` and `DominatingCIRValue` are basically copy and paste from classic codegen, and I have to admit that I only have a rough understanding of how they work. As I understand it this is a trivial fallback implementation that intentionally does nothing. It basically is establishing a pattern for what the derived classes do. As far as I can tell there is no real reason for `type` and `saved_type` to be different here other than that they will be different in some derived classes and having them different here (arguably) promotes readability.

I don't think this PR actually reaches any of these fallback implementations, but they will be needed later.

The basic idea is that we have some value at one point in the CIR and we need to reference it at some later point in the IR. The `InvariantValue` class is saying that it doesn't change and so nothing needs to be done to make it available at the later point. But for `DominatingValue` we may need to save it to a temporary location and reload it, which is what `save` and `restore` will do there.

The classic codegen implementation of `pushFullExprCleanup` uses the `DominatingValue` class to "save" all of the packed arguments, so it ends up getting used for things like `QualType` that fall back on the `InvariantValue` implementation. I'm not sure we're going to need that for CIR, so maybe I should strip in down a bit more for now?

https://github.com/llvm/llvm-project/pull/192544


More information about the cfe-commits mailing list