clang  13.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  // POSIX specific.
330  case 'C': k = ConversionSpecifier::CArg; break;
331  case 'S': k = ConversionSpecifier::SArg; break;
332  // Apple extension for os_log
333  case 'P':
335  break;
336  // Objective-C.
337  case '@': k = ConversionSpecifier::ObjCObjArg; break;
338  // Glibc specific.
339  case 'm': k = ConversionSpecifier::PrintErrno; break;
340  // FreeBSD kernel specific.
341  case 'b':
342  if (isFreeBSDKPrintf)
343  k = ConversionSpecifier::FreeBSDbArg; // int followed by char *
344  break;
345  case 'r':
346  if (isFreeBSDKPrintf)
348  break;
349  case 'y':
350  if (isFreeBSDKPrintf)
352  break;
353  // Apple-specific.
354  case 'D':
355  if (isFreeBSDKPrintf)
356  k = ConversionSpecifier::FreeBSDDArg; // void * followed by char *
357  else if (Target.getTriple().isOSDarwin())
359  break;
360  case 'O':
361  if (Target.getTriple().isOSDarwin())
363  break;
364  case 'U':
365  if (Target.getTriple().isOSDarwin())
367  break;
368  // MS specific.
369  case 'Z':
370  if (Target.getTriple().isOSMSVCRT())
372  break;
373  }
374 
375  // Check to see if we used the Objective-C modifier flags with
376  // a conversion specifier other than '@'.
379  ObjCModifierFlagsStart) {
380  H.HandleObjCFlagsWithNonObjCConversion(ObjCModifierFlagsStart,
381  ObjCModifierFlagsEnd + 1,
382  conversionPosition);
383  return true;
384  }
385 
386  PrintfConversionSpecifier CS(conversionPosition, k);
387  FS.setConversionSpecifier(CS);
388  if (CS.consumesDataArgument() && !FS.usesPositionalArg())
389  FS.setArgIndex(argIndex++);
390  // FreeBSD kernel specific.
393  argIndex++;
394 
396  unsigned Len = I - Start;
397  if (ParseUTF8InvalidSpecifier(Start, E, Len)) {
398  CS.setEndScanList(Start + Len);
399  FS.setConversionSpecifier(CS);
400  }
401  // Assume the conversion takes one argument.
402  return !H.HandleInvalidPrintfConversionSpecifier(FS, Start, Len);
403  }
404  return PrintfSpecifierResult(Start, FS);
405 }
406 
408  const char *I,
409  const char *E,
410  const LangOptions &LO,
411  const TargetInfo &Target,
412  bool isFreeBSDKPrintf) {
413 
414  unsigned argIndex = 0;
415 
416  // Keep looking for a format specifier until we have exhausted the string.
417  while (I != E) {
418  const PrintfSpecifierResult &FSR = ParsePrintfSpecifier(H, I, E, argIndex,
419  LO, Target, true,
420  isFreeBSDKPrintf);
421  // Did a fail-stop error of any kind occur when parsing the specifier?
422  // If so, don't do any more processing.
423  if (FSR.shouldStop())
424  return true;
425  // Did we exhaust the string or encounter an error that
426  // we can recover from?
427  if (!FSR.hasValue())
428  continue;
429  // We have a format specifier. Pass it to the callback.
430  if (!H.HandlePrintfSpecifier(FSR.getValue(), FSR.getStart(),
431  I - FSR.getStart()))
432  return true;
433  }
434  assert(I == E && "Format string not exhausted");
435  return false;
436 }
437 
439  const char *E,
440  const LangOptions &LO,
441  const TargetInfo &Target) {
442 
443  unsigned argIndex = 0;
444 
445  // Keep looking for a %s format specifier until we have exhausted the string.
447  while (I != E) {
448  const PrintfSpecifierResult &FSR = ParsePrintfSpecifier(H, I, E, argIndex,
449  LO, Target, false,
450  false);
451  // Did a fail-stop error of any kind occur when parsing the specifier?
452  // If so, don't do any more processing.
453  if (FSR.shouldStop())
454  return false;
455  // Did we exhaust the string or encounter an error that
456  // we can recover from?
457  if (!FSR.hasValue())
458  continue;
459  const analyze_printf::PrintfSpecifier &FS = FSR.getValue();
460  // Return true if this a %s format specifier.
461  if (FS.getConversionSpecifier().getKind() == ConversionSpecifier::Kind::sArg)
462  return true;
463  }
464  return false;
465 }
466 
468  const char *Begin, const char *End, const LangOptions &LO,
469  const TargetInfo &Target) {
470  unsigned ArgIndex = 0;
471  // Keep looking for a formatting specifier until we have exhausted the string.
473  while (Begin != End) {
474  const PrintfSpecifierResult &FSR =
475  ParsePrintfSpecifier(H, Begin, End, ArgIndex, LO, Target, false, false);
476  if (FSR.shouldStop())
477  break;
478  if (FSR.hasValue())
479  return true;
480  }
481  return false;
482 }
483 
484 //===----------------------------------------------------------------------===//
485 // Methods on PrintfSpecifier.
486 //===----------------------------------------------------------------------===//
487 
488 ArgType PrintfSpecifier::getScalarArgType(ASTContext &Ctx,
489  bool IsObjCLiteral) const {
490  if (CS.getKind() == ConversionSpecifier::cArg)
491  switch (LM.getKind()) {
493  return Ctx.IntTy;
496  return ArgType(ArgType::WIntTy, "wint_t");
498  if (Ctx.getTargetInfo().getTriple().isOSMSVCRT())
499  return Ctx.IntTy;
500  LLVM_FALLTHROUGH;
501  default:
502  return ArgType::Invalid();
503  }
504 
505  if (CS.isIntArg())
506  switch (LM.getKind()) {
508  // GNU extension.
509  return Ctx.LongLongTy;
512  return Ctx.IntTy;
514  return ArgType(Ctx.IntTy, "__int32");
516  return ArgType::AnyCharTy;
517  case LengthModifier::AsShort: return Ctx.ShortTy;
518  case LengthModifier::AsLong: return Ctx.LongTy;
521  return Ctx.LongLongTy;
523  return ArgType(Ctx.LongLongTy, "__int64");
525  return ArgType(Ctx.getIntMaxType(), "intmax_t");
527  return ArgType::makeSizeT(ArgType(Ctx.getSignedSizeType(), "ssize_t"));
529  return Ctx.getTargetInfo().getTriple().isArch64Bit()
530  ? ArgType(Ctx.LongLongTy, "__int64")
531  : ArgType(Ctx.IntTy, "__int32");
533  return ArgType::makePtrdiffT(
534  ArgType(Ctx.getPointerDiffType(), "ptrdiff_t"));
538  return ArgType::Invalid();
539  }
540 
541  if (CS.isUIntArg())
542  switch (LM.getKind()) {
544  // GNU extension.
545  return Ctx.UnsignedLongLongTy;
548  return Ctx.UnsignedIntTy;
550  return ArgType(Ctx.UnsignedIntTy, "unsigned __int32");
551  case LengthModifier::AsChar: return Ctx.UnsignedCharTy;
552  case LengthModifier::AsShort: return Ctx.UnsignedShortTy;
553  case LengthModifier::AsLong: return Ctx.UnsignedLongTy;
556  return Ctx.UnsignedLongLongTy;
558  return ArgType(Ctx.UnsignedLongLongTy, "unsigned __int64");
560  return ArgType(Ctx.getUIntMaxType(), "uintmax_t");
562  return ArgType::makeSizeT(ArgType(Ctx.getSizeType(), "size_t"));
564  return Ctx.getTargetInfo().getTriple().isArch64Bit()
565  ? ArgType(Ctx.UnsignedLongLongTy, "unsigned __int64")
566  : ArgType(Ctx.UnsignedIntTy, "unsigned __int32");
568  return ArgType::makePtrdiffT(
569  ArgType(Ctx.getUnsignedPointerDiffType(), "unsigned ptrdiff_t"));
573  return ArgType::Invalid();
574  }
575 
576  if (CS.isDoubleArg()) {
577  if (!VectorNumElts.isInvalid()) {
578  switch (LM.getKind()) {
580  return Ctx.HalfTy;
582  return Ctx.FloatTy;
584  default:
585  return Ctx.DoubleTy;
586  }
587  }
588 
589  if (LM.getKind() == LengthModifier::AsLongDouble)
590  return Ctx.LongDoubleTy;
591  return Ctx.DoubleTy;
592  }
593 
594  if (CS.getKind() == ConversionSpecifier::nArg) {
595  switch (LM.getKind()) {
597  return ArgType::PtrTo(Ctx.IntTy);
599  return ArgType::PtrTo(Ctx.SignedCharTy);
601  return ArgType::PtrTo(Ctx.ShortTy);
603  return ArgType::PtrTo(Ctx.LongTy);
606  return ArgType::PtrTo(Ctx.LongLongTy);
608  return ArgType::PtrTo(ArgType(Ctx.getIntMaxType(), "intmax_t"));
610  return ArgType::PtrTo(ArgType(Ctx.getSignedSizeType(), "ssize_t"));
612  return ArgType::PtrTo(ArgType(Ctx.getPointerDiffType(), "ptrdiff_t"));
614  return ArgType(); // FIXME: Is this a known extension?
621  return ArgType::Invalid();
623  llvm_unreachable("only used for OpenCL which doesn not handle nArg");
624  }
625  }
626 
627  switch (CS.getKind()) {
629  if (LM.getKind() == LengthModifier::AsWideChar) {
630  if (IsObjCLiteral)
632  "const unichar *");
633  return ArgType(ArgType::WCStrTy, "wchar_t *");
634  }
635  if (LM.getKind() == LengthModifier::AsWide)
636  return ArgType(ArgType::WCStrTy, "wchar_t *");
637  return ArgType::CStrTy;
639  if (IsObjCLiteral)
641  "const unichar *");
642  if (Ctx.getTargetInfo().getTriple().isOSMSVCRT() &&
643  LM.getKind() == LengthModifier::AsShort)
644  return ArgType::CStrTy;
645  return ArgType(ArgType::WCStrTy, "wchar_t *");
647  if (IsObjCLiteral)
648  return ArgType(Ctx.UnsignedShortTy, "unichar");
649  if (Ctx.getTargetInfo().getTriple().isOSMSVCRT() &&
650  LM.getKind() == LengthModifier::AsShort)
651  return Ctx.IntTy;
652  return ArgType(Ctx.WideCharTy, "wchar_t");
655  return ArgType::CPointerTy;
657  return ArgType::ObjCPointerTy;
658  default:
659  break;
660  }
661 
662  // FIXME: Handle other cases.
663  return ArgType();
664 }
665 
666 
667 ArgType PrintfSpecifier::getArgType(ASTContext &Ctx,
668  bool IsObjCLiteral) const {
669  const PrintfConversionSpecifier &CS = getConversionSpecifier();
670 
671  if (!CS.consumesDataArgument())
672  return ArgType::Invalid();
673 
674  ArgType ScalarTy = getScalarArgType(Ctx, IsObjCLiteral);
675  if (!ScalarTy.isValid() || VectorNumElts.isInvalid())
676  return ScalarTy;
677 
678  return ScalarTy.makeVectorType(Ctx, VectorNumElts.getConstantAmount());
679 }
680 
681 bool PrintfSpecifier::fixType(QualType QT, const LangOptions &LangOpt,
682  ASTContext &Ctx, bool IsObjCLiteral) {
683  // %n is different from other conversion specifiers; don't try to fix it.
684  if (CS.getKind() == ConversionSpecifier::nArg)
685  return false;
686 
687  // Handle Objective-C objects first. Note that while the '%@' specifier will
688  // not warn for structure pointer or void pointer arguments (because that's
689  // how CoreFoundation objects are implemented), we only show a fixit for '%@'
690  // if we know it's an object (block, id, class, or __attribute__((NSObject))).
691  if (QT->isObjCRetainableType()) {
692  if (!IsObjCLiteral)
693  return false;
694 
696 
697  // Disable irrelevant flags
698  HasThousandsGrouping = false;
699  HasPlusPrefix = false;
700  HasSpacePrefix = false;
701  HasAlternativeForm = false;
702  HasLeadingZeroes = false;
703  Precision.setHowSpecified(OptionalAmount::NotSpecified);
704  LM.setKind(LengthModifier::None);
705 
706  return true;
707  }
708 
709  // Handle strings next (char *, wchar_t *)
710  if (QT->isPointerType() && (QT->getPointeeType()->isAnyCharacterType())) {
711  CS.setKind(ConversionSpecifier::sArg);
712 
713  // Disable irrelevant flags
714  HasAlternativeForm = 0;
715  HasLeadingZeroes = 0;
716 
717  // Set the long length modifier for wide characters
718  if (QT->getPointeeType()->isWideCharType())
719  LM.setKind(LengthModifier::AsWideChar);
720  else
721  LM.setKind(LengthModifier::None);
722 
723  return true;
724  }
725 
726  // If it's an enum, get its underlying type.
727  if (const EnumType *ETy = QT->getAs<EnumType>())
728  QT = ETy->getDecl()->getIntegerType();
729 
730  const BuiltinType *BT = QT->getAs<BuiltinType>();
731  if (!BT) {
732  const VectorType *VT = QT->getAs<VectorType>();
733  if (VT) {
734  QT = VT->getElementType();
735  BT = QT->getAs<BuiltinType>();
736  VectorNumElts = OptionalAmount(VT->getNumElements());
737  }
738  }
739 
740  // We can only work with builtin types.
741  if (!BT)
742  return false;
743 
744  // Set length modifier
745  switch (BT->getKind()) {
746  case BuiltinType::Bool:
747  case BuiltinType::WChar_U:
748  case BuiltinType::WChar_S:
749  case BuiltinType::Char8: // FIXME: Treat like 'char'?
750  case BuiltinType::Char16:
751  case BuiltinType::Char32:
752  case BuiltinType::UInt128:
753  case BuiltinType::Int128:
754  case BuiltinType::Half:
755  case BuiltinType::BFloat16:
756  case BuiltinType::Float16:
757  case BuiltinType::Float128:
758  case BuiltinType::ShortAccum:
759  case BuiltinType::Accum:
760  case BuiltinType::LongAccum:
761  case BuiltinType::UShortAccum:
762  case BuiltinType::UAccum:
763  case BuiltinType::ULongAccum:
764  case BuiltinType::ShortFract:
765  case BuiltinType::Fract:
766  case BuiltinType::LongFract:
767  case BuiltinType::UShortFract:
768  case BuiltinType::UFract:
769  case BuiltinType::ULongFract:
770  case BuiltinType::SatShortAccum:
771  case BuiltinType::SatAccum:
772  case BuiltinType::SatLongAccum:
773  case BuiltinType::SatUShortAccum:
774  case BuiltinType::SatUAccum:
775  case BuiltinType::SatULongAccum:
776  case BuiltinType::SatShortFract:
777  case BuiltinType::SatFract:
778  case BuiltinType::SatLongFract:
779  case BuiltinType::SatUShortFract:
780  case BuiltinType::SatUFract:
781  case BuiltinType::SatULongFract:
782  // Various types which are non-trivial to correct.
783  return false;
784 
785 #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
786  case BuiltinType::Id:
787 #include "clang/Basic/OpenCLImageTypes.def"
788 #define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
789  case BuiltinType::Id:
790 #include "clang/Basic/OpenCLExtensionTypes.def"
791 #define SVE_TYPE(Name, Id, SingletonId) \
792  case BuiltinType::Id:
793 #include "clang/Basic/AArch64SVEACLETypes.def"
794 #define PPC_VECTOR_TYPE(Name, Id, Size) \
795  case BuiltinType::Id:
796 #include "clang/Basic/PPCTypes.def"
797 #define RVV_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
798 #include "clang/Basic/RISCVVTypes.def"
799 #define SIGNED_TYPE(Id, SingletonId)
800 #define UNSIGNED_TYPE(Id, SingletonId)
801 #define FLOATING_TYPE(Id, SingletonId)
802 #define BUILTIN_TYPE(Id, SingletonId) \
803  case BuiltinType::Id:
804 #include "clang/AST/BuiltinTypes.def"
805  // Misc other stuff which doesn't make sense here.
806  return false;
807 
808  case BuiltinType::UInt:
809  case BuiltinType::Int:
810  case BuiltinType::Float:
811  LM.setKind(VectorNumElts.isInvalid() ?
813  break;
814  case BuiltinType::Double:
815  LM.setKind(VectorNumElts.isInvalid() ?
817  break;
818  case BuiltinType::Char_U:
819  case BuiltinType::UChar:
820  case BuiltinType::Char_S:
821  case BuiltinType::SChar:
822  LM.setKind(LengthModifier::AsChar);
823  break;
824 
825  case BuiltinType::Short:
826  case BuiltinType::UShort:
827  LM.setKind(LengthModifier::AsShort);
828  break;
829 
830  case BuiltinType::Long:
831  case BuiltinType::ULong:
832  LM.setKind(LengthModifier::AsLong);
833  break;
834 
835  case BuiltinType::LongLong:
836  case BuiltinType::ULongLong:
837  LM.setKind(LengthModifier::AsLongLong);
838  break;
839 
840  case BuiltinType::LongDouble:
841  LM.setKind(LengthModifier::AsLongDouble);
842  break;
843  }
844 
845  // Handle size_t, ptrdiff_t, etc. that have dedicated length modifiers in C99.
846  if (isa<TypedefType>(QT) && (LangOpt.C99 || LangOpt.CPlusPlus11))
847  namedTypeToLengthModifier(QT, LM);
848 
849  // If fixing the length modifier was enough, we might be done.
850  if (hasValidLengthModifier(Ctx.getTargetInfo(), LangOpt)) {
851  // If we're going to offer a fix anyway, make sure the sign matches.
852  switch (CS.getKind()) {
855  if (QT->isSignedIntegerType())
857  break;
861  if (QT->isUnsignedIntegerType() && !HasPlusPrefix)
863  break;
864  default:
865  // Other specifiers do not have signed/unsigned variants.
866  break;
867  }
868 
869  const analyze_printf::ArgType &ATR = getArgType(Ctx, IsObjCLiteral);
870  if (ATR.isValid() && ATR.matchesType(Ctx, QT))
871  return true;
872  }
873 
874  // Set conversion specifier and disable any flags which do not apply to it.
875  // Let typedefs to char fall through to int, as %c is silly for uint8_t.
876  if (!isa<TypedefType>(QT) && QT->isCharType()) {
877  CS.setKind(ConversionSpecifier::cArg);
878  LM.setKind(LengthModifier::None);
879  Precision.setHowSpecified(OptionalAmount::NotSpecified);
880  HasAlternativeForm = 0;
881  HasLeadingZeroes = 0;
882  HasPlusPrefix = 0;
883  }
884  // Test for Floating type first as LongDouble can pass isUnsignedIntegerType
885  else if (QT->isRealFloatingType()) {
886  CS.setKind(ConversionSpecifier::fArg);
887  }
888  else if (QT->isSignedIntegerType()) {
889  CS.setKind(ConversionSpecifier::dArg);
890  HasAlternativeForm = 0;
891  }
892  else if (QT->isUnsignedIntegerType()) {
893  CS.setKind(ConversionSpecifier::uArg);
894  HasAlternativeForm = 0;
895  HasPlusPrefix = 0;
896  } else {
897  llvm_unreachable("Unexpected type");
898  }
899 
900  return true;
901 }
902 
903 void PrintfSpecifier::toString(raw_ostream &os) const {
904  // Whilst some features have no defined order, we are using the order
905  // appearing in the C99 standard (ISO/IEC 9899:1999 (E) 7.19.6.1)
906  os << "%";
907 
908  // Positional args
909  if (usesPositionalArg()) {
910  os << getPositionalArgIndex() << "$";
911  }
912 
913  // Conversion flags
914  if (IsLeftJustified) os << "-";
915  if (HasPlusPrefix) os << "+";
916  if (HasSpacePrefix) os << " ";
917  if (HasAlternativeForm) os << "#";
918  if (HasLeadingZeroes) os << "0";
919 
920  // Minimum field width
921  FieldWidth.toString(os);
922  // Precision
923  Precision.toString(os);
924 
925  // Vector modifier
926  if (!VectorNumElts.isInvalid())
927  os << 'v' << VectorNumElts.getConstantAmount();
928 
929  // Length modifier
930  os << LM.toString();
931  // Conversion specifier
932  os << CS.toString();
933 }
934 
935 bool PrintfSpecifier::hasValidPlusPrefix() const {
936  if (!HasPlusPrefix)
937  return true;
938 
939  // The plus prefix only makes sense for signed conversions
940  switch (CS.getKind()) {
954  return true;
955 
956  default:
957  return false;
958  }
959 }
960 
961 bool PrintfSpecifier::hasValidAlternativeForm() const {
962  if (!HasAlternativeForm)
963  return true;
964 
965  // Alternate form flag only valid with the oxXaAeEfFgG conversions
966  switch (CS.getKind()) {
981  return true;
982 
983  default:
984  return false;
985  }
986 }
987 
988 bool PrintfSpecifier::hasValidLeadingZeros() const {
989  if (!HasLeadingZeroes)
990  return true;
991 
992  // Leading zeroes flag only valid with the diouxXaAeEfFgG conversions
993  switch (CS.getKind()) {
1013  return true;
1014 
1015  default:
1016  return false;
1017  }
1018 }
1019 
1020 bool PrintfSpecifier::hasValidSpacePrefix() const {
1021  if (!HasSpacePrefix)
1022  return true;
1023 
1024  // The space prefix only makes sense for signed conversions
1025  switch (CS.getKind()) {
1039  return true;
1040 
1041  default:
1042  return false;
1043  }
1044 }
1045 
1046 bool PrintfSpecifier::hasValidLeftJustified() const {
1047  if (!IsLeftJustified)
1048  return true;
1049 
1050  // The left justified flag is valid for all conversions except n
1051  switch (CS.getKind()) {
1053  return false;
1054 
1055  default:
1056  return true;
1057  }
1058 }
1059 
1060 bool PrintfSpecifier::hasValidThousandsGroupingPrefix() const {
1061  if (!HasThousandsGrouping)
1062  return true;
1063 
1064  switch (CS.getKind()) {
1074  return true;
1075  default:
1076  return false;
1077  }
1078 }
1079 
1080 bool PrintfSpecifier::hasValidPrecision() const {
1081  if (Precision.getHowSpecified() == OptionalAmount::NotSpecified)
1082  return true;
1083 
1084  // Precision is only valid with the diouxXaAeEfFgGsP conversions
1085  switch (CS.getKind()) {
1107  return true;
1108 
1109  default:
1110  return false;
1111  }
1112 }
1113 bool PrintfSpecifier::hasValidFieldWidth() const {
1114  if (FieldWidth.getHowSpecified() == OptionalAmount::NotSpecified)
1115  return true;
1116 
1117  // The field width is valid for all conversions except n
1118  switch (CS.getKind()) {
1120  return false;
1121 
1122  default:
1123  return true;
1124  }
1125 }
clang::BuiltinType
This class is used for builtin types like 'int'.
Definition: Type.h:2480
clang::ASTContext::LongDoubleTy
CanQualType LongDoubleTy
Definition: ASTContext.h:1007
clang::analyze_format_string::ConversionSpecifier::SArg
@ SArg
Definition: FormatString.h:158
clang::analyze_format_string::ConversionSpecifier::oArg
@ oArg
Definition: FormatString.h:133
clang::analyze_format_string::FormatStringHandler::HandleInvalidObjCModifierFlag
virtual void HandleInvalidObjCModifierFlag(const char *startFlag, unsigned flagLen)
Definition: FormatString.h:712
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:302
clang::analyze_os_log::OSLogBufferItem::IsPrivate
@ IsPrivate
Definition: OSLog.h:62
clang::analyze_format_string::ConversionSpecifier::cArg
@ cArg
Definition: FormatString.h:126
clang::analyze_format_string::LengthModifier::AsWideChar
@ AsWideChar
Definition: FormatString.h:84
clang::analyze_os_log::OSLogBufferItem::IsPublic
@ IsPublic
Definition: OSLog.h:65
clang::analyze_format_string::ConversionSpecifier::ObjCObjArg
@ ObjCObjArg
Definition: FormatString.h:170
clang::ASTContext::UnsignedShortTy
CanQualType UnsignedShortTy
Definition: ASTContext.h:1005
clang::analyze_format_string::SpecifierResult
Definition: FormatStringParsing.h:72
clang::Type::isObjCRetainableType
bool isObjCRetainableType() const
Definition: Type.cpp:4271
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:500
clang::analyze_format_string::ConversionSpecifier::setEndScanList
void setEndScanList(const char *pos)
Definition: FormatString.h:226
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:709
clang::analyze_format_string::ConversionSpecifier::xArg
@ xArg
Definition: FormatString.h:137
clang::Type::isCharType
bool isCharType() const
Definition: Type.cpp:1946
llvm::SmallVector
Definition: LLVM.h:38
clang::analyze_format_string::FormatStringHandler
Definition: FormatString.h:692
TargetInfo.h
clang::MultiVersionKind::Target
@ Target
clang::Type::isWideCharType
bool isWideCharType() const
Definition: Type.cpp:1955
clang::QualType
A (possibly-)qualified type.
Definition: Type.h:661
clang::analyze_format_string::FormatStringHandler::HandlePrintfSpecifier
virtual bool HandlePrintfSpecifier(const analyze_printf::PrintfSpecifier &FS, const char *startSpecifier, unsigned specifierLen)
Definition: FormatString.h:727
clang::analyze_format_string::ConversionSpecifier::sArg
@ sArg
Definition: FormatString.h:153
clang::TargetInfo
Exposes information about the current target.
Definition: TargetInfo.h:188
clang::Type::isRealFloatingType
bool isRealFloatingType() const
Floating point categories.
Definition: Type.cpp:2110
clang::analyze_format_string::LengthModifier::AsInt3264
@ AsInt3264
Definition: FormatString.h:78
clang::analyze_format_string::ArgType::WIntTy
@ WIntTy
Definition: FormatString.h:252
clang::analyze_format_string::ArgType::makeVectorType
ArgType makeVectorType(ASTContext &C, unsigned NumElts) const
Definition: FormatString.cpp:495
clang::ASTContext::getUnsignedPointerDiffType
QualType getUnsignedPointerDiffType() const
Return the unique unsigned counterpart of "ptrdiff_t" integer type.
Definition: ASTContext.cpp:5670
clang::analyze_format_string::ParsePositionAmount
OptionalAmount ParsePositionAmount(FormatStringHandler &H, const char *Start, const char *&Beg, const char *E, PositionContext p)
Definition: FormatString.cpp:75
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:690
clang::analyze_format_string::ConversionSpecifier::FArg
@ FArg
Definition: FormatString.h:143
clang::analyze_printf::PrintfConversionSpecifier
Definition: FormatString.h:477
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:142
clang::analyze_format_string::ConversionSpecifier::FreeBSDDArg
@ FreeBSDDArg
Definition: FormatString.h:176
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:407
clang::analyze_format_string::OptionalAmount
Definition: FormatString.h:325
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:5630
clang::analyze_format_string::ConversionSpecifier::nArg
@ nArg
Definition: FormatString.h:155
clang::ASTContext::WideCharTy
CanQualType WideCharTy
Definition: ASTContext.h:999
clang::analyze_format_string::ConversionSpecifier::gArg
@ gArg
Definition: FormatString.h:146
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:734
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:310
clang::Type::isAnyCharacterType
bool isAnyCharacterType() const
Determine whether this type is any of the built-in character types.
Definition: Type.cpp:1982
clang::threadSafety::sx::toString
std::string toString(const til::SExpr *E)
Definition: ThreadSafetyCommon.h:89
clang::VectorType
Represents a GCC generic vector type.
Definition: Type.h:3216
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:187
clang::ASTContext::getSizeType
CanQualType getSizeType() const
Return the unique type for "size_t" (C99 7.17), defined in <stddef.h>.
Definition: ASTContext.cpp:5619
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:294
clang::analyze_format_string::ConversionSpecifier::consumesDataArgument
bool consumesDataArgument() const
Definition: FormatString.h:207
clang::Type::getAs
const T * getAs() const
Member-template getAs<specific type>'.
Definition: Type.h:7153
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:211
clang::analyze_format_string::ConversionSpecifier::FreeBSDyArg
@ FreeBSDyArg
Definition: FormatString.h:178
FormatStringParsing.h
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:252
clang::analyze_format_string::ParseVectorModifier
bool ParseVectorModifier(FormatStringHandler &H, FormatSpecifier &FS, const char *&Beg, const char *E, const LangOptions &LO)
Definition: FormatString.cpp:181
clang::analyze_format_string::ArgType::CPointerTy
@ CPointerTy
Definition: FormatString.h:251
clang::analyze_format_string::LengthModifier::AsWide
@ AsWide
Definition: FormatString.h:83
clang::ASTContext::FloatTy
CanQualType FloatTy
Definition: ASTContext.h:1007
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:135
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:697
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:5625
clang::analyze_format_string::LengthModifier::AsInt32
@ AsInt32
Definition: FormatString.h:77
clang::ASTContext::ShortTy
CanQualType ShortTy
Definition: ASTContext.h:1004
clang::ASTContext::UnsignedLongLongTy
CanQualType UnsignedLongLongTy
Definition: ASTContext.h:1006
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:287
clang::ASTContext::UnsignedCharTy
CanQualType UnsignedCharTy
Definition: ASTContext.h:1005
clang::TargetInfo::getTriple
const llvm::Triple & getTriple() const
Returns the target triple of the primary target.
Definition: TargetInfo.h:1092
clang::analyze_format_string::ConversionSpecifier::Kind
Kind
Definition: FormatString.h:123
clang::ASTContext::UnsignedLongTy
CanQualType UnsignedLongTy
Definition: ASTContext.h:1005
clang::analyze_format_string::ParseNonPositionAmount
OptionalAmount ParseNonPositionAmount(const char *&Beg, const char *E, unsigned &argIndex)
Definition: FormatString.cpp:63
clang::analyze_format_string::LengthModifier::AsSizeT
@ AsSizeT
Definition: FormatString.h:75
clang::ASTContext::LongLongTy
CanQualType LongLongTy
Definition: ASTContext.h:1004
FormatString.h
clang::analyze_format_string::ArgType::matchesType
MatchKind matchesType(ASTContext &C, QualType argTy) const
Definition: FormatString.cpp:324
clang::ASTContext::UnsignedIntTy
CanQualType UnsignedIntTy
Definition: ASTContext.h:1005
clang::analyze_format_string::ConversionSpecifier::XArg
@ XArg
Definition: FormatString.h:138
clang::Type::isPointerType
bool isPointerType() const
Definition: Type.h:6668
clang::ASTContext::DoubleTy
CanQualType DoubleTy
Definition: ASTContext.h:1007
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:122
clang::analyze_format_string::SpecifierResult::getStart
const char * getStart() const
Definition: FormatStringParsing.h:83
clang::ASTContext::IntTy
CanQualType IntTy
Definition: ASTContext.h:1004
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:5635
clang::analyze_format_string::ConversionSpecifier::GArg
@ GArg
Definition: FormatString.h:147
OSLog.h
Begin
SourceLocation Begin
Definition: USRLocFinder.cpp:165
clang::ASTContext::LongTy
CanQualType LongTy
Definition: ASTContext.h:1004
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:181
clang::analyze_format_string::FormatStringHandler::HandleObjCFlagsWithNonObjCConversion
virtual void HandleObjCFlagsWithNonObjCConversion(const char *flagsStart, const char *flagsEnd, const char *conversionPosition)
Definition: FormatString.h:715
clang::ASTContext::HalfTy
CanQualType HalfTy
Definition: ASTContext.h:1019
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:2003
clang::analyze_format_string::ConversionSpecifier::PercentArg
@ PercentArg
Definition: FormatString.h:156
clang::analyze_format_string::LengthModifier::None
@ None
Definition: FormatString.h:67
clang::analyze_format_string::ConversionSpecifier::aArg
@ aArg
Definition: FormatString.h:148
clang::ASTContext::getTargetInfo
const TargetInfo & getTargetInfo() const
Definition: ASTContext.h:692
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:467
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:144
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:58
clang::analyze_format_string::ConversionSpecifier::FreeBSDrArg
@ FreeBSDrArg
Definition: FormatString.h:177
clang::analyze_format_string::ConversionSpecifier::OArg
@ OArg
Definition: FormatString.h:134
clang::BuiltinType::getKind
Kind getKind() const
Definition: Type.h:2515
clang::UpdateOnReturn
Definition: FormatStringParsing.h:26
clang::analyze_format_string::ConversionSpecifier::PArg
@ PArg
Definition: FormatString.h:163
clang::analyze_format_string::FormatStringHandler::HandleIncompleteSpecifier
virtual void HandleIncompleteSpecifier(const char *startSpecifier, unsigned specifierLen)
Definition: FormatString.h:706
clang::analyze_os_log::OSLogBufferItem::IsSensitive
@ IsSensitive
Definition: OSLog.h:68
clang::analyze_format_string::OptionalAmount::isInvalid
bool isInvalid() const
Definition: FormatString.h:345
clang
Dataflow Directional Tag Classes.
Definition: CalledOnceCheck.h:17
clang::analyze_format_string::ArgType
Definition: FormatString.h:249
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:3257
clang::analyze_format_string::ConversionSpecifier::CArg
@ CArg
Definition: FormatString.h:157
clang::analyze_format_string::LengthModifier::AsAllocate
@ AsAllocate
Definition: FormatString.h:81
clang::analyze_printf
Pieces specific to fprintf format strings.
Definition: FormatString.h:475
PrintfSpecifierResult
clang::analyze_format_string::SpecifierResult< PrintfSpecifier > PrintfSpecifierResult
Definition: PrintfFormatString.cpp:30
clang::ASTContext::SignedCharTy
CanQualType SignedCharTy
Definition: ASTContext.h:1004
clang::analyze_format_string::ArgType::ObjCPointerTy
@ ObjCPointerTy
Definition: FormatString.h:251
clang::analyze_format_string::ConversionSpecifier::ZArg
@ ZArg
Definition: FormatString.h:167
clang::analyze_format_string::ConversionSpecifier::AArg
@ AArg
Definition: FormatString.h:149
clang::analyze_format_string::LengthModifier::AsChar
@ AsChar
Definition: FormatString.h:68
clang::analyze_format_string::ConversionSpecifier::pArg
@ pArg
Definition: FormatString.h:154
clang::analyze_format_string::ArgType::CStrTy
@ CStrTy
Definition: FormatString.h:252
clang::ASTContext::getPointerDiffType
QualType getPointerDiffType() const
Return the unique type for "ptrdiff_t" (C99 7.17) defined in <stddef.h>.
Definition: ASTContext.cpp:5663
clang::analyze_format_string::ConversionSpecifier::UArg
@ UArg
Definition: FormatString.h:136
clang::analyze_format_string::FormatStringHandler::HandleInvalidPrintfConversionSpecifier
virtual bool HandleInvalidPrintfConversionSpecifier(const analyze_printf::PrintfSpecifier &FS, const char *startSpecifier, unsigned specifierLen)
Definition: FormatString.h:720
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:296
clang::analyze_format_string::ParseFormatStringHasSArg
bool ParseFormatStringHasSArg(const char *beg, const char *end, const LangOptions &LO, const TargetInfo &Target)
Definition: PrintfFormatString.cpp:438
c
__device__ __2f16 float c
Definition: __clang_hip_libdevice_declares.h:303
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:3179
clang::analyze_format_string::ArgType::Invalid
static ArgType Invalid()
Definition: FormatString.h:286
clang::analyze_format_string::ConversionSpecifier::eArg
@ eArg
Definition: FormatString.h:144
clang::VectorType::getNumElements
unsigned getNumElements() const
Definition: Type.h:3258
clang::analyze_format_string::OptionalAmount::NotSpecified
@ NotSpecified
Definition: FormatString.h:327
clang::analyze_format_string::ConversionSpecifier::FreeBSDbArg
@ FreeBSDbArg
Definition: FormatString.h:175
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:2050
clang::EnumType
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of enums.
Definition: Type.h:4634
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:145
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:252