55 Commits

Author SHA1 Message Date
Timm Bäder
bc9c6c0c65 [clang][Interp][NFC] Remove ByteCodeGenError
Unused.
2024-03-04 17:46:08 +01:00
MagentaTreehouse
f505a92fc2
[NFC] Use fold expressions to replace discarded initializer_lists (#83693) 2024-03-02 23:44:17 +01:00
Timm Bäder
68516bfd2f [clang][Interp] Lambda This captures can be non-pointers
If they are captured by value.
2024-03-01 18:06:18 +01:00
Timm Bäder
a4ce870859 [clang][Interp][NFC] Add missing comment
Looks like I lost this last time.
2024-02-16 19:20:28 +01:00
Timm Bäder
7f45acfbfe [clang][Interp] Implement various overflow and carry builtins
Enough so we can enable SemaCXX/builtin-overflow.cpp.
2024-02-16 19:00:40 +01:00
Timm Bäder
cd183428a9 [clang][Interp] Fix handling of generic lambdas
When compiling their static invoker, we need to get the
right specialization.
2024-02-08 16:03:42 +01:00
Timm Bäder
3f1e95a9d4 [clang][Interp] consider "MS constexpr" functions as well
This implements the minimum amout of support for this feature
to get the test/AST/ms-constexpr.cpp test working. More has to
be added to get SemaCXX tests to work.
2024-02-06 21:49:13 +01:00
Timm Baeder
64a849a52e
[clang][Interp] Support arbitrary precision constants (#79747)
Add (de)serialization support for them, like we do for Floating values.
2024-01-31 10:00:42 +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 Baeder
1908d4cda6
[clang][Interp] Reject static lambdas with captures (#74718)
Static lambdas cannot have captures. They may still end up in the
constant evaluator though. They've been diagnosted appropriately before,
so just reject them here.

This is similar to #74661, but for the new constant expression
interpreter.
2023-12-12 11:08:38 +01:00
Timm Baeder
965d301dff
[clang][Interp] Implement __builtin_classify_type (#71972)
This adds some infrastructure for unevaluated builtin calls, and uses the implementation from ExprConstant.cpp
2023-11-17 16:13:23 +01:00
Kazu Hirata
0439a017ef [llvm] Drop unaligned from calls to llvm::support::endian::{read,write} (NFC)
The last template parameter of llvm::support::endian::{read,write}
defaults to unaligned, so we can drop that at call sites.
2023-10-10 22:41:47 -07:00
Kazu Hirata
c8e1774975 [Interp] Use llvm::endianness::native (NFC)
This patch replaces endianness::native with llvm::endianness::native.
Note that endianness::native would rely on:

  using endianness = llvm::endianness;

in llvm/include/llvm/Support/Endian.h.
2023-10-10 22:26:08 -07:00
Timm Bäder
57147bb253 [clang][Interp] Support LambdaThisCaptures
Differential Revision: https://reviews.llvm.org/D154262
2023-10-05 09:46:15 +02:00
Corentin Jabot
af4751738d [C++] Implement "Deducing this" (P0847R7)
This patch implements P0847R7 (partially),
CWG2561 and CWG2653.

Reviewed By: aaron.ballman, #clang-language-wg

Differential Revision: https://reviews.llvm.org/D140828
2023-10-02 14:33:02 +02:00
Timm Baeder
364757d2d5
[clang][Interp] Fix compiling undefined templated functions (#67232) 2023-09-25 17:28:44 +02:00
Timm Bäder
a7fdbecfb3 [clang][Interp][NFC] Clean up Context includes 2023-09-24 10:40:17 +02:00
Timm Bäder
658b655191 [clang][Interp][NFC] Refactor ByteCodeEmitter a bit 2023-09-23 11:45:30 +02:00
Timm Bäder
cf10061da7 [clang][Interp] Fully serialize Floating values to bytes
The Floating class wraps a APFloat, which might heap allocate memory to
represent large floating values. When writing those to bytecode, we
would free() the heap allocation after writing, when destroying the
actual APFloat we wrote.

Fix this by seralizing a Floating as Semantics + APInt.

This will be neccessary in more cases later, when we support
arbitrary-precision integers or _BitInt.

Differential Revision: https://reviews.llvm.org/D155165
2023-08-17 12:41:39 +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
6d2e141e5c [clang][Interp] Handle lambda static invokers
Differential Revision: https://reviews.llvm.org/D150111
2023-07-26 08:42:16 +02:00
Timm Bäder
eaadbcd5e0 [clang][Interp] Implement __builtin_strcmp
Make our Function class keep a list of parameter offsets so we can
simply get a parameter by index when evaluating builtin functions.

Differential Revision: https://reviews.llvm.org/D149816
2023-07-20 15:46:04 +02:00
Timm Bäder
e35719da5e [clang][Interp][NFC] Use std::byte for byte code. 2023-07-13 13:45:48 +02:00
Timm Bäder
00c27397dc [clang][Interp][NFC] Move some declarations into the if condition 2023-07-06 14:52:05 +02:00
Timm Bäder
bd59d17e71 [clang][Interp][NFC] Fix some doc comment confusion
These are supposed to be regular comments.
2023-07-06 14:52:05 +02:00
Timm Bäder
461f91b1e4 [clang][Interp] Handle LambdaExprs
Differential Revision: https://reviews.llvm.org/D146030
2023-06-16 10:05:33 +02:00
Timm Bäder
fce093ccb1 [clang][Interp] Fix parameter map when re-visiting function
'Params' is a member of the ByteCodeEmitter. We only added the
parameters the first time  we saw the function, so subsequent visits
didn't work if they had (and used) parameters.

Just do the work everytime we see a function.

Differential Revision: https://reviews.llvm.org/D141681
2023-03-31 08:06:06 +02:00
Timm Bäder
30f96a8fb4 [clang][Interp] Properly identify not-yet-defined functions
Since we now handle functions without a body as well, we can't just use
getHasBody() anymore. Funtions that haven't been defined yet are those
that don't have a body *and* aren't valid.

Also, just pass the information about whether the Function has a body or
not along from the FunctionDecl.

Differential Revision: https://reviews.llvm.org/D141591
2023-03-31 07:27:04 +02:00
Timm Bäder
bf6c1344ec [clang][Interp] Handle defined functions without a body
This happens when explicitly defaulting a constructor, for example.

Differential Revision: https://reviews.llvm.org/D140776
2023-03-02 08:17:48 +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
1221af9928 [clang][Interp] Use placement new to construct opcode args into vector
Differential Revision: https://reviews.llvm.org/D139185
2023-01-19 09:22:57 +01:00
Timm Bäder
89b009559c Revert "[clang][Interp] Use placement new to construct opcode args into vector"
This reverts commit aaf73ae266db44fce107a0b73fcb33527bfb52eb.

This breaks sanitized builds because the constructor is called with an
unaligned address.
2022-11-30 16:07:57 +01:00
Timm Bäder
ec23e5584d [clang][Interp][NFC] Avoid unnecessary work in compileFunc()
We don't need to create the paramter descriptors etc. if we've already
done that in the past.
2022-11-30 16:07:29 +01:00
Timm Bäder
aaf73ae266 [clang][Interp] Use placement new to construct opcode args into vector
This way we're invoking the copy constructor, which might be necessary
if the argument is not trivially constructible.

Differential Revision: https://reviews.llvm.org/D138554
2022-11-30 10:09:52 +01:00
Timm Bäder
c3380c32f8 [clang][Interp] Handle undefined functions better
Differential Revision: https://reviews.llvm.org/D136936
2022-11-30 10:09:52 +01:00
Timm Bäder
7f3013c5f9 [clang][Interp][NFC] Fix instance method check
This was a change suggested by Aaron that I forgot to commit.
2022-10-28 12:49:38 +02:00
Timm Bäder
8013ab4f98 [clang][Interp][NFC] Simplify creating parameter descriptors
... using value_or instead of the if-else statement.
2022-10-22 10:32:05 +02:00
Timm Bäder
7fbfe5518c [clang][Interp][NFC] Rename a parameter to be more descriptive 2022-10-14 13:32:31 +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
1c35f3b93a [clang][Interp][NFC] Unify emit() implementations
Instead of two overloads, use a if constexpr to differentiate between
pointer and non-pointer parameters
2022-09-29 12:50:55 +02:00
Timm Bäder
aa7c5c9c4e [clang][Interp] Handle missing local initializers better
This is illegal in a constexpr context. We can already figure that out,
but we'd still run into an assertion later on when trying to visit the
missing initializer or run the invalid function.

Differential Revision: https://reviews.llvm.org/D132832
2022-09-08 07:31:07 +02:00
Jessica Clarke
40080e7e7f [Clang interpreter] Avoid storing pointers at unaligned locations
The Clang interpreter's bytecode uses a packed stream of bytes
representation, but also wants to have some opcodes take pointers as
arguments, which are currently embedded in the bytecode directly.

However, CHERI, and thus Arm's upcoming experimental Morello prototype,
provide spatial memory safety for C/C++ by implementing language-level
(and sub-language-level) pointers as capabilities, which track bounds,
permissions and validity in hardware. This uses tagged memory with a
single tag bit at every capability-aligned address, and so storing
pointers to unaligned addresses results in the tag being stripped,
leading to a tag fault when the pointer is ultimately dereferenced at a
later point.

In order to support a stricter C/C++ implementation like CHERI, we no
longer store pointers directly in the bytecode, instead storing them in
a table and embedding the index in the bytecode.

Reviewed By: nand

Differential Revision: https://reviews.llvm.org/D97606
2021-07-28 16:03:41 +01: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