Commit Graph

63 Commits

Author SHA1 Message Date
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
819bd9e39b [clang][Interp] IndirectMember initializers (#69900)
We need to look at the chain of declarations to initialize the right
field.
2024-01-18 16:25:05 +01:00
Timm Baeder
b72732c37f [clang][Interp] Handle CXXTryStmts (#70584)
Just do the same thing the current interpreter does: Ignore all handlers
and visit the try block like normal.
2023-10-30 09:38:02 +01:00
Timm Baeder
de9b3c5eba [clang][Interp] Handle delegating constructors (#67823) 2023-10-16 14:11:25 +02:00
Timm Bäder
6172960cea [clang][Interp] Basic support for bit fields
Differential Revision: https://reviews.llvm.org/D155548
2023-10-10 13:38:26 +02:00
Timm Baeder
f58d54ab96 [clang][Interp] Diagnose uninitialized bases (#67131) 2023-10-03 06:46:31 +02:00
Timm Bäder
3935a18a5c [clang][Interp][NFC] Use GetPtrThisField intead of two ops 2023-09-24 09:56:48 +02:00
Timm Baeder
d462bd527a [clang][Interp] Handle AttributedStmts (#66495)
Just ignore the attributes.
2023-09-15 21:03:18 +02:00
Timm Bäder
73371faf05 [clang][Interp][NFC] Remove unused includes 2023-09-15 13:37:35 +02:00
Takuya Shimizu
01b88dd66d [NFC] Remove unused variables declared in conditions
D152495 makes clang warn on unused variables that are declared in conditions like `if (int var = init) {}`
This patch is an NFC fix to suppress the new warning in llvm,clang,lld builds to pass CI in the above patch.

Differential Revision: https://reviews.llvm.org/D158016
2023-08-30 10:05:06 +09:00
Timm Bäder
89361e2b98 [clang][Interp] Fix passing parameters of composite type
We pass these as pointers, so we need to be careful not to emit pointers
to pointers when we emit visit DeclRefExprs pointing to parameters.

Differential Revision: https://reviews.llvm.org/D153695
2023-08-17 12:08:10 +02:00
Timm Bäder
b56ab41d54 Revert "[clang][Interp] Basic support for bit fields"
This reverts commit 8065b1cc13.

This breaks builders. I forgot this depends
on https://reviews.llvm.org/D155548
2023-08-10 09:17:07 +02:00
Timm Bäder
8065b1cc13 [clang][Interp] Basic support for bit fields
Differential Revision: https://reviews.llvm.org/D155270
2023-08-10 08:50:10 +02:00
Timm Bäder
744a968f91 [clang][Interp] Fix return statements with expresssion in void functions
If the return type of a function is void, ReturnType is not set, but we
used to emit a RVOPtr instruction, which doesn't make sense for a
function returning void.

Differential Revision: https://reviews.llvm.org/D153649
2023-07-26 11:50:07 +02:00
Timm Bäder
7d876c62a3 [clang][Interp] Add 'Invalid' opcode and use it for throw stmts
We will use this opcode for conditionally executed statements that are
invalid in a constant expression.

Differential Revision: https://reviews.llvm.org/D150364
2023-07-26 08:59:53 +02:00
Timm Bäder
6d2e141e5c [clang][Interp] Handle lambda static invokers
Differential Revision: https://reviews.llvm.org/D150111
2023-07-26 08:42:16 +02:00
Timm Bäder
142bfaff7e [clang][Interp][NFC] Fix two small code style problems 2023-07-23 10:31:22 +02:00
Timm Bäder
25d6123854 [clang][Interp] Make sure we have a variable scope for initializers
Otherwise, we run into an assertion when trying to use the current
variable scope while creating temporaries for constructor initializers.

Differential Revision: https://reviews.llvm.org/D147534
2023-04-13 15:35:30 +02:00
Timm Bäder
ee71cbddb7 [clang][Interp] Ignore more non-VarDecl declarations
They are harmless and handled by other means, but we used to return
false from visitDeclStmt.

Differential Revision: https://reviews.llvm.org/D145861
2023-04-04 10:41:46 +02:00
Timm Bäder
192c2c5c89 [clang][Interp] Ignore StaticAssertDecls
They have already been handled before, but we can't just return false
when we encounter one.

Differential Revision: https://reviews.llvm.org/D144272
2023-04-03 16:56:58 +02:00
Timm Bäder
243b355ee0 [clang][Interp] Support destructors
Emit destructors for non-primitive (array) variables on scope ends.

Differential Revision: https://reviews.llvm.org/D145545
2023-03-30 13:17:04 +02:00
HerrCai0907
73f9a0c923 Fix typo: statment to statement; NFC
Differential Revision: https://reviews.llvm.org/D145834
2023-03-13 11:51:28 -04:00
Timm Bäder
5e12002c6c Revert "[clang][Interp] Support destructors"
This reverts commit 78e4237460.

This breaks the memory sanitizer builder:
https://lab.llvm.org/buildbot/#/builders/5/builds/31959
2023-03-05 13:18:13 +01:00
Timm Bäder
78e4237460 [clang][Interp] Support destructors
Use the existing local variable cleanup infrastructure to implement
destruction.

Differential Revision: https://reviews.llvm.org/D137070
2023-03-05 10:02:42 +01:00
Timm Bäder
2708869801 Re-land "[clang][Interp] Implement C++ Range-for loops"
Differential Revision: https://reviews.llvm.org/D140803
2023-03-04 15:17:44 +01:00
Timm Bäder
43e67707f9 Revert "[clang][Interp] Implement C++ Range-for loops"
This reverts commit bce8b3c183.

This commit breaks memory-sanitizer builds:
https://lab.llvm.org/buildbot/#/builders/5/builds/31899
2023-03-02 11:04:09 +01:00
Timm Bäder
bce8b3c183 [clang][Interp] Implement C++ Range-for loops
Differential Revision: https://reviews.llvm.org/D140803
2023-03-02 08:59:07 +01:00
Timm Bäder
730eca6a3d [clang][Interp] Handle DecompositionDecls
Differential Revision: https://reviews.llvm.org/D138802
2023-03-01 17:11:57 +01:00
Timm Bäder
8b70d97c39 [clang][Interp][NFC] Use InitThisField in initializers
This creates fewer instructions, makes the bytecode easier to read and
InitThisField also cares about checkingPotentialConstantExpression()
cases.
2023-01-25 16:59:19 +01:00
Timm Bäder
024e4f16ca [clang][Interp] Implement switch statements
Differential Revision: https://reviews.llvm.org/D137415
2023-01-25 13:21:24 +01:00
Timm Bäder
3665da3d00 Re-commit "[clang][Interp] Unify visiting variable declarations"
We often visit the same variable multiple times, e.g. once when checking
its initializer and later when compiling the function. Unify both of
those in visitVarDecl() and do the returning of the value in
visitDecl().

This time, use a VariableScope instead of a DeclScope for local
variables. This way, we don't emit Destroy ops for the local variables
immediately after creating them.

Differential Revision: https://reviews.llvm.org/D136815
2023-01-21 10:23:53 +01:00
Timm Bäder
8df7e818de Revert "[clang][Interp] Unify visiting variable declarations"
This reverts commit 5b54cf1a28.

This breaks a builder: https://lab.llvm.org/buildbot/#/builders/5/builds/30854
2023-01-19 13:52:47 +01:00
Timm Bäder
5b54cf1a28 [clang][Interp] Unify visiting variable declarations
We often visit the same variable multiple times, e.g. once when checking
its initializer and later when compiling the function. Unify both of
those in visitVarDecl() and do the returning of the value in
visitDecl().

Differential Revision: https://reviews.llvm.org/D136815
2023-01-19 10:46:16 +01:00
Timm Bäder
865094746e [clang][Interp] Track initialization state of local variables
Use an InlineDescriptor per local variable to track whether locals
have been initialized or not. This way we can support uninitialized
local variables in constexpr functions.

Differential Revision: https://reviews.llvm.org/D135750
2023-01-18 16:55:02 +01:00
Timm Bäder
d4f1f35978 [clang][Interp][NFC] Move to std::optional 2022-12-05 17:31:49 +01:00
Timm Bäder
7c215a4571 [clang][Interp] Explicitly handle RVO Pointer
The calling convention is:

[RVO pointer]
[instance pointer]
[... args ...]

We handle the instance pointer ourselves, BUT for the RVO pointer, we
just assumed in visitReturnStmt() that it is on top of the stack. Which
isn't true if there are other args present (and a this pointer, maybe).

Fix this by recording the RVO pointer explicitly when creating an
InterpFrame, just like we do with the instance/This pointer.

There is already a "RVOAndParams()" test in test/AST/Inter/records.cpp,
that was supposed to test this, however, it didn't trigger any
problematic behavior because the parameter and the return value have the
same type.

Differential Revision: https://reviews.llvm.org/D137392
2022-11-30 10:37:57 +01:00
Timm Bäder
99d3ead44c [clang][Interp] Protect Record creation against infinite recursion
This happens only in error cases, but we need to handle it anyway.

Differential Revision: https://reviews.llvm.org/D136831
2022-11-11 08:38:06 +01:00
Timm Bäder
5bd6bd1227 [clang][Interp][NFC] Simplify visitReturnStmt() 2022-11-07 09:42:41 +01:00
Timm Bäder
9a3b969d1f [clang][Interp][NFC] Make InitField() not pop the pointer
This was confusing. InitElem peeks a pointer, while InitElemPop will
pop the pointer. However, for fields, InitField would pop the pointer
and no InitFieldPop exists. At least make InitField and InitElem behave
the same.
2022-11-07 08:30:43 +01:00
Timm Bäder
0ccff030f3 [clang][Interp] Fix record members of reference type
When assigning to them, we can't classify the expression type, because
that doesn't contain the right information.

And when reading from them, we need to do the extra deref, just like we
do when reading from a DeclRefExpr.

Differential Revision: https://reviews.llvm.org/D136012
2022-10-28 16:34:45 +02:00
Timm Bäder
751f1bfb5f [clang][Interp][NFC] Assert we have a valid Record instance 2022-10-26 08:49:31 +02:00
Timm Bäder
f6f02e0900 [clang][Interp] Implement for loops
Differential Revision: https://reviews.llvm.org/D135764
2022-10-26 08:48:36 +02:00
Timm Bäder
9cb4e90e72 [clang][Interp] Support base class constructors
Differential Revision: https://reviews.llvm.org/D135025
2022-10-21 10:49:45 +02:00
Timm Bäder
5a859432f3 [clang][Interp] Implement while and do-while loops
Differential Revision: https://reviews.llvm.org/D135433
2022-10-14 14:41:05 +02:00
Timm Bäder
33b52836de [clang][Interp] Fix using default copy constructors
Implement ArrayInitLoopExprs, which are used in copy constructors to
copy arrays. Also fix problems encountered while doing that.

Differential Revision: https://reviews.llvm.org/D134361
2022-10-14 10:21:53 +02:00
Timm Bäder
cb5f205828 [clang][Interp] Implement nested struct initialization
Recurse into visitInitializer() if necessary.

Differential Revision: https://reviews.llvm.org/D134175
2022-10-14 10:21:53 +02:00
Timm Bäder
0ddd13acc9 [clang][Interp] Implement This pointer passing to methods
Implement passing the this pointer to member functions and constructors.
The this pointer is passed via the stack. This changes the functions to
explicitly track whether they have a RVO pointer and a this pointer.

Differential Revision: https://reviews.llvm.org/D134699
2022-10-14 10:21:53 +02:00
Timm Bäder
1942a2538b [clang][Interp] Start implementing record types
Implement simple constructors as well as member access expressions.

Differential Revision: https://reviews.llvm.org/D134057
2022-10-14 10:21:53 +02:00
Timm Bäder
3a7d476087 [clang][Interp] Implement array initializers and subscript expressions
Differential Revision: https://reviews.llvm.org/D132727
2022-09-08 07:31:07 +02:00
Timm Bäder
aa7c5c9c4e [clang][Interp] Handle missing local initializers better
This is illegal in a constexpr context. We can already figure that out,
but we'd still run into an assertion later on when trying to visit the
missing initializer or run the invalid function.

Differential Revision: https://reviews.llvm.org/D132832
2022-09-08 07:31:07 +02:00