[clang-check][syntax] Crash in setRole: Assertion `N->getRole() == NodeRole::Detached' failed.
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
This input is generated by a fuzzer.
Seems to be valid?
Maybe related to #207599
```cxx
static union {
int x;
};
auto test2() -> char(&)[__builtin_omp_required_simd_align(decltype(x))];
```
```
clang-check --tokens-dump example.cpp -- -xc++ -std=c++23
```
```
clang-check: /home/ubuntu2404/llvm-project-196067/clang/lib/Tooling/Syntax/BuildTree.cpp:556: void clang::syntax::TreeBuilder::setRole(clang::syntax::Node*, clang::syntax::NodeRole): Assertion `N->getRole() == NodeRole::Detached' failed.
#0 0x00005919deb371f1 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/ubuntu2404/build-196067-assert/bin/clang-check+0x96d1f1)
#1 0x00005919deb33dac llvm::sys::RunSignalHandlers() (/home/ubuntu2404/build-196067-assert/bin/clang-check+0x969dac)
#2 0x00005919deb33f0c SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
#3 0x0000744798c45330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330)
#4 0x0000744798c9eb2c __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
#5 0x0000744798c9eb2c __pthread_kill_internal ./nptl/pthread_kill.c:78:10
#6 0x0000744798c9eb2c pthread_kill ./nptl/pthread_kill.c:89:10
#7 0x0000744798c4527e raise ./signal/../sysdeps/posix/raise.c:27:6
#8 0x0000744798c288ff abort ./stdlib/abort.c:81:7
#9 0x0000744798c2881b _nl_load_domain ./intl/loadmsgcat.c:1177:9
#10 0x0000744798c3b517 (/lib/x86_64-linux-gnu/libc.so.6+0x3b517)
#11 0x00005919deecbb5b (/home/ubuntu2404/build-196067-assert/bin/clang-check+0xd01b5b)
#12 0x00005919deed06d1 (anonymous namespace)::BuildTreeVisitor::WalkUpFromMemberExpr(clang::MemberExpr*) BuildTree.cpp:0:0
#13 0x00005919deee0260 clang::RecursiveASTVisitor<(anonymous namespace)::BuildTreeVisitor>::TraverseStmt(clang::Stmt*, llvm::SmallVectorImpl, llvm::PointerIntPairInfo>>>*) (.constprop.0) BuildTree.cpp:0:0
#14 0x00005919deee6648 clang::RecursiveASTVisitor<(anonymous namespace)::BuildTreeVisitor>::TraverseDecltypeTypeLoc(clang::DecltypeTypeLoc, bool) (.isra.0) BuildTree.cpp:0:0
#15 0x00005919deed7a25 clang::RecursiveASTVisitor<(anonymous namespace)::BuildTreeVisitor>::TraverseTypeLoc(clang::TypeLoc, bool) (.constprop.0) BuildTree.cpp:0:0
#16 0x00005919deede147 clang::RecursiveASTVisitor<(anonymous namespace)::BuildTreeVisitor>::dataTraverseNode(clang::Stmt*, llvm::SmallVectorImpl, llvm::PointerIntPairInfo>>>*) BuildTree.cpp:0:0
#17 0x00005919deede9be clang::RecursiveASTVisitor<(anonymous namespace)::BuildTreeVisitor>::TraverseStmt(clang::Stmt*, llvm::SmallVectorImpl, llvm::PointerIntPairInfo>>>*) (.constprop.0) BuildTree.cpp:0:0
#18 0x00005919deef151c clang::RecursiveASTVisitor<(anonymous namespace)::BuildTreeVisitor>::TraverseConstantArrayTypeLoc(clang::ConstantArrayTypeLoc, bool) (.isra.0) BuildTree.cpp:0:0
#19 0x00005919deed81f5 clang::RecursiveASTVisitor<(anonymous namespace)::BuildTreeVisitor>::TraverseTypeLoc(clang::TypeLoc, bool) (.constprop.0) BuildTree.cpp:0:0
#20 0x00005919deed7bd1 clang::RecursiveASTVisitor<(anonymous namespace)::BuildTreeVisitor>::TraverseTypeLoc(clang::TypeLoc, bool) (.constprop.0) BuildTree.cpp:0:0
#21 0x00005919deef03ad clang::RecursiveASTVisitor<(anonymous namespace)::BuildTreeVisitor>::TraverseLValueReferenceTypeLoc(clang::LValueReferenceTypeLoc, bool) (.isra.0) BuildTree.cpp:0:0
#22 0x00005919deed82e5 clang::RecursiveASTVisitor<(anonymous namespace)::BuildTreeVisitor>::TraverseTypeLoc(clang::TypeLoc, bool) (.constprop.0) BuildTree.cpp:0:0
#23 0x00005919deed6d15 clang::RecursiveASTVisitor<(anonymous namespace)::BuildTreeVisitor>::TraverseFunctionProtoTypeLoc(clang::FunctionProtoTypeLoc, bool) (.isra.0) BuildTree.cpp:0:0
#24 0x00005919deed80f5 clang::RecursiveASTVisitor<(anonymous namespace)::BuildTreeVisitor>::TraverseTypeLoc(clang::TypeLoc, bool) (.constprop.0) BuildTree.cpp:0:0
#25 0x00005919deee959f clang::RecursiveASTVisitor<(anonymous namespace)::BuildTreeVisitor>::TraverseFunctionHelper(clang::FunctionDecl*) BuildTree.cpp:0:0
#26 0x00005919deed5ddc clang::RecursiveASTVisitor<(anonymous namespace)::BuildTreeVisitor>::TraverseDecl(clang::Decl*) BuildTree.cpp:0:0
#27 0x00005919deed6aea clang::RecursiveASTVisitor<(anonymous namespace)::BuildTreeVisitor>::TraverseDeclContextHelper(clang::DeclContext*) BuildTree.cpp:0:0
#28 0x00005919deeef83b clang::RecursiveASTVisitor<(anonymous namespace)::BuildTreeVisitor>::TraverseTranslationUnitDecl(clang::TranslationUnitDecl*) BuildTree.cpp:0:0
#29 0x00005919deed6439 clang::syntax::buildSyntaxTree(clang::syntax::Arena&, clang::syntax::TokenBufferTokenManager&, clang::ASTContext&) (/home/ubuntu2404/build-196067-assert/bin/clang-check+0xd0c439)
#30 0x00005919de5ca4af (anonymous namespace)::DumpSyntaxTree::CreateASTConsumer(clang::CompilerInstance&, llvm::StringRef)::Consumer::HandleTranslationUnit(clang::ASTContext&) ClangCheck.cpp:0:0
#31 0x00005919e0400f9c clang::ParseAST(clang::Sema&, bool, bool) (/home/ubuntu2404/build-196067-assert/bin/clang-check+0x2236f9c)
#32 0x00005919deb8e271 clang::FrontendAction::Execute() (/home/ubuntu2404/build-196067-assert/bin/clang-check+0x9c4271)
#33 0x00005919debda308 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/home/ubuntu2404/build-196067-assert/bin/clang-check+0xa10308)
#34 0x00005919deeb6cb7 clang::tooling::FrontendActionFactory::runInvocation(std::shared_ptr, clang::FileManager*, std::shared_ptr, clang::DiagnosticConsumer*) (/home/ubuntu2404/build-196067-assert/bin/clang-check+0xceccb7)
#35 0x00005919deeb0b2a clang::tooling::ToolInvocation::runInvocation(char const*, clang::driver::Compilation*, std::shared_ptr, std::shared_ptr) (/home/ubuntu2404/build-196067-assert/bin/clang-check+0xce6b2a)
#36 0x00005919deeb31e2 clang::tooling::ToolInvocation::run() (/home/ubuntu2404/build-196067-assert/bin/clang-check+0xce91e2)
#37 0x00005919deeb4e19 clang::tooling::ClangTool::run(clang::tooling::ToolAction*) (/home/ubuntu2404/build-196067-assert/bin/clang-check+0xceae19)
#38 0x00005919de54f405 main (/home/ubuntu2404/build-196067-assert/bin/clang-check+0x385405)
#39 0x0000744798c2a1ca __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:74:3
#40 0x0000744798c2a28b call_init ./csu/../csu/libc-start.c:128:20
#41 0x0000744798c2a28b __libc_start_main ./csu/../csu/libc-start.c:347:5
#42 0x00005919de5c9045 _start (/home/ubuntu2404/build-196067-assert/bin/clang-check+0x3ff045)
Aborted (core dumped)
```
Contributor guide
Research direction
Reproduce the crash with clang-check --tokens-dump example.cpp -- -xc++ -std=c++23, then inspect clang/lib/Tooling/Syntax/BuildTree.cpp around setRole at line 556 and the MemberExpr traversal shown in the stack trace. Done means the supplied input no longer triggers the assertion while syntax-tree construction completes normally.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100