diff options
author | Jackson Schuster <36744439+jtschuster@users.noreply.github.com> | 2022-05-31 20:39:42 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-31 20:39:42 +0300 |
commit | 79b5653ccfd0663790b4dc4efe65c1285ede73fc (patch) | |
tree | e677d27b9f8a484f60ff54de182f4b786f64a35b /test/Mono.Linker.Tests.Cases | |
parent | e9b4688a35569d6865a67e40a8837fd044f1a23a (diff) |
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>
Diffstat (limited to 'test/Mono.Linker.Tests.Cases')
-rw-r--r-- | test/Mono.Linker.Tests.Cases/DataFlow/ByRefDataflow.cs | 30 |
1 files changed, 30 insertions, 0 deletions
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 (); + } + } } } |