Since we cannot find up the parent of a node, we keep a stack of parents
| 328 | |
| 329 | // Since we cannot find up the parent of a node, we keep a stack of parents |
| 330 | bool TraverseStmt(clang::Stmt *s) { |
| 331 | if (++recursionCount > 10000) { |
| 332 | // Give up if the stack is too big to avoid stack overflow |
| 333 | std::cerr << "TraverseStmt: Stack overflow, giving up traversal"; |
| 334 | return true; |
| 335 | } |
| 336 | auto e = llvm::dyn_cast_or_null<clang::Expr>(s); |
| 337 | decltype(expr_stack) old_stack; |
| 338 | if (e) { |
| 339 | expr_stack.push_front(e); |
| 340 | } else { |
| 341 | std::swap(old_stack, expr_stack); |
| 342 | if (auto i = llvm::dyn_cast_or_null<clang::IfStmt>(s)) { |
| 343 | expr_stack.topExpr = i->getCond(); |
| 344 | expr_stack.topType = Annotator::Use_Read; |
| 345 | } else if (auto r = llvm::dyn_cast_or_null<clang::ReturnStmt>(s)) { |
| 346 | expr_stack.topExpr = r->getRetValue(); |
| 347 | if (auto f = llvm::dyn_cast_or_null<clang::FunctionDecl>(currentContext)) { |
| 348 | auto t = getResultType(f); |
| 349 | if (t->isReferenceType() /*&& !t.getNonReferenceType().isConstQualified()*/) |
| 350 | expr_stack.topType = Annotator::Use_Address; // non const reference |
| 351 | else |
| 352 | expr_stack.topType = Annotator::Use_Read; // anything else is considered as read; |
| 353 | } |
| 354 | } else if (auto sw = llvm::dyn_cast_or_null<clang::SwitchStmt>(s)) { |
| 355 | expr_stack.topExpr = sw->getCond(); |
| 356 | expr_stack.topType = Annotator::Use_Read; |
| 357 | } else if (auto d = llvm::dyn_cast_or_null<clang::DoStmt>(s)) { |
| 358 | expr_stack.topExpr = d->getCond(); |
| 359 | expr_stack.topType = Annotator::Use_Read; |
| 360 | } else if (auto w = llvm::dyn_cast_or_null<clang::WhileStmt>(s)) { |
| 361 | expr_stack.topExpr = w->getCond(); |
| 362 | expr_stack.topType = Annotator::Use_Read; |
| 363 | } |
| 364 | } |
| 365 | auto r = Base::TraverseStmt(s); |
| 366 | if (e) { |
| 367 | expr_stack.pop_front(); |
| 368 | } else { |
| 369 | std::swap(old_stack, expr_stack); |
| 370 | } |
| 371 | recursionCount--; |
| 372 | return r; |
| 373 | } |
| 374 | |
| 375 | #if CLANG_VERSION_MAJOR == 3 && CLANG_VERSION_MINOR < 8 |
| 376 | bool shouldUseDataRecursionFor(clang::Stmt *S) { |
nothing calls this directly
no test coverage detected