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) {
122 const char *OSLogVisibilityFlagsStart =
nullptr,
123 *OSLogVisibilityFlagsEnd =
nullptr;
125 OSLogVisibilityFlagsStart =
I++;
127 while (
I != E && *
I !=
'}') {
136 OSLogVisibilityFlagsEnd =
I++;
140 const char *
P = OSLogVisibilityFlagsStart + 1;
141 while (P < OSLogVisibilityFlagsEnd && isspace(*P))
143 const char *WordStart =
P;
144 while (P < OSLogVisibilityFlagsEnd && (isalnum(*P) || *P ==
'_'))
146 const char *WordEnd =
P;
147 StringRef Word(WordStart, WordEnd - WordStart);
148 if (Word ==
"private") {
149 FS.setIsPrivate(WordStart);
150 }
else if (Word ==
"public") {
151 FS.setIsPublic(WordStart);
157 for ( ;
I !=
E; ++
I) {
159 default: hasMore =
false;
break;
162 FS.setHasThousandsGrouping(
I);
164 case '-': FS.setIsLeftJustified(
I);
break;
165 case '+': FS.setHasPlusPrefix(
I);
break;
166 case ' ': FS.setHasSpacePrefix(
I);
break;
167 case '#': FS.setHasAlternativeForm(
I);
break;
168 case '0': FS.setHasLeadingZeros(
I);
break;
183 FS.usesPositionalArg() ?
nullptr : &argIndex))
203 FS.usesPositionalArg() ?
nullptr : &argIndex))
228 const char *ObjCModifierFlagsStart =
nullptr,
229 *ObjCModifierFlagsEnd =
nullptr;
231 ObjCModifierFlagsStart =
I;
235 ObjCModifierFlagsEnd =
I;
261 const char *conversionPosition =
I++;
263 switch (*conversionPosition) {
299 if (isFreeBSDKPrintf)
303 if (isFreeBSDKPrintf)
307 if (isFreeBSDKPrintf)
312 if (isFreeBSDKPrintf)
314 else if (Target.
getTriple().isOSDarwin())
335 ObjCModifierFlagsStart) {
337 ObjCModifierFlagsEnd + 1,
343 FS.setConversionSpecifier(CS);
345 FS.setArgIndex(argIndex++);
352 unsigned Len =
I - Start;
355 FS.setConversionSpecifier(CS);
368 bool isFreeBSDKPrintf) {
370 unsigned argIndex = 0;
390 assert(I == E &&
"Format string not exhausted");
399 unsigned argIndex = 0;
428 bool IsObjCLiteral)
const {
435 switch (LM.getKind()) {
450 switch (LM.getKind()) {
457 return ArgType(Ctx.
IntTy,
"__int32");
473 : ArgType(Ctx.
IntTy,
"__int32");
483 switch (LM.getKind()) {
524 switch (LM.getKind()) {
610 HasThousandsGrouping =
false;
611 HasPlusPrefix =
false;
612 HasSpacePrefix =
false;
613 HasAlternativeForm =
false;
614 HasLeadingZeroes =
false;
626 HasAlternativeForm = 0;
627 HasLeadingZeroes = 0;
640 QT = ETy->getDecl()->getIntegerType();
649 case BuiltinType::Bool:
650 case BuiltinType::WChar_U:
651 case BuiltinType::WChar_S:
652 case BuiltinType::Char16:
653 case BuiltinType::Char32:
654 case BuiltinType::UInt128:
655 case BuiltinType::Int128:
656 case BuiltinType::Half:
657 case BuiltinType::Float128:
661 #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
662 case BuiltinType::Id:
663 #include "clang/Basic/OpenCLImageTypes.def"
664 #define SIGNED_TYPE(Id, SingletonId)
665 #define UNSIGNED_TYPE(Id, SingletonId)
666 #define FLOATING_TYPE(Id, SingletonId)
667 #define BUILTIN_TYPE(Id, SingletonId) \
668 case BuiltinType::Id:
669 #include "clang/AST/BuiltinTypes.def"
673 case BuiltinType::UInt:
674 case BuiltinType::Int:
675 case BuiltinType::Float:
676 case BuiltinType::Double:
680 case BuiltinType::Char_U:
681 case BuiltinType::UChar:
682 case BuiltinType::Char_S:
683 case BuiltinType::SChar:
687 case BuiltinType::Short:
688 case BuiltinType::UShort:
692 case BuiltinType::Long:
693 case BuiltinType::ULong:
697 case BuiltinType::LongLong:
698 case BuiltinType::ULongLong:
702 case BuiltinType::LongDouble:
708 if (isa<TypedefType>(QT) && (LangOpt.C99 || LangOpt.CPlusPlus11))
709 namedTypeToLengthModifier(QT, LM);
714 switch (CS.getKind()) {
731 const analyze_printf::ArgType &ATR = getArgType(Ctx, IsObjCLiteral);
732 if (ATR.isValid() && ATR.matchesType(Ctx, QT))
738 if (!isa<TypedefType>(QT) && QT->
isCharType()) {
742 HasAlternativeForm = 0;
743 HasLeadingZeroes = 0;
752 HasAlternativeForm = 0;
756 HasAlternativeForm = 0;
759 llvm_unreachable(
"Unexpected type");
771 if (usesPositionalArg()) {
772 os << getPositionalArgIndex() <<
"$";
776 if (IsLeftJustified) os <<
"-";
777 if (HasPlusPrefix) os <<
"+";
778 if (HasSpacePrefix) os <<
" ";
779 if (HasAlternativeForm) os <<
"#";
780 if (HasLeadingZeroes) os <<
"0";
783 FieldWidth.toString(os);
785 Precision.toString(os);
792 bool PrintfSpecifier::hasValidPlusPrefix()
const {
797 switch (CS.getKind()) {
818 bool PrintfSpecifier::hasValidAlternativeForm()
const {
819 if (!HasAlternativeForm)
823 switch (CS.getKind()) {
845 bool PrintfSpecifier::hasValidLeadingZeros()
const {
846 if (!HasLeadingZeroes)
850 switch (CS.getKind()) {
877 bool PrintfSpecifier::hasValidSpacePrefix()
const {
882 switch (CS.getKind()) {
903 bool PrintfSpecifier::hasValidLeftJustified()
const {
904 if (!IsLeftJustified)
908 switch (CS.getKind()) {
917 bool PrintfSpecifier::hasValidThousandsGroupingPrefix()
const {
918 if (!HasThousandsGrouping)
921 switch (CS.getKind()) {
937 bool PrintfSpecifier::hasValidPrecision()
const {
942 switch (CS.getKind()) {
970 bool PrintfSpecifier::hasValidFieldWidth()
const {
975 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...
CanQualType getSignedSizeType() const
Return the unique signed counterpart of the integer type corresponding to size_t. ...
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