clang  16.0.0git
PrintfFormatString.cpp
Go to the documentation of this file.
1 //== PrintfFormatString.cpp - Analysis of printf 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 // Handling of format string in printf and friends. The structure of format
10 // strings for fprintf() are described in C99 7.19.6.1.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "FormatStringParsing.h"
15 #include "clang/AST/FormatString.h"
16 #include "clang/AST/OSLog.h"
17 #include "clang/Basic/TargetInfo.h"
18 #include "llvm/Support/Regex.h"
19 
26 
27 using namespace clang;
28 
31 
32 //===----------------------------------------------------------------------===//
33 // Methods for parsing format strings.
34 //===----------------------------------------------------------------------===//
35 
37 
39  const char *Start, const char *&Beg, const char *E,
40  unsigned *argIndex) {
41  if (argIndex) {
42  FS.setPrecision(ParseNonPositionAmount(Beg, E, *argIndex));
43  } else {
44  const OptionalAmount Amt = ParsePositionAmount(H, Start, Beg, E,
46  if (Amt.isInvalid())
47  return true;
48  FS.setPrecision(Amt);
49  }
50  return false;
51 }
52 
54  const char *FlagBeg, const char *E, bool Warn) {
55  StringRef Flag(FlagBeg, E - FlagBeg);
56  // Currently there is only one flag.
57  if (Flag == "tt") {
58  FS.setHasObjCTechnicalTerm(FlagBeg);
59  return false;
60  }
61  // Handle either the case of no flag or an invalid flag.
62  if (Warn) {
63  if (Flag == "")
64  H.HandleEmptyObjCModifierFlag(FlagBeg, E - FlagBeg);
65  else
66  H.HandleInvalidObjCModifierFlag(FlagBeg, E - FlagBeg);
67  }
68  return true;
69 }
70 
72  const char *&Beg,
73  const char *E,
74  unsigned &argIndex,
75  const LangOptions &LO,
76  const TargetInfo &Target,
77  bool Warn,
78  bool isFreeBSDKPrintf) {
79 
80  using namespace clang::analyze_format_string;
81  using namespace clang::analyze_printf;
82 
83  const char *I = Beg;
84  const char *Start = nullptr;
85  UpdateOnReturn <const char*> UpdateBeg(Beg, I);
86 
87  // Look for a '%' character that indicates the start of a format specifier.
88  for ( ; I != E ; ++I) {
89  char c = *I;
90  if (c == '\0') {
91  // Detect spurious null characters, which are likely errors.
92  H.HandleNullChar(I);
93  return true;
94  }
95  if (c == '%') {
96  Start = I++; // Record the start of the format specifier.
97  break;
98  }
99  }
100 
101  // No format specifier found?
102  if (!Start)
103  return false;
104 
105  if (I == E) {
106  // No more characters left?
107  if (Warn)
108  H.HandleIncompleteSpecifier(Start, E - Start);
109  return true;
110  }
111 
112  PrintfSpecifier FS;
113  if (ParseArgPosition(H, FS, Start, I, E))
114  return true;
115 
116  if (I == E) {
117  // No more characters left?
118  if (Warn)
119  H.HandleIncompleteSpecifier(Start, E - Start);
120  return true;
121  }
122 
123  if (*I == '{') {
124  ++I;
125  unsigned char PrivacyFlags = 0;
126  StringRef MatchedStr;
127 
128  do {
129  StringRef Str(I, E - I);
130  std::string Match = "^[[:space:]]*"
131  "(private|public|sensitive|mask\\.[^[:space:],}]*)"
132  "[[:space:]]*(,|})";
133  llvm::Regex R(Match);
135 
136  if (R.match(Str, &Matches)) {
137  MatchedStr = Matches[1];
138  I += Matches[0].size();
139 
140  // Set the privacy flag if the privacy annotation in the
141  // comma-delimited segment is at least as strict as the privacy
142  // annotations in previous comma-delimited segments.
143  if (MatchedStr.startswith("mask")) {
144  StringRef MaskType = MatchedStr.substr(sizeof("mask.") - 1);
145  unsigned Size = MaskType.size();
146  if (Warn && (Size == 0 || Size > 8))
147  H.handleInvalidMaskType(MaskType);
148  FS.setMaskType(MaskType);
149  } else if (MatchedStr.equals("sensitive"))
151  else if (PrivacyFlags !=
153  MatchedStr.equals("private"))
155  else if (PrivacyFlags == 0 && MatchedStr.equals("public"))
157  } else {
158  size_t CommaOrBracePos =
159  Str.find_if([](char c) { return c == ',' || c == '}'; });
160 
161  if (CommaOrBracePos == StringRef::npos) {
162  // Neither a comma nor the closing brace was found.
163  if (Warn)
164  H.HandleIncompleteSpecifier(Start, E - Start);
165  return true;
166  }
167 
168  I += CommaOrBracePos + 1;
169  }
170  // Continue until the closing brace is found.
171  } while (*(I - 1) == ',');
172 
173  // Set the privacy flag.
174  switch (PrivacyFlags) {
175  case 0:
176  break;
178  FS.setIsPrivate(MatchedStr.data());
179  break;
181  FS.setIsPublic(MatchedStr.data());
182  break;
184  FS.setIsSensitive(MatchedStr.data());
185  break;
186  default:
187  llvm_unreachable("Unexpected privacy flag value");
188  }
189  }
190 
191  // Look for flags (if any).
192  bool hasMore = true;
193  for ( ; I != E; ++I) {
194  switch (*I) {
195  default: hasMore = false; break;
196  case '\'':
197  // FIXME: POSIX specific. Always accept?
198  FS.setHasThousandsGrouping(I);
199  break;
200  case '-': FS.setIsLeftJustified(I); break;
201  case '+': FS.setHasPlusPrefix(I); break;
202  case ' ': FS.setHasSpacePrefix(I); break;
203  case '#': FS.setHasAlternativeForm(I); break;
204  case '0': FS.setHasLeadingZeros(I); break;
205  }
206  if (!hasMore)
207  break;
208  }
209 
210  if (I == E) {
211  // No more characters left?
212  if (Warn)
213  H.HandleIncompleteSpecifier(Start, E - Start);
214  return true;
215  }
216 
217  // Look for the field width (if any).
218  if (ParseFieldWidth(H, FS, Start, I, E,
219  FS.usesPositionalArg() ? nullptr : &argIndex))
220  return true;
221 
222  if (I == E) {
223  // No more characters left?
224  if (Warn)
225  H.HandleIncompleteSpecifier(Start, E - Start);
226  return true;
227  }
228 
229  // Look for the precision (if any).
230  if (*I == '.') {
231  ++I;
232  if (I == E) {
233  if (Warn)
234  H.HandleIncompleteSpecifier(Start, E - Start);
235  return true;
236  }
237 
238  if (ParsePrecision(H, FS, Start, I, E,
239  FS.usesPositionalArg() ? nullptr : &argIndex))
240  return true;
241 
242  if (I == E) {
243  // No more characters left?
244  if (Warn)
245  H.HandleIncompleteSpecifier(Start, E - Start);
246  return true;
247  }
248  }
249 
250  if (ParseVectorModifier(H, FS, I, E, LO))
251  return true;
252 
253  // Look for the length modifier.
254  if (ParseLengthModifier(FS, I, E, LO) && I == E) {
255  // No more characters left?
256  if (Warn)
257  H.HandleIncompleteSpecifier(Start, E - Start);
258  return true;
259  }
260 
261  // Look for the Objective-C modifier flags, if any.
262  // We parse these here, even if they don't apply to
263  // the conversion specifier, and then emit an error
264  // later if the conversion specifier isn't '@'. This
265  // enables better recovery, and we don't know if
266  // these flags are applicable until later.
267  const char *ObjCModifierFlagsStart = nullptr,
268  *ObjCModifierFlagsEnd = nullptr;
269  if (*I == '[') {
270  ObjCModifierFlagsStart = I;
271  ++I;
272  auto flagStart = I;
273  for (;; ++I) {
274  ObjCModifierFlagsEnd = I;
275  if (I == E) {
276  if (Warn)
277  H.HandleIncompleteSpecifier(Start, E - Start);
278  return true;
279  }
280  // Did we find the closing ']'?
281  if (*I == ']') {
282  if (ParseObjCFlags(H, FS, flagStart, I, Warn))
283  return true;
284  ++I;
285  break;
286  }
287  // There are no separators defined yet for multiple
288  // Objective-C modifier flags. When those are
289  // defined, this is the place to check.
290  }
291  }
292 
293  if (*I == '\0') {
294  // Detect spurious null characters, which are likely errors.
295  H.HandleNullChar(I);
296  return true;
297  }
298 
299  // Finally, look for the conversion specifier.
300  const char *conversionPosition = I++;
302  switch (*conversionPosition) {
303  default:
304  break;
305  // C99: 7.19.6.1 (section 8).
306  case '%': k = ConversionSpecifier::PercentArg; break;
307  case 'A': k = ConversionSpecifier::AArg; break;
308  case 'E': k = ConversionSpecifier::EArg; break;
309  case 'F': k = ConversionSpecifier::FArg; break;
310  case 'G': k = ConversionSpecifier::GArg; break;
311  case 'X': k = ConversionSpecifier::XArg; break;
312  case 'a': k = ConversionSpecifier::aArg; break;
313  case 'c': k = ConversionSpecifier::cArg; break;
314  case 'd': k = ConversionSpecifier::dArg; break;
315  case 'e': k = ConversionSpecifier::eArg; break;
316  case 'f': k = ConversionSpecifier::fArg; break;
317  case 'g': k = ConversionSpecifier::gArg; break;
318  case 'i': k = ConversionSpecifier::iArg; break;
319  case 'n':
320  // Not handled, but reserved in OpenCL.
321  if (!LO.OpenCL)
323  break;
324  case 'o': k = ConversionSpecifier::oArg; break;
325  case 'p': k = ConversionSpecifier::pArg; break;
326  case 's': k = ConversionSpecifier::sArg; break;
327  case 'u': k = ConversionSpecifier::uArg; break;
328  case 'x': k = ConversionSpecifier::xArg; break;
329  // C23.
330  case 'b':
331  if (isFreeBSDKPrintf)
332  k = ConversionSpecifier::FreeBSDbArg; // int followed by char *
333  else
335  break;
336  case 'B': k = ConversionSpecifier::BArg; break;
337  // POSIX specific.
338  case 'C': k = ConversionSpecifier::CArg; break;
339  case 'S': k = ConversionSpecifier::SArg; break;
340  // Apple extension for os_log
341  case 'P':
343  break;
344  // Objective-C.
345  case '@': k = ConversionSpecifier::ObjCObjArg; break;
346  // Glibc specific.
347  case 'm': k = ConversionSpecifier::PrintErrno; break;
348  case 'r':
349  if (isFreeBSDKPrintf)
351  break;
352  case 'y':
353  if (isFreeBSDKPrintf)
355  break;
356  // Apple-specific.
357  case 'D':
358  if (isFreeBSDKPrintf)
359  k = ConversionSpecifier::FreeBSDDArg; // void * followed by char *
360  else if (Target.getTriple().isOSDarwin())
362  break;
363  case 'O':
364  if (Target.getTriple().isOSDarwin())
366  break;
367  case 'U':
368  if (Target.getTriple().isOSDarwin())
370  break;
371  // MS specific.
372  case 'Z':
373  if (Target.getTriple().isOSMSVCRT())
375  break;
376  }
377 
378  // Check to see if we used the Objective-C modifier flags with
379  // a conversion specifier other than '@'.
382  ObjCModifierFlagsStart) {
383  H.HandleObjCFlagsWithNonObjCConversion(ObjCModifierFlagsStart,
384  ObjCModifierFlagsEnd + 1,
385  conversionPosition);
386  return true;
387  }
388 
389  PrintfConversionSpecifier CS(conversionPosition, k);
390  FS.setConversionSpecifier(CS);
391  if (CS.consumesDataArgument() && !FS.usesPositionalArg())
392  FS.setArgIndex(argIndex++);
393  // FreeBSD kernel specific.
396  argIndex++;
397 
399  unsigned Len = I - Start;
400  if (ParseUTF8InvalidSpecifier(Start, E, Len)) {
401  CS.setEndScanList(Start + Len);
402  FS.setConversionSpecifier(CS);
403  }
404  // Assume the conversion takes one argument.
405  return !H.HandleInvalidPrintfConversionSpecifier(FS, Start, Len);
406  }
407  return PrintfSpecifierResult(Start, FS);
408 }
409 
411  const char *I,
412  const char *E,
413  const LangOptions &LO,
414  const TargetInfo &Target,
415  bool isFreeBSDKPrintf) {
416 
417  unsigned argIndex = 0;
418 
419  // Keep looking for a format specifier until we have exhausted the string.
420  while (I != E) {
421  const PrintfSpecifierResult &FSR = ParsePrintfSpecifier(H, I, E, argIndex,
422  LO, Target, true,
423  isFreeBSDKPrintf);
424  // Did a fail-stop error of any kind occur when parsing the specifier?
425  // If so, don't do any more processing.
426  if (FSR.shouldStop())
427  return true;
428  // Did we exhaust the string or encounter an error that
429  // we can recover from?
430  if (!FSR.hasValue())
431  continue;
432  // We have a format specifier. Pass it to the callback.
433  if (!H.HandlePrintfSpecifier(FSR.getValue(), FSR.getStart(),
434  I - FSR.getStart(), Target))
435  return true;
436  }
437  assert(I == E && "Format string not exhausted");
438  return false;
439 }
440 
442  const char *E,
443  const LangOptions &LO,
444  const TargetInfo &Target) {
445 
446  unsigned argIndex = 0;
447 
448  // Keep looking for a %s format specifier until we have exhausted the string.
450  while (I != E) {
451  const PrintfSpecifierResult &FSR = ParsePrintfSpecifier(H, I, E, argIndex,
452  LO, Target, false,
453  false);
454  // Did a fail-stop error of any kind occur when parsing the specifier?
455  // If so, don't do any more processing.
456  if (FSR.shouldStop())
457  return false;
458  // Did we exhaust the string or encounter an error that
459  // we can recover from?
460  if (!FSR.hasValue())
461  continue;
462  const analyze_printf::PrintfSpecifier &FS = FSR.getValue();
463  // Return true if this a %s format specifier.
464  if (FS.getConversionSpecifier().getKind() == ConversionSpecifier::Kind::sArg)
465  return true;
466  }
467  return false;
468 }
469 
471  const char *Begin, const char *End, const LangOptions &LO,
472  const TargetInfo &Target) {
473  unsigned ArgIndex = 0;
474  // Keep looking for a formatting specifier until we have exhausted the string.
476  while (Begin != End) {
477  const PrintfSpecifierResult &FSR =
478  ParsePrintfSpecifier(H, Begin, End, ArgIndex, LO, Target, false, false);
479  if (FSR.shouldStop())
480  break;
481  if (FSR.hasValue())
482  return true;
483  }
484  return false;
485 }
486 
487 //===----------------------------------------------------------------------===//
488 // Methods on PrintfSpecifier.
489 //===----------------------------------------------------------------------===//
490 
491 ArgType PrintfSpecifier::getScalarArgType(ASTContext &Ctx,
492  bool IsObjCLiteral) const {
493  if (CS.getKind() == ConversionSpecifier::cArg)
494  switch (LM.getKind()) {
496  return Ctx.IntTy;
499  return ArgType(ArgType::WIntTy, "wint_t");
501  if (Ctx.getTargetInfo().getTriple().isOSMSVCRT())
502  return Ctx.IntTy;
503  [[fallthrough]];
504  default:
505  return ArgType::Invalid();
506  }
507 
508  if (CS.isIntArg())
509  switch (LM.getKind()) {
511  // GNU extension.
512  return Ctx.LongLongTy;
515  return Ctx.IntTy;
517  return ArgType(Ctx.IntTy, "__int32");
519  return ArgType::AnyCharTy;
520  case LengthModifier::AsShort: return Ctx.ShortTy;
521  case LengthModifier::AsLong: return Ctx.LongTy;
524  return Ctx.LongLongTy;
526  return ArgType(Ctx.LongLongTy, "__int64");
528  return ArgType(Ctx.getIntMaxType(), "intmax_t");
530  return ArgType::makeSizeT(ArgType(Ctx.getSignedSizeType(), "ssize_t"));
532  return Ctx.getTargetInfo().getTriple().isArch64Bit()
533  ? ArgType(Ctx.LongLongTy, "__int64")
534  : ArgType(Ctx.IntTy, "__int32");
536  return ArgType::makePtrdiffT(
537  ArgType(Ctx.getPointerDiffType(), "ptrdiff_t"));
541  return ArgType::Invalid();
542  }
543 
544  if (CS.isUIntArg())
545  switch (LM.getKind()) {
547  // GNU extension.
548  return Ctx.UnsignedLongLongTy;
551  return Ctx.UnsignedIntTy;
553  return ArgType(Ctx.UnsignedIntTy, "unsigned __int32");
554  case LengthModifier::AsChar: return Ctx.UnsignedCharTy;
555  case LengthModifier::AsShort: return Ctx.UnsignedShortTy;
556  case LengthModifier::AsLong: return Ctx.UnsignedLongTy;
559  return Ctx.UnsignedLongLongTy;
561  return ArgType(Ctx.UnsignedLongLongTy, "unsigned __int64");
563  return ArgType(Ctx.getUIntMaxType(), "uintmax_t");
565  return ArgType::makeSizeT(ArgType(Ctx.getSizeType(), "size_t"));
567  return Ctx.getTargetInfo().getTriple().isArch64Bit()
568  ? ArgType(Ctx.UnsignedLongLongTy, "unsigned __int64")
569  : ArgType(Ctx.UnsignedIntTy, "unsigned __int32");
571  return ArgType::makePtrdiffT(
572  ArgType(Ctx.getUnsignedPointerDiffType(), "unsigned ptrdiff_t"));
576  return ArgType::Invalid();
577  }
578 
579  if (CS.isDoubleArg()) {
580  if (!VectorNumElts.isInvalid()) {
581  switch (LM.getKind()) {
583  return Ctx.HalfTy;
585  return Ctx.FloatTy;
587  default:
588  return Ctx.DoubleTy;
589  }
590  }
591 
592  if (LM.getKind() == LengthModifier::AsLongDouble)
593  return Ctx.LongDoubleTy;
594  return Ctx.DoubleTy;
595  }
596 
597  if (CS.getKind() == ConversionSpecifier::nArg) {
598  switch (LM.getKind()) {
600  return ArgType::PtrTo(Ctx.IntTy);
602  return ArgType::PtrTo(Ctx.SignedCharTy);
604  return ArgType::PtrTo(Ctx.ShortTy);
606  return ArgType::PtrTo(Ctx.LongTy);
609  return ArgType::PtrTo(Ctx.LongLongTy);
611  return ArgType::PtrTo(ArgType(Ctx.getIntMaxType(), "intmax_t"));
613  return ArgType::PtrTo(ArgType(Ctx.getSignedSizeType(), "ssize_t"));
615  return ArgType::PtrTo(ArgType(Ctx.getPointerDiffType(), "ptrdiff_t"));
617  return ArgType(); // FIXME: Is this a known extension?
624  return ArgType::Invalid();
626  llvm_unreachable("only used for OpenCL which doesn not handle nArg");
627  }
628  }
629 
630  switch (CS.getKind()) {
632  if (LM.getKind() == LengthModifier::AsWideChar) {
633  if (IsObjCLiteral)
635  "const unichar *");
636  return ArgType(ArgType::WCStrTy, "wchar_t *");
637  }
638  if (LM.getKind() == LengthModifier::AsWide)
639  return ArgType(ArgType::WCStrTy, "wchar_t *");
640  return ArgType::CStrTy;
642  if (IsObjCLiteral)
644  "const unichar *");
645  if (Ctx.getTargetInfo().getTriple().isOSMSVCRT() &&
646  LM.getKind() == LengthModifier::AsShort)
647  return ArgType::CStrTy;
648  return ArgType(ArgType::WCStrTy, "wchar_t *");
650  if (IsObjCLiteral)
651  return ArgType(Ctx.UnsignedShortTy, "unichar");
652  if (Ctx.getTargetInfo().getTriple().isOSMSVCRT() &&
653  LM.getKind() == LengthModifier::AsShort)
654  return Ctx.IntTy;
655  return ArgType(Ctx.WideCharTy, "wchar_t");
658  return ArgType::CPointerTy;
660  return ArgType::ObjCPointerTy;
661  default:
662  break;
663  }
664 
665  // FIXME: Handle other cases.
666  return ArgType();
667 }
668 
669 
670 ArgType PrintfSpecifier::getArgType(ASTContext &Ctx,
671  bool IsObjCLiteral) const {
672  const PrintfConversionSpecifier &CS = getConversionSpecifier();
673 
674  if (!CS.consumesDataArgument())
675  return ArgType::Invalid();
676 
677  ArgType ScalarTy = getScalarArgType(Ctx, IsObjCLiteral);
678  if (!ScalarTy.isValid() || VectorNumElts.isInvalid())
679  return ScalarTy;
680 
681  return ScalarTy.makeVectorType(Ctx, VectorNumElts.getConstantAmount());
682 }
683 
684 bool PrintfSpecifier::fixType(QualType QT, const LangOptions &LangOpt,
685  ASTContext &Ctx, bool IsObjCLiteral) {
686  // %n is different from other conversion specifiers; don't try to fix it.
687  if (CS.getKind() == ConversionSpecifier::nArg)
688  return false;
689 
690  // Handle Objective-C objects first. Note that while the '%@' specifier will
691  // not warn for structure pointer or void pointer arguments (because that's
692  // how CoreFoundation objects are implemented), we only show a fixit for '%@'
693  // if we know it's an object (block, id, class, or __attribute__((NSObject))).
694  if (QT->isObjCRetainableType()) {
695  if (!IsObjCLiteral)
696  return false;
697 
699 
700  // Disable irrelevant flags
701  HasThousandsGrouping = false;
702  HasPlusPrefix = false;
703  HasSpacePrefix = false;
704  HasAlternativeForm = false;
705  HasLeadingZeroes = false;
706  Precision.setHowSpecified(OptionalAmount::NotSpecified);
707  LM.setKind(LengthModifier::None);
708 
709  return true;
710  }
711 
712  // Handle strings next (char *, wchar_t *)
713  if (QT->isPointerType() && (QT->getPointeeType()->isAnyCharacterType())) {
714  CS.setKind(ConversionSpecifier::sArg);
715 
716  // Disable irrelevant flags
717  HasAlternativeForm = false;
718  HasLeadingZeroes = false;
719 
720  // Set the long length modifier for wide characters
721  if (QT->getPointeeType()->isWideCharType())
722  LM.setKind(LengthModifier::AsWideChar);
723  else
724  LM.setKind(LengthModifier::None);
725 
726  return true;
727  }
728 
729  // If it's an enum, get its underlying type.
730  if (const EnumType *ETy = QT->getAs<EnumType>())
731  QT = ETy->getDecl()->getIntegerType();
732 
733  const BuiltinType *BT = QT->getAs<BuiltinType>();
734  if (!BT) {
735  const VectorType *VT = QT->getAs<VectorType>();
736  if (VT) {
737  QT = VT->getElementType();
738  BT = QT->getAs<BuiltinType>();
739  VectorNumElts = OptionalAmount(VT->getNumElements());
740  }
741  }
742 
743  // We can only work with builtin types.
744  if (!BT)
745  return false;
746 
747  // Set length modifier
748  switch (BT->getKind()) {
749  case BuiltinType::Bool:
750  case BuiltinType::WChar_U:
751  case BuiltinType::WChar_S:
752  case BuiltinType::Char8: // FIXME: Treat like 'char'?
753  case BuiltinType::Char16:
754  case BuiltinType::Char32:
755  case BuiltinType::UInt128:
756  case BuiltinType::Int128:
757  case BuiltinType::Half:
758  case BuiltinType::BFloat16:
759  case BuiltinType::Float16:
760  case BuiltinType::Float128:
761  case BuiltinType::Ibm128:
762  case BuiltinType::ShortAccum:
763  case BuiltinType::Accum:
764  case BuiltinType::LongAccum:
765  case BuiltinType::UShortAccum:
766  case BuiltinType::UAccum:
767  case BuiltinType::ULongAccum:
768  case BuiltinType::ShortFract:
769  case BuiltinType::Fract:
770  case BuiltinType::LongFract:
771  case BuiltinType::UShortFract:
772  case BuiltinType::UFract:
773  case BuiltinType::ULongFract:
774  case BuiltinType::SatShortAccum:
775  case BuiltinType::SatAccum:
776  case BuiltinType::SatLongAccum:
777  case BuiltinType::SatUShortAccum:
778  case BuiltinType::SatUAccum:
779  case BuiltinType::SatULongAccum:
780  case BuiltinType::SatShortFract:
781  case BuiltinType::SatFract:
782  case BuiltinType::SatLongFract:
783  case BuiltinType::SatUShortFract:
784  case BuiltinType::SatUFract:
785  case BuiltinType::SatULongFract:
786  // Various types which are non-trivial to correct.
787  return false;
788 
789 #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
790  case BuiltinType::Id:
791 #include "clang/Basic/OpenCLImageTypes.def"
792 #define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
793  case BuiltinType::Id:
794 #include "clang/Basic/OpenCLExtensionTypes.def"
795 #define SVE_TYPE(Name, Id, SingletonId) \
796  case BuiltinType::Id:
797 #include "clang/Basic/AArch64SVEACLETypes.def"
798 #define PPC_VECTOR_TYPE(Name, Id, Size) \
799  case BuiltinType::Id:
800 #include "clang/Basic/PPCTypes.def"
801 #define RVV_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
802 #include "clang/Basic/RISCVVTypes.def"
803 #define SIGNED_TYPE(Id, SingletonId)
804 #define UNSIGNED_TYPE(Id, SingletonId)
805 #define FLOATING_TYPE(Id, SingletonId)
806 #define BUILTIN_TYPE(Id, SingletonId) \
807  case BuiltinType::Id:
808 #include "clang/AST/BuiltinTypes.def"
809  // Misc other stuff which doesn't make sense here.
810  return false;
811 
812  case BuiltinType::UInt:
813  case BuiltinType::Int:
814  case BuiltinType::Float:
815  LM.setKind(VectorNumElts.isInvalid() ?
817  break;
818  case BuiltinType::Double:
819  LM.setKind(VectorNumElts.isInvalid() ?
821  break;
822  case BuiltinType::Char_U:
823  case BuiltinType::UChar:
824  case BuiltinType::Char_S:
825  case BuiltinType::SChar:
826  LM.setKind(LengthModifier::AsChar);
827  break;
828 
829  case BuiltinType::Short:
830  case BuiltinType::UShort:
831  LM.setKind(LengthModifier::AsShort);
832  break;
833 
834  case BuiltinType::Long:
835  case BuiltinType::ULong:
836  LM.setKind(LengthModifier::AsLong);
837  break;
838 
839  case BuiltinType::LongLong:
840  case BuiltinType::ULongLong:
841  LM.setKind(LengthModifier::AsLongLong);
842  break;
843 
844  case BuiltinType::LongDouble:
845  LM.setKind(LengthModifier::AsLongDouble);
846  break;
847  }
848 
849  // Handle size_t, ptrdiff_t, etc. that have dedicated length modifiers in C99.
850  if (LangOpt.C99 || LangOpt.CPlusPlus11)
851  namedTypeToLengthModifier(QT, LM);
852 
853  // If fixing the length modifier was enough, we might be done.
854  if (hasValidLengthModifier(Ctx.getTargetInfo(), LangOpt)) {
855  // If we're going to offer a fix anyway, make sure the sign matches.
856  switch (CS.getKind()) {
859  if (QT->isSignedIntegerType())
861  break;
865  if (QT->isUnsignedIntegerType() && !HasPlusPrefix)
867  break;
868  default:
869  // Other specifiers do not have signed/unsigned variants.
870  break;
871  }
872 
873  const analyze_printf::ArgType &ATR = getArgType(Ctx, IsObjCLiteral);
874  if (ATR.isValid() && ATR.matchesType(Ctx, QT))
875  return true;
876  }
877 
878  // Set conversion specifier and disable any flags which do not apply to it.
879  // Let typedefs to char fall through to int, as %c is silly for uint8_t.
880  if (!QT->getAs<TypedefType>() && QT->isCharType()) {
881  CS.setKind(ConversionSpecifier::cArg);
882  LM.setKind(LengthModifier::None);
883  Precision.setHowSpecified(OptionalAmount::NotSpecified);
884  HasAlternativeForm = false;
885  HasLeadingZeroes = false;
886  HasPlusPrefix = false;
887  }
888  // Test for Floating type first as LongDouble can pass isUnsignedIntegerType
889  else if (QT->isRealFloatingType()) {
890  CS.setKind(ConversionSpecifier::fArg);
891  } else if (QT->isSignedIntegerType()) {
892  CS.setKind(ConversionSpecifier::dArg);
893  HasAlternativeForm = false;
894  } else if (QT->isUnsignedIntegerType()) {
895  CS.setKind(ConversionSpecifier::uArg);
896  HasAlternativeForm = false;
897  HasPlusPrefix = false;
898  } else {
899  llvm_unreachable("Unexpected type");
900  }
901 
902  return true;
903 }
904 
905 void PrintfSpecifier::toString(raw_ostream &os) const {
906  // Whilst some features have no defined order, we are using the order
907  // appearing in the C99 standard (ISO/IEC 9899:1999 (E) 7.19.6.1)
908  os << "%";
909 
910  // Positional args
911  if (usesPositionalArg()) {
912  os << getPositionalArgIndex() << "$";
913  }
914 
915  // Conversion flags
916  if (IsLeftJustified) os << "-";
917  if (HasPlusPrefix) os << "+";
918  if (HasSpacePrefix) os << " ";
919  if (HasAlternativeForm) os << "#";
920  if (HasLeadingZeroes) os << "0";
921 
922  // Minimum field width
923  FieldWidth.toString(os);
924  // Precision
925  Precision.toString(os);
926 
927  // Vector modifier
928  if (!VectorNumElts.isInvalid())
929  os << 'v' << VectorNumElts.getConstantAmount();
930 
931  // Length modifier
932  os << LM.toString();
933  // Conversion specifier
934  os << CS.toString();
935 }
936 
937 bool PrintfSpecifier::hasValidPlusPrefix() const {
938  if (!HasPlusPrefix)
939  return true;
940 
941  // The plus prefix only makes sense for signed conversions
942  switch (CS.getKind()) {
956  return true;
957 
958  default:
959  return false;
960  }
961 }
962 
963 bool PrintfSpecifier::hasValidAlternativeForm() const {
964  if (!HasAlternativeForm)
965  return true;
966 
967  // Alternate form flag only valid with the bBoxXaAeEfFgG conversions
968  switch (CS.getKind()) {
985  return true;
986 
987  default:
988  return false;
989  }
990 }
991 
992 bool PrintfSpecifier::hasValidLeadingZeros() const {
993  if (!HasLeadingZeroes)
994  return true;
995 
996  // Leading zeroes flag only valid with the bBdiouxXaAeEfFgG conversions
997  switch (CS.getKind()) {
1019  return true;
1020 
1021  default:
1022  return false;
1023  }
1024 }
1025 
1026 bool PrintfSpecifier::hasValidSpacePrefix() const {
1027  if (!HasSpacePrefix)
1028  return true;
1029 
1030  // The space prefix only makes sense for signed conversions
1031  switch (CS.getKind()) {
1045  return true;
1046 
1047  default:
1048  return false;
1049  }
1050 }
1051 
1052 bool PrintfSpecifier::hasValidLeftJustified() const {
1053  if (!IsLeftJustified)
1054  return true;
1055 
1056  // The left justified flag is valid for all conversions except n
1057  switch (CS.getKind()) {
1059  return false;
1060 
1061  default:
1062  return true;
1063  }
1064 }
1065 
1066 bool PrintfSpecifier::hasValidThousandsGroupingPrefix() const {
1067  if (!HasThousandsGrouping)
1068  return true;
1069 
1070  switch (CS.getKind()) {
1080  return true;
1081  default:
1082  return false;
1083  }
1084 }
1085 
1086 bool PrintfSpecifier::hasValidPrecision() const {
1087  if (Precision.getHowSpecified() == OptionalAmount::NotSpecified)
1088  return true;
1089 
1090  // Precision is only valid with the bBdiouxXaAeEfFgGsP conversions
1091  switch (CS.getKind()) {
1115  return true;
1116 
1117  default:
1118  return false;
1119  }
1120 }
1121 bool PrintfSpecifier::hasValidFieldWidth() const {
1122  if (FieldWidth.getHowSpecified() == OptionalAmount::NotSpecified)
1123  return true;
1124 
1125  // The field width is valid for all conversions except n
1126  switch (CS.getKind()) {
1128  return false;
1129 
1130  default:
1131  return true;
1132  }
1133 }
clang::BuiltinType
This class is used for builtin types like 'int'.
Definition: Type.h:2620
clang::ASTContext::LongDoubleTy
CanQualType LongDoubleTy
Definition: ASTContext.h:1119
clang::analyze_format_string::ConversionSpecifier::SArg
@ SArg
Definition: FormatString.h:162
clang::analyze_format_string::ConversionSpecifier::oArg
@ oArg
Definition: FormatString.h:137
clang::analyze_format_string::FormatStringHandler::HandleInvalidObjCModifierFlag
virtual void HandleInvalidObjCModifierFlag(const char *startFlag, unsigned flagLen)
Definition: FormatString.h:722
clang::analyze_format_string::ArgType::makeSizeT
static ArgType makeSizeT(const ArgType &A)
Create an ArgType which corresponds to the size_t/ssize_t type.
Definition: FormatString.h:312
clang::analyze_format_string::ConversionSpecifier::cArg
@ cArg
Definition: FormatString.h:126
clang::analyze_format_string::LengthModifier::AsWideChar
@ AsWideChar
Definition: FormatString.h:84
clang::analyze_format_string::FormatStringHandler::HandlePrintfSpecifier
virtual bool HandlePrintfSpecifier(const analyze_printf::PrintfSpecifier &FS, const char *startSpecifier, unsigned specifierLen, const TargetInfo &Target)
Definition: FormatString.h:737
clang::analyze_format_string::ConversionSpecifier::ObjCObjArg
@ ObjCObjArg
Definition: FormatString.h:174
clang::ASTContext::UnsignedShortTy
CanQualType UnsignedShortTy
Definition: ASTContext.h:1117
clang::analyze_format_string::SpecifierResult
Definition: FormatStringParsing.h:72
clang::Type::isObjCRetainableType
bool isObjCRetainableType() const
Definition: Type.cpp:4385
string
string(SUBSTRING ${CMAKE_CURRENT_BINARY_DIR} 0 ${PATH_LIB_START} PATH_HEAD) string(SUBSTRING $
Definition: CMakeLists.txt:22
clang::analyze_printf::PrintfSpecifier
Definition: FormatString.h:510
clang::analyze_format_string::ConversionSpecifier::setEndScanList
void setEndScanList(const char *pos)
Definition: FormatString.h:230
clang::analyze_format_string::LengthModifier::AsMAllocate
@ AsMAllocate
Definition: FormatString.h:82
clang::analyze_format_string::LengthModifier::AsLongDouble
@ AsLongDouble
Definition: FormatString.h:80
clang::analyze_format_string::FormatStringHandler::HandleEmptyObjCModifierFlag
virtual void HandleEmptyObjCModifierFlag(const char *startFlags, unsigned flagsLen)
Definition: FormatString.h:719
clang::analyze_format_string::ConversionSpecifier::xArg
@ xArg
Definition: FormatString.h:141
clang::Type::isCharType
bool isCharType() const
Definition: Type.cpp:1962
llvm::SmallVector
Definition: LLVM.h:38
clang::analyze_format_string::FormatStringHandler
Definition: FormatString.h:702
TargetInfo.h
clang::MultiVersionKind::Target
@ Target
clang::Type::isWideCharType
bool isWideCharType() const
Definition: Type.cpp:1971
clang::QualType
A (possibly-)qualified type.
Definition: Type.h:737
clang::analyze_format_string::ConversionSpecifier::sArg
@ sArg
Definition: FormatString.h:157
clang::TargetInfo
Exposes information about the current target.
Definition: TargetInfo.h:205
clang::Type::isRealFloatingType
bool isRealFloatingType() const
Floating point categories.
Definition: Type.cpp:2138
clang::analyze_os_log::OSLogBufferItem::IsPublic
@ IsPublic
Definition: OSLog.h:65
clang::analyze_format_string::LengthModifier::AsInt3264
@ AsInt3264
Definition: FormatString.h:78
clang::analyze_format_string::ArgType::WIntTy
@ WIntTy
Definition: FormatString.h:256
clang::analyze_format_string::ArgType::makeVectorType
ArgType makeVectorType(ASTContext &C, unsigned NumElts) const
Definition: FormatString.cpp:559
clang::ASTContext::getUnsignedPointerDiffType
QualType getUnsignedPointerDiffType() const
Return the unique unsigned counterpart of "ptrdiff_t" integer type.
Definition: ASTContext.cpp:5984
clang::analyze_format_string::ParsePositionAmount
OptionalAmount ParsePositionAmount(FormatStringHandler &H, const char *Start, const char *&Beg, const char *E, PositionContext p)
Definition: FormatString.cpp:74
clang::analyze_format_string::ConversionSpecifier::iArg
@ iArg
Definition: FormatString.h:129
clang::analyze_format_string::ConversionSpecifier
Definition: FormatString.h:121
clang::analyze_format_string::PrecisionPos
@ PrecisionPos
Definition: FormatString.h:700
clang::analyze_format_string::ConversionSpecifier::FArg
@ FArg
Definition: FormatString.h:147
clang::analyze_printf::PrintfConversionSpecifier
Definition: FormatString.h:487
End
SourceLocation End
Definition: USRLocFinder.cpp:167
ParseObjCFlags
static bool ParseObjCFlags(FormatStringHandler &H, PrintfSpecifier &FS, const char *FlagBeg, const char *E, bool Warn)
Definition: PrintfFormatString.cpp:53
clang::analyze_format_string::ConversionSpecifier::fArg
@ fArg
Definition: FormatString.h:146
clang::analyze_format_string::ConversionSpecifier::FreeBSDDArg
@ FreeBSDDArg
Definition: FormatString.h:180
clang::TypedefType
Definition: Type.h:4535
clang::analyze_format_string::SpecifierResult::shouldStop
bool shouldStop() const
Definition: FormatStringParsing.h:84
clang::analyze_format_string::ParsePrintfString
bool ParsePrintfString(FormatStringHandler &H, const char *beg, const char *end, const LangOptions &LO, const TargetInfo &Target, bool isFreeBSDKPrintf)
Definition: PrintfFormatString.cpp:410
clang::analyze_format_string::OptionalAmount
Definition: FormatString.h:335
ParsePrecision
static bool ParsePrecision(FormatStringHandler &H, PrintfSpecifier &FS, const char *Start, const char *&Beg, const char *E, unsigned *argIndex)
Definition: PrintfFormatString.cpp:38
clang::ASTContext::getIntMaxType
CanQualType getIntMaxType() const
Return the unique type for "intmax_t" (C99 7.18.1.5), defined in <stdint.h>.
Definition: ASTContext.cpp:5944
clang::analyze_format_string::ConversionSpecifier::nArg
@ nArg
Definition: FormatString.h:159
clang::ASTContext::WideCharTy
CanQualType WideCharTy
Definition: ASTContext.h:1111
clang::analyze_format_string::ConversionSpecifier::gArg
@ gArg
Definition: FormatString.h:150
clang::analyze_format_string::FormatStringHandler::handleInvalidMaskType
virtual void handleInvalidMaskType(StringRef MaskType)
Handle mask types whose sizes are not between one and eight bytes.
Definition: FormatString.h:745
clang::analyze_format_string::ArgType::makePtrdiffT
static ArgType makePtrdiffT(const ArgType &A)
Create an ArgType which corresponds to the ptrdiff_t/unsigned ptrdiff_t type.
Definition: FormatString.h:320
clang::analyze_format_string::ConversionSpecifier::BArg
@ BArg
Definition: FormatString.h:132
clang::Type::isAnyCharacterType
bool isAnyCharacterType() const
Determine whether this type is any of the built-in character types.
Definition: Type.cpp:1998
clang::threadSafety::sx::toString
std::string toString(const til::SExpr *E)
Definition: ThreadSafetyCommon.h:91
clang::VectorType
Represents a GCC generic vector type.
Definition: Type.h:3358
clang::analyze_format_string::ConversionSpecifier::DArg
@ DArg
Definition: FormatString.h:128
clang::ASTContext
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:209
clang::ASTContext::getSizeType
CanQualType getSizeType() const
Return the unique type for "size_t" (C99 7.17), defined in <stddef.h>.
Definition: ASTContext.cpp:5933
clang::analyze_format_string::ArgType::PtrTo
static ArgType PtrTo(const ArgType &A)
Create an ArgType which corresponds to the type pointer to A.
Definition: FormatString.h:304
clang::analyze_format_string::ConversionSpecifier::consumesDataArgument
bool consumesDataArgument() const
Definition: FormatString.h:211
clang::Type::getAs
const T * getAs() const
Member-template getAs<specific type>'.
Definition: Type.h:7386
clang::analyze_format_string::ParseLengthModifier
bool ParseLengthModifier(FormatSpecifier &FS, const char *&Beg, const char *E, const LangOptions &LO, bool IsScanf=false)
Returns true if a LengthModifier was parsed and installed in the FormatSpecifier& argument,...
Definition: FormatString.cpp:210
clang::analyze_format_string::ConversionSpecifier::FreeBSDyArg
@ FreeBSDyArg
Definition: FormatString.h:182
FormatStringParsing.h
clang::analyze_format_string::ConversionSpecifier::bArg
@ bArg
Definition: FormatString.h:131
clang::analyze_format_string::ConversionSpecifier::dArg
@ dArg
Definition: FormatString.h:127
clang::analyze_format_string::SpecifierResult::getValue
const T & getValue() const
Definition: FormatStringParsing.h:86
clang::analyze_format_string::ArgType::AnyCharTy
@ AnyCharTy
Definition: FormatString.h:256
clang::analyze_format_string::ParseVectorModifier
bool ParseVectorModifier(FormatStringHandler &H, FormatSpecifier &FS, const char *&Beg, const char *E, const LangOptions &LO)
Definition: FormatString.cpp:180
clang::analyze_format_string::ArgType::CPointerTy
@ CPointerTy
Definition: FormatString.h:255
clang::analyze_format_string::LengthModifier::AsWide
@ AsWide
Definition: FormatString.h:83
clang::ASTContext::FloatTy
CanQualType FloatTy
Definition: ASTContext.h:1119
clang::Type::getPointeeType
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
Definition: Type.cpp:625
clang::analyze_format_string::ConversionSpecifier::uArg
@ uArg
Definition: FormatString.h:139
clang::analyze_format_string::LengthModifier::AsLongLong
@ AsLongLong
Definition: FormatString.h:72
clang::analyze_format_string::FormatStringHandler::HandleNullChar
virtual void HandleNullChar(const char *nullCharacter)
Definition: FormatString.h:707
clang::analyze_format_string::LengthModifier::AsQuad
@ AsQuad
Definition: FormatString.h:73
clang::ASTContext::getSignedSizeType
CanQualType getSignedSizeType() const
Return the unique signed counterpart of the integer type corresponding to size_t.
Definition: ASTContext.cpp:5939
clang::analyze_format_string::LengthModifier::AsInt32
@ AsInt32
Definition: FormatString.h:77
clang::ASTContext::ShortTy
CanQualType ShortTy
Definition: ASTContext.h:1116
clang::ASTContext::UnsignedLongLongTy
CanQualType UnsignedLongLongTy
Definition: ASTContext.h:1118
clang::analyze_format_string::LengthModifier::AsIntMax
@ AsIntMax
Definition: FormatString.h:74
clang::analyze_format_string::LengthModifier::AsShort
@ AsShort
Definition: FormatString.h:69
clang::analyze_format_string::ArgType::isValid
bool isValid() const
Definition: FormatString.h:297
clang::ASTContext::UnsignedCharTy
CanQualType UnsignedCharTy
Definition: ASTContext.h:1117
clang::TargetInfo::getTriple
const llvm::Triple & getTriple() const
Returns the target triple of the primary target.
Definition: TargetInfo.h:1195
clang::analyze_format_string::ConversionSpecifier::Kind
Kind
Definition: FormatString.h:123
clang::ASTContext::UnsignedLongTy
CanQualType UnsignedLongTy
Definition: ASTContext.h:1117
clang::analyze_format_string::ParseNonPositionAmount
OptionalAmount ParseNonPositionAmount(const char *&Beg, const char *E, unsigned &argIndex)
Definition: FormatString.cpp:62
clang::analyze_format_string::LengthModifier::AsSizeT
@ AsSizeT
Definition: FormatString.h:75
clang::ASTContext::LongLongTy
CanQualType LongLongTy
Definition: ASTContext.h:1116
FormatString.h
clang::analyze_format_string::ArgType::matchesType
MatchKind matchesType(ASTContext &C, QualType argTy) const
Definition: FormatString.cpp:323
clang::ASTContext::UnsignedIntTy
CanQualType UnsignedIntTy
Definition: ASTContext.h:1117
clang::analyze_format_string::ConversionSpecifier::XArg
@ XArg
Definition: FormatString.h:142
clang::Type::isPointerType
bool isPointerType() const
Definition: Type.h:6883
clang::ASTContext::DoubleTy
CanQualType DoubleTy
Definition: ASTContext.h:1119
clang::analyze_format_string::ParseFieldWidth
bool ParseFieldWidth(FormatStringHandler &H, FormatSpecifier &CS, const char *Start, const char *&Beg, const char *E, unsigned *argIndex)
Definition: FormatString.cpp:121
clang::analyze_format_string::SpecifierResult::getStart
const char * getStart() const
Definition: FormatStringParsing.h:83
clang::ASTContext::IntTy
CanQualType IntTy
Definition: ASTContext.h:1116
clang::ASTContext::getUIntMaxType
CanQualType getUIntMaxType() const
Return the unique type for "uintmax_t" (C99 7.18.1.5), defined in <stdint.h>.
Definition: ASTContext.cpp:5949
clang::analyze_format_string::ConversionSpecifier::GArg
@ GArg
Definition: FormatString.h:151
OSLog.h
Begin
SourceLocation Begin
Definition: USRLocFinder.cpp:165
clang::ASTContext::LongTy
CanQualType LongTy
Definition: ASTContext.h:1116
clang::CanQual::withConst
QualType withConst() const
Retrieves a version of this type with const applied.
Definition: CanonicalType.h:161
clang::analyze_format_string::ConversionSpecifier::PrintErrno
@ PrintErrno
Definition: FormatString.h:185
clang::RISCV::Float
@ Float
Definition: RISCVVIntrinsicUtils.h:170
clang::analyze_format_string::FormatStringHandler::HandleObjCFlagsWithNonObjCConversion
virtual void HandleObjCFlagsWithNonObjCConversion(const char *flagsStart, const char *flagsEnd, const char *conversionPosition)
Definition: FormatString.h:725
clang::analyze_os_log::OSLogBufferItem::IsSensitive
@ IsSensitive
Definition: OSLog.h:68
clang::ASTContext::HalfTy
CanQualType HalfTy
Definition: ASTContext.h:1131
clang::Type::isSignedIntegerType
bool isSignedIntegerType() const
Return true if this is an integer type that is signed, according to C99 6.2.5p4 [char,...
Definition: Type.cpp:2019
clang::analyze_format_string::ConversionSpecifier::PercentArg
@ PercentArg
Definition: FormatString.h:160
clang::analyze_format_string::LengthModifier::None
@ None
Definition: FormatString.h:67
clang::analyze_format_string::ConversionSpecifier::aArg
@ aArg
Definition: FormatString.h:152
clang::ASTContext::getTargetInfo
const TargetInfo & getTargetInfo() const
Definition: ASTContext.h:773
clang::analyze_format_string::parseFormatStringHasFormattingSpecifiers
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.
Definition: PrintfFormatString.cpp:470
clang::analyze_format_string
Common components of both fprintf and fscanf format strings.
Definition: FormatString.h:29
clang::analyze_format_string::ParseArgPosition
bool ParseArgPosition(FormatStringHandler &H, FormatSpecifier &CS, const char *Start, const char *&Beg, const char *E)
Definition: FormatString.cpp:143
clang::LangOptions
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:81
clang::analyze_format_string::ConversionSpecifier::FreeBSDrArg
@ FreeBSDrArg
Definition: FormatString.h:181
clang::analyze_format_string::ConversionSpecifier::OArg
@ OArg
Definition: FormatString.h:138
clang::BuiltinType::getKind
Kind getKind() const
Definition: Type.h:2655
clang::UpdateOnReturn
Definition: FormatStringParsing.h:26
clang::analyze_format_string::ConversionSpecifier::PArg
@ PArg
Definition: FormatString.h:167
clang::analyze_format_string::FormatStringHandler::HandleIncompleteSpecifier
virtual void HandleIncompleteSpecifier(const char *startSpecifier, unsigned specifierLen)
Definition: FormatString.h:716
clang::analyze_format_string::OptionalAmount::isInvalid
bool isInvalid() const
Definition: FormatString.h:355
clang::analyze_os_log::OSLogBufferItem::IsPrivate
@ IsPrivate
Definition: OSLog.h:62
clang
Definition: CalledOnceCheck.h:17
clang::analyze_format_string::ArgType
Definition: FormatString.h:253
ParsePrintfSpecifier
static PrintfSpecifierResult ParsePrintfSpecifier(FormatStringHandler &H, const char *&Beg, const char *E, unsigned &argIndex, const LangOptions &LO, const TargetInfo &Target, bool Warn, bool isFreeBSDKPrintf)
Definition: PrintfFormatString.cpp:71
clang::analyze_format_string::ConversionSpecifier::InvalidSpecifier
@ InvalidSpecifier
Definition: FormatString.h:124
clang::VectorType::getElementType
QualType getElementType() const
Definition: Type.h:3399
clang::analyze_format_string::ConversionSpecifier::CArg
@ CArg
Definition: FormatString.h:161
clang::analyze_format_string::LengthModifier::AsAllocate
@ AsAllocate
Definition: FormatString.h:81
clang::analyze_printf
Pieces specific to fprintf format strings.
Definition: FormatString.h:485
PrintfSpecifierResult
clang::analyze_format_string::SpecifierResult< PrintfSpecifier > PrintfSpecifierResult
Definition: PrintfFormatString.cpp:30
clang::ASTContext::SignedCharTy
CanQualType SignedCharTy
Definition: ASTContext.h:1116
clang::analyze_format_string::ArgType::ObjCPointerTy
@ ObjCPointerTy
Definition: FormatString.h:255
clang::analyze_format_string::ConversionSpecifier::ZArg
@ ZArg
Definition: FormatString.h:171
clang::analyze_format_string::ConversionSpecifier::AArg
@ AArg
Definition: FormatString.h:153
clang::analyze_format_string::LengthModifier::AsChar
@ AsChar
Definition: FormatString.h:68
clang::analyze_format_string::ConversionSpecifier::pArg
@ pArg
Definition: FormatString.h:158
clang::analyze_format_string::ArgType::CStrTy
@ CStrTy
Definition: FormatString.h:256
clang::ASTContext::getPointerDiffType
QualType getPointerDiffType() const
Return the unique type for "ptrdiff_t" (C99 7.17) defined in <stddef.h>.
Definition: ASTContext.cpp:5977
clang::analyze_format_string::ConversionSpecifier::UArg
@ UArg
Definition: FormatString.h:140
clang::analyze_format_string::FormatStringHandler::HandleInvalidPrintfConversionSpecifier
virtual bool HandleInvalidPrintfConversionSpecifier(const analyze_printf::PrintfSpecifier &FS, const char *startSpecifier, unsigned specifierLen)
Definition: FormatString.h:730
clang::analyze_format_string::ParseUTF8InvalidSpecifier
bool ParseUTF8InvalidSpecifier(const char *SpecifierBegin, const char *FmtStrEnd, unsigned &Len)
Returns true if the invalid specifier in SpecifierBegin is a UTF-8 string; check that it won't go fur...
Definition: FormatString.cpp:295
clang::analyze_format_string::ParseFormatStringHasSArg
bool ParseFormatStringHasSArg(const char *beg, const char *end, const LangOptions &LO, const TargetInfo &Target)
Definition: PrintfFormatString.cpp:441
c
__device__ __2f16 float c
Definition: __clang_hip_libdevice_declares.h:320
clang::ASTContext::getPointerType
QualType getPointerType(QualType T) const
Return the uniqued reference to the type for a pointer to the specified type.
Definition: ASTContext.cpp:3341
clang::analyze_format_string::ArgType::Invalid
static ArgType Invalid()
Definition: FormatString.h:296
clang::analyze_format_string::ConversionSpecifier::eArg
@ eArg
Definition: FormatString.h:148
clang::VectorType::getNumElements
unsigned getNumElements() const
Definition: Type.h:3400
clang::analyze_format_string::OptionalAmount::NotSpecified
@ NotSpecified
Definition: FormatString.h:337
clang::analyze_format_string::ConversionSpecifier::FreeBSDbArg
@ FreeBSDbArg
Definition: FormatString.h:179
clang::analyze_format_string::LengthModifier::AsShortLong
@ AsShortLong
Definition: FormatString.h:70
clang::Type::isUnsignedIntegerType
bool isUnsignedIntegerType() const
Return true if this is an integer type that is unsigned, according to C99 6.2.5p6 [which returns true...
Definition: Type.cpp:2069
clang::EnumType
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of enums.
Definition: Type.h:4842
clang::analyze_format_string::SpecifierResult::hasValue
bool hasValue() const
Definition: FormatStringParsing.h:85
clang::analyze_format_string::LengthModifier
Represents the length modifier in a format string in scanf/printf.
Definition: FormatString.h:64
clang::analyze_format_string::ConversionSpecifier::EArg
@ EArg
Definition: FormatString.h:149
clang::analyze_format_string::LengthModifier::AsLong
@ AsLong
Definition: FormatString.h:71
clang::analyze_format_string::LengthModifier::AsPtrDiff
@ AsPtrDiff
Definition: FormatString.h:76
clang::analyze_format_string::LengthModifier::AsInt64
@ AsInt64
Definition: FormatString.h:79
clang::analyze_format_string::ArgType::WCStrTy
@ WCStrTy
Definition: FormatString.h:256