clang  6.0.0svn
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 llvm::UTF8 *SB =
270  reinterpret_cast<const llvm::UTF8 *>(SpecifierBegin + 1);
271  const llvm::UTF8 *SE = reinterpret_cast<const llvm::UTF8 *>(FmtStrEnd);
272  const char FirstByte = *SB;
273 
274  // If the invalid specifier is a multibyte UTF-8 string, return the
275  // total length accordingly so that the conversion specifier can be
276  // properly updated to reflect a complete UTF-8 specifier.
277  unsigned NumBytes = llvm::getNumBytesForUTF8(FirstByte);
278  if (NumBytes == 1)
279  return false;
280  if (SB + NumBytes > SE)
281  return false;
282 
283  Len = NumBytes + 1;
284  return true;
285 }
286 
287 //===----------------------------------------------------------------------===//
288 // Methods on ArgType.
289 //===----------------------------------------------------------------------===//
290 
292 ArgType::matchesType(ASTContext &C, QualType argTy) const {
293  if (Ptr) {
294  // It has to be a pointer.
295  const PointerType *PT = argTy->getAs<PointerType>();
296  if (!PT)
297  return NoMatch;
298 
299  // We cannot write through a const qualified pointer.
300  if (PT->getPointeeType().isConstQualified())
301  return NoMatch;
302 
303  argTy = PT->getPointeeType();
304  }
305 
306  switch (K) {
307  case InvalidTy:
308  llvm_unreachable("ArgType must be valid");
309 
310  case UnknownTy:
311  return Match;
312 
313  case AnyCharTy: {
314  if (const EnumType *ETy = argTy->getAs<EnumType>()) {
315  // If the enum is incomplete we know nothing about the underlying type.
316  // Assume that it's 'int'.
317  if (!ETy->getDecl()->isComplete())
318  return NoMatch;
319  argTy = ETy->getDecl()->getIntegerType();
320  }
321 
322  if (const BuiltinType *BT = argTy->getAs<BuiltinType>())
323  switch (BT->getKind()) {
324  default:
325  break;
326  case BuiltinType::Char_S:
327  case BuiltinType::SChar:
328  case BuiltinType::UChar:
329  case BuiltinType::Char_U:
330  return Match;
331  }
332  return NoMatch;
333  }
334 
335  case SpecificTy: {
336  if (const EnumType *ETy = argTy->getAs<EnumType>()) {
337  // If the enum is incomplete we know nothing about the underlying type.
338  // Assume that it's 'int'.
339  if (!ETy->getDecl()->isComplete())
340  argTy = C.IntTy;
341  else
342  argTy = ETy->getDecl()->getIntegerType();
343  }
344  argTy = C.getCanonicalType(argTy).getUnqualifiedType();
345 
346  if (T == argTy)
347  return Match;
348  // Check for "compatible types".
349  if (const BuiltinType *BT = argTy->getAs<BuiltinType>())
350  switch (BT->getKind()) {
351  default:
352  break;
353  case BuiltinType::Char_S:
354  case BuiltinType::SChar:
355  case BuiltinType::Char_U:
356  case BuiltinType::UChar:
357  return T == C.UnsignedCharTy || T == C.SignedCharTy ? Match
358  : NoMatch;
359  case BuiltinType::Short:
360  return T == C.UnsignedShortTy ? Match : NoMatch;
361  case BuiltinType::UShort:
362  return T == C.ShortTy ? Match : NoMatch;
363  case BuiltinType::Int:
364  return T == C.UnsignedIntTy ? Match : NoMatch;
365  case BuiltinType::UInt:
366  return T == C.IntTy ? Match : NoMatch;
367  case BuiltinType::Long:
368  return T == C.UnsignedLongTy ? Match : NoMatch;
369  case BuiltinType::ULong:
370  return T == C.LongTy ? Match : NoMatch;
371  case BuiltinType::LongLong:
372  return T == C.UnsignedLongLongTy ? Match : NoMatch;
373  case BuiltinType::ULongLong:
374  return T == C.LongLongTy ? Match : NoMatch;
375  }
376  return NoMatch;
377  }
378 
379  case CStrTy: {
380  const PointerType *PT = argTy->getAs<PointerType>();
381  if (!PT)
382  return NoMatch;
383  QualType pointeeTy = PT->getPointeeType();
384  if (const BuiltinType *BT = pointeeTy->getAs<BuiltinType>())
385  switch (BT->getKind()) {
386  case BuiltinType::Void:
387  case BuiltinType::Char_U:
388  case BuiltinType::UChar:
389  case BuiltinType::Char_S:
390  case BuiltinType::SChar:
391  return Match;
392  default:
393  break;
394  }
395 
396  return NoMatch;
397  }
398 
399  case WCStrTy: {
400  const PointerType *PT = argTy->getAs<PointerType>();
401  if (!PT)
402  return NoMatch;
403  QualType pointeeTy =
404  C.getCanonicalType(PT->getPointeeType()).getUnqualifiedType();
405  return pointeeTy == C.getWideCharType() ? Match : NoMatch;
406  }
407 
408  case WIntTy: {
409 
410  QualType PromoArg =
411  argTy->isPromotableIntegerType()
412  ? C.getPromotedIntegerType(argTy) : argTy;
413 
414  QualType WInt = C.getCanonicalType(C.getWIntType()).getUnqualifiedType();
415  PromoArg = C.getCanonicalType(PromoArg).getUnqualifiedType();
416 
417  // If the promoted argument is the corresponding signed type of the
418  // wint_t type, then it should match.
419  if (PromoArg->hasSignedIntegerRepresentation() &&
420  C.getCorrespondingUnsignedType(PromoArg) == WInt)
421  return Match;
422 
423  return WInt == PromoArg ? Match : NoMatch;
424  }
425 
426  case CPointerTy:
427  if (argTy->isVoidPointerType()) {
428  return Match;
429  } if (argTy->isPointerType() || argTy->isObjCObjectPointerType() ||
430  argTy->isBlockPointerType() || argTy->isNullPtrType()) {
431  return NoMatchPedantic;
432  } else {
433  return NoMatch;
434  }
435 
436  case ObjCPointerTy: {
437  if (argTy->getAs<ObjCObjectPointerType>() ||
438  argTy->getAs<BlockPointerType>())
439  return Match;
440 
441  // Handle implicit toll-free bridging.
442  if (const PointerType *PT = argTy->getAs<PointerType>()) {
443  // Things such as CFTypeRef are really just opaque pointers
444  // to C structs representing CF types that can often be bridged
445  // to Objective-C objects. Since the compiler doesn't know which
446  // structs can be toll-free bridged, we just accept them all.
447  QualType pointee = PT->getPointeeType();
448  if (pointee->getAsStructureType() || pointee->isVoidType())
449  return Match;
450  }
451  return NoMatch;
452  }
453  }
454 
455  llvm_unreachable("Invalid ArgType Kind!");
456 }
457 
458 QualType ArgType::getRepresentativeType(ASTContext &C) const {
459  QualType Res;
460  switch (K) {
461  case InvalidTy:
462  llvm_unreachable("No representative type for Invalid ArgType");
463  case UnknownTy:
464  llvm_unreachable("No representative type for Unknown ArgType");
465  case AnyCharTy:
466  Res = C.CharTy;
467  break;
468  case SpecificTy:
469  Res = T;
470  break;
471  case CStrTy:
472  Res = C.getPointerType(C.CharTy);
473  break;
474  case WCStrTy:
475  Res = C.getPointerType(C.getWideCharType());
476  break;
477  case ObjCPointerTy:
478  Res = C.ObjCBuiltinIdTy;
479  break;
480  case CPointerTy:
481  Res = C.VoidPtrTy;
482  break;
483  case WIntTy: {
484  Res = C.getWIntType();
485  break;
486  }
487  }
488 
489  if (Ptr)
490  Res = C.getPointerType(Res);
491  return Res;
492 }
493 
494 std::string ArgType::getRepresentativeTypeName(ASTContext &C) const {
495  std::string S = getRepresentativeType(C).getAsString();
496 
497  std::string Alias;
498  if (Name) {
499  // Use a specific name for this type, e.g. "size_t".
500  Alias = Name;
501  if (Ptr) {
502  // If ArgType is actually a pointer to T, append an asterisk.
503  Alias += (Alias[Alias.size()-1] == '*') ? "*" : " *";
504  }
505  // If Alias is the same as the underlying type, e.g. wchar_t, then drop it.
506  if (S == Alias)
507  Alias.clear();
508  }
509 
510  if (!Alias.empty())
511  return std::string("'") + Alias + "' (aka '" + S + "')";
512  return std::string("'") + S + "'";
513 }
514 
515 
516 //===----------------------------------------------------------------------===//
517 // Methods on OptionalAmount.
518 //===----------------------------------------------------------------------===//
519 
520 ArgType
522  return Ctx.IntTy;
523 }
524 
525 //===----------------------------------------------------------------------===//
526 // Methods on LengthModifier.
527 //===----------------------------------------------------------------------===//
528 
529 const char *
531  switch (kind) {
532  case AsChar:
533  return "hh";
534  case AsShort:
535  return "h";
536  case AsLong: // or AsWideChar
537  return "l";
538  case AsLongLong:
539  return "ll";
540  case AsQuad:
541  return "q";
542  case AsIntMax:
543  return "j";
544  case AsSizeT:
545  return "z";
546  case AsPtrDiff:
547  return "t";
548  case AsInt32:
549  return "I32";
550  case AsInt3264:
551  return "I";
552  case AsInt64:
553  return "I64";
554  case AsLongDouble:
555  return "L";
556  case AsAllocate:
557  return "a";
558  case AsMAllocate:
559  return "m";
560  case AsWide:
561  return "w";
562  case None:
563  return "";
564  }
565  return nullptr;
566 }
567 
568 //===----------------------------------------------------------------------===//
569 // Methods on ConversionSpecifier.
570 //===----------------------------------------------------------------------===//
571 
572 const char *ConversionSpecifier::toString() const {
573  switch (kind) {
574  case dArg: return "d";
575  case DArg: return "D";
576  case iArg: return "i";
577  case oArg: return "o";
578  case OArg: return "O";
579  case uArg: return "u";
580  case UArg: return "U";
581  case xArg: return "x";
582  case XArg: return "X";
583  case fArg: return "f";
584  case FArg: return "F";
585  case eArg: return "e";
586  case EArg: return "E";
587  case gArg: return "g";
588  case GArg: return "G";
589  case aArg: return "a";
590  case AArg: return "A";
591  case cArg: return "c";
592  case sArg: return "s";
593  case pArg: return "p";
594  case PArg:
595  return "P";
596  case nArg: return "n";
597  case PercentArg: return "%";
598  case ScanListArg: return "[";
599  case InvalidSpecifier: return nullptr;
600 
601  // POSIX unicode extensions.
602  case CArg: return "C";
603  case SArg: return "S";
604 
605  // Objective-C specific specifiers.
606  case ObjCObjArg: return "@";
607 
608  // FreeBSD kernel specific specifiers.
609  case FreeBSDbArg: return "b";
610  case FreeBSDDArg: return "D";
611  case FreeBSDrArg: return "r";
612  case FreeBSDyArg: return "y";
613 
614  // GlibC specific specifiers.
615  case PrintErrno: return "m";
616 
617  // MS specific specifiers.
618  case ZArg: return "Z";
619  }
620  return nullptr;
621 }
622 
626 
627  switch (getKind()) {
628  default:
629  return None;
630  case DArg:
631  NewKind = dArg;
632  break;
633  case UArg:
634  NewKind = uArg;
635  break;
636  case OArg:
637  NewKind = oArg;
638  break;
639  }
640 
641  ConversionSpecifier FixedCS(*this);
642  FixedCS.setKind(NewKind);
643  return FixedCS;
644 }
645 
646 //===----------------------------------------------------------------------===//
647 // Methods on OptionalAmount.
648 //===----------------------------------------------------------------------===//
649 
650 void OptionalAmount::toString(raw_ostream &os) const {
651  switch (hs) {
652  case Invalid:
653  case NotSpecified:
654  return;
655  case Arg:
656  if (UsesDotPrefix)
657  os << ".";
658  if (usesPositionalArg())
659  os << "*" << getPositionalArgIndex() << "$";
660  else
661  os << "*";
662  break;
663  case Constant:
664  if (UsesDotPrefix)
665  os << ".";
666  os << amt;
667  break;
668  }
669 }
670 
672  switch (LM.getKind()) {
674  return true;
675 
676  // Handle most integer flags
678  if (Target.getTriple().isOSMSVCRT()) {
679  switch (CS.getKind()) {
685  return true;
686  default:
687  break;
688  }
689  }
690  // Fall through.
697  switch (CS.getKind()) {
708  return true;
711  return Target.getTriple().isOSFreeBSD() || Target.getTriple().isPS4();
712  default:
713  return false;
714  }
715 
716  // Handle 'l' flag
717  case LengthModifier::AsLong: // or AsWideChar
718  switch (CS.getKind()) {
741  return true;
744  return Target.getTriple().isOSFreeBSD() || Target.getTriple().isPS4();
745  default:
746  return false;
747  }
748 
750  switch (CS.getKind()) {
759  return true;
760  // GNU libc extension.
767  return !Target.getTriple().isOSDarwin() &&
768  !Target.getTriple().isOSWindows();
769  default:
770  return false;
771  }
772 
774  switch (CS.getKind()) {
778  return true;
779  default:
780  return false;
781  }
782 
784  switch (CS.getKind()) {
790  return true;
791  default:
792  return false;
793  }
797  switch (CS.getKind()) {
804  return Target.getTriple().isOSMSVCRT();
805  default:
806  return false;
807  }
809  switch (CS.getKind()) {
815  return Target.getTriple().isOSMSVCRT();
816  default:
817  return false;
818  }
819  }
820  llvm_unreachable("Invalid LengthModifier Kind!");
821 }
822 
824  switch (LM.getKind()) {
834  return true;
842  return false;
843  }
844  llvm_unreachable("Invalid LengthModifier Kind!");
845 }
846 
848  const LangOptions &LangOpt) const {
849  switch (CS.getKind()) {
872  return true;
875  return LangOpt.ObjC1 || LangOpt.ObjC2;
886  return false;
887  }
888  llvm_unreachable("Invalid ConversionSpecifier Kind!");
889 }
890 
892  if (LM.getKind() == LengthModifier::AsLongDouble) {
893  switch(CS.getKind()) {
900  return false;
901  default:
902  return true;
903  }
904  }
905  return true;
906 }
907 
909  if (CS.isAnyIntArg() || CS.getKind() == ConversionSpecifier::nArg) {
910  if (LM.getKind() == LengthModifier::AsLongDouble ||
911  LM.getKind() == LengthModifier::AsQuad) {
912  LengthModifier FixedLM(LM);
914  return FixedLM;
915  }
916  }
917 
918  return None;
919 }
920 
922  LengthModifier &LM) {
923  assert(isa<TypedefType>(QT) && "Expected a TypedefType");
924  const TypedefNameDecl *Typedef = cast<TypedefType>(QT)->getDecl();
925 
926  for (;;) {
927  const IdentifierInfo *Identifier = Typedef->getIdentifier();
928  if (Identifier->getName() == "size_t") {
930  return true;
931  } else if (Identifier->getName() == "ssize_t") {
932  // Not C99, but common in Unix.
934  return true;
935  } else if (Identifier->getName() == "intmax_t") {
937  return true;
938  } else if (Identifier->getName() == "uintmax_t") {
940  return true;
941  } else if (Identifier->getName() == "ptrdiff_t") {
943  return true;
944  }
945 
946  QualType T = Typedef->getUnderlyingType();
947  if (!isa<TypedefType>(T))
948  break;
949 
950  Typedef = cast<TypedefType>(T)->getDecl();
951  }
952  return false;
953 }
virtual void HandlePosition(const char *startPos, unsigned posLen)
Definition: FormatString.h:631
CanQualType LongLongTy
Definition: ASTContext.h:1004
PointerType - C99 6.7.5.1 - Pointer Declarators.
Definition: Type.h:2285
CanQualType VoidPtrTy
Definition: ASTContext.h:1012
QualType getPointeeType() const
Definition: Type.h:2298
A (possibly-)qualified type.
Definition: Type.h:653
bool isBlockPointerType() const
Definition: Type.h:5952
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee...
Definition: Type.cpp:456
const llvm::Triple & getTriple() const
Returns the target triple of the primary target.
Definition: TargetInfo.h:790
virtual void HandleZeroPosition(const char *startPos, unsigned posLen)
Definition: FormatString.h:636
const RecordType * getAsStructureType() const
Definition: Type.cpp:472
bool ParseArgPosition(FormatStringHandler &H, FormatSpecifier &CS, const char *Start, const char *&Beg, const char *E)
CanQualType LongTy
Definition: ASTContext.h:1004
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:6307
IdentifierInfo * getIdentifier() const
getIdentifier - Get the identifier that names this declaration, if there is one.
Definition: Decl.h:265
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:149
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:394
Represents the length modifier in a format string in scanf/printf.
Definition: FormatString.h:65
bool hasValidLengthModifier(const TargetInfo &Target) const
CanQualType UnsignedCharTy
Definition: ASTContext.h:1005
OptionalAmount ParseNonPositionAmount(const char *&Beg, const char *E, unsigned &argIndex)
bool isPromotableIntegerType() const
More type predicates useful for type checking/promotion.
Definition: Type.cpp:2381
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:54
Defines the clang::LangOptions interface.
const FunctionProtoType * T
bool isNullPtrType() const
Definition: Type.h:6184
CanQualType ShortTy
Definition: ASTContext.h:1004
CanQualType SignedCharTy
Definition: ASTContext.h:1004
bool isVoidPointerType() const
Definition: Type.cpp:426
bool isConstQualified() const
Determine whether this type is const-qualified.
Definition: Type.h:5779
QualType getWideCharType() const
Return the type of wide characters.
Definition: ASTContext.h:1516
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of enums...
Definition: Type.h:4004
virtual void HandleInvalidPosition(const char *startPos, unsigned posLen, PositionContext p)
Definition: FormatString.h:633
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 getWIntType() const
In C99, this returns a type compatible with the type defined in <stddef.h> as defined by the target...
Definition: ASTContext.h:1530
bool isObjCObjectPointerType() const
Definition: Type.h:6041
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:1005
Base class for declarations which introduce a typedef-name.
Definition: Decl.h:2796
CanQualType CharTy
Definition: ASTContext.h:998
CanQualType ObjCBuiltinIdTy
Definition: ASTContext.h:1016
Dataflow Directional Tag Classes.
QualType getUnderlyingType() const
Definition: Decl.h:2847
CanQualType UnsignedLongLongTy
Definition: ASTContext.h:1006
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:5442
Pointer to a block type.
Definition: Type.h:2387
CanQualType UnsignedLongTy
Definition: ASTContext.h:1005
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:2174
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:1830
bool isVoidType() const
Definition: Type.h:6171
virtual void HandleIncompleteSpecifier(const char *startSpecifier, unsigned specifierLen)
Definition: FormatString.h:638
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:61
This class is used for builtin types like &#39;int&#39;.
Definition: Type.h:2145
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:915
CanQualType IntTy
Definition: ASTContext.h:1004
bool isPointerType() const
Definition: Type.h:5944
Optional< ConversionSpecifier > getStandardSpecifier() const
CanQualType UnsignedIntTy
Definition: ASTContext.h:1005
OptionalAmount ParsePositionAmount(FormatStringHandler &H, const char *Start, const char *&Beg, const char *E, PositionContext p)