From 79b5653ccfd0663790b4dc4efe65c1285ede73fc Mon Sep 17 00:00:00 2001 From: Jackson Schuster <36744439+jtschuster@users.noreply.github.com> Date: Tue, 31 May 2022 12:39:42 -0500 Subject: Warn on unhandled store in reference case instead of throwing (#2807) Warn instead of throwing on unhandled reference store I scoped the exception down to the case of a typed value which is of interesting type. Currently we don't think this can every happen and it's basically the only case where there's a potential for analysis hole. Added a test case which actually reproes the failure from the runtime - not exactly (it seems the compiler in runtime is slightly different or something else is going on and the exact same code from runtime produces different IL in the linker tests), but modified so that it does hit the exception in unchanged code. Co-authored-by: vitek-karas <10670590+vitek-karas@users.noreply.github.com> --- .../DataFlow/ByRefDataflow.cs | 30 ++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'test/Mono.Linker.Tests.Cases') diff --git a/test/Mono.Linker.Tests.Cases/DataFlow/ByRefDataflow.cs b/test/Mono.Linker.Tests.Cases/DataFlow/ByRefDataflow.cs index 3d47170d6..0b05ededc 100644 --- a/test/Mono.Linker.Tests.Cases/DataFlow/ByRefDataflow.cs +++ b/test/Mono.Linker.Tests.Cases/DataFlow/ByRefDataflow.cs @@ -9,6 +9,7 @@ using Mono.Linker.Tests.Cases.Expectations.Metadata; namespace Mono.Linker.Tests.Cases.DataFlow { [SetupCompileArgument ("/langversion:7.3")] + [SetupCompileArgument ("/unsafe")] [Kept] [ExpectedNoWarnings] class ByRefDataflow @@ -31,6 +32,8 @@ namespace Mono.Linker.Tests.Cases.DataFlow PassRefToField (); PassRefToParameter (null); + + PointerDereference.Test (); } [Kept] @@ -102,5 +105,32 @@ namespace Mono.Linker.Tests.Cases.DataFlow public static void KeptMethod () { } internal static void RemovedMethod () { } } + + [Kept] + unsafe class PointerDereference + { + [Kept] + [KeptAttributeAttribute (typeof (RequiresUnreferencedCodeAttribute))] + [RequiresUnreferencedCode ("")] + static unsafe void IntPtrDeref () + { + *_ptr = GetDangerous (); + } + + [Kept] + static IntPtr* _ptr; + + [Kept] + [KeptAttributeAttribute (typeof (RequiresUnreferencedCodeAttribute))] + [RequiresUnreferencedCode ("")] + static IntPtr GetDangerous () { return IntPtr.Zero; } + + [Kept] + [ExpectedWarning ("IL2026")] + public static void Test () + { + IntPtrDeref (); + } + } } } -- cgit v1.2.3