Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fd27bde

Browse files
committed
Add function pointer conversion tests
1 parent 15e8847 commit fd27bde

4 files changed

Lines changed: 59 additions & 0 deletions

File tree

csharp/ql/test/library-tests/csharp9/FunctionPointer.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,18 @@ static void M3(delegate* managed<ref int, out object?, in int, ref int> f)
3535
{
3636
int j = f(new T());
3737
}
38+
39+
static void M5(delegate*<B, A> f, delegate*<A, B> ff)
40+
{
41+
M5(ff, ff); // implicit conversion due to implicit reference conversion
42+
}
43+
44+
static void M6(delegate*<int*, void*> f, delegate*<void*, int*> ff)
45+
{
46+
M6(ff, ff); // implicit conversion due to implicit pointer conversion
47+
}
48+
49+
class A { }
50+
class B : A { }
3851
}
3952
}

csharp/ql/test/library-tests/csharp9/FunctionPointer.expected

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,25 @@
11
type
2+
| file://:0:0:0:0 | delegate* default<A,B> | B | 0 |
3+
| file://:0:0:0:0 | delegate* default<B,A> | A | 0 |
24
| file://:0:0:0:0 | delegate* default<Int32 ref,Object out,Int32 in,Int32 ref> | Int32 | 0 |
35
| file://:0:0:0:0 | delegate* default<Int32 ref,Object out,Int32> | Int32 | 0 |
6+
| file://:0:0:0:0 | delegate* default<Int32*,Void*> | Void* | 0 |
47
| file://:0:0:0:0 | delegate* default<Int32> | Int32 | 0 |
58
| file://:0:0:0:0 | delegate* default<T,Int32> | Int32 | 0 |
9+
| file://:0:0:0:0 | delegate* default<Void*,Int32*> | Int32* | 0 |
610
| file://:0:0:0:0 | delegate* stdcall<Int32 ref,Object out,T,Void> | Void | 2 |
711
unmanagedCallingConvention
812
parameter
13+
| file://:0:0:0:0 | delegate* default<A,B> | 0 | file://:0:0:0:0 | | A |
14+
| file://:0:0:0:0 | delegate* default<B,A> | 0 | file://:0:0:0:0 | | B |
915
| file://:0:0:0:0 | delegate* default<Int32 ref,Object out,Int32 in,Int32 ref> | 0 | file://:0:0:0:0 | | Int32 |
1016
| file://:0:0:0:0 | delegate* default<Int32 ref,Object out,Int32 in,Int32 ref> | 1 | file://:0:0:0:0 | `1 | Object |
1117
| file://:0:0:0:0 | delegate* default<Int32 ref,Object out,Int32 in,Int32 ref> | 2 | file://:0:0:0:0 | `2 | Int32 |
1218
| file://:0:0:0:0 | delegate* default<Int32 ref,Object out,Int32> | 0 | file://:0:0:0:0 | | Int32 |
1319
| file://:0:0:0:0 | delegate* default<Int32 ref,Object out,Int32> | 1 | file://:0:0:0:0 | `1 | Object |
20+
| file://:0:0:0:0 | delegate* default<Int32*,Void*> | 0 | file://:0:0:0:0 | | Int32* |
1421
| file://:0:0:0:0 | delegate* default<T,Int32> | 0 | file://:0:0:0:0 | | T |
22+
| file://:0:0:0:0 | delegate* default<Void*,Int32*> | 0 | file://:0:0:0:0 | | Void* |
1523
| file://:0:0:0:0 | delegate* stdcall<Int32 ref,Object out,T,Void> | 0 | file://:0:0:0:0 | | Int32 |
1624
| file://:0:0:0:0 | delegate* stdcall<Int32 ref,Object out,T,Void> | 1 | file://:0:0:0:0 | `1 | Object |
1725
| file://:0:0:0:0 | delegate* stdcall<Int32 ref,Object out,T,Void> | 2 | file://:0:0:0:0 | `2 | T |
@@ -20,3 +28,6 @@ invocation
2028
| FunctionPointer.cs:25:13:25:44 | function pointer call |
2129
| FunctionPointer.cs:31:29:31:57 | function pointer call |
2230
| FunctionPointer.cs:36:21:36:30 | function pointer call |
31+
casts
32+
| FunctionPointer.cs:41:16:41:17 | (...) ... | file://:0:0:0:0 | delegate* default<A,B> | file://:0:0:0:0 | delegate* default<B,A> |
33+
| FunctionPointer.cs:46:16:46:17 | (...) ... | file://:0:0:0:0 | delegate* default<Void*,Int32*> | file://:0:0:0:0 | delegate* default<Int32*,Void*> |

csharp/ql/test/library-tests/csharp9/FunctionPointer.ql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,7 @@ query predicate parameter(FunctionPointerType fpt, int i, Parameter p, string t)
1414
}
1515

1616
query predicate invocation(FunctionPointerCall fpc) { any() }
17+
18+
query predicate casts(ImplicitCast cast, FunctionPointerType fromType, FunctionPointerType toType) {
19+
cast.getSourceType() = fromType and cast.getTargetType() = toType
20+
}

csharp/ql/test/library-tests/csharp9/PrintAst.expected

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,37 @@ FunctionPointer.cs:
193193
# 36| -1: [ParameterAccess] access to parameter f
194194
# 36| 0: [ObjectCreation] object creation of type T
195195
# 36| 0: [TypeMention] T
196+
# 39| 11: [Method] M5
197+
# 39| -1: [TypeMention] Void
198+
#-----| 2: (Parameters)
199+
# 39| 0: [Parameter] f
200+
# 39| -1: [TypeMention] delegate* default<B,A>
201+
# 39| 1: [Parameter] ff
202+
# 39| -1: [TypeMention] delegate* default<A,B>
203+
# 40| 4: [BlockStmt] {...}
204+
# 41| 0: [ExprStmt] ...;
205+
# 41| 0: [MethodCall] call to method M5
206+
# 41| 0: [CastExpr] (...) ...
207+
# 41| 1: [ParameterAccess] access to parameter ff
208+
# 41| 1: [ParameterAccess] access to parameter ff
209+
# 44| 12: [Method] M6
210+
# 44| -1: [TypeMention] Void
211+
#-----| 2: (Parameters)
212+
# 44| 0: [Parameter] f
213+
# 44| -1: [TypeMention] delegate* default<Int32*,Void*>
214+
# 44| 1: [Parameter] ff
215+
# 44| -1: [TypeMention] delegate* default<Void*,Int32*>
216+
# 45| 4: [BlockStmt] {...}
217+
# 46| 0: [ExprStmt] ...;
218+
# 46| 0: [MethodCall] call to method M6
219+
# 46| 0: [CastExpr] (...) ...
220+
# 46| 1: [ParameterAccess] access to parameter ff
221+
# 46| 1: [ParameterAccess] access to parameter ff
222+
# 49| 13: [Class] A
223+
# 50| 14: [Class] B
224+
#-----| 3: (Base types)
225+
# 50| 0: [TypeMention] A
226+
# 50| 0: [TypeMention] A
196227
InitOnlyProperty.cs:
197228
# 3| [NamespaceDeclaration] namespace ... { ... }
198229
# 5| 1: [Class] IsExternalInit

0 commit comments

Comments
 (0)