clang 23.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 "llvm/ADT/StringRef.h"
23#include <optional>
24
25namespace clang {
26
27class TargetInfo;
28
29//===----------------------------------------------------------------------===//
30/// Common components of both fprintf and fscanf format strings.
32
33/// Class representing optional flags with location and representation
34/// information.
36public:
37 OptionalFlag(const char *Representation)
38 : representation(Representation), flag(false) {}
39 bool isSet() const { return flag; }
40 void set() { flag = true; }
41 void clear() { flag = false; }
42 void setPosition(const char *position) {
43 assert(position);
44 flag = true;
45 this->position = position;
46 }
47 const char *getPosition() const {
48 assert(position);
49 return position;
50 }
51 const char *toString() const { return representation; }
52
53 // Overloaded operators for bool like qualities
54 explicit operator bool() const { return flag; }
55 OptionalFlag &operator=(const bool &rhs) {
56 flag = rhs;
57 return *this; // Return a reference to myself.
58 }
59
60private:
61 const char *representation;
62 const char *position;
63 bool flag;
64};
65
66/// Represents the length modifier in a format string in scanf/printf.
68public:
69 enum Kind {
71 AsChar, // 'hh'
72 AsShort, // 'h'
73 AsShortLong, // 'hl' (OpenCL float/int vector element)
74 AsLong, // 'l'
75 AsLongLong, // 'll'
76 AsQuad, // 'q' (BSD, deprecated, for 64-bit integer types)
77 AsIntMax, // 'j'
78 AsSizeT, // 'z'
79 AsPtrDiff, // 't'
80 AsInt32, // 'I32' (MSVCRT, like __int32)
81 AsInt3264, // 'I' (MSVCRT, like __int3264 from MIDL)
82 AsInt64, // 'I64' (MSVCRT, like __int64)
84 AsIntN, // 'wN'
85 AsFastIntN, // 'wfN'
86 AsDecimal32, // 'H' (C23, _Decimal32)
87 AsDecimal64, // 'D' (C23, _Decimal64)
88 AsDecimal128, // 'DD' (C23, _Decimal128)
89 AsAllocate, // for '%as', GNU extension to C90 scanf
90 AsMAllocate, // for '%ms', GNU extension to scanf
91 AsWide, // 'w' (MSVCRT, like l but only for c, C, s, S, or Z
92 AsWideChar = AsLong // for '%ls', only makes sense for printf
93 };
94
95 LengthModifier() : Position(nullptr), kind(None) {}
96 LengthModifier(const char *pos, Kind k) : Position(pos), kind(k) {}
97 LengthModifier(const char *pos, Kind k, unsigned bitWidth, unsigned length)
98 : Position(pos), kind(k), BitWidth(bitWidth), ModifierLength(length) {}
99
100 const char *getStart() const { return Position; }
101
102 unsigned getLength() const {
103 switch (kind) {
104 default:
105 return 1;
106 case AsLongLong:
107 case AsChar:
108 case AsDecimal128:
109 return 2;
110 case AsIntN:
111 case AsFastIntN:
112 assert(ModifierLength != 0 &&
113 "C23 wN/wfN length modifiers must have a nonzero length");
114 return ModifierLength;
115 case AsInt32:
116 case AsInt64:
117 return 3;
118 case None:
119 return 0;
120 }
121 }
122
123 Kind getKind() const { return kind; }
124 void setKind(Kind k) { kind = k; }
125
126 unsigned getBitWidth() const { return BitWidth; }
127
128 StringRef toString() const;
129
130private:
131 const char *Position;
132 Kind kind;
133 unsigned BitWidth = 0;
134 unsigned ModifierLength = 0;
135};
136
138public:
139 enum Kind {
141 // C99 conversion specifiers.
144 DArg, // Apple extension
146 // C23 conversion specifiers.
149
152
154 OArg, // Apple extension
156 UArg, // Apple extension
161
172
179
180 // Apple extension: P specifies to os_log that the data being pointed to is
181 // to be copied by os_log. The precision indicates the number of bytes to
182 // copy.
184
185 // ** Printf-specific **
186
187 ZArg, // MS extension
188
189 // ISO/IEC TR 18037 (fixed-point) specific specifiers.
190 kArg, // %k for signed accum types
191 KArg, // %K for unsigned accum types
192 rArg, // %r for signed fract types
193 RArg, // %R for unsigned fract types
196
197 // Objective-C specific specifiers.
201
202 // FreeBSD kernel specific specifiers.
207
208 // GlibC specific specifiers.
210
213
214 // ** Scanf-specific **
218 };
219
220 ConversionSpecifier(bool isPrintf = true)
223
224 ConversionSpecifier(bool isPrintf, const char *pos, Kind k)
225 : IsPrintf(isPrintf), Position(pos), EndScanList(nullptr), kind(k) {}
226
227 const char *getStart() const { return Position; }
228
229 StringRef getCharacters() const { return StringRef(getStart(), getLength()); }
230
231 bool consumesDataArgument() const {
232 switch (kind) {
233 case PrintErrno:
234 assert(IsPrintf);
235 return false;
236 case PercentArg:
237 return false;
238 case InvalidSpecifier:
239 return false;
240 default:
241 return true;
242 }
243 }
244
245 Kind getKind() const { return kind; }
246 void setKind(Kind k) { kind = k; }
247 unsigned getLength() const {
248 return EndScanList ? EndScanList - Position : 1;
249 }
250 void setEndScanList(const char *pos) { EndScanList = pos; }
251
252 bool isIntArg() const {
253 return (kind >= IntArgBeg && kind <= IntArgEnd) || kind == FreeBSDrArg ||
254 kind == FreeBSDyArg;
255 }
256 bool isUIntArg() const { return kind >= UIntArgBeg && kind <= UIntArgEnd; }
257 bool isAnyIntArg() const { return kind >= IntArgBeg && kind <= UIntArgEnd; }
258 bool isDoubleArg() const {
259 return kind >= DoubleArgBeg && kind <= DoubleArgEnd;
260 }
261 bool isFixedPointArg() const {
263 }
264
265 const char *toString() const;
266
267 bool isPrintfKind() const { return IsPrintf; }
268
269 std::optional<ConversionSpecifier> getStandardSpecifier() const;
270
271protected:
273 const char *Position;
274 const char *EndScanList;
276};
277
278class ArgType {
279public:
292
293 /// How well a given conversion specifier matches its argument.
295 /// The conversion specifier and the argument types are incompatible. For
296 /// instance, "%d" and float.
298 /// The conversion specifier and the argument type are compatible. For
299 /// instance, "%d" and int.
300 Match = 1,
301 /// The conversion specifier and the argument type are compatible because of
302 /// default argument promotions. For instance, "%hhd" and int.
304 /// The conversion specifier and the argument type are compatible but still
305 /// seems likely to be an error. For instanace, "%hhd" and short.
307 /// The conversion specifier and the argument type are disallowed by the C
308 /// standard, but are in practice harmless. For instance, "%p" and int*.
310 /// The conversion specifier and the argument type have different sign.
312 /// The conversion specifier and the argument type are compatible, but still
313 /// seems likely to be an error. For instance, "%hd" and _Bool.
315 };
316
317private:
318 Kind K;
319 QualType T;
320 const char *Name = nullptr;
321 bool Ptr = false;
322
323 /// The TypeKind identifies certain well-known types.
324 enum class TypeKind {
325 DontCare,
326 SizeT,
327 PtrdiffT,
328 IntN,
329 UIntN,
330 FastIntN,
331 FastUIntN,
332 };
333 TypeKind TK = TypeKind::DontCare;
334 unsigned BitWidth = 0;
335
336public:
337 ArgType(Kind K = UnknownTy, const char *N = nullptr) : K(K), Name(N) {}
338 ArgType(QualType T, const char *N = nullptr) : K(SpecificTy), T(T), Name(N) {}
340
341 static ArgType Invalid() { return ArgType(InvalidTy); }
342 static ArgType Unsupported(const char *N) {
344 A.Name = N;
345 return A;
346 }
347 bool isValid() const { return K != InvalidTy; }
348 bool isUnsupported() const { return K == UnsupportedTy; }
349
350 bool isSizeT() const { return TK == TypeKind::SizeT; }
351
352 bool isPtrdiffT() const { return TK == TypeKind::PtrdiffT; }
353
354 /// Create an ArgType which corresponds to the type pointer to A.
355 static ArgType PtrTo(const ArgType &A) {
356 assert(A.K >= InvalidTy && "ArgType cannot be pointer to invalid/unknown");
357 ArgType Res = A;
358 Res.Ptr = true;
359 return Res;
360 }
361
362 /// Create an ArgType which corresponds to the size_t/ssize_t type.
363 static ArgType makeSizeT(const ArgType &A) {
364 ArgType Res = A;
365 Res.TK = TypeKind::SizeT;
366 return Res;
367 }
368
369 /// Create an ArgType which corresponds to the ptrdiff_t/unsigned ptrdiff_t
370 /// type.
371 static ArgType makePtrdiffT(const ArgType &A) {
372 ArgType Res = A;
373 Res.TK = TypeKind::PtrdiffT;
374 return Res;
375 }
376
377 static ArgType makeIntNType(ASTContext &Ctx, const LengthModifier &LengthMod,
378 bool Signed);
379
381 MatchKind matchesArgType(ASTContext &C, const ArgType &other) const;
382
384
385 ArgType makeVectorType(ASTContext &C, unsigned NumElts) const;
386
387 std::string getRepresentativeTypeName(ASTContext &C) const;
388};
389
391public:
393
394 OptionalAmount(HowSpecified howSpecified, unsigned amount,
395 const char *amountStart, unsigned amountLength,
397 : start(amountStart), length(amountLength), hs(howSpecified), amt(amount),
398 UsesPositionalArg(usesPositionalArg), UsesDotPrefix(false) {}
399
400 OptionalAmount(bool valid = true)
401 : start(nullptr), length(0), hs(valid ? NotSpecified : Invalid), amt(0),
402 UsesPositionalArg(false), UsesDotPrefix(false) {}
403
404 explicit OptionalAmount(unsigned Amount)
405 : start(nullptr), length(0), hs(Constant), amt(Amount),
406 UsesPositionalArg(false), UsesDotPrefix(false) {}
407
408 bool isInvalid() const { return hs == Invalid; }
409
410 HowSpecified getHowSpecified() const { return hs; }
411 void setHowSpecified(HowSpecified h) { hs = h; }
412
413 bool hasDataArgument() const { return hs == Arg; }
414
415 unsigned getArgIndex() const {
416 assert(hasDataArgument());
417 return amt;
418 }
419
420 unsigned getConstantAmount() const {
421 assert(hs == Constant);
422 return amt;
423 }
424
425 const char *getStart() const {
426 // We include the . character if it is given.
427 return start - UsesDotPrefix;
428 }
429
430 unsigned getConstantLength() const {
431 assert(hs == Constant);
432 return length + UsesDotPrefix;
433 }
434
435 StringRef getCharacters() const {
436 return StringRef(start - UsesDotPrefix, length + UsesDotPrefix);
437 }
438
439 ArgType getArgType(ASTContext &Ctx) const;
440
441 void toString(raw_ostream &os) const;
442
443 bool usesPositionalArg() const { return (bool)UsesPositionalArg; }
444 unsigned getPositionalArgIndex() const {
445 assert(hasDataArgument());
446 return amt + 1;
447 }
448
449 bool usesDotPrefix() const { return UsesDotPrefix; }
450 void setUsesDotPrefix() { UsesDotPrefix = true; }
451
452private:
453 const char *start;
454 unsigned length;
455 HowSpecified hs;
456 unsigned amt;
457 bool UsesPositionalArg : 1;
458 bool UsesDotPrefix;
459};
460
462protected:
467
468 /// Positional arguments, an IEEE extension:
469 /// IEEE Std 1003.1, 2004 Edition
470 /// http://www.opengroup.org/onlinepubs/009695399/functions/printf.html
472 unsigned argIndex;
473
474public:
475 FormatSpecifier(bool isPrintf)
477 argIndex(0) {}
478
480
482
483 void setArgIndex(unsigned i) { argIndex = i; }
484
485 unsigned getArgIndex() const { return argIndex; }
486
487 unsigned getPositionalArgIndex() const { return argIndex + 1; }
488
489 const LengthModifier &getLengthModifier() const { return LM; }
490
491 const OptionalAmount &getFieldWidth() const { return FieldWidth; }
492
494
496
497 void setFieldWidth(const OptionalAmount &Amt) { FieldWidth = Amt; }
498
499 bool usesPositionalArg() const { return UsesPositionalArg; }
500
502 const LangOptions &LO) const;
503
504 bool hasStandardLengthModifier() const;
505
506 std::optional<LengthModifier> getCorrectedLengthModifier() const;
507
508 bool hasStandardConversionSpecifier(const LangOptions &LangOpt) const;
509
511
512 /// For a TypedefType QT, if it is a named integer type such as size_t,
513 /// assign the appropriate value to LM and return true.
514 static bool namedTypeToLengthModifier(ASTContext &Ctx, QualType QT,
516};
517
518} // namespace analyze_format_string
519
520//===----------------------------------------------------------------------===//
521/// Pieces specific to fprintf format strings.
522
523namespace analyze_printf {
524
527public:
530
531 PrintfConversionSpecifier(const char *pos, Kind k)
532 : ConversionSpecifier(true, pos, k) {}
533
534 bool isObjCArg() const { return kind >= ObjCBeg && kind <= ObjCEnd; }
535 bool isDoubleArg() const {
536 return kind >= DoubleArgBeg && kind <= DoubleArgEnd;
537 }
538
540 return CS->isPrintfKind();
541 }
542};
543
548
550 OptionalFlag HasThousandsGrouping; // ''', POSIX extension.
551 OptionalFlag IsLeftJustified; // '-'
552 OptionalFlag HasPlusPrefix; // '+'
553 OptionalFlag HasSpacePrefix; // ' '
554 OptionalFlag HasAlternativeForm; // '#'
555 OptionalFlag HasLeadingZeroes; // '0'
556 OptionalFlag HasObjCTechnicalTerm; // '[tt]'
557 OptionalFlag IsPrivate; // '{private}'
558 OptionalFlag IsPublic; // '{public}'
559 OptionalFlag IsSensitive; // '{sensitive}'
560 OptionalAmount Precision;
561 StringRef MaskType;
562
563 ArgType getScalarArgType(ASTContext &Ctx, bool IsObjCLiteral) const;
564
565public:
567 : FormatSpecifier(/* isPrintf = */ true), HasThousandsGrouping("'"),
568 IsLeftJustified("-"), HasPlusPrefix("+"), HasSpacePrefix(" "),
569 HasAlternativeForm("#"), HasLeadingZeroes("0"),
570 HasObjCTechnicalTerm("tt"), IsPrivate("private"), IsPublic("public"),
571 IsSensitive("sensitive") {}
572
573 static PrintfSpecifier Parse(const char *beg, const char *end);
574
575 // Methods for incrementally constructing the PrintfSpecifier.
577 void setHasThousandsGrouping(const char *position) {
578 HasThousandsGrouping.setPosition(position);
579 }
580 void setIsLeftJustified(const char *position) {
581 IsLeftJustified.setPosition(position);
582 }
583 void setHasPlusPrefix(const char *position) {
584 HasPlusPrefix.setPosition(position);
585 }
586 void setHasSpacePrefix(const char *position) {
587 HasSpacePrefix.setPosition(position);
588 }
589 void setHasAlternativeForm(const char *position) {
590 HasAlternativeForm.setPosition(position);
591 }
592 void setHasLeadingZeros(const char *position) {
593 HasLeadingZeroes.setPosition(position);
594 }
595 void setHasObjCTechnicalTerm(const char *position) {
596 HasObjCTechnicalTerm.setPosition(position);
597 }
598 void setIsPrivate(const char *position) { IsPrivate.setPosition(position); }
599 void setIsPublic(const char *position) { IsPublic.setPosition(position); }
600 void setIsSensitive(const char *position) {
601 IsSensitive.setPosition(position);
602 }
604
605 // Methods for querying the format specifier.
606
610
611 void setPrecision(const OptionalAmount &Amt) {
612 Precision = Amt;
613 Precision.setUsesDotPrefix();
614 }
615
616 const OptionalAmount &getPrecision() const { return Precision; }
617
621
622 /// Returns the builtin type that a data argument
623 /// paired with this format specifier should have. This method
624 /// will return null if the format specifier does not have
625 /// a matching data argument or the matching argument matches
626 /// more than one type.
627 ArgType getArgType(ASTContext &Ctx, bool IsObjCLiteral) const;
628
630 return HasThousandsGrouping;
631 }
632 const OptionalFlag &isLeftJustified() const { return IsLeftJustified; }
633 const OptionalFlag &hasPlusPrefix() const { return HasPlusPrefix; }
634 const OptionalFlag &hasAlternativeForm() const { return HasAlternativeForm; }
635 const OptionalFlag &hasLeadingZeros() const { return HasLeadingZeroes; }
636 const OptionalFlag &hasSpacePrefix() const { return HasSpacePrefix; }
638 return HasObjCTechnicalTerm;
639 }
640 const OptionalFlag &isPrivate() const { return IsPrivate; }
641 const OptionalFlag &isPublic() const { return IsPublic; }
642 const OptionalFlag &isSensitive() const { return IsSensitive; }
643 bool usesPositionalArg() const { return UsesPositionalArg; }
644
645 StringRef getMaskType() const { return MaskType; }
646 void setMaskType(StringRef S) { MaskType = S; }
647
648 /// Changes the specifier and length according to a QualType, retaining any
649 /// flags or options. Returns true on success, or false when a conversion
650 /// was not successful.
651 bool fixType(QualType QT, const LangOptions &LangOpt, ASTContext &Ctx,
652 bool IsObjCLiteral);
653
654 void toString(raw_ostream &os) const;
655
656 // Validation methods - to check if any element results in undefined behavior
657 bool hasValidPlusPrefix() const;
658 bool hasValidAlternativeForm() const;
659 bool hasValidLeadingZeros() const;
660 bool hasValidSpacePrefix() const;
661 bool hasValidLeftJustified() const;
663
664 bool hasValidPrecision() const;
665 bool hasValidFieldWidth() const;
666};
667} // namespace analyze_printf
668
669//===----------------------------------------------------------------------===//
670/// Pieces specific to fscanf format strings.
671
672namespace analyze_scanf {
673
687
692
694 OptionalFlag SuppressAssignment; // '*'
695public:
697 : FormatSpecifier(/* isPrintf = */ false), SuppressAssignment("*") {}
698
699 void setSuppressAssignment(const char *position) {
700 SuppressAssignment.setPosition(position);
701 }
702
704 return SuppressAssignment;
705 }
706
708
712
713 bool consumesDataArgument() const {
714 return CS.consumesDataArgument() && !SuppressAssignment;
715 }
716
717 ArgType getArgType(ASTContext &Ctx) const;
718
719 bool fixType(QualType QT, QualType RawQT, const LangOptions &LangOpt,
720 ASTContext &Ctx);
721
722 void toString(raw_ostream &os) const;
723
724 static ScanfSpecifier Parse(const char *beg, const char *end);
725};
726
727} // namespace analyze_scanf
728
729//===----------------------------------------------------------------------===//
730// Parsing and processing of format strings (both fprintf and fscanf).
731
732namespace analyze_format_string {
733
735
737public:
739 virtual ~FormatStringHandler();
740
741 virtual void HandleNullChar(const char *nullCharacter) {}
742
743 virtual void HandlePosition(const char *startPos, unsigned posLen) {}
744
745 virtual void HandleInvalidPosition(const char *startPos, unsigned posLen,
746 PositionContext p) {}
747
748 virtual void HandleZeroPosition(const char *startPos, unsigned posLen) {}
749
750 virtual void HandleIncompleteSpecifier(const char *startSpecifier,
751 unsigned specifierLen) {}
752
753 virtual void HandleEmptyObjCModifierFlag(const char *startFlags,
754 unsigned flagsLen) {}
755
756 virtual void HandleInvalidObjCModifierFlag(const char *startFlag,
757 unsigned flagLen) {}
758
759 virtual void
761 const char *flagsEnd,
762 const char *conversionPosition) {}
763 // Printf-specific handlers.
764
766 const analyze_printf::PrintfSpecifier &FS, const char *startSpecifier,
767 unsigned specifierLen) {
768 return true;
769 }
770
772 const char *startSpecifier,
773 unsigned specifierLen,
774 const TargetInfo &Target) {
775 return true;
776 }
777
778 /// Handle mask types whose sizes are not between one and eight bytes.
779 virtual void handleInvalidMaskType(StringRef MaskType) {}
780
781 // Scanf-specific handlers.
782
783 virtual bool
785 const char *startSpecifier,
786 unsigned specifierLen) {
787 return true;
788 }
789
791 const char *startSpecifier,
792 unsigned specifierLen) {
793 return true;
794 }
795
796 virtual void HandleIncompleteScanList(const char *start, const char *end) {}
797};
798
799bool ParsePrintfString(FormatStringHandler &H, const char *beg, const char *end,
800 const LangOptions &LO, const TargetInfo &Target,
801 bool isFreeBSDKPrintf);
802
803bool ParseFormatStringHasSArg(const char *beg, const char *end,
804 const LangOptions &LO, const TargetInfo &Target);
805
806bool ParseScanfString(FormatStringHandler &H, const char *beg, const char *end,
807 const LangOptions &LO, const TargetInfo &Target);
808
809/// Return true if the given string has at least one formatting specifier.
810bool parseFormatStringHasFormattingSpecifiers(const char *Begin,
811 const char *End,
812 const LangOptions &LO,
813 const TargetInfo &Target);
814
815} // namespace analyze_format_string
816} // namespace clang
817#endif
*collection of selector each with an associated kind and an ordered *collection of selectors A selector has a kind
ArgType(Kind K=UnknownTy, const char *N=nullptr)
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition ASTContext.h:223
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
A (possibly-)qualified type.
Definition TypeBase.h:937
Exposes information about the current target.
Definition TargetInfo.h:227
static ArgType makePtrdiffT(const ArgType &A)
Create an ArgType which corresponds to the ptrdiff_t/unsigned ptrdiff_t type.
MatchKind
How well a given conversion specifier matches its argument.
@ NoMatch
The conversion specifier and the argument types are incompatible.
@ NoMatchPedantic
The conversion specifier and the argument type are disallowed by the C standard, but are in practice ...
@ Match
The conversion specifier and the argument type are compatible.
@ MatchPromotion
The conversion specifier and the argument type are compatible because of default argument promotions.
@ NoMatchSignedness
The conversion specifier and the argument type have different sign.
@ NoMatchTypeConfusion
The conversion specifier and the argument type are compatible, but still seems likely to be an error.
@ NoMatchPromotionTypeConfusion
The conversion specifier and the argument type are compatible but still seems likely to be an error.
static ArgType PtrTo(const ArgType &A)
Create an ArgType which corresponds to the type pointer to A.
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
static ArgType Unsupported(const char *N)
static ArgType makeIntNType(ASTContext &Ctx, const LengthModifier &LengthMod, bool Signed)
ArgType(QualType T, const char *N=nullptr)
static ArgType makeSizeT(const ArgType &A)
Create an ArgType which corresponds to the size_t/ssize_t type.
ArgType(Kind K=UnknownTy, const char *N=nullptr)
MatchKind matchesType(ASTContext &C, QualType argTy) const
std::optional< ConversionSpecifier > getStandardSpecifier() const
ConversionSpecifier(bool isPrintf, const char *pos, Kind k)
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)
const OptionalAmount & getFieldWidth() const
bool hasStandardConversionSpecifier(const LangOptions &LangOpt) const
const LengthModifier & getLengthModifier() const
const OptionalAmount & getVectorNumElts() const
bool hasValidLengthModifier(const TargetInfo &Target, const LangOptions &LO) const
bool UsesPositionalArg
Positional arguments, an IEEE extension: IEEE Std 1003.1, 2004 Edition http://www....
std::optional< LengthModifier > getCorrectedLengthModifier() const
void setVectorNumElts(const OptionalAmount &Amt)
virtual bool HandleInvalidPrintfConversionSpecifier(const analyze_printf::PrintfSpecifier &FS, const char *startSpecifier, unsigned specifierLen)
virtual void HandleObjCFlagsWithNonObjCConversion(const char *flagsStart, const char *flagsEnd, const char *conversionPosition)
virtual void HandleInvalidObjCModifierFlag(const char *startFlag, unsigned flagLen)
virtual void HandleIncompleteScanList(const char *start, const char *end)
virtual void HandleNullChar(const char *nullCharacter)
virtual void handleInvalidMaskType(StringRef MaskType)
Handle mask types whose sizes are not between one and eight bytes.
virtual void HandlePosition(const char *startPos, unsigned posLen)
virtual bool HandlePrintfSpecifier(const analyze_printf::PrintfSpecifier &FS, const char *startSpecifier, unsigned specifierLen, const TargetInfo &Target)
virtual void HandleInvalidPosition(const char *startPos, unsigned posLen, PositionContext p)
virtual void HandleEmptyObjCModifierFlag(const char *startFlags, unsigned flagsLen)
virtual void HandleZeroPosition(const char *startPos, unsigned posLen)
virtual void HandleIncompleteSpecifier(const char *startSpecifier, unsigned specifierLen)
virtual bool HandleScanfSpecifier(const analyze_scanf::ScanfSpecifier &FS, const char *startSpecifier, unsigned specifierLen)
virtual bool HandleInvalidScanfConversionSpecifier(const analyze_scanf::ScanfSpecifier &FS, const char *startSpecifier, unsigned specifierLen)
Represents the length modifier in a format string in scanf/printf.
LengthModifier(const char *pos, Kind k, unsigned bitWidth, unsigned length)
ArgType getArgType(ASTContext &Ctx) const
OptionalAmount(HowSpecified howSpecified, unsigned amount, const char *amountStart, unsigned amountLength, bool usesPositionalArg)
Class representing optional flags with location and representation information.
OptionalFlag(const char *Representation)
void setPosition(const char *position)
OptionalFlag & operator=(const bool &rhs)
static bool classof(const analyze_format_string::ConversionSpecifier *CS)
const OptionalFlag & isPrivate() const
void setHasAlternativeForm(const char *position)
void setIsSensitive(const char *position)
void setHasSpacePrefix(const char *position)
void setHasThousandsGrouping(const char *position)
const OptionalAmount & getPrecision() const
static PrintfSpecifier Parse(const char *beg, const char *end)
const OptionalFlag & hasSpacePrefix() const
void setIsLeftJustified(const char *position)
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
const OptionalFlag & isLeftJustified() const
const OptionalFlag & hasLeadingZeros() const
const OptionalFlag & hasAlternativeForm() const
void setHasPlusPrefix(const char *position)
void setIsPrivate(const char *position)
const PrintfConversionSpecifier & getConversionSpecifier() const
void setHasLeadingZeros(const char *position)
const OptionalFlag & hasPlusPrefix() const
const OptionalFlag & hasThousandsGrouping() const
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)
const OptionalFlag & hasObjCTechnicalTerm() const
void setPrecision(const OptionalAmount &Amt)
void setHasObjCTechnicalTerm(const char *position)
const OptionalFlag & isPublic() const
void setConversionSpecifier(const PrintfConversionSpecifier &cs)
ScanfConversionSpecifier(const char *pos, Kind k)
static bool classof(const analyze_format_string::ConversionSpecifier *CS)
static ScanfSpecifier Parse(const char *beg, const char *end)
bool fixType(QualType QT, QualType RawQT, const LangOptions &LangOpt, ASTContext &Ctx)
const OptionalFlag & getSuppressAssignment() const
void setConversionSpecifier(const ScanfConversionSpecifier &cs)
const ScanfConversionSpecifier & getConversionSpecifier() const
void setSuppressAssignment(const char *position)
ArgType getArgType(ASTContext &Ctx) const
Common components of both fprintf and fscanf format strings.
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)
Pieces specific to fprintf format strings.
Pieces specific to fscanf format strings.
The JSON file list parser is used to communicate input to InstallAPI.
CanQual< Type > CanQualType
Represents a canonical, potentially-qualified type.
nullptr
This class represents a compute construct, representing a 'Kind' of ‘parallel’, 'serial',...
U cast(CodeGen::Address addr)
Definition Address.h:327
float __ovld __cnfn length(float)
Return the length of vector p, i.e., sqrt(p.x2 + p.y 2 + ...)
#define false
Definition stdbool.h:26
#define true
Definition stdbool.h:25