| commit | a150e8081ac2b4c7c056b0290afb88b9a01d7a1d | [log] [tgz] |
|---|---|---|
| author | Ayush Kumar Gaur <132849148+Ayush3941@users.noreply.github.com> | Mon Jan 26 11:01:02 2026 -0500 |
| committer | GitHub <noreply@github.com> | Mon Jan 26 17:01:02 2026 +0100 |
| tree | d19421b998e55c4f063f19440c72aa739b1c0f74 | |
| parent | b0ce26c320ec09940442ded28d7771043639377e [diff] |
[clang][bytecode] Avoid crash in constexpr wcslen on invalid argument… (#177891)
### What the problem ?
Fix a clang bytecode constant interpreter crash when evaluating
wcslen("x") in a constant-expression path.
Previously we asserted on wchar element size mismatch and crashed in
assertion builds.
### Why it happened
The expression is already ill-typed (char[2] → const wchar_t*), clang
correctly emits a diagnostic, but later ICE checking tries to fold the
expression and reaches the builtin handler. That path must not crash.
### whats the Fix
Replace the assert(ElemSize == wchar_t size) with a graceful failure
(return false / emit appropriate diagnostic) when element sizes don’t
match, so evaluation stops safely.
### how to Test it
Add a regression test that triggers ICE checking with
-fexperimental-new-constant-interpreter and ensures clang does not crash
(verifies it reports the type error / static_assert failure instead).
Fixes #177844.
<img width="1366" height="768" alt="Screenshot_2026-01-25_22_07_50"
src="https://github.com/user-attachments/assets/488dd0b0-3c17-4f45-b2d0-9339b8fd3409"
/>
where wclen_crash.c is
`
#include <wchar.h>
static_assert(wcslen("x") == 'x');
int main() {}
`
---------
Co-authored-by: Timm Baeder <tbaeder@redhat.com>Welcome to the LLVM project!
This repository contains the source code for LLVM, a toolkit for the construction of highly optimized compilers, optimizers, and run-time environments.
The LLVM project has multiple components. The core of the project is itself called “LLVM”. This contains all of the tools, libraries, and header files needed to process intermediate representations and convert them into object files. Tools include an assembler, disassembler, bitcode analyzer, and bitcode optimizer.
C-like languages use the Clang frontend. This component compiles C, C++, Objective-C, and Objective-C++ code into LLVM bitcode -- and from there into object files, using LLVM.
Other components include: the libc++ C++ standard library, the LLD linker, and more.
Consult the Getting Started with LLVM page for information on building and running LLVM.
For information on how to contribute to the LLVM project, please take a look at the Contributing to LLVM guide.
Join the LLVM Discourse forums, Discord chat, LLVM Office Hours or Regular sync-ups.
The LLVM project has adopted a code of conduct for participants to all modes of communication within the project.