clang 22.0.0git
FormatString.h
Go to the documentation of this file.
1//= FormatString.h - Analysis of printf/fprintf format strings --*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file defines APIs for analyzing the format strings of printf, fscanf,
10// and friends.
11//
12// The structure of format strings for fprintf are described in C99 7.19.6.1.
13//
14// The structure of format strings for fscanf are described in C99 7.19.6.2.
15//
16//===----------------------------------------------------------------------===//
17
18#ifndef LLVM_CLANG_AST_FORMATSTRING_H
19#define LLVM_CLANG_AST_FORMATSTRING_H
20
22#include <optional>
23
24namespace clang {
25
26class TargetInfo;
27
28//===----------------------------------------------------------------------===//
29/// Common components of both fprintf and fscanf format strings.
30namespace analyze_format_string {
31
32/// Class representing optional flags with location and representation
33/// information.
35public:
36 OptionalFlag(const char *Representation)
37 : representation(Representation), flag(false) {}
38 bool isSet() const { return flag; }
39 void set() { flag = true; }
40 void clear() { flag = false; }
41 void setPosition(const char *position) {
42 assert(position);
43 flag = true;
44 this->position = position;
45 }
46 const char *getPosition() const {
47 assert(position);
48 return position;
49 }
50 const char *toString() const { return representation; }
51
52 // Overloaded operators for bool like qualities
53 explicit operator bool() const { return flag; }
54 OptionalFlag& operator=(const bool &rhs) {
55 flag = rhs;
56 return *this; // Return a reference to myself.
57 }
58private:
59 const char *representation;
60 const char *position;
61 bool flag;
62};
63
64/// Represents the length modifier in a format string in scanf/printf.
66public:
67 enum Kind {
69 AsChar, // 'hh'
70 AsShort, // 'h'
71 AsShortLong, // 'hl' (OpenCL float/int vector element)
72 AsLong, // 'l'
73 AsLongLong, // 'll'
74 AsQuad, // 'q' (BSD, deprecated, for 64-bit integer types)
75 AsIntMax, // 'j'
76 AsSizeT, // 'z'
77 AsPtrDiff, // 't'
78 AsInt32, // 'I32' (MSVCRT, like __int32)
79 AsInt3264, // 'I' (MSVCRT, like __int3264 from MIDL)
80 AsInt64, // 'I64' (MSVCRT, like __int64)
82 AsAllocate, // for '%as', GNU extension to C90 scanf
83 AsMAllocate, // for '%ms', GNU extension to scanf
84 AsWide, // 'w' (MSVCRT, like l but only for c, C, s, S, or Z
85 AsWideChar = AsLong // for '%ls', only makes sense for printf
86 };
87
89 : Position(nullptr), kind(None) {}
90 LengthModifier(const char *pos, Kind k)
91 : Position(pos), kind(k) {}
92
93 const char *getStart() const {
94 return Position;
95 }
96
97 unsigned getLength() const {
98 switch (kind) {
99 default:
100 return 1;
101 case AsLongLong:
102 case AsChar:
103 return 2;
104 case AsInt32:
105 case AsInt64:
106 return 3;
107 case None:
108 return 0;
109 }
110 }
111
112 Kind getKind() const { return kind; }
113 void setKind(Kind k) { kind = k; }
114
115 const char *toString() const;
116
117private:
118 const char *Position;
119 Kind kind;
120};
121
123public:
124 enum Kind {
126 // C99 conversion specifiers.
129 DArg, // Apple extension
131 // C23 conversion specifiers.
134
137
139 OArg, // Apple extension
141 UArg, // Apple extension
146
157
164
165 // Apple extension: P specifies to os_log that the data being pointed to is
166 // to be copied by os_log. The precision indicates the number of bytes to
167 // copy.
169
170 // ** Printf-specific **
171
172 ZArg, // MS extension
173
174 // ISO/IEC TR 18037 (fixed-point) specific specifiers.
175 kArg, // %k for signed accum types
176 KArg, // %K for unsigned accum types
177 rArg, // %r for signed fract types
178 RArg, // %R for unsigned fract types
181
182 // Objective-C specific specifiers.
186
187 // FreeBSD kernel specific specifiers.
192
193 // GlibC specific specifiers.
195
198
199 // ** Scanf-specific **
203 };
204
205 ConversionSpecifier(bool isPrintf = true)
206 : IsPrintf(isPrintf), Position(nullptr), EndScanList(nullptr),
208
209 ConversionSpecifier(bool isPrintf, const char *pos, Kind k)
210 : IsPrintf(isPrintf), Position(pos), EndScanList(nullptr), kind(k) {}
211
212 const char *getStart() const {
213 return Position;
214 }
215
216 StringRef getCharacters() const {
217 return StringRef(getStart(), getLength());
218 }
219
220 bool consumesDataArgument() const {
221 switch (kind) {
222 case PrintErrno:
223 assert(IsPrintf);
224 return false;
225 case PercentArg:
226 return false;
227 case InvalidSpecifier:
228 return false;
229 default:
230 return true;
231 }
232 }
233
234 Kind getKind() const { return kind; }
235 void setKind(Kind k) { kind = k; }
236 unsigned getLength() const {
237 return EndScanList ? EndScanList - Position : 1;
238 }
239 void setEndScanList(const char *pos) { EndScanList = pos; }
240
241 bool isIntArg() const { return (kind >= IntArgBeg && kind <= IntArgEnd) ||
242 kind == FreeBSDrArg || kind == FreeBSDyArg; }
243 bool isUIntArg() const { return kind >= UIntArgBeg && kind <= UIntArgEnd; }
244 bool isAnyIntArg() const { return kind >= IntArgBeg && kind <= UIntArgEnd; }
245 bool isDoubleArg() const {
246 return kind >= DoubleArgBeg && kind <= DoubleArgEnd;
247 }
248 bool isFixedPointArg() const {
250 }
251
252 const char *toString() const;
253
254 bool isPrintfKind() const { return IsPrintf; }
255
256 std::optional<ConversionSpecifier> getStandardSpecifier() const;
257
258protected:
260 const char *Position;
261 const char *EndScanList;
263};
264
265class ArgType {
266public:
269
270 /// How well a given conversion specifier matches its argument.
272 /// The conversion specifier and the argument types are incompatible. For
273 /// instance, "%d" and float.
275 /// The conversion specifier and the argument type are compatible. For
276 /// instance, "%d" and int.
277 Match = 1,
278 /// The conversion specifier and the argument type are compatible because of
279 /// default argument promotions. For instance, "%hhd" and int.
281 /// The conversion specifier and the argument type are compatible but still
282 /// seems likely to be an error. For instanace, "%hhd" and short.
284 /// The conversion specifier and the argument type are disallowed by the C
285 /// standard, but are in practice harmless. For instance, "%p" and int*.
287 /// The conversion specifier and the argument type have different sign.
289 /// The conversion specifier and the argument type are compatible, but still
290 /// seems likely to be an error. For instance, "%hd" and _Bool.
292 };
293
294private:
295 Kind K;
296 QualType T;
297 const char *Name = nullptr;
298 bool Ptr = false;
299
300 /// The TypeKind identifies certain well-known types like size_t and
301 /// ptrdiff_t.
302 enum class TypeKind { DontCare, SizeT, PtrdiffT };
303 TypeKind TK = TypeKind::DontCare;
304
305public:
306 ArgType(Kind K = UnknownTy, const char *N = nullptr) : K(K), Name(N) {}
307 ArgType(QualType T, const char *N = nullptr) : K(SpecificTy), T(T), Name(N) {}
309
310 static ArgType Invalid() { return ArgType(InvalidTy); }
311 bool isValid() const { return K != InvalidTy; }
312
313 bool isSizeT() const { return TK == TypeKind::SizeT; }
314
315 bool isPtrdiffT() const { return TK == TypeKind::PtrdiffT; }
316
317 /// Create an ArgType which corresponds to the type pointer to A.
318 static ArgType PtrTo(const ArgType& A) {
319 assert(A.K >= InvalidTy && "ArgType cannot be pointer to invalid/unknown");
320 ArgType Res = A;
321 Res.Ptr = true;
322 return Res;
323 }
324
325 /// Create an ArgType which corresponds to the size_t/ssize_t type.
326 static ArgType makeSizeT(const ArgType &A) {
327 ArgType Res = A;
328 Res.TK = TypeKind::SizeT;
329 return Res;
330 }
331
332 /// Create an ArgType which corresponds to the ptrdiff_t/unsigned ptrdiff_t
333 /// type.
334 static ArgType makePtrdiffT(const ArgType &A) {
335 ArgType Res = A;
336 Res.TK = TypeKind::PtrdiffT;
337 return Res;
338 }
339
341 MatchKind matchesArgType(ASTContext &C, const ArgType &other) const;
342
344
345 ArgType makeVectorType(ASTContext &C, unsigned NumElts) const;
346
347 std::string getRepresentativeTypeName(ASTContext &C) const;
348};
349
351public:
353
355 unsigned amount,
356 const char *amountStart,
357 unsigned amountLength,
359 : start(amountStart), length(amountLength), hs(howSpecified), amt(amount),
360 UsesPositionalArg(usesPositionalArg), UsesDotPrefix(false) {}
361
362 OptionalAmount(bool valid = true)
363 : start(nullptr),length(0), hs(valid ? NotSpecified : Invalid), amt(0),
364 UsesPositionalArg(false), UsesDotPrefix(false) {}
365
366 explicit OptionalAmount(unsigned Amount)
367 : start(nullptr), length(0), hs(Constant), amt(Amount),
368 UsesPositionalArg(false), UsesDotPrefix(false) {}
369
370 bool isInvalid() const {
371 return hs == Invalid;
372 }
373
374 HowSpecified getHowSpecified() const { return hs; }
375 void setHowSpecified(HowSpecified h) { hs = h; }
376
377 bool hasDataArgument() const { return hs == Arg; }
378
379 unsigned getArgIndex() const {
380 assert(hasDataArgument());
381 return amt;
382 }
383
384 unsigned getConstantAmount() const {
385 assert(hs == Constant);
386 return amt;
387 }
388
389 const char *getStart() const {
390 // We include the . character if it is given.
391 return start - UsesDotPrefix;
392 }
393
394 unsigned getConstantLength() const {
395 assert(hs == Constant);
396 return length + UsesDotPrefix;
397 }
398
399 ArgType getArgType(ASTContext &Ctx) const;
400
401 void toString(raw_ostream &os) const;
402
403 bool usesPositionalArg() const { return (bool) UsesPositionalArg; }
404 unsigned getPositionalArgIndex() const {
405 assert(hasDataArgument());
406 return amt + 1;
407 }
408
409 bool usesDotPrefix() const { return UsesDotPrefix; }
410 void setUsesDotPrefix() { UsesDotPrefix = true; }
411
412private:
413 const char *start;
414 unsigned length;
415 HowSpecified hs;
416 unsigned amt;
417 bool UsesPositionalArg : 1;
418 bool UsesDotPrefix;
419};
420
421
423protected:
428
429 /// Positional arguments, an IEEE extension:
430 /// IEEE Std 1003.1, 2004 Edition
431 /// http://www.opengroup.org/onlinepubs/009695399/functions/printf.html
433 unsigned argIndex;
434public:
435 FormatSpecifier(bool isPrintf)
436 : CS(isPrintf), VectorNumElts(false),
438
440 LM = lm;
441 }
442
444
445 void setArgIndex(unsigned i) {
446 argIndex = i;
447 }
448
449 unsigned getArgIndex() const {
450 return argIndex;
451 }
452
453 unsigned getPositionalArgIndex() const {
454 return argIndex + 1;
455 }
456
458 return LM;
459 }
460
462 return FieldWidth;
463 }
464
466 VectorNumElts = Amt;
467 }
468
470 return VectorNumElts;
471 }
472
473 void setFieldWidth(const OptionalAmount &Amt) {
474 FieldWidth = Amt;
475 }
476
477 bool usesPositionalArg() const { return UsesPositionalArg; }
478
480 const LangOptions &LO) const;
481
482 bool hasStandardLengthModifier() const;
483
484 std::optional<LengthModifier> getCorrectedLengthModifier() const;
485
486 bool hasStandardConversionSpecifier(const LangOptions &LangOpt) const;
487
489
490 /// For a TypedefType QT, if it is a named integer type such as size_t,
491 /// assign the appropriate value to LM and return true.
492 static bool namedTypeToLengthModifier(ASTContext &Ctx, QualType QT,
494};
495
496} // end analyze_format_string namespace
497
498//===----------------------------------------------------------------------===//
499/// Pieces specific to fprintf format strings.
500
501namespace analyze_printf {
502
505public:
508
509 PrintfConversionSpecifier(const char *pos, Kind k)
510 : ConversionSpecifier(true, pos, k) {}
511
512 bool isObjCArg() const { return kind >= ObjCBeg && kind <= ObjCEnd; }
513 bool isDoubleArg() const { return kind >= DoubleArgBeg &&
514 kind <= DoubleArgEnd; }
515
517 return CS->isPrintfKind();
518 }
519};
520
525
527 OptionalFlag HasThousandsGrouping; // ''', POSIX extension.
528 OptionalFlag IsLeftJustified; // '-'
529 OptionalFlag HasPlusPrefix; // '+'
530 OptionalFlag HasSpacePrefix; // ' '
531 OptionalFlag HasAlternativeForm; // '#'
532 OptionalFlag HasLeadingZeroes; // '0'
533 OptionalFlag HasObjCTechnicalTerm; // '[tt]'
534 OptionalFlag IsPrivate; // '{private}'
535 OptionalFlag IsPublic; // '{public}'
536 OptionalFlag IsSensitive; // '{sensitive}'
537 OptionalAmount Precision;
538 StringRef MaskType;
539
540 ArgType getScalarArgType(ASTContext &Ctx, bool IsObjCLiteral) const;
541
542public:
544 : FormatSpecifier(/* isPrintf = */ true), HasThousandsGrouping("'"),
545 IsLeftJustified("-"), HasPlusPrefix("+"), HasSpacePrefix(" "),
546 HasAlternativeForm("#"), HasLeadingZeroes("0"),
547 HasObjCTechnicalTerm("tt"), IsPrivate("private"), IsPublic("public"),
548 IsSensitive("sensitive") {}
549
550 static PrintfSpecifier Parse(const char *beg, const char *end);
551
552 // Methods for incrementally constructing the PrintfSpecifier.
554 CS = cs;
555 }
556 void setHasThousandsGrouping(const char *position) {
557 HasThousandsGrouping.setPosition(position);
558 }
559 void setIsLeftJustified(const char *position) {
560 IsLeftJustified.setPosition(position);
561 }
562 void setHasPlusPrefix(const char *position) {
563 HasPlusPrefix.setPosition(position);
564 }
565 void setHasSpacePrefix(const char *position) {
566 HasSpacePrefix.setPosition(position);
567 }
568 void setHasAlternativeForm(const char *position) {
569 HasAlternativeForm.setPosition(position);
570 }
571 void setHasLeadingZeros(const char *position) {
572 HasLeadingZeroes.setPosition(position);
573 }
574 void setHasObjCTechnicalTerm(const char *position) {
575 HasObjCTechnicalTerm.setPosition(position);
576 }
577 void setIsPrivate(const char *position) { IsPrivate.setPosition(position); }
578 void setIsPublic(const char *position) { IsPublic.setPosition(position); }
579 void setIsSensitive(const char *position) {
580 IsSensitive.setPosition(position);
581 }
583
584 // Methods for querying the format specifier.
585
587 return cast<PrintfConversionSpecifier>(CS);
588 }
589
590 void setPrecision(const OptionalAmount &Amt) {
591 Precision = Amt;
592 Precision.setUsesDotPrefix();
593 }
594
596 return Precision;
597 }
598
599 bool consumesDataArgument() const {
601 }
602
603 /// Returns the builtin type that a data argument
604 /// paired with this format specifier should have. This method
605 /// will return null if the format specifier does not have
606 /// a matching data argument or the matching argument matches
607 /// more than one type.
608 ArgType getArgType(ASTContext &Ctx, bool IsObjCLiteral) const;
609
611 return HasThousandsGrouping;
612 }
613 const OptionalFlag &isLeftJustified() const { return IsLeftJustified; }
614 const OptionalFlag &hasPlusPrefix() const { return HasPlusPrefix; }
615 const OptionalFlag &hasAlternativeForm() const { return HasAlternativeForm; }
616 const OptionalFlag &hasLeadingZeros() const { return HasLeadingZeroes; }
617 const OptionalFlag &hasSpacePrefix() const { return HasSpacePrefix; }
618 const OptionalFlag &hasObjCTechnicalTerm() const { return HasObjCTechnicalTerm; }
619 const OptionalFlag &isPrivate() const { return IsPrivate; }
620 const OptionalFlag &isPublic() const { return IsPublic; }
621 const OptionalFlag &isSensitive() const { return IsSensitive; }
622 bool usesPositionalArg() const { return UsesPositionalArg; }
623
624 StringRef getMaskType() const { return MaskType; }
625 void setMaskType(StringRef S) { MaskType = S; }
626
627 /// Changes the specifier and length according to a QualType, retaining any
628 /// flags or options. Returns true on success, or false when a conversion
629 /// was not successful.
630 bool fixType(QualType QT, const LangOptions &LangOpt, ASTContext &Ctx,
631 bool IsObjCLiteral);
632
633 void toString(raw_ostream &os) const;
634
635 // Validation methods - to check if any element results in undefined behavior
636 bool hasValidPlusPrefix() const;
637 bool hasValidAlternativeForm() const;
638 bool hasValidLeadingZeros() const;
639 bool hasValidSpacePrefix() const;
640 bool hasValidLeftJustified() const;
642
643 bool hasValidPrecision() const;
644 bool hasValidFieldWidth() const;
645};
646} // end analyze_printf namespace
647
648//===----------------------------------------------------------------------===//
649/// Pieces specific to fscanf format strings.
650
651namespace analyze_scanf {
652
655public:
658
659 ScanfConversionSpecifier(const char *pos, Kind k)
660 : ConversionSpecifier(false, pos, k) {}
661
663 return !CS->isPrintfKind();
664 }
665};
666
671
673 OptionalFlag SuppressAssignment; // '*'
674public:
676 FormatSpecifier(/* isPrintf = */ false),
677 SuppressAssignment("*") {}
678
679 void setSuppressAssignment(const char *position) {
680 SuppressAssignment.setPosition(position);
681 }
682
684 return SuppressAssignment;
685 }
686
688 CS = cs;
689 }
690
692 return cast<ScanfConversionSpecifier>(CS);
693 }
694
695 bool consumesDataArgument() const {
696 return CS.consumesDataArgument() && !SuppressAssignment;
697 }
698
699 ArgType getArgType(ASTContext &Ctx) const;
700
701 bool fixType(QualType QT, QualType RawQT, const LangOptions &LangOpt,
702 ASTContext &Ctx);
703
704 void toString(raw_ostream &os) const;
705
706 static ScanfSpecifier Parse(const char *beg, const char *end);
707};
708
709} // end analyze_scanf namespace
710
711//===----------------------------------------------------------------------===//
712// Parsing and processing of format strings (both fprintf and fscanf).
713
714namespace analyze_format_string {
715
717
719public:
721 virtual ~FormatStringHandler();
722
723 virtual void HandleNullChar(const char *nullCharacter) {}
724
725 virtual void HandlePosition(const char *startPos, unsigned posLen) {}
726
727 virtual void HandleInvalidPosition(const char *startPos, unsigned posLen,
728 PositionContext p) {}
729
730 virtual void HandleZeroPosition(const char *startPos, unsigned posLen) {}
731
732 virtual void HandleIncompleteSpecifier(const char *startSpecifier,
733 unsigned specifierLen) {}
734
735 virtual void HandleEmptyObjCModifierFlag(const char *startFlags,
736 unsigned flagsLen) {}
737
738 virtual void HandleInvalidObjCModifierFlag(const char *startFlag,
739 unsigned flagLen) {}
740
741 virtual void HandleObjCFlagsWithNonObjCConversion(const char *flagsStart,
742 const char *flagsEnd,
743 const char *conversionPosition) {}
744 // Printf-specific handlers.
745
748 const char *startSpecifier,
749 unsigned specifierLen) {
750 return true;
751 }
752
754 const char *startSpecifier,
755 unsigned specifierLen,
756 const TargetInfo &Target) {
757 return true;
758 }
759
760 /// Handle mask types whose sizes are not between one and eight bytes.
761 virtual void handleInvalidMaskType(StringRef MaskType) {}
762
763 // Scanf-specific handlers.
764
767 const char *startSpecifier,
768 unsigned specifierLen) {
769 return true;
770 }
771
773 const char *startSpecifier,
774 unsigned specifierLen) {
775 return true;
776 }
777
778 virtual void HandleIncompleteScanList(const char *start, const char *end) {}
779};
780
781bool ParsePrintfString(FormatStringHandler &H,
782 const char *beg, const char *end, const LangOptions &LO,
783 const TargetInfo &Target, bool isFreeBSDKPrintf);
784
785bool ParseFormatStringHasSArg(const char *beg, const char *end,
786 const LangOptions &LO, const TargetInfo &Target);
787
788bool ParseScanfString(FormatStringHandler &H,
789 const char *beg, const char *end, const LangOptions &LO,
790 const TargetInfo &Target);
791
792/// Return true if the given string has at least one formatting specifier.
794 const char *End,
795 const LangOptions &LO,
796 const TargetInfo &Target);
797
798} // end analyze_format_string namespace
799} // end clang namespace
800#endif
llvm::MachO::Target Target
Definition: MachO.h:51
SourceLocation Begin
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:188
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:434
A (possibly-)qualified type.
Definition: TypeBase.h:937
Exposes information about the current target.
Definition: TargetInfo.h:226
static ArgType makePtrdiffT(const ArgType &A)
Create an ArgType which corresponds to the ptrdiff_t/unsigned ptrdiff_t type.
Definition: FormatString.h:334
MatchKind
How well a given conversion specifier matches its argument.
Definition: FormatString.h:271
@ NoMatch
The conversion specifier and the argument types are incompatible.
Definition: FormatString.h:274
@ NoMatchPedantic
The conversion specifier and the argument type are disallowed by the C standard, but are in practice ...
Definition: FormatString.h:286
@ Match
The conversion specifier and the argument type are compatible.
Definition: FormatString.h:277
@ MatchPromotion
The conversion specifier and the argument type are compatible because of default argument promotions.
Definition: FormatString.h:280
@ NoMatchSignedness
The conversion specifier and the argument type have different sign.
Definition: FormatString.h:288
@ NoMatchTypeConfusion
The conversion specifier and the argument type are compatible, but still seems likely to be an error.
Definition: FormatString.h:291
@ NoMatchPromotionTypeConfusion
The conversion specifier and the argument type are compatible but still seems likely to be an error.
Definition: FormatString.h:283
static ArgType PtrTo(const ArgType &A)
Create an ArgType which corresponds to the type pointer to A.
Definition: FormatString.h:318
ArgType makeVectorType(ASTContext &C, unsigned NumElts) const
MatchKind matchesArgType(ASTContext &C, const ArgType &other) const
QualType getRepresentativeType(ASTContext &C) const
std::string getRepresentativeTypeName(ASTContext &C) const
ArgType(QualType T, const char *N=nullptr)
Definition: FormatString.h:307
static ArgType makeSizeT(const ArgType &A)
Create an ArgType which corresponds to the size_t/ssize_t type.
Definition: FormatString.h:326
ArgType(Kind K=UnknownTy, const char *N=nullptr)
Definition: FormatString.h:306
MatchKind matchesType(ASTContext &C, QualType argTy) const
std::optional< ConversionSpecifier > getStandardSpecifier() const
ConversionSpecifier(bool isPrintf, const char *pos, Kind k)
Definition: FormatString.h:209
static bool namedTypeToLengthModifier(ASTContext &Ctx, QualType QT, LengthModifier &LM)
For a TypedefType QT, if it is a named integer type such as size_t, assign the appropriate value to L...
void setFieldWidth(const OptionalAmount &Amt)
Definition: FormatString.h:473
const OptionalAmount & getFieldWidth() const
Definition: FormatString.h:461
bool hasStandardConversionSpecifier(const LangOptions &LangOpt) const
const LengthModifier & getLengthModifier() const
Definition: FormatString.h:457
const OptionalAmount & getVectorNumElts() const
Definition: FormatString.h:469
bool hasValidLengthModifier(const TargetInfo &Target, const LangOptions &LO) const
bool UsesPositionalArg
Positional arguments, an IEEE extension: IEEE Std 1003.1, 2004 Edition http://www....
Definition: FormatString.h:432
std::optional< LengthModifier > getCorrectedLengthModifier() const
void setVectorNumElts(const OptionalAmount &Amt)
Definition: FormatString.h:465
virtual bool HandleInvalidPrintfConversionSpecifier(const analyze_printf::PrintfSpecifier &FS, const char *startSpecifier, unsigned specifierLen)
Definition: FormatString.h:746
virtual void HandleObjCFlagsWithNonObjCConversion(const char *flagsStart, const char *flagsEnd, const char *conversionPosition)
Definition: FormatString.h:741
virtual void HandleInvalidObjCModifierFlag(const char *startFlag, unsigned flagLen)
Definition: FormatString.h:738
virtual void HandleIncompleteScanList(const char *start, const char *end)
Definition: FormatString.h:778
virtual void HandleNullChar(const char *nullCharacter)
Definition: FormatString.h:723
virtual void handleInvalidMaskType(StringRef MaskType)
Handle mask types whose sizes are not between one and eight bytes.
Definition: FormatString.h:761
virtual void HandlePosition(const char *startPos, unsigned posLen)
Definition: FormatString.h:725
virtual bool HandlePrintfSpecifier(const analyze_printf::PrintfSpecifier &FS, const char *startSpecifier, unsigned specifierLen, const TargetInfo &Target)
Definition: FormatString.h:753
virtual void HandleInvalidPosition(const char *startPos, unsigned posLen, PositionContext p)
Definition: FormatString.h:727
virtual void HandleEmptyObjCModifierFlag(const char *startFlags, unsigned flagsLen)
Definition: FormatString.h:735
virtual void HandleZeroPosition(const char *startPos, unsigned posLen)
Definition: FormatString.h:730
virtual void HandleIncompleteSpecifier(const char *startSpecifier, unsigned specifierLen)
Definition: FormatString.h:732
virtual bool HandleScanfSpecifier(const analyze_scanf::ScanfSpecifier &FS, const char *startSpecifier, unsigned specifierLen)
Definition: FormatString.h:772
virtual bool HandleInvalidScanfConversionSpecifier(const analyze_scanf::ScanfSpecifier &FS, const char *startSpecifier, unsigned specifierLen)
Definition: FormatString.h:765
Represents the length modifier in a format string in scanf/printf.
Definition: FormatString.h:65
ArgType getArgType(ASTContext &Ctx) const
OptionalAmount(HowSpecified howSpecified, unsigned amount, const char *amountStart, unsigned amountLength, bool usesPositionalArg)
Definition: FormatString.h:354
Class representing optional flags with location and representation information.
Definition: FormatString.h:34
OptionalFlag(const char *Representation)
Definition: FormatString.h:36
void setPosition(const char *position)
Definition: FormatString.h:41
OptionalFlag & operator=(const bool &rhs)
Definition: FormatString.h:54
PrintfConversionSpecifier(const char *pos, Kind k)
Definition: FormatString.h:509
static bool classof(const analyze_format_string::ConversionSpecifier *CS)
Definition: FormatString.h:516
const OptionalFlag & isPrivate() const
Definition: FormatString.h:619
void setHasAlternativeForm(const char *position)
Definition: FormatString.h:568
void setIsSensitive(const char *position)
Definition: FormatString.h:579
void setHasSpacePrefix(const char *position)
Definition: FormatString.h:565
void setHasThousandsGrouping(const char *position)
Definition: FormatString.h:556
const OptionalAmount & getPrecision() const
Definition: FormatString.h:595
static PrintfSpecifier Parse(const char *beg, const char *end)
const OptionalFlag & hasSpacePrefix() const
Definition: FormatString.h:617
void setIsLeftJustified(const char *position)
Definition: FormatString.h:559
bool fixType(QualType QT, const LangOptions &LangOpt, ASTContext &Ctx, bool IsObjCLiteral)
Changes the specifier and length according to a QualType, retaining any flags or options.
const OptionalFlag & isSensitive() const
Definition: FormatString.h:621
const OptionalFlag & isLeftJustified() const
Definition: FormatString.h:613
const OptionalFlag & hasLeadingZeros() const
Definition: FormatString.h:616
const OptionalFlag & hasAlternativeForm() const
Definition: FormatString.h:615
void setHasPlusPrefix(const char *position)
Definition: FormatString.h:562
void setIsPrivate(const char *position)
Definition: FormatString.h:577
const PrintfConversionSpecifier & getConversionSpecifier() const
Definition: FormatString.h:586
void setHasLeadingZeros(const char *position)
Definition: FormatString.h:571
const OptionalFlag & hasPlusPrefix() const
Definition: FormatString.h:614
const OptionalFlag & hasThousandsGrouping() const
Definition: FormatString.h:610
ArgType getArgType(ASTContext &Ctx, bool IsObjCLiteral) const
Returns the builtin type that a data argument paired with this format specifier should have.
void setIsPublic(const char *position)
Definition: FormatString.h:578
const OptionalFlag & hasObjCTechnicalTerm() const
Definition: FormatString.h:618
void setPrecision(const OptionalAmount &Amt)
Definition: FormatString.h:590
void setHasObjCTechnicalTerm(const char *position)
Definition: FormatString.h:574
const OptionalFlag & isPublic() const
Definition: FormatString.h:620
void setConversionSpecifier(const PrintfConversionSpecifier &cs)
Definition: FormatString.h:553
ScanfConversionSpecifier(const char *pos, Kind k)
Definition: FormatString.h:659
static bool classof(const analyze_format_string::ConversionSpecifier *CS)
Definition: FormatString.h:662
static ScanfSpecifier Parse(const char *beg, const char *end)
bool fixType(QualType QT, QualType RawQT, const LangOptions &LangOpt, ASTContext &Ctx)
const OptionalFlag & getSuppressAssignment() const
Definition: FormatString.h:683
void toString(raw_ostream &os) const
void setConversionSpecifier(const ScanfConversionSpecifier &cs)
Definition: FormatString.h:687
const ScanfConversionSpecifier & getConversionSpecifier() const
Definition: FormatString.h:691
void setSuppressAssignment(const char *position)
Definition: FormatString.h:679
ArgType getArgType(ASTContext &Ctx) const
#define bool
Definition: gpuintrin.h:32
bool parseFormatStringHasFormattingSpecifiers(const char *Begin, const char *End, const LangOptions &LO, const TargetInfo &Target)
Return true if the given string has at least one formatting specifier.
bool ParsePrintfString(FormatStringHandler &H, const char *beg, const char *end, const LangOptions &LO, const TargetInfo &Target, bool isFreeBSDKPrintf)
bool ParseScanfString(FormatStringHandler &H, const char *beg, const char *end, const LangOptions &LO, const TargetInfo &Target)
bool ParseFormatStringHasSArg(const char *beg, const char *end, const LangOptions &LO, const TargetInfo &Target)
The JSON file list parser is used to communicate input to InstallAPI.
const FunctionProtoType * T
#define true
Definition: stdbool.h:25
#define false
Definition: stdbool.h:26