52#include "llvm/ADT/STLExtras.h"
53#include "llvm/ADT/SmallString.h"
54#include "llvm/ADT/StringExtras.h"
55#include "llvm/Support/FormatVariadic.h"
64class StdLibraryFunctionsChecker
65 :
public Checker<check::PreCall, check::PostCall, eval::Call> {
71 enum InvalidationKind {
80 enum RangeKind { OutOfRange, WithinRange };
82 static RangeKind negateKind(RangeKind K) {
89 llvm_unreachable(
"Unknown range kind");
98 typedef std::vector<std::pair<RangeInt, RangeInt>> IntRangeVector;
105 static const ArgNo Ret;
109 static void printArgDesc(ArgNo, llvm::raw_ostream &Out);
114 const CallEvent &
Call, llvm::raw_ostream &Out);
117 static void appendInsideRangeDesc(llvm::APSInt RMin, llvm::APSInt RMax,
118 QualType ArgT, BasicValueFactory &BVF,
119 llvm::raw_ostream &Out);
122 static void appendOutOfRangeDesc(llvm::APSInt RMin, llvm::APSInt RMax,
123 QualType ArgT, BasicValueFactory &BVF,
124 llvm::raw_ostream &Out);
126 class ValueConstraint;
135 using ValueConstraintPtr = std::shared_ptr<ValueConstraint>;
147 class ValueConstraint {
149 ValueConstraint(ArgNo ArgN) : ArgN(ArgN) {}
150 virtual ~ValueConstraint() {}
155 const Summary &Summary,
156 CheckerContext &
C)
const = 0;
160 enum DescriptionKind {
176 virtual void describe(DescriptionKind DK,
const CallEvent &
Call,
178 llvm::raw_ostream &Out)
const {
183 "Description not implemented for summary case constraints");
198 virtual bool describeArgumentValue(
const CallEvent &
Call,
200 const Summary &Summary,
201 llvm::raw_ostream &Out)
const {
202 if (
auto N = getArgSVal(
Call, getArgNo()).getAs<NonLoc>()) {
203 if (
const llvm::APSInt *Int = N->getAsInteger()) {
217 virtual std::vector<ArgNo> getArgsToTrack()
const {
return {ArgN}; }
220 virtual ValueConstraintPtr negate()
const {
221 llvm_unreachable(
"Not implemented");
229 bool checkValidity(
const FunctionDecl *FD)
const {
231 assert(ValidArg &&
"Arg out of range!");
235 return checkSpecificValidity(FD);
239 ArgNo getArgNo()
const {
return ArgN; }
250 virtual bool checkSpecificValidity(
const FunctionDecl *FD)
const {
265 class RangeConstraint :
public ValueConstraint {
272 IntRangeVector Ranges;
277 StringRef Description;
280 RangeConstraint(ArgNo ArgN, RangeKind Kind,
const IntRangeVector &Ranges,
282 : ValueConstraint(ArgN), Kind(Kind), Ranges(Ranges), Description(Desc) {
285 const IntRangeVector &getRanges()
const {
return Ranges; }
288 const Summary &Summary,
289 CheckerContext &
C)
const override;
291 void describe(DescriptionKind DK,
const CallEvent &
Call,
293 llvm::raw_ostream &Out)
const override;
296 const Summary &Summary,
297 llvm::raw_ostream &Out)
const override;
299 ValueConstraintPtr negate()
const override {
300 RangeConstraint Tmp(*
this);
301 Tmp.Kind = negateKind(Kind);
302 return std::make_shared<RangeConstraint>(Tmp);
306 bool checkSpecificValidity(
const FunctionDecl *FD)
const override {
307 const bool ValidArg =
310 "This constraint should be applied on an integral type");
319 using RangeApplyFunction =
324 void applyOnWithinRange(BasicValueFactory &BVF, QualType ArgT,
325 const RangeApplyFunction &F)
const;
336 void applyOnOutOfRange(BasicValueFactory &BVF, QualType ArgT,
337 const RangeApplyFunction &F)
const;
340 void applyOnRange(RangeKind Kind, BasicValueFactory &BVF, QualType ArgT,
341 const RangeApplyFunction &F)
const {
344 applyOnOutOfRange(BVF, ArgT, F);
347 applyOnWithinRange(BVF, ArgT, F);
354 class ComparisonConstraint :
public ValueConstraint {
361 : ValueConstraint(ArgN), Opcode(Opcode), OtherArgN(OtherArgN) {}
362 ArgNo getOtherArgNo()
const {
return OtherArgN; }
365 const Summary &Summary,
366 CheckerContext &
C)
const override;
370 class NullnessConstraint :
public ValueConstraint {
371 using ValueConstraint::ValueConstraint;
373 bool CannotBeNull =
true;
376 NullnessConstraint(ArgNo ArgN,
bool CannotBeNull =
true)
377 : ValueConstraint(ArgN), CannotBeNull(CannotBeNull) {}
380 const Summary &Summary,
381 CheckerContext &
C)
const override;
383 void describe(DescriptionKind DK,
const CallEvent &
Call,
385 llvm::raw_ostream &Out)
const override;
388 const Summary &Summary,
389 llvm::raw_ostream &Out)
const override;
391 ValueConstraintPtr negate()
const override {
392 NullnessConstraint Tmp(*
this);
393 Tmp.CannotBeNull = !this->CannotBeNull;
394 return std::make_shared<NullnessConstraint>(Tmp);
398 bool checkSpecificValidity(
const FunctionDecl *FD)
const override {
399 const bool ValidArg = getArgType(FD, ArgN)->isPointerType();
401 "This constraint should be applied only on a pointer type");
412 class BufferNullnessConstraint :
public ValueConstraint {
413 using ValueConstraint::ValueConstraint;
415 std::optional<ArgNo> SizeArg2N;
417 bool CannotBeNull =
true;
420 BufferNullnessConstraint(ArgNo ArgN, ArgNo SizeArg1N,
421 std::optional<ArgNo> SizeArg2N,
422 bool CannotBeNull =
true)
423 : ValueConstraint(ArgN), SizeArg1N(SizeArg1N), SizeArg2N(SizeArg2N),
424 CannotBeNull(CannotBeNull) {}
427 const Summary &Summary,
428 CheckerContext &
C)
const override;
430 void describe(DescriptionKind DK,
const CallEvent &
Call,
432 llvm::raw_ostream &Out)
const override;
435 const Summary &Summary,
436 llvm::raw_ostream &Out)
const override;
438 ValueConstraintPtr negate()
const override {
439 BufferNullnessConstraint Tmp(*
this);
440 Tmp.CannotBeNull = !this->CannotBeNull;
441 return std::make_shared<BufferNullnessConstraint>(Tmp);
445 bool checkSpecificValidity(
const FunctionDecl *FD)
const override {
446 const bool ValidArg = getArgType(FD, ArgN)->isPointerType();
448 "This constraint should be applied only on a pointer type");
463 class BufferSizeConstraint :
public ValueConstraint {
465 std::optional<llvm::APSInt> ConcreteSize;
467 std::optional<ArgNo> SizeArgN;
471 std::optional<ArgNo> SizeMultiplierArgN;
476 BufferSizeConstraint(ArgNo Buffer, llvm::APSInt BufMinSize)
477 : ValueConstraint(Buffer), ConcreteSize(BufMinSize) {}
478 BufferSizeConstraint(ArgNo Buffer, ArgNo BufSize)
479 : ValueConstraint(Buffer), SizeArgN(BufSize) {}
480 BufferSizeConstraint(ArgNo Buffer, ArgNo BufSize, ArgNo BufSizeMultiplier)
481 : ValueConstraint(Buffer), SizeArgN(BufSize),
482 SizeMultiplierArgN(BufSizeMultiplier) {}
485 const Summary &Summary,
486 CheckerContext &
C)
const override;
488 void describe(DescriptionKind DK,
const CallEvent &
Call,
490 llvm::raw_ostream &Out)
const override;
493 const Summary &Summary,
494 llvm::raw_ostream &Out)
const override;
496 std::vector<ArgNo> getArgsToTrack()
const override {
497 std::vector<ArgNo>
Result{ArgN};
499 Result.push_back(*SizeArgN);
500 if (SizeMultiplierArgN)
501 Result.push_back(*SizeMultiplierArgN);
505 ValueConstraintPtr negate()
const override {
506 BufferSizeConstraint Tmp(*
this);
508 return std::make_shared<BufferSizeConstraint>(Tmp);
512 bool checkSpecificValidity(
const FunctionDecl *FD)
const override {
513 const bool ValidArg = getArgType(FD, ArgN)->isPointerType();
515 "This constraint should be applied only on a pointer type");
521 using ConstraintSet = std::vector<ValueConstraintPtr>;
530 class ErrnoConstraintBase {
534 const Summary &Summary,
535 CheckerContext &
C)
const = 0;
540 virtual std::string
describe(CheckerContext &
C)
const {
return ""; }
542 virtual ~ErrnoConstraintBase() {}
545 ErrnoConstraintBase() =
default;
555 class ResetErrnoConstraint :
public ErrnoConstraintBase {
558 const Summary &Summary,
559 CheckerContext &
C)
const override {
568 class NoErrnoConstraint :
public ErrnoConstraintBase {
571 const Summary &Summary,
572 CheckerContext &
C)
const override {
581 class FailureErrnoConstraint :
public ErrnoConstraintBase {
584 const Summary &Summary,
585 CheckerContext &
C)
const override {
586 SValBuilder &SVB =
C.getSValBuilder();
588 C.blockCount(), &Tag)
599 class SuccessErrnoConstraint :
public ErrnoConstraintBase {
602 const Summary &Summary,
603 CheckerContext &
C)
const override {
607 std::string
describe(CheckerContext &
C)
const override {
608 return "'errno' becomes undefined after the call";
616 class ErrnoMustBeCheckedConstraint :
public ErrnoConstraintBase {
619 const Summary &Summary,
620 CheckerContext &
C)
const override {
622 Call.getCFGElementRef());
625 std::string
describe(CheckerContext &
C)
const override {
626 return "reading 'errno' is required to find out if the call has failed";
652 ConstraintSet Constraints;
653 const ErrnoConstraintBase &ErrnoConstraint;
657 SummaryCase(ConstraintSet &&Constraints,
const ErrnoConstraintBase &ErrnoC,
659 : Constraints(std::move(Constraints)), ErrnoConstraint(ErrnoC),
662 SummaryCase(
const ConstraintSet &Constraints,
663 const ErrnoConstraintBase &ErrnoC, StringRef Note)
664 : Constraints(Constraints), ErrnoConstraint(ErrnoC), Note(Note) {}
666 const ConstraintSet &getConstraints()
const {
return Constraints; }
667 const ErrnoConstraintBase &getErrnoConstraint()
const {
668 return ErrnoConstraint;
670 StringRef getNote()
const {
return Note; }
673 using ArgTypes = ArrayRef<std::optional<QualType>>;
674 using RetType = std::optional<QualType>;
678 const QualType Irrelevant{};
679 bool static isIrrelevant(QualType
T) {
return T.isNull(); }
686 using ArgQualTypes = std::vector<QualType>;
690 bool Invalid =
false;
695 Signature(ArgTypes ArgTys, RetType RetTy) {
696 for (std::optional<QualType> Arg : ArgTys) {
701 assertArgTypeSuitableForSignature(*Arg);
702 this->ArgTys.push_back(*Arg);
709 assertRetTypeSuitableForSignature(*RetTy);
710 this->RetTy = *RetTy;
714 bool isInvalid()
const {
return Invalid; }
715 bool matches(
const FunctionDecl *FD)
const;
718 static void assertArgTypeSuitableForSignature(QualType
T) {
720 "We should have no void types in the spec");
721 assert((
T.isNull() ||
T.isCanonical()) &&
722 "We should only have canonical types in the spec");
724 static void assertRetTypeSuitableForSignature(QualType
T) {
725 assert((
T.isNull() ||
T.isCanonical()) &&
726 "We should only have canonical types in the spec");
730 static QualType getArgType(
const FunctionDecl *FD, ArgNo ArgN) {
731 assert(FD &&
"Function must be set");
732 QualType
T = (ArgN == Ret)
738 using SummaryCases = std::vector<SummaryCase>;
757 const InvalidationKind InvalidationKd;
759 ConstraintSet ArgConstraints;
763 const FunctionDecl *FD =
nullptr;
766 Summary(InvalidationKind InvalidationKd) : InvalidationKd(InvalidationKd) {}
768 Summary &Case(ConstraintSet &&CS,
const ErrnoConstraintBase &ErrnoC,
769 StringRef
Note =
"") {
770 Cases.push_back(SummaryCase(std::move(CS), ErrnoC,
Note));
773 Summary &Case(
const ConstraintSet &CS,
const ErrnoConstraintBase &ErrnoC,
774 StringRef
Note =
"") {
775 Cases.push_back(SummaryCase(CS, ErrnoC,
Note));
778 Summary &ArgConstraint(ValueConstraintPtr VC) {
779 assert(VC->getArgNo() != Ret &&
780 "Arg constraint should not refer to the return value");
781 ArgConstraints.push_back(VC);
785 InvalidationKind getInvalidationKd()
const {
return InvalidationKd; }
786 const SummaryCases &getCases()
const {
return Cases; }
787 const ConstraintSet &getArgConstraints()
const {
return ArgConstraints; }
789 QualType getArgType(ArgNo ArgN)
const {
790 return StdLibraryFunctionsChecker::getArgType(FD, ArgN);
795 bool matchesAndSet(
const Signature &Sign,
const FunctionDecl *FD) {
796 bool Result = Sign.matches(FD) && validateByConstraints(FD);
798 assert(!this->FD &&
"FD must not be set more than once");
807 bool validateByConstraints(
const FunctionDecl *FD)
const {
808 for (
const SummaryCase &Case : Cases)
809 for (
const ValueConstraintPtr &Constraint : Case.getConstraints())
810 if (!Constraint->checkValidity(FD))
812 for (
const ValueConstraintPtr &Constraint : ArgConstraints)
813 if (!Constraint->checkValidity(FD))
821 using FunctionSummaryMapType = llvm::DenseMap<const FunctionDecl *, Summary>;
822 mutable FunctionSummaryMapType FunctionSummaryMap;
824 const BugType BT_InvalidArg{
this,
"Function call with invalid argument"};
825 mutable bool SummariesInitialized =
false;
827 static SVal getArgSVal(
const CallEvent &
Call, ArgNo ArgN) {
828 return ArgN == Ret ?
Call.getReturnValue() :
Call.getArgSVal(ArgN);
831 assert(
Call.getDecl() &&
832 "Call was found by a summary, should have declaration");
837 void checkPreCall(
const CallEvent &
Call, CheckerContext &
C)
const;
838 void checkPostCall(
const CallEvent &
Call, CheckerContext &
C)
const;
839 bool evalCall(
const CallEvent &
Call, CheckerContext &
C)
const;
841 CheckerNameRef CheckName;
842 bool AddTestFunctions =
false;
844 bool DisplayLoadedSummaries =
false;
845 bool ModelPOSIX =
false;
846 bool ShouldAssumeControlledEnvironment =
false;
849 std::optional<Summary> findFunctionSummary(
const FunctionDecl *FD,
850 CheckerContext &
C)
const;
851 std::optional<Summary> findFunctionSummary(
const CallEvent &
Call,
852 CheckerContext &
C)
const;
854 void initFunctionSummaries(CheckerContext &
C)
const;
856 void reportBug(
const CallEvent &
Call, ExplodedNode *N,
857 const ValueConstraint *VC,
const ValueConstraint *NegatedVC,
858 const Summary &Summary, CheckerContext &
C)
const {
859 assert(
Call.getDecl() &&
860 "Function found in summary must have a declaration available");
861 SmallString<256> Msg;
862 llvm::raw_svector_ostream MsgOs(Msg);
865 printArgDesc(VC->getArgNo(), MsgOs);
868 NegatedVC->describeArgumentValue(
Call, N->
getState(), Summary, MsgOs);
872 MsgOs <<
"is out of the accepted range; It ";
873 VC->describe(ValueConstraint::Violation,
Call,
C.getState(), Summary,
875 Msg[0] = toupper(Msg[0]);
876 auto R = std::make_unique<PathSensitiveBugReport>(BT_InvalidArg, Msg, N);
878 for (ArgNo ArgN : VC->getArgsToTrack()) {
880 R->markInteresting(
Call.getArgSVal(ArgN));
882 R->addRange(
Call.getArgSourceRange(ArgN));
885 C.emitReport(std::move(R));
893 const NoErrnoConstraint ErrnoUnchanged{};
894 const ResetErrnoConstraint ErrnoIrrelevant{};
895 const ErrnoMustBeCheckedConstraint ErrnoMustBeChecked{};
896 const SuccessErrnoConstraint ErrnoMustNotBeChecked{};
897 const FailureErrnoConstraint ErrnoNEZeroIrrelevant{};
900int StdLibraryFunctionsChecker::ErrnoConstraintBase::Tag = 0;
902const StdLibraryFunctionsChecker::ArgNo StdLibraryFunctionsChecker::Ret =
903 std::numeric_limits<ArgNo>::max();
913void StdLibraryFunctionsChecker::printArgDesc(
914 StdLibraryFunctionsChecker::ArgNo ArgN, llvm::raw_ostream &Out) {
915 Out << std::to_string(ArgN + 1);
916 Out << llvm::getOrdinalSuffix(ArgN + 1);
920void StdLibraryFunctionsChecker::printArgValueInfo(ArgNo ArgN,
922 const CallEvent &
Call,
923 llvm::raw_ostream &Out) {
924 if (
const llvm::APSInt *Val =
925 State->getStateManager().getSValBuilder().getKnownValue(
926 State, getArgSVal(
Call, ArgN)))
927 Out <<
" (which is " << *Val <<
")";
930void StdLibraryFunctionsChecker::appendInsideRangeDesc(llvm::APSInt RMin,
933 BasicValueFactory &BVF,
934 llvm::raw_ostream &Out) {
935 if (RMin.isZero() && RMax.isZero())
937 else if (RMin == RMax)
943 Out <<
"<= " << RMax;
948 Out <<
">= " << RMin;
949 }
else if (RMin.isNegative() == RMax.isNegative() &&
950 RMin.getLimitedValue() == RMax.getLimitedValue() - 1) {
951 Out << RMin <<
" or " << RMax;
953 Out <<
"between " << RMin <<
" and " << RMax;
957void StdLibraryFunctionsChecker::appendOutOfRangeDesc(llvm::APSInt RMin,
960 BasicValueFactory &BVF,
961 llvm::raw_ostream &Out) {
962 if (RMin.isZero() && RMax.isZero())
964 else if (RMin == RMax) {
965 Out <<
"not equal to " << RMin;
976 }
else if (RMin.isNegative() == RMax.isNegative() &&
977 RMin.getLimitedValue() == RMax.getLimitedValue() - 1) {
978 Out <<
"not " << RMin <<
" and not " << RMax;
980 Out <<
"not between " << RMin <<
" and " << RMax;
984void StdLibraryFunctionsChecker::RangeConstraint::applyOnWithinRange(
985 BasicValueFactory &BVF, QualType ArgT,
const RangeApplyFunction &F)
const {
989 for (
auto [Start, End] : getRanges()) {
990 const llvm::APSInt &
Min = BVF.getValue(Start, ArgT);
991 const llvm::APSInt &
Max = BVF.getValue(End, ArgT);
998void StdLibraryFunctionsChecker::RangeConstraint::applyOnOutOfRange(
999 BasicValueFactory &BVF, QualType ArgT,
const RangeApplyFunction &F)
const {
1003 const IntRangeVector &R = getRanges();
1004 size_t E = R.size();
1006 const llvm::APSInt &MinusInf = BVF.
getMinValue(ArgT);
1007 const llvm::APSInt &PlusInf = BVF.
getMaxValue(ArgT);
1009 const llvm::APSInt &RangeLeft = BVF.getValue(R[0].first - 1ULL, ArgT);
1010 const llvm::APSInt &RangeRight = BVF.getValue(R[E - 1].second + 1ULL, ArgT);
1013 for (
size_t I = 1; I != E; ++I) {
1014 const llvm::APSInt &
Min = BVF.getValue(R[I - 1].second + 1ULL, ArgT);
1015 const llvm::APSInt &
Max = BVF.getValue(R[I].first - 1ULL, ArgT);
1022 if (RangeLeft != PlusInf) {
1023 assert(MinusInf <= RangeLeft);
1024 if (!F(MinusInf, RangeLeft))
1028 if (RangeRight != MinusInf) {
1029 assert(RangeRight <= PlusInf);
1030 if (!F(RangeRight, PlusInf))
1037 CheckerContext &
C)
const {
1038 ConstraintManager &CM =
C.getConstraintManager();
1039 SVal
V = getArgSVal(
Call, getArgNo());
1040 QualType
T = Summary.getArgType(getArgNo());
1042 if (
auto N =
V.getAs<NonLoc>()) {
1043 auto ExcludeRangeFromArg = [&](
const llvm::APSInt &
Min,
1044 const llvm::APSInt &
Max) {
1046 return static_cast<bool>(State);
1050 applyOnRange(negateKind(Kind),
C.getSValBuilder().getBasicValueFactory(),
T,
1051 ExcludeRangeFromArg);
1057void StdLibraryFunctionsChecker::RangeConstraint::describe(
1059 const Summary &Summary, llvm::raw_ostream &Out)
const {
1061 BasicValueFactory &BVF = getBVF(State);
1062 QualType
T = Summary.getArgType(getArgNo());
1064 Out << ((DK == Violation) ?
"should be " :
"is ");
1065 if (!Description.empty()) {
1068 unsigned I = Ranges.size();
1069 if (Kind == WithinRange) {
1070 for (
const std::pair<RangeInt, RangeInt> &R : Ranges) {
1071 appendInsideRangeDesc(BVF.getValue(R.first,
T),
1072 BVF.getValue(R.second,
T),
T, BVF, Out);
1077 for (
const std::pair<RangeInt, RangeInt> &R : Ranges) {
1078 appendOutOfRangeDesc(BVF.getValue(R.first,
T),
1079 BVF.getValue(R.second,
T),
T, BVF, Out);
1087bool StdLibraryFunctionsChecker::RangeConstraint::describeArgumentValue(
1089 llvm::raw_ostream &Out)
const {
1090 unsigned int NRanges = 0;
1091 bool HaveAllRanges =
true;
1093 ProgramStateManager &Mgr = State->getStateManager();
1096 SVal
V = getArgSVal(
Call, getArgNo());
1098 if (
auto N =
V.getAs<NonLoc>()) {
1099 if (
const llvm::APSInt *Int = N->getAsInteger()) {
1104 QualType
T = Summary.getArgType(getArgNo());
1105 SmallString<128> MoreInfo;
1106 llvm::raw_svector_ostream MoreInfoOs(MoreInfo);
1107 auto ApplyF = [&](
const llvm::APSInt &
Min,
const llvm::APSInt &
Max) {
1110 MoreInfoOs <<
" or ";
1111 appendInsideRangeDesc(
Min,
Max,
T, BVF, MoreInfoOs);
1114 HaveAllRanges =
false;
1119 applyOnRange(Kind, BVF,
T, ApplyF);
1120 assert(NRanges > 0);
1121 if (!HaveAllRanges || NRanges == 1) {
1130ProgramStateRef StdLibraryFunctionsChecker::ComparisonConstraint::apply(
1132 CheckerContext &
C)
const {
1134 ProgramStateManager &Mgr = State->getStateManager();
1137 QualType
T = Summary.getArgType(getArgNo());
1138 SVal
V = getArgSVal(
Call, getArgNo());
1141 ArgNo OtherArg = getOtherArgNo();
1142 SVal OtherV = getArgSVal(
Call, OtherArg);
1143 QualType OtherT = Summary.getArgType(OtherArg);
1145 OtherV = SVB.
evalCast(OtherV,
T, OtherT);
1146 if (
auto CompV = SVB.
evalBinOp(State, Op,
V, OtherV, CondT)
1147 .
getAs<DefinedOrUnknownSVal>())
1148 State = State->assume(*CompV,
true);
1154 CheckerContext &
C)
const {
1155 SVal
V = getArgSVal(
Call, getArgNo());
1159 DefinedOrUnknownSVal L =
V.castAs<DefinedOrUnknownSVal>();
1163 return State->assume(L, CannotBeNull);
1166void StdLibraryFunctionsChecker::NullnessConstraint::describe(
1168 const Summary &Summary, llvm::raw_ostream &Out)
const {
1169 assert(CannotBeNull &&
1170 "'describe' is not implemented when the value must be NULL");
1171 if (DK == Violation)
1172 Out <<
"should not be NULL";
1174 Out <<
"is not NULL";
1177bool StdLibraryFunctionsChecker::NullnessConstraint::describeArgumentValue(
1179 llvm::raw_ostream &Out)
const {
1180 assert(!CannotBeNull &&
"'describeArgumentValue' is not implemented when the "
1181 "value must be non-NULL");
1186ProgramStateRef StdLibraryFunctionsChecker::BufferNullnessConstraint::apply(
1188 CheckerContext &
C)
const {
1189 SVal
V = getArgSVal(
Call, getArgNo());
1192 DefinedOrUnknownSVal L =
V.
castAs<DefinedOrUnknownSVal>();
1196 std::optional<DefinedOrUnknownSVal> SizeArg1 =
1197 getArgSVal(
Call, SizeArg1N).getAs<DefinedOrUnknownSVal>();
1198 std::optional<DefinedOrUnknownSVal> SizeArg2;
1200 SizeArg2 = getArgSVal(
Call, *SizeArg2N).getAs<DefinedOrUnknownSVal>();
1202 auto IsArgZero = [State](std::optional<DefinedOrUnknownSVal> Val) {
1209 if (IsArgZero(SizeArg1) || IsArgZero(SizeArg2))
1212 return State->assume(L, CannotBeNull);
1215void StdLibraryFunctionsChecker::BufferNullnessConstraint::describe(
1217 const Summary &Summary, llvm::raw_ostream &Out)
const {
1218 assert(CannotBeNull &&
1219 "'describe' is not implemented when the buffer must be NULL");
1220 if (DK == Violation)
1221 Out <<
"should not be NULL";
1223 Out <<
"is not NULL";
1226bool StdLibraryFunctionsChecker::BufferNullnessConstraint::
1228 const Summary &Summary,
1229 llvm::raw_ostream &Out)
const {
1230 assert(!CannotBeNull &&
"'describeArgumentValue' is not implemented when the "
1231 "buffer must be non-NULL");
1236ProgramStateRef StdLibraryFunctionsChecker::BufferSizeConstraint::apply(
1238 CheckerContext &
C)
const {
1239 SValBuilder &SvalBuilder =
C.getSValBuilder();
1241 SVal BufV = getArgSVal(
Call, getArgNo());
1244 const SVal SizeV = [
this, &State, &
Call, &Summary, &SvalBuilder]() {
1246 return SVal(SvalBuilder.
makeIntVal(*ConcreteSize));
1248 assert(SizeArgN &&
"The constraint must be either a concrete value or "
1249 "encoded in an argument.");
1251 SVal SizeV = getArgSVal(
Call, *SizeArgN);
1253 if (SizeMultiplierArgN) {
1254 SVal SizeMulV = getArgSVal(
Call, *SizeMultiplierArgN);
1255 SizeV = SvalBuilder.
evalBinOp(State, BO_Mul, SizeV, SizeMulV,
1256 Summary.getArgType(*SizeArgN));
1264 SVal Feasible = SvalBuilder.
evalBinOp(State, Op, SizeV, BufDynSize,
1266 if (
auto F = Feasible.
getAs<DefinedOrUnknownSVal>())
1267 return State->assume(*F,
true);
1275 llvm_unreachable(
"Size argument or the dynamic size is Undefined");
1278void StdLibraryFunctionsChecker::BufferSizeConstraint::describe(
1280 const Summary &Summary, llvm::raw_ostream &Out)
const {
1281 Out << ((DK == Violation) ?
"should be " :
"is ");
1282 Out <<
"a buffer with size equal to or greater than ";
1284 Out << *ConcreteSize;
1285 }
else if (SizeArgN) {
1286 Out <<
"the value of the ";
1287 printArgDesc(*SizeArgN, Out);
1288 printArgValueInfo(*SizeArgN, State,
Call, Out);
1289 if (SizeMultiplierArgN) {
1290 Out <<
" times the ";
1291 printArgDesc(*SizeMultiplierArgN, Out);
1292 printArgValueInfo(*SizeMultiplierArgN, State,
Call, Out);
1297bool StdLibraryFunctionsChecker::BufferSizeConstraint::describeArgumentValue(
1299 llvm::raw_ostream &Out)
const {
1300 SVal BufV = getArgSVal(
Call, getArgNo());
1302 if (
const llvm::APSInt *Val =
1303 State->getStateManager().getSValBuilder().getKnownValue(State,
1305 Out <<
"is a buffer with size " << *Val;
1311void StdLibraryFunctionsChecker::checkPreCall(
const CallEvent &
Call,
1312 CheckerContext &
C)
const {
1313 std::optional<Summary> FoundSummary = findFunctionSummary(
Call,
C);
1317 const Summary &Summary = *FoundSummary;
1321 ExplodedNode *NewNode =
C.getPredecessor();
1322 for (
const ValueConstraintPtr &Constraint : Summary.getArgConstraints()) {
1323 ValueConstraintPtr NegatedConstraint = Constraint->negate();
1326 NegatedConstraint->apply(NewState,
Call, Summary,
C);
1328 if (FailureSt && !SuccessSt) {
1329 if (ExplodedNode *N =
C.generateErrorNode(State, NewNode))
1330 reportBug(
Call, N, Constraint.get(), NegatedConstraint.get(), Summary,
1339 NewState = SuccessSt;
1340 if (NewState != State) {
1341 SmallString<128> Msg;
1342 llvm::raw_svector_ostream Os(Msg);
1343 Os <<
"Assuming that the ";
1344 printArgDesc(Constraint->getArgNo(), Os);
1348 Constraint->describe(ValueConstraint::Assumption,
Call, NewState, Summary,
1350 const auto ArgSVal =
Call.getArgSVal(Constraint->getArgNo());
1351 NewNode =
C.addTransition(
1353 C.getNoteTag([Msg = std::move(Msg), ArgSVal](
1354 PathSensitiveBugReport &BR, llvm::raw_ostream &
OS) {
1355 if (BR.isInteresting(ArgSVal))
1362void StdLibraryFunctionsChecker::checkPostCall(
const CallEvent &
Call,
1363 CheckerContext &
C)
const {
1364 std::optional<Summary> FoundSummary = findFunctionSummary(
Call,
C);
1369 const Summary &Summary = *FoundSummary;
1371 ExplodedNode *Node =
C.getPredecessor();
1374 for (
const SummaryCase &Case : Summary.getCases()) {
1376 for (
const ValueConstraintPtr &Constraint : Case.getConstraints()) {
1377 NewState = Constraint->apply(NewState,
Call, Summary,
C);
1383 NewState = Case.getErrnoConstraint().apply(NewState,
Call, Summary,
C);
1394 ExplodedNode *Pred = Node;
1395 DeclarationName FunctionName =
1398 std::string ErrnoNote = Case.getErrnoConstraint().describe(
C);
1399 std::string CaseNote;
1400 if (Case.getNote().empty()) {
1401 if (!ErrnoNote.empty())
1403 llvm::formatv(
"After calling '{0}' {1}", FunctionName, ErrnoNote);
1408 llvm::formatv(
false, Case.getNote().str().c_str(), FunctionName);
1410 const SVal RV =
Call.getReturnValue();
1412 if (Summary.getInvalidationKd() == EvalCallAsPure) {
1415 if (!CaseNote.empty()) {
1416 const NoteTag *
Tag =
C.getNoteTag(
1417 [Node, CaseNote, RV](PathSensitiveBugReport &BR) -> std::string {
1432 Pred =
C.addTransition(NewState, Pred, Tag);
1435 if (!CaseNote.empty() || !ErrnoNote.empty()) {
1436 const NoteTag *
Tag =
1437 C.getNoteTag([CaseNote, ErrnoNote,
1438 RV](PathSensitiveBugReport &BR) -> std::string {
1445 std::optional<Loc> ErrnoLoc =
1447 bool ErrnoImportant = !ErrnoNote.empty() && ErrnoLoc &&
1449 if (ErrnoImportant) {
1451 if (CaseNote.empty())
1453 return llvm::formatv(
"{0}; {1}", CaseNote, ErrnoNote);
1460 Pred =
C.addTransition(NewState, Pred, Tag);
1465 if (Pred == Node && NewState != State)
1466 C.addTransition(NewState);
1470bool StdLibraryFunctionsChecker::evalCall(
const CallEvent &
Call,
1471 CheckerContext &
C)
const {
1472 std::optional<Summary> FoundSummary = findFunctionSummary(
Call,
C);
1476 const Summary &Summary = *FoundSummary;
1477 switch (Summary.getInvalidationKd()) {
1478 case EvalCallAsPure: {
1480 const LocationContext *LC =
C.getLocationContext();
1482 SVal
V =
C.getSValBuilder().conjureSymbolVal(
Call,
C.blockCount());
1483 State = State->BindExpr(CE, LC,
V);
1485 C.addTransition(State);
1494 llvm_unreachable(
"Unknown invalidation kind!");
1497bool StdLibraryFunctionsChecker::Signature::matches(
1498 const FunctionDecl *FD)
const {
1511 auto RemoveRestrict = [&FD](QualType
T) {
1513 T.removeLocalRestrict();
1518 if (!isIrrelevant(RetTy)) {
1520 if (RetTy != FDRetTy)
1525 for (
auto [Idx, ArgTy] : llvm::enumerate(ArgTys)) {
1526 if (isIrrelevant(ArgTy))
1530 if (ArgTy != FDArgTy)
1537std::optional<StdLibraryFunctionsChecker::Summary>
1538StdLibraryFunctionsChecker::findFunctionSummary(
const FunctionDecl *FD,
1539 CheckerContext &
C)
const {
1541 return std::nullopt;
1543 initFunctionSummaries(
C);
1546 if (FSMI == FunctionSummaryMap.end())
1547 return std::nullopt;
1548 return FSMI->second;
1551std::optional<StdLibraryFunctionsChecker::Summary>
1552StdLibraryFunctionsChecker::findFunctionSummary(
const CallEvent &
Call,
1553 CheckerContext &
C)
const {
1554 const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(
Call.getDecl());
1556 return std::nullopt;
1557 return findFunctionSummary(FD,
C);
1560void StdLibraryFunctionsChecker::initFunctionSummaries(
1561 CheckerContext &
C)
const {
1562 if (SummariesInitialized)
1564 SummariesInitialized =
true;
1566 SValBuilder &SVB =
C.getSValBuilder();
1569 Preprocessor &PP =
C.getPreprocessor();
1573 const ASTContext &ACtx;
1576 LookupType(
const ASTContext &ACtx) : ACtx(ACtx) {}
1579 std::optional<QualType> operator()(StringRef Name) {
1580 IdentifierInfo &II = ACtx.
Idents.
get(Name);
1582 if (LookupRes.empty())
1583 return std::nullopt;
1590 for (Decl *D : LookupRes)
1591 if (
auto *TD = dyn_cast<TypedefNameDecl>(D))
1598 for (Decl *D : LookupRes)
1599 if (
auto *TD = dyn_cast<TypeDecl>(D))
1601 return std::nullopt;
1607 class GetRestrictTy {
1608 const ASTContext &ACtx;
1611 GetRestrictTy(
const ASTContext &ACtx) : ACtx(ACtx) {}
1612 QualType operator()(QualType Ty) {
1615 std::optional<QualType> operator()(std::optional<QualType> Ty) {
1617 return operator()(*Ty);
1618 return std::nullopt;
1620 } getRestrictTy(ACtx);
1621 class GetPointerTy {
1622 const ASTContext &ACtx;
1625 GetPointerTy(
const ASTContext &ACtx) : ACtx(ACtx) {}
1626 QualType operator()(QualType Ty) {
return ACtx.
getPointerType(Ty); }
1627 std::optional<QualType> operator()(std::optional<QualType> Ty) {
1629 return operator()(*Ty);
1630 return std::nullopt;
1632 } getPointerTy(ACtx);
1635 std::optional<QualType> operator()(std::optional<QualType> Ty) {
1636 return Ty ? std::optional<QualType>(Ty->withConst()) : std::nullopt;
1638 QualType operator()(QualType Ty) {
return Ty.
withConst(); }
1641 BasicValueFactory &BVF;
1644 GetMaxValue(BasicValueFactory &BVF) : BVF(BVF) {}
1645 std::optional<RangeInt> operator()(QualType Ty) {
1648 std::optional<RangeInt> operator()(std::optional<QualType> Ty) {
1650 return operator()(*Ty);
1652 return std::nullopt;
1663 const QualType VoidTy = ACtx.
VoidTy;
1664 const QualType CharTy = ACtx.
CharTy;
1665 const QualType WCharTy = ACtx.
WCharTy;
1666 const QualType IntTy = ACtx.
IntTy;
1668 const QualType LongTy = ACtx.
LongTy;
1671 const QualType VoidPtrTy = getPointerTy(VoidTy);
1672 const QualType IntPtrTy = getPointerTy(IntTy);
1673 const QualType UnsignedIntPtrTy =
1674 getPointerTy(UnsignedIntTy);
1675 const QualType VoidPtrRestrictTy = getRestrictTy(VoidPtrTy);
1676 const QualType ConstVoidPtrTy =
1677 getPointerTy(getConstTy(VoidTy));
1678 const QualType CharPtrTy = getPointerTy(CharTy);
1679 const QualType CharPtrRestrictTy = getRestrictTy(CharPtrTy);
1680 const QualType ConstCharPtrTy =
1681 getPointerTy(getConstTy(CharTy));
1682 const QualType ConstCharPtrRestrictTy = getRestrictTy(ConstCharPtrTy);
1683 const QualType Wchar_tPtrTy = getPointerTy(WCharTy);
1684 const QualType ConstWchar_tPtrTy =
1685 getPointerTy(getConstTy(WCharTy));
1686 const QualType ConstVoidPtrRestrictTy = getRestrictTy(ConstVoidPtrTy);
1687 const QualType SizePtrTy = getPointerTy(SizeTyCanonTy);
1688 const QualType SizePtrRestrictTy = getRestrictTy(SizePtrTy);
1690 const RangeInt IntMax = BVF.
getMaxValue(IntTy)->getLimitedValue();
1691 const RangeInt UnsignedIntMax =
1692 BVF.
getMaxValue(UnsignedIntTy)->getLimitedValue();
1693 const RangeInt LongMax = BVF.
getMaxValue(LongTy)->getLimitedValue();
1694 const RangeInt SizeMax = BVF.
getMaxValue(SizeTyCanonTy)->getLimitedValue();
1702 const RangeInt UCharRangeMax =
1712 struct AddToFunctionSummaryMap {
1713 const ASTContext &ACtx;
1714 FunctionSummaryMapType ⤅
1715 bool DisplayLoadedSummaries;
1716 AddToFunctionSummaryMap(
const ASTContext &ACtx, FunctionSummaryMapType &FSM,
1717 bool DisplayLoadedSummaries)
1718 : ACtx(ACtx), Map(FSM), DisplayLoadedSummaries(DisplayLoadedSummaries) {
1726 bool operator()(StringRef Name, Signature Sign, Summary Sum) {
1727 if (Sign.isInvalid())
1729 IdentifierInfo &II = ACtx.
Idents.
get(Name);
1731 if (LookupRes.empty())
1733 for (Decl *D : LookupRes) {
1734 if (
auto *FD = dyn_cast<FunctionDecl>(D)) {
1735 if (Sum.matchesAndSet(Sign, FD)) {
1737 assert(Res.second &&
"Function already has a summary set!");
1739 if (DisplayLoadedSummaries) {
1740 llvm::errs() <<
"Loaded summary for: ";
1741 FD->
print(llvm::errs());
1742 llvm::errs() <<
"\n";
1752 void operator()(ArrayRef<StringRef> Names, Signature Sign, Summary Sum) {
1753 for (StringRef Name : Names)
1754 operator()(Name, Sign, Sum);
1756 } addToFunctionSummaryMap(ACtx, FunctionSummaryMap, DisplayLoadedSummaries);
1759 auto ArgumentCondition = [](ArgNo ArgN, RangeKind
Kind, IntRangeVector Ranges,
1760 StringRef Desc =
"") {
1761 return std::make_shared<RangeConstraint>(ArgN, Kind, Ranges, Desc);
1763 auto BufferSize = [](
auto... Args) {
1764 return std::make_shared<BufferSizeConstraint>(Args...);
1767 auto operator()(RangeKind Kind, IntRangeVector Ranges) {
1768 return std::make_shared<RangeConstraint>(Ret, Kind, Ranges);
1771 return std::make_shared<ComparisonConstraint>(Ret, Op, OtherArgN);
1773 } ReturnValueCondition;
1775 auto operator()(RangeInt
b, RangeInt e) {
1776 return IntRangeVector{std::pair<RangeInt, RangeInt>{
b, e}};
1778 auto operator()(RangeInt
b, std::optional<RangeInt> e) {
1780 return IntRangeVector{std::pair<RangeInt, RangeInt>{
b, *e}};
1781 return IntRangeVector{};
1783 auto operator()(std::pair<RangeInt, RangeInt> i0,
1784 std::pair<RangeInt, std::optional<RangeInt>> i1) {
1786 return IntRangeVector{i0, {i1.first, *(i1.second)}};
1787 return IntRangeVector{i0};
1790 auto SingleValue = [](RangeInt v) {
1791 return IntRangeVector{std::pair<RangeInt, RangeInt>{v, v}};
1793 auto LessThanOrEq = BO_LE;
1794 auto NotNull = [&](ArgNo ArgN) {
1795 return std::make_shared<NullnessConstraint>(ArgN);
1797 auto IsNull = [&](ArgNo ArgN) {
1798 return std::make_shared<NullnessConstraint>(ArgN,
false);
1800 auto NotNullBuffer = [&](ArgNo ArgN, ArgNo SizeArg1N,
1801 std::optional<ArgNo> SizeArg2N = std::nullopt) {
1802 return std::make_shared<BufferNullnessConstraint>(ArgN, SizeArg1N,
1806 std::optional<QualType> FileTy = lookupTy(
"FILE");
1807 std::optional<QualType> FilePtrTy = getPointerTy(FileTy);
1808 std::optional<QualType> FilePtrRestrictTy = getRestrictTy(FilePtrTy);
1810 std::optional<QualType> FPosTTy = lookupTy(
"fpos_t");
1811 std::optional<QualType> FPosTPtrTy = getPointerTy(FPosTTy);
1812 std::optional<QualType> ConstFPosTPtrTy = getPointerTy(getConstTy(FPosTTy));
1813 std::optional<QualType> FPosTPtrRestrictTy = getRestrictTy(FPosTPtrTy);
1815 constexpr llvm::StringLiteral GenericSuccessMsg(
1816 "Assuming that '{0}' is successful");
1817 constexpr llvm::StringLiteral GenericFailureMsg(
"Assuming that '{0}' fails");
1834 addToFunctionSummaryMap(
1835 "isalnum", Signature(ArgTypes{IntTy}, RetType{IntTy}),
1836 Summary(EvalCallAsPure)
1838 .Case({ArgumentCondition(0U, WithinRange,
1839 {{
'0',
'9'}, {
'A',
'Z'}, {
'a',
'z'}}),
1840 ReturnValueCondition(OutOfRange, SingleValue(0))},
1841 ErrnoIrrelevant,
"Assuming the character is alphanumeric")
1845 .Case({ArgumentCondition(0U, WithinRange, {{128, UCharRangeMax}})},
1850 {{
'0',
'9'}, {
'A',
'Z'}, {
'a',
'z'}, {128, UCharRangeMax}}),
1851 ReturnValueCondition(WithinRange, SingleValue(0))},
1852 ErrnoIrrelevant,
"Assuming the character is non-alphanumeric")
1853 .ArgConstraint(ArgumentCondition(0U, WithinRange,
1854 {{EOFv, EOFv}, {0, UCharRangeMax}},
1855 "an unsigned char value or EOF")));
1856 addToFunctionSummaryMap(
1857 "isalpha", Signature(ArgTypes{IntTy}, RetType{IntTy}),
1858 Summary(EvalCallAsPure)
1859 .Case({ArgumentCondition(0U, WithinRange, {{
'A',
'Z'}, {
'a',
'z'}}),
1860 ReturnValueCondition(OutOfRange, SingleValue(0))},
1861 ErrnoIrrelevant,
"Assuming the character is alphabetical")
1863 .Case({ArgumentCondition(0U, WithinRange, {{128, UCharRangeMax}})},
1865 .Case({ArgumentCondition(
1867 {{
'A',
'Z'}, {
'a',
'z'}, {128, UCharRangeMax}}),
1868 ReturnValueCondition(WithinRange, SingleValue(0))},
1869 ErrnoIrrelevant,
"Assuming the character is non-alphabetical"));
1870 addToFunctionSummaryMap(
1871 "isascii", Signature(ArgTypes{IntTy}, RetType{IntTy}),
1872 Summary(EvalCallAsPure)
1873 .Case({ArgumentCondition(0U, WithinRange,
Range(0, 127)),
1874 ReturnValueCondition(OutOfRange, SingleValue(0))},
1875 ErrnoIrrelevant,
"Assuming the character is an ASCII character")
1876 .Case({ArgumentCondition(0U, OutOfRange,
Range(0, 127)),
1877 ReturnValueCondition(WithinRange, SingleValue(0))},
1879 "Assuming the character is not an ASCII character"));
1880 addToFunctionSummaryMap(
1881 "isblank", Signature(ArgTypes{IntTy}, RetType{IntTy}),
1882 Summary(EvalCallAsPure)
1883 .Case({ArgumentCondition(0U, WithinRange, {{
'\t',
'\t'}, {
' ',
' '}}),
1884 ReturnValueCondition(OutOfRange, SingleValue(0))},
1885 ErrnoIrrelevant,
"Assuming the character is a blank character")
1886 .Case({ArgumentCondition(0U, OutOfRange, {{
'\t',
'\t'}, {
' ',
' '}}),
1887 ReturnValueCondition(WithinRange, SingleValue(0))},
1889 "Assuming the character is not a blank character"));
1890 addToFunctionSummaryMap(
1891 "iscntrl", Signature(ArgTypes{IntTy}, RetType{IntTy}),
1892 Summary(EvalCallAsPure)
1893 .Case({ArgumentCondition(0U, WithinRange, {{0, 32}, {127, 127}}),
1894 ReturnValueCondition(OutOfRange, SingleValue(0))},
1896 "Assuming the character is a control character")
1897 .Case({ArgumentCondition(0U, OutOfRange, {{0, 32}, {127, 127}}),
1898 ReturnValueCondition(WithinRange, SingleValue(0))},
1900 "Assuming the character is not a control character"));
1901 addToFunctionSummaryMap(
1902 "isdigit", Signature(ArgTypes{IntTy}, RetType{IntTy}),
1903 Summary(EvalCallAsPure)
1904 .Case({ArgumentCondition(0U, WithinRange,
Range(
'0',
'9')),
1905 ReturnValueCondition(OutOfRange, SingleValue(0))},
1906 ErrnoIrrelevant,
"Assuming the character is a digit")
1907 .Case({ArgumentCondition(0U, OutOfRange,
Range(
'0',
'9')),
1908 ReturnValueCondition(WithinRange, SingleValue(0))},
1909 ErrnoIrrelevant,
"Assuming the character is not a digit"));
1910 addToFunctionSummaryMap(
1911 "isgraph", Signature(ArgTypes{IntTy}, RetType{IntTy}),
1912 Summary(EvalCallAsPure)
1913 .Case({ArgumentCondition(0U, WithinRange,
Range(33, 126)),
1914 ReturnValueCondition(OutOfRange, SingleValue(0))},
1916 "Assuming the character has graphical representation")
1918 {ArgumentCondition(0U, OutOfRange,
Range(33, 126)),
1919 ReturnValueCondition(WithinRange, SingleValue(0))},
1921 "Assuming the character does not have graphical representation"));
1922 addToFunctionSummaryMap(
1923 "islower", Signature(ArgTypes{IntTy}, RetType{IntTy}),
1924 Summary(EvalCallAsPure)
1926 .Case({ArgumentCondition(0U, WithinRange,
Range(
'a',
'z')),
1927 ReturnValueCondition(OutOfRange, SingleValue(0))},
1928 ErrnoIrrelevant,
"Assuming the character is a lowercase letter")
1930 .Case({ArgumentCondition(0U, WithinRange,
Range(0, 127)),
1931 ArgumentCondition(0U, OutOfRange,
Range(
'a',
'z')),
1932 ReturnValueCondition(WithinRange, SingleValue(0))},
1934 "Assuming the character is not a lowercase letter")
1936 .Case({ArgumentCondition(0U, WithinRange, {{128, UCharRangeMax}})},
1939 .Case({ArgumentCondition(0U, OutOfRange,
Range(0, UCharRangeMax)),
1940 ReturnValueCondition(WithinRange, SingleValue(0))},
1942 addToFunctionSummaryMap(
1943 "isprint", Signature(ArgTypes{IntTy}, RetType{IntTy}),
1944 Summary(EvalCallAsPure)
1945 .Case({ArgumentCondition(0U, WithinRange,
Range(32, 126)),
1946 ReturnValueCondition(OutOfRange, SingleValue(0))},
1947 ErrnoIrrelevant,
"Assuming the character is printable")
1948 .Case({ArgumentCondition(0U, OutOfRange,
Range(32, 126)),
1949 ReturnValueCondition(WithinRange, SingleValue(0))},
1950 ErrnoIrrelevant,
"Assuming the character is non-printable"));
1951 addToFunctionSummaryMap(
1952 "ispunct", Signature(ArgTypes{IntTy}, RetType{IntTy}),
1953 Summary(EvalCallAsPure)
1954 .Case({ArgumentCondition(
1956 {{
'!',
'/'}, {
':',
'@'}, {
'[',
'`'}, {
'{',
'~'}}),
1957 ReturnValueCondition(OutOfRange, SingleValue(0))},
1958 ErrnoIrrelevant,
"Assuming the character is a punctuation mark")
1959 .Case({ArgumentCondition(
1961 {{
'!',
'/'}, {
':',
'@'}, {
'[',
'`'}, {
'{',
'~'}}),
1962 ReturnValueCondition(WithinRange, SingleValue(0))},
1964 "Assuming the character is not a punctuation mark"));
1965 addToFunctionSummaryMap(
1966 "isspace", Signature(ArgTypes{IntTy}, RetType{IntTy}),
1967 Summary(EvalCallAsPure)
1969 .Case({ArgumentCondition(0U, WithinRange, {{9, 13}, {
' ',
' '}}),
1970 ReturnValueCondition(OutOfRange, SingleValue(0))},
1972 "Assuming the character is a whitespace character")
1974 .Case({ArgumentCondition(0U, WithinRange, {{128, UCharRangeMax}})},
1976 .Case({ArgumentCondition(0U, OutOfRange,
1977 {{9, 13}, {
' ',
' '}, {128, UCharRangeMax}}),
1978 ReturnValueCondition(WithinRange, SingleValue(0))},
1980 "Assuming the character is not a whitespace character"));
1981 addToFunctionSummaryMap(
1982 "isupper", Signature(ArgTypes{IntTy}, RetType{IntTy}),
1983 Summary(EvalCallAsPure)
1985 .Case({ArgumentCondition(0U, WithinRange,
Range(
'A',
'Z')),
1986 ReturnValueCondition(OutOfRange, SingleValue(0))},
1988 "Assuming the character is an uppercase letter")
1990 .Case({ArgumentCondition(0U, WithinRange, {{128, UCharRangeMax}})},
1993 .Case({ArgumentCondition(0U, OutOfRange,
1994 {{
'A',
'Z'}, {128, UCharRangeMax}}),
1995 ReturnValueCondition(WithinRange, SingleValue(0))},
1997 "Assuming the character is not an uppercase letter"));
1998 addToFunctionSummaryMap(
1999 "isxdigit", Signature(ArgTypes{IntTy}, RetType{IntTy}),
2000 Summary(EvalCallAsPure)
2001 .Case({ArgumentCondition(0U, WithinRange,
2002 {{
'0',
'9'}, {
'A',
'F'}, {
'a',
'f'}}),
2003 ReturnValueCondition(OutOfRange, SingleValue(0))},
2005 "Assuming the character is a hexadecimal digit")
2006 .Case({ArgumentCondition(0U, OutOfRange,
2007 {{
'0',
'9'}, {
'A',
'F'}, {
'a',
'f'}}),
2008 ReturnValueCondition(WithinRange, SingleValue(0))},
2010 "Assuming the character is not a hexadecimal digit"));
2011 addToFunctionSummaryMap(
2012 "toupper", Signature(ArgTypes{IntTy}, RetType{IntTy}),
2013 Summary(EvalCallAsPure)
2014 .ArgConstraint(ArgumentCondition(0U, WithinRange,
2015 {{EOFv, EOFv}, {0, UCharRangeMax}},
2016 "an unsigned char value or EOF")));
2017 addToFunctionSummaryMap(
2018 "tolower", Signature(ArgTypes{IntTy}, RetType{IntTy}),
2019 Summary(EvalCallAsPure)
2020 .ArgConstraint(ArgumentCondition(0U, WithinRange,
2021 {{EOFv, EOFv}, {0, UCharRangeMax}},
2022 "an unsigned char value or EOF")));
2023 addToFunctionSummaryMap(
2024 "toascii", Signature(ArgTypes{IntTy}, RetType{IntTy}),
2025 Summary(EvalCallAsPure)
2026 .ArgConstraint(ArgumentCondition(0U, WithinRange,
2027 {{EOFv, EOFv}, {0, UCharRangeMax}},
2028 "an unsigned char value or EOF")));
2030 addToFunctionSummaryMap(
2031 "getchar", Signature(ArgTypes{}, RetType{IntTy}),
2033 .Case({ReturnValueCondition(WithinRange,
2034 {{EOFv, EOFv}, {0, UCharRangeMax}})},
2040 .Case({ArgumentCondition(1U, WithinRange,
Range(1, SizeMax)),
2041 ArgumentCondition(2U, WithinRange,
Range(1, SizeMax)),
2042 ReturnValueCondition(BO_LT, ArgNo(2)),
2043 ReturnValueCondition(WithinRange,
Range(0, SizeMax))},
2044 ErrnoNEZeroIrrelevant, GenericFailureMsg)
2045 .Case({ArgumentCondition(1U, WithinRange,
Range(1, SizeMax)),
2046 ReturnValueCondition(BO_EQ, ArgNo(2)),
2047 ReturnValueCondition(WithinRange,
Range(0, SizeMax))},
2048 ErrnoMustNotBeChecked, GenericSuccessMsg)
2049 .Case({ArgumentCondition(1U, WithinRange, SingleValue(0)),
2050 ReturnValueCondition(WithinRange, SingleValue(0))},
2051 ErrnoMustNotBeChecked,
2052 "Assuming that argument 'size' to '{0}' is 0")
2053 .ArgConstraint(NotNullBuffer(ArgNo(0), ArgNo(1), ArgNo(2)))
2054 .ArgConstraint(NotNull(ArgNo(3)))
2055 .ArgConstraint(BufferSize(ArgNo(0), ArgNo(1),
2060 addToFunctionSummaryMap(
"fread",
2061 Signature(ArgTypes{VoidPtrRestrictTy, SizeTyCanonTy,
2062 SizeTyCanonTy, FilePtrRestrictTy},
2063 RetType{SizeTyCanonTy}),
2067 addToFunctionSummaryMap(
2069 Signature(ArgTypes{ConstVoidPtrRestrictTy, SizeTyCanonTy, SizeTyCanonTy,
2071 RetType{SizeTyCanonTy}),
2074 std::optional<QualType> Ssize_tTy = lookupTy(
"ssize_t");
2075 std::optional<RangeInt> Ssize_tMax = getMaxValue(Ssize_tTy);
2079 .Case({ReturnValueCondition(LessThanOrEq, ArgNo(2)),
2080 ReturnValueCondition(WithinRange,
Range(-1, Ssize_tMax))},
2086 addToFunctionSummaryMap(
2088 Signature(ArgTypes{IntTy, VoidPtrTy, SizeTyCanonTy}, RetType{Ssize_tTy}),
2091 addToFunctionSummaryMap(
2093 Signature(ArgTypes{IntTy, ConstVoidPtrTy, SizeTyCanonTy},
2094 RetType{Ssize_tTy}),
2097 auto GetLineSummary =
2099 .Case({ReturnValueCondition(WithinRange,
2100 Range({-1, -1}, {1, Ssize_tMax}))},
2103 QualType CharPtrPtrRestrictTy = getRestrictTy(getPointerTy(CharPtrTy));
2110 addToFunctionSummaryMap(
2113 ArgTypes{CharPtrPtrRestrictTy, SizePtrRestrictTy, FilePtrRestrictTy},
2114 RetType{Ssize_tTy}),
2118 addToFunctionSummaryMap(
2120 Signature(ArgTypes{CharPtrPtrRestrictTy, SizePtrRestrictTy, IntTy,
2122 RetType{Ssize_tTy}),
2126 Summary GetenvSummary =
2128 .ArgConstraint(NotNull(ArgNo(0)))
2129 .Case({NotNull(Ret)}, ErrnoIrrelevant,
2130 "Assuming the environment variable exists");
2132 if (!ShouldAssumeControlledEnvironment)
2133 GetenvSummary.Case({NotNull(Ret)->negate()}, ErrnoIrrelevant,
2134 "Assuming the environment variable does not exist");
2137 addToFunctionSummaryMap(
2138 "getenv", Signature(ArgTypes{ConstCharPtrTy}, RetType{CharPtrTy}),
2139 std::move(GetenvSummary));
2145 addToFunctionSummaryMap(
2146 {
"getc",
"fgetc"}, Signature(ArgTypes{FilePtrTy}, RetType{IntTy}),
2148 .Case({ReturnValueCondition(WithinRange,
2149 {{EOFv, EOFv}, {0, UCharRangeMax}})},
2151 .ArgConstraint(NotNull(ArgNo(0))));
2153 const auto ReturnsZeroOrMinusOne =
2154 ConstraintSet{ReturnValueCondition(WithinRange,
Range(-1, 0))};
2155 const auto ReturnsZero =
2156 ConstraintSet{ReturnValueCondition(WithinRange, SingleValue(0))};
2157 const auto ReturnsMinusOne =
2158 ConstraintSet{ReturnValueCondition(WithinRange, SingleValue(-1))};
2159 const auto ReturnsEOF =
2160 ConstraintSet{ReturnValueCondition(WithinRange, SingleValue(EOFv))};
2161 const auto ReturnsNonnegative =
2162 ConstraintSet{ReturnValueCondition(WithinRange,
Range(0, IntMax))};
2163 const auto ReturnsNonZero =
2164 ConstraintSet{ReturnValueCondition(OutOfRange, SingleValue(0))};
2165 const auto ReturnsFileDescriptor =
2166 ConstraintSet{ReturnValueCondition(WithinRange,
Range(-1, IntMax))};
2167 const auto &ReturnsValidFileDescriptor = ReturnsNonnegative;
2169 auto ValidFileDescriptorOrAtFdcwd = [&](ArgNo ArgN) {
2170 return std::make_shared<RangeConstraint>(
2171 ArgN, WithinRange,
Range({AT_FDCWDv, AT_FDCWDv}, {0, IntMax}),
2172 "a valid file descriptor or AT_FDCWD");
2176 addToFunctionSummaryMap(
2178 Signature(ArgTypes{ConstCharPtrRestrictTy, ConstCharPtrRestrictTy},
2179 RetType{FilePtrTy}),
2181 .Case({NotNull(Ret)}, ErrnoMustNotBeChecked, GenericSuccessMsg)
2182 .Case({
IsNull(Ret)}, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2183 .ArgConstraint(NotNull(ArgNo(0)))
2184 .ArgConstraint(NotNull(ArgNo(1))));
2187 addToFunctionSummaryMap(
2189 Signature(ArgTypes{IntTy, ConstCharPtrTy}, RetType{FilePtrTy}),
2191 .Case({NotNull(Ret)}, ErrnoMustNotBeChecked, GenericSuccessMsg)
2192 .Case({
IsNull(Ret)}, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2193 .ArgConstraint(ArgumentCondition(0, WithinRange,
Range(0, IntMax)))
2194 .ArgConstraint(NotNull(ArgNo(1))));
2197 addToFunctionSummaryMap(
2198 "tmpfile", Signature(ArgTypes{}, RetType{FilePtrTy}),
2200 .Case({NotNull(Ret)}, ErrnoMustNotBeChecked, GenericSuccessMsg)
2201 .Case({
IsNull(Ret)}, ErrnoNEZeroIrrelevant, GenericFailureMsg));
2205 addToFunctionSummaryMap(
2207 Signature(ArgTypes{ConstCharPtrRestrictTy, ConstCharPtrRestrictTy,
2209 RetType{FilePtrTy}),
2211 .Case({ReturnValueCondition(BO_EQ, ArgNo(2))},
2212 ErrnoMustNotBeChecked, GenericSuccessMsg)
2213 .Case({
IsNull(Ret)}, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2214 .ArgConstraint(NotNull(ArgNo(1)))
2215 .ArgConstraint(NotNull(ArgNo(2))));
2218 addToFunctionSummaryMap(
2220 Signature(ArgTypes{ConstCharPtrTy, ConstCharPtrTy}, RetType{FilePtrTy}),
2222 .Case({NotNull(Ret)}, ErrnoMustNotBeChecked, GenericSuccessMsg)
2223 .Case({
IsNull(Ret)}, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2224 .ArgConstraint(NotNull(ArgNo(0)))
2225 .ArgConstraint(NotNull(ArgNo(1))));
2228 addToFunctionSummaryMap(
2229 "fclose", Signature(ArgTypes{FilePtrTy}, RetType{IntTy}),
2231 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2232 .Case(ReturnsEOF, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2233 .ArgConstraint(NotNull(ArgNo(0))));
2236 addToFunctionSummaryMap(
2237 "pclose", Signature(ArgTypes{FilePtrTy}, RetType{IntTy}),
2239 .Case({ReturnValueCondition(WithinRange, {{0, IntMax}})},
2240 ErrnoMustNotBeChecked, GenericSuccessMsg)
2241 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2242 .ArgConstraint(NotNull(ArgNo(0))));
2244 std::optional<QualType> Off_tTy = lookupTy(
"off_t");
2245 std::optional<RangeInt> Off_tMax = getMaxValue(Off_tTy);
2249 addToFunctionSummaryMap(
2250 {
"getc",
"fgetc"}, Signature(ArgTypes{FilePtrTy}, RetType{IntTy}),
2252 .Case({ReturnValueCondition(WithinRange, {{0, UCharRangeMax}})},
2253 ErrnoMustNotBeChecked, GenericSuccessMsg)
2254 .Case({ReturnValueCondition(WithinRange, SingleValue(EOFv))},
2255 ErrnoIrrelevant, GenericFailureMsg)
2256 .ArgConstraint(NotNull(ArgNo(0))));
2260 addToFunctionSummaryMap(
2262 Signature(ArgTypes{IntTy, FilePtrTy}, RetType{IntTy}),
2264 .Case({ArgumentCondition(0, WithinRange,
Range(0, UCharRangeMax)),
2265 ReturnValueCondition(BO_EQ, ArgNo(0))},
2266 ErrnoMustNotBeChecked, GenericSuccessMsg)
2267 .Case({ArgumentCondition(0, OutOfRange,
Range(0, UCharRangeMax)),
2268 ReturnValueCondition(WithinRange,
Range(0, UCharRangeMax))},
2269 ErrnoMustNotBeChecked, GenericSuccessMsg)
2270 .Case({ReturnValueCondition(WithinRange, SingleValue(EOFv))},
2271 ErrnoNEZeroIrrelevant, GenericFailureMsg)
2272 .ArgConstraint(NotNull(ArgNo(1))));
2275 addToFunctionSummaryMap(
2277 Signature(ArgTypes{CharPtrRestrictTy, IntTy, FilePtrRestrictTy},
2278 RetType{CharPtrTy}),
2280 .Case({ReturnValueCondition(BO_EQ, ArgNo(0))},
2281 ErrnoMustNotBeChecked, GenericSuccessMsg)
2282 .Case({
IsNull(Ret)}, ErrnoIrrelevant, GenericFailureMsg)
2283 .ArgConstraint(NotNull(ArgNo(0)))
2284 .ArgConstraint(ArgumentCondition(1, WithinRange,
Range(0, IntMax)))
2286 BufferSize(ArgNo(0), ArgNo(1)))
2287 .ArgConstraint(NotNull(ArgNo(2))));
2290 addToFunctionSummaryMap(
2292 Signature(ArgTypes{ConstCharPtrRestrictTy, FilePtrRestrictTy},
2295 .Case(ReturnsNonnegative, ErrnoMustNotBeChecked, GenericSuccessMsg)
2296 .Case({ReturnValueCondition(WithinRange, SingleValue(EOFv))},
2297 ErrnoNEZeroIrrelevant, GenericFailureMsg)
2298 .ArgConstraint(NotNull(ArgNo(0)))
2299 .ArgConstraint(NotNull(ArgNo(1))));
2302 addToFunctionSummaryMap(
2303 "ungetc", Signature(ArgTypes{IntTy, FilePtrTy}, RetType{IntTy}),
2305 .Case({ReturnValueCondition(BO_EQ, ArgNo(0)),
2306 ArgumentCondition(0, WithinRange, {{0, UCharRangeMax}})},
2307 ErrnoMustNotBeChecked, GenericSuccessMsg)
2308 .Case({ReturnValueCondition(WithinRange, SingleValue(EOFv)),
2309 ArgumentCondition(0, WithinRange, SingleValue(EOFv))},
2310 ErrnoNEZeroIrrelevant,
2311 "Assuming that 'ungetc' fails because EOF was passed as "
2313 .Case({ReturnValueCondition(WithinRange, SingleValue(EOFv)),
2314 ArgumentCondition(0, WithinRange, {{0, UCharRangeMax}})},
2315 ErrnoNEZeroIrrelevant, GenericFailureMsg)
2316 .ArgConstraint(ArgumentCondition(
2317 0, WithinRange, {{EOFv, EOFv}, {0, UCharRangeMax}}))
2318 .ArgConstraint(NotNull(ArgNo(1))));
2324 addToFunctionSummaryMap(
2325 "fseek", Signature(ArgTypes{FilePtrTy, LongTy, IntTy}, RetType{IntTy}),
2327 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2328 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2329 .ArgConstraint(NotNull(ArgNo(0)))
2330 .ArgConstraint(ArgumentCondition(2, WithinRange, {{0, 2}})));
2333 addToFunctionSummaryMap(
2335 Signature(ArgTypes{FilePtrTy, Off_tTy, IntTy}, RetType{IntTy}),
2337 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2338 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2339 .ArgConstraint(NotNull(ArgNo(0)))
2340 .ArgConstraint(ArgumentCondition(2, WithinRange, {{0, 2}})));
2346 addToFunctionSummaryMap(
2348 Signature(ArgTypes{FilePtrRestrictTy, FPosTPtrRestrictTy},
2351 .Case(ReturnsZero, ErrnoUnchanged, GenericSuccessMsg)
2352 .Case(ReturnsNonZero, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2353 .ArgConstraint(NotNull(ArgNo(0)))
2354 .ArgConstraint(NotNull(ArgNo(1))));
2360 addToFunctionSummaryMap(
2362 Signature(ArgTypes{FilePtrTy, ConstFPosTPtrTy}, RetType{IntTy}),
2364 .Case(ReturnsZero, ErrnoUnchanged, GenericSuccessMsg)
2365 .Case(ReturnsNonZero, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2366 .ArgConstraint(NotNull(ArgNo(0)))
2367 .ArgConstraint(NotNull(ArgNo(1))));
2370 addToFunctionSummaryMap(
2371 "fflush", Signature(ArgTypes{FilePtrTy}, RetType{IntTy}),
2373 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2374 .Case(ReturnsEOF, ErrnoNEZeroIrrelevant, GenericFailureMsg));
2380 addToFunctionSummaryMap(
2381 "ftell", Signature(ArgTypes{FilePtrTy}, RetType{LongTy}),
2383 .Case({ReturnValueCondition(WithinRange,
Range(0, LongMax))},
2384 ErrnoUnchanged, GenericSuccessMsg)
2385 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2386 .ArgConstraint(NotNull(ArgNo(0))));
2389 addToFunctionSummaryMap(
2390 "ftello", Signature(ArgTypes{FilePtrTy}, RetType{Off_tTy}),
2392 .Case({ReturnValueCondition(WithinRange,
Range(0, Off_tMax))},
2393 ErrnoMustNotBeChecked, GenericSuccessMsg)
2394 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2395 .ArgConstraint(NotNull(ArgNo(0))));
2403 addToFunctionSummaryMap(
2404 "fileno", Signature(ArgTypes{FilePtrTy}, RetType{IntTy}),
2406 .Case(ReturnsValidFileDescriptor, ErrnoUnchanged, GenericSuccessMsg)
2407 .ArgConstraint(NotNull(ArgNo(0))));
2411 addToFunctionSummaryMap(
"rewind",
2412 Signature(ArgTypes{FilePtrTy}, RetType{VoidTy}),
2414 .Case({}, ErrnoMustBeChecked)
2415 .ArgConstraint(NotNull(ArgNo(0))));
2418 addToFunctionSummaryMap(
2419 "clearerr", Signature(ArgTypes{FilePtrTy}, RetType{VoidTy}),
2420 Summary(NoEvalCall).ArgConstraint(NotNull(ArgNo(0))));
2423 addToFunctionSummaryMap(
2424 "feof", Signature(ArgTypes{FilePtrTy}, RetType{IntTy}),
2425 Summary(NoEvalCall).ArgConstraint(NotNull(ArgNo(0))));
2428 addToFunctionSummaryMap(
2429 "ferror", Signature(ArgTypes{FilePtrTy}, RetType{IntTy}),
2430 Summary(NoEvalCall).ArgConstraint(NotNull(ArgNo(0))));
2433 addToFunctionSummaryMap(
2434 "a64l", Signature(ArgTypes{ConstCharPtrTy}, RetType{LongTy}),
2435 Summary(NoEvalCall).ArgConstraint(NotNull(ArgNo(0))));
2438 addToFunctionSummaryMap(
"l64a",
2439 Signature(ArgTypes{LongTy}, RetType{CharPtrTy}),
2441 .ArgConstraint(ArgumentCondition(
2442 0, WithinRange,
Range(0, LongMax))));
2445 addToFunctionSummaryMap(
2446 "open", Signature(ArgTypes{ConstCharPtrTy, IntTy}, RetType{IntTy}),
2448 .Case(ReturnsValidFileDescriptor, ErrnoMustNotBeChecked,
2450 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2451 .ArgConstraint(NotNull(ArgNo(0))));
2454 addToFunctionSummaryMap(
2456 Signature(ArgTypes{IntTy, ConstCharPtrTy, IntTy}, RetType{IntTy}),
2458 .Case(ReturnsValidFileDescriptor, ErrnoMustNotBeChecked,
2460 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2461 .ArgConstraint(ValidFileDescriptorOrAtFdcwd(ArgNo(0)))
2462 .ArgConstraint(NotNull(ArgNo(1))));
2465 addToFunctionSummaryMap(
2466 "access", Signature(ArgTypes{ConstCharPtrTy, IntTy}, RetType{IntTy}),
2468 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2469 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2470 .ArgConstraint(NotNull(ArgNo(0))));
2473 addToFunctionSummaryMap(
2475 Signature(ArgTypes{IntTy, ConstCharPtrTy, IntTy, IntTy},
2478 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2479 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2480 .ArgConstraint(ValidFileDescriptorOrAtFdcwd(ArgNo(0)))
2481 .ArgConstraint(NotNull(ArgNo(1))));
2484 addToFunctionSummaryMap(
2485 "dup", Signature(ArgTypes{IntTy}, RetType{IntTy}),
2487 .Case(ReturnsValidFileDescriptor, ErrnoMustNotBeChecked,
2489 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2491 ArgumentCondition(0, WithinRange,
Range(0, IntMax))));
2494 addToFunctionSummaryMap(
2495 "dup2", Signature(ArgTypes{IntTy, IntTy}, RetType{IntTy}),
2497 .Case(ReturnsValidFileDescriptor, ErrnoMustNotBeChecked,
2499 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2500 .ArgConstraint(ArgumentCondition(0, WithinRange,
Range(0, IntMax)))
2502 ArgumentCondition(1, WithinRange,
Range(0, IntMax))));
2505 addToFunctionSummaryMap(
2506 "fdatasync", Signature(ArgTypes{IntTy}, RetType{IntTy}),
2508 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2509 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2511 ArgumentCondition(0, WithinRange,
Range(0, IntMax))));
2514 addToFunctionSummaryMap(
2516 Signature(ArgTypes{ConstCharPtrTy, ConstCharPtrTy, IntTy},
2519 .ArgConstraint(NotNull(ArgNo(0)))
2520 .ArgConstraint(NotNull(ArgNo(1))));
2523 addToFunctionSummaryMap(
2524 "fsync", Signature(ArgTypes{IntTy}, RetType{IntTy}),
2526 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2527 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2529 ArgumentCondition(0, WithinRange,
Range(0, IntMax))));
2532 addToFunctionSummaryMap(
2534 Signature(ArgTypes{ConstCharPtrTy, Off_tTy}, RetType{IntTy}),
2536 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2537 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2538 .ArgConstraint(NotNull(ArgNo(0))));
2541 addToFunctionSummaryMap(
2543 Signature(ArgTypes{ConstCharPtrTy, ConstCharPtrTy}, RetType{IntTy}),
2545 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2546 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2547 .ArgConstraint(NotNull(ArgNo(0)))
2548 .ArgConstraint(NotNull(ArgNo(1))));
2551 addToFunctionSummaryMap(
2553 Signature(ArgTypes{ConstCharPtrTy, IntTy, ConstCharPtrTy},
2556 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2557 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2558 .ArgConstraint(NotNull(ArgNo(0)))
2559 .ArgConstraint(ValidFileDescriptorOrAtFdcwd(ArgNo(1)))
2560 .ArgConstraint(NotNull(ArgNo(2))));
2563 addToFunctionSummaryMap(
2564 "lockf", Signature(ArgTypes{IntTy, IntTy, Off_tTy}, RetType{IntTy}),
2566 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2567 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2569 ArgumentCondition(0, WithinRange,
Range(0, IntMax))));
2571 std::optional<QualType> Mode_tTy = lookupTy(
"mode_t");
2574 addToFunctionSummaryMap(
2575 "creat", Signature(ArgTypes{ConstCharPtrTy, Mode_tTy}, RetType{IntTy}),
2577 .Case(ReturnsValidFileDescriptor, ErrnoMustNotBeChecked,
2579 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2580 .ArgConstraint(NotNull(ArgNo(0))));
2583 addToFunctionSummaryMap(
2584 "sleep", Signature(ArgTypes{UnsignedIntTy}, RetType{UnsignedIntTy}),
2587 ArgumentCondition(0, WithinRange,
Range(0, UnsignedIntMax))));
2589 std::optional<QualType> DirTy = lookupTy(
"DIR");
2590 std::optional<QualType> DirPtrTy = getPointerTy(DirTy);
2593 addToFunctionSummaryMap(
2594 "dirfd", Signature(ArgTypes{DirPtrTy}, RetType{IntTy}),
2596 .Case(ReturnsValidFileDescriptor, ErrnoMustNotBeChecked,
2598 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2599 .ArgConstraint(NotNull(ArgNo(0))));
2602 addToFunctionSummaryMap(
2603 "alarm", Signature(ArgTypes{UnsignedIntTy}, RetType{UnsignedIntTy}),
2606 ArgumentCondition(0, WithinRange,
Range(0, UnsignedIntMax))));
2609 addToFunctionSummaryMap(
2610 "closedir", Signature(ArgTypes{DirPtrTy}, RetType{IntTy}),
2612 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2613 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2614 .ArgConstraint(NotNull(ArgNo(0))));
2617 addToFunctionSummaryMap(
2618 "strdup", Signature(ArgTypes{ConstCharPtrTy}, RetType{CharPtrTy}),
2619 Summary(NoEvalCall).ArgConstraint(NotNull(ArgNo(0))));
2622 addToFunctionSummaryMap(
2624 Signature(ArgTypes{ConstCharPtrTy, SizeTyCanonTy}, RetType{CharPtrTy}),
2626 .ArgConstraint(NotNull(ArgNo(0)))
2628 ArgumentCondition(1, WithinRange,
Range(0, SizeMax))));
2631 addToFunctionSummaryMap(
2632 "wcsdup", Signature(ArgTypes{ConstWchar_tPtrTy}, RetType{Wchar_tPtrTy}),
2633 Summary(NoEvalCall).ArgConstraint(NotNull(ArgNo(0))));
2636 addToFunctionSummaryMap(
2637 "mkstemp", Signature(ArgTypes{CharPtrTy}, RetType{IntTy}),
2639 .Case(ReturnsValidFileDescriptor, ErrnoMustNotBeChecked,
2641 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2642 .ArgConstraint(NotNull(ArgNo(0))));
2645 addToFunctionSummaryMap(
2646 "mkdtemp", Signature(ArgTypes{CharPtrTy}, RetType{CharPtrTy}),
2648 .Case({ReturnValueCondition(BO_EQ, ArgNo(0))},
2649 ErrnoMustNotBeChecked, GenericSuccessMsg)
2650 .Case({
IsNull(Ret)}, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2651 .ArgConstraint(NotNull(ArgNo(0))));
2654 addToFunctionSummaryMap(
2656 Signature(ArgTypes{CharPtrTy, SizeTyCanonTy}, RetType{CharPtrTy}),
2659 ArgumentCondition(1, WithinRange,
Range(1, SizeMax)),
2660 ReturnValueCondition(BO_EQ, ArgNo(0))},
2661 ErrnoMustNotBeChecked, GenericSuccessMsg)
2663 ArgumentCondition(1, WithinRange, SingleValue(0)),
2665 ErrnoNEZeroIrrelevant,
"Assuming that argument 'size' is 0")
2667 ArgumentCondition(1, WithinRange,
Range(1, SizeMax)),
2669 ErrnoNEZeroIrrelevant, GenericFailureMsg)
2670 .Case({
IsNull(0), NotNull(Ret)}, ErrnoMustNotBeChecked,
2675 BufferSize( ArgNo(0), ArgNo(1)))
2677 ArgumentCondition(1, WithinRange,
Range(0, SizeMax))));
2680 addToFunctionSummaryMap(
2681 "mkdir", Signature(ArgTypes{ConstCharPtrTy, Mode_tTy}, RetType{IntTy}),
2683 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2684 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2685 .ArgConstraint(NotNull(ArgNo(0))));
2688 addToFunctionSummaryMap(
2690 Signature(ArgTypes{IntTy, ConstCharPtrTy, Mode_tTy}, RetType{IntTy}),
2692 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2693 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2694 .ArgConstraint(ValidFileDescriptorOrAtFdcwd(ArgNo(0)))
2695 .ArgConstraint(NotNull(ArgNo(1))));
2697 std::optional<QualType> Dev_tTy = lookupTy(
"dev_t");
2700 addToFunctionSummaryMap(
2702 Signature(ArgTypes{ConstCharPtrTy, Mode_tTy, Dev_tTy}, RetType{IntTy}),
2704 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2705 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2706 .ArgConstraint(NotNull(ArgNo(0))));
2709 addToFunctionSummaryMap(
2711 Signature(ArgTypes{IntTy, ConstCharPtrTy, Mode_tTy, Dev_tTy},
2714 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2715 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2716 .ArgConstraint(ValidFileDescriptorOrAtFdcwd(ArgNo(0)))
2717 .ArgConstraint(NotNull(ArgNo(1))));
2720 addToFunctionSummaryMap(
2721 "chmod", Signature(ArgTypes{ConstCharPtrTy, Mode_tTy}, RetType{IntTy}),
2723 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2724 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2725 .ArgConstraint(NotNull(ArgNo(0))));
2728 addToFunctionSummaryMap(
2730 Signature(ArgTypes{IntTy, ConstCharPtrTy, Mode_tTy, IntTy},
2733 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2734 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2735 .ArgConstraint(ValidFileDescriptorOrAtFdcwd(ArgNo(0)))
2736 .ArgConstraint(NotNull(ArgNo(1))));
2739 addToFunctionSummaryMap(
2740 "fchmod", Signature(ArgTypes{IntTy, Mode_tTy}, RetType{IntTy}),
2742 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2743 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2745 ArgumentCondition(0, WithinRange,
Range(0, IntMax))));
2747 std::optional<QualType> Uid_tTy = lookupTy(
"uid_t");
2748 std::optional<QualType> Gid_tTy = lookupTy(
"gid_t");
2752 addToFunctionSummaryMap(
2754 Signature(ArgTypes{IntTy, ConstCharPtrTy, Uid_tTy, Gid_tTy, IntTy},
2757 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2758 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2759 .ArgConstraint(ValidFileDescriptorOrAtFdcwd(ArgNo(0)))
2760 .ArgConstraint(NotNull(ArgNo(1))));
2763 addToFunctionSummaryMap(
2765 Signature(ArgTypes{ConstCharPtrTy, Uid_tTy, Gid_tTy}, RetType{IntTy}),
2767 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2768 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2769 .ArgConstraint(NotNull(ArgNo(0))));
2772 addToFunctionSummaryMap(
2774 Signature(ArgTypes{ConstCharPtrTy, Uid_tTy, Gid_tTy}, RetType{IntTy}),
2776 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2777 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2778 .ArgConstraint(NotNull(ArgNo(0))));
2781 addToFunctionSummaryMap(
2782 "fchown", Signature(ArgTypes{IntTy, Uid_tTy, Gid_tTy}, RetType{IntTy}),
2784 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2785 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2787 ArgumentCondition(0, WithinRange,
Range(0, IntMax))));
2790 addToFunctionSummaryMap(
2791 "rmdir", Signature(ArgTypes{ConstCharPtrTy}, RetType{IntTy}),
2793 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2794 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2795 .ArgConstraint(NotNull(ArgNo(0))));
2798 addToFunctionSummaryMap(
2799 "chdir", Signature(ArgTypes{ConstCharPtrTy}, RetType{IntTy}),
2801 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2802 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2803 .ArgConstraint(NotNull(ArgNo(0))));
2806 addToFunctionSummaryMap(
2808 Signature(ArgTypes{ConstCharPtrTy, ConstCharPtrTy}, RetType{IntTy}),
2810 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2811 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2812 .ArgConstraint(NotNull(ArgNo(0)))
2813 .ArgConstraint(NotNull(ArgNo(1))));
2817 addToFunctionSummaryMap(
2819 Signature(ArgTypes{IntTy, ConstCharPtrTy, IntTy, ConstCharPtrTy, IntTy},
2822 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2823 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2824 .ArgConstraint(ValidFileDescriptorOrAtFdcwd(ArgNo(0)))
2825 .ArgConstraint(NotNull(ArgNo(1)))
2826 .ArgConstraint(ValidFileDescriptorOrAtFdcwd(ArgNo(2)))
2827 .ArgConstraint(NotNull(ArgNo(3))));
2830 addToFunctionSummaryMap(
2831 "unlink", Signature(ArgTypes{ConstCharPtrTy}, RetType{IntTy}),
2833 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2834 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2835 .ArgConstraint(NotNull(ArgNo(0))));
2838 addToFunctionSummaryMap(
2840 Signature(ArgTypes{IntTy, ConstCharPtrTy, IntTy}, RetType{IntTy}),
2842 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2843 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2844 .ArgConstraint(ValidFileDescriptorOrAtFdcwd(ArgNo(0)))
2845 .ArgConstraint(NotNull(ArgNo(1))));
2847 std::optional<QualType> StructStatTy = lookupTy(
"stat");
2848 std::optional<QualType> StructStatPtrTy = getPointerTy(StructStatTy);
2849 std::optional<QualType> StructStatPtrRestrictTy =
2850 getRestrictTy(StructStatPtrTy);
2853 addToFunctionSummaryMap(
2854 "fstat", Signature(ArgTypes{IntTy, StructStatPtrTy}, RetType{IntTy}),
2856 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2857 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2858 .ArgConstraint(ArgumentCondition(0, WithinRange,
Range(0, IntMax)))
2859 .ArgConstraint(NotNull(ArgNo(1))));
2862 addToFunctionSummaryMap(
2864 Signature(ArgTypes{ConstCharPtrRestrictTy, StructStatPtrRestrictTy},
2867 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2868 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2869 .ArgConstraint(NotNull(ArgNo(0)))
2870 .ArgConstraint(NotNull(ArgNo(1))));
2873 addToFunctionSummaryMap(
2875 Signature(ArgTypes{ConstCharPtrRestrictTy, StructStatPtrRestrictTy},
2878 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2879 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2880 .ArgConstraint(NotNull(ArgNo(0)))
2881 .ArgConstraint(NotNull(ArgNo(1))));
2885 addToFunctionSummaryMap(
2887 Signature(ArgTypes{IntTy, ConstCharPtrRestrictTy,
2888 StructStatPtrRestrictTy, IntTy},
2891 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2892 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2893 .ArgConstraint(ValidFileDescriptorOrAtFdcwd(ArgNo(0)))
2894 .ArgConstraint(NotNull(ArgNo(1)))
2895 .ArgConstraint(NotNull(ArgNo(2))));
2898 addToFunctionSummaryMap(
2899 "opendir", Signature(ArgTypes{ConstCharPtrTy}, RetType{DirPtrTy}),
2901 .Case({NotNull(Ret)}, ErrnoMustNotBeChecked, GenericSuccessMsg)
2902 .Case({
IsNull(Ret)}, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2903 .ArgConstraint(NotNull(ArgNo(0))));
2906 addToFunctionSummaryMap(
2907 "fdopendir", Signature(ArgTypes{IntTy}, RetType{DirPtrTy}),
2909 .Case({NotNull(Ret)}, ErrnoMustNotBeChecked, GenericSuccessMsg)
2910 .Case({
IsNull(Ret)}, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2912 ArgumentCondition(0, WithinRange,
Range(0, IntMax))));
2915 addToFunctionSummaryMap(
2916 "isatty", Signature(ArgTypes{IntTy}, RetType{IntTy}),
2918 .Case({ReturnValueCondition(WithinRange,
Range(0, 1))},
2921 ArgumentCondition(0, WithinRange,
Range(0, IntMax))));
2924 addToFunctionSummaryMap(
2925 "close", Signature(ArgTypes{IntTy}, RetType{IntTy}),
2927 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2928 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2930 ArgumentCondition(0, WithinRange,
Range(-1, IntMax))));
2933 addToFunctionSummaryMap(
"fpathconf",
2934 Signature(ArgTypes{IntTy, IntTy}, RetType{LongTy}),
2936 .ArgConstraint(ArgumentCondition(
2937 0, WithinRange,
Range(0, IntMax))));
2940 addToFunctionSummaryMap(
2941 "pathconf", Signature(ArgTypes{ConstCharPtrTy, IntTy}, RetType{LongTy}),
2942 Summary(NoEvalCall).ArgConstraint(NotNull(ArgNo(0))));
2945 addToFunctionSummaryMap(
2946 "rewinddir", Signature(ArgTypes{DirPtrTy}, RetType{VoidTy}),
2947 Summary(NoEvalCall).ArgConstraint(NotNull(ArgNo(0))));
2950 addToFunctionSummaryMap(
2951 "seekdir", Signature(ArgTypes{DirPtrTy, LongTy}, RetType{VoidTy}),
2952 Summary(NoEvalCall).ArgConstraint(NotNull(ArgNo(0))));
2955 addToFunctionSummaryMap(
2956 "rand_r", Signature(ArgTypes{UnsignedIntPtrTy}, RetType{IntTy}),
2957 Summary(NoEvalCall).ArgConstraint(NotNull(ArgNo(0))));
2962 addToFunctionSummaryMap(
2965 ArgTypes{VoidPtrTy, SizeTyCanonTy, IntTy, IntTy, IntTy, Off_tTy},
2966 RetType{VoidPtrTy}),
2968 .ArgConstraint(ArgumentCondition(1, WithinRange,
Range(1, SizeMax)))
2970 ArgumentCondition(4, WithinRange,
Range(-1, IntMax))));
2972 std::optional<QualType> Off64_tTy = lookupTy(
"off64_t");
2976 addToFunctionSummaryMap(
2979 ArgTypes{VoidPtrTy, SizeTyCanonTy, IntTy, IntTy, IntTy, Off64_tTy},
2980 RetType{VoidPtrTy}),
2982 .ArgConstraint(ArgumentCondition(1, WithinRange,
Range(1, SizeMax)))
2984 ArgumentCondition(4, WithinRange,
Range(-1, IntMax))));
2987 addToFunctionSummaryMap(
2988 "pipe", Signature(ArgTypes{IntPtrTy}, RetType{IntTy}),
2990 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2991 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2992 .ArgConstraint(NotNull(ArgNo(0))));
2999 addToFunctionSummaryMap(
3000 "lseek", Signature(ArgTypes{IntTy, Off_tTy, IntTy}, RetType{Off_tTy}),
3002 .Case(ReturnsNonnegative, ErrnoIrrelevant)
3003 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
3005 ArgumentCondition(0, WithinRange,
Range(0, IntMax))));
3009 addToFunctionSummaryMap(
3012 ArgTypes{ConstCharPtrRestrictTy, CharPtrRestrictTy, SizeTyCanonTy},
3013 RetType{Ssize_tTy}),
3015 .Case({ArgumentCondition(2, WithinRange,
Range(1, IntMax)),
3016 ReturnValueCondition(LessThanOrEq, ArgNo(2)),
3017 ReturnValueCondition(WithinRange,
Range(1, Ssize_tMax))},
3018 ErrnoMustNotBeChecked, GenericSuccessMsg)
3019 .Case({ArgumentCondition(2, WithinRange, SingleValue(0)),
3020 ReturnValueCondition(WithinRange, SingleValue(0))},
3021 ErrnoMustNotBeChecked,
3022 "Assuming that argument 'bufsize' is 0")
3023 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
3024 .ArgConstraint(NotNull(ArgNo(0)))
3025 .ArgConstraint(NotNull(ArgNo(1)))
3026 .ArgConstraint(BufferSize(ArgNo(1),
3029 ArgumentCondition(2, WithinRange,
Range(0, SizeMax))));
3033 addToFunctionSummaryMap(
3035 Signature(ArgTypes{IntTy, ConstCharPtrRestrictTy, CharPtrRestrictTy,
3037 RetType{Ssize_tTy}),
3039 .Case({ArgumentCondition(3, WithinRange,
Range(1, IntMax)),
3040 ReturnValueCondition(LessThanOrEq, ArgNo(3)),
3041 ReturnValueCondition(WithinRange,
Range(1, Ssize_tMax))},
3042 ErrnoMustNotBeChecked, GenericSuccessMsg)
3043 .Case({ArgumentCondition(3, WithinRange, SingleValue(0)),
3044 ReturnValueCondition(WithinRange, SingleValue(0))},
3045 ErrnoMustNotBeChecked,
3046 "Assuming that argument 'bufsize' is 0")
3047 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
3048 .ArgConstraint(ValidFileDescriptorOrAtFdcwd(ArgNo(0)))
3049 .ArgConstraint(NotNull(ArgNo(1)))
3050 .ArgConstraint(NotNull(ArgNo(2)))
3051 .ArgConstraint(BufferSize(ArgNo(2),
3054 ArgumentCondition(3, WithinRange,
Range(0, SizeMax))));
3058 addToFunctionSummaryMap(
3060 Signature(ArgTypes{IntTy, ConstCharPtrTy, IntTy, ConstCharPtrTy},
3063 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
3064 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
3065 .ArgConstraint(ValidFileDescriptorOrAtFdcwd(ArgNo(0)))
3066 .ArgConstraint(NotNull(ArgNo(1)))
3067 .ArgConstraint(ValidFileDescriptorOrAtFdcwd(ArgNo(2)))
3068 .ArgConstraint(NotNull(ArgNo(3))));
3074 addToFunctionSummaryMap(
3076 Signature(ArgTypes{ConstCharPtrRestrictTy, CharPtrRestrictTy},
3077 RetType{CharPtrTy}),
3079 .Case({NotNull(Ret)}, ErrnoMustNotBeChecked, GenericSuccessMsg)
3080 .Case({
IsNull(Ret)}, ErrnoNEZeroIrrelevant, GenericFailureMsg)
3081 .ArgConstraint(NotNull(ArgNo(0))));
3083 QualType CharPtrConstPtr = getPointerTy(getConstTy(CharPtrTy));
3086 addToFunctionSummaryMap(
3088 Signature(ArgTypes{ConstCharPtrTy, CharPtrConstPtr}, RetType{IntTy}),
3090 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant)
3091 .ArgConstraint(NotNull(ArgNo(0))));
3094 addToFunctionSummaryMap(
3096 Signature(ArgTypes{ConstCharPtrTy, CharPtrConstPtr}, RetType{IntTy}),
3098 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant)
3099 .ArgConstraint(NotNull(ArgNo(0))));
3102 addToFunctionSummaryMap(
3104 Signature(ArgTypes{IntTy, CharPtrConstPtr, ConstCharPtrTy},
3107 .Case({ReturnValueCondition(WithinRange,
Range(-1, UCharRangeMax))},
3109 .ArgConstraint(ArgumentCondition(0, WithinRange,
Range(0, IntMax)))
3110 .ArgConstraint(NotNull(ArgNo(1)))
3111 .ArgConstraint(NotNull(ArgNo(2))));
3113 std::optional<QualType> StructSockaddrTy = lookupTy(
"sockaddr");
3114 std::optional<QualType> StructSockaddrPtrTy =
3115 getPointerTy(StructSockaddrTy);
3116 std::optional<QualType> ConstStructSockaddrPtrTy =
3117 getPointerTy(getConstTy(StructSockaddrTy));
3118 std::optional<QualType> StructSockaddrPtrRestrictTy =
3119 getRestrictTy(StructSockaddrPtrTy);
3120 std::optional<QualType> ConstStructSockaddrPtrRestrictTy =
3121 getRestrictTy(ConstStructSockaddrPtrTy);
3122 std::optional<QualType> Socklen_tTy = lookupTy(
"socklen_t");
3123 std::optional<QualType> Socklen_tPtrTy = getPointerTy(Socklen_tTy);
3124 std::optional<QualType> Socklen_tPtrRestrictTy =
3125 getRestrictTy(Socklen_tPtrTy);
3126 std::optional<RangeInt> Socklen_tMax = getMaxValue(Socklen_tTy);
3136 addToFunctionSummaryMap(
3137 "socket", Signature(ArgTypes{IntTy, IntTy, IntTy}, RetType{IntTy}),
3139 .Case(ReturnsValidFileDescriptor, ErrnoMustNotBeChecked,
3141 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg));
3145 .Case(ReturnsValidFileDescriptor, ErrnoMustNotBeChecked,
3147 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
3148 .ArgConstraint(ArgumentCondition(0, WithinRange,
Range(0, IntMax)));
3149 if (!addToFunctionSummaryMap(
3153 Signature(ArgTypes{IntTy, StructSockaddrPtrRestrictTy,
3154 Socklen_tPtrRestrictTy},
3157 addToFunctionSummaryMap(
3159 Signature(ArgTypes{IntTy,
Irrelevant, Socklen_tPtrRestrictTy},
3165 if (!addToFunctionSummaryMap(
3167 Signature(ArgTypes{IntTy, ConstStructSockaddrPtrTy, Socklen_tTy},
3170 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
3171 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
3173 ArgumentCondition(0, WithinRange,
Range(0, IntMax)))
3174 .ArgConstraint(NotNull(ArgNo(1)))
3176 BufferSize(ArgNo(1), ArgNo(2)))
3178 ArgumentCondition(2, WithinRange,
Range(0, Socklen_tMax)))))
3180 addToFunctionSummaryMap(
3182 Signature(ArgTypes{IntTy,
Irrelevant, Socklen_tTy}, RetType{IntTy}),
3184 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
3185 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
3187 ArgumentCondition(0, WithinRange,
Range(0, IntMax)))
3189 ArgumentCondition(2, WithinRange,
Range(0, Socklen_tMax))));
3193 if (!addToFunctionSummaryMap(
3195 Signature(ArgTypes{IntTy, StructSockaddrPtrRestrictTy,
3196 Socklen_tPtrRestrictTy},
3199 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
3200 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
3202 ArgumentCondition(0, WithinRange,
Range(0, IntMax)))
3203 .ArgConstraint(NotNull(ArgNo(1)))
3204 .ArgConstraint(NotNull(ArgNo(2)))))
3205 addToFunctionSummaryMap(
3207 Signature(ArgTypes{IntTy,
Irrelevant, Socklen_tPtrRestrictTy},
3210 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
3211 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
3213 ArgumentCondition(0, WithinRange,
Range(0, IntMax))));
3217 if (!addToFunctionSummaryMap(
3219 Signature(ArgTypes{IntTy, StructSockaddrPtrRestrictTy,
3220 Socklen_tPtrRestrictTy},
3223 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
3224 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
3226 ArgumentCondition(0, WithinRange,
Range(0, IntMax)))
3227 .ArgConstraint(NotNull(ArgNo(1)))
3228 .ArgConstraint(NotNull(ArgNo(2)))))
3229 addToFunctionSummaryMap(
3231 Signature(ArgTypes{IntTy,
Irrelevant, Socklen_tPtrRestrictTy},
3234 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
3235 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
3237 ArgumentCondition(0, WithinRange,
Range(0, IntMax))));
3241 if (!addToFunctionSummaryMap(
3243 Signature(ArgTypes{IntTy, ConstStructSockaddrPtrTy, Socklen_tTy},
3246 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
3247 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
3249 ArgumentCondition(0, WithinRange,
Range(0, IntMax)))
3250 .ArgConstraint(NotNull(ArgNo(1)))))
3251 addToFunctionSummaryMap(
3253 Signature(ArgTypes{IntTy,
Irrelevant, Socklen_tTy}, RetType{IntTy}),
3255 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
3256 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
3258 ArgumentCondition(0, WithinRange,
Range(0, IntMax))));
3262 .Case({ReturnValueCondition(LessThanOrEq, ArgNo(2)),
3263 ReturnValueCondition(WithinRange,
Range(1, Ssize_tMax))},
3264 ErrnoMustNotBeChecked, GenericSuccessMsg)
3265 .Case({ReturnValueCondition(WithinRange, SingleValue(0)),
3266 ArgumentCondition(2, WithinRange, SingleValue(0))},
3267 ErrnoMustNotBeChecked, GenericSuccessMsg)
3268 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
3269 .ArgConstraint(ArgumentCondition(0, WithinRange,
Range(0, IntMax)))
3270 .ArgConstraint(BufferSize(ArgNo(1),
3272 if (!addToFunctionSummaryMap(
3278 Signature(ArgTypes{IntTy, VoidPtrRestrictTy, SizeTyCanonTy, IntTy,
3279 StructSockaddrPtrRestrictTy,
3280 Socklen_tPtrRestrictTy},
3281 RetType{Ssize_tTy}),
3283 addToFunctionSummaryMap(
3285 Signature(ArgTypes{IntTy, VoidPtrRestrictTy, SizeTyCanonTy, IntTy,
3287 RetType{Ssize_tTy}),
3292 .Case({ReturnValueCondition(LessThanOrEq, ArgNo(2)),
3293 ReturnValueCondition(WithinRange,
Range(1, Ssize_tMax))},
3294 ErrnoMustNotBeChecked, GenericSuccessMsg)
3295 .Case({ReturnValueCondition(WithinRange, SingleValue(0)),
3296 ArgumentCondition(2, WithinRange, SingleValue(0))},
3297 ErrnoMustNotBeChecked, GenericSuccessMsg)
3298 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
3299 .ArgConstraint(ArgumentCondition(0, WithinRange,
Range(0, IntMax)))
3300 .ArgConstraint(BufferSize(ArgNo(1),
3302 if (!addToFunctionSummaryMap(
3307 Signature(ArgTypes{IntTy, ConstVoidPtrTy, SizeTyCanonTy, IntTy,
3308 ConstStructSockaddrPtrTy, Socklen_tTy},
3309 RetType{Ssize_tTy}),
3311 addToFunctionSummaryMap(
3313 Signature(ArgTypes{IntTy, ConstVoidPtrTy, SizeTyCanonTy, IntTy,
3315 RetType{Ssize_tTy}),
3319 addToFunctionSummaryMap(
3320 "listen", Signature(ArgTypes{IntTy, IntTy}, RetType{IntTy}),
3322 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
3323 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
3325 ArgumentCondition(0, WithinRange,
Range(0, IntMax))));
3328 addToFunctionSummaryMap(
3330 Signature(ArgTypes{IntTy, VoidPtrTy, SizeTyCanonTy, IntTy},
3331 RetType{Ssize_tTy}),
3333 .Case({ReturnValueCondition(LessThanOrEq, ArgNo(2)),
3334 ReturnValueCondition(WithinRange,
Range(1, Ssize_tMax))},
3335 ErrnoMustNotBeChecked, GenericSuccessMsg)
3336 .Case({ReturnValueCondition(WithinRange, SingleValue(0)),
3337 ArgumentCondition(2, WithinRange, SingleValue(0))},
3338 ErrnoMustNotBeChecked, GenericSuccessMsg)
3339 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
3340 .ArgConstraint(ArgumentCondition(0, WithinRange,
Range(0, IntMax)))
3341 .ArgConstraint(BufferSize(ArgNo(1),
3344 std::optional<QualType> StructMsghdrTy = lookupTy(
"msghdr");
3345 std::optional<QualType> StructMsghdrPtrTy = getPointerTy(StructMsghdrTy);
3346 std::optional<QualType> ConstStructMsghdrPtrTy =
3347 getPointerTy(getConstTy(StructMsghdrTy));
3350 addToFunctionSummaryMap(
3352 Signature(ArgTypes{IntTy, StructMsghdrPtrTy, IntTy},
3353 RetType{Ssize_tTy}),
3355 .Case({ReturnValueCondition(WithinRange,
Range(1, Ssize_tMax))},
3356 ErrnoMustNotBeChecked, GenericSuccessMsg)
3357 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
3359 ArgumentCondition(0, WithinRange,
Range(0, IntMax))));
3362 addToFunctionSummaryMap(
3364 Signature(ArgTypes{IntTy, ConstStructMsghdrPtrTy, IntTy},
3365 RetType{Ssize_tTy}),
3367 .Case({ReturnValueCondition(WithinRange,
Range(1, Ssize_tMax))},
3368 ErrnoMustNotBeChecked, GenericSuccessMsg)
3369 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
3371 ArgumentCondition(0, WithinRange,
Range(0, IntMax))));
3375 addToFunctionSummaryMap(
3377 Signature(ArgTypes{IntTy, IntTy, IntTy, ConstVoidPtrTy, Socklen_tTy},
3380 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
3381 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
3382 .ArgConstraint(NotNullBuffer(ArgNo(3), ArgNo(4)))
3384 BufferSize(ArgNo(3), ArgNo(4)))
3386 ArgumentCondition(4, WithinRange,
Range(0, Socklen_tMax))));
3391 addToFunctionSummaryMap(
3393 Signature(ArgTypes{IntTy, IntTy, IntTy, VoidPtrRestrictTy,
3394 Socklen_tPtrRestrictTy},
3397 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
3398 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
3399 .ArgConstraint(NotNull(ArgNo(3)))
3400 .ArgConstraint(NotNull(ArgNo(4))));
3403 addToFunctionSummaryMap(
3405 Signature(ArgTypes{IntTy, ConstVoidPtrTy, SizeTyCanonTy, IntTy},
3406 RetType{Ssize_tTy}),
3408 .Case({ReturnValueCondition(LessThanOrEq, ArgNo(2)),
3409 ReturnValueCondition(WithinRange,
Range(1, Ssize_tMax))},
3410 ErrnoMustNotBeChecked, GenericSuccessMsg)
3411 .Case({ReturnValueCondition(WithinRange, SingleValue(0)),
3412 ArgumentCondition(2, WithinRange, SingleValue(0))},
3413 ErrnoMustNotBeChecked, GenericSuccessMsg)
3414 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
3415 .ArgConstraint(ArgumentCondition(0, WithinRange,
Range(0, IntMax)))
3416 .ArgConstraint(BufferSize(ArgNo(1),
3420 addToFunctionSummaryMap(
3422 Signature(ArgTypes{IntTy, IntTy, IntTy, IntPtrTy}, RetType{IntTy}),
3424 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
3425 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
3426 .ArgConstraint(NotNull(ArgNo(3))));
3429 addToFunctionSummaryMap(
3430 "shutdown", Signature(ArgTypes{IntTy, IntTy}, RetType{IntTy}),
3432 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
3433 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
3435 ArgumentCondition(0, WithinRange,
Range(0, IntMax))));
3444 addToFunctionSummaryMap(
3446 Signature(ArgTypes{ConstStructSockaddrPtrRestrictTy, Socklen_tTy,
3447 CharPtrRestrictTy, Socklen_tTy, CharPtrRestrictTy,
3448 Socklen_tTy, IntTy},
3452 BufferSize(ArgNo(0), ArgNo(1)))
3454 ArgumentCondition(1, WithinRange,
Range(0, Socklen_tMax)))
3456 BufferSize(ArgNo(2), ArgNo(3)))
3458 ArgumentCondition(3, WithinRange,
Range(0, Socklen_tMax)))
3460 BufferSize(ArgNo(4), ArgNo(5)))
3462 ArgumentCondition(5, WithinRange,
Range(0, Socklen_tMax))));
3464 std::optional<QualType> StructUtimbufTy = lookupTy(
"utimbuf");
3465 std::optional<QualType> StructUtimbufPtrTy = getPointerTy(StructUtimbufTy);
3468 addToFunctionSummaryMap(
3470 Signature(ArgTypes{ConstCharPtrTy, StructUtimbufPtrTy}, RetType{IntTy}),
3472 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
3473 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
3474 .ArgConstraint(NotNull(ArgNo(0))));
3476 std::optional<QualType> StructTimespecTy = lookupTy(
"timespec");
3477 std::optional<QualType> StructTimespecPtrTy =
3478 getPointerTy(StructTimespecTy);
3479 std::optional<QualType> ConstStructTimespecPtrTy =
3480 getPointerTy(getConstTy(StructTimespecTy));
3483 addToFunctionSummaryMap(
3485 Signature(ArgTypes{IntTy, ConstStructTimespecPtrTy}, RetType{IntTy}),
3487 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
3488 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
3490 ArgumentCondition(0, WithinRange,
Range(0, IntMax))));
3494 addToFunctionSummaryMap(
3497 ArgTypes{IntTy, ConstCharPtrTy, ConstStructTimespecPtrTy, IntTy},
3500 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
3501 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
3502 .ArgConstraint(NotNull(ArgNo(1))));
3504 std::optional<QualType> StructTimevalTy = lookupTy(
"timeval");
3505 std::optional<QualType> ConstStructTimevalPtrTy =
3506 getPointerTy(getConstTy(StructTimevalTy));
3509 addToFunctionSummaryMap(
3511 Signature(ArgTypes{ConstCharPtrTy, ConstStructTimevalPtrTy},
3514 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
3515 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
3516 .ArgConstraint(NotNull(ArgNo(0))));
3519 addToFunctionSummaryMap(
3521 Signature(ArgTypes{ConstStructTimespecPtrTy, StructTimespecPtrTy},
3524 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
3525 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
3526 .ArgConstraint(NotNull(ArgNo(0))));
3528 std::optional<QualType> Time_tTy = lookupTy(
"time_t");
3529 std::optional<QualType> ConstTime_tPtrTy =
3530 getPointerTy(getConstTy(Time_tTy));
3531 std::optional<QualType> ConstTime_tPtrRestrictTy =
3532 getRestrictTy(ConstTime_tPtrTy);
3534 std::optional<QualType> StructTmTy = lookupTy(
"tm");
3535 std::optional<QualType> StructTmPtrTy = getPointerTy(StructTmTy);
3536 std::optional<QualType> StructTmPtrRestrictTy =
3537 getRestrictTy(StructTmPtrTy);
3538 std::optional<QualType> ConstStructTmPtrTy =
3539 getPointerTy(getConstTy(StructTmTy));
3540 std::optional<QualType> ConstStructTmPtrRestrictTy =
3541 getRestrictTy(ConstStructTmPtrTy);
3544 addToFunctionSummaryMap(
3546 Signature(ArgTypes{ConstTime_tPtrTy}, RetType{StructTmPtrTy}),
3547 Summary(NoEvalCall).ArgConstraint(NotNull(ArgNo(0))));
3551 addToFunctionSummaryMap(
3553 Signature(ArgTypes{ConstTime_tPtrRestrictTy, StructTmPtrRestrictTy},
3554 RetType{StructTmPtrTy}),
3556 .ArgConstraint(NotNull(ArgNo(0)))
3557 .ArgConstraint(NotNull(ArgNo(1))));
3560 addToFunctionSummaryMap(
3562 Signature(ArgTypes{ConstStructTmPtrRestrictTy, CharPtrRestrictTy},
3563 RetType{CharPtrTy}),
3565 .ArgConstraint(NotNull(ArgNo(0)))
3566 .ArgConstraint(NotNull(ArgNo(1)))
3567 .ArgConstraint(BufferSize(ArgNo(1),
3568 BVF.getValue(26, IntTy))));
3571 addToFunctionSummaryMap(
3573 Signature(ArgTypes{ConstTime_tPtrTy, CharPtrTy}, RetType{CharPtrTy}),
3575 .ArgConstraint(NotNull(ArgNo(0)))
3576 .ArgConstraint(NotNull(ArgNo(1)))
3577 .ArgConstraint(BufferSize(
3579 BVF.getValue(26, IntTy))));
3583 addToFunctionSummaryMap(
3585 Signature(ArgTypes{ConstTime_tPtrRestrictTy, StructTmPtrRestrictTy},
3586 RetType{StructTmPtrTy}),
3588 .ArgConstraint(NotNull(ArgNo(0)))
3589 .ArgConstraint(NotNull(ArgNo(1))));
3592 addToFunctionSummaryMap(
3593 "gmtime", Signature(ArgTypes{ConstTime_tPtrTy}, RetType{StructTmPtrTy}),
3594 Summary(NoEvalCall).ArgConstraint(NotNull(ArgNo(0))));
3596 std::optional<QualType> Clockid_tTy = lookupTy(
"clockid_t");
3599 addToFunctionSummaryMap(
3601 Signature(ArgTypes{Clockid_tTy, StructTimespecPtrTy}, RetType{IntTy}),
3603 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
3604 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
3605 .ArgConstraint(NotNull(ArgNo(1))));
3607 std::optional<QualType> StructItimervalTy = lookupTy(
"itimerval");
3608 std::optional<QualType> StructItimervalPtrTy =
3609 getPointerTy(StructItimervalTy);
3612 addToFunctionSummaryMap(
3614 Signature(ArgTypes{IntTy, StructItimervalPtrTy}, RetType{IntTy}),
3616 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
3617 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
3618 .ArgConstraint(NotNull(ArgNo(1))));
3620 std::optional<QualType> Pthread_cond_tTy = lookupTy(
"pthread_cond_t");
3621 std::optional<QualType> Pthread_cond_tPtrTy =
3622 getPointerTy(Pthread_cond_tTy);
3623 std::optional<QualType> Pthread_tTy = lookupTy(
"pthread_t");
3624 std::optional<QualType> Pthread_tPtrTy = getPointerTy(Pthread_tTy);
3625 std::optional<QualType> Pthread_tPtrRestrictTy =
3626 getRestrictTy(Pthread_tPtrTy);
3627 std::optional<QualType> Pthread_mutex_tTy = lookupTy(
"pthread_mutex_t");
3628 std::optional<QualType> Pthread_mutex_tPtrTy =
3629 getPointerTy(Pthread_mutex_tTy);
3630 std::optional<QualType> Pthread_mutex_tPtrRestrictTy =
3631 getRestrictTy(Pthread_mutex_tPtrTy);
3632 std::optional<QualType> Pthread_attr_tTy = lookupTy(
"pthread_attr_t");
3633 std::optional<QualType> Pthread_attr_tPtrTy =
3634 getPointerTy(Pthread_attr_tTy);
3635 std::optional<QualType> ConstPthread_attr_tPtrTy =
3636 getPointerTy(getConstTy(Pthread_attr_tTy));
3637 std::optional<QualType> ConstPthread_attr_tPtrRestrictTy =
3638 getRestrictTy(ConstPthread_attr_tPtrTy);
3639 std::optional<QualType> Pthread_mutexattr_tTy =
3640 lookupTy(
"pthread_mutexattr_t");
3641 std::optional<QualType> ConstPthread_mutexattr_tPtrTy =
3642 getPointerTy(getConstTy(Pthread_mutexattr_tTy));
3643 std::optional<QualType> ConstPthread_mutexattr_tPtrRestrictTy =
3644 getRestrictTy(ConstPthread_mutexattr_tPtrTy);
3646 QualType PthreadStartRoutineTy = getPointerTy(
3648 FunctionProtoType::ExtProtoInfo()));
3652 addToFunctionSummaryMap(
3653 {
"pthread_cond_signal",
"pthread_cond_broadcast"},
3654 Signature(ArgTypes{Pthread_cond_tPtrTy}, RetType{IntTy}),
3655 Summary(NoEvalCall).ArgConstraint(NotNull(ArgNo(0))));
3660 addToFunctionSummaryMap(
3662 Signature(ArgTypes{Pthread_tPtrRestrictTy,
3663 ConstPthread_attr_tPtrRestrictTy,
3664 PthreadStartRoutineTy, VoidPtrRestrictTy},
3667 .ArgConstraint(NotNull(ArgNo(0)))
3668 .ArgConstraint(NotNull(ArgNo(2))));
3672 addToFunctionSummaryMap(
3673 {
"pthread_attr_destroy",
"pthread_attr_init"},
3674 Signature(ArgTypes{Pthread_attr_tPtrTy}, RetType{IntTy}),
3675 Summary(NoEvalCall).ArgConstraint(NotNull(ArgNo(0))));
3681 addToFunctionSummaryMap(
3682 {
"pthread_attr_getstacksize",
"pthread_attr_getguardsize"},
3683 Signature(ArgTypes{ConstPthread_attr_tPtrRestrictTy, SizePtrRestrictTy},
3686 .ArgConstraint(NotNull(ArgNo(0)))
3687 .ArgConstraint(NotNull(ArgNo(1))));
3691 addToFunctionSummaryMap(
3692 {
"pthread_attr_setstacksize",
"pthread_attr_setguardsize"},
3693 Signature(ArgTypes{Pthread_attr_tPtrTy, SizeTyCanonTy}, RetType{IntTy}),
3695 .ArgConstraint(NotNull(ArgNo(0)))
3697 ArgumentCondition(1, WithinRange,
Range(0, SizeMax))));
3701 addToFunctionSummaryMap(
3702 "pthread_mutex_init",
3703 Signature(ArgTypes{Pthread_mutex_tPtrRestrictTy,
3704 ConstPthread_mutexattr_tPtrRestrictTy},
3706 Summary(NoEvalCall).ArgConstraint(NotNull(ArgNo(0))));
3712 addToFunctionSummaryMap(
3713 {
"pthread_mutex_destroy",
"pthread_mutex_lock",
"pthread_mutex_trylock",
3714 "pthread_mutex_unlock"},
3715 Signature(ArgTypes{Pthread_mutex_tPtrTy}, RetType{IntTy}),
3716 Summary(NoEvalCall).ArgConstraint(NotNull(ArgNo(0))));
3720 if (AddTestFunctions) {
3721 const RangeInt IntMin = BVF.
getMinValue(IntTy)->getLimitedValue();
3723 addToFunctionSummaryMap(
3724 "__not_null", Signature(ArgTypes{IntPtrTy}, RetType{IntTy}),
3725 Summary(EvalCallAsPure).ArgConstraint(NotNull(ArgNo(0))));
3727 addToFunctionSummaryMap(
3728 "__not_null_buffer",
3729 Signature(ArgTypes{VoidPtrTy, IntTy, IntTy}, RetType{IntTy}),
3730 Summary(EvalCallAsPure)
3731 .ArgConstraint(NotNullBuffer(ArgNo(0), ArgNo(1), ArgNo(2))));
3734 addToFunctionSummaryMap(
3735 "__single_val_0", Signature(ArgTypes{IntTy}, RetType{IntTy}),
3736 Summary(EvalCallAsPure)
3737 .ArgConstraint(ArgumentCondition(0U, WithinRange, SingleValue(0))));
3738 addToFunctionSummaryMap(
3739 "__single_val_1", Signature(ArgTypes{IntTy}, RetType{IntTy}),
3740 Summary(EvalCallAsPure)
3741 .ArgConstraint(ArgumentCondition(0U, WithinRange, SingleValue(1))));
3742 addToFunctionSummaryMap(
3743 "__range_1_2", Signature(ArgTypes{IntTy}, RetType{IntTy}),
3744 Summary(EvalCallAsPure)
3745 .ArgConstraint(ArgumentCondition(0U, WithinRange,
Range(1, 2))));
3746 addToFunctionSummaryMap(
3747 "__range_m1_1", Signature(ArgTypes{IntTy}, RetType{IntTy}),
3748 Summary(EvalCallAsPure)
3749 .ArgConstraint(ArgumentCondition(0U, WithinRange,
Range(-1, 1))));
3750 addToFunctionSummaryMap(
3751 "__range_m2_m1", Signature(ArgTypes{IntTy}, RetType{IntTy}),
3752 Summary(EvalCallAsPure)
3753 .ArgConstraint(ArgumentCondition(0U, WithinRange,
Range(-2, -1))));
3754 addToFunctionSummaryMap(
3755 "__range_m10_10", Signature(ArgTypes{IntTy}, RetType{IntTy}),
3756 Summary(EvalCallAsPure)
3757 .ArgConstraint(ArgumentCondition(0U, WithinRange,
Range(-10, 10))));
3758 addToFunctionSummaryMap(
"__range_m1_inf",
3759 Signature(ArgTypes{IntTy}, RetType{IntTy}),
3760 Summary(EvalCallAsPure)
3761 .ArgConstraint(ArgumentCondition(
3762 0U, WithinRange,
Range(-1, IntMax))));
3763 addToFunctionSummaryMap(
"__range_0_inf",
3764 Signature(ArgTypes{IntTy}, RetType{IntTy}),
3765 Summary(EvalCallAsPure)
3766 .ArgConstraint(ArgumentCondition(
3767 0U, WithinRange,
Range(0, IntMax))));
3768 addToFunctionSummaryMap(
"__range_1_inf",
3769 Signature(ArgTypes{IntTy}, RetType{IntTy}),
3770 Summary(EvalCallAsPure)
3771 .ArgConstraint(ArgumentCondition(
3772 0U, WithinRange,
Range(1, IntMax))));
3773 addToFunctionSummaryMap(
"__range_minf_m1",
3774 Signature(ArgTypes{IntTy}, RetType{IntTy}),
3775 Summary(EvalCallAsPure)
3776 .ArgConstraint(ArgumentCondition(
3777 0U, WithinRange,
Range(IntMin, -1))));
3778 addToFunctionSummaryMap(
"__range_minf_0",
3779 Signature(ArgTypes{IntTy}, RetType{IntTy}),
3780 Summary(EvalCallAsPure)
3781 .ArgConstraint(ArgumentCondition(
3782 0U, WithinRange,
Range(IntMin, 0))));
3783 addToFunctionSummaryMap(
"__range_minf_1",
3784 Signature(ArgTypes{IntTy}, RetType{IntTy}),
3785 Summary(EvalCallAsPure)
3786 .ArgConstraint(ArgumentCondition(
3787 0U, WithinRange,
Range(IntMin, 1))));
3788 addToFunctionSummaryMap(
"__range_1_2__4_6",
3789 Signature(ArgTypes{IntTy}, RetType{IntTy}),
3790 Summary(EvalCallAsPure)
3791 .ArgConstraint(ArgumentCondition(
3792 0U, WithinRange,
Range({1, 2}, {4, 6}))));
3793 addToFunctionSummaryMap(
3794 "__range_1_2__4_inf", Signature(ArgTypes{IntTy}, RetType{IntTy}),
3795 Summary(EvalCallAsPure)
3796 .ArgConstraint(ArgumentCondition(0U, WithinRange,
3797 Range({1, 2}, {4, IntMax}))));
3800 addToFunctionSummaryMap(
3801 "__single_val_out_0", Signature(ArgTypes{IntTy}, RetType{IntTy}),
3802 Summary(EvalCallAsPure)
3803 .ArgConstraint(ArgumentCondition(0U, OutOfRange, SingleValue(0))));
3804 addToFunctionSummaryMap(
3805 "__single_val_out_1", Signature(ArgTypes{IntTy}, RetType{IntTy}),
3806 Summary(EvalCallAsPure)
3807 .ArgConstraint(ArgumentCondition(0U, OutOfRange, SingleValue(1))));
3808 addToFunctionSummaryMap(
3809 "__range_out_1_2", Signature(ArgTypes{IntTy}, RetType{IntTy}),
3810 Summary(EvalCallAsPure)
3811 .ArgConstraint(ArgumentCondition(0U, OutOfRange,
Range(1, 2))));
3812 addToFunctionSummaryMap(
3813 "__range_out_m1_1", Signature(ArgTypes{IntTy}, RetType{IntTy}),
3814 Summary(EvalCallAsPure)
3815 .ArgConstraint(ArgumentCondition(0U, OutOfRange,
Range(-1, 1))));
3816 addToFunctionSummaryMap(
3817 "__range_out_m2_m1", Signature(ArgTypes{IntTy}, RetType{IntTy}),
3818 Summary(EvalCallAsPure)
3819 .ArgConstraint(ArgumentCondition(0U, OutOfRange,
Range(-2, -1))));
3820 addToFunctionSummaryMap(
3821 "__range_out_m10_10", Signature(ArgTypes{IntTy}, RetType{IntTy}),
3822 Summary(EvalCallAsPure)
3823 .ArgConstraint(ArgumentCondition(0U, OutOfRange,
Range(-10, 10))));
3824 addToFunctionSummaryMap(
"__range_out_m1_inf",
3825 Signature(ArgTypes{IntTy}, RetType{IntTy}),
3826 Summary(EvalCallAsPure)
3827 .ArgConstraint(ArgumentCondition(
3828 0U, OutOfRange,
Range(-1, IntMax))));
3829 addToFunctionSummaryMap(
"__range_out_0_inf",
3830 Signature(ArgTypes{IntTy}, RetType{IntTy}),
3831 Summary(EvalCallAsPure)
3832 .ArgConstraint(ArgumentCondition(
3833 0U, OutOfRange,
Range(0, IntMax))));
3834 addToFunctionSummaryMap(
"__range_out_1_inf",
3835 Signature(ArgTypes{IntTy}, RetType{IntTy}),
3836 Summary(EvalCallAsPure)
3837 .ArgConstraint(ArgumentCondition(
3838 0U, OutOfRange,
Range(1, IntMax))));
3839 addToFunctionSummaryMap(
"__range_out_minf_m1",
3840 Signature(ArgTypes{IntTy}, RetType{IntTy}),
3841 Summary(EvalCallAsPure)
3842 .ArgConstraint(ArgumentCondition(
3843 0U, OutOfRange,
Range(IntMin, -1))));
3844 addToFunctionSummaryMap(
"__range_out_minf_0",
3845 Signature(ArgTypes{IntTy}, RetType{IntTy}),
3846 Summary(EvalCallAsPure)
3847 .ArgConstraint(ArgumentCondition(
3848 0U, OutOfRange,
Range(IntMin, 0))));
3849 addToFunctionSummaryMap(
"__range_out_minf_1",
3850 Signature(ArgTypes{IntTy}, RetType{IntTy}),
3851 Summary(EvalCallAsPure)
3852 .ArgConstraint(ArgumentCondition(
3853 0U, OutOfRange,
Range(IntMin, 1))));
3854 addToFunctionSummaryMap(
"__range_out_1_2__4_6",
3855 Signature(ArgTypes{IntTy}, RetType{IntTy}),
3856 Summary(EvalCallAsPure)
3857 .ArgConstraint(ArgumentCondition(
3858 0U, OutOfRange,
Range({1, 2}, {4, 6}))));
3859 addToFunctionSummaryMap(
3860 "__range_out_1_2__4_inf", Signature(ArgTypes{IntTy}, RetType{IntTy}),
3861 Summary(EvalCallAsPure)
3863 ArgumentCondition(0U, OutOfRange,
Range({1, 2}, {4, IntMax}))));
3866 addToFunctionSummaryMap(
3867 "__within", Signature(ArgTypes{IntTy}, RetType{IntTy}),
3868 Summary(EvalCallAsPure)
3869 .ArgConstraint(ArgumentCondition(0U, WithinRange, SingleValue(1))));
3870 addToFunctionSummaryMap(
3871 "__out_of", Signature(ArgTypes{IntTy}, RetType{IntTy}),
3872 Summary(EvalCallAsPure)
3873 .ArgConstraint(ArgumentCondition(0U, OutOfRange, SingleValue(1))));
3875 addToFunctionSummaryMap(
3876 "__two_constrained_args",
3877 Signature(ArgTypes{IntTy, IntTy}, RetType{IntTy}),
3878 Summary(EvalCallAsPure)
3879 .ArgConstraint(ArgumentCondition(0U, WithinRange, SingleValue(1)))
3880 .ArgConstraint(ArgumentCondition(1U, WithinRange, SingleValue(1))));
3881 addToFunctionSummaryMap(
3882 "__arg_constrained_twice", Signature(ArgTypes{IntTy}, RetType{IntTy}),
3883 Summary(EvalCallAsPure)
3884 .ArgConstraint(ArgumentCondition(0U, OutOfRange, SingleValue(1)))
3885 .ArgConstraint(ArgumentCondition(0U, OutOfRange, SingleValue(2))));
3886 addToFunctionSummaryMap(
3888 Signature(ArgTypes{
Irrelevant, IntTy}, RetType{IntTy}),
3889 Summary(EvalCallAsPure).ArgConstraint(NotNull(ArgNo(0))));
3890 addToFunctionSummaryMap(
3892 Signature(ArgTypes{VoidPtrTy, ConstCharPtrTy}, RetType{IntTy}),
3893 Summary(EvalCallAsPure)
3894 .ArgConstraint(NotNull(ArgNo(0)))
3895 .ArgConstraint(NotNull(ArgNo(1))));
3896 addToFunctionSummaryMap(
3897 "__buf_size_arg_constraint",
3898 Signature(ArgTypes{ConstVoidPtrTy, SizeTyCanonTy}, RetType{IntTy}),
3899 Summary(EvalCallAsPure)
3901 BufferSize(ArgNo(0), ArgNo(1))));
3902 addToFunctionSummaryMap(
3903 "__buf_size_arg_constraint_mul",
3904 Signature(ArgTypes{ConstVoidPtrTy, SizeTyCanonTy, SizeTyCanonTy},
3906 Summary(EvalCallAsPure)
3907 .ArgConstraint(BufferSize(ArgNo(0), ArgNo(1),
3909 addToFunctionSummaryMap(
3910 "__buf_size_arg_constraint_concrete",
3911 Signature(ArgTypes{ConstVoidPtrTy}, RetType{IntTy}),
3912 Summary(EvalCallAsPure)
3913 .ArgConstraint(BufferSize(ArgNo(0),
3914 BVF.getValue(10, IntTy))));
3915 addToFunctionSummaryMap(
3916 {
"__test_restrict_param_0",
"__test_restrict_param_1",
3917 "__test_restrict_param_2"},
3918 Signature(ArgTypes{VoidPtrRestrictTy}, RetType{VoidTy}),
3919 Summary(EvalCallAsPure));
3922 addToFunctionSummaryMap(
3923 "__test_case_note", Signature(ArgTypes{}, RetType{IntTy}),
3924 Summary(EvalCallAsPure)
3925 .Case({ReturnValueCondition(WithinRange, SingleValue(0))},
3926 ErrnoIrrelevant,
"Function returns 0")
3927 .Case({ReturnValueCondition(WithinRange, SingleValue(1))},
3928 ErrnoIrrelevant,
"Function returns 1"));
3929 addToFunctionSummaryMap(
3930 "__test_case_range_1_2__4_6",
3931 Signature(ArgTypes{IntTy}, RetType{IntTy}),
3932 Summary(EvalCallAsPure)
3933 .Case({ArgumentCondition(0U, WithinRange,
3934 IntRangeVector{{IntMin, 0}, {3, 3}}),
3935 ReturnValueCondition(WithinRange, SingleValue(1))},
3937 .Case({ArgumentCondition(0U, WithinRange,
3938 IntRangeVector{{3, 3}, {7, IntMax}}),
3939 ReturnValueCondition(WithinRange, SingleValue(2))},
3941 .Case({ArgumentCondition(0U, WithinRange,
3942 IntRangeVector{{IntMin, 0}, {7, IntMax}}),
3943 ReturnValueCondition(WithinRange, SingleValue(3))},
3945 .Case({ArgumentCondition(
3947 IntRangeVector{{IntMin, 0}, {3, 3}, {7, IntMax}}),
3948 ReturnValueCondition(WithinRange, SingleValue(4))},
3953void ento::registerStdCLibraryFunctionsChecker(CheckerManager &mgr) {
3957 Checker->DisplayLoadedSummaries =
3958 Opts.getCheckerBooleanOption(Checker,
"DisplayLoadedSummaries");
3959 Checker->ModelPOSIX = Opts.getCheckerBooleanOption(Checker,
"ModelPOSIX");
3960 Checker->ShouldAssumeControlledEnvironment =
3961 Opts.ShouldAssumeControlledEnvironment;
3964bool ento::shouldRegisterStdCLibraryFunctionsChecker(
3965 const CheckerManager &mgr) {
3969void ento::registerStdCLibraryFunctionsTesterChecker(CheckerManager &mgr) {
3970 auto *Checker = mgr.
getChecker<StdLibraryFunctionsChecker>();
3971 Checker->AddTestFunctions =
true;
3974bool ento::shouldRegisterStdCLibraryFunctionsTesterChecker(
3975 const CheckerManager &mgr) {
static std::string getFunctionName(const CallEvent &Call)
static bool isInvalid(LocType Loc, bool *Invalid)
TranslationUnitDecl * getTranslationUnitDecl() const
QualType getPointerType(QualType T) const
Return the uniqued reference to the type for a pointer to the specified type.
const LangOptions & getLangOpts() const
CanQualType getCanonicalSizeType() const
QualType getRestrictType(QualType T) const
Return the uniqued reference to the type for a restrict qualified type.
CanQualType getCanonicalTypeDeclType(const TypeDecl *TD) const
CanQualType UnsignedCharTy
CanQualType UnsignedIntTy
QualType getFunctionType(QualType ResultTy, ArrayRef< QualType > Args, const FunctionProtoType::ExtProtoInfo &EPI) const
Return a normal function type with a typed argument list.
static Opcode negateComparisonOp(Opcode Opc)
BinaryOperatorKind Opcode
lookup_result lookup(DeclarationName Name) const
lookup - Find the declarations (if any) with the given Name in this context.
ASTContext & getASTContext() const LLVM_READONLY
void print(raw_ostream &Out, unsigned Indentation=0, bool PrintInstantiation=false) const
const ParmVarDecl * getParamDecl(unsigned i) const
QualType getReturnType() const
FunctionDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
unsigned getNumParams() const
Return the number of parameters this function must have based on its FunctionType.
size_t param_size() const
IdentifierInfo & get(StringRef Name)
Return the identifier token info for the specified named identifier.
QualType withConst() const
QualType getCanonicalType() const
APSIntPtr getMaxValue(const llvm::APSInt &v)
APSIntPtr getMinValue(const llvm::APSInt &v)
ASTContext & getContext() const
const AnalyzerOptions & getAnalyzerOptions() const
CHECKER * registerChecker(AT &&...Args)
Register a single-part checker (derived from Checker): construct its singleton instance,...
CheckerNameRef getCurrentCheckerName() const
CHECKER * getChecker(AT &&...Args)
If the the singleton instance of a checker class is not yet constructed, then construct it (with the ...
Simple checker classes that implement one frontend (i.e.
ProgramStateRef assumeInclusiveRange(ProgramStateRef State, NonLoc Value, const llvm::APSInt &From, const llvm::APSInt &To, bool InBound)
const ProgramStateRef & getState() const
unsigned succ_size() const
const ExplodedNode * getErrorNode() const
void markNotInteresting(SymbolRef sym)
bool isInteresting(SymbolRef sym) const
SValBuilder & getSValBuilder()
ConstraintManager & getConstraintManager()
BasicValueFactory & getBasicValueFactory()
ASTContext & getContext()
nonloc::ConcreteInt makeIntVal(const IntegerLiteral *integer)
SVal evalCast(SVal V, QualType CastTy, QualType OriginalTy)
Cast a given SVal to another SVal using given QualType's.
QualType getConditionType() const
DefinedOrUnknownSVal conjureSymbolVal(const void *symbolTag, ConstCFGElementRef elem, const LocationContext *LCtx, unsigned count)
Create a new symbol with a unique 'name'.
SVal evalBinOp(ProgramStateRef state, BinaryOperator::Opcode op, SVal lhs, SVal rhs, QualType type)
std::optional< T > getAs() const
Convert to the specified SVal type, returning std::nullopt if this SVal is not of the desired type.
T castAs() const
Convert to the specified SVal type, asserting that this SVal is of the desired type.
bool trackExpressionValue(const ExplodedNode *N, const Expr *E, PathSensitiveBugReport &R, TrackingOptions Opts={})
Attempts to add visitors to track expression value back to its point of origin.
std::optional< Loc > getErrnoLoc(ProgramStateRef State)
Returns the location that points to the MemoryRegion where the 'errno' value is stored.
ProgramStateRef setErrnoForStdSuccess(ProgramStateRef State, CheckerContext &C)
Set errno state for the common case when a standard function is successful.
ProgramStateRef setErrnoStdMustBeChecked(ProgramStateRef State, CheckerContext &C, ConstCFGElementRef Elem)
Set errno state for the common case when a standard function indicates failure only by errno.
ProgramStateRef setErrnoState(ProgramStateRef State, ErrnoCheckState EState)
Set the errno check state, do not modify the errno value.
ProgramStateRef setErrnoForStdFailure(ProgramStateRef State, CheckerContext &C, NonLoc ErrnoSym)
Set errno state for the common case when a standard function fails.
@ Irrelevant
We do not know anything about 'errno'.
IntrusiveRefCntPtr< const ProgramState > ProgramStateRef
SVal getDynamicExtentWithOffset(ProgramStateRef State, SVal BufV)
Get the dynamic extent for a symbolic value that represents a buffer.
@ OS
Indicates that the tracking object is a descendant of a referenced-counted OSObject,...
std::optional< int > tryExpandAsInteger(StringRef Macro, const Preprocessor &PP)
Try to parse the value of a defined preprocessor macro.
bool IsNonNull(InterpState &S, CodePtr OpPC)
bool Ret(InterpState &S, CodePtr &PC)
bool matches(const til::SExpr *E1, const til::SExpr *E2)
The JSON file list parser is used to communicate input to InstallAPI.
bool isa(CodeGen::Address addr)
@ Result
The result type of a method or function.
const FunctionProtoType * T
U cast(CodeGen::Address addr)
int const char * function