clang  10.0.0svn
FormatString.cpp
Go to the documentation of this file.
1 // FormatString.cpp - Common stuff for handling printf/scanf formats -*- 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 // Shared details for processing format strings of printf and scanf
10 // (and friends).
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "FormatStringParsing.h"
16 #include "clang/Basic/TargetInfo.h"
17 #include "llvm/Support/ConvertUTF.h"
18 
26 using namespace clang;
27 
28 // Key function to FormatStringHandler.
29 FormatStringHandler::~FormatStringHandler() {}
30 
31 //===----------------------------------------------------------------------===//
32 // Functions for parsing format strings components in both printf and
33 // scanf format strings.
34 //===----------------------------------------------------------------------===//
35 
37 clang::analyze_format_string::ParseAmount(const char *&Beg, const char *E) {
38  const char *I = Beg;
39  UpdateOnReturn <const char*> UpdateBeg(Beg, I);
40 
41  unsigned accumulator = 0;
42  bool hasDigits = false;
43 
44  for ( ; I != E; ++I) {
45  char c = *I;
46  if (c >= '0' && c <= '9') {
47  hasDigits = true;
48  accumulator = (accumulator * 10) + (c - '0');
49  continue;
50  }
51 
52  if (hasDigits)
53  return OptionalAmount(OptionalAmount::Constant, accumulator, Beg, I - Beg,
54  false);
55 
56  break;
57  }
58 
59  return OptionalAmount();
60 }
61 
64  const char *E,
65  unsigned &argIndex) {
66  if (*Beg == '*') {
67  ++Beg;
68  return OptionalAmount(OptionalAmount::Arg, argIndex++, Beg, 0, false);
69  }
70 
71  return ParseAmount(Beg, E);
72 }
73 
76  const char *Start,
77  const char *&Beg,
78  const char *E,
79  PositionContext p) {
80  if (*Beg == '*') {
81  const char *I = Beg + 1;
82  const OptionalAmount &Amt = ParseAmount(I, E);
83 
84  if (Amt.getHowSpecified() == OptionalAmount::NotSpecified) {
85  H.HandleInvalidPosition(Beg, I - Beg, p);
86  return OptionalAmount(false);
87  }
88 
89  if (I == E) {
90  // No more characters left?
91  H.HandleIncompleteSpecifier(Start, E - Start);
92  return OptionalAmount(false);
93  }
94 
95  assert(Amt.getHowSpecified() == OptionalAmount::Constant);
96 
97  if (*I == '$') {
98  // Handle positional arguments
99 
100  // Special case: '*0$', since this is an easy mistake.
101  if (Amt.getConstantAmount() == 0) {
102  H.HandleZeroPosition(Beg, I - Beg + 1);
103  return OptionalAmount(false);
104  }
105 
106  const char *Tmp = Beg;
107  Beg = ++I;
108 
109  return OptionalAmount(OptionalAmount::Arg, Amt.getConstantAmount() - 1,
110  Tmp, 0, true);
111  }
112 
113  H.HandleInvalidPosition(Beg, I - Beg, p);
114  return OptionalAmount(false);
115  }
116 
117  return ParseAmount(Beg, E);
118 }
119 
120 
121 bool
123  FormatSpecifier &CS,
124  const char *Start,
125  const char *&Beg, const char *E,
126  unsigned *argIndex) {
127  // FIXME: Support negative field widths.
128  if (argIndex) {
129  CS.setFieldWidth(ParseNonPositionAmount(Beg, E, *argIndex));
130  }
131  else {
132  const OptionalAmount Amt =
133  ParsePositionAmount(H, Start, Beg, E,
135 
136  if (Amt.isInvalid())
137  return true;
138  CS.setFieldWidth(Amt);
139  }
140  return false;
141 }
142 
143 bool
145  FormatSpecifier &FS,
146  const char *Start,
147  const char *&Beg,
148  const char *E) {
149  const char *I = Beg;
150 
151  const OptionalAmount &Amt = ParseAmount(I, E);
152 
153  if (I == E) {
154  // No more characters left?
155  H.HandleIncompleteSpecifier(Start, E - Start);
156  return true;
157  }
158 
159  if (Amt.getHowSpecified() == OptionalAmount::Constant && *(I++) == '$') {
160  // Warn that positional arguments are non-standard.
161  H.HandlePosition(Start, I - Start);
162 
163  // Special case: '%0$', since this is an easy mistake.
164  if (Amt.getConstantAmount() == 0) {
165  H.HandleZeroPosition(Start, I - Start);
166  return true;
167  }
168 
169  FS.setArgIndex(Amt.getConstantAmount() - 1);
171  // Update the caller's pointer if we decided to consume
172  // these characters.
173  Beg = I;
174  return false;
175  }
176 
177  return false;
178 }
179 
180 bool
182  FormatSpecifier &FS,
183  const char *&I,
184  const char *E,
185  const LangOptions &LO) {
186  if (!LO.OpenCL)
187  return false;
188 
189  const char *Start = I;
190  if (*I == 'v') {
191  ++I;
192 
193  if (I == E) {
194  H.HandleIncompleteSpecifier(Start, E - Start);
195  return true;
196  }
197 
198  OptionalAmount NumElts = ParseAmount(I, E);
199  if (NumElts.getHowSpecified() != OptionalAmount::Constant) {
200  H.HandleIncompleteSpecifier(Start, E - Start);
201  return true;
202  }
203 
204  FS.setVectorNumElts(NumElts);
205  }
206 
207  return false;
208 }
209 
210 bool
212  const char *&I,
213  const char *E,
214  const LangOptions &LO,
215  bool IsScanf) {
217  const char *lmPosition = I;
218  switch (*I) {
219  default:
220  return false;
221  case 'h':
222  ++I;
223  if (I != E && *I == 'h') {
224  ++I;
225  lmKind = LengthModifier::AsChar;
226  } else if (I != E && *I == 'l' && LO.OpenCL) {
227  ++I;
228  lmKind = LengthModifier::AsShortLong;
229  } else {
230  lmKind = LengthModifier::AsShort;
231  }
232  break;
233  case 'l':
234  ++I;
235  if (I != E && *I == 'l') {
236  ++I;
237  lmKind = LengthModifier::AsLongLong;
238  } else {
239  lmKind = LengthModifier::AsLong;
240  }
241  break;
242  case 'j': lmKind = LengthModifier::AsIntMax; ++I; break;
243  case 'z': lmKind = LengthModifier::AsSizeT; ++I; break;
244  case 't': lmKind = LengthModifier::AsPtrDiff; ++I; break;
245  case 'L': lmKind = LengthModifier::AsLongDouble; ++I; break;
246  case 'q': lmKind = LengthModifier::AsQuad; ++I; break;
247  case 'a':
248  if (IsScanf && !LO.C99 && !LO.CPlusPlus11) {
249  // For scanf in C90, look at the next character to see if this should
250  // be parsed as the GNU extension 'a' length modifier. If not, this
251  // will be parsed as a conversion specifier.
252  ++I;
253  if (I != E && (*I == 's' || *I == 'S' || *I == '[')) {
254  lmKind = LengthModifier::AsAllocate;
255  break;
256  }
257  --I;
258  }
259  return false;
260  case 'm':
261  if (IsScanf) {
262  lmKind = LengthModifier::AsMAllocate;
263  ++I;
264  break;
265  }
266  return false;
267  // printf: AsInt64, AsInt32, AsInt3264
268  // scanf: AsInt64
269  case 'I':
270  if (I + 1 != E && I + 2 != E) {
271  if (I[1] == '6' && I[2] == '4') {
272  I += 3;
273  lmKind = LengthModifier::AsInt64;
274  break;
275  }
276  if (IsScanf)
277  return false;
278 
279  if (I[1] == '3' && I[2] == '2') {
280  I += 3;
281  lmKind = LengthModifier::AsInt32;
282  break;
283  }
284  }
285  ++I;
286  lmKind = LengthModifier::AsInt3264;
287  break;
288  case 'w':
289  lmKind = LengthModifier::AsWide; ++I; break;
290  }
291  LengthModifier lm(lmPosition, lmKind);
292  FS.setLengthModifier(lm);
293  return true;
294 }
295 
297  const char *SpecifierBegin, const char *FmtStrEnd, unsigned &Len) {
298  if (SpecifierBegin + 1 >= FmtStrEnd)
299  return false;
300 
301  const llvm::UTF8 *SB =
302  reinterpret_cast<const llvm::UTF8 *>(SpecifierBegin + 1);
303  const llvm::UTF8 *SE = reinterpret_cast<const llvm::UTF8 *>(FmtStrEnd);
304  const char FirstByte = *SB;
305 
306  // If the invalid specifier is a multibyte UTF-8 string, return the
307  // total length accordingly so that the conversion specifier can be
308  // properly updated to reflect a complete UTF-8 specifier.
309  unsigned NumBytes = llvm::getNumBytesForUTF8(FirstByte);
310  if (NumBytes == 1)
311  return false;
312  if (SB + NumBytes > SE)
313  return false;
314 
315  Len = NumBytes + 1;
316  return true;
317 }
318 
319 //===----------------------------------------------------------------------===//
320 // Methods on ArgType.
321 //===----------------------------------------------------------------------===//
322 
324 ArgType::matchesType(ASTContext &C, QualType argTy) const {
325  if (Ptr) {
326  // It has to be a pointer.
327  const PointerType *PT = argTy->getAs<PointerType>();
328  if (!PT)
329  return NoMatch;
330 
331  // We cannot write through a const qualified pointer.
332  if (PT->getPointeeType().isConstQualified())
333  return NoMatch;
334 
335  argTy = PT->getPointeeType();
336  }
337 
338  switch (K) {
339  case InvalidTy:
340  llvm_unreachable("ArgType must be valid");
341 
342  case UnknownTy:
343  return Match;
344 
345  case AnyCharTy: {
346  if (const EnumType *ETy = argTy->getAs<EnumType>()) {
347  // If the enum is incomplete we know nothing about the underlying type.
348  // Assume that it's 'int'.
349  if (!ETy->getDecl()->isComplete())
350  return NoMatch;
351  argTy = ETy->getDecl()->getIntegerType();
352  }
353 
354  if (const BuiltinType *BT = argTy->getAs<BuiltinType>())
355  switch (BT->getKind()) {
356  default:
357  break;
358  case BuiltinType::Char_S:
359  case BuiltinType::SChar:
360  case BuiltinType::UChar:
361  case BuiltinType::Char_U:
362  return Match;
363  }
364  return NoMatch;
365  }
366 
367  case SpecificTy: {
368  if (const EnumType *ETy = argTy->getAs<EnumType>()) {
369  // If the enum is incomplete we know nothing about the underlying type.
370  // Assume that it's 'int'.
371  if (!ETy->getDecl()->isComplete())
372  argTy = C.IntTy;
373  else
374  argTy = ETy->getDecl()->getIntegerType();
375  }
376  argTy = C.getCanonicalType(argTy).getUnqualifiedType();
377 
378  if (T == argTy)
379  return Match;
380  // Check for "compatible types".
381  if (const BuiltinType *BT = argTy->getAs<BuiltinType>())
382  switch (BT->getKind()) {
383  default:
384  break;
385  case BuiltinType::Char_S:
386  case BuiltinType::SChar:
387  case BuiltinType::Char_U:
388  case BuiltinType::UChar:
389  if (T == C.UnsignedShortTy || T == C.ShortTy)
390  return NoMatchPedantic;
391  return T == C.UnsignedCharTy || T == C.SignedCharTy ? Match
392  : NoMatch;
393  case BuiltinType::Short:
394  return T == C.UnsignedShortTy ? Match : NoMatch;
395  case BuiltinType::UShort:
396  return T == C.ShortTy ? Match : NoMatch;
397  case BuiltinType::Int:
398  return T == C.UnsignedIntTy ? Match : NoMatch;
399  case BuiltinType::UInt:
400  return T == C.IntTy ? Match : NoMatch;
401  case BuiltinType::Long:
402  return T == C.UnsignedLongTy ? Match : NoMatch;
403  case BuiltinType::ULong:
404  return T == C.LongTy ? Match : NoMatch;
405  case BuiltinType::LongLong:
406  return T == C.UnsignedLongLongTy ? Match : NoMatch;
407  case BuiltinType::ULongLong:
408  return T == C.LongLongTy ? Match : NoMatch;
409  }
410  return NoMatch;
411  }
412 
413  case CStrTy: {
414  const PointerType *PT = argTy->getAs<PointerType>();
415  if (!PT)
416  return NoMatch;
417  QualType pointeeTy = PT->getPointeeType();
418  if (const BuiltinType *BT = pointeeTy->getAs<BuiltinType>())
419  switch (BT->getKind()) {
420  case BuiltinType::Void:
421  case BuiltinType::Char_U:
422  case BuiltinType::UChar:
423  case BuiltinType::Char_S:
424  case BuiltinType::SChar:
425  return Match;
426  default:
427  break;
428  }
429 
430  return NoMatch;
431  }
432 
433  case WCStrTy: {
434  const PointerType *PT = argTy->getAs<PointerType>();
435  if (!PT)
436  return NoMatch;
437  QualType pointeeTy =
438  C.getCanonicalType(PT->getPointeeType()).getUnqualifiedType();
439  return pointeeTy == C.getWideCharType() ? Match : NoMatch;
440  }
441 
442  case WIntTy: {
443  QualType WInt = C.getCanonicalType(C.getWIntType()).getUnqualifiedType();
444 
445  if (C.getCanonicalType(argTy).getUnqualifiedType() == WInt)
446  return Match;
447 
448  QualType PromoArg = argTy->isPromotableIntegerType()
449  ? C.getPromotedIntegerType(argTy)
450  : argTy;
451  PromoArg = C.getCanonicalType(PromoArg).getUnqualifiedType();
452 
453  // If the promoted argument is the corresponding signed type of the
454  // wint_t type, then it should match.
455  if (PromoArg->hasSignedIntegerRepresentation() &&
456  C.getCorrespondingUnsignedType(PromoArg) == WInt)
457  return Match;
458 
459  return WInt == PromoArg ? Match : NoMatch;
460  }
461 
462  case CPointerTy:
463  if (argTy->isVoidPointerType()) {
464  return Match;
465  } if (argTy->isPointerType() || argTy->isObjCObjectPointerType() ||
466  argTy->isBlockPointerType() || argTy->isNullPtrType()) {
467  return NoMatchPedantic;
468  } else {
469  return NoMatch;
470  }
471 
472  case ObjCPointerTy: {
473  if (argTy->getAs<ObjCObjectPointerType>() ||
474  argTy->getAs<BlockPointerType>())
475  return Match;
476 
477  // Handle implicit toll-free bridging.
478  if (const PointerType *PT = argTy->getAs<PointerType>()) {
479  // Things such as CFTypeRef are really just opaque pointers
480  // to C structs representing CF types that can often be bridged
481  // to Objective-C objects. Since the compiler doesn't know which
482  // structs can be toll-free bridged, we just accept them all.
483  QualType pointee = PT->getPointeeType();
484  if (pointee->getAsStructureType() || pointee->isVoidType())
485  return Match;
486  }
487  return NoMatch;
488  }
489  }
490 
491  llvm_unreachable("Invalid ArgType Kind!");
492 }
493 
494 ArgType ArgType::makeVectorType(ASTContext &C, unsigned NumElts) const {
495  // Check for valid vector element types.
496  if (T.isNull())
497  return ArgType::Invalid();
498 
499  QualType Vec = C.getExtVectorType(T, NumElts);
500  return ArgType(Vec, Name);
501 }
502 
503 QualType ArgType::getRepresentativeType(ASTContext &C) const {
504  QualType Res;
505  switch (K) {
506  case InvalidTy:
507  llvm_unreachable("No representative type for Invalid ArgType");
508  case UnknownTy:
509  llvm_unreachable("No representative type for Unknown ArgType");
510  case AnyCharTy:
511  Res = C.CharTy;
512  break;
513  case SpecificTy:
514  Res = T;
515  break;
516  case CStrTy:
517  Res = C.getPointerType(C.CharTy);
518  break;
519  case WCStrTy:
520  Res = C.getPointerType(C.getWideCharType());
521  break;
522  case ObjCPointerTy:
523  Res = C.ObjCBuiltinIdTy;
524  break;
525  case CPointerTy:
526  Res = C.VoidPtrTy;
527  break;
528  case WIntTy: {
529  Res = C.getWIntType();
530  break;
531  }
532  }
533 
534  if (Ptr)
535  Res = C.getPointerType(Res);
536  return Res;
537 }
538 
539 std::string ArgType::getRepresentativeTypeName(ASTContext &C) const {
540  std::string S = getRepresentativeType(C).getAsString();
541 
542  std::string Alias;
543  if (Name) {
544  // Use a specific name for this type, e.g. "size_t".
545  Alias = Name;
546  if (Ptr) {
547  // If ArgType is actually a pointer to T, append an asterisk.
548  Alias += (Alias[Alias.size()-1] == '*') ? "*" : " *";
549  }
550  // If Alias is the same as the underlying type, e.g. wchar_t, then drop it.
551  if (S == Alias)
552  Alias.clear();
553  }
554 
555  if (!Alias.empty())
556  return std::string("'") + Alias + "' (aka '" + S + "')";
557  return std::string("'") + S + "'";
558 }
559 
560 
561 //===----------------------------------------------------------------------===//
562 // Methods on OptionalAmount.
563 //===----------------------------------------------------------------------===//
564 
565 ArgType
567  return Ctx.IntTy;
568 }
569 
570 //===----------------------------------------------------------------------===//
571 // Methods on LengthModifier.
572 //===----------------------------------------------------------------------===//
573 
574 const char *
576  switch (kind) {
577  case AsChar:
578  return "hh";
579  case AsShort:
580  return "h";
581  case AsShortLong:
582  return "hl";
583  case AsLong: // or AsWideChar
584  return "l";
585  case AsLongLong:
586  return "ll";
587  case AsQuad:
588  return "q";
589  case AsIntMax:
590  return "j";
591  case AsSizeT:
592  return "z";
593  case AsPtrDiff:
594  return "t";
595  case AsInt32:
596  return "I32";
597  case AsInt3264:
598  return "I";
599  case AsInt64:
600  return "I64";
601  case AsLongDouble:
602  return "L";
603  case AsAllocate:
604  return "a";
605  case AsMAllocate:
606  return "m";
607  case AsWide:
608  return "w";
609  case None:
610  return "";
611  }
612  return nullptr;
613 }
614 
615 //===----------------------------------------------------------------------===//
616 // Methods on ConversionSpecifier.
617 //===----------------------------------------------------------------------===//
618 
619 const char *ConversionSpecifier::toString() const {
620  switch (kind) {
621  case dArg: return "d";
622  case DArg: return "D";
623  case iArg: return "i";
624  case oArg: return "o";
625  case OArg: return "O";
626  case uArg: return "u";
627  case UArg: return "U";
628  case xArg: return "x";
629  case XArg: return "X";
630  case fArg: return "f";
631  case FArg: return "F";
632  case eArg: return "e";
633  case EArg: return "E";
634  case gArg: return "g";
635  case GArg: return "G";
636  case aArg: return "a";
637  case AArg: return "A";
638  case cArg: return "c";
639  case sArg: return "s";
640  case pArg: return "p";
641  case PArg:
642  return "P";
643  case nArg: return "n";
644  case PercentArg: return "%";
645  case ScanListArg: return "[";
646  case InvalidSpecifier: return nullptr;
647 
648  // POSIX unicode extensions.
649  case CArg: return "C";
650  case SArg: return "S";
651 
652  // Objective-C specific specifiers.
653  case ObjCObjArg: return "@";
654 
655  // FreeBSD kernel specific specifiers.
656  case FreeBSDbArg: return "b";
657  case FreeBSDDArg: return "D";
658  case FreeBSDrArg: return "r";
659  case FreeBSDyArg: return "y";
660 
661  // GlibC specific specifiers.
662  case PrintErrno: return "m";
663 
664  // MS specific specifiers.
665  case ZArg: return "Z";
666  }
667  return nullptr;
668 }
669 
673 
674  switch (getKind()) {
675  default:
676  return None;
677  case DArg:
678  NewKind = dArg;
679  break;
680  case UArg:
681  NewKind = uArg;
682  break;
683  case OArg:
684  NewKind = oArg;
685  break;
686  }
687 
688  ConversionSpecifier FixedCS(*this);
689  FixedCS.setKind(NewKind);
690  return FixedCS;
691 }
692 
693 //===----------------------------------------------------------------------===//
694 // Methods on OptionalAmount.
695 //===----------------------------------------------------------------------===//
696 
697 void OptionalAmount::toString(raw_ostream &os) const {
698  switch (hs) {
699  case Invalid:
700  case NotSpecified:
701  return;
702  case Arg:
703  if (UsesDotPrefix)
704  os << ".";
705  if (usesPositionalArg())
706  os << "*" << getPositionalArgIndex() << "$";
707  else
708  os << "*";
709  break;
710  case Constant:
711  if (UsesDotPrefix)
712  os << ".";
713  os << amt;
714  break;
715  }
716 }
717 
719  const LangOptions &LO) const {
720  switch (LM.getKind()) {
722  return true;
723 
724  // Handle most integer flags
726  // Length modifier only applies to FP vectors.
727  if (LO.OpenCL && CS.isDoubleArg())
728  return !VectorNumElts.isInvalid();
729 
730  if (Target.getTriple().isOSMSVCRT()) {
731  switch (CS.getKind()) {
737  return true;
738  default:
739  break;
740  }
741  }
742  LLVM_FALLTHROUGH;
749  switch (CS.getKind()) {
760  return true;
763  return Target.getTriple().isOSFreeBSD() || Target.getTriple().isPS4();
764  default:
765  return false;
766  }
767 
769  return LO.OpenCL && !VectorNumElts.isInvalid();
770 
771  // Handle 'l' flag
772  case LengthModifier::AsLong: // or AsWideChar
773  if (CS.isDoubleArg()) {
774  // Invalid for OpenCL FP scalars.
775  if (LO.OpenCL && VectorNumElts.isInvalid())
776  return false;
777  return true;
778  }
779 
780  switch (CS.getKind()) {
795  return true;
798  return Target.getTriple().isOSFreeBSD() || Target.getTriple().isPS4();
799  default:
800  return false;
801  }
802 
804  switch (CS.getKind()) {
813  return true;
814  // GNU libc extension.
821  return !Target.getTriple().isOSDarwin() &&
822  !Target.getTriple().isOSWindows();
823  default:
824  return false;
825  }
826 
828  switch (CS.getKind()) {
832  return true;
833  default:
834  return false;
835  }
836 
838  switch (CS.getKind()) {
844  return true;
845  default:
846  return false;
847  }
851  switch (CS.getKind()) {
858  return Target.getTriple().isOSMSVCRT();
859  default:
860  return false;
861  }
863  switch (CS.getKind()) {
869  return Target.getTriple().isOSMSVCRT();
870  default:
871  return false;
872  }
873  }
874  llvm_unreachable("Invalid LengthModifier Kind!");
875 }
876 
878  switch (LM.getKind()) {
888  return true;
896  case LengthModifier::AsShortLong: // ???
897  return false;
898  }
899  llvm_unreachable("Invalid LengthModifier Kind!");
900 }
901 
903  const LangOptions &LangOpt) const {
904  switch (CS.getKind()) {
927  return true;
930  return LangOpt.ObjC;
941  return false;
942  }
943  llvm_unreachable("Invalid ConversionSpecifier Kind!");
944 }
945 
947  if (LM.getKind() == LengthModifier::AsLongDouble) {
948  switch(CS.getKind()) {
955  return false;
956  default:
957  return true;
958  }
959  }
960  return true;
961 }
962 
964  if (CS.isAnyIntArg() || CS.getKind() == ConversionSpecifier::nArg) {
965  if (LM.getKind() == LengthModifier::AsLongDouble ||
966  LM.getKind() == LengthModifier::AsQuad) {
967  LengthModifier FixedLM(LM);
969  return FixedLM;
970  }
971  }
972 
973  return None;
974 }
975 
977  LengthModifier &LM) {
978  assert(isa<TypedefType>(QT) && "Expected a TypedefType");
979  const TypedefNameDecl *Typedef = cast<TypedefType>(QT)->getDecl();
980 
981  for (;;) {
982  const IdentifierInfo *Identifier = Typedef->getIdentifier();
983  if (Identifier->getName() == "size_t") {
985  return true;
986  } else if (Identifier->getName() == "ssize_t") {
987  // Not C99, but common in Unix.
989  return true;
990  } else if (Identifier->getName() == "intmax_t") {
992  return true;
993  } else if (Identifier->getName() == "uintmax_t") {
995  return true;
996  } else if (Identifier->getName() == "ptrdiff_t") {
998  return true;
999  }
1000 
1001  QualType T = Typedef->getUnderlyingType();
1002  if (!isa<TypedefType>(T))
1003  break;
1004 
1005  Typedef = cast<TypedefType>(T)->getDecl();
1006  }
1007  return false;
1008 }
virtual void HandlePosition(const char *startPos, unsigned posLen)
Definition: FormatString.h:685
CanQualType LongLongTy
Definition: ASTContext.h:1021
StringRef Identifier
Definition: Format.cpp:1756
PointerType - C99 6.7.5.1 - Pointer Declarators.
Definition: Type.h:2575
CanQualType VoidPtrTy
Definition: ASTContext.h:1040
QualType getPointeeType() const
Definition: Type.h:2588
A (possibly-)qualified type.
Definition: Type.h:643
bool isBlockPointerType() const
Definition: Type.h:6398
bool hasValidLengthModifier(const TargetInfo &Target, const LangOptions &LO) const
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee...
Definition: Type.cpp:518
const llvm::Triple & getTriple() const
Returns the target triple of the primary target.
Definition: TargetInfo.h:991
bool ParseVectorModifier(FormatStringHandler &H, FormatSpecifier &FS, const char *&Beg, const char *E, const LangOptions &LO)
virtual void HandleZeroPosition(const char *startPos, unsigned posLen)
Definition: FormatString.h:690
const RecordType * getAsStructureType() const
Definition: Type.cpp:534
bool ParseArgPosition(FormatStringHandler &H, FormatSpecifier &CS, const char *Start, const char *&Beg, const char *E)
CanQualType LongTy
Definition: ASTContext.h:1021
CanQual< T > getUnqualifiedType() const
Retrieve the unqualified form of this type.
QualType getCorrespondingUnsignedType(QualType T) const
const T * getAs() const
Member-template getAs<specific type>&#39;.
Definition: Type.h:6857
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
Definition: Decl.h:269
One of these records is kept for each identifier that is lexed.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:160
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:49
void setFieldWidth(const OptionalAmount &Amt)
Definition: FormatString.h:434
Represents the length modifier in a format string in scanf/printf.
Definition: FormatString.h:64
CanQualType UnsignedCharTy
Definition: ASTContext.h:1022
OptionalAmount ParseNonPositionAmount(const char *&Beg, const char *E, unsigned &argIndex)
bool isPromotableIntegerType() const
More type predicates useful for type checking/promotion.
Definition: Type.cpp:2511
QualType getPromotedIntegerType(QualType PromotableType) const
Return the type that PromotableType will promote to: C99 6.3.1.1p2, assuming that PromotableType is a...
Exposes information about the current target.
Definition: TargetInfo.h:161
Defines the clang::LangOptions interface.
bool isNullPtrType() const
Definition: Type.h:6674
CanQualType ShortTy
Definition: ASTContext.h:1021
void setVectorNumElts(const OptionalAmount &Amt)
Definition: FormatString.h:426
CanQualType SignedCharTy
Definition: ASTContext.h:1021
bool isVoidPointerType() const
Definition: Type.cpp:482
bool isConstQualified() const
Determine whether this type is const-qualified.
Definition: Type.h:6207
QualType getWideCharType() const
Return the type of wide characters.
Definition: ASTContext.h:1571
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of enums...
Definition: Type.h:4470
virtual void HandleInvalidPosition(const char *startPos, unsigned posLen, PositionContext p)
Definition: FormatString.h:687
static bool namedTypeToLengthModifier(QualType QT, LengthModifier &LM)
For a TypedefType QT, if it is a named integer type such as size_t, assign the appropriate value to L...
QualType getExtVectorType(QualType VectorType, unsigned NumElts) const
Return the unique reference to an extended vector type of the specified element type and size...
QualType getWIntType() const
In C99, this returns a type compatible with the type defined in <stddef.h> as defined by the target...
Definition: ASTContext.h:1585
bool isObjCObjectPointerType() const
Definition: Type.h:6494
bool ParseFieldWidth(FormatStringHandler &H, FormatSpecifier &CS, const char *Start, const char *&Beg, const char *E, unsigned *argIndex)
StringRef getName() const
Return the actual identifier string.
CanQualType UnsignedShortTy
Definition: ASTContext.h:1022
Base class for declarations which introduce a typedef-name.
Definition: Decl.h:2957
CanQualType CharTy
Definition: ASTContext.h:1014
CanQualType ObjCBuiltinIdTy
Definition: ASTContext.h:1044
Dataflow Directional Tag Classes.
QualType getUnderlyingType() const
Definition: Decl.h:3012
CanQualType UnsignedLongLongTy
Definition: ASTContext.h:1023
Optional< LengthModifier > getCorrectedLengthModifier() const
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&#39;t go fur...
Represents a pointer to an Objective C object.
Definition: Type.h:5870
Pointer to a block type.
Definition: Type.h:2677
CanQualType UnsignedLongTy
Definition: ASTContext.h:1022
ArgType getArgType(ASTContext &Ctx) const
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...
CanQualType getCanonicalType(QualType T) const
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
Definition: ASTContext.h:2286
bool hasSignedIntegerRepresentation() const
Determine whether this type has an signed integer representation of some sort, e.g., it is an signed integer type or a vector.
Definition: Type.cpp:1918
bool isVoidType() const
Definition: Type.h:6649
virtual void HandleIncompleteSpecifier(const char *startSpecifier, unsigned specifierLen)
Definition: FormatString.h:692
QualType getPointerType(QualType T) const
Return the uniqued reference to the type for a pointer to the specified type.
unsigned kind
All of the diagnostics that can be emitted by the frontend.
Definition: DiagnosticIDs.h:60
This class is used for builtin types like &#39;int&#39;.
Definition: Type.h:2426
Defines the clang::TargetInfo interface.
bool hasStandardConversionSpecifier(const LangOptions &LangOpt) const
OptionalAmount ParseAmount(const char *&Beg, const char *E)
static Decl::Kind getKind(const Decl *D)
Definition: DeclBase.cpp:945
CanQualType IntTy
Definition: ASTContext.h:1021
bool isPointerType() const
Definition: Type.h:6390
Optional< ConversionSpecifier > getStandardSpecifier() const
CanQualType UnsignedIntTy
Definition: ASTContext.h:1022
OptionalAmount ParsePositionAmount(FormatStringHandler &H, const char *Start, const char *&Beg, const char *E, PositionContext p)