Fix #4135: Keep bool-to-int conditional in its local
Once comp(x != 0) is removed for a bool x, `int n = b ? 1 : 0` becomes a plain copy of the bool, and copy propagation replaced every load of n with `(b ? 1 : 0)`. Refuse copies between bool and non-bool variables rather than requiring identical types, which would also block legitimate copies such as dynamic -> object or Derived[] -> Base[].
This commit is contained in:
1 parent
1942c2ab0f
commit
9b36f6e6da
2 files changed
+21
No files matched your search
@@ -377,6 +377,23 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
|
||||
{
|
||||
return (int)a == 0;
|
||||
}
|
||||
|
||||
public static byte BoolToIntLocalUsedTwice(byte b, bool flag)
|
||||
{
|
||||
int num = (flag ? 1 : 0);
|
||||
return (byte)(b + num >> num);
|
||||
}
|
||||
|
||||
public static int BoolToIntLocalAsLoopBound(object[] array, bool skipFirst)
|
||||
{
|
||||
int num = (skipFirst ? 1 : 0);
|
||||
int num2 = array.Length - 1;
|
||||
while (num2 >= num && array[num2] == null)
|
||||
{
|
||||
num2--;
|
||||
}
|
||||
return num2;
|
||||
}
|
||||
}
|
||||
|
||||
public enum UIntEnum : uint
|
||||
|
||||
@@ -124,6 +124,10 @@ namespace ICSharpCode.Decompiler.IL.Transforms
|
||||
{
|
||||
return false; // non-local code move might change semantics when there's split variables
|
||||
}
|
||||
if (v.Type.IsKnownType(KnownTypeCode.Boolean) != target.Type.IsKnownType(KnownTypeCode.Boolean))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
switch (v.Kind)
|
||||
{
|
||||
case VariableKind.Parameter:
|
||||
|
||||
Reference in new issue
Block a user