35 Commits

Author SHA1 Message Date
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
a99b912c9b [clang][Interp] Create dummy pointers for external variables
This way we can use their address, which is necessary in some
scenarios. This requires us to create different descriptors
for dummy arrays so we can get the diagnostics right.
2024-03-14 14:35:44 +01:00
Timm Bäder
c089fa5a72 [clang][Interp] Fix assertion in InitElem{,Pop} ops
... when the pointer is an unknown size array.
2024-03-04 13:31:36 +01:00
Timm Bäder
ddfc7e2254 [clang][Interp] Emit more dummy pointers in C++ mode 2024-02-29 10:04:42 +01:00
Timm Bäder
eddf9cf38a [clang][Interp] Fix failure to allocate local variables
We were incorrectly returning true when the allocateLocal() call
failed.
2024-02-19 11:52:13 +01:00
Timm Bäder
a52c0c7700 [clang][Interp] Lazily visit constant locals in C++
While we _do_ get them registered via visitInitializer(), they
are still local, so gone on the next call to e.g. evaluateAsRValue().

Visit them lazily, similarly like we do in C.
2024-02-16 12:49:05 +01:00
Timm Bäder
c227eca739 [clang][Interp][NFC] Convert test case to verify=expected,both style 2024-02-09 11:01:31 +01:00
Timm Bäder
79e43eb3e2 [clang][Interp] Protect ArrayDecay ops against dummy pointers 2024-02-09 10:12:26 +01:00
Timm Baeder
fc2766c1d4
[clang][Interp] Diagnose reads from non-const global variables (#71919)
This fixes a long-standing FIXME item.

Unfortunately it changes the diagnostic output of the tests added in
`cxx23.cpp`, but they were wrong before and are wrong after, so no big
deal.
2024-01-13 05:51:03 +01:00
Timm Baeder
c15e5836d4
[clang][Interp] Fix nullptr array dereferencing (#75798)
The attached test case would cause an assertion failure in Pointer.h
when operating on a null pointer.
2024-01-08 08:33:15 +01:00
Timm Baeder
c8c9af150d
[clang][Interp] Decay arrays to the first element (#72660)
This way we have a pointer to the
first element on the stack.
2023-12-12 11:01:47 +01:00
Timm Baeder
e01efddbf3
[clang][Interp] Correctly emit destructors for multi-dimensional arrays (#69140)
We were not taking those into account correctly when emitting
destructors. Fix that and add tests for it.

Fixes #69115
2023-10-26 14:51:30 +02: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
isuckatcs
9022f40212
[clang][Interp] Only evaluate the source array initialization of an ArrayInitLoopExpr once (#68039)
This patch implements an `OpaqueValueExpr` caching functionality in `Interp`
by storing the result of the expression in a local variable.
2023-10-23 17:52:27 +02:00
Timm Baeder
7bc793a692
[clang][Interp] Check pointer inc/dec ops for null (#69168) 2023-10-17 06:53:33 +02:00
Timm Baeder
4909e7cac7
[clang][Interp] Zero-init remaining string literal elements (#66862) 2023-09-30 08:28:09 +02:00
isuckatcs
c496aa34c0
[clang] Fix a crash from nested ArrayInitLoopExpr (#67722)
This patch makes sure that everything is cleaned up properly
when ExprConstant evaluates an ArrayInitLoopExpr.

Fixes #57135
2023-09-29 19:12:49 +02:00
Timm Bäder
38018ecf96 [clang][Interp][NFC] Add a failing test case for ArrayInitLoopExprs 2023-09-29 07:04:31 +02:00
Timm Bäder
c9e403d199 [clang][Interp] Fix zero-init of float and pointer arrays
Our Zero opcode only exists for integer types. Use
visitZeroInitializer() here as well so it works for floats and pointers.

Differential Revision: https://reviews.llvm.org/D149059
2023-04-25 09:00:47 +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
7348bb36c5 [clang][Interp] Support inc/dec operators for pointers
Differential Revision: https://reviews.llvm.org/D137232
2023-01-25 11:57:05 +01:00
Timm Bäder
ad2fb01cb6 [clang][Interp] Fix dereferencing arrays with no offset applied
A pointer to an array and a pointer to the first element of the array
are not the same in the interpreter, so handle this specially in
deref().

Differential Revision: https://reviews.llvm.org/D137082
2023-01-25 11:21:31 +01:00
Timm Bäder
8095b090db [clang][Interp] Array initialization via CXXConstructExpr
Differential Revision: https://reviews.llvm.org/D136920
2022-11-30 10:09:52 +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
f79f64b8d0 [clang][Interp] Implement inc and dec operators
Differential Revision: https://reviews.llvm.org/D136423
2022-10-28 17:47:32 +02:00
Timm Bäder
c29f0638c1 [clang][Interp] Add a missing static_assert message
This broke a builder:
https://lab.llvm.org/buildbot/#builders/139/builds/29923
2022-10-22 10:32:05 +02:00
Timm Bäder
d78a3957ea [clang][Interp][NFC] Add two more array tests 2022-10-22 10:19:42 +02:00
Timm Bäder
09bbc903a5 [clang][Interp] Array initialization via ImplicitValueInitExpr
Differential Revision: https://reviews.llvm.org/D135013
2022-10-21 10:49:45 +02:00
Timm Bäder
e83bea40b6 [clang][Interp][NFC] Add some tests for invalid array access 2022-10-14 14:41:05 +02:00
Timm Bäder
bf3efa8b16 [clang][Interp] Handle DeclRefExpr of reference types
References are implemented through pointers, so we need a second deref
when encountering a DeclRefExpr of a reference type.

Differential Revision: https://reviews.llvm.org/D132997
2022-09-13 10:40:51 +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
Timm Bäder
4d700ffe67 [clang][Interp] Implement ImplicitValueInitExprs
Take the existing Zero opcode and emit it.

Differential Revision: https://reviews.llvm.org/D132829
2022-09-08 07:31:07 +02:00