Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/linker.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSven Boemer <sbomer@gmail.com>2022-04-21 02:37:24 +0300
committerGitHub <noreply@github.com>2022-04-21 02:37:24 +0300
commit6374217e191b8cef0c5a3d862f4291583eb959f4 (patch)
tree58d990d05046cea90cafd64a9d52a6e799731f60 /test/Mono.Linker.Tests.Cases
parenta073a68561a7f45a2dba0976083ee3e9873bf423 (diff)
Don't throw on NoneOperation (#2753)
Diffstat (limited to 'test/Mono.Linker.Tests.Cases')
-rw-r--r--test/Mono.Linker.Tests.Cases/DataFlow/UnsafeDataFlow.cs68
1 files changed, 68 insertions, 0 deletions
diff --git a/test/Mono.Linker.Tests.Cases/DataFlow/UnsafeDataFlow.cs b/test/Mono.Linker.Tests.Cases/DataFlow/UnsafeDataFlow.cs
new file mode 100644
index 000000000..c4d9f98d5
--- /dev/null
+++ b/test/Mono.Linker.Tests.Cases/DataFlow/UnsafeDataFlow.cs
@@ -0,0 +1,68 @@
+// Copyright (c) .NET Foundation and contributors. All rights reserved.
+// Licensed under the MIT license. See LICENSE file in the project root for full license information.
+
+using System;
+using System.Diagnostics.CodeAnalysis;
+using Mono.Linker.Tests.Cases.Expectations.Assertions;
+using Mono.Linker.Tests.Cases.Expectations.Helpers;
+using Mono.Linker.Tests.Cases.Expectations.Metadata;
+
+namespace Mono.Linker.Tests.Cases.DataFlow
+{
+ [SetupCompileArgument ("/unsafe")]
+ [SkipKeptItemsValidation]
+ [ExpectedNoWarnings]
+ class UnsafeDataFlow
+ {
+ public static void Main ()
+ {
+ TestReadFromPointer ();
+ TestWriteToPointer ();
+ TestWriteToStackAllocedStruct ();
+ }
+
+ // We don't analyze the pointer manipulation, so it should produce a warning
+ // about reading an unknown type, without crashing the analyzer.
+ [ExpectedWarning ("IL2062", nameof (DataFlowTypeExtensions.RequiresAll))]
+ static unsafe void TestReadFromPointer ()
+ {
+ int i = 6;
+ int* pI = &i;
+ Type[] arr = new Type[] { GetWithPublicMethods () };
+ arr[*pI].RequiresAll ();
+ }
+
+ // We don't analyze the pointer manipulation, so it should produce a warning
+ // about reading an unknown type, without crashing the analyzer.
+ [ExpectedWarning ("IL2062", nameof (DataFlowTypeExtensions.RequiresAll))]
+ static unsafe void TestWriteToPointer ()
+ {
+ int i = 6;
+ int* pI = &i;
+ *pI = 0;
+ Type[] arr = new Type[] { GetWithPublicMethods () };
+ arr[i].RequiresAll ();
+ }
+
+ // We don't analyze the stackalloc'd struct member, so it should produce a warning
+ // about reading an unknown type, without crashing the analyzer.
+ [ExpectedWarning ("IL2062", nameof (DataFlowTypeExtensions.RequiresAll))]
+ static unsafe void TestWriteToStackAllocedStruct ()
+ {
+ var stackArr = stackalloc S[1];
+ stackArr[0] = new S {
+ I = 0
+ };
+ Type[] arr = new Type[] { GetWithPublicMethods () };
+ arr[stackArr[0].I].RequiresAll ();
+ }
+
+ struct S
+ {
+ public int I;
+ }
+
+ [return: DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)]
+ static Type GetWithPublicMethods () => null;
+ }
+}