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 return getArgType(FD, ArgN)->isIntegralType(FD->
getASTContext());
315 using RangeApplyFunction =
320 void applyOnWithinRange(BasicValueFactory &BVF, QualType ArgT,
321 const RangeApplyFunction &F)
const;
332 void applyOnOutOfRange(BasicValueFactory &BVF, QualType ArgT,
333 const RangeApplyFunction &F)
const;
336 void applyOnRange(RangeKind Kind, BasicValueFactory &BVF, QualType ArgT,
337 const RangeApplyFunction &F)
const {
340 applyOnOutOfRange(BVF, ArgT, F);
343 applyOnWithinRange(BVF, ArgT, F);
350 class ComparisonConstraint :
public ValueConstraint {
357 : ValueConstraint(ArgN), Opcode(Opcode), OtherArgN(OtherArgN) {}
358 ArgNo getOtherArgNo()
const {
return OtherArgN; }
361 const Summary &Summary,
362 CheckerContext &
C)
const override;
366 class NullnessConstraint :
public ValueConstraint {
367 using ValueConstraint::ValueConstraint;
369 bool CannotBeNull =
true;
372 NullnessConstraint(ArgNo ArgN,
bool CannotBeNull =
true)
373 : ValueConstraint(ArgN), CannotBeNull(CannotBeNull) {}
376 const Summary &Summary,
377 CheckerContext &
C)
const override;
379 void describe(DescriptionKind DK,
const CallEvent &
Call,
381 llvm::raw_ostream &Out)
const override;
384 const Summary &Summary,
385 llvm::raw_ostream &Out)
const override;
387 ValueConstraintPtr negate()
const override {
388 NullnessConstraint Tmp(*
this);
389 Tmp.CannotBeNull = !this->CannotBeNull;
390 return std::make_shared<NullnessConstraint>(Tmp);
394 bool checkSpecificValidity(
const FunctionDecl *FD)
const override {
395 const bool ValidArg = getArgType(FD, ArgN)->isPointerType();
397 "This constraint should be applied only on a pointer type");
408 class BufferNullnessConstraint :
public ValueConstraint {
409 using ValueConstraint::ValueConstraint;
411 std::optional<ArgNo> SizeArg2N;
413 bool CannotBeNull =
true;
416 BufferNullnessConstraint(ArgNo ArgN, ArgNo SizeArg1N,
417 std::optional<ArgNo> SizeArg2N,
418 bool CannotBeNull =
true)
419 : ValueConstraint(ArgN), SizeArg1N(SizeArg1N), SizeArg2N(SizeArg2N),
420 CannotBeNull(CannotBeNull) {}
423 const Summary &Summary,
424 CheckerContext &
C)
const override;
426 void describe(DescriptionKind DK,
const CallEvent &
Call,
428 llvm::raw_ostream &Out)
const override;
431 const Summary &Summary,
432 llvm::raw_ostream &Out)
const override;
434 ValueConstraintPtr negate()
const override {
435 BufferNullnessConstraint Tmp(*
this);
436 Tmp.CannotBeNull = !this->CannotBeNull;
437 return std::make_shared<BufferNullnessConstraint>(Tmp);
441 bool checkSpecificValidity(
const FunctionDecl *FD)
const override {
442 const bool ValidArg = getArgType(FD, ArgN)->isPointerType();
444 "This constraint should be applied only on a pointer type");
459 class BufferSizeConstraint :
public ValueConstraint {
461 std::optional<llvm::APSInt> ConcreteSize;
463 std::optional<ArgNo> SizeArgN;
467 std::optional<ArgNo> SizeMultiplierArgN;
472 BufferSizeConstraint(ArgNo Buffer, llvm::APSInt BufMinSize)
473 : ValueConstraint(Buffer), ConcreteSize(BufMinSize) {}
474 BufferSizeConstraint(ArgNo Buffer, ArgNo BufSize)
475 : ValueConstraint(Buffer), SizeArgN(BufSize) {}
476 BufferSizeConstraint(ArgNo Buffer, ArgNo BufSize, ArgNo BufSizeMultiplier)
477 : ValueConstraint(Buffer), SizeArgN(BufSize),
478 SizeMultiplierArgN(BufSizeMultiplier) {}
481 const Summary &Summary,
482 CheckerContext &
C)
const override;
484 void describe(DescriptionKind DK,
const CallEvent &
Call,
486 llvm::raw_ostream &Out)
const override;
489 const Summary &Summary,
490 llvm::raw_ostream &Out)
const override;
492 std::vector<ArgNo> getArgsToTrack()
const override {
493 std::vector<ArgNo>
Result{ArgN};
495 Result.push_back(*SizeArgN);
496 if (SizeMultiplierArgN)
497 Result.push_back(*SizeMultiplierArgN);
501 ValueConstraintPtr negate()
const override {
502 BufferSizeConstraint Tmp(*
this);
504 return std::make_shared<BufferSizeConstraint>(Tmp);
508 bool checkSpecificValidity(
const FunctionDecl *FD)
const override {
509 const bool ValidArg = getArgType(FD, ArgN)->isPointerType();
511 "This constraint should be applied only on a pointer type");
517 using ConstraintSet = std::vector<ValueConstraintPtr>;
526 class ErrnoConstraintBase {
530 const Summary &Summary,
531 CheckerContext &
C)
const = 0;
536 virtual std::string
describe(CheckerContext &
C)
const {
return ""; }
538 virtual ~ErrnoConstraintBase() {}
541 ErrnoConstraintBase() =
default;
551 class ResetErrnoConstraint :
public ErrnoConstraintBase {
554 const Summary &Summary,
555 CheckerContext &
C)
const override {
564 class NoErrnoConstraint :
public ErrnoConstraintBase {
567 const Summary &Summary,
568 CheckerContext &
C)
const override {
577 class FailureErrnoConstraint :
public ErrnoConstraintBase {
580 const Summary &Summary,
581 CheckerContext &
C)
const override {
582 SValBuilder &SVB =
C.getSValBuilder();
584 C.blockCount(), &Tag)
595 class SuccessErrnoConstraint :
public ErrnoConstraintBase {
598 const Summary &Summary,
599 CheckerContext &
C)
const override {
603 std::string
describe(CheckerContext &
C)
const override {
604 return "'errno' becomes undefined after the call";
612 class ErrnoMustBeCheckedConstraint :
public ErrnoConstraintBase {
615 const Summary &Summary,
616 CheckerContext &
C)
const override {
618 Call.getCFGElementRef());
621 std::string
describe(CheckerContext &
C)
const override {
622 return "reading 'errno' is required to find out if the call has failed";
648 ConstraintSet Constraints;
649 const ErrnoConstraintBase &ErrnoConstraint;
653 SummaryCase(ConstraintSet &&Constraints,
const ErrnoConstraintBase &ErrnoC,
655 : Constraints(std::move(Constraints)), ErrnoConstraint(ErrnoC),
658 SummaryCase(
const ConstraintSet &Constraints,
659 const ErrnoConstraintBase &ErrnoC, StringRef Note)
660 : Constraints(Constraints), ErrnoConstraint(ErrnoC), Note(Note) {}
662 const ConstraintSet &getConstraints()
const {
return Constraints; }
663 const ErrnoConstraintBase &getErrnoConstraint()
const {
664 return ErrnoConstraint;
666 StringRef getNote()
const {
return Note; }
669 using ArgTypes = ArrayRef<std::optional<QualType>>;
670 using RetType = std::optional<QualType>;
674 const QualType Irrelevant{};
675 bool static isIrrelevant(QualType
T) {
return T.isNull(); }
682 using ArgQualTypes = std::vector<QualType>;
686 bool Invalid =
false;
691 Signature(ArgTypes ArgTys, RetType RetTy) {
692 for (std::optional<QualType> Arg : ArgTys) {
697 assertArgTypeSuitableForSignature(*Arg);
698 this->ArgTys.push_back(*Arg);
705 assertRetTypeSuitableForSignature(*RetTy);
706 this->RetTy = *RetTy;
710 bool isInvalid()
const {
return Invalid; }
711 bool matches(
const FunctionDecl *FD)
const;
714 static void assertArgTypeSuitableForSignature(QualType
T) {
716 "We should have no void types in the spec");
717 assert((
T.isNull() ||
T.isCanonical()) &&
718 "We should only have canonical types in the spec");
720 static void assertRetTypeSuitableForSignature(QualType
T) {
721 assert((
T.isNull() ||
T.isCanonical()) &&
722 "We should only have canonical types in the spec");
726 static QualType getArgType(
const FunctionDecl *FD, ArgNo ArgN) {
727 assert(FD &&
"Function must be set");
728 QualType
T = (ArgN == Ret)
734 using SummaryCases = std::vector<SummaryCase>;
753 const InvalidationKind InvalidationKd;
755 ConstraintSet ArgConstraints;
759 const FunctionDecl *FD =
nullptr;
762 Summary(InvalidationKind InvalidationKd) : InvalidationKd(InvalidationKd) {}
764 Summary &Case(ConstraintSet &&CS,
const ErrnoConstraintBase &ErrnoC,
765 StringRef
Note =
"") {
766 Cases.push_back(SummaryCase(std::move(CS), ErrnoC,
Note));
769 Summary &Case(
const ConstraintSet &CS,
const ErrnoConstraintBase &ErrnoC,
770 StringRef
Note =
"") {
771 Cases.push_back(SummaryCase(CS, ErrnoC,
Note));
774 Summary &ArgConstraint(ValueConstraintPtr VC) {
775 assert(VC->getArgNo() != Ret &&
776 "Arg constraint should not refer to the return value");
777 ArgConstraints.push_back(VC);
781 InvalidationKind getInvalidationKd()
const {
return InvalidationKd; }
782 const SummaryCases &getCases()
const {
return Cases; }
783 const ConstraintSet &getArgConstraints()
const {
return ArgConstraints; }
785 QualType getArgType(ArgNo ArgN)
const {
786 return StdLibraryFunctionsChecker::getArgType(FD, ArgN);
791 bool matchesAndSet(
const Signature &Sign,
const FunctionDecl *FD) {
792 bool Result = Sign.matches(FD) && validateByConstraints(FD);
794 assert(!this->FD &&
"FD must not be set more than once");
803 bool validateByConstraints(
const FunctionDecl *FD)
const {
804 for (
const SummaryCase &Case : Cases)
805 for (
const ValueConstraintPtr &Constraint : Case.getConstraints())
806 if (!Constraint->checkValidity(FD))
808 for (
const ValueConstraintPtr &Constraint : ArgConstraints)
809 if (!Constraint->checkValidity(FD))
817 using FunctionSummaryMapType = llvm::DenseMap<const FunctionDecl *, Summary>;
818 mutable FunctionSummaryMapType FunctionSummaryMap;
820 const BugType BT_InvalidArg{
this,
"Function call with invalid argument"};
821 mutable bool SummariesInitialized =
false;
823 static SVal getArgSVal(
const CallEvent &
Call, ArgNo ArgN) {
824 return ArgN == Ret ?
Call.getReturnValue() :
Call.getArgSVal(ArgN);
827 assert(
Call.getDecl() &&
828 "Call was found by a summary, should have declaration");
833 void checkPreCall(
const CallEvent &
Call, CheckerContext &
C)
const;
834 void checkPostCall(
const CallEvent &
Call, CheckerContext &
C)
const;
835 bool evalCall(
const CallEvent &
Call, CheckerContext &
C)
const;
837 CheckerNameRef CheckName;
838 bool AddTestFunctions =
false;
840 bool DisplayLoadedSummaries =
false;
841 bool ModelPOSIX =
false;
842 bool ShouldAssumeControlledEnvironment =
false;
845 std::optional<Summary> findFunctionSummary(
const FunctionDecl *FD,
846 CheckerContext &
C)
const;
847 std::optional<Summary> findFunctionSummary(
const CallEvent &
Call,
848 CheckerContext &
C)
const;
850 LLVM_ATTRIBUTE_MINSIZE
void initFunctionSummaries(CheckerContext &
C)
const;
852 void reportBug(
const CallEvent &
Call, ExplodedNode *N,
853 const ValueConstraint *VC,
const ValueConstraint *NegatedVC,
854 const Summary &Summary, CheckerContext &
C)
const {
855 assert(
Call.getDecl() &&
856 "Function found in summary must have a declaration available");
857 SmallString<256> Msg;
858 llvm::raw_svector_ostream MsgOs(Msg);
861 printArgDesc(VC->getArgNo(), MsgOs);
864 NegatedVC->describeArgumentValue(
Call, N->
getState(), Summary, MsgOs);
868 MsgOs <<
"is out of the accepted range; It ";
869 VC->describe(ValueConstraint::Violation,
Call,
C.getState(), Summary,
871 Msg[0] = toupper(Msg[0]);
872 auto R = std::make_unique<PathSensitiveBugReport>(BT_InvalidArg, Msg, N);
874 for (ArgNo ArgN : VC->getArgsToTrack()) {
876 R->markInteresting(
Call.getArgSVal(ArgN));
878 R->addRange(
Call.getArgSourceRange(ArgN));
881 C.emitReport(std::move(R));
889 const NoErrnoConstraint ErrnoUnchanged{};
890 const ResetErrnoConstraint ErrnoIrrelevant{};
891 const ErrnoMustBeCheckedConstraint ErrnoMustBeChecked{};
892 const SuccessErrnoConstraint ErrnoMustNotBeChecked{};
893 const FailureErrnoConstraint ErrnoNEZeroIrrelevant{};
896int StdLibraryFunctionsChecker::ErrnoConstraintBase::Tag = 0;
898const StdLibraryFunctionsChecker::ArgNo StdLibraryFunctionsChecker::Ret =
899 std::numeric_limits<ArgNo>::max();
909void StdLibraryFunctionsChecker::printArgDesc(
910 StdLibraryFunctionsChecker::ArgNo ArgN, llvm::raw_ostream &Out) {
911 Out << std::to_string(ArgN + 1);
912 Out << llvm::getOrdinalSuffix(ArgN + 1);
916void StdLibraryFunctionsChecker::printArgValueInfo(ArgNo ArgN,
918 const CallEvent &
Call,
919 llvm::raw_ostream &Out) {
920 if (
const llvm::APSInt *Val =
921 State->getStateManager().getSValBuilder().getKnownValue(
922 State, getArgSVal(
Call, ArgN)))
923 Out <<
" (which is " << *Val <<
")";
926void StdLibraryFunctionsChecker::appendInsideRangeDesc(llvm::APSInt RMin,
929 BasicValueFactory &BVF,
930 llvm::raw_ostream &Out) {
931 if (RMin.isZero() && RMax.isZero())
933 else if (RMin == RMax)
939 Out <<
"<= " << RMax;
944 Out <<
">= " << RMin;
945 }
else if (RMin.isNegative() == RMax.isNegative() &&
946 RMin.getLimitedValue() == RMax.getLimitedValue() - 1) {
947 Out << RMin <<
" or " << RMax;
949 Out <<
"between " << RMin <<
" and " << RMax;
953void StdLibraryFunctionsChecker::appendOutOfRangeDesc(llvm::APSInt RMin,
956 BasicValueFactory &BVF,
957 llvm::raw_ostream &Out) {
958 if (RMin.isZero() && RMax.isZero())
960 else if (RMin == RMax) {
961 Out <<
"not equal to " << RMin;
972 }
else if (RMin.isNegative() == RMax.isNegative() &&
973 RMin.getLimitedValue() == RMax.getLimitedValue() - 1) {
974 Out <<
"not " << RMin <<
" and not " << RMax;
976 Out <<
"not between " << RMin <<
" and " << RMax;
980void StdLibraryFunctionsChecker::RangeConstraint::applyOnWithinRange(
981 BasicValueFactory &BVF, QualType ArgT,
const RangeApplyFunction &F)
const {
985 for (
auto [Start, End] : getRanges()) {
986 const llvm::APSInt &
Min = BVF.getValue(Start, ArgT);
987 const llvm::APSInt &
Max = BVF.getValue(End, ArgT);
994void StdLibraryFunctionsChecker::RangeConstraint::applyOnOutOfRange(
995 BasicValueFactory &BVF, QualType ArgT,
const RangeApplyFunction &F)
const {
999 const IntRangeVector &
R = getRanges();
1000 size_t E =
R.size();
1002 const llvm::APSInt &MinusInf = BVF.
getMinValue(ArgT);
1003 const llvm::APSInt &PlusInf = BVF.
getMaxValue(ArgT);
1005 const llvm::APSInt &RangeLeft = BVF.getValue(R[0].first - 1ULL, ArgT);
1006 const llvm::APSInt &RangeRight = BVF.getValue(R[E - 1].second + 1ULL, ArgT);
1009 for (
size_t I = 1; I != E; ++I) {
1010 const llvm::APSInt &
Min = BVF.getValue(R[I - 1].second + 1ULL, ArgT);
1011 const llvm::APSInt &
Max = BVF.getValue(R[I].first - 1ULL, ArgT);
1018 if (RangeLeft != PlusInf) {
1019 assert(MinusInf <= RangeLeft);
1020 if (!F(MinusInf, RangeLeft))
1024 if (RangeRight != MinusInf) {
1025 assert(RangeRight <= PlusInf);
1026 if (!F(RangeRight, PlusInf))
1033 CheckerContext &
C)
const {
1034 ConstraintManager &CM =
C.getConstraintManager();
1035 SVal
V = getArgSVal(
Call, getArgNo());
1036 QualType
T = Summary.getArgType(getArgNo());
1038 if (
auto N =
V.getAs<NonLoc>()) {
1039 auto ExcludeRangeFromArg = [&](
const llvm::APSInt &
Min,
1040 const llvm::APSInt &
Max) {
1042 return static_cast<bool>(State);
1046 applyOnRange(negateKind(Kind),
C.getSValBuilder().getBasicValueFactory(),
T,
1047 ExcludeRangeFromArg);
1053void StdLibraryFunctionsChecker::RangeConstraint::describe(
1055 const Summary &Summary, llvm::raw_ostream &Out)
const {
1057 BasicValueFactory &BVF = getBVF(State);
1058 QualType
T = Summary.getArgType(getArgNo());
1060 Out << ((DK == Violation) ?
"should be " :
"is ");
1061 if (!Description.empty()) {
1064 unsigned I = Ranges.size();
1065 if (Kind == WithinRange) {
1066 for (
const std::pair<RangeInt, RangeInt> &R : Ranges) {
1067 appendInsideRangeDesc(BVF.getValue(
R.first,
T),
1068 BVF.getValue(
R.second,
T),
T, BVF, Out);
1073 for (
const std::pair<RangeInt, RangeInt> &R : Ranges) {
1074 appendOutOfRangeDesc(BVF.getValue(
R.first,
T),
1075 BVF.getValue(
R.second,
T),
T, BVF, Out);
1083bool StdLibraryFunctionsChecker::RangeConstraint::describeArgumentValue(
1085 llvm::raw_ostream &Out)
const {
1086 unsigned int NRanges = 0;
1087 bool HaveAllRanges =
true;
1089 ProgramStateManager &Mgr = State->getStateManager();
1092 SVal
V = getArgSVal(
Call, getArgNo());
1094 if (
auto N =
V.getAs<NonLoc>()) {
1095 if (
const llvm::APSInt *Int = N->getAsInteger()) {
1100 QualType
T = Summary.getArgType(getArgNo());
1101 SmallString<128> MoreInfo;
1102 llvm::raw_svector_ostream MoreInfoOs(MoreInfo);
1103 auto ApplyF = [&](
const llvm::APSInt &
Min,
const llvm::APSInt &
Max) {
1106 MoreInfoOs <<
" or ";
1107 appendInsideRangeDesc(
Min,
Max,
T, BVF, MoreInfoOs);
1110 HaveAllRanges =
false;
1115 applyOnRange(Kind, BVF,
T, ApplyF);
1116 assert(NRanges > 0);
1117 if (!HaveAllRanges || NRanges == 1) {
1126ProgramStateRef StdLibraryFunctionsChecker::ComparisonConstraint::apply(
1128 CheckerContext &
C)
const {
1130 ProgramStateManager &Mgr = State->getStateManager();
1133 QualType
T = Summary.getArgType(getArgNo());
1134 SVal
V = getArgSVal(
Call, getArgNo());
1137 ArgNo OtherArg = getOtherArgNo();
1138 SVal OtherV = getArgSVal(
Call, OtherArg);
1139 QualType OtherT = Summary.getArgType(OtherArg);
1141 OtherV = SVB.
evalCast(OtherV,
T, OtherT);
1142 if (
auto CompV = SVB.
evalBinOp(State, Op,
V, OtherV, CondT)
1143 .
getAs<DefinedOrUnknownSVal>())
1144 State = State->assume(*CompV,
true);
1150 CheckerContext &
C)
const {
1151 SVal
V = getArgSVal(
Call, getArgNo());
1155 DefinedOrUnknownSVal L =
V.castAs<DefinedOrUnknownSVal>();
1159 return State->assume(L, CannotBeNull);
1162void StdLibraryFunctionsChecker::NullnessConstraint::describe(
1164 const Summary &Summary, llvm::raw_ostream &Out)
const {
1165 assert(CannotBeNull &&
1166 "'describe' is not implemented when the value must be NULL");
1167 if (DK == Violation)
1168 Out <<
"should not be NULL";
1170 Out <<
"is not NULL";
1173bool StdLibraryFunctionsChecker::NullnessConstraint::describeArgumentValue(
1175 llvm::raw_ostream &Out)
const {
1176 assert(!CannotBeNull &&
"'describeArgumentValue' is not implemented when the "
1177 "value must be non-NULL");
1182ProgramStateRef StdLibraryFunctionsChecker::BufferNullnessConstraint::apply(
1184 CheckerContext &
C)
const {
1185 SVal
V = getArgSVal(
Call, getArgNo());
1188 DefinedOrUnknownSVal L =
V.
castAs<DefinedOrUnknownSVal>();
1192 std::optional<DefinedOrUnknownSVal> SizeArg1 =
1193 getArgSVal(
Call, SizeArg1N).getAs<DefinedOrUnknownSVal>();
1194 std::optional<DefinedOrUnknownSVal> SizeArg2;
1196 SizeArg2 = getArgSVal(
Call, *SizeArg2N).getAs<DefinedOrUnknownSVal>();
1198 auto IsArgZero = [State](std::optional<DefinedOrUnknownSVal> Val) {
1205 if (IsArgZero(SizeArg1) || IsArgZero(SizeArg2))
1208 return State->assume(L, CannotBeNull);
1211void StdLibraryFunctionsChecker::BufferNullnessConstraint::describe(
1213 const Summary &Summary, llvm::raw_ostream &Out)
const {
1214 assert(CannotBeNull &&
1215 "'describe' is not implemented when the buffer must be NULL");
1216 if (DK == Violation)
1217 Out <<
"should not be NULL";
1219 Out <<
"is not NULL";
1222bool StdLibraryFunctionsChecker::BufferNullnessConstraint::
1224 const Summary &Summary,
1225 llvm::raw_ostream &Out)
const {
1226 assert(!CannotBeNull &&
"'describeArgumentValue' is not implemented when the "
1227 "buffer must be non-NULL");
1232ProgramStateRef StdLibraryFunctionsChecker::BufferSizeConstraint::apply(
1234 CheckerContext &
C)
const {
1235 SValBuilder &SvalBuilder =
C.getSValBuilder();
1237 SVal BufV = getArgSVal(
Call, getArgNo());
1240 const SVal SizeV = [
this, &State, &
Call, &Summary, &SvalBuilder]() {
1242 return SVal(SvalBuilder.
makeIntVal(*ConcreteSize));
1244 assert(SizeArgN &&
"The constraint must be either a concrete value or "
1245 "encoded in an argument.");
1247 SVal SizeV = getArgSVal(
Call, *SizeArgN);
1249 if (SizeMultiplierArgN) {
1250 SVal SizeMulV = getArgSVal(
Call, *SizeMultiplierArgN);
1251 SizeV = SvalBuilder.
evalBinOp(State, BO_Mul, SizeV, SizeMulV,
1252 Summary.getArgType(*SizeArgN));
1260 SVal Feasible = SvalBuilder.
evalBinOp(State, Op, SizeV, BufDynSize,
1262 if (
auto F = Feasible.
getAs<DefinedOrUnknownSVal>())
1263 return State->assume(*F,
true);
1271 llvm_unreachable(
"Size argument or the dynamic size is Undefined");
1274void StdLibraryFunctionsChecker::BufferSizeConstraint::describe(
1276 const Summary &Summary, llvm::raw_ostream &Out)
const {
1277 Out << ((DK == Violation) ?
"should be " :
"is ");
1278 Out <<
"a buffer with size equal to or greater than ";
1280 Out << *ConcreteSize;
1281 }
else if (SizeArgN) {
1282 Out <<
"the value of the ";
1283 printArgDesc(*SizeArgN, Out);
1284 printArgValueInfo(*SizeArgN, State,
Call, Out);
1285 if (SizeMultiplierArgN) {
1286 Out <<
" times the ";
1287 printArgDesc(*SizeMultiplierArgN, Out);
1288 printArgValueInfo(*SizeMultiplierArgN, State,
Call, Out);
1293bool StdLibraryFunctionsChecker::BufferSizeConstraint::describeArgumentValue(
1295 llvm::raw_ostream &Out)
const {
1296 SVal BufV = getArgSVal(
Call, getArgNo());
1298 if (
const llvm::APSInt *Val =
1299 State->getStateManager().getSValBuilder().getKnownValue(State,
1301 Out <<
"is a buffer with size " << *Val;
1307void StdLibraryFunctionsChecker::checkPreCall(
const CallEvent &
Call,
1308 CheckerContext &
C)
const {
1309 std::optional<Summary> FoundSummary = findFunctionSummary(
Call,
C);
1313 const Summary &Summary = *FoundSummary;
1317 ExplodedNode *NewNode =
C.getPredecessor();
1318 for (
const ValueConstraintPtr &Constraint : Summary.getArgConstraints()) {
1319 ValueConstraintPtr NegatedConstraint = Constraint->negate();
1322 NegatedConstraint->apply(NewState,
Call, Summary,
C);
1324 if (FailureSt && !SuccessSt) {
1325 if (ExplodedNode *N =
C.generateErrorNode(State, NewNode))
1326 reportBug(
Call, N, Constraint.get(), NegatedConstraint.get(), Summary,
1335 NewState = SuccessSt;
1336 if (NewState != State) {
1337 SmallString<128> Msg;
1338 llvm::raw_svector_ostream Os(Msg);
1339 Os <<
"Assuming that the ";
1340 printArgDesc(Constraint->getArgNo(), Os);
1344 Constraint->describe(ValueConstraint::Assumption,
Call, NewState, Summary,
1346 const auto ArgSVal =
Call.getArgSVal(Constraint->getArgNo());
1347 NewNode =
C.addTransition(
1349 C.getNoteTag([Msg = std::move(Msg), ArgSVal](
1350 PathSensitiveBugReport &BR, llvm::raw_ostream &
OS) {
1351 if (BR.isInteresting(ArgSVal))
1358void StdLibraryFunctionsChecker::checkPostCall(
const CallEvent &
Call,
1359 CheckerContext &
C)
const {
1360 std::optional<Summary> FoundSummary = findFunctionSummary(
Call,
C);
1365 const Summary &Summary = *FoundSummary;
1367 ExplodedNode *Node =
C.getPredecessor();
1370 for (
const SummaryCase &Case : Summary.getCases()) {
1372 for (
const ValueConstraintPtr &Constraint : Case.getConstraints()) {
1373 NewState = Constraint->apply(NewState,
Call, Summary,
C);
1379 NewState = Case.getErrnoConstraint().apply(NewState,
Call, Summary,
C);
1390 ExplodedNode *Pred = Node;
1391 DeclarationName FunctionName =
1394 std::string ErrnoNote = Case.getErrnoConstraint().describe(
C);
1395 std::string CaseNote;
1396 if (Case.getNote().empty()) {
1397 if (!ErrnoNote.empty())
1399 llvm::formatv(
"After calling '{0}' {1}", FunctionName, ErrnoNote);
1404 llvm::formatv(
false, Case.getNote().str().c_str(), FunctionName);
1406 const SVal RV =
Call.getReturnValue();
1408 if (Summary.getInvalidationKd() == EvalCallAsPure) {
1411 if (!CaseNote.empty()) {
1412 const NoteTag *
Tag =
C.getNoteTag(
1413 [Node, CaseNote, RV](PathSensitiveBugReport &BR) -> std::string {
1428 Pred =
C.addTransition(NewState, Pred, Tag);
1431 if (!CaseNote.empty() || !ErrnoNote.empty()) {
1432 const NoteTag *
Tag =
1433 C.getNoteTag([CaseNote, ErrnoNote,
1434 RV](PathSensitiveBugReport &BR) -> std::string {
1441 std::optional<Loc> ErrnoLoc =
1443 bool ErrnoImportant = !ErrnoNote.empty() && ErrnoLoc &&
1445 if (ErrnoImportant) {
1447 if (CaseNote.empty())
1449 return llvm::formatv(
"{0}; {1}", CaseNote, ErrnoNote);
1456 Pred =
C.addTransition(NewState, Pred, Tag);
1461 if (Pred == Node && NewState != State)
1462 C.addTransition(NewState);
1466bool StdLibraryFunctionsChecker::evalCall(
const CallEvent &
Call,
1467 CheckerContext &
C)
const {
1468 std::optional<Summary> FoundSummary = findFunctionSummary(
Call,
C);
1472 const Summary &Summary = *FoundSummary;
1473 switch (Summary.getInvalidationKd()) {
1474 case EvalCallAsPure: {
1477 SVal
V =
C.getSValBuilder().conjureSymbolVal(
Call,
C.blockCount());
1478 State = State->BindExpr(CE,
C.getStackFrame(),
V);
1480 C.addTransition(State);
1489 llvm_unreachable(
"Unknown invalidation kind!");
1492bool StdLibraryFunctionsChecker::Signature::matches(
1493 const FunctionDecl *FD)
const {
1506 auto RemoveRestrict = [&FD](QualType
T) {
1508 T.removeLocalRestrict();
1513 if (!isIrrelevant(RetTy)) {
1515 if (RetTy != FDRetTy)
1520 for (
auto [Idx, ArgTy] : llvm::enumerate(ArgTys)) {
1521 if (isIrrelevant(ArgTy))
1525 if (ArgTy != FDArgTy)
1532std::optional<StdLibraryFunctionsChecker::Summary>
1533StdLibraryFunctionsChecker::findFunctionSummary(
const FunctionDecl *FD,
1534 CheckerContext &
C)
const {
1536 return std::nullopt;
1538 initFunctionSummaries(
C);
1541 if (FSMI == FunctionSummaryMap.end())
1542 return std::nullopt;
1543 return FSMI->second;
1546std::optional<StdLibraryFunctionsChecker::Summary>
1547StdLibraryFunctionsChecker::findFunctionSummary(
const CallEvent &
Call,
1548 CheckerContext &
C)
const {
1549 const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(
Call.getDecl());
1551 return std::nullopt;
1552 return findFunctionSummary(FD,
C);
1555void StdLibraryFunctionsChecker::initFunctionSummaries(
1556 CheckerContext &
C)
const {
1557 if (SummariesInitialized)
1559 SummariesInitialized =
true;
1561 SValBuilder &SVB =
C.getSValBuilder();
1564 Preprocessor &PP =
C.getPreprocessor();
1568 const ASTContext &ACtx;
1571 LookupType(
const ASTContext &ACtx) : ACtx(ACtx) {}
1574 std::optional<QualType> operator()(StringRef Name) {
1575 IdentifierInfo &II = ACtx.
Idents.
get(Name);
1577 if (LookupRes.empty())
1578 return std::nullopt;
1585 for (Decl *D : LookupRes)
1586 if (
auto *TD = dyn_cast<TypedefNameDecl>(D))
1593 for (Decl *D : LookupRes)
1594 if (
auto *TD = dyn_cast<TypeDecl>(D))
1596 return std::nullopt;
1602 class GetRestrictTy {
1603 const ASTContext &ACtx;
1606 GetRestrictTy(
const ASTContext &ACtx) : ACtx(ACtx) {}
1607 QualType operator()(QualType Ty) {
1610 std::optional<QualType> operator()(std::optional<QualType> Ty) {
1612 return operator()(*Ty);
1613 return std::nullopt;
1615 } getRestrictTy(ACtx);
1616 class GetPointerTy {
1617 const ASTContext &ACtx;
1620 GetPointerTy(
const ASTContext &ACtx) : ACtx(ACtx) {}
1621 QualType operator()(QualType Ty) {
return ACtx.
getPointerType(Ty); }
1622 std::optional<QualType> operator()(std::optional<QualType> Ty) {
1624 return operator()(*Ty);
1625 return std::nullopt;
1627 } getPointerTy(ACtx);
1630 std::optional<QualType> operator()(std::optional<QualType> Ty) {
1631 return Ty ? std::optional<QualType>(Ty->withConst()) : std::nullopt;
1633 QualType operator()(QualType Ty) {
return Ty.
withConst(); }
1636 BasicValueFactory &BVF;
1639 GetMaxValue(BasicValueFactory &BVF) : BVF(BVF) {}
1640 std::optional<RangeInt> operator()(QualType Ty) {
1643 std::optional<RangeInt> operator()(std::optional<QualType> Ty) {
1645 return operator()(*Ty);
1647 return std::nullopt;
1658 const QualType VoidTy = ACtx.
VoidTy;
1659 const QualType CharTy = ACtx.
CharTy;
1660 const QualType WCharTy = ACtx.
WCharTy;
1661 const QualType IntTy = ACtx.
IntTy;
1663 const QualType LongTy = ACtx.
LongTy;
1666 const QualType VoidPtrTy = getPointerTy(VoidTy);
1667 const QualType IntPtrTy = getPointerTy(IntTy);
1668 const QualType UnsignedIntPtrTy =
1669 getPointerTy(UnsignedIntTy);
1670 const QualType VoidPtrRestrictTy = getRestrictTy(VoidPtrTy);
1671 const QualType ConstVoidPtrTy =
1672 getPointerTy(getConstTy(VoidTy));
1673 const QualType CharPtrTy = getPointerTy(CharTy);
1674 const QualType CharPtrRestrictTy = getRestrictTy(CharPtrTy);
1675 const QualType ConstCharPtrTy =
1676 getPointerTy(getConstTy(CharTy));
1677 const QualType ConstCharPtrRestrictTy = getRestrictTy(ConstCharPtrTy);
1678 const QualType Wchar_tPtrTy = getPointerTy(WCharTy);
1679 const QualType ConstWchar_tPtrTy =
1680 getPointerTy(getConstTy(WCharTy));
1681 const QualType ConstVoidPtrRestrictTy = getRestrictTy(ConstVoidPtrTy);
1682 const QualType SizePtrTy = getPointerTy(SizeTyCanonTy);
1683 const QualType SizePtrRestrictTy = getRestrictTy(SizePtrTy);
1685 const RangeInt IntMax = BVF.
getMaxValue(IntTy)->getLimitedValue();
1686 const RangeInt UnsignedIntMax =
1687 BVF.
getMaxValue(UnsignedIntTy)->getLimitedValue();
1688 const RangeInt LongMax = BVF.
getMaxValue(LongTy)->getLimitedValue();
1689 const RangeInt SizeMax = BVF.
getMaxValue(SizeTyCanonTy)->getLimitedValue();
1697 const RangeInt UCharRangeMax =
1707 struct AddToFunctionSummaryMap {
1708 const ASTContext &ACtx;
1709 FunctionSummaryMapType ⤅
1710 bool DisplayLoadedSummaries;
1711 AddToFunctionSummaryMap(
const ASTContext &ACtx, FunctionSummaryMapType &FSM,
1712 bool DisplayLoadedSummaries)
1713 : ACtx(ACtx), Map(FSM), DisplayLoadedSummaries(DisplayLoadedSummaries) {
1721 bool operator()(StringRef Name, Signature Sign, Summary Sum) {
1722 if (Sign.isInvalid())
1724 IdentifierInfo &II = ACtx.
Idents.
get(Name);
1726 if (LookupRes.empty())
1728 for (Decl *D : LookupRes) {
1729 if (
auto *FD = dyn_cast<FunctionDecl>(D)) {
1730 if (Sum.matchesAndSet(Sign, FD)) {
1732 assert(Res.second &&
"Function already has a summary set!");
1734 if (DisplayLoadedSummaries) {
1735 llvm::errs() <<
"Loaded summary for: ";
1736 FD->
print(llvm::errs());
1737 llvm::errs() <<
"\n";
1747 void operator()(ArrayRef<StringRef> Names, Signature Sign, Summary Sum) {
1748 for (StringRef Name : Names)
1749 operator()(Name, Sign, Sum);
1751 } addToFunctionSummaryMap(ACtx, FunctionSummaryMap, DisplayLoadedSummaries);
1754 auto ArgumentCondition = [](ArgNo ArgN, RangeKind
Kind, IntRangeVector Ranges,
1755 StringRef Desc =
"") {
1756 return std::make_shared<RangeConstraint>(ArgN, Kind, Ranges, Desc);
1758 auto BufferSize = [](
auto... Args) {
1759 return std::make_shared<BufferSizeConstraint>(Args...);
1762 auto operator()(RangeKind Kind, IntRangeVector Ranges) {
1763 return std::make_shared<RangeConstraint>(Ret, Kind, Ranges);
1766 return std::make_shared<ComparisonConstraint>(Ret, Op, OtherArgN);
1768 } ReturnValueCondition;
1770 auto operator()(RangeInt b, RangeInt e) {
1771 return IntRangeVector{std::pair<RangeInt, RangeInt>{b, e}};
1773 auto operator()(RangeInt b, std::optional<RangeInt> e) {
1775 return IntRangeVector{std::pair<RangeInt, RangeInt>{b, *e}};
1776 return IntRangeVector{};
1778 auto operator()(std::pair<RangeInt, RangeInt> i0,
1779 std::pair<RangeInt, std::optional<RangeInt>> i1) {
1781 return IntRangeVector{i0, {i1.first, *(i1.second)}};
1782 return IntRangeVector{i0};
1785 auto SingleValue = [](RangeInt v) {
1786 return IntRangeVector{std::pair<RangeInt, RangeInt>{v, v}};
1788 auto LessThanOrEq = BO_LE;
1789 auto NotNull = [&](ArgNo ArgN) {
1790 return std::make_shared<NullnessConstraint>(ArgN);
1792 auto IsNull = [&](ArgNo ArgN) {
1793 return std::make_shared<NullnessConstraint>(ArgN,
false);
1795 auto NotNullBuffer = [&](ArgNo ArgN, ArgNo SizeArg1N,
1796 std::optional<ArgNo> SizeArg2N = std::nullopt) {
1797 return std::make_shared<BufferNullnessConstraint>(ArgN, SizeArg1N,
1801 std::optional<QualType> FileTy = lookupTy(
"FILE");
1802 std::optional<QualType> FilePtrTy = getPointerTy(FileTy);
1803 std::optional<QualType> FilePtrRestrictTy = getRestrictTy(FilePtrTy);
1805 std::optional<QualType> FPosTTy = lookupTy(
"fpos_t");
1806 std::optional<QualType> FPosTPtrTy = getPointerTy(FPosTTy);
1807 std::optional<QualType> ConstFPosTPtrTy = getPointerTy(getConstTy(FPosTTy));
1808 std::optional<QualType> FPosTPtrRestrictTy = getRestrictTy(FPosTPtrTy);
1810 constexpr llvm::StringLiteral GenericSuccessMsg(
1811 "Assuming that '{0}' is successful");
1812 constexpr llvm::StringLiteral GenericFailureMsg(
"Assuming that '{0}' fails");
1829 addToFunctionSummaryMap(
1830 "isalnum", Signature(ArgTypes{IntTy}, RetType{IntTy}),
1831 Summary(EvalCallAsPure)
1833 .Case({ArgumentCondition(0U, WithinRange,
1834 {{
'0',
'9'}, {
'A',
'Z'}, {
'a',
'z'}}),
1835 ReturnValueCondition(OutOfRange, SingleValue(0))},
1836 ErrnoIrrelevant,
"Assuming the character is alphanumeric")
1840 .Case({ArgumentCondition(0U, WithinRange, {{128, UCharRangeMax}})},
1845 {{
'0',
'9'}, {
'A',
'Z'}, {
'a',
'z'}, {128, UCharRangeMax}}),
1846 ReturnValueCondition(WithinRange, SingleValue(0))},
1847 ErrnoIrrelevant,
"Assuming the character is non-alphanumeric")
1848 .ArgConstraint(ArgumentCondition(0U, WithinRange,
1849 {{EOFv, EOFv}, {0, UCharRangeMax}},
1850 "an unsigned char value or EOF")));
1851 addToFunctionSummaryMap(
1852 "isalpha", Signature(ArgTypes{IntTy}, RetType{IntTy}),
1853 Summary(EvalCallAsPure)
1854 .Case({ArgumentCondition(0U, WithinRange, {{
'A',
'Z'}, {
'a',
'z'}}),
1855 ReturnValueCondition(OutOfRange, SingleValue(0))},
1856 ErrnoIrrelevant,
"Assuming the character is alphabetical")
1858 .Case({ArgumentCondition(0U, WithinRange, {{128, UCharRangeMax}})},
1860 .Case({ArgumentCondition(
1862 {{
'A',
'Z'}, {
'a',
'z'}, {128, UCharRangeMax}}),
1863 ReturnValueCondition(WithinRange, SingleValue(0))},
1864 ErrnoIrrelevant,
"Assuming the character is non-alphabetical"));
1865 addToFunctionSummaryMap(
1866 "isascii", Signature(ArgTypes{IntTy}, RetType{IntTy}),
1867 Summary(EvalCallAsPure)
1868 .Case({ArgumentCondition(0U, WithinRange,
Range(0, 127)),
1869 ReturnValueCondition(OutOfRange, SingleValue(0))},
1870 ErrnoIrrelevant,
"Assuming the character is an ASCII character")
1871 .Case({ArgumentCondition(0U, OutOfRange,
Range(0, 127)),
1872 ReturnValueCondition(WithinRange, SingleValue(0))},
1874 "Assuming the character is not an ASCII character"));
1875 addToFunctionSummaryMap(
1876 "isblank", Signature(ArgTypes{IntTy}, RetType{IntTy}),
1877 Summary(EvalCallAsPure)
1878 .Case({ArgumentCondition(0U, WithinRange, {{
'\t',
'\t'}, {
' ',
' '}}),
1879 ReturnValueCondition(OutOfRange, SingleValue(0))},
1880 ErrnoIrrelevant,
"Assuming the character is a blank character")
1881 .Case({ArgumentCondition(0U, OutOfRange, {{
'\t',
'\t'}, {
' ',
' '}}),
1882 ReturnValueCondition(WithinRange, SingleValue(0))},
1884 "Assuming the character is not a blank character"));
1885 addToFunctionSummaryMap(
1886 "iscntrl", Signature(ArgTypes{IntTy}, RetType{IntTy}),
1887 Summary(EvalCallAsPure)
1888 .Case({ArgumentCondition(0U, WithinRange, {{0, 32}, {127, 127}}),
1889 ReturnValueCondition(OutOfRange, SingleValue(0))},
1891 "Assuming the character is a control character")
1892 .Case({ArgumentCondition(0U, OutOfRange, {{0, 32}, {127, 127}}),
1893 ReturnValueCondition(WithinRange, SingleValue(0))},
1895 "Assuming the character is not a control character"));
1896 addToFunctionSummaryMap(
1897 "isdigit", Signature(ArgTypes{IntTy}, RetType{IntTy}),
1898 Summary(EvalCallAsPure)
1899 .Case({ArgumentCondition(0U, WithinRange,
Range(
'0',
'9')),
1900 ReturnValueCondition(OutOfRange, SingleValue(0))},
1901 ErrnoIrrelevant,
"Assuming the character is a digit")
1902 .Case({ArgumentCondition(0U, OutOfRange,
Range(
'0',
'9')),
1903 ReturnValueCondition(WithinRange, SingleValue(0))},
1904 ErrnoIrrelevant,
"Assuming the character is not a digit"));
1905 addToFunctionSummaryMap(
1906 "isgraph", Signature(ArgTypes{IntTy}, RetType{IntTy}),
1907 Summary(EvalCallAsPure)
1908 .Case({ArgumentCondition(0U, WithinRange,
Range(33, 126)),
1909 ReturnValueCondition(OutOfRange, SingleValue(0))},
1911 "Assuming the character has graphical representation")
1913 {ArgumentCondition(0U, OutOfRange,
Range(33, 126)),
1914 ReturnValueCondition(WithinRange, SingleValue(0))},
1916 "Assuming the character does not have graphical representation"));
1917 addToFunctionSummaryMap(
1918 "islower", Signature(ArgTypes{IntTy}, RetType{IntTy}),
1919 Summary(EvalCallAsPure)
1921 .Case({ArgumentCondition(0U, WithinRange,
Range(
'a',
'z')),
1922 ReturnValueCondition(OutOfRange, SingleValue(0))},
1923 ErrnoIrrelevant,
"Assuming the character is a lowercase letter")
1925 .Case({ArgumentCondition(0U, WithinRange,
Range(0, 127)),
1926 ArgumentCondition(0U, OutOfRange,
Range(
'a',
'z')),
1927 ReturnValueCondition(WithinRange, SingleValue(0))},
1929 "Assuming the character is not a lowercase letter")
1931 .Case({ArgumentCondition(0U, WithinRange, {{128, UCharRangeMax}})},
1934 .Case({ArgumentCondition(0U, OutOfRange,
Range(0, UCharRangeMax)),
1935 ReturnValueCondition(WithinRange, SingleValue(0))},
1937 addToFunctionSummaryMap(
1938 "isprint", Signature(ArgTypes{IntTy}, RetType{IntTy}),
1939 Summary(EvalCallAsPure)
1940 .Case({ArgumentCondition(0U, WithinRange,
Range(32, 126)),
1941 ReturnValueCondition(OutOfRange, SingleValue(0))},
1942 ErrnoIrrelevant,
"Assuming the character is printable")
1943 .Case({ArgumentCondition(0U, OutOfRange,
Range(32, 126)),
1944 ReturnValueCondition(WithinRange, SingleValue(0))},
1945 ErrnoIrrelevant,
"Assuming the character is non-printable"));
1946 addToFunctionSummaryMap(
1947 "ispunct", Signature(ArgTypes{IntTy}, RetType{IntTy}),
1948 Summary(EvalCallAsPure)
1949 .Case({ArgumentCondition(
1951 {{
'!',
'/'}, {
':',
'@'}, {
'[',
'`'}, {
'{',
'~'}}),
1952 ReturnValueCondition(OutOfRange, SingleValue(0))},
1953 ErrnoIrrelevant,
"Assuming the character is a punctuation mark")
1954 .Case({ArgumentCondition(
1956 {{
'!',
'/'}, {
':',
'@'}, {
'[',
'`'}, {
'{',
'~'}}),
1957 ReturnValueCondition(WithinRange, SingleValue(0))},
1959 "Assuming the character is not a punctuation mark"));
1960 addToFunctionSummaryMap(
1961 "isspace", Signature(ArgTypes{IntTy}, RetType{IntTy}),
1962 Summary(EvalCallAsPure)
1964 .Case({ArgumentCondition(0U, WithinRange, {{9, 13}, {
' ',
' '}}),
1965 ReturnValueCondition(OutOfRange, SingleValue(0))},
1967 "Assuming the character is a whitespace character")
1969 .Case({ArgumentCondition(0U, WithinRange, {{128, UCharRangeMax}})},
1971 .Case({ArgumentCondition(0U, OutOfRange,
1972 {{9, 13}, {
' ',
' '}, {128, UCharRangeMax}}),
1973 ReturnValueCondition(WithinRange, SingleValue(0))},
1975 "Assuming the character is not a whitespace character"));
1976 addToFunctionSummaryMap(
1977 "isupper", Signature(ArgTypes{IntTy}, RetType{IntTy}),
1978 Summary(EvalCallAsPure)
1980 .Case({ArgumentCondition(0U, WithinRange,
Range(
'A',
'Z')),
1981 ReturnValueCondition(OutOfRange, SingleValue(0))},
1983 "Assuming the character is an uppercase letter")
1985 .Case({ArgumentCondition(0U, WithinRange, {{128, UCharRangeMax}})},
1988 .Case({ArgumentCondition(0U, OutOfRange,
1989 {{
'A',
'Z'}, {128, UCharRangeMax}}),
1990 ReturnValueCondition(WithinRange, SingleValue(0))},
1992 "Assuming the character is not an uppercase letter"));
1993 addToFunctionSummaryMap(
1994 "isxdigit", Signature(ArgTypes{IntTy}, RetType{IntTy}),
1995 Summary(EvalCallAsPure)
1996 .Case({ArgumentCondition(0U, WithinRange,
1997 {{
'0',
'9'}, {
'A',
'F'}, {
'a',
'f'}}),
1998 ReturnValueCondition(OutOfRange, SingleValue(0))},
2000 "Assuming the character is a hexadecimal digit")
2001 .Case({ArgumentCondition(0U, OutOfRange,
2002 {{
'0',
'9'}, {
'A',
'F'}, {
'a',
'f'}}),
2003 ReturnValueCondition(WithinRange, SingleValue(0))},
2005 "Assuming the character is not a hexadecimal digit"));
2006 addToFunctionSummaryMap(
2007 "toupper", Signature(ArgTypes{IntTy}, RetType{IntTy}),
2008 Summary(EvalCallAsPure)
2009 .ArgConstraint(ArgumentCondition(0U, WithinRange,
2010 {{EOFv, EOFv}, {0, UCharRangeMax}},
2011 "an unsigned char value or EOF")));
2012 addToFunctionSummaryMap(
2013 "tolower", Signature(ArgTypes{IntTy}, RetType{IntTy}),
2014 Summary(EvalCallAsPure)
2015 .ArgConstraint(ArgumentCondition(0U, WithinRange,
2016 {{EOFv, EOFv}, {0, UCharRangeMax}},
2017 "an unsigned char value or EOF")));
2018 addToFunctionSummaryMap(
2019 "toascii", Signature(ArgTypes{IntTy}, RetType{IntTy}),
2020 Summary(EvalCallAsPure)
2021 .ArgConstraint(ArgumentCondition(0U, WithinRange,
2022 {{EOFv, EOFv}, {0, UCharRangeMax}},
2023 "an unsigned char value or EOF")));
2025 addToFunctionSummaryMap(
2026 "getchar", Signature(ArgTypes{}, RetType{IntTy}),
2028 .Case({ReturnValueCondition(WithinRange,
2029 {{EOFv, EOFv}, {0, UCharRangeMax}})},
2035 .Case({ArgumentCondition(1U, WithinRange,
Range(1, SizeMax)),
2036 ArgumentCondition(2U, WithinRange,
Range(1, SizeMax)),
2037 ReturnValueCondition(BO_LT, ArgNo(2)),
2038 ReturnValueCondition(WithinRange,
Range(0, SizeMax))},
2039 ErrnoNEZeroIrrelevant, GenericFailureMsg)
2040 .Case({ArgumentCondition(1U, WithinRange,
Range(1, SizeMax)),
2041 ReturnValueCondition(BO_EQ, ArgNo(2)),
2042 ReturnValueCondition(WithinRange,
Range(0, SizeMax))},
2043 ErrnoMustNotBeChecked, GenericSuccessMsg)
2044 .Case({ArgumentCondition(1U, WithinRange, SingleValue(0)),
2045 ReturnValueCondition(WithinRange, SingleValue(0))},
2046 ErrnoMustNotBeChecked,
2047 "Assuming that argument 'size' to '{0}' is 0")
2048 .ArgConstraint(NotNullBuffer(ArgNo(0), ArgNo(1), ArgNo(2)))
2049 .ArgConstraint(NotNull(ArgNo(3)))
2050 .ArgConstraint(BufferSize(ArgNo(0), ArgNo(1),
2055 addToFunctionSummaryMap(
"fread",
2056 Signature(ArgTypes{VoidPtrRestrictTy, SizeTyCanonTy,
2057 SizeTyCanonTy, FilePtrRestrictTy},
2058 RetType{SizeTyCanonTy}),
2062 addToFunctionSummaryMap(
2064 Signature(ArgTypes{ConstVoidPtrRestrictTy, SizeTyCanonTy, SizeTyCanonTy,
2066 RetType{SizeTyCanonTy}),
2069 std::optional<QualType> Ssize_tTy = lookupTy(
"ssize_t");
2070 std::optional<RangeInt> Ssize_tMax = getMaxValue(Ssize_tTy);
2074 .Case({ReturnValueCondition(LessThanOrEq, ArgNo(2)),
2075 ReturnValueCondition(WithinRange,
Range(-1, Ssize_tMax))},
2081 addToFunctionSummaryMap(
2083 Signature(ArgTypes{IntTy, VoidPtrTy, SizeTyCanonTy}, RetType{Ssize_tTy}),
2086 addToFunctionSummaryMap(
2088 Signature(ArgTypes{IntTy, ConstVoidPtrTy, SizeTyCanonTy},
2089 RetType{Ssize_tTy}),
2092 auto GetLineSummary =
2094 .Case({ReturnValueCondition(WithinRange,
2095 Range({-1, -1}, {1, Ssize_tMax}))},
2098 QualType CharPtrPtrRestrictTy = getRestrictTy(getPointerTy(CharPtrTy));
2105 addToFunctionSummaryMap(
2108 ArgTypes{CharPtrPtrRestrictTy, SizePtrRestrictTy, FilePtrRestrictTy},
2109 RetType{Ssize_tTy}),
2113 addToFunctionSummaryMap(
2115 Signature(ArgTypes{CharPtrPtrRestrictTy, SizePtrRestrictTy, IntTy,
2117 RetType{Ssize_tTy}),
2121 Summary GetenvSummary =
2123 .ArgConstraint(NotNull(ArgNo(0)))
2124 .Case({NotNull(Ret)}, ErrnoIrrelevant,
2125 "Assuming the environment variable exists");
2127 if (!ShouldAssumeControlledEnvironment)
2128 GetenvSummary.Case({NotNull(Ret)->negate()}, ErrnoIrrelevant,
2129 "Assuming the environment variable does not exist");
2132 addToFunctionSummaryMap(
2133 "getenv", Signature(ArgTypes{ConstCharPtrTy}, RetType{CharPtrTy}),
2134 std::move(GetenvSummary));
2140 addToFunctionSummaryMap(
2141 {
"getc",
"fgetc"}, Signature(ArgTypes{FilePtrTy}, RetType{IntTy}),
2143 .Case({ReturnValueCondition(WithinRange,
2144 {{EOFv, EOFv}, {0, UCharRangeMax}})},
2146 .ArgConstraint(NotNull(ArgNo(0))));
2148 const auto ReturnsZero =
2149 ConstraintSet{ReturnValueCondition(WithinRange, SingleValue(0))};
2150 const auto ReturnsMinusOne =
2151 ConstraintSet{ReturnValueCondition(WithinRange, SingleValue(-1))};
2152 const auto ReturnsEOF =
2153 ConstraintSet{ReturnValueCondition(WithinRange, SingleValue(EOFv))};
2154 const auto ReturnsNonnegative =
2155 ConstraintSet{ReturnValueCondition(WithinRange,
Range(0, IntMax))};
2156 const auto ReturnsNonZero =
2157 ConstraintSet{ReturnValueCondition(OutOfRange, SingleValue(0))};
2158 const auto &ReturnsValidFileDescriptor = ReturnsNonnegative;
2160 auto ValidFileDescriptorOrAtFdcwd = [&](ArgNo ArgN) {
2161 return std::make_shared<RangeConstraint>(
2162 ArgN, WithinRange,
Range({AT_FDCWDv, AT_FDCWDv}, {0, IntMax}),
2163 "a valid file descriptor or AT_FDCWD");
2167 addToFunctionSummaryMap(
2169 Signature(ArgTypes{ConstCharPtrRestrictTy, ConstCharPtrRestrictTy},
2170 RetType{FilePtrTy}),
2172 .Case({NotNull(Ret)}, ErrnoMustNotBeChecked, GenericSuccessMsg)
2173 .Case({
IsNull(Ret)}, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2174 .ArgConstraint(NotNull(ArgNo(0)))
2175 .ArgConstraint(NotNull(ArgNo(1))));
2178 addToFunctionSummaryMap(
2180 Signature(ArgTypes{IntTy, ConstCharPtrTy}, RetType{FilePtrTy}),
2182 .Case({NotNull(Ret)}, ErrnoMustNotBeChecked, GenericSuccessMsg)
2183 .Case({
IsNull(Ret)}, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2184 .ArgConstraint(ArgumentCondition(0, WithinRange,
Range(0, IntMax)))
2185 .ArgConstraint(NotNull(ArgNo(1))));
2188 addToFunctionSummaryMap(
2189 "tmpfile", Signature(ArgTypes{}, RetType{FilePtrTy}),
2191 .Case({NotNull(Ret)}, ErrnoMustNotBeChecked, GenericSuccessMsg)
2192 .Case({
IsNull(Ret)}, ErrnoNEZeroIrrelevant, GenericFailureMsg));
2196 addToFunctionSummaryMap(
2198 Signature(ArgTypes{ConstCharPtrRestrictTy, ConstCharPtrRestrictTy,
2200 RetType{FilePtrTy}),
2202 .Case({ReturnValueCondition(BO_EQ, ArgNo(2))},
2203 ErrnoMustNotBeChecked, GenericSuccessMsg)
2204 .Case({
IsNull(Ret)}, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2205 .ArgConstraint(NotNull(ArgNo(1)))
2206 .ArgConstraint(NotNull(ArgNo(2))));
2209 addToFunctionSummaryMap(
2211 Signature(ArgTypes{ConstCharPtrTy, ConstCharPtrTy}, RetType{FilePtrTy}),
2213 .Case({NotNull(Ret)}, ErrnoMustNotBeChecked, GenericSuccessMsg)
2214 .Case({
IsNull(Ret)}, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2215 .ArgConstraint(NotNull(ArgNo(0)))
2216 .ArgConstraint(NotNull(ArgNo(1))));
2219 addToFunctionSummaryMap(
2220 "fclose", Signature(ArgTypes{FilePtrTy}, RetType{IntTy}),
2222 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2223 .Case(ReturnsEOF, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2224 .ArgConstraint(NotNull(ArgNo(0))));
2227 addToFunctionSummaryMap(
2228 "pclose", Signature(ArgTypes{FilePtrTy}, RetType{IntTy}),
2230 .Case({ReturnValueCondition(WithinRange, {{0, IntMax}})},
2231 ErrnoMustNotBeChecked, GenericSuccessMsg)
2232 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2233 .ArgConstraint(NotNull(ArgNo(0))));
2235 std::optional<QualType> Off_tTy = lookupTy(
"off_t");
2236 std::optional<RangeInt> Off_tMax = getMaxValue(Off_tTy);
2240 addToFunctionSummaryMap(
2241 {
"getc",
"fgetc"}, Signature(ArgTypes{FilePtrTy}, RetType{IntTy}),
2243 .Case({ReturnValueCondition(WithinRange, {{0, UCharRangeMax}})},
2244 ErrnoMustNotBeChecked, GenericSuccessMsg)
2245 .Case({ReturnValueCondition(WithinRange, SingleValue(EOFv))},
2246 ErrnoIrrelevant, GenericFailureMsg)
2247 .ArgConstraint(NotNull(ArgNo(0))));
2251 addToFunctionSummaryMap(
2253 Signature(ArgTypes{IntTy, FilePtrTy}, RetType{IntTy}),
2255 .Case({ArgumentCondition(0, WithinRange,
Range(0, UCharRangeMax)),
2256 ReturnValueCondition(BO_EQ, ArgNo(0))},
2257 ErrnoMustNotBeChecked, GenericSuccessMsg)
2258 .Case({ArgumentCondition(0, OutOfRange,
Range(0, UCharRangeMax)),
2259 ReturnValueCondition(WithinRange,
Range(0, UCharRangeMax))},
2260 ErrnoMustNotBeChecked, GenericSuccessMsg)
2261 .Case({ReturnValueCondition(WithinRange, SingleValue(EOFv))},
2262 ErrnoNEZeroIrrelevant, GenericFailureMsg)
2263 .ArgConstraint(NotNull(ArgNo(1))));
2266 addToFunctionSummaryMap(
2268 Signature(ArgTypes{CharPtrRestrictTy, IntTy, FilePtrRestrictTy},
2269 RetType{CharPtrTy}),
2271 .Case({NotNull(Ret), ReturnValueCondition(BO_EQ, ArgNo(0))},
2272 ErrnoMustNotBeChecked, GenericSuccessMsg)
2273 .Case({
IsNull(Ret)}, ErrnoIrrelevant, GenericFailureMsg)
2274 .ArgConstraint(NotNull(ArgNo(0)))
2275 .ArgConstraint(ArgumentCondition(1, WithinRange,
Range(0, IntMax)))
2277 BufferSize(ArgNo(0), ArgNo(1)))
2278 .ArgConstraint(NotNull(ArgNo(2))));
2281 addToFunctionSummaryMap(
2283 Signature(ArgTypes{ConstCharPtrRestrictTy, FilePtrRestrictTy},
2286 .Case(ReturnsNonnegative, ErrnoMustNotBeChecked, GenericSuccessMsg)
2287 .Case({ReturnValueCondition(WithinRange, SingleValue(EOFv))},
2288 ErrnoNEZeroIrrelevant, GenericFailureMsg)
2289 .ArgConstraint(NotNull(ArgNo(0)))
2290 .ArgConstraint(NotNull(ArgNo(1))));
2293 addToFunctionSummaryMap(
2294 "ungetc", Signature(ArgTypes{IntTy, FilePtrTy}, RetType{IntTy}),
2296 .Case({ReturnValueCondition(BO_EQ, ArgNo(0)),
2297 ArgumentCondition(0, WithinRange, {{0, UCharRangeMax}})},
2298 ErrnoMustNotBeChecked, GenericSuccessMsg)
2299 .Case({ReturnValueCondition(WithinRange, SingleValue(EOFv)),
2300 ArgumentCondition(0, WithinRange, SingleValue(EOFv))},
2301 ErrnoNEZeroIrrelevant,
2302 "Assuming that 'ungetc' fails because EOF was passed as "
2304 .Case({ReturnValueCondition(WithinRange, SingleValue(EOFv)),
2305 ArgumentCondition(0, WithinRange, {{0, UCharRangeMax}})},
2306 ErrnoNEZeroIrrelevant, GenericFailureMsg)
2307 .ArgConstraint(ArgumentCondition(
2308 0, WithinRange, {{EOFv, EOFv}, {0, UCharRangeMax}}))
2309 .ArgConstraint(NotNull(ArgNo(1))));
2315 addToFunctionSummaryMap(
2316 "fseek", Signature(ArgTypes{FilePtrTy, LongTy, IntTy}, RetType{IntTy}),
2318 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2319 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2320 .ArgConstraint(NotNull(ArgNo(0)))
2321 .ArgConstraint(ArgumentCondition(2, WithinRange, {{0, 2}})));
2324 addToFunctionSummaryMap(
2326 Signature(ArgTypes{FilePtrTy, Off_tTy, IntTy}, RetType{IntTy}),
2328 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2329 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2330 .ArgConstraint(NotNull(ArgNo(0)))
2331 .ArgConstraint(ArgumentCondition(2, WithinRange, {{0, 2}})));
2337 addToFunctionSummaryMap(
2339 Signature(ArgTypes{FilePtrRestrictTy, FPosTPtrRestrictTy},
2342 .Case(ReturnsZero, ErrnoUnchanged, GenericSuccessMsg)
2343 .Case(ReturnsNonZero, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2344 .ArgConstraint(NotNull(ArgNo(0)))
2345 .ArgConstraint(NotNull(ArgNo(1))));
2351 addToFunctionSummaryMap(
2353 Signature(ArgTypes{FilePtrTy, ConstFPosTPtrTy}, RetType{IntTy}),
2355 .Case(ReturnsZero, ErrnoUnchanged, GenericSuccessMsg)
2356 .Case(ReturnsNonZero, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2357 .ArgConstraint(NotNull(ArgNo(0)))
2358 .ArgConstraint(NotNull(ArgNo(1))));
2361 addToFunctionSummaryMap(
2362 "fflush", Signature(ArgTypes{FilePtrTy}, RetType{IntTy}),
2364 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2365 .Case(ReturnsEOF, ErrnoNEZeroIrrelevant, GenericFailureMsg));
2371 addToFunctionSummaryMap(
2372 "ftell", Signature(ArgTypes{FilePtrTy}, RetType{LongTy}),
2374 .Case({ReturnValueCondition(WithinRange,
Range(0, LongMax))},
2375 ErrnoUnchanged, GenericSuccessMsg)
2376 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2377 .ArgConstraint(NotNull(ArgNo(0))));
2380 addToFunctionSummaryMap(
2381 "ftello", Signature(ArgTypes{FilePtrTy}, RetType{Off_tTy}),
2383 .Case({ReturnValueCondition(WithinRange,
Range(0, Off_tMax))},
2384 ErrnoMustNotBeChecked, GenericSuccessMsg)
2385 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2386 .ArgConstraint(NotNull(ArgNo(0))));
2394 addToFunctionSummaryMap(
2395 "fileno", Signature(ArgTypes{FilePtrTy}, RetType{IntTy}),
2397 .Case(ReturnsValidFileDescriptor, ErrnoUnchanged, GenericSuccessMsg)
2398 .ArgConstraint(NotNull(ArgNo(0))));
2402 addToFunctionSummaryMap(
"rewind",
2403 Signature(ArgTypes{FilePtrTy}, RetType{VoidTy}),
2405 .Case({}, ErrnoMustBeChecked)
2406 .ArgConstraint(NotNull(ArgNo(0))));
2409 addToFunctionSummaryMap(
2410 "clearerr", Signature(ArgTypes{FilePtrTy}, RetType{VoidTy}),
2411 Summary(NoEvalCall).ArgConstraint(NotNull(ArgNo(0))));
2414 addToFunctionSummaryMap(
2415 "feof", Signature(ArgTypes{FilePtrTy}, RetType{IntTy}),
2416 Summary(NoEvalCall).ArgConstraint(NotNull(ArgNo(0))));
2419 addToFunctionSummaryMap(
2420 "ferror", Signature(ArgTypes{FilePtrTy}, RetType{IntTy}),
2421 Summary(NoEvalCall).ArgConstraint(NotNull(ArgNo(0))));
2424 addToFunctionSummaryMap(
2425 "a64l", Signature(ArgTypes{ConstCharPtrTy}, RetType{LongTy}),
2426 Summary(NoEvalCall).ArgConstraint(NotNull(ArgNo(0))));
2429 addToFunctionSummaryMap(
"l64a",
2430 Signature(ArgTypes{LongTy}, RetType{CharPtrTy}),
2432 .ArgConstraint(ArgumentCondition(
2433 0, WithinRange,
Range(0, LongMax))));
2436 addToFunctionSummaryMap(
2437 "open", Signature(ArgTypes{ConstCharPtrTy, IntTy}, RetType{IntTy}),
2439 .Case(ReturnsValidFileDescriptor, ErrnoMustNotBeChecked,
2441 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2442 .ArgConstraint(NotNull(ArgNo(0))));
2445 addToFunctionSummaryMap(
2447 Signature(ArgTypes{IntTy, ConstCharPtrTy, IntTy}, RetType{IntTy}),
2449 .Case(ReturnsValidFileDescriptor, ErrnoMustNotBeChecked,
2451 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2452 .ArgConstraint(ValidFileDescriptorOrAtFdcwd(ArgNo(0)))
2453 .ArgConstraint(NotNull(ArgNo(1))));
2456 addToFunctionSummaryMap(
2457 "access", Signature(ArgTypes{ConstCharPtrTy, IntTy}, RetType{IntTy}),
2459 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2460 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2461 .ArgConstraint(NotNull(ArgNo(0))));
2464 addToFunctionSummaryMap(
2466 Signature(ArgTypes{IntTy, ConstCharPtrTy, IntTy, IntTy},
2469 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2470 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2471 .ArgConstraint(ValidFileDescriptorOrAtFdcwd(ArgNo(0)))
2472 .ArgConstraint(NotNull(ArgNo(1))));
2475 addToFunctionSummaryMap(
2476 "dup", Signature(ArgTypes{IntTy}, RetType{IntTy}),
2478 .Case(ReturnsValidFileDescriptor, ErrnoMustNotBeChecked,
2480 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2482 ArgumentCondition(0, WithinRange,
Range(0, IntMax))));
2485 addToFunctionSummaryMap(
2486 "dup2", Signature(ArgTypes{IntTy, IntTy}, RetType{IntTy}),
2488 .Case(ReturnsValidFileDescriptor, ErrnoMustNotBeChecked,
2490 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2491 .ArgConstraint(ArgumentCondition(0, WithinRange,
Range(0, IntMax)))
2493 ArgumentCondition(1, WithinRange,
Range(0, IntMax))));
2496 addToFunctionSummaryMap(
2497 "fdatasync", Signature(ArgTypes{IntTy}, RetType{IntTy}),
2499 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2500 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2502 ArgumentCondition(0, WithinRange,
Range(0, IntMax))));
2505 addToFunctionSummaryMap(
2507 Signature(ArgTypes{ConstCharPtrTy, ConstCharPtrTy, IntTy},
2510 .ArgConstraint(NotNull(ArgNo(0)))
2511 .ArgConstraint(NotNull(ArgNo(1))));
2514 addToFunctionSummaryMap(
2515 "fsync", Signature(ArgTypes{IntTy}, RetType{IntTy}),
2517 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2518 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2520 ArgumentCondition(0, WithinRange,
Range(0, IntMax))));
2523 addToFunctionSummaryMap(
2525 Signature(ArgTypes{ConstCharPtrTy, Off_tTy}, RetType{IntTy}),
2527 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2528 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2529 .ArgConstraint(NotNull(ArgNo(0))));
2532 addToFunctionSummaryMap(
2534 Signature(ArgTypes{ConstCharPtrTy, ConstCharPtrTy}, RetType{IntTy}),
2536 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2537 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2538 .ArgConstraint(NotNull(ArgNo(0)))
2539 .ArgConstraint(NotNull(ArgNo(1))));
2542 addToFunctionSummaryMap(
2544 Signature(ArgTypes{ConstCharPtrTy, IntTy, ConstCharPtrTy},
2547 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2548 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2549 .ArgConstraint(NotNull(ArgNo(0)))
2550 .ArgConstraint(ValidFileDescriptorOrAtFdcwd(ArgNo(1)))
2551 .ArgConstraint(NotNull(ArgNo(2))));
2554 addToFunctionSummaryMap(
2555 "lockf", Signature(ArgTypes{IntTy, IntTy, Off_tTy}, RetType{IntTy}),
2557 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2558 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2560 ArgumentCondition(0, WithinRange,
Range(0, IntMax))));
2562 std::optional<QualType> Mode_tTy = lookupTy(
"mode_t");
2565 addToFunctionSummaryMap(
2566 "creat", Signature(ArgTypes{ConstCharPtrTy, Mode_tTy}, RetType{IntTy}),
2568 .Case(ReturnsValidFileDescriptor, ErrnoMustNotBeChecked,
2570 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2571 .ArgConstraint(NotNull(ArgNo(0))));
2574 addToFunctionSummaryMap(
2575 "sleep", Signature(ArgTypes{UnsignedIntTy}, RetType{UnsignedIntTy}),
2578 ArgumentCondition(0, WithinRange,
Range(0, UnsignedIntMax))));
2580 std::optional<QualType> DirTy = lookupTy(
"DIR");
2581 std::optional<QualType> DirPtrTy = getPointerTy(DirTy);
2584 addToFunctionSummaryMap(
2585 "dirfd", Signature(ArgTypes{DirPtrTy}, RetType{IntTy}),
2587 .Case(ReturnsValidFileDescriptor, ErrnoMustNotBeChecked,
2589 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2590 .ArgConstraint(NotNull(ArgNo(0))));
2593 addToFunctionSummaryMap(
2594 "alarm", Signature(ArgTypes{UnsignedIntTy}, RetType{UnsignedIntTy}),
2597 ArgumentCondition(0, WithinRange,
Range(0, UnsignedIntMax))));
2600 addToFunctionSummaryMap(
2601 "closedir", Signature(ArgTypes{DirPtrTy}, RetType{IntTy}),
2603 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2604 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2605 .ArgConstraint(NotNull(ArgNo(0))));
2608 addToFunctionSummaryMap(
2609 "strdup", Signature(ArgTypes{ConstCharPtrTy}, RetType{CharPtrTy}),
2610 Summary(NoEvalCall).ArgConstraint(NotNull(ArgNo(0))));
2613 addToFunctionSummaryMap(
2615 Signature(ArgTypes{ConstCharPtrTy, SizeTyCanonTy}, RetType{CharPtrTy}),
2617 .ArgConstraint(NotNull(ArgNo(0)))
2619 ArgumentCondition(1, WithinRange,
Range(0, SizeMax))));
2622 addToFunctionSummaryMap(
2623 "wcsdup", Signature(ArgTypes{ConstWchar_tPtrTy}, RetType{Wchar_tPtrTy}),
2624 Summary(NoEvalCall).ArgConstraint(NotNull(ArgNo(0))));
2627 addToFunctionSummaryMap(
2628 "mkstemp", Signature(ArgTypes{CharPtrTy}, RetType{IntTy}),
2630 .Case(ReturnsValidFileDescriptor, ErrnoMustNotBeChecked,
2632 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2633 .ArgConstraint(NotNull(ArgNo(0))));
2636 addToFunctionSummaryMap(
2637 "mkdtemp", Signature(ArgTypes{CharPtrTy}, RetType{CharPtrTy}),
2639 .Case({NotNull(Ret), ReturnValueCondition(BO_EQ, ArgNo(0))},
2640 ErrnoMustNotBeChecked, GenericSuccessMsg)
2641 .Case({
IsNull(Ret)}, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2642 .ArgConstraint(NotNull(ArgNo(0))));
2645 addToFunctionSummaryMap(
2647 Signature(ArgTypes{CharPtrTy, SizeTyCanonTy}, RetType{CharPtrTy}),
2650 ArgumentCondition(1, WithinRange,
Range(1, SizeMax)),
2651 ReturnValueCondition(BO_EQ, ArgNo(0)), NotNull(Ret)},
2652 ErrnoMustNotBeChecked, GenericSuccessMsg)
2654 ArgumentCondition(1, WithinRange, SingleValue(0)),
2656 ErrnoNEZeroIrrelevant,
"Assuming that argument 'size' is 0")
2658 ArgumentCondition(1, WithinRange,
Range(1, SizeMax)),
2660 ErrnoNEZeroIrrelevant, GenericFailureMsg)
2661 .Case({
IsNull(0), NotNull(Ret)}, ErrnoMustNotBeChecked,
2666 BufferSize( ArgNo(0), ArgNo(1)))
2668 ArgumentCondition(1, WithinRange,
Range(0, SizeMax))));
2671 addToFunctionSummaryMap(
2672 "mkdir", Signature(ArgTypes{ConstCharPtrTy, Mode_tTy}, RetType{IntTy}),
2674 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2675 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2676 .ArgConstraint(NotNull(ArgNo(0))));
2679 addToFunctionSummaryMap(
2681 Signature(ArgTypes{IntTy, ConstCharPtrTy, Mode_tTy}, RetType{IntTy}),
2683 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2684 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2685 .ArgConstraint(ValidFileDescriptorOrAtFdcwd(ArgNo(0)))
2686 .ArgConstraint(NotNull(ArgNo(1))));
2688 std::optional<QualType> Dev_tTy = lookupTy(
"dev_t");
2691 addToFunctionSummaryMap(
2693 Signature(ArgTypes{ConstCharPtrTy, Mode_tTy, Dev_tTy}, RetType{IntTy}),
2695 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2696 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2697 .ArgConstraint(NotNull(ArgNo(0))));
2700 addToFunctionSummaryMap(
2702 Signature(ArgTypes{IntTy, ConstCharPtrTy, Mode_tTy, Dev_tTy},
2705 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2706 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2707 .ArgConstraint(ValidFileDescriptorOrAtFdcwd(ArgNo(0)))
2708 .ArgConstraint(NotNull(ArgNo(1))));
2711 addToFunctionSummaryMap(
2712 "chmod", Signature(ArgTypes{ConstCharPtrTy, Mode_tTy}, RetType{IntTy}),
2714 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2715 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2716 .ArgConstraint(NotNull(ArgNo(0))));
2719 addToFunctionSummaryMap(
2721 Signature(ArgTypes{IntTy, ConstCharPtrTy, Mode_tTy, IntTy},
2724 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2725 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2726 .ArgConstraint(ValidFileDescriptorOrAtFdcwd(ArgNo(0)))
2727 .ArgConstraint(NotNull(ArgNo(1))));
2730 addToFunctionSummaryMap(
2731 "fchmod", Signature(ArgTypes{IntTy, Mode_tTy}, RetType{IntTy}),
2733 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2734 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2736 ArgumentCondition(0, WithinRange,
Range(0, IntMax))));
2738 std::optional<QualType> Uid_tTy = lookupTy(
"uid_t");
2739 std::optional<QualType> Gid_tTy = lookupTy(
"gid_t");
2743 addToFunctionSummaryMap(
2745 Signature(ArgTypes{IntTy, ConstCharPtrTy, Uid_tTy, Gid_tTy, IntTy},
2748 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2749 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2750 .ArgConstraint(ValidFileDescriptorOrAtFdcwd(ArgNo(0)))
2751 .ArgConstraint(NotNull(ArgNo(1))));
2754 addToFunctionSummaryMap(
2756 Signature(ArgTypes{ConstCharPtrTy, Uid_tTy, Gid_tTy}, RetType{IntTy}),
2758 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2759 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2760 .ArgConstraint(NotNull(ArgNo(0))));
2763 addToFunctionSummaryMap(
2765 Signature(ArgTypes{ConstCharPtrTy, Uid_tTy, Gid_tTy}, RetType{IntTy}),
2767 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2768 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2769 .ArgConstraint(NotNull(ArgNo(0))));
2772 addToFunctionSummaryMap(
2773 "fchown", Signature(ArgTypes{IntTy, Uid_tTy, Gid_tTy}, RetType{IntTy}),
2775 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2776 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2778 ArgumentCondition(0, WithinRange,
Range(0, IntMax))));
2781 addToFunctionSummaryMap(
2782 "rmdir", Signature(ArgTypes{ConstCharPtrTy}, RetType{IntTy}),
2784 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2785 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2786 .ArgConstraint(NotNull(ArgNo(0))));
2789 addToFunctionSummaryMap(
2790 "chdir", Signature(ArgTypes{ConstCharPtrTy}, RetType{IntTy}),
2792 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2793 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2794 .ArgConstraint(NotNull(ArgNo(0))));
2797 addToFunctionSummaryMap(
2799 Signature(ArgTypes{ConstCharPtrTy, ConstCharPtrTy}, RetType{IntTy}),
2801 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2802 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2803 .ArgConstraint(NotNull(ArgNo(0)))
2804 .ArgConstraint(NotNull(ArgNo(1))));
2808 addToFunctionSummaryMap(
2810 Signature(ArgTypes{IntTy, ConstCharPtrTy, IntTy, ConstCharPtrTy, IntTy},
2813 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2814 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2815 .ArgConstraint(ValidFileDescriptorOrAtFdcwd(ArgNo(0)))
2816 .ArgConstraint(NotNull(ArgNo(1)))
2817 .ArgConstraint(ValidFileDescriptorOrAtFdcwd(ArgNo(2)))
2818 .ArgConstraint(NotNull(ArgNo(3))));
2821 addToFunctionSummaryMap(
2822 "unlink", Signature(ArgTypes{ConstCharPtrTy}, RetType{IntTy}),
2824 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2825 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2826 .ArgConstraint(NotNull(ArgNo(0))));
2829 addToFunctionSummaryMap(
2831 Signature(ArgTypes{IntTy, ConstCharPtrTy, IntTy}, RetType{IntTy}),
2833 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2834 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2835 .ArgConstraint(ValidFileDescriptorOrAtFdcwd(ArgNo(0)))
2836 .ArgConstraint(NotNull(ArgNo(1))));
2838 std::optional<QualType> StructStatTy = lookupTy(
"stat");
2839 std::optional<QualType> StructStatPtrTy = getPointerTy(StructStatTy);
2840 std::optional<QualType> StructStatPtrRestrictTy =
2841 getRestrictTy(StructStatPtrTy);
2844 addToFunctionSummaryMap(
2845 "fstat", Signature(ArgTypes{IntTy, StructStatPtrTy}, RetType{IntTy}),
2847 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2848 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2849 .ArgConstraint(ArgumentCondition(0, WithinRange,
Range(0, IntMax)))
2850 .ArgConstraint(NotNull(ArgNo(1))));
2853 addToFunctionSummaryMap(
2855 Signature(ArgTypes{ConstCharPtrRestrictTy, StructStatPtrRestrictTy},
2858 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2859 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2860 .ArgConstraint(NotNull(ArgNo(0)))
2861 .ArgConstraint(NotNull(ArgNo(1))));
2864 addToFunctionSummaryMap(
2866 Signature(ArgTypes{ConstCharPtrRestrictTy, StructStatPtrRestrictTy},
2869 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2870 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2871 .ArgConstraint(NotNull(ArgNo(0)))
2872 .ArgConstraint(NotNull(ArgNo(1))));
2876 addToFunctionSummaryMap(
2878 Signature(ArgTypes{IntTy, ConstCharPtrRestrictTy,
2879 StructStatPtrRestrictTy, IntTy},
2882 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2883 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2884 .ArgConstraint(ValidFileDescriptorOrAtFdcwd(ArgNo(0)))
2885 .ArgConstraint(NotNull(ArgNo(1)))
2886 .ArgConstraint(NotNull(ArgNo(2))));
2889 addToFunctionSummaryMap(
2890 "opendir", Signature(ArgTypes{ConstCharPtrTy}, RetType{DirPtrTy}),
2892 .Case({NotNull(Ret)}, ErrnoMustNotBeChecked, GenericSuccessMsg)
2893 .Case({
IsNull(Ret)}, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2894 .ArgConstraint(NotNull(ArgNo(0))));
2897 addToFunctionSummaryMap(
2898 "fdopendir", Signature(ArgTypes{IntTy}, RetType{DirPtrTy}),
2900 .Case({NotNull(Ret)}, ErrnoMustNotBeChecked, GenericSuccessMsg)
2901 .Case({
IsNull(Ret)}, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2903 ArgumentCondition(0, WithinRange,
Range(0, IntMax))));
2906 addToFunctionSummaryMap(
2907 "isatty", Signature(ArgTypes{IntTy}, RetType{IntTy}),
2909 .Case({ReturnValueCondition(WithinRange,
Range(0, 1))},
2912 ArgumentCondition(0, WithinRange,
Range(0, IntMax))));
2915 addToFunctionSummaryMap(
2916 "close", Signature(ArgTypes{IntTy}, RetType{IntTy}),
2918 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2919 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2921 ArgumentCondition(0, WithinRange,
Range(-1, IntMax))));
2924 addToFunctionSummaryMap(
"fpathconf",
2925 Signature(ArgTypes{IntTy, IntTy}, RetType{LongTy}),
2927 .ArgConstraint(ArgumentCondition(
2928 0, WithinRange,
Range(0, IntMax))));
2931 addToFunctionSummaryMap(
2932 "pathconf", Signature(ArgTypes{ConstCharPtrTy, IntTy}, RetType{LongTy}),
2933 Summary(NoEvalCall).ArgConstraint(NotNull(ArgNo(0))));
2936 addToFunctionSummaryMap(
2937 "rewinddir", Signature(ArgTypes{DirPtrTy}, RetType{VoidTy}),
2938 Summary(NoEvalCall).ArgConstraint(NotNull(ArgNo(0))));
2941 addToFunctionSummaryMap(
2942 "seekdir", Signature(ArgTypes{DirPtrTy, LongTy}, RetType{VoidTy}),
2943 Summary(NoEvalCall).ArgConstraint(NotNull(ArgNo(0))));
2946 addToFunctionSummaryMap(
2947 "rand_r", Signature(ArgTypes{UnsignedIntPtrTy}, RetType{IntTy}),
2948 Summary(NoEvalCall).ArgConstraint(NotNull(ArgNo(0))));
2953 addToFunctionSummaryMap(
2956 ArgTypes{VoidPtrTy, SizeTyCanonTy, IntTy, IntTy, IntTy, Off_tTy},
2957 RetType{VoidPtrTy}),
2959 .ArgConstraint(ArgumentCondition(1, WithinRange,
Range(1, SizeMax)))
2961 ArgumentCondition(4, WithinRange,
Range(-1, IntMax))));
2963 std::optional<QualType> Off64_tTy = lookupTy(
"off64_t");
2967 addToFunctionSummaryMap(
2970 ArgTypes{VoidPtrTy, SizeTyCanonTy, IntTy, IntTy, IntTy, Off64_tTy},
2971 RetType{VoidPtrTy}),
2973 .ArgConstraint(ArgumentCondition(1, WithinRange,
Range(1, SizeMax)))
2975 ArgumentCondition(4, WithinRange,
Range(-1, IntMax))));
2978 addToFunctionSummaryMap(
2979 "pipe", Signature(ArgTypes{IntPtrTy}, RetType{IntTy}),
2981 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
2982 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2983 .ArgConstraint(NotNull(ArgNo(0))));
2990 addToFunctionSummaryMap(
2991 "lseek", Signature(ArgTypes{IntTy, Off_tTy, IntTy}, RetType{Off_tTy}),
2993 .Case(ReturnsNonnegative, ErrnoIrrelevant)
2994 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2996 ArgumentCondition(0, WithinRange,
Range(0, IntMax))));
3000 addToFunctionSummaryMap(
3003 ArgTypes{ConstCharPtrRestrictTy, CharPtrRestrictTy, SizeTyCanonTy},
3004 RetType{Ssize_tTy}),
3006 .Case({ArgumentCondition(2, WithinRange,
Range(1, IntMax)),
3007 ReturnValueCondition(LessThanOrEq, ArgNo(2)),
3008 ReturnValueCondition(WithinRange,
Range(1, Ssize_tMax))},
3009 ErrnoMustNotBeChecked, GenericSuccessMsg)
3010 .Case({ArgumentCondition(2, WithinRange, SingleValue(0)),
3011 ReturnValueCondition(WithinRange, SingleValue(0))},
3012 ErrnoMustNotBeChecked,
3013 "Assuming that argument 'bufsize' is 0")
3014 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
3015 .ArgConstraint(NotNull(ArgNo(0)))
3016 .ArgConstraint(NotNull(ArgNo(1)))
3017 .ArgConstraint(BufferSize(ArgNo(1),
3020 ArgumentCondition(2, WithinRange,
Range(0, SizeMax))));
3024 addToFunctionSummaryMap(
3026 Signature(ArgTypes{IntTy, ConstCharPtrRestrictTy, CharPtrRestrictTy,
3028 RetType{Ssize_tTy}),
3030 .Case({ArgumentCondition(3, WithinRange,
Range(1, IntMax)),
3031 ReturnValueCondition(LessThanOrEq, ArgNo(3)),
3032 ReturnValueCondition(WithinRange,
Range(1, Ssize_tMax))},
3033 ErrnoMustNotBeChecked, GenericSuccessMsg)
3034 .Case({ArgumentCondition(3, WithinRange, SingleValue(0)),
3035 ReturnValueCondition(WithinRange, SingleValue(0))},
3036 ErrnoMustNotBeChecked,
3037 "Assuming that argument 'bufsize' is 0")
3038 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
3039 .ArgConstraint(ValidFileDescriptorOrAtFdcwd(ArgNo(0)))
3040 .ArgConstraint(NotNull(ArgNo(1)))
3041 .ArgConstraint(NotNull(ArgNo(2)))
3042 .ArgConstraint(BufferSize(ArgNo(2),
3045 ArgumentCondition(3, WithinRange,
Range(0, SizeMax))));
3049 addToFunctionSummaryMap(
3051 Signature(ArgTypes{IntTy, ConstCharPtrTy, IntTy, ConstCharPtrTy},
3054 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
3055 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
3056 .ArgConstraint(ValidFileDescriptorOrAtFdcwd(ArgNo(0)))
3057 .ArgConstraint(NotNull(ArgNo(1)))
3058 .ArgConstraint(ValidFileDescriptorOrAtFdcwd(ArgNo(2)))
3059 .ArgConstraint(NotNull(ArgNo(3))));
3065 addToFunctionSummaryMap(
3067 Signature(ArgTypes{ConstCharPtrRestrictTy, CharPtrRestrictTy},
3068 RetType{CharPtrTy}),
3070 .Case({NotNull(Ret)}, ErrnoMustNotBeChecked, GenericSuccessMsg)
3071 .Case({
IsNull(Ret)}, ErrnoNEZeroIrrelevant, GenericFailureMsg)
3072 .ArgConstraint(NotNull(ArgNo(0))));
3074 QualType CharPtrConstPtr = getPointerTy(getConstTy(CharPtrTy));
3077 addToFunctionSummaryMap(
3079 Signature(ArgTypes{ConstCharPtrTy, CharPtrConstPtr}, RetType{IntTy}),
3081 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant)
3082 .ArgConstraint(NotNull(ArgNo(0))));
3085 addToFunctionSummaryMap(
3087 Signature(ArgTypes{ConstCharPtrTy, CharPtrConstPtr}, RetType{IntTy}),
3089 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant)
3090 .ArgConstraint(NotNull(ArgNo(0))));
3093 addToFunctionSummaryMap(
3095 Signature(ArgTypes{IntTy, CharPtrConstPtr, ConstCharPtrTy},
3098 .Case({ReturnValueCondition(WithinRange,
Range(-1, UCharRangeMax))},
3100 .ArgConstraint(ArgumentCondition(0, WithinRange,
Range(0, IntMax)))
3101 .ArgConstraint(NotNull(ArgNo(1)))
3102 .ArgConstraint(NotNull(ArgNo(2))));
3104 std::optional<QualType> StructSockaddrTy = lookupTy(
"sockaddr");
3105 std::optional<QualType> StructSockaddrPtrTy =
3106 getPointerTy(StructSockaddrTy);
3107 std::optional<QualType> ConstStructSockaddrPtrTy =
3108 getPointerTy(getConstTy(StructSockaddrTy));
3109 std::optional<QualType> StructSockaddrPtrRestrictTy =
3110 getRestrictTy(StructSockaddrPtrTy);
3111 std::optional<QualType> ConstStructSockaddrPtrRestrictTy =
3112 getRestrictTy(ConstStructSockaddrPtrTy);
3113 std::optional<QualType> Socklen_tTy = lookupTy(
"socklen_t");
3114 std::optional<QualType> Socklen_tPtrTy = getPointerTy(Socklen_tTy);
3115 std::optional<QualType> Socklen_tPtrRestrictTy =
3116 getRestrictTy(Socklen_tPtrTy);
3117 std::optional<RangeInt> Socklen_tMax = getMaxValue(Socklen_tTy);
3127 addToFunctionSummaryMap(
3128 "socket", Signature(ArgTypes{IntTy, IntTy, IntTy}, RetType{IntTy}),
3130 .Case(ReturnsValidFileDescriptor, ErrnoMustNotBeChecked,
3132 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg));
3136 .Case(ReturnsValidFileDescriptor, ErrnoMustNotBeChecked,
3138 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
3139 .ArgConstraint(ArgumentCondition(0, WithinRange,
Range(0, IntMax)));
3140 if (!addToFunctionSummaryMap(
3144 Signature(ArgTypes{IntTy, StructSockaddrPtrRestrictTy,
3145 Socklen_tPtrRestrictTy},
3148 addToFunctionSummaryMap(
3150 Signature(ArgTypes{IntTy,
Irrelevant, Socklen_tPtrRestrictTy},
3156 if (!addToFunctionSummaryMap(
3158 Signature(ArgTypes{IntTy, ConstStructSockaddrPtrTy, Socklen_tTy},
3161 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
3162 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
3164 ArgumentCondition(0, WithinRange,
Range(0, IntMax)))
3165 .ArgConstraint(NotNull(ArgNo(1)))
3167 BufferSize(ArgNo(1), ArgNo(2)))
3169 ArgumentCondition(2, WithinRange,
Range(0, Socklen_tMax)))))
3171 addToFunctionSummaryMap(
3173 Signature(ArgTypes{IntTy,
Irrelevant, Socklen_tTy}, RetType{IntTy}),
3175 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
3176 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
3178 ArgumentCondition(0, WithinRange,
Range(0, IntMax)))
3180 ArgumentCondition(2, WithinRange,
Range(0, Socklen_tMax))));
3184 if (!addToFunctionSummaryMap(
3186 Signature(ArgTypes{IntTy, StructSockaddrPtrRestrictTy,
3187 Socklen_tPtrRestrictTy},
3190 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
3191 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
3193 ArgumentCondition(0, WithinRange,
Range(0, IntMax)))
3194 .ArgConstraint(NotNull(ArgNo(1)))
3195 .ArgConstraint(NotNull(ArgNo(2)))))
3196 addToFunctionSummaryMap(
3198 Signature(ArgTypes{IntTy,
Irrelevant, Socklen_tPtrRestrictTy},
3201 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
3202 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
3204 ArgumentCondition(0, WithinRange,
Range(0, IntMax))));
3208 if (!addToFunctionSummaryMap(
3210 Signature(ArgTypes{IntTy, StructSockaddrPtrRestrictTy,
3211 Socklen_tPtrRestrictTy},
3214 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
3215 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
3217 ArgumentCondition(0, WithinRange,
Range(0, IntMax)))
3218 .ArgConstraint(NotNull(ArgNo(1)))
3219 .ArgConstraint(NotNull(ArgNo(2)))))
3220 addToFunctionSummaryMap(
3222 Signature(ArgTypes{IntTy,
Irrelevant, Socklen_tPtrRestrictTy},
3225 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
3226 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
3228 ArgumentCondition(0, WithinRange,
Range(0, IntMax))));
3232 if (!addToFunctionSummaryMap(
3234 Signature(ArgTypes{IntTy, ConstStructSockaddrPtrTy, Socklen_tTy},
3237 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
3238 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
3240 ArgumentCondition(0, WithinRange,
Range(0, IntMax)))
3241 .ArgConstraint(NotNull(ArgNo(1)))))
3242 addToFunctionSummaryMap(
3244 Signature(ArgTypes{IntTy,
Irrelevant, Socklen_tTy}, RetType{IntTy}),
3246 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
3247 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
3249 ArgumentCondition(0, WithinRange,
Range(0, IntMax))));
3253 .Case({ReturnValueCondition(LessThanOrEq, ArgNo(2)),
3254 ReturnValueCondition(WithinRange,
Range(1, Ssize_tMax))},
3255 ErrnoMustNotBeChecked, GenericSuccessMsg)
3256 .Case({ReturnValueCondition(WithinRange, SingleValue(0)),
3257 ArgumentCondition(2, WithinRange, SingleValue(0))},
3258 ErrnoMustNotBeChecked, GenericSuccessMsg)
3259 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
3260 .ArgConstraint(ArgumentCondition(0, WithinRange,
Range(0, IntMax)))
3261 .ArgConstraint(BufferSize(ArgNo(1),
3263 if (!addToFunctionSummaryMap(
3269 Signature(ArgTypes{IntTy, VoidPtrRestrictTy, SizeTyCanonTy, IntTy,
3270 StructSockaddrPtrRestrictTy,
3271 Socklen_tPtrRestrictTy},
3272 RetType{Ssize_tTy}),
3274 addToFunctionSummaryMap(
3276 Signature(ArgTypes{IntTy, VoidPtrRestrictTy, SizeTyCanonTy, IntTy,
3278 RetType{Ssize_tTy}),
3283 .Case({ReturnValueCondition(LessThanOrEq, ArgNo(2)),
3284 ReturnValueCondition(WithinRange,
Range(1, Ssize_tMax))},
3285 ErrnoMustNotBeChecked, GenericSuccessMsg)
3286 .Case({ReturnValueCondition(WithinRange, SingleValue(0)),
3287 ArgumentCondition(2, WithinRange, SingleValue(0))},
3288 ErrnoMustNotBeChecked, GenericSuccessMsg)
3289 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
3290 .ArgConstraint(ArgumentCondition(0, WithinRange,
Range(0, IntMax)))
3291 .ArgConstraint(BufferSize(ArgNo(1),
3293 if (!addToFunctionSummaryMap(
3298 Signature(ArgTypes{IntTy, ConstVoidPtrTy, SizeTyCanonTy, IntTy,
3299 ConstStructSockaddrPtrTy, Socklen_tTy},
3300 RetType{Ssize_tTy}),
3302 addToFunctionSummaryMap(
3304 Signature(ArgTypes{IntTy, ConstVoidPtrTy, SizeTyCanonTy, IntTy,
3306 RetType{Ssize_tTy}),
3310 addToFunctionSummaryMap(
3311 "listen", Signature(ArgTypes{IntTy, IntTy}, RetType{IntTy}),
3313 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
3314 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
3316 ArgumentCondition(0, WithinRange,
Range(0, IntMax))));
3319 addToFunctionSummaryMap(
3321 Signature(ArgTypes{IntTy, VoidPtrTy, SizeTyCanonTy, IntTy},
3322 RetType{Ssize_tTy}),
3324 .Case({ReturnValueCondition(LessThanOrEq, ArgNo(2)),
3325 ReturnValueCondition(WithinRange,
Range(1, Ssize_tMax))},
3326 ErrnoMustNotBeChecked, GenericSuccessMsg)
3327 .Case({ReturnValueCondition(WithinRange, SingleValue(0)),
3328 ArgumentCondition(2, WithinRange, SingleValue(0))},
3329 ErrnoMustNotBeChecked, GenericSuccessMsg)
3330 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
3331 .ArgConstraint(ArgumentCondition(0, WithinRange,
Range(0, IntMax)))
3332 .ArgConstraint(BufferSize(ArgNo(1),
3335 std::optional<QualType> StructMsghdrTy = lookupTy(
"msghdr");
3336 std::optional<QualType> StructMsghdrPtrTy = getPointerTy(StructMsghdrTy);
3337 std::optional<QualType> ConstStructMsghdrPtrTy =
3338 getPointerTy(getConstTy(StructMsghdrTy));
3341 addToFunctionSummaryMap(
3343 Signature(ArgTypes{IntTy, StructMsghdrPtrTy, IntTy},
3344 RetType{Ssize_tTy}),
3346 .Case({ReturnValueCondition(WithinRange,
Range(1, Ssize_tMax))},
3347 ErrnoMustNotBeChecked, GenericSuccessMsg)
3348 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
3350 ArgumentCondition(0, WithinRange,
Range(0, IntMax))));
3353 addToFunctionSummaryMap(
3355 Signature(ArgTypes{IntTy, ConstStructMsghdrPtrTy, IntTy},
3356 RetType{Ssize_tTy}),
3358 .Case({ReturnValueCondition(WithinRange,
Range(1, Ssize_tMax))},
3359 ErrnoMustNotBeChecked, GenericSuccessMsg)
3360 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
3362 ArgumentCondition(0, WithinRange,
Range(0, IntMax))));
3366 addToFunctionSummaryMap(
3368 Signature(ArgTypes{IntTy, IntTy, IntTy, ConstVoidPtrTy, Socklen_tTy},
3371 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
3372 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
3373 .ArgConstraint(NotNullBuffer(ArgNo(3), ArgNo(4)))
3375 BufferSize(ArgNo(3), ArgNo(4)))
3377 ArgumentCondition(4, WithinRange,
Range(0, Socklen_tMax))));
3382 addToFunctionSummaryMap(
3384 Signature(ArgTypes{IntTy, IntTy, IntTy, VoidPtrRestrictTy,
3385 Socklen_tPtrRestrictTy},
3388 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
3389 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
3390 .ArgConstraint(NotNull(ArgNo(3)))
3391 .ArgConstraint(NotNull(ArgNo(4))));
3394 addToFunctionSummaryMap(
3396 Signature(ArgTypes{IntTy, ConstVoidPtrTy, SizeTyCanonTy, IntTy},
3397 RetType{Ssize_tTy}),
3399 .Case({ReturnValueCondition(LessThanOrEq, ArgNo(2)),
3400 ReturnValueCondition(WithinRange,
Range(1, Ssize_tMax))},
3401 ErrnoMustNotBeChecked, GenericSuccessMsg)
3402 .Case({ReturnValueCondition(WithinRange, SingleValue(0)),
3403 ArgumentCondition(2, WithinRange, SingleValue(0))},
3404 ErrnoMustNotBeChecked, GenericSuccessMsg)
3405 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
3406 .ArgConstraint(ArgumentCondition(0, WithinRange,
Range(0, IntMax)))
3407 .ArgConstraint(BufferSize(ArgNo(1),
3411 addToFunctionSummaryMap(
3413 Signature(ArgTypes{IntTy, IntTy, IntTy, IntPtrTy}, RetType{IntTy}),
3415 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
3416 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
3417 .ArgConstraint(NotNull(ArgNo(3))));
3420 addToFunctionSummaryMap(
3421 "shutdown", Signature(ArgTypes{IntTy, IntTy}, RetType{IntTy}),
3423 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
3424 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
3426 ArgumentCondition(0, WithinRange,
Range(0, IntMax))));
3435 addToFunctionSummaryMap(
3437 Signature(ArgTypes{ConstStructSockaddrPtrRestrictTy, Socklen_tTy,
3438 CharPtrRestrictTy, Socklen_tTy, CharPtrRestrictTy,
3439 Socklen_tTy, IntTy},
3443 BufferSize(ArgNo(0), ArgNo(1)))
3445 ArgumentCondition(1, WithinRange,
Range(0, Socklen_tMax)))
3447 BufferSize(ArgNo(2), ArgNo(3)))
3449 ArgumentCondition(3, WithinRange,
Range(0, Socklen_tMax)))
3451 BufferSize(ArgNo(4), ArgNo(5)))
3453 ArgumentCondition(5, WithinRange,
Range(0, Socklen_tMax))));
3455 std::optional<QualType> StructUtimbufTy = lookupTy(
"utimbuf");
3456 std::optional<QualType> StructUtimbufPtrTy = getPointerTy(StructUtimbufTy);
3459 addToFunctionSummaryMap(
3461 Signature(ArgTypes{ConstCharPtrTy, StructUtimbufPtrTy}, RetType{IntTy}),
3463 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
3464 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
3465 .ArgConstraint(NotNull(ArgNo(0))));
3467 std::optional<QualType> StructTimespecTy = lookupTy(
"timespec");
3468 std::optional<QualType> StructTimespecPtrTy =
3469 getPointerTy(StructTimespecTy);
3470 std::optional<QualType> ConstStructTimespecPtrTy =
3471 getPointerTy(getConstTy(StructTimespecTy));
3474 addToFunctionSummaryMap(
3476 Signature(ArgTypes{IntTy, ConstStructTimespecPtrTy}, RetType{IntTy}),
3478 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
3479 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
3481 ArgumentCondition(0, WithinRange,
Range(0, IntMax))));
3485 addToFunctionSummaryMap(
3488 ArgTypes{IntTy, ConstCharPtrTy, ConstStructTimespecPtrTy, IntTy},
3491 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
3492 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
3493 .ArgConstraint(NotNull(ArgNo(1))));
3495 std::optional<QualType> StructTimevalTy = lookupTy(
"timeval");
3496 std::optional<QualType> ConstStructTimevalPtrTy =
3497 getPointerTy(getConstTy(StructTimevalTy));
3500 addToFunctionSummaryMap(
3502 Signature(ArgTypes{ConstCharPtrTy, ConstStructTimevalPtrTy},
3505 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
3506 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
3507 .ArgConstraint(NotNull(ArgNo(0))));
3510 addToFunctionSummaryMap(
3512 Signature(ArgTypes{ConstStructTimespecPtrTy, StructTimespecPtrTy},
3515 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
3516 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
3517 .ArgConstraint(NotNull(ArgNo(0))));
3519 std::optional<QualType> Time_tTy = lookupTy(
"time_t");
3520 std::optional<QualType> ConstTime_tPtrTy =
3521 getPointerTy(getConstTy(Time_tTy));
3522 std::optional<QualType> ConstTime_tPtrRestrictTy =
3523 getRestrictTy(ConstTime_tPtrTy);
3525 std::optional<QualType> StructTmTy = lookupTy(
"tm");
3526 std::optional<QualType> StructTmPtrTy = getPointerTy(StructTmTy);
3527 std::optional<QualType> StructTmPtrRestrictTy =
3528 getRestrictTy(StructTmPtrTy);
3529 std::optional<QualType> ConstStructTmPtrTy =
3530 getPointerTy(getConstTy(StructTmTy));
3531 std::optional<QualType> ConstStructTmPtrRestrictTy =
3532 getRestrictTy(ConstStructTmPtrTy);
3535 addToFunctionSummaryMap(
3537 Signature(ArgTypes{ConstTime_tPtrTy}, RetType{StructTmPtrTy}),
3538 Summary(NoEvalCall).ArgConstraint(NotNull(ArgNo(0))));
3542 addToFunctionSummaryMap(
3544 Signature(ArgTypes{ConstTime_tPtrRestrictTy, StructTmPtrRestrictTy},
3545 RetType{StructTmPtrTy}),
3547 .ArgConstraint(NotNull(ArgNo(0)))
3548 .ArgConstraint(NotNull(ArgNo(1))));
3551 addToFunctionSummaryMap(
3553 Signature(ArgTypes{ConstStructTmPtrRestrictTy, CharPtrRestrictTy},
3554 RetType{CharPtrTy}),
3556 .ArgConstraint(NotNull(ArgNo(0)))
3557 .ArgConstraint(NotNull(ArgNo(1)))
3558 .ArgConstraint(BufferSize(ArgNo(1),
3559 BVF.getValue(26, IntTy))));
3562 addToFunctionSummaryMap(
3564 Signature(ArgTypes{ConstTime_tPtrTy, CharPtrTy}, RetType{CharPtrTy}),
3566 .ArgConstraint(NotNull(ArgNo(0)))
3567 .ArgConstraint(NotNull(ArgNo(1)))
3568 .ArgConstraint(BufferSize(
3570 BVF.getValue(26, IntTy))));
3574 addToFunctionSummaryMap(
3576 Signature(ArgTypes{ConstTime_tPtrRestrictTy, StructTmPtrRestrictTy},
3577 RetType{StructTmPtrTy}),
3579 .ArgConstraint(NotNull(ArgNo(0)))
3580 .ArgConstraint(NotNull(ArgNo(1))));
3583 addToFunctionSummaryMap(
3584 "gmtime", Signature(ArgTypes{ConstTime_tPtrTy}, RetType{StructTmPtrTy}),
3585 Summary(NoEvalCall).ArgConstraint(NotNull(ArgNo(0))));
3587 std::optional<QualType> Clockid_tTy = lookupTy(
"clockid_t");
3590 addToFunctionSummaryMap(
3592 Signature(ArgTypes{Clockid_tTy, StructTimespecPtrTy}, RetType{IntTy}),
3594 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
3595 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
3596 .ArgConstraint(NotNull(ArgNo(1))));
3598 std::optional<QualType> StructItimervalTy = lookupTy(
"itimerval");
3599 std::optional<QualType> StructItimervalPtrTy =
3600 getPointerTy(StructItimervalTy);
3603 addToFunctionSummaryMap(
3605 Signature(ArgTypes{IntTy, StructItimervalPtrTy}, RetType{IntTy}),
3607 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
3608 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
3609 .ArgConstraint(NotNull(ArgNo(1))));
3611 std::optional<QualType> Pthread_cond_tTy = lookupTy(
"pthread_cond_t");
3612 std::optional<QualType> Pthread_cond_tPtrTy =
3613 getPointerTy(Pthread_cond_tTy);
3614 std::optional<QualType> Pthread_tTy = lookupTy(
"pthread_t");
3615 std::optional<QualType> Pthread_tPtrTy = getPointerTy(Pthread_tTy);
3616 std::optional<QualType> Pthread_tPtrRestrictTy =
3617 getRestrictTy(Pthread_tPtrTy);
3618 std::optional<QualType> Pthread_mutex_tTy = lookupTy(
"pthread_mutex_t");
3619 std::optional<QualType> Pthread_mutex_tPtrTy =
3620 getPointerTy(Pthread_mutex_tTy);
3621 std::optional<QualType> Pthread_mutex_tPtrRestrictTy =
3622 getRestrictTy(Pthread_mutex_tPtrTy);
3623 std::optional<QualType> Pthread_attr_tTy = lookupTy(
"pthread_attr_t");
3624 std::optional<QualType> Pthread_attr_tPtrTy =
3625 getPointerTy(Pthread_attr_tTy);
3626 std::optional<QualType> ConstPthread_attr_tPtrTy =
3627 getPointerTy(getConstTy(Pthread_attr_tTy));
3628 std::optional<QualType> ConstPthread_attr_tPtrRestrictTy =
3629 getRestrictTy(ConstPthread_attr_tPtrTy);
3630 std::optional<QualType> Pthread_mutexattr_tTy =
3631 lookupTy(
"pthread_mutexattr_t");
3632 std::optional<QualType> ConstPthread_mutexattr_tPtrTy =
3633 getPointerTy(getConstTy(Pthread_mutexattr_tTy));
3634 std::optional<QualType> ConstPthread_mutexattr_tPtrRestrictTy =
3635 getRestrictTy(ConstPthread_mutexattr_tPtrTy);
3637 QualType PthreadStartRoutineTy = getPointerTy(
3639 FunctionProtoType::ExtProtoInfo()));
3643 addToFunctionSummaryMap(
3644 {
"pthread_cond_signal",
"pthread_cond_broadcast"},
3645 Signature(ArgTypes{Pthread_cond_tPtrTy}, RetType{IntTy}),
3646 Summary(NoEvalCall).ArgConstraint(NotNull(ArgNo(0))));
3651 addToFunctionSummaryMap(
3653 Signature(ArgTypes{Pthread_tPtrRestrictTy,
3654 ConstPthread_attr_tPtrRestrictTy,
3655 PthreadStartRoutineTy, VoidPtrRestrictTy},
3658 .ArgConstraint(NotNull(ArgNo(0)))
3659 .ArgConstraint(NotNull(ArgNo(2))));
3663 addToFunctionSummaryMap(
3664 {
"pthread_attr_destroy",
"pthread_attr_init"},
3665 Signature(ArgTypes{Pthread_attr_tPtrTy}, RetType{IntTy}),
3666 Summary(NoEvalCall).ArgConstraint(NotNull(ArgNo(0))));
3672 addToFunctionSummaryMap(
3673 {
"pthread_attr_getstacksize",
"pthread_attr_getguardsize"},
3674 Signature(ArgTypes{ConstPthread_attr_tPtrRestrictTy, SizePtrRestrictTy},
3677 .ArgConstraint(NotNull(ArgNo(0)))
3678 .ArgConstraint(NotNull(ArgNo(1))));
3682 addToFunctionSummaryMap(
3683 {
"pthread_attr_setstacksize",
"pthread_attr_setguardsize"},
3684 Signature(ArgTypes{Pthread_attr_tPtrTy, SizeTyCanonTy}, RetType{IntTy}),
3686 .ArgConstraint(NotNull(ArgNo(0)))
3688 ArgumentCondition(1, WithinRange,
Range(0, SizeMax))));
3692 addToFunctionSummaryMap(
3693 "pthread_mutex_init",
3694 Signature(ArgTypes{Pthread_mutex_tPtrRestrictTy,
3695 ConstPthread_mutexattr_tPtrRestrictTy},
3697 Summary(NoEvalCall).ArgConstraint(NotNull(ArgNo(0))));
3703 addToFunctionSummaryMap(
3704 {
"pthread_mutex_destroy",
"pthread_mutex_lock",
"pthread_mutex_trylock",
3705 "pthread_mutex_unlock"},
3706 Signature(ArgTypes{Pthread_mutex_tPtrTy}, RetType{IntTy}),
3707 Summary(NoEvalCall).ArgConstraint(NotNull(ArgNo(0))));
3711 if (AddTestFunctions) {
3712 const RangeInt IntMin = BVF.
getMinValue(IntTy)->getLimitedValue();
3714 addToFunctionSummaryMap(
3715 "__not_null", Signature(ArgTypes{IntPtrTy}, RetType{IntTy}),
3716 Summary(EvalCallAsPure).ArgConstraint(NotNull(ArgNo(0))));
3718 addToFunctionSummaryMap(
3719 "__not_null_buffer",
3720 Signature(ArgTypes{VoidPtrTy, IntTy, IntTy}, RetType{IntTy}),
3721 Summary(EvalCallAsPure)
3722 .ArgConstraint(NotNullBuffer(ArgNo(0), ArgNo(1), ArgNo(2))));
3725 addToFunctionSummaryMap(
3726 "__single_val_0", Signature(ArgTypes{IntTy}, RetType{IntTy}),
3727 Summary(EvalCallAsPure)
3728 .ArgConstraint(ArgumentCondition(0U, WithinRange, SingleValue(0))));
3729 addToFunctionSummaryMap(
3730 "__single_val_1", Signature(ArgTypes{IntTy}, RetType{IntTy}),
3731 Summary(EvalCallAsPure)
3732 .ArgConstraint(ArgumentCondition(0U, WithinRange, SingleValue(1))));
3733 addToFunctionSummaryMap(
3734 "__range_1_2", Signature(ArgTypes{IntTy}, RetType{IntTy}),
3735 Summary(EvalCallAsPure)
3736 .ArgConstraint(ArgumentCondition(0U, WithinRange,
Range(1, 2))));
3737 addToFunctionSummaryMap(
3738 "__range_m1_1", Signature(ArgTypes{IntTy}, RetType{IntTy}),
3739 Summary(EvalCallAsPure)
3740 .ArgConstraint(ArgumentCondition(0U, WithinRange,
Range(-1, 1))));
3741 addToFunctionSummaryMap(
3742 "__range_m2_m1", Signature(ArgTypes{IntTy}, RetType{IntTy}),
3743 Summary(EvalCallAsPure)
3744 .ArgConstraint(ArgumentCondition(0U, WithinRange,
Range(-2, -1))));
3745 addToFunctionSummaryMap(
3746 "__range_m10_10", Signature(ArgTypes{IntTy}, RetType{IntTy}),
3747 Summary(EvalCallAsPure)
3748 .ArgConstraint(ArgumentCondition(0U, WithinRange,
Range(-10, 10))));
3749 addToFunctionSummaryMap(
"__range_m1_inf",
3750 Signature(ArgTypes{IntTy}, RetType{IntTy}),
3751 Summary(EvalCallAsPure)
3752 .ArgConstraint(ArgumentCondition(
3753 0U, WithinRange,
Range(-1, IntMax))));
3754 addToFunctionSummaryMap(
"__range_0_inf",
3755 Signature(ArgTypes{IntTy}, RetType{IntTy}),
3756 Summary(EvalCallAsPure)
3757 .ArgConstraint(ArgumentCondition(
3758 0U, WithinRange,
Range(0, IntMax))));
3759 addToFunctionSummaryMap(
"__range_1_inf",
3760 Signature(ArgTypes{IntTy}, RetType{IntTy}),
3761 Summary(EvalCallAsPure)
3762 .ArgConstraint(ArgumentCondition(
3763 0U, WithinRange,
Range(1, IntMax))));
3764 addToFunctionSummaryMap(
"__range_minf_m1",
3765 Signature(ArgTypes{IntTy}, RetType{IntTy}),
3766 Summary(EvalCallAsPure)
3767 .ArgConstraint(ArgumentCondition(
3768 0U, WithinRange,
Range(IntMin, -1))));
3769 addToFunctionSummaryMap(
"__range_minf_0",
3770 Signature(ArgTypes{IntTy}, RetType{IntTy}),
3771 Summary(EvalCallAsPure)
3772 .ArgConstraint(ArgumentCondition(
3773 0U, WithinRange,
Range(IntMin, 0))));
3774 addToFunctionSummaryMap(
"__range_minf_1",
3775 Signature(ArgTypes{IntTy}, RetType{IntTy}),
3776 Summary(EvalCallAsPure)
3777 .ArgConstraint(ArgumentCondition(
3778 0U, WithinRange,
Range(IntMin, 1))));
3779 addToFunctionSummaryMap(
"__range_1_2__4_6",
3780 Signature(ArgTypes{IntTy}, RetType{IntTy}),
3781 Summary(EvalCallAsPure)
3782 .ArgConstraint(ArgumentCondition(
3783 0U, WithinRange,
Range({1, 2}, {4, 6}))));
3784 addToFunctionSummaryMap(
3785 "__range_1_2__4_inf", Signature(ArgTypes{IntTy}, RetType{IntTy}),
3786 Summary(EvalCallAsPure)
3787 .ArgConstraint(ArgumentCondition(0U, WithinRange,
3788 Range({1, 2}, {4, IntMax}))));
3791 addToFunctionSummaryMap(
3792 "__single_val_out_0", Signature(ArgTypes{IntTy}, RetType{IntTy}),
3793 Summary(EvalCallAsPure)
3794 .ArgConstraint(ArgumentCondition(0U, OutOfRange, SingleValue(0))));
3795 addToFunctionSummaryMap(
3796 "__single_val_out_1", Signature(ArgTypes{IntTy}, RetType{IntTy}),
3797 Summary(EvalCallAsPure)
3798 .ArgConstraint(ArgumentCondition(0U, OutOfRange, SingleValue(1))));
3799 addToFunctionSummaryMap(
3800 "__range_out_1_2", Signature(ArgTypes{IntTy}, RetType{IntTy}),
3801 Summary(EvalCallAsPure)
3802 .ArgConstraint(ArgumentCondition(0U, OutOfRange,
Range(1, 2))));
3803 addToFunctionSummaryMap(
3804 "__range_out_m1_1", Signature(ArgTypes{IntTy}, RetType{IntTy}),
3805 Summary(EvalCallAsPure)
3806 .ArgConstraint(ArgumentCondition(0U, OutOfRange,
Range(-1, 1))));
3807 addToFunctionSummaryMap(
3808 "__range_out_m2_m1", Signature(ArgTypes{IntTy}, RetType{IntTy}),
3809 Summary(EvalCallAsPure)
3810 .ArgConstraint(ArgumentCondition(0U, OutOfRange,
Range(-2, -1))));
3811 addToFunctionSummaryMap(
3812 "__range_out_m10_10", Signature(ArgTypes{IntTy}, RetType{IntTy}),
3813 Summary(EvalCallAsPure)
3814 .ArgConstraint(ArgumentCondition(0U, OutOfRange,
Range(-10, 10))));
3815 addToFunctionSummaryMap(
"__range_out_m1_inf",
3816 Signature(ArgTypes{IntTy}, RetType{IntTy}),
3817 Summary(EvalCallAsPure)
3818 .ArgConstraint(ArgumentCondition(
3819 0U, OutOfRange,
Range(-1, IntMax))));
3820 addToFunctionSummaryMap(
"__range_out_0_inf",
3821 Signature(ArgTypes{IntTy}, RetType{IntTy}),
3822 Summary(EvalCallAsPure)
3823 .ArgConstraint(ArgumentCondition(
3824 0U, OutOfRange,
Range(0, IntMax))));
3825 addToFunctionSummaryMap(
"__range_out_1_inf",
3826 Signature(ArgTypes{IntTy}, RetType{IntTy}),
3827 Summary(EvalCallAsPure)
3828 .ArgConstraint(ArgumentCondition(
3829 0U, OutOfRange,
Range(1, IntMax))));
3830 addToFunctionSummaryMap(
"__range_out_minf_m1",
3831 Signature(ArgTypes{IntTy}, RetType{IntTy}),
3832 Summary(EvalCallAsPure)
3833 .ArgConstraint(ArgumentCondition(
3834 0U, OutOfRange,
Range(IntMin, -1))));
3835 addToFunctionSummaryMap(
"__range_out_minf_0",
3836 Signature(ArgTypes{IntTy}, RetType{IntTy}),
3837 Summary(EvalCallAsPure)
3838 .ArgConstraint(ArgumentCondition(
3839 0U, OutOfRange,
Range(IntMin, 0))));
3840 addToFunctionSummaryMap(
"__range_out_minf_1",
3841 Signature(ArgTypes{IntTy}, RetType{IntTy}),
3842 Summary(EvalCallAsPure)
3843 .ArgConstraint(ArgumentCondition(
3844 0U, OutOfRange,
Range(IntMin, 1))));
3845 addToFunctionSummaryMap(
"__range_out_1_2__4_6",
3846 Signature(ArgTypes{IntTy}, RetType{IntTy}),
3847 Summary(EvalCallAsPure)
3848 .ArgConstraint(ArgumentCondition(
3849 0U, OutOfRange,
Range({1, 2}, {4, 6}))));
3850 addToFunctionSummaryMap(
3851 "__range_out_1_2__4_inf", Signature(ArgTypes{IntTy}, RetType{IntTy}),
3852 Summary(EvalCallAsPure)
3854 ArgumentCondition(0U, OutOfRange,
Range({1, 2}, {4, IntMax}))));
3857 addToFunctionSummaryMap(
3858 "__within", Signature(ArgTypes{IntTy}, RetType{IntTy}),
3859 Summary(EvalCallAsPure)
3860 .ArgConstraint(ArgumentCondition(0U, WithinRange, SingleValue(1))));
3861 addToFunctionSummaryMap(
3862 "__out_of", Signature(ArgTypes{IntTy}, RetType{IntTy}),
3863 Summary(EvalCallAsPure)
3864 .ArgConstraint(ArgumentCondition(0U, OutOfRange, SingleValue(1))));
3866 addToFunctionSummaryMap(
3867 "__two_constrained_args",
3868 Signature(ArgTypes{IntTy, IntTy}, RetType{IntTy}),
3869 Summary(EvalCallAsPure)
3870 .ArgConstraint(ArgumentCondition(0U, WithinRange, SingleValue(1)))
3871 .ArgConstraint(ArgumentCondition(1U, WithinRange, SingleValue(1))));
3872 addToFunctionSummaryMap(
3873 "__arg_constrained_twice", Signature(ArgTypes{IntTy}, RetType{IntTy}),
3874 Summary(EvalCallAsPure)
3875 .ArgConstraint(ArgumentCondition(0U, OutOfRange, SingleValue(1)))
3876 .ArgConstraint(ArgumentCondition(0U, OutOfRange, SingleValue(2))));
3877 addToFunctionSummaryMap(
3879 Signature(ArgTypes{
Irrelevant, IntTy}, RetType{IntTy}),
3880 Summary(EvalCallAsPure).ArgConstraint(NotNull(ArgNo(0))));
3881 addToFunctionSummaryMap(
3883 Signature(ArgTypes{VoidPtrTy, ConstCharPtrTy}, RetType{IntTy}),
3884 Summary(EvalCallAsPure)
3885 .ArgConstraint(NotNull(ArgNo(0)))
3886 .ArgConstraint(NotNull(ArgNo(1))));
3887 addToFunctionSummaryMap(
3888 "__buf_size_arg_constraint",
3889 Signature(ArgTypes{ConstVoidPtrTy, SizeTyCanonTy}, RetType{IntTy}),
3890 Summary(EvalCallAsPure)
3892 BufferSize(ArgNo(0), ArgNo(1))));
3893 addToFunctionSummaryMap(
3894 "__buf_size_arg_constraint_mul",
3895 Signature(ArgTypes{ConstVoidPtrTy, SizeTyCanonTy, SizeTyCanonTy},
3897 Summary(EvalCallAsPure)
3898 .ArgConstraint(BufferSize(ArgNo(0), ArgNo(1),
3900 addToFunctionSummaryMap(
3901 "__buf_size_arg_constraint_concrete",
3902 Signature(ArgTypes{ConstVoidPtrTy}, RetType{IntTy}),
3903 Summary(EvalCallAsPure)
3904 .ArgConstraint(BufferSize(ArgNo(0),
3905 BVF.getValue(10, IntTy))));
3906 addToFunctionSummaryMap(
3907 {
"__test_restrict_param_0",
"__test_restrict_param_1",
3908 "__test_restrict_param_2"},
3909 Signature(ArgTypes{VoidPtrRestrictTy}, RetType{VoidTy}),
3910 Summary(EvalCallAsPure));
3913 addToFunctionSummaryMap(
3914 "__test_case_note", Signature(ArgTypes{}, RetType{IntTy}),
3915 Summary(EvalCallAsPure)
3916 .Case({ReturnValueCondition(WithinRange, SingleValue(0))},
3917 ErrnoIrrelevant,
"Function returns 0")
3918 .Case({ReturnValueCondition(WithinRange, SingleValue(1))},
3919 ErrnoIrrelevant,
"Function returns 1"));
3920 addToFunctionSummaryMap(
3921 "__test_case_range_1_2__4_6",
3922 Signature(ArgTypes{IntTy}, RetType{IntTy}),
3923 Summary(EvalCallAsPure)
3924 .Case({ArgumentCondition(0U, WithinRange,
3925 IntRangeVector{{IntMin, 0}, {3, 3}}),
3926 ReturnValueCondition(WithinRange, SingleValue(1))},
3928 .Case({ArgumentCondition(0U, WithinRange,
3929 IntRangeVector{{3, 3}, {7, IntMax}}),
3930 ReturnValueCondition(WithinRange, SingleValue(2))},
3932 .Case({ArgumentCondition(0U, WithinRange,
3933 IntRangeVector{{IntMin, 0}, {7, IntMax}}),
3934 ReturnValueCondition(WithinRange, SingleValue(3))},
3936 .Case({ArgumentCondition(
3938 IntRangeVector{{IntMin, 0}, {3, 3}, {7, IntMax}}),
3939 ReturnValueCondition(WithinRange, SingleValue(4))},
3944void ento::registerStdCLibraryFunctionsChecker(CheckerManager &mgr) {
3948 Checker->DisplayLoadedSummaries =
3949 Opts.getCheckerBooleanOption(Checker,
"DisplayLoadedSummaries");
3950 Checker->ModelPOSIX = Opts.getCheckerBooleanOption(Checker,
"ModelPOSIX");
3951 Checker->ShouldAssumeControlledEnvironment =
3952 Opts.ShouldAssumeControlledEnvironment;
3955bool ento::shouldRegisterStdCLibraryFunctionsChecker(
3956 const CheckerManager &mgr) {
3960void ento::registerStdCLibraryFunctionsTesterChecker(CheckerManager &mgr) {
3961 auto *Checker = mgr.
getChecker<StdLibraryFunctionsChecker>();
3962 Checker->AddTestFunctions =
true;
3965bool ento::shouldRegisterStdCLibraryFunctionsTesterChecker(
3966 const CheckerManager &mgr) {
static std::string getFunctionName(const CallEvent &Call)
static bool isInvalid(LocType Loc, bool *Invalid)
TranslationUnitDecl * getTranslationUnitDecl() const
QualType getPointerType(QualType T) const
Return the uniqued reference to the type for a pointer to the specified type.
const LangOptions & getLangOpts() const
CanQualType getCanonicalSizeType() const
QualType getRestrictType(QualType T) const
Return the uniqued reference to the type for a restrict qualified type.
CanQualType getCanonicalTypeDeclType(const TypeDecl *TD) const
CanQualType UnsignedCharTy
CanQualType UnsignedIntTy
QualType getFunctionType(QualType ResultTy, ArrayRef< QualType > Args, const FunctionProtoType::ExtProtoInfo &EPI) const
Return a normal function type with a typed argument list.
static Opcode negateComparisonOp(Opcode Opc)
BinaryOperatorKind Opcode
lookup_result lookup(DeclarationName Name) const
lookup - Find the declarations (if any) with the given Name in this context.
ASTContext & getASTContext() const LLVM_READONLY
void print(raw_ostream &Out, unsigned Indentation=0, bool PrintInstantiation=false) const
const ParmVarDecl * getParamDecl(unsigned i) const
QualType getReturnType() const
FunctionDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
unsigned getNumParams() const
Return the number of parameters this function must have based on its FunctionType.
size_t param_size() const
IdentifierInfo & get(StringRef Name)
Return the identifier token info for the specified named identifier.
QualType withConst() const
QualType getCanonicalType() const
APSIntPtr getMaxValue(const llvm::APSInt &v)
APSIntPtr getMinValue(const llvm::APSInt &v)
ASTContext & getContext() const
const AnalyzerOptions & getAnalyzerOptions() const
CHECKER * registerChecker(AT &&...Args)
Register a single-part checker (derived from Checker): construct its singleton instance,...
CheckerNameRef getCurrentCheckerName() const
CHECKER * getChecker(AT &&...Args)
If the the singleton instance of a checker class is not yet constructed, then construct it (with the ...
Simple checker classes that implement one frontend (i.e.
ProgramStateRef assumeInclusiveRange(ProgramStateRef State, NonLoc Value, const llvm::APSInt &From, const llvm::APSInt &To, bool InBound)
const ProgramStateRef & getState() const
unsigned succ_size() const
const ExplodedNode * getErrorNode() const
void markNotInteresting(SymbolRef sym)
bool isInteresting(SymbolRef sym) const
SValBuilder & getSValBuilder()
ConstraintManager & getConstraintManager()
BasicValueFactory & getBasicValueFactory()
ASTContext & getContext()
nonloc::ConcreteInt makeIntVal(const IntegerLiteral *integer)
SVal evalCast(SVal V, QualType CastTy, QualType OriginalTy)
Cast a given SVal to another SVal using given QualType's.
QualType getConditionType() const
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.
PRESERVE_NONE bool Ret(InterpState &S)
bool IsNonNull(InterpState &S)
bool matches(const til::SExpr *E1, const til::SExpr *E2)
The JSON file list parser is used to communicate input to InstallAPI.
bool isa(CodeGen::Address addr)
@ Result
The result type of a method or function.
const FunctionProtoType * T
U cast(CodeGen::Address addr)
int const char * function
__packed_splat4 __packed_splat2 __packed_splat8 __packed_splat4 __packed_splat2 __packed_splat4 __packed_splat2 __packed_splat8 __packed_splat4 uint32_t