| Issue |
234188
|
| Summary |
clang: crash-on-invalid - Unexpected placeholder builtin type! after rejecting _Generic void association under -Werror=c2y-extensions
|
| Labels |
|
| Assignees |
|
| Reporter |
kdupontbe
|
## Summary
On clang 23 / trunk (assertions builds), compiling an invalid `_Generic` association that uses incomplete type `void`, when the result is used as a scalar, crashes in CodeGen instead of stopping after Sema diagnostics.
Release builds of clang 23 may segfault rather than hit the unreachable.
This looks related to https://github.com/llvm/llvm-project/issues/173921 (same `CodeGenTypes::ConvertType` / `Unexpected placeholder builtin type!` via a different invalid AST involving `void`). The trigger here is C `_Generic` plus C2y incomplete-association diagnostics turned into errors.
## Compiler Explorer
https://godbolt.org/z/Yn5eoxjvx
## Reduced reproducer
```c
void f(void) {
int x;
x = _Generic(0, void: 1);
}
```
```text
clang -std=c11 -Werror=c2y-extensions -S -emit-llvm repro.c
```
`-pedantic-errors` instead of `-Werror=c2y-extensions` also triggers the crash.
## Observed behavior
Sema correctly diagnoses the invalid association, then CodeGen continues and dies:
```text
error: use of incomplete type 'void' in a '_Generic' association is a C2y extension [-Werror,-Wc2y-extensions]
error: cannot compile this scalar _expression_ yet
Unexpected placeholder builtin type!
UNREACHABLE executed at clang/lib/CodeGen/CodeGenTypes.cpp:618!
```
Stack (abridged): `CodeGenTypes::ConvertType` <- `ScalarExprEmitter::VisitExpr` <- `VisitCastExpr` <- `EmitScalarExpr` while generating `f`.
## Expected behavior
Error diagnostics only (as on clang 21 / 22), then exit non-zero. No CodeGen crash or segfault.
## Version matrix (Godbolt / local)
- clang assertions trunk: `UNREACHABLE: Unexpected placeholder builtin type!`
- clang 23.1.0 (release): segfault (signal 11)
- clang 22.1.0 / 21.1.0: clean `-Werror` diagnostics, no crash
Regression between clang 22 and 23. Target-independent (reproduced on x86-64 and RISC-V).
## Necessary conditions
All three are required:
1. Error-level diagnostic for the incomplete `void` association (`-Werror=c2y-extensions` or `-pedantic-errors`). Plain `-std=c11` (warning only) or `-std=c2y` does not crash.
2. No matching association / no `default:`, so Sema builds a `RecoveryExpr` of placeholder type.
3. Result is used as a scalar (`x = ...`). Discarding the value, e.g. `(void)_Generic(0, void: 1);`, does not crash.
## Notes / analysis
After the `-Werror` error, clang still runs IR generation. It reaches `ScalarExprEmitter::VisitExpr` on the `RecoveryExpr`, then `ConvertType` on the placeholder type, and hits the unreachable in `CodeGenTypes.cpp`.
Possibly the same class of bug as https://github.com/llvm/llvm-project/issues/173921 (CodeGen of a placeholder / void-ish recovery value), with a different frontend path into that unreachable.
Assisted by AI in creating the issue text
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs