- Added boolean IsScalar argument to the helper functions in
InterpBuiltin/ExprConstant
- Made minsh_round_mask, maxsh_round_mask constexpr only for
_MM_FROUND_CUR_DIRECTION rounding mode.
- Added helper function for scalar round mask in
InterpBuiltin/ExprConstant
Resolves#175198
## Summary
- Fix crash when passing non primitive types (structs) to
`__builtin_infer_alloc_token`
- The bytecode interpreter's discard loop dereferenced an empty
`OptPrimType` for non primitive arguments
## Test plan
- Added regression test in `clang/test/SemaCXX/alloc-token.cpp`
- Existing tests continue to pass
Fixes#178892
This is like https://github.com/llvm/llvm-project/pull/179033, which
broke a few builders for reasons I still don't really understand. I ran
the other clang tests and this version fixes a few of the introduced
regressions.
This still regresses `CodeGen/pass-object-size.c`, but that's a
pre-existing issue.
Patch is of coursed based on #179033 by @mariusdr.
Fixes#138474
Use new bytecode intepreter in `Expr::tryEvaluateObjectSize`. Reuses the
already existing implementation for `__builtin_object_size` in of the
intepreter.
---------
Co-authored-by: Timm Baeder <tbaeder@redhat.com>
## Summary
Fix assertion failure when evaluating
`__builtin_align_up`/`__builtin_align_down`/`__builtin_is_aligned` with
one-past-end pointers like `&array[size]`.
## Root Cause
`getIndex()` calls `getOffset()` which asserts when `Offset ==
PastEndMark`. This happens for one-past-end element pointers.
## Fix
Check `isElementPastEnd()` before calling `getIndex()`. For past-end
pointers, use `getNumElems()` instead which gives the correct index
value.
## Test
Added test cases in `builtin-align-cxx.cpp` for one-past-end pointer
alignment.
Fixes#178647
Update the callback signature for `EvaluateFpBinOpExpr` and
`interp__builtin_elementwise_fp_binop` to return
`std::optional<APFloat>`, allowing individual callbacks to decide
whether to handle special floating-point cases (inf/nan/denormal).
Previously, the helper functions had hardcoded validation that forced
all callbacks to reject these cases. This blocked intrinsics needing
custom validation (e.g., rounding mode checks). Now each callback
controls its own validation and returns `std::nullopt` when the fold is
invalid.
Fixes#178416
### 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>
Mostly inspired by https://github.com/llvm/llvm-project/pull/152971
CRC32 implementation using reversed polynomial that does not match an
Intel manual, can be changed to canonical implementation if required (if
there is a canonical implementation we should use, please attach a link)
Closes#168881
Part of #30794
This patch adds type-generic rotate builtins that accept any unsigned
integer
type. These builtins provide:
- Support for all unsigned integer types, including _BitInt
- Constexpr evaluation capability
- Automatic normalization of rotation counts modulo the bit-width
- Proper handling of negative rotation counts (converted to equivalent
positive rotations in the opposite direction)
- Implicit conversion support for both arguments for
types with conversion operators.
The builtins follow C23 naming conventions.
Resolves https://github.com/llvm/llvm-project/issues/122819
This matches the behaviour of ISD::TRUNCATE_SSAT_U and X86ISD::PACKUS
truncations: saturate signed input to unsigned result -
`truncate(smin(smax(x, 0), C))`
Add unit test coverage and update existing PACKUS constant folding to
use the APInt helper
* Implemented a generic function interp__builtin_elementwise_fp_binop
* NaN, Infinity, Denormal cases can be integrated into the lambda in
future. For, now these cases are hardcoded in the generic function
Resolves: #169991
The getType() call might fail. We can't pull the isReadable() check up
though because that creates different diagnostic output compared to the
current interpreter.
Fixes#172202
Resolves#169312
Enables the usage of the following X86 intrinsics in `constexpr`:
```c
_mm256_permute2f128_pd _mm256_permute2f128_ps
_mm256_permute2f128_si256 _mm256_permute2x128_si256
```
Save them as a pointer intead of using a shared_ptr. This we we can use
the pointer integer value to differentiate the "no initmap yet" and "all
values initialzed" cases.
This regresses one test case in const-eval.c, but as it turns out, that
only worked coincidentally before.
Add AVX512 kshiftli/kshiftri mask intrinsics to be used in constexpr.
Enables constexpr evaluation for:
- `_kshiftli_mask8/16/32/64`
- `_kshiftri_mask8/16/32/64`
Fixes#162056
This patch implements constant evaluation support for the following X86
intrinsics:
- _mm_cvtpd_ps, _mm256_cvtpd_ps (Packed Double to Float)
- _mm_cvtsd_ss (Scalar Double to Float merge)
- Masked variants of the above
It implements the strict "Exact and Finite" rule: conversions that are
inexact, infinite, or NaN are rejected in constexpr contexts.
Fixes#169370