llvm / llvm/llvm-project

[clang-check][syntax] Crash in TreeBuilder::foldChildren: Assertion `(EndChildren == Trees.end() || EndChildren->first == Tokens.end()) && "fold crosses boundaries of existing subtrees"' `failed. on fuzzer‑generated malformed C input

Open
#207,594 1 comment 0 reactions 0 assignees View on GitHub
clang-tools-extra crash generated by fuzzer
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

This is generated by a fuzzer.
Possibly related to https://github.com/llvm/llvm-project/issues/207567.

```c
foo (bar
int foo;
foo
```

```
clang-check \
--syntax-tree-dump \
example.c \
-- -xc -std=c11
```

Assertion:

```
(EndChildren == Trees.end() || EndChildren->first == Tokens.end()) && "fold crosses boundaries of existing subtrees"
```

stacktracec:
```
clang-check: /home/ubuntu2404/llvm-project-196067/clang/lib/Tooling/Syntax/BuildTree.cpp:636: void clang::syntax::TreeBuilder::Forest::foldChildren(const clang::syntax::TokenBuffer&, llvm::ArrayRef, clang::syntax::Tree*): Assertion `(EndChildren == Trees.end() || EndChildren->first == Tokens.end()) && "fold crosses boundaries of existing subtrees"' failed.
#0 0x000062f2593d61f1 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/ubuntu2404/build-196067-assert/bin/clang-check+0x96d1f1)
#1 0x000062f2593d2dac llvm::sys::RunSignalHandlers() (/home/ubuntu2404/build-196067-assert/bin/clang-check+0x969dac)
#2 0x000062f2593d2f0c SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
#3 0x000078aa0c045330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330)
#4 0x000078aa0c09eb2c __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
#5 0x000078aa0c09eb2c __pthread_kill_internal ./nptl/pthread_kill.c:78:10
#6 0x000078aa0c09eb2c pthread_kill ./nptl/pthread_kill.c:89:10
#7 0x000078aa0c04527e raise ./signal/../sysdeps/posix/raise.c:27:6
#8 0x000078aa0c0288ff abort ./stdlib/abort.c:81:7
#9 0x000078aa0c02881b _nl_load_domain ./intl/loadmsgcat.c:1177:9
#10 0x000078aa0c03b517 (/lib/x86_64-linux-gnu/libc.so.6+0x3b517)
#11 0x000062f25976de6e clang::syntax::TreeBuilder::foldNode(llvm::ArrayRef, clang::syntax::Tree*, llvm::PointerUnion) (/home/ubuntu2404/build-196067-assert/bin/clang-check+0xd04e6e)
#12 0x000062f25976e580 (anonymous namespace)::BuildTreeVisitor::WalkUpFromFunctionTypeLoc(clang::FunctionTypeLoc) BuildTree.cpp:0:0
#13 0x000062f259776028 clang::RecursiveASTVisitor<(anonymous namespace)::BuildTreeVisitor>::TraverseFunctionProtoTypeLoc(clang::FunctionProtoTypeLoc, bool) (.isra.0) BuildTree.cpp:0:0
#14 0x000062f2597770f5 clang::RecursiveASTVisitor<(anonymous namespace)::BuildTreeVisitor>::TraverseTypeLoc(clang::TypeLoc, bool) (.constprop.0) BuildTree.cpp:0:0
#15 0x000062f25978859f clang::RecursiveASTVisitor<(anonymous namespace)::BuildTreeVisitor>::TraverseFunctionHelper(clang::FunctionDecl*) BuildTree.cpp:0:0
#16 0x000062f259774ddc clang::RecursiveASTVisitor<(anonymous namespace)::BuildTreeVisitor>::TraverseDecl(clang::Decl*) BuildTree.cpp:0:0
#17 0x000062f259775aea clang::RecursiveASTVisitor<(anonymous namespace)::BuildTreeVisitor>::TraverseDeclContextHelper(clang::DeclContext*) BuildTree.cpp:0:0
#18 0x000062f25978e83b clang::RecursiveASTVisitor<(anonymous namespace)::BuildTreeVisitor>::TraverseTranslationUnitDecl(clang::TranslationUnitDecl*) BuildTree.cpp:0:0
#19 0x000062f259775439 clang::syntax::buildSyntaxTree(clang::syntax::Arena&, clang::syntax::TokenBufferTokenManager&, clang::ASTContext&) (/home/ubuntu2404/build-196067-assert/bin/clang-check+0xd0c439)
#20 0x000062f258e694af (anonymous namespace)::DumpSyntaxTree::CreateASTConsumer(clang::CompilerInstance&, llvm::StringRef)::Consumer::HandleTranslationUnit(clang::ASTContext&) ClangCheck.cpp:0:0
#21 0x000062f25ac9ff9c clang::ParseAST(clang::Sema&, bool, bool) (/home/ubuntu2404/build-196067-assert/bin/clang-check+0x2236f9c)
#22 0x000062f25942d271 clang::FrontendAction::Execute() (/home/ubuntu2404/build-196067-assert/bin/clang-check+0x9c4271)
#23 0x000062f259479308 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/home/ubuntu2404/build-196067-assert/bin/clang-check+0xa10308)
#24 0x000062f259755cb7 clang::tooling::FrontendActionFactory::runInvocation(std::shared_ptr, clang::FileManager*, std::shared_ptr, clang::DiagnosticConsumer*) (/home/ubuntu2404/build-196067-assert/bin/clang-check+0xceccb7)
#25 0x000062f25974fb2a clang::tooling::ToolInvocation::runInvocation(char const*, clang::driver::Compilation*, std::shared_ptr, std::shared_ptr) (/home/ubuntu2404/build-196067-assert/bin/clang-check+0xce6b2a)
#26 0x000062f2597521e2 clang::tooling::ToolInvocation::run() (/home/ubuntu2404/build-196067-assert/bin/clang-check+0xce91e2)
#27 0x000062f259753e19 clang::tooling::ClangTool::run(clang::tooling::ToolAction*) (/home/ubuntu2404/build-196067-assert/bin/clang-check+0xceae19)
#28 0x000062f258dee405 main (/home/ubuntu2404/build-196067-assert/bin/clang-check+0x385405)
#29 0x000078aa0c02a1ca __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:74:3
#30 0x000078aa0c02a28b call_init ./csu/../csu/libc-start.c:128:20
#31 0x000078aa0c02a28b __libc_start_main ./csu/../csu/libc-start.c:347:5
#32 0x000062f258e68045 _start (/home/ubuntu2404/build-196067-assert/bin/clang-check+0x3ff045)
Aborted (core dumped)
```

Contributor guide

Open the contributing guide

Research direction

Start with clang/lib/Tooling/Syntax/BuildTree.cpp at the reported foldChildren assertion, then reproduce the crash using the provided malformed C input and clang-check command. Trace how the syntax tree is built for this input and verify that the command no longer aborts on the assertion.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.