| Issue |
233301
|
| Summary |
[clang-format] UseBreakAfter crashes on a semicolon in an inactive initializer branch
|
| Labels |
clang-format
|
| Assignees |
|
| Reporter |
andremueiot
|
With `PackArguments.BinPack: UseBreakAfter`, clang-format crashes on a nested
braced initializer containing a semicolon in an inactive preprocessor branch.
## Version and platform
Windows, using:
```text
clang-format version 24.0.0git (https://github.com/llvm/llvm-project.git 4bd435d59f89ded8e537e5c6e0b560ad89518c3f)
```
## Reproducer
Save these two files in the same directory.
`repro.cpp`:
```cpp
// Copyright (c) Microsoft Corporation. All rights reserved.
int g_values[] =
{
{
#if 1
0
#else
;
#endif
}
};
```
`.clang-format`:
```yaml
PackArguments:
BinPack: UseBreakAfter
```
Run:
```text
clang-format --style=file repro.cpp
```
No headers, project dependencies, explicit `BreakAfter` value, or `-i` are needed.
## Expected result
The formatter should not crash. With `#if 1`, the active code is equivalent
to `int g_values[] = {{0}};`, which is valid C++. The semicolon occurs only
in the inactive `#else` branch.
## Actual result
clang-format terminates with an access violation:
```text
Exception Code: 0xC0000005
```
Full crash output is supplied separately as `crash.txt`.
## Additional observations
Each of the following independently prevents the crash:
- Change `PackArguments.BinPack` from `UseBreakAfter` to `BinPack`.
- Remove the semicolon in the inactive branch.
- Remove the inner pair of initializer braces, leaving a flat initializer.
The original occurrence had an assertion statement in an unsupported-platform
branch of an aggregate initializer. A lone semicolon is sufficient to reproduce
the crash, so it does not depend on that assertion macro.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs