clang  3.9.0
FormatString.cpp
Go to the documentation of this file.
1 // FormatString.cpp - Common stuff for handling printf/scanf formats -*- C++ -*-
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // Shared details for processing format strings of printf and scanf
11 // (and friends).
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #include "FormatStringParsing.h"
17 #include "clang/Basic/TargetInfo.h"
18 #include "llvm/Support/ConvertUTF.h"
19 
27 using namespace clang;
28 
29 // Key function to FormatStringHandler.
30 FormatStringHandler::~FormatStringHandler() {}
31 
32 //===----------------------------------------------------------------------===//
33 // Functions for parsing format strings components in both printf and
34 // scanf format strings.
35 //===----------------------------------------------------------------------===//
36 
38 clang::analyze_format_string::ParseAmount(const char *&Beg, const char *E) {
39  const char *I = Beg;
40  UpdateOnReturn <const char*> UpdateBeg(Beg, I);
41 
42  unsigned accumulator = 0;
43  bool hasDigits = false;
44 
45  for ( ; I != E; ++I) {
46  char c = *I;
47  if (c >= '0' && c <= '9') {
48  hasDigits = true;
49  accumulator = (accumulator * 10) + (c - '0');
50  continue;
51  }
52 
53  if (hasDigits)
54  return OptionalAmount(OptionalAmount::Constant, accumulator, Beg, I - Beg,
55  false);
56 
57  break;
58  }
59 
60  return OptionalAmount();
61 }
62 
65  const char *E,
66  unsigned &argIndex) {
67  if (*Beg == '*') {
68  ++Beg;
69  return OptionalAmount(OptionalAmount::Arg, argIndex++, Beg, 0, false);
70  }
71 
72  return ParseAmount(Beg, E);
73 }
74 
77  const char *Start,
78  const char *&Beg,
79  const char *E,
80  PositionContext p) {
81  if (*Beg == '*') {
82  const char *I = Beg + 1;
83  const OptionalAmount &Amt = ParseAmount(I, E);
84 
85  if (Amt.getHowSpecified() == OptionalAmount::NotSpecified) {
86  H.HandleInvalidPosition(Beg, I - Beg, p);
87  return OptionalAmount(false);
88  }
89 
90  if (I == E) {
91  // No more characters left?
92  H.HandleIncompleteSpecifier(Start, E - Start);
93  return OptionalAmount(false);
94  }
95 
96  assert(Amt.getHowSpecified() == OptionalAmount::Constant);
97 
98  if (*I == '$') {
99  // Handle positional arguments
100 
101  // Special case: '*0$', since this is an easy mistake.
102  if (Amt.getConstantAmount() == 0) {
103  H.HandleZeroPosition(Beg, I - Beg + 1);
104  return OptionalAmount(false);
105  }
106 
107  const char *Tmp = Beg;
108  Beg = ++I;
109 
110  return OptionalAmount(OptionalAmount::Arg, Amt.getConstantAmount() - 1,
111  Tmp, 0, true);
112  }
113 
114  H.HandleInvalidPosition(Beg, I - Beg, p);
115  return OptionalAmount(false);
116  }
117 
118  return ParseAmount(Beg, E);
119 }
120 
121 
122 bool
124  FormatSpecifier &CS,
125  const char *Start,
126  const char *&Beg, const char *E,
127  unsigned *argIndex) {
128  // FIXME: Support negative field widths.
129  if (argIndex) {
130  CS.setFieldWidth(ParseNonPositionAmount(Beg, E, *argIndex));
131  }
132  else {
133  const OptionalAmount Amt =
134  ParsePositionAmount(H, Start, Beg, E,
136 
137  if (Amt.isInvalid())
138  return true;
139  CS.setFieldWidth(Amt);
140  }
141  return false;
142 }
143 
144 bool
146  FormatSpecifier &FS,
147  const char *Start,
148  const char *&Beg,
149  const char *E) {
150  const char *I = Beg;
151 
152  const OptionalAmount &Amt = ParseAmount(I, E);
153 
154  if (I == E) {
155  // No more characters left?
156  H.HandleIncompleteSpecifier(Start, E - Start);
157  return true;
158  }
159 
160  if (Amt.getHowSpecified() == OptionalAmount::Constant && *(I++) == '$') {
161  // Warn that positional arguments are non-standard.
162  H.HandlePosition(Start, I - Start);
163 
164  // Special case: '%0$', since this is an easy mistake.
165  if (Amt.getConstantAmount() == 0) {
166  H.HandleZeroPosition(Start, I - Start);
167  return true;
168  }
169 
170  FS.setArgIndex(Amt.getConstantAmount() - 1);
172  // Update the caller's pointer if we decided to consume
173  // these characters.
174  Beg = I;
175  return false;
176  }
177 
178  return false;
179 }
180 
181 bool
183  const char *&I,
184  const char *E,
185  const LangOptions &LO,
186  bool IsScanf) {
188  const char *lmPosition = I;
189  switch (*I) {
190  default:
191  return false;
192  case 'h':
193  ++I;
194  if (I != E && *I == 'h') {
195  ++I;
196  lmKind = LengthModifier::AsChar;
197  } else {
198  lmKind = LengthModifier::AsShort;
199  }
200  break;
201  case 'l':
202  ++I;
203  if (I != E && *I == 'l') {
204  ++I;
205  lmKind = LengthModifier::AsLongLong;
206  } else {
207  lmKind = LengthModifier::AsLong;
208  }
209  break;
210  case 'j': lmKind = LengthModifier::AsIntMax; ++I; break;
211  case 'z': lmKind = LengthModifier::AsSizeT; ++I; break;
212  case 't': lmKind = LengthModifier::AsPtrDiff; ++I; break;
213  case 'L': lmKind = LengthModifier::AsLongDouble; ++I; break;
214  case 'q': lmKind = LengthModifier::AsQuad; ++I; break;
215  case 'a':
216  if (IsScanf && !LO.C99 && !LO.CPlusPlus11) {
217  // For scanf in C90, look at the next character to see if this should
218  // be parsed as the GNU extension 'a' length modifier. If not, this
219  // will be parsed as a conversion specifier.
220  ++I;
221  if (I != E && (*I == 's' || *I == 'S' || *I == '[')) {
222  lmKind = LengthModifier::AsAllocate;
223  break;
224  }
225  --I;
226  }
227  return false;
228  case 'm':
229  if (IsScanf) {
230  lmKind = LengthModifier::AsMAllocate;
231  ++I;
232  break;
233  }
234  return false;
235  // printf: AsInt64, AsInt32, AsInt3264
236  // scanf: AsInt64
237  case 'I':
238  if (I + 1 != E && I + 2 != E) {
239  if (I[1] == '6' && I[2] == '4') {
240  I += 3;
241  lmKind = LengthModifier::AsInt64;
242  break;
243  }
244  if (IsScanf)
245  return false;
246 
247  if (I[1] == '3' && I[2] == '2') {
248  I += 3;
249  lmKind = LengthModifier::AsInt32;
250  break;
251  }
252  }
253  ++I;
254  lmKind = LengthModifier::AsInt3264;
255  break;
256  case 'w':
257  lmKind = LengthModifier::AsWide; ++I; break;
258  }
259  LengthModifier lm(lmPosition, lmKind);
260  FS.setLengthModifier(lm);
261  return true;
262 }
263 
265  const char *SpecifierBegin, const char *FmtStrEnd, unsigned &Len) {
266  if (SpecifierBegin + 1 >= FmtStrEnd)
267  return false;
268 
269  const UTF8 *SB = reinterpret_cast<const UTF8 *>(SpecifierBegin + 1);
270  const UTF8 *SE = reinterpret_cast<const UTF8 *>(FmtStrEnd);
271  const char FirstByte = *SB;
272 
273  // If the invalid specifier is a multibyte UTF-8 string, return the
274  // total length accordingly so that the conversion specifier can be
275  // properly updated to reflect a complete UTF-8 specifier.
276  unsigned NumBytes = getNumBytesForUTF8(FirstByte);
277  if (NumBytes == 1)
278  return false;
279  if (SB + NumBytes > SE)
280  return false;
281 
282  Len = NumBytes + 1;
283  return true;
284 }
285 
286 //===----------------------------------------------------------------------===//
287 // Methods on ArgType.
288 //===----------------------------------------------------------------------===//
289 
291 ArgType::matchesType(ASTContext &C, QualType argTy) const {
292  if (Ptr) {
293  // It has to be a pointer.
294  const PointerType *PT = argTy->getAs<PointerType>();
295  if (!PT)
296  return NoMatch;
297 
298  // We cannot write through a const qualified pointer.
299  if (PT->getPointeeType().isConstQualified())
300  return NoMatch;
301 
302  argTy = PT->getPointeeType();
303  }
304 
305  switch (K) {
306  case InvalidTy:
307  llvm_unreachable("ArgType must be valid");
308 
309  case UnknownTy:
310  return Match;
311 
312  case AnyCharTy: {
313  if (const EnumType *ETy = argTy->getAs<EnumType>())
314  argTy = ETy->getDecl()->getIntegerType();
315 
316  if (const BuiltinType *BT = argTy->getAs<BuiltinType>())
317  switch (BT->getKind()) {
318  default:
319  break;
320  case BuiltinType::Char_S:
321  case BuiltinType::SChar:
322  case BuiltinType::UChar:
323  case BuiltinType::Char_U:
324  return Match;
325  }
326  return NoMatch;
327  }
328 
329  case SpecificTy: {
330  if (const EnumType *ETy = argTy->getAs<EnumType>())
331  argTy = ETy->getDecl()->getIntegerType();
332  argTy = C.getCanonicalType(argTy).getUnqualifiedType();
333 
334  if (T == argTy)
335  return Match;
336  // Check for "compatible types".
337  if (const BuiltinType *BT = argTy->getAs<BuiltinType>())
338  switch (BT->getKind()) {
339  default:
340  break;
341  case BuiltinType::Char_S:
342  case BuiltinType::SChar:
343  case BuiltinType::Char_U:
344  case BuiltinType::UChar:
345  return T == C.UnsignedCharTy || T == C.SignedCharTy ? Match
346  : NoMatch;
347  case BuiltinType::Short:
348  return T == C.UnsignedShortTy ? Match : NoMatch;
349  case BuiltinType::UShort:
350  return T == C.ShortTy ? Match : NoMatch;
351  case BuiltinType::Int:
352  return T == C.UnsignedIntTy ? Match : NoMatch;
353  case BuiltinType::UInt:
354  return T == C.IntTy ? Match : NoMatch;
355  case BuiltinType::Long:
356  return T == C.UnsignedLongTy ? Match : NoMatch;
357  case BuiltinType::ULong:
358  return T == C.LongTy ? Match : NoMatch;
359  case BuiltinType::LongLong:
360  return T == C.UnsignedLongLongTy ? Match : NoMatch;
361  case BuiltinType::ULongLong:
362  return T == C.LongLongTy ? Match : NoMatch;
363  }
364  return NoMatch;
365  }
366 
367  case CStrTy: {
368  const PointerType *PT = argTy->getAs<PointerType>();
369  if (!PT)
370  return NoMatch;
371  QualType pointeeTy = PT->getPointeeType();
372  if (const BuiltinType *BT = pointeeTy->getAs<BuiltinType>())
373  switch (BT->getKind()) {
374  case BuiltinType::Void:
375  case BuiltinType::Char_U:
376  case BuiltinType::UChar:
377  case BuiltinType::Char_S:
378  case BuiltinType::SChar:
379  return Match;
380  default:
381  break;
382  }
383 
384  return NoMatch;
385  }
386 
387  case WCStrTy: {
388  const PointerType *PT = argTy->getAs<PointerType>();
389  if (!PT)
390  return NoMatch;
391  QualType pointeeTy =
392  C.getCanonicalType(PT->getPointeeType()).getUnqualifiedType();
393  return pointeeTy == C.getWideCharType() ? Match : NoMatch;
394  }
395 
396  case WIntTy: {
397 
398  QualType PromoArg =
399  argTy->isPromotableIntegerType()
400  ? C.getPromotedIntegerType(argTy) : argTy;
401 
402  QualType WInt = C.getCanonicalType(C.getWIntType()).getUnqualifiedType();
403  PromoArg = C.getCanonicalType(PromoArg).getUnqualifiedType();
404 
405  // If the promoted argument is the corresponding signed type of the
406  // wint_t type, then it should match.
407  if (PromoArg->hasSignedIntegerRepresentation() &&
408  C.getCorrespondingUnsignedType(PromoArg) == WInt)
409  return Match;
410 
411  return WInt == PromoArg ? Match : NoMatch;
412  }
413 
414  case CPointerTy:
415  if (argTy->isVoidPointerType()) {
416  return Match;
417  } if (argTy->isPointerType() || argTy->isObjCObjectPointerType() ||
418  argTy->isBlockPointerType() || argTy->isNullPtrType()) {
419  return NoMatchPedantic;
420  } else {
421  return NoMatch;
422  }
423 
424  case ObjCPointerTy: {
425  if (argTy->getAs<ObjCObjectPointerType>() ||
426  argTy->getAs<BlockPointerType>())
427  return Match;
428 
429  // Handle implicit toll-free bridging.
430  if (const PointerType *PT = argTy->getAs<PointerType>()) {
431  // Things such as CFTypeRef are really just opaque pointers
432  // to C structs representing CF types that can often be bridged
433  // to Objective-C objects. Since the compiler doesn't know which
434  // structs can be toll-free bridged, we just accept them all.
435  QualType pointee = PT->getPointeeType();
436  if (pointee->getAsStructureType() || pointee->isVoidType())
437  return Match;
438  }
439  return NoMatch;
440  }
441  }
442 
443  llvm_unreachable("Invalid ArgType Kind!");
444 }
445 
446 QualType ArgType::getRepresentativeType(ASTContext &C) const {
447  QualType Res;
448  switch (K) {
449  case InvalidTy:
450  llvm_unreachable("No representative type for Invalid ArgType");
451  case UnknownTy:
452  llvm_unreachable("No representative type for Unknown ArgType");
453  case AnyCharTy:
454  Res = C.CharTy;
455  break;
456  case SpecificTy:
457  Res = T;
458  break;
459  case CStrTy:
460  Res = C.getPointerType(C.CharTy);
461  break;
462  case WCStrTy:
463  Res = C.getPointerType(C.getWideCharType());
464  break;
465  case ObjCPointerTy:
466  Res = C.ObjCBuiltinIdTy;
467  break;
468  case CPointerTy:
469  Res = C.VoidPtrTy;
470  break;
471  case WIntTy: {
472  Res = C.getWIntType();
473  break;
474  }
475  }
476 
477  if (Ptr)
478  Res = C.getPointerType(Res);
479  return Res;
480 }
481 
482 std::string ArgType::getRepresentativeTypeName(ASTContext &C) const {
483  std::string S = getRepresentativeType(C).getAsString();
484 
485  std::string Alias;
486  if (Name) {
487  // Use a specific name for this type, e.g. "size_t".
488  Alias = Name;
489  if (Ptr) {
490  // If ArgType is actually a pointer to T, append an asterisk.
491  Alias += (Alias[Alias.size()-1] == '*') ? "*" : " *";
492  }
493  // If Alias is the same as the underlying type, e.g. wchar_t, then drop it.
494  if (S == Alias)
495  Alias.clear();
496  }
497 
498  if (!Alias.empty())
499  return std::string("'") + Alias + "' (aka '" + S + "')";
500  return std::string("'") + S + "'";
501 }
502 
503 
504 //===----------------------------------------------------------------------===//
505 // Methods on OptionalAmount.
506 //===----------------------------------------------------------------------===//
507 
508 ArgType
510  return Ctx.IntTy;
511 }
512 
513 //===----------------------------------------------------------------------===//
514 // Methods on LengthModifier.
515 //===----------------------------------------------------------------------===//
516 
517 const char *
519  switch (kind) {
520  case AsChar:
521  return "hh";
522  case AsShort:
523  return "h";
524  case AsLong: // or AsWideChar
525  return "l";
526  case AsLongLong:
527  return "ll";
528  case AsQuad:
529  return "q";
530  case AsIntMax:
531  return "j";
532  case AsSizeT:
533  return "z";
534  case AsPtrDiff:
535  return "t";
536  case AsInt32:
537  return "I32";
538  case AsInt3264:
539  return "I";
540  case AsInt64:
541  return "I64";
542  case AsLongDouble:
543  return "L";
544  case AsAllocate:
545  return "a";
546  case AsMAllocate:
547  return "m";
548  case AsWide:
549  return "w";
550  case None:
551  return "";
552  }
553  return nullptr;
554 }
555 
556 //===----------------------------------------------------------------------===//
557 // Methods on ConversionSpecifier.
558 //===----------------------------------------------------------------------===//
559 
560 const char *ConversionSpecifier::toString() const {
561  switch (kind) {
562  case dArg: return "d";
563  case DArg: return "D";
564  case iArg: return "i";
565  case oArg: return "o";
566  case OArg: return "O";
567  case uArg: return "u";
568  case UArg: return "U";
569  case xArg: return "x";
570  case XArg: return "X";
571  case fArg: return "f";
572  case FArg: return "F";
573  case eArg: return "e";
574  case EArg: return "E";
575  case gArg: return "g";
576  case GArg: return "G";
577  case aArg: return "a";
578  case AArg: return "A";
579  case cArg: return "c";
580  case sArg: return "s";
581  case pArg: return "p";
582  case nArg: return "n";
583  case PercentArg: return "%";
584  case ScanListArg: return "[";
585  case InvalidSpecifier: return nullptr;
586 
587  // POSIX unicode extensions.
588  case CArg: return "C";
589  case SArg: return "S";
590 
591  // Objective-C specific specifiers.
592  case ObjCObjArg: return "@";
593 
594  // FreeBSD kernel specific specifiers.
595  case FreeBSDbArg: return "b";
596  case FreeBSDDArg: return "D";
597  case FreeBSDrArg: return "r";
598  case FreeBSDyArg: return "y";
599 
600  // GlibC specific specifiers.
601  case PrintErrno: return "m";
602 
603  // MS specific specifiers.
604  case ZArg: return "Z";
605  }
606  return nullptr;
607 }
608 
612 
613  switch (getKind()) {
614  default:
615  return None;
616  case DArg:
617  NewKind = dArg;
618  break;
619  case UArg:
620  NewKind = uArg;
621  break;
622  case OArg:
623  NewKind = oArg;
624  break;
625  }
626 
627  ConversionSpecifier FixedCS(*this);
628  FixedCS.setKind(NewKind);
629  return FixedCS;
630 }
631 
632 //===----------------------------------------------------------------------===//
633 // Methods on OptionalAmount.
634 //===----------------------------------------------------------------------===//
635 
636 void OptionalAmount::toString(raw_ostream &os) const {
637  switch (hs) {
638  case Invalid:
639  case NotSpecified:
640  return;
641  case Arg:
642  if (UsesDotPrefix)
643  os << ".";
644  if (usesPositionalArg())
645  os << "*" << getPositionalArgIndex() << "$";
646  else
647  os << "*";
648  break;
649  case Constant:
650  if (UsesDotPrefix)
651  os << ".";
652  os << amt;
653  break;
654  }
655 }
656 
658  switch (LM.getKind()) {
660  return true;
661 
662  // Handle most integer flags
664  if (Target.getTriple().isOSMSVCRT()) {
665  switch (CS.getKind()) {
671  return true;
672  default:
673  break;
674  }
675  }
676  // Fall through.
683  switch (CS.getKind()) {
694  return true;
697  return Target.getTriple().isOSFreeBSD() || Target.getTriple().isPS4();
698  default:
699  return false;
700  }
701 
702  // Handle 'l' flag
703  case LengthModifier::AsLong: // or AsWideChar
704  switch (CS.getKind()) {
727  return true;
730  return Target.getTriple().isOSFreeBSD() || Target.getTriple().isPS4();
731  default:
732  return false;
733  }
734 
736  switch (CS.getKind()) {
745  return true;
746  // GNU libc extension.
753  return !Target.getTriple().isOSDarwin() &&
754  !Target.getTriple().isOSWindows();
755  default:
756  return false;
757  }
758 
760  switch (CS.getKind()) {
764  return true;
765  default:
766  return false;
767  }
768 
770  switch (CS.getKind()) {
776  return true;
777  default:
778  return false;
779  }
783  switch (CS.getKind()) {
790  return Target.getTriple().isOSMSVCRT();
791  default:
792  return false;
793  }
795  switch (CS.getKind()) {
801  return Target.getTriple().isOSMSVCRT();
802  default:
803  return false;
804  }
805  }
806  llvm_unreachable("Invalid LengthModifier Kind!");
807 }
808 
810  switch (LM.getKind()) {
820  return true;
828  return false;
829  }
830  llvm_unreachable("Invalid LengthModifier Kind!");
831 }
832 
834  const LangOptions &LangOpt) const {
835  switch (CS.getKind()) {
857  return true;
860  return LangOpt.ObjC1 || LangOpt.ObjC2;
871  return false;
872  }
873  llvm_unreachable("Invalid ConversionSpecifier Kind!");
874 }
875 
878  switch(CS.getKind()) {
885  return false;
886  default:
887  return true;
888  }
889  }
890  return true;
891 }
892 
897  LengthModifier FixedLM(LM);
899  return FixedLM;
900  }
901  }
902 
903  return None;
904 }
905 
907  LengthModifier &LM) {
908  assert(isa<TypedefType>(QT) && "Expected a TypedefType");
909  const TypedefNameDecl *Typedef = cast<TypedefType>(QT)->getDecl();
910 
911  for (;;) {
912  const IdentifierInfo *Identifier = Typedef->getIdentifier();
913  if (Identifier->getName() == "size_t") {
915  return true;
916  } else if (Identifier->getName() == "ssize_t") {
917  // Not C99, but common in Unix.
919  return true;
920  } else if (Identifier->getName() == "intmax_t") {
922  return true;
923  } else if (Identifier->getName() == "uintmax_t") {
925  return true;
926  } else if (Identifier->getName() == "ptrdiff_t") {
928  return true;
929  }
930 
931  QualType T = Typedef->getUnderlyingType();
932  if (!isa<TypedefType>(T))
933  break;
934 
935  Typedef = cast<TypedefType>(T)->getDecl();
936  }
937  return false;
938 }
virtual void HandlePosition(const char *startPos, unsigned posLen)
Definition: FormatString.h:612
CanQualType LongLongTy
Definition: ASTContext.h:901
QualType getPromotedIntegerType(QualType PromotableType) const
Return the type that PromotableType will promote to: C99 6.3.1.1p2, assuming that PromotableType is a...
bool isNullPtrType() const
Definition: Type.h:5693
PointerType - C99 6.7.5.1 - Pointer Declarators.
Definition: Type.h:2179
CanQualType VoidPtrTy
Definition: ASTContext.h:908
A (possibly-)qualified type.
Definition: Type.h:598
IdentifierInfo * getIdentifier() const
getIdentifier - Get the identifier that names this declaration, if there is one.
Definition: Decl.h:232
CanQual< T > getUnqualifiedType() const
Retrieve the unqualified form of this type.
Optional< LengthModifier > getCorrectedLengthModifier() const
bool hasStandardConversionSpecifier(const LangOptions &LangOpt) const
QualType getUnderlyingType() const
Definition: Decl.h:2649
virtual void HandleZeroPosition(const char *startPos, unsigned posLen)
Definition: FormatString.h:617
bool isVoidPointerType() const
Definition: Type.cpp:385
bool ParseArgPosition(FormatStringHandler &H, FormatSpecifier &CS, const char *Start, const char *&Beg, const char *E)
CanQualType LongTy
Definition: ASTContext.h:901
bool isBlockPointerType() const
Definition: Type.h:5488
bool isVoidType() const
Definition: Type.h:5680
One of these records is kept for each identifier that is lexed.
class LLVM_ALIGNAS(8) DependentTemplateSpecializationType const IdentifierInfo * Name
Represents a template specialization type whose template cannot be resolved, e.g. ...
Definition: Type.h:4549
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:92
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:48
void setFieldWidth(const OptionalAmount &Amt)
Definition: FormatString.h:381
Optional< ConversionSpecifier > getStandardSpecifier() const
Represents the length modifier in a format string in scanf/printf.
Definition: FormatString.h:65
detail::InMemoryDirectory::const_iterator I
CanQualType UnsignedCharTy
Definition: ASTContext.h:902
OptionalAmount ParseNonPositionAmount(const char *&Beg, const char *E, unsigned &argIndex)
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee...
Definition: Type.cpp:415
Exposes information about the current target.
Defines the clang::LangOptions interface.
StringRef getName() const
Return the actual identifier string.
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:1360
CanQualType ShortTy
Definition: ASTContext.h:901
QualType getWideCharType() const
Return the type of wide characters.
Definition: ASTContext.h:1346
CanQualType SignedCharTy
Definition: ASTContext.h:901
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of enums...
Definition: Type.h:3733
virtual void HandleInvalidPosition(const char *startPos, unsigned posLen, PositionContext p)
Definition: FormatString.h:614
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...
bool isPromotableIntegerType() const
More type predicates useful for type checking/promotion.
Definition: Type.cpp:2320
bool ParseFieldWidth(FormatStringHandler &H, FormatSpecifier &CS, const char *Start, const char *&Beg, const char *E, unsigned *argIndex)
QualType getPointeeType() const
Definition: Type.h:2193
CanQualType UnsignedShortTy
Definition: ASTContext.h:902
Base class for declarations which introduce a typedef-name.
Definition: Decl.h:2609
CanQualType CharTy
Definition: ASTContext.h:895
CanQualType ObjCBuiltinIdTy
Definition: ASTContext.h:912
CanQualType UnsignedLongLongTy
Definition: ASTContext.h:903
QualType getPointerType(QualType T) const
Return the uniqued reference to the type for a pointer to the specified type.
const llvm::Triple & getTriple() const
Returns the target triple of the primary target.
detail::InMemoryDirectory::const_iterator E
CanQualType getCanonicalType(QualType T) const
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
Definition: ASTContext.h:1966
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...
QualType getCorrespondingUnsignedType(QualType T) const
const RecordType * getAsStructureType() const
Definition: Type.cpp:431
Represents a pointer to an Objective C object.
Definition: Type.h:4991
Pointer to a block type.
Definition: Type.h:2286
const T * getAs() const
Member-template getAs<specific type>'.
Definition: Type.h:5818
CanQualType UnsignedLongTy
Definition: ASTContext.h:902
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...
bool isObjCObjectPointerType() const
Definition: Type.h:5554
virtual void HandleIncompleteSpecifier(const char *startSpecifier, unsigned specifierLen)
Definition: FormatString.h:619
unsigned kind
All of the diagnostics that can be emitted by the frontend.
Definition: DiagnosticIDs.h:43
This class is used for builtin types like 'int'.
Definition: Type.h:2039
Defines the clang::TargetInfo interface.
OptionalAmount ParseAmount(const char *&Beg, const char *E)
CanQualType IntTy
Definition: ASTContext.h:901
ArgType getArgType(ASTContext &Ctx) const
bool hasValidLengthModifier(const TargetInfo &Target) const
bool isConstQualified() const
Determine whether this type is const-qualified.
Definition: Type.h:5318
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:1736
CanQualType UnsignedIntTy
Definition: ASTContext.h:902
OptionalAmount ParsePositionAmount(FormatStringHandler &H, const char *Start, const char *&Beg, const char *E, PositionContext p)
bool isPointerType() const
Definition: Type.h:5482