135 Commits

Author SHA1 Message Date
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
Timm Bäder
cef69ce779 [clang][Interp] Fix record initialization via CallExpr subclasses
We can't just use VisitCallExpr() here, as that doesn't handle CallExpr
subclasses such as CXXMemberCallExpr.

Differential Revision: https://reviews.llvm.org/D141772
2023-03-31 13:16:49 +02:00
Timm Bäder
30f96a8fb4 [clang][Interp] Properly identify not-yet-defined functions
Since we now handle functions without a body as well, we can't just use
getHasBody() anymore. Funtions that haven't been defined yet are those
that don't have a body *and* aren't valid.

Also, just pass the information about whether the Function has a body or
not along from the FunctionDecl.

Differential Revision: https://reviews.llvm.org/D141591
2023-03-31 07:27:04 +02:00
Timm Bäder
3ad167329a [clang][Interp] Implement function pointers
Differential Revision: https://reviews.llvm.org/D141472
2023-03-30 15:37:49 +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
Kazu Hirata
7eaa7b0553 [clang] Use *{Map,Set}::contains (NFC) 2023-03-15 18:06:34 -07:00
Timm Bäder
5e12002c6c Revert "[clang][Interp] Support destructors"
This reverts commit 78e4237460bf58f3d6b75f275e0424f38e3b1d04.

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
33ba940de0 [clang][Interp][NFCI] Support more expression in initializers 2023-03-05 09:57:52 +01:00
Timm Bäder
90d921fa1f [clang][Interp] Handle record initialization via CastExpr
Differential Revision: https://reviews.llvm.org/D140808
2023-03-02 10:08:41 +01:00
Timm Bäder
6b5afda61c [clang][Interp] Add ArrayElemPtr{,Pop} opcode
We usually access array elements in the same pattern, which uses
narrow(). Add an extra opcode for this. This saves us quite some
instructions and makes the bytecode easier to read.

Differential Revision: https://reviews.llvm.org/D140805
2023-03-02 09:45:18 +01:00
Timm Bäder
f18b71d14f [clang][Interp] Implement remaining MaterializeTemporaryExpr bits
As well as support for CompoundLiteralExprs.

Differential Revision: https://reviews.llvm.org/D140668
2023-03-02 07:51:54 +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
4a2c4acb98 [clang][Interp] Support pointers in compound assignment operators
Differential Revision: https://reviews.llvm.org/D140874
2023-02-03 16:42:46 +01:00
Timm Bäder
a7f3bcaa84 [clang][Interp][NFCI] Handle DiscardResult for ExprWithCleanups
Just pop the pointer.
2023-02-03 16:07:14 +01:00
Timm Bäder
7bb615ea0e [clang][Interp] Materializing primitive temporaries
Implement MaterializeTemporaryExpr for primitive types.

Differential Revision: https://reviews.llvm.org/D136017
2023-02-03 15:11:15 +01:00
Timm Bäder
7b966e2156 [clang][Interp][NFC] Add GetPtrBasePop opcode
Change GetPtrBase to *not* pop the base pointer and add a *Pop variant.
This will be used in later patches.
2023-01-27 08:05:53 +01:00
Timm Bäder
5bf56a5877 [clang][Interp][NFCI] Don't crash on void builtin functions
classifyPrim() runs into a llvm_unreachable() for those.
2023-01-26 07:32:33 +01:00
Timm Bäder
d2ea8ae5d4 [clang][Interp] Implement logical and/or operators
Differential Revision: https://reviews.llvm.org/D140809
2023-01-26 06:52:35 +01:00
Timm Bäder
eee8075f57 [clang][Interp][NFCI] Remove an unnecessary DupPtr op
When initializing a primitive array, we don't need to dup the base
pointer for every element.
2023-01-25 17:09:33 +01:00
Timm Bäder
5de6b94f85 [clang][Interp][NFC] Replace remaining dyn_cast_or_null uses 2023-01-25 16:39:26 +01:00
Timm Bäder
af3a171dcf [clang][Interp] Compound assign operators for FP values
Differential Revision: https://reviews.llvm.org/D140377
2023-01-25 16:25:04 +01:00
Timm Bäder
cb7f582211 Re-apply "[clang][Interp] Support floating-point values"
Don't move the Repr struct into Integral this time.

Differential Revision: https://reviews.llvm.org/D134859
2023-01-25 15:13:09 +01:00
Timm Bäder
b3b1d86137 Revert "[clang][Interp] Support floating-point values"
This reverts commit 62f43c3eae2460d4ca3da7897fd2d7c56920638c.

This breaks a couple of builders, e.g.

https://lab.llvm.org/buildbot/#/builders/139/builds/34925
2023-01-25 14:48:39 +01:00
Timm Bäder
62f43c3eae [clang][Interp] Support floating-point values
Add a new Floating type and a few new opcodes to support floating point
values.

Differential Revision: https://reviews.llvm.org/D134859
2023-01-25 14:41:26 +01:00
Timm Bäder
0a3243de62 [clang][Interp] Array initialization via string literal
Differential Revision: https://reviews.llvm.org/D137488
2023-01-25 14:22:05 +01:00
Timm Bäder
a7a4463acb [clang][Interp] Start implementing builtin functions
Differential Revision: https://reviews.llvm.org/D137487
2023-01-25 14:08:03 +01:00
Timm Bäder
f4a6842c5a [clang][Interp] Reject invalid declarations and expressions
Reject them early, since we will run into problems and/or assertions
later on anyway.

Differential Revision: https://reviews.llvm.org/D137386
2023-01-25 12:52:44 +01:00