<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=http://email.email.llvm.org/c/eJylV91zmzgQ_2vwiwYGBDb2gx8wxDlmHCdju732XjwCZEyLkUcSaXN__a0EGH8ld9d6SACtfrur_SZh2dv0D_JaVDmS-0KgQ1EVB1IWQhYpSvc0_U45OpZ1XlSGGxh2ZNiBMbKbKz0e2xXsFlVa1hlFhhuW5evBwPMg2sD_Gackk_t5wYWMJeVEMm7tDfehRd7BpyWpcoCuJQEtgoqUb39TDgsh41TdGrXOufwK_olUJP8NNi9E7te0EoUsXtW73iEK8ct855xVklZZr-KK5uAJ_nZjsFooj1XkQMWRpBQ1PN3Z-R5YEwLN5jNgUrUMQX6AjnVSKu82mAAuWknWPLX7QM1-TYdB8xisNyHL6AzCBjRCht9KbFieIgS1v1dWZE0UnQPxOGWVkCiiaYkMHEQGDlEv7sqOBh6hQw638JL39a9nMKvzFT0yLtV58Wi2MvAENSJPCl-jIxPOk9WHY8hKBsLGgDnZ83ozqSVD6S4Ha0ZKNyunMpw_Air6CAaITgpsbXELcMLzUYpWJFhC8pqes7nPbMfU4cZalVgrotNOGyDZbRPldGXpXd7wUpuwc7NPh9vZLgPP4IqVxd611YUZEi0bvBi_e-7u1wumnLcHVgkBFzDAJMsg7sCCuFtMzqioyC6JgFf0OUqUUcGSs5Kl3-PoxDdApnMpwRiGlbr9m6KQN5RLJeAjdxp-dEk4LaiHS-_RnxCMldIhVEdogjHdE95k4Za0VSB4iT9TLgpWrSWHFDeGM2MYaROHi2D5uA2WweLrXw-rLezcfn5YrePn5Xa9WcXLx49FNqmohXFdVShvc1154qNa0BUhlUu8fb4bHx3RAk_2deSyAKk6phyEr5bBK1j7KK5e2XcqUB_DHUVfZ2lxsnbXjprXkB2ORUkRqTLE6woV8rZxiX1XmD2UNyGPTAHuoBkydy9xiEx20sASDJmQEfNaqCrdVXJTSBWRaQN3PDCAuauYSX-m9CjBgwKZ0fZx-Wm7fv60Ch_UG3gqCrfh83K9CZab7VMQrp7XPWH-vHoKbpcX8VPcr_5JyhKZea8edGFklovF56f-UNqfyExTB0iMZMgCzS8O1Ebc6YGbaeeh6KpnqGnASu8a-8eectpuQIW4MyI07zr6vrQ1rnXfVfRkTEWUSiL0Y68cCLvt_-LwGAlKbyU3r_O6SpUzdK-xf46H45E31kMK6Iwt1bIc_QcxVhaV4uM1aw_du6KP0BfQx9fH6Cq1fxJoqphjdZWt5UE2Uvyx3UjRLPA7IjoLKB4RO0OPztGu5gDolJUK6J8hVdUJ78l3NYcGMezBV1iQG8PMAW12UajhrLWR752hnZFu9dgvKqiJPrIv2hJUqJmrbPKw3Ky-KsMM-7K4rtNUKKKjHRmgmXMDds4BytadAHjdqFcIDMuyuqBQCOsC8wJZq4XgTghGM_dWh468_LRYoNntKfD_1dzWx_4Sb65OfVLoPrbtc2BoP0nwuGls7i1tMmxpzhXNbpY9PPEmIx9Phqd5T9fwi8qgQkcbVYfudS0-TXf3xrOznqCyB1q8DqN7neJ2ZHt369lwpre1k5lSMdBtF5JVxWWiQm1HwOeZdfGpcJnlg2zqZhN3QgYwjewZn34reCFKkrwNal5O91IedVXCc7jyQu7rxEqZ-jxpv1LUzTxy9o2mUlV3IWoKHXE-dO3RaLCfEkxGqUdSkk3ILvN2yZCM6DizvWTsed44GYAsWoqp6tQYV_QH0iz0tBENfl-DYoptjG3H9h3XGQ49i2bEdZxhlmUJ8X3fNjybHsBOluJjMZ4P-FSzTOpcAFEVOtETYbYp8orSaTNaDGQhSzq995WGUlIL6MQEpZyI_UArNtVa_QM_H_Ss>53066</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
BreadthFirstIterator causes a crash
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
jirislaby
</td>
</tr>
</table>
<pre>
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.
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJylV91zmzgQ_2vwiwYGhDH2gx8wxDlmHCdju732XjwCZEyLkUcSadO__lYCjL-Su-t5SACtfrur_SZh2dv0D_JaVDmS-0KgQ1EVB1IWQhYpSvc0_U45OpZ1XlSGGxh2ZNiBMbKbKz0e2xXsFlVa1hlFhhuW5evBwPMg2sD_Gackk_t5wYWMJeVEMm7tDfehRd7BpyWpcoCuJQEtgoqUb78oh4WQcapujVrnXH4H_0Qqkv8PNi9E7te0EoUsXtW73iEK8dt855xVklZZr-KK5uAJ_nZjsFooj1XkQMWRpBQ1PN3Z-R5YEwLN5jNgUrUMQX6AjnVSKu82mAAuWknWPLX7QM1-TYdB8xisNyHL6AzCBjRCht9KbFieIgS1v1dWZE0UnQPxOGWVkCiiaYkMHEQGDlEv7sqOBh6hQw638JL39a9nMKvzFT0yLtV58Wi2MvAENSJPCl-jIxPOk9WHY8hKBsLGgDnZ83ozqSVD6S4Ha0ZKNyunMpw_Air6CAaITgpsbXELcMLzUYpWJFhC8pqes7nPbMfU4cZalVgrotNOGyDZbRPldGXpXd7wUpuwc7NPh9vZLgPP4IqVxd611YUZEi0bvBi_e-7u1wumnLcHVgkBFzDAJMsg7sCCuFtMzqioyC6JgFf0OUqUUcGSs5Kl3-PoxDdApnMpwfDCSt3-SVHIG8qlEvCROw0_uiScFtTDpffoTwjGSukQqiM0wZjuCW-ycEvaKhC8xJ8pFwWr1pJDihvezPAibeJwESwft8EyWHz962G1hZ3bzw-rdfy83K43q3j5-LHIJhW1MK6rCuVtritPfFQLuiKkcom3z3fjoyNa4Mm-jlwWIFXHlIPw1TJ4BWsfxdUr-04F6mO4o-jrLC1O1u7aUfMassOxKCkiVYZ4XaFC3jYuse8K8xDlTcgjU4A7aIbM3UscIpOdNLAEQyZkxLwWqkp3ldwUUk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