llvm / llvm/llvm-project

[clang] C++20 aggregate init triggers assertion/crash when generating LLVM IR

Open
#215,501 3 comments 0 reactions 0 assignees View on GitHub
clang:codegen crash-on-valid
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

C++20 aggregate initialization with braced-init-lists for arrays passed to functions taking unknown-bound array references causes LLVM IR generation to crash (assertion: "type mismatch in call argument!"). This is a Clang frontend IR codegen bug that is not target-specific. It affects all target triples, including Windows MSVC.

According to [Clang - C++ Programming Language Status](https://clang.llvm.org/cxx_status.html), [Proposal: conversions to arrays of unknown bound](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p0388r4.html) is supported since Clang 14.

Here is a [Compiler Explorer](https://godbolt.org/z/3s5zPbbEK) to reproduce this on the following code.

```
void unknownBoundArrayRef(int const (&arr)[]) { int x = arr[0]; }

void testArrayOfUnknownBoundCpp20() { unknownBoundArrayRef({1, 2, 3}); }
```

Contributor guide

Open the contributing guide

Research direction

Start with the Compiler Explorer reproducer and the shown C++20 code, confirming the assertion during LLVM IR generation across target triples. Trace the Clang frontend IR codegen path for aggregate initialization passed to an unknown-bound array reference; done means the reproducer no longer crashes and generated IR is valid, with a regression test covering it.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
50/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.