Skip to content

Commit 3ca23ce

Browse files
committed
Use BugType parameters for reportBug{,IfInvariantHolds}
1 parent 2708bed commit 3ca23ce

File tree

1 file changed

+25
-25
lines changed

1 file changed

+25
-25
lines changed

clang/lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -169,15 +169,15 @@ class NullabilityChecker
169169
/// When \p SuppressPath is set to true, no more bugs will be reported on this
170170
/// path by this checker.
171171
void reportBugIfInvariantHolds(StringRef Msg, ErrorKind Error,
172-
CheckerPartIdx Idx, ExplodedNode *N,
172+
const BugType &BT, ExplodedNode *N,
173173
const MemRegion *Region, CheckerContext &C,
174174
const Stmt *ValueExpr = nullptr,
175175
bool SuppressPath = false) const;
176176

177-
void reportBug(StringRef Msg, ErrorKind Error, CheckerPartIdx Idx,
177+
void reportBug(StringRef Msg, ErrorKind Error, const BugType &BT,
178178
ExplodedNode *N, const MemRegion *Region, BugReporter &BR,
179179
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);
181181
if (Region) {
182182
R->markInteresting(Region);
183183
R->addVisitor<NullabilityBugVisitor>(Region);
@@ -483,7 +483,7 @@ static bool checkInvariantViolation(ProgramStateRef State, ExplodedNode *N,
483483
}
484484

485485
void NullabilityChecker::reportBugIfInvariantHolds(
486-
StringRef Msg, ErrorKind Error, CheckerPartIdx Idx, ExplodedNode *N,
486+
StringRef Msg, ErrorKind Error, const BugType &BT, ExplodedNode *N,
487487
const MemRegion *Region, CheckerContext &C, const Stmt *ValueExpr,
488488
bool SuppressPath) const {
489489
ProgramStateRef OriginalState = N->getState();
@@ -495,7 +495,7 @@ void NullabilityChecker::reportBugIfInvariantHolds(
495495
N = C.addTransition(OriginalState, N);
496496
}
497497

498-
reportBug(Msg, Error, Idx, N, Region, C.getBugReporter(), ValueExpr);
498+
reportBug(Msg, Error, BT, N, Region, C.getBugReporter(), ValueExpr);
499499
}
500500

501501
/// Cleaning up the program state.
@@ -555,14 +555,15 @@ void NullabilityChecker::checkEvent(ImplicitNullDerefEvent Event) const {
555555
// Do not suppress errors on defensive code paths, because dereferencing
556556
// a nullable pointer is always an error.
557557
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);
561561
else {
562562
reportBug("Nullable pointer is passed to a callee that requires a "
563563
"non-null",
564-
ErrorKind::NullablePassedToNonnull, NullableDereferencedChecker,
565-
Event.SinkNode, Region, BR);
564+
ErrorKind::NullablePassedToNonnull,
565+
BugTypes[NullableDereferencedChecker], Event.SinkNode, Region,
566+
BR);
566567
}
567568
}
568569
}
@@ -730,8 +731,8 @@ void NullabilityChecker::checkPreStmt(const ReturnStmt *S,
730731
OS << " returned from a " << C.getDeclDescription(D) <<
731732
" that is expected to return a non-null value";
732733
reportBugIfInvariantHolds(OS.str(), ErrorKind::NilReturnedToNonnull,
733-
NullReturnedFromNonnullChecker, N, nullptr, C,
734-
RetExpr);
734+
BugTypes[NullReturnedFromNonnullChecker], N,
735+
nullptr, C, RetExpr);
735736
return;
736737
}
737738

@@ -764,8 +765,8 @@ void NullabilityChecker::checkPreStmt(const ReturnStmt *S,
764765
" that is expected to return a non-null value";
765766

766767
reportBugIfInvariantHolds(OS.str(), ErrorKind::NullableReturnedToNonnull,
767-
NullableReturnedFromNonnullChecker, N, Region,
768-
C);
768+
BugTypes[NullableReturnedFromNonnullChecker], N,
769+
Region, C);
769770
}
770771
return;
771772
}
@@ -831,9 +832,8 @@ void NullabilityChecker::checkPreCall(const CallEvent &Call,
831832
OS << " passed to a callee that requires a non-null " << ParamIdx
832833
<< llvm::getOrdinalSuffix(ParamIdx) << " parameter";
833834
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);
837837
return;
838838
}
839839

@@ -858,17 +858,17 @@ void NullabilityChecker::checkPreCall(const CallEvent &Call,
858858
OS << "Nullable pointer is passed to a callee that requires a non-null "
859859
<< ParamIdx << llvm::getOrdinalSuffix(ParamIdx) << " parameter";
860860
reportBugIfInvariantHolds(OS.str(), ErrorKind::NullablePassedToNonnull,
861-
NullablePassedToNonnullChecker, N, Region, C,
862-
ArgExpr, /*SuppressPath=*/true);
861+
BugTypes[NullablePassedToNonnullChecker], N,
862+
Region, C, ArgExpr, /*SuppressPath=*/true);
863863
return;
864864
}
865865
if (isPartEnabled(NullableDereferencedChecker) &&
866866
Param->getType()->isReferenceType()) {
867867
ExplodedNode *N = C.addTransition(State);
868868
reportBugIfInvariantHolds("Nullable pointer is dereferenced",
869869
ErrorKind::NullableDereferenced,
870-
NullableDereferencedChecker, N, Region, C,
871-
ArgExpr, /*SuppressPath=*/true);
870+
BugTypes[NullableDereferencedChecker], N,
871+
Region, C, ArgExpr, /*SuppressPath=*/true);
872872
return;
873873
}
874874
continue;
@@ -1321,8 +1321,8 @@ void NullabilityChecker::checkBind(SVal L, SVal V, const Stmt *S,
13211321
OS << (LocType->isObjCObjectPointerType() ? "nil" : "Null");
13221322
OS << " assigned to a pointer which is expected to have non-null value";
13231323
reportBugIfInvariantHolds(OS.str(), ErrorKind::NilAssignedToNonnull,
1324-
NullPassedToNonnullChecker, N, nullptr, C,
1325-
ValueStmt);
1324+
BugTypes[NullPassedToNonnullChecker], N, nullptr,
1325+
C, ValueStmt);
13261326
return;
13271327
}
13281328

@@ -1355,8 +1355,8 @@ void NullabilityChecker::checkBind(SVal L, SVal V, const Stmt *S,
13551355
reportBugIfInvariantHolds("Nullable pointer is assigned to a pointer "
13561356
"which is expected to have non-null value",
13571357
ErrorKind::NullableAssignedToNonnull,
1358-
NullablePassedToNonnullChecker, N, ValueRegion,
1359-
C);
1358+
BugTypes[NullablePassedToNonnullChecker], N,
1359+
ValueRegion, C);
13601360
}
13611361
return;
13621362
}

0 commit comments

Comments
 (0)