43 Commits

Author SHA1 Message Date
Timm Baeder
1709eac58f
[clang][Interp] Integral pointers (#84159)
This turns the current `Pointer` class into a discriminated union of
`BlockPointer` and `IntPointer`. The former is what `Pointer` currently
is while the latter is just an integer value and an optional
`Descriptor*`.

The `Pointer` then has type check functions like
`isBlockPointer()`/`isIntegralPointer()`/`asBlockPointer()`/`asIntPointer()`,
which can be used to access its data.

Right now, the `IntPointer` and `BlockPointer` structs do not have any
methods of their own and everything is instead implemented in Pointer
(like it was before) and the functions now just either assert for the
right type or decide what to do based on it.

This also implements bitcasts by decaying the pointer to an integral
pointer.

`test/AST/Interp/const-eval.c` is a new test testing all kinds of stuff
related to this. It still has a few tests `#ifdef`-ed out but that
mostly depends on other unimplemented things like
`__builtin_constant_p`.
2024-04-10 12:53:54 +02:00
Timm Bäder
b7a93bc1f2 [clang][Interp] Start implementing vector types
Map them to primtive arrays, much like complex types.
2024-04-10 10:45:06 +02:00
Timm Bäder
d412047713 [clang][Interp] Fix "Initializing" zero-size arrays
getIndex() returns 0 here, so we were trying to initalize the 0th
element.

Fixes #88018
2024-04-09 07:04:35 +02:00
Timm Bäder
72d300adad [clang][Interp][NFC] Move a varible declaration in the closest scope 2024-03-14 13:50:05 +01:00
Timm Bäder
66f73100b8 [clang][Interp] Fix ltor conversion for pointer types
This special case is wrong, we need to handle pointer types here
just like anything else.
2024-02-13 08:44:15 +01:00
Timm Bäder
76eb8e35d6 [clang][Interp] Fix marking results as nullptr
I screwed this up in an earlier NFC commit, but the isZero()
case needs to set IsNullPtr to true of course.
2024-02-12 17:10:19 +01:00
Timm Bäder
635dfd5d69 [clang][Interp] Fix a designated initializer testcase
This protected GetPtrField and ArrayDecay ops from dummy pointers
which fixes the attached test case for designated initializers in C.
2024-02-12 15:36:07 +01:00
Timm Bäder
ea8de6e433 [clang][Interp][NFC] Make two local variables const 2024-02-12 15:36:07 +01:00
Timm Bäder
268799cc59 [clang][Interp][NFC] Refactor Pointer::toAPValue()
Use early-out style rather than letting control flow through
the entire function.
2024-02-12 13:27:42 +01:00
Timm Baeder
5bb99edcb6
[clang][Interp] Add inline descriptor to global variables (#72892)
Some time ago, I did a similar patch for local variables.

Initializing global variables can fail as well:
```c++
constexpr int a = 1/0;
static_assert(a == 0);
```
... would succeed in the new interpreter, because we never saved the
fact that `a` has not been successfully initialized.
2024-01-31 08:03:37 +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
1217a54be9 [clang][Interp][NFC] Make InlineDescriptor::Desc const 2023-10-26 11:38:32 +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
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
235dad3328 [clang][Interp][NFC] Make some variables const 2023-08-17 07:54:37 +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
193db1ebf0 [clang][Interp][NFC] Make pointer chain management more robust
Add a bunch of assertions to ensure we're doing the right thing. Also,
rename movePointer to replacePointer, since the old name didn't make
much sense.
2023-07-09 16:27:49 +02:00
Timm Bäder
3262aea06d [clang][Interp][NFC] Add missing return statement
I removed the else here, but forgot to add a return before.
Interestingly, none of the existing test cases triggered a problem. A
future commit will add a test case.
2023-07-09 16:13:18 +02:00
Timm Bäder
b1a019747e [clang][Interp][NFC] Remove unnecessary else blocks 2023-07-05 09:05:54 +02:00
Timm Bäder
a31b3a1a6d [clang[[Interp][NFC] Make some Descriptor pointers const 2023-04-26 10:57:43 +02:00
Timm Bäder
f63138d444 [clang][Interp] Fix Pointer::toAPValue() for expressions
Differential Revision: https://reviews.llvm.org/D141858
2023-02-03 14:30:05 +01:00
Timm Bäder
435225c6e2 [clang][Interp][NFC] Remove an unnecessary isArray() check
We already do an isPrimitiveArray() check, so no need for the isArray()
check.
2023-01-27 09:00:51 +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
10483ac743 [clang][Interp] Support pointer arithmethic in binary operators
Differential Revision: https://reviews.llvm.org/D135858
2022-11-07 07:47:19 +01:00
Timm Bäder
ee9bbfa5e6 [clang][Interp] Make sure we free() allocated InitMaps
They get allocated when calling initialize() on a primitive array. And
they get free'd when the array is fully initialized. However, when that
never happens, they get leaked. Fix that by calling the destructor of
global variables.

Differential Revision: https://reviews.llvm.org/D136826
2022-10-28 17:00:15 +02:00
Timm Bäder
4d2d426a51 [clang][Interp] Fix Pointer::toAPValue() LValuePath order 2022-10-14 12:31:24 +02:00
Timm Bäder
6e83209f62 [clang][Interp] Fix copy constructors with record array members
Differential Revision: https://reviews.llvm.org/D134523
2022-10-14 11:57:26 +02:00
Timm Bäder
86271798e5 [clang][Interp] Only initialize initmaps for primitive arrays
As the comment states, this code should only run for primitive arrays.

This should fix the memory sanitize builds.
2022-09-08 10:03:06 +02:00
Timm Bäder
3a7d476087 [clang][Interp] Implement array initializers and subscript expressions
Differential Revision: https://reviews.llvm.org/D132727
2022-09-08 07:31:07 +02:00
Fangrui Song
e4df934ca7 [Clang interpreter] Rename Block.{h,cpp} to InterpBlock.{h,cpp}
The Blocks runtime provide a header named Block.h.
It is generally preferable to avoid name collision with system headers
(reducing reliance on -isystem order, more friendly when navigating files in
an editor, etc).

Reviewed By: gribozavr2

Differential Revision: https://reviews.llvm.org/D74934
2020-02-21 09:47:28 -08: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