[clang-doc] clang-doc crashes on invalid SourceLocation when visiting incomplete anonymous namespace
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
This input is generated by a fuzzer.
source code:
```cxx
class b {
namespace {
```
```
clang-doc --format=html
```
```
/clang/include/clang/Basic/SourceLocation.h:361: unsigned int clang::PresumedLoc::getLine() const: Assertion `isValid()' failed.
Program received signal SIGABRT, Aborted.
__pthread_kill_implementation (no_tid=0, signo=6, threadid=) at ./nptl/pthread_kill.c:44
warning: 44 ./nptl/pthread_kill.c: No such file or directory
#0 __pthread_kill_implementation (no_tid=0, signo=6, threadid=) at ./nptl/pthread_kill.c:44
#1 __pthread_kill_internal (signo=6, threadid=) at ./nptl/pthread_kill.c:78
#2 __GI___pthread_kill (threadid=, signo=signo@entry=6) at ./nptl/pthread_kill.c:89
#3 0x00007ffff764527e in __GI_raise (sig=sig@entry=6) at ../sysdeps/posix/raise.c:26
#4 0x00007ffff76288ff in __GI_abort () at ./stdlib/abort.c:79
#5 0x00007ffff762881b in __assert_fail_base (fmt=0x7ffff77d01e8 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n", assertion=assertion@entry=0x55556267e740 "isValid()", file=file@entry=0x55556267e760 "tmp/llvm-project-main-20260622-latest/clang/include/clang/Basic/SourceLocation.h", line=line@entry=361, function=function@entry=0x55556267e800 <__PRETTY_FUNCTION__._ZNK5clang11PresumedLoc7getLineEv> "unsigned int clang::PresumedLoc::getLine() const") at ./assert/assert.c:96
#6 0x00007ffff763b517 in __assert_fail (assertion=0x55556267e740 "isValid()", file=0x55556267e760 "tmp/llvm-project-main-20260622-latest/clang/include/clang/Basic/SourceLocation.h", line=361, function=0x55556267e800 <__PRETTY_FUNCTION__._ZNK5clang11PresumedLoc7getLineEv> "unsigned int clang::PresumedLoc::getLine() const") at ./assert/assert.c:105
#7 0x0000555556e18233 in clang::PresumedLoc::getLine (this=) at tmp/llvm-project-main-20260622-latest/clang/include/clang/Basic/SourceLocation.h:361
#8 0x0000555556e18233 in clang::doc::MapASTVisitor::getDeclLocation (this=0x515000001c00, D=0x521000077568)
#9 0x0000555556e1b517 in clang::doc::MapASTVisitor::mapDecl (this=, D=0x521000077568, IsDefinition=) at tmp/llvm-project-main-20260622-latest/clang-tools-extra/clang-doc/Mapper.cpp:91
#10 0x0000555556e526da in clang::doc::MapASTVisitor::VisitNamespaceDecl (this=0x515000001c00, D=0x521000077568) at tmp/llvm-project-main-20260622-latest/clang-tools-extra/clang-doc/Mapper.cpp:111
#11 clang::RecursiveASTVisitor::WalkUpFromNamespaceDecl (this=0x515000001c00, D=0x521000077568) at tools/clang/include/clang/AST/DeclNodes.inc:584
#12 clang::RecursiveASTVisitor::TraverseNamespaceDecl (this=0x14a7, D=0x14a7) at tmp/llvm-project-main-20260622-latest/clang/include/clang/AST/RecursiveASTVisitor.h:1809
#13 0x0000555556e1913a in clang::RecursiveASTVisitor::TraverseDecl (this=0x14a7, this@entry=0x515000001c00, D=0x14a7, D@entry=0x521000077568) at tools/clang/include/clang/AST/DeclNodes.inc:584
#14 0x0000555556e2b4fa in clang::RecursiveASTVisitor::TraverseDeclContextHelper (this=0x515000001c00, DC=) at tmp/llvm-project-main-20260622-latest/clang/include/clang/AST/RecursiveASTVisitor.h:1653
#15 clang::RecursiveASTVisitor::TraverseTranslationUnitDecl (this=0x515000001c00, D=0x521000023108) at llvm-project-main-20260622-latest/clang/include/clang/AST/RecursiveASTVisitor.h:1773
#16 0x0000555556e18ebb in clang::RecursiveASTVisitor::TraverseDecl (this=0x14a7, this@entry=0x515000001c00, D=0x14a7) at tools/clang/include/clang/AST/DeclNodes.inc:24
#17 0x0000555556e189ff in clang::doc::MapASTVisitor::HandleTranslationUnit (this=0x515000001c00, Context=...) at tmp/llvm-project-main-20260622-latest/clang-tools-extra/clang-doc/Mapper.cpp:45
#18 0x00005555580a84c6 in clang::ParseAST (S=..., PrintStats=false, SkipFunctionBodies=) at tmp/llvm-project-main-20260622-latest/clang/lib/Parse/ParseAST.cpp:183
#19 0x0000555557cc5555 in clang::FrontendAction::Execute (this=0x516000003c80) at llvm-project-main-20260622-latest/clang/lib/Frontend/FrontendAction.cpp:1342
#20 0x0000555557a1f535 in clang::CompilerInstance::ExecuteAction (this=0x7ffff5a92020, Act=...) at /llvm-project-main-20260622-latest/clang/lib/Frontend/CompilerInstance.cpp:1027
#21 0x0000555556cd5dbd in clang::tooling::FrontendActionFactory::runInvocation (this=, Invocation=..., Files=, PCHContainerOps=..., DiagConsumer=) at tmp/llvm-project-main-20260622-latest/clang/lib/Tooling/Tooling.cpp:459
#22 0x0000555556cd4a25 in clang::tooling::ToolInvocation::runInvocation (this=, BinaryName=, Compilation=, Invocation=std::shared_ptr (empty) = {...}, PCHContainerOps=...) at llvm-project-main-20260622-latest/clang/lib/Tooling/Tooling.cpp:439
#23 0x0000555556cce5dd in clang::tooling::ToolInvocation::run (this=) at tmp/llvm-project-main-20260622-latest/clang/lib/Tooling/Tooling.cpp:424
#24 0x0000555556cde702 in clang::tooling::ClangTool::run (this=0x5150000000d0, Action=) at tmp/llvm-project-main-20260622-latest/clang/lib/Tooling/Tooling.cpp:631
#25 0x0000555556cc64d3 in clang::tooling::StandaloneToolExecutor::execute(llvm::ArrayRef >, std::function, std::allocator >, std::allocator, std::allocator > > > (std::vector, std::allocator >, std::allocator, std::allocator > > > const&, llvm::StringRef)> > >) (this=, Actions=...) at llvm-project-main-20260622-latest/clang/lib/Tooling/StandaloneExecution.cpp:66
#26 0x0000555556cb2bcf in clang::tooling::ToolExecutor::execute(std::unique_ptr >, std::function, std::allocator >, std::allocator, std::allocator > > > (std::vector, std::allocator >, std::allocator, std::allocator > > > const&, llvm::StringRef)>) (this=, Action=std::unique_ptr = {...}, Adjuster=...) at llvm-project-main-20260622-latest/clang/lib/Tooling/Execution.cpp:53
#27 0x00005555567b352d in main (argc=, argv=) at llvm-project-main-20260622-latest/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp:324
Contributor guide
Research direction
Run clang-doc --format=html with the incomplete anonymous-namespace input to reproduce the assertion. Then inspect clang-tools-extra/clang-doc/Mapper.cpp, starting at MapASTVisitor::getDeclLocation and the NamespaceDecl path around line 91; done means this input no longer aborts on an invalid SourceLocation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 65/100