8000 [clang][bytecode] Classify variable initializer, not the decl by tbaederr · Pull Request #146338 · llvm/llvm-project · GitHub
[go: up one dir, main page]

Skip to content

[clang][bytecode] Classify variable initializer, not the decl #146338

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

8000

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 30, 2025

Conversation

tbaederr
Copy link
Contributor
@tbaederr tbaederr commented Jun 30, 2025

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

@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" clang:bytecode Issues for the clang bytecode constexpr interpreter labels Jun 30, 2025
@llvmbot
Copy link
Member
llvmbot commented Jun 30, 2025

@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)

Changes

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&lt;std::add_pointer, clang::ASTDeclWriter, void&gt;::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&lt;clang::Sema *, clang::Preprocessor *&gt; @ 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&amp;)::$_0::operator()(this=0x00007bff805225e0) const at CompilerInstance.cpp:1291:18
[...]
    frame #<!-- -->39: 0x00007fffa3ab2a35 libLLVM.so.21.0git`void* llvm::thread::ThreadProxy&lt;std::tuple&lt;void (*)(void*), (anonymous namespace)::RunSafelyOnThreadInfo*&gt;&gt;(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 &lt;/[...]test-suite-install/include/c++/v1/__condition_variable/condition_variable.h:49:3, col:53&gt; col:8 in std.condition_variable.condition_variable hidden referenced __result_max '_Rep' cinit `-CallExpr 0x7bff79077078 &lt;col:23, col:53&gt; 'type':'long long'
  `-ImplicitCastExpr 0x7bff79077058 &lt;col:23, col:49&gt; 'type (*)() noexcept' &lt;FunctionToPointerDecay&gt;
    `-DeclRefExpr 0x7bff79076670 &lt;col:23, col:49&gt; 'type () noexcept' lvalue CXXMethod 0x7bff791df1f8 'max' 'type () noexcept'
      `-NestedNameSpecifier TypeSpec 'numeric_limits&lt;__ns_rep&gt;':'std::numeric_limits&lt;long long&gt;'

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
```

---
Full diff: https://github.com/llvm/llvm-project/pull/146338.diff


1 Files Affected:

- (modified) clang/lib/AST/ByteCode/Compiler.cpp (+4-3) 


````
8000
``````diff
diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp
index 81da16e797bce..91918bf389da5 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -4574,15 +4574,15 @@ VarCreationState Compiler<Emitter>::visitDecl(const VarDecl *VD,
 template <class Emitter>
 bool Compiler<Emitter>::visitDeclAndReturn(const VarDecl *VD,
                                            bool ConstantContext) {
-  std::optional<PrimType> VarT = classify(VD->getType());
 
   // We only create variables if we're evaluating in a constant context.
   // Otherwise, just evaluate the initializer and return it.
   if (!ConstantContext) {
     DeclScope<Emitter> LS(this, VD);
-    if (!this->visit(VD->getAnyInitializer()))
+    const Expr *Init = VD->getInit();
+    if (!this->visit(Init))
       return false;
-    return this->emitRet(VarT.value_or(PT_Ptr), VD) && LS.destroyLocals() &&
+    return this->emitRet(classify(Init).value_or(PT_Ptr), VD) && LS.destroyLocals() &&
            this->emitCheckAllocations(VD);
   }
 
@@ -4590,6 +4590,7 @@ bool Compiler<Emitter>::visitDeclAndReturn(const VarDecl *VD,
   if (!this->visitVarDecl(VD, /*Toplevel=*/true))
     return false;
 
+  std::optional<PrimType> VarT = classify(VD->getType());
   if (Context::shouldBeGloballyIndexed(VD)) {
     auto GlobalIndex = P.getGlobal(VD);
     assert(GlobalIndex); // visitVarDecl() didn't return false.

Copy link
github-actions bot commented Jun 30, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

I'm not attaching a test case because I wasn't able to reproduce.
The backtrace looks as follows:

    frame llvm#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 llvm#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 llvm#12: 0x00007fffdde7ca84 libclang-cpp.so.21.0git`clang::VarDecl::evaluateValueImpl(this=0x00007bff77ce24b0, Notes=0x00007bff7f0d1620, IsConstantInitialization=false) const at Decl.cpp:2607:23
    frame llvm#13: 0x00007fffdde7a4a2 libclang-cpp.so.21.0git`clang::VarDecl::evaluateValue(this=0x00007bff77ce24b0) const at Decl.cpp:2583:10
    frame llvm#14: 0x00007fffdde7a0d7 libclang-cpp.so.21.0git`clang::VarDecl::hasInitWithSideEffects(this=0x00007bff77ce24b0) const at Decl.cpp:2458:39
    frame llvm#15: 0x00007fffe8c2e77b libclang-cpp.so.21.0git`clang::ASTDeclWriter::VisitVarDecl(this=0x00007bff7f381b50, D=0x00007bff77ce24b0) at ASTWriterDecl.cpp:1308:27
    frame llvm#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 llvm#17: 0x00007fffe8c1ad7e libclang-cpp.so.21.0git`clang::ASTDeclWriter::Visit(this=0x00007bff7f381b50, D=0x00007bff77ce24b0) at ASTWriterDecl.cpp:460:31
    frame llvm#18: 0x00007fffe8c4f5ae libclang-cpp.so.21.0git`clang::ASTWriter::WriteDecl(this=0x00007e0f83dd8608, Context=0x00007e9f839f8200, D=0x00007bff77ce24b0) at ASTWriterDecl.cpp:3060:5
    frame llvm#19: 0x00007fffe8a908a7 libclang-cpp.so.21.0git`clang::ASTWriter::WriteDeclAndTypes(this=0x00007e0f83dd8608, Context=0x00007e9f839f8200) at ASTWriter.cpp:6243:9
    frame llvm#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 llvm#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 llvm#22: 0x00007fffe8cd2168 libclang-cpp.so.21.0git`clang::PCHGenerator::HandleTranslationUnit(this=0x00007e0f83dd8500, Ctx=0x00007e9f839f8200) at GeneratePCH.cpp:86:30
    frame llvm#23: 0x00007fffe9595e11 libclang-cpp.so.21.0git`clang::MultiplexConsumer::HandleTranslationUnit(this=0x00007c5f83a00300, Ctx=0x00007e9f839f8200) at MultiplexConsumer.cpp:339:15
    frame llvm#24: 0x00007fffdc94121d libclang-cpp.so.21.0git`clang::ParseAST(S=0x00007e8f83cd3200, PrintStats=false, SkipFunctionBodies=false) at ParseAST.cpp:183:13
    frame llvm#25: 0x00007fffe9480085 libclang-cpp.so.21.0git`clang::ASTFrontendAction::ExecuteAction(this=0x00007bff7efb9020) at FrontendAction.cpp:1339:3
    frame llvm#26: 0x00007fffe947e650 libclang-cpp.so.21.0git`clang::FrontendAction::Execute(this=0x00007bff7efb9020) at FrontendAction.cpp:1221:3
    frame llvm#27: 0x00007fffe915a163 libclang-cpp.so.21.0git`clang::CompilerInstance::ExecuteAction(this=0x00007d2f839ef000, Act=0x00007bff7efb9020) at CompilerInstance.cpp:1055:33
    frame llvm#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 llvm#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 llvm#40: 0x000000000039933b clang++`asan_thread_start(void*) + 155
    frame llvm#41: 0x00007fff84a7dfa8 libc.so.6`start_thread + 952
    frame llvm#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 extractred 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
@tbaederr tbaederr changed the title [clang][bytecode] Classify varible initializer, not the decl [clang][bytecode] Classify variable initializer, not the decl Jun 30, 2025
@tbaederr tbaederr merged commit 36cf51d into llvm:main Jun 30, 2025
7 checks passed
@llvm-ci
Copy link
Collaborator
llvm-ci commented Jun 30, 2025

LLVM Buildbot has detected a new failure on builder clangd-ubuntu-tsan running on clangd-ubuntu-clang while building clang at step 5 "build-clangd-clangd-index-server-clangd-indexer".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/134/builds/21619

Here is the relevant piece of the build log for the reference
Step 5 (build-clangd-clangd-index-server-clangd-indexer) failure: build (failure)
0.007 [3320/18/1] Building CXX object lib/Demangle/CMakeFiles/LLVMDemangle.dir/MicrosoftDemangle.cpp.o
FAILED: lib/Demangle/CMakeFiles/LLVMDemangle.dir/MicrosoftDemangle.cpp.o 
ccache /usr/bin/clang++ -DGTEST_HAS_RTTI=0 -D_DEBUG -D_GLIBCXX_ASSERTIONS -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/vol/worker/clangd-ubuntu-clang/clangd-ubuntu-tsan/build/lib/Demangle -I/vol/worker/clangd-ubuntu-clang/clangd-ubuntu-tsan/llvm-project/llvm/lib/Demangle -I/vol/worker/clangd-ubuntu-clang/clangd-ubuntu-tsan/build/include -I/vol/worker/clangd-ubuntu-clang/clangd-ubuntu-tsan/llvm-project/llvm/include -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fno-omit-frame-pointer -gline-tables-only -fsanitize=thread -fdiagnostics-color -ffunction-sections -fdata-sections -O3 -DNDEBUG  -fno-exceptions -funwind-tables -fno-rtti -UNDEBUG -std=c++17 -MD -MT lib/Demangle/CMakeFiles/LLVMDemangle.dir/MicrosoftDemangle.cpp.o -MF lib/Demangle/CMakeFiles/LLVMDemangle.dir/MicrosoftDemangle.cpp.o.d -o lib/Demangle/CMakeFiles/LLVMDemangle.dir/MicrosoftDemangle.cpp.o -c /vol/worker/clangd-ubuntu-clang/clangd-ubuntu-tsan/llvm-project/llvm/lib/Demangle/MicrosoftDemangle.cpp
ccache: error: /vol/ccache/ccache.conf: No such file or directory
0.008 [3320/17/2] Creating /vol/worker/clangd-ubuntu-clang/clangd-ubuntu-tsan/build/NATIVE...
0.067 [3320/16/3] Building CXX object lib/Support/CMakeFiles/LLVMSupport.dir/ABIBreak.cpp.o
0.559 [3320/15/4] Building CXX object lib/Demangle/CMakeFiles/LLVMDemangle.dir/DLangDemangle.cpp.o
0.577 [3320/14/5] Building CXX object lib/Demangle/CMakeFiles/LLVMDemangle.dir/Demangle.cpp.o
0.896 [3320/13/6] Building CXX object lib/Support/CMakeFiles/LLVMSupport.dir/HexagonAttributes.cpp.o
0.988 [3320/12/7] Building CXX object lib/Support/CMakeFiles/LLVMSupport.dir/ARMBuildAttributes.cpp.o
1.137 [3320/11/8] Building CXX object lib/Support/CMakeFiles/LLVMSupport.dir/InstructionCost.cpp.o
1.277 [3320/10/9] Building CXX object lib/Support/CMakeFiles/LLVMSupport.dir/APSInt.cpp.o
1.277 [3320/9/10] Building CXX object lib/Demangle/CMakeFiles/LLVMDemangle.dir/MicrosoftDemangleNodes.cpp.o
1.343 [3320/8/11] Building CXX object lib/Demangle/CMakeFiles/LLVMDemangle.dir/RustDemangle.cpp.o
1.439 [3320/7/12] Building CXX object lib/Support/CMakeFiles/LLVMSupport.dir/InitLLVM.cpp.o
1.544 [3320/6/13] Building CXX object lib/Support/CMakeFiles/LLVMSupport.dir/HexagonAttributeParser.cpp.o
1.782 [3320/5/14] Building CXX object lib/Support/CMakeFiles/LLVMSupport.dir/APFixedPoint.cpp.o
2.195 [3320/4/15] Building CXX object lib/Support/CMakeFiles/LLVMSupport.dir/AMDGPUMetadata.cpp.o
3.990 [3320/3/16] Building CXX object lib/Support/CMakeFiles/LLVMSupport.dir/APInt.cpp.o
4.119 [3320/2/17] Building CXX object lib/Support/CMakeFiles/LLVMSupport.dir/APFloat.cpp.o
5.080 [3320/1/18] Building CXX object lib/Demangle/CMakeFiles/LLVMDemangle.dir/ItaniumDemangle.cpp.o
ninja: build stopped: subcommand failed.

rlavaee pushed a commit to rlavaee/llvm-project that referenced this pull request Jul 1, 2025
…46338)

I'm not attaching a test case because I wasn't able to reproduce. The
backtrace looks as follows:

```
    frame llvm#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 llvm#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 llvm#12: 0x00007fffdde7ca84 libclang-cpp.so.21.0git`clang::VarDecl::evaluateValueImpl(this=0x00007bff77ce24b0, Notes=0x00007bff7f0d1620, IsConstantInitialization=false) const at Decl.cpp:2607:23
    frame llvm#13: 0x00007fffdde7a4a2 libclang-cpp.so.21.0git`clang::VarDecl::evaluateValue(this=0x00007bff77ce24b0) const at Decl.cpp:2583:10
    frame llvm#14: 0x00007fffdde7a0d7 libclang-cpp.so.21.0git`clang::VarDecl::hasInitWithSideEffects(this=0x00007bff77ce24b0) const at Decl.cpp:2458:39
    frame llvm#15: 0x00007fffe8c2e77b libclang-cpp.so.21.0git`clang::ASTDeclWriter::VisitVarDecl(this=0x00007bff7f381b50, D=0x00007bff77ce24b0) at ASTWriterDecl.cpp:1308:27
    frame llvm#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 llvm#17: 0x00007fffe8c1ad7e libclang-cpp.so.21.0git`clang::ASTDeclWriter::Visit(this=0x00007bff7f381b50, D=0x00007bff77ce24b0) at ASTWriterDecl.cpp:460:31
    frame llvm#18: 0x00007fffe8c4f5ae libclang-cpp.so.21.0git`clang::ASTWriter::WriteDecl(this=0x00007e0f83dd8608, Context=0x00007e9f839f8200, D=0x00007bff77ce24b0) at ASTWriterDecl.cpp:3060:5
    frame llvm#19: 0x00007fffe8a908a7 libclang-cpp.so.21.0git`clang::ASTWriter::WriteDeclAndTypes(this=0x00007e0f83dd8608, Context=0x00007e9f839f8200) at ASTWriter.cpp:6243:9
    frame llvm#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 llvm#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 llvm#22: 0x00007fffe8cd2168 libclang-cpp.so.21.0git`clang::PCHGenerator::HandleTranslationUnit(this=0x00007e0f83dd8500, Ctx=0x00007e9f839f8200) at GeneratePCH.cpp:86:30
    frame llvm#23: 0x00007fffe9595e11 libclang-cpp.so.21.0git`clang::MultiplexConsumer::HandleTranslationUnit(this=0x00007c5f83a00300, Ctx=0x00007e9f839f8200) at MultiplexConsumer.cpp:339:15
    frame llvm#24: 0x00007fffdc94121d libclang-cpp.so.21.0git`clang::ParseAST(S=0x00007e8f83cd3200, PrintStats=false, SkipFunctionBodies=false) at ParseAST.cpp:183:13
    frame llvm#25: 0x00007fffe9480085 libclang-cpp.so.21.0git`clang::ASTFrontendAction::ExecuteAction(this=0x00007bff7efb9020) at FrontendAction.cpp:1339:3
    frame llvm#26: 0x00007fffe947e650 libclang-cpp.so.21.0git`clang::FrontendAction::Execute(this=0x00007bff7efb9020) at FrontendAction.cpp:1221:3
    frame llvm#27: 0x00007fffe915a163 libclang-cpp.so.21.0git`clang::CompilerInstance::ExecuteAction(this=0x00007d2f839ef000, Act=0x00007bff7efb9020) at CompilerInstance.cpp:1055:33
    frame llvm#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 llvm#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 llvm#40: 0x000000000039933b clang++`asan_thread_start(void*) + 155
    frame llvm#41: 0x00007fff84a7dfa8 libc.so.6`start_thread + 952
    frame llvm#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
```
rlavaee pushed a commit to rlavaee/llvm-project that referenced this pull request Jul 1, 2025
…46338)

I'm not attaching a test case because I wasn't able to reproduce. The
backtrace looks as follows:

```
    frame llvm#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 llvm#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 llvm#12: 0x00007fffdde7ca84 libclang-cpp.so.21.0git`clang::VarDecl::evaluateValueImpl(this=0x00007bff77ce24b0, Notes=0x00007bff7f0d1620, IsConstantInitialization=false) const at Decl.cpp:2607:23
    frame llvm#13: 0x00007fffdde7a4a2 libclang-cpp.so.21.0git`clang::VarDecl::evaluateValue(this=0x00007bff77ce24b0) const at Decl.cpp:2583:10
    frame llvm#14: 0x00007fffdde7a0d7 libclang-cpp.so.21.0git`clang::VarDecl::hasInitWithSideEffects(this=0x00007bff77ce24b0) const at Decl.cpp:2458:39
    frame llvm#15: 0x00007fffe8c2e77b libclang-cpp.so.21.0git`clang::ASTDeclWriter::VisitVarDecl(this=0x00007bff7f381b50, D=0x00007bff77ce24b0) at ASTWriterDecl.cpp:1308:27
    frame llvm#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 llvm#17: 0x00007fffe8c1ad7e libclang-cpp.so.21.0git`clang::ASTDeclWriter::Visit(this=0x00007bff7f381b50, D=0x00007bff77ce24b0) at ASTWriterDecl.cpp:460:31
    frame llvm#18: 0x00007fffe8c4f5ae libclang-cpp.so.21.0git`clang::ASTWriter::WriteDecl(this=0x00007e0f83dd8608, Context=0x00007e9f839f8200, D=0x00007bff77ce24b0) at ASTWriterDecl.cpp:3060:5
    frame llvm#19: 0x00007fffe8a908a7 libclang-cpp.so.21.0git`clang::ASTWriter::WriteDeclAndTypes(this=0x00007e0f83dd8608, Context=0x00007e9f839f8200) at ASTWriter.cpp:6243:9
    frame llvm#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 llvm#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 llvm#22: 0x00007fffe8cd2168 libclang-cpp.so.21.0git`clang::PCHGenerator::HandleTranslationUnit(this=0x00007e0f83dd8500, Ctx=0x00007e9f839f8200) at GeneratePCH.cpp:86:30
    frame llvm#23: 0x00007fffe9595e11 libclang-cpp.so.21.0git`clang::MultiplexConsumer::HandleTranslationUnit(this=0x00007c5f83a00300, Ctx=0x00007e9f839f8200) at MultiplexConsumer.cpp:339:15
    frame llvm#24: 0x00007fffdc94121d libclang-cpp.so.21.0git`clang::ParseAST(S=0x00007e8f83cd3200, PrintStats=false, SkipFunctionBodies=false) at ParseAST.cpp:183:13
    frame llvm#25: 0x00007fffe9480085 libclang-cpp.so.21.0git`clang::ASTFrontendAction::ExecuteAction(this=0x00007bff7efb9020) at FrontendAction.cpp:1339:3
    frame llvm#26: 0x00007fffe947e650 libclang-cpp.so.21.0git`clang::FrontendAction::Execute(this=0x00007bff7efb9020) at FrontendAction.cpp:1221:3
    frame llvm#27: 0x00007fffe915a163 libclang-cpp.so.21.0git`clang::CompilerInstance::ExecuteAction(this=0x00007d2f839ef000, Act=0x00007bff7efb9020) at CompilerInstance.cpp:1055:33
    frame llvm#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 llvm#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 llvm#40: 0x000000000039933b clang++`asan_thread_start(void*) + 155
    frame llvm#41: 0x00007fff84a7dfa8 libc.so.6`start_thread + 952
    frame llvm#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 
6DBA
-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
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:bytecode Issues for the clang bytecode constexpr interpreter clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0