diff options
author | Hans Wennborg <hans@hanshq.net> | 2012-08-07 08:59:46 +0000 |
---|---|---|
committer | Hans Wennborg <hans@hanshq.net> | 2012-08-07 08:59:46 +0000 |
commit | 58e1e54476d610d6c33ef483f216ed8a1282d35c (patch) | |
tree | 53ddc9b5444c8e4da14bfcf799a740466ed66a3d /include/clang/Analysis/Analyses/FormatString.h | |
parent | 5d435b6001fb853747426bfa47b0e0f49a736fe4 (diff) |
Remove ScanfArgType and bake that logic into ArgType.
This is useful for example for %n in printf, which expects
a pointer to int with the same logic for checking as %d
would have in scanf.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@161407 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/clang/Analysis/Analyses/FormatString.h')
-rw-r--r-- | include/clang/Analysis/Analyses/FormatString.h | 43 |
1 files changed, 14 insertions, 29 deletions
diff --git a/include/clang/Analysis/Analyses/FormatString.h b/include/clang/Analysis/Analyses/FormatString.h index 45779099d1..7f50ee392b 100644 --- a/include/clang/Analysis/Analyses/FormatString.h +++ b/include/clang/Analysis/Analyses/FormatString.h @@ -209,15 +209,24 @@ private: const Kind K; QualType T; const char *Name; + bool Ptr; public: - ArgType(Kind k = UnknownTy, const char *n = 0) : K(k), Name(n) {} - ArgType(QualType t, const char *n = 0) : K(SpecificTy), T(t), Name(n) {} - ArgType(CanQualType t) : K(SpecificTy), T(t), Name(0) {} + ArgType(Kind k = UnknownTy, const char *n = 0) : K(k), Name(n), Ptr(false) {} + ArgType(QualType t, const char *n = 0) + : K(SpecificTy), T(t), Name(n), Ptr(false) {} + ArgType(CanQualType t) : K(SpecificTy), T(t), Name(0), Ptr(false) {} static ArgType Invalid() { return ArgType(InvalidTy); } - bool isValid() const { return K != InvalidTy; } + /// Create an ArgType which corresponds to the type pointer to A. + static ArgType PtrTo(const ArgType& A) { + assert(A.K >= InvalidTy && "ArgType cannot be pointer to invalid/unknown"); + ArgType Res = A; + Res.Ptr = true; + return Res; + } + bool matchesType(ASTContext &C, QualType argTy) const; QualType getRepresentativeType(ASTContext &C) const; @@ -517,30 +526,6 @@ using analyze_format_string::LengthModifier; using analyze_format_string::OptionalAmount; using analyze_format_string::OptionalFlag; -class ScanfArgType : public ArgType { -public: - enum Kind { UnknownTy, InvalidTy, CStrTy, WCStrTy, PtrToArgTypeTy }; -private: - Kind K; - ArgType A; - const char *Name; - QualType getRepresentativeType(ASTContext &C) const; -public: - ScanfArgType(Kind k = UnknownTy, const char* n = 0) : K(k), Name(n) {} - ScanfArgType(ArgType a, const char *n = 0) - : K(PtrToArgTypeTy), A(a), Name(n) { - assert(A.isValid()); - } - - static ScanfArgType Invalid() { return ScanfArgType(InvalidTy); } - - bool isValid() const { return K != InvalidTy; } - - bool matchesType(ASTContext& C, QualType argTy) const; - - std::string getRepresentativeTypeName(ASTContext& C) const; -}; - class ScanfSpecifier : public analyze_format_string::FormatSpecifier { OptionalFlag SuppressAssignment; // '*' public: @@ -569,7 +554,7 @@ public: return CS.consumesDataArgument() && !SuppressAssignment; } - ScanfArgType getArgType(ASTContext &Ctx) const; + ArgType getArgType(ASTContext &Ctx) const; bool fixType(QualType QT, const LangOptions &LangOpt, ASTContext &Ctx); |