@@ -169,15 +169,15 @@ class NullabilityChecker
169
169
// / When \p SuppressPath is set to true, no more bugs will be reported on this
170
170
// / path by this checker.
171
171
void reportBugIfInvariantHolds (StringRef Msg, ErrorKind Error,
172
- CheckerPartIdx Idx , ExplodedNode *N,
172
+ const BugType &BT , ExplodedNode *N,
173
173
const MemRegion *Region, CheckerContext &C,
174
174
const Stmt *ValueExpr = nullptr ,
175
175
bool SuppressPath = false ) const ;
176
176
177
- void reportBug (StringRef Msg, ErrorKind Error, CheckerPartIdx Idx ,
177
+ void reportBug (StringRef Msg, ErrorKind Error, const BugType &BT ,
178
178
ExplodedNode *N, const MemRegion *Region, BugReporter &BR,
179
179
const Stmt *ValueExpr = nullptr ) const {
180
- auto R = std::make_unique<PathSensitiveBugReport>(BugTypes[Idx] , Msg, N);
180
+ auto R = std::make_unique<PathSensitiveBugReport>(BT , Msg, N);
181
181
if (Region) {
182
182
R->markInteresting (Region);
183
183
R->addVisitor <NullabilityBugVisitor>(Region);
@@ -483,7 +483,7 @@ static bool checkInvariantViolation(ProgramStateRef State, ExplodedNode *N,
483
483
}
484
484
485
485
void NullabilityChecker::reportBugIfInvariantHolds (
486
- StringRef Msg, ErrorKind Error, CheckerPartIdx Idx , ExplodedNode *N,
486
+ StringRef Msg, ErrorKind Error, const BugType &BT , ExplodedNode *N,
487
487
const MemRegion *Region, CheckerContext &C, const Stmt *ValueExpr,
488
488
bool SuppressPath) const {
489
489
ProgramStateRef OriginalState = N->getState ();
@@ -495,7 +495,7 @@ void NullabilityChecker::reportBugIfInvariantHolds(
495
495
N = C.addTransition (OriginalState, N);
496
496
}
497
497
498
- reportBug (Msg, Error, Idx , N, Region, C.getBugReporter (), ValueExpr);
498
+ reportBug (Msg, Error, BT , N, Region, C.getBugReporter (), ValueExpr);
499
499
}
500
500
501
501
// / Cleaning up the program state.
@@ -555,14 +555,15 @@ void NullabilityChecker::checkEvent(ImplicitNullDerefEvent Event) const {
555
555
// Do not suppress errors on defensive code paths, because dereferencing
556
556
// a nullable pointer is always an error.
557
557
if (Event.IsDirectDereference )
558
- reportBug (" Nullable pointer is dereferenced " ,
559
- ErrorKind::NullableDereferenced, NullableDereferencedChecker ,
560
- Event.SinkNode , Region, BR);
558
+ reportBug (
559
+ " Nullable pointer is dereferenced " , ErrorKind::NullableDereferenced,
560
+ BugTypes[NullableDereferencedChecker], Event.SinkNode , Region, BR);
561
561
else {
562
562
reportBug (" Nullable pointer is passed to a callee that requires a "
563
563
" non-null" ,
564
- ErrorKind::NullablePassedToNonnull, NullableDereferencedChecker,
565
- Event.SinkNode , Region, BR);
564
+ ErrorKind::NullablePassedToNonnull,
565
+ BugTypes[NullableDereferencedChecker], Event.SinkNode , Region,
566
+ BR);
566
567
}
567
568
}
568
569
}
@@ -730,8 +731,8 @@ void NullabilityChecker::checkPreStmt(const ReturnStmt *S,
730
731
OS << " returned from a " << C.getDeclDescription (D) <<
731
732
" that is expected to return a non-null value" ;
732
733
reportBugIfInvariantHolds (OS.str (), ErrorKind::NilReturnedToNonnull,
733
- NullReturnedFromNonnullChecker, N, nullptr , C ,
734
- RetExpr);
734
+ BugTypes[ NullReturnedFromNonnullChecker] , N,
735
+ nullptr , C, RetExpr);
735
736
return ;
736
737
}
737
738
@@ -764,8 +765,8 @@ void NullabilityChecker::checkPreStmt(const ReturnStmt *S,
764
765
" that is expected to return a non-null value" ;
765
766
766
767
reportBugIfInvariantHolds (OS.str (), ErrorKind::NullableReturnedToNonnull,
767
- NullableReturnedFromNonnullChecker, N, Region ,
768
- C);
768
+ BugTypes[ NullableReturnedFromNonnullChecker] , N,
769
+ Region, C);
769
770
}
770
771
return ;
771
772
}
@@ -831,9 +832,8 @@ void NullabilityChecker::checkPreCall(const CallEvent &Call,
831
832
OS << " passed to a callee that requires a non-null " << ParamIdx
832
833
<< llvm::getOrdinalSuffix (ParamIdx) << " parameter" ;
833
834
reportBugIfInvariantHolds (OS.str (), ErrorKind::NilPassedToNonnull,
834
- NullPassedToNonnullChecker, N, nullptr , C,
835
- ArgExpr,
836
- /* SuppressPath=*/ false );
835
+ BugTypes[NullPassedToNonnullChecker], N,
836
+ nullptr , C, ArgExpr, /* SuppressPath=*/ false );
837
837
return ;
838
838
}
839
839
@@ -858,17 +858,17 @@ void NullabilityChecker::checkPreCall(const CallEvent &Call,
858
858
OS << " Nullable pointer is passed to a callee that requires a non-null "
859
859
<< ParamIdx << llvm::getOrdinalSuffix (ParamIdx) << " parameter" ;
860
860
reportBugIfInvariantHolds (OS.str (), ErrorKind::NullablePassedToNonnull,
861
- NullablePassedToNonnullChecker, N, Region, C ,
862
- ArgExpr, /* SuppressPath=*/ true );
861
+ BugTypes[ NullablePassedToNonnullChecker] , N,
862
+ Region, C, ArgExpr, /* SuppressPath=*/ true );
863
863
return ;
864
864
}
865
865
if (isPartEnabled (NullableDereferencedChecker) &&
866
866
Param->getType ()->isReferenceType ()) {
867
867
ExplodedNode *N = C.addTransition (State);
868
868
reportBugIfInvariantHolds (" Nullable pointer is dereferenced" ,
869
869
ErrorKind::NullableDereferenced,
870
- NullableDereferencedChecker, N, Region, C ,
871
- ArgExpr, /* SuppressPath=*/ true );
870
+ BugTypes[ NullableDereferencedChecker] , N,
871
+ Region, C, ArgExpr, /* SuppressPath=*/ true );
872
872
return ;
873
873
}
874
874
continue ;
@@ -1321,8 +1321,8 @@ void NullabilityChecker::checkBind(SVal L, SVal V, const Stmt *S,
1321
1321
OS << (LocType->isObjCObjectPointerType () ? " nil" : " Null" );
1322
1322
OS << " assigned to a pointer which is expected to have non-null value" ;
1323
1323
reportBugIfInvariantHolds (OS.str (), ErrorKind::NilAssignedToNonnull,
1324
- NullPassedToNonnullChecker, N, nullptr , C ,
1325
- ValueStmt);
1324
+ BugTypes[ NullPassedToNonnullChecker] , N, nullptr ,
1325
+ C, ValueStmt);
1326
1326
return ;
1327
1327
}
1328
1328
@@ -1355,8 +1355,8 @@ void NullabilityChecker::checkBind(SVal L, SVal V, const Stmt *S,
1355
1355
reportBugIfInvariantHolds (" Nullable pointer is assigned to a pointer "
1356
1356
" which is expected to have non-null value" ,
1357
1357
ErrorKind::NullableAssignedToNonnull,
1358
- NullablePassedToNonnullChecker, N, ValueRegion ,
1359
- C);
1358
+ BugTypes[ NullablePassedToNonnullChecker] , N,
1359
+ ValueRegion, C);
1360
1360
}
1361
1361
return ;
1362
1362
}
0 commit comments