@@ -260,22 +260,6 @@ void TBRAnalyzer::overlay(const clang::Expr* E) {
260260}
261261// NOLINTEND(cppcoreguidelines-pro-type-union-access)
262262
263- void TBRAnalyzer::copyVarToCurBlock (const clang::VarDecl* VD ) {
264- // Visit all predecessors one by one until the variable VD is found.
265- auto & curBranch = getCurBlockVarsData ();
266- auto * pred = curBranch.m_Prev ;
267- while (pred) {
268- auto it = pred->find (VD );
269- if (it != pred->end ()) {
270- curBranch[VD ] = copy (it->second );
271- return ;
272- }
273- pred = pred->m_Prev ;
274- }
275- // If this variable was not found in predecessors, add it.
276- addVar (VD );
277- }
278-
279263void TBRAnalyzer::addVar (const clang::VarDecl* VD , bool forceNonRefType) {
280264 auto & curBranch = getCurBlockVarsData ();
281265
@@ -296,6 +280,34 @@ void TBRAnalyzer::markLocation(const clang::Expr* E) {
296280}
297281
298282void TBRAnalyzer::setIsRequired (const clang::Expr* E, bool isReq) {
283+ // FIXME: generalize to other exprs
284+ if (const auto * DRE = dyn_cast<DeclRefExpr>(E)) {
285+ // Since TBRAnalyzer is a RecursiveASTVisitor,
286+ // it automatically visits all sub-stmts including
287+ // decl refs of functions.
288+ if (!isa<VarDecl>(DRE ->getDecl ()))
289+ return ;
290+ const auto * VD = cast<VarDecl>(DRE ->getDecl ());
291+ auto & curBranch = getCurBlockVarsData ();
292+ if (curBranch.find (VD ) == curBranch.end ()) {
293+ // Visit all predecessors one by one until the variable VD is found.
294+ auto * pred = curBranch.m_Prev ;
295+ bool found = false ;
296+ while (pred) {
297+ auto it = pred->find (VD );
298+ if (it != pred->end ()) {
299+ curBranch[VD ] = copy (it->second );
300+ found = true ;
301+ break ;
302+ }
303+ pred = pred->m_Prev ;
304+ }
305+ // If this variable was not found in predecessors, add it.
306+ if (!found)
307+ addVar (VD );
308+ }
309+ }
310+
299311 if (!isReq ||
300312 (m_ModeStack.back () == (Mode::kMarkingMode | Mode::kNonLinearMode ))) {
301313 VarData* data = getExprVarData (E);
@@ -571,14 +583,7 @@ void TBRAnalyzer::merge(VarsData* targetData, VarsData* mergeData) {
571583}
572584
573585bool TBRAnalyzer::VisitDeclRefExpr (DeclRefExpr* DRE ) {
574- if (const auto * VD = dyn_cast<VarDecl>(DRE ->getDecl ())) {
575- auto & curBranch = getCurBlockVarsData ();
576- if (curBranch.find (VD ) == curBranch.end ())
577- copyVarToCurBlock (VD );
578- }
579-
580586 setIsRequired (DRE );
581-
582587 return true ;
583588}
584589
0 commit comments