40 Commits

Author SHA1 Message Date
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
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
f838a5e96c
[clang][bytecode] Fix diagnostic difference with opaque call cmps (#129702)
Try to dig out the call expression and diagnose this as an opaque call.
2025-03-04 15:04:57 +01:00
Timm Baeder
53d433e702
[clang][bytecode] Only emit literal_comparison for string literals (#129691)
This is what the current interpreter does as well.
2025-03-04 14:07:53 +01:00
Timm Baeder
dfbd764a55
[clang][bytecode][NFC] Add failing memmove testcase (#126682)
Reduced from
libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char32_t/move.pass.cpp
2025-02-11 08:45:24 +01:00
Timm Baeder
fd6baa477f
[clang][ExprConst] Add diagnostics for invalid binary arithmetic (#118475)
... 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-09 11:42:35 +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
d5c8af492f
[clang][bytecode] Consider start index when copying composite array (#121461)
... elements.
2025-01-02 10:31:49 +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
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 Baeder
8713914d76
[clang][bytecode] Handle __builtin_memcmp (#119544) 2024-12-12 08:59:35 +01:00
Timm Baeder
4dde52d76b
[clang][bytecode] Check for overlapping memcpy regions (#119535) 2024-12-11 12:06:56 +01:00
Timm Baeder
ce1587346b
[clang][bytecode] Allow checking builtin functions... (#119328)
... in checkingPotentialConstantExpression mode. This is what the
current interpreter does, yet it doesn't do so for
`__builtin_operator_new`.
2024-12-10 07:42:13 +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
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 89a0ee89973c3d213c4bc11c26b41eab67e06da0.

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
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
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
c8ef
332ac18e31
[clang] constexpr built-in abs function. (#112539)
According to [P0533R9](https://wg21.link/P0533R9), the C++ standard
library functions corresponding to the C macros in `[c.math.abs]` are
now `constexpr`.

To implement this feature in libc++, we must make the built-in abs
function `constexpr`. This patch adds the implementation of a
`constexpr` abs function for the current constant evaluator and the new
bytecode interpreter.

It is important to note that in 2's complement systems, the absolute
value of the most negative value is out of range. In gcc, it will result
in an out-of-range error and will not be evaluated as constants. We
follow the same approach here.
2024-10-18 19:03:50 +08:00
Timm Baeder
fed8695bb8
[clang][bytecode] Emit better diagnostic for invalid shufflevector index (#111643) 2024-10-09 09:56:37 +02:00
Richard Smith
d8a2815903
[clang] implement current direction of CWG2765 for string literal comparisons in constant evaluation (#109208)
Track the identity of each string literal object produced by evaluation
with a global version number. Accept comparisons between literals of the
same version, and between literals of different versions that cannot
possibly be placed in overlapping storage. Treat the remaining
comparisons as non-constant.

---------

Co-authored-by: Timm Baeder <tbaeder@redhat.com>
Co-authored-by: Aaron Ballman <aaron@aaronballman.com>
2024-09-26 15:56:33 -07:00
Timm Baeder
d03822d888
[clang][bytecode] Fix lookup of source locations in implicit ctors (#107992)
Implicit functions may still have a body. The !hasBody() check is
enough.
2024-09-11 07:21:49 +02:00
Timm Baeder
9626e84fae
[clang][bytecode][NFC] Simplify builtin-functions.cpp (#107118)
The effect is the same, but this version doesn't take as long to
evaluate.
2024-09-03 18:41:01 +02:00
Timm Baeder
360e4abfc8
[clang][bytecode] Diagnose comparisons with literals (#106734)
This requires adding a new opcode for PointerToBoolean casts, since we
otherwise emit too many diagnostics. But that fixes an older problem
when casting weak pointers to bool.
2024-08-31 06:24:36 +02:00
Mital Ashok
f1b642775f
[Clang][test] Add bytecode interpreter tests for floating comparison functions (#104703)
See also: #94118, 71801707e33c235656b172fa7dfb8662473a95c2
2024-08-20 11:45:33 +02:00
Timm Baeder
a07aba5d44
[clang] Rename all AST/Interp stuff to AST/ByteCode (#104552)
"Interp" clashes with the clang interpreter and people often confuse
this.
2024-08-16 17:13:12 +02:00