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
Timm Bäder
49c399c2d1
[clang][Interp] Toplevel destructors may fail
...
We used to run them, but not check if they failed. If they do,
the expression is invalid, even if we already have a result.
I do have a suspicion that we need to manually call destroyLocals()
in more places (everywhere basically?), but I'll wait with that
until I have a reproducer at hand.
2024-02-28 09:48:27 +01:00
Timm Bäder
b70f42a430
[clang][Interp] Handle PseudoObjectExprs
...
Evaluate all the semantic expressions.
2024-02-27 17:11:19 +01:00
Timm Bäder
d612d593ef
[clang][Interp] Fix local lvalue compound literals
...
Same fix we had for global ones: leave a pointer on the stack.
2024-02-27 16:57:17 +01:00
Timm Bäder
70e61f5bbb
[clang][Interp][NFC] Rename InitPtr{,Pop} to FinishInit{,Pop}
...
The old name clashes with the Init opcode.
2024-02-27 16:14:37 +01:00
Timm Bäder
b5048700fc
[clang][Interp] Fix lvalue CompoundLiteralExprs
...
We need to leave a pointer on the stack for them, even if their
type is primitive.
2024-02-26 16:39:43 +01:00
Timm Bäder
af971396a9
[clang][Interp] Handle missing Lambda field initializer
2024-02-26 13:16:35 +01:00
Timm Bäder
a5ccf8522b
[clang][Interp] Not all RVO call expressions are initializing
...
We do not necessarily prepare storage for the return value when
we are returning a complex value.
2024-02-26 11:40:58 +01:00
Timm Bäder
15426017bd
[clang][Interp] Handle non-complex operands in complex bin ops
...
Either LHS or RHS might be non-complex, but not both.
2024-02-26 09:08:50 +01:00
Timm Bäder
8c5e9cf737
[clang][Interp] Implement nullability argument checking
...
Implement constexpr checking for null pointers being passed to
arguments annotated as nonnull.
2024-02-26 06:19:25 +01:00
Timm Bäder
ad49fe3e89
[clang][Interp] Don't return success for already failed global variables
...
We might be visiting them more than once. We used to return true for
second and subsequent cases, just because we had already visited it
before.
2024-02-23 14:05:19 +01:00
Timm Bäder
13b0321e97
[clang][Interp][NFC] Reject unimplemented cast expressions differently
...
Instead of asserting, emit an appropriate diagnostic.
2024-02-21 17:26:29 +01:00
Timm Bäder
ffcdf47bc4
[clang][Interp] Allow adding an offset to a function pointer
...
Pretty sure this isn't doing anything, but it fixes a test and
is generally the right thing to do.
Fixing the behavior will come later.
2024-02-21 17:18:22 +01:00
Timm Bäder
91ebd010aa
[clang][Interp] Remove dereference()
...
This function tried to be smart about the dereferenced value,
but it ended up hurting more than it helped. At least in the current
state, where we still try get the correct output.
I might add something similar back later.
2024-02-21 15:25:55 +01:00
Timm Bäder
9bec1ef5f9
[clang][Interp] assignments aren't always lvalues in C
...
If they aren't we need to load from the pointer the Store op
leaves on the stack.
2024-02-20 12:26:15 +01:00
Timm Baeder
9fa18f6598
[clang][Interp] Handle complex values in visitBool() ( #79452 )
...
In C++, we get a ComplexToBool cast, but we might not in C.
2024-02-20 10:27:41 +01:00
Timm Bäder
48439bd7a7
[clang][Interp] Handle rewritten binary operators
...
Just delegate to the syntactic form.
2024-02-19 13:05:56 +01:00
Timm Bäder
21431e0f94
[clang][Interp] Remove questionable initializer special case
...
I'm not sure where this would be needed, but for the time being,
removing it fixes a problem.
2024-02-19 12:18:49 +01:00
Timm Bäder
e488fe5a97
[clang][Interp] Fix non-initializing MemberExprs
...
We need to create a value for them, do that via visit()
2024-02-19 11:57:01 +01:00