@@ -7269,98 +7269,16 @@ CompilerType TypeSystemClang::GetTypeForFormatters(void *type) {
72697269
72707270bool TypeSystemClang::IsPromotableIntegerType (
72717271 lldb::opaque_compiler_type_t type) {
7272- // Unscoped enums are always considered as promotable, even if their
7273- // underlying type does not need to be promoted (e.g. "int").
7274- bool is_signed = false ;
7275- bool isUnscopedEnumerationType =
7276- IsEnumerationType (type, is_signed) && !IsScopedEnumerationType (type);
7277- if (isUnscopedEnumerationType)
7278- return true ;
7279-
7280- switch (GetBasicTypeEnumeration (type)) {
7281- case lldb::eBasicTypeBool:
7282- case lldb::eBasicTypeChar:
7283- case lldb::eBasicTypeSignedChar:
7284- case lldb::eBasicTypeUnsignedChar:
7285- case lldb::eBasicTypeShort:
7286- case lldb::eBasicTypeUnsignedShort:
7287- case lldb::eBasicTypeWChar:
7288- case lldb::eBasicTypeSignedWChar:
7289- case lldb::eBasicTypeUnsignedWChar:
7290- case lldb::eBasicTypeChar16:
7291- case lldb::eBasicTypeChar32:
7292- return true ;
7293-
7294- default :
7295- return false ;
7296- }
7297-
7298- llvm_unreachable (" All cases handled above." );
7272+ clang::QualType qual_type (GetCanonicalQualType (type));
7273+ return getASTContext ().isPromotableIntegerType (qual_type);
72997274}
73007275
7301- llvm::Expected<CompilerType>
7302- TypeSystemClang::DoIntegralPromotion (CompilerType from,
7303- ExecutionContextScope *exe_scope) {
7304- if (!from.IsInteger () && !from.IsUnscopedEnumerationType ())
7305- return from;
7306-
7307- if (!from.IsPromotableIntegerType ())
7308- return from;
7309-
7310- if (from.IsUnscopedEnumerationType ()) {
7311- EnumDecl *enum_decl = GetAsEnumDecl (from);
7312- CompilerType promotion_type = GetType (enum_decl->getPromotionType ());
7313- return DoIntegralPromotion (promotion_type, exe_scope);
7314- }
7315-
7316- lldb::BasicType builtin_type =
7317- from.GetCanonicalType ().GetBasicTypeEnumeration ();
7318- uint64_t from_size = 0 ;
7319- if (builtin_type == lldb::eBasicTypeWChar ||
7320- builtin_type == lldb::eBasicTypeSignedWChar ||
7321- builtin_type == lldb::eBasicTypeUnsignedWChar ||
7322- builtin_type == lldb::eBasicTypeChar16 ||
7323- builtin_type == lldb::eBasicTypeChar32) {
7324- // Find the type that can hold the entire range of values for our type.
7325- bool is_signed = from.IsSigned ();
7326- llvm::Expected<uint64_t > from_size = from.GetByteSize (exe_scope);
7327- if (!from_size)
7328- return from_size.takeError ();
7329- CompilerType promote_types[] = {
7330- GetBasicTypeFromAST (lldb::eBasicTypeInt),
7331- GetBasicTypeFromAST (lldb::eBasicTypeUnsignedInt),
7332- GetBasicTypeFromAST (lldb::eBasicTypeLong),
7333- GetBasicTypeFromAST (lldb::eBasicTypeUnsignedLong),
7334- GetBasicTypeFromAST (lldb::eBasicTypeLongLong),
7335- GetBasicTypeFromAST (lldb::eBasicTypeUnsignedLongLong),
7336- };
7337- for (CompilerType &type : promote_types) {
7338- llvm::Expected<uint64_t > byte_size = type.GetByteSize (exe_scope);
7339- if (!byte_size)
7340- return byte_size.takeError ();
7341- if (*from_size < *byte_size ||
7342- (*from_size == *byte_size && is_signed == type.IsSigned ())) {
7343- return type;
7344- }
7345- }
7346- llvm_unreachable (" char type should fit into long long" );
7347- }
7348-
7349- // Here we can promote only to "int" or "unsigned int".
7350- CompilerType int_type = GetBasicTypeFromAST (lldb::eBasicTypeInt);
7351- llvm::Expected<uint64_t > int_byte_size = int_type.GetByteSize (exe_scope);
7352- if (!int_byte_size)
7353- return int_byte_size.takeError ();
7354-
7355- // Signed integer types can be safely promoted to "int".
7356- if (from.IsSigned ()) {
7357- return int_type;
7358- }
7359- // Unsigned integer types are promoted to "unsigned int" if "int" cannot hold
7360- // their entire value range.
7361- return (from_size == *int_byte_size)
7362- ? GetBasicTypeFromAST (lldb::eBasicTypeUnsignedInt)
7363- : int_type;
7276+ CompilerType
7277+ TypeSystemClang::GetPromotedIntegerType (lldb::opaque_compiler_type_t type) {
7278+ if (!IsPromotableIntegerType (type))
7279+ return CompilerType ();
7280+ clang::QualType qual_type (GetCanonicalQualType (type));
7281+ return GetType (getASTContext ().getPromotedIntegerType (qual_type));
73647282}
73657283
73667284clang::EnumDecl *TypeSystemClang::GetAsEnumDecl (const CompilerType &type) {
0 commit comments