public void FuncCall() { var code = @" class S { public static void stat(){} } class A { public int triple(int i) { return 3*i; } void log(int i) {} int f(int i) { var result = triple(triple(i)); log(result); unknownVariable = i; unknownFunc(i); S.stat(); UnknownClass.func(i); Console.WriteLine(i); // Unknown too, since we are missing library/using i = i + unknownVariabe; return result; } int g(A a, int i) { var result = a.triple(i); a.log(result); return result; } } "; MlirTestUtilities.ValidateCodeGeneration(code, TestContext.TestName); }
public void CheckedUnchecked() { var code = @" public int CheckedStmt(int i) { checked { var j = i * 2; return j; } } public int CheckedExpr(int i) { return checked(i * 2); } public int UncheckedStmt(int i) { unchecked { var j = i * 2; return j; } } public int UncheckedExpr(int i) { return unchecked(i * 2); } "; MlirTestUtilities.ValidateCodeGeneration(code, TestContext.TestName); }
public void BinaryOperatorAssignment() { var code = @" public void f(int i) { i -= 1; i += 2; i *= 3; i /= 4; i %= 5; i >>= 6; i <<= 7; i &= 8; i |= 9; i ^= 10; } public void g(int[] array1, long[] array2) { array1[0] += 2; array2[0] += 3; } "; MlirTestUtilities.ValidateCodeGeneration(code, TestContext.TestName); }
public void BoolAssignmentInsideIfCondition() { var code = @" public class Derived { protected bool j; void f() { bool k = true; j = 0; if(j = k) { k=1; } else { k=2; } } } "; MlirTestUtilities.ValidateCodeGeneration(code, TestContext.TestName); }
public void PropertyFromAnotherAssembly() { var code = @" using System; using System.Collections.ObjectModel; public class A<T> : Collection<T> { public void RemoveType(Type type) { for (var i = Count - 1; i >= 0; i--) { var formatter = this[i]; if (formatter.GetType() == type) { RemoveAt(i); } } } } "; MlirTestUtilities.ValidateCodeGeneration(code, TestContext.TestName); }
public void SimpleMethod() { var code = @" class C { int Mult(int i, int j) { return i*j; } void Empty() {} void Nop(int i) { int j = 2*i;} //int Cond(int i) { return i%2 == 0 ? i/2 : i*3 +1; } int Cond2(int i) { if (i%2 == 0) return i/2; else return i*3 +1; } } "; MlirTestUtilities.ValidateCodeGeneration(code, TestContext.TestName); }
public void TestAssignToLocalVarAndParam() { var code = @" void Func(int i) { var j = 12; j = j + 1; i = i + 1; } "; var expected = @" func @_$invalid$global$code$.Func$int$(%arg0: i32) { %0 = cbde.alloca i32 cbde.store %arg0, %0 : memref<i32> br ^bb1 ^bb1: // pred: ^bb0 %c12_i32 = constant 12 : i32 %1 = cbde.alloca i32 cbde.store %c12_i32, %1 : memref<i32> %2 = cbde.load %1 : memref<i32> %c1_i32 = constant 1 : i32 %3 = addi %2, %c1_i32 : i32 cbde.store %3, %1 : memref<i32> %4 = cbde.load %0 : memref<i32> %c1_i32_0 = constant 1 : i32 %5 = addi %4, %c1_i32_0 : i32 cbde.store %5, %0 : memref<i32> br ^bb2 ^bb2: // pred: ^bb1 return } "; MlirTestUtilities.ValidateWithReference(code, expected, TestContext.TestName); }
public void NoIdentifier() { var code = @" public class A { public int count; } public int f() { var a = new A(); if (--a.count > 0) { return 1; } if ((a.count += 1) > 0) { return 1; } return 0; } "; MlirTestUtilities.ValidateCodeGeneration(code, TestContext.TestName); }
public void MultiplicationDivisionModulo() { var code = @" void Func(int i) { var j = 12; j = j * i; j *= i; j = j / i; j /= i; j = j % i; j %= i; } "; var expected = @" func @_$invalid$global$code$.Func$int$(%arg0: i32) { %0 = cbde.alloca i32 cbde.store %arg0, %0 : memref<i32> br ^bb1 ^bb1: // pred: ^bb0 %c12_i32 = constant 12 : i32 %1 = cbde.alloca i32 cbde.store %c12_i32, %1 : memref<i32> %2 = cbde.load %1 : memref<i32> %3 = cbde.load %0 : memref<i32> %4 = muli %2, %3 : i32 cbde.store %4, %1 : memref<i32> %5 = cbde.load %1 : memref<i32> %6 = cbde.load %0 : memref<i32> %7 = muli %5, %6 : i32 cbde.store %7, %1 : memref<i32> %8 = cbde.load %1 : memref<i32> %9 = cbde.load %0 : memref<i32> %10 = divis %8, %9 : i32 cbde.store %10, %1 : memref<i32> %11 = cbde.load %1 : memref<i32> %12 = cbde.load %0 : memref<i32> %13 = divis %11, %12 : i32 cbde.store %13, %1 : memref<i32> %14 = cbde.load %1 : memref<i32> %15 = cbde.load %0 : memref<i32> %16 = remis %14, %15 : i32 cbde.store %16, %1 : memref<i32> %17 = cbde.load %1 : memref<i32> %18 = cbde.load %0 : memref<i32> %19 = remis %17, %18 : i32 cbde.store %19, %1 : memref<i32> br ^bb2 ^bb2: // pred: ^bb1 return } "; MlirTestUtilities.ValidateWithReference(code, expected, TestContext.TestName); }
public void TestBitwiseAndOrXor() { var code = @" class Foo { void Func(int i) { var j = 12; j = j & i; j &= i; j = j | i; j |= i; j = j ^ i; j ^= i; } } "; var expected = @" func @_Foo.Func$int$(%arg0: i32) { %0 = cbde.alloca i32 cbde.store %arg0, %0 : memref<i32> br ^bb1 ^bb1: // pred: ^bb0 %c12_i32 = constant 12 : i32 %1 = cbde.alloca i32 cbde.store %c12_i32, %1 : memref<i32> %2 = cbde.load %1 : memref<i32> %3 = cbde.load %0 : memref<i32> %4 = and %2, %3 : i32 cbde.store %4, %1 : memref<i32> %5 = cbde.load %1 : memref<i32> %6 = cbde.load %0 : memref<i32> %7 = and %5, %6 : i32 cbde.store %7, %1 : memref<i32> %8 = cbde.load %1 : memref<i32> %9 = cbde.load %0 : memref<i32> %10 = or %8, %9 : i32 cbde.store %10, %1 : memref<i32> %11 = cbde.load %1 : memref<i32> %12 = cbde.load %0 : memref<i32> %13 = or %11, %12 : i32 cbde.store %13, %1 : memref<i32> %14 = cbde.load %1 : memref<i32> %15 = cbde.load %0 : memref<i32> %16 = xor %14, %15 : i32 cbde.store %16, %1 : memref<i32> %17 = cbde.load %1 : memref<i32> %18 = cbde.load %0 : memref<i32> %19 = xor %17, %18 : i32 cbde.store %19, %1 : memref<i32> br ^bb2 ^bb2: // pred: ^bb1 return } "; MlirTestUtilities.ValidateWithReference(code, expected, TestContext.TestName); }
public void EmptyBody() { var code = @" public static extern void Extern(int p1); "; MlirTestUtilities.ValidateCodeGeneration(code, TestContext.TestName); }
public void ParamsKeyword() { var code = @" public void f(params int[] args) { } "; MlirTestUtilities.ValidateCodeGeneration(code, TestContext.TestName); }
public void Arglist() { var code = @" public void f(__arglist) { } "; MlirTestUtilities.ValidateCodeGeneration(code, TestContext.TestName); }
public void AssignmentInBinaryOperator() { var code = @" void f(int a, int b) { a = (b = 2) + 1; } "; MlirTestUtilities.ValidateCodeGeneration(code, TestContext.TestName); }
public void ParenthesizedLambdaExpression() { var code = @" Action f() { return () => Y(); } "; MlirTestUtilities.ValidateCodeGeneration(code, TestContext.TestName); }
public void SimpleLambdaExpression() { var code = @" public System.Linq.Expressions.Expression<Func<int, int>> F() { return x => 2*x; } "; MlirTestUtilities.ValidateCodeGeneration(code, TestContext.TestName); }
public void UnnamedFunctionParameter() { var code = @" int Func(int, int, int i) { return 2*i; } "; MlirTestUtilities.ValidateCodeGeneration(code, TestContext.TestName); }
public void IgnoreParenthesesInAssignment() { var code = @" void f(int a, int b) { a = (b = 2); } "; MlirTestUtilities.ValidateCodeGeneration(code, TestContext.TestName); }
public void ReturnParenthesizedNullLitteral() { var code = @" public Type f() { return (null); } "; MlirTestUtilities.ValidateCodeGeneration(code, TestContext.TestName); }
public void MethodGroup() { var code = @" public static Func<string, bool> CreateFilter() { return string.IsNullOrEmpty; } "; MlirTestUtilities.ValidateCodeGeneration(code, TestContext.TestName); }
public void ChainingAssignments() { var code = @" void f(int i) { int j = i = 0; i = j = 10; } "; MlirTestUtilities.ValidateCodeGeneration(code, TestContext.TestName); }
public void UnknownMethodOnMultipleLines() { var code = @" void f(int i, int j) { g(i, j); } "; MlirTestUtilities.ValidateCodeGeneration(code, TestContext.TestName); }
public void ArrayAssignment() { var code = @" void f() { int[] array = new int[5]; array[0] = 2; } "; MlirTestUtilities.ValidateCodeGeneration(code, TestContext.TestName); }
public void AnonymousObjectCreation() { var code = @" public int f() { var v = new { a = 108, m = ""Hello"" }; return v.a; } "; MlirTestUtilities.ValidateCodeGeneration(code, TestContext.TestName); }
public void AsyncFunction() { var code = @" class A { async System.Threading.Tasks.Task<int> FuncAsync() { return 3; } } "; MlirTestUtilities.ValidateCodeGeneration(code, TestContext.TestName); }
public void Goto() { var code = @" void f() { goto Label; Label: return; } "; MlirTestUtilities.ValidateCodeGeneration(code, TestContext.TestName); }
public void CommentsWithNewLine() { var code = @" void f() { new A() { i = 3 }; // Noncompliant // ^^^^^^^^^ new A() { i = 4 }; } "; MlirTestUtilities.ValidateCodeGeneration(code, TestContext.TestName); }
public void ForWithoutCondition() { var code = @" void f(int i) { for (;;) { i = i + 1; } } "; MlirTestUtilities.ValidateCodeGeneration(code, TestContext.TestName); }
public void Enum() { var code = @" using System; public enum Color { Red, Green, Blue }; private enum Color { Red, Green, Blue }; class A { private Color WorkWithEnum(int i, Color col) { if (col == Color.Blue && i == (int)col) { Color c = Color.Blue; return c; } else { return Color.Red; } } private Color WorkWithUnaccessibleEnum(int i, Color col) { if (col == Color.Blue && i == (int)col) { Color c = Color.Blue; return c; } else { return Color.Red; } } private ConsoleColor WorkWithExternalEnum(int i, ConsoleColor col) { if (col == ConsoleColor.Blue && i == (int)col) { Color c = ConsoleColor.Blue; return c; } else { return ConsoleColor.Red; } } } "; MlirTestUtilities.ValidateCodeGeneration(code, TestContext.TestName); }
public void Namespace() { var code = @" namespace Tests { public static void f() { Tests.g(); } } "; MlirTestUtilities.ValidateCodeGeneration(code, TestContext.TestName); }