35 Commits

Author SHA1 Message Date
Timm Baeder
17d3029331
[clang][bytecode] Make union activation more granular (#148835)
Only activate things if the syntactical structure suggests so. This adds
a bunch of new opcodes to control whether to activate in stores, etc.

Fixes #134789
2025-07-16 09:03:33 +02:00
Timm Baeder
130e6121f5
[clang][bytecode][NFC] Move Pointer::StorageKind above the union (#147942)
This is easier to read in debuggers and more common.
2025-07-10 15:05:28 +02:00
Timm Baeder
36dd61f12a
[clang][bytecode] Fix activating nested unions (#147338)
When activating the new pointer, we need to de-activate pointers of all
parent unions, not just the topmost one.
2025-07-08 07:45:17 +02:00
Timm Baeder
1828381ed2
[clang][bytecode] Fix APValue generation for RValueReferenceType (#147207)
We need to ignore the lvalue path, just like we do for lvalue reference
types.
2025-07-06 21:12:18 +02:00
Timm Baeder
db4e927f9f
[clang][bytecode] Misc union fixes (#146824)
First, don't forget to also activate fields which are bitfields on
assignment.

Second, when deactivating fields, recurse into records.
2025-07-06 14:55:29 +02:00
Timm Baeder
fb2c7610e8
[clang][bytecode] Fix comparing pointers pointing to base classes (#146285)
In the attached test case, one pointer points to the `Derived` class and
one to `Base`, but they should compare equal. They didn't because those
two bases are saved at different offsets in the block. Use
`computeOffsetForComparison` not just for unions and fix it to work in
the more general cases.
2025-07-05 19:42:50 +02:00
Timm Baeder
1fe993c251
[clang][bytecode] Allocate operator new data as array (#146471)
Even if we only allocate one element, we still need to allocate it as a
single-element array. This matches what the current interpreter does.
2025-07-01 15:45:50 +02:00
Timm Baeder
c445ca5412
[clang][bytecode] Remove incorrect assertion (#145341)
P.block() will assert that P is a block pointer, which it doesn't have
to be here.
2025-06-23 19:11:01 +02:00
Timm Baeder
2e70da3fba
[clang][bytecode] Partially address string literal uniqueness (#142555)
This still leaves the case of the

constexpr auto b3 = name1() == name1();

test from cxx20.cpp broken.
2025-06-03 16:26:31 +02:00
Timm Baeder
9ae7aa79b1
[clang][bytecode] Diagnose comparing pointers to fields... (#137159)
... with different access specifiers.
2025-04-24 17:04:36 +02:00
Timm Baeder
6196b4ee8c
[clang][bytecode] Don't set OnePastEnd bit for array elements (#136422)
If we refer to arr[N], don't set the OnePastEnd bit of the APValue,
since that is already encoded in the array index.
2025-04-19 16:48:49 +02:00
Timm Baeder
38ca73db22
[clang][bytecode] Give typeinfo APValues an LValuePath (#135948)
That's what the current interpreter does as well.
2025-04-16 13:37:03 +02:00
Timm Baeder
2d63faead4
[clang][bytecode][NFC] Remove PT_FnPtr (#135947)
We don't need this anymore since we don't return it from classify()
anymore.
2025-04-16 13:21:25 +02:00
Timm Baeder
fafeaab6d9
[clang][bytecode] Misc TypeidPointer fixes (#135322)
Fix comparing type id pointers, add mor info when print()ing them, use
the most derived type in GetTypeidPtr() and the canonically unqualified
type when we know the type statically.
2025-04-11 10:35:28 +02:00
Timm Baeder
02f923f8e4
[clang][bytecode] Classify function pointers as PT_Ptr (#135026)
The Pointer class already has the capability to be a function pointer,
but we still classifed function pointers as PT_FnPtr/FunctionPointer.
This means when converting from a Pointer to a FunctionPointer, we lost
the information of what the original Pointer pointed to.
2025-04-10 06:40:54 +02:00
Timm Baeder
7267dbfe10
[clang][bytecode] Fix comparing the addresses of union members (#133852)
Union members get the same address, so we can't just use
`Pointer::getByteOffset()`.
2025-04-01 09:00:46 +02:00
Timm Baeder
a29b0d74a1
[clang][bytecode] Fix base cast of nullptr without descriptor (#132909)
The missing descriptor should only happen if the pointer is null
pointer.
2025-03-25 11:37:03 +01:00
Timm Baeder
107fe0ec6c
[clang][bytecode] Fix a crash in CheckConstantExpression (#129752)
The APValue we generated for a pointer with a LValueReferenceType base
had an incorrect lvalue path attached.

The attached test case is extracted from libc++'s regex.cpp.
2025-03-05 08:21:51 +01:00
Timm Baeder
06fc7d68ff
[clang][bytecode] Don't error out on incomplete declarations (#129685)
Later operations on these are invalid, but the declaration is fine, if
extern.
2025-03-04 12:41:34 +01:00
Timm Baeder
82d111e820
[clang][bytecode][NFC] Minor cleanups (#129553)
Pull local variables in to the closest scope, remove some unnecessary
calls to getLocation() and remove an outdated comment.
2025-03-04 06:17:07 +01:00
Timm Baeder
dff2ca424c
[clang][bytecode] Add special case for anonymous unions (#128681)
This fixes the expected output to match the one of the current
interpreter.
2025-02-25 12:46:06 +01:00
Timm Baeder
51c7338cc6
[clang][bytecode] Fix dummy handling for p2280r4 (#124396)
This makes some other problems show up like the fact that we didn't
suppress diagnostics during __builtin_constant_p evaluation.
2025-01-29 09:32:35 +01:00
Timm Bäder
3496e96f78 [clang][bytecode] Add a missing break 2024-12-28 14:17:06 +01:00
Timm Baeder
e86b68ff56
[clang][bytecode] Add support for typeid pointers (#121251)
Add it as another kind of pointer, saving both a `Type*` for the result
of the typeid() expression as well as one for the type of the typeid
expression.
2024-12-28 14:07:01 +01:00
Timm Baeder
39e8953f89
[clang][bytecode] Move a local variable to a later point (#121250)
We don't need `E` before.
2024-12-28 07:43:15 +01:00
Timm Baeder
2c82079924
[clang][bytecode] Fix Pointer::toAPValue() for multidimensional arrays (#114400)
When we see an array root, that pointer might yet again be an array
element, so check for that.
2024-10-31 15:15:59 +01:00
Timm Baeder
df8b785838
[clang][bytecode] Narrow pointer in UO_Deref unary operators (#113089)
Otherwise we treat this like an array element even though we should
treat it as a single object.
2024-10-21 07:51:49 +02:00
Timm Baeder
36b0707767
[clang][bytecode] Return an lvalue path for dummy pointers (#111862)
Not doing this is wrong in general and we need to reject expressions
where it would matter differently.
2024-10-11 05:58:25 +02:00
Timm Baeder
800b07396f
[clang][bytecode] Change isArrayElement() for narrowed composite arrays (#111110)
Make isArrayElement() return true here, so we can know that such a
pointer is in fact an array element and handle it properly in
toAPValue().
2024-10-04 14:19:32 +02:00
Timm Baeder
904f58e6b9
[clang][bytecode] Use field descriptor in IntPointer::atOffset (#109238)
We're otherwise still pointing to the old type, but with the new offset.
2024-09-19 09:12:17 +02:00
Timm Baeder
43fd2c401e
[clang][bytecode] Implement base casts on integral pointers (#108340)
Get the right offset to apply from the RecordLayout.
2024-09-12 17:19:37 +02:00
Timm Baeder
360e4abfc8
[clang][bytecode] Diagnose comparisons with literals (#106734)
This requires adding a new opcode for PointerToBoolean casts, since we
otherwise emit too many diagnostics. But that fixes an older problem
when casting weak pointers to bool.
2024-08-31 06:24:36 +02:00
Timm Baeder
dac182990d
[clang][bytecode] IntPointer::atOffset() should append (#104686)
... to current offset. This breaks other tests which this commit also
fixes. Namely, getIndex() should return the integer representation for
non-block pointers.
2024-08-18 08:59:34 +02:00
Timm Bäder
07bd3bb9b7 [clang][bytecode][NFC] Improve Pointer::print()
Do not access PointeeStorage.BS.Pointee if we have a non-block pointer
and extend printing to handle function pointers as well.
2024-08-18 08:55:22 +02:00
Timm Baeder
a07aba5d44
[clang] Rename all AST/Interp stuff to AST/ByteCode (#104552)
"Interp" clashes with the clang interpreter and people often confuse
this.
2024-08-16 17:13:12 +02:00