150 Commits

Author SHA1 Message Date
Timm Baeder
ccb7cc319f
[clang][bytecode] Diagnose negative array sizes differently (#114380)
We have a special diagnostic ID for this.
2024-10-31 10:59:53 +01:00
Timm Baeder
f0b9a0ba06
[clang][bytecode] Diagnose delete with non-virtual dtor (#114373)
... in the base class.
2024-10-31 10:13:40 +01:00
Timm Baeder
87b6ec3be6
[clang][bytecode] Diagnose placement-new construction to inactive field (#114047)
We can reuse CheckActive() for this.
2024-10-29 15:08:41 +01:00
Timm Baeder
ec871cfcdf
[clang][bytecode][NFC] Remove Pointer::elem() (#114046)
Unused.
2024-10-29 15:00:36 +01:00
Timm Baeder
b46a0482f9
[clang][bytecode] Implement __builtin_arithmetic_fence (#113937) 2024-10-29 00:56:03 +01:00
Timm Baeder
7b88e7530d
[clang][bytecode][NFC] Make CheckVolatile static (#113785) 2024-10-27 05:06:47 +01:00
Timm Baeder
d5b42db00f
[clang][bytecode][NFC] Only do CheckConstant checks for global pointers (#113786)
We can check isStatic() early here and save ourselves some work.
2024-10-27 04:56:53 +01:00
Timm Baeder
46ad7ff4b7
[clang][bytecode] Diagnose non-const initialiers in diagnoseUnknownDecl (#113276)
This is more similar to the diagnostic output of the current interpreter
2024-10-23 05:50:30 +02:00
Timm Baeder
9ae41c24b3
[clang][bytecode] Create dummy pointers for non-reference DeclRefExprs (#113202)
... with non-constant initializers.
2024-10-22 10:38:13 +02:00
Timm Baeder
159f253017
[clang][bytecode] Diagnose invalid declrefs differently if we've... (#113140)
... tried their initializer already. In that case, diagnose the
non-const initializer instead of the reference to a non-constexpr
variable later. This is used in a lot of openmp tests.
2024-10-21 12:07:09 +02:00
Timm Baeder
923b8eea64
[clang][bytecode] Allow ArrayElemPtr ops on null pointers (#113132)
This regresses one of the _Complex test cases a bit, but since the
diagnostic output wasn't very good here in the first place, let's ignore
it.
2024-10-21 09:52:07 +02:00
Timm Baeder
615a5eb02c
[clang][bytecode] Check ai32_bextr builtins for integer args (#113128) 2024-10-21 08:15:51 +02:00
Timm Baeder
df8b785838
[clang][bytecode] Narrow pointer in UO_Deref unary operators (#113089)
Otherwise we treat this like an array element even though we should
treat it as a single object.
2024-10-21 07:51:49 +02:00
Timm Baeder
5405ba50de
[clang][bytecode] Check ia32_{pext,pdep} builtins for integer args (#113091) 2024-10-20 19:37:41 +02: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
3eaf4a9d1a
[clang][bytecode] Check for memory leaks after destroying global scope (#112868)
The global scope we create when evaluating expressions might free some
of the dynamic memory allocations, so we can't check for memory leaks
before destroying it.
2024-10-18 13:03:13 +02:00
Timm Baeder
9d0616ce52
[clang][bytecode] Ignore explicit calls to trivial dtors (#112841)
This is what the current interpreter does as well.
2024-10-18 09:45:02 +02:00
Timm Baeder
5d08625347
[clang][bytecode] Activate pointers in Init{,Pop} (#112832) 2024-10-18 07:38:22 +02:00
Timm Baeder
03888a9046
[clang][bytecode] Handle non-arrays in initElem{,Pop} (#112719)
... provided the given index is 0. Skip the atIndex() in that case.
2024-10-17 19:07:47 +02:00
Timm Bäder
1251687448 [clang][bytecode][NFC] Remove a leftover dump call 2024-10-17 12:40:14 +02:00
Timm Baeder
5b4071c755
[clang][bytecode] Explicitly truncate in IntegralAP::from() (#112683)
Add Integral::toAPInt(), which truncates to the given BitWidth, similar
to the toAPSInt() we already have.
2024-10-17 12:26:44 +02:00
Nikita Popov
255a99c29f
[APInt] Fix APInt constructions where value does not fit bitwidth (NFCI) (#80309)
This fixes all the places that hit the new assertion added in
https://github.com/llvm/llvm-project/pull/106524 in tests. That is,
cases where the value passed to the APInt constructor is not an N-bit
signed/unsigned integer, where N is the bit width and signedness is
determined by the isSigned flag.

The fixes either set the correct value for isSigned, set the
implicitTrunc flag, or perform more calculations inside APInt.

Note that the assertion is currently still disabled by default, so this
patch is mostly NFC.
2024-10-17 08:48:08 +02:00
yronglin
8079a2c578
[clang][bytecode] Diagnose reference to non-constexpr variable of const type in C23 constexpr (#112211)
```cpp
const int V33 = 4;
const int V34 = 0;
const int V35 = 2;

constexpr int V36 = V33 / V34;
// expected-error@-1 {{constexpr variable 'V36' must be initialized by a constant expression}}
constexpr int V37 = V33 / V35;
// expected-error@-1 {{constexpr variable 'V37' must be initialized by a constant expression}}
```

---------

Signed-off-by: yronglin <yronglin777@gmail.com>
2024-10-16 00:11:12 +08:00
Timm Baeder
790d986946
[clang][bytecode] Implement __builtin_f{maximum,minimum}_num (#112335) 2024-10-15 12:49:32 +02:00
Timm Baeder
51d0e40c2e
[clang][bytecode] Fix __builtin_convertvector with float-cast (#112238)
Comparing their PrimTypes isn't enough in this case. We can have a
floating cast here as well.
2024-10-15 07:49:55 +02:00
Timm Baeder
4c78c8cc21
[clang][bytecode] Fix discarding block expressions (#112185) 2024-10-14 15:11:39 +02:00
Timm Baeder
80c15c48d1
[clang][bytecode] Implement __builtin_assume_aligned (#111968) 2024-10-11 11:46:33 +02:00
Timm Baeder
ff04bb8f40
[clang][bytecode] Use PredefinedExpr as base for its variable (#111956)
This fixes the error message generated.
2024-10-11 09:31:49 +02:00
Timm Baeder
1fd79f105d
[clang][bytecode] Check number of addcarry/subborrow args (#111952)
Apparently this can fail as well.
2024-10-11 08:08:28 +02:00
Timm Baeder
36b0707767
[clang][bytecode] Return an lvalue path for dummy pointers (#111862)
Not doing this is wrong in general and we need to reject expressions
where it would matter differently.
2024-10-11 05:58:25 +02:00
Timm Baeder
55d51dd9dc
[clang][bytecode] Fix temporary lvalue base expression (#111808)
We need to use the MaterializeTemporaryExpr here so the checks in
ExprConstant.cpp do the right thing.
2024-10-10 14:10:38 +02:00
Timm Baeder
f1eac77617
[clang][bytecode] Check new builtins for integer types (#111801)
These might also be called with vectors, but we don't support that.
2024-10-10 10:23:59 +02:00
Timm Baeder
f93258e4ac
[clang][bytecode] Diagnose class-specific operator delete calls (#111700) 2024-10-10 08:40:14 +02:00
Timm Baeder
208584d91a
[clang][bytecode] Fix source range of uncalled base dtor (#111683)
Make this emit the same source range as the current interpreter.
2024-10-09 20:00:33 +02:00
Timm Baeder
e637a5c9fe
[clang][bytecode] Only allow lossless ptr-to-int casts (#111669)
Only allow those casts if the bitwidth of the two types match.
2024-10-09 17:13:22 +02:00
Timm Baeder
6f8e855150
[clang][bytecode] Implement __builtin_ai32_addcarryx* (#111671) 2024-10-09 15:42:19 +02:00
Timm Baeder
fed8695bb8
[clang][bytecode] Emit better diagnostic for invalid shufflevector index (#111643) 2024-10-09 09:56:37 +02:00
Timm Baeder
235067b222
[clang][bytecode] Make sure ia32_bzhi input is an integer (#111505) 2024-10-08 13:30:40 +02:00
Kazu Hirata
93f7fce397
[ByteCode] Avoid repeated hash lookups (NFC) (#111273) 2024-10-06 09:22:13 -07:00
Timm Baeder
c57418037a
[clang][bytecode] Handle UETT_OpenMPRequiredSimdAlign (#111259) 2024-10-05 18:04:06 +02:00
Timm Baeder
4e5f8a8f0b
[clang][bytecode] Save a per-Block IsWeak bit (#111248)
Checking the decl for every load is rather expensive.
2024-10-05 17:35:52 +02:00
bd1976bris
d2051919bb
[MSVC] work-around for compile time issue 102513 (#110986)
Disable optimizations when building clang/lib/AST/ByteCode/Interp.cpp
with Microsoft's compiler as it has a bug that causes excessive build
times. We do this only when NDEBUG is not defined on the assumption that
building without asserts indicates that a user is strongly invested in
runtime performance.

Partially addresses: https://github.com/llvm/llvm-project/issues/102513.

Once the bug is addressed in the Microsoft compiler this can be removed.

Co-authored-by: dyung
2024-10-04 14:59:41 +01:00
Timm Baeder
800b07396f
[clang][bytecode] Change isArrayElement() for narrowed composite arrays (#111110)
Make isArrayElement() return true here, so we can know that such a
pointer is in fact an array element and handle it properly in
toAPValue().
2024-10-04 14:19:32 +02:00
Timm Baeder
e1e788f423
[clang][bytecode] Protect ia32_{lzcnt,tzcnt} against non-integers (#110699)
These are also called for vectors.
2024-10-02 05:44:54 +02:00
Timm Baeder
f3baa73c8b
[clang][bytecode] Implement ia32_{pdep,pext} builtins (#110675) 2024-10-01 17:17:37 +02:00
Timm Baeder
55c70f6d89
[clang][bytecode] Check GetPtrBase ops for null pointers (#110673) 2024-10-01 17:09:26 +02:00
Timm Baeder
7147e88f55
[clang][bytecode] Implement lzcnt/tzcnt/bzhi builtins (#110639) 2024-10-01 12:04:32 +02:00
Timm Baeder
8518178857
[clang][bytecode] Implement ia32_bextr builitns (#110513) 2024-09-30 20:07:28 +02:00
Timm Baeder
3c85102756
[clang][bytecode] Handle DiscardResult for fixed-point literals (#110475) 2024-09-30 12:42:18 +02:00
Timm Baeder
79382eb97a
[clang][bytecode] Remove superfluous check from fixed-point div (#110478)
We shouldn't do this check for fixed-point values, at least the current
interpreter doesn't do it.
2024-09-30 12:13:21 +02:00