-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a test verifying that double negation is not removed for CSEs
- Loading branch information
1 parent
16052be
commit b413465
Showing
2 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System; | ||
using System.Runtime.CompilerServices; | ||
|
||
namespace CSEWithDoubleNegation | ||
{ | ||
class DoNotMorphAwayCSEThatRepresentsDoubleNegation | ||
{ | ||
private static int _static = 0; | ||
|
||
static int Main(string[] args) | ||
{ | ||
if (DoubleNeg() != 22) | ||
{ | ||
Console.WriteLine("DoubleNeg() failed to return the expected value of 22"); | ||
return -1; | ||
} | ||
|
||
return 100; | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.NoInlining)] | ||
private static int DoubleNeg() | ||
{ | ||
var a = 21; | ||
_static = 42; | ||
|
||
return 43 - (0 - (a - _static)); | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<CLRTestPriority>1</CLRTestPriority> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<DebugType>None</DebugType> | ||
<Optimize>True</Optimize> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Compile Include="CSEWithDoubleNegation.cs" /> | ||
</ItemGroup> | ||
</Project> |