<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/149757>149757</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[analyzer] assertion failure on strnlen
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang:static analyzer,
crash
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
k-arrows
</td>
</tr>
</table>
<pre>
Reproducer:
https://godbolt.org/z/eMedGszjE
```c
typedef __SIZE_TYPE__ size_t;
extern char* strnlen(const char*, size_t);
char** q;
void f(const char *s)
{
extern char a[8];
q[0] = strnlen(a, 7);
}
```
Backtrace:
```console
clang: /root/llvm-project/llvm/include/llvm/Support/Casting.h:566: decltype(auto) llvm::cast(const From&) [with To = clang::ento::NonLoc; From = clang::ento::SVal]: Assertion `isa<To>(Val) && "cast<Ty>() argument of incompatible type!"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0. Program arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/clang -gdwarf-4 -g -o /app/output.s -mllvm --x86-asm-syntax=intel -fno-verbose-asm -S --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics --analyze <source>
1. <eof> parser at end of file
2. While analyzing stack:
#0 Calling f
3. <source>:9:10: Error evaluating statement
4. <source>:9:10: Error evaluating statement
#0 0x0000000003fc1498 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3fc1498)
#1 0x0000000003fbe8c4 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3fbe8c4)
#2 0x0000000003f03098 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#3 0x0000734a59642520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#4 0x0000734a596969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
#5 0x0000734a59642476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
#6 0x0000734a596287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
#7 0x0000734a5962871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
#8 0x0000734a59639e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
#9 0x00000000060f207f decltype(auto) llvm::cast<clang::ento::NonLoc, clang::ento::SVal>(clang::ento::SVal const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x60f207f)
#10 0x00000000060fe952 (anonymous namespace)::CStringChecker::evalstrLengthCommon(clang::ento::CheckerContext&, clang::ento::CallEvent const&, bool) const CStringChecker.cpp:0:0
#11 0x00000000060eddf8 bool clang::ento::eval::Call::_evalCall<(anonymous namespace)::CStringChecker>(void*, clang::ento::CallEvent const&, clang::ento::CheckerContext&) CStringChecker.cpp:0:0
#12 0x00000000064d7c3a clang::ento::CheckerManager::runCheckersForEvalCall(clang::ento::ExplodedNodeSet&, clang::ento::ExplodedNodeSet const&, clang::ento::CallEvent const&, clang::ento::ExprEngine&, clang::ento::EvalCallOptions const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x64d7c3a)
#13 0x00000000065524e2 clang::ento::ExprEngine::evalCall(clang::ento::ExplodedNodeSet&, clang::ento::ExplodedNode*, clang::ento::CallEvent const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x65524e2)
#14 0x0000000006553457 clang::ento::ExprEngine::VisitCallExpr(clang::CallExpr const*, clang::ento::ExplodedNode*, clang::ento::ExplodedNodeSet&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x6553457)
#15 0x000000000652ad71 clang::ento::ExprEngine::Visit(clang::Stmt const*, clang::ento::ExplodedNode*, clang::ento::ExplodedNodeSet&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x652ad71)
#16 0x000000000652bdcd clang::ento::ExprEngine::ProcessStmt(clang::Stmt const*, clang::ento::ExplodedNode*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x652bdcd)
#17 0x00000000064e0bbb clang::ento::CoreEngine::HandlePostStmt(clang::CFGBlock const*, unsigned int, clang::ento::ExplodedNode*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x64e0bbb)
#18 0x00000000064e12a8 clang::ento::CoreEngine::dispatchWorkItem(clang::ento::ExplodedNode*, clang::ProgramPoint, clang::ento::WorkListUnit const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x64e12a8)
#19 0x00000000064e1611 clang::ento::CoreEngine::ExecuteWorkList(clang::LocationContext const*, unsigned int, llvm::IntrusiveRefCntPtr<clang::ento::ProgramState const>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x64e1611)
#20 0x00000000060a8727 (anonymous namespace)::AnalysisConsumer::HandleCode(clang::Decl*, unsigned int, clang::ento::ExprEngine::InliningModes, llvm::DenseSet<clang::Decl const*, llvm::DenseMapInfo<clang::Decl const*, void>>*) AnalysisConsumer.cpp:0:0
#21 0x00000000060aa35e (anonymous namespace)::AnalysisConsumer::HandleDeclsCallGraph(unsigned int) AnalysisConsumer.cpp:0:0
#22 0x00000000060abd63 (anonymous namespace)::AnalysisConsumer::HandleTranslationUnit(clang::ASTContext&) AnalysisConsumer.cpp:0:0
#23 0x000000000666650c clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x666650c)
#24 0x0000000004c64025 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4c64025)
#25 0x0000000004be0e6e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4be0e6e)
#26 0x0000000004d57b01 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4d57b01)
#27 0x0000000000d9ec4f cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xd9ec4f)
#28 0x0000000000d9582a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#29 0x00000000049d7709 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#30 0x0000000003f03534 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3f03534)
#31 0x00000000049d7d1f clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (.part.0) Job.cpp:0:0
#32 0x0000000004999d6d clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4999d6d)
#33 0x000000000499adfe clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x499adfe)
#34 0x00000000049a3945 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x49a3945)
#35 0x0000000000d9b0ff clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xd9b0ff)
#36 0x0000000000c4f5b4 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xc4f5b4)
#37 0x0000734a59629d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#38 0x0000734a59629e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#39 0x0000000000d952d5 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xd952d5)
clang: error: clang frontend command failed with exit code 134 (use -v to see invocation)
Compiler returned: 134
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzkWt9v4zby_2uYF8KGROqH9ZAHRbH7TbHbBut8W9y9GBRF2WxkUiWprLN__YGUZFlKnE1a7x0OV3QBWeTMfObDmeGIIdGabwVj1yC8AeHtFWnMTqrrxxlRSn7VV7ksnq-_sFrJoqFMAZwCL90ZU2v7iFYArbayyGVl5lJtAVp9A2jFPrPiJ_3tjyXwUhB57f8UeKl5rlnBSrjZrO_-udw8_ON-udlAzb-xjQH4xk73UnYwTAlId0QBlEJtlKiYAGhBpdCmfw9Q1guipJU9jqTwz6O2J8kLWI6kIUCptlJeCmI7DcITm5CA8GYBwttWBYR_gvDGA-EtBPj2BA2xCOKjcRDfnnrbGr8h9NEoQlnL28CFFFpWzGKuiNgCnEKAVkpKA9Cqqp72s1rJPxjtfwK04oJWTcGGF-umrqWyMzKiDRfb-Q7gNIwiq61gtLJkW5yNkQAl0InhFOCUEm2OhKyU3AMU2RkgvPnKzQ4-SOdqDw3glAkj26dfpPgkKcA3TvD8vPVvpHIcpjDVminDpYAg8rgmAGcPEuAlQAs7yRq29iMIEHLQcPbw3I7bQaK2zZ4JA2UJuaByXxPD84rB1j8fIARQDEvCK1bMgZfef1qm6yXUTb7nBhKYN1uomOUKGgknscvNrsnn1HLQEzvhn2vdMA3QChJRwG4ZoNkxSBXRO5gf1xhlsFY2VSjTmhVQy0a1r60k0VpSTgwroGoE1FTx2li8a0PoIyyafd1GiTcHXnKv5FaR_dF73cWIrC0mywKvmJqxQ11JxZR9Z5dhRnqy9cyoRjwCtMq56IfhbFt8JaqcBXC2hTNpNZK6tnobUzdmruFsb_2Hs9lhEc2I3s_0szDkAPAtF4ZVcFYKOXtiKpea2XE4W8PZbEvpzEhZ0R3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