llvm / llvm/llvm-project

[clang-check][syntax] buildIdentifier Assertion `NameSpecifierTokens.size() == 1'` failed.

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

Description

This input is generated by a fuzzer.
```cxx
namespace Templates {
template
void f() {
struct Inner {
static int getValue() { return Value; }
};
}
}
int main()
{
f();
}
```
```
clang-check --tokens-dump example.cpp -- -xc++ -std=c++23
```

stacktrace:
```
clang-check: /home/ubuntu2404/llvm-project-196067/clang/lib/Tooling/Syntax/BuildTree.cpp:934: clang::syntax::NameSpecifier* {anonymous}::BuildTreeVisitor::buildIdentifier(clang::SourceRange, bool): Assertion `NameSpecifierTokens.size() == 1' failed.
#0 0x0000644148dfd1f1 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/ubuntu2404/build-196067-assert/bin/clang-check+0x96d1f1)
#1 0x0000644148df9dac llvm::sys::RunSignalHandlers() (/home/ubuntu2404/build-196067-assert/bin/clang-check+0x969dac)
#2 0x0000644148df9f0c SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
#3 0x0000748e84845330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330)
#4 0x0000748e8489eb2c __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
#5 0x0000748e8489eb2c __pthread_kill_internal ./nptl/pthread_kill.c:78:10
#6 0x0000748e8489eb2c pthread_kill ./nptl/pthread_kill.c:89:10
#7 0x0000748e8484527e raise ./signal/../sysdeps/posix/raise.c:27:6
#8 0x0000748e848288ff abort ./stdlib/abort.c:81:7
#9 0x0000748e8482881b _nl_load_domain ./intl/loadmsgcat.c:1177:9
#10 0x0000748e8483b517 (/lib/x86_64-linux-gnu/libc.so.6+0x3b517)
#11 0x00006441491950c2 (anonymous namespace)::BuildTreeVisitor::buildIdentifier(clang::SourceRange, bool) BuildTree.cpp:0:0
#12 0x00006441491ac893 (anonymous namespace)::BuildTreeVisitor::TraverseNestedNameSpecifierLoc(clang::NestedNameSpecifierLoc) BuildTree.cpp:0:0
#13 0x00006441491af1e4 clang::RecursiveASTVisitor<(anonymous namespace)::BuildTreeVisitor>::TraverseUnresolvedMemberExpr(clang::UnresolvedMemberExpr*, llvm::SmallVectorImpl, llvm::PointerIntPairInfo>>>*) BuildTree.cpp:0:0
#14 0x00006441491a49be clang::RecursiveASTVisitor<(anonymous namespace)::BuildTreeVisitor>::TraverseStmt(clang::Stmt*, llvm::SmallVectorImpl, llvm::PointerIntPairInfo>>>*) (.constprop.0) BuildTree.cpp:0:0
#15 0x00006441491a9a2d clang::RecursiveASTVisitor<(anonymous namespace)::BuildTreeVisitor>::TraverseObjCBoxedExpr(clang::ObjCBoxedExpr*, llvm::SmallVectorImpl, llvm::PointerIntPairInfo>>>*) BuildTree.cpp:0:0
#16 0x00006441491a49be clang::RecursiveASTVisitor<(anonymous namespace)::BuildTreeVisitor>::TraverseStmt(clang::Stmt*, llvm::SmallVectorImpl, llvm::PointerIntPairInfo>>>*) (.constprop.0) BuildTree.cpp:0:0
#17 0x00006441491a6bfc clang::RecursiveASTVisitor<(anonymous namespace)::BuildTreeVisitor>::TraverseCompoundStmt(clang::CompoundStmt*, llvm::SmallVectorImpl, llvm::PointerIntPairInfo>>>*) BuildTree.cpp:0:0
#18 0x00006441491a49be clang::RecursiveASTVisitor<(anonymous namespace)::BuildTreeVisitor>::TraverseStmt(clang::Stmt*, llvm::SmallVectorImpl, llvm::PointerIntPairInfo>>>*) (.constprop.0) BuildTree.cpp:0:0
#19 0x00006441491af740 clang::RecursiveASTVisitor<(anonymous namespace)::BuildTreeVisitor>::TraverseFunctionHelper(clang::FunctionDecl*) BuildTree.cpp:0:0
#20 0x000064414919bddc clang::RecursiveASTVisitor<(anonymous namespace)::BuildTreeVisitor>::TraverseDecl(clang::Decl*) BuildTree.cpp:0:0
#21 0x000064414919caea clang::RecursiveASTVisitor<(anonymous namespace)::BuildTreeVisitor>::TraverseDeclContextHelper(clang::DeclContext*) BuildTree.cpp:0:0
#22 0x00006441491b583b clang::RecursiveASTVisitor<(anonymous namespace)::BuildTreeVisitor>::TraverseTranslationUnitDecl(clang::TranslationUnitDecl*) BuildTree.cpp:0:0
#23 0x000064414919c439 clang::syntax::buildSyntaxTree(clang::syntax::Arena&, clang::syntax::TokenBufferTokenManager&, clang::ASTContext&) (/home/ubuntu2404/build-196067-assert/bin/clang-check+0xd0c439)
#24 0x00006441488904af (anonymous namespace)::DumpSyntaxTree::CreateASTConsumer(clang::CompilerInstance&, llvm::StringRef)::Consumer::HandleTranslationUnit(clang::ASTContext&) ClangCheck.cpp:0:0
#25 0x000064414a6c6f9c clang::ParseAST(clang::Sema&, bool, bool) (/home/ubuntu2404/build-196067-assert/bin/clang-check+0x2236f9c)
#26 0x0000644148e54271 clang::FrontendAction::Execute() (/home/ubuntu2404/build-196067-assert/bin/clang-check+0x9c4271)
#27 0x0000644148ea0308 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/home/ubuntu2404/build-196067-assert/bin/clang-check+0xa10308)
#28 0x000064414917ccb7 clang::tooling::FrontendActionFactory::runInvocation(std::shared_ptr, clang::FileManager*, std::shared_ptr, clang::DiagnosticConsumer*) (/home/ubuntu2404/build-196067-assert/bin/clang-check+0xceccb7)
#29 0x0000644149176b2a clang::tooling::ToolInvocation::runInvocation(char const*, clang::driver::Compilation*, std::shared_ptr, std::shared_ptr) (/home/ubuntu2404/build-196067-assert/bin/clang-check+0xce6b2a)
#30 0x00006441491791e2 clang::tooling::ToolInvocation::run() (/home/ubuntu2404/build-196067-assert/bin/clang-check+0xce91e2)
#31 0x000064414917ae19 clang::tooling::ClangTool::run(clang::tooling::ToolAction*) (/home/ubuntu2404/build-196067-assert/bin/clang-check+0xceae19)
#32 0x0000644148815405 main (/home/ubuntu2404/build-196067-assert/bin/clang-check+0x385405)
#33 0x0000748e8482a1ca __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:74:3
#34 0x0000748e8482a28b call_init ./csu/../csu/libc-start.c:128:20
#35 0x0000748e8482a28b __libc_start_main ./csu/../csu/libc-start.c:347:5
#36 0x000064414888f045 _start (/home/ubuntu2404/build-196067-assert/bin/clang-check+0x3ff045)
Aborted (core dumped)
```

Contributor guide

Open the contributing guide

Research direction

Run the reported clang-check command with the supplied C++ reproducer, then inspect clang/lib/Tooling/Syntax/BuildTree.cpp around buildIdentifier and the buildSyntaxTree path shown in the stack trace. Done means this input no longer triggers the NameSpecifierTokens assertion or aborts clang-check; verify the behavior with the reproducer and relevant syntax tooling tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.