357 Commits

Author SHA1 Message Date
Danial Klimkin
e57b872414
Avoid unusable variable in ByteCodeExprGen.cpp (#90469)
Inline assert to avoid unusable variable warning/error when asserts are
disabled.
2024-04-29 15:23:29 +02:00
Timm Bäder
f5ed917046 [clang][Interp] Fix creating variables for TemplateParamObjectDecls
Actually initialize them with their value. While at it, fix doing
it for non-primitive (only struct so far) types as well.
2024-04-29 14:34:33 +02:00
Timm Bäder
f2452d4b68 [clang][Interp] Implement zero-init for record types 2024-04-29 13:02:31 +02:00
Timm Bäder
15f02723d4 [clang][Interp] Improve support for virtual bases
Fix initializing virtual bases. We only consider their base size,
not their virtual size because they get flattened into the Record
hierarchy when we create them. Fix that and also virtual
derived-to-base casts.
2024-04-26 11:10:45 +02:00
Timm Bäder
bc8a4ea110 [clang][Interp][NFC] Move collectBaseOffset() to Context
We will need this outside of ByteCodeExprGen later.
2024-04-26 10:21:27 +02:00
Timm Bäder
15883684a7 [clang][Interp] Fix casting pointers to int128 2024-04-22 14:39:24 +02:00
Timm Bäder
103f1be76f [clang][Interp][NFC] getRecord() might return null 2024-04-22 14:39:24 +02:00
Timm Bäder
c2d665b7ae [clang][Interp] Support ImplicitArrayInitExpr for vectors 2024-04-22 10:58:55 +02:00
Timm Bäder
0ff992e5f2 [clang][Interp][NFC] Get ComplexType directly
Instead of doing a isa<> + getAs<>
2024-04-22 10:34:43 +02:00
Timm Bäder
fd98f80f60 [clang][Interp] Finish initializing structs from CompoundLiteralExprs 2024-04-18 10:31:31 +02:00
Timm Bäder
562f061e7e [clang][Interp] Load result of pre-inc/dec operation if necessary
This can happen in C.
2024-04-18 08:30:09 +02:00
Timm Bäder
9099f6f8dc [clang][Interp] Skip unnamed bit fields in initializers
Fixes the Codegen/CSKY/csky-hard-abi.c test
2024-04-18 08:19:36 +02:00
Timm Bäder
75054525ae [clang][Interp] Implement VectorSplat casts 2024-04-16 19:31:16 +02:00
Timm Bäder
32b74ca6e4 [clang][Interp] Load value from MemberExpr if required 2024-04-16 13:04:28 +02:00
Timm Bäder
c09384e2b4 [clang][Interp] Support MemberExprs pointing to VarDecls 2024-04-16 12:34:35 +02:00
Timm Bäder
31424be3ae [clang][Interp][NFC] Compare std::optionals directly 2024-04-16 12:09:49 +02:00
Timm Bäder
58b49cef1d [clang][Interp] Support __builtin_vectorelements 2024-04-16 11:21:41 +02:00
Timm Bäder
9141e1c24f [clang][Interp] Gracefully handle bitcasts to non-primitive types
We were calling classfiyPrim() instead of classify().
2024-04-16 11:08:30 +02:00
Timm Bäder
64c3997939 [clang][Interp] Allow initializing static class members
We need to handle this when registering global variables.
2024-04-11 19:05:29 +02:00
Timm Baeder
1709eac58f
[clang][Interp] Integral pointers (#84159)
This turns the current `Pointer` class into a discriminated union of
`BlockPointer` and `IntPointer`. The former is what `Pointer` currently
is while the latter is just an integer value and an optional
`Descriptor*`.

The `Pointer` then has type check functions like
`isBlockPointer()`/`isIntegralPointer()`/`asBlockPointer()`/`asIntPointer()`,
which can be used to access its data.

Right now, the `IntPointer` and `BlockPointer` structs do not have any
methods of their own and everything is instead implemented in Pointer
(like it was before) and the functions now just either assert for the
right type or decide what to do based on it.

This also implements bitcasts by decaying the pointer to an integral
pointer.

`test/AST/Interp/const-eval.c` is a new test testing all kinds of stuff
related to this. It still has a few tests `#ifdef`-ed out but that
mostly depends on other unimplemented things like
`__builtin_constant_p`.
2024-04-10 12:53:54 +02:00
Timm Bäder
b7a93bc1f2 [clang][Interp] Start implementing vector types
Map them to primtive arrays, much like complex types.
2024-04-10 10:45:06 +02:00
Timm Bäder
3f71d29e23 [clang][Interp] Handle __unaligned in alignof expressions 2024-04-09 16:06:36 +02:00
NAKAMURA Takumi
d08a76d1ac Fix warnings discovered by #87348 [-Wunused-but-set-variable] 2024-04-07 11:02:08 +09:00
Chris B
28ddbd4a86
[NFC] Refactor ConstantArrayType size storage (#85716)
In PR #79382, I need to add a new type that derives from
ConstantArrayType. This means that ConstantArrayType can no longer use
`llvm::TrailingObjects` to store the trailing optional Expr*.

This change refactors ConstantArrayType to store a 60-bit integer and
4-bits for the integer size in bytes. This replaces the APInt field
previously in the type but preserves enough information to recreate it
where needed.

To reduce the number of places where the APInt is re-constructed I've
also added some helper methods to the ConstantArrayType to allow some
common use cases that operate on either the stored small integer or the
APInt as appropriate.

Resolves #85124.
2024-03-26 14:15:56 -05:00
Timm Bäder
6aaf9c8309 [clang][Interp][NFC] Sanitize collectBaseOffset parameters 2024-03-19 10:07:23 +01:00
Timm Bäder
d56110fa02 [clang][Interp] Fix _Complex comma operators
Handle them before shelling out to visitComplexBinOp().
2024-03-18 16:02:40 +01:00
Timm Bäder
c2f75c7159 [clang][Interp] Handle CXXDefaultInitExpr of composite type 2024-03-18 12:59:56 +01:00
Timm Bäder
a4b39f6515 [clang][Interp] Lazily visit const-qualified static data members in C++ 2024-03-17 18:07:51 +01:00
Timm Bäder
0211389064 [clang][Interp] Handle __datasizeof. 2024-03-17 16:33:39 +01:00
Timm Bäder
8e69052b0e [clang][Interp] Handle ArrayTypeTraitExprs 2024-03-16 12:46:28 +01:00
Timm Bäder
72d85b0315 [clang][Interp] Emit Error op for contains-error expressions
Instead of aborting interpretation right away. This way we can still
successfully evaluate such functions provided we don't reach the
Error op at all.
2024-03-15 10:52:58 +01:00
Timm Bäder
719e077a56 [clang][Interp] Handle PackIndexExprs 2024-03-15 10:04:23 +01:00
Timm Bäder
797994da3c [clang][Interp] Strip _Atomic from _Complex types
... when doing binary operations on them.
2024-03-14 16:55:38 +01:00
Timm Bäder
2cd19df792 [clang][Interp] Allow visiting extern variables
If the variable is additionally const(expr), visit them like normal
but omit the initializer.
2024-03-14 15:39:28 +01:00
Timm Bäder
160693dbde [clang][Interp][NFC] allocateLocalPrimitive never fails
It returns the local offset, not an std::optional.
2024-03-14 14:57:24 +01:00
Timm Bäder
a99b912c9b [clang][Interp] Create dummy pointers for external variables
This way we can use their address, which is necessary in some
scenarios. This requires us to create different descriptors
for dummy arrays so we can get the diagnostics right.
2024-03-14 14:35:44 +01:00
Timm Bäder
b97c12936d [clang][Interp] Fix non-primitive ltor casts
This doesn't happen in C++ since it will instead call the
struct's copy constructor. However, in C, this needs to work.
2024-03-14 13:55:55 +01:00
Timm Bäder
103469b5f7 [clang][Interp] Implement more easy _Complex unary operators 2024-03-12 08:51:12 +01:00
Timm Bäder
1dd104db59 [clang][Interp] Implement _Complex Not unary operators
This only happens in C as far as I can tell. The complex varialbe
will have undergone a conversion to bool in C++ before reaching
the unary operator.
2024-03-12 07:48:56 +01:00
Timm Bäder
d02d8df0cd [clang][Interp] Implement _Complex negation
Factor complex unary operations into their own function.
2024-03-12 05:34:57 +01:00
Timm Bäder
9e4f289bd6 [clang][Interp][NFC] Add [[nodiscard]] attribute to emit functions 2024-03-07 19:37:52 +01:00
Timm Bäder
b1f2e19dc2 [clang][Interp][NFC] Use ArrayElem{,Pop} ops more often
Instead of the longer ArrayElemPtr + Load.
2024-03-07 17:47:01 +01:00
Timm Bäder
8aed911fe9 [clang][Interp] Implement complex comparisons 2024-03-07 17:04:05 +01:00
Timm Bäder
bc9c6c0c65 [clang][Interp][NFC] Remove ByteCodeGenError
Unused.
2024-03-04 17:46:08 +01:00
Timm Bäder
89e41e2965 [clang][Interp] Implement __builtin_complex 2024-03-04 17:15:42 +01:00
Timm Bäder
57f599d644 [clang][Interp] Improve handling of external variables
Further down in this function, we assert that the variable has
an initializer, which didn't work for external declarations.
2024-03-02 17:40:16 +01:00
Timm Bäder
68516bfd2f [clang][Interp] Lambda This captures can be non-pointers
If they are captured by value.
2024-03-01 18:06:18 +01:00
Timm Bäder
f15d799f16 [clang][Interp] Fix variadic operator calls
Operator calls pass their instance member explicitly, so remove
it from NumParams when calling a variadic function
2024-03-01 15:46:00 +01:00
Timm Bäder
990dbf2b7e [clang][Interp] OpaqueValueExprs can have null subexprs 2024-03-01 10:12:50 +01:00
Timm Bäder
ddfc7e2254 [clang][Interp] Emit more dummy pointers in C++ mode 2024-02-29 10:04:42 +01:00