225 Commits

Author SHA1 Message Date
Timm Baeder
216dfd5ff0
[clang][Interp] Fix stack peek offset for This ptr (#70663)
`Function::getArgSize()` include both the instance and the RVO pointer,
so we need to subtract here.
2023-11-14 16:22:22 +01:00
Timm Baeder
190b9179a5
[clang][Interp] Handle SizeOfPackExprs (#71929) 2023-11-12 05:34:16 +01:00
Timm Bäder
7b1a058021 [clang][Interp][NFC] Use direct Get{Local,Global} when possible
When returning variable declaration values, try to get the value
directly instead of always going through a Pointer.
2023-11-10 11:30:38 +01:00
Timm Baeder
feedb7c0db
[clang][Interp] Fix IntAP(s) to IntAP(s) casts (#69915)
This was still assert(false)'ed out, it's for casts between two IntAP/IntAPS expressions.
We can't just short-circuit for FromT == ToT because we need to consider the bitwidth when doing the cast.
2023-11-06 15:13:43 +01:00
Timm Bäder
8a1719d3ed [clang][Interp][NFC] Use delegate() in VisitCXXBindTemporaryExpr 2023-10-30 17:20:27 +01:00
Timm Bäder
051fade10f [clang][Interp][NFC] Use delegate() address-of operators 2023-10-27 10:43:35 +02:00
Timm Baeder
e01efddbf3
[clang][Interp] Correctly emit destructors for multi-dimensional arrays (#69140)
We were not taking those into account correctly when emitting
destructors. Fix that and add tests for it.

Fixes #69115
2023-10-26 14:51:30 +02:00
Timm Baeder
658874e084
[clang][Interp] Handle unknown-size arrays better (#68868)
We unfortunately actually need to do some checks for array-to-pointer
decays it seems.
2023-10-26 13:53:54 +02:00
Timm Bäder
b4fc1418d9 [clang][Interp] Fix ArrayInitLoop common expr life time
The local variable needs to survive for all the interations of the
ArrayInitLoopExpr. So, visit it explicitly before we iterate.
2023-10-24 12:20:02 +02:00
Timm Baeder
b44763c5e6
[clang][Interp] Fix scalar inits of void type (#69868) 2023-10-24 09:18:39 +02:00
isuckatcs
9022f40212
[clang][Interp] Only evaluate the source array initialization of an ArrayInitLoopExpr once (#68039)
This patch implements an `OpaqueValueExpr` caching functionality in `Interp`
by storing the result of the expression in a local variable.
2023-10-23 17:52:27 +02:00
Timm Bäder
311f725d9a [clang][Interp] Create only globals when initializing a global variable
For this code:

struct O {
  int &&j;
};

O o1(0);

The generated AST for the initializer of o1 is:

VarDecl 0x62100006ab08 <array.cpp:119:3, col:9> col:5 o1 'O':'O' parenlistinit
`-ExprWithCleanups 0x62100006b250 <col:7, col:9> 'O':'O'
  `-CXXParenListInitExpr 0x62100006b210 <col:7, col:9> 'O':'O'
    `-MaterializeTemporaryExpr 0x62100006b1f0 <col:8> 'int' xvalue
      `-IntegerLiteral 0x62100006abd0 <col:8> 'int' 0

Before this patch, we create a local temporary variable for the
MaterializeTemporaryExpr and destroy it again when destroying the
EvalEmitter we create to interpret the initializer. However, since
O::j is a reference, this reference now points to a local variable
that doesn't exist anymore.

Differential Revision: https://reviews.llvm.org/D156453
2023-10-19 14:50:17 +02:00
Timm Baeder
59d2dc239b
[clang][Interp] IntegralAP zero-initializers (#68081) 2023-10-19 08:20:53 +02:00
Timm Bäder
3c4ecc4628 [clang][Interp][NFC] Refactor VisitImplicitValueInitExpr
The FIXME comment here is not really correct. Also, handle the case of
non-primitive array element types differently, to reduce indentation.
2023-10-15 08:52:43 +02:00
Timm Bäder
80737d2ddf [clang][Interp][NFC] Pass PrimType to visitZeroInitializer()
This fixes an old FIXME comment. Almost all callers already classify()
the type anyway, so just pass the result of that
to visitZeroInitializer().
2023-10-14 18:43:00 +02:00
Timm Baeder
a653749aca
[clang][Interp] Implement compound assign operators on bitfields (#67306) 2023-10-14 09:17:35 +02:00
Timm Baeder
26d9f851cf
[clang][Interp] Add basic support for _BitInt (#68069)
Make sure we pass the expected bitwidth around when casting to
IntAP/IntAPS.

This makes it easier to test the `IntegralAP` code for different bit
widths than 128.
2023-10-11 08:53:21 +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
12107386ca
[clang][Interp] Handle CXXScalarValueInitExprs (#67147)
Handle those by just zero-initializing the result.
2023-10-10 12:45:09 +02:00
Timm Baeder
2bed2a7a5c
[clang][Interp] Emit dummy values for unknown C variables (#66749)
We can't load anything from them, but we can still take their address or
return them as lvalues.
2023-10-07 16:00:19 +02:00
Timm Bäder
57147bb253 [clang][Interp] Support LambdaThisCaptures
Differential Revision: https://reviews.llvm.org/D154262
2023-10-05 09:46:15 +02:00
Timm Bäder
4d7f4a7c82 [clang][Interp] Only lazily visit constant globals
Differential Revision: https://reviews.llvm.org/D158516
2023-10-05 09:37:37 +02:00
Timm Baeder
f58d54ab96
[clang][Interp] Diagnose uninitialized bases (#67131) 2023-10-03 06:46:31 +02:00
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