162 Commits

Author SHA1 Message Date
Timm Bäder
c0a36a157d [clang][Interp] Fix ignoring CompoundLiteralExprs
Differential Revision: https://reviews.llvm.org/D149837
2023-08-01 11:48:04 +02:00
Timm Bäder
b864592915 [clang][Interp] Fix ignoring TypeTraitExprs
Differential Revision: https://reviews.llvm.org/D149834
2023-08-01 10:58:08 +02:00
Timm Bäder
c7b400f4a8 [clang][Interp] Fix ignoring SubstNonTypeTemplateParmExpr
Ignore the expressions and re-do the tests without all the "result
ignored" expected warnings. Those are expected, given the nature of the
tests.

Differential Revision: https://reviews.llvm.org/D149831
2023-08-01 10:25:16 +02:00
Timm Bäder
6aac11bad9 [clang][Interp] Evaluate Base when discarding a MemberExpr
The Base expression might cause side-effects, so we still have to
evaluate it.

Differential Revision: https://reviews.llvm.org/D149828
2023-08-01 10:16:31 +02:00
Timm Bäder
97cddb7850 [clang][Interp] Fix ignoring MaterializeTemporaryExprs
Differential Revision: https://reviews.llvm.org/D154475
2023-08-01 09:45:33 +02:00
Timm Bäder
9092acc510 [clang][Interp] Emit proper diagnostic when comparing unrelated pointers
Differential Revision: https://reviews.llvm.org/D149172
2023-07-28 13:23:48 +02:00
Timm Bäder
7010a4f14e [clang][Interp] Don't assume throw stmts have a subexpr
Differential Revision: https://reviews.llvm.org/D156503
2023-07-28 12:44:53 +02:00
Timm Bäder
ae4849f967 [clang][Interp] PointerToIntegral casts
Differential Revision: https://reviews.llvm.org/D150946
2023-07-26 13:39:37 +02:00
Timm Bäder
378fcbf20f [clang][Interp] Handle CXXNoexceptExprs
Differential Revision: https://reviews.llvm.org/D155707
2023-07-26 12:23:54 +02:00
Timm Bäder
8c0246c7f5 [clang][Interp] Reject reinterpret_casts
Add a new InvalidCast op for this purpose and emit a diagnostic.

Differential Revision: https://reviews.llvm.org/D153276
2023-07-26 09:56:29 +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
2606545b02 [clang][Interp] Fix ignoring conditional operators
Differential Revision: https://reviews.llvm.org/D148982
2023-07-26 07:46:04 +02:00
Timm Bäder
aed9646d8e [clang][Interp] Fix discarding void-typed comma expressions
First, we need to handle void types in visitExpr, so we don't run into
an assertion there when we try to pop a return value from the stack
that isn't there.

Secondly, we need to handle it when visiting comma expressions so we
don't do the same thing there.

Differential Revision: https://reviews.llvm.org/D148925
2023-07-26 07:45:02 +02:00
Timm Bäder
e45d199768 [clang][Interp] Handle CXXTemporaryObjectExprs
This is a CXXConstructExpr, so create a local temporary variable and
initialize it.

Differential Revision: https://reviews.llvm.org/D147591
2023-07-26 07:36:26 +02:00
Timm Bäder
10020791b1 [clang][Interp] Call invalid destructors
We need to call them like any other function, so we can generate proper
diagnostics.

Differential Revision: https://reviews.llvm.org/D150040
2023-07-26 07:19:02 +02:00
Timm Bäder
78e774e0c8 [clang][Interp] Handle __extension__ unary operators
Differential Revision: https://reviews.llvm.org/D148690
2023-07-26 07:16:45 +02:00
Timm Bäder
8cb6e476cc [clang][Interp] Handle PtrMemOps
Differential Revision: https://reviews.llvm.org/D144164
2023-07-26 07:04:21 +02:00
Timm Bäder
25b7417bba [clang][Interp][NFC] Use existing local variable
Instead of calling getSubExpr() again.
2023-07-23 10:27:51 +02:00
Timm Bäder
a1c0e3be6f [clang][Interp] Fix compound assign operator evaluation order
We need to evaluated the RHS before the LHS.

Differential Revision: https://reviews.llvm.org/D149550
2023-07-20 15:58:01 +02:00
Timm Bäder
465f65a549 [clang][Interp][NFC] Add a debugging assertion
We will probably have to remove this at some point, but until then, make
sure we're not running into much-harder-to-debug problems later on.
2023-07-20 14:06:09 +02:00
Timm Bäder
ddbd8ffe31 [clang][Interp][NFC] Move a declaration into an if statement 2023-07-13 13:45:48 +02:00
Timm Bäder
254ad7dd41 [clang][Interp][NFC] Move isGloballyIndexed() to Context
And use it in Program as well, to make a similar decision.
2023-07-09 16:27:49 +02:00
Timm Bäder
c319694731 [clang][Interp][NFC] Compare std::optional variables directly
We can do that and we already checked that they aren't nullopt before.
2023-06-27 11:36:42 +02:00
Timm Bäder
1e9ac71787 [clang][Interp] Handle PredefinedExprs
Differential Revision: https://reviews.llvm.org/D148689
2023-06-16 15:52:12 +02:00
Timm Bäder
461f91b1e4 [clang][Interp] Handle LambdaExprs
Differential Revision: https://reviews.llvm.org/D146030
2023-06-16 10:05:33 +02:00
Timm Bäder
976d8b40cc [clang][Interp] Virtual function calls
Add a CallVirt opcode and implement virtual function calls this way.

Differential Revision: https://reviews.llvm.org/D142630
2023-06-15 13:33:43 +02:00
Timm Bäder
710749f786 [clang][Interp] Optionally cast comparison result to non-bool
Our comparison opcodes always produce a Boolean value and push it on the
stack. However, the result of such a comparison in C is int, so the
later code expects an integer value on the stack.

Work around this problem by casting the boolean value to int in those
cases. This is not ideal for C however. The comparison is usually
wrapped in a IntegerToBool cast anyway.

Differential Revision: https://reviews.llvm.org/D149645
2023-06-01 10:36:33 +02:00
Timm Bäder
2e676fad26 Revert "[clang][Interp] Optionally cast comparison result to non-bool"
This reverts commit 81522a012accfcc6bbf4dfa21a793aea6e4e532a.

Looks like we're not ready for this yet:
https://lab.llvm.org/buildbot/#/builders/139/builds/41797
2023-05-31 13:07:40 +02:00
Timm Bäder
81522a012a [clang][Interp] Optionally cast comparison result to non-bool
Our comparison opcodes always produce a Boolean value and push it on the
stack. However, the result of such a comparison in C is int, so the
later code expects an integer value on the stack.

Work around this problem by casting the boolean value to int in those
cases. This is not ideal for C however. The comparison is usually
wrapped in a IntegerToBool cast anyway.

Differential Revision: https://reviews.llvm.org/D149645
2023-05-31 13:01:01 +02:00
Timm Bäder
c3f1faf96f [clang][Interp][NFC] Fix allocateLocalPrimitive parameter name
This is passed on to Program::createDescriptor, where it is used as a
value for IsConst.
2023-05-04 13:45:14 +02:00
Timm Bäder
0354f31b51 [clang][Interp][NFC] Don't cast primitive types to the same type
We might classify different clang types to the same interp types, so
skip the cast in that case.

No test attached since this is already exercised a few times in the
existing tests.
2023-05-04 09:53:15 +02:00
Timm Bäder
338c2489f6 [clang][Interp] Implement inc/dec operators for floats
Differential Revision: https://reviews.llvm.org/D149634
2023-05-04 08:52:53 +02:00
Timm Bäder
fd4c302c41 [clang][Interp][NFC] Call discard() when discarding ExprWithCleanups 2023-05-04 08:45:14 +02:00
Timm Bäder
92f67dc27f [clang][Interp] Handle DiscardResult for DeclRef- and ParenExprs
Fixes https://github.com/llvm/llvm-project/issues/62004

Differential Revision: https://reviews.llvm.org/D147840
2023-05-04 08:22:06 +02:00
Timm Bäder
7d0938bf2c [clang][Interp][NFC] Make OptionScope final 2023-05-02 06:16:49 +02:00
Timm Bäder
c9e403d199 [clang][Interp] Fix zero-init of float and pointer arrays
Our Zero opcode only exists for integer types. Use
visitZeroInitializer() here as well so it works for floats and pointers.

Differential Revision: https://reviews.llvm.org/D149059
2023-04-25 09:00:47 +02:00
Timm Bäder
7766648c3a [clang][Interp] PointerToBoolean casts
Just emit e != nullptr for these.

Differential Revision: https://reviews.llvm.org/D148981
2023-04-25 08:04:08 +02:00
Timm Bäder
8aea6e004f [clang][Interp][NFC] Take a QualType in visitZeroInitializer()
The given expression is not necessarily usable to obtain a type for,
so we can't use it to get the floating point semantics. Pass a QualType
instead, which we can use--and classify() that here.
2023-04-24 17:58:15 +02:00
Timm Bäder
f508d9b1d4 [clang][Interp] Don't create global variables more than once
just because we're being told to evaluate it twice. This sometimes
happens when a variable is evaluated again during codegen.

Differential Revision: https://reviews.llvm.org/D147535
2023-04-13 15:41:43 +02:00
Timm Bäder
70e5a2a943 [clang][Interp] Fix zero-initializing of floating types
Differential Revision: https://reviews.llvm.org/D146788
2023-04-06 10:52:01 +02:00
Timm Bäder
47ee8519ec [clang][Interp][NFC] Context: Add getFloatSemantics()
We use this quite a bit, so add some convenience API for it.
2023-04-06 10:39:49 +02:00
Timm Bäder
4016e5d949 [clang][Interp][NFC] Call emit*Ptr directly
Instead of the version that uses a switch statement to figure this out.
2023-04-06 10:25:57 +02:00
Timm Bäder
92417f2d4b [clang][Interp] Record initialization via conditional operator
Differential Revision: https://reviews.llvm.org/D141497
2023-04-06 09:44:02 +02:00
Timm Bäder
b15a946b9f [clang][Interp][NFC] Refactor VisitDeclRefExpr
Make it clearer that we only need to check for variables and parameters
if we don't have the easy case. Also only do the IsReference check if
necessary.
2023-04-03 16:42:25 +02:00
Timm Bäder
056042d21b [clang][Interp] Fix initializing fields after base class members
Differential Revision: https://reviews.llvm.org/D145860
2023-04-03 15:55:11 +02:00
Timm Bäder
58cf70b2cd [clang][Interp] Fix diagnostics for calling non-constexpr constructors
Differential Revision: https://reviews.llvm.org/D145841
2023-04-03 15:42:08 +02:00
Timm Bäder
db3dcdc08c [clang][Interp] Fix initializing base class members
For the given test case, we were trying to initialize a member of C,
which doesn't have any. Get the proper base pointer instead and
initialize the members there.

Differential Revision: https://reviews.llvm.org/D143466
2023-04-03 13:51:04 +02:00
Timm Bäder
968b4172f6 [clang][Interp] Fix derived-to-base casts for >1 levels
The GetPtrBasePop op we were using only works for direct base classes.

Differential Revision: https://reviews.llvm.org/D143480
2023-04-03 11:35:55 +02:00
Timm Bäder
8d2899acbc [clang][Interp] Handle TypeTraitExprs
Differential Revision: https://reviews.llvm.org/D142448
2023-03-31 15:54:44 +02:00
Timm Bäder
d29f70670d [clang][Interp] Fix binary comma operators
We left the result of RHS on the stack in case DiscardResult was true.

Differential Revision: https://reviews.llvm.org/D141784
2023-03-31 14:54:51 +02:00