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++);
315 unsigned Len =
I - Start;
318 FS.setConversionSpecifier(CS);
331 bool isFreeBSDKPrintf) {
333 unsigned argIndex = 0;
353 assert(I == E &&
"Format string not exhausted");
362 unsigned argIndex = 0;
391 bool IsObjCLiteral)
const {
398 switch (LM.getKind()) {
412 switch (LM.getKind()) {
419 return ArgType(Ctx.
IntTy,
"__int32");
436 : ArgType(Ctx.
IntTy,
"__int32");
446 switch (LM.getKind()) {
487 switch (LM.getKind()) {
572 HasThousandsGrouping =
false;
573 HasPlusPrefix =
false;
574 HasSpacePrefix =
false;
575 HasAlternativeForm =
false;
576 HasLeadingZeroes =
false;
588 HasAlternativeForm = 0;
589 HasLeadingZeroes = 0;
602 QT = ETy->getDecl()->getIntegerType();
611 case BuiltinType::Bool:
612 case BuiltinType::WChar_U:
613 case BuiltinType::WChar_S:
614 case BuiltinType::Char16:
615 case BuiltinType::Char32:
616 case BuiltinType::UInt128:
617 case BuiltinType::Int128:
618 case BuiltinType::Half:
619 case BuiltinType::Float128:
623 #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
624 case BuiltinType::Id:
625 #include "clang/Basic/OpenCLImageTypes.def"
626 #define SIGNED_TYPE(Id, SingletonId)
627 #define UNSIGNED_TYPE(Id, SingletonId)
628 #define FLOATING_TYPE(Id, SingletonId)
629 #define BUILTIN_TYPE(Id, SingletonId) \
630 case BuiltinType::Id:
631 #include "clang/AST/BuiltinTypes.def"
635 case BuiltinType::UInt:
636 case BuiltinType::Int:
637 case BuiltinType::Float:
638 case BuiltinType::Double:
642 case BuiltinType::Char_U:
643 case BuiltinType::UChar:
644 case BuiltinType::Char_S:
645 case BuiltinType::SChar:
649 case BuiltinType::Short:
650 case BuiltinType::UShort:
654 case BuiltinType::Long:
655 case BuiltinType::ULong:
659 case BuiltinType::LongLong:
660 case BuiltinType::ULongLong:
664 case BuiltinType::LongDouble:
670 if (isa<TypedefType>(QT) && (LangOpt.C99 || LangOpt.CPlusPlus11))
671 namedTypeToLengthModifier(QT, LM);
676 switch (CS.getKind()) {
693 const analyze_printf::ArgType &ATR = getArgType(Ctx, IsObjCLiteral);
694 if (ATR.isValid() && ATR.matchesType(Ctx, QT))
700 if (!isa<TypedefType>(QT) && QT->
isCharType()) {
704 HasAlternativeForm = 0;
705 HasLeadingZeroes = 0;
714 HasAlternativeForm = 0;
718 HasAlternativeForm = 0;
721 llvm_unreachable(
"Unexpected type");
733 if (usesPositionalArg()) {
734 os << getPositionalArgIndex() <<
"$";
738 if (IsLeftJustified) os <<
"-";
739 if (HasPlusPrefix) os <<
"+";
740 if (HasSpacePrefix) os <<
" ";
741 if (HasAlternativeForm) os <<
"#";
742 if (HasLeadingZeroes) os <<
"0";
745 FieldWidth.toString(os);
747 Precision.toString(os);
754 bool PrintfSpecifier::hasValidPlusPrefix()
const {
759 switch (CS.getKind()) {
780 bool PrintfSpecifier::hasValidAlternativeForm()
const {
781 if (!HasAlternativeForm)
785 switch (CS.getKind()) {
807 bool PrintfSpecifier::hasValidLeadingZeros()
const {
808 if (!HasLeadingZeroes)
812 switch (CS.getKind()) {
839 bool PrintfSpecifier::hasValidSpacePrefix()
const {
844 switch (CS.getKind()) {
865 bool PrintfSpecifier::hasValidLeftJustified()
const {
866 if (!IsLeftJustified)
870 switch (CS.getKind()) {
879 bool PrintfSpecifier::hasValidThousandsGroupingPrefix()
const {
880 if (!HasThousandsGrouping)
883 switch (CS.getKind()) {
899 bool PrintfSpecifier::hasValidPrecision()
const {
904 switch (CS.getKind()) {
931 bool PrintfSpecifier::hasValidFieldWidth()
const {
936 switch (CS.getKind()) {
A (possibly-)qualified type.
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.
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
Return true if this is an integer type that is unsigned, according to C99 6.2.5p6 [which returns true...
detail::InMemoryDirectory::const_iterator I
CanQualType UnsignedCharTy
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee...
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
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of enums...
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.
detail::InMemoryDirectory::const_iterator E
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>.
const T * getAs() const
Member-template getAs<specific type>'.
CanQualType UnsignedLongTy
This class is used for builtin types like 'int'.
Defines the clang::TargetInfo interface.
bool isSignedIntegerType() const
Return true if this is an integer type that is signed, according to C99 6.2.5p4 [char, signed char, short, int, long..], or an enum decl which has a signed representation.
CanQualType UnsignedIntTy
bool isPointerType() const