TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Clang Static Analyzer and the Z3 constraint solver

63 点作者 fcambus将近 3 年前

4 条评论

rgovostes将近 3 年前
The Clang Static Analyzer is a great codebase to learn from. A long time ago, before Z3 was open source, I added a constraint manager that used STP for the same objective: <a href="https:&#x2F;&#x2F;reviews.llvm.org&#x2F;D15609" rel="nofollow">https:&#x2F;&#x2F;reviews.llvm.org&#x2F;D15609</a><p>It may be dated by now but there is also a tutorial on writing checkers (<a href="https:&#x2F;&#x2F;clang-analyzer.llvm.org&#x2F;checker_dev_manual.html" rel="nofollow">https:&#x2F;&#x2F;clang-analyzer.llvm.org&#x2F;checker_dev_manual.html</a>), or follow one of the many examples in the codebase.<p>My first checker is still there — it just turned 10 years old, and is under 100 lines without comments. <a href="https:&#x2F;&#x2F;github.com&#x2F;llvm&#x2F;llvm-project&#x2F;blob&#x2F;main&#x2F;clang&#x2F;lib&#x2F;StaticAnalyzer&#x2F;Checkers&#x2F;BoolAssignmentChecker.cpp" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;llvm&#x2F;llvm-project&#x2F;blob&#x2F;main&#x2F;clang&#x2F;lib&#x2F;Sta...</a>
yaantc将近 3 年前
I&#x27;m very happy with the Clang static analyzer used with Z3 in the recommended way (for verification, not as the main constraint handler) through CodeChecker [1]. We use it with &quot;cross translation unit&quot; (CTU) support, to analyze call flows across files.<p>As said, there are few false positives. For embedded software the fact that Z3 understand bitfields and bit operations is nice. But in general we found that it makes better use of CTU information than a proprietary tool we&#x27;re using (and now consider phasing out).<p>When used with cross compiled software the CC+ClangSA combination can be made to work, but is sometimes a bit rough when there are GCC&#x2F;Clang subtle incompatibilities. But nothing too bad, and CC provided the hooks to work around any issue we found.<p>Even in &quot;verification&quot; mode, Z3 also helps the analysis as I understand from the docs. Some cheap Z3 analysis are used to prune some paths, which also helps the classical range analysis. Those tools must make some approximation to deal with the combinatorial explosion, so pruning useless paths early can help exploring others leading to bugs. So Z3, even in the default mode, is not only to filter out false positive but can also help finding issues.<p>I would highly recommend it for people using C and C++. With those languages the tooling around is very important to (partially) mitigate their known &quot;dangerosity&quot;.<p>[1] <a href="https:&#x2F;&#x2F;codechecker.readthedocs.io&#x2F;en&#x2F;latest&#x2F;" rel="nofollow">https:&#x2F;&#x2F;codechecker.readthedocs.io&#x2F;en&#x2F;latest&#x2F;</a>
fallingmeat将近 3 年前
Does this use tactics to identify contradictions, tautologies, subsumptions, etc in conditions? How does this work?
评论 #31833327 未加载
zogomoox将近 3 年前
They&#x27;re using a terrible example, because I&#x27;d prefer that null reference to be caught whether the code is reachable or not.
评论 #31840211 未加载
评论 #31835894 未加载