189 Commits

Author SHA1 Message Date
Timm Bäder
293ae0b4b4 [clang][Interp] Actually consider ConstantExpr result
Since we have visitAPValue now, we might as well use it here.

Differential Revision: https://reviews.llvm.org/D158502
2023-09-14 09:27:56 +02:00
Timm Bäder
a7f256fb4c [clang][Interp][NFC] Use delegate() once more 2023-09-13 17:08:40 +02:00
Timm Bäder
87461d6696 [clang][Interp] Implement __builtin_offsetof
Differential Revision: https://reviews.llvm.org/D156400
2023-09-11 12:03:47 +02:00
Timm Bäder
2744d9b649 [clang][Interp][NFC] Use delegate() vor ParenExprs
Now what we have delegate() we can use it here.
2023-09-09 11:07:56 +02:00
Timm Bäder
211f7ddbe1 [clang][Interp][NFC] Tiny indentation fix 2023-09-09 11:07:55 +02:00
Timm Bäder
f8074942c5 [clang][Interp] Fix SourceLocExpr used in CXXDefaultInitExprs
... when initializing.

Fixes a problem pointed out in https://reviews.llvm.org/D156045/
2023-09-09 07:28:50 +02:00
Timm Bäder
92ac46e703 [clang][Interp] Handle CXXParenListInitExprs
Differential Revision: https://reviews.llvm.org/D156047
2023-09-06 15:26:54 +02:00
Timm Bäder
b93d2d37e7 [clang][Interp] Handle SourceLocExprs
Differential Revision: https://reviews.llvm.org/D155627
2023-09-06 14:45:49 +02:00
Timm Bäder
5704dde307 [clang][Interp] Reject calling virtual constexpr functions in pre-c++20
Differential Revision: https://reviews.llvm.org/D157619
2023-09-05 12:21:26 +02:00
Timm Bäder
adb1fb40e8 [clang][Interp] Handle mixed floating/integral compound assign operators
Differential Revision: https://reviews.llvm.org/D157596
2023-09-05 12:10:00 +02:00
Timm Bäder
6d79f985b5 [clang][Interp] Implement zero-init of record types
Differential Revision: https://reviews.llvm.org/D154189
2023-09-05 11:20:35 +02:00
Timm Bäder
12a789710e [clang][Interp] BaseToDerived casts
We can implement these similarly to DerivedToBase casts. We just have to
walk the class hierarchy, sum the base offsets and subtract it from the
current base offset of the pointer.

Differential Revision: https://reviews.llvm.org/D149133
2023-09-05 10:53:54 +02:00
Timm Bäder
ac56556047 [clang][Interp][NFC] Rename a parameter
We always call the expression parameter E.
2023-09-04 15:44:09 +02:00
Timm Bäder
1900721ae7 [clang][Interp][NFC] Check some emit* calls for errors
This doesn't make a difference right now but makes future commits
easier.
2023-09-04 15:42:33 +02:00
Mikhail Goncharov
c2647ed9b9 fix unused variables in condition warning
for 92023b15099012a657da07ebf49dd7d94a260f84
2023-08-30 17:39:54 +02:00
Timm Bäder
6dfe55569d [clang][Interp] Rework initializers
Before this patch, we had visitRecordInitializer() and
visitArrayInitializer(), which were different from the regular visit()
in that they expected a pointer on the top of the stack, which they
initialized. For example, visitArrayInitializer handled InitListExprs by
looping over the members and initializing the elements of that pointer.

However, this had a few corner cases and problems. For example, in
visitLambdaExpr() (a lambda is always of record type), it was not clear
whether we should always create a new local variable to save the lambda
to, or not. This is why https://reviews.llvm.org/D153616 changed
things around.

This patch changes the visiting functions to:

 - visit(): Always leaves a new value on the stack. If the expression
   can be mapped to a primitive type, it's just visited and the value is
   put on the stack. If it's of composite type, this function will
   create a local variable for the expression value and call
   visitInitializer(). The pointer to the local variable will stay on
   the stack.

 - visitInitializer(): Visits the given expression, assuming there is a
   pointer on top of the stack that will be initialized by it.

 - discard(): Visit the expression for side-effects, but don't leave a
   value on the stack.

It also adds an additional Initializing flag to differentiate between the initializing and non-initializing case.

Differential Revision: https://reviews.llvm.org/D156027
2023-08-20 13:33:08 +02:00
Timm Bäder
8a58f0d370 [clang][Interp] Handle global composite temporaries
We only did this for primitive temporaries.

Unfortunately, the existing Pointer::toAPValue() won't do here, since
we're expected to set an rvalue on the LifetimeExtendedTemporaryDecl.

Differential Revision: https://reviews.llvm.org/D144457
2023-08-20 11:15:17 +02: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
c4becd50ad [clang][Interp] Support __null
Differential Revision: https://reviews.llvm.org/D155552
2023-08-17 10:28:37 +02:00
Timm Bäder
8a25145058 [clang][Interp] Pass CallExpr to builtin functions
For some builtins, we need to do quite a bit of type checking ourselves,
so pass the call expression along. This way we can inspect arguments,
expected return value, etc.

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

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
015ffba811 [clang][Interp] Fix converting function pointers to bool
Differential Revision: https://reviews.llvm.org/D156786
2023-08-01 15:36:34 +02:00
Timm Bäder
21aa8a220c [clang][Interp] Fix ignoring Integral- and IntegralToBoolean casts
Differential Revision: https://reviews.llvm.org/D154474
2023-08-01 15:21:20 +02:00
Timm Bäder
65dca4cbcb [clang][Interp] Fix tests for ignored expressions
We didn't call the function explicitly in a static_assert() statement
and the checkPotentialConstantExpression() invocation quietly aborted
early because of the missing initializer for A::a.

Fix this by calling ignoredExprs() explicitly.

Differential Revision: https://reviews.llvm.org/D149965
2023-08-01 14:58:46 +02:00
Timm Bäder
eec6931d77 [clang][Interp] Fix ignoring String- and CharacterLiterals
Differential Revision: https://reviews.llvm.org/D149960
2023-08-01 12:23:57 +02:00
Timm Bäder
0d2e9b6e46 [clang][Interp][NFC] Ignore ArraySubScriptExpr like the other exprs
Instead of evaluating the entire thing and then pop'ing the value from
the stack, just pass the discard() on.
2023-08-01 12:14:20 +02:00
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