26 using namespace clang;
38 const char *Start,
const char *&Beg,
const char *E,
53 const char *FlagBeg,
const char *E,
bool Warn) {
54 StringRef Flag(FlagBeg, E - FlagBeg);
77 bool isFreeBSDKPrintf) {
79 using namespace clang::analyze_format_string;
80 using namespace clang::analyze_printf;
83 const char *Start =
nullptr;
87 for ( ; I != E ; ++I) {
124 for ( ; I != E; ++I) {
126 default: hasMore =
false;
break;
129 FS.setHasThousandsGrouping(I);
131 case '-': FS.setIsLeftJustified(I);
break;
132 case '+': FS.setHasPlusPrefix(I);
break;
133 case ' ': FS.setHasSpacePrefix(I);
break;
134 case '#': FS.setHasAlternativeForm(I);
break;
135 case '0': FS.setHasLeadingZeros(I);
break;
150 FS.usesPositionalArg() ?
nullptr : &argIndex))
170 FS.usesPositionalArg() ?
nullptr : &argIndex))
195 const char *ObjCModifierFlagsStart =
nullptr,
196 *ObjCModifierFlagsEnd =
nullptr;
198 ObjCModifierFlagsStart = I;
202 ObjCModifierFlagsEnd = I;
228 const char *conversionPosition = I++;
230 switch (*conversionPosition) {
262 if (isFreeBSDKPrintf)
266 if (isFreeBSDKPrintf)
270 if (isFreeBSDKPrintf)
275 if (isFreeBSDKPrintf)
277 else if (Target.
getTriple().isOSDarwin())
298 ObjCModifierFlagsStart) {
300 ObjCModifierFlagsEnd + 1,
306 FS.setConversionSpecifier(CS);
308 FS.setArgIndex(argIndex++);
326 bool isFreeBSDKPrintf) {
328 unsigned argIndex = 0;
348 assert(I == E &&
"Format string not exhausted");
357 unsigned argIndex = 0;
386 bool IsObjCLiteral)
const {
393 switch (LM.getKind()) {
407 switch (LM.getKind()) {
414 return ArgType(Ctx.
IntTy,
"__int32");
431 : ArgType(Ctx.
IntTy,
"__int32");
441 switch (LM.getKind()) {
482 switch (LM.getKind()) {
567 HasThousandsGrouping =
false;
568 HasPlusPrefix =
false;
569 HasSpacePrefix =
false;
570 HasAlternativeForm =
false;
571 HasLeadingZeroes =
false;
583 HasAlternativeForm = 0;
584 HasLeadingZeroes = 0;
597 QT = ETy->getDecl()->getIntegerType();
606 case BuiltinType::Bool:
607 case BuiltinType::WChar_U:
608 case BuiltinType::WChar_S:
609 case BuiltinType::Char16:
610 case BuiltinType::Char32:
611 case BuiltinType::UInt128:
612 case BuiltinType::Int128:
613 case BuiltinType::Half:
617 #define SIGNED_TYPE(Id, SingletonId)
618 #define UNSIGNED_TYPE(Id, SingletonId)
619 #define FLOATING_TYPE(Id, SingletonId)
620 #define BUILTIN_TYPE(Id, SingletonId) \
621 case BuiltinType::Id:
622 #include "clang/AST/BuiltinTypes.def"
626 case BuiltinType::UInt:
627 case BuiltinType::Int:
628 case BuiltinType::Float:
629 case BuiltinType::Double:
633 case BuiltinType::Char_U:
634 case BuiltinType::UChar:
635 case BuiltinType::Char_S:
636 case BuiltinType::SChar:
640 case BuiltinType::Short:
641 case BuiltinType::UShort:
645 case BuiltinType::Long:
646 case BuiltinType::ULong:
650 case BuiltinType::LongLong:
651 case BuiltinType::ULongLong:
655 case BuiltinType::LongDouble:
661 if (isa<TypedefType>(QT) && (LangOpt.C99 || LangOpt.CPlusPlus11))
662 namedTypeToLengthModifier(QT, LM);
667 switch (CS.getKind()) {
684 const analyze_printf::ArgType &ATR = getArgType(Ctx, IsObjCLiteral);
685 if (ATR.isValid() && ATR.matchesType(Ctx, QT))
691 if (!isa<TypedefType>(QT) && QT->
isCharType()) {
695 HasAlternativeForm = 0;
696 HasLeadingZeroes = 0;
705 HasAlternativeForm = 0;
709 HasAlternativeForm = 0;
712 llvm_unreachable(
"Unexpected type");
724 if (usesPositionalArg()) {
725 os << getPositionalArgIndex() <<
"$";
729 if (IsLeftJustified) os <<
"-";
730 if (HasPlusPrefix) os <<
"+";
731 if (HasSpacePrefix) os <<
" ";
732 if (HasAlternativeForm) os <<
"#";
733 if (HasLeadingZeroes) os <<
"0";
736 FieldWidth.toString(os);
738 Precision.toString(os);
745 bool PrintfSpecifier::hasValidPlusPrefix()
const {
750 switch (CS.getKind()) {
771 bool PrintfSpecifier::hasValidAlternativeForm()
const {
772 if (!HasAlternativeForm)
776 switch (CS.getKind()) {
798 bool PrintfSpecifier::hasValidLeadingZeros()
const {
799 if (!HasLeadingZeroes)
803 switch (CS.getKind()) {
830 bool PrintfSpecifier::hasValidSpacePrefix()
const {
835 switch (CS.getKind()) {
856 bool PrintfSpecifier::hasValidLeftJustified()
const {
857 if (!IsLeftJustified)
861 switch (CS.getKind()) {
870 bool PrintfSpecifier::hasValidThousandsGroupingPrefix()
const {
871 if (!HasThousandsGrouping)
874 switch (CS.getKind()) {
890 bool PrintfSpecifier::hasValidPrecision()
const {
895 switch (CS.getKind()) {
922 bool PrintfSpecifier::hasValidFieldWidth()
const {
927 switch (CS.getKind()) {
bool isAnyCharacterType() const
Determine whether this type is any of the built-in character types.
CanQualType getSizeType() const
Return the unique type for "size_t" (C99 7.17), defined in <stddef.h>.
bool isObjCRetainableType() const
QualType withConst() const
Retrieves a version of this type with const applied. Note that this does not always yield a canonical...
CanQualType getIntMaxType() const
Return the unique type for "intmax_t" (C99 7.18.1.5), defined in <stdint.h>.
void setPrecision(const OptionalAmount &Amt)
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
const TargetInfo & getTargetInfo() const
bool isUnsignedIntegerType() const
CanQualType UnsignedCharTy
QualType getPointeeType() const
bool isRealFloatingType() const
Floating point categories.
Exposes information about the current target.
CanQualType getUIntMaxType() const
Return the unique type for "uintmax_t" (C99 7.18.1.5), defined in <stdint.h>.
const PrintfConversionSpecifier & getConversionSpecifier() const
CanQualType UnsignedShortTy
CanQualType UnsignedLongLongTy
QualType getPointerType(QualType T) const
Return the uniqued reference to the type for a pointer to the specified type.
const llvm::Triple & getTriple() const
Returns the target triple of the primary target.
bool isWideCharType() const
std::string toString(const til::SExpr *E)
void setHasObjCTechnicalTerm(const char *position)
QualType getPointerDiffType() const
Return the unique type for "ptrdiff_t" (C99 7.17) defined in <stddef.h>. Pointer - pointer requires t...
CanQualType UnsignedLongTy
Defines the clang::TargetInfo interface.
bool isSignedIntegerType() const
CanQualType UnsignedIntTy
bool isPointerType() const