diff --git a/clang/include/clang/CConv/ABounds.h b/clang/include/clang/CConv/ABounds.h index f58ff4a91182..b70adf4b9305 100644 --- a/clang/include/clang/CConv/ABounds.h +++ b/clang/include/clang/CConv/ABounds.h @@ -39,11 +39,19 @@ class ABounds { BoundsKind Kind; protected: ABounds(BoundsKind K): Kind(K) { } + void addBoundsUsedKey(BoundsKey); public: virtual ~ABounds() { } virtual std::string mkString(AVarBoundsInfo *) = 0; virtual bool areSame(ABounds *) = 0; + virtual BoundsKey getBKey() = 0; + virtual ABounds* makeCopy(BoundsKey NK) = 0; + + // Set that maintains all the bound keys that are used inin + static std::set KeysUsedInBounds; + + static bool isKeyUsedInBounds(BoundsKey ToCheck); static ABounds *getBoundsInfo(AVarBoundsInfo *AVBInfo, BoundsExpr *BExpr, const ASTContext &C); @@ -51,12 +59,16 @@ class ABounds { class CountBound : public ABounds { public: - CountBound(BoundsKey Var) : ABounds(CountBoundKind), CountVar(Var) { } + CountBound(BoundsKey Var) : ABounds(CountBoundKind), CountVar(Var) { + addBoundsUsedKey(Var); + } virtual ~CountBound() { } std::string mkString(AVarBoundsInfo *ABI) override ; bool areSame(ABounds *O) override; + BoundsKey getBKey() override; + ABounds* makeCopy(BoundsKey NK) override; static bool classof(const ABounds *S) { return S->getKind() == CountBoundKind; @@ -69,12 +81,16 @@ class CountBound : public ABounds { class ByteBound : public ABounds { public: - ByteBound(BoundsKey Var) : ABounds(ByteBoundKind), ByteVar(Var) { } + ByteBound(BoundsKey Var) : ABounds(ByteBoundKind), ByteVar(Var) { + addBoundsUsedKey(Var); + } virtual ~ByteBound() { } std::string mkString(AVarBoundsInfo *ABI) override ; bool areSame(ABounds *O) override; + BoundsKey getBKey() override; + ABounds* makeCopy(BoundsKey NK) override; static bool classof(const ABounds *S) { return S->getKind() == ByteBoundKind; @@ -87,13 +103,26 @@ class ByteBound : public ABounds { class RangeBound : public ABounds { public: RangeBound(BoundsKey L, BoundsKey R) : ABounds(RangeBoundKind), - LB(L), UB(R) { } + LB(L), UB(R) { + addBoundsUsedKey(L); + addBoundsUsedKey(R); + } virtual ~RangeBound() { } std::string mkString(AVarBoundsInfo *ABI) override ; bool areSame(ABounds *O) override; + BoundsKey getBKey() override { + assert (false && "Not implemented."); + return 0; + } + + ABounds* makeCopy(BoundsKey NK) override { + assert (false &&& "Not Implemented"); + return nullptr; + } + static bool classof(const ABounds *S) { return S->getKind() == RangeBoundKind; } diff --git a/clang/include/clang/CConv/AVarBoundsInfo.h b/clang/include/clang/CConv/AVarBoundsInfo.h index 1c43b72e22bd..865b6481676d 100644 --- a/clang/include/clang/CConv/AVarBoundsInfo.h +++ b/clang/include/clang/CConv/AVarBoundsInfo.h @@ -20,6 +20,7 @@ #include "clang/CConv/ConstraintVariables.h" class ProgramInfo; +class ConstraintResolver; // Class that maintains stats about how the bounds of various variables is // computed. @@ -78,6 +79,14 @@ class AVarBoundsStats { }; +// Priority for bounds. +enum BoundsPriority { + Declared = 1, // Highest priority: These are declared by the user. + Allocator, // Second priority: allocator based bounds. + FlowInferred, // Flow based bounds. + Heuristics, // Least-priority, based on heuristics. + Invalid // Invalid priority type. +}; class AVarBoundsInfo; @@ -103,6 +112,9 @@ class AvarBoundsInference { bool predictBounds(BoundsKey K, std::set &Neighbours, ABounds **KB); + + void mergeReachableProgramVars(std::set &AllVars); + AVarBoundsInfo *BI; }; @@ -115,6 +127,8 @@ class AVarBoundsInfo { BInfo.clear(); DeclVarMap.clear(); TmpBoundsKey.clear(); + CSBoundsKey.clear(); + ArrPointersWithArithmetic.clear(); } typedef std::tuple ParamDeclType; @@ -123,10 +137,12 @@ class AVarBoundsInfo { bool isValidBoundVariable(clang::Decl *D); void insertDeclaredBounds(clang::Decl *D, ABounds *B); - bool mergeBounds(BoundsKey L, ABounds *B); - bool removeBounds(BoundsKey L); - bool replaceBounds(BoundsKey L, ABounds *B); - ABounds *getBounds(BoundsKey L); + bool mergeBounds(BoundsKey L, BoundsPriority P, ABounds *B); + bool removeBounds(BoundsKey L, BoundsPriority P = Invalid); + bool replaceBounds(BoundsKey L, BoundsPriority P, ABounds *B); + ABounds *getBounds(BoundsKey L, + BoundsPriority ReqP = Invalid, + BoundsPriority *RetP = nullptr); bool updatePotentialCountBounds(BoundsKey BK, std::set &CntBK); // Try and get BoundsKey, into R, for the given declaration. If the declaration @@ -143,6 +159,7 @@ class AVarBoundsInfo { BoundsKey getVariable(clang::VarDecl *VD); BoundsKey getVariable(clang::ParmVarDecl *PVD); BoundsKey getVariable(clang::FieldDecl *FD); + BoundsKey getVariable(clang::FunctionDecl *FD); BoundsKey getConstKey(uint64_t value); // Generate a random bounds key to be used for inference. @@ -153,6 +170,28 @@ class AVarBoundsInfo { bool addAssignment(clang::Decl *L, clang::Decl *R); bool addAssignment(clang::DeclRefExpr *L, clang::DeclRefExpr *R); bool addAssignment(BoundsKey L, BoundsKey R); + bool handlePointerAssignment(clang::Stmt *St, clang::Expr *L, + clang::Expr *R, + ASTContext *C, + ConstraintResolver *CR); + bool handleAssignment(clang::Expr *L, CVarSet &LCVars, + clang::Expr *R, CVarSet &RCVars, + ASTContext *C, ConstraintResolver *CR); + bool handleAssignment(clang::Decl *L, CVarSet &LCVars, + clang::Expr *R, CVarSet &RCVars, + ASTContext *C, ConstraintResolver *CR); + // Handle context sensitive assignment. + bool handleContextSensitiveAssignment(CallExpr *CE, clang::Decl *L, + ConstraintVariable *LCVar, + clang::Expr *R, CVarSet &RCVars, + ASTContext *C, ConstraintResolver *CR); + + // Handle the arithmetic expression. This is required to adjust bounds + // for pointers that has pointer arithmetic performed on them. + void recordArithmeticOperation(clang::Expr *E, ConstraintResolver *CR); + + // Check if the given bounds key has a pointer arithmetic done on it. + bool hasPointerArithmetic(BoundsKey BK); // Get the ProgramVar for the provided VarKey. ProgramVar *getProgramVar(BoundsKey VK); @@ -164,6 +203,17 @@ class AVarBoundsInfo { // Propagate the array bounds information for all array ptrs. bool performFlowAnalysis(ProgramInfo *PI); + // Reset (i.e., clear) the context sensitive bounds information. + void resetContextSensitiveBoundsKey(); + // Create context sensitive BoundsKey variables for the given set of + // ConstraintVariables. + bool contextualizeCVar(CallExpr *CE, + const std::set &CV); + // Get the context sensitive BoundsKey for the given key. + // If there exists no context-sensitive bounds key, we just return + // the provided key. + BoundsKey getContextSensitiveBoundsKey(CallExpr *CE, BoundsKey BK); + AVarBoundsStats &getBStats() { return BoundsInferStats; } // Dump the AVar graph to the provided dot file. @@ -176,7 +226,10 @@ class AVarBoundsInfo { private: friend class AvarBoundsInference; + friend struct llvm::DOTGraphTraits; + // List of bounds priority in descending order of priorities. + static std::vector PrioList; // Variable that is used to generate new bound keys. BoundsKey BCount; @@ -184,16 +237,22 @@ class AVarBoundsInfo { std::map PVarInfo; // Map of APSInt (constants) and corresponding VarKeys. std::map ConstVarKeys; - // Map of BoundsKey and corresponding bounds information. + // Map of BoundsKey and corresponding prioritized bounds information. // Note that although each PSL could have multiple ConstraintKeys Ex: **p. // Only the outer most pointer can have bounds. - std::map BInfo; + std::map> BInfo; // Set that contains BoundsKeys of variables which have invalid bounds. std::set InvalidBounds; + // These are the bounds key of the pointers that has arithmetic operations + // performed on them. + std::set ArrPointersWithArithmetic; // Set of BoundsKeys that correspond to pointers. std::set PointerBoundsKey; // Set of BoundsKey that correspond to array pointers. std::set ArrPointerBoundsKey; + // Set of BoundsKey that correspond to array pointers with in the program + // being compiled i.e., it does not include array pointers that belong + // to libraries. std::set InProgramArrPtrBoundsKeys; // These are temporary bound keys generated during inference. @@ -204,6 +263,9 @@ class AVarBoundsInfo { BiMap DeclVarMap; // BiMap of parameter keys and BoundsKey for function parameters. BiMap ParamDeclVarMap; + // BiMap of function keys and BoundsKey for function return values. + BiMap, + BoundsKey> FuncDeclVarMap; // Graph of all program variables. AVarGraph ProgVarGraph; @@ -213,6 +275,12 @@ class AVarBoundsInfo { // which can be the count bounds. std::map> PotentialCntBounds; + // Context sensitive bounds key. + // For each call-site a map of original bounds key and the bounds key + // specific to this call-site. + // Note: This map is only active for the compilation unit being parsed. + std::map> CSBoundsKey; + // BoundsKey helper function: These functions help in getting bounds key from // various artifacts. bool hasVarKey(PersistentSourceLoc &PSL); @@ -225,6 +293,16 @@ class AVarBoundsInfo { void insertProgramVar(BoundsKey NK, ProgramVar *PV); + // Check if the provided bounds key corresponds to function return. + bool isFunctionReturn(BoundsKey BK); + + // Of all teh pointer bounds key, find arr pointers. + void computerArrPointers(ProgramInfo *PI, std::set &Ret); + + // Keep only highest priority bounds for all the provided BoundsKeys + // returns true if any thing changed, else false. + bool keepHighestPriorityBounds(std::set &ArrPtrs); + // Perform worklist based inference on the requested array variables. // The flag FromPB requests the algorithm to use potential length variables. bool performWorkListInference(std::set &ArrNeededBounds, @@ -233,4 +311,39 @@ class AVarBoundsInfo { void insertParamKey(ParamDeclType ParamDecl, BoundsKey NK); }; +// This class creates context sensitive bounds key information that is +// useful to resolve certain bounds information. +// Consider the following example: +// _Arry_ptr foo(unsigned int s) : count(s); +// .... +// int *a, *c; +// unsigned b, d; +// a = foo(b); +// c = foo(d); +// ... +// Here, when we do our analysis we do not know whether b or d is the bounds +// of a. +// The reason for this is because we maintain a single bounds variable for foo, +// consequently, when we do our flow analysis we see that b and d both propagate +// to s (which is the bounds of the return value of foo). +// However, if we maintain context sensitive bounds keys, then we know that +// at a = foo(b), it is b that is passed to s and there by helps us infer that +// the bounds of a should be b i.e., _Array_ptr : count(b). +// This class helps in maintaining the context sensitive bounds information. +class ContextSensitiveBoundsKeyVisitor : + public RecursiveASTVisitor { +public: + explicit ContextSensitiveBoundsKeyVisitor(ASTContext *C, ProgramInfo &I, + ConstraintResolver *CResolver); + + virtual ~ContextSensitiveBoundsKeyVisitor(); + + bool VisitCallExpr(CallExpr *CE); + +private: + ASTContext *Context; + ProgramInfo &Info; + ConstraintResolver *CR; +}; + #endif // _AVARBOUNDSINFO_H diff --git a/clang/include/clang/CConv/ConstraintResolver.h b/clang/include/clang/CConv/ConstraintResolver.h index 21eae09b3ab4..f5ac5ef9c2b9 100644 --- a/clang/include/clang/CConv/ConstraintResolver.h +++ b/clang/include/clang/CConv/ConstraintResolver.h @@ -45,7 +45,7 @@ class ConstraintResolver { ConsAction CAction = Same_to_Same); // Check if the set contains any valid constraints. - bool containsValidCons(CVarSet &CVs); + bool containsValidCons(const CVarSet &CVs); bool isValidCons(ConstraintVariable *CV); // Try to get the bounds key from the constraint variable set. bool resolveBoundsKey(CVarSet &CVs, BoundsKey &BK); diff --git a/clang/include/clang/CConv/ConstraintVariables.h b/clang/include/clang/CConv/ConstraintVariables.h index c6e99113fb69..c4c07c9a00c1 100644 --- a/clang/include/clang/CConv/ConstraintVariables.h +++ b/clang/include/clang/CConv/ConstraintVariables.h @@ -104,6 +104,10 @@ class ConstraintVariable { assert(ValidBoundsKey && "No valid Bkey"); return BKey; } + void setBoundsKey(BoundsKey NK) { + ValidBoundsKey = true; + BKey = NK; + } virtual bool solutionEqualTo(Constraints &, const ConstraintVariable *) const = 0; diff --git a/clang/include/clang/CConv/ProgramVar.h b/clang/include/clang/CConv/ProgramVar.h index ac155d07fd6f..838f749f4226 100644 --- a/clang/include/clang/CConv/ProgramVar.h +++ b/clang/include/clang/CConv/ProgramVar.h @@ -220,7 +220,9 @@ class ProgramVar { BoundsKey getKey() { return K; } bool IsNumConstant() { return IsConstant; } std::string mkString(bool GetKey = false); + std::string getVarName() { return VarName; } std::string verboseStr(); + ProgramVar *makeCopy(BoundsKey NK); virtual ~ProgramVar() { } private: BoundsKey K; diff --git a/clang/lib/CConv/ABounds.cpp b/clang/lib/CConv/ABounds.cpp index ba346b879a4f..f89fb302b601 100644 --- a/clang/lib/CConv/ABounds.cpp +++ b/clang/lib/CConv/ABounds.cpp @@ -13,6 +13,16 @@ #include "clang/CConv/ABounds.h" #include "clang/CConv/AVarBoundsInfo.h" +std::set ABounds::KeysUsedInBounds; + +void ABounds::addBoundsUsedKey(BoundsKey BK) { + KeysUsedInBounds.insert(BK); +} + +bool ABounds::isKeyUsedInBounds(BoundsKey ToCheck) { + return KeysUsedInBounds.find(ToCheck) != KeysUsedInBounds.end(); +} + ABounds *ABounds::getBoundsInfo(AVarBoundsInfo *ABInfo, BoundsExpr *BExpr, const ASTContext &C) { @@ -21,15 +31,18 @@ ABounds *ABounds::getBoundsInfo(AVarBoundsInfo *ABInfo, RangeBoundsExpr *RBE = dyn_cast(BExpr->IgnoreParenCasts()); BoundsKey VK; if (CBE && !CBE->isCompilerGenerated()) { - if (BExpr->isElementCount() && - ABInfo->tryGetVariable(CBE->getCountExpr()->IgnoreParenCasts(), C, - VK)) { - Ret = new CountBound(VK); - } - if (BExpr->isByteCount() && - ABInfo->tryGetVariable(CBE->getCountExpr()->IgnoreParenCasts(), C, - VK)) { - Ret = new ByteBound(VK); + if (ABInfo->tryGetVariable(CBE->getCountExpr()->IgnoreParenCasts(), C, + VK)) { + ProgramVar *PV = ABInfo->getProgramVar(VK); + if (PV->IsNumConstant() && PV->getVarName() == "0") { + // Invalid bounds. This is for functions like free. + // Where the bounds is 0. + Ret = nullptr; + } else if (BExpr->isElementCount()) { + Ret = new CountBound(VK); + } else if (BExpr->isByteCount()) { + Ret = new ByteBound(VK); + } } } if (BExpr->isRange() && RBE) { @@ -59,6 +72,14 @@ bool CountBound::areSame(ABounds *O) { return false; } +BoundsKey CountBound::getBKey() { + return this->CountVar; +} + +ABounds* CountBound::makeCopy(BoundsKey NK) { + return new CountBound(NK); +} + std::string ByteBound::mkString(AVarBoundsInfo *ABI) { ProgramVar *PV = ABI->getProgramVar(ByteVar); assert(PV != nullptr && "No Valid program var"); @@ -74,6 +95,15 @@ bool ByteBound::areSame(ABounds *O) { return false; } + +BoundsKey ByteBound::getBKey() { + return this->ByteVar; +} + +ABounds* ByteBound::makeCopy(BoundsKey NK) { + return new ByteBound(NK); +} + std::string RangeBound::mkString(AVarBoundsInfo *ABI) { ProgramVar *LBVar = ABI->getProgramVar(LB); ProgramVar *UBVar = ABI->getProgramVar(UB); diff --git a/clang/lib/CConv/AVarBoundsInfo.cpp b/clang/lib/CConv/AVarBoundsInfo.cpp index 53cb8eaaeeaa..4db314844bc3 100644 --- a/clang/lib/CConv/AVarBoundsInfo.cpp +++ b/clang/lib/CConv/AVarBoundsInfo.cpp @@ -12,6 +12,10 @@ #include "clang/CConv/AVarBoundsInfo.h" #include "clang/CConv/ProgramInfo.h" +#include "clang/CConv/ConstraintResolver.h" + +std::vector + AVarBoundsInfo::PrioList {Declared, Allocator, FlowInferred, Heuristics}; void AVarBoundsStats::print(llvm::raw_ostream &O, const std::set *InSrcArrs, @@ -53,8 +57,8 @@ bool AVarBoundsInfo::isValidBoundVariable(clang::Decl *D) { if (VarDecl *VD = dyn_cast(D)) { return !VD->getNameAsString().empty(); } - if (isa(D)) { - // All parameters are valid bound variables. + if (isa(D) || isa(D)) { + // All parameters and return values are valid bound variables. return true; } if(FieldDecl *FD = dyn_cast(D)) { @@ -69,10 +73,8 @@ void AVarBoundsInfo::insertDeclaredBounds(clang::Decl *D, ABounds *B) { tryGetVariable(D, BK); if (B != nullptr) { // If there is already bounds information, release it. - if (BInfo.find(BK) != BInfo.end()) { - delete (BInfo[BK]); - } - BInfo[BK] = B; + removeBounds(BK); + BInfo[BK][Declared] = B; BoundsInferStats.DeclaredBounds.insert(BK); } else { // Set bounds to be invalid. @@ -91,6 +93,9 @@ bool AVarBoundsInfo::tryGetVariable(clang::Decl *D, BoundsKey &R) { if (FieldDecl *FD = dyn_cast(D)) { R = getVariable(FD); } + if (FunctionDecl *FD = dyn_cast(D)) { + R = getVariable(FD); + } return true; } return false; @@ -123,41 +128,73 @@ bool AVarBoundsInfo::tryGetVariable(clang::Expr *E, return Ret; } -bool AVarBoundsInfo::mergeBounds(BoundsKey L, ABounds *B) { +bool AVarBoundsInfo::mergeBounds(BoundsKey L, BoundsPriority P, ABounds *B) { bool RetVal = false; - if (BInfo.find(L) != BInfo.end()) { + if (BInfo.find(L) != BInfo.end() && BInfo[L].find(P) != BInfo[L].end()) { // If previous computed bounds are not same? Then release the old bounds. - if (!BInfo[L]->areSame(B)) { + if (!BInfo[L][P]->areSame(B)) { InvalidBounds.insert(L); - delete (BInfo[L]); - BInfo.erase(L); + // TODO: Should we keep bounds for other priorities? + removeBounds(L); } } else { - BInfo[L] = B; + BInfo[L][P] = B; RetVal = true; } return RetVal; } -bool AVarBoundsInfo::removeBounds(BoundsKey L) { +bool AVarBoundsInfo::removeBounds(BoundsKey L, BoundsPriority P) { bool RetVal = false; if (BInfo.find(L) != BInfo.end()) { - delete (BInfo[L]); - BInfo.erase(L); - RetVal = true; + auto &PriBInfo = BInfo[L]; + if (P == Invalid) { + // Delete bounds for all priorities. + for (auto &T : PriBInfo) { + delete (T.second); + } + BInfo.erase(L); + RetVal = true; + } else { + // Delete bounds for only the given priority. + if (PriBInfo.find(P) != PriBInfo.end()) { + delete (PriBInfo[P]); + PriBInfo.erase(P); + RetVal = true; + } + // If there are no other bounds then remove the key. + if (BInfo[L].empty()) { + BInfo.erase(L); + RetVal = true; + } + } } return RetVal; } -bool AVarBoundsInfo::replaceBounds(BoundsKey L, ABounds *B) { +bool AVarBoundsInfo::replaceBounds(BoundsKey L, BoundsPriority P, ABounds *B) { removeBounds(L); - return mergeBounds(L, B); + return mergeBounds(L, P, B); } -ABounds *AVarBoundsInfo::getBounds(BoundsKey L) { +ABounds *AVarBoundsInfo::getBounds(BoundsKey L, BoundsPriority ReqP, + BoundsPriority *RetP) { if (InvalidBounds.find(L) == InvalidBounds.end() && BInfo.find(L) != BInfo.end()) { - return BInfo[L]; + auto &PriBInfo = BInfo[L]; + if (ReqP == Invalid) { + // Fetch bounds by priority i.e., give the highest priority bounds. + for (BoundsPriority P : PrioList) { + if (PriBInfo.find(P) != PriBInfo.end()) { + if (RetP != nullptr) + *RetP = P; + return PriBInfo[P]; + } + } + assert(false && "Bounds present but has invalid priority."); + } else if (PriBInfo.find(ReqP) != PriBInfo.end()) { + return PriBInfo[ReqP]; + } } return nullptr; } @@ -212,7 +249,6 @@ BoundsKey AVarBoundsInfo::getVariable(clang::ParmVarDecl *PVD) { std::string FileName = Psl.getFileName(); auto ParamKey = std::make_tuple(FD->getNameAsString(), FileName, FD->isStatic(), ParamIdx); - assert(ParamIdx >= 0 && "Unable to find parameter."); if (ParamDeclVarMap.left().find(ParamKey) == ParamDeclVarMap.left().end()) { BoundsKey NK = ++BCount; FunctionParamScope *FPS = @@ -233,6 +269,27 @@ BoundsKey AVarBoundsInfo::getVariable(clang::ParmVarDecl *PVD) { return ParamDeclVarMap.left().at(ParamKey); } +BoundsKey AVarBoundsInfo::getVariable(clang::FunctionDecl *FD) { + assert(isValidBoundVariable(FD) && "Not a valid bound declaration."); + auto Psl = PersistentSourceLoc::mkPSL(FD, FD->getASTContext()); + std::string FileName = Psl.getFileName(); + auto FuncKey = std::make_tuple(FD->getNameAsString(), FileName, + FD->isStatic()); + if (FuncDeclVarMap.left().find(FuncKey) == FuncDeclVarMap.left().end()) { + BoundsKey NK = ++BCount; + FunctionParamScope *FPS = + FunctionParamScope::getFunctionParamScope(FD->getNameAsString(), + FD->isStatic()); + + auto *PVar = new ProgramVar(NK, FD->getNameAsString(), FPS); + insertProgramVar(NK, PVar); + FuncDeclVarMap.insert(FuncKey, NK); + if (FD->getReturnType()->isPointerType()) + PointerBoundsKey.insert(NK); + } + return FuncDeclVarMap.left().at(FuncKey); +} + BoundsKey AVarBoundsInfo::getVariable(clang::FieldDecl *FD) { assert(isValidBoundVariable(FD) && "Not a valid bound declaration."); PersistentSourceLoc PSL = PersistentSourceLoc::mkPSL(FD, FD->getASTContext()); @@ -268,12 +325,160 @@ bool AVarBoundsInfo::addAssignment(clang::DeclRefExpr *L, return addAssignment(L->getDecl(), R->getDecl()); } +bool AVarBoundsInfo::handleAssignment(clang::Expr *L, CVarSet &LCVars, + clang::Expr *R, CVarSet &RCVars, + ASTContext *C, ConstraintResolver *CR) { + BoundsKey LKey, RKey; + if ((CR->resolveBoundsKey(LCVars, LKey) || + tryGetVariable(L, *C, LKey)) && + (CR->resolveBoundsKey(RCVars, RKey) || + tryGetVariable(R, *C, RKey))) { + return addAssignment(LKey, RKey); + } + return false; +} + +bool AVarBoundsInfo::handleAssignment(clang::Decl *L, CVarSet &LCVars, + clang::Expr *R, CVarSet &RCVars, + ASTContext *C, ConstraintResolver *CR) { + BoundsKey LKey, RKey; + if ((CR->resolveBoundsKey(LCVars, LKey) || + tryGetVariable(L, LKey)) && + (CR->resolveBoundsKey(RCVars, RKey) || + tryGetVariable(R, *C, RKey))) { + return addAssignment(LKey, RKey); + } + return false; +} + +bool AVarBoundsInfo::handleContextSensitiveAssignment(CallExpr *CE, + clang::Decl *L, + ConstraintVariable *LCVar, + clang::Expr *R, + CVarSet &RCVars, + ASTContext *C, + ConstraintResolver *CR) { + // If these are pointer variable then directly get the context-sensitive + // bounds key. + if(CR->containsValidCons({LCVar}) && CR->containsValidCons(RCVars)) { + for (auto *RT : RCVars) { + if (LCVar->hasBoundsKey() && RT->hasBoundsKey()) { + BoundsKey NewL = getContextSensitiveBoundsKey(CE, LCVar->getBoundsKey()); + BoundsKey NewR = getContextSensitiveBoundsKey(CE, RT->getBoundsKey()); + addAssignment(NewL, NewR); + } + } + } else { + // This is the assignment of regular variables. + BoundsKey LKey, RKey; + if ((CR->resolveBoundsKey({LCVar}, LKey) || + tryGetVariable(L, LKey)) && + (CR->resolveBoundsKey(RCVars, RKey) || + tryGetVariable(R, *C, RKey))) { + BoundsKey NewL = getContextSensitiveBoundsKey(CE, LKey); + BoundsKey NewR = getContextSensitiveBoundsKey(CE, RKey); + addAssignment(NewL, NewR); + } + } + return true; +} + bool AVarBoundsInfo::addAssignment(BoundsKey L, BoundsKey R) { - ProgVarGraph.addEdge(L, R); - ProgVarGraph.addEdge(R, L); + // If we are adding to function return, do not add bi-directional edges. + if (isFunctionReturn(L) || isFunctionReturn(R)) { + // Do not assign edge from return to itself. + // This is because while inferring bounds of return value, we expect + // all the variables used in return values to have bounds. + // So, if we create a edge from return to itself then we create a cyclic + // dependency and never will be able to find the bounds for the return + // value. + if (L != R) + ProgVarGraph.addEdge(R, L); + } else { + ProgVarGraph.addEdge(L, R); + ProgVarGraph.addEdge(R, L); + } return true; } +// Visitor to collect all the variables that are used during the life-time +// of the visitor. +// This class also has a flag that gets set when a variable is observed +// more than once. +class CollectDeclsVisitor : public RecursiveASTVisitor { +public: + + std::set ObservedDecls; + std::set StructAccess; + + explicit CollectDeclsVisitor(ASTContext *Ctx) : C(Ctx) { + ObservedDecls.clear(); + StructAccess.clear(); + } + virtual ~CollectDeclsVisitor() { + ObservedDecls.clear(); + } + + bool VisitDeclRefExpr(DeclRefExpr *DRE) { + VarDecl *VD = dyn_cast_or_null(DRE->getDecl()); + if (VD != nullptr) { + ObservedDecls.insert(VD); + } + return true; + } + + // For a->b; We need to get `a->b` + bool VisitMemberExpr(MemberExpr *ME) { + std::string MAccess = getSourceText(ME->getSourceRange(), *C); + if (!MAccess.empty()) { + StructAccess.insert(MAccess); + } + return false; + } + +private: + ASTContext *C; +}; + +bool +AVarBoundsInfo::handlePointerAssignment(clang::Stmt *St, clang::Expr *L, + clang::Expr *R, + ASTContext *C, + ConstraintResolver *CR) { + CollectDeclsVisitor LVarVis(C); + LVarVis.TraverseStmt(L->getExprStmt()); + + CollectDeclsVisitor RVarVis(C); + RVarVis.TraverseStmt(R->getExprStmt()); + + std::set CommonVars; + std::set CommonStVars; + findIntersection(LVarVis.ObservedDecls, RVarVis.ObservedDecls, CommonVars); + findIntersection(LVarVis.StructAccess, RVarVis.StructAccess, CommonStVars); + + if (!CommonVars.empty() || CommonStVars.empty()) { + for (auto *LHSCVar : CR->getExprConstraintVars(L)) { + if (LHSCVar->hasBoundsKey()) + ArrPointerBoundsKey.insert(LHSCVar->getBoundsKey()); + } + } + return true; +} + +void +AVarBoundsInfo::recordArithmeticOperation(clang::Expr *E, + ConstraintResolver *CR) { + CVarSet CSet = CR->getExprConstraintVars(E); + for (auto *CV : CSet) { + if (CV->hasBoundsKey()) + ArrPointersWithArithmetic.insert(CV->getBoundsKey()); + } +} + +bool AVarBoundsInfo::hasPointerArithmetic(BoundsKey BK) { + return ArrPointersWithArithmetic.find(BK) != ArrPointersWithArithmetic.end(); +} + ProgramVar *AVarBoundsInfo::getProgramVar(BoundsKey VK) { ProgramVar *Ret = nullptr; if (PVarInfo.find(VK) != PVarInfo.end()) { @@ -435,6 +640,38 @@ bool AvarBoundsInference::intersectBounds(std::set &ProgVars, return !CurrB.empty(); } +void +AvarBoundsInference:: + mergeReachableProgramVars(std::set &AllVars) { + if (AllVars.size() > 1) { + ProgramVar *BVar = nullptr; + // We want to merge all bounds vars. We give preference to + // non-constants if there are multiple non-constant variables, + // we give up. + for (auto *TmpB : AllVars) { + if (BVar == nullptr) { + BVar = TmpB; + } else if (BVar->IsNumConstant()) { + if (!TmpB->IsNumConstant()) { + // We give preference to non-constant lengths. + BVar = TmpB; + } else if (BVar->getKey() != TmpB->getKey()) { + // If both are different constants? + BVar = nullptr; + break; + } + } else if (!TmpB->IsNumConstant() && BVar->getKey() != TmpB->getKey()) { + // If they are different variables? + BVar = nullptr; + break; + } + } + AllVars.clear(); + if (BVar) + AllVars.insert(BVar); + } +} + bool AvarBoundsInference::inferPossibleBounds(BoundsKey K, ABounds *SB, std::set &EB) { bool RetVal = false; @@ -469,6 +706,8 @@ bool AvarBoundsInference::inferPossibleBounds(BoundsKey K, ABounds *SB, }); } + mergeReachableProgramVars(PotentialB); + // Are there are other in-scope variables where the bounds variable // has been assigned to? if (!PotentialB.empty()) @@ -481,20 +720,14 @@ bool AvarBoundsInference::inferPossibleBounds(BoundsKey K, ABounds *SB, bool AvarBoundsInference::getRelevantBounds(std::set &RBKeys, std::set &ResBounds) { - std::set IncomingArrs; - std::set TmpIncomingKeys; - - // First, get all the related bounds keys that are arrays. - findIntersection(RBKeys, BI->ArrPointerBoundsKey, IncomingArrs); - // Also get all the temporary bounds keys. - findIntersection(RBKeys, BI->TmpBoundsKey, TmpIncomingKeys); - - // Consider the tmp keys as incoming arrays. - IncomingArrs.insert(TmpIncomingKeys.begin(), TmpIncomingKeys.end()); - - // Next, try to get their bounds. + // Try to get the bounds of all RBKeys. bool ValidB = true; - for (auto PrevBKey : IncomingArrs) { + for (auto PrevBKey : RBKeys) { + // If this pointer is used in pointer arithmetic then there + // are no relevant bounds for this pointer. + if (BI->hasPointerArithmetic(PrevBKey)) { + continue; + } auto *PrevBounds = BI->getBounds(PrevBKey); // Does the parent arr has bounds? if (PrevBounds != nullptr) @@ -509,20 +742,29 @@ bool AvarBoundsInference::predictBounds(BoundsKey K, std::set ResBounds; std::set KBounds; *KB = nullptr; - bool IsValid = true; + bool IsValid = false; // Get all the relevant bounds from the neighbour ARRs if (getRelevantBounds(Neighbours, ResBounds)) { + bool IsFuncRet = BI->isFunctionReturn(K); + // For function returns, we want all the predecessors to have bounds. + if (IsFuncRet && ResBounds.size() != Neighbours.size()) { + return IsValid; + } if (!ResBounds.empty()) { + IsValid = true; // Find the intersection? for (auto *B : ResBounds) { - inferPossibleBounds(K, B, KBounds); //TODO: check this // This is stricter version i.e., there should be at least one common // bounds information from an incoming ARR. - /*if (!inferPossibleBounds(K, B, KBounds)) { - ValidB = false; + // Should we follow same for all the pointers? + + // For function returns we should have atleast one common bound + // from all the return values. + if (!inferPossibleBounds(K, B, KBounds) && IsFuncRet) { + IsValid = false; break; - }*/ + } } // If we converge to single bounds information? We found the bounds. if (KBounds.size() == 1) { @@ -568,47 +810,25 @@ bool AvarBoundsInference::inferBounds(BoundsKey K, bool FromPB) { PotentialB.insert(TKVar); } } - if (!PotentialB.empty()) { - ProgramVar *BVar = nullptr; - // We want to merge all bounds vars. We give preference to - // non-constants if there are multiple non-constant variables, - // we give up. - for (auto *TmpB : PotentialB) { - if (BVar == nullptr) { - BVar = TmpB; - } else if (BVar->IsNumConstant()) { - if (!TmpB->IsNumConstant()) { - // We give preference to non-constant lengths. - BVar = TmpB; - } else if (BVar->getKey() != TmpB->getKey()) { - // If both are different constants? - BVar = nullptr; - break; - } - } else if (!TmpB->IsNumConstant() && - BVar->getKey() != TmpB->getKey()) { - // If they are different variables? - BVar = nullptr; - break; - } - } - if (BVar != nullptr) { - KB = new CountBound(BVar->getKey()); - } - } + ProgramVar *BVar = nullptr; + mergeReachableProgramVars(PotentialB); + if (!PotentialB.empty()) + BVar = *(PotentialB.begin()); + if (BVar != nullptr) + KB = new CountBound(BVar->getKey()); } } else { // Infer from the flow-graph. std::set TmpBkeys; - // Try to predict bounds from successors. - BI->ProgVarGraph.getSuccessors(K, TmpBkeys); + // Try to predict bounds from predecessors. + BI->ProgVarGraph.getPredecessors(K, TmpBkeys); if (!predictBounds(K, TmpBkeys, &KB)) { KB = nullptr; } } if (KB != nullptr) { - BI->replaceBounds(K, KB); + BI->replaceBounds(K, FlowInferred, KB); IsChanged = true; } } @@ -649,14 +869,87 @@ bool AVarBoundsInfo::performWorkListInference(std::set &ArrNeededBoun } return RetVal; } -bool AVarBoundsInfo::performFlowAnalysis(ProgramInfo *PI) { - bool RetVal = false; + +// Here, we create a new BoundsKey for every BoundsKey var that is related to +// any ConstraintVariable in CSet and store the information by the +// corresponding call expression (CE). +// Here, we only care about variables that have bounds declaration +// or that are used in a bounds declaration. +bool +AVarBoundsInfo::contextualizeCVar(CallExpr *CE, const CVarSet &CSet) { + for (auto *CV : CSet) { + // If this is a FV Constraint the contextualize its returns and + // parameters. + if (FVConstraint *FV = dyn_cast_or_null(CV)) { + contextualizeCVar(CE, {FV->getReturnVar()}); + for (unsigned i = 0; i < FV->numParams(); i++) { + contextualizeCVar(CE, {FV->getParamVar(i)}); + } + } + + if (PVConstraint *PV = dyn_cast_or_null(CV)) { + if (PV->hasBoundsKey()) { + // First duplicate the bounds key. + BoundsKey CK = PV->getBoundsKey(); + // Either this is a regular variable and used in a bounds declaration + // or a pointer that has bounds declaration? Then we need to + // contextualize it. + // If this is just a regular pointer or variable without declared + // bounds. We ignore it. + if((PV->getCvars().empty() && !ABounds::isKeyUsedInBounds(CK)) || + !PV->hasBoundsStr()) + continue; + + ProgramVar *CKVar = getProgramVar(CK); + auto &BKeyMap = CSBoundsKey[CE]; + if (BKeyMap.find(CK) == BKeyMap.end()) { + BoundsKey NK = ++BCount; + insertProgramVar(NK, CKVar->makeCopy(NK)); + BKeyMap[CK] = NK; + // Next duplicate the Bounds information. + BoundsPriority TP = Invalid; + ABounds *CKBounds = getBounds(CK, Invalid, &TP); + if (CKBounds != nullptr) { + BoundsKey NBK = CKBounds->getBKey(); + ProgramVar *NBKVar = getProgramVar(CK); + if (BKeyMap.find(NBK) == BKeyMap.end()) { + BoundsKey TmpBK = ++BCount; + BKeyMap[NBK] = TmpBK; + insertProgramVar(TmpBK, NBKVar->makeCopy(TmpBK)); + } + CKBounds = CKBounds->makeCopy(BKeyMap[NBK]); + replaceBounds(NK, TP, CKBounds); + } + } + } + } + } + return true; +} + +void AVarBoundsInfo::resetContextSensitiveBoundsKey() { + CSBoundsKey.clear(); +} + +BoundsKey AVarBoundsInfo::getContextSensitiveBoundsKey(CallExpr *CE, + BoundsKey BK) { + if (CSBoundsKey.find(CE) != CSBoundsKey.end()) { + auto &TmpMap = CSBoundsKey[CE]; + if (TmpMap.find(BK) != TmpMap.end()) { + return TmpMap[BK]; + } + } + return BK; +} + +void AVarBoundsInfo::computerArrPointers(ProgramInfo *PI, + std::set &ArrPointers) { auto &CS = PI->getConstraints(); - // First get all the pointer vars which are ARRs - std::set ArrPointers; for (auto Bkey : PointerBoundsKey) { - if (DeclVarMap.right().find(Bkey) != DeclVarMap.right().end()) { - auto &PSL = DeclVarMap.right().at(Bkey); + // Regular variables. + auto &BkeyToPSL = DeclVarMap.right(); + if (BkeyToPSL.find(Bkey) != BkeyToPSL.end()) { + auto &PSL = BkeyToPSL.at(Bkey); if (hasArray(PI->getVarMap()[PSL], CS)) { ArrPointers.insert(Bkey); } @@ -666,8 +959,11 @@ bool AVarBoundsInfo::performFlowAnalysis(ProgramInfo *PI) { } continue; } - if (ParamDeclVarMap.right().find(Bkey) != ParamDeclVarMap.right().end()) { - auto &ParmTup = ParamDeclVarMap.right().at(Bkey); + + // Function parameters + auto &ParmBkeyToPSL = ParamDeclVarMap.right(); + if (ParmBkeyToPSL.find(Bkey) != ParmBkeyToPSL.end()) { + auto &ParmTup = ParmBkeyToPSL.at(Bkey); std::string FuncName = std::get<0>(ParmTup); std::string FileName = std::get<1>(ParmTup); bool IsStatic = std::get<2>(ParmTup); @@ -689,15 +985,57 @@ bool AVarBoundsInfo::performFlowAnalysis(ProgramInfo *PI) { continue; } + // Function returns. + auto &FuncKeyToPSL = FuncDeclVarMap.right(); + if (FuncKeyToPSL.find(Bkey) != FuncKeyToPSL.end()) { + auto &FuncRet = FuncKeyToPSL.at(Bkey); + std::string FuncName = std::get<0>(FuncRet); + std::string FileName = std::get<1>(FuncRet); + bool IsStatic = std::get<2>(FuncRet); + const FVConstraint *FV = nullptr; + std::set Tmp; + Tmp.clear(); + if (IsStatic || !PI->getExtFuncDefnConstraint(FuncName)) { + Tmp.insert(PI->getStaticFuncConstraint(FuncName, FileName)); + FV = getOnly(Tmp); + } else { + Tmp.insert(PI->getExtFuncDefnConstraint(FuncName)); + FV = getOnly(Tmp); + } + + if (hasArray({FV->getReturnVar()}, CS)) { + ArrPointers.insert(Bkey); + } + // Does this array belongs to a valid program variable? + if (isInSrcArray({FV->getReturnVar()}, CS)) { + InProgramArrPtrBoundsKeys.insert(Bkey); + } + continue; + } } +} + +bool AVarBoundsInfo::performFlowAnalysis(ProgramInfo *PI) { + bool RetVal = false; + // First get all the pointer vars which are ARRs + std::set ArrPointers; + computerArrPointers(PI, ArrPointers); // Repopulate array bounds key. ArrPointerBoundsKey.clear(); ArrPointerBoundsKey.insert(ArrPointers.begin(), ArrPointers.end()); + // Keep only highest priority bounds. + // Any thing changed? which means bounds of a variable changed + // Which means we need to recompute the flow based bounds for + // all arrays that have flow based bounds. + if (keepHighestPriorityBounds(ArrPointerBoundsKey)) { + // Remove flow inferred bounds, if exist for all the array pointers. + for (auto TBK : ArrPointerBoundsKey) + removeBounds(TBK, FlowInferred); + } // Next, get the ARR pointers that has bounds. - // These are pointers with bounds. std::set ArrWithBounds; for (auto &T : BInfo) { @@ -727,6 +1065,23 @@ bool AVarBoundsInfo::performFlowAnalysis(ProgramInfo *PI) { return RetVal; } +bool AVarBoundsInfo::keepHighestPriorityBounds(std::set &ArrPtrs) { + bool FoundBounds = false; + bool HasChanged = false; + for (auto BK : ArrPtrs) { + FoundBounds = false; + for (BoundsPriority P : PrioList) { + if (FoundBounds) { + // We already found bounds. So delete these bounds. + HasChanged = removeBounds(BK, P) || HasChanged; + } else if (getBounds(BK, P) != nullptr) { + FoundBounds = true; + } + } + } + return HasChanged; +} + void AVarBoundsInfo::dumpAVarGraph(const std::string &DFPath) { std::error_code Err; llvm::raw_fd_ostream DotFile(DFPath, Err); @@ -734,6 +1089,10 @@ void AVarBoundsInfo::dumpAVarGraph(const std::string &DFPath) { DotFile.close(); } +bool AVarBoundsInfo::isFunctionReturn(BoundsKey BK) { + return (FuncDeclVarMap.right().find(BK) != FuncDeclVarMap.right().end()); +} + void AVarBoundsInfo::print_stats(llvm::raw_ostream &O, const CVarSet &SrcCVarSet, bool JsonFormat) const { @@ -761,4 +1120,28 @@ void AVarBoundsInfo::print_stats(llvm::raw_ostream &O, O << "}"; O << "}"; } +} + +ContextSensitiveBoundsKeyVisitor::ContextSensitiveBoundsKeyVisitor(ASTContext *C, + ProgramInfo &I, + ConstraintResolver *CResolver) +: Context(C), Info(I), CR(CResolver) { + Info.getABoundsInfo().resetContextSensitiveBoundsKey(); +} + +ContextSensitiveBoundsKeyVisitor::~ContextSensitiveBoundsKeyVisitor() { + // Reset the context sensitive bounds. + // This is to ensure that we store pointers to the AST objects + // when we are with in the corresponding compilation unit. + Info.getABoundsInfo().resetContextSensitiveBoundsKey(); +} + +bool ContextSensitiveBoundsKeyVisitor::VisitCallExpr(CallExpr *CE) { + if (FunctionDecl *FD = dyn_cast_or_null(CE->getCalleeDecl())) { + // Contextualize the function at this call-site. + for (auto *CFV : Info.getVariable(FD, Context)) { + Info.getABoundsInfo().contextualizeCVar(CE, {CFV}); + } + } + return true; } \ No newline at end of file diff --git a/clang/lib/CConv/AVarGraph.cpp b/clang/lib/CConv/AVarGraph.cpp index aba6bc4831d1..3fa74c67576d 100644 --- a/clang/lib/CConv/AVarGraph.cpp +++ b/clang/lib/CConv/AVarGraph.cpp @@ -51,7 +51,6 @@ std::string llvm::DOTGraphTraits::getNodeAttributes } } } - return "color=\"" + ClrStr + "\", " + "shape=\"" + ShapeStr + "\""; } @@ -61,7 +60,10 @@ std::string llvm::DOTGraphTraits:: const AVarGraph &G) { AVarBoundsInfo *ABInfo = G.ABInfo; BoundsKey BK = Node->getData(); - std::string LblStr = ABInfo->getProgramVar(BK)->verboseStr(); + ProgramVar *Tmp = ABInfo->getProgramVar(BK); + std::string LblStr = "Temp"; + if (Tmp != nullptr) + LblStr = Tmp->verboseStr(); bool IsArrPtr = ABInfo->ArrPointerBoundsKey.find(BK) != ABInfo->ArrPointerBoundsKey.end(); if (IsArrPtr) diff --git a/clang/lib/CConv/ArrayBoundsInferenceConsumer.cpp b/clang/lib/CConv/ArrayBoundsInferenceConsumer.cpp index a4bc233eb7e3..204de0a4e311 100644 --- a/clang/lib/CConv/ArrayBoundsInferenceConsumer.cpp +++ b/clang/lib/CConv/ArrayBoundsInferenceConsumer.cpp @@ -290,7 +290,7 @@ static void handleAllocatorCall(QualType LHSType, BoundsKey LK, Expr *E, // Either both should be in same scope or the RHS should be constant. if (*(PrgLVar->getScope()) == *(PrgRVar->getScope()) || PrgRVar->IsNumConstant()) { - if (!AVarBInfo.mergeBounds(LK, LBounds)) { + if (!AVarBInfo.mergeBounds(LK, Allocator, LBounds)) { delete (LBounds); } else { ABStats.AllocatorMatch.insert(LK); @@ -310,7 +310,7 @@ static void handleAllocatorCall(QualType LHSType, BoundsKey LK, Expr *E, // tmp <- bounds(count) // p->arr <- tmp BoundsKey TmpKey = AVarBInfo.getRandomBKey(); - AVarBInfo.replaceBounds(TmpKey, LBounds); + AVarBInfo.replaceBounds(TmpKey, Declared, LBounds); AVarBInfo.addAssignment(LK, TmpKey); } else { assert (LBounds != nullptr && "LBounds cannot be nullptr here."); @@ -394,11 +394,11 @@ bool GlobalABVisitor::VisitRecordDecl(RecordDecl *RD) { // variable name heuristic lets use it. if (hasLengthKeyword(LenField.first)) { ABStats.NamePrefixMatch.insert(PtrField.second); - ABInfo.replaceBounds(PtrField.second, FldBounds); + ABInfo.replaceBounds(PtrField.second, Heuristics, FldBounds); break; } ABStats.VariableNameMatch.insert(PtrField.second); - ABInfo.replaceBounds(PtrField.second, FldBounds); + ABInfo.replaceBounds(PtrField.second, Heuristics, FldBounds); } } // If the name-correspondence heuristics failed. @@ -467,7 +467,7 @@ bool GlobalABVisitor::VisitFunctionDecl(FunctionDecl *FD) { BoundsKey PBKey = ArrParamPair.second.second; if (LengthParams.find(PIdx +1) != LengthParams.end()) { ABounds *PBounds = new CountBound(LengthParams[PIdx+1].second); - ABInfo.replaceBounds(PBKey, PBounds); + ABInfo.replaceBounds(PBKey, Heuristics, PBounds); ABStats.NeighbourParamMatch.insert(PBKey); continue; } @@ -478,7 +478,7 @@ bool GlobalABVisitor::VisitFunctionDecl(FunctionDecl *FD) { LenParamPair.second.first)) { FoundLen = true; ABounds *PBounds = new CountBound(LenParamPair.second.second); - ABInfo.replaceBounds(PBKey, PBounds); + ABInfo.replaceBounds(PBKey, Heuristics, PBounds); ABStats.NamePrefixMatch.insert(PBKey); break; } @@ -487,7 +487,7 @@ bool GlobalABVisitor::VisitFunctionDecl(FunctionDecl *FD) { LenParamPair.second.first)) { FoundLen = true; ABounds *PBounds = new CountBound(LenParamPair.second.second); - ABInfo.replaceBounds(PBKey, PBounds); + ABInfo.replaceBounds(PBKey, Heuristics, PBounds); ABStats.NamePrefixMatch.insert(PBKey); continue; } @@ -499,7 +499,7 @@ bool GlobalABVisitor::VisitFunctionDecl(FunctionDecl *FD) { if (fieldNameMatch(currLenParamPair.second.first)) { FoundLen = true; ABounds *PBounds = new CountBound(currLenParamPair.second.second); - ABInfo.replaceBounds(PBKey, PBounds); + ABInfo.replaceBounds(PBKey, Heuristics, PBounds); ABStats.VariableNameMatch.insert(PBKey); } } @@ -519,7 +519,7 @@ bool GlobalABVisitor::VisitFunctionDecl(FunctionDecl *FD) { if (LengthParams.find(PIdx +1) != LengthParams.end()) { if (fieldNameMatch(LengthParams[PIdx +1].first)) { ABounds *PBounds = new CountBound(LengthParams[PIdx +1].second); - ABInfo.replaceBounds(PBKey, PBounds); + ABInfo.replaceBounds(PBKey, Heuristics, PBounds); ABStats.VariableNameMatch.insert(PBKey); continue; } @@ -616,7 +616,7 @@ bool LocalVarABVisitor::VisitDeclStmt(DeclStmt *S) { if (SL != nullptr) { ABounds *ByBounds = new ByteBound(ABoundsInfo.getConstKey(SL->getByteLength())); - if (!ABoundsInfo.mergeBounds(DeclKey, ByBounds)) { + if (!ABoundsInfo.mergeBounds(DeclKey, Allocator, ByBounds)) { delete (ByBounds); } else { ABoundsInfo.getBStats().AllocatorMatch.insert(DeclKey); @@ -666,7 +666,7 @@ void AddMainFuncHeuristic(ASTContext *C, ProgramInfo &I, FunctionDecl *FD) { tryGetBoundsKeyVar(Argv, ArgvKey, I, C) && tryGetBoundsKeyVar(FD->getParamDecl(0), ArgcKey, I, C)) { ABounds *ArgcBounds = new CountBound(ArgcKey); - ABInfo.replaceBounds(ArgvKey, ArgcBounds); + ABInfo.replaceBounds(ArgvKey, Declared, ArgcBounds); } } } diff --git a/clang/lib/CConv/ConstraintBuilder.cpp b/clang/lib/CConv/ConstraintBuilder.cpp index 1094a396747c..76db275981c3 100644 --- a/clang/lib/CConv/ConstraintBuilder.cpp +++ b/clang/lib/CConv/ConstraintBuilder.cpp @@ -135,7 +135,7 @@ class FunctionVisitor : public RecursiveASTVisitor { switch(O->getOpcode()) { case BO_AddAssign: case BO_SubAssign: - arithBinop(O); + arithBinop(O, true); break; // rest shouldn't happen on pointers, so we ignore default: @@ -237,18 +237,14 @@ class FunctionVisitor : public RecursiveASTVisitor { ConstraintVariable *ParameterDC = TargetFV->getParamVar(i); constrainConsVarGeq(ParameterDC, ArgumentConstraints, CS, &PL, Wild_to_Safe, false, &Info); - if (AllTypes && TFD != nullptr && - !CB.isValidCons(ParameterDC) && - !CB.containsValidCons(ArgumentConstraints)) { + + if (AllTypes && TFD != nullptr) { auto *PVD = TFD->getParamDecl(i); auto &ABI = Info.getABoundsInfo(); - BoundsKey PVKey, AGKey; - if ((CB.resolveBoundsKey(ParameterDC, PVKey) || - ABI.tryGetVariable(PVD, PVKey)) && - (CB.resolveBoundsKey(ArgumentConstraints, AGKey) || - ABI.tryGetVariable(A, *Context, AGKey))) { - ABI.addAssignment(PVKey, AGKey); - } + // Here, we need to handle context-sensitive assignment. + ABI.handleContextSensitiveAssignment(E, PVD, ParameterDC, A, + ArgumentConstraints, + Context, &CB); } } else { // The argument passed to a function ith varargs; make it wild @@ -383,20 +379,24 @@ class FunctionVisitor : public RecursiveASTVisitor { } } - void arithBinop(BinaryOperator *O) { - constraintPointerArithmetic(O->getLHS()); - constraintPointerArithmetic(O->getRHS()); + // Here the flag, ModifyingExpr indicates if the arithmetic operation + // is modifying any variable. + void arithBinop(BinaryOperator *O, bool ModifyingExpr = false) { + constraintPointerArithmetic(O->getLHS(), ModifyingExpr); + constraintPointerArithmetic(O->getRHS(), ModifyingExpr); } // Pointer arithmetic constrains the expression to be at least ARR, // unless it is on a function pointer. In this case the function pointer // is WILD. - void constraintPointerArithmetic(Expr *E) { + void constraintPointerArithmetic(Expr *E, bool ModifyingExpr = true) { if (E->getType()->isFunctionPointerType()) { CVarSet Var = CB.getExprConstraintVars(E); std::string Rsn = "Pointer arithmetic performed on a function pointer."; CB.constraintAllCVarsToWild(Var, Rsn, E); } else { + if (ModifyingExpr) + Info.getABoundsInfo().recordArithmeticOperation(E, &CB); constraintInBodyVariable(E, Info.getConstraints().getArr()); } } @@ -553,15 +553,19 @@ void ConstraintBuilderConsumer::HandleTranslationUnit(ASTContext &C) { VariableAdderVisitor VAV = VariableAdderVisitor(&C, Info); TypeVarVisitor TV = TypeVarVisitor(&C, Info); + ConstraintResolver CSResolver(Info, &C); + ContextSensitiveBoundsKeyVisitor CSBV = + ContextSensitiveBoundsKeyVisitor(&C, Info, &CSResolver); ConstraintGenVisitor GV = ConstraintGenVisitor(&C, Info, TV); TranslationUnitDecl *TUD = C.getTranslationUnitDecl(); // Generate constraints. for (const auto &D : TUD->decls()) { - // The order of these traversals cannot be changed because both the type + // The order of these traversals CANNOT be changed because both the type // variable and constraint gen visitor require that variables have been // added to ProgramInfo, and the constraint gen visitor requires the type // variable information gathered in the type variable traversal. VAV.TraverseDecl(D); + CSBV.TraverseDecl(D); TV.TraverseDecl(D); GV.TraverseDecl(D); } diff --git a/clang/lib/CConv/ConstraintResolver.cpp b/clang/lib/CConv/ConstraintResolver.cpp index 4e82e8b7b13e..8131969e182e 100644 --- a/clang/lib/CConv/ConstraintResolver.cpp +++ b/clang/lib/CConv/ConstraintResolver.cpp @@ -510,10 +510,22 @@ CVarSet NewCV = new PVConstraint(CE->getType(), nullptr, PCV->getName(), Info, *Context, nullptr, PCV->getIsGeneric()); + if (PCV->hasBoundsKey()) + NewCV->setBoundsKey(PCV->getBoundsKey()); + } else { NewCV = CV->getCopy(CS); } - + + // Make the bounds key context sensitive. + if (NewCV->hasBoundsKey()) { + auto &ABInfo = Info.getABoundsInfo(); + auto CSensBKey = + ABInfo.getContextSensitiveBoundsKey(CE, + NewCV->getBoundsKey()); + NewCV->setBoundsKey(CSensBKey); + } + // Important: Do Safe_to_Wild from returnvar in this copy, which then // might be assigned otherwise (Same_to_Same) to LHS constrainConsVarGeq(NewCV, CV, CS, nullptr, Safe_to_Wild, false, @@ -660,18 +672,15 @@ void ConstraintResolver::constrainLocalAssign(Stmt *TSt, Expr *LHS, Expr *RHS, CVarSet R = getExprConstraintVars(RHS); constrainConsVarGeq(L, R, Info.getConstraints(), &PL, CAction, false, &Info); + // Handle pointer arithmetic. + auto &ABI = Info.getABoundsInfo(); + ABI.handlePointerAssignment(TSt, LHS, RHS, Context,this); + // Only if all types are enabled and these are not pointers, then track // the assignment. if (AllTypes && !containsValidCons(L) && !containsValidCons(R)) { - BoundsKey LKey, RKey; - auto &ABI = Info.getABoundsInfo(); - if ((resolveBoundsKey(L, LKey) || - ABI.tryGetVariable(LHS, *Context, LKey)) && - (resolveBoundsKey(R, RKey) || - ABI.tryGetVariable(RHS, *Context, RKey))) { - ABI.addAssignment(LKey, RKey); - } + ABI.handleAssignment(LHS, L, RHS, R, Context, this); } } @@ -689,15 +698,10 @@ void ConstraintResolver::constrainLocalAssign(Stmt *TSt, DeclaratorDecl *D, constrainConsVarGeq(V, RHSCons, Info.getConstraints(), PLPtr, CAction, false, &Info); - if (AllTypes && !containsValidCons(V) && !containsValidCons(RHSCons)) { - BoundsKey LKey, RKey; + if (AllTypes && !containsValidCons(V) && + !containsValidCons(RHSCons)) { auto &ABI = Info.getABoundsInfo(); - if ((resolveBoundsKey(V, LKey) || - ABI.tryGetVariable(D, LKey)) && - (resolveBoundsKey(RHSCons, RKey) || - ABI.tryGetVariable(RHS, *Context, RKey))) { - ABI.addAssignment(LKey, RKey); - } + ABI.handleAssignment(D, V, RHS, RHSCons, Context, this); } } @@ -739,7 +743,7 @@ PVConstraint *ConstraintResolver::getRewritablePVConstraint(Expr *E) { return P; } -bool ConstraintResolver::containsValidCons(CVarSet &CVs) { +bool ConstraintResolver::containsValidCons(const CVarSet &CVs) { for (auto *ConsVar : CVs) if (isValidCons(ConsVar)) return true; diff --git a/clang/lib/CConv/DeclRewriter.cpp b/clang/lib/CConv/DeclRewriter.cpp index 92fcec1df147..61ca8222ac9a 100644 --- a/clang/lib/CConv/DeclRewriter.cpp +++ b/clang/lib/CConv/DeclRewriter.cpp @@ -530,6 +530,7 @@ bool FunctionDeclBuilder::VisitFunctionDecl(FunctionDecl *FD) { std::string ReturnVar = ""; std::string ItypeStr = ""; + bool GeneratedRetIType = false; // Does the same job as DidAnyParams, but with respect to the return value. If // the return does not change, there is no need to rewrite it. @@ -550,6 +551,7 @@ bool FunctionDeclBuilder::VisitFunctionDecl(FunctionDecl *FD) { Defn->mkString(Info.getConstraints().getVariables(), false, true); ReturnVar = Defn->getRewritableOriginalTy(); ItypeStr = " : itype(" + Itype + ")"; + GeneratedRetIType = true; // A small hack here. The inserted itype comes after param declarations, // so we have to rewrite the parameters if we want to insert an itype. @@ -595,6 +597,10 @@ bool FunctionDeclBuilder::VisitFunctionDecl(FunctionDecl *FD) { if (!ItypeStr.empty()) NewSig = NewSig + ItypeStr; + if (ItypeStr.empty() || GeneratedRetIType) { + NewSig = NewSig + ABRewriter.getBoundsString(Defn, FD, GeneratedRetIType); + } + // Add new declarations to RewriteThese if it has changed if (DidAnyReturn || DidAnyParams) { for (auto *const RD : Definition->redecls()) diff --git a/clang/lib/CConv/ProgramVar.cpp b/clang/lib/CConv/ProgramVar.cpp index f476f2ef0b67..8a23584cc240 100644 --- a/clang/lib/CConv/ProgramVar.cpp +++ b/clang/lib/CConv/ProgramVar.cpp @@ -63,6 +63,12 @@ std::string ProgramVar::mkString(bool GetKey) { return Ret; } +ProgramVar *ProgramVar::makeCopy(BoundsKey NK) { + ProgramVar *NewPVar = new ProgramVar(NK, this->VarName, this->VScope, + this->IsConstant); + return NewPVar; +} + std::string ProgramVar::verboseStr() { std::string Ret = mkString(true) + "(" + VScope->getStr() + ")"; return Ret; diff --git a/clang/lib/CConv/RewriteUtils.cpp b/clang/lib/CConv/RewriteUtils.cpp index d41130fb3a7e..f334eb9d7585 100644 --- a/clang/lib/CConv/RewriteUtils.cpp +++ b/clang/lib/CConv/RewriteUtils.cpp @@ -347,7 +347,8 @@ std::string ArrayBoundsRewriter::getBoundsString(PVConstraint *PV, if (ValidBKey) { ABounds *ArrB = ABInfo.getBounds(DK); - if (ArrB != nullptr) { + // Only we we have bounds and no pointer arithmetic on the variable. + if (ArrB != nullptr && !ABInfo.hasPointerArithmetic(DK)) { BString = ArrB->mkString(&ABInfo); if (!BString.empty()) BString = Pfix + BString; diff --git a/clang/test/CheckedCRewriter/arrboth.c b/clang/test/CheckedCRewriter/arrboth.c index f42aaf1aa60a..478a76c7e388 100644 --- a/clang/test/CheckedCRewriter/arrboth.c +++ b/clang/test/CheckedCRewriter/arrboth.c @@ -108,11 +108,11 @@ x = (int *) 5; //CHECK: x = (int *) 5; int *z = calloc(5, sizeof(int)); //CHECK_NOALL: int *z = calloc(5, sizeof(int)); - //CHECK_ALL: _Array_ptr z : count(5) = calloc(5, sizeof(int)); + //CHECK_ALL: _Array_ptr z = calloc(5, sizeof(int)); int i, fac; int *p; //CHECK_NOALL: int *p; - //CHECK_ALL: _Array_ptr p : count(5) = ((void *)0); + //CHECK_ALL: _Array_ptr p = ((void *)0); for(i = 0, p = z, fac = 1; i < 5; ++i, p++, fac *= i) { *p = fac; } //CHECK_NOALL: { *p = fac; } diff --git a/clang/test/CheckedCRewriter/arrbothmulti2.c b/clang/test/CheckedCRewriter/arrbothmulti2.c index 47d1921533b9..4a3e7d7cae31 100644 --- a/clang/test/CheckedCRewriter/arrbothmulti2.c +++ b/clang/test/CheckedCRewriter/arrbothmulti2.c @@ -116,11 +116,11 @@ x = (int *) 5; //CHECK: x = (int *) 5; int *z = calloc(5, sizeof(int)); //CHECK_NOALL: int *z = calloc(5, sizeof(int)); - //CHECK_ALL: _Array_ptr z : count(5) = calloc(5, sizeof(int)); + //CHECK_ALL: _Array_ptr z = calloc(5, sizeof(int)); int i, fac; int *p; //CHECK_NOALL: int *p; - //CHECK_ALL: _Array_ptr p : count(5) = ((void *)0); + //CHECK_ALL: _Array_ptr p = ((void *)0); for(i = 0, p = z, fac = 1; i < 5; ++i, p++, fac *= i) { *p = fac; } //CHECK_NOALL: { *p = fac; } diff --git a/clang/test/CheckedCRewriter/arrboundsbasic.c b/clang/test/CheckedCRewriter/arrboundsbasic.c index 94a14bf94352..f73fcd7908f4 100644 --- a/clang/test/CheckedCRewriter/arrboundsbasic.c +++ b/clang/test/CheckedCRewriter/arrboundsbasic.c @@ -26,8 +26,8 @@ int foo(int *arr, unsigned len) { struct bar a; char *arr1 = malloc(n*sizeof(char)); char *arr2 = calloc(n, sizeof(char)); - arr1++; - arr2++; + arr1[0] = 0; + arr2[0] = 0; for (i=0; i x : byte_count(c), int c) { -//CHECK: _Array_ptr q = malloc(sizeof(int)*c); +//CHECK: _Array_ptr q : count(c) = malloc(sizeof(int)*c); diff --git a/clang/test/CheckedCRewriter/arrcallee.c b/clang/test/CheckedCRewriter/arrcallee.c index dc195e944ce2..e29e2834c16a 100644 --- a/clang/test/CheckedCRewriter/arrcallee.c +++ b/clang/test/CheckedCRewriter/arrcallee.c @@ -108,11 +108,11 @@ x = (int *) 5; //CHECK: x = (int *) 5; int *z = calloc(5, sizeof(int)); //CHECK_NOALL: int *z = calloc(5, sizeof(int)); - //CHECK_ALL: _Array_ptr z : count(5) = calloc(5, sizeof(int)); + //CHECK_ALL: _Array_ptr z = calloc(5, sizeof(int)); int i, fac; int *p; //CHECK_NOALL: int *p; - //CHECK_ALL: _Array_ptr p : count(5) = ((void *)0); + //CHECK_ALL: _Array_ptr p = ((void *)0); for(i = 0, p = z, fac = 1; i < 5; ++i, p++, fac *= i) { *p = fac; } //CHECK_NOALL: { *p = fac; } diff --git a/clang/test/CheckedCRewriter/arrcalleemulti2.c b/clang/test/CheckedCRewriter/arrcalleemulti2.c index fc5f6c2f6d01..3f862136bd80 100644 --- a/clang/test/CheckedCRewriter/arrcalleemulti2.c +++ b/clang/test/CheckedCRewriter/arrcalleemulti2.c @@ -116,11 +116,11 @@ x = (int *) 5; //CHECK: x = (int *) 5; int *z = calloc(5, sizeof(int)); //CHECK_NOALL: int *z = calloc(5, sizeof(int)); - //CHECK_ALL: _Array_ptr z : count(5) = calloc(5, sizeof(int)); + //CHECK_ALL: _Array_ptr z = calloc(5, sizeof(int)); int i, fac; int *p; //CHECK_NOALL: int *p; - //CHECK_ALL: _Array_ptr p : count(5) = ((void *)0); + //CHECK_ALL: _Array_ptr p = ((void *)0); for(i = 0, p = z, fac = 1; i < 5; ++i, p++, fac *= i) { *p = fac; } //CHECK_NOALL: { *p = fac; } diff --git a/clang/test/CheckedCRewriter/arrcaller.c b/clang/test/CheckedCRewriter/arrcaller.c index 4bad3cbdf6ae..3033f77db473 100644 --- a/clang/test/CheckedCRewriter/arrcaller.c +++ b/clang/test/CheckedCRewriter/arrcaller.c @@ -103,7 +103,7 @@ int *mul2(int *x) { int * sus(int * x, int * y) { //CHECK_NOALL: int * sus(int * x, _Ptr y) { - //CHECK_ALL: _Array_ptr sus(int * x, _Ptr y) { + //CHECK_ALL: _Array_ptr sus(int * x, _Ptr y) : count(5) { x = (int *) 5; //CHECK: x = (int *) 5; int *z = calloc(5, sizeof(int)); @@ -112,7 +112,7 @@ x = (int *) 5; int i, fac; int *p; //CHECK_NOALL: int *p; - //CHECK_ALL: _Array_ptr p : count(5) = ((void *)0); + //CHECK_ALL: _Array_ptr p = ((void *)0); for(i = 0, p = z, fac = 1; i < 5; ++i, p++, fac *= i) { *p = fac; } //CHECK_NOALL: { *p = fac; } @@ -121,14 +121,14 @@ return z; } int * foo() { //CHECK_NOALL: int * foo(void) { - //CHECK_ALL: _Array_ptr foo(void) { + //CHECK_ALL: _Array_ptr foo(void) : count(5) { int * x = malloc(sizeof(int)); //CHECK: int * x = malloc(sizeof(int)); int * y = malloc(sizeof(int)); //CHECK: _Ptr y = malloc(sizeof(int)); int * z = sus(x, y); //CHECK_NOALL: int * z = sus(x, y); - //CHECK_ALL: _Array_ptr z = sus(x, y); + //CHECK_ALL: _Array_ptr z : count(5) = sus(x, y); return z; } int * bar() { diff --git a/clang/test/CheckedCRewriter/arrcallermulti1.c b/clang/test/CheckedCRewriter/arrcallermulti1.c index b11ce140c8e7..29fd461176f5 100644 --- a/clang/test/CheckedCRewriter/arrcallermulti1.c +++ b/clang/test/CheckedCRewriter/arrcallermulti1.c @@ -111,18 +111,18 @@ int *mul2(int *x) { int * sus(int *, int *); //CHECK_NOALL: int * sus(int *, _Ptr y); - //CHECK_ALL: _Array_ptr sus(int *, _Ptr y); + //CHECK_ALL: _Array_ptr sus(int *, _Ptr y) : count(5); int * foo() { //CHECK_NOALL: int * foo(void) { - //CHECK_ALL: _Array_ptr foo(void) { + //CHECK_ALL: _Array_ptr foo(void) : count(5) { int * x = malloc(sizeof(int)); //CHECK: int * x = malloc(sizeof(int)); int * y = malloc(sizeof(int)); //CHECK: _Ptr y = malloc(sizeof(int)); int * z = sus(x, y); //CHECK_NOALL: int * z = sus(x, y); - //CHECK_ALL: _Array_ptr z = sus(x, y); + //CHECK_ALL: _Array_ptr z : count(5) = sus(x, y); return z; } int * bar() { diff --git a/clang/test/CheckedCRewriter/arrcallermulti2.c b/clang/test/CheckedCRewriter/arrcallermulti2.c index 064978bd17b5..501fd6e875d0 100644 --- a/clang/test/CheckedCRewriter/arrcallermulti2.c +++ b/clang/test/CheckedCRewriter/arrcallermulti2.c @@ -111,7 +111,7 @@ int *mul2(int *x) { int * sus(int * x, int * y) { //CHECK_NOALL: int * sus(int * x, _Ptr y) { - //CHECK_ALL: _Array_ptr sus(int * x, _Ptr y) { + //CHECK_ALL: _Array_ptr sus(int * x, _Ptr y) : count(5) { x = (int *) 5; //CHECK: x = (int *) 5; int *z = calloc(5, sizeof(int)); @@ -120,7 +120,7 @@ x = (int *) 5; int i, fac; int *p; //CHECK_NOALL: int *p; - //CHECK_ALL: _Array_ptr p : count(5) = ((void *)0); + //CHECK_ALL: _Array_ptr p = ((void *)0); for(i = 0, p = z, fac = 1; i < 5; ++i, p++, fac *= i) { *p = fac; } //CHECK_NOALL: { *p = fac; } diff --git a/clang/test/CheckedCRewriter/arrofstructboth.c b/clang/test/CheckedCRewriter/arrofstructboth.c index 798c14bf0d8e..8959b4c4201a 100644 --- a/clang/test/CheckedCRewriter/arrofstructboth.c +++ b/clang/test/CheckedCRewriter/arrofstructboth.c @@ -109,7 +109,7 @@ x = (struct general *) 5; //CHECK: x = (struct general *) 5; struct general **z = calloc(5, sizeof(struct general *)); //CHECK_NOALL: struct general **z = calloc(5, sizeof(struct general *)); - //CHECK_ALL: _Array_ptr<_Ptr> z : count(5) = calloc<_Ptr>(5, sizeof(struct general *)); + //CHECK_ALL: _Array_ptr<_Ptr> z = calloc<_Ptr>(5, sizeof(struct general *)); struct general *curr = y; //CHECK_NOALL: struct general *curr = y; //CHECK_ALL: _Ptr curr = y; diff --git a/clang/test/CheckedCRewriter/arrofstructbothmulti2.c b/clang/test/CheckedCRewriter/arrofstructbothmulti2.c index dd293c829851..4cd27c6dacd2 100644 --- a/clang/test/CheckedCRewriter/arrofstructbothmulti2.c +++ b/clang/test/CheckedCRewriter/arrofstructbothmulti2.c @@ -117,7 +117,7 @@ x = (struct general *) 5; //CHECK: x = (struct general *) 5; struct general **z = calloc(5, sizeof(struct general *)); //CHECK_NOALL: struct general **z = calloc(5, sizeof(struct general *)); - //CHECK_ALL: _Array_ptr<_Ptr> z : count(5) = calloc<_Ptr>(5, sizeof(struct general *)); + //CHECK_ALL: _Array_ptr<_Ptr> z = calloc<_Ptr>(5, sizeof(struct general *)); struct general *curr = y; //CHECK_NOALL: struct general *curr = y; //CHECK_ALL: _Ptr curr = y; diff --git a/clang/test/CheckedCRewriter/arrofstructcallee.c b/clang/test/CheckedCRewriter/arrofstructcallee.c index a449af90b092..5e97bbfbf9b6 100644 --- a/clang/test/CheckedCRewriter/arrofstructcallee.c +++ b/clang/test/CheckedCRewriter/arrofstructcallee.c @@ -109,7 +109,7 @@ x = (struct general *) 5; //CHECK: x = (struct general *) 5; struct general **z = calloc(5, sizeof(struct general *)); //CHECK_NOALL: struct general **z = calloc(5, sizeof(struct general *)); - //CHECK_ALL: _Array_ptr<_Ptr> z : count(5) = calloc<_Ptr>(5, sizeof(struct general *)); + //CHECK_ALL: _Array_ptr<_Ptr> z = calloc<_Ptr>(5, sizeof(struct general *)); struct general *curr = y; //CHECK_NOALL: struct general *curr = y; //CHECK_ALL: _Ptr curr = y; diff --git a/clang/test/CheckedCRewriter/arrofstructcalleemulti2.c b/clang/test/CheckedCRewriter/arrofstructcalleemulti2.c index c12bcd438170..7db1a8327060 100644 --- a/clang/test/CheckedCRewriter/arrofstructcalleemulti2.c +++ b/clang/test/CheckedCRewriter/arrofstructcalleemulti2.c @@ -117,7 +117,7 @@ x = (struct general *) 5; //CHECK: x = (struct general *) 5; struct general **z = calloc(5, sizeof(struct general *)); //CHECK_NOALL: struct general **z = calloc(5, sizeof(struct general *)); - //CHECK_ALL: _Array_ptr<_Ptr> z : count(5) = calloc<_Ptr>(5, sizeof(struct general *)); + //CHECK_ALL: _Array_ptr<_Ptr> z = calloc<_Ptr>(5, sizeof(struct general *)); struct general *curr = y; //CHECK_NOALL: struct general *curr = y; //CHECK_ALL: _Ptr curr = y; diff --git a/clang/test/CheckedCRewriter/arrofstructcaller.c b/clang/test/CheckedCRewriter/arrofstructcaller.c index f4d6c3384631..170b3e07c4ad 100644 --- a/clang/test/CheckedCRewriter/arrofstructcaller.c +++ b/clang/test/CheckedCRewriter/arrofstructcaller.c @@ -104,7 +104,7 @@ int *mul2(int *x) { struct general ** sus(struct general * x, struct general * y) { //CHECK_NOALL: struct general ** sus(struct general * x, struct general * y) { - //CHECK_ALL: _Array_ptr<_Ptr> sus(struct general * x, _Ptr y) { + //CHECK_ALL: _Array_ptr<_Ptr> sus(struct general * x, _Ptr y) : count(5) { x = (struct general *) 5; //CHECK: x = (struct general *) 5; struct general **z = calloc(5, sizeof(struct general *)); @@ -125,7 +125,7 @@ return z; } struct general ** foo() { //CHECK_NOALL: struct general ** foo(void) { - //CHECK_ALL: _Array_ptr<_Ptr> foo(void) { + //CHECK_ALL: _Array_ptr<_Ptr> foo(void) : count(5) { struct general * x = malloc(sizeof(struct general)); //CHECK: struct general * x = malloc(sizeof(struct general)); struct general * y = malloc(sizeof(struct general)); @@ -143,7 +143,7 @@ struct general ** foo() { } struct general ** z = sus(x, y); //CHECK_NOALL: struct general ** z = sus(x, y); - //CHECK_ALL: _Array_ptr<_Ptr> z = sus(x, y); + //CHECK_ALL: _Array_ptr<_Ptr> z : count(5) = sus(x, y); return z; } struct general ** bar() { diff --git a/clang/test/CheckedCRewriter/arrofstructcallermulti1.c b/clang/test/CheckedCRewriter/arrofstructcallermulti1.c index e32d1fa2ef4e..e9008c845521 100644 --- a/clang/test/CheckedCRewriter/arrofstructcallermulti1.c +++ b/clang/test/CheckedCRewriter/arrofstructcallermulti1.c @@ -112,11 +112,11 @@ int *mul2(int *x) { struct general ** sus(struct general *, struct general *); //CHECK_NOALL: struct general ** sus(struct general *, struct general *); - //CHECK_ALL: _Array_ptr<_Ptr> sus(struct general *, _Ptr y); + //CHECK_ALL: _Array_ptr<_Ptr> sus(struct general *, _Ptr y) : count(5); struct general ** foo() { //CHECK_NOALL: struct general ** foo(void) { - //CHECK_ALL: _Array_ptr<_Ptr> foo(void) { + //CHECK_ALL: _Array_ptr<_Ptr> foo(void) : count(5) { struct general * x = malloc(sizeof(struct general)); //CHECK: struct general * x = malloc(sizeof(struct general)); struct general * y = malloc(sizeof(struct general)); @@ -134,7 +134,7 @@ struct general ** foo() { } struct general ** z = sus(x, y); //CHECK_NOALL: struct general ** z = sus(x, y); - //CHECK_ALL: _Array_ptr<_Ptr> z = sus(x, y); + //CHECK_ALL: _Array_ptr<_Ptr> z : count(5) = sus(x, y); return z; } struct general ** bar() { diff --git a/clang/test/CheckedCRewriter/arrofstructcallermulti2.c b/clang/test/CheckedCRewriter/arrofstructcallermulti2.c index 768005d88d13..3a9b8c45da39 100644 --- a/clang/test/CheckedCRewriter/arrofstructcallermulti2.c +++ b/clang/test/CheckedCRewriter/arrofstructcallermulti2.c @@ -112,7 +112,7 @@ int *mul2(int *x) { struct general ** sus(struct general * x, struct general * y) { //CHECK_NOALL: struct general ** sus(struct general * x, struct general * y) { - //CHECK_ALL: _Array_ptr<_Ptr> sus(struct general * x, _Ptr y) { + //CHECK_ALL: _Array_ptr<_Ptr> sus(struct general * x, _Ptr y) : count(5) { x = (struct general *) 5; //CHECK: x = (struct general *) 5; struct general **z = calloc(5, sizeof(struct general *)); diff --git a/clang/test/CheckedCRewriter/arrofstructprotoboth.c b/clang/test/CheckedCRewriter/arrofstructprotoboth.c index 9e56e41f2f00..878838342ca0 100644 --- a/clang/test/CheckedCRewriter/arrofstructprotoboth.c +++ b/clang/test/CheckedCRewriter/arrofstructprotoboth.c @@ -163,7 +163,7 @@ x = (struct general *) 5; //CHECK: x = (struct general *) 5; struct general **z = calloc(5, sizeof(struct general *)); //CHECK_NOALL: struct general **z = calloc(5, sizeof(struct general *)); - //CHECK_ALL: _Array_ptr<_Ptr> z : count(5) = calloc<_Ptr>(5, sizeof(struct general *)); + //CHECK_ALL: _Array_ptr<_Ptr> z = calloc<_Ptr>(5, sizeof(struct general *)); struct general *curr = y; //CHECK_NOALL: struct general *curr = y; //CHECK_ALL: _Ptr curr = y; diff --git a/clang/test/CheckedCRewriter/arrofstructprotocallee.c b/clang/test/CheckedCRewriter/arrofstructprotocallee.c index 76a61117518d..3365c6ca2e14 100644 --- a/clang/test/CheckedCRewriter/arrofstructprotocallee.c +++ b/clang/test/CheckedCRewriter/arrofstructprotocallee.c @@ -162,7 +162,7 @@ x = (struct general *) 5; //CHECK: x = (struct general *) 5; struct general **z = calloc(5, sizeof(struct general *)); //CHECK_NOALL: struct general **z = calloc(5, sizeof(struct general *)); - //CHECK_ALL: _Array_ptr<_Ptr> z : count(5) = calloc<_Ptr>(5, sizeof(struct general *)); + //CHECK_ALL: _Array_ptr<_Ptr> z = calloc<_Ptr>(5, sizeof(struct general *)); struct general *curr = y; //CHECK_NOALL: struct general *curr = y; //CHECK_ALL: _Ptr curr = y; diff --git a/clang/test/CheckedCRewriter/arrofstructprotocaller.c b/clang/test/CheckedCRewriter/arrofstructprotocaller.c index c7b35461607f..3df90a8821da 100644 --- a/clang/test/CheckedCRewriter/arrofstructprotocaller.c +++ b/clang/test/CheckedCRewriter/arrofstructprotocaller.c @@ -107,11 +107,11 @@ int *mul2(int *x) { struct general ** sus(struct general *, struct general *); //CHECK_NOALL: struct general ** sus(struct general *, struct general *); - //CHECK_ALL: _Array_ptr<_Ptr> sus(struct general * x, _Ptr y); + //CHECK_ALL: _Array_ptr<_Ptr> sus(struct general * x, _Ptr y) : count(5); struct general ** foo() { //CHECK_NOALL: struct general ** foo(void) { - //CHECK_ALL: _Array_ptr<_Ptr> foo(void) { + //CHECK_ALL: _Array_ptr<_Ptr> foo(void) : count(5) { struct general * x = malloc(sizeof(struct general)); //CHECK: struct general * x = malloc(sizeof(struct general)); struct general * y = malloc(sizeof(struct general)); @@ -129,7 +129,7 @@ struct general ** foo() { } struct general ** z = sus(x, y); //CHECK_NOALL: struct general ** z = sus(x, y); - //CHECK_ALL: _Array_ptr<_Ptr> z = sus(x, y); + //CHECK_ALL: _Array_ptr<_Ptr> z : count(5) = sus(x, y); return z; } struct general ** bar() { @@ -158,7 +158,7 @@ return z; } struct general ** sus(struct general * x, struct general * y) { //CHECK_NOALL: struct general ** sus(struct general * x, struct general * y) { - //CHECK_ALL: _Array_ptr<_Ptr> sus(struct general * x, _Ptr y) { + //CHECK_ALL: _Array_ptr<_Ptr> sus(struct general * x, _Ptr y) : count(5) { x = (struct general *) 5; //CHECK: x = (struct general *) 5; struct general **z = calloc(5, sizeof(struct general *)); diff --git a/clang/test/CheckedCRewriter/arrofstructprotosafe.c b/clang/test/CheckedCRewriter/arrofstructprotosafe.c index e13ae3736136..a69bab47c62f 100644 --- a/clang/test/CheckedCRewriter/arrofstructprotosafe.c +++ b/clang/test/CheckedCRewriter/arrofstructprotosafe.c @@ -106,11 +106,10 @@ int *mul2(int *x) { struct general ** sus(struct general *, struct general *); //CHECK_NOALL: struct general ** sus(struct general *, struct general *); - //CHECK_ALL: _Array_ptr<_Ptr> sus(struct general * x, _Ptr y); - + //CHECK_ALL: _Array_ptr<_Ptr> sus(struct general * x, _Ptr y) : count(5); struct general ** foo() { //CHECK_NOALL: struct general ** foo(void) { - //CHECK_ALL: _Array_ptr<_Ptr> foo(void) { + //CHECK_ALL: _Array_ptr<_Ptr> foo(void) : count(5) { struct general * x = malloc(sizeof(struct general)); //CHECK: struct general * x = malloc(sizeof(struct general)); struct general * y = malloc(sizeof(struct general)); @@ -128,12 +127,12 @@ struct general ** foo() { } struct general ** z = sus(x, y); //CHECK_NOALL: struct general ** z = sus(x, y); - //CHECK_ALL: _Array_ptr<_Ptr> z = sus(x, y); + //CHECK_ALL: _Array_ptr<_Ptr> z : count(5) = sus(x, y); return z; } struct general ** bar() { //CHECK_NOALL: struct general ** bar(void) { - //CHECK_ALL: _Array_ptr<_Ptr> bar(void) { + //CHECK_ALL: _Array_ptr<_Ptr> bar(void) : count(5) { struct general * x = malloc(sizeof(struct general)); //CHECK: struct general * x = malloc(sizeof(struct general)); struct general * y = malloc(sizeof(struct general)); @@ -151,12 +150,12 @@ struct general ** bar() { } struct general ** z = sus(x, y); //CHECK_NOALL: struct general ** z = sus(x, y); - //CHECK_ALL: _Array_ptr<_Ptr> z = sus(x, y); + //CHECK_ALL: _Array_ptr<_Ptr> z : count(5) = sus(x, y); return z; } struct general ** sus(struct general * x, struct general * y) { //CHECK_NOALL: struct general ** sus(struct general * x, struct general * y) { - //CHECK_ALL: _Array_ptr<_Ptr> sus(struct general * x, _Ptr y) { + //CHECK_ALL: _Array_ptr<_Ptr> sus(struct general * x, _Ptr y) : count(5) { x = (struct general *) 5; //CHECK: x = (struct general *) 5; struct general **z = calloc(5, sizeof(struct general *)); diff --git a/clang/test/CheckedCRewriter/arrofstructsafe.c b/clang/test/CheckedCRewriter/arrofstructsafe.c index 64765ecd822a..ddb6239aa3e4 100644 --- a/clang/test/CheckedCRewriter/arrofstructsafe.c +++ b/clang/test/CheckedCRewriter/arrofstructsafe.c @@ -103,7 +103,7 @@ int *mul2(int *x) { struct general ** sus(struct general * x, struct general * y) { //CHECK_NOALL: struct general ** sus(struct general * x, struct general * y) { - //CHECK_ALL: _Array_ptr<_Ptr> sus(struct general * x, _Ptr y) { + //CHECK_ALL: _Array_ptr<_Ptr> sus(struct general * x, _Ptr y) : count(5) { x = (struct general *) 5; //CHECK: x = (struct general *) 5; struct general **z = calloc(5, sizeof(struct general *)); @@ -124,7 +124,7 @@ return z; } struct general ** foo() { //CHECK_NOALL: struct general ** foo(void) { - //CHECK_ALL: _Array_ptr<_Ptr> foo(void) { + //CHECK_ALL: _Array_ptr<_Ptr> foo(void) : count(5) { struct general * x = malloc(sizeof(struct general)); //CHECK: struct general * x = malloc(sizeof(struct general)); struct general * y = malloc(sizeof(struct general)); @@ -142,12 +142,12 @@ struct general ** foo() { } struct general ** z = sus(x, y); //CHECK_NOALL: struct general ** z = sus(x, y); - //CHECK_ALL: _Array_ptr<_Ptr> z = sus(x, y); + //CHECK_ALL: _Array_ptr<_Ptr> z : count(5) = sus(x, y); return z; } struct general ** bar() { //CHECK_NOALL: struct general ** bar(void) { - //CHECK_ALL: _Array_ptr<_Ptr> bar(void) { + //CHECK_ALL: _Array_ptr<_Ptr> bar(void) : count(5) { struct general * x = malloc(sizeof(struct general)); //CHECK: struct general * x = malloc(sizeof(struct general)); struct general * y = malloc(sizeof(struct general)); @@ -165,5 +165,5 @@ struct general ** bar() { } struct general ** z = sus(x, y); //CHECK_NOALL: struct general ** z = sus(x, y); - //CHECK_ALL: _Array_ptr<_Ptr> z = sus(x, y); + //CHECK_ALL: _Array_ptr<_Ptr> z : count(5) = sus(x, y); return z; } diff --git a/clang/test/CheckedCRewriter/arrofstructsafemulti1.c b/clang/test/CheckedCRewriter/arrofstructsafemulti1.c index 05dbe1578120..7d5a030fcaf3 100644 --- a/clang/test/CheckedCRewriter/arrofstructsafemulti1.c +++ b/clang/test/CheckedCRewriter/arrofstructsafemulti1.c @@ -111,11 +111,11 @@ int *mul2(int *x) { struct general ** sus(struct general *, struct general *); //CHECK_NOALL: struct general ** sus(struct general *, struct general *); - //CHECK_ALL: _Array_ptr<_Ptr> sus(struct general *, _Ptr y); + //CHECK_ALL: _Array_ptr<_Ptr> sus(struct general *, _Ptr y) : count(5); struct general ** foo() { //CHECK_NOALL: struct general ** foo(void) { - //CHECK_ALL: _Array_ptr<_Ptr> foo(void) { + //CHECK_ALL: _Array_ptr<_Ptr> foo(void) : count(5) { struct general * x = malloc(sizeof(struct general)); //CHECK: struct general * x = malloc(sizeof(struct general)); struct general * y = malloc(sizeof(struct general)); @@ -133,12 +133,12 @@ struct general ** foo() { } struct general ** z = sus(x, y); //CHECK_NOALL: struct general ** z = sus(x, y); - //CHECK_ALL: _Array_ptr<_Ptr> z = sus(x, y); + //CHECK_ALL: _Array_ptr<_Ptr> z : count(5) = sus(x, y); return z; } struct general ** bar() { //CHECK_NOALL: struct general ** bar(void) { - //CHECK_ALL: _Array_ptr<_Ptr> bar(void) { + //CHECK_ALL: _Array_ptr<_Ptr> bar(void) : count(5) { struct general * x = malloc(sizeof(struct general)); //CHECK: struct general * x = malloc(sizeof(struct general)); struct general * y = malloc(sizeof(struct general)); @@ -156,5 +156,5 @@ struct general ** bar() { } struct general ** z = sus(x, y); //CHECK_NOALL: struct general ** z = sus(x, y); - //CHECK_ALL: _Array_ptr<_Ptr> z = sus(x, y); + //CHECK_ALL: _Array_ptr<_Ptr> z : count(5) = sus(x, y); return z; } diff --git a/clang/test/CheckedCRewriter/arrofstructsafemulti2.c b/clang/test/CheckedCRewriter/arrofstructsafemulti2.c index 4357d9b55261..4bad1fe455de 100644 --- a/clang/test/CheckedCRewriter/arrofstructsafemulti2.c +++ b/clang/test/CheckedCRewriter/arrofstructsafemulti2.c @@ -111,7 +111,7 @@ int *mul2(int *x) { struct general ** sus(struct general * x, struct general * y) { //CHECK_NOALL: struct general ** sus(struct general * x, struct general * y) { - //CHECK_ALL: _Array_ptr<_Ptr> sus(struct general * x, _Ptr y) { + //CHECK_ALL: _Array_ptr<_Ptr> sus(struct general * x, _Ptr y) : count(5) { x = (struct general *) 5; //CHECK: x = (struct general *) 5; struct general **z = calloc(5, sizeof(struct general *)); diff --git a/clang/test/CheckedCRewriter/arrprotoboth.c b/clang/test/CheckedCRewriter/arrprotoboth.c index d3427915e1b1..f0970adde1e5 100644 --- a/clang/test/CheckedCRewriter/arrprotoboth.c +++ b/clang/test/CheckedCRewriter/arrprotoboth.c @@ -140,11 +140,11 @@ x = (int *) 5; //CHECK: x = (int *) 5; int *z = calloc(5, sizeof(int)); //CHECK_NOALL: int *z = calloc(5, sizeof(int)); - //CHECK_ALL: _Array_ptr z : count(5) = calloc(5, sizeof(int)); + //CHECK_ALL: _Array_ptr z = calloc(5, sizeof(int)); int i, fac; int *p; //CHECK_NOALL: int *p; - //CHECK_ALL: _Array_ptr p : count(5) = ((void *)0); + //CHECK_ALL: _Array_ptr p = ((void *)0); for(i = 0, p = z, fac = 1; i < 5; ++i, p++, fac *= i) { *p = fac; } //CHECK_NOALL: { *p = fac; } diff --git a/clang/test/CheckedCRewriter/arrprotocallee.c b/clang/test/CheckedCRewriter/arrprotocallee.c index ead60ff67937..0035dfb1c723 100644 --- a/clang/test/CheckedCRewriter/arrprotocallee.c +++ b/clang/test/CheckedCRewriter/arrprotocallee.c @@ -139,11 +139,11 @@ x = (int *) 5; //CHECK: x = (int *) 5; int *z = calloc(5, sizeof(int)); //CHECK_NOALL: int *z = calloc(5, sizeof(int)); - //CHECK_ALL: _Array_ptr z : count(5) = calloc(5, sizeof(int)); + //CHECK_ALL: _Array_ptr z = calloc(5, sizeof(int)); int i, fac; int *p; //CHECK_NOALL: int *p; - //CHECK_ALL: _Array_ptr p : count(5) = ((void *)0); + //CHECK_ALL: _Array_ptr p = ((void *)0); for(i = 0, p = z, fac = 1; i < 5; ++i, p++, fac *= i) { *p = fac; } //CHECK_NOALL: { *p = fac; } diff --git a/clang/test/CheckedCRewriter/arrprotocaller.c b/clang/test/CheckedCRewriter/arrprotocaller.c index 5a50901a1544..d89c05c24a14 100644 --- a/clang/test/CheckedCRewriter/arrprotocaller.c +++ b/clang/test/CheckedCRewriter/arrprotocaller.c @@ -106,18 +106,18 @@ int *mul2(int *x) { int * sus(int *, int *); //CHECK_NOALL: int * sus(int * x, _Ptr y); - //CHECK_ALL: _Array_ptr sus(int * x, _Ptr y); + //CHECK_ALL: _Array_ptr sus(int * x, _Ptr y) : count(5); int * foo() { //CHECK_NOALL: int * foo(void) { - //CHECK_ALL: _Array_ptr foo(void) { + //CHECK_ALL: _Array_ptr foo(void) : count(5) { int * x = malloc(sizeof(int)); //CHECK: int * x = malloc(sizeof(int)); int * y = malloc(sizeof(int)); //CHECK: _Ptr y = malloc(sizeof(int)); int * z = sus(x, y); //CHECK_NOALL: int * z = sus(x, y); - //CHECK_ALL: _Array_ptr z = sus(x, y); + //CHECK_ALL: _Array_ptr z : count(5) = sus(x, y); return z; } int * bar() { @@ -135,7 +135,7 @@ return z; } int * sus(int * x, int * y) { //CHECK_NOALL: int * sus(int * x, _Ptr y) { - //CHECK_ALL: _Array_ptr sus(int * x, _Ptr y) { + //CHECK_ALL: _Array_ptr sus(int * x, _Ptr y) : count(5) { x = (int *) 5; //CHECK: x = (int *) 5; int *z = calloc(5, sizeof(int)); @@ -144,7 +144,7 @@ x = (int *) 5; int i, fac; int *p; //CHECK_NOALL: int *p; - //CHECK_ALL: _Array_ptr p : count(5) = ((void *)0); + //CHECK_ALL: _Array_ptr p = ((void *)0); for(i = 0, p = z, fac = 1; i < 5; ++i, p++, fac *= i) { *p = fac; } //CHECK_NOALL: { *p = fac; } diff --git a/clang/test/CheckedCRewriter/arrprotosafe.c b/clang/test/CheckedCRewriter/arrprotosafe.c index 01685403ddfe..b835e8a8eac6 100644 --- a/clang/test/CheckedCRewriter/arrprotosafe.c +++ b/clang/test/CheckedCRewriter/arrprotosafe.c @@ -105,35 +105,35 @@ int *mul2(int *x) { int * sus(int *, int *); //CHECK_NOALL: int * sus(int * x, _Ptr y); - //CHECK_ALL: _Array_ptr sus(int * x, _Ptr y); + //CHECK_ALL: _Array_ptr sus(int * x, _Ptr y) : count(5); int * foo() { //CHECK_NOALL: int * foo(void) { - //CHECK_ALL: _Array_ptr foo(void) { + //CHECK_ALL: _Array_ptr foo(void) : count(5) { int * x = malloc(sizeof(int)); //CHECK: int * x = malloc(sizeof(int)); int * y = malloc(sizeof(int)); //CHECK: _Ptr y = malloc(sizeof(int)); int * z = sus(x, y); //CHECK_NOALL: int * z = sus(x, y); - //CHECK_ALL: _Array_ptr z = sus(x, y); + //CHECK_ALL: _Array_ptr z : count(5) = sus(x, y); return z; } int * bar() { //CHECK_NOALL: int * bar(void) { - //CHECK_ALL: _Array_ptr bar(void) { + //CHECK_ALL: _Array_ptr bar(void) : count(5) { int * x = malloc(sizeof(int)); //CHECK: int * x = malloc(sizeof(int)); int * y = malloc(sizeof(int)); //CHECK: _Ptr y = malloc(sizeof(int)); int * z = sus(x, y); //CHECK_NOALL: int * z = sus(x, y); - //CHECK_ALL: _Array_ptr z = sus(x, y); + //CHECK_ALL: _Array_ptr z : count(5) = sus(x, y); return z; } int * sus(int * x, int * y) { //CHECK_NOALL: int * sus(int * x, _Ptr y) { - //CHECK_ALL: _Array_ptr sus(int * x, _Ptr y) { + //CHECK_ALL: _Array_ptr sus(int * x, _Ptr y) : count(5) { x = (int *) 5; //CHECK: x = (int *) 5; int *z = calloc(5, sizeof(int)); @@ -142,7 +142,7 @@ x = (int *) 5; int i, fac; int *p; //CHECK_NOALL: int *p; - //CHECK_ALL: _Array_ptr p : count(5) = ((void *)0); + //CHECK_ALL: _Array_ptr p = ((void *)0); for(i = 0, p = z, fac = 1; i < 5; ++i, p++, fac *= i) { *p = fac; } //CHECK_NOALL: { *p = fac; } diff --git a/clang/test/CheckedCRewriter/arrsafe.c b/clang/test/CheckedCRewriter/arrsafe.c index 214b5e3d3de4..7783656ffbf5 100644 --- a/clang/test/CheckedCRewriter/arrsafe.c +++ b/clang/test/CheckedCRewriter/arrsafe.c @@ -102,7 +102,7 @@ int *mul2(int *x) { int * sus(int * x, int * y) { //CHECK_NOALL: int * sus(int * x, _Ptr y) { - //CHECK_ALL: _Array_ptr sus(int * x, _Ptr y) { + //CHECK_ALL: _Array_ptr sus(int * x, _Ptr y) : count(5) { x = (int *) 5; //CHECK: x = (int *) 5; int *z = calloc(5, sizeof(int)); @@ -111,7 +111,7 @@ x = (int *) 5; int i, fac; int *p; //CHECK_NOALL: int *p; - //CHECK_ALL: _Array_ptr p : count(5) = ((void *)0); + //CHECK_ALL: _Array_ptr p = ((void *)0); for(i = 0, p = z, fac = 1; i < 5; ++i, p++, fac *= i) { *p = fac; } //CHECK_NOALL: { *p = fac; } @@ -120,24 +120,24 @@ return z; } int * foo() { //CHECK_NOALL: int * foo(void) { - //CHECK_ALL: _Array_ptr foo(void) { + //CHECK_ALL: _Array_ptr foo(void) : count(5) { int * x = malloc(sizeof(int)); //CHECK: int * x = malloc(sizeof(int)); int * y = malloc(sizeof(int)); //CHECK: _Ptr y = malloc(sizeof(int)); int * z = sus(x, y); //CHECK_NOALL: int * z = sus(x, y); - //CHECK_ALL: _Array_ptr z = sus(x, y); + //CHECK_ALL: _Array_ptr z : count(5) = sus(x, y); return z; } int * bar() { //CHECK_NOALL: int * bar(void) { - //CHECK_ALL: _Array_ptr bar(void) { + //CHECK_ALL: _Array_ptr bar(void) : count(5) { int * x = malloc(sizeof(int)); //CHECK: int * x = malloc(sizeof(int)); int * y = malloc(sizeof(int)); //CHECK: _Ptr y = malloc(sizeof(int)); int * z = sus(x, y); //CHECK_NOALL: int * z = sus(x, y); - //CHECK_ALL: _Array_ptr z = sus(x, y); + //CHECK_ALL: _Array_ptr z : count(5) = sus(x, y); return z; } diff --git a/clang/test/CheckedCRewriter/arrsafemulti1.c b/clang/test/CheckedCRewriter/arrsafemulti1.c index 0eb228bf9d12..37c322e8e44d 100644 --- a/clang/test/CheckedCRewriter/arrsafemulti1.c +++ b/clang/test/CheckedCRewriter/arrsafemulti1.c @@ -110,28 +110,28 @@ int *mul2(int *x) { int * sus(int *, int *); //CHECK_NOALL: int * sus(int *, _Ptr y); - //CHECK_ALL: _Array_ptr sus(int *, _Ptr y); + //CHECK_ALL: _Array_ptr sus(int *, _Ptr y) : count(5); int * foo() { //CHECK_NOALL: int * foo(void) { - //CHECK_ALL: _Array_ptr foo(void) { + //CHECK_ALL: _Array_ptr foo(void) : count(5) { int * x = malloc(sizeof(int)); //CHECK: int * x = malloc(sizeof(int)); int * y = malloc(sizeof(int)); //CHECK: _Ptr y = malloc(sizeof(int)); int * z = sus(x, y); //CHECK_NOALL: int * z = sus(x, y); - //CHECK_ALL: _Array_ptr z = sus(x, y); + //CHECK_ALL: _Array_ptr z : count(5) = sus(x, y); return z; } int * bar() { //CHECK_NOALL: int * bar(void) { - //CHECK_ALL: _Array_ptr bar(void) { + //CHECK_ALL: _Array_ptr bar(void) : count(5) { int * x = malloc(sizeof(int)); //CHECK: int * x = malloc(sizeof(int)); int * y = malloc(sizeof(int)); //CHECK: _Ptr y = malloc(sizeof(int)); int * z = sus(x, y); //CHECK_NOALL: int * z = sus(x, y); - //CHECK_ALL: _Array_ptr z = sus(x, y); + //CHECK_ALL: _Array_ptr z : count(5) = sus(x, y); return z; } diff --git a/clang/test/CheckedCRewriter/arrsafemulti2.c b/clang/test/CheckedCRewriter/arrsafemulti2.c index b6fe126036d8..845f718c80a3 100644 --- a/clang/test/CheckedCRewriter/arrsafemulti2.c +++ b/clang/test/CheckedCRewriter/arrsafemulti2.c @@ -110,7 +110,7 @@ int *mul2(int *x) { int * sus(int * x, int * y) { //CHECK_NOALL: int * sus(int * x, _Ptr y) { - //CHECK_ALL: _Array_ptr sus(int * x, _Ptr y) { + //CHECK_ALL: _Array_ptr sus(int * x, _Ptr y) : count(5) { x = (int *) 5; //CHECK: x = (int *) 5; int *z = calloc(5, sizeof(int)); @@ -119,7 +119,7 @@ x = (int *) 5; int i, fac; int *p; //CHECK_NOALL: int *p; - //CHECK_ALL: _Array_ptr p : count(5) = ((void *)0); + //CHECK_ALL: _Array_ptr p = ((void *)0); for(i = 0, p = z, fac = 1; i < 5; ++i, p++, fac *= i) { *p = fac; } //CHECK_NOALL: { *p = fac; } diff --git a/clang/test/CheckedCRewriter/arrstructboth.c b/clang/test/CheckedCRewriter/arrstructboth.c index c1c8a4645016..4184ddb15117 100644 --- a/clang/test/CheckedCRewriter/arrstructboth.c +++ b/clang/test/CheckedCRewriter/arrstructboth.c @@ -108,7 +108,7 @@ x = (struct general *) 5; //CHECK: x = (struct general *) 5; int *z = calloc(5, sizeof(int)); //CHECK_NOALL: int *z = calloc(5, sizeof(int)); - //CHECK_ALL: _Array_ptr z : count(5) = calloc(5, sizeof(int)); + //CHECK_ALL: _Array_ptr z = calloc(5, sizeof(int)); struct general *p = y; //CHECK: _Ptr p = y; int i; diff --git a/clang/test/CheckedCRewriter/arrstructbothmulti2.c b/clang/test/CheckedCRewriter/arrstructbothmulti2.c index 091b9d220de1..128fd99f3c79 100644 --- a/clang/test/CheckedCRewriter/arrstructbothmulti2.c +++ b/clang/test/CheckedCRewriter/arrstructbothmulti2.c @@ -116,7 +116,7 @@ x = (struct general *) 5; //CHECK: x = (struct general *) 5; int *z = calloc(5, sizeof(int)); //CHECK_NOALL: int *z = calloc(5, sizeof(int)); - //CHECK_ALL: _Array_ptr z : count(5) = calloc(5, sizeof(int)); + //CHECK_ALL: _Array_ptr z = calloc(5, sizeof(int)); struct general *p = y; //CHECK: _Ptr p = y; int i; diff --git a/clang/test/CheckedCRewriter/arrstructcallee.c b/clang/test/CheckedCRewriter/arrstructcallee.c index 505f7103e062..e110ee6844a1 100644 --- a/clang/test/CheckedCRewriter/arrstructcallee.c +++ b/clang/test/CheckedCRewriter/arrstructcallee.c @@ -108,7 +108,7 @@ x = (struct general *) 5; //CHECK: x = (struct general *) 5; int *z = calloc(5, sizeof(int)); //CHECK_NOALL: int *z = calloc(5, sizeof(int)); - //CHECK_ALL: _Array_ptr z : count(5) = calloc(5, sizeof(int)); + //CHECK_ALL: _Array_ptr z = calloc(5, sizeof(int)); struct general *p = y; //CHECK: _Ptr p = y; int i; diff --git a/clang/test/CheckedCRewriter/arrstructcalleemulti2.c b/clang/test/CheckedCRewriter/arrstructcalleemulti2.c index 40db4802cea2..25ab1d74ab4d 100644 --- a/clang/test/CheckedCRewriter/arrstructcalleemulti2.c +++ b/clang/test/CheckedCRewriter/arrstructcalleemulti2.c @@ -116,7 +116,7 @@ x = (struct general *) 5; //CHECK: x = (struct general *) 5; int *z = calloc(5, sizeof(int)); //CHECK_NOALL: int *z = calloc(5, sizeof(int)); - //CHECK_ALL: _Array_ptr z : count(5) = calloc(5, sizeof(int)); + //CHECK_ALL: _Array_ptr z = calloc(5, sizeof(int)); struct general *p = y; //CHECK: _Ptr p = y; int i; diff --git a/clang/test/CheckedCRewriter/arrstructcaller.c b/clang/test/CheckedCRewriter/arrstructcaller.c index 0236acb0bf56..cc0962890c56 100644 --- a/clang/test/CheckedCRewriter/arrstructcaller.c +++ b/clang/test/CheckedCRewriter/arrstructcaller.c @@ -103,7 +103,7 @@ int *mul2(int *x) { int * sus(struct general * x, struct general * y) { //CHECK_NOALL: int * sus(struct general * x, _Ptr y) { - //CHECK_ALL: _Array_ptr sus(struct general * x, _Ptr y) { + //CHECK_ALL: _Array_ptr sus(struct general * x, _Ptr y) : count(5) { x = (struct general *) 5; //CHECK: x = (struct general *) 5; int *z = calloc(5, sizeof(int)); @@ -122,7 +122,7 @@ return z; } int * foo() { //CHECK_NOALL: int * foo(void) { - //CHECK_ALL: _Array_ptr foo(void) { + //CHECK_ALL: _Array_ptr foo(void) : count(5) { struct general * x = malloc(sizeof(struct general)); //CHECK: struct general * x = malloc(sizeof(struct general)); struct general * y = malloc(sizeof(struct general)); @@ -138,7 +138,7 @@ int * foo() { } int * z = sus(x, y); //CHECK_NOALL: int * z = sus(x, y); - //CHECK_ALL: _Array_ptr z = sus(x, y); + //CHECK_ALL: _Array_ptr z : count(5) = sus(x, y); return z; } int * bar() { diff --git a/clang/test/CheckedCRewriter/arrstructcallermulti1.c b/clang/test/CheckedCRewriter/arrstructcallermulti1.c index a589448af2b5..13b952fb46c2 100644 --- a/clang/test/CheckedCRewriter/arrstructcallermulti1.c +++ b/clang/test/CheckedCRewriter/arrstructcallermulti1.c @@ -111,11 +111,11 @@ int *mul2(int *x) { int * sus(struct general *, struct general *); //CHECK_NOALL: int * sus(struct general *, _Ptr y); - //CHECK_ALL: _Array_ptr sus(struct general *, _Ptr y); + //CHECK_ALL: _Array_ptr sus(struct general *, _Ptr y) : count(5); int * foo() { //CHECK_NOALL: int * foo(void) { - //CHECK_ALL: _Array_ptr foo(void) { + //CHECK_ALL: _Array_ptr foo(void) : count(5) { struct general * x = malloc(sizeof(struct general)); //CHECK: struct general * x = malloc(sizeof(struct general)); struct general * y = malloc(sizeof(struct general)); @@ -131,7 +131,7 @@ int * foo() { } int * z = sus(x, y); //CHECK_NOALL: int * z = sus(x, y); - //CHECK_ALL: _Array_ptr z = sus(x, y); + //CHECK_ALL: _Array_ptr z : count(5) = sus(x, y); return z; } int * bar() { diff --git a/clang/test/CheckedCRewriter/arrstructcallermulti2.c b/clang/test/CheckedCRewriter/arrstructcallermulti2.c index 34ffc4d66f33..2d16f2fef3fd 100644 --- a/clang/test/CheckedCRewriter/arrstructcallermulti2.c +++ b/clang/test/CheckedCRewriter/arrstructcallermulti2.c @@ -111,7 +111,7 @@ int *mul2(int *x) { int * sus(struct general * x, struct general * y) { //CHECK_NOALL: int * sus(struct general * x, _Ptr y) { - //CHECK_ALL: _Array_ptr sus(struct general * x, _Ptr y) { + //CHECK_ALL: _Array_ptr sus(struct general * x, _Ptr y) : count(5) { x = (struct general *) 5; //CHECK: x = (struct general *) 5; int *z = calloc(5, sizeof(int)); diff --git a/clang/test/CheckedCRewriter/arrstructprotoboth.c b/clang/test/CheckedCRewriter/arrstructprotoboth.c index 7a84b643c968..a96e35906732 100644 --- a/clang/test/CheckedCRewriter/arrstructprotoboth.c +++ b/clang/test/CheckedCRewriter/arrstructprotoboth.c @@ -158,7 +158,7 @@ x = (struct general *) 5; //CHECK: x = (struct general *) 5; int *z = calloc(5, sizeof(int)); //CHECK_NOALL: int *z = calloc(5, sizeof(int)); - //CHECK_ALL: _Array_ptr z : count(5) = calloc(5, sizeof(int)); + //CHECK_ALL: _Array_ptr z = calloc(5, sizeof(int)); struct general *p = y; //CHECK: _Ptr p = y; int i; diff --git a/clang/test/CheckedCRewriter/arrstructprotocallee.c b/clang/test/CheckedCRewriter/arrstructprotocallee.c index fbf1cbcb4469..0f5440ae6c6c 100644 --- a/clang/test/CheckedCRewriter/arrstructprotocallee.c +++ b/clang/test/CheckedCRewriter/arrstructprotocallee.c @@ -157,7 +157,7 @@ x = (struct general *) 5; //CHECK: x = (struct general *) 5; int *z = calloc(5, sizeof(int)); //CHECK_NOALL: int *z = calloc(5, sizeof(int)); - //CHECK_ALL: _Array_ptr z : count(5) = calloc(5, sizeof(int)); + //CHECK_ALL: _Array_ptr z = calloc(5, sizeof(int)); struct general *p = y; //CHECK: _Ptr p = y; int i; diff --git a/clang/test/CheckedCRewriter/arrstructprotocaller.c b/clang/test/CheckedCRewriter/arrstructprotocaller.c index 11ea55713194..ccfbb166d063 100644 --- a/clang/test/CheckedCRewriter/arrstructprotocaller.c +++ b/clang/test/CheckedCRewriter/arrstructprotocaller.c @@ -106,11 +106,11 @@ int *mul2(int *x) { int * sus(struct general *, struct general *); //CHECK_NOALL: int * sus(struct general * x, _Ptr y); - //CHECK_ALL: _Array_ptr sus(struct general * x, _Ptr y); + //CHECK_ALL: _Array_ptr sus(struct general * x, _Ptr y) : count(5); int * foo() { //CHECK_NOALL: int * foo(void) { - //CHECK_ALL: _Array_ptr foo(void) { + //CHECK_ALL: _Array_ptr foo(void) : count(5) { struct general * x = malloc(sizeof(struct general)); //CHECK: struct general * x = malloc(sizeof(struct general)); struct general * y = malloc(sizeof(struct general)); @@ -126,7 +126,7 @@ int * foo() { } int * z = sus(x, y); //CHECK_NOALL: int * z = sus(x, y); - //CHECK_ALL: _Array_ptr z = sus(x, y); + //CHECK_ALL: _Array_ptr z : count(5) = sus(x, y); return z; } int * bar() { @@ -153,7 +153,7 @@ return z; } int * sus(struct general * x, struct general * y) { //CHECK_NOALL: int * sus(struct general * x, _Ptr y) { - //CHECK_ALL: _Array_ptr sus(struct general * x, _Ptr y) { + //CHECK_ALL: _Array_ptr sus(struct general * x, _Ptr y) : count(5) { x = (struct general *) 5; //CHECK: x = (struct general *) 5; int *z = calloc(5, sizeof(int)); diff --git a/clang/test/CheckedCRewriter/arrstructprotosafe.c b/clang/test/CheckedCRewriter/arrstructprotosafe.c index e16c998093f3..e9d065509080 100644 --- a/clang/test/CheckedCRewriter/arrstructprotosafe.c +++ b/clang/test/CheckedCRewriter/arrstructprotosafe.c @@ -105,11 +105,11 @@ int *mul2(int *x) { int * sus(struct general *, struct general *); //CHECK_NOALL: int * sus(struct general * x, _Ptr y); - //CHECK_ALL: _Array_ptr sus(struct general * x, _Ptr y); + //CHECK_ALL: _Array_ptr sus(struct general * x, _Ptr y) : count(5); int * foo() { //CHECK_NOALL: int * foo(void) { - //CHECK_ALL: _Array_ptr foo(void) { + //CHECK_ALL: _Array_ptr foo(void) : count(5) { struct general * x = malloc(sizeof(struct general)); //CHECK: struct general * x = malloc(sizeof(struct general)); struct general * y = malloc(sizeof(struct general)); @@ -125,12 +125,12 @@ int * foo() { } int * z = sus(x, y); //CHECK_NOALL: int * z = sus(x, y); - //CHECK_ALL: _Array_ptr z = sus(x, y); + //CHECK_ALL: _Array_ptr z : count(5) = sus(x, y); return z; } int * bar() { //CHECK_NOALL: int * bar(void) { - //CHECK_ALL: _Array_ptr bar(void) { + //CHECK_ALL: _Array_ptr bar(void) : count(5) { struct general * x = malloc(sizeof(struct general)); //CHECK: struct general * x = malloc(sizeof(struct general)); struct general * y = malloc(sizeof(struct general)); @@ -146,12 +146,12 @@ int * bar() { } int * z = sus(x, y); //CHECK_NOALL: int * z = sus(x, y); - //CHECK_ALL: _Array_ptr z = sus(x, y); + //CHECK_ALL: _Array_ptr z : count(5) = sus(x, y); return z; } int * sus(struct general * x, struct general * y) { //CHECK_NOALL: int * sus(struct general * x, _Ptr y) { - //CHECK_ALL: _Array_ptr sus(struct general * x, _Ptr y) { + //CHECK_ALL: _Array_ptr sus(struct general * x, _Ptr y) : count(5) { x = (struct general *) 5; //CHECK: x = (struct general *) 5; int *z = calloc(5, sizeof(int)); diff --git a/clang/test/CheckedCRewriter/arrstructsafe.c b/clang/test/CheckedCRewriter/arrstructsafe.c index ea891e9ff85e..c03b84dee868 100644 --- a/clang/test/CheckedCRewriter/arrstructsafe.c +++ b/clang/test/CheckedCRewriter/arrstructsafe.c @@ -102,7 +102,7 @@ int *mul2(int *x) { int * sus(struct general * x, struct general * y) { //CHECK_NOALL: int * sus(struct general * x, _Ptr y) { - //CHECK_ALL: _Array_ptr sus(struct general * x, _Ptr y) { + //CHECK_ALL: _Array_ptr sus(struct general * x, _Ptr y) : count(5) { x = (struct general *) 5; //CHECK: x = (struct general *) 5; int *z = calloc(5, sizeof(int)); @@ -121,7 +121,7 @@ return z; } int * foo() { //CHECK_NOALL: int * foo(void) { - //CHECK_ALL: _Array_ptr foo(void) { + //CHECK_ALL: _Array_ptr foo(void) : count(5) { struct general * x = malloc(sizeof(struct general)); //CHECK: struct general * x = malloc(sizeof(struct general)); struct general * y = malloc(sizeof(struct general)); @@ -137,12 +137,12 @@ int * foo() { } int * z = sus(x, y); //CHECK_NOALL: int * z = sus(x, y); - //CHECK_ALL: _Array_ptr z = sus(x, y); + //CHECK_ALL: _Array_ptr z : count(5) = sus(x, y); return z; } int * bar() { //CHECK_NOALL: int * bar(void) { - //CHECK_ALL: _Array_ptr bar(void) { + //CHECK_ALL: _Array_ptr bar(void) : count(5) { struct general * x = malloc(sizeof(struct general)); //CHECK: struct general * x = malloc(sizeof(struct general)); struct general * y = malloc(sizeof(struct general)); @@ -158,5 +158,5 @@ int * bar() { } int * z = sus(x, y); //CHECK_NOALL: int * z = sus(x, y); - //CHECK_ALL: _Array_ptr z = sus(x, y); + //CHECK_ALL: _Array_ptr z : count(5) = sus(x, y); return z; } diff --git a/clang/test/CheckedCRewriter/arrstructsafemulti1.c b/clang/test/CheckedCRewriter/arrstructsafemulti1.c index 16263a317eed..fef01a9699ac 100644 --- a/clang/test/CheckedCRewriter/arrstructsafemulti1.c +++ b/clang/test/CheckedCRewriter/arrstructsafemulti1.c @@ -110,11 +110,11 @@ int *mul2(int *x) { int * sus(struct general *, struct general *); //CHECK_NOALL: int * sus(struct general *, _Ptr y); - //CHECK_ALL: _Array_ptr sus(struct general *, _Ptr y); + //CHECK_ALL: _Array_ptr sus(struct general *, _Ptr y) : count(5); int * foo() { //CHECK_NOALL: int * foo(void) { - //CHECK_ALL: _Array_ptr foo(void) { + //CHECK_ALL: _Array_ptr foo(void) : count(5) { struct general * x = malloc(sizeof(struct general)); //CHECK: struct general * x = malloc(sizeof(struct general)); struct general * y = malloc(sizeof(struct general)); @@ -130,12 +130,12 @@ int * foo() { } int * z = sus(x, y); //CHECK_NOALL: int * z = sus(x, y); - //CHECK_ALL: _Array_ptr z = sus(x, y); + //CHECK_ALL: _Array_ptr z : count(5) = sus(x, y); return z; } int * bar() { //CHECK_NOALL: int * bar(void) { - //CHECK_ALL: _Array_ptr bar(void) { + //CHECK_ALL: _Array_ptr bar(void) : count(5) { struct general * x = malloc(sizeof(struct general)); //CHECK: struct general * x = malloc(sizeof(struct general)); struct general * y = malloc(sizeof(struct general)); @@ -151,5 +151,5 @@ int * bar() { } int * z = sus(x, y); //CHECK_NOALL: int * z = sus(x, y); - //CHECK_ALL: _Array_ptr z = sus(x, y); + //CHECK_ALL: _Array_ptr z : count(5) = sus(x, y); return z; } diff --git a/clang/test/CheckedCRewriter/arrstructsafemulti2.c b/clang/test/CheckedCRewriter/arrstructsafemulti2.c index 497438a61142..b9fa4e9490b2 100644 --- a/clang/test/CheckedCRewriter/arrstructsafemulti2.c +++ b/clang/test/CheckedCRewriter/arrstructsafemulti2.c @@ -110,7 +110,7 @@ int *mul2(int *x) { int * sus(struct general * x, struct general * y) { //CHECK_NOALL: int * sus(struct general * x, _Ptr y) { - //CHECK_ALL: _Array_ptr sus(struct general * x, _Ptr y) { + //CHECK_ALL: _Array_ptr sus(struct general * x, _Ptr y) : count(5) { x = (struct general *) 5; //CHECK: x = (struct general *) 5; int *z = calloc(5, sizeof(int)); diff --git a/clang/test/CheckedCRewriter/contextsensitivebounds.c b/clang/test/CheckedCRewriter/contextsensitivebounds.c new file mode 100644 index 000000000000..1fca592f385f --- /dev/null +++ b/clang/test/CheckedCRewriter/contextsensitivebounds.c @@ -0,0 +1,43 @@ +/** +Test for context sensitive bounds. +**/ + +// RUN: cconv-standalone -alltypes %s -- | FileCheck -match-full-lines -check-prefixes="CHECK_ALL","CHECK" %s +// RUN: cconv-standalone %s -- | FileCheck -match-full-lines -check-prefixes="CHECK_NOALL","CHECK" %s +_Itype_for_any(T) void *somefunc(unsigned long size) : itype(_Array_ptr) byte_count(size); +struct hash_node +{ + int *p_key; + int *q_key; + int *r_key; + unsigned pqlen; + unsigned r_len; +}; + +//CHECK_ALL: _Array_ptr p_key : byte_count(pqlen); +//CHECK_NOALL: int *p_key; +//CHECK_ALL: _Array_ptr q_key : byte_count(pqlen); +//CHECK_NOALL: int *q_key; +//CHECK_ALL: _Array_ptr r_key : byte_count(r_len); +//CHECK_NOALL: int *r_key; + +int bar(struct hash_node *p) { + p->p_key = p->q_key; + return 0; +} +//CHECK_ALL: int bar(_Ptr p) { +//CHECK_NOALL: int bar(_Ptr p) { + +int foo() { + unsigned i; + struct hash_node *n = somefunc(sizeof(struct hash_node)); + i = 5*sizeof(int); + n->pqlen = i; + n->p_key = somefunc(i); + n->r_key = somefunc(n->r_len); + n->p_key[0] = 1; + n->r_key[0] = 1; + return 0; +} +//CHECK_ALL: _Ptr n = somefunc(sizeof(struct hash_node)); +//CHECK_NOALL: struct hash_node *n = somefunc(sizeof(struct hash_node)); diff --git a/clang/test/CheckedCRewriter/fptrarrboth.c b/clang/test/CheckedCRewriter/fptrarrboth.c index d16cf399bc2a..6e9869a07c93 100644 --- a/clang/test/CheckedCRewriter/fptrarrboth.c +++ b/clang/test/CheckedCRewriter/fptrarrboth.c @@ -110,7 +110,7 @@ int ** sus(int *x, int *y) { //CHECK: x = (int *) 5; int **z = calloc(5, sizeof(int *)); //CHECK_NOALL: int **z = calloc(5, sizeof(int *)); - //CHECK_ALL: _Array_ptr<_Array_ptr> z : count(5) = calloc<_Array_ptr>(5, sizeof(int *)); + //CHECK_ALL: _Array_ptr<_Array_ptr> z = calloc<_Array_ptr>(5, sizeof(int *)); int * (*mul2ptr) (int *) = mul2; //CHECK_NOALL: _Ptr mul2ptr = mul2; //CHECK_ALL: _Ptr<_Array_ptr (_Array_ptr )> mul2ptr = mul2; diff --git a/clang/test/CheckedCRewriter/fptrarrbothmulti2.c b/clang/test/CheckedCRewriter/fptrarrbothmulti2.c index 0cdfa1441841..52e2ab3786af 100644 --- a/clang/test/CheckedCRewriter/fptrarrbothmulti2.c +++ b/clang/test/CheckedCRewriter/fptrarrbothmulti2.c @@ -118,7 +118,7 @@ int ** sus(int *x, int *y) { //CHECK: x = (int *) 5; int **z = calloc(5, sizeof(int *)); //CHECK_NOALL: int **z = calloc(5, sizeof(int *)); - //CHECK_ALL: _Array_ptr<_Array_ptr> z : count(5) = calloc<_Array_ptr>(5, sizeof(int *)); + //CHECK_ALL: _Array_ptr<_Array_ptr> z = calloc<_Array_ptr>(5, sizeof(int *)); int * (*mul2ptr) (int *) = mul2; //CHECK_NOALL: _Ptr mul2ptr = mul2; //CHECK_ALL: _Ptr<_Array_ptr (_Array_ptr )> mul2ptr = mul2; diff --git a/clang/test/CheckedCRewriter/fptrarrcallee.c b/clang/test/CheckedCRewriter/fptrarrcallee.c index 2e8afce44986..1cfe6e54f957 100644 --- a/clang/test/CheckedCRewriter/fptrarrcallee.c +++ b/clang/test/CheckedCRewriter/fptrarrcallee.c @@ -110,7 +110,7 @@ int ** sus(int *x, int *y) { //CHECK: x = (int *) 5; int **z = calloc(5, sizeof(int *)); //CHECK_NOALL: int **z = calloc(5, sizeof(int *)); - //CHECK_ALL: _Array_ptr<_Array_ptr> z : count(5) = calloc<_Array_ptr>(5, sizeof(int *)); + //CHECK_ALL: _Array_ptr<_Array_ptr> z = calloc<_Array_ptr>(5, sizeof(int *)); int * (*mul2ptr) (int *) = mul2; //CHECK_NOALL: _Ptr mul2ptr = mul2; //CHECK_ALL: _Ptr<_Array_ptr (_Array_ptr )> mul2ptr = mul2; diff --git a/clang/test/CheckedCRewriter/fptrarrcalleemulti2.c b/clang/test/CheckedCRewriter/fptrarrcalleemulti2.c index 5e76b017ff7d..536bed5f98a9 100644 --- a/clang/test/CheckedCRewriter/fptrarrcalleemulti2.c +++ b/clang/test/CheckedCRewriter/fptrarrcalleemulti2.c @@ -118,7 +118,7 @@ int ** sus(int *x, int *y) { //CHECK: x = (int *) 5; int **z = calloc(5, sizeof(int *)); //CHECK_NOALL: int **z = calloc(5, sizeof(int *)); - //CHECK_ALL: _Array_ptr<_Array_ptr> z : count(5) = calloc<_Array_ptr>(5, sizeof(int *)); + //CHECK_ALL: _Array_ptr<_Array_ptr> z = calloc<_Array_ptr>(5, sizeof(int *)); int * (*mul2ptr) (int *) = mul2; //CHECK_NOALL: _Ptr mul2ptr = mul2; //CHECK_ALL: _Ptr<_Array_ptr (_Array_ptr )> mul2ptr = mul2; diff --git a/clang/test/CheckedCRewriter/fptrarrcaller.c b/clang/test/CheckedCRewriter/fptrarrcaller.c index 01202dc4039c..9dd3354b1b1d 100644 --- a/clang/test/CheckedCRewriter/fptrarrcaller.c +++ b/clang/test/CheckedCRewriter/fptrarrcaller.c @@ -104,7 +104,7 @@ int *mul2(int *x) { int ** sus(int *x, int *y) { //CHECK_NOALL: int ** sus(int *x, int *y) { - //CHECK_ALL: _Array_ptr<_Array_ptr> sus(int *x, _Array_ptr y : count(5)) { + //CHECK_ALL: _Array_ptr<_Array_ptr> sus(int *x, _Array_ptr y : count(5)) : count(5) { x = (int *) 5; //CHECK: x = (int *) 5; @@ -125,7 +125,7 @@ return z; } int ** foo() { //CHECK_NOALL: int ** foo(void) { - //CHECK_ALL: _Array_ptr<_Array_ptr> foo(void) { + //CHECK_ALL: _Array_ptr<_Array_ptr> foo(void) : count(5) { int *x = malloc(sizeof(int)); //CHECK: int *x = malloc(sizeof(int)); @@ -140,7 +140,7 @@ int ** foo() { } int **z = sus(x, y); //CHECK_NOALL: int **z = sus(x, y); - //CHECK_ALL: _Array_ptr<_Array_ptr> z = sus(x, y); + //CHECK_ALL: _Array_ptr<_Array_ptr> z : count(5) = sus(x, y); return z; } diff --git a/clang/test/CheckedCRewriter/fptrarrcallermulti1.c b/clang/test/CheckedCRewriter/fptrarrcallermulti1.c index 17cd8e19bbaf..192311115b2f 100644 --- a/clang/test/CheckedCRewriter/fptrarrcallermulti1.c +++ b/clang/test/CheckedCRewriter/fptrarrcallermulti1.c @@ -112,11 +112,11 @@ int *mul2(int *x) { int ** sus(int *, int *); //CHECK_NOALL: int ** sus(int *, int *); - //CHECK_ALL: _Array_ptr<_Array_ptr> sus(int *, _Array_ptr y : count(5)); + //CHECK_ALL: _Array_ptr<_Array_ptr> sus(int *, _Array_ptr y : count(5)) : count(5); int ** foo() { //CHECK_NOALL: int ** foo(void) { - //CHECK_ALL: _Array_ptr<_Array_ptr> foo(void) { + //CHECK_ALL: _Array_ptr<_Array_ptr> foo(void) : count(5) { int *x = malloc(sizeof(int)); //CHECK: int *x = malloc(sizeof(int)); @@ -131,7 +131,7 @@ int ** foo() { } int **z = sus(x, y); //CHECK_NOALL: int **z = sus(x, y); - //CHECK_ALL: _Array_ptr<_Array_ptr> z = sus(x, y); + //CHECK_ALL: _Array_ptr<_Array_ptr> z : count(5) = sus(x, y); return z; } diff --git a/clang/test/CheckedCRewriter/fptrarrcallermulti2.c b/clang/test/CheckedCRewriter/fptrarrcallermulti2.c index 7b4ba52e9e31..676479c46937 100644 --- a/clang/test/CheckedCRewriter/fptrarrcallermulti2.c +++ b/clang/test/CheckedCRewriter/fptrarrcallermulti2.c @@ -112,7 +112,7 @@ int *mul2(int *x) { int ** sus(int *x, int *y) { //CHECK_NOALL: int ** sus(int *x, int *y) { - //CHECK_ALL: _Array_ptr<_Array_ptr> sus(int *x, _Array_ptr y : count(5)) { + //CHECK_ALL: _Array_ptr<_Array_ptr> sus(int *x, _Array_ptr y : count(5)) : count(5) { x = (int *) 5; //CHECK: x = (int *) 5; diff --git a/clang/test/CheckedCRewriter/fptrarrprotoboth.c b/clang/test/CheckedCRewriter/fptrarrprotoboth.c index 81210c62518c..415b6f13319c 100644 --- a/clang/test/CheckedCRewriter/fptrarrprotoboth.c +++ b/clang/test/CheckedCRewriter/fptrarrprotoboth.c @@ -160,7 +160,7 @@ int ** sus(int *x, int *y) { //CHECK: x = (int *) 5; int **z = calloc(5, sizeof(int *)); //CHECK_NOALL: int **z = calloc(5, sizeof(int *)); - //CHECK_ALL: _Array_ptr<_Array_ptr> z : count(5) = calloc<_Array_ptr>(5, sizeof(int *)); + //CHECK_ALL: _Array_ptr<_Array_ptr> z = calloc<_Array_ptr>(5, sizeof(int *)); int * (*mul2ptr) (int *) = mul2; //CHECK_NOALL: _Ptr mul2ptr = mul2; //CHECK_ALL: _Ptr<_Array_ptr (_Array_ptr )> mul2ptr = mul2; diff --git a/clang/test/CheckedCRewriter/fptrarrprotocallee.c b/clang/test/CheckedCRewriter/fptrarrprotocallee.c index be9d5acb6ad2..61c2f2911a2c 100644 --- a/clang/test/CheckedCRewriter/fptrarrprotocallee.c +++ b/clang/test/CheckedCRewriter/fptrarrprotocallee.c @@ -159,7 +159,7 @@ int ** sus(int *x, int *y) { //CHECK: x = (int *) 5; int **z = calloc(5, sizeof(int *)); //CHECK_NOALL: int **z = calloc(5, sizeof(int *)); - //CHECK_ALL: _Array_ptr<_Array_ptr> z : count(5) = calloc<_Array_ptr>(5, sizeof(int *)); + //CHECK_ALL: _Array_ptr<_Array_ptr> z = calloc<_Array_ptr>(5, sizeof(int *)); int * (*mul2ptr) (int *) = mul2; //CHECK_NOALL: _Ptr mul2ptr = mul2; //CHECK_ALL: _Ptr<_Array_ptr (_Array_ptr )> mul2ptr = mul2; diff --git a/clang/test/CheckedCRewriter/fptrarrprotocaller.c b/clang/test/CheckedCRewriter/fptrarrprotocaller.c index c4c9d644e40b..8a7b02618a1a 100644 --- a/clang/test/CheckedCRewriter/fptrarrprotocaller.c +++ b/clang/test/CheckedCRewriter/fptrarrprotocaller.c @@ -107,11 +107,11 @@ int *mul2(int *x) { int ** sus(int *, int *); //CHECK_NOALL: int ** sus(int *, int *); - //CHECK_ALL: _Array_ptr<_Array_ptr> sus(int *x, _Array_ptr y : count(5)); + //CHECK_ALL: _Array_ptr<_Array_ptr> sus(int *x, _Array_ptr y : count(5)) : count(5); int ** foo() { //CHECK_NOALL: int ** foo(void) { - //CHECK_ALL: _Array_ptr<_Array_ptr> foo(void) { + //CHECK_ALL: _Array_ptr<_Array_ptr> foo(void) : count(5) { int *x = malloc(sizeof(int)); //CHECK: int *x = malloc(sizeof(int)); @@ -126,7 +126,7 @@ int ** foo() { } int **z = sus(x, y); //CHECK_NOALL: int **z = sus(x, y); - //CHECK_ALL: _Array_ptr<_Array_ptr> z = sus(x, y); + //CHECK_ALL: _Array_ptr<_Array_ptr> z : count(5) = sus(x, y); return z; } @@ -154,7 +154,7 @@ return z; } int ** sus(int *x, int *y) { //CHECK_NOALL: int ** sus(int *x, int *y) { - //CHECK_ALL: _Array_ptr<_Array_ptr> sus(int *x, _Array_ptr y : count(5)) { + //CHECK_ALL: _Array_ptr<_Array_ptr> sus(int *x, _Array_ptr y : count(5)) : count(5) { x = (int *) 5; //CHECK: x = (int *) 5; diff --git a/clang/test/CheckedCRewriter/fptrarrprotosafe.c b/clang/test/CheckedCRewriter/fptrarrprotosafe.c index c4d3b29ec613..8721ff94bc09 100644 --- a/clang/test/CheckedCRewriter/fptrarrprotosafe.c +++ b/clang/test/CheckedCRewriter/fptrarrprotosafe.c @@ -106,11 +106,11 @@ int *mul2(int *x) { int ** sus(int *, int *); //CHECK_NOALL: int ** sus(int *, int *); - //CHECK_ALL: _Array_ptr<_Array_ptr> sus(int *x, _Array_ptr y : count(5)); + //CHECK_ALL: _Array_ptr<_Array_ptr> sus(int *x, _Array_ptr y : count(5)) : count(5); int ** foo() { //CHECK_NOALL: int ** foo(void) { - //CHECK_ALL: _Array_ptr<_Array_ptr> foo(void) { + //CHECK_ALL: _Array_ptr<_Array_ptr> foo(void) : count(5) { int *x = malloc(sizeof(int)); //CHECK: int *x = malloc(sizeof(int)); @@ -125,13 +125,13 @@ int ** foo() { } int **z = sus(x, y); //CHECK_NOALL: int **z = sus(x, y); - //CHECK_ALL: _Array_ptr<_Array_ptr> z = sus(x, y); + //CHECK_ALL: _Array_ptr<_Array_ptr> z : count(5) = sus(x, y); return z; } int ** bar() { //CHECK_NOALL: int ** bar(void) { - //CHECK_ALL: _Array_ptr<_Array_ptr> bar(void) { + //CHECK_ALL: _Array_ptr<_Array_ptr> bar(void) : count(5) { int *x = malloc(sizeof(int)); //CHECK: int *x = malloc(sizeof(int)); @@ -146,13 +146,13 @@ int ** bar() { } int **z = sus(x, y); //CHECK_NOALL: int **z = sus(x, y); - //CHECK_ALL: _Array_ptr<_Array_ptr> z = sus(x, y); + //CHECK_ALL: _Array_ptr<_Array_ptr> z : count(5) = sus(x, y); return z; } int ** sus(int *x, int *y) { //CHECK_NOALL: int ** sus(int *x, int *y) { - //CHECK_ALL: _Array_ptr<_Array_ptr> sus(int *x, _Array_ptr y : count(5)) { + //CHECK_ALL: _Array_ptr<_Array_ptr> sus(int *x, _Array_ptr y : count(5)) : count(5) { x = (int *) 5; //CHECK: x = (int *) 5; diff --git a/clang/test/CheckedCRewriter/fptrarrsafe.c b/clang/test/CheckedCRewriter/fptrarrsafe.c index 9b2e23ceca31..e93b3ae9e5dc 100644 --- a/clang/test/CheckedCRewriter/fptrarrsafe.c +++ b/clang/test/CheckedCRewriter/fptrarrsafe.c @@ -103,7 +103,7 @@ int *mul2(int *x) { int ** sus(int *x, int *y) { //CHECK_NOALL: int ** sus(int *x, int *y) { - //CHECK_ALL: _Array_ptr<_Array_ptr> sus(int *x, _Array_ptr y : count(5)) { + //CHECK_ALL: _Array_ptr<_Array_ptr> sus(int *x, _Array_ptr y : count(5)) : count(5) { x = (int *) 5; //CHECK: x = (int *) 5; @@ -124,7 +124,7 @@ return z; } int ** foo() { //CHECK_NOALL: int ** foo(void) { - //CHECK_ALL: _Array_ptr<_Array_ptr> foo(void) { + //CHECK_ALL: _Array_ptr<_Array_ptr> foo(void) : count(5) { int *x = malloc(sizeof(int)); //CHECK: int *x = malloc(sizeof(int)); @@ -139,13 +139,13 @@ int ** foo() { } int **z = sus(x, y); //CHECK_NOALL: int **z = sus(x, y); - //CHECK_ALL: _Array_ptr<_Array_ptr> z = sus(x, y); + //CHECK_ALL: _Array_ptr<_Array_ptr> z : count(5) = sus(x, y); return z; } int ** bar() { //CHECK_NOALL: int ** bar(void) { - //CHECK_ALL: _Array_ptr<_Array_ptr> bar(void) { + //CHECK_ALL: _Array_ptr<_Array_ptr> bar(void) : count(5) { int *x = malloc(sizeof(int)); //CHECK: int *x = malloc(sizeof(int)); @@ -160,6 +160,6 @@ int ** bar() { } int **z = sus(x, y); //CHECK_NOALL: int **z = sus(x, y); - //CHECK_ALL: _Array_ptr<_Array_ptr> z = sus(x, y); + //CHECK_ALL: _Array_ptr<_Array_ptr> z : count(5) = sus(x, y); return z; } diff --git a/clang/test/CheckedCRewriter/fptrarrsafemulti1.c b/clang/test/CheckedCRewriter/fptrarrsafemulti1.c index 121064579daa..0e33723d0163 100644 --- a/clang/test/CheckedCRewriter/fptrarrsafemulti1.c +++ b/clang/test/CheckedCRewriter/fptrarrsafemulti1.c @@ -111,11 +111,11 @@ int *mul2(int *x) { int ** sus(int *, int *); //CHECK_NOALL: int ** sus(int *, int *); - //CHECK_ALL: _Array_ptr<_Array_ptr> sus(int *, _Array_ptr y : count(5)); + //CHECK_ALL: _Array_ptr<_Array_ptr> sus(int *, _Array_ptr y : count(5)) : count(5); int ** foo() { //CHECK_NOALL: int ** foo(void) { - //CHECK_ALL: _Array_ptr<_Array_ptr> foo(void) { + //CHECK_ALL: _Array_ptr<_Array_ptr> foo(void) : count(5) { int *x = malloc(sizeof(int)); //CHECK: int *x = malloc(sizeof(int)); @@ -130,13 +130,13 @@ int ** foo() { } int **z = sus(x, y); //CHECK_NOALL: int **z = sus(x, y); - //CHECK_ALL: _Array_ptr<_Array_ptr> z = sus(x, y); + //CHECK_ALL: _Array_ptr<_Array_ptr> z : count(5) = sus(x, y); return z; } int ** bar() { //CHECK_NOALL: int ** bar(void) { - //CHECK_ALL: _Array_ptr<_Array_ptr> bar(void) { + //CHECK_ALL: _Array_ptr<_Array_ptr> bar(void) : count(5) { int *x = malloc(sizeof(int)); //CHECK: int *x = malloc(sizeof(int)); @@ -151,6 +151,6 @@ int ** bar() { } int **z = sus(x, y); //CHECK_NOALL: int **z = sus(x, y); - //CHECK_ALL: _Array_ptr<_Array_ptr> z = sus(x, y); + //CHECK_ALL: _Array_ptr<_Array_ptr> z : count(5) = sus(x, y); return z; } diff --git a/clang/test/CheckedCRewriter/fptrarrsafemulti2.c b/clang/test/CheckedCRewriter/fptrarrsafemulti2.c index 2bff38af1a59..694496d1fce9 100644 --- a/clang/test/CheckedCRewriter/fptrarrsafemulti2.c +++ b/clang/test/CheckedCRewriter/fptrarrsafemulti2.c @@ -111,7 +111,7 @@ int *mul2(int *x) { int ** sus(int *x, int *y) { //CHECK_NOALL: int ** sus(int *x, int *y) { - //CHECK_ALL: _Array_ptr<_Array_ptr> sus(int *x, _Array_ptr y : count(5)) { + //CHECK_ALL: _Array_ptr<_Array_ptr> sus(int *x, _Array_ptr y : count(5)) : count(5) { x = (int *) 5; //CHECK: x = (int *) 5; diff --git a/clang/test/CheckedCRewriter/fptrsafeboth.c b/clang/test/CheckedCRewriter/fptrsafeboth.c index dd56f3921105..288843fd9b78 100644 --- a/clang/test/CheckedCRewriter/fptrsafeboth.c +++ b/clang/test/CheckedCRewriter/fptrsafeboth.c @@ -109,7 +109,7 @@ int * sus(struct general *x, struct general *y) { //CHECK: x = (struct general *) 5; int *z = calloc(5, sizeof(int)); //CHECK_NOALL: int *z = calloc(5, sizeof(int)); - //CHECK_ALL: _Array_ptr z : count(5) = calloc(5, sizeof(int)); + //CHECK_ALL: _Array_ptr z = calloc(5, sizeof(int)); struct general *p = y; //CHECK: _Ptr p = y; int i; diff --git a/clang/test/CheckedCRewriter/fptrsafebothmulti2.c b/clang/test/CheckedCRewriter/fptrsafebothmulti2.c index f71d1fa9ade0..4fcc8dc16a36 100644 --- a/clang/test/CheckedCRewriter/fptrsafebothmulti2.c +++ b/clang/test/CheckedCRewriter/fptrsafebothmulti2.c @@ -117,7 +117,7 @@ int * sus(struct general *x, struct general *y) { //CHECK: x = (struct general *) 5; int *z = calloc(5, sizeof(int)); //CHECK_NOALL: int *z = calloc(5, sizeof(int)); - //CHECK_ALL: _Array_ptr z : count(5) = calloc(5, sizeof(int)); + //CHECK_ALL: _Array_ptr z = calloc(5, sizeof(int)); struct general *p = y; //CHECK: _Ptr p = y; int i; diff --git a/clang/test/CheckedCRewriter/fptrsafecallee.c b/clang/test/CheckedCRewriter/fptrsafecallee.c index c48efbba69aa..9b8af5104dee 100644 --- a/clang/test/CheckedCRewriter/fptrsafecallee.c +++ b/clang/test/CheckedCRewriter/fptrsafecallee.c @@ -109,7 +109,7 @@ int * sus(struct general *x, struct general *y) { //CHECK: x = (struct general *) 5; int *z = calloc(5, sizeof(int)); //CHECK_NOALL: int *z = calloc(5, sizeof(int)); - //CHECK_ALL: _Array_ptr z : count(5) = calloc(5, sizeof(int)); + //CHECK_ALL: _Array_ptr z = calloc(5, sizeof(int)); struct general *p = y; //CHECK: _Ptr p = y; int i; diff --git a/clang/test/CheckedCRewriter/fptrsafecalleemulti2.c b/clang/test/CheckedCRewriter/fptrsafecalleemulti2.c index 7d7806094086..310c07d33fa1 100644 --- a/clang/test/CheckedCRewriter/fptrsafecalleemulti2.c +++ b/clang/test/CheckedCRewriter/fptrsafecalleemulti2.c @@ -117,7 +117,7 @@ int * sus(struct general *x, struct general *y) { //CHECK: x = (struct general *) 5; int *z = calloc(5, sizeof(int)); //CHECK_NOALL: int *z = calloc(5, sizeof(int)); - //CHECK_ALL: _Array_ptr z : count(5) = calloc(5, sizeof(int)); + //CHECK_ALL: _Array_ptr z = calloc(5, sizeof(int)); struct general *p = y; //CHECK: _Ptr p = y; int i; diff --git a/clang/test/CheckedCRewriter/fptrsafeprotoboth.c b/clang/test/CheckedCRewriter/fptrsafeprotoboth.c index 8e8c72ed06f5..30b037c2cb41 100644 --- a/clang/test/CheckedCRewriter/fptrsafeprotoboth.c +++ b/clang/test/CheckedCRewriter/fptrsafeprotoboth.c @@ -167,7 +167,7 @@ int * sus(struct general *x, struct general *y) { //CHECK: x = (struct general *) 5; int *z = calloc(5, sizeof(int)); //CHECK_NOALL: int *z = calloc(5, sizeof(int)); - //CHECK_ALL: _Array_ptr z : count(5) = calloc(5, sizeof(int)); + //CHECK_ALL: _Array_ptr z = calloc(5, sizeof(int)); struct general *p = y; //CHECK: _Ptr p = y; int i; diff --git a/clang/test/CheckedCRewriter/fptrsafeprotocallee.c b/clang/test/CheckedCRewriter/fptrsafeprotocallee.c index 52a8d38b3699..84ab0c34d43b 100644 --- a/clang/test/CheckedCRewriter/fptrsafeprotocallee.c +++ b/clang/test/CheckedCRewriter/fptrsafeprotocallee.c @@ -166,7 +166,7 @@ int * sus(struct general *x, struct general *y) { //CHECK: x = (struct general *) 5; int *z = calloc(5, sizeof(int)); //CHECK_NOALL: int *z = calloc(5, sizeof(int)); - //CHECK_ALL: _Array_ptr z : count(5) = calloc(5, sizeof(int)); + //CHECK_ALL: _Array_ptr z = calloc(5, sizeof(int)); struct general *p = y; //CHECK: _Ptr p = y; int i; diff --git a/clang/test/CheckedCRewriter/free.c b/clang/test/CheckedCRewriter/free.c index 1d6e525ecd84..67fca5178f73 100644 --- a/clang/test/CheckedCRewriter/free.c +++ b/clang/test/CheckedCRewriter/free.c @@ -9,7 +9,7 @@ _Itype_for_any(T) void *malloc(size_t size) : itype(_Array_ptr) byte_count(si int *test() { // CHECK_NOALL: int *test(void) { -// CHECK_ALL: _Array_ptr test(void) { +// CHECK_ALL: _Array_ptr test(void) : count(5) { int *a = malloc(sizeof(int)); // CHECK: _Ptr a = malloc(sizeof(int)); free(a); @@ -27,7 +27,7 @@ _Itype_for_any(T) void my_free(void *pointer : itype(_Array_ptr) byte_count(0 int *test2() { // CHECK_NOALL: int *test2(void) { -// CHECK_ALL:_Array_ptr test2(void) { +// CHECK_ALL:_Array_ptr test2(void) : count(5) { int *a = malloc(sizeof(int)); // CHECK: _Ptr a = malloc(sizeof(int)); my_free(a); diff --git a/clang/test/CheckedCRewriter/pointerarithm.c b/clang/test/CheckedCRewriter/pointerarithm.c index efef9c418930..6be5754fc021 100644 --- a/clang/test/CheckedCRewriter/pointerarithm.c +++ b/clang/test/CheckedCRewriter/pointerarithm.c @@ -18,7 +18,7 @@ int *sus(int *x, int*y) { *x = 2; return z; } -//CHECK: _Array_ptr sus(int *x : itype(_Array_ptr), _Ptr y) { +//CHECK: _Array_ptr sus(int *x : itype(_Array_ptr), _Ptr y) : count(2) { //CHECK-NEXT: _Array_ptr z : count(2) = malloc(sizeof(int)*2); int* foo() { diff --git a/clang/test/CheckedCRewriter/ptrTOptrboth.c b/clang/test/CheckedCRewriter/ptrTOptrboth.c index eae7ea3ed848..fc146b027a04 100644 --- a/clang/test/CheckedCRewriter/ptrTOptrboth.c +++ b/clang/test/CheckedCRewriter/ptrTOptrboth.c @@ -110,7 +110,7 @@ x = (char * * *) 5; *ch = 'A'; /*Capital A*/ char *** z = malloc(5*sizeof(char**)); //CHECK_NOALL: char *** z = malloc(5*sizeof(char**)); - //CHECK_ALL: _Array_ptr<_Array_ptr> z : count(5) = malloc<_Array_ptr>(5*sizeof(char**)); + //CHECK_ALL: _Array_ptr<_Array_ptr> z = malloc<_Array_ptr>(5*sizeof(char**)); for(int i = 0; i < 5; i++) { z[i] = malloc(5*sizeof(char *)); //CHECK: z[i] = malloc(5*sizeof(char *)); diff --git a/clang/test/CheckedCRewriter/ptrTOptrbothmulti2.c b/clang/test/CheckedCRewriter/ptrTOptrbothmulti2.c index f169e78830de..141e49debed4 100644 --- a/clang/test/CheckedCRewriter/ptrTOptrbothmulti2.c +++ b/clang/test/CheckedCRewriter/ptrTOptrbothmulti2.c @@ -118,7 +118,7 @@ x = (char * * *) 5; *ch = 'A'; /*Capital A*/ char *** z = malloc(5*sizeof(char**)); //CHECK_NOALL: char *** z = malloc(5*sizeof(char**)); - //CHECK_ALL: _Array_ptr<_Array_ptr> z : count(5) = malloc<_Array_ptr>(5*sizeof(char**)); + //CHECK_ALL: _Array_ptr<_Array_ptr> z = malloc<_Array_ptr>(5*sizeof(char**)); for(int i = 0; i < 5; i++) { z[i] = malloc(5*sizeof(char *)); //CHECK: z[i] = malloc(5*sizeof(char *)); diff --git a/clang/test/CheckedCRewriter/ptrTOptrcallee.c b/clang/test/CheckedCRewriter/ptrTOptrcallee.c index 3a4096567ccc..ed8c28e5c33a 100644 --- a/clang/test/CheckedCRewriter/ptrTOptrcallee.c +++ b/clang/test/CheckedCRewriter/ptrTOptrcallee.c @@ -110,7 +110,7 @@ x = (char * * *) 5; *ch = 'A'; /*Capital A*/ char *** z = malloc(5*sizeof(char**)); //CHECK_NOALL: char *** z = malloc(5*sizeof(char**)); - //CHECK_ALL: _Array_ptr<_Array_ptr> z : count(5) = malloc<_Array_ptr>(5*sizeof(char**)); + //CHECK_ALL: _Array_ptr<_Array_ptr> z = malloc<_Array_ptr>(5*sizeof(char**)); for(int i = 0; i < 5; i++) { z[i] = malloc(5*sizeof(char *)); //CHECK: z[i] = malloc(5*sizeof(char *)); diff --git a/clang/test/CheckedCRewriter/ptrTOptrcalleemulti2.c b/clang/test/CheckedCRewriter/ptrTOptrcalleemulti2.c index 05b4000681e7..31b9a1e5bfa0 100644 --- a/clang/test/CheckedCRewriter/ptrTOptrcalleemulti2.c +++ b/clang/test/CheckedCRewriter/ptrTOptrcalleemulti2.c @@ -118,7 +118,7 @@ x = (char * * *) 5; *ch = 'A'; /*Capital A*/ char *** z = malloc(5*sizeof(char**)); //CHECK_NOALL: char *** z = malloc(5*sizeof(char**)); - //CHECK_ALL: _Array_ptr<_Array_ptr> z : count(5) = malloc<_Array_ptr>(5*sizeof(char**)); + //CHECK_ALL: _Array_ptr<_Array_ptr> z = malloc<_Array_ptr>(5*sizeof(char**)); for(int i = 0; i < 5; i++) { z[i] = malloc(5*sizeof(char *)); //CHECK: z[i] = malloc(5*sizeof(char *)); diff --git a/clang/test/CheckedCRewriter/ptrTOptrcaller.c b/clang/test/CheckedCRewriter/ptrTOptrcaller.c index de0eed5756a1..182d1c729f26 100644 --- a/clang/test/CheckedCRewriter/ptrTOptrcaller.c +++ b/clang/test/CheckedCRewriter/ptrTOptrcaller.c @@ -102,7 +102,7 @@ int *mul2(int *x) { char *** sus(char * * * x, char * * * y) { //CHECK_NOALL: char *** sus(char * * * x, _Ptr<_Ptr<_Ptr>> y) { - //CHECK_ALL: _Array_ptr<_Array_ptr> sus(char * * * x, _Ptr<_Ptr<_Ptr>> y) { + //CHECK_ALL: _Array_ptr<_Array_ptr> sus(char * * * x, _Ptr<_Ptr<_Ptr>> y) : count(5) { x = (char * * *) 5; //CHECK: x = (char * * *) 5; char *ch = malloc(sizeof(char)); diff --git a/clang/test/CheckedCRewriter/ptrTOptrcallermulti1.c b/clang/test/CheckedCRewriter/ptrTOptrcallermulti1.c index 21b3b8780bee..f61d6768e507 100644 --- a/clang/test/CheckedCRewriter/ptrTOptrcallermulti1.c +++ b/clang/test/CheckedCRewriter/ptrTOptrcallermulti1.c @@ -110,7 +110,7 @@ int *mul2(int *x) { char *** sus(char * * *, char * * *); //CHECK_NOALL: char *** sus(char * * *, _Ptr<_Ptr<_Ptr>> y); - //CHECK_ALL: _Array_ptr<_Array_ptr> sus(char * * *, _Ptr<_Ptr<_Ptr>> y); + //CHECK_ALL: _Array_ptr<_Array_ptr> sus(char * * *, _Ptr<_Ptr<_Ptr>> y) : count(5); char *** foo() { //CHECK_NOALL: char *** foo(void) { diff --git a/clang/test/CheckedCRewriter/ptrTOptrcallermulti2.c b/clang/test/CheckedCRewriter/ptrTOptrcallermulti2.c index 098a37b1488c..cc7b9416a792 100644 --- a/clang/test/CheckedCRewriter/ptrTOptrcallermulti2.c +++ b/clang/test/CheckedCRewriter/ptrTOptrcallermulti2.c @@ -110,7 +110,7 @@ int *mul2(int *x) { char *** sus(char * * * x, char * * * y) { //CHECK_NOALL: char *** sus(char * * * x, _Ptr<_Ptr<_Ptr>> y) { - //CHECK_ALL: _Array_ptr<_Array_ptr> sus(char * * * x, _Ptr<_Ptr<_Ptr>> y) { + //CHECK_ALL: _Array_ptr<_Array_ptr> sus(char * * * x, _Ptr<_Ptr<_Ptr>> y) : count(5) { x = (char * * *) 5; //CHECK: x = (char * * *) 5; char *ch = malloc(sizeof(char)); diff --git a/clang/test/CheckedCRewriter/ptrTOptrprotoboth.c b/clang/test/CheckedCRewriter/ptrTOptrprotoboth.c index 86675bd2952b..7da0d7f6fd8a 100644 --- a/clang/test/CheckedCRewriter/ptrTOptrprotoboth.c +++ b/clang/test/CheckedCRewriter/ptrTOptrprotoboth.c @@ -142,7 +142,7 @@ x = (char * * *) 5; *ch = 'A'; /*Capital A*/ char *** z = malloc(5*sizeof(char**)); //CHECK_NOALL: char *** z = malloc(5*sizeof(char**)); - //CHECK_ALL: _Array_ptr<_Array_ptr> z : count(5) = malloc<_Array_ptr>(5*sizeof(char**)); + //CHECK_ALL: _Array_ptr<_Array_ptr> z = malloc<_Array_ptr>(5*sizeof(char**)); for(int i = 0; i < 5; i++) { z[i] = malloc(5*sizeof(char *)); //CHECK: z[i] = malloc(5*sizeof(char *)); diff --git a/clang/test/CheckedCRewriter/ptrTOptrprotocallee.c b/clang/test/CheckedCRewriter/ptrTOptrprotocallee.c index 3bcd045815c0..9e7de6f48913 100644 --- a/clang/test/CheckedCRewriter/ptrTOptrprotocallee.c +++ b/clang/test/CheckedCRewriter/ptrTOptrprotocallee.c @@ -141,7 +141,7 @@ x = (char * * *) 5; *ch = 'A'; /*Capital A*/ char *** z = malloc(5*sizeof(char**)); //CHECK_NOALL: char *** z = malloc(5*sizeof(char**)); - //CHECK_ALL: _Array_ptr<_Array_ptr> z : count(5) = malloc<_Array_ptr>(5*sizeof(char**)); + //CHECK_ALL: _Array_ptr<_Array_ptr> z = malloc<_Array_ptr>(5*sizeof(char**)); for(int i = 0; i < 5; i++) { z[i] = malloc(5*sizeof(char *)); //CHECK: z[i] = malloc(5*sizeof(char *)); diff --git a/clang/test/CheckedCRewriter/ptrTOptrprotocaller.c b/clang/test/CheckedCRewriter/ptrTOptrprotocaller.c index 13672020480b..22a26af2a501 100644 --- a/clang/test/CheckedCRewriter/ptrTOptrprotocaller.c +++ b/clang/test/CheckedCRewriter/ptrTOptrprotocaller.c @@ -105,7 +105,7 @@ int *mul2(int *x) { char *** sus(char * * *, char * * *); //CHECK_NOALL: char *** sus(char * * * x, _Ptr<_Ptr<_Ptr>> y); - //CHECK_ALL: _Array_ptr<_Array_ptr> sus(char * * * x, _Ptr<_Ptr<_Ptr>> y); + //CHECK_ALL: _Array_ptr<_Array_ptr> sus(char * * * x, _Ptr<_Ptr<_Ptr>> y) : count(5); char *** foo() { //CHECK_NOALL: char *** foo(void) { @@ -134,7 +134,7 @@ return z; } char *** sus(char * * * x, char * * * y) { //CHECK_NOALL: char *** sus(char * * * x, _Ptr<_Ptr<_Ptr>> y) { - //CHECK_ALL: _Array_ptr<_Array_ptr> sus(char * * * x, _Ptr<_Ptr<_Ptr>> y) { + //CHECK_ALL: _Array_ptr<_Array_ptr> sus(char * * * x, _Ptr<_Ptr<_Ptr>> y) : count(5) { x = (char * * *) 5; //CHECK: x = (char * * *) 5; char *ch = malloc(sizeof(char)); diff --git a/clang/test/CheckedCRewriter/return_not_least.c b/clang/test/CheckedCRewriter/return_not_least.c index 28f62270c59b..c82adb1d3713 100644 --- a/clang/test/CheckedCRewriter/return_not_least.c +++ b/clang/test/CheckedCRewriter/return_not_least.c @@ -47,8 +47,8 @@ int *bar() { //CHECK_NOALL: int *bar(void) { //CHECK_ALL: _Array_ptr bar(void) { int *z = calloc(2, sizeof(int)); - //CHECK_NOALL: int *z = calloc(2, sizeof(int)); - //CHECK_ALL: _Array_ptr z : count(2) = calloc(2, sizeof(int)); + //CHECK_NOALL: int *z = calloc(2, sizeof(int)); + //CHECK_ALL: _Array_ptr z = calloc(2, sizeof(int)); z += 2; return z; } diff --git a/clang/test/CheckedCRewriter/safefptrargboth.c b/clang/test/CheckedCRewriter/safefptrargboth.c index 822b2d77d5d4..8710c60a8ced 100644 --- a/clang/test/CheckedCRewriter/safefptrargboth.c +++ b/clang/test/CheckedCRewriter/safefptrargboth.c @@ -109,7 +109,7 @@ int * sus(int (*x) (int), int (*y) (int)) { //CHECK: x = (int (*) (int)) 5; int *z = calloc(5, sizeof(int)); //CHECK_NOALL: int *z = calloc(5, sizeof(int)); - //CHECK_ALL: _Array_ptr z : count(5) = calloc(5, sizeof(int)); + //CHECK_ALL: _Array_ptr z = calloc(5, sizeof(int)); int i; for(i = 0; i < 5; i++) { //CHECK_NOALL: for(i = 0; i < 5; i++) { diff --git a/clang/test/CheckedCRewriter/safefptrargbothmulti2.c b/clang/test/CheckedCRewriter/safefptrargbothmulti2.c index 917744b6a6e7..1952da3e34e3 100644 --- a/clang/test/CheckedCRewriter/safefptrargbothmulti2.c +++ b/clang/test/CheckedCRewriter/safefptrargbothmulti2.c @@ -117,7 +117,7 @@ int * sus(int (*x) (int), int (*y) (int)) { //CHECK: x = (int (*) (int)) 5; int *z = calloc(5, sizeof(int)); //CHECK_NOALL: int *z = calloc(5, sizeof(int)); - //CHECK_ALL: _Array_ptr z : count(5) = calloc(5, sizeof(int)); + //CHECK_ALL: _Array_ptr z = calloc(5, sizeof(int)); int i; for(i = 0; i < 5; i++) { //CHECK_NOALL: for(i = 0; i < 5; i++) { diff --git a/clang/test/CheckedCRewriter/safefptrargcallee.c b/clang/test/CheckedCRewriter/safefptrargcallee.c index 1ef3f0b722de..684b340041e3 100644 --- a/clang/test/CheckedCRewriter/safefptrargcallee.c +++ b/clang/test/CheckedCRewriter/safefptrargcallee.c @@ -109,7 +109,7 @@ int * sus(int (*x) (int), int (*y) (int)) { //CHECK: x = (int (*) (int)) 5; int *z = calloc(5, sizeof(int)); //CHECK_NOALL: int *z = calloc(5, sizeof(int)); - //CHECK_ALL: _Array_ptr z : count(5) = calloc(5, sizeof(int)); + //CHECK_ALL: _Array_ptr z = calloc(5, sizeof(int)); int i; for(i = 0; i < 5; i++) { //CHECK_NOALL: for(i = 0; i < 5; i++) { diff --git a/clang/test/CheckedCRewriter/safefptrargcalleemulti2.c b/clang/test/CheckedCRewriter/safefptrargcalleemulti2.c index abd4706cb1c7..42631029179d 100644 --- a/clang/test/CheckedCRewriter/safefptrargcalleemulti2.c +++ b/clang/test/CheckedCRewriter/safefptrargcalleemulti2.c @@ -117,7 +117,7 @@ int * sus(int (*x) (int), int (*y) (int)) { //CHECK: x = (int (*) (int)) 5; int *z = calloc(5, sizeof(int)); //CHECK_NOALL: int *z = calloc(5, sizeof(int)); - //CHECK_ALL: _Array_ptr z : count(5) = calloc(5, sizeof(int)); + //CHECK_ALL: _Array_ptr z = calloc(5, sizeof(int)); int i; for(i = 0; i < 5; i++) { //CHECK_NOALL: for(i = 0; i < 5; i++) { diff --git a/clang/test/CheckedCRewriter/safefptrargcaller.c b/clang/test/CheckedCRewriter/safefptrargcaller.c index 03143e381498..e11cf26b49d9 100644 --- a/clang/test/CheckedCRewriter/safefptrargcaller.c +++ b/clang/test/CheckedCRewriter/safefptrargcaller.c @@ -103,7 +103,7 @@ int *mul2(int *x) { int * sus(int (*x) (int), int (*y) (int)) { //CHECK_NOALL: int * sus(int (*x) (int), _Ptr y) { - //CHECK_ALL: _Array_ptr sus(int (*x) (int), _Ptr y) { + //CHECK_ALL: _Array_ptr sus(int (*x) (int), _Ptr y) : count(5) { x = (int (*) (int)) 5; //CHECK: x = (int (*) (int)) 5; @@ -121,7 +121,7 @@ return z; } int * foo() { //CHECK_NOALL: int * foo(void) { - //CHECK_ALL: _Array_ptr foo(void) { + //CHECK_ALL: _Array_ptr foo(void) : count(5) { int (*x)(int) = add1; //CHECK: int (*x)(int) = add1; @@ -129,7 +129,7 @@ int * foo() { //CHECK: _Ptr y = sub1; int *z = sus(x, y); //CHECK_NOALL: int *z = sus(x, y); - //CHECK_ALL: _Array_ptr z = sus(x, y); + //CHECK_ALL: _Array_ptr z : count(5) = sus(x, y); return z; } diff --git a/clang/test/CheckedCRewriter/safefptrargcallermulti1.c b/clang/test/CheckedCRewriter/safefptrargcallermulti1.c index fd9c06e24e58..5f833736071a 100644 --- a/clang/test/CheckedCRewriter/safefptrargcallermulti1.c +++ b/clang/test/CheckedCRewriter/safefptrargcallermulti1.c @@ -111,11 +111,11 @@ int *mul2(int *x) { int * sus(int (*) (int), int (*) (int)); //CHECK_NOALL: int * sus(int (*) (int), _Ptr y); - //CHECK_ALL: _Array_ptr sus(int (*) (int), _Ptr y); + //CHECK_ALL: _Array_ptr sus(int (*) (int), _Ptr y) : count(5); int * foo() { //CHECK_NOALL: int * foo(void) { - //CHECK_ALL: _Array_ptr foo(void) { + //CHECK_ALL: _Array_ptr foo(void) : count(5) { int (*x)(int) = add1; //CHECK: int (*x)(int) = add1; @@ -123,7 +123,7 @@ int * foo() { //CHECK: _Ptr y = sub1; int *z = sus(x, y); //CHECK_NOALL: int *z = sus(x, y); - //CHECK_ALL: _Array_ptr z = sus(x, y); + //CHECK_ALL: _Array_ptr z : count(5) = sus(x, y); return z; } diff --git a/clang/test/CheckedCRewriter/safefptrargcallermulti2.c b/clang/test/CheckedCRewriter/safefptrargcallermulti2.c index f75a5d01676e..fb2c00ae6aa1 100644 --- a/clang/test/CheckedCRewriter/safefptrargcallermulti2.c +++ b/clang/test/CheckedCRewriter/safefptrargcallermulti2.c @@ -111,7 +111,7 @@ int *mul2(int *x) { int * sus(int (*x) (int), int (*y) (int)) { //CHECK_NOALL: int * sus(int (*x) (int), _Ptr y) { - //CHECK_ALL: _Array_ptr sus(int (*x) (int), _Ptr y) { + //CHECK_ALL: _Array_ptr sus(int (*x) (int), _Ptr y) : count(5) { x = (int (*) (int)) 5; //CHECK: x = (int (*) (int)) 5; diff --git a/clang/test/CheckedCRewriter/safefptrargprotoboth.c b/clang/test/CheckedCRewriter/safefptrargprotoboth.c index d9c024b9b304..a2f755502168 100644 --- a/clang/test/CheckedCRewriter/safefptrargprotoboth.c +++ b/clang/test/CheckedCRewriter/safefptrargprotoboth.c @@ -145,7 +145,7 @@ int * sus(int (*x) (int), int (*y) (int)) { //CHECK: x = (int (*) (int)) 5; int *z = calloc(5, sizeof(int)); //CHECK_NOALL: int *z = calloc(5, sizeof(int)); - //CHECK_ALL: _Array_ptr z : count(5) = calloc(5, sizeof(int)); + //CHECK_ALL: _Array_ptr z = calloc(5, sizeof(int)); int i; for(i = 0; i < 5; i++) { //CHECK_NOALL: for(i = 0; i < 5; i++) { diff --git a/clang/test/CheckedCRewriter/safefptrargprotocallee.c b/clang/test/CheckedCRewriter/safefptrargprotocallee.c index a31ce6421462..e68a75fc8841 100644 --- a/clang/test/CheckedCRewriter/safefptrargprotocallee.c +++ b/clang/test/CheckedCRewriter/safefptrargprotocallee.c @@ -144,7 +144,7 @@ int * sus(int (*x) (int), int (*y) (int)) { //CHECK: x = (int (*) (int)) 5; int *z = calloc(5, sizeof(int)); //CHECK_NOALL: int *z = calloc(5, sizeof(int)); - //CHECK_ALL: _Array_ptr z : count(5) = calloc(5, sizeof(int)); + //CHECK_ALL: _Array_ptr z = calloc(5, sizeof(int)); int i; for(i = 0; i < 5; i++) { //CHECK_NOALL: for(i = 0; i < 5; i++) { diff --git a/clang/test/CheckedCRewriter/safefptrargprotocaller.c b/clang/test/CheckedCRewriter/safefptrargprotocaller.c index 572a1d5ee0b7..4122d7be747b 100644 --- a/clang/test/CheckedCRewriter/safefptrargprotocaller.c +++ b/clang/test/CheckedCRewriter/safefptrargprotocaller.c @@ -106,11 +106,11 @@ int *mul2(int *x) { int * sus(int (*) (int), int (*) (int)); //CHECK_NOALL: int * sus(int (*x) (int), _Ptr y); - //CHECK_ALL: _Array_ptr sus(int (*x) (int), _Ptr y); + //CHECK_ALL: _Array_ptr sus(int (*x) (int), _Ptr y) : count(5); int * foo() { //CHECK_NOALL: int * foo(void) { - //CHECK_ALL: _Array_ptr foo(void) { + //CHECK_ALL: _Array_ptr foo(void) : count(5) { int (*x)(int) = add1; //CHECK: int (*x)(int) = add1; @@ -118,7 +118,7 @@ int * foo() { //CHECK: _Ptr y = sub1; int *z = sus(x, y); //CHECK_NOALL: int *z = sus(x, y); - //CHECK_ALL: _Array_ptr z = sus(x, y); + //CHECK_ALL: _Array_ptr z : count(5) = sus(x, y); return z; } @@ -139,7 +139,7 @@ return z; } int * sus(int (*x) (int), int (*y) (int)) { //CHECK_NOALL: int * sus(int (*x) (int), _Ptr y) { - //CHECK_ALL: _Array_ptr sus(int (*x) (int), _Ptr y) { + //CHECK_ALL: _Array_ptr sus(int (*x) (int), _Ptr y) : count(5) { x = (int (*) (int)) 5; //CHECK: x = (int (*) (int)) 5; diff --git a/clang/test/CheckedCRewriter/safefptrargprotosafe.c b/clang/test/CheckedCRewriter/safefptrargprotosafe.c index ee468506f3a0..48772803b5ef 100644 --- a/clang/test/CheckedCRewriter/safefptrargprotosafe.c +++ b/clang/test/CheckedCRewriter/safefptrargprotosafe.c @@ -105,11 +105,11 @@ int *mul2(int *x) { int * sus(int (*) (int), int (*) (int)); //CHECK_NOALL: int * sus(int (*x) (int), _Ptr y); - //CHECK_ALL: _Array_ptr sus(int (*x) (int), _Ptr y); + //CHECK_ALL: _Array_ptr sus(int (*x) (int), _Ptr y) : count(5); int * foo() { //CHECK_NOALL: int * foo(void) { - //CHECK_ALL: _Array_ptr foo(void) { + //CHECK_ALL: _Array_ptr foo(void) : count(5) { int (*x)(int) = add1; //CHECK: int (*x)(int) = add1; @@ -117,13 +117,13 @@ int * foo() { //CHECK: _Ptr y = sub1; int *z = sus(x, y); //CHECK_NOALL: int *z = sus(x, y); - //CHECK_ALL: _Array_ptr z = sus(x, y); + //CHECK_ALL: _Array_ptr z : count(5) = sus(x, y); return z; } int * bar() { //CHECK_NOALL: int * bar(void) { - //CHECK_ALL: _Array_ptr bar(void) { + //CHECK_ALL: _Array_ptr bar(void) : count(5) { int (*x)(int) = add1; //CHECK: int (*x)(int) = add1; @@ -131,13 +131,13 @@ int * bar() { //CHECK: _Ptr y = sub1; int *z = sus(x, y); //CHECK_NOALL: int *z = sus(x, y); - //CHECK_ALL: _Array_ptr z = sus(x, y); + //CHECK_ALL: _Array_ptr z : count(5) = sus(x, y); return z; } int * sus(int (*x) (int), int (*y) (int)) { //CHECK_NOALL: int * sus(int (*x) (int), _Ptr y) { - //CHECK_ALL: _Array_ptr sus(int (*x) (int), _Ptr y) { + //CHECK_ALL: _Array_ptr sus(int (*x) (int), _Ptr y) : count(5) { x = (int (*) (int)) 5; //CHECK: x = (int (*) (int)) 5; diff --git a/clang/test/CheckedCRewriter/safefptrargsafe.c b/clang/test/CheckedCRewriter/safefptrargsafe.c index c3ecf3da0bfa..f7096456ec76 100644 --- a/clang/test/CheckedCRewriter/safefptrargsafe.c +++ b/clang/test/CheckedCRewriter/safefptrargsafe.c @@ -102,7 +102,7 @@ int *mul2(int *x) { int * sus(int (*x) (int), int (*y) (int)) { //CHECK_NOALL: int * sus(int (*x) (int), _Ptr y) { - //CHECK_ALL: _Array_ptr sus(int (*x) (int), _Ptr y) { + //CHECK_ALL: _Array_ptr sus(int (*x) (int), _Ptr y) : count(5) { x = (int (*) (int)) 5; //CHECK: x = (int (*) (int)) 5; @@ -120,7 +120,7 @@ return z; } int * foo() { //CHECK_NOALL: int * foo(void) { - //CHECK_ALL: _Array_ptr foo(void) { + //CHECK_ALL: _Array_ptr foo(void) : count(5) { int (*x)(int) = add1; //CHECK: int (*x)(int) = add1; @@ -128,13 +128,13 @@ int * foo() { //CHECK: _Ptr y = sub1; int *z = sus(x, y); //CHECK_NOALL: int *z = sus(x, y); - //CHECK_ALL: _Array_ptr z = sus(x, y); + //CHECK_ALL: _Array_ptr z : count(5) = sus(x, y); return z; } int * bar() { //CHECK_NOALL: int * bar(void) { - //CHECK_ALL: _Array_ptr bar(void) { + //CHECK_ALL: _Array_ptr bar(void) : count(5) { int (*x)(int) = add1; //CHECK: int (*x)(int) = add1; @@ -142,6 +142,6 @@ int * bar() { //CHECK: _Ptr y = sub1; int *z = sus(x, y); //CHECK_NOALL: int *z = sus(x, y); - //CHECK_ALL: _Array_ptr z = sus(x, y); + //CHECK_ALL: _Array_ptr z : count(5) = sus(x, y); return z; } diff --git a/clang/test/CheckedCRewriter/safefptrargsafemulti1.c b/clang/test/CheckedCRewriter/safefptrargsafemulti1.c index 27b111efb004..833dbf292c62 100644 --- a/clang/test/CheckedCRewriter/safefptrargsafemulti1.c +++ b/clang/test/CheckedCRewriter/safefptrargsafemulti1.c @@ -110,11 +110,11 @@ int *mul2(int *x) { int * sus(int (*) (int), int (*) (int)); //CHECK_NOALL: int * sus(int (*) (int), _Ptr y); - //CHECK_ALL: _Array_ptr sus(int (*) (int), _Ptr y); + //CHECK_ALL: _Array_ptr sus(int (*) (int), _Ptr y) : count(5); int * foo() { //CHECK_NOALL: int * foo(void) { - //CHECK_ALL: _Array_ptr foo(void) { + //CHECK_ALL: _Array_ptr foo(void) : count(5) { int (*x)(int) = add1; //CHECK: int (*x)(int) = add1; @@ -122,13 +122,13 @@ int * foo() { //CHECK: _Ptr y = sub1; int *z = sus(x, y); //CHECK_NOALL: int *z = sus(x, y); - //CHECK_ALL: _Array_ptr z = sus(x, y); + //CHECK_ALL: _Array_ptr z : count(5) = sus(x, y); return z; } int * bar() { //CHECK_NOALL: int * bar(void) { - //CHECK_ALL: _Array_ptr bar(void) { + //CHECK_ALL: _Array_ptr bar(void) : count(5) { int (*x)(int) = add1; //CHECK: int (*x)(int) = add1; @@ -136,6 +136,6 @@ int * bar() { //CHECK: _Ptr y = sub1; int *z = sus(x, y); //CHECK_NOALL: int *z = sus(x, y); - //CHECK_ALL: _Array_ptr z = sus(x, y); + //CHECK_ALL: _Array_ptr z : count(5) = sus(x, y); return z; } diff --git a/clang/test/CheckedCRewriter/safefptrargsafemulti2.c b/clang/test/CheckedCRewriter/safefptrargsafemulti2.c index 68435467be3a..2ebbc45a16f8 100644 --- a/clang/test/CheckedCRewriter/safefptrargsafemulti2.c +++ b/clang/test/CheckedCRewriter/safefptrargsafemulti2.c @@ -110,7 +110,7 @@ int *mul2(int *x) { int * sus(int (*x) (int), int (*y) (int)) { //CHECK_NOALL: int * sus(int (*x) (int), _Ptr y) { - //CHECK_ALL: _Array_ptr sus(int (*x) (int), _Ptr y) { + //CHECK_ALL: _Array_ptr sus(int (*x) (int), _Ptr y) : count(5) { x = (int (*) (int)) 5; //CHECK: x = (int (*) (int)) 5; diff --git a/clang/test/CheckedCRewriter/treeBUG.c b/clang/test/CheckedCRewriter/tree.c similarity index 97% rename from clang/test/CheckedCRewriter/treeBUG.c rename to clang/test/CheckedCRewriter/tree.c index db584cd579cf..7f9e4eebbaff 100644 --- a/clang/test/CheckedCRewriter/treeBUG.c +++ b/clang/test/CheckedCRewriter/tree.c @@ -1,7 +1,6 @@ // RUN: cconv-standalone -alltypes %s -- | FileCheck -match-full-lines -check-prefixes="CHECK_ALL","CHECK" %s // RUN: cconv-standalone %s -- | FileCheck -match-full-lines -check-prefixes="CHECK_NOALL","CHECK" %s // RUN: cconv-standalone %s -- | %clang -c -fcheckedc-extension -x c -o /dev/null - -// XFAIL: * #include extern _Itype_for_any(T) void *calloc(size_t nmemb, size_t size) : itype(_Array_ptr) byte_count(nmemb * size); @@ -17,7 +16,7 @@ struct tree { struct tree *parent; //CHECK: _Ptr parent; struct tree **children; -// FIX_CHECK_ALL: _Array_ptr<_Ptr> children : count(len); +//CHECK_ALL: _Array_ptr<_Ptr> children : count(len); //CHECK_NOALL: struct tree **children; int len; int child_count;