llvm / llvm/llvm-project

[CIR] Upstream missing support for aggregate initialization and destruction

Open
#192,329 4 comments 0 reactions 1 assignee Claimed by @andykaylor View on GitHub
ClangIR
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

### Overview

Upstream code from the incubator project to replace errorNYI calls in the
CIR codegen implementation related to aggregate initialization and
destruction cleanup handling:
- **Return value with destruction**: allocating a temporary via `CreateMemTemp`,
passing it via `ReturnValueSlot`, and copying the result to the destination
via `emitFinalDestCopy` when the return value requires non-trivial C struct
destruction
- **Deferred deactivation cleanup for base classes**: calling
`pushDestroyAndDeferDeactivation()` for each base class with a destructed type
during `visitCXXParenListOrInitListExpr`
- **Designated initializer update constants**: implementing
`EmitDesignatedInitUpdater` for both record types (via
`ConstRecordBuilder::UpdateRecord`) and array types, handling element
iteration, fillers, and nested `InitListExpr` nodes

Upstream NYI locations:
- `CIRGenExprAggregate.cpp` — `withReturnValueSlot`: return value requiring
destruction
- `CIRGenExprAggregate.cpp` — `visitCXXParenListOrInitListExpr`: push deferred
deactivation cleanup for base classes
- `CIRGenExprConstant.cpp` — `ConstRecordBuilder`: designated init lists

### Suggested minimal test case

```cpp
struct Inner {
int x;
~Inner() {}
};

struct Outer {
Inner a;
Inner b;
int c;
};

Outer test_aggregate_init() {
return Outer{{1}, {2}, 3};
}

// Designated init update
struct S { int a, b, c; };
S global = (S){.a = 1, .b = 2};
S updated = (S){global, .c = 3};
```

### Existing incubator tests

- `clang/test/CIR/CodeGen/agg-init.cpp`
- `clang/test/CIR/CodeGen/agg-init2.cpp`
- `clang/test/CIR/CodeGen/array-init-destroy.cpp`

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.