Timm Baeder
cfa07ccdfc
[clang][bytecode] Fix builtin_memchr with non-0 start index ( #131633 )
2025-03-17 19:02:55 +01:00
Timm Baeder
cf6a520a7a
[clang][bytecode] Fix builtin_memcmp buffer sizes for pointers ( #130570 )
...
Don't use the pointer size, but the number of elements multiplied by the
element size.
2025-03-10 15:51:31 +01:00
Timm Baeder
0f732481ac
[clang][bytecode] Fix getting pointer element type in __builtin_memcmp ( #130485 )
...
When such a pointer is heap allocated, the type we get is a pointer
type. Take the pointee type in that case.
2025-03-09 12:57:42 +01:00
Timm Baeder
227f9544a4
[clang][bytecode][NFC] Bail out on non constant evaluated builtins ( #130431 )
...
If the ASTContext says so, don't bother trying to constant evaluate the
given builtin.
2025-03-09 06:35:19 +01:00
Timm Baeder
46d218d1af
[clang][bytecode] Implement __builtin_{memchr,strchr,char_memchr} ( #130420 )
...
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-08 16:52:06 +01:00
Timm Baeder
d08cf7900d
[clang][bytecode] Implement __builtin_constant_p ( #130143 )
...
Use the regular code paths for interpreting.
Add new instructions: `StartSpeculation` will reset the diagnostics
pointers to `nullptr`, which will keep us from reporting any diagnostics
during speculation. `EndSpeculation` will undo this.
The rest depends on what `Emitter` we use.
For `EvalEmitter`, we have no bytecode, so we implement `speculate()` by
simply visiting the first argument of `__builtin_constant_p`. If the
evaluation fails, we push a `0` on the stack, otherwise a `1`.
For `ByteCodeEmitter`, add another instrucion called `BCP`, that
interprets all the instructions following it until the next
`EndSpeculation` instruction. If any of those instructions fails, we
jump to the `EndLabel`, which brings us right before the
`EndSpeculation`. We then push the result on the stack.
2025-03-08 06:06:14 +01:00
Timm Baeder
e9fe95acf3
[clang][bytecode][NFC] Use maxnum/minnum for fmax/fmin ( #129643 )
...
Equivalent of https://github.com/llvm/llvm-project/pull/129630 for the
bytecode interpreter.
2025-03-04 07:22:54 +01:00
Timm Baeder
e8d848824b
[clang][bytecode] Fix dynamic array allocation return values ( #127387 )
...
We need to return a pointer to the first element, not the array itself.
2025-02-16 12:24:35 +01:00
Timm Baeder
20506a0a15
[clang][bytecode] Fix operator new source expression ( #126870 )
...
... for composite element types. Looks like I forgot this in
e6030d3895
2025-02-12 10:05:49 +01:00
Timm Baeder
51c7338cc6
[clang][bytecode] Fix dummy handling for p2280r4 ( #124396 )
...
This makes some other problems show up like the fact that we didn't
suppress diagnostics during __builtin_constant_p evaluation.
2025-01-29 09:32:35 +01:00
Timm Baeder
e6030d3895
[clang][bytecode] Use std::allocator calls for Descriptor source ( #123900 )
...
... for the dynamic blocks created for operator new calls. This way we
get the type of memory allocated right. As a side-effect, the
diagnostics now point to the std::allocator calls, which is an
improvement.
2025-01-24 11:50:56 +01:00
Chandler Carruth
dc3cd2e95e
Factor common code for quoting a builtin name ( #120835 )
...
This shows up in several places in order to match the quoting of other
uses of the same diagnostic. Handling it centrally simplifies the code
and reduces changes if the storage for builtin names changes.
This refactoring is extracted out of #120534 as requested in code
review.
2025-01-03 19:23:42 -08:00
Timm Baeder
02b30128e8
[clang][bytecode] Always return false for invalid bcp results ( #121467 )
2025-01-02 13:44:45 +01:00
Timm Baeder
34097c07e1
[clang][bytecode] Consider unknown-size arrays in memcpy/memcmp ( #121462 )
...
When emitting diagnostics for the number of elements.
2025-01-02 10:59:08 +01:00
Timm Baeder
45e874e390
[clang][bytecode] Check for memcpy/memmove dummy pointers earlier ( #121453 )
2025-01-02 09:15:14 +01:00
Timm Baeder
f0d60170cc
[clang][bytecode] Check memove/memcpy for available elements ( #121383 )
...
Both destination and source pointer need to have at least as many
elements as requested.
2024-12-31 12:14:27 +01:00
Timm Baeder
1f2d934525
[clang][bytecode] Support pointers in __builtin_mem{move,cpy} ( #120560 )
...
Unfortunately, that means we can't use the __builtin_bit_cast
implementation for this.
2024-12-19 16:38:58 +01:00
Timm Baeder
dd6f6a096a
[clang][bytecode] Handle builtin_wmemcmp ( #120070 )
2024-12-16 13:41:14 +01:00
Timm Baeder
30cbd09f4b
[clang][bytecode] Fix memcmp/bcmp failures on big-endian hosts ( #119851 )
...
See the discussion in
https://github.com/llvm/llvm-project/pull/119678#issuecomment-2539680746
and
https://github.com/llvm/llvm-project/pull/119544#issuecomment-2539678561
2024-12-13 12:19:27 +01:00
Timm Baeder
98470c0b2e
[clang][bytecode] Handle __builtin_bcmp ( #119678 )
...
... 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 10:57:39 +01:00
Timm Bäder
cfad8f14f8
[clang][bytecode] Fix a build failure on aarch64
...
This broke e.g.
https://lab.llvm.org/buildbot/#/builders/190/builds/11216
2024-12-12 09:08:30 +01:00
Timm Baeder
8713914d76
[clang][bytecode] Handle __builtin_memcmp ( #119544 )
2024-12-12 08:59:35 +01:00
Timm Baeder
d416cae180
[clang][bytecode][NFC] Use Pointer::pointToSameBlock ( #119552 )
...
block() requires the pointer to be a block pointer.
2024-12-11 16:14:19 +01:00
Timm Baeder
4dde52d76b
[clang][bytecode] Check for overlapping memcpy regions ( #119535 )
2024-12-11 12:06:56 +01:00
Timm Baeder
6168739f00
[clang][bytecode] Reject memcpy sizes with element size remainder ( #119209 )
2024-12-09 16:57:49 +01:00
Timm Baeder
d17e51f306
[clang][bytecode] Handle __builtin_strncmp ( #119208 )
2024-12-09 16:17:39 +01:00
Jie Fu
4f08fa1a77
[clang] Fix -Wunused-variable in InterpBuiltin.cpp (NFC)
...
/llvm-project/clang/lib/AST/ByteCode/InterpBuiltin.cpp:262:23:
error: unused variable 'AC' [-Werror,-Wunused-variable]
const ASTContext &AC = S.getASTContext();
^
1 error generated.
2024-12-09 21:23:08 +08:00
Timm Baeder
00b50c917b
[clang][bytecode] Handle __builtin_wcslen ( #119187 )
...
Handle different char widths in builtin_strlen.
2024-12-09 12:34:25 +01:00
Timm Baeder
abc27039be
[clang][bytecode] Pass __builtin_memcpy size along ( #118649 )
...
To DoBitCastPtr, so we know how many bytes we want to read.
2024-12-05 06:55:18 +01:00
Timm Bäder
61c2ac03d8
Revert "[clang][bytecode] Handle __builtin_wcslen ( #118446 )"
...
This reverts commit 89a0ee8997 .
This breaks builders:
https://lab.llvm.org/buildbot/#/builders/13/builds/3885
2024-12-03 13:35:57 +01:00
Timm Baeder
3f39c5df08
[clang][bytecode] Reject memcpy dummy pointers after null check ( #118460 )
...
To match the diagnostic output of the current interpreter.
2024-12-03 11:51:49 +01:00
Timm Baeder
0f4dc4276f
[clang][bytecode] Initialize elements in __builtin_elementwise_popcount ( #118457 )
2024-12-03 11:14:06 +01:00
Timm Baeder
89a0ee8997
[clang][bytecode] Handle __builtin_wcslen ( #118446 )
...
... just like strlen.
2024-12-03 10:20:30 +01:00
Timm Baeder
46446bb2d3
[clang][bytecode][NFC] Diagnose non-constexpr builtin strcmp calls ( #118442 )
2024-12-03 09:49:26 +01:00
Timm Baeder
789551362e
[clang][bytecode] Handle memmove like memcpy ( #118431 )
...
This is the same thing for us, except for diagnostic differences.
2024-12-03 07:56:06 +01:00
Timm Baeder
dac9736d05
[clang][bytecode][NFC] Diagnose no-constexpr memcpy/strlen versions ( #118429 )
2024-12-03 06:59:56 +01:00
Timm Baeder
fc9052ee25
[clang][bytecode] Check __builtin_memcpy for null pointers ( #118313 )
2024-12-03 03:36:57 +01:00
Timm Baeder
637a1ae855
[clang][bytecode] Implement __builtin_elementwise_popcount ( #118307 )
2024-12-02 16:48:22 +01:00
Timm Baeder
b587b910d5
[clang][bytecode] Implement __builtin_reduce_xor ( #118299 )
2024-12-02 16:04:49 +01:00
Timm Baeder
1288f6d405
[clang][bytecode] Implement __builtin_reduce_or ( #118292 )
2024-12-02 15:28:26 +01:00
Timm Baeder
ccc471fe3e
[clang][bytecode] Implement __builtin_reduce_and ( #118289 )
2024-12-02 14:29:38 +01:00
Timm Baeder
c1dcf75a7c
[clang][bytecode] Implement __builtin_reduce_mul ( #118287 )
2024-12-02 14:03:53 +01:00
Timm Baeder
0611fdd320
[clang][bytecode] Add simple __builtin_memcpy implementation ( #118278 )
...
Not handling all the special- and error cases yet. Just making sure the
bitcast code can be used for this as well.
2024-12-02 13:11:22 +01:00
Timm Baeder
31bde711c4
[clang][bytecode] Support __builtin_reduce_add ( #117672 )
2024-12-01 17:39:11 +01:00
Timm Baeder
82ed9c0319
[clang][bytecode][NFC] Remove APValue Result argument where unnecessary ( #118199 )
...
This is unneeded in almost all circumstances. We only return an APValue
back to clang when the evaluation is finished, and that is always done
by an EvalEmitter - which has its own implementation of the Ret
instructions.
2024-12-01 17:36:19 +01:00
Congcong Cai
cbdd14ee9d
[clang][NFC]add static for internal linkage function ( #117482 )
...
Detected by misc-use-internal-linkage
2024-11-25 06:48:33 +08:00
Timm Baeder
8951b51402
[clang][bytecode] Add more checks to _ai32_* builtins ( #114412 )
...
They are called in a few different forms that we don't support.
2024-11-01 14:19:59 +01:00
Timm Baeder
ef2a104c94
[clang][bytecode] Start implementing __builtin_bit_cast ( #112126 )
...
This is a subset of #68288 , with hopefully narrower scope. It does not
support bitcasting to non-integral types yet.
Bitfields are supported, but only if they result in a full byte-sized
final buffer. It does not support casting from null-pointers yet or
casting from indeterminate bits.
The tests are from #68288 and partially from #74775 .
The `BitcastBuffer` struct is currently always working in single bits,
but I plan to (try to) optimize this for the common full-byte case.
2024-10-31 18:09:40 +01:00
Timm Baeder
b46a0482f9
[clang][bytecode] Implement __builtin_arithmetic_fence ( #113937 )
2024-10-29 00:56:03 +01:00
Timm Baeder
615a5eb02c
[clang][bytecode] Check ai32_bextr builtins for integer args ( #113128 )
2024-10-21 08:15:51 +02:00