Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions lib/SILOptimizer/Utils/ConstantFolding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,24 @@ static SILValue constantFoldBinary(BuiltinInst *BI, BuiltinValueKind ID,
}
}

Type getIntegerType(ASTContext &Ctx, unsigned width, bool DstTySigned) {
if (DstTySigned) {
switch (width) {
case 8: return Ctx.getInt8Type();
case 16: return Ctx.getInt16Type();
case 32: return Ctx.getInt32Type();
case 64: return Ctx.getInt64Type();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'd need default:. Also there is (U)Int128.

}
} else {
switch (width) {
case 8: return Ctx.getUInt8Type();
case 16: return Ctx.getUInt16Type();
case 32: return Ctx.getUInt32Type();
case 64: return Ctx.getUInt64Type();
}
}
}

static SILValue
constantFoldAndCheckIntegerConversions(BuiltinInst *BI,
const BuiltinInfo &Builtin,
Expand Down Expand Up @@ -910,7 +928,7 @@ constantFoldAndCheckIntegerConversions(BuiltinInst *BI,
} else {
diagnose(M.getASTContext(), Loc.getSourceLoc(),
diag::integer_literal_overflow_builtin_types,
DstTySigned, DstTy, SrcAsString);
DstTySigned, getIntegerType(M.getASTContext(), DstBitWidth, DstTySigned), SrcAsString);
}
} else {
// Try to print user-visible types if they are available.
Expand All @@ -922,7 +940,8 @@ constantFoldAndCheckIntegerConversions(BuiltinInst *BI,
// Otherwise, print the Builtin Types.
} else {
// Since builtin types are sign-agnostic, print the signedness
// separately.
// separately

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated change?

diagnose(M.getASTContext(), Loc.getSourceLoc(),
diag::integer_conversion_overflow_builtin_types,
SrcTySigned, SrcTy, DstTySigned, DstTy);
Expand Down