|
| 1 | +// Licensed to the .NET Foundation under one or more agreements. |
| 2 | +// The .NET Foundation licenses this file to you under the MIT license. |
| 3 | +// |
| 4 | + |
| 5 | +using System.Runtime.CompilerServices; |
| 6 | +using Xunit; |
| 7 | + |
| 8 | +public class CompareTest |
| 9 | +{ |
| 10 | + [MethodImplAttribute(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)] |
| 11 | + public static bool Lt2((int, float) x) => (x.Item1 < 2); |
| 12 | + |
| 13 | + [MethodImplAttribute(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)] |
| 14 | + public static bool Gt2((int, float) x) => (x.Item1 > 2); |
| 15 | + |
| 16 | + [MethodImplAttribute(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)] |
| 17 | + public static bool Le2((int, float) x) => (x.Item1 <= 2); |
| 18 | + |
| 19 | + [MethodImplAttribute(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)] |
| 20 | + public static bool Ge2((int, float) x) => (x.Item1 >= 2); |
| 21 | + |
| 22 | + [MethodImplAttribute(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)] |
| 23 | + public static bool Eq0((int, float) x) => (x.Item1 == 0); |
| 24 | + |
| 25 | + [MethodImplAttribute(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)] |
| 26 | + public static bool Ne0((int, float) x) => (x.Item1 != 0); |
| 27 | + |
| 28 | + [Fact] |
| 29 | + public static void Test() |
| 30 | + { |
| 31 | + // The integer field of a struct passed in a register according to RISC-V floating-point calling convention is |
| 32 | + // not extended. Comparisons on RISC-V, however, always operate on full registers. |
| 33 | + // Note: reflection calls poison the undefined bits in runtime debug mode making it a better repro. |
| 34 | + var type = typeof(CompareTest); |
| 35 | + var args = new object[] {(2, 0f)}; |
| 36 | + Assert.False((bool)type.GetMethod("Lt2").Invoke(null, args)); |
| 37 | + Assert.False((bool)type.GetMethod("Gt2").Invoke(null, args)); |
| 38 | + Assert.True((bool)type.GetMethod("Le2").Invoke(null, args)); |
| 39 | + Assert.True((bool)type.GetMethod("Ge2").Invoke(null, args)); |
| 40 | + args = new object[] {(0, 0f)}; |
| 41 | + Assert.True((bool)type.GetMethod("Eq0").Invoke(null, args)); |
| 42 | + Assert.False((bool)type.GetMethod("Ne0").Invoke(null, args)); |
| 43 | + } |
| 44 | +} |
0 commit comments