aboutsummaryrefslogtreecommitdiff
path: root/clang/test/AST/ByteCode/builtin-functions.cpp
AgeCommit message (Collapse)AuthorFilesLines
2025-07-08[clang][bytecode] Fix __builtin_is_within_lifetime in initializers (#147480)Timm Baeder1-0/+20
2025-07-06[clang][bytecode] Fix a crash in overflow builtins (#147189)Timm Baeder1-0/+8
Only initialize pointers that can be initialized.
2025-06-23[clang][bytecode] Fix assignInteger() with allocated primtypes (#145302)Timm Baeder1-0/+14
2025-06-20Reapply "Reapply "[clang][bytecode] Allocate IntegralAP and Floating … ↵Timm Baeder1-7/+5
(#145014) …types usi… (#144676)" This reverts commit 68471d29eed2c49f9b439e505b3f24d387d54f97. IntegralAP contains a union: union { uint64_t *Memory = nullptr; uint64_t Val; }; On 64bit systems, both Memory and Val have the same size. However, on 32 bit system, Val is 64bit and Memory only 32bit. Which means the default initializer for Memory will only zero half of Val. We fixed this by zero-initializing Val explicitly in the IntegralAP(unsigned BitWidth) constructor. See also the discussion in https://github.com/llvm/llvm-project/pull/144246
2025-06-18Revert "Reapply "[clang][bytecode] Allocate IntegralAP and Floating types ↵Timm Bäder1-5/+7
usi… (#144676)" This reverts commit 7c15edb306932e41c159f3d69c161ed0d89d47b7. This still breaks clang-armv8-quick: https://lab.llvm.org/buildbot/#/builders/154/builds/17587
2025-06-18Reapply "[clang][bytecode] Allocate IntegralAP and Floating types usi… ↵Timm Baeder1-7/+5
(#144676) …ng an allocator (#144246)" This reverts commit 57828fec760f086b334ce0cb1c465fc559dcaea4.
2025-06-17Revert "[clang][bytecode] Allocate IntegralAP and Floating types using an ↵Timm Bäder1-5/+7
allocator (#144246)" This reverts commit c66be289901b3f035187d391e80e3610d7d6232e. This breaks the armv8-quick builder: https://lab.llvm.org/buildbot/#/builders/154/builds/17549
2025-06-17[clang][bytecode] Allocate IntegralAP and Floating types using an allocator ↵Timm Baeder1-7/+5
(#144246) Both `APInt` and `APFloat` will heap-allocate memory themselves using the system allocator when the size of their data exceeds 64 bits. This is why clang has `APNumericStorage`, which allocates its memory using an allocator (via `ASTContext`) instead. Calling `getValue()` on an ast node like that will then create a new `APInt`/`APFloat` , which will copy the data (in the `APFloat` case, we even copy it twice). That's sad but whatever. In the bytecode interpreter, we have a similar problem. Large integers and floating-point values are placement-new allocated into the `InterpStack` (or into the bytecode, which is a `vector<std::byte>`). When we then later interrupt interpretation, we don't run the destructor for all items on the stack, which means we leak the memory the `APInt`/`APFloat` (which backs the `IntegralAP`/`Floating` the interpreter uses). Fix this by using an approach similar to the one used in the AST. Add an allocator to `InterpState`, which is used for temporaries and local values. Those values will be freed at the end of interpretation. For global variables, we need to promote the values to global lifetime, which we do via `InitGlobal` and `FinishInitGlobal` ops. Interestingly, this results in a slight _improvement_ in compile times: https://llvm-compile-time-tracker.com/compare.php?from=6bfcdda9b1ddf0900f82f7e30cb5e3253a791d50&to=88d1d899127b408f0fb0f385c2c58e6283195049&stat=instructions:u (but don't ask me why). Fixes https://github.com/llvm/llvm-project/issues/139012
2025-04-29[clang][bytecode] Start implementing builtin_is_within_lifetime (#137765)Timm Baeder1-0/+33
2025-04-29[clang][bytecode] Allow This pointers in CPCE mode (#137761)Timm Baeder1-2/+2
The outermost function doesn't have a This pointers, but inner calls can. This still doesn't match the diagnostic output of the current interpreter properly, but it's closer I think.
2025-04-29[clang][bytecode] Remove base casts before doing memcpy (#137754)Timm Baeder1-1/+13
We have to copy the entire thing, not just one of the bases.
2025-04-17[clang][bytecode] Add missing __builtin_memcpy checks (#135975)Timm Baeder1-0/+35
Add a test for type punning and tests and the necessary checks for non-trivially-copyable types and incomplete types.
2025-04-16[clang][bytecode] Implement __builtin_wmem{cpy,move} (#135969)Timm Baeder1-0/+62
2025-03-31[clang][bytecode] Return Invalid() on non-constexpr builtins (#133700)Timm Baeder1-0/+9
So the diagnostic output matches with the current interpreter
2025-03-26Reapply "[clang][bytecode] Implement __builtin_{wcscmp,wcsncmp} (#132… ↵Timm Baeder1-0/+46
(#132963) …723)" This reverts commit 1e2ad6793ac205607e7c809283cf69e1cc36a69a. Fix the previous commit on big-endian hosts by _not_ falling through to the `uint8_t` code path.
2025-03-25Revert "[clang][bytecode] Implement __builtin_{wcscmp,wcsncmp} (#132723)"Timm Bäder1-46/+0
This reverts commit f7aea4d081f77dba48b0fc019f59b678fb679aa8. This broke the clang-solaris11-sparcv9 builder: https://lab.llvm.org/buildbot/#/builders/13/builds/6151
2025-03-24[clang][bytecode] Redo RUN lines in the builtin-functions test (#132762)Timm Baeder1-5/+11
Make sure we run each configuration once with the bytecode interpreter and once with the current one. Add a triple to the one that was previously without.
2025-03-24[clang][bytecode] Implement __builtin_{wcscmp,wcsncmp} (#132723)Timm Baeder1-0/+46
2025-03-24[clang][bytecode] Diagnose integral source/dest in memcpy (#132715)Timm Baeder1-0/+6
Like the current interpreter does.
2025-03-24[clang][bytecode] Implement __builtin_wcschr (#132708)Timm Baeder1-0/+21
This is already almost implemented, just need to enable support for it.
2025-03-22[clang][bytecode] Support overlapping regions in __builtin_memmove (#132523)Timm Baeder1-2/+1
Unfortunately, a few circumstances make the implementation here less than ideal, but we need to handle overlapping regions anyway.
2025-03-20[clang][bytecode] Implement __builtin_wmemchr (#132254)Timm Baeder1-0/+24
2025-03-17[clang][bytecode] Fix builtin_memchr with non-0 start index (#131633)Timm Baeder1-0/+5
2025-03-09[clang][bytecode] Fix getting pointer element type in __builtin_memcmp (#130485)Timm Baeder1-0/+15
When such a pointer is heap allocated, the type we get is a pointer type. Take the pointee type in that case.
2025-03-08[clang][bytecode] Implement __builtin_{memchr,strchr,char_memchr} (#130420)Timm Baeder1-0/+118
llvm has recently started to use `__builitn_memchr` at compile time, so implement this. Still needs some work but the basics are done.
2025-03-04[clang][bytecode] Fix diagnostic difference with opaque call cmps (#129702)Timm Baeder1-3/+2
Try to dig out the call expression and diagnose this as an opaque call.
2025-03-04[clang][bytecode] Only emit literal_comparison for string literals (#129691)Timm Baeder1-2/+2
This is what the current interpreter does as well.
2025-02-11[clang][bytecode][NFC] Add failing memmove testcase (#126682)Timm Baeder1-0/+16
Reduced from libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char32_t/move.pass.cpp
2025-01-09[clang][ExprConst] Add diagnostics for invalid binary arithmetic (#118475)Timm Baeder1-1/+1
... between unrelated declarations or literals. Leaving this small (I haven't run the whole test suite locally) to get some feedback on the wording and implementation first. The output of the sample in https://github.com/llvm/llvm-project/issues/117409 is now: ```console ./array.cpp:57:6: warning: expression result unused [-Wunused-value] 57 | am - aj.af(); | ~~ ^ ~~~~~~~ ./array.cpp:70:8: error: call to consteval function 'L::L<bx>' is not a constant expression 70 | q(0, [] { | ^ ./array.cpp:57:6: note: arithmetic on addresses of literals has unspecified value 57 | am - aj.af(); | ^ ./array.cpp:62:5: note: in call to 'al(&""[0], {&""[0]})' 62 | al(bp.af(), k); | ^~~~~~~~~~~~~~ ./array.cpp:70:8: note: in call to 'L<bx>({})' 70 | q(0, [] { | ^~~~ 71 | struct bx { | ~~~~~~~~~~~ 72 | constexpr operator ab<g<l<decltype(""[0])>::e>::e>() { return t(""); } | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 73 | }; | ~~ 74 | return bx(); | ~~~~~~~~~~~~ 75 | }()); | ~~~ ``` The output for ```c++ int a, b; constexpr int n = &b - &a ``` is now: ```console ./array.cpp:80:15: error: constexpr variable 'n' must be initialized by a constant expression 80 | constexpr int n = &b - &a; | ^ ~~~~~~~ ./array.cpp:80:22: note: arithmetic involving '&b' and '&a' has unspecified value 80 | constexpr int n = &b - &a; | ^ 1 error generated. ```
2025-01-02[clang][bytecode] Consider unknown-size arrays in memcpy/memcmp (#121462)Timm Baeder1-0/+9
When emitting diagnostics for the number of elements.
2025-01-02[clang][bytecode] Consider start index when copying composite array (#121461)Timm Baeder1-0/+10
... elements.
2024-12-31[clang][bytecode] Check memove/memcpy for available elements (#121383)Timm Baeder1-0/+9
Both destination and source pointer need to have at least as many elements as requested.
2024-12-19[clang][bytecode] Support pointers in __builtin_mem{move,cpy} (#120560)Timm Baeder1-0/+22
Unfortunately, that means we can't use the __builtin_bit_cast implementation for this.
2024-12-16[clang][bytecode] Handle builtin_wmemcmp (#120070)Timm Baeder1-0/+15
2024-12-12[clang][bytecode] Handle __builtin_bcmp (#119678)Timm Baeder1-0/+15
... the same as `__builtin_memcmp`. Also fix a bug we still had when we couldn't find a difference in the two inputs after `Size` bytes.
2024-12-12[clang][bytecode] Handle __builtin_memcmp (#119544)Timm Baeder1-0/+33
2024-12-11[clang][bytecode] Check for overlapping memcpy regions (#119535)Timm Baeder1-0/+15
2024-12-10[clang][bytecode] Allow checking builtin functions... (#119328)Timm Baeder1-2/+2
... in checkingPotentialConstantExpression mode. This is what the current interpreter does, yet it doesn't do so for `__builtin_operator_new`.
2024-12-09[clang][bytecode] Reject memcpy sizes with element size remainder (#119209)Timm Baeder1-0/+10
2024-12-09[clang][bytecode] Handle __builtin_strncmp (#119208)Timm Baeder1-0/+9
2024-12-09[clang][bytecode] Handle __builtin_wcslen (#119187)Timm Baeder1-0/+12
Handle different char widths in builtin_strlen.
2024-12-05[clang][bytecode] Pass __builtin_memcpy size along (#118649)Timm Baeder1-0/+7
To DoBitCastPtr, so we know how many bytes we want to read.
2024-12-03Revert "[clang][bytecode] Handle __builtin_wcslen (#118446)"Timm Bäder1-12/+0
This reverts commit 89a0ee89973c3d213c4bc11c26b41eab67e06da0. This breaks builders: https://lab.llvm.org/buildbot/#/builders/13/builds/3885
2024-12-03[clang][bytecode] Reject memcpy dummy pointers after null check (#118460)Timm Baeder1-0/+4
To match the diagnostic output of the current interpreter.
2024-12-03[clang][bytecode] Initialize elements in __builtin_elementwise_popcount ↵Timm Baeder1-0/+12
(#118457)
2024-12-03[clang][bytecode] Handle __builtin_wcslen (#118446)Timm Baeder1-0/+12
... just like strlen.
2024-12-03[clang][bytecode] Handle memmove like memcpy (#118431)Timm Baeder1-0/+7
This is the same thing for us, except for diagnostic differences.
2024-12-03[clang][bytecode] Check __builtin_memcpy for null pointers (#118313)Timm Baeder1-0/+8
2024-12-02[clang][bytecode] Implement __builtin_elementwise_popcount (#118307)Timm Baeder1-0/+22
2024-12-02[clang][bytecode] Implement __builtin_reduce_xor (#118299)Timm Baeder1-0/+12