@@ -367,13 +367,13 @@ class StdLibraryFunctionsChecker
367367 };
368368
369369 // / Check null or non-null-ness of an argument that is of pointer type.
370- class NotNullConstraint : public ValueConstraint {
370+ class NullnessConstraint : public ValueConstraint {
371371 using ValueConstraint::ValueConstraint;
372372 // This variable has a role when we negate the constraint.
373373 bool CannotBeNull = true ;
374374
375375 public:
376- NotNullConstraint (ArgNo ArgN, bool CannotBeNull = true )
376+ NullnessConstraint (ArgNo ArgN, bool CannotBeNull = true )
377377 : ValueConstraint(ArgN), CannotBeNull(CannotBeNull) {}
378378
379379 ProgramStateRef apply (ProgramStateRef State, const CallEvent &Call,
@@ -389,9 +389,9 @@ class StdLibraryFunctionsChecker
389389 llvm::raw_ostream &Out) const override ;
390390
391391 ValueConstraintPtr negate () const override {
392- NotNullConstraint Tmp (*this );
392+ NullnessConstraint Tmp (*this );
393393 Tmp.CannotBeNull = !this ->CannotBeNull ;
394- return std::make_shared<NotNullConstraint >(Tmp);
394+ return std::make_shared<NullnessConstraint >(Tmp);
395395 }
396396
397397 protected:
@@ -407,19 +407,19 @@ class StdLibraryFunctionsChecker
407407 // / The argument is meant to be a buffer that has a size constraint, and it
408408 // / is allowed to have a NULL value if the size is 0. The size can depend on
409409 // / 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 {
413413 using ValueConstraint::ValueConstraint;
414414 ArgNo SizeArg1N;
415415 std::optional<ArgNo> SizeArg2N;
416416 // This variable has a role when we negate the constraint.
417417 bool CannotBeNull = true ;
418418
419419 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 )
423423 : ValueConstraint(ArgN), SizeArg1N(SizeArg1N), SizeArg2N(SizeArg2N),
424424 CannotBeNull (CannotBeNull) {}
425425
@@ -436,9 +436,9 @@ class StdLibraryFunctionsChecker
436436 llvm::raw_ostream &Out) const override ;
437437
438438 ValueConstraintPtr negate () const override {
439- NotNullBufferConstraint Tmp (*this );
439+ BufferNullnessConstraint Tmp (*this );
440440 Tmp.CannotBeNull = !this ->CannotBeNull ;
441- return std::make_shared<NotNullBufferConstraint >(Tmp);
441+ return std::make_shared<BufferNullnessConstraint >(Tmp);
442442 }
443443
444444 protected:
@@ -1151,7 +1151,7 @@ ProgramStateRef StdLibraryFunctionsChecker::ComparisonConstraint::apply(
11511151 return State;
11521152}
11531153
1154- ProgramStateRef StdLibraryFunctionsChecker::NotNullConstraint ::apply (
1154+ ProgramStateRef StdLibraryFunctionsChecker::NullnessConstraint ::apply (
11551155 ProgramStateRef State, const CallEvent &Call, const Summary &Summary,
11561156 CheckerContext &C) const {
11571157 SVal V = getArgSVal (Call, getArgNo ());
@@ -1165,26 +1165,27 @@ ProgramStateRef StdLibraryFunctionsChecker::NotNullConstraint::apply(
11651165 return State->assume (L, CannotBeNull);
11661166}
11671167
1168- void StdLibraryFunctionsChecker::NotNullConstraint ::describe (
1168+ void StdLibraryFunctionsChecker::NullnessConstraint ::describe (
11691169 DescriptionKind DK, const CallEvent &Call, ProgramStateRef State,
11701170 const Summary &Summary, llvm::raw_ostream &Out) const {
11711171 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" );
11731173 if (DK == Violation)
11741174 Out << " should not be NULL" ;
11751175 else
11761176 Out << " is not NULL" ;
11771177}
11781178
1179- bool StdLibraryFunctionsChecker::NotNullConstraint ::describeArgumentValue (
1179+ bool StdLibraryFunctionsChecker::NullnessConstraint ::describeArgumentValue (
11801180 const CallEvent &Call, ProgramStateRef State, const Summary &Summary,
11811181 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" );
11831184 Out << " is NULL" ;
11841185 return true ;
11851186}
11861187
1187- ProgramStateRef StdLibraryFunctionsChecker::NotNullBufferConstraint ::apply (
1188+ ProgramStateRef StdLibraryFunctionsChecker::BufferNullnessConstraint ::apply (
11881189 ProgramStateRef State, const CallEvent &Call, const Summary &Summary,
11891190 CheckerContext &C) const {
11901191 SVal V = getArgSVal (Call, getArgNo ());
@@ -1213,21 +1214,23 @@ ProgramStateRef StdLibraryFunctionsChecker::NotNullBufferConstraint::apply(
12131214 return State->assume (L, CannotBeNull);
12141215}
12151216
1216- void StdLibraryFunctionsChecker::NotNullBufferConstraint ::describe (
1217+ void StdLibraryFunctionsChecker::BufferNullnessConstraint ::describe (
12171218 DescriptionKind DK, const CallEvent &Call, ProgramStateRef State,
12181219 const Summary &Summary, llvm::raw_ostream &Out) const {
12191220 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" );
12211222 if (DK == Violation)
12221223 Out << " should not be NULL" ;
12231224 else
12241225 Out << " is not NULL" ;
12251226}
12261227
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" );
12311234 Out << " is NULL" ;
12321235 return true ;
12331236}
@@ -1792,15 +1795,15 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
17921795 };
17931796 auto LessThanOrEq = BO_LE;
17941797 auto NotNull = [&](ArgNo ArgN) {
1795- return std::make_shared<NotNullConstraint >(ArgN);
1798+ return std::make_shared<NullnessConstraint >(ArgN);
17961799 };
17971800 auto IsNull = [&](ArgNo ArgN) {
1798- return std::make_shared<NotNullConstraint >(ArgN, false );
1801+ return std::make_shared<NullnessConstraint >(ArgN, false );
17991802 };
18001803 auto NotNullBuffer = [&](ArgNo ArgN, ArgNo SizeArg1N,
18011804 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);
18041807 };
18051808
18061809 std::optional<QualType> FileTy = lookupTy (" FILE" );
0 commit comments