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");
722 "We should only have canonical types in the spec");
724 static void assertRetTypeSuitableForSignature(QualType T) {
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 LLVM_ATTRIBUTE_MINSIZE
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: {
1481 SVal
V =
C.getSValBuilder().conjureSymbolVal(
Call,
C.blockCount());
1482 State = State->BindExpr(CE,
C.getStackFrame(),
V);
1484 C.addTransition(State);
1493 llvm_unreachable(
"Unknown invalidation kind!");
1496bool StdLibraryFunctionsChecker::Signature::matches(
1497 const FunctionDecl *FD)
const {
1510 auto RemoveRestrict = [&FD](QualType T) {
1517 if (!isIrrelevant(RetTy)) {
1519 if (RetTy != FDRetTy)
1524 for (
auto [Idx, ArgTy] : llvm::enumerate(ArgTys)) {
1525 if (isIrrelevant(ArgTy))
1529 if (ArgTy != FDArgTy)
1536std::optional<StdLibraryFunctionsChecker::Summary>
1537StdLibraryFunctionsChecker::findFunctionSummary(
const FunctionDecl *FD,
1538 CheckerContext &
C)
const {
1540 return std::nullopt;
1542 initFunctionSummaries(
C);
1545 if (FSMI == FunctionSummaryMap.end())
1546 return std::nullopt;
1547 return FSMI->second;
1550std::optional<StdLibraryFunctionsChecker::Summary>
1551StdLibraryFunctionsChecker::findFunctionSummary(
const CallEvent &
Call,
1552 CheckerContext &
C)
const {
1553 const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(
Call.getDecl());
1555 return std::nullopt;
1556 return findFunctionSummary(FD,
C);
1559void StdLibraryFunctionsChecker::initFunctionSummaries(
1560 CheckerContext &
C)
const {
1561 if (SummariesInitialized)
1563 SummariesInitialized =
true;
1565 SValBuilder &SVB =
C.getSValBuilder();
1568 Preprocessor &PP =
C.getPreprocessor();
1572 const ASTContext &ACtx;
1575 LookupType(
const ASTContext &ACtx) : ACtx(ACtx) {}
1578 std::optional<QualType> operator()(StringRef Name) {
1579 IdentifierInfo &II = ACtx.
Idents.
get(Name);
1581 if (LookupRes.empty())
1582 return std::nullopt;
1589 for (Decl *D : LookupRes)
1590 if (
auto *TD = dyn_cast<TypedefNameDecl>(D))
1597 for (Decl *D : LookupRes)
1598 if (
auto *TD = dyn_cast<TypeDecl>(D))
1600 return std::nullopt;
1606 class GetRestrictTy {
1607 const ASTContext &ACtx;
1610 GetRestrictTy(
const ASTContext &ACtx) : ACtx(ACtx) {}
1611 QualType operator()(QualType Ty) {
1614 std::optional<QualType> operator()(std::optional<QualType> Ty) {
1616 return operator()(*Ty);
1617 return std::nullopt;
1619 } getRestrictTy(ACtx);
1620 class GetPointerTy {
1621 const ASTContext &ACtx;
1624 GetPointerTy(
const ASTContext &ACtx) : ACtx(ACtx) {}
1625 QualType operator()(QualType Ty) {
return ACtx.
getPointerType(Ty); }
1626 std::optional<QualType> operator()(std::optional<QualType> Ty) {
1628 return operator()(*Ty);
1629 return std::nullopt;
1631 } getPointerTy(ACtx);
1634 std::optional<QualType> operator()(std::optional<QualType> Ty) {
1635 return Ty ? std::optional<QualType>(Ty->withConst()) : std::nullopt;
1637 QualType operator()(QualType Ty) {
return Ty.
withConst(); }
1640 BasicValueFactory &BVF;
1643 GetMaxValue(BasicValueFactory &BVF) : BVF(BVF) {}
1644 std::optional<RangeInt> operator()(QualType Ty) {
1647 std::optional<RangeInt> operator()(std::optional<QualType> Ty) {
1649 return operator()(*Ty);
1651 return std::nullopt;
1662 const QualType VoidTy = ACtx.
VoidTy;
1663 const QualType CharTy = ACtx.
CharTy;
1664 const QualType WCharTy = ACtx.
WCharTy;
1665 const QualType IntTy = ACtx.
IntTy;
1667 const QualType LongTy = ACtx.
LongTy;
1670 const QualType VoidPtrTy = getPointerTy(VoidTy);
1671 const QualType IntPtrTy = getPointerTy(IntTy);
1672 const QualType UnsignedIntPtrTy =
1673 getPointerTy(UnsignedIntTy);
1674 const QualType VoidPtrRestrictTy = getRestrictTy(VoidPtrTy);
1675 const QualType ConstVoidPtrTy =
1676 getPointerTy(getConstTy(VoidTy));
1677 const QualType CharPtrTy = getPointerTy(CharTy);
1678 const QualType CharPtrRestrictTy = getRestrictTy(CharPtrTy);
1679 const QualType ConstCharPtrTy =
1680 getPointerTy(getConstTy(CharTy));
1681 const QualType ConstCharPtrRestrictTy = getRestrictTy(ConstCharPtrTy);
1682 const QualType Wchar_tPtrTy = getPointerTy(WCharTy);
1683 const QualType ConstWchar_tPtrTy =
1684 getPointerTy(getConstTy(WCharTy));
1685 const QualType ConstVoidPtrRestrictTy = getRestrictTy(ConstVoidPtrTy);
1686 const QualType SizePtrTy = getPointerTy(SizeTyCanonTy);
1687 const QualType SizePtrRestrictTy = getRestrictTy(SizePtrTy);
1689 const RangeInt IntMax = BVF.
getMaxValue(IntTy)->getLimitedValue();
1690 const RangeInt UnsignedIntMax =
1691 BVF.
getMaxValue(UnsignedIntTy)->getLimitedValue();
1692 const RangeInt LongMax = BVF.
getMaxValue(LongTy)->getLimitedValue();
1693 const RangeInt SizeMax = BVF.
getMaxValue(SizeTyCanonTy)->getLimitedValue();
1701 const RangeInt UCharRangeMax =
1711 struct AddToFunctionSummaryMap {
1712 const ASTContext &ACtx;
1713 FunctionSummaryMapType ⤅
1714 bool DisplayLoadedSummaries;
1715 AddToFunctionSummaryMap(
const ASTContext &ACtx, FunctionSummaryMapType &FSM,
1716 bool DisplayLoadedSummaries)
1717 : ACtx(ACtx), Map(FSM), DisplayLoadedSummaries(DisplayLoadedSummaries) {
1725 bool operator()(StringRef Name, Signature Sign, Summary Sum) {
1726 if (Sign.isInvalid())
1728 IdentifierInfo &II = ACtx.
Idents.
get(Name);
1730 if (LookupRes.empty())
1732 for (Decl *D : LookupRes) {
1733 if (
auto *FD = dyn_cast<FunctionDecl>(D)) {
1734 if (Sum.matchesAndSet(Sign, FD)) {
1736 assert(Res.second &&
"Function already has a summary set!");
1738 if (DisplayLoadedSummaries) {
1739 llvm::errs() <<
"Loaded summary for: ";
1740 FD->
print(llvm::errs());
1741 llvm::errs() <<
"\n";
1751 void operator()(ArrayRef<StringRef> Names, Signature Sign, Summary Sum) {
1752 for (StringRef Name : Names)
1753 operator()(Name, Sign, Sum);
1755 } addToFunctionSummaryMap(ACtx, FunctionSummaryMap, DisplayLoadedSummaries);
1758 auto ArgumentCondition = [](ArgNo ArgN, RangeKind
Kind, IntRangeVector Ranges,
1759 StringRef Desc =
"") {
1760 return std::make_shared<RangeConstraint>(ArgN, Kind, Ranges, Desc);
1762 auto BufferSize = [](
auto... Args) {
1763 return std::make_shared<BufferSizeConstraint>(Args...);
1766 auto operator()(RangeKind Kind, IntRangeVector Ranges) {
1767 return std::make_shared<RangeConstraint>(Ret, Kind, Ranges);
1770 return std::make_shared<ComparisonConstraint>(Ret, Op, OtherArgN);
1772 } ReturnValueCondition;
1774 auto operator()(RangeInt b, RangeInt e) {
1775 return IntRangeVector{std::pair<RangeInt, RangeInt>{b, e}};
1777 auto operator()(RangeInt b, std::optional<RangeInt> e) {
1779 return IntRangeVector{std::pair<RangeInt, RangeInt>{b, *e}};
1780 return IntRangeVector{};
1782 auto operator()(std::pair<RangeInt, RangeInt> i0,
1783 std::pair<RangeInt, std::optional<RangeInt>> i1) {
1785 return IntRangeVector{i0, {i1.first, *(i1.second)}};
1786 return IntRangeVector{i0};
1789 auto SingleValue = [](RangeInt v) {
1790 return IntRangeVector{std::pair<RangeInt, RangeInt>{v, v}};
1792 auto LessThanOrEq = BO_LE;
1793 auto NotNull = [&](ArgNo ArgN) {
1794 return std::make_shared<NullnessConstraint>(ArgN);
1796 auto IsNull = [&](ArgNo ArgN) {
1797 return std::make_shared<NullnessConstraint>(ArgN,
false);
1799 auto NotNullBuffer = [&](ArgNo ArgN, ArgNo SizeArg1N,
1800 std::optional<ArgNo> SizeArg2N = std::nullopt) {
1801 return std::make_shared<BufferNullnessConstraint>(ArgN, SizeArg1N,
1805 std::optional<QualType> FileTy = lookupTy(
"FILE");
1806 std::optional<QualType> FilePtrTy = getPointerTy(FileTy);
1807 std::optional<QualType> FilePtrRestrictTy = getRestrictTy(FilePtrTy);
1809 std::optional<QualType> FPosTTy = lookupTy(
"fpos_t");
1810 std::optional<QualType> FPosTPtrTy = getPointerTy(FPosTTy);
1811 std::optional<QualType> ConstFPosTPtrTy = getPointerTy(getConstTy(FPosTTy));
1812 std::optional<QualType> FPosTPtrRestrictTy = getRestrictTy(FPosTPtrTy);
1814 constexpr llvm::StringLiteral GenericSuccessMsg(
1815 "Assuming that '{0}' is successful");
1816 constexpr llvm::StringLiteral GenericFailureMsg(
"Assuming that '{0}' fails");
1833 addToFunctionSummaryMap(
1834 "isalnum", Signature(ArgTypes{IntTy}, RetType{IntTy}),
1835 Summary(EvalCallAsPure)
1837 .Case({ArgumentCondition(0U, WithinRange,
1838 {{
'0',
'9'}, {
'A',
'Z'}, {
'a',
'z'}}),
1839 ReturnValueCondition(OutOfRange, SingleValue(0))},
1840 ErrnoIrrelevant,
"Assuming the character is alphanumeric")
1844 .Case({ArgumentCondition(0U, WithinRange, {{128, UCharRangeMax}})},
1849 {{
'0',
'9'}, {
'A',
'Z'}, {
'a',
'z'}, {128, UCharRangeMax}}),
1850 ReturnValueCondition(WithinRange, SingleValue(0))},
1851 ErrnoIrrelevant,
"Assuming the character is non-alphanumeric")
1852 .ArgConstraint(ArgumentCondition(0U, WithinRange,
1853 {{EOFv, EOFv}, {0, UCharRangeMax}},
1854 "an unsigned char value or EOF")));
1855 addToFunctionSummaryMap(
1856 "isalpha", Signature(ArgTypes{IntTy}, RetType{IntTy}),
1857 Summary(EvalCallAsPure)
1858 .Case({ArgumentCondition(0U, WithinRange, {{
'A',
'Z'}, {
'a',
'z'}}),
1859 ReturnValueCondition(OutOfRange, SingleValue(0))},
1860 ErrnoIrrelevant,
"Assuming the character is alphabetical")
1862 .Case({ArgumentCondition(0U, WithinRange, {{128, UCharRangeMax}})},
1864 .Case({ArgumentCondition(
1866 {{
'A',
'Z'}, {
'a',
'z'}, {128, UCharRangeMax}}),
1867 ReturnValueCondition(WithinRange, SingleValue(0))},
1868 ErrnoIrrelevant,
"Assuming the character is non-alphabetical"));
1869 addToFunctionSummaryMap(
1870 "isascii", Signature(ArgTypes{IntTy}, RetType{IntTy}),
1871 Summary(EvalCallAsPure)
1872 .Case({ArgumentCondition(0U, WithinRange,
Range(0, 127)),
1873 ReturnValueCondition(OutOfRange, SingleValue(0))},
1874 ErrnoIrrelevant,
"Assuming the character is an ASCII character")
1875 .Case({ArgumentCondition(0U, OutOfRange,
Range(0, 127)),
1876 ReturnValueCondition(WithinRange, SingleValue(0))},
1878 "Assuming the character is not an ASCII character"));
1879 addToFunctionSummaryMap(
1880 "isblank", Signature(ArgTypes{IntTy}, RetType{IntTy}),
1881 Summary(EvalCallAsPure)
1882 .Case({ArgumentCondition(0U, WithinRange, {{
'\t',
'\t'}, {
' ',
' '}}),
1883 ReturnValueCondition(OutOfRange, SingleValue(0))},
1884 ErrnoIrrelevant,
"Assuming the character is a blank character")
1885 .Case({ArgumentCondition(0U, OutOfRange, {{
'\t',
'\t'}, {
' ',
' '}}),
1886 ReturnValueCondition(WithinRange, SingleValue(0))},
1888 "Assuming the character is not a blank character"));
1889 addToFunctionSummaryMap(
1890 "iscntrl", Signature(ArgTypes{IntTy}, RetType{IntTy}),
1891 Summary(EvalCallAsPure)
1892 .Case({ArgumentCondition(0U, WithinRange, {{0, 32}, {127, 127}}),
1893 ReturnValueCondition(OutOfRange, SingleValue(0))},
1895 "Assuming the character is a control character")
1896 .Case({ArgumentCondition(0U, OutOfRange, {{0, 32}, {127, 127}}),
1897 ReturnValueCondition(WithinRange, SingleValue(0))},
1899 "Assuming the character is not a control character"));
1900 addToFunctionSummaryMap(
1901 "isdigit", Signature(ArgTypes{IntTy}, RetType{IntTy}),
1902 Summary(EvalCallAsPure)
1903 .Case({ArgumentCondition(0U, WithinRange,
Range(
'0',
'9')),
1904 ReturnValueCondition(OutOfRange, SingleValue(0))},
1905 ErrnoIrrelevant,
"Assuming the character is a digit")
1906 .Case({ArgumentCondition(0U, OutOfRange,
Range(
'0',
'9')),
1907 ReturnValueCondition(WithinRange, SingleValue(0))},
1908 ErrnoIrrelevant,
"Assuming the character is not a digit"));
1909 addToFunctionSummaryMap(
1910 "isgraph", Signature(ArgTypes{IntTy}, RetType{IntTy}),
1911 Summary(EvalCallAsPure)
1912 .Case({ArgumentCondition(0U, WithinRange,
Range(33, 126)),
1913 ReturnValueCondition(OutOfRange, SingleValue(0))},
1915 "Assuming the character has graphical representation")
1917 {ArgumentCondition(0U, OutOfRange,
Range(33, 126)),
1918 ReturnValueCondition(WithinRange, SingleValue(0))},
1920 "Assuming the character does not have graphical representation"));
1921 addToFunctionSummaryMap(
1922 "islower", Signature(ArgTypes{IntTy}, RetType{IntTy}),
1923 Summary(EvalCallAsPure)
1925 .Case({ArgumentCondition(0U, WithinRange,
Range(
'a',
'z')),
1926 ReturnValueCondition(OutOfRange, SingleValue(0))},
1927 ErrnoIrrelevant,
"Assuming the character is a lowercase letter")
1929 .Case({ArgumentCondition(0U, WithinRange,
Range(0, 127)),
1930 ArgumentCondition(0U, OutOfRange,
Range(
'a',
'z')),
1931 ReturnValueCondition(WithinRange, SingleValue(0))},
1933 "Assuming the character is not a lowercase letter")
1935 .Case({ArgumentCondition(0U, WithinRange, {{128, UCharRangeMax}})},
1938 .Case({ArgumentCondition(0U, OutOfRange,
Range(0, UCharRangeMax)),
1939 ReturnValueCondition(WithinRange, SingleValue(0))},
1941 addToFunctionSummaryMap(
1942 "isprint", Signature(ArgTypes{IntTy}, RetType{IntTy}),
1943 Summary(EvalCallAsPure)
1944 .Case({ArgumentCondition(0U, WithinRange,
Range(32, 126)),
1945 ReturnValueCondition(OutOfRange, SingleValue(0))},
1946 ErrnoIrrelevant,
"Assuming the character is printable")
1947 .Case({ArgumentCondition(0U, OutOfRange,
Range(32, 126)),
1948 ReturnValueCondition(WithinRange, SingleValue(0))},
1949 ErrnoIrrelevant,
"Assuming the character is non-printable"));
1950 addToFunctionSummaryMap(
1951 "ispunct", Signature(ArgTypes{IntTy}, RetType{IntTy}),
1952 Summary(EvalCallAsPure)
1953 .Case({ArgumentCondition(
1955 {{
'!',
'/'}, {
':',
'@'}, {
'[',
'`'}, {
'{',
'~'}}),
1956 ReturnValueCondition(OutOfRange, SingleValue(0))},
1957 ErrnoIrrelevant,
"Assuming the character is a punctuation mark")
1958 .Case({ArgumentCondition(
1960 {{
'!',
'/'}, {
':',
'@'}, {
'[',
'`'}, {
'{',
'~'}}),
1961 ReturnValueCondition(WithinRange, SingleValue(0))},
1963 "Assuming the character is not a punctuation mark"));
1964 addToFunctionSummaryMap(
1965 "isspace", Signature(ArgTypes{IntTy}, RetType{IntTy}),
1966 Summary(EvalCallAsPure)
1968 .Case({ArgumentCondition(0U, WithinRange, {{9, 13}, {
' ',
' '}}),
1969 ReturnValueCondition(OutOfRange, SingleValue(0))},
1971 "Assuming the character is a whitespace character")
1973 .Case({ArgumentCondition(0U, WithinRange, {{128, UCharRangeMax}})},
1975 .Case({ArgumentCondition(0U, OutOfRange,
1976 {{9, 13}, {
' ',
' '}, {128, UCharRangeMax}}),
1977 ReturnValueCondition(WithinRange, SingleValue(0))},
1979 "Assuming the character is not a whitespace character"));
1980 addToFunctionSummaryMap(
1981 "isupper", Signature(ArgTypes{IntTy}, RetType{IntTy}),
1982 Summary(EvalCallAsPure)
1984 .Case({ArgumentCondition(0U, WithinRange,
Range(
'A',
'Z')),
1985 ReturnValueCondition(OutOfRange, SingleValue(0))},
1987 "Assuming the character is an uppercase letter")
1989 .Case({ArgumentCondition(0U, WithinRange, {{128, UCharRangeMax}})},
1992 .Case({ArgumentCondition(0U, OutOfRange,
1993 {{
'A',
'Z'}, {128, UCharRangeMax}}),
1994 ReturnValueCondition(WithinRange, SingleValue(0))},
1996 "Assuming the character is not an uppercase letter"));
1997 addToFunctionSummaryMap(
1998 "isxdigit", Signature(ArgTypes{IntTy}, RetType{IntTy}),
1999 Summary(EvalCallAsPure)
2000 .Case({ArgumentCondition(0U, WithinRange,
2001 {{
'0',
'9'}, {
'A',
'F'}, {
'a',
'f'}}),
2002 ReturnValueCondition(OutOfRange, SingleValue(0))},
2004 "Assuming the character is a hexadecimal digit")
2005 .Case({ArgumentCondition(0U, OutOfRange,
2006 {{
'0',
'9'}, {
'A',
'F'}, {
'a',
'f'}}),
2007 ReturnValueCondition(WithinRange, SingleValue(0))},
2009 "Assuming the character is not a hexadecimal digit"));
2010 addToFunctionSummaryMap(
2011 "toupper", Signature(ArgTypes{IntTy}, RetType{IntTy}),
2012 Summary(EvalCallAsPure)
2013 .ArgConstraint(ArgumentCondition(0U, WithinRange,
2014 {{EOFv, EOFv}, {0, UCharRangeMax}},
2015 "an unsigned char value or EOF")));
2016 addToFunctionSummaryMap(
2017 "tolower", Signature(ArgTypes{IntTy}, RetType{IntTy}),
2018 Summary(EvalCallAsPure)
2019 .ArgConstraint(ArgumentCondition(0U, WithinRange,
2020 {{EOFv, EOFv}, {0, UCharRangeMax}},
2021 "an unsigned char value or EOF")));
2022 addToFunctionSummaryMap(
2023 "toascii", Signature(ArgTypes{IntTy}, RetType{IntTy}),
2024 Summary(EvalCallAsPure)
2025 .ArgConstraint(ArgumentCondition(0U, WithinRange,
2026 {{EOFv, EOFv}, {0, UCharRangeMax}},
2027 "an unsigned char value or EOF")));
2029 addToFunctionSummaryMap(
2030 "getchar", Signature(ArgTypes{}, RetType{IntTy}),
2032 .Case({ReturnValueCondition(WithinRange,
2033 {{EOFv, EOFv}, {0, UCharRangeMax}})},
2039 .Case({ArgumentCondition(1U, WithinRange,
Range(1, SizeMax)),
2040 ArgumentCondition(2U, WithinRange,
Range(1, SizeMax)),
2041 ReturnValueCondition(BO_LT, ArgNo(2)),
2042 ReturnValueCondition(WithinRange,
Range(0, SizeMax))},
2043 ErrnoNEZeroIrrelevant, GenericFailureMsg)
2044 .Case({ArgumentCondition(1U, WithinRange,
Range(1, SizeMax)),
2045 ReturnValueCondition(BO_EQ, ArgNo(2)),
2046 ReturnValueCondition(WithinRange,
Range(0, SizeMax))},
2047 ErrnoMustNotBeChecked, GenericSuccessMsg)
2048 .Case({ArgumentCondition(1U, WithinRange, SingleValue(0)),
2049 ReturnValueCondition(WithinRange, SingleValue(0))},
2050 ErrnoMustNotBeChecked,
2051 "Assuming that argument 'size' to '{0}' is 0")
2052 .ArgConstraint(NotNullBuffer(ArgNo(0), ArgNo(1), ArgNo(2)))
2053 .ArgConstraint(NotNull(ArgNo(3)))
2054 .ArgConstraint(BufferSize(ArgNo(0), ArgNo(1),
2059 addToFunctionSummaryMap(
"fread",
2060 Signature(ArgTypes{VoidPtrRestrictTy, SizeTyCanonTy,
2061 SizeTyCanonTy, FilePtrRestrictTy},
2062 RetType{SizeTyCanonTy}),
2066 addToFunctionSummaryMap(
2068 Signature(ArgTypes{ConstVoidPtrRestrictTy, SizeTyCanonTy, SizeTyCanonTy,
2070 RetType{SizeTyCanonTy}),
2073 std::optional<QualType> Ssize_tTy = lookupTy(
"ssize_t");
2074 std::optional<RangeInt> Ssize_tMax = getMaxValue(Ssize_tTy);
2078 .Case({ReturnValueCondition(LessThanOrEq, ArgNo(2)),
2079 ReturnValueCondition(WithinRange,
Range(-1, Ssize_tMax))},
2085 addToFunctionSummaryMap(
2087 Signature(ArgTypes{IntTy, VoidPtrTy, SizeTyCanonTy}, RetType{Ssize_tTy}),
2090 addToFunctionSummaryMap(
2092 Signature(ArgTypes{IntTy, ConstVoidPtrTy, SizeTyCanonTy},
2093 RetType{Ssize_tTy}),
2096 auto GetLineSummary =
2098 .Case({ReturnValueCondition(WithinRange,
2099 Range({-1, -1}, {1, Ssize_tMax}))},
2102 QualType CharPtrPtrRestrictTy = getRestrictTy(getPointerTy(CharPtrTy));
2109 addToFunctionSummaryMap(
2112 ArgTypes{CharPtrPtrRestrictTy, SizePtrRestrictTy, FilePtrRestrictTy},
2113 RetType{Ssize_tTy}),
2117 addToFunctionSummaryMap(
2119 Signature(ArgTypes{CharPtrPtrRestrictTy, SizePtrRestrictTy, IntTy,
2121 RetType{Ssize_tTy}),
2125 Summary GetenvSummary =
2127 .ArgConstraint(NotNull(ArgNo(0)))
2128 .Case({NotNull(Ret)}, ErrnoIrrelevant,
2129 "Assuming the environment variable exists");
2131 if (!ShouldAssumeControlledEnvironment)
2132 GetenvSummary.Case({NotNull(Ret)->negate()}, ErrnoIrrelevant,
2133 "Assuming the environment variable does not exist");
2136 addToFunctionSummaryMap(
2137 "getenv", Signature(ArgTypes{ConstCharPtrTy}, RetType{CharPtrTy}),
2138 std::move(GetenvSummary));
2144 addToFunctionSummaryMap(
2145 {
"getc",
"fgetc"}, Signature(ArgTypes{FilePtrTy}, RetType{IntTy}),
2147 .Case({ReturnValueCondition(WithinRange,
2148 {{EOFv, EOFv}, {0, UCharRangeMax}})},
2150 .ArgConstraint(NotNull(ArgNo(0))));
2152 const auto ReturnsZeroOrMinusOne =
2153 ConstraintSet{ReturnValueCondition(WithinRange,
Range(-1, 0))};
2154 const auto ReturnsZero =
2155 ConstraintSet{ReturnValueCondition(WithinRange, SingleValue(0))};
2156 const auto ReturnsMinusOne =
2157 ConstraintSet{ReturnValueCondition(WithinRange, SingleValue(-1))};
2158 const auto ReturnsEOF =
2159 ConstraintSet{ReturnValueCondition(WithinRange, SingleValue(EOFv))};
2160 const auto ReturnsNonnegative =
2161 ConstraintSet{ReturnValueCondition(WithinRange,
Range(0, IntMax))};
2162 const auto ReturnsNonZero =
2163 ConstraintSet{ReturnValueCondition(OutOfRange, SingleValue(0))};
2164 const auto ReturnsFileDescriptor =
2165 ConstraintSet{ReturnValueCondition(WithinRange,
Range(-1, IntMax))};
2166 const auto &ReturnsValidFileDescriptor = ReturnsNonnegative;
2168 auto ValidFileDescriptorOrAtFdcwd = [&](ArgNo ArgN) {
2169 return std::make_shared<RangeConstraint>(
2170 ArgN, WithinRange,
Range({AT_FDCWDv, AT_FDCWDv}, {0, IntMax}),
2171 "a valid file descriptor or AT_FDCWD");
2175 addToFunctionSummaryMap(
2177 Signature(ArgTypes{ConstCharPtrRestrictTy, ConstCharPtrRestrictTy},
2178 RetType{FilePtrTy}),
2180 .Case({NotNull(Ret)}, ErrnoMustNotBeChecked, GenericSuccessMsg)
2181 .Case({
IsNull(Ret)}, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2182 .ArgConstraint(NotNull(ArgNo(0)))
2183 .ArgConstraint(NotNull(ArgNo(1))));
2186 addToFunctionSummaryMap(
2188 Signature(ArgTypes{IntTy, ConstCharPtrTy}, RetType{FilePtrTy}),
2190 .Case({NotNull(Ret)}, ErrnoMustNotBeChecked, GenericSuccessMsg)
2191 .Case({
IsNull(Ret)}, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2192 .ArgConstraint(ArgumentCondition(0, WithinRange,
Range(0, IntMax)))
2193 .ArgConstraint(NotNull(ArgNo(1))));
2196 addToFunctionSummaryMap(
2197 "tmpfile", Signature(ArgTypes{}, RetType{FilePtrTy}),
2199 .Case({NotNull(Ret)}, ErrnoMustNotBeChecked, GenericSuccessMsg)
2200 .Case({
IsNull(Ret)}, ErrnoNEZeroIrrelevant, GenericFailureMsg));
2204 addToFunctionSummaryMap(
2206 Signature(ArgTypes{ConstCharPtrRestrictTy, ConstCharPtrRestrictTy,
2208 RetType{FilePtrTy}),
2210 .Case({ReturnValueCondition(BO_EQ, ArgNo(2))},
2211 ErrnoMustNotBeChecked, GenericSuccessMsg)
2212 .Case({
IsNull(Ret)}, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2213 .ArgConstraint(NotNull(ArgNo(1)))
2214 .ArgConstraint(NotNull(ArgNo(2))));
2217 addToFunctionSummaryMap(
2219 Signature(ArgTypes{ConstCharPtrTy, ConstCharPtrTy}, RetType{FilePtrTy}),
2221 .Case({NotNull(Ret)}, ErrnoMustNotBeChecked, GenericSuccessMsg)
2222 .Case({
IsNull(Ret)}, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2223 .ArgConstraint(NotNull(ArgNo(0)))
2224 .ArgConstraint(NotNull(ArgNo(1))));
2227 addToFunctionSummaryMap(
2228 "fclose", Signature(ArgTypes{FilePtrTy}, RetType{IntTy}),
2230 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2231 .Case(ReturnsEOF, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2232 .ArgConstraint(NotNull(ArgNo(0))));
2235 addToFunctionSummaryMap(
2236 "pclose", Signature(ArgTypes{FilePtrTy}, RetType{IntTy}),
2238 .Case({ReturnValueCondition(WithinRange, {{0, IntMax}})},
2239 ErrnoMustNotBeChecked, GenericSuccessMsg)
2240 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2241 .ArgConstraint(NotNull(ArgNo(0))));
2243 std::optional<QualType> Off_tTy = lookupTy(
"off_t");
2244 std::optional<RangeInt> Off_tMax = getMaxValue(Off_tTy);
2248 addToFunctionSummaryMap(
2249 {
"getc",
"fgetc"}, Signature(ArgTypes{FilePtrTy}, RetType{IntTy}),
2251 .Case({ReturnValueCondition(WithinRange, {{0, UCharRangeMax}})},
2252 ErrnoMustNotBeChecked, GenericSuccessMsg)
2253 .Case({ReturnValueCondition(WithinRange, SingleValue(EOFv))},
2254 ErrnoIrrelevant, GenericFailureMsg)
2255 .ArgConstraint(NotNull(ArgNo(0))));
2259 addToFunctionSummaryMap(
2261 Signature(ArgTypes{IntTy, FilePtrTy}, RetType{IntTy}),
2263 .Case({ArgumentCondition(0, WithinRange,
Range(0, UCharRangeMax)),
2264 ReturnValueCondition(BO_EQ, ArgNo(0))},
2265 ErrnoMustNotBeChecked, GenericSuccessMsg)
2266 .Case({ArgumentCondition(0, OutOfRange,
Range(0, UCharRangeMax)),
2267 ReturnValueCondition(WithinRange,
Range(0, UCharRangeMax))},
2268 ErrnoMustNotBeChecked, GenericSuccessMsg)
2269 .Case({ReturnValueCondition(WithinRange, SingleValue(EOFv))},
2270 ErrnoNEZeroIrrelevant, GenericFailureMsg)
2271 .ArgConstraint(NotNull(ArgNo(1))));
2274 addToFunctionSummaryMap(
2276 Signature(ArgTypes{CharPtrRestrictTy, IntTy, FilePtrRestrictTy},
2277 RetType{CharPtrTy}),
2279 .Case({NotNull(Ret), ReturnValueCondition(BO_EQ, ArgNo(0))},
2280 ErrnoMustNotBeChecked, GenericSuccessMsg)
2281 .Case({
IsNull(Ret)}, ErrnoIrrelevant, GenericFailureMsg)
2282 .ArgConstraint(NotNull(ArgNo(0)))
2283 .ArgConstraint(ArgumentCondition(1, WithinRange,
Range(0, IntMax)))
2285 BufferSize(ArgNo(0), ArgNo(1)))
2286 .ArgConstraint(NotNull(ArgNo(2))));
2289 addToFunctionSummaryMap(
2291 Signature(ArgTypes{ConstCharPtrRestrictTy, FilePtrRestrictTy},
2294 .Case(ReturnsNonnegative, ErrnoMustNotBeChecked, GenericSuccessMsg)
2295 .Case({ReturnValueCondition(WithinRange, SingleValue(EOFv))},
2296 ErrnoNEZeroIrrelevant, GenericFailureMsg)
2297 .ArgConstraint(NotNull(ArgNo(0)))
2298 .ArgConstraint(NotNull(ArgNo(1))));
2301 addToFunctionSummaryMap(
2302 "ungetc", Signature(ArgTypes{IntTy, FilePtrTy}, RetType{IntTy}),
2304 .Case({ReturnValueCondition(BO_EQ, ArgNo(0)),
2305 ArgumentCondition(0, WithinRange, {{0, UCharRangeMax}})},
2306 ErrnoMustNotBeChecked, GenericSuccessMsg)
2307 .Case({ReturnValueCondition(WithinRange, SingleValue(EOFv)),
2308 ArgumentCondition(0, WithinRange, SingleValue(EOFv))},
2309 ErrnoNEZeroIrrelevant,
2310 "Assuming that 'ungetc' fails because EOF was passed as "
2312 .Case({ReturnValueCondition(WithinRange, SingleValue(EOFv)),
2313 ArgumentCondition(0, WithinRange, {{0, UCharRangeMax}})},
2314 ErrnoNEZeroIrrelevant, GenericFailureMsg)
2315 .ArgConstraint(ArgumentCondition(
2316 0, WithinRange, {{EOFv, EOFv}, {0, UCharRangeMax}}))
2317 .ArgConstraint(NotNull(ArgNo(1))));
2323 addToFunctionSummaryMap(
2324 "fseek", Signature(ArgTypes{FilePtrTy, LongTy, IntTy}, RetType{IntTy}),
2326 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2327 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2328 .ArgConstraint(NotNull(ArgNo(0)))
2329 .ArgConstraint(ArgumentCondition(2, WithinRange, {{0, 2}})));
2332 addToFunctionSummaryMap(
2334 Signature(ArgTypes{FilePtrTy, Off_tTy, IntTy}, RetType{IntTy}),
2336 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2337 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2338 .ArgConstraint(NotNull(ArgNo(0)))
2339 .ArgConstraint(ArgumentCondition(2, WithinRange, {{0, 2}})));
2345 addToFunctionSummaryMap(
2347 Signature(ArgTypes{FilePtrRestrictTy, FPosTPtrRestrictTy},
2350 .Case(ReturnsZero, ErrnoUnchanged, GenericSuccessMsg)
2351 .Case(ReturnsNonZero, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2352 .ArgConstraint(NotNull(ArgNo(0)))
2353 .ArgConstraint(NotNull(ArgNo(1))));
2359 addToFunctionSummaryMap(
2361 Signature(ArgTypes{FilePtrTy, ConstFPosTPtrTy}, RetType{IntTy}),
2363 .Case(ReturnsZero, ErrnoUnchanged, GenericSuccessMsg)
2364 .Case(ReturnsNonZero, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2365 .ArgConstraint(NotNull(ArgNo(0)))
2366 .ArgConstraint(NotNull(ArgNo(1))));
2369 addToFunctionSummaryMap(
2370 "fflush", Signature(ArgTypes{FilePtrTy}, RetType{IntTy}),
2372 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2373 .Case(ReturnsEOF, ErrnoNEZeroIrrelevant, GenericFailureMsg));
2379 addToFunctionSummaryMap(
2380 "ftell", Signature(ArgTypes{FilePtrTy}, RetType{LongTy}),
2382 .Case({ReturnValueCondition(WithinRange,
Range(0, LongMax))},
2383 ErrnoUnchanged, GenericSuccessMsg)
2384 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2385 .ArgConstraint(NotNull(ArgNo(0))));
2388 addToFunctionSummaryMap(
2389 "ftello", Signature(ArgTypes{FilePtrTy}, RetType{Off_tTy}),
2391 .Case({ReturnValueCondition(WithinRange,
Range(0, Off_tMax))},
2392 ErrnoMustNotBeChecked, GenericSuccessMsg)
2393 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2394 .ArgConstraint(NotNull(ArgNo(0))));
2402 addToFunctionSummaryMap(
2403 "fileno", Signature(ArgTypes{FilePtrTy}, RetType{IntTy}),
2405 .Case(ReturnsValidFileDescriptor, ErrnoUnchanged, GenericSuccessMsg)
2406 .ArgConstraint(NotNull(ArgNo(0))));
2410 addToFunctionSummaryMap(
"rewind",
2411 Signature(ArgTypes{FilePtrTy}, RetType{VoidTy}),
2413 .Case({}, ErrnoMustBeChecked)
2414 .ArgConstraint(NotNull(ArgNo(0))));
2417 addToFunctionSummaryMap(
2418 "clearerr", Signature(ArgTypes{FilePtrTy}, RetType{VoidTy}),
2419 Summary(NoEvalCall).ArgConstraint(NotNull(ArgNo(0))));
2422 addToFunctionSummaryMap(
2423 "feof", Signature(ArgTypes{FilePtrTy}, RetType{IntTy}),
2424 Summary(NoEvalCall).ArgConstraint(NotNull(ArgNo(0))));
2427 addToFunctionSummaryMap(
2428 "ferror", Signature(ArgTypes{FilePtrTy}, RetType{IntTy}),
2429 Summary(NoEvalCall).ArgConstraint(NotNull(ArgNo(0))));
2432 addToFunctionSummaryMap(
2433 "a64l", Signature(ArgTypes{ConstCharPtrTy}, RetType{LongTy}),
2434 Summary(NoEvalCall).ArgConstraint(NotNull(ArgNo(0))));
2437 addToFunctionSummaryMap(
"l64a",
2438 Signature(ArgTypes{LongTy}, RetType{CharPtrTy}),
2440 .ArgConstraint(ArgumentCondition(
2441 0, WithinRange,
Range(0, LongMax))));
2444 addToFunctionSummaryMap(
2445 "open", Signature(ArgTypes{ConstCharPtrTy, IntTy}, RetType{IntTy}),
2447 .Case(ReturnsValidFileDescriptor, ErrnoMustNotBeChecked,
2449 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2450 .ArgConstraint(NotNull(ArgNo(0))));
2453 addToFunctionSummaryMap(
2455 Signature(ArgTypes{IntTy, ConstCharPtrTy, IntTy}, RetType{IntTy}),
2457 .Case(ReturnsValidFileDescriptor, ErrnoMustNotBeChecked,
2459 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2460 .ArgConstraint(ValidFileDescriptorOrAtFdcwd(ArgNo(0)))
2461 .ArgConstraint(NotNull(ArgNo(1))));
2464 addToFunctionSummaryMap(
2465 "access", Signature(ArgTypes{ConstCharPtrTy, IntTy}, RetType{IntTy}),
2467 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2468 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2469 .ArgConstraint(NotNull(ArgNo(0))));
2472 addToFunctionSummaryMap(
2474 Signature(ArgTypes{IntTy, ConstCharPtrTy, IntTy, IntTy},
2477 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2478 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2479 .ArgConstraint(ValidFileDescriptorOrAtFdcwd(ArgNo(0)))
2480 .ArgConstraint(NotNull(ArgNo(1))));
2483 addToFunctionSummaryMap(
2484 "dup", Signature(ArgTypes{IntTy}, RetType{IntTy}),
2486 .Case(ReturnsValidFileDescriptor, ErrnoMustNotBeChecked,
2488 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2490 ArgumentCondition(0, WithinRange,
Range(0, IntMax))));
2493 addToFunctionSummaryMap(
2494 "dup2", Signature(ArgTypes{IntTy, IntTy}, RetType{IntTy}),
2496 .Case(ReturnsValidFileDescriptor, ErrnoMustNotBeChecked,
2498 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2499 .ArgConstraint(ArgumentCondition(0, WithinRange,
Range(0, IntMax)))
2501 ArgumentCondition(1, WithinRange,
Range(0, IntMax))));
2504 addToFunctionSummaryMap(
2505 "fdatasync", Signature(ArgTypes{IntTy}, RetType{IntTy}),
2507 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2508 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2510 ArgumentCondition(0, WithinRange,
Range(0, IntMax))));
2513 addToFunctionSummaryMap(
2515 Signature(ArgTypes{ConstCharPtrTy, ConstCharPtrTy, IntTy},
2518 .ArgConstraint(NotNull(ArgNo(0)))
2519 .ArgConstraint(NotNull(ArgNo(1))));
2522 addToFunctionSummaryMap(
2523 "fsync", Signature(ArgTypes{IntTy}, RetType{IntTy}),
2525 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2526 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2528 ArgumentCondition(0, WithinRange,
Range(0, IntMax))));
2531 addToFunctionSummaryMap(
2533 Signature(ArgTypes{ConstCharPtrTy, Off_tTy}, RetType{IntTy}),
2535 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2536 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2537 .ArgConstraint(NotNull(ArgNo(0))));
2540 addToFunctionSummaryMap(
2542 Signature(ArgTypes{ConstCharPtrTy, ConstCharPtrTy}, RetType{IntTy}),
2544 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2545 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2546 .ArgConstraint(NotNull(ArgNo(0)))
2547 .ArgConstraint(NotNull(ArgNo(1))));
2550 addToFunctionSummaryMap(
2552 Signature(ArgTypes{ConstCharPtrTy, IntTy, ConstCharPtrTy},
2555 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2556 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2557 .ArgConstraint(NotNull(ArgNo(0)))
2558 .ArgConstraint(ValidFileDescriptorOrAtFdcwd(ArgNo(1)))
2559 .ArgConstraint(NotNull(ArgNo(2))));
2562 addToFunctionSummaryMap(
2563 "lockf", Signature(ArgTypes{IntTy, IntTy, Off_tTy}, RetType{IntTy}),
2565 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2566 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2568 ArgumentCondition(0, WithinRange,
Range(0, IntMax))));
2570 std::optional<QualType> Mode_tTy = lookupTy(
"mode_t");
2573 addToFunctionSummaryMap(
2574 "creat", Signature(ArgTypes{ConstCharPtrTy, Mode_tTy}, RetType{IntTy}),
2576 .Case(ReturnsValidFileDescriptor, ErrnoMustNotBeChecked,
2578 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2579 .ArgConstraint(NotNull(ArgNo(0))));
2582 addToFunctionSummaryMap(
2583 "sleep", Signature(ArgTypes{UnsignedIntTy}, RetType{UnsignedIntTy}),
2586 ArgumentCondition(0, WithinRange,
Range(0, UnsignedIntMax))));
2588 std::optional<QualType> DirTy = lookupTy(
"DIR");
2589 std::optional<QualType> DirPtrTy = getPointerTy(DirTy);
2592 addToFunctionSummaryMap(
2593 "dirfd", Signature(ArgTypes{DirPtrTy}, RetType{IntTy}),
2595 .Case(ReturnsValidFileDescriptor, ErrnoMustNotBeChecked,
2597 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2598 .ArgConstraint(NotNull(ArgNo(0))));
2601 addToFunctionSummaryMap(
2602 "alarm", Signature(ArgTypes{UnsignedIntTy}, RetType{UnsignedIntTy}),
2605 ArgumentCondition(0, WithinRange,
Range(0, UnsignedIntMax))));
2608 addToFunctionSummaryMap(
2609 "closedir", Signature(ArgTypes{DirPtrTy}, RetType{IntTy}),
2611 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2612 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2613 .ArgConstraint(NotNull(ArgNo(0))));
2616 addToFunctionSummaryMap(
2617 "strdup", Signature(ArgTypes{ConstCharPtrTy}, RetType{CharPtrTy}),
2618 Summary(NoEvalCall).ArgConstraint(NotNull(ArgNo(0))));
2621 addToFunctionSummaryMap(
2623 Signature(ArgTypes{ConstCharPtrTy, SizeTyCanonTy}, RetType{CharPtrTy}),
2625 .ArgConstraint(NotNull(ArgNo(0)))
2627 ArgumentCondition(1, WithinRange,
Range(0, SizeMax))));
2630 addToFunctionSummaryMap(
2631 "wcsdup", Signature(ArgTypes{ConstWchar_tPtrTy}, RetType{Wchar_tPtrTy}),
2632 Summary(NoEvalCall).ArgConstraint(NotNull(ArgNo(0))));
2635 addToFunctionSummaryMap(
2636 "mkstemp", Signature(ArgTypes{CharPtrTy}, RetType{IntTy}),
2638 .Case(ReturnsValidFileDescriptor, ErrnoMustNotBeChecked,
2640 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2641 .ArgConstraint(NotNull(ArgNo(0))));
2644 addToFunctionSummaryMap(
2645 "mkdtemp", Signature(ArgTypes{CharPtrTy}, RetType{CharPtrTy}),
2647 .Case({NotNull(Ret), ReturnValueCondition(BO_EQ, ArgNo(0))},
2648 ErrnoMustNotBeChecked, GenericSuccessMsg)
2649 .Case({
IsNull(Ret)}, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2650 .ArgConstraint(NotNull(ArgNo(0))));
2653 addToFunctionSummaryMap(
2655 Signature(ArgTypes{CharPtrTy, SizeTyCanonTy}, RetType{CharPtrTy}),
2658 ArgumentCondition(1, WithinRange,
Range(1, SizeMax)),
2659 ReturnValueCondition(BO_EQ, ArgNo(0)), NotNull(Ret)},
2660 ErrnoMustNotBeChecked, GenericSuccessMsg)
2662 ArgumentCondition(1, WithinRange, SingleValue(0)),
2664 ErrnoNEZeroIrrelevant,
"Assuming that argument 'size' is 0")
2666 ArgumentCondition(1, WithinRange,
Range(1, SizeMax)),
2668 ErrnoNEZeroIrrelevant, GenericFailureMsg)
2669 .Case({
IsNull(0), NotNull(Ret)}, ErrnoMustNotBeChecked,
2674 BufferSize( ArgNo(0), ArgNo(1)))
2676 ArgumentCondition(1, WithinRange,
Range(0, SizeMax))));
2679 addToFunctionSummaryMap(
2680 "mkdir", Signature(ArgTypes{ConstCharPtrTy, Mode_tTy}, RetType{IntTy}),
2682 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2683 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2684 .ArgConstraint(NotNull(ArgNo(0))));
2687 addToFunctionSummaryMap(
2689 Signature(ArgTypes{IntTy, ConstCharPtrTy, Mode_tTy}, RetType{IntTy}),
2691 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2692 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2693 .ArgConstraint(ValidFileDescriptorOrAtFdcwd(ArgNo(0)))
2694 .ArgConstraint(NotNull(ArgNo(1))));
2696 std::optional<QualType> Dev_tTy = lookupTy(
"dev_t");
2699 addToFunctionSummaryMap(
2701 Signature(ArgTypes{ConstCharPtrTy, Mode_tTy, Dev_tTy}, RetType{IntTy}),
2703 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2704 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2705 .ArgConstraint(NotNull(ArgNo(0))));
2708 addToFunctionSummaryMap(
2710 Signature(ArgTypes{IntTy, ConstCharPtrTy, Mode_tTy, Dev_tTy},
2713 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2714 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2715 .ArgConstraint(ValidFileDescriptorOrAtFdcwd(ArgNo(0)))
2716 .ArgConstraint(NotNull(ArgNo(1))));
2719 addToFunctionSummaryMap(
2720 "chmod", Signature(ArgTypes{ConstCharPtrTy, Mode_tTy}, RetType{IntTy}),
2722 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2723 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2724 .ArgConstraint(NotNull(ArgNo(0))));
2727 addToFunctionSummaryMap(
2729 Signature(ArgTypes{IntTy, ConstCharPtrTy, Mode_tTy, IntTy},
2732 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2733 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2734 .ArgConstraint(ValidFileDescriptorOrAtFdcwd(ArgNo(0)))
2735 .ArgConstraint(NotNull(ArgNo(1))));
2738 addToFunctionSummaryMap(
2739 "fchmod", Signature(ArgTypes{IntTy, Mode_tTy}, RetType{IntTy}),
2741 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2742 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2744 ArgumentCondition(0, WithinRange,
Range(0, IntMax))));
2746 std::optional<QualType> Uid_tTy = lookupTy(
"uid_t");
2747 std::optional<QualType> Gid_tTy = lookupTy(
"gid_t");
2751 addToFunctionSummaryMap(
2753 Signature(ArgTypes{IntTy, ConstCharPtrTy, Uid_tTy, Gid_tTy, IntTy},
2756 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2757 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2758 .ArgConstraint(ValidFileDescriptorOrAtFdcwd(ArgNo(0)))
2759 .ArgConstraint(NotNull(ArgNo(1))));
2762 addToFunctionSummaryMap(
2764 Signature(ArgTypes{ConstCharPtrTy, Uid_tTy, Gid_tTy}, RetType{IntTy}),
2766 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2767 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2768 .ArgConstraint(NotNull(ArgNo(0))));
2771 addToFunctionSummaryMap(
2773 Signature(ArgTypes{ConstCharPtrTy, Uid_tTy, Gid_tTy}, RetType{IntTy}),
2775 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2776 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2777 .ArgConstraint(NotNull(ArgNo(0))));
2780 addToFunctionSummaryMap(
2781 "fchown", Signature(ArgTypes{IntTy, Uid_tTy, Gid_tTy}, RetType{IntTy}),
2783 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2784 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2786 ArgumentCondition(0, WithinRange,
Range(0, IntMax))));
2789 addToFunctionSummaryMap(
2790 "rmdir", Signature(ArgTypes{ConstCharPtrTy}, RetType{IntTy}),
2792 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2793 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2794 .ArgConstraint(NotNull(ArgNo(0))));
2797 addToFunctionSummaryMap(
2798 "chdir", Signature(ArgTypes{ConstCharPtrTy}, RetType{IntTy}),
2800 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2801 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2802 .ArgConstraint(NotNull(ArgNo(0))));
2805 addToFunctionSummaryMap(
2807 Signature(ArgTypes{ConstCharPtrTy, ConstCharPtrTy}, RetType{IntTy}),
2809 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2810 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2811 .ArgConstraint(NotNull(ArgNo(0)))
2812 .ArgConstraint(NotNull(ArgNo(1))));
2816 addToFunctionSummaryMap(
2818 Signature(ArgTypes{IntTy, ConstCharPtrTy, IntTy, ConstCharPtrTy, IntTy},
2821 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2822 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2823 .ArgConstraint(ValidFileDescriptorOrAtFdcwd(ArgNo(0)))
2824 .ArgConstraint(NotNull(ArgNo(1)))
2825 .ArgConstraint(ValidFileDescriptorOrAtFdcwd(ArgNo(2)))
2826 .ArgConstraint(NotNull(ArgNo(3))));
2829 addToFunctionSummaryMap(
2830 "unlink", Signature(ArgTypes{ConstCharPtrTy}, RetType{IntTy}),
2832 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2833 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2834 .ArgConstraint(NotNull(ArgNo(0))));
2837 addToFunctionSummaryMap(
2839 Signature(ArgTypes{IntTy, ConstCharPtrTy, IntTy}, RetType{IntTy}),
2841 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2842 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2843 .ArgConstraint(ValidFileDescriptorOrAtFdcwd(ArgNo(0)))
2844 .ArgConstraint(NotNull(ArgNo(1))));
2846 std::optional<QualType> StructStatTy = lookupTy(
"stat");
2847 std::optional<QualType> StructStatPtrTy = getPointerTy(StructStatTy);
2848 std::optional<QualType> StructStatPtrRestrictTy =
2849 getRestrictTy(StructStatPtrTy);
2852 addToFunctionSummaryMap(
2853 "fstat", Signature(ArgTypes{IntTy, StructStatPtrTy}, RetType{IntTy}),
2855 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2856 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2857 .ArgConstraint(ArgumentCondition(0, WithinRange,
Range(0, IntMax)))
2858 .ArgConstraint(NotNull(ArgNo(1))));
2861 addToFunctionSummaryMap(
2863 Signature(ArgTypes{ConstCharPtrRestrictTy, StructStatPtrRestrictTy},
2866 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2867 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2868 .ArgConstraint(NotNull(ArgNo(0)))
2869 .ArgConstraint(NotNull(ArgNo(1))));
2872 addToFunctionSummaryMap(
2874 Signature(ArgTypes{ConstCharPtrRestrictTy, StructStatPtrRestrictTy},
2877 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2878 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2879 .ArgConstraint(NotNull(ArgNo(0)))
2880 .ArgConstraint(NotNull(ArgNo(1))));
2884 addToFunctionSummaryMap(
2886 Signature(ArgTypes{IntTy, ConstCharPtrRestrictTy,
2887 StructStatPtrRestrictTy, IntTy},
2890 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2891 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2892 .ArgConstraint(ValidFileDescriptorOrAtFdcwd(ArgNo(0)))
2893 .ArgConstraint(NotNull(ArgNo(1)))
2894 .ArgConstraint(NotNull(ArgNo(2))));
2897 addToFunctionSummaryMap(
2898 "opendir", Signature(ArgTypes{ConstCharPtrTy}, RetType{DirPtrTy}),
2900 .Case({NotNull(Ret)}, ErrnoMustNotBeChecked, GenericSuccessMsg)
2901 .Case({
IsNull(Ret)}, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2902 .ArgConstraint(NotNull(ArgNo(0))));
2905 addToFunctionSummaryMap(
2906 "fdopendir", Signature(ArgTypes{IntTy}, RetType{DirPtrTy}),
2908 .Case({NotNull(Ret)}, ErrnoMustNotBeChecked, GenericSuccessMsg)
2909 .Case({
IsNull(Ret)}, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2911 ArgumentCondition(0, WithinRange,
Range(0, IntMax))));
2914 addToFunctionSummaryMap(
2915 "isatty", Signature(ArgTypes{IntTy}, RetType{IntTy}),
2917 .Case({ReturnValueCondition(WithinRange,
Range(0, 1))},
2920 ArgumentCondition(0, WithinRange,
Range(0, IntMax))));
2923 addToFunctionSummaryMap(
2924 "close", Signature(ArgTypes{IntTy}, RetType{IntTy}),
2926 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2927 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2929 ArgumentCondition(0, WithinRange,
Range(-1, IntMax))));
2932 addToFunctionSummaryMap(
"fpathconf",
2933 Signature(ArgTypes{IntTy, IntTy}, RetType{LongTy}),
2935 .ArgConstraint(ArgumentCondition(
2936 0, WithinRange,
Range(0, IntMax))));
2939 addToFunctionSummaryMap(
2940 "pathconf", Signature(ArgTypes{ConstCharPtrTy, IntTy}, RetType{LongTy}),
2941 Summary(NoEvalCall).ArgConstraint(NotNull(ArgNo(0))));
2944 addToFunctionSummaryMap(
2945 "rewinddir", Signature(ArgTypes{DirPtrTy}, RetType{VoidTy}),
2946 Summary(NoEvalCall).ArgConstraint(NotNull(ArgNo(0))));
2949 addToFunctionSummaryMap(
2950 "seekdir", Signature(ArgTypes{DirPtrTy, LongTy}, RetType{VoidTy}),
2951 Summary(NoEvalCall).ArgConstraint(NotNull(ArgNo(0))));
2954 addToFunctionSummaryMap(
2955 "rand_r", Signature(ArgTypes{UnsignedIntPtrTy}, RetType{IntTy}),
2956 Summary(NoEvalCall).ArgConstraint(NotNull(ArgNo(0))));
2961 addToFunctionSummaryMap(
2964 ArgTypes{VoidPtrTy, SizeTyCanonTy, IntTy, IntTy, IntTy, Off_tTy},
2965 RetType{VoidPtrTy}),
2967 .ArgConstraint(ArgumentCondition(1, WithinRange,
Range(1, SizeMax)))
2969 ArgumentCondition(4, WithinRange,
Range(-1, IntMax))));
2971 std::optional<QualType> Off64_tTy = lookupTy(
"off64_t");
2975 addToFunctionSummaryMap(
2978 ArgTypes{VoidPtrTy, SizeTyCanonTy, IntTy, IntTy, IntTy, Off64_tTy},
2979 RetType{VoidPtrTy}),
2981 .ArgConstraint(ArgumentCondition(1, WithinRange,
Range(1, SizeMax)))
2983 ArgumentCondition(4, WithinRange,
Range(-1, IntMax))));
2986 addToFunctionSummaryMap(
2987 "pipe", Signature(ArgTypes{IntPtrTy}, RetType{IntTy}),
2989 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2990 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2991 .ArgConstraint(NotNull(ArgNo(0))));
2998 addToFunctionSummaryMap(
2999 "lseek", Signature(ArgTypes{IntTy, Off_tTy, IntTy}, RetType{Off_tTy}),
3001 .Case(ReturnsNonnegative, ErrnoIrrelevant)
3002 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
3004 ArgumentCondition(0, WithinRange,
Range(0, IntMax))));
3008 addToFunctionSummaryMap(
3011 ArgTypes{ConstCharPtrRestrictTy, CharPtrRestrictTy, SizeTyCanonTy},
3012 RetType{Ssize_tTy}),
3014 .Case({ArgumentCondition(2, WithinRange,
Range(1, IntMax)),
3015 ReturnValueCondition(LessThanOrEq, ArgNo(2)),
3016 ReturnValueCondition(WithinRange,
Range(1, Ssize_tMax))},
3017 ErrnoMustNotBeChecked, GenericSuccessMsg)
3018 .Case({ArgumentCondition(2, WithinRange, SingleValue(0)),
3019 ReturnValueCondition(WithinRange, SingleValue(0))},
3020 ErrnoMustNotBeChecked,
3021 "Assuming that argument 'bufsize' is 0")
3022 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
3023 .ArgConstraint(NotNull(ArgNo(0)))
3024 .ArgConstraint(NotNull(ArgNo(1)))
3025 .ArgConstraint(BufferSize(ArgNo(1),
3028 ArgumentCondition(2, WithinRange,
Range(0, SizeMax))));
3032 addToFunctionSummaryMap(
3034 Signature(ArgTypes{IntTy, ConstCharPtrRestrictTy, CharPtrRestrictTy,
3036 RetType{Ssize_tTy}),
3038 .Case({ArgumentCondition(3, WithinRange,
Range(1, IntMax)),
3039 ReturnValueCondition(LessThanOrEq, ArgNo(3)),
3040 ReturnValueCondition(WithinRange,
Range(1, Ssize_tMax))},
3041 ErrnoMustNotBeChecked, GenericSuccessMsg)
3042 .Case({ArgumentCondition(3, WithinRange, SingleValue(0)),
3043 ReturnValueCondition(WithinRange, SingleValue(0))},
3044 ErrnoMustNotBeChecked,
3045 "Assuming that argument 'bufsize' is 0")
3046 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
3047 .ArgConstraint(ValidFileDescriptorOrAtFdcwd(ArgNo(0)))
3048 .ArgConstraint(NotNull(ArgNo(1)))
3049 .ArgConstraint(NotNull(ArgNo(2)))
3050 .ArgConstraint(BufferSize(ArgNo(2),
3053 ArgumentCondition(3, WithinRange,
Range(0, SizeMax))));
3057 addToFunctionSummaryMap(
3059 Signature(ArgTypes{IntTy, ConstCharPtrTy, IntTy, ConstCharPtrTy},
3062 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
3063 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
3064 .ArgConstraint(ValidFileDescriptorOrAtFdcwd(ArgNo(0)))
3065 .ArgConstraint(NotNull(ArgNo(1)))
3066 .ArgConstraint(ValidFileDescriptorOrAtFdcwd(ArgNo(2)))
3067 .ArgConstraint(NotNull(ArgNo(3))));
3073 addToFunctionSummaryMap(
3075 Signature(ArgTypes{ConstCharPtrRestrictTy, CharPtrRestrictTy},
3076 RetType{CharPtrTy}),
3078 .Case({NotNull(Ret)}, ErrnoMustNotBeChecked, GenericSuccessMsg)
3079 .Case({
IsNull(Ret)}, ErrnoNEZeroIrrelevant, GenericFailureMsg)
3080 .ArgConstraint(NotNull(ArgNo(0))));
3082 QualType CharPtrConstPtr = getPointerTy(getConstTy(CharPtrTy));
3085 addToFunctionSummaryMap(
3087 Signature(ArgTypes{ConstCharPtrTy, CharPtrConstPtr}, RetType{IntTy}),
3089 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant)
3090 .ArgConstraint(NotNull(ArgNo(0))));
3093 addToFunctionSummaryMap(
3095 Signature(ArgTypes{ConstCharPtrTy, CharPtrConstPtr}, RetType{IntTy}),
3097 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant)
3098 .ArgConstraint(NotNull(ArgNo(0))));
3101 addToFunctionSummaryMap(
3103 Signature(ArgTypes{IntTy, CharPtrConstPtr, ConstCharPtrTy},
3106 .Case({ReturnValueCondition(WithinRange,
Range(-1, UCharRangeMax))},
3108 .ArgConstraint(ArgumentCondition(0, WithinRange,
Range(0, IntMax)))
3109 .ArgConstraint(NotNull(ArgNo(1)))
3110 .ArgConstraint(NotNull(ArgNo(2))));
3112 std::optional<QualType> StructSockaddrTy = lookupTy(
"sockaddr");
3113 std::optional<QualType> StructSockaddrPtrTy =
3114 getPointerTy(StructSockaddrTy);
3115 std::optional<QualType> ConstStructSockaddrPtrTy =
3116 getPointerTy(getConstTy(StructSockaddrTy));
3117 std::optional<QualType> StructSockaddrPtrRestrictTy =
3118 getRestrictTy(StructSockaddrPtrTy);
3119 std::optional<QualType> ConstStructSockaddrPtrRestrictTy =
3120 getRestrictTy(ConstStructSockaddrPtrTy);
3121 std::optional<QualType> Socklen_tTy = lookupTy(
"socklen_t");
3122 std::optional<QualType> Socklen_tPtrTy = getPointerTy(Socklen_tTy);
3123 std::optional<QualType> Socklen_tPtrRestrictTy =
3124 getRestrictTy(Socklen_tPtrTy);
3125 std::optional<RangeInt> Socklen_tMax = getMaxValue(Socklen_tTy);
3135 addToFunctionSummaryMap(
3136 "socket", Signature(ArgTypes{IntTy, IntTy, IntTy}, RetType{IntTy}),
3138 .Case(ReturnsValidFileDescriptor, ErrnoMustNotBeChecked,
3140 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg));
3144 .Case(ReturnsValidFileDescriptor, ErrnoMustNotBeChecked,
3146 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
3147 .ArgConstraint(ArgumentCondition(0, WithinRange,
Range(0, IntMax)));
3148 if (!addToFunctionSummaryMap(
3152 Signature(ArgTypes{IntTy, StructSockaddrPtrRestrictTy,
3153 Socklen_tPtrRestrictTy},
3156 addToFunctionSummaryMap(
3158 Signature(ArgTypes{IntTy,
Irrelevant, Socklen_tPtrRestrictTy},
3164 if (!addToFunctionSummaryMap(
3166 Signature(ArgTypes{IntTy, ConstStructSockaddrPtrTy, Socklen_tTy},
3169 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
3170 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
3172 ArgumentCondition(0, WithinRange,
Range(0, IntMax)))
3173 .ArgConstraint(NotNull(ArgNo(1)))
3175 BufferSize(ArgNo(1), ArgNo(2)))
3177 ArgumentCondition(2, WithinRange,
Range(0, Socklen_tMax)))))
3179 addToFunctionSummaryMap(
3181 Signature(ArgTypes{IntTy,
Irrelevant, Socklen_tTy}, RetType{IntTy}),
3183 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
3184 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
3186 ArgumentCondition(0, WithinRange,
Range(0, IntMax)))
3188 ArgumentCondition(2, WithinRange,
Range(0, Socklen_tMax))));
3192 if (!addToFunctionSummaryMap(
3194 Signature(ArgTypes{IntTy, StructSockaddrPtrRestrictTy,
3195 Socklen_tPtrRestrictTy},
3198 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
3199 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
3201 ArgumentCondition(0, WithinRange,
Range(0, IntMax)))
3202 .ArgConstraint(NotNull(ArgNo(1)))
3203 .ArgConstraint(NotNull(ArgNo(2)))))
3204 addToFunctionSummaryMap(
3206 Signature(ArgTypes{IntTy,
Irrelevant, Socklen_tPtrRestrictTy},
3209 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
3210 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
3212 ArgumentCondition(0, WithinRange,
Range(0, IntMax))));
3216 if (!addToFunctionSummaryMap(
3218 Signature(ArgTypes{IntTy, StructSockaddrPtrRestrictTy,
3219 Socklen_tPtrRestrictTy},
3222 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
3223 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
3225 ArgumentCondition(0, WithinRange,
Range(0, IntMax)))
3226 .ArgConstraint(NotNull(ArgNo(1)))
3227 .ArgConstraint(NotNull(ArgNo(2)))))
3228 addToFunctionSummaryMap(
3230 Signature(ArgTypes{IntTy,
Irrelevant, Socklen_tPtrRestrictTy},
3233 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
3234 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
3236 ArgumentCondition(0, WithinRange,
Range(0, IntMax))));
3240 if (!addToFunctionSummaryMap(
3242 Signature(ArgTypes{IntTy, ConstStructSockaddrPtrTy, Socklen_tTy},
3245 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
3246 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
3248 ArgumentCondition(0, WithinRange,
Range(0, IntMax)))
3249 .ArgConstraint(NotNull(ArgNo(1)))))
3250 addToFunctionSummaryMap(
3252 Signature(ArgTypes{IntTy,
Irrelevant, Socklen_tTy}, RetType{IntTy}),
3254 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
3255 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
3257 ArgumentCondition(0, WithinRange,
Range(0, IntMax))));
3261 .Case({ReturnValueCondition(LessThanOrEq, ArgNo(2)),
3262 ReturnValueCondition(WithinRange,
Range(1, Ssize_tMax))},
3263 ErrnoMustNotBeChecked, GenericSuccessMsg)
3264 .Case({ReturnValueCondition(WithinRange, SingleValue(0)),
3265 ArgumentCondition(2, WithinRange, SingleValue(0))},
3266 ErrnoMustNotBeChecked, GenericSuccessMsg)
3267 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
3268 .ArgConstraint(ArgumentCondition(0, WithinRange,
Range(0, IntMax)))
3269 .ArgConstraint(BufferSize(ArgNo(1),
3271 if (!addToFunctionSummaryMap(
3277 Signature(ArgTypes{IntTy, VoidPtrRestrictTy, SizeTyCanonTy, IntTy,
3278 StructSockaddrPtrRestrictTy,
3279 Socklen_tPtrRestrictTy},
3280 RetType{Ssize_tTy}),
3282 addToFunctionSummaryMap(
3284 Signature(ArgTypes{IntTy, VoidPtrRestrictTy, SizeTyCanonTy, IntTy,
3286 RetType{Ssize_tTy}),
3291 .Case({ReturnValueCondition(LessThanOrEq, ArgNo(2)),
3292 ReturnValueCondition(WithinRange,
Range(1, Ssize_tMax))},
3293 ErrnoMustNotBeChecked, GenericSuccessMsg)
3294 .Case({ReturnValueCondition(WithinRange, SingleValue(0)),
3295 ArgumentCondition(2, WithinRange, SingleValue(0))},
3296 ErrnoMustNotBeChecked, GenericSuccessMsg)
3297 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
3298 .ArgConstraint(ArgumentCondition(0, WithinRange,
Range(0, IntMax)))
3299 .ArgConstraint(BufferSize(ArgNo(1),
3301 if (!addToFunctionSummaryMap(
3306 Signature(ArgTypes{IntTy, ConstVoidPtrTy, SizeTyCanonTy, IntTy,
3307 ConstStructSockaddrPtrTy, Socklen_tTy},
3308 RetType{Ssize_tTy}),
3310 addToFunctionSummaryMap(
3312 Signature(ArgTypes{IntTy, ConstVoidPtrTy, SizeTyCanonTy, IntTy,
3314 RetType{Ssize_tTy}),
3318 addToFunctionSummaryMap(
3319 "listen", Signature(ArgTypes{IntTy, IntTy}, RetType{IntTy}),
3321 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
3322 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
3324 ArgumentCondition(0, WithinRange,
Range(0, IntMax))));
3327 addToFunctionSummaryMap(
3329 Signature(ArgTypes{IntTy, VoidPtrTy, SizeTyCanonTy, IntTy},
3330 RetType{Ssize_tTy}),
3332 .Case({ReturnValueCondition(LessThanOrEq, ArgNo(2)),
3333 ReturnValueCondition(WithinRange,
Range(1, Ssize_tMax))},
3334 ErrnoMustNotBeChecked, GenericSuccessMsg)
3335 .Case({ReturnValueCondition(WithinRange, SingleValue(0)),
3336 ArgumentCondition(2, WithinRange, SingleValue(0))},
3337 ErrnoMustNotBeChecked, GenericSuccessMsg)
3338 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
3339 .ArgConstraint(ArgumentCondition(0, WithinRange,
Range(0, IntMax)))
3340 .ArgConstraint(BufferSize(ArgNo(1),
3343 std::optional<QualType> StructMsghdrTy = lookupTy(
"msghdr");
3344 std::optional<QualType> StructMsghdrPtrTy = getPointerTy(StructMsghdrTy);
3345 std::optional<QualType> ConstStructMsghdrPtrTy =
3346 getPointerTy(getConstTy(StructMsghdrTy));
3349 addToFunctionSummaryMap(
3351 Signature(ArgTypes{IntTy, StructMsghdrPtrTy, IntTy},
3352 RetType{Ssize_tTy}),
3354 .Case({ReturnValueCondition(WithinRange,
Range(1, Ssize_tMax))},
3355 ErrnoMustNotBeChecked, GenericSuccessMsg)
3356 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
3358 ArgumentCondition(0, WithinRange,
Range(0, IntMax))));
3361 addToFunctionSummaryMap(
3363 Signature(ArgTypes{IntTy, ConstStructMsghdrPtrTy, IntTy},
3364 RetType{Ssize_tTy}),
3366 .Case({ReturnValueCondition(WithinRange,
Range(1, Ssize_tMax))},
3367 ErrnoMustNotBeChecked, GenericSuccessMsg)
3368 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
3370 ArgumentCondition(0, WithinRange,
Range(0, IntMax))));
3374 addToFunctionSummaryMap(
3376 Signature(ArgTypes{IntTy, IntTy, IntTy, ConstVoidPtrTy, Socklen_tTy},
3379 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
3380 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
3381 .ArgConstraint(NotNullBuffer(ArgNo(3), ArgNo(4)))
3383 BufferSize(ArgNo(3), ArgNo(4)))
3385 ArgumentCondition(4, WithinRange,
Range(0, Socklen_tMax))));
3390 addToFunctionSummaryMap(
3392 Signature(ArgTypes{IntTy, IntTy, IntTy, VoidPtrRestrictTy,
3393 Socklen_tPtrRestrictTy},
3396 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
3397 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
3398 .ArgConstraint(NotNull(ArgNo(3)))
3399 .ArgConstraint(NotNull(ArgNo(4))));
3402 addToFunctionSummaryMap(
3404 Signature(ArgTypes{IntTy, ConstVoidPtrTy, SizeTyCanonTy, IntTy},
3405 RetType{Ssize_tTy}),
3407 .Case({ReturnValueCondition(LessThanOrEq, ArgNo(2)),
3408 ReturnValueCondition(WithinRange,
Range(1, Ssize_tMax))},
3409 ErrnoMustNotBeChecked, GenericSuccessMsg)
3410 .Case({ReturnValueCondition(WithinRange, SingleValue(0)),
3411 ArgumentCondition(2, WithinRange, SingleValue(0))},
3412 ErrnoMustNotBeChecked, GenericSuccessMsg)
3413 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
3414 .ArgConstraint(ArgumentCondition(0, WithinRange,
Range(0, IntMax)))
3415 .ArgConstraint(BufferSize(ArgNo(1),
3419 addToFunctionSummaryMap(
3421 Signature(ArgTypes{IntTy, IntTy, IntTy, IntPtrTy}, RetType{IntTy}),
3423 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
3424 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
3425 .ArgConstraint(NotNull(ArgNo(3))));
3428 addToFunctionSummaryMap(
3429 "shutdown", Signature(ArgTypes{IntTy, IntTy}, RetType{IntTy}),
3431 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
3432 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
3434 ArgumentCondition(0, WithinRange,
Range(0, IntMax))));
3443 addToFunctionSummaryMap(
3445 Signature(ArgTypes{ConstStructSockaddrPtrRestrictTy, Socklen_tTy,
3446 CharPtrRestrictTy, Socklen_tTy, CharPtrRestrictTy,
3447 Socklen_tTy, IntTy},
3451 BufferSize(ArgNo(0), ArgNo(1)))
3453 ArgumentCondition(1, WithinRange,
Range(0, Socklen_tMax)))
3455 BufferSize(ArgNo(2), ArgNo(3)))
3457 ArgumentCondition(3, WithinRange,
Range(0, Socklen_tMax)))
3459 BufferSize(ArgNo(4), ArgNo(5)))
3461 ArgumentCondition(5, WithinRange,
Range(0, Socklen_tMax))));
3463 std::optional<QualType> StructUtimbufTy = lookupTy(
"utimbuf");
3464 std::optional<QualType> StructUtimbufPtrTy = getPointerTy(StructUtimbufTy);
3467 addToFunctionSummaryMap(
3469 Signature(ArgTypes{ConstCharPtrTy, StructUtimbufPtrTy}, RetType{IntTy}),
3471 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
3472 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
3473 .ArgConstraint(NotNull(ArgNo(0))));
3475 std::optional<QualType> StructTimespecTy = lookupTy(
"timespec");
3476 std::optional<QualType> StructTimespecPtrTy =
3477 getPointerTy(StructTimespecTy);
3478 std::optional<QualType> ConstStructTimespecPtrTy =
3479 getPointerTy(getConstTy(StructTimespecTy));
3482 addToFunctionSummaryMap(
3484 Signature(ArgTypes{IntTy, ConstStructTimespecPtrTy}, RetType{IntTy}),
3486 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
3487 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
3489 ArgumentCondition(0, WithinRange,
Range(0, IntMax))));
3493 addToFunctionSummaryMap(
3496 ArgTypes{IntTy, ConstCharPtrTy, ConstStructTimespecPtrTy, IntTy},
3499 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
3500 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
3501 .ArgConstraint(NotNull(ArgNo(1))));
3503 std::optional<QualType> StructTimevalTy = lookupTy(
"timeval");
3504 std::optional<QualType> ConstStructTimevalPtrTy =
3505 getPointerTy(getConstTy(StructTimevalTy));
3508 addToFunctionSummaryMap(
3510 Signature(ArgTypes{ConstCharPtrTy, ConstStructTimevalPtrTy},
3513 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
3514 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
3515 .ArgConstraint(NotNull(ArgNo(0))));
3518 addToFunctionSummaryMap(
3520 Signature(ArgTypes{ConstStructTimespecPtrTy, StructTimespecPtrTy},
3523 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
3524 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
3525 .ArgConstraint(NotNull(ArgNo(0))));
3527 std::optional<QualType> Time_tTy = lookupTy(
"time_t");
3528 std::optional<QualType> ConstTime_tPtrTy =
3529 getPointerTy(getConstTy(Time_tTy));
3530 std::optional<QualType> ConstTime_tPtrRestrictTy =
3531 getRestrictTy(ConstTime_tPtrTy);
3533 std::optional<QualType> StructTmTy = lookupTy(
"tm");
3534 std::optional<QualType> StructTmPtrTy = getPointerTy(StructTmTy);
3535 std::optional<QualType> StructTmPtrRestrictTy =
3536 getRestrictTy(StructTmPtrTy);
3537 std::optional<QualType> ConstStructTmPtrTy =
3538 getPointerTy(getConstTy(StructTmTy));
3539 std::optional<QualType> ConstStructTmPtrRestrictTy =
3540 getRestrictTy(ConstStructTmPtrTy);
3543 addToFunctionSummaryMap(
3545 Signature(ArgTypes{ConstTime_tPtrTy}, RetType{StructTmPtrTy}),
3546 Summary(NoEvalCall).ArgConstraint(NotNull(ArgNo(0))));
3550 addToFunctionSummaryMap(
3552 Signature(ArgTypes{ConstTime_tPtrRestrictTy, StructTmPtrRestrictTy},
3553 RetType{StructTmPtrTy}),
3555 .ArgConstraint(NotNull(ArgNo(0)))
3556 .ArgConstraint(NotNull(ArgNo(1))));
3559 addToFunctionSummaryMap(
3561 Signature(ArgTypes{ConstStructTmPtrRestrictTy, CharPtrRestrictTy},
3562 RetType{CharPtrTy}),
3564 .ArgConstraint(NotNull(ArgNo(0)))
3565 .ArgConstraint(NotNull(ArgNo(1)))
3566 .ArgConstraint(BufferSize(ArgNo(1),
3567 BVF.getValue(26, IntTy))));
3570 addToFunctionSummaryMap(
3572 Signature(ArgTypes{ConstTime_tPtrTy, CharPtrTy}, RetType{CharPtrTy}),
3574 .ArgConstraint(NotNull(ArgNo(0)))
3575 .ArgConstraint(NotNull(ArgNo(1)))
3576 .ArgConstraint(BufferSize(
3578 BVF.getValue(26, IntTy))));
3582 addToFunctionSummaryMap(
3584 Signature(ArgTypes{ConstTime_tPtrRestrictTy, StructTmPtrRestrictTy},
3585 RetType{StructTmPtrTy}),
3587 .ArgConstraint(NotNull(ArgNo(0)))
3588 .ArgConstraint(NotNull(ArgNo(1))));
3591 addToFunctionSummaryMap(
3592 "gmtime", Signature(ArgTypes{ConstTime_tPtrTy}, RetType{StructTmPtrTy}),
3593 Summary(NoEvalCall).ArgConstraint(NotNull(ArgNo(0))));
3595 std::optional<QualType> Clockid_tTy = lookupTy(
"clockid_t");
3598 addToFunctionSummaryMap(
3600 Signature(ArgTypes{Clockid_tTy, StructTimespecPtrTy}, RetType{IntTy}),
3602 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
3603 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
3604 .ArgConstraint(NotNull(ArgNo(1))));
3606 std::optional<QualType> StructItimervalTy = lookupTy(
"itimerval");
3607 std::optional<QualType> StructItimervalPtrTy =
3608 getPointerTy(StructItimervalTy);
3611 addToFunctionSummaryMap(
3613 Signature(ArgTypes{IntTy, StructItimervalPtrTy}, RetType{IntTy}),
3615 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
3616 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
3617 .ArgConstraint(NotNull(ArgNo(1))));
3619 std::optional<QualType> Pthread_cond_tTy = lookupTy(
"pthread_cond_t");
3620 std::optional<QualType> Pthread_cond_tPtrTy =
3621 getPointerTy(Pthread_cond_tTy);
3622 std::optional<QualType> Pthread_tTy = lookupTy(
"pthread_t");
3623 std::optional<QualType> Pthread_tPtrTy = getPointerTy(Pthread_tTy);
3624 std::optional<QualType> Pthread_tPtrRestrictTy =
3625 getRestrictTy(Pthread_tPtrTy);
3626 std::optional<QualType> Pthread_mutex_tTy = lookupTy(
"pthread_mutex_t");
3627 std::optional<QualType> Pthread_mutex_tPtrTy =
3628 getPointerTy(Pthread_mutex_tTy);
3629 std::optional<QualType> Pthread_mutex_tPtrRestrictTy =
3630 getRestrictTy(Pthread_mutex_tPtrTy);
3631 std::optional<QualType> Pthread_attr_tTy = lookupTy(
"pthread_attr_t");
3632 std::optional<QualType> Pthread_attr_tPtrTy =
3633 getPointerTy(Pthread_attr_tTy);
3634 std::optional<QualType> ConstPthread_attr_tPtrTy =
3635 getPointerTy(getConstTy(Pthread_attr_tTy));
3636 std::optional<QualType> ConstPthread_attr_tPtrRestrictTy =
3637 getRestrictTy(ConstPthread_attr_tPtrTy);
3638 std::optional<QualType> Pthread_mutexattr_tTy =
3639 lookupTy(
"pthread_mutexattr_t");
3640 std::optional<QualType> ConstPthread_mutexattr_tPtrTy =
3641 getPointerTy(getConstTy(Pthread_mutexattr_tTy));
3642 std::optional<QualType> ConstPthread_mutexattr_tPtrRestrictTy =
3643 getRestrictTy(ConstPthread_mutexattr_tPtrTy);
3645 QualType PthreadStartRoutineTy = getPointerTy(
3647 FunctionProtoType::ExtProtoInfo()));
3651 addToFunctionSummaryMap(
3652 {
"pthread_cond_signal",
"pthread_cond_broadcast"},
3653 Signature(ArgTypes{Pthread_cond_tPtrTy}, RetType{IntTy}),
3654 Summary(NoEvalCall).ArgConstraint(NotNull(ArgNo(0))));
3659 addToFunctionSummaryMap(
3661 Signature(ArgTypes{Pthread_tPtrRestrictTy,
3662 ConstPthread_attr_tPtrRestrictTy,
3663 PthreadStartRoutineTy, VoidPtrRestrictTy},
3666 .ArgConstraint(NotNull(ArgNo(0)))
3667 .ArgConstraint(NotNull(ArgNo(2))));
3671 addToFunctionSummaryMap(
3672 {
"pthread_attr_destroy",
"pthread_attr_init"},
3673 Signature(ArgTypes{Pthread_attr_tPtrTy}, RetType{IntTy}),
3674 Summary(NoEvalCall).ArgConstraint(NotNull(ArgNo(0))));
3680 addToFunctionSummaryMap(
3681 {
"pthread_attr_getstacksize",
"pthread_attr_getguardsize"},
3682 Signature(ArgTypes{ConstPthread_attr_tPtrRestrictTy, SizePtrRestrictTy},
3685 .ArgConstraint(NotNull(ArgNo(0)))
3686 .ArgConstraint(NotNull(ArgNo(1))));
3690 addToFunctionSummaryMap(
3691 {
"pthread_attr_setstacksize",
"pthread_attr_setguardsize"},
3692 Signature(ArgTypes{Pthread_attr_tPtrTy, SizeTyCanonTy}, RetType{IntTy}),
3694 .ArgConstraint(NotNull(ArgNo(0)))
3696 ArgumentCondition(1, WithinRange,
Range(0, SizeMax))));
3700 addToFunctionSummaryMap(
3701 "pthread_mutex_init",
3702 Signature(ArgTypes{Pthread_mutex_tPtrRestrictTy,
3703 ConstPthread_mutexattr_tPtrRestrictTy},
3705 Summary(NoEvalCall).ArgConstraint(NotNull(ArgNo(0))));
3711 addToFunctionSummaryMap(
3712 {
"pthread_mutex_destroy",
"pthread_mutex_lock",
"pthread_mutex_trylock",
3713 "pthread_mutex_unlock"},
3714 Signature(ArgTypes{Pthread_mutex_tPtrTy}, RetType{IntTy}),
3715 Summary(NoEvalCall).ArgConstraint(NotNull(ArgNo(0))));
3719 if (AddTestFunctions) {
3720 const RangeInt IntMin = BVF.
getMinValue(IntTy)->getLimitedValue();
3722 addToFunctionSummaryMap(
3723 "__not_null", Signature(ArgTypes{IntPtrTy}, RetType{IntTy}),
3724 Summary(EvalCallAsPure).ArgConstraint(NotNull(ArgNo(0))));
3726 addToFunctionSummaryMap(
3727 "__not_null_buffer",
3728 Signature(ArgTypes{VoidPtrTy, IntTy, IntTy}, RetType{IntTy}),
3729 Summary(EvalCallAsPure)
3730 .ArgConstraint(NotNullBuffer(ArgNo(0), ArgNo(1), ArgNo(2))));
3733 addToFunctionSummaryMap(
3734 "__single_val_0", Signature(ArgTypes{IntTy}, RetType{IntTy}),
3735 Summary(EvalCallAsPure)
3736 .ArgConstraint(ArgumentCondition(0U, WithinRange, SingleValue(0))));
3737 addToFunctionSummaryMap(
3738 "__single_val_1", Signature(ArgTypes{IntTy}, RetType{IntTy}),
3739 Summary(EvalCallAsPure)
3740 .ArgConstraint(ArgumentCondition(0U, WithinRange, SingleValue(1))));
3741 addToFunctionSummaryMap(
3742 "__range_1_2", Signature(ArgTypes{IntTy}, RetType{IntTy}),
3743 Summary(EvalCallAsPure)
3744 .ArgConstraint(ArgumentCondition(0U, WithinRange,
Range(1, 2))));
3745 addToFunctionSummaryMap(
3746 "__range_m1_1", Signature(ArgTypes{IntTy}, RetType{IntTy}),
3747 Summary(EvalCallAsPure)
3748 .ArgConstraint(ArgumentCondition(0U, WithinRange,
Range(-1, 1))));
3749 addToFunctionSummaryMap(
3750 "__range_m2_m1", Signature(ArgTypes{IntTy}, RetType{IntTy}),
3751 Summary(EvalCallAsPure)
3752 .ArgConstraint(ArgumentCondition(0U, WithinRange,
Range(-2, -1))));
3753 addToFunctionSummaryMap(
3754 "__range_m10_10", Signature(ArgTypes{IntTy}, RetType{IntTy}),
3755 Summary(EvalCallAsPure)
3756 .ArgConstraint(ArgumentCondition(0U, WithinRange,
Range(-10, 10))));
3757 addToFunctionSummaryMap(
"__range_m1_inf",
3758 Signature(ArgTypes{IntTy}, RetType{IntTy}),
3759 Summary(EvalCallAsPure)
3760 .ArgConstraint(ArgumentCondition(
3761 0U, WithinRange,
Range(-1, IntMax))));
3762 addToFunctionSummaryMap(
"__range_0_inf",
3763 Signature(ArgTypes{IntTy}, RetType{IntTy}),
3764 Summary(EvalCallAsPure)
3765 .ArgConstraint(ArgumentCondition(
3766 0U, WithinRange,
Range(0, IntMax))));
3767 addToFunctionSummaryMap(
"__range_1_inf",
3768 Signature(ArgTypes{IntTy}, RetType{IntTy}),
3769 Summary(EvalCallAsPure)
3770 .ArgConstraint(ArgumentCondition(
3771 0U, WithinRange,
Range(1, IntMax))));
3772 addToFunctionSummaryMap(
"__range_minf_m1",
3773 Signature(ArgTypes{IntTy}, RetType{IntTy}),
3774 Summary(EvalCallAsPure)
3775 .ArgConstraint(ArgumentCondition(
3776 0U, WithinRange,
Range(IntMin, -1))));
3777 addToFunctionSummaryMap(
"__range_minf_0",
3778 Signature(ArgTypes{IntTy}, RetType{IntTy}),
3779 Summary(EvalCallAsPure)
3780 .ArgConstraint(ArgumentCondition(
3781 0U, WithinRange,
Range(IntMin, 0))));
3782 addToFunctionSummaryMap(
"__range_minf_1",
3783 Signature(ArgTypes{IntTy}, RetType{IntTy}),
3784 Summary(EvalCallAsPure)
3785 .ArgConstraint(ArgumentCondition(
3786 0U, WithinRange,
Range(IntMin, 1))));
3787 addToFunctionSummaryMap(
"__range_1_2__4_6",
3788 Signature(ArgTypes{IntTy}, RetType{IntTy}),
3789 Summary(EvalCallAsPure)
3790 .ArgConstraint(ArgumentCondition(
3791 0U, WithinRange,
Range({1, 2}, {4, 6}))));
3792 addToFunctionSummaryMap(
3793 "__range_1_2__4_inf", Signature(ArgTypes{IntTy}, RetType{IntTy}),
3794 Summary(EvalCallAsPure)
3795 .ArgConstraint(ArgumentCondition(0U, WithinRange,
3796 Range({1, 2}, {4, IntMax}))));
3799 addToFunctionSummaryMap(
3800 "__single_val_out_0", Signature(ArgTypes{IntTy}, RetType{IntTy}),
3801 Summary(EvalCallAsPure)
3802 .ArgConstraint(ArgumentCondition(0U, OutOfRange, SingleValue(0))));
3803 addToFunctionSummaryMap(
3804 "__single_val_out_1", Signature(ArgTypes{IntTy}, RetType{IntTy}),
3805 Summary(EvalCallAsPure)
3806 .ArgConstraint(ArgumentCondition(0U, OutOfRange, SingleValue(1))));
3807 addToFunctionSummaryMap(
3808 "__range_out_1_2", Signature(ArgTypes{IntTy}, RetType{IntTy}),
3809 Summary(EvalCallAsPure)
3810 .ArgConstraint(ArgumentCondition(0U, OutOfRange,
Range(1, 2))));
3811 addToFunctionSummaryMap(
3812 "__range_out_m1_1", Signature(ArgTypes{IntTy}, RetType{IntTy}),
3813 Summary(EvalCallAsPure)
3814 .ArgConstraint(ArgumentCondition(0U, OutOfRange,
Range(-1, 1))));
3815 addToFunctionSummaryMap(
3816 "__range_out_m2_m1", Signature(ArgTypes{IntTy}, RetType{IntTy}),
3817 Summary(EvalCallAsPure)
3818 .ArgConstraint(ArgumentCondition(0U, OutOfRange,
Range(-2, -1))));
3819 addToFunctionSummaryMap(
3820 "__range_out_m10_10", Signature(ArgTypes{IntTy}, RetType{IntTy}),
3821 Summary(EvalCallAsPure)
3822 .ArgConstraint(ArgumentCondition(0U, OutOfRange,
Range(-10, 10))));
3823 addToFunctionSummaryMap(
"__range_out_m1_inf",
3824 Signature(ArgTypes{IntTy}, RetType{IntTy}),
3825 Summary(EvalCallAsPure)
3826 .ArgConstraint(ArgumentCondition(
3827 0U, OutOfRange,
Range(-1, IntMax))));
3828 addToFunctionSummaryMap(
"__range_out_0_inf",
3829 Signature(ArgTypes{IntTy}, RetType{IntTy}),
3830 Summary(EvalCallAsPure)
3831 .ArgConstraint(ArgumentCondition(
3832 0U, OutOfRange,
Range(0, IntMax))));
3833 addToFunctionSummaryMap(
"__range_out_1_inf",
3834 Signature(ArgTypes{IntTy}, RetType{IntTy}),
3835 Summary(EvalCallAsPure)
3836 .ArgConstraint(ArgumentCondition(
3837 0U, OutOfRange,
Range(1, IntMax))));
3838 addToFunctionSummaryMap(
"__range_out_minf_m1",
3839 Signature(ArgTypes{IntTy}, RetType{IntTy}),
3840 Summary(EvalCallAsPure)
3841 .ArgConstraint(ArgumentCondition(
3842 0U, OutOfRange,
Range(IntMin, -1))));
3843 addToFunctionSummaryMap(
"__range_out_minf_0",
3844 Signature(ArgTypes{IntTy}, RetType{IntTy}),
3845 Summary(EvalCallAsPure)
3846 .ArgConstraint(ArgumentCondition(
3847 0U, OutOfRange,
Range(IntMin, 0))));
3848 addToFunctionSummaryMap(
"__range_out_minf_1",
3849 Signature(ArgTypes{IntTy}, RetType{IntTy}),
3850 Summary(EvalCallAsPure)
3851 .ArgConstraint(ArgumentCondition(
3852 0U, OutOfRange,
Range(IntMin, 1))));
3853 addToFunctionSummaryMap(
"__range_out_1_2__4_6",
3854 Signature(ArgTypes{IntTy}, RetType{IntTy}),
3855 Summary(EvalCallAsPure)
3856 .ArgConstraint(ArgumentCondition(
3857 0U, OutOfRange,
Range({1, 2}, {4, 6}))));
3858 addToFunctionSummaryMap(
3859 "__range_out_1_2__4_inf", Signature(ArgTypes{IntTy}, RetType{IntTy}),
3860 Summary(EvalCallAsPure)
3862 ArgumentCondition(0U, OutOfRange,
Range({1, 2}, {4, IntMax}))));
3865 addToFunctionSummaryMap(
3866 "__within", Signature(ArgTypes{IntTy}, RetType{IntTy}),
3867 Summary(EvalCallAsPure)
3868 .ArgConstraint(ArgumentCondition(0U, WithinRange, SingleValue(1))));
3869 addToFunctionSummaryMap(
3870 "__out_of", Signature(ArgTypes{IntTy}, RetType{IntTy}),
3871 Summary(EvalCallAsPure)
3872 .ArgConstraint(ArgumentCondition(0U, OutOfRange, SingleValue(1))));
3874 addToFunctionSummaryMap(
3875 "__two_constrained_args",
3876 Signature(ArgTypes{IntTy, IntTy}, RetType{IntTy}),
3877 Summary(EvalCallAsPure)
3878 .ArgConstraint(ArgumentCondition(0U, WithinRange, SingleValue(1)))
3879 .ArgConstraint(ArgumentCondition(1U, WithinRange, SingleValue(1))));
3880 addToFunctionSummaryMap(
3881 "__arg_constrained_twice", Signature(ArgTypes{IntTy}, RetType{IntTy}),
3882 Summary(EvalCallAsPure)
3883 .ArgConstraint(ArgumentCondition(0U, OutOfRange, SingleValue(1)))
3884 .ArgConstraint(ArgumentCondition(0U, OutOfRange, SingleValue(2))));
3885 addToFunctionSummaryMap(
3887 Signature(ArgTypes{
Irrelevant, IntTy}, RetType{IntTy}),
3888 Summary(EvalCallAsPure).ArgConstraint(NotNull(ArgNo(0))));
3889 addToFunctionSummaryMap(
3891 Signature(ArgTypes{VoidPtrTy, ConstCharPtrTy}, RetType{IntTy}),
3892 Summary(EvalCallAsPure)
3893 .ArgConstraint(NotNull(ArgNo(0)))
3894 .ArgConstraint(NotNull(ArgNo(1))));
3895 addToFunctionSummaryMap(
3896 "__buf_size_arg_constraint",
3897 Signature(ArgTypes{ConstVoidPtrTy, SizeTyCanonTy}, RetType{IntTy}),
3898 Summary(EvalCallAsPure)
3900 BufferSize(ArgNo(0), ArgNo(1))));
3901 addToFunctionSummaryMap(
3902 "__buf_size_arg_constraint_mul",
3903 Signature(ArgTypes{ConstVoidPtrTy, SizeTyCanonTy, SizeTyCanonTy},
3905 Summary(EvalCallAsPure)
3906 .ArgConstraint(BufferSize(ArgNo(0), ArgNo(1),
3908 addToFunctionSummaryMap(
3909 "__buf_size_arg_constraint_concrete",
3910 Signature(ArgTypes{ConstVoidPtrTy}, RetType{IntTy}),
3911 Summary(EvalCallAsPure)
3912 .ArgConstraint(BufferSize(ArgNo(0),
3913 BVF.getValue(10, IntTy))));
3914 addToFunctionSummaryMap(
3915 {
"__test_restrict_param_0",
"__test_restrict_param_1",
3916 "__test_restrict_param_2"},
3917 Signature(ArgTypes{VoidPtrRestrictTy}, RetType{VoidTy}),
3918 Summary(EvalCallAsPure));
3921 addToFunctionSummaryMap(
3922 "__test_case_note", Signature(ArgTypes{}, RetType{IntTy}),
3923 Summary(EvalCallAsPure)
3924 .Case({ReturnValueCondition(WithinRange, SingleValue(0))},
3925 ErrnoIrrelevant,
"Function returns 0")
3926 .Case({ReturnValueCondition(WithinRange, SingleValue(1))},
3927 ErrnoIrrelevant,
"Function returns 1"));
3928 addToFunctionSummaryMap(
3929 "__test_case_range_1_2__4_6",
3930 Signature(ArgTypes{IntTy}, RetType{IntTy}),
3931 Summary(EvalCallAsPure)
3932 .Case({ArgumentCondition(0U, WithinRange,
3933 IntRangeVector{{IntMin, 0}, {3, 3}}),
3934 ReturnValueCondition(WithinRange, SingleValue(1))},
3936 .Case({ArgumentCondition(0U, WithinRange,
3937 IntRangeVector{{3, 3}, {7, IntMax}}),
3938 ReturnValueCondition(WithinRange, SingleValue(2))},
3940 .Case({ArgumentCondition(0U, WithinRange,
3941 IntRangeVector{{IntMin, 0}, {7, IntMax}}),
3942 ReturnValueCondition(WithinRange, SingleValue(3))},
3944 .Case({ArgumentCondition(
3946 IntRangeVector{{IntMin, 0}, {3, 3}, {7, IntMax}}),
3947 ReturnValueCondition(WithinRange, SingleValue(4))},
3952void ento::registerStdCLibraryFunctionsChecker(CheckerManager &mgr) {
3956 Checker->DisplayLoadedSummaries =
3957 Opts.getCheckerBooleanOption(Checker,
"DisplayLoadedSummaries");
3958 Checker->ModelPOSIX = Opts.getCheckerBooleanOption(Checker,
"ModelPOSIX");
3959 Checker->ShouldAssumeControlledEnvironment =
3960 Opts.ShouldAssumeControlledEnvironment;
3963bool ento::shouldRegisterStdCLibraryFunctionsChecker(
3964 const CheckerManager &mgr) {
3968void ento::registerStdCLibraryFunctionsTesterChecker(CheckerManager &mgr) {
3969 auto *Checker = mgr.
getChecker<StdLibraryFunctionsChecker>();
3970 Checker->AddTestFunctions =
true;
3973bool ento::shouldRegisterStdCLibraryFunctionsTesterChecker(
3974 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
bool isNull() const
Return true if this QualType doesn't point to a type yet.
QualType getCanonicalType() const
void removeLocalRestrict()
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
SVal evalBinOp(ProgramStateRef state, BinaryOperator::Opcode op, SVal lhs, SVal rhs, QualType type)
DefinedOrUnknownSVal conjureSymbolVal(const void *symbolTag, ConstCFGElementRef elem, const StackFrame *SF, unsigned count)
Create a new symbol with a unique 'name'.
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)
PRESERVE_NONE 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.
U cast(CodeGen::Address addr)
int const char * function
__packed_splat4 __packed_splat2 __packed_splat8 __packed_splat4 __packed_splat2 __packed_splat4 __packed_splat2 __packed_splat8 __packed_splat4 uint32_t