Commit Graph

168 Commits

Author SHA1 Message Date
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
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
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
e86b68ff56 [clang][bytecode] Add support for typeid pointers (#121251)
Add it as another kind of pointer, saving both a `Type*` for the result
of the typeid() expression as well as one for the type of the typeid
expression.
2024-12-28 14:07:01 +01:00
Timm Baeder
acb7dfaa01 [clang][bytecode] Create local scopes for if then/else statements (#120852)
In case those aren't compound statements.
2024-12-22 08:04:49 +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
56fd46edb3 [clang][bytecode] Remove a bitcast nullptr_t special case (#120188)
We still need to check the input pointer, so let this go through
BitCastPrim.
2024-12-17 13:23:14 +01:00
Timm Baeder
056cd12284 [clang][bytecode] Don't check returned pointers for liveness (#120107)
We're supposed to let them through and then later diagnose reading from
them, but returning dead pointers is fine.
2024-12-17 06:20:14 +01:00
Timm Baeder
dd6f6a096a [clang][bytecode] Handle builtin_wmemcmp (#120070) 2024-12-16 13:41:14 +01:00
Timm Bäder
2503a66596 Reapply "[clang][bytecode] Fix some shift edge cases (#119895)"
This reverts commit a6636ce4d1.

This original commit failed on hosts with signed wchar_t. Care for
this in the test.
2024-12-16 10:01:46 +01:00
Timm Bäder
a6636ce4d1 Revert "[clang][bytecode] Fix some shift edge cases (#119895)"
This reverts commit 49c2207f21.

This breaks on big-endian, again:
https://lab.llvm.org/buildbot/#/builders/154/builds/9018
2024-12-14 06:28:12 +01:00
Timm Baeder
49c2207f21 [clang][bytecode] Fix some shift edge cases (#119895)
Around shifting negative values.
2024-12-14 06:15:56 +01:00
Mariya Podchishchaeva
1d65c35ce1 [clang] Reject _Complex _BitInt (#119402)
The C standard doesn't require support for these types and Codegen for
these types is incorrect ATM.
See https://github.com/llvm/llvm-project/issues/119352
2024-12-12 12:19:48 +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
0fb06172f1 [clang][bytecode] Check vector element types for eligibility (#119385)
Like we do in ExprConstant.cpp.
2024-12-10 17:56:48 +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
1fbbf4c418 [clang][bytecode] Pass (float) BitWidth to DoBitCast (#119119)
In certain cases (i.e. long double on x86), the bit with we get from the
floating point semantics is different than the type size we compute for
the BitCast instruction. Pass this along to DoBitCast, so in there we
can check only the relevant bits for being initialized.

This also fixes a weirdness we still had in DoBitCast.
2024-12-08 18:54:08 +01:00
Timm Baeder
b4150ed128 [clang][bytecode] Check composite bitcasts for indeterminate bits (#118988) 2024-12-07 13:06:00 +01:00
Timm Baeder
2f9cd43a73 [clang][bytecode] Check primitive bit casts for indeterminate bits (#118954)
Record bits ranges of initialized bits and check them in
allInitialized().
2024-12-06 15:50:59 +01:00
Timm Baeder
b6217f67a4 [clang][bytecode] Fix bitcasting from null pointers (#116999) 2024-12-05 13:13:59 +01:00
Timm Bäder
17dfdd3a86 [clang][bytecode][tests] Specify triple in bitfields tests
This still breaks on 32bit hosts otherwise.
See https://github.com/llvm/llvm-project/pull/116843
2024-12-05 11:10:58 +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 Baeder
44be794658 [clang][bytecode] Not all null pointers are 0 (#118601)
Get the Value from the ASTContext instead.
2024-12-05 06:03:50 +01:00
Timm Baeder
7aec6dc477 [clang][bytecode] Initialize bases when bitcasting (#117179)
Base pointers do not get passed to the callback, so initialize them when iterating bases.
2024-12-04 16:49:03 +01:00
Timm Bäder
12ca72ba7f Reapply "[clang][bytecode] Handle bitcasts involving bitfields (#116843)"
This reverts commit 54db16221c.

Check for existence of __SIZOEF_INT128__ so we don't run those
tests on targets that don't have int128.
2024-12-04 11:53:37 +01:00
Timm Bäder
54db16221c Revert "[clang][bytecode] Handle bitcasts involving bitfields (#116843)"
This reverts commit 4b5e7fa4de.

This breaks builders:
https://lab.llvm.org/buildbot/#/builders/154/builds/8464

I guess some more testing on 32 bit hosts is needed.
2024-12-04 11:43:43 +01:00
Timm Baeder
4b5e7fa4de [clang][bytecode] Handle bitcasts involving bitfields (#116843)
Copy the data one bit at a time, leaving optimizations for future work.
Adds a BitcastBuffer that takes care of pushing the bits in the right
order.
2024-12-04 11:25:04 +01:00
Timm Baeder
7802fb5f51 [clang][bytecode] Fix __extension__ handling for vector operators (#118482)
Don't reject them, but delegate to the subexpression.
2024-12-03 14:48:55 +01:00
Timm Baeder
ff0babc917 [clang][bytecode] Fix discarded pointer subtractions (#118477)
We need to pop the value.
2024-12-03 14:34:32 +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
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
dd0d9561b8 [clang][bytecode] Support vector-to-vector bitcasts (#118230) 2024-12-02 08:20:41 +01:00
Timm Baeder
31bde711c4 [clang][bytecode] Support __builtin_reduce_add (#117672) 2024-12-01 17:39:11 +01:00