clang 19.0.0git
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"
17#include "llvm/Support/ConvertUTF.h"
18#include <optional>
19
26using namespace clang;
27
28// Key function to FormatStringHandler.
30
31//===----------------------------------------------------------------------===//
32// Functions for parsing format strings components in both printf and
33// scanf format strings.
34//===----------------------------------------------------------------------===//
35
37clang::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,
80 if (*Beg == '*') {
81 const char *I = Beg + 1;
82 const OptionalAmount &Amt = ParseAmount(I, E);
83
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
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
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
121bool
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
143bool
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);
170 FS.setUsesPositionalArg();
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
180bool
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
210bool
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;
229 } else {
231 }
232 break;
233 case 'l':
234 ++I;
235 if (I != E && *I == 'l') {
236 ++I;
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 == '[')) {
255 break;
256 }
257 --I;
258 }
259 return false;
260 case 'm':
261 if (IsScanf) {
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;
274 break;
275 }
276 if (IsScanf)
277 return false;
278
279 if (I[1] == '3' && I[2] == '2') {
280 I += 3;
282 break;
283 }
284 }
285 ++I;
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
325 // When using the format attribute in C++, you can receive a function or an
326 // array that will necessarily decay to a pointer when passed to the final
327 // format consumer. Apply decay before type comparison.
328 if (argTy->canDecayToPointerType())
329 argTy = C.getDecayedType(argTy);
330
331 if (Ptr) {
332 // It has to be a pointer.
333 const PointerType *PT = argTy->getAs<PointerType>();
334 if (!PT)
335 return NoMatch;
336
337 // We cannot write through a const qualified pointer.
339 return NoMatch;
340
341 argTy = PT->getPointeeType();
342 }
343
344 switch (K) {
345 case InvalidTy:
346 llvm_unreachable("ArgType must be valid");
347
348 case UnknownTy:
349 return Match;
350
351 case AnyCharTy: {
352 if (const auto *ETy = argTy->getAs<EnumType>()) {
353 // If the enum is incomplete we know nothing about the underlying type.
354 // Assume that it's 'int'. Do not use the underlying type for a scoped
355 // enumeration.
356 if (!ETy->getDecl()->isComplete())
357 return NoMatch;
358 if (ETy->isUnscopedEnumerationType())
359 argTy = ETy->getDecl()->getIntegerType();
360 }
361
362 if (const auto *BT = argTy->getAs<BuiltinType>()) {
363 // The types are perfectly matched?
364 switch (BT->getKind()) {
365 default:
366 break;
367 case BuiltinType::Char_S:
368 case BuiltinType::SChar:
369 case BuiltinType::UChar:
370 case BuiltinType::Char_U:
371 return Match;
372 case BuiltinType::Bool:
373 if (!Ptr)
374 return Match;
375 break;
376 }
377 // "Partially matched" because of promotions?
378 if (!Ptr) {
379 switch (BT->getKind()) {
380 default:
381 break;
382 case BuiltinType::Int:
383 case BuiltinType::UInt:
384 return MatchPromotion;
385 case BuiltinType::Short:
386 case BuiltinType::UShort:
387 case BuiltinType::WChar_S:
388 case BuiltinType::WChar_U:
390 }
391 }
392 }
393 return NoMatch;
394 }
395
396 case SpecificTy: {
397 if (const EnumType *ETy = argTy->getAs<EnumType>()) {
398 // If the enum is incomplete we know nothing about the underlying type.
399 // Assume that it's 'int'. Do not use the underlying type for a scoped
400 // enumeration as that needs an exact match.
401 if (!ETy->getDecl()->isComplete())
402 argTy = C.IntTy;
403 else if (ETy->isUnscopedEnumerationType())
404 argTy = ETy->getDecl()->getIntegerType();
405 }
406
407 if (argTy->isSaturatedFixedPointType())
408 argTy = C.getCorrespondingUnsaturatedType(argTy);
409
410 argTy = C.getCanonicalType(argTy).getUnqualifiedType();
411
412 if (T == argTy)
413 return Match;
414 if (const auto *BT = argTy->getAs<BuiltinType>()) {
415 // Check if the only difference between them is signed vs unsigned
416 // if true, we consider they are compatible.
417 switch (BT->getKind()) {
418 default:
419 break;
420 case BuiltinType::Bool:
421 if (Ptr && (T == C.UnsignedCharTy || T == C.SignedCharTy))
422 return NoMatch;
423 [[fallthrough]];
424 case BuiltinType::Char_S:
425 case BuiltinType::SChar:
426 case BuiltinType::Char_U:
427 case BuiltinType::UChar:
428 if (T == C.UnsignedShortTy || T == C.ShortTy)
430 if (T == C.UnsignedCharTy || T == C.SignedCharTy)
431 return Match;
432 break;
433 case BuiltinType::Short:
434 if (T == C.UnsignedShortTy)
435 return Match;
436 break;
437 case BuiltinType::UShort:
438 if (T == C.ShortTy)
439 return Match;
440 break;
441 case BuiltinType::Int:
442 if (T == C.UnsignedIntTy)
443 return Match;
444 break;
445 case BuiltinType::UInt:
446 if (T == C.IntTy)
447 return Match;
448 break;
449 case BuiltinType::Long:
450 if (T == C.UnsignedLongTy)
451 return Match;
452 break;
453 case BuiltinType::ULong:
454 if (T == C.LongTy)
455 return Match;
456 break;
457 case BuiltinType::LongLong:
458 if (T == C.UnsignedLongLongTy)
459 return Match;
460 break;
461 case BuiltinType::ULongLong:
462 if (T == C.LongLongTy)
463 return Match;
464 break;
465 }
466 // "Partially matched" because of promotions?
467 if (!Ptr) {
468 switch (BT->getKind()) {
469 default:
470 break;
471 case BuiltinType::Bool:
472 if (T == C.IntTy || T == C.UnsignedIntTy)
473 return MatchPromotion;
474 break;
475 case BuiltinType::Int:
476 case BuiltinType::UInt:
477 if (T == C.SignedCharTy || T == C.UnsignedCharTy ||
478 T == C.ShortTy || T == C.UnsignedShortTy || T == C.WCharTy ||
479 T == C.WideCharTy)
480 return MatchPromotion;
481 break;
482 case BuiltinType::Char_U:
483 if (T == C.UnsignedIntTy)
484 return MatchPromotion;
485 if (T == C.UnsignedShortTy)
487 break;
488 case BuiltinType::Char_S:
489 if (T == C.IntTy)
490 return MatchPromotion;
491 if (T == C.ShortTy)
493 break;
494 case BuiltinType::Half:
495 case BuiltinType::Float:
496 if (T == C.DoubleTy)
497 return MatchPromotion;
498 break;
499 case BuiltinType::Short:
500 case BuiltinType::UShort:
501 if (T == C.SignedCharTy || T == C.UnsignedCharTy)
503 break;
504 case BuiltinType::WChar_U:
505 case BuiltinType::WChar_S:
506 if (T != C.WCharTy && T != C.WideCharTy)
508 }
509 }
510 }
511 return NoMatch;
512 }
513
514 case CStrTy: {
515 const PointerType *PT = argTy->getAs<PointerType>();
516 if (!PT)
517 return NoMatch;
518 QualType pointeeTy = PT->getPointeeType();
519 if (const BuiltinType *BT = pointeeTy->getAs<BuiltinType>())
520 switch (BT->getKind()) {
521 case BuiltinType::Char_U:
522 case BuiltinType::UChar:
523 case BuiltinType::Char_S:
524 case BuiltinType::SChar:
525 return Match;
526 default:
527 break;
528 }
529
530 return NoMatch;
531 }
532
533 case WCStrTy: {
534 const PointerType *PT = argTy->getAs<PointerType>();
535 if (!PT)
536 return NoMatch;
537 QualType pointeeTy =
538 C.getCanonicalType(PT->getPointeeType()).getUnqualifiedType();
539 return pointeeTy == C.getWideCharType() ? Match : NoMatch;
540 }
541
542 case WIntTy: {
543 QualType WInt = C.getCanonicalType(C.getWIntType()).getUnqualifiedType();
544
545 if (C.getCanonicalType(argTy).getUnqualifiedType() == WInt)
546 return Match;
547
548 QualType PromoArg = C.isPromotableIntegerType(argTy)
549 ? C.getPromotedIntegerType(argTy)
550 : argTy;
551 PromoArg = C.getCanonicalType(PromoArg).getUnqualifiedType();
552
553 // If the promoted argument is the corresponding signed type of the
554 // wint_t type, then it should match.
555 if (PromoArg->hasSignedIntegerRepresentation() &&
556 C.getCorrespondingUnsignedType(PromoArg) == WInt)
557 return Match;
558
559 return WInt == PromoArg ? Match : NoMatch;
560 }
561
562 case CPointerTy:
563 if (argTy->isVoidPointerType()) {
564 return Match;
565 } if (argTy->isPointerType() || argTy->isObjCObjectPointerType() ||
566 argTy->isBlockPointerType() || argTy->isNullPtrType()) {
567 return NoMatchPedantic;
568 } else {
569 return NoMatch;
570 }
571
572 case ObjCPointerTy: {
573 if (argTy->getAs<ObjCObjectPointerType>() ||
574 argTy->getAs<BlockPointerType>())
575 return Match;
576
577 // Handle implicit toll-free bridging.
578 if (const PointerType *PT = argTy->getAs<PointerType>()) {
579 // Things such as CFTypeRef are really just opaque pointers
580 // to C structs representing CF types that can often be bridged
581 // to Objective-C objects. Since the compiler doesn't know which
582 // structs can be toll-free bridged, we just accept them all.
583 QualType pointee = PT->getPointeeType();
584 if (pointee->getAsStructureType() || pointee->isVoidType())
585 return Match;
586 }
587 return NoMatch;
588 }
589 }
590
591 llvm_unreachable("Invalid ArgType Kind!");
592}
593
594ArgType ArgType::makeVectorType(ASTContext &C, unsigned NumElts) const {
595 // Check for valid vector element types.
596 if (T.isNull())
597 return ArgType::Invalid();
598
599 QualType Vec = C.getExtVectorType(T, NumElts);
600 return ArgType(Vec, Name);
601}
602
604 QualType Res;
605 switch (K) {
606 case InvalidTy:
607 llvm_unreachable("No representative type for Invalid ArgType");
608 case UnknownTy:
609 llvm_unreachable("No representative type for Unknown ArgType");
610 case AnyCharTy:
611 Res = C.CharTy;
612 break;
613 case SpecificTy:
614 Res = T;
615 break;
616 case CStrTy:
617 Res = C.getPointerType(C.CharTy);
618 break;
619 case WCStrTy:
620 Res = C.getPointerType(C.getWideCharType());
621 break;
622 case ObjCPointerTy:
623 Res = C.ObjCBuiltinIdTy;
624 break;
625 case CPointerTy:
626 Res = C.VoidPtrTy;
627 break;
628 case WIntTy: {
629 Res = C.getWIntType();
630 break;
631 }
632 }
633
634 if (Ptr)
635 Res = C.getPointerType(Res);
636 return Res;
637}
638
640 std::string S = getRepresentativeType(C).getAsString(C.getPrintingPolicy());
641
642 std::string Alias;
643 if (Name) {
644 // Use a specific name for this type, e.g. "size_t".
645 Alias = Name;
646 if (Ptr) {
647 // If ArgType is actually a pointer to T, append an asterisk.
648 Alias += (Alias[Alias.size()-1] == '*') ? "*" : " *";
649 }
650 // If Alias is the same as the underlying type, e.g. wchar_t, then drop it.
651 if (S == Alias)
652 Alias.clear();
653 }
654
655 if (!Alias.empty())
656 return std::string("'") + Alias + "' (aka '" + S + "')";
657 return std::string("'") + S + "'";
658}
659
660
661//===----------------------------------------------------------------------===//
662// Methods on OptionalAmount.
663//===----------------------------------------------------------------------===//
664
667 return Ctx.IntTy;
668}
669
670//===----------------------------------------------------------------------===//
671// Methods on LengthModifier.
672//===----------------------------------------------------------------------===//
673
674const char *
676 switch (kind) {
677 case AsChar:
678 return "hh";
679 case AsShort:
680 return "h";
681 case AsShortLong:
682 return "hl";
683 case AsLong: // or AsWideChar
684 return "l";
685 case AsLongLong:
686 return "ll";
687 case AsQuad:
688 return "q";
689 case AsIntMax:
690 return "j";
691 case AsSizeT:
692 return "z";
693 case AsPtrDiff:
694 return "t";
695 case AsInt32:
696 return "I32";
697 case AsInt3264:
698 return "I";
699 case AsInt64:
700 return "I64";
701 case AsLongDouble:
702 return "L";
703 case AsAllocate:
704 return "a";
705 case AsMAllocate:
706 return "m";
707 case AsWide:
708 return "w";
709 case None:
710 return "";
711 }
712 return nullptr;
713}
714
715//===----------------------------------------------------------------------===//
716// Methods on ConversionSpecifier.
717//===----------------------------------------------------------------------===//
718
719const char *ConversionSpecifier::toString() const {
720 switch (kind) {
721 case bArg: return "b";
722 case BArg: return "B";
723 case dArg: return "d";
724 case DArg: return "D";
725 case iArg: return "i";
726 case oArg: return "o";
727 case OArg: return "O";
728 case uArg: return "u";
729 case UArg: return "U";
730 case xArg: return "x";
731 case XArg: return "X";
732 case fArg: return "f";
733 case FArg: return "F";
734 case eArg: return "e";
735 case EArg: return "E";
736 case gArg: return "g";
737 case GArg: return "G";
738 case aArg: return "a";
739 case AArg: return "A";
740 case cArg: return "c";
741 case sArg: return "s";
742 case pArg: return "p";
743 case PArg:
744 return "P";
745 case nArg: return "n";
746 case PercentArg: return "%";
747 case ScanListArg: return "[";
748 case InvalidSpecifier: return nullptr;
749
750 // POSIX unicode extensions.
751 case CArg: return "C";
752 case SArg: return "S";
753
754 // Objective-C specific specifiers.
755 case ObjCObjArg: return "@";
756
757 // FreeBSD kernel specific specifiers.
758 case FreeBSDbArg: return "b";
759 case FreeBSDDArg: return "D";
760 case FreeBSDrArg: return "r";
761 case FreeBSDyArg: return "y";
762
763 // GlibC specific specifiers.
764 case PrintErrno: return "m";
765
766 // MS specific specifiers.
767 case ZArg: return "Z";
768
769 // ISO/IEC TR 18037 (fixed-point) specific specifiers.
770 case rArg:
771 return "r";
772 case RArg:
773 return "R";
774 case kArg:
775 return "k";
776 case KArg:
777 return "K";
778 }
779 return nullptr;
780}
781
782std::optional<ConversionSpecifier>
785
786 switch (getKind()) {
787 default:
788 return std::nullopt;
789 case DArg:
790 NewKind = dArg;
791 break;
792 case UArg:
793 NewKind = uArg;
794 break;
795 case OArg:
796 NewKind = oArg;
797 break;
798 }
799
800 ConversionSpecifier FixedCS(*this);
801 FixedCS.setKind(NewKind);
802 return FixedCS;
803}
804
805//===----------------------------------------------------------------------===//
806// Methods on OptionalAmount.
807//===----------------------------------------------------------------------===//
808
809void OptionalAmount::toString(raw_ostream &os) const {
810 switch (hs) {
811 case Invalid:
812 case NotSpecified:
813 return;
814 case Arg:
815 if (UsesDotPrefix)
816 os << ".";
817 if (usesPositionalArg())
818 os << "*" << getPositionalArgIndex() << "$";
819 else
820 os << "*";
821 break;
822 case Constant:
823 if (UsesDotPrefix)
824 os << ".";
825 os << amt;
826 break;
827 }
828}
829
831 const LangOptions &LO) const {
832 switch (LM.getKind()) {
834 return true;
835
836 // Handle most integer flags
838 // Length modifier only applies to FP vectors.
839 if (LO.OpenCL && CS.isDoubleArg())
840 return !VectorNumElts.isInvalid();
841
842 if (CS.isFixedPointArg())
843 return true;
844
845 if (Target.getTriple().isOSMSVCRT()) {
846 switch (CS.getKind()) {
852 return true;
853 default:
854 break;
855 }
856 }
857 [[fallthrough]];
864 switch (CS.getKind()) {
877 return true;
880 return Target.getTriple().isOSFreeBSD() || Target.getTriple().isPS();
881 default:
882 return false;
883 }
884
886 return LO.OpenCL && !VectorNumElts.isInvalid();
887
888 // Handle 'l' flag
889 case LengthModifier::AsLong: // or AsWideChar
890 if (CS.isDoubleArg()) {
891 // Invalid for OpenCL FP scalars.
892 if (LO.OpenCL && VectorNumElts.isInvalid())
893 return false;
894 return true;
895 }
896
897 if (CS.isFixedPointArg())
898 return true;
899
900 switch (CS.getKind()) {
917 return true;
920 return Target.getTriple().isOSFreeBSD() || Target.getTriple().isPS();
921 default:
922 return false;
923 }
924
926 switch (CS.getKind()) {
935 return true;
936 // GNU libc extension.
943 return !Target.getTriple().isOSDarwin() &&
944 !Target.getTriple().isOSWindows();
945 default:
946 return false;
947 }
948
950 switch (CS.getKind()) {
954 return true;
955 default:
956 return false;
957 }
958
960 switch (CS.getKind()) {
966 return true;
967 default:
968 return false;
969 }
973 switch (CS.getKind()) {
980 return Target.getTriple().isOSMSVCRT();
981 default:
982 return false;
983 }
985 switch (CS.getKind()) {
991 return Target.getTriple().isOSMSVCRT();
992 default:
993 return false;
994 }
995 }
996 llvm_unreachable("Invalid LengthModifier Kind!");
997}
998
1000 switch (LM.getKind()) {
1010 return true;
1018 case LengthModifier::AsShortLong: // ???
1019 return false;
1020 }
1021 llvm_unreachable("Invalid LengthModifier Kind!");
1022}
1023
1025 const LangOptions &LangOpt) const {
1026 switch (CS.getKind()) {
1051 return true;
1054 return LangOpt.ObjC;
1065 return false;
1070 return LangOpt.FixedPoint;
1071 }
1072 llvm_unreachable("Invalid ConversionSpecifier Kind!");
1073}
1074
1077 switch(CS.getKind()) {
1084 return false;
1085 default:
1086 return true;
1087 }
1088 }
1089 return true;
1090}
1091
1092std::optional<LengthModifier>
1097 LengthModifier FixedLM(LM);
1099 return FixedLM;
1100 }
1101 }
1102
1103 return std::nullopt;
1104}
1105
1107 LengthModifier &LM) {
1108 for (/**/; const auto *TT = QT->getAs<TypedefType>();
1109 QT = TT->getDecl()->getUnderlyingType()) {
1110 const TypedefNameDecl *Typedef = TT->getDecl();
1111 const IdentifierInfo *Identifier = Typedef->getIdentifier();
1112 if (Identifier->getName() == "size_t") {
1114 return true;
1115 } else if (Identifier->getName() == "ssize_t") {
1116 // Not C99, but common in Unix.
1118 return true;
1119 } else if (Identifier->getName() == "intmax_t") {
1121 return true;
1122 } else if (Identifier->getName() == "uintmax_t") {
1124 return true;
1125 } else if (Identifier->getName() == "ptrdiff_t") {
1127 return true;
1128 }
1129 }
1130 return false;
1131}
StringRef Identifier
Definition: Format.cpp:2977
Defines the clang::LangOptions interface.
llvm::MachO::Target Target
Definition: MachO.h:44
__device__ __2f16 float c
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:182
CanQualType IntTy
Definition: ASTContext.h:1097
Pointer to a block type.
Definition: Type.h:3138
This class is used for builtin types like 'int'.
Definition: Type.h:2770
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of enums.
Definition: Type.h:5335
One of these records is kept for each identifier that is lexed.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:449
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
Definition: Decl.h:270
Represents a pointer to an Objective C object.
Definition: Type.h:6768
PointerType - C99 6.7.5.1 - Pointer Declarators.
Definition: Type.h:2928
QualType getPointeeType() const
Definition: Type.h:2938
A (possibly-)qualified type.
Definition: Type.h:738
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Definition: Type.h:805
bool isConstQualified() const
Determine whether this type is const-qualified.
Definition: Type.h:7191
static std::string getAsString(SplitQualType split, const PrintingPolicy &Policy)
Definition: Type.h:1125
Exposes information about the current target.
Definition: TargetInfo.h:213
bool isBlockPointerType() const
Definition: Type.h:7379
bool isVoidType() const
Definition: Type.h:7660
bool canDecayToPointerType() const
Determines whether this type can decay to a pointer type.
Definition: Type.h:7815
bool isVoidPointerType() const
Definition: Type.cpp:654
bool isPointerType() const
Definition: Type.h:7371
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
Definition: Type.cpp:694
bool isSaturatedFixedPointType() const
Return true if this is a saturated fixed point type according to ISO/IEC JTC1 SC22 WG14 N1169.
Definition: Type.h:7729
bool hasSignedIntegerRepresentation() const
Determine whether this type has an signed integer representation of some sort, e.g....
Definition: Type.cpp:2166
const RecordType * getAsStructureType() const
Definition: Type.cpp:710
bool isObjCObjectPointerType() const
Definition: Type.h:7499
const T * getAs() const
Member-template getAs<specific type>'.
Definition: Type.h:7878
bool isNullPtrType() const
Definition: Type.h:7693
Base class for declarations which introduce a typedef-name.
Definition: Decl.h:3399
MatchKind
How well a given conversion specifier matches its argument.
Definition: FormatString.h:271
@ NoMatch
The conversion specifier and the argument types are incompatible.
Definition: FormatString.h:274
@ NoMatchPedantic
The conversion specifier and the argument type are disallowed by the C standard, but are in practice ...
Definition: FormatString.h:286
@ Match
The conversion specifier and the argument type are compatible.
Definition: FormatString.h:277
@ MatchPromotion
The conversion specifier and the argument type are compatible because of default argument promotions.
Definition: FormatString.h:280
@ NoMatchTypeConfusion
The conversion specifier and the argument type are compatible, but still seems likely to be an error.
Definition: FormatString.h:289
@ NoMatchPromotionTypeConfusion
The conversion specifier and the argument type are compatible but still seems likely to be an error.
Definition: FormatString.h:283
ArgType makeVectorType(ASTContext &C, unsigned NumElts) const
QualType getRepresentativeType(ASTContext &C) const
std::string getRepresentativeTypeName(ASTContext &C) const
MatchKind matchesType(ASTContext &C, QualType argTy) const
std::optional< ConversionSpecifier > getStandardSpecifier() const
void setFieldWidth(const OptionalAmount &Amt)
Definition: FormatString.h:470
bool hasStandardConversionSpecifier(const LangOptions &LangOpt) const
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 hasValidLengthModifier(const TargetInfo &Target, const LangOptions &LO) const
std::optional< LengthModifier > getCorrectedLengthModifier() const
virtual void HandlePosition(const char *startPos, unsigned posLen)
Definition: FormatString.h:721
virtual void HandleInvalidPosition(const char *startPos, unsigned posLen, PositionContext p)
Definition: FormatString.h:723
virtual void HandleZeroPosition(const char *startPos, unsigned posLen)
Definition: FormatString.h:726
virtual void HandleIncompleteSpecifier(const char *startSpecifier, unsigned specifierLen)
Definition: FormatString.h:728
Represents the length modifier in a format string in scanf/printf.
Definition: FormatString.h:65
ArgType getArgType(ASTContext &Ctx) const
Defines the clang::TargetInfo interface.
bool ParseFieldWidth(FormatStringHandler &H, FormatSpecifier &CS, const char *Start, const char *&Beg, const char *E, unsigned *argIndex)
OptionalAmount ParsePositionAmount(FormatStringHandler &H, const char *Start, const char *&Beg, const char *E, PositionContext p)
OptionalAmount ParseAmount(const char *&Beg, const char *E)
OptionalAmount ParseNonPositionAmount(const char *&Beg, const char *E, unsigned &argIndex)
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 ParseArgPosition(FormatStringHandler &H, FormatSpecifier &CS, const char *Start, const char *&Beg, const char *E)
bool ParseVectorModifier(FormatStringHandler &H, FormatSpecifier &FS, const char *&Beg, const char *E, const LangOptions &LO)
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...
The JSON file list parser is used to communicate input to InstallAPI.
@ None
The alignment was not explicit in code.