@@ -78,33 +78,44 @@ void IdDependentBackwardBranchCheck::registerMatchers(MatchFinder *Finder) {
78
78
79
79
IdDependentBackwardBranchCheck::IdDependencyRecord *
80
80
IdDependentBackwardBranchCheck::hasIdDepVar (const Expr *Expression) {
81
+ if (!Expression)
82
+ return nullptr ;
83
+
81
84
if (const auto *Declaration = dyn_cast<DeclRefExpr>(Expression)) {
82
85
// It is a DeclRefExpr, so check if it's an ID-dependent variable.
83
- const auto *CheckVariable = dyn_cast<VarDecl>(Declaration->getDecl ());
86
+ const auto *CheckVariable =
87
+ dyn_cast_if_present<VarDecl>(Declaration->getDecl ());
88
+ if (!CheckVariable)
89
+ return nullptr ;
84
90
auto FoundVariable = IdDepVarsMap.find (CheckVariable);
85
91
if (FoundVariable == IdDepVarsMap.end ())
86
92
return nullptr ;
87
93
return &(FoundVariable->second );
88
94
}
89
95
for (const auto *Child : Expression->children ())
90
- if (const auto *ChildExpression = dyn_cast <Expr>(Child))
96
+ if (const auto *ChildExpression = dyn_cast_if_present <Expr>(Child))
91
97
if (IdDependencyRecord *Result = hasIdDepVar (ChildExpression))
92
98
return Result;
93
99
return nullptr ;
94
100
}
95
101
96
102
IdDependentBackwardBranchCheck::IdDependencyRecord *
97
103
IdDependentBackwardBranchCheck::hasIdDepField (const Expr *Expression) {
104
+ if (!Expression)
105
+ return nullptr ;
106
+
98
107
if (const auto *MemberExpression = dyn_cast<MemberExpr>(Expression)) {
99
108
const auto *CheckField =
100
- dyn_cast<FieldDecl>(MemberExpression->getMemberDecl ());
109
+ dyn_cast_if_present<FieldDecl>(MemberExpression->getMemberDecl ());
110
+ if (!CheckField)
111
+ return nullptr ;
101
112
auto FoundField = IdDepFieldsMap.find (CheckField);
102
113
if (FoundField == IdDepFieldsMap.end ())
103
114
return nullptr ;
104
115
return &(FoundField->second );
105
116
}
106
117
for (const auto *Child : Expression->children ())
107
- if (const auto *ChildExpression = dyn_cast <Expr>(Child))
118
+ if (const auto *ChildExpression = dyn_cast_if_present <Expr>(Child))
108
119
if (IdDependencyRecord *Result = hasIdDepField (ChildExpression))
109
120
return Result;
110
121
return nullptr ;
0 commit comments