mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[Sema] Add Sema checks for detecting large integer literals that
overflow Builtin.Int2048 and add tests for checking the correctness of the diagnostics.
This commit is contained in:
@@ -1865,7 +1865,6 @@ namespace {
|
||||
return bridgeFromObjectiveC(object, valueType, false);
|
||||
}
|
||||
|
||||
TypeAliasDecl *MaxIntegerTypeDecl = nullptr;
|
||||
TypeAliasDecl *MaxFloatTypeDecl = nullptr;
|
||||
|
||||
public:
|
||||
@@ -1928,28 +1927,6 @@ namespace {
|
||||
}
|
||||
}
|
||||
|
||||
// Find the maximum-sized builtin integer type.
|
||||
|
||||
if (!MaxIntegerTypeDecl) {
|
||||
SmallVector<ValueDecl *, 1> lookupResults;
|
||||
tc.getStdlibModule(dc)->lookupValue(/*AccessPath=*/{},
|
||||
tc.Context.Id_MaxBuiltinIntegerType,
|
||||
NLKind::QualifiedLookup,
|
||||
lookupResults);
|
||||
if (lookupResults.size() == 1) {
|
||||
MaxIntegerTypeDecl = dyn_cast<TypeAliasDecl>(lookupResults.front());
|
||||
tc.validateDecl(MaxIntegerTypeDecl);
|
||||
}
|
||||
}
|
||||
if (!MaxIntegerTypeDecl ||
|
||||
!MaxIntegerTypeDecl->hasInterfaceType() ||
|
||||
!MaxIntegerTypeDecl->getDeclaredInterfaceType()->is<BuiltinIntegerType>()) {
|
||||
tc.diagnose(expr->getLoc(), diag::no_MaxBuiltinIntegerType_found);
|
||||
return nullptr;
|
||||
}
|
||||
tc.validateDecl(MaxIntegerTypeDecl);
|
||||
auto maxType = MaxIntegerTypeDecl->getUnderlyingTypeLoc().getType();
|
||||
|
||||
DeclName initName(tc.Context, DeclBaseName::createConstructor(),
|
||||
{ tc.Context.Id_integerLiteral });
|
||||
DeclName builtinInitName(tc.Context, DeclBaseName::createConstructor(),
|
||||
@@ -1963,7 +1940,9 @@ namespace {
|
||||
tc.Context.Id_IntegerLiteralType,
|
||||
initName,
|
||||
builtinProtocol,
|
||||
maxType,
|
||||
// Note that 'MaxIntegerType' is guaranteed to be available.
|
||||
// Otherwise it would be caught by CSGen::visitLiteralExpr
|
||||
tc.getMaxIntegerType(dc),
|
||||
builtinInitName,
|
||||
nullptr,
|
||||
diag::integer_literal_broken_proto,
|
||||
|
||||
Reference in New Issue
Block a user