clang 20.0.0git
LoopWidening.cpp
Go to the documentation of this file.
1//===--- LoopWidening.cpp - Widen loops -------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8///
9/// This file contains functions which are used to widen loops. A loop may be
10/// widened to approximate the exit state(s), without analyzing every
11/// iteration. The widening is done by invalidating anything which might be
12/// modified by the body of the loop.
13///
14//===----------------------------------------------------------------------===//
15
16#include "clang/AST/AST.h"
20
21using namespace clang;
22using namespace ento;
23using namespace clang::ast_matchers;
24
25const auto MatchRef = "matchref";
26
27/// Return the loops condition Stmt or NULL if LoopStmt is not a loop
28static const Expr *getLoopCondition(const Stmt *LoopStmt) {
29 switch (LoopStmt->getStmtClass()) {
30 default:
31 return nullptr;
32 case Stmt::ForStmtClass:
33 return cast<ForStmt>(LoopStmt)->getCond();
34 case Stmt::WhileStmtClass:
35 return cast<WhileStmt>(LoopStmt)->getCond();
36 case Stmt::DoStmtClass:
37 return cast<DoStmt>(LoopStmt)->getCond();
38 case Stmt::CXXForRangeStmtClass:
39 return cast<CXXForRangeStmt>(LoopStmt)->getCond();
40 }
41}
42
43namespace clang {
44namespace ento {
45
47 const LocationContext *LCtx,