aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/AST/ByteCode/Pointer.cpp
AgeCommit message (Collapse)AuthorFilesLines
5 days[clang][bytecode][NFC] Use switches for pointer type distinction (#160879)Timm Baeder1-20/+28
In the important places. They are all fully covered switch statements so we know where to add code when adding a new pointer type.
2025-09-17[clang][bytecode] Optimize InitElem{,Pop} (#159084)Timm Baeder1-26/+34
Try harder to avoid creating a new `Pointer` for the element.
2025-09-02[clang] Followup for constexpr-unknown potential constant expressions. (#151053)Eli Friedman1-3/+0
6a60f18997d62b0e2842a921fcb6beb3e52ed823 fixed the primary issue of dereferences, but there are some expressions that depend on the identity of the pointed-to object without actually accessing it. Handle those cases. Also, while I'm here, fix a crash in interpreter mode comparing typeid to nullptr.
2025-08-28[clang][bytecode] Speed up `EvaluationResult::CheckArrayInitialized()` (#155756)Timm Baeder1-16/+49
For large primitive arrays, avoid creating a new `Pointer` for every element (via `Pointer::isElementInitialized()`) or avoid iterating over the array altogether (via `Pointer::allElementsInitialized()`).
2025-08-27[clang] AST: fix getAs canonicalization of leaf types (#155028)Matheus Izvekov1-1/+1
2025-08-26[clang][bytecode] Check that a ltor cast to a complex value is possible ↵Timm Baeder1-1/+4
(#155152) When we get to this point, the pointer might _not_ be backed by a primitive array, so the later code will fail. Fixes #155144
2025-08-22[clang][bytecode][NFC] Move local into closest scope (#154969)Timm Baeder1-1/+1
2025-08-20[clang][bytecode] Diagnose one-past-end reads from global arrays (#154484)Timm Baeder1-1/+1
Fixes #154312
2025-08-20[clang][bytecode][NFC] Use an anonymous union in Pointer (#154405)Timm Baeder1-59/+76
So we can save ourselves writing PointeeStorage all the time.
2025-08-20[clang][bytecode] Fix comparing pointers to union members (#154342)Timm Baeder1-0/+2
If one of them is a one-past-end pointer.
2025-08-19[clang][bytecode] Save a per-block dynamic allocation ID (#154094)Timm Baeder1-4/+1
This fixes an old todo item about wrong allocation counting and some diagnostic differences.
2025-08-09[clang] Improve nested name specifier AST representation (#147835)Matheus Izvekov1-3/+4
This is a major change on how we represent nested name qualifications in the AST. * The nested name specifier itself and how it's stored is changed. The prefixes for types are handled within the type hierarchy, which makes canonicalization for them super cheap, no memory allocation required. Also translating a type into nested name specifier form becomes a no-op. An identifier is stored as a DependentNameType. The nested name specifier gains a lightweight handle class, to be used instead of passing around pointers, which is similar to what is implemented for TemplateName. There is still one free bit available, and this handle can be used within a PointerUnion and PointerIntPair, which should keep bit-packing aficionados happy. * The ElaboratedType node is removed, all type nodes in which it could previously apply to can now store the elaborated keyword and name qualifier, tail allocating when present. * TagTypes can now point to the exact declaration found when producing these, as opposed to the previous situation of there only existing one TagType per entity. This increases the amount of type sugar retained, and can have several applications, for example in tracking module ownership, and other tools which care about source file origins, such as IWYU. These TagTypes are lazily allocated, in order to limit the increase in AST size. This patch offers a great performance benefit. It greatly improves compilation time for [stdexec](https://github.com/NVIDIA/stdexec). For one datapoint, for `test_on2.cpp` in that project, which is the slowest compiling test, this patch improves `-c` compilation time by about 7.2%, with the `-fsyntax-only` improvement being at ~12%. This has great results on compile-time-tracker as well: ![image](https://github.com/user-attachments/assets/700dce98-2cab-4aa8-97d1-b038c0bee831) This patch also further enables other optimziations in the future, and will reduce the performance impact of template specialization resugaring when that lands. It has some other miscelaneous drive-by fixes. About the review: Yes the patch is huge, sorry about that. Part of the reason is that I started by the nested name specifier part, before the ElaboratedType part, but that had a huge performance downside, as ElaboratedType is a big performance hog. I didn't have the steam to go back and change the patch after the fact. There is also a lot of internal API changes, and it made sense to remove ElaboratedType in one go, versus removing it from one type at a time, as that would present much more churn to the users. Also, the nested name specifier having a different API avoids missing changes related to how prefixes work now, which could make existing code compile but not work. How to review: The important changes are all in `clang/include/clang/AST` and `clang/lib/AST`, with also important changes in `clang/lib/Sema/TreeTransform.h`. The rest and bulk of the changes are mostly consequences of the changes in API. PS: TagType::getDecl is renamed to `getOriginalDecl` in this patch, just for easier to rebasing. I plan to rename it back after this lands. Fixes #136624 Fixes https://github.com/llvm/llvm-project/issues/43179 Fixes https://github.com/llvm/llvm-project/issues/68670 Fixes https://github.com/llvm/llvm-project/issues/92757
2025-07-30[clang][bytecode] Move Pointer::{Prev,Next} into BlockPointer (#151097)Timm Baeder1-3/+1
They are only relevant for block pointers.
2025-07-29[clang][bytecode] Add Pointer::initializeAllElements() (#151151)Timm Baeder1-0/+13
To initialize all elements of a primitive array at once. This saves us from creating the InitMap just to destroy it again after all elements have been initialized.
2025-07-28[clang][bytecode][NFC] Fix a few clang-tidy complaints (#150940)Timm Baeder1-5/+8
2025-07-21[clang][bytecode] Use OptPrimType instead of std::optional<PrimType> (#149812)Timm Baeder1-6/+6
We use this construct a lot. Use something similar to clang's UnsignedOrNone. This results in some slighy compile time improvements: https://llvm-compile-time-tracker.com/compare.php?from=17a4b0399d161a3b89d8f0ce82add1638f23f5d4&to=a251d81ecd0ed45dd190462663155fdb303ef04d&stat=instructions:u
2025-07-20[clang][bytecode] Reintroduce Pointer::elem() (#149693)Timm Baeder1-7/+6
As a way of writing atIndex(I).deref<T>(), which creates an intermediate Pointer, which in turn adds (and removes) that pointer from the pointer list of the Block. This way we can avoid that.
2025-07-16[clang][bytecode] Make union activation more granular (#148835)Timm Baeder1-1/+10
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-10[clang][bytecode][NFC] Move Pointer::StorageKind above the union (#147942)Timm Baeder1-4/+4
This is easier to read in debuggers and more common.
2025-07-08[clang][bytecode] Fix activating nested unions (#147338)Timm Baeder1-30/+12
When activating the new pointer, we need to de-activate pointers of all parent unions, not just the topmost one.
2025-07-06[clang][bytecode] Fix APValue generation for RValueReferenceType (#147207)Timm Baeder1-1/+1
We need to ignore the lvalue path, just like we do for lvalue reference types.
2025-07-06[clang][bytecode] Misc union fixes (#146824)Timm Baeder1-5/+26
First, don't forget to also activate fields which are bitfields on assignment. Second, when deactivating fields, recurse into records.
2025-07-05[clang][bytecode] Fix comparing pointers pointing to base classes (#146285)Timm Baeder1-4/+28
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-01[clang][bytecode] Allocate operator new data as array (#146471)Timm Baeder1-13/+2
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-06-23[clang][bytecode] Remove incorrect assertion (#145341)Timm Baeder1-1/+0
P.block() will assert that P is a block pointer, which it doesn't have to be here.
2025-06-03[clang][bytecode] Partially address string literal uniqueness (#142555)Timm Baeder1-0/+11
This still leaves the case of the constexpr auto b3 = name1() == name1(); test from cxx20.cpp broken.
2025-04-24[clang][bytecode] Diagnose comparing pointers to fields... (#137159)Timm Baeder1-0/+42
... with different access specifiers.
2025-04-19[clang][bytecode] Don't set OnePastEnd bit for array elements (#136422)Timm Baeder1-4/+5
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-16[clang][bytecode] Give typeinfo APValues an LValuePath (#135948)Timm Baeder1-1/+2
That's what the current interpreter does as well.
2025-04-16[clang][bytecode][NFC] Remove PT_FnPtr (#135947)Timm Baeder1-3/+3
We don't need this anymore since we don't return it from classify() anymore.
2025-04-11[clang][bytecode] Misc TypeidPointer fixes (#135322)Timm Baeder1-1/+3
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-10[clang][bytecode] Classify function pointers as PT_Ptr (#135026)Timm Baeder1-2/+12
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-01[clang][bytecode] Fix comparing the addresses of union members (#133852)Timm Baeder1-0/+33
Union members get the same address, so we can't just use `Pointer::getByteOffset()`.
2025-03-25[clang][bytecode] Fix base cast of nullptr without descriptor (#132909)Timm Baeder1-0/+4
The missing descriptor should only happen if the pointer is null pointer.
2025-03-05[clang][bytecode] Fix a crash in CheckConstantExpression (#129752)Timm Baeder1-1/+2
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-04[clang][bytecode] Don't error out on incomplete declarations (#129685)Timm Baeder1-1/+6
Later operations on these are invalid, but the declaration is fine, if extern.
2025-03-04[clang][bytecode][NFC] Minor cleanups (#129553)Timm Baeder1-1/+1
Pull local variables in to the closest scope, remove some unnecessary calls to getLocation() and remove an outdated comment.
2025-02-25[clang][bytecode] Add special case for anonymous unions (#128681)Timm Baeder1-8/+15
This fixes the expected output to match the one of the current interpreter.
2025-01-29[clang][bytecode] Fix dummy handling for p2280r4 (#124396)Timm Baeder1-11/+22
This makes some other problems show up like the fact that we didn't suppress diagnostics during __builtin_constant_p evaluation.
2024-12-28[clang][bytecode] Add a missing breakTimm Bäder1-0/+1
2024-12-28[clang][bytecode] Add support for typeid pointers (#121251)Timm Baeder1-0/+16
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[clang][bytecode] Move a local variable to a later point (#121250)Timm Baeder1-1/+1
We don't need `E` before.
2024-10-31[clang][bytecode] Fix Pointer::toAPValue() for multidimensional arrays (#114400)Timm Baeder1-7/+17
When we see an array root, that pointer might yet again be an array element, so check for that.
2024-10-21[clang][bytecode] Narrow pointer in UO_Deref unary operators (#113089)Timm Baeder1-1/+1
Otherwise we treat this like an array element even though we should treat it as a single object.
2024-10-11[clang][bytecode] Return an lvalue path for dummy pointers (#111862)Timm Baeder1-5/+0
Not doing this is wrong in general and we need to reject expressions where it would matter differently.
2024-10-04[clang][bytecode] Change isArrayElement() for narrowed composite arrays ↵Timm Baeder1-2/+6
(#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-09-19[clang][bytecode] Use field descriptor in IntPointer::atOffset (#109238)Timm Baeder1-1/+1
We're otherwise still pointing to the old type, but with the new offset.
2024-09-12[clang][bytecode] Implement base casts on integral pointers (#108340)Timm Baeder1-0/+23
Get the right offset to apply from the RecordLayout.
2024-08-31[clang][bytecode] Diagnose comparisons with literals (#106734)Timm Baeder1-0/+11
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-18[clang][bytecode] IntPointer::atOffset() should append (#104686)Timm Baeder1-1/+1
... to current offset. This breaks other tests which this commit also fixes. Namely, getIndex() should return the integer representation for non-block pointers.