aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/AST/ByteCode
AgeCommit message (Collapse)AuthorFilesLines
3 days[clang][bytecode] Activate primitive fields before initializing them (#149963)Timm Baeder4-39/+63
The initializer itself might need the field to be active.
3 days[clang][bytecode] Only implicitly start lifetime of ↵Timm Baeder1-1/+8
trivially-default-constructible union members (#149835) See https://github.com/llvm/llvm-project/commit/faee39baa87e43f4b746dd77e479268391163658
4 days[clang][bytecode] Error on bitcasts to bool that aren't 0 or 1 (#149996)Timm Baeder1-2/+12
This is also what the current interpreter does.
4 days[clang][bytecode] Use OptPrimType instead of std::optional<PrimType> (#149812)Timm Baeder11-92/+120
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
6 days[clang][bytecode] Reintroduce Pointer::elem() (#149693)Timm Baeder7-52/+67
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.
6 days[clang][bytecode] Use in Expr::tryEvaluateStrLen() (#149677)Timm Baeder2-0/+41
Fixes #138475
6 days[clang][bytecode] Diagnose dereferencing a null pointer (#149330)Timm Baeder3-0/+14
7 days[clang][bytecode] Use bytecode interpreter in isPotentialConstantExprU… ↵Timm Baeder7-3/+46
(#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
8 days[clang][bytecode] Fix const-in-mutable fields (#149286)Timm Baeder5-1/+16
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.
8 days[clang][bytecode] Report mutable reads when copying unions (#149320)Timm Baeder2-0/+7
8 days[clang][bytecode][NFC] Remove unused includes (#149460)Timm Baeder2-6/+0
10 days[Clang] Diagnose forming references to nullptr (#143667)Corentin Jabot1-0/+1
Per [decl.ref], > Because a null pointer value or a pointer past the end of an object does not point to an object, a reference in a well-defined program cannot refer to such things. Note this does not fixes the new bytecode interpreter. Fixes #48665
10 days[clang][bytecode] Fix contains check using llvm::find (#149050)Timm Baeder1-1/+1
We need to compare to the end() interator.
10 days[clang][bytecode][NFC] Remove unused function prototypes (#149031)Timm Baeder2-18/+4
10 days[clang][bytecode] Make union activation more granular (#148835)Timm Baeder6-100/+335
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] Check lambda captures before binding decls (#148130)Timm Baeder1-12/+20
If the given decls is a lambda capture (but also a BindingDecl), handle it as a lambda capture instead of a BindingDecl.
2025-07-11[clang][bytecode] Keep a list of initializing blocks in InterpState (#148120)Timm Baeder2-22/+25
So we can know what blocks we're currently running constructors or destructors for.
2025-07-10[clang][bytecode][NFC] Move Pointer::StorageKind above the union (#147942)Timm Baeder2-5/+5
This is easier to read in debuggers and more common.
2025-07-10[clang][bytecode] Implement missing elementwise builtins (#147892)Timm Baeder1-5/+103
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-07-09[clang][bytecode] Devirtualize calls during con- and destruction (#147685)Timm Baeder2-3/+38
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-07-09[clang][bytecode][NFC] Don't push anything in OffsetHelper (#147550)Timm Baeder1-45/+60
Instead, return the new Pointer. This was weird before because some callers had to get the value from the stack again to perform further operations.
2025-07-08[clang][bytecode] Fix __builtin_is_within_lifetime in initializers (#147480)Timm Baeder1-1/+13
2025-07-08[clang][bytecode] Don't crash on erroneous switch conditions (#147533)Timm Baeder1-0/+3
Not attaching a test since I've only seen this when compiling a large c++26 test case as c++17.
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-08[clang][bytecode] Create a temporary for discarded CXXBindTemporaryExprs ↵Timm Baeder2-2/+16
(#147303) So we run the destructor.
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] Fix visiting for-range loop variable (#147188)Timm Baeder1-2/+1
Make sure we're properly registering DecompositionDecls.
2025-07-06[clang][bytecode] Fix a crash in overflow builtins (#147189)Timm Baeder1-1/+3
Only initialize pointers that can be initialized.
2025-07-06[clang][bytecode] Misc union fixes (#146824)Timm Baeder2-7/+32
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] Narrow allocated single-array Pointer (#147160)Timm Baeder1-1/+1
Since the result should not be an array element.
2025-07-05[clang][bytecode] Fix comparing pointers pointing to base classes (#146285)Timm Baeder3-26/+35
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-04[clang][bytecode] Fix copy constructors for empty unions (#147050)Timm Baeder1-0/+2
Nothing to do in that case.
2025-07-02[clang][bytecode] Add back missing initialize call (#146589)Timm Baeder1-5/+1
This was only accidentally dropped, so add it back.
2025-07-01[clang][bytecode] Check pointer data type for bitcast eligibility (#146552)Timm Baeder1-3/+4
So we get the proper type for a heap-allocated value.
2025-07-01[clang][bytecode] Allocate operator new data as array (#146471)Timm Baeder2-35/+18
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[clang][bytecode] Remove unused InRange function (#146509)Timm Baeder1-14/+0
2025-07-01[Clang][Bytecode] Implement P1061 structured binding pack (#146474)Yanzuo Liu1-1/+1
Other part of this feature was implemented by #121417.
2025-06-30[clang][bytecode] Classify variable initializer, not the decl (#146338)Timm Baeder1-4/+5
I'm not attaching a test case because I wasn't able to reproduce. The backtrace looks as follows: ``` frame #10: 0x00007fffdedf0b0d libclang-cpp.so.21.0git`clang::interp::Context::evaluateAsInitializer(this=0x00007c6f839f62f0, Parent=0x00007bff7f3820e0, VD=0x00007bff77ce24b0, Result=0x00007bff7165cd78) at Context.cpp:123:16 frame #11: 0x00007fffde7bcc2f libclang-cpp.so.21.0git`clang::Expr::EvaluateAsInitializer(this=0x00007bff77ce3078, Value=0x00007bff7165cd78, Ctx=0x00007e9f839f8200, VD=0x00007bff77ce24b0, Notes=0x00007bff7f0d1620, IsConstantInitialization=false) const at ExprConstant.cpp:17096:20 frame #12: 0x00007fffdde7ca84 libclang-cpp.so.21.0git`clang::VarDecl::evaluateValueImpl(this=0x00007bff77ce24b0, Notes=0x00007bff7f0d1620, IsConstantInitialization=false) const at Decl.cpp:2607:23 frame #13: 0x00007fffdde7a4a2 libclang-cpp.so.21.0git`clang::VarDecl::evaluateValue(this=0x00007bff77ce24b0) const at Decl.cpp:2583:10 frame #14: 0x00007fffdde7a0d7 libclang-cpp.so.21.0git`clang::VarDecl::hasInitWithSideEffects(this=0x00007bff77ce24b0) const at Decl.cpp:2458:39 frame #15: 0x00007fffe8c2e77b libclang-cpp.so.21.0git`clang::ASTDeclWriter::VisitVarDecl(this=0x00007bff7f381b50, D=0x00007bff77ce24b0) at ASTWriterDecl.cpp:1308:27 frame #16: 0x00007fffe8c58bf8 libclang-cpp.so.21.0git`clang::declvisitor::Base<std::add_pointer, clang::ASTDeclWriter, void>::Visit(this=0x00007bff7f381b50, D=0x00007bff77ce24b0) at DeclNodes.inc:296:1 frame #17: 0x00007fffe8c1ad7e libclang-cpp.so.21.0git`clang::ASTDeclWriter::Visit(this=0x00007bff7f381b50, D=0x00007bff77ce24b0) at ASTWriterDecl.cpp:460:31 frame #18: 0x00007fffe8c4f5ae libclang-cpp.so.21.0git`clang::ASTWriter::WriteDecl(this=0x00007e0f83dd8608, Context=0x00007e9f839f8200, D=0x00007bff77ce24b0) at ASTWriterDecl.cpp:3060:5 frame #19: 0x00007fffe8a908a7 libclang-cpp.so.21.0git`clang::ASTWriter::WriteDeclAndTypes(this=0x00007e0f83dd8608, Context=0x00007e9f839f8200) at ASTWriter.cpp:6243:9 frame #20: 0x00007fffe8a805f5 libclang-cpp.so.21.0git`clang::ASTWriter::WriteASTCore(this=0x00007e0f83dd8608, SemaPtr=0x00007e8f83cd3200, isysroot=(Data = "", Length = 0), WritingModule=0x00007e0f83d5bc18) at ASTWriter.cpp:6083:5 frame #21: 0x00007fffe8a7cfa2 libclang-cpp.so.21.0git`clang::ASTWriter::WriteAST(this=0x00007e0f83dd8608, Subject=PointerUnion<clang::Sema *, clang::Preprocessor *> @ 0x00007bff7f18e640, OutputFile=(Data = "/home/tbaeder/code/llvm-project/build/runtimes/runtimes-bins/libcxx/test/libcxx/clang_modules_include.gen.py/Output/complex.h.compile.pass.cpp.dir/t.tmp/1WNKSCAH8NSAM/std-PE20VSNDCJ1A.pcm", Length = 187), WritingModule=0x00007e0f83d5bc18, isysroot=(Data = "", Length = 0), ShouldCacheASTInMemory=true) at ASTWriter.cpp:5434:32 frame #22: 0x00007fffe8cd2168 libclang-cpp.so.21.0git`clang::PCHGenerator::HandleTranslationUnit(this=0x00007e0f83dd8500, Ctx=0x00007e9f839f8200) at GeneratePCH.cpp:86:30 frame #23: 0x00007fffe9595e11 libclang-cpp.so.21.0git`clang::MultiplexConsumer::HandleTranslationUnit(this=0x00007c5f83a00300, Ctx=0x00007e9f839f8200) at MultiplexConsumer.cpp:339:15 frame #24: 0x00007fffdc94121d libclang-cpp.so.21.0git`clang::ParseAST(S=0x00007e8f83cd3200, PrintStats=false, SkipFunctionBodies=false) at ParseAST.cpp:183:13 frame #25: 0x00007fffe9480085 libclang-cpp.so.21.0git`clang::ASTFrontendAction::ExecuteAction(this=0x00007bff7efb9020) at FrontendAction.cpp:1339:3 frame #26: 0x00007fffe947e650 libclang-cpp.so.21.0git`clang::FrontendAction::Execute(this=0x00007bff7efb9020) at FrontendAction.cpp:1221:3 frame #27: 0x00007fffe915a163 libclang-cpp.so.21.0git`clang::CompilerInstance::ExecuteAction(this=0x00007d2f839ef000, Act=0x00007bff7efb9020) at CompilerInstance.cpp:1055:33 frame #28: 0x00007fffe9175bbf libclang-cpp.so.21.0git`clang::CompilerInstance::compileModule(clang::SourceLocation, llvm::StringRef, llvm::StringRef, clang::CompilerInstance&)::$_0::operator()(this=0x00007bff805225e0) const at CompilerInstance.cpp:1291:18 [...] frame #39: 0x00007fffa3ab2a35 libLLVM.so.21.0git`void* llvm::thread::ThreadProxy<std::tuple<void (*)(void*), (anonymous namespace)::RunSafelyOnThreadInfo*>>(Ptr=0x00007c1f839e4330) at thread.h:58:5 frame #40: 0x000000000039933b clang++`asan_thread_start(void*) + 155 frame #41: 0x00007fff84a7dfa8 libc.so.6`start_thread + 952 frame #42: 0x00007fff84b01fcc libc.so.6`__clone3 + 44 ``` where we encounter this declaration: ``` VarDecl 0x7bff790764b0 </[...]test-suite-install/include/c++/v1/__condition_variable/condition_variable.h:49:3, col:53> col:8 in std.condition_variable.condition_variable hidden referenced __result_max '_Rep' cinit `-CallExpr 0x7bff79077078 <col:23, col:53> 'type':'long long' `-ImplicitCastExpr 0x7bff79077058 <col:23, col:49> 'type (*)() noexcept' <FunctionToPointerDecay> `-DeclRefExpr 0x7bff79076670 <col:23, col:49> 'type () noexcept' lvalue CXXMethod 0x7bff791df1f8 'max' 'type () noexcept' `-NestedNameSpecifier TypeSpec 'numeric_limits<__ns_rep>':'std::numeric_limits<long long>' ``` which looks fine at first, but the declaration type does not: ``` TemplateTypeParmType 0x7bff79074dd0 '_Rep' dependent depth 0 index 0 `-TemplateTypeParm 0x7bff79074d70 '_Rep' ``` we cannot classify this, so we later run into an assertion because we assume `PT_Ptr` while the value on the stack is of type `classify(long long)`. Work around this by only looking at the initializer type in that case. For the record, the command line that crashed could be extracted from `ninja check-cxx` and was: ``` /home/tbaeder/code/llvm-project/build/bin/clang++ /home/tbaeder/code/llvm-project/build/runtimes/runtimes-bins/libcxx/test/libcxx/clang_modules_include.gen.py/complex.h.compile.pass.cpp -pthread --target=x86_64-redhat-linux -nostdinc++ -I /home/tbaeder/code/llvm-project/build/runtimes/runtimes-bins/libcxx/test-suite-install/include/x86_64-redhat-linux/c++/v1 -I /home/tbaeder/code/llvm-project/build/runtimes/runtimes-bins/libcxx/test-suite-install/include/c++/v1 -I /home/tbaeder/code/llvm-project/libcxx/test/support -std=c++26 -Werror -Wall -Wctad-maybe-unsupported -Wextra -Wshadow -Wundef -Wunused-template -Wno-unused-command-line-argument -Wno-attributes -Wno-pessimizing-move -Wno-noexcept-type -Wno-atomic-alignment -Wno-reserved-module-identifier -Wdeprecated-copy -Wdeprecated-copy-dtor -Wshift-negative-value -Wno-user-defined-literals -Wno-tautological-compare -Wsign-compare -Wunused-variable -Wunused-parameter -Wunreachable-code -Wno-unused-local-typedef -Wno-local-type-template-args -Wno-c++11-extensions -Wno-unknown-pragmas -Wno-pass-failed -Wno-mismatched-new-delete -Wno-redundant-move -Wno-self-move -Wno-nullability-completeness -D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER -D_LIBCPP_ENABLE_EXPERIMENTAL -D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_EXTENSIVE -Werror=thread-safety -Wuser-defined-warnings -fmodules -fcxx-modules -fmodules-cache-path=/home/tbaeder/code/llvm-project/build/runtimes/runtimes-bins/libcxx/test/libcxx/clang_modules_include.gen.py/Output/complex.h.compile.pass.cpp.dir/t.tmp -fsyntax-only ```
2025-06-30[clang][bytecode] Add `Descriptor::hasTrivialDtor()` (#146286)Timm Baeder3-9/+27
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-30[clang][bytecode][NFC] Remove some dead code (#146287)Timm Baeder1-2/+0
2025-06-28[clang] Remove unused includes (NFC) (#146254)Kazu Hirata1-1/+0
These are identified by misc-include-cleaner. I've filtered out those that break builds. Also, I'm staying away from llvm-config.h, config.h, and Compiler.h, which likely cause platform- or compiler-specific build failures.
2025-06-27[Clang][ByteCode][NFC] Avoid copies by using move in Disasm.cpp (#146127)Shafik Yaghmour1-4/+4
Static analysis flagged some cases we could avoid copies by using std::move in Disasm.cpp.
2025-06-27[Clang][ByteCode][NFC] Misc minor performance fixes (#145988)Shafik Yaghmour1-8/+8
Static analysis flagged multiple places we could move instead of copy. In one case I realized we could avoid computing the same thing multiple times and did that fix instead.
2025-06-23[NFC][Clang][AST] Drop `llvm::` in front of `ArrayRef`/`MutableArrayRef` ↵Rahul Joshi6-9/+8
(#145207)
2025-06-23[clang][bytecode] Fix IntegralAP::{isMin,isMax} (#145339)Timm Baeder1-2/+10
We need to take signeness into account here.
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-23[clang][bytecode] Fix assignInteger() with allocated primtypes (#145302)Timm Baeder1-6/+17
2025-06-23[clang][bytecode] Fix shifts with an allocated RHS (#145280)Timm Baeder2-27/+38
This was broken before because we ended up using a constructor that was disabled via assert(false). Use ShiftAP() if either LHS or RHS is allocated.