aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/AST/ByteCode/Interp.cpp
AgeCommit message (Collapse)AuthorFilesLines
3 days[clang][bytecode] Diagnose volatile writes (#160350)Timm Baeder1-0/+2
7 days[clang][bytecode] Use stack offsets for This/RVO ptrs (#160285)Timm Baeder1-4/+4
Instead of keeping the `Pointer`s itself in `InterpFrame`, just save them as offsets and use stackRef<>() when we need them.
12 days[clang][bytecode] Typecheck called function pointers more thorougly (#159757)Timm Baeder1-3/+10
Fix two older FIXME items from the `functions.cpp` test.
2025-09-12[clang][bytecode] Compile the definition, not the most recent decl (#158093)Timm Baeder1-2/+5
2025-09-11[clang][bytecode] Check reads for null block pointers (#157695)Timm Baeder1-9/+9
All pointer types can be null, so check that independently from the pointer type. Fixes #157650
2025-09-05[clang][bytecode][NFC] Use an early return in CheckLoad (#157105)Timm Baeder1-3/+2
If the block is not accessible, one of the check has to fail.
2025-09-04[clang][bytecode] Reject null pointers in CheckStore() (#156645)Timm Baeder1-1/+1
In the attached test case, the global variable later only points to gargbage, because the MaterializeTemporaryExpr used to initialize it is a local variable, which is gone by the time we try to evaluate the store. Fixes #156223
2025-08-26[clang][bytecode][NFC] Check hasTrivialDtor() in RunDestructors (#155381)Timm Baeder1-10/+11
We do this when calling Free() on dynamically allocated memory.
2025-08-26[clang][bytecode] Don't call getIndex() on one-past-end pointers (#155173)Timm Baeder1-2/+2
That doesn't work. Fixes #152903
2025-08-21[clang][bytecode] Call CheckFinalLoad in all language modes (#154496)Timm Baeder1-11/+2
Fixes #153997
2025-08-20[clang][bytecode] Diagnose one-past-end reads from global arrays (#154484)Timm Baeder1-2/+2
Fixes #154312
2025-08-18[clang][bytecode] Disable EndLifetime op for array elements (#154119)Timm Baeder1-0/+10
This breaks a ton of libc++ tests otherwise, since calling std::destroy_at will currently end the lifetime of the entire array not just the given element. See https://github.com/llvm/llvm-project/issues/147528
2025-08-10 [clang][bytecode] Move CheckExtern call into isAccessible() block (#152926)Timm Baeder1-2/+2
This is where it belongs, but it was accidentally left where it was.
2025-08-09[clang][bytecode] Add AccessFlags to Block (#152590)Timm Baeder1-34/+77
This way, we can check a single uint8_t for != 0 to know whether this block is accessible or not. If not, we still need to figure out why not and diagnose appropriately of course.
2025-08-09[clang] Improve nested name specifier AST representation (#147835)Matheus Izvekov1-4/+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-08-08[clang][bytecode] Handle reads on zero-size arrays (#152706)Timm Baeder1-3/+1
2025-08-07[clang][bytecode] Handle more invalid member pointer casts (#152546)Timm Baeder1-2/+11
2025-08-07[clang][bytecode] Refactor Check* functions (#152300)Timm Baeder1-59/+85
... so we don't have to create Pointer instances when we don't need them.
2025-08-05[clang][bytecode] Call CheckLocalLoad in GetLocal (#152090)Timm Baeder1-0/+2
I forgot to call this here as well. It was only used in the EvalEmitter implementation of the function. Also fix a problem where we didn't diagnose out-of-lifetime reads here.
2025-08-04[clang][bytecode] Try to load primitive values directly (#151833)Timm Baeder1-17/+31
Instead of doing a GetPtrLocal + Load or GetPtrGlobal + Load pair, try to load the value directly.
2025-07-28[clang][bytecode][NFC] Fix a few clang-tidy complaints (#150940)Timm Baeder1-1/+1
2025-07-19[clang][bytecode] Use bytecode interpreter in isPotentialConstantExprU… ↵Timm Baeder1-1/+8
(#149462) …nevaluated Fake a function call to the given function and evaluate the given expression as if it was part of that function call. Fixes #149383
2025-07-18[clang][bytecode] Fix const-in-mutable fields (#149286)Timm Baeder1-1/+4
For mutable and const fields, we have two bits in InlineDescriptor, which both get inherited down the hierarchy. When a field is both const and mutable, we CAN read from it if it is a mutable-in-const field, but we _can't_ read from it if it is a const-in-mutable field. We need another bit to distinguish the two cases.
2025-07-16[clang][bytecode] Fix contains check using llvm::find (#149050)Timm Baeder1-1/+1
We need to compare to the end() interator.
2025-07-16[clang][bytecode][NFC] Remove unused function prototypes (#149031)Timm Baeder1-4/+4
2025-07-16[clang][bytecode] Make union activation more granular (#148835)Timm Baeder1-2/+5
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-11[clang][bytecode] Remove needless global check (#148163)Timm Baeder1-7/+1
Remove the call to D->hasGlobalStorage(), since we never reach this point for local variables.
2025-07-11[clang][bytecode] Keep a list of initializing blocks in InterpState (#148120)Timm Baeder1-22/+21
So we can know what blocks we're currently running constructors or destructors for.
2025-07-10[clang][bytecode] Check new/delete mismatch earlier (#147732)Timm Baeder1-14/+18
This fixes a mismatch in diagnostic output with the current intepreter.
2025-06-23[NFC][Clang][AST] Drop `llvm::` in front of `ArrayRef`/`MutableArrayRef` ↵Rahul Joshi1-1/+1
(#145207)
2025-06-20Reapply "Reapply "[clang][bytecode] Allocate IntegralAP and Floating … ↵Timm Baeder1-4/+102
(#145014) …types usi… (#144676)" This reverts commit 68471d29eed2c49f9b439e505b3f24d387d54f97. IntegralAP contains a union: union { uint64_t *Memory = nullptr; uint64_t Val; }; On 64bit systems, both Memory and Val have the same size. However, on 32 bit system, Val is 64bit and Memory only 32bit. Which means the default initializer for Memory will only zero half of Val. We fixed this by zero-initializing Val explicitly in the IntegralAP(unsigned BitWidth) constructor. See also the discussion in https://github.com/llvm/llvm-project/pull/144246
2025-06-18Revert "Reapply "[clang][bytecode] Allocate IntegralAP and Floating types ↵Timm Bäder1-102/+4
usi… (#144676)" This reverts commit 7c15edb306932e41c159f3d69c161ed0d89d47b7. This still breaks clang-armv8-quick: https://lab.llvm.org/buildbot/#/builders/154/builds/17587
2025-06-18Reapply "[clang][bytecode] Allocate IntegralAP and Floating types usi… ↵Timm Baeder1-4/+102
(#144676) …ng an allocator (#144246)" This reverts commit 57828fec760f086b334ce0cb1c465fc559dcaea4.
2025-06-17Revert "[clang][bytecode] Allocate IntegralAP and Floating types using an ↵Timm Bäder1-102/+4
allocator (#144246)" This reverts commit c66be289901b3f035187d391e80e3610d7d6232e. This breaks the armv8-quick builder: https://lab.llvm.org/buildbot/#/builders/154/builds/17549
2025-06-17[clang][bytecode] Allocate IntegralAP and Floating types using an allocator ↵Timm Baeder1-4/+102
(#144246) Both `APInt` and `APFloat` will heap-allocate memory themselves using the system allocator when the size of their data exceeds 64 bits. This is why clang has `APNumericStorage`, which allocates its memory using an allocator (via `ASTContext`) instead. Calling `getValue()` on an ast node like that will then create a new `APInt`/`APFloat` , which will copy the data (in the `APFloat` case, we even copy it twice). That's sad but whatever. In the bytecode interpreter, we have a similar problem. Large integers and floating-point values are placement-new allocated into the `InterpStack` (or into the bytecode, which is a `vector<std::byte>`). When we then later interrupt interpretation, we don't run the destructor for all items on the stack, which means we leak the memory the `APInt`/`APFloat` (which backs the `IntegralAP`/`Floating` the interpreter uses). Fix this by using an approach similar to the one used in the AST. Add an allocator to `InterpState`, which is used for temporaries and local values. Those values will be freed at the end of interpretation. For global variables, we need to promote the values to global lifetime, which we do via `InitGlobal` and `FinishInitGlobal` ops. Interestingly, this results in a slight _improvement_ in compile times: https://llvm-compile-time-tracker.com/compare.php?from=6bfcdda9b1ddf0900f82f7e30cb5e3253a791d50&to=88d1d899127b408f0fb0f385c2c58e6283195049&stat=instructions:u (but don't ask me why). Fixes https://github.com/llvm/llvm-project/issues/139012
2025-06-05[clang][bytecode] Save Constexpr bit in Function (#142793)Timm Baeder1-9/+9
Rename isConstexpr to isValid, the former was always a bad name. Save a constexpr bit in Function so we don't have to access the decl in CheckCallable.
2025-06-03[clang][bytecode] Partially address string literal uniqueness (#142555)Timm Baeder1-0/+45
This still leaves the case of the constexpr auto b3 = name1() == name1(); test from cxx20.cpp broken.
2025-05-29[clang][bytecode] Only check expr in CheckThis() if we have to (#141951)Timm Baeder1-10/+9
Pre C++11, we dont't need to get the value of IsImplicit.
2025-05-29[clang][bytecode] Simplify diagnoseUnknownDecl if we're not diagnosing (#141910)Timm Baeder1-0/+7
See the added comment. This improves compile times a bit: https://llvm-compile-time-tracker.com/compare.php?from=ac62f73f19ae9fb415d3fc423949b8d7543e8717&to=0d6cf47197a4ee11cdd1ee4a48ea38a2907c3d45&stat=instructions:u
2025-05-28[clang][bytecode] Recursively start lifetimes as well (#141742)Timm Baeder1-7/+30
The constructor starts the lifetime of all the subobjects.
2025-05-24[clang][bytecode] Check lifetime of all ptr bases in placement-new (#141272)Timm Baeder1-2/+54
placement-new'ing an object with a dead base object is not allowed, so we need to check all the pointer bases.
2025-05-23[clang][bytecode] Fix AccessKinds in placement new CheckStore() call (#141123)Timm Baeder1-1/+17
CheckStore is for assignments, but we're constructing something here, so pass AK_Construct instead. We already diagnosed the test case, but as an assignment.
2025-05-23[clang][bytecode] Diagnose placement-new'ing to a temporary (#141099)Timm Baeder1-0/+2
... that's been created in a different evaluation.
2025-05-22[clang][bytecode] Fix self-init diagnostics in C++23 (#141044)Timm Baeder1-1/+2
2025-05-22[clang][bytecode] Change diagnostics for self-initialization (#141006)Timm Baeder1-0/+15
Change the diagnostics when reading from the variable we're currently initializing do be the same as the one the current interpreter emits.
2025-05-19[clang][bytecode] Diagnose failed constexpr assertions differently (#140000)Timm Baeder1-0/+15
Adjust to the new way the ast walker is doing it.
2025-05-15[clang][bytecode] Check dtor calls for one-past-end pointers (#140047)Timm Baeder1-0/+2
2025-05-15[clang][bytecode] Check destructors for temporaries (#140039)Timm Baeder1-0/+2
Also, increase the EvalID in isPotentialConstantExpr(), since this is its own evaluation.
2025-05-13[clang][bytecode] Save Immediate bit in Function (#139671)Timm Baeder1-1/+1
Otherwise, we have to look at the FunctionDecl at every function call.
2025-05-13[clang][bytecode] Optimize enum value range checks (#139672)Timm Baeder1-3/+2
Only do the work if we really have to.