25 Commits

Author SHA1 Message Date
Timm Baeder
f71e321966
[clang][bytecode] Implement constexpr step limit (#176150)
This only calls `noteStep()` on jump opcodes, so this works for loops.
It does not prevent "hangs" when a function is just _very_ long (could
be interesting how this interfaces with expand statements?).

Fixes https://github.com/llvm/llvm-project/issues/165951
2026-02-09 12:22:48 +01:00
Timm Baeder
136bbde262
[clang][ExprConst] Move shared EvalInfo state into interp::State (#177738)
Instead of having `InterpState` call into its parent `EvalInfo`, just
save the state in `interp::State`, where both subclasses can access it.
2026-02-02 09:00:10 +01:00
Timm Baeder
9b00a58cbd
[clang][bytecode] Use bytecode interpreter in EvaluateAsLValue (#158038)
Set the EvalMode on InterpState and abort when initalizing a global
temporary, like the current interpreter does. The rest is just plumbing
in EvaluateAsLValue.

Fixes #157497
2025-09-11 13:29:44 +02:00
Timm Baeder
17a7114054
[clang][bytecode] Use InterpState::InConstantContext directly (#157224)
Instead of referring to the EvalInfo's flag.
2025-09-08 16:29:44 +02:00
Timm Baeder
5c8c59d792
[clang][bytecode] Remove unused reportOverflow() (#157225) 2025-09-06 07:25:53 +02:00
Timm Baeder
f58844b6b6
[clang] Move two flags from EvalInfo to State (#157046)
Instead of relaying from InterpState to the parent state (which is an
EvalInfo), just save the variables in State instead, so both subclasses
have access to it.
2025-09-06 06:16:15 +02:00
Timm Baeder
e96ff4530f
[clang][bytecode] Lazily create DynamicAllocator (#155831)
Due to all the tracking via map(s) and a BumpPtrAllocator, the creating
and destroying the DynamicAllocator is rather expensive. Try to do it
lazily and only create it when first calling
InterpState::getAllocator().
2025-09-02 17:57:18 +02:00
Timm Baeder
a805dfbc9f
[clang][bytecode] Remove split frame business (#155980)
This was never really needed.
2025-08-29 09:42:46 +02:00
Timm Baeder
6ce13ae1c2
[clang][bytecode] Always track item types in InterpStack (#151088)
This has been a long-standing problem, but we didn't use to call the
destructors of items on the stack unless we explicitly `pop()` or
`discard()` them.

When interpretation was interrupted midway-through (because something
failed), we left `Pointer`s on the stack. Since all `Block`s track what
`Pointer`s point to them (via a doubly-linked list in the `Pointer`),
that meant we potentially leave deallocated pointers in that list. We
used to work around this by removing the `Pointer` from the list before
deallocating the block.

However, we now want to track pointers to global blocks as well, which
poses a problem since the blocks are never deallocated and thus those
pointers are always left dangling.

I've tried a few different approaches to fixing this but in the end I
just gave up on the idea of never knowing what items are in the stack.
We already have an `ItemTypes` vector that we use for debugging
assertions. This patch simply enables this vector unconditionally and
uses it in the abort case to properly `discard()` all elements from the
stack. That's a little sad IMO but I don't know of another way of
solving this problem.

As expected, this is a slight hit to compile times:
https://llvm-compile-time-tracker.com/compare.php?from=574d0a92060bf4808776b7a0239ffe91a092b15d&to=0317105f559093cfb909bfb01857a6b837991940&stat=instructions:u
2025-08-18 17:15:31 +02:00
Timm Baeder
7a6c9813d6
[clang][bytecode] Add AccessFlags to Block (#152590)
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 15:46:28 +02:00
Timm Baeder
d54516b9ad
[clang][bytecode][NFC] Use an existing local variable (#152710)
Instead of calling getSize() again.
2025-08-08 15:41:58 +02:00
Timm Baeder
8d26252eec
[clang][bytecode][NFC] Dead blocks are always uninitialized (#152699)
We always call the descriptor dtor before, so they are never
initialized.
2025-08-08 14:57:38 +02:00
Timm Baeder
fde9ee1ac2
[clang][bytecode] Don't deallocate dynamic blocks with pointers (#152672)
This fixes the edge case we had with variables pointing to dynamic
blocks, which forced us to convert basically *all* dynamic blocks to
DeadBlock when deallocating them.

We now don't run dynamic blocks through InterpState::deallocate() but
instead add them to a DeadAllocations list when they are deallocated but
still have pointers.

As a consequence, not all blocks with Block::IsDead = true are
DeadBlocks.
2025-08-08 13:02:01 +02:00
Timm Baeder
3b5cc2dc63
[clang][bytecode][NFC] Refactor DynamicAllocator a bit (#152510)
Use empty()-style functions instead of exposing the size if we don't
need it.
2025-08-07 17:03:53 +02:00
Timm Baeder
4784585747
[clang][bytecode][NFC] Remove unnecessary local variable (#152468)
Desc is only used once and we can get that information from the Block as
well.
2025-08-07 12:39:32 +02:00
Timm Baeder
8259be65c7
[clang][bytecode] Remove unused includes (#151848)
UnsignedOrNone.h from PrimType.h and ASTLambda.h from Function.h.
2025-08-03 08:52:03 +02:00
Timm Baeder
41803a2414
[clang][bytecode] Replace MoveFn With DtorFn + memcpy (#151717)
First, the old MoveFn was rather inefficient, since the dead data cannot
ever be accessed anyway.

Second, there was a problem where the only reason a block still had a
pointer to it (and thus was made into a DeadBlock instead of simply
being deallocated) as that a nested field in the block pointed to the
block itself.

Fix this by calling the dtor function unconditionally. If the block
*still* has pointers after that, we really need to create a DeadBlock
for it.
2025-08-02 14:47:49 +02:00
Timm Baeder
fb49c6784a
[clang][bytecode] Move Pointer::{Prev,Next} into BlockPointer (#151097)
They are only relevant for block pointers.
2025-07-30 10:17:21 +02:00
Timm Baeder
4eb66f7462
[clang][bytecode] Allow memory leaks before C++20 (#137445)
The expression allocating the memory wasn't valid in the first place.
This matches the diagnostic behavior of the current interpreter.
2025-04-26 07:13:44 +02:00
Timm Baeder
1a78ef9a9e
[clang][bytecode] Allow casts from void* only in std::allocator calls (#136714)
Otherwise, add the missing diagnostic.
2025-04-23 08:00:57 +02:00
Timm Baeder
06130ed341
Reapply "[clang][bytecode] Stack-allocate bottom function frame" (#12… (#125349)
…5325)

Move the BottomFrame to InterpState instead.
2025-02-01 18:12:35 +01:00
Jorge Gorbe Moya
386af4a5c6
Revert "[clang][bytecode] Stack-allocate bottom function frame" (#125325)
Reverts llvm/llvm-project#125253

It introduced an msan failure. Caught by a buildbot here:
https://lab.llvm.org/buildbot/#/builders/164/builds/6922/steps/17/logs/stdio
2025-01-31 20:09:14 -08:00
Timm Baeder
f3549814f8
[clang][bytecode] Stack-allocate bottom function frame (#125253)
Instead of heap-allocating it. This is similar to what the current
interpeter does. In C, we have no function calls, so the extra heap
allocation never makes sense.
2025-01-31 20:08:58 +01:00
Timm Baeder
a024a0ceed
[clang][bytecode] Override InConstantContext flag for immediate calls (#109967)
And fix the diagnostics for __builtin_is_constant_evaluated(). We can be
in a non-constant context, but calling an immediate function always
makes the context constant for the duration of that call.
2024-09-25 16:46:46 +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