diff options
Diffstat (limited to 'lib/Analysis')
-rw-r--r-- | lib/Analysis/FormatString.cpp | 30 | ||||
-rw-r--r-- | lib/Analysis/PrintfFormatString.cpp | 8 | ||||
-rw-r--r-- | lib/Analysis/ScanfFormatString.cpp | 8 |
3 files changed, 37 insertions, 9 deletions
diff --git a/lib/Analysis/FormatString.cpp b/lib/Analysis/FormatString.cpp index e7ea48688d..45c722a5d5 100644 --- a/lib/Analysis/FormatString.cpp +++ b/lib/Analysis/FormatString.cpp @@ -14,6 +14,7 @@ #include "FormatStringParsing.h" #include "clang/Basic/LangOptions.h" +#include "clang/Basic/TargetInfo.h" using clang::analyze_format_string::ArgType; using clang::analyze_format_string::FormatStringHandler; @@ -548,7 +549,7 @@ void OptionalAmount::toString(raw_ostream &os) const { } } -bool FormatSpecifier::hasValidLengthModifier() const { +bool FormatSpecifier::hasValidLengthModifier(const TargetInfo &Target) const { switch (LM.getKind()) { case LengthModifier::None: return true; @@ -611,14 +612,15 @@ bool FormatSpecifier::hasValidLengthModifier() const { case ConversionSpecifier::gArg: case ConversionSpecifier::GArg: return true; - // GNU extension. + // GNU libc extension. case ConversionSpecifier::dArg: case ConversionSpecifier::iArg: case ConversionSpecifier::oArg: case ConversionSpecifier::uArg: case ConversionSpecifier::xArg: case ConversionSpecifier::XArg: - return true; + return !Target.getTriple().isOSDarwin() && + !Target.getTriple().isOSWindows(); default: return false; } @@ -719,6 +721,28 @@ bool FormatSpecifier::hasStandardLengthConversionCombination() const { return true; } +llvm::Optional<LengthModifier> +FormatSpecifier::getCorrectedLengthModifier() const { + if (LM.getKind() == LengthModifier::AsLongDouble) { + switch (CS.getKind()) { + case ConversionSpecifier::dArg: + case ConversionSpecifier::iArg: + case ConversionSpecifier::oArg: + case ConversionSpecifier::uArg: + case ConversionSpecifier::xArg: + case ConversionSpecifier::XArg: { + LengthModifier FixedLM(LM); + FixedLM.setKind(LengthModifier::AsLongLong); + return FixedLM; + } + default: + break; + } + } + + return llvm::Optional<LengthModifier>(); +} + bool FormatSpecifier::namedTypeToLengthModifier(QualType QT, LengthModifier &LM) { assert(isa<TypedefType>(QT) && "Expected a TypedefType"); diff --git a/lib/Analysis/PrintfFormatString.cpp b/lib/Analysis/PrintfFormatString.cpp index 9e4c0fec4c..9a4f0ca6bb 100644 --- a/lib/Analysis/PrintfFormatString.cpp +++ b/lib/Analysis/PrintfFormatString.cpp @@ -482,9 +482,11 @@ bool PrintfSpecifier::fixType(QualType QT, const LangOptions &LangOpt, namedTypeToLengthModifier(QT, LM); // If fixing the length modifier was enough, we are done. - const analyze_printf::ArgType &ATR = getArgType(Ctx, IsObjCLiteral); - if (hasValidLengthModifier() && ATR.isValid() && ATR.matchesType(Ctx, QT)) - return true; + if (hasValidLengthModifier(Ctx.getTargetInfo())) { + const analyze_printf::ArgType &ATR = getArgType(Ctx, IsObjCLiteral); + if (ATR.isValid() && ATR.matchesType(Ctx, QT)) + return true; + } // Set conversion specifier and disable any flags which do not apply to it. // Let typedefs to char fall through to int, as %c is silly for uint8_t. diff --git a/lib/Analysis/ScanfFormatString.cpp b/lib/Analysis/ScanfFormatString.cpp index 2942400621..082c06af58 100644 --- a/lib/Analysis/ScanfFormatString.cpp +++ b/lib/Analysis/ScanfFormatString.cpp @@ -430,9 +430,11 @@ bool ScanfSpecifier::fixType(QualType QT, const LangOptions &LangOpt, namedTypeToLengthModifier(PT, LM); // If fixing the length modifier was enough, we are done. - const analyze_scanf::ArgType &AT = getArgType(Ctx); - if (hasValidLengthModifier() && AT.isValid() && AT.matchesType(Ctx, QT)) - return true; + if (hasValidLengthModifier(Ctx.getTargetInfo())) { + const analyze_scanf::ArgType &AT = getArgType(Ctx); + if (AT.isValid() && AT.matchesType(Ctx, QT)) + return true; + } // Figure out the conversion specifier. if (PT->isRealFloatingType()) |