@@ -367,13 +367,13 @@ class StdLibraryFunctionsChecker
367
367
};
368
368
369
369
// / Check null or non-null-ness of an argument that is of pointer type.
370
- class NotNullConstraint : public ValueConstraint {
370
+ class NullnessConstraint : public ValueConstraint {
371
371
using ValueConstraint::ValueConstraint;
372
372
// This variable has a role when we negate the constraint.
373
373
bool CannotBeNull = true ;
374
374
375
375
public:
376
- NotNullConstraint (ArgNo ArgN, bool CannotBeNull = true )
376
+ NullnessConstraint (ArgNo ArgN, bool CannotBeNull = true )
377
377
: ValueConstraint(ArgN), CannotBeNull(CannotBeNull) {}
378
378
379
379
ProgramStateRef apply (ProgramStateRef State, const CallEvent &Call,
@@ -389,9 +389,9 @@ class StdLibraryFunctionsChecker
389
389
llvm::raw_ostream &Out) const override ;
390
390
391
391
ValueConstraintPtr negate () const override {
392
- NotNullConstraint Tmp (*this );
392
+ NullnessConstraint Tmp (*this );
393
393
Tmp.CannotBeNull = !this ->CannotBeNull ;
394
- return std::make_shared<NotNullConstraint >(Tmp);
394
+ return std::make_shared<NullnessConstraint >(Tmp);
395
395
}
396
396
397
397
protected:
@@ -407,19 +407,19 @@ class StdLibraryFunctionsChecker
407
407
// / The argument is meant to be a buffer that has a size constraint, and it
408
408
// / is allowed to have a NULL value if the size is 0. The size can depend on
409
409
// / 1 or 2 additional arguments, if one of these is 0 the buffer is allowed to
410
- // / be NULL. This is useful for functions like `fread` which have this special
411
- // / property.
412
- class NotNullBufferConstraint : public ValueConstraint {
410
+ // / be NULL. Otherwise, the buffer pointer must be non-null. This is useful
411
+ // / for functions like `fread` which have this special property.
412
+ class BufferNullnessConstraint : public ValueConstraint {
413
413
using ValueConstraint::ValueConstraint;
414
414
ArgNo SizeArg1N;
415
415
std::optional<ArgNo> SizeArg2N;
416
416
// This variable has a role when we negate the constraint.
417
417
bool CannotBeNull = true ;
418
418
419
419
public:
420
- NotNullBufferConstraint (ArgNo ArgN, ArgNo SizeArg1N,
421
- std::optional<ArgNo> SizeArg2N,
422
- bool CannotBeNull = true )
420
+ BufferNullnessConstraint (ArgNo ArgN, ArgNo SizeArg1N,
421
+ std::optional<ArgNo> SizeArg2N,
422
+ bool CannotBeNull = true )
423
423
: ValueConstraint(ArgN), SizeArg1N(SizeArg1N), SizeArg2N(SizeArg2N),
424
424
CannotBeNull (CannotBeNull) {}
425
425
@@ -436,9 +436,9 @@ class StdLibraryFunctionsChecker
436
436
llvm::raw_ostream &Out) const override ;
437
437
438
438
ValueConstraintPtr negate () const override {
439
- NotNullBufferConstraint Tmp (*this );
439
+ BufferNullnessConstraint Tmp (*this );
440
440
Tmp.CannotBeNull = !this ->CannotBeNull ;
441
- return std::make_shared<NotNullBufferConstraint >(Tmp);
441
+ return std::make_shared<BufferNullnessConstraint >(Tmp);
442
442
}
443
443
444
444
protected:
@@ -1151,7 +1151,7 @@ ProgramStateRef StdLibraryFunctionsChecker::ComparisonConstraint::apply(
1151
1151
return State;
1152
1152
}
1153
1153
1154
- ProgramStateRef StdLibraryFunctionsChecker::NotNullConstraint ::apply (
1154
+ ProgramStateRef StdLibraryFunctionsChecker::NullnessConstraint ::apply (
1155
1155
ProgramStateRef State, const CallEvent &Call, const Summary &Summary,
1156
1156
CheckerContext &C) const {
1157
1157
SVal V = getArgSVal (Call, getArgNo ());
@@ -1165,26 +1165,27 @@ ProgramStateRef StdLibraryFunctionsChecker::NotNullConstraint::apply(
1165
1165
return State->assume (L, CannotBeNull);
1166
1166
}
1167
1167
1168
- void StdLibraryFunctionsChecker::NotNullConstraint ::describe (
1168
+ void StdLibraryFunctionsChecker::NullnessConstraint ::describe (
1169
1169
DescriptionKind DK, const CallEvent &Call, ProgramStateRef State,
1170
1170
const Summary &Summary, llvm::raw_ostream &Out) const {
1171
1171
assert (CannotBeNull &&
1172
- " Describe should not be used when the value must be NULL" );
1172
+ " 'describe' is not implemented when the value must be NULL" );
1173
1173
if (DK == Violation)
1174
1174
Out << " should not be NULL" ;
1175
1175
else
1176
1176
Out << " is not NULL" ;
1177
1177
}
1178
1178
1179
- bool StdLibraryFunctionsChecker::NotNullConstraint ::describeArgumentValue (
1179
+ bool StdLibraryFunctionsChecker::NullnessConstraint ::describeArgumentValue (
1180
1180
const CallEvent &Call, ProgramStateRef State, const Summary &Summary,
1181
1181
llvm::raw_ostream &Out) const {
1182
- assert (!CannotBeNull && " This function is used when the value is NULL" );
1182
+ assert (!CannotBeNull && " 'describeArgumentValue' is not implemented when the "
1183
+ " value must be non-NULL" );
1183
1184
Out << " is NULL" ;
1184
1185
return true ;
1185
1186
}
1186
1187
1187
- ProgramStateRef StdLibraryFunctionsChecker::NotNullBufferConstraint ::apply (
1188
+ ProgramStateRef StdLibraryFunctionsChecker::BufferNullnessConstraint ::apply (
1188
1189
ProgramStateRef State, const CallEvent &Call, const Summary &Summary,
1189
1190
CheckerContext &C) const {
1190
1191
SVal V = getArgSVal (Call, getArgNo ());
@@ -1213,21 +1214,23 @@ ProgramStateRef StdLibraryFunctionsChecker::NotNullBufferConstraint::apply(
1213
1214
return State->assume (L, CannotBeNull);
1214
1215
}
1215
1216
1216
- void StdLibraryFunctionsChecker::NotNullBufferConstraint ::describe (
1217
+ void StdLibraryFunctionsChecker::BufferNullnessConstraint ::describe (
1217
1218
DescriptionKind DK, const CallEvent &Call, ProgramStateRef State,
1218
1219
const Summary &Summary, llvm::raw_ostream &Out) const {
1219
1220
assert (CannotBeNull &&
1220
- " Describe should not be used when the value must be NULL" );
1221
+ " 'describe' is not implemented when the buffer must be NULL" );
1221
1222
if (DK == Violation)
1222
1223
Out << " should not be NULL" ;
1223
1224
else
1224
1225
Out << " is not NULL" ;
1225
1226
}
1226
1227
1227
- bool StdLibraryFunctionsChecker::NotNullBufferConstraint::describeArgumentValue (
1228
- const CallEvent &Call, ProgramStateRef State, const Summary &Summary,
1229
- llvm::raw_ostream &Out) const {
1230
- assert (!CannotBeNull && " This function is used when the value is NULL" );
1228
+ bool StdLibraryFunctionsChecker::BufferNullnessConstraint::
1229
+ describeArgumentValue (const CallEvent &Call, ProgramStateRef State,
1230
+ const Summary &Summary,
1231
+ llvm::raw_ostream &Out) const {
1232
+ assert (!CannotBeNull && " 'describeArgumentValue' is not implemented when the "
1233
+ " buffer must be non-NULL" );
1231
1234
Out << " is NULL" ;
1232
1235
return true ;
1233
1236
}
@@ -1792,15 +1795,15 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
1792
1795
};
1793
1796
auto LessThanOrEq = BO_LE;
1794
1797
auto NotNull = [&](ArgNo ArgN) {
1795
- return std::make_shared<NotNullConstraint >(ArgN);
1798
+ return std::make_shared<NullnessConstraint >(ArgN);
1796
1799
};
1797
1800
auto IsNull = [&](ArgNo ArgN) {
1798
- return std::make_shared<NotNullConstraint >(ArgN, false );
1801
+ return std::make_shared<NullnessConstraint >(ArgN, false );
1799
1802
};
1800
1803
auto NotNullBuffer = [&](ArgNo ArgN, ArgNo SizeArg1N,
1801
1804
std::optional<ArgNo> SizeArg2N = std::nullopt) {
1802
- return std::make_shared<NotNullBufferConstraint >(ArgN, SizeArg1N,
1803
- SizeArg2N);
1805
+ return std::make_shared<BufferNullnessConstraint >(ArgN, SizeArg1N,
1806
+ SizeArg2N);
1804
1807
};
1805
1808
1806
1809
std::optional<QualType> FileTy = lookupTy (" FILE" );
0 commit comments