| Issue |
53066
|
| Summary |
BreadthFirstIterator causes a crash
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
jirislaby
|
Having this minimalistic checker plugin:
```cpp
#include <llvm/ADT/BreadthFirstIterator.h>
#include <clang/StaticAnalyzer/Core/Checker.h>
#include <clang/StaticAnalyzer/Core/CheckerManager.h>
#include <clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h>
#include <clang/StaticAnalyzer/Frontend/CheckerRegistry.h>
using namespace clang;
class BFBeginChecker : public clang::ento::Checker<ento::check::ASTCodeBody> {
public:
void checkASTCodeBody(const Decl *D, ento::AnalysisManager& mgr,
ento::BugReporter &BR) const {
D->dumpColor();
auto cfg = mgr.getCFG(D);
cfg->dump(mgr.getLangOpts(), true);
for (auto I = llvm::bf_begin(cfg); I != llvm::bf_end(cfg); ++I) {
auto b = *I;
llvm::errs() << "addr=" << b << " id=" << (b ? b->getBlockID() : -1) << "\n";
assert(b);
}
}
};
extern "C" const char clang_analyzerAPIVersionString[] = CLANG_ANALYZER_API_VERSION_STRING;
extern "C" void clang_registerCheckers(clang::ento::CheckerRegistry ®istry) {
registry.addChecker<BFBeginChecker>("BFBeginChecker", "Invokes bf_begin", "");
}
```
Compile and run it:
```sh
$ g++ -shared -fPIC -o bf_begin.so -I/usr/include -std=c++14 -fno-exceptions -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -Wall -g bf_begin.cpp -lLLVM
$ clang -cc1 -load ./bf_begin.so -analyze -analyzer-checker=BFBeginChecker list.c
```
where list.c is:
```c
void X()
{
do { } while (0);
}
```
I see:
```
FunctionDecl 0x858648 <list2.c:1:1, line:4:1> line:1:6 X 'void ()'
`-CompoundStmt 0x858780 <line:2:1, line:4:1>
`-DoStmt 0x858760 <line:3:2, col:17>
|-CompoundStmt 0x858730 <col:5, col:7>
`-IntegerLiteral 0x858740 <col:16> 'int' 0
[B3 (ENTRY)]
Succs (1): B1
[B1]
1: 0
T: do ... while [B1.1]
Preds (2): B2 B3
Succs (2): NULL B0
[B2]
Succs (1): B1
[B0 (EXIT)]
Preds (1): B1
addr=0x87bb28 id=3
addr=0x87b958 id=1
addr=0x0 id=4294967295
clang: bf_begin.cpp:21: void BFBeginChecker::checkASTCodeBody(const clang::Decl*, clang::ento::AnalysisManager&, clang::ento::BugReporter&) const: Assertion `b' failed.
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs