202 Commits

Author SHA1 Message Date
Timm Bäder
18461dc454 [clang][Interp] Add IntegralAP for arbitrary-precision integers (#65844) 2023-10-01 07:11:07 +02:00
Timm Bäder
4bae636abf Revert "[clang][Interp] Add IntegralAP for arbitrary-precision integers (#65844)"
This reverts commit 16b9e6fbac4c0bd94c66e7670a41b5c266cf7bff.

This breaks buildbots.
2023-09-30 20:12:14 +02:00
Timm Baeder
16b9e6fbac
[clang][Interp] Add IntegralAP for arbitrary-precision integers (#65844)
This adds `IntegralAP` backing the two new primtypes `IntAP` (unsigned
arbitrary-precision int) and `IntAPS` (same but signed).

We use this for `int128` support (which isn't available on all host
systems we support AFAIK) and I think we can also use this for `_BitInt`
later.
2023-09-30 20:08:22 +02:00
Timm Baeder
4909e7cac7
[clang][Interp] Zero-init remaining string literal elements (#66862) 2023-09-30 08:28:09 +02:00
Timm Baeder
512739ebbb
[clang][Interp] Three-way comparisons (#65901) 2023-09-29 09:41:58 +02:00
Timm Bäder
765b38fbf1 [clang][Interp][NFC] Small code refactoring 2023-09-20 14:33:46 +02:00
Timm Bäder
52a55a7178 [clang][Interp] Allow zero-init of primitives with an empty init list
Differential Revision: https://reviews.llvm.org/D158595
2023-09-18 11:09:30 +02:00
Timm Bäder
23c39f9a9e [clang][Interp] Diagnose unknown parameter values
Differential Revision: https://reviews.llvm.org/D156509
2023-09-15 13:10:19 +02:00
Timm Bäder
cd2f2c1662 [clang][Interp] Visit Logical-not operand as bool
Differential Revision: https://reviews.llvm.org/D157200
2023-09-15 10:12:20 +02:00
Timm Bäder
d485fc40f3 [clang][Interp][NFC] Fix a comment typo 2023-09-15 09:55:52 +02:00
Timm Bäder
a259005a21 [clang][Interp] Convert logical binop operands to bool
Differential Revision: https://reviews.llvm.org/D157174
2023-09-15 09:52:41 +02:00
Timm Bäder
6d73cca186 [clang][Interp] Lazily visit unknown global declarations
In C, we don't get a evaluateAsInitializer() call for all global
declarations, yet we have to handle DeclRefExpr pointing to them.

Differential Revision: https://reviews.llvm.org/D156794
2023-09-15 08:50:21 +02:00
Timm Bäder
d61ba038a9 [clang][Interp][NFC] Call delegate() for the RHS of a comma op 2023-09-14 13:36:51 +02:00
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