llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

bugprone-unchecked-optional-access crashes with "Assertion `Cond != nullptr' failed"

Open gburgessiv opened this issue 4 years ago • 3 comments

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

gburgessiv avatar Jun 29 '22 22:06 gburgessiv

@llvm/issue-subscribers-clang-tidy

llvmbot avatar Jun 29 '22 22:06 llvmbot

Thanks! Interestingly, you're the third person to notice this today. @sgatev has the fix: https://reviews.llvm.org/D128833

ymand avatar Jun 29 '22 23:06 ymand

Great! Trying on ToT seems to work now, so I'll close this. Thanks.

gburgessiv avatar Jul 13 '22 19:07 gburgessiv