17#include "llvm/ADT/StringExtras.h"
18#include "llvm/Support/ConvertUTF.h"
39 const char *E)
const {
43 unsigned accumulator = 0;
44 bool hasDigits =
false;
48 if (c >=
'0' && c <=
'9') {
50 accumulator = (accumulator * 10) + (c -
'0');
64bool FormatStringParser::parseWidthModifier(
const char *&I,
const char *E,
66 unsigned &ModifierLength)
const {
67 StringRef W = StringRef(I, E - I).take_while(llvm::isDigit);
68 if (W.empty() || W.front() ==
'0')
71 if (W.getAsInteger(10, BitWidth))
75 ModifierLength += W.size();
82 unsigned &argIndex)
const {
96 const char *I = Beg + 1;
100 H.HandleInvalidPosition(Beg, I - Beg, p);
106 H.HandleIncompleteSpecifier(Start, E - Start);
117 H.HandleZeroPosition(Beg, I - Beg + 1);
121 const char *Tmp = Beg;
128 H.HandleInvalidPosition(Beg, I - Beg, p);
136 const char *&Beg,
const char *E,
137 unsigned *argIndex)
const {
153 const char *Start,
const char *&Beg,
154 const char *E)
const {
161 H.HandleIncompleteSpecifier(Start, E - Start);
167 H.HandlePosition(Start, I - Start);
171 H.HandleZeroPosition(Start, I - Start);
188 const char *E)
const {
192 const char *Start = I;
197 H.HandleIncompleteSpecifier(Start, E - Start);
203 H.HandleIncompleteSpecifier(Start, E - Start);
215 const char *E)
const {
217 const char *lmPosition = I;
223 if (I != E && *I ==
'h') {
226 }
else if (I != E && *I ==
'l' &&
LO.OpenCL) {
235 if (I != E && *I ==
'l') {
268 if (I != E && (*I ==
's' || *I ==
'S' || *I ==
'[')) {
285 if (I + 1 != E && I + 2 != E) {
286 if (I[1] ==
'6' && I[2] ==
'4') {
294 if (I[1] ==
'3' && I[2] ==
'2') {
313 if (I != E && *I ==
'D') {
324 const char *WidthModifier = I + 1;
325 unsigned BitWidth = 0;
326 unsigned ModifierLength = 1;
329 if (WidthModifier != E && *WidthModifier ==
'f') {
330 WidthModifier = I + 2;
335 if (parseWidthModifier(WidthModifier, E, BitWidth, ModifierLength)) {
352 const char *FmtStrEnd,
353 unsigned &Len)
const {
354 if (SpecifierBegin + 1 >= FmtStrEnd)
357 const llvm::UTF8 *SB =
358 reinterpret_cast<const llvm::UTF8 *
>(SpecifierBegin + 1);
359 const llvm::UTF8 *SE =
reinterpret_cast<const llvm::UTF8 *
>(FmtStrEnd);
360 const char FirstByte = *SB;
365 unsigned NumBytes = llvm::getNumBytesForUTF8(FirstByte);
368 if (SB + NumBytes > SE)
384 const auto *TD = TT->getDecl();
385 const auto *DC = TT->getDecl()->getDeclContext();
386 if (DC->isTranslationUnit() || DC->isStdNamespace()) {
387 StringRef Name = TD->getIdentifier()->getName();
388 if (Name ==
"size_t") {
391 }
else if (Name ==
"ssize_t" ) {
394 }
else if (Name ==
"ptrdiff_t") {
397 }
else if (Name ==
"intmax_t") {
400 }
else if (Name ==
"uintmax_t") {
408 switch (PST->getKind()) {
410 case Kind::SignedSizeT:
417 llvm_unreachable(
"unexpected kind");
430 if (!
T->isIntegerType() ||
T->isBooleanType())
431 return MatchKind::NoMatch;
433 if (
C.hasSameType(
T, E))
434 return MatchKind::Match;
436 if (
C.getCorrespondingSignedType(
T.getCanonicalType()) !=
438 return MatchKind::NoMatch;
440 return MatchKind::NoMatchSignedness;
449 argTy =
C.getDecayedType(argTy);
464 if (
const auto *OBT = argTy->
getAs<OverflowBehaviorType>())
465 argTy = OBT->getUnderlyingType();
469 llvm_unreachable(
"ArgType must be valid");
482 if (!ED->isComplete())
485 argTy = ED->getIntegerType();
490 switch (BT->getKind()) {
493 case BuiltinType::Char_S:
494 case BuiltinType::SChar:
495 case BuiltinType::UChar:
496 case BuiltinType::Char_U:
498 case BuiltinType::Bool:
505 switch (BT->getKind()) {
508 case BuiltinType::Int:
509 case BuiltinType::UInt:
511 case BuiltinType::Short:
512 case BuiltinType::UShort:
513 case BuiltinType::WChar_S:
514 case BuiltinType::WChar_U:
523 if (TK == TypeKind::SizeT || TK == TypeKind::PtrdiffT) {
531 if (!ED->isComplete())
533 else if (!ED->isScoped())
534 argTy = ED->getIntegerType();
538 argTy =
C.getCorrespondingUnsaturatedType(argTy);
540 argTy =
C.getCanonicalType(argTy).getUnqualifiedType();
547 switch (BT->getKind()) {
550 case BuiltinType::Bool:
551 if (Ptr && (T ==
C.UnsignedCharTy || T ==
C.SignedCharTy))
554 case BuiltinType::Char_S:
555 case BuiltinType::SChar:
556 if (T ==
C.UnsignedShortTy || T ==
C.ShortTy)
558 if (T ==
C.UnsignedCharTy)
560 if (T ==
C.SignedCharTy)
563 case BuiltinType::Char_U:
564 case BuiltinType::UChar:
565 if (T ==
C.UnsignedShortTy || T ==
C.ShortTy)
567 if (T ==
C.UnsignedCharTy)
569 if (T ==
C.SignedCharTy)
572 case BuiltinType::Short:
573 if (T ==
C.UnsignedShortTy)
576 case BuiltinType::UShort:
580 case BuiltinType::Int:
581 if (T ==
C.UnsignedIntTy)
584 case BuiltinType::UInt:
588 case BuiltinType::Long:
589 if (T ==
C.UnsignedLongTy)
592 case BuiltinType::ULong:
596 case BuiltinType::LongLong:
597 if (T ==
C.UnsignedLongLongTy)
600 case BuiltinType::ULongLong:
601 if (T ==
C.LongLongTy)
607 switch (BT->getKind()) {
610 case BuiltinType::Bool:
611 if (T ==
C.IntTy || T ==
C.UnsignedIntTy)
614 case BuiltinType::Int:
615 case BuiltinType::UInt:
616 if (T ==
C.SignedCharTy || T ==
C.UnsignedCharTy || T ==
C.ShortTy ||
617 T ==
C.UnsignedShortTy || T ==
C.WCharTy || T ==
C.WideCharTy)
620 case BuiltinType::Char_U:
621 if (T ==
C.UnsignedIntTy)
623 if (T ==
C.UnsignedShortTy)
626 case BuiltinType::Char_S:
632 case BuiltinType::Half:
633 case BuiltinType::Float:
637 case BuiltinType::Short:
638 case BuiltinType::UShort:
639 if (T ==
C.SignedCharTy || T ==
C.UnsignedCharTy)
642 case BuiltinType::WChar_U:
643 case BuiltinType::WChar_S:
644 if (T !=
C.WCharTy && T !=
C.WideCharTy)
661 C.hasSameUnqualifiedType(PT->getPointeeType(),
C.getWideCharType()))
666 QualType WInt =
C.getCanonicalType(
C.getWIntType()).getUnqualifiedType();
668 if (
C.getCanonicalType(argTy).getUnqualifiedType() == WInt)
671 QualType PromoArg =
C.isPromotableIntegerType(argTy)
672 ?
C.getPromotedIntegerType(argTy)
674 PromoArg =
C.getCanonicalType(PromoArg).getUnqualifiedType();
679 C.getCorrespondingUnsignedType(PromoArg) == WInt)
724 llvm_unreachable(
"Invalid ArgType Kind!");
734 if (std::max(ASize, IntSize) != std::max(BSize, IntSize))
737 return MK::NoMatchSignedness;
739 return MK::MatchPromotion;
748 if (K == AK::InvalidTy ||
Other.K == AK::InvalidTy)
750 if (K == AK::UnsupportedTy ||
Other.K == AK::UnsupportedTy)
752 if (K == AK::UnknownTy ||
Other.K == AK::UnknownTy)
759 bool LeftWasPointer =
false;
761 bool RightWasPointer =
false;
764 LeftWasPointer =
true;
765 }
else if (Left.K == AK::SpecificTy && Left.T->isPointerType()) {
766 Left.T = Left.T->getPointeeType();
767 LeftWasPointer =
true;
771 RightWasPointer =
true;
772 }
else if (Right.K == AK::SpecificTy && Right.T->isPointerType()) {
773 Right.T = Right.T->getPointeeType();
774 RightWasPointer =
true;
777 if (LeftWasPointer != RightWasPointer)
782 if (Right.K == AK::SpecificTy)
783 std::swap(Left, Right);
785 if (Left.K == AK::SpecificTy) {
786 if (Right.K == AK::SpecificTy) {
787 if (Left.TK != TypeKind::DontCare) {
789 }
else if (Right.TK != TypeKind::DontCare) {
793 auto Canon1 =
C.getCanonicalType(Left.T);
794 auto Canon2 =
C.getCanonicalType(Right.T);
795 if (Canon1 == Canon2)
800 if (BT1 ==
nullptr || BT2 ==
nullptr)
805 if (!LeftWasPointer && BT1->isInteger() && BT2->
isInteger())
808 }
else if (Right.K == AK::AnyCharTy) {
809 if (!LeftWasPointer && Left.T->isIntegerType())
812 }
else if (Right.K == AK::WIntTy) {
813 if (!LeftWasPointer && Left.T->isIntegerType())
831 QualType Vec =
C.getExtVectorType(T, NumElts);
845 Res.TK = IsFast ? (
Signed ? TypeKind::FastIntN : TypeKind::FastUIntN)
846 : (
Signed ? TypeKind::IntN : TypeKind::UIntN);
855 llvm_unreachable(
"No representative type for Invalid ArgType");
857 llvm_unreachable(
"No representative type for Unknown ArgType");
859 llvm_unreachable(
"No representative type for Unsupported ArgType");
864 if (TK == TypeKind::PtrdiffT || TK == TypeKind::SizeT)
871 Res =
C.getPointerType(
C.CharTy);
874 Res =
C.getPointerType(
C.getWideCharType());
877 Res =
C.ObjCBuiltinIdTy;
883 Res =
C.getWIntType();
889 Res =
C.getPointerType(Res);
903 const char *Prefix =
nullptr;
908 case TypeKind::UIntN:
911 case TypeKind::FastIntN:
914 case TypeKind::FastUIntN:
915 Prefix =
"uint_fast";
917 case TypeKind::DontCare:
918 case TypeKind::SizeT:
919 case TypeKind::PtrdiffT:
924 Alias += std::to_string(BitWidth);
928 if (!Alias.empty()) {
931 Alias += (Alias[Alias.size() - 1] ==
'*') ?
"*" :
" *";
939 return std::string(
"'") + S +
"'";
941 return std::string(
"'") + Alias +
"'" +
1004 llvm_unreachable(
"Invalid LengthModifier Kind!");
1109std::optional<ConversionSpecifier>
1115 return std::nullopt;
1159 switch (
LM.getKind()) {
1166 if (LO.OpenCL &&
CS.isDoubleArg())
1169 if (
CS.isFixedPointArg())
1172 if (
Target.getTriple().isOSMSVCRT()) {
1173 switch (
CS.getKind()) {
1191 switch (
CS.getKind()) {
1207 return Target.getTriple().isOSFreeBSD() ||
Target.getTriple().isPS();
1217 if (
CS.isDoubleArg()) {
1224 if (
CS.isFixedPointArg())
1227 switch (
CS.getKind()) {
1247 return Target.getTriple().isOSFreeBSD() ||
Target.getTriple().isPS();
1253 switch (
CS.getKind()) {
1270 return !
Target.getTriple().isOSDarwin() &&
1271 !
Target.getTriple().isOSWindows();
1283 ?
Target.getIntTypeByWidth(
LM.getBitWidth(),
true)
1284 :
Target.getLeastIntTypeByWidth(
LM.getBitWidth(),
1289 switch (
CS.getKind()) {
1306 switch (
CS.getKind()) {
1316 switch (
CS.getKind()) {
1329 switch (
CS.getKind()) {
1336 return Target.getTriple().isOSMSVCRT();
1341 switch (
CS.getKind()) {
1347 return Target.getTriple().isOSMSVCRT();
1355 switch (
CS.getKind()) {
1369 llvm_unreachable(
"Invalid LengthModifier Kind!");
1373 switch (
LM.getKind()) {
1399 llvm_unreachable(
"Invalid LengthModifier Kind!");
1404 switch (
CS.getKind()) {
1432 return LangOpt.ObjC;
1448 return LangOpt.FixedPoint;
1450 llvm_unreachable(
"Invalid ConversionSpecifier Kind!");
1455 switch (
CS.getKind()) {
1470std::optional<LengthModifier>
1481 return std::nullopt;
Defines the clang::LangOptions interface.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
const LangOptions & getLangOpts() const
QualType getIntTypeForBitwidth(unsigned DestWidth, unsigned Signed) const
getIntTypeForBitwidth - sets integer QualTy according to specified details: bitwidth,...
QualType getLeastIntTypeForBitwidth(unsigned DestWidth, unsigned Signed) const
This class is used for builtin types like 'int'.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Represents a pointer to an Objective C object.
PointerType - C99 6.7.5.1 - Pointer Declarators.
QualType getPointeeType() const
A (possibly-)qualified type.
bool isNull() const
Return true if this QualType doesn't point to a type yet.
QualType getCanonicalType() const
bool isConstQualified() const
Determine whether this type is const-qualified.
static std::string getAsString(SplitQualType split, const PrintingPolicy &Policy)
Exposes information about the current target.
bool isStructureType() const
bool isBlockPointerType() const
bool isSignedIntegerType() const
Return true if this is an integer type that is signed, according to C99 6.2.5p4 [char,...
bool canDecayToPointerType() const
Determines whether this type can decay to a pointer type.
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
bool isSaturatedFixedPointType() const
Return true if this is a saturated fixed point type according to ISO/IEC JTC1 SC22 WG14 N1169.
bool hasSignedIntegerRepresentation() const
Determine whether this type has an signed integer representation of some sort, e.g....
QualType getCanonicalTypeInternal() const
EnumDecl * getAsEnumDecl() const
Retrieves the EnumDecl this type refers to.
bool isObjCObjectPointerType() const
const T * getAs() const
Member-template getAs<specific type>'.
bool isNullPtrType() const
Defines the clang::TargetInfo interface.
Top level wrappers for InstallAPI frontend operations.
const FunctionProtoType * T
__builtin_elementwise_add_sat __builtin_elementwise_sub_sat uint32_t uint64_t __builtin_riscv_ssha_i32 __builtin_riscv_sshl_u32 uint64_t
IntType
===-— Target Data Type Query Methods ----------------------------—===//