diff options
author | Pascal Stumpf <pascal@cvs.openbsd.org> | 2016-09-03 22:46:58 +0000 |
---|---|---|
committer | Pascal Stumpf <pascal@cvs.openbsd.org> | 2016-09-03 22:46:58 +0000 |
commit | 82a2d5f499b831e8b5424fe14d4ff2f5662b89dc (patch) | |
tree | 78b7bd9e1d30d255be80de4c36e65cab2739dab1 | |
parent | 8b09d0d01f5d7d9e2aaced50adf31510e4cb3758 (diff) |
Use the space freed up by sparc and zaurus to import LLVM.
ok hackroom@
-rw-r--r-- | gnu/llvm/tools/clang/include/clang/Analysis/Analyses/FormatString.h | 61 | ||||
-rw-r--r-- | gnu/llvm/tools/clang/lib/Analysis/FormatString.cpp | 64 |
2 files changed, 31 insertions, 94 deletions
diff --git a/gnu/llvm/tools/clang/include/clang/Analysis/Analyses/FormatString.h b/gnu/llvm/tools/clang/include/clang/Analysis/Analyses/FormatString.h index 8c531d638cc..4471311a339 100644 --- a/gnu/llvm/tools/clang/include/clang/Analysis/Analyses/FormatString.h +++ b/gnu/llvm/tools/clang/include/clang/Analysis/Analyses/FormatString.h @@ -35,7 +35,7 @@ class OptionalFlag { public: OptionalFlag(const char *Representation) : representation(Representation), flag(false) {} - bool isSet() const { return flag; } + bool isSet() { return flag; } void set() { flag = true; } void clear() { flag = false; } void setPosition(const char *position) { @@ -122,13 +122,12 @@ class ConversionSpecifier { public: enum Kind { InvalidSpecifier = 0, - // C99 conversion specifiers. + // C99 conversion specifiers. cArg, dArg, DArg, // Apple extension iArg, - IntArgBeg = dArg, - IntArgEnd = iArg, + IntArgBeg = dArg, IntArgEnd = iArg, oArg, OArg, // Apple extension @@ -136,8 +135,7 @@ public: UArg, // Apple extension xArg, XArg, - UIntArgBeg = oArg, - UIntArgEnd = XArg, + UIntArgBeg = oArg, UIntArgEnd = XArg, fArg, FArg, @@ -147,8 +145,7 @@ public: GArg, aArg, AArg, - DoubleArgBeg = fArg, - DoubleArgEnd = AArg, + DoubleArgBeg = fArg, DoubleArgEnd = AArg, sArg, pArg, @@ -157,19 +154,13 @@ public: CArg, SArg, - // Apple extension: P specifies to os_log that the data being pointed to is - // to be copied by os_log. The precision indicates the number of bytes to - // copy. - PArg, - // ** Printf-specific ** ZArg, // MS extension // Objective-C specific specifiers. - ObjCObjArg, // '@' - ObjCBeg = ObjCObjArg, - ObjCEnd = ObjCObjArg, + ObjCObjArg, // '@' + ObjCBeg = ObjCObjArg, ObjCEnd = ObjCObjArg, // FreeBSD kernel specific specifiers. FreeBSDbArg, @@ -178,15 +169,13 @@ public: FreeBSDyArg, // GlibC specific specifiers. - PrintErrno, // 'm' + PrintErrno, // 'm' - PrintfConvBeg = ObjCObjArg, - PrintfConvEnd = PrintErrno, + PrintfConvBeg = ObjCObjArg, PrintfConvEnd = PrintErrno, // ** Scanf-specific ** ScanListArg, // '[' - ScanfConvBeg = ScanListArg, - ScanfConvEnd = ScanListArg + ScanfConvBeg = ScanListArg, ScanfConvEnd = ScanListArg }; ConversionSpecifier(bool isPrintf = true) @@ -211,8 +200,6 @@ public: return false; case PercentArg: return false; - case InvalidSpecifier: - return false; default: return true; } @@ -223,16 +210,11 @@ public: unsigned getLength() const { return EndScanList ? EndScanList - Position : 1; } - void setEndScanList(const char *pos) { EndScanList = pos; } bool isIntArg() const { return (kind >= IntArgBeg && kind <= IntArgEnd) || kind == FreeBSDrArg || kind == FreeBSDyArg; } bool isUIntArg() const { return kind >= UIntArgBeg && kind <= UIntArgEnd; } bool isAnyIntArg() const { return kind >= IntArgBeg && kind <= UIntArgEnd; } - bool isDoubleArg() const { - return kind >= DoubleArgBeg && kind <= DoubleArgEnd; - } - const char *toString() const; bool isPrintfKind() const { return IsPrintf; } @@ -431,6 +413,11 @@ public: bool isObjCArg() const { return kind >= ObjCBeg && kind <= ObjCEnd; } bool isDoubleArg() const { return kind >= DoubleArgBeg && kind <= DoubleArgEnd; } + unsigned getLength() const { + // Conversion specifiers currently only are represented by + // single characters, but we be flexible. + return 1; + } static bool classof(const analyze_format_string::ConversionSpecifier *CS) { return CS->isPrintfKind(); @@ -450,15 +437,13 @@ class PrintfSpecifier : public analyze_format_string::FormatSpecifier { OptionalFlag HasAlternativeForm; // '#' OptionalFlag HasLeadingZeroes; // '0' OptionalFlag HasObjCTechnicalTerm; // '[tt]' - OptionalFlag IsPrivate; // '{private}' - OptionalFlag IsPublic; // '{public}' OptionalAmount Precision; public: - PrintfSpecifier() - : FormatSpecifier(/* isPrintf = */ true), HasThousandsGrouping("'"), - IsLeftJustified("-"), HasPlusPrefix("+"), HasSpacePrefix(" "), - HasAlternativeForm("#"), HasLeadingZeroes("0"), - HasObjCTechnicalTerm("tt"), IsPrivate("private"), IsPublic("public") {} + PrintfSpecifier() : + FormatSpecifier(/* isPrintf = */ true), + HasThousandsGrouping("'"), IsLeftJustified("-"), HasPlusPrefix("+"), + HasSpacePrefix(" "), HasAlternativeForm("#"), HasLeadingZeroes("0"), + HasObjCTechnicalTerm("tt") {} static PrintfSpecifier Parse(const char *beg, const char *end); @@ -487,8 +472,6 @@ public: void setHasObjCTechnicalTerm(const char *position) { HasObjCTechnicalTerm.setPosition(position); } - void setIsPrivate(const char *position) { IsPrivate.setPosition(position); } - void setIsPublic(const char *position) { IsPublic.setPosition(position); } void setUsesPositionalArg() { UsesPositionalArg = true; } // Methods for querying the format specifier. @@ -526,8 +509,6 @@ public: const OptionalFlag &hasLeadingZeros() const { return HasLeadingZeroes; } const OptionalFlag &hasSpacePrefix() const { return HasSpacePrefix; } const OptionalFlag &hasObjCTechnicalTerm() const { return HasObjCTechnicalTerm; } - const OptionalFlag &isPrivate() const { return IsPrivate; } - const OptionalFlag &isPublic() const { return IsPublic; } bool usesPositionalArg() const { return UsesPositionalArg; } /// Changes the specifier and length according to a QualType, retaining any @@ -565,6 +546,8 @@ public: ScanfConversionSpecifier(const char *pos, Kind k) : ConversionSpecifier(false, pos, k) {} + void setEndScanList(const char *pos) { EndScanList = pos; } + static bool classof(const analyze_format_string::ConversionSpecifier *CS) { return !CS->isPrintfKind(); } diff --git a/gnu/llvm/tools/clang/lib/Analysis/FormatString.cpp b/gnu/llvm/tools/clang/lib/Analysis/FormatString.cpp index c62e537e92d..0948bc0b08a 100644 --- a/gnu/llvm/tools/clang/lib/Analysis/FormatString.cpp +++ b/gnu/llvm/tools/clang/lib/Analysis/FormatString.cpp @@ -15,7 +15,6 @@ #include "FormatStringParsing.h" #include "clang/Basic/LangOptions.h" #include "clang/Basic/TargetInfo.h" -#include "llvm/Support/ConvertUTF.h" using clang::analyze_format_string::ArgType; using clang::analyze_format_string::FormatStringHandler; @@ -191,21 +190,13 @@ clang::analyze_format_string::ParseLengthModifier(FormatSpecifier &FS, return false; case 'h': ++I; - if (I != E && *I == 'h') { - ++I; - lmKind = LengthModifier::AsChar; - } else { - lmKind = LengthModifier::AsShort; - } + lmKind = (I != E && *I == 'h') ? (++I, LengthModifier::AsChar) + : LengthModifier::AsShort; break; case 'l': ++I; - if (I != E && *I == 'l') { - ++I; - lmKind = LengthModifier::AsLongLong; - } else { - lmKind = LengthModifier::AsLong; - } + lmKind = (I != E && *I == 'l') ? (++I, LengthModifier::AsLongLong) + : LengthModifier::AsLong; break; case 'j': lmKind = LengthModifier::AsIntMax; ++I; break; case 'z': lmKind = LengthModifier::AsSizeT; ++I; break; @@ -261,29 +252,6 @@ clang::analyze_format_string::ParseLengthModifier(FormatSpecifier &FS, return true; } -bool clang::analyze_format_string::ParseUTF8InvalidSpecifier( - const char *SpecifierBegin, const char *FmtStrEnd, unsigned &Len) { - if (SpecifierBegin + 1 >= FmtStrEnd) - return false; - - const llvm::UTF8 *SB = - reinterpret_cast<const llvm::UTF8 *>(SpecifierBegin + 1); - const llvm::UTF8 *SE = reinterpret_cast<const llvm::UTF8 *>(FmtStrEnd); - const char FirstByte = *SB; - - // If the invalid specifier is a multibyte UTF-8 string, return the - // total length accordingly so that the conversion specifier can be - // properly updated to reflect a complete UTF-8 specifier. - unsigned NumBytes = llvm::getNumBytesForUTF8(FirstByte); - if (NumBytes == 1) - return false; - if (SB + NumBytes > SE) - return false; - - Len = NumBytes + 1; - return true; -} - //===----------------------------------------------------------------------===// // Methods on ArgType. //===----------------------------------------------------------------------===// @@ -311,13 +279,8 @@ ArgType::matchesType(ASTContext &C, QualType argTy) const { return Match; case AnyCharTy: { - if (const EnumType *ETy = argTy->getAs<EnumType>()) { - // If the enum is incomplete we know nothing about the underlying type. - // Assume that it's 'int'. - if (!ETy->getDecl()->isComplete()) - return NoMatch; + if (const EnumType *ETy = argTy->getAs<EnumType>()) argTy = ETy->getDecl()->getIntegerType(); - } if (const BuiltinType *BT = argTy->getAs<BuiltinType>()) switch (BT->getKind()) { @@ -333,14 +296,8 @@ ArgType::matchesType(ASTContext &C, QualType argTy) const { } case SpecificTy: { - if (const EnumType *ETy = argTy->getAs<EnumType>()) { - // If the enum is incomplete we know nothing about the underlying type. - // Assume that it's 'int'. - if (!ETy->getDecl()->isComplete()) - argTy = C.IntTy; - else - argTy = ETy->getDecl()->getIntegerType(); - } + if (const EnumType *ETy = argTy->getAs<EnumType>()) + argTy = ETy->getDecl()->getIntegerType(); argTy = C.getCanonicalType(argTy).getUnqualifiedType(); if (T == argTy) @@ -591,8 +548,6 @@ const char *ConversionSpecifier::toString() const { case cArg: return "c"; case sArg: return "s"; case pArg: return "p"; - case PArg: - return "P"; case nArg: return "n"; case PercentArg: return "%"; case ScanListArg: return "["; @@ -708,7 +663,7 @@ bool FormatSpecifier::hasValidLengthModifier(const TargetInfo &Target) const { return true; case ConversionSpecifier::FreeBSDrArg: case ConversionSpecifier::FreeBSDyArg: - return Target.getTriple().isOSFreeBSD() || Target.getTriple().isPS4(); + return Target.getTriple().isOSFreeBSD(); default: return false; } @@ -741,7 +696,7 @@ bool FormatSpecifier::hasValidLengthModifier(const TargetInfo &Target) const { return true; case ConversionSpecifier::FreeBSDrArg: case ConversionSpecifier::FreeBSDyArg: - return Target.getTriple().isOSFreeBSD() || Target.getTriple().isPS4(); + return Target.getTriple().isOSFreeBSD(); default: return false; } @@ -868,7 +823,6 @@ bool FormatSpecifier::hasStandardConversionSpecifier( case ConversionSpecifier::ObjCObjArg: case ConversionSpecifier::ScanListArg: case ConversionSpecifier::PercentArg: - case ConversionSpecifier::PArg: return true; case ConversionSpecifier::CArg: case ConversionSpecifier::SArg: |