24 Worklist.push_back(Body);
25 while (!Worklist.empty()) {
26 const Stmt *S = Worklist.pop_back_val();
30 case Stmt::GotoStmtClass:
31 case Stmt::SwitchStmtClass:
32 case Stmt::IndirectGotoStmtClass:
34 case Stmt::GCCAsmStmtClass:
42 Worklist.push_back(Child);
53 BypassedVarsAtSource.clear();
54 Scopes = {{~0
U,
nullptr}};
55 AlwaysBypassed =
false;
58 unsigned ParentScope = 0;
59 AlwaysBypassed = !BuildScopeInformation(CGM, Body, ParentScope);
68 unsigned &ParentScope) {
69 const VarDecl *VD = dyn_cast<VarDecl>(D);
71 Scopes.push_back({ParentScope, VD});
72 ParentScope = Scopes.size() - 1;
75 if (
const VarDecl *VD = dyn_cast<VarDecl>(D))
77 return BuildScopeInformation(CGM,
Init, ParentScope);
86bool VarBypassDetector::BuildScopeInformation(
CodeGenModule &CGM,
const Stmt *S,
87 unsigned &origParentScope) {
91 unsigned independentParentScope = origParentScope;
92 unsigned &ParentScope =
94 : independentParentScope);
96 unsigned StmtsToSkip = 0u;
99 case Stmt::IndirectGotoStmtClass:
102 case Stmt::SwitchStmtClass:
104 if (!BuildScopeInformation(CGM,
Init, ParentScope))
109 if (!BuildScopeInformation(CGM, Var, ParentScope))
115 case Stmt::GotoStmtClass:
116 FromScopes.push_back({S, ParentScope});
119 case Stmt::DeclStmtClass: {
121 for (
auto *I : DS->
decls())
122 if (!BuildScopeInformation(CGM, I, origParentScope))
127 case Stmt::CaseStmtClass:
128 case Stmt::DefaultStmtClass:
129 case Stmt::LabelStmtClass:
130 llvm_unreachable(
"the loop below handles labels and cases");
137 for (
const Stmt *SubStmt : S->
children()) {
150 if (
const SwitchCase *SC = dyn_cast<SwitchCase>(SubStmt))
151 Next = SC->getSubStmt();
152 else if (
const LabelStmt *LS = dyn_cast<LabelStmt>(SubStmt))
153 Next = LS->getSubStmt();
157 ToScopes[SubStmt] = ParentScope;
164 Result = BuildScopeInformation(CGM, SubStmt, ParentScope);
170 if (
const auto *GAS = dyn_cast<GCCAsmStmt>(S); GAS && GAS->isAsmGoto())
171 FromScopes.push_back({S, ParentScope});
177void VarBypassDetector::Detect() {
178 for (
const auto &S : FromScopes) {
179 const Stmt *St = S.first;
180 unsigned from = S.second;
181 if (
const GotoStmt *GS = dyn_cast<GotoStmt>(St)) {
182 if (
const LabelStmt *LS = GS->getLabel()->getStmt())
183 Detect(from, ToScopes[LS], GS);
184 }
else if (
const SwitchStmt *SS = dyn_cast<SwitchStmt>(St)) {
187 for (
const SwitchCase *SC = SS->getSwitchCaseList(); SC;
188 SC = SC->getNextSwitchCase()) {
189 Detect(from, ToScopes[SC], SS);
191 }
else if (
const GCCAsmStmt *GAS = dyn_cast<GCCAsmStmt>(St)) {
192 for (
const AddrLabelExpr *L : GAS->labels())
193 if (
const LabelStmt *LS = L->getLabel()->getStmt())
194 Detect(from, ToScopes[LS], GAS);
196 llvm_unreachable(
"goto, switch, or asm goto was expected");
202void VarBypassDetector::Detect(
unsigned From,
unsigned To,
const Stmt *Source) {
205 assert(Scopes[To].first < To);
206 const auto &ScopeTo = Scopes[To];
208 Bypasses.insert(ScopeTo.second);
210 BypassedVarsAtSource[Source].insert(ScopeTo.second);
212 assert(Scopes[From].first < From);
213 From = Scopes[From].first;
static bool hasJumpStmts(const Stmt *Body)
True if the body contains a goto, switch, indirect goto, or asm goto.
This class organizes the cross-function state that is used while generating LLVM code.
void runWithSufficientStackSpace(SourceLocation Loc, llvm::function_ref< void()> Fn)
Run some code with "sufficient" stack space.
void Init(CodeGenModule &CGM, const Stmt *Body)
Clear the object and pre-process for the given statement, usually function body statement.
This represents one expression.
Stmt - This represents one statement.
SourceLocation getEndLoc() const LLVM_READONLY
StmtClass getStmtClass() const
Represents a variable declaration or definition.
const Expr * getInit() const
bool hasLocalStorage() const
Returns true if a variable with function scope is a non-static local variable.
@ Decl
The l-value was an access to a declared entity or something equivalently strong, like the address of ...
Top level wrappers for InstallAPI frontend operations.
bool isa(CodeGen::Address addr)
@ Result
The result type of a method or function.
U cast(CodeGen::Address addr)