263 Commits

Author SHA1 Message Date
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
Timm Baeder
12e425d0cf
[clang][Interp] Support __real/__imag on primitives (#75485) 2024-01-15 16:08:22 +01:00
Timm Bäder
826fe84a2c [clang][Interp][NFC] Remove outdated FIXME comment
Virtual desturctors are already supported and tested in
AST/Interp/records.cpp.
2024-01-15 12:03:59 +01:00
Timm Baeder
fc2766c1d4
[clang][Interp] Diagnose reads from non-const global variables (#71919)
This fixes a long-standing FIXME item.

Unfortunately it changes the diagnostic output of the tests added in
`cxx23.cpp`, but they were wrong before and are wrong after, so no big
deal.
2024-01-13 05:51:03 +01:00
Timm Baeder
e80b943647
[clang][Interp] Fix discarded integral and floating casts (#77295)
We need to handle this at the CastExpr level.
2024-01-10 20:19:04 +01:00
Timm Bäder
f32662a40b [clang][Interp][NFC] Remove outdated FIXME comment
This rework has already happened.
2023-12-15 14:30:44 +01:00
Timm Bäder
d16cf470ac [clang][Interp] Start implementing binary operators for complex types
Differential Revision: https://reviews.llvm.org/D155572
2023-12-14 15:33:52 +01:00
Timm Bäder
88abd530ef [clang][Interp] Allow evaluating standalone complex expressions
We reach visitExpr() when evaluating standalone expressions. However,
the RetValue() code path was unused before, because we never reach it,
even with structs or arrays.

RetValue expects a pointer on the stack it can take apart to return an
APValue, so provide it with one.

Differential Revision: https://reviews.llvm.org/D150661
2023-12-14 15:07:42 +01:00
Timm Bäder
935f5ee9c9 [clang][Interp] ComplexFloatingToBoolean casts
Differential Revision: https://reviews.llvm.org/D150654
2023-12-14 13:17:40 +01:00
Timm Bäder
497480b38a [clang][Interp] IntegralComplexToBoolean casts
Differential Revision: https://reviews.llvm.org/D148426
2023-12-14 13:11:00 +01:00
Timm Bäder
07e3c245ba [clang][Interp] Support empty initlist initializers for complex types
Differential Revision: https://reviews.llvm.org/D147369
2023-12-14 12:53:40 +01:00
Timm Bäder
797fee68d1 [clang][Interp] Start supporting complex types
Differential Revision: https://reviews.llvm.org/D146408
2023-12-14 11:57:38 +01:00
Timm Bäder
9406d2a345 [clang][Interp][NFC] Remove unused include 2023-12-07 15:20:22 +01:00
Timm Bäder
489df61a29 [clang][Interp][NFC] const qualify a local variable 2023-11-27 11:17:49 +01:00
Timm Bäder
4a8b43ba3b [clang][Interp][NFC] Factor array element init into its own function 2023-11-20 13:00:57 +01:00
Timm Baeder
965d301dff
[clang][Interp] Implement __builtin_classify_type (#71972)
This adds some infrastructure for unevaluated builtin calls, and uses the implementation from ExprConstant.cpp
2023-11-17 16:13:23 +01:00
Timm Baeder
216dfd5ff0
[clang][Interp] Fix stack peek offset for This ptr (#70663)
`Function::getArgSize()` include both the instance and the RVO pointer,
so we need to subtract here.
2023-11-14 16:22:22 +01:00
Timm Baeder
190b9179a5
[clang][Interp] Handle SizeOfPackExprs (#71929) 2023-11-12 05:34:16 +01:00
Timm Bäder
7b1a058021 [clang][Interp][NFC] Use direct Get{Local,Global} when possible
When returning variable declaration values, try to get the value
directly instead of always going through a Pointer.
2023-11-10 11:30:38 +01:00
Timm Baeder
feedb7c0db
[clang][Interp] Fix IntAP(s) to IntAP(s) casts (#69915)
This was still assert(false)'ed out, it's for casts between two IntAP/IntAPS expressions.
We can't just short-circuit for FromT == ToT because we need to consider the bitwidth when doing the cast.
2023-11-06 15:13:43 +01:00
Timm Bäder
8a1719d3ed [clang][Interp][NFC] Use delegate() in VisitCXXBindTemporaryExpr 2023-10-30 17:20:27 +01:00
Timm Bäder
051fade10f [clang][Interp][NFC] Use delegate() address-of operators 2023-10-27 10:43:35 +02:00
Timm Baeder
e01efddbf3
[clang][Interp] Correctly emit destructors for multi-dimensional arrays (#69140)
We were not taking those into account correctly when emitting
destructors. Fix that and add tests for it.

Fixes #69115
2023-10-26 14:51:30 +02:00
Timm Baeder
658874e084
[clang][Interp] Handle unknown-size arrays better (#68868)
We unfortunately actually need to do some checks for array-to-pointer
decays it seems.
2023-10-26 13:53:54 +02:00
Timm Bäder
b4fc1418d9 [clang][Interp] Fix ArrayInitLoop common expr life time
The local variable needs to survive for all the interations of the
ArrayInitLoopExpr. So, visit it explicitly before we iterate.
2023-10-24 12:20:02 +02:00
Timm Baeder
b44763c5e6
[clang][Interp] Fix scalar inits of void type (#69868) 2023-10-24 09:18:39 +02:00
isuckatcs
9022f40212
[clang][Interp] Only evaluate the source array initialization of an ArrayInitLoopExpr once (#68039)
This patch implements an `OpaqueValueExpr` caching functionality in `Interp`
by storing the result of the expression in a local variable.
2023-10-23 17:52:27 +02:00
Timm Bäder
311f725d9a [clang][Interp] Create only globals when initializing a global variable
For this code:

struct O {
  int &&j;
};

O o1(0);

The generated AST for the initializer of o1 is:

VarDecl 0x62100006ab08 <array.cpp:119:3, col:9> col:5 o1 'O':'O' parenlistinit
`-ExprWithCleanups 0x62100006b250 <col:7, col:9> 'O':'O'
  `-CXXParenListInitExpr 0x62100006b210 <col:7, col:9> 'O':'O'
    `-MaterializeTemporaryExpr 0x62100006b1f0 <col:8> 'int' xvalue
      `-IntegerLiteral 0x62100006abd0 <col:8> 'int' 0

Before this patch, we create a local temporary variable for the
MaterializeTemporaryExpr and destroy it again when destroying the
EvalEmitter we create to interpret the initializer. However, since
O::j is a reference, this reference now points to a local variable
that doesn't exist anymore.

Differential Revision: https://reviews.llvm.org/D156453
2023-10-19 14:50:17 +02:00