47 Commits

Author SHA1 Message Date
Timm Bäder
5143a12413 [clang][Interp] Add __builtin_is_constant_evaluated warnings
Add the same warnings the current interpreter emits.
2024-03-17 18:07:51 +01:00
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
b37bd78e41 [clang][Interp][NFC] Add missing special cases for implicit functions
We have this special case in getSource() and getRange(), but we
were missing it in getExpr() and getLocation().
2024-02-14 15:58:37 +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 Bäder
32ec462519 [clang][Interp][NFC] Handle body-less functions like implicit ones
They don't have any source to look up locations in.
2023-12-11 16:48:21 +01: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 Baeder
fedc982731
[clang][Diagnostics] Add source range to uninitialized diagnostics (#65896)
Before:

```
array.cpp:319:10: note: read of uninitialized object is not allowed in a constant expression
  319 |    return aaa;
      |           ^
```

After:

```
array.cpp:319:10: note: read of uninitialized object is not allowed in a constant expression
  319 |    return aaa;
      |           ^~~
```
2023-09-11 07:03:18 +02:00
Timm Bäder
871ee94141 [clang][ExprConst] Use call source range for 'in call to' diags
Differential Revision: https://reviews.llvm.org/D156604
2023-08-16 15:22:29 +02:00
Timm Bäder
7a3ad8ed77 [clang] Provide source range to 'invalid subexpr in const expr' diags
Differential Revision: https://reviews.llvm.org/D150566
2023-07-26 09:12:11 +02:00
Timm Bäder
e6afacc034 [clang][Interp] Diagnose callsite for implicit functions
We don't have any code to point at here, so the diagnostics would just
point to the record declaration. Make them point to the call site
intead.

Differential Revision: https://reviews.llvm.org/D154761
2023-07-17 14:02:04 +02:00
Timm Bäder
a83079f754 [clang][ConstExpr][NFC] Make Frame::describe() const 2023-07-09 15:49:32 +02:00
Timm Bäder
da836b36bc [clang][Interp] Track frame depth
Save the depth of each InterpFrame and bail out if we're too deep.

Differential Revision: https://reviews.llvm.org/D148614
2023-05-31 12:08:03 +02:00
Timm Bäder
ddff70cb4b [clang][Interp][NFC] Make InterpFrame::describe() more const-correct 2023-05-31 09:01:57 +02:00
Timm Bäder
f8c99477d4 [clang][Interp][NFC] Move dyn_cast check into if condition
M is not used anywhere else.
2023-05-17 10:27:44 +02:00
Timm Bäder
1c818b0a4f [clang][Interp] Fix a crash when calling invalid constexpr functions
Differential Revision: https://reviews.llvm.org/D147845
2023-04-08 15:28:47 +02:00
Timm Bäder
d472c55fa2 [clang][Interp] Fix double-printing InterpFrame::describe()
Differential Revision: https://reviews.llvm.org/D141831
2023-03-31 15:25:30 +02:00
Timm Bäder
c68af565ff [clang][Interp][NFC] Cast in InterpFrame::localBlock
We know we save a Block* here, so do the cast there instead of
everywhere we're calling this function.
2023-01-25 17:09:34 +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
d54ae905d1 [clang][Interp][NFC] Rename InlineDescptor::IsMutable to IsFieldMutable 2023-01-23 10:32:51 +01:00
Timm Bäder
b07399f0fa [clang][Interp][NFC] Forward-declare Boolean in PrimTypes.h
We don't need the full header file here.
2023-01-22 08:33:39 +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
6b0cd497b0 [clang][Interp] Check Field initialization after constructor call
Differential Revision: https://reviews.llvm.org/D136694
2023-01-19 09:42:22 +01:00
Timm Bäder
29d25f9e9a [clang][Interp][NFC] Simplify InterpFrame constructor
Try to decrease the block depth here a bit.
2023-01-18 18:14:23 +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
9a3f3a9a08 [clang][Interp][NFC] Use range for loop 2023-01-16 10:39:13 +01:00
Timm Bäder
7c215a4571 [clang][Interp] Explicitly handle RVO Pointer
The calling convention is:

[RVO pointer]
[instance pointer]
[... args ...]

We handle the instance pointer ourselves, BUT for the RVO pointer, we
just assumed in visitReturnStmt() that it is on top of the stack. Which
isn't true if there are other args present (and a this pointer, maybe).

Fix this by recording the RVO pointer explicitly when creating an
InterpFrame, just like we do with the instance/This pointer.

There is already a "RVOAndParams()" test in test/AST/Inter/records.cpp,
that was supposed to test this, however, it didn't trigger any
problematic behavior because the parameter and the return value have the
same type.

Differential Revision: https://reviews.llvm.org/D137392
2022-11-30 10:37:57 +01:00
Timm Bäder
caa83d2329 [clang][Interp][NFC] Simplify InterpFrame::describe 2022-10-26 08:49:44 +02:00
Timm Bäder
f007c99ed1 [clang][Interp] Fix InterpFrame::describe() for This pointers
Since we pass this via the stack, we need to account for it when
desribing the stack frame (parameters). This fixes a previously
commented-out test case.

Differential Revision: https://reviews.llvm.org/D136670
2022-10-26 08:48:55 +02:00
Timm Bäder
4abd868304 [clang][Interp][NFC] Trim InterpFrame includes 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
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
1d31549e93 [clang][Interp][NFC] Forward-declare Pointer in InterpFrame.h
We don't need the full include here.
2022-09-29 12:50:55 +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