llvm-project
llvm-project copied to clipboard
bugprone-unchecked-optional-access crashes with "Assertion `Cond != nullptr' failed"
When evaluating this check on Chromium, I noted a few crashes. A creduce'd test-case for one of them is below; it repros on 206a6037a093a73d928a60c3012593f921a4f639:
typedef int a;
namespace {
namespace base {
template <typename> class Optional {
public:
operator bool();
};
Optional<a> b(char *);
namespace {
using af = char;
af ag() {
for (;;)
;
char ah[4];
Optional ai = b(ah);
!ai;
}
} // namespace
} // namespace base
} // namespace
$ clang-tidy '-checks=-*,bugprone-unchecked-optional-access' repro.cpp -- clang -c -std=c++17 -x c++ repro.cpp
clang-tidy: /usr/local/google/home/gbiv/llvm/main/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp:100: void clang::dataflow::TerminatorVisitor::VisitForStmt(const clang::ForStmt *): Assertion `Cond != nullptr' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0. Program arguments: /usr/local/google/home/gbiv/llvm/main/build/release/bin/clang-tidy -checks=-*,bugprone-unchecked-optional-access repro.cpp -- clang -c -std=c++17 -x c++ repro.cpp
1. <eof> parser at end of file
2. ASTMatcher: Processing 'bugprone-unchecked-optional-access' against:
FunctionDecl (anonymous namespace)::base::(anonymous namespace)::ag : <repro.cpp:11:1, line:17:1>
--- Bound Nodes Begin ---
T - { BuiltinType : int }
fun - { FunctionDecl (anonymous namespace)::base::(anonymous namespace)::ag : <repro.cpp:11:1, line:17:1> }
--- Bound Nodes End ---
cc @ymand
@llvm/issue-subscribers-clang-tidy
Thanks! Interestingly, you're the third person to notice this today. @sgatev has the fix: https://reviews.llvm.org/D128833
Great! Trying on ToT seems to work now, so I'll close this. Thanks.