aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/AST/ByteCode/Compiler.h
AgeCommit message (Collapse)AuthorFilesLines
3 days[clang][bytecode] Diagnose volatile writes (#160350)Timm Baeder1-0/+1
2025-09-16[clang][bytecode][NFC] Remove BlockScope (#158656)Timm Baeder1-8/+0
Unused these days.
2025-09-15[clang][bytecode] Pass initializer along in `evaluateAsInitializer()` (#158056)Timm Baeder1-2/+4
We just called `getInit()`, which isn't always correct and used the wrong initializer in the module test case.
2025-09-11[clang][bytecode] Implement C23 named loops (#156856)Timm Baeder1-12/+17
2025-09-05[clang][bytecode][NFC] Remove instance pointer from emitDestruction (#157040)Timm Baeder1-5/+3
We only call this when we just pushed a new pointer to the stack, so try to save the folling PopPtr op by removing the pointer inside emitDestruction directly, e.g. by letting the Call op just remove it.
2025-08-19[clang][bytecode][NFC] Replace std::optional<unsigned> with UnsignedO… ↵Timm Baeder1-7/+7
(#154286) …rNone
2025-08-19[clang][bytecode] Fix initializing float elements from #embed (#154285)Timm Baeder1-1/+2
Fixes #152885
2025-08-18[clang][bytecode] Improve __builtin_{,dynamic_}object_size implementation ↵Timm Baeder1-0/+2
(#153601)
2025-08-10[clang][bytecode] Use Param decl as variable source if we can (#152909)Timm Baeder1-1/+1
This results in diagnostics that are closer to what the current interpreter produces.
2025-08-09[clang][bytecode] Add canClassify() helper (#152755)Timm Baeder1-0/+2
Sometimes we don't need the return value of a classsify() call, we only need to know if we can map the given Expr/Type to a primitive type. Add canClassify() for that.
2025-08-05[clang][bytecode] Disable location tracking for implicit field inits (#150190)Timm Baeder1-0/+2
2025-07-30[clang][bytecode] Clean up {Compiler,Interp}.h (#151335)Timm Baeder1-1/+0
Remove else after return and remove some unused includes.
2025-07-23[clang][bytecode] Activate primitive fields before initializing them (#149963)Timm Baeder1-0/+2
The initializer itself might need the field to be active.
2025-07-21[clang][bytecode] Use OptPrimType instead of std::optional<PrimType> (#149812)Timm Baeder1-8/+4
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-16[clang][bytecode] Make union activation more granular (#148835)Timm Baeder1-1/+3
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-09[clang][bytecode] Devirtualize calls during con- and destruction (#147685)Timm Baeder1-0/+2
When compiliung compiling a ctor or dtor, we need to devirtualize the virtual function calls so we always call the implementation of the current class.
2025-06-30[clang][bytecode] Add `Descriptor::hasTrivialDtor()` (#146286)Timm Baeder1-9/+9
We sometimes used to have a long list of ``` GetLocalPtr PopPtr [...] ``` ops at the end of scopes, because we first got a pointer to a local variable and only then did we figure out that we didn't actually want to call the destructor for it. Add a new function that allows us to just ask the `Descriptor` whether we need to call its destructor.
2025-06-20Reapply "Reapply "[clang][bytecode] Allocate IntegralAP and Floating … ↵Timm Baeder1-0/+1
(#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-1/+0
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-0/+1
(#144676) …ng an allocator (#144246)" This reverts commit 57828fec760f086b334ce0cb1c465fc559dcaea4.
2025-06-17Revert "[clang][bytecode] Allocate IntegralAP and Floating types using an ↵Timm Bäder1-1/+0
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-0/+1
(#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-05-19[clang][bytecode] Add a scope to function calls (#140441)Timm Baeder1-26/+33
We need a place to destroy the temporaries created for call arguments.
2025-05-15[clang][bytecode] Fix discarded LValueToRValueBitCasts (#140034)Timm Baeder1-0/+1
We handle discarding fine, but we used to ignore all discarded cast expressions. Handle bitcasts differently.
2025-05-13[clang][bytecode] Avoid classifying in visitArrayElemInit() (#139674)Timm Baeder1-1/+2
We usually call this more than once, but the type of the initializer never changes. Let's classify only once and pass that to visitArrayElemInit().
2025-04-26[clang][bytecode] Diagnose dynamic_cast before C++20 (#137442)Timm Baeder1-0/+1
Emit a CCE diagnostic.
2025-04-16[clang][bytecode] Explicitly mark constexpr-unknown variables as such (#135806)Timm Baeder1-4/+8
Instead of trying to figure out what's constexpr-unknown later on.
2025-04-13[clang][bytecode] Fix an inconsistency with loop condition jumps (#135530)Timm Baeder1-1/+2
When emitting the jump for e.g. a for loop condition, we used to jump out of the CondScope, leaving the scope initialized, because we skipped the corresponding Destroy opcode. If that loop was in a loop itself, that outer loop could then iterate once more, leading to us initializing a scope that was still initialized. Fix this by also destroying the scope after the EndLabel.
2025-03-19[clang][bytecode] Fix initializing array struct fields from an APValue (#131983)Timm Baeder1-1/+1
We need to recurse once more here and move the array case into the bigger if chain.
2025-03-11[Clang] Implement P0963R3 "Structured binding declaration as a condition" ↵Younan Zhang1-1/+2
(#130228) This implements the R2 semantics of P0963. The R1 semantics, as outlined in the paper, were introduced in Clang 6. In addition to that, the paper proposes swapping the evaluation order of condition expressions and the initialization of binding declarations (i.e. std::tuple-like decompositions).
2025-03-08[clang][bytecode] Implement __builtin_constant_p (#130143)Timm Baeder1-1/+4
Use the regular code paths for interpreting. Add new instructions: `StartSpeculation` will reset the diagnostics pointers to `nullptr`, which will keep us from reporting any diagnostics during speculation. `EndSpeculation` will undo this. The rest depends on what `Emitter` we use. For `EvalEmitter`, we have no bytecode, so we implement `speculate()` by simply visiting the first argument of `__builtin_constant_p`. If the evaluation fails, we push a `0` on the stack, otherwise a `1`. For `ByteCodeEmitter`, add another instrucion called `BCP`, that interprets all the instructions following it until the next `EndSpeculation` instruction. If any of those instructions fails, we jump to the `EndLabel`, which brings us right before the `EndSpeculation`. We then push the result on the stack.
2025-02-21[clang][bytecode] Use ExtendingDecl mechanism for primitives as well (#128141)Timm Baeder1-1/+1
... when creating the temporary variables for a MaterializeTemporaryExpr.
2025-02-03[clang][bytecode] Handle union move assignment operators as well (#125516)Timm Baeder1-1/+1
2025-02-03[clang][bytecode] Add special handling for union copy assign operators (#125476)Timm Baeder1-0/+1
2025-01-31[clang][bytecode] Handle invalid temporary descriptors (#125033)Timm Baeder1-1/+1
This happens e.g. when a vector element type is not primitive.
2025-01-14[clang][bytecode] Add init link for the RVO ptr (#122904)Timm Baeder1-1/+3
2025-01-14[clang][bytecode] Change the way we do init chains (#122871)Timm Baeder1-0/+2
See the comment in Compiler<>::VisitCXXThisExpr. We need to mark the InitList explicitly, so we later know what to refer to when the init chain is active.
2024-12-28[clang][bytecode] Add support for typeid pointers (#121251)Timm Baeder1-0/+1
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-11-25[clang][bytecode] Support ImplicitValueInitExpr for multi-dim arrays (#117312)Timm Baeder1-0/+1
The attached test case from https://github.com/llvm/llvm-project/issues/117294 used to cause an assertion because we called classifPrim() on an array type. The new result doesn't crash but isn't exactly perfect either. Since the problem arises when evaluating an ImplicitValueInitExpr, we have no proper source location to point to. Point to the caller instead.
2024-10-31[clang][bytecode] Start implementing __builtin_bit_cast (#112126)Timm Baeder1-0/+1
This is a subset of #68288, with hopefully narrower scope. It does not support bitcasting to non-integral types yet. Bitfields are supported, but only if they result in a full byte-sized final buffer. It does not support casting from null-pointers yet or casting from indeterminate bits. The tests are from #68288 and partially from #74775. The `BitcastBuffer` struct is currently always working in single bits, but I plan to (try to) optimize this for the common full-byte case.
2024-10-22[clang][bytecode] Create dummy pointers for non-reference DeclRefExprs (#113202)Timm Baeder1-0/+1
... with non-constant initializers.
2024-10-10[clang][bytecode] Fix temporary lvalue base expression (#111808)Timm Baeder1-1/+2
We need to use the MaterializeTemporaryExpr here so the checks in ExprConstant.cpp do the right thing.
2024-09-29[clang][bytecode] Implement fixed-point-to-int casts (#110417)Timm Baeder1-0/+1
And some cleanups around overflow handling.
2024-09-28[clang][bytecode] Implement (N)EQ between fixed point and integral (#110358)Timm Baeder1-0/+1
Convert the non-fixed-point side to a fixed-point type before doing the comparison.
2024-09-27[clang][bytecode] Start implementing fixed point types (#110216)Timm Baeder1-0/+1
Add the primitive type and implement to-bool casts.
2024-09-26[clang][bytecode] Add a source location to destructor calls (#110121)Timm Baeder1-3/+3
The added test case is still diagnosed differently, but I'm not sure which version is better.
2024-09-10[clang][bytecode] Fix local destructor order (#107951)Timm Baeder1-3/+5
Add appropriate scopes and use reverse-order iteration in LocalScope::emitDestructors().
2024-09-08[clang][bytecode] Fix a variable scope problem with continue/break jumps ↵Timm Baeder1-0/+2
(#107738) Cleaning up _all_ the scopes is a little too much. Only clean up until the point here we started the scope relevant for the break/continue statement.
2024-09-07[clang][bytecode] Implement using operator new/operator delete (#107679)Timm Baeder1-1/+1
Reuse the __builtin_operator_{new,delete} implementations.
2024-09-07[clang][bytecode] Allow continuing when discarded MemberExpr Base fails ↵Timm Baeder1-1/+1
(#107231) We don't need the value in this case, since we're discarding it anyway. Allow continuing the interpretation but note the side effect.