[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:
Ravi Kandhadai
2018-05-21 18:36:07 -07:00
parent dc5827cf22
commit f1ff8a61a5
10 changed files with 190 additions and 31 deletions

View File

@@ -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,