290 Commits

Author SHA1 Message Date
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
Timm Bäder
eddf9cf38a [clang][Interp] Fix failure to allocate local variables
We were incorrectly returning true when the allocateLocal() call
failed.
2024-02-19 11:52:13 +01:00
Timm Bäder
0b34d7e9e2 [clang][Interp] Fix calling static operators
They don't have an instance pointer anywhere but get one passed
via their CallExpr.
2024-02-19 10:34:18 +01:00
Timm Bäder
e98abc3ea0 [clang][Interp] Emit dtors when ignoring CXXConstructExprs
The comment says we should emit destructors, but we didn't.
2024-02-19 09:48:50 +01:00
Timm Bäder
fcf3ca9a5e [clang][Interp][NFC] Split emitRecordDestruction
into a general part and a record part. This will be needed in future
patches.
2024-02-19 09:23:31 +01:00
Timm Bäder
ba27c3963d [clang][Interp] Classify correct type for compound shifts
RT must be the type of the RHS, otherwise this later fails when
we set the RHS value to the temporary variable.
2024-02-18 16:31:40 +01:00
Timm Bäder
d228191c8b [clang][Interp] Create global variables for TemplateParamObjectDecls 2024-02-16 16:07:42 +01:00
Timm Bäder
a52c0c7700 [clang][Interp] Lazily visit constant locals in C++
While we _do_ get them registered via visitInitializer(), they
are still local, so gone on the next call to e.g. evaluateAsRValue().

Visit them lazily, similarly like we do in C.
2024-02-16 12:49:05 +01:00
Timm Bäder
f06e07be9a [clang][Interp][NFC] Check pointer compound assign operators for errors
This needs to be done but we didn't use to do it.
2024-02-16 12:30:24 +01:00
Timm Bäder
6a8ab12930 [clang][Interp] Properly emit call ops to invalid functions
Just like everywhere else, we can't just abort compilation because
a function is invalid. We need to emit the Call op and let later
interpretation handle the failure.

This fixes a long standing FIXME comment.
2024-02-15 20:17:51 +01:00
Timm Bäder
54826d4980 [clang][Interp] Emit dummy pointers for unknown static locals
We used to emit dummy pointers for unknown declarations in certain
cases in C, but this is also necessary in C++.

I'm limiting this to static local variables for now.
2024-02-15 18:12:47 +01:00
Timm Bäder
c81929e9a8 [clang][Interp][NFC] Return std::nullopt explicitly. 2024-02-15 17:49:31 +01:00
Timm Baeder
d68aa303fe
[clang][Interp] Do r-to-l conversion immediately when returning (#80662)
First, we need to register local constant variables in C, so we get the
same diagnostic behavior as the current interpeter.

Second, when returning an LValue (as a Pointer), which we eventually
convert to an RValue, we need to do the conversion immediately when
saving the Pointer in the EvaluationResult. Otherwise, we will possibly
deallocate the data before doing the conversion (which will look at the
Block*).
2024-02-15 15:13:12 +01:00
Timm Bäder
d53515afef [clang][Interp] Fix variadic member functions
For variadic member functions, the way we calculated the instance
pointer and RVO pointer offsts on the stack was incorrect, due
to Func->getArgSize() not returning the full size of all the
passed arguments. When calling variadic functions, we need
to pass the size of the passed (variadic) arguments to the Call*
ops, so they can use that information to properly check the
instance pointer, etc.

This patch adds a bit of code duplication in Interp.h, which I
will get rid of in later cleanup NFC patches.
2024-02-15 05:59:53 +01:00
Timm Bäder
bb60c066a2 [clang][Interp] Handle Requires- and ConceptSpecializationExprs
Just emit their satisfaction state, which is what the current
interpreter does as well.
2024-02-13 15:01:17 +01:00
Timm Bäder
9b718c0d5d [clang][Interp] Handle CXXUuidofExprs
Allocate storage and initialize it with the given APValue contents.
2024-02-13 13:41:06 +01:00
Timm Bäder
85e6e71eb0 [clang][Interp] Handle discarded PointerToIntegral casts
Resolve an old TODO comment.
2024-02-13 06:57:30 +01:00
Timm Bäder
15b0cc1212 [clang][Interp][NFC] Move a declaration into an if statement 2024-02-12 15:36:07 +01:00
Timm Bäder
b4c6ab600f [clang][Interp][NFC] Don't use visitLocalInitializer in visitExpr
We were unnecessarily getting the pointer of the local variable twice.
2024-02-10 18:01:30 +01:00
Timm Bäder
2cb61a1d11 [clang][Interp] Fix initializing PredefinedExprs 2024-02-09 11:54:40 +01:00
Timm Bäder
9e73656af5 [clang][Interp] Support ExpressionTraitExprs
Just push a constant bool value.
2024-02-09 10:23:54 +01:00
Timm Bäder
df2513c80b [clang][Interp] Fix three-way comparison detection
Instead of using !T && CPlusPlus, just check the BinaryOperator's
opcode. Turns out we also hit this code path for some assignments
of structs in C++.
2024-02-09 10:12:25 +01:00
Timm Bäder
06774d6bbf [clang][Interp] Handle CXXInheritedCtorInitExprs
We need to forward all arguments of the current function and
call the ctor function.
2024-02-08 15:36:07 +01:00
Timm Bäder
d4a2c7f952 [clang][Interp] Fix record initialization from temporary in initlist 2024-02-07 16:09:49 +01:00
Timm Bäder
61c7a69fa0 [clang][Interp] Fix sizeof of reference types 2024-02-07 13:32:07 +01:00
Timm Bäder
28b82075ff [clang][Interp] Support ImplicitValueInitExpr for complex types
Initialize both elements to 0, once again.
2024-02-07 08:26:47 +01:00
Timm Bäder
8c84096da1 [clang][Interp] Fix initializing _Complex values from DeclRefExpr
See the comment I added. When initializing a complex value from a
DeclRefExpr, we need to manually copy both array elements.
This adds some unfortunate code duplication that I'm still pondering
on how to get rid of best.
2024-02-07 08:07:05 +01:00
Timm Baeder
cc55af777a
[clang][Interp] Only check ComparisonCategoryInfo in C++ (#80131)
Binary operators are also of struct type in C, when assigning. Don't try to get the ComparisonCategoryInfo in that case.
2024-02-06 22:01:59 +01:00
Timm Bäder
26db3c3b72 [clang][Interp] Handle discarding ConstantExprs
Assume no side-effects in the presence of a cashed result in the form
of an APValue. This is also what the current interpreter does.
2024-02-06 14:32:21 +01:00
Timm Bäder
5e8626c920 [clang][Interp] Handle ObjCBoolLiteralExprs
Emit them just like the others, but these are integer typed.
2024-02-05 18:21:30 +01:00
Timm Baeder
4881cbd407
[clang][Interp] Fix MemberExpr initializing an existing value (#79973)
This is similar to c1ad363e6eba308fa94c47374ee98b3c79693a35, but with
the additional twist that initializing an existing value from a
`MemberExpr` was not working correctly.
2024-02-05 16:41:55 +01:00
Timm Baeder
e524ada6cb
[clang][Interp] Support zero init for complex types (#79728)
Initialize both elements to 0.
2024-02-05 15:56:06 +01:00
Timm Bäder
e4f1ef85fd [clang][Interp] Reject bitcasts to atomic types
The current interpreter does this, so follow suit to match its
diagnostics.
2024-02-05 15:45:26 +01:00
Timm Bäder
a2da7d06c7 [clang][Interp] Ignore LValueToRValue casts before doing the load
If the SubExpr results in an invalid pointer, we will otherwise
reject the constant expression.
2024-02-02 08:46:55 +01:00
Timm Bäder
58ceefe09c [clang][Interp] Support ChooseExprs 2024-02-02 08:20:52 +01:00
Timm Bäder
2147a2a4f3 [clang][Interp] Not all TypeTraitExprs are of bool type
In C, they return an integer, so emit their value as such.
2024-02-02 07:40:05 +01:00
Timm Bäder
48f8b74c35 [clang][Interp] Support GenericSelectionExprs
Just delegate to the resulting expression.
2024-02-01 08:15:11 +01:00
Timm Baeder
6ff431b01e
[clang][Interp] Handle imaginary literals (#79130)
Initialize the first element to 0 and the second element to the value of
the subexpression.
2024-02-01 07:13:10 +01:00
Timm Bäder
a8f317aeac [clang][Interp] complex binary operators aren't always initializing
The added test case would trigger the removed assertion.
2024-02-01 07:09:43 +01:00
Timm Bäder
dfd5a64da4 [clang][Interp] Remove wrong * operator
classifyComplexElementType used to return a std::optional, seems like
this was left in a PR and not re-tested.

This broke build bots, e.g.
https://lab.llvm.org/buildbot/#/builders/68/builds/67930
2024-01-31 17:00:42 +01:00
Timm Baeder
32c00485f1
[clang][Interp] Handle casts between complex types (#79269)
Just handle this like two primtive casts.
2024-01-31 16:53:33 +01:00
Timm Baeder
64a849a52e
[clang][Interp] Support arbitrary precision constants (#79747)
Add (de)serialization support for them, like we do for Floating values.
2024-01-31 10:00:42 +01:00
Timm Baeder
5bb99edcb6
[clang][Interp] Add inline descriptor to global variables (#72892)
Some time ago, I did a similar patch for local variables.

Initializing global variables can fail as well:
```c++
constexpr int a = 1/0;
static_assert(a == 0);
```
... would succeed in the new interpreter, because we never saved the
fact that `a` has not been successfully initialized.
2024-01-31 08:03:37 +01:00
Timm Bäder
ce75cbeda2 [clang][Interp][NFC] Don't unnecessarily use std::optional
classifyComplexElementType() doesn't return a std::optional anymore.
2024-01-27 09:06:04 +01:00
isuckatcs
c177507bd2
[clang][Interp] Cleaning up FIXMEs added during ArrayInitLoopExpr implementation. (#70053)
This patch removes the two `FIXME`s that were added with patches related
to the expression mentioned in the title.
2024-01-26 17:19:11 +01:00
Timm Bäder
dee02ee9f8 [clang][Interp][NFC] Complex elements can only be primitives
So, return a PrimType directly from classifyComplexElementType().
2024-01-24 12:56:16 +01:00
Timm Bäder
d38c61a13d [clang][Interp][NFC] Move ToVoid casts to the bottom
So we have all the complex casts together.
2024-01-23 15:02:08 +01:00
Timm Baeder
4e7cf1b1ed
[clang][Interp] Add an EvaluationResult class (#71315)
Add an `EvaluationResult` class. This contains the result either as a
`Pointer` or as a `APValue`.

This way, we can inspect the result of the evaluation and diagnose
problems with it (e.g. uninitialized fields in global initializers or
pointers pointing to things they shouldn't point to).
2024-01-19 10:08:03 +01:00
Timm Baeder
8b4bb15f6d
[clang][Interp] Implement integral->complex casts (#75590)
Allocate storage for them, initialize the first member with the given
value and the second member to 0.
2024-01-19 09:27:30 +01:00
Timm Baeder
18d0a7e4c0
[clang][Interp] Implement ComplexToReal casts (#77294)
Add a new emitComplexReal() helper function and use that for the new
casts as well as the old __real implementation.
2024-01-18 13:55:04 +01:00