From 9a14bb9bd0b43f023eb72aac132483d9ddb1b77a Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Sun, 17 Sep 2017 21:42:19 +0200 Subject: [PATCH] Avoid 'unchecked' annotation on float->double casts. --- ICSharpCode.Decompiler/CSharp/TranslatedExpression.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ICSharpCode.Decompiler/CSharp/TranslatedExpression.cs b/ICSharpCode.Decompiler/CSharp/TranslatedExpression.cs index 0e08fd7da..8d49ce4cd 100644 --- a/ICSharpCode.Decompiler/CSharp/TranslatedExpression.cs +++ b/ICSharpCode.Decompiler/CSharp/TranslatedExpression.cs @@ -181,6 +181,9 @@ namespace ICSharpCode.Decompiler.CSharp return this; } var compilation = expressionBuilder.compilation; + bool isLifted = type.IsKnownType(KnownTypeCode.NullableOfT) && targetType.IsKnownType(KnownTypeCode.NullableOfT); + IType utype = isLifted ? NullableType.GetUnderlyingType(type) : type; + IType targetUType = isLifted ? NullableType.GetUnderlyingType(targetType) : targetType; if (type.IsKnownType(KnownTypeCode.Boolean) && targetType.GetStackType().IsIntegerType()) { // convert from boolean to integer (or enum) return new ConditionalExpression( @@ -311,7 +314,10 @@ namespace ICSharpCode.Decompiler.CSharp return this; } var castExpr = new CastExpression(expressionBuilder.ConvertType(targetType), Expression); - castExpr.AddAnnotation(checkForOverflow ? AddCheckedBlocks.CheckedAnnotation : AddCheckedBlocks.UncheckedAnnotation); + bool avoidCheckAnnotation = utype.IsKnownType(KnownTypeCode.Single) && targetUType.IsKnownType(KnownTypeCode.Double); + if (!avoidCheckAnnotation) { + castExpr.AddAnnotation(checkForOverflow ? AddCheckedBlocks.CheckedAnnotation : AddCheckedBlocks.UncheckedAnnotation); + } return castExpr.WithoutILInstruction().WithRR(rr); }