llvm / llvm/llvm-project

[CIR] Upstream missing support for complex expressions

Open
#192,331 0 comments 1 reaction 1 assignee Claimed by @AmrDeveloper 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 fallback / pass-through paths in
complex expression emission that are not yet handled in the upstream:
- **ConstantExpr fallthrough**: when `tryEmitConstantExpr` fails for a
`ConstantExpr` with complex type, falling through to
`Visit(e->getSubExpr())` for runtime evaluation
- **UnaryCoawait pass-through**: returning `Visit(e->getSubExpr())` for the
unary `co_await` operator on complex values (correct transparent behavior)
- **VLA binding in explicit cast**: calling
`CGM.emitExplicitCastExprType(ece, &cgf)` unconditionally for explicit casts
on complex values, which internally handles VLA size binding

Upstream NYI locations:
- `CIRGenExprComplex.cpp` — `VisitConstantExpr`: non-constant-foldable
`ConstantExpr` with complex type
- `CIRGenExprComplex.cpp` — `VisitUnaryCoawait`: unary `co_await` on complex
values
- `CIRGenExprComplex.cpp` — `VisitCastExpr`: binding VLAs in explicit cast type
for complex values

### Suggested minimal test case

```cpp
_Complex float test_complex_constant() {
return (_Complex float){1.0f, 2.0f};
}

// VLA cast on complex
void test_complex_vla_cast(int n) {
typedef _Complex float CVT[n];
_Complex float arr[n];
(void)(CVT *)&arr;
}
```

### Existing incubator tests

- `clang/test/CIR/CodeGen/complex.cpp`
- `clang/test/CIR/CodeGen/complex-cast.cpp`
- `clang/test/CIR/CodeGen/complex-cast.c`
- `clang/test/CIR/CodeGen/complex-arithmetic.c`

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.