88
99#include " VarBypassDetector.h"
1010
11+ #include " CodeGenModule.h"
1112#include " clang/AST/Decl.h"
1213#include " clang/AST/Expr.h"
1314#include " clang/AST/Stmt.h"
@@ -17,21 +18,21 @@ using namespace CodeGen;
1718
1819// / Clear the object and pre-process for the given statement, usually function
1920// / body statement.
20- void VarBypassDetector::Init (const Stmt *Body) {
21+ void VarBypassDetector::Init (CodeGenModule &CGM, const Stmt *Body) {
2122 FromScopes.clear ();
2223 ToScopes.clear ();
2324 Bypasses.clear ();
2425 Scopes = {{~0U , nullptr }};
2526 unsigned ParentScope = 0 ;
26- AlwaysBypassed = !BuildScopeInformation (Body, ParentScope);
27+ AlwaysBypassed = !BuildScopeInformation (CGM, Body, ParentScope);
2728 if (!AlwaysBypassed)
2829 Detect ();
2930}
3031
3132// / Build scope information for a declaration that is part of a DeclStmt.
3233// / Returns false if we failed to build scope information and can't tell for
3334// / which vars are being bypassed.
34- bool VarBypassDetector::BuildScopeInformation (const Decl *D,
35+ bool VarBypassDetector::BuildScopeInformation (CodeGenModule &CGM, const Decl *D,
3536 unsigned &ParentScope) {
3637 const VarDecl *VD = dyn_cast<VarDecl>(D);
3738 if (VD && VD->hasLocalStorage ()) {
@@ -41,7 +42,7 @@ bool VarBypassDetector::BuildScopeInformation(const Decl *D,
4142
4243 if (const VarDecl *VD = dyn_cast<VarDecl>(D))
4344 if (const Expr *Init = VD->getInit ())
44- return BuildScopeInformation (Init, ParentScope);
45+ return BuildScopeInformation (CGM, Init, ParentScope);
4546
4647 return true ;
4748}
@@ -50,7 +51,7 @@ bool VarBypassDetector::BuildScopeInformation(const Decl *D,
5051// / LabelAndGotoScopes and recursively walking the AST as needed.
5152// / Returns false if we failed to build scope information and can't tell for
5253// / which vars are being bypassed.
53- bool VarBypassDetector::BuildScopeInformation (const Stmt *S,
54+ bool VarBypassDetector::BuildScopeInformation (CodeGenModule &CGM, const Stmt *S,
5455 unsigned &origParentScope) {
5556 // If this is a statement, rather than an expression, scopes within it don't
5657 // propagate out into the enclosing scope. Otherwise we have to worry about
@@ -68,12 +69,12 @@ bool VarBypassDetector::BuildScopeInformation(const Stmt *S,
6869
6970 case Stmt::SwitchStmtClass:
7071 if (const Stmt *Init = cast<SwitchStmt>(S)->getInit ()) {
71- if (!BuildScopeInformation (Init, ParentScope))
72+ if (!BuildScopeInformation (CGM, Init, ParentScope))
7273 return false ;
7374 ++StmtsToSkip;
7475 }
7576 if (const VarDecl *Var = cast<SwitchStmt>(S)->getConditionVariable ()) {
76- if (!BuildScopeInformation (Var, ParentScope))
77+ if (!BuildScopeInformation (CGM, Var, ParentScope))
7778 return false ;
7879 ++StmtsToSkip;
7980 }
@@ -86,7 +87,7 @@ bool VarBypassDetector::BuildScopeInformation(const Stmt *S,
8687 case Stmt::DeclStmtClass: {
8788 const DeclStmt *DS = cast<DeclStmt>(S);
8889 for (auto *I : DS->decls ())
89- if (!BuildScopeInformation (I, origParentScope))
90+ if (!BuildScopeInformation (CGM, I, origParentScope))
9091 return false ;
9192 return true ;
9293 }
@@ -126,7 +127,11 @@ bool VarBypassDetector::BuildScopeInformation(const Stmt *S,
126127 }
127128
128129 // Recursively walk the AST.
129- if (!BuildScopeInformation (SubStmt, ParentScope))
130+ bool Result;
131+ CGM.runWithSufficientStackSpace (S->getEndLoc (), [&] {
132+ Result = BuildScopeInformation (CGM, SubStmt, ParentScope);
133+ });
134+ if (!Result)
130135 return false ;
131136 }
132137 return true ;
0 commit comments