55 Commits

Author SHA1 Message Date
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
bc9c6c0c65 [clang][Interp][NFC] Remove ByteCodeGenError
Unused.
2024-03-04 17:46:08 +01:00
Timm Bäder
f651f134bb [clang][Interp][NFC] Add precondition assertions
All three of these need to be non-null.
2024-03-01 15:41:49 +01:00
Timm Bäder
dbf3d779bd [clang][Interp][NFC] Remove unused paramter
We manage the Result through EvaluationResult now.
2024-03-01 15:28:15 +01:00
Timm Bäder
18d2ff4be7 [clang][Interp] Allow recursive intepretation
This shouldn't be a problem in general, but we used to have some
sanity checks that prevented it from working. Remove those and
only do them on the non-recursive calls instead.
2024-03-01 15:28:14 +01:00
Timm Bäder
a35599b9ae [clang][Interp] Implement a few _is_lock_free builtins
Implementation looks similar to the one in the current interpreter.
Except for three static assertions, test/Sema/atomic-ops.c works.
2024-02-26 13:56:37 +01:00
Timm Bäder
2e43ca49d0 [clang][Interp] Check variable initialization in Ret op
Just like we did with the l-to-r conversion, we need to do this
while the data is still alive.
2024-02-16 12:05:03 +01:00
Timm Baeder
d68aa303fe
[clang][Interp] Do r-to-l conversion immediately when returning (#80662)
First, we need to register local constant variables in C, so we get the
same diagnostic behavior as the current interpeter.

Second, when returning an LValue (as a Pointer), which we eventually
convert to an RValue, we need to do the conversion immediately when
saving the Pointer in the EvaluationResult. Otherwise, we will possibly
deallocate the data before doing the conversion (which will look at the
Block*).
2024-02-15 15:13:12 +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 Baeder
6ff431b01e
[clang][Interp] Handle imaginary literals (#79130)
Initialize the first element to 0 and the second element to the value of
the subexpression.
2024-02-01 07:13:10 +01:00
Timm Bäder
70e2253754 [clang][Interp][NFC] Remove unnecessary braces 2024-01-28 14:36:27 +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 Bäder
00d809c374 [clang][Interp][NFC] Fix a comment typo 2023-12-12 15:47:49 +01:00
Timm Bäder
684e4c0085 [clang][Interp] Don't explicitly call InterpState destructor()
This broke the msan builders because the destructor will be called
twice. Should've guessed.
2023-10-24 12:00:40 +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
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
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
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
6dfe55569d [clang][Interp] Rework initializers
Before this patch, we had visitRecordInitializer() and
visitArrayInitializer(), which were different from the regular visit()
in that they expected a pointer on the top of the stack, which they
initialized. For example, visitArrayInitializer handled InitListExprs by
looping over the members and initializing the elements of that pointer.

However, this had a few corner cases and problems. For example, in
visitLambdaExpr() (a lambda is always of record type), it was not clear
whether we should always create a new local variable to save the lambda
to, or not. This is why https://reviews.llvm.org/D153616 changed
things around.

This patch changes the visiting functions to:

 - visit(): Always leaves a new value on the stack. If the expression
   can be mapped to a primitive type, it's just visited and the value is
   put on the stack. If it's of composite type, this function will
   create a local variable for the expression value and call
   visitInitializer(). The pointer to the local variable will stay on
   the stack.

 - visitInitializer(): Visits the given expression, assuming there is a
   pointer on top of the stack that will be initialized by it.

 - discard(): Visit the expression for side-effects, but don't leave a
   value on the stack.

It also adds an additional Initializing flag to differentiate between the initializing and non-initializing case.

Differential Revision: https://reviews.llvm.org/D156027
2023-08-20 13:33:08 +02:00
Timm Bäder
b2e6516fd1 [clang][Interp][NFC] Return std::nullopt explicitly from classify() 2023-07-26 09:34:26 +02:00
Timm Bäder
5b78868661 [clang][Interp][NFC] Make some locals const 2023-07-26 07:12:47 +02:00
Timm Bäder
8cb6e476cc [clang][Interp] Handle PtrMemOps
Differential Revision: https://reviews.llvm.org/D144164
2023-07-26 07:04:21 +02:00
Timm Bäder
b9e167994f [clang][Interp][NFC] Clear stack memory even on success
This makes it easier to use asan to find memory problems. clear() will
actually free the memory.
2023-07-09 16:13:19 +02:00
Timm Bäder
868aa93605 [clang][Interp][NFC] Take a const Function pointer in Context::Run() 2023-07-06 14:52:05 +02:00
Timm Bäder
976d8b40cc [clang][Interp] Virtual function calls
Add a CallVirt opcode and implement virtual function calls this way.

Differential Revision: https://reviews.llvm.org/D142630
2023-06-15 13:33:43 +02:00
Timm Bäder
47ee8519ec [clang][Interp][NFC] Context: Add getFloatSemantics()
We use this quite a bit, so add some convenience API for it.
2023-04-06 10:39:49 +02:00
Timm Bäder
3ad167329a [clang][Interp] Implement function pointers
Differential Revision: https://reviews.llvm.org/D141472
2023-03-30 15:37:49 +02:00
Timm Bäder
cb703434cb [clang][Interp] Add back Run() call
We need to run the functions we compiled immediately after to check if
they can ever be a constant expression.

Differential Revision: https://reviews.llvm.org/D140724
2023-01-25 17:01:55 +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
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
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
c01ac372fc [clang][Interp][NFC] Add assertions to VM entry points
Assert that the previous call left the stack empty, as well as that
successful interpretations leave an empty stack.
2022-10-22 10:19:42 +02:00
Timm Bäder
699449d71e [clang][Interp][NFC] Use a SourceRange for errors
This makes the error message generated by bail() a bit more pleasant to
read.
2022-10-14 12:46:51 +02:00
Timm Bäder
1928da1ef7 [clang][Interp] Don't run functions immediately after compiling them
This doesn't make much sense with functions that expect valid parameters
and/or a certain call stack on the caller side like This/RVO pointers.

Differential Revision: https://reviews.llvm.org/D135569
2022-10-14 10:21:53 +02:00
Timm Bäder
0da7e409e0 [clang][Interp][NFC] Context::classify() can be const 2022-09-08 07:31:08 +02:00
Reid Kleckner
4c2a6567bb Avoid ASTContext.h -> TargetInfo.h dep
This has been done before in 2008: ab13857072
But these things regress easily.
Move some things out of line.

Saves 316 includes + transitive stuff:
    316 -    ../clang/include/clang/Basic/TargetOptions.h
    316 -    ../clang/include/clang/Basic/TargetInfo.h
    316 -    ../clang/include/clang/Basic/TargetCXXABI.h
    316 -    ../clang/include/clang/Basic/OpenCLOptions.h
    316 -    ../clang/include/clang/Basic/OpenCLExtensions.def
    302 -    ../llvm/include/llvm/Target/TargetOptions.h
    302 -    ../llvm/include/llvm/Support/CodeGen.h
    302 -    ../llvm/include/llvm/MC/MCTargetOptions.h
    302 -    ../llvm/include/llvm/ADT/FloatingPointMode.h
    302 -    ../clang/include/clang/Basic/XRayInstr.h
    302 -    ../clang/include/clang/Basic/DebugInfoOptions.h
    302 -    ../clang/include/clang/Basic/CodeGenOptions.h
    302 -    ../clang/include/clang/Basic/CodeGenOptions.def
    257 -    ../llvm/include/llvm/Support/Regex.h
     79 -    ../llvm/include/llvm/ADT/SmallSet.h
     68 -    MSVCSTL/include/set
     66 -    ../llvm/include/llvm/ADT/SmallPtrSet.h
     62 -    ../llvm/include/llvm/ADT/StringSwitch.h
2020-02-27 14:35:00 -08:00
Nandor Licker
f584f04dab [ConstExprPreter] Removed the flag forcing the use of the interpreter
Summary:
Removed the ```-fforce-experimental-new-constant-interpreter flag```, leaving
only the ```-fexperimental-new-constant-interpreter``` one. The interpreter
now always emits an error on an unsupported feature.

Allowing the interpreter to bail out would require a mapping from APValue to
interpreter memory, which will not be necessary in the final version. It is
more sensible to always emit an error if the interpreter fails.

Reviewers: jfb, Bigcheese, rsmith, dexonsmith

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D70071
2019-11-27 20:07:19 +00: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