36 Commits

Author SHA1 Message Date
Timm Bäder
d53515afef [clang][Interp] Fix variadic member functions
For variadic member functions, the way we calculated the instance
pointer and RVO pointer offsts on the stack was incorrect, due
to Func->getArgSize() not returning the full size of all the
passed arguments. When calling variadic functions, we need
to pass the size of the passed (variadic) arguments to the Call*
ops, so they can use that information to properly check the
instance pointer, etc.

This patch adds a bit of code duplication in Interp.h, which I
will get rid of in later cleanup NFC patches.
2024-02-15 05:59:53 +01:00
Timm Bäder
ba451c80ba [clang][Interp][NFC] Only set result invalid if empty
This is currently NFC but required for later changes. A Ret op
might fail and set the result to invalid, causing another setInvalid()
call, which asserts that the result is still empty.
2024-02-10 19:45:10 +01:00
Timm Baeder
4e7cf1b1ed
[clang][Interp] Add an EvaluationResult class (#71315)
Add an `EvaluationResult` class. This contains the result either as a
`Pointer` or as a `APValue`.

This way, we can inspect the result of the evaluation and diagnose
problems with it (e.g. uninitialized fields in global initializers or
pointers pointing to things they shouldn't point to).
2024-01-19 10:08:03 +01:00
Timm Bäder
797fee68d1 [clang][Interp] Start supporting complex types
Differential Revision: https://reviews.llvm.org/D146408
2023-12-14 11:57:38 +01: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
3fe2be75c0 [clang][Interp] Call destructors of local variables
Differential Revision: https://reviews.llvm.org/D154581
2023-10-24 08:57:59 +02:00
Timm Bäder
368a39882d Revert "[clang][Interp] Call destructors of local variables"
This reverts commit 3671a69470f3fa708926a9e5ce579751c6b51dac.

This breaks builders, e.g.
https://lab.llvm.org/buildbot/#/builders/245/builds/15697
2023-10-24 06:48:29 +02:00
Timm Bäder
3671a69470 [clang][Interp] Call destructors of local variables
This prevents us from leaking memory if the interpretation of byte code
fails midway-throug.

Differential Revision: https://reviews.llvm.org/D154581
2023-10-24 06:27:10 +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 Bäder
f4aabc2d9d [clang][Interp][NFC] Clean up EvalEmitter includes 2023-09-24 10:22:34 +02:00
Timm Bäder
235dad3328 [clang][Interp][NFC] Make some variables const 2023-08-17 07:54:37 +02:00
Timm Bäder
df5213c442 [clang][Interp][NFC] Return a const pointer from Pointer::getRecord() 2023-07-04 17:21:51 +02:00
Timm Bäder
0a6c8c1b25 [clang][Interp][NFC] Add a helper function for local variables
... in EvalEmitter.
2023-01-25 16:57:59 +01:00
Timm Bäder
d54ae905d1 [clang][Interp][NFC] Rename InlineDescptor::IsMutable to IsFieldMutable 2023-01-23 10:32:51 +01:00
Timm Bäder
b7894ebf84 [clang][Interp] Initialize remaining InlineDescriptor fields
for local variables. Hoping this will please msan.
2023-01-20 10:04:16 +01:00
Timm Bäder
865094746e [clang][Interp] Track initialization state of local variables
Use an InlineDescriptor per local variable to track whether locals
have been initialized or not. This way we can support uninitialized
local variables in constexpr functions.

Differential Revision: https://reviews.llvm.org/D135750
2023-01-18 16:55:02 +01:00
Timm Bäder
d4f1f35978 [clang][Interp][NFC] Move to std::optional 2022-12-05 17:31:49 +01:00
Timm Bäder
0e754cfadc [clang][Interp][NFC] Unify Call() implementations
The type parameter we used to pass to call() was unused. Use the same
implementation for void and value-returning function calls.
2022-10-22 10:32:05 +02:00
Timm Bäder
cc79ddb52c [clang][Interp] Check instance pointers before calling functions on them
Remove the double Call() implementation to reduce code duplication. Then
fix Function::getSource() so we can diagnose instance pointers being
null.

Differential Revision: https://reviews.llvm.org/D135513
2022-10-22 10:32:05 +02:00
Timm Bäder
55c7ad31aa [clang][Interp][NFC] Pass Function* pointers around as const 2022-10-14 12:31:24 +02:00
Benjamin Kramer
2f357054d7 [Interp] Silence warning in release builds. NFC. 2022-10-14 10:38:32 +02:00
Timm Bäder
0ddd13acc9 [clang][Interp] Implement This pointer passing to methods
Implement passing the this pointer to member functions and constructors.
The this pointer is passed via the stack. This changes the functions to
explicitly track whether they have a RVO pointer and a this pointer.

Differential Revision: https://reviews.llvm.org/D134699
2022-10-14 10:21:53 +02:00
Timm Bäder
8e41e6a4ea [clang][Interp] Implement function calls
Add Call() and CallVoid() ops and use them to call functions. Only
FunctionDecls are supported for now.

Differential Revision: https://reviews.llvm.org/D132286
2022-09-08 07:31:07 +02:00
Nandor Licker
950b70dcc7 [Clang Interpreter] Initial patch for the constexpr interpreter
Summary:
This patch introduces the skeleton of the constexpr interpreter,
capable of evaluating a simple constexpr functions consisting of
if statements. The interpreter is described in more detail in the
RFC. Further patches will add more features.

Reviewers: Bigcheese, jfb, rsmith

Subscribers: bruno, uenoku, ldionne, Tyker, thegameg, tschuett, dexonsmith, mgorny, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D64146

llvm-svn: 371834
2019-09-13 09:46:16 +00:00
Roman Lebedev
2c9f83cfab Revert "[Clang Interpreter] Initial patch for the constexpr interpreter"
Breaks BUILD_SHARED_LIBS build, introduces cycles in library dependency
graphs. (clangInterp depends on clangAST which depends on clangInterp)

This reverts r370839, which is an yet another recommit of D64146.

llvm-svn: 370874
2019-09-04 10:57:06 +00:00
Nandor Licker
32f82c9cba [Clang Interpreter] Initial patch for the constexpr interpreter
Summary:
This patch introduces the skeleton of the constexpr interpreter,
capable of evaluating a simple constexpr functions consisting of
if statements. The interpreter is described in more detail in the
RFC. Further patches will add more features.

Reviewers: Bigcheese, jfb, rsmith

Subscribers: bruno, uenoku, ldionne, Tyker, thegameg, tschuett, dexonsmith, mgorny, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D64146

llvm-svn: 370839
2019-09-04 05:49:41 +00:00
Nandor Licker
c3bdad8c1e Revert [Clang Interpreter] Initial patch for the constexpr interpreter
This reverts r370636 (git commit 8327fed9475a14c3376b4860c75370c730e08f33)

llvm-svn: 370642
2019-09-02 11:34:47 +00:00
Nandor Licker
8327fed947 [Clang Interpreter] Initial patch for the constexpr interpreter
Summary:
This patch introduces the skeleton of the constexpr interpreter,
capable of evaluating a simple constexpr functions consisting of
if statements. The interpreter is described in more detail in the
RFC. Further patches will add more features.

Reviewers: Bigcheese, jfb, rsmith

Subscribers: bruno, uenoku, ldionne, Tyker, thegameg, tschuett, dexonsmith, mgorny, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D64146

llvm-svn: 370636
2019-09-02 10:38:08 +00:00
Nandor Licker
a6bef738bf Revert [Clang Interpreter] Initial patch for the constexpr interpreter
This reverts r370584 (git commit afcb3de117265a69d21e5673356e925a454d7d02)

llvm-svn: 370588
2019-08-31 15:15:39 +00:00
Nandor Licker
afcb3de117 [Clang Interpreter] Initial patch for the constexpr interpreter
Summary:
This patch introduces the skeleton of the constexpr interpreter,
capable of evaluating a simple constexpr functions consisting of
if statements. The interpreter is described in more detail in the
RFC. Further patches will add more features.

Reviewers: Bigcheese, jfb, rsmith

Subscribers: bruno, uenoku, ldionne, Tyker, thegameg, tschuett, dexonsmith, mgorny, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D64146

llvm-svn: 370584
2019-08-31 15:00:38 +00:00
Nandor Licker
0300c3536a Revert [Clang Interpreter] Initial patch for the constexpr interpreter
This reverts r370531 (git commit d4c1002e0bbbbab50f6891cdd2f5bd3a8f3a3584)

llvm-svn: 370535
2019-08-30 21:32:00 +00:00
Nandor Licker
d4c1002e0b [Clang Interpreter] Initial patch for the constexpr interpreter
Summary:
This patch introduces the skeleton of the constexpr interpreter,
capable of evaluating a simple constexpr functions consisting of
if statements. The interpreter is described in more detail in the
RFC. Further patches will add more features.

Reviewers: Bigcheese, jfb, rsmith

Subscribers: bruno, uenoku, ldionne, Tyker, thegameg, tschuett, dexonsmith, mgorny, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D64146

llvm-svn: 370531
2019-08-30 21:17:03 +00:00
Nandor Licker
5c8b94a672 Revert [Clang Interpreter] Initial patch for the constexpr interpreter
This reverts r370476 (git commit a5590950549719d0d9ea69ed164b0c8c0f4e02e6)

llvm-svn: 370481
2019-08-30 15:41:45 +00:00
Nandor Licker
a559095054 [Clang Interpreter] Initial patch for the constexpr interpreter
Summary:
This patch introduces the skeleton of the constexpr interpreter,
capable of evaluating a simple constexpr functions consisting of
if statements. The interpreter is described in more detail in the
RFC. Further patches will add more features.

Reviewers: Bigcheese, jfb, rsmith

Subscribers: bruno, uenoku, ldionne, Tyker, thegameg, tschuett, dexonsmith, mgorny, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D64146

llvm-svn: 370476
2019-08-30 15:02:09 +00:00