@@ -526,46 +526,30 @@ Interpreter::PickIntegerType(lldb::TypeSystemSP type_system,
526526 bool unsigned_is_allowed = literal->IsUnsigned () || literal->GetRadix () != 10 ;
527527 llvm::APInt apint = literal->GetValue ();
528528
529- // Try int/unsigned int.
530- llvm::Expected<uint64_t > int_size =
531- GetBasicType (type_system, lldb::eBasicTypeInt).GetBitSize (ctx.get ());
532- if (!int_size)
533- return int_size.takeError ();
534- if (literal->GetTypeSuffix () == IntegerTypeSuffix::None &&
535- apint.isIntN (*int_size)) {
536- if (!literal->IsUnsigned () && apint.isIntN (*int_size - 1 ))
537- return GetBasicType (type_system, lldb::eBasicTypeInt);
538- if (unsigned_is_allowed)
539- return GetBasicType (type_system, lldb::eBasicTypeUnsignedInt);
540- }
541- // Try long/unsigned long.
542- llvm::Expected<uint64_t > long_size =
543- GetBasicType (type_system, lldb::eBasicTypeLong).GetBitSize (ctx.get ());
544- if (!long_size)
545- return long_size.takeError ();
546- if (literal->GetTypeSuffix () != IntegerTypeSuffix::LongLong &&
547- apint.isIntN (*long_size)) {
548- if (!literal->IsUnsigned () && apint.isIntN (*long_size - 1 ))
549- return GetBasicType (type_system, lldb::eBasicTypeLong);
550- if (unsigned_is_allowed)
551- return GetBasicType (type_system, lldb::eBasicTypeUnsignedLong);
552- }
553- // Try long long/unsigned long long.
554- llvm::Expected<uint64_t > long_long_size =
555- GetBasicType (type_system, lldb::eBasicTypeLongLong).GetBitSize (ctx.get ());
556- if (!long_long_size)
557- return long_long_size.takeError ();
558- if (apint.isIntN (*long_long_size)) {
559- if (!literal->IsUnsigned () && apint.isIntN (*long_long_size - 1 ))
560- return GetBasicType (type_system, lldb::eBasicTypeLongLong);
561- // If we still couldn't decide a type, we probably have something that
562- // does not fit in a signed long long, but has no U suffix. Also known as:
563- //
564- // warning: integer literal is too large to be represented in a signed
565- // integer type, interpreting as unsigned [-Wimplicitly-unsigned-literal]
566- //
567- return GetBasicType (type_system, lldb::eBasicTypeUnsignedLongLong);
529+ llvm::SmallVector<std::pair<lldb::BasicType, lldb::BasicType>, 3 > candidates;
530+ if (literal->GetTypeSuffix () <= IntegerTypeSuffix::None)
531+ candidates.emplace_back (lldb::eBasicTypeInt,
532+ unsigned_is_allowed ? lldb::eBasicTypeUnsignedInt
533+ : lldb::eBasicTypeInvalid);
534+ if (literal->GetTypeSuffix () <= IntegerTypeSuffix::Long)
535+ candidates.emplace_back (lldb::eBasicTypeLong,
536+ unsigned_is_allowed ? lldb::eBasicTypeUnsignedLong
537+ : lldb::eBasicTypeInvalid);
538+ candidates.emplace_back (lldb::eBasicTypeLongLong,
539+ lldb::eBasicTypeUnsignedLongLong);
540+ for (auto [signed_, unsigned_] : candidates) {
541+ CompilerType signed_type = type_system->GetBasicTypeFromAST (signed_);
542+ if (!signed_type)
543+ continue ;
544+ llvm::Expected<uint64_t > size = signed_type.GetBitSize (ctx.get ());
545+ if (!size)
546+ return size.takeError ();
547+ if (!literal->IsUnsigned () && apint.isIntN (*size - 1 ))
548+ return signed_type;
549+ if (unsigned_ != lldb::eBasicTypeInvalid && apint.isIntN (*size))
550+ return type_system->GetBasicTypeFromAST (unsigned_);
568551 }
552+
569553 return llvm::make_error<DILDiagnosticError>(
570554 m_expr,
571555 " integer literal is too large to be represented in any integer type" ,
0 commit comments