From 6374217e191b8cef0c5a3d862f4291583eb959f4 Mon Sep 17 00:00:00 2001 From: Sven Boemer Date: Wed, 20 Apr 2022 16:37:24 -0700 Subject: Don't throw on NoneOperation (#2753) --- .../DataFlow/UnsafeDataFlow.cs | 68 ++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 test/Mono.Linker.Tests.Cases/DataFlow/UnsafeDataFlow.cs (limited to 'test/Mono.Linker.Tests.Cases') 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; + } +} -- cgit v1.2.3