From e69a0b5835591100e369d7bab3b8dd15300da34c Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Wed, 3 Nov 2021 20:15:10 +0100 Subject: [PATCH] Disabled [SkipLocalsInit] generation on unsupported targets --- src/ComputeSharp.SourceGenerators/IShaderGenerator.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/ComputeSharp.SourceGenerators/IShaderGenerator.cs b/src/ComputeSharp.SourceGenerators/IShaderGenerator.cs index 29b01464..986e19ca 100644 --- a/src/ComputeSharp.SourceGenerators/IShaderGenerator.cs +++ b/src/ComputeSharp.SourceGenerators/IShaderGenerator.cs @@ -89,8 +89,9 @@ public sealed partial class IShaderGenerator : ISourceGenerator Literal("This method is not intended to be used directly by user code")))))) }; - // Add [SkipLocalsInit] if the target project allows it - if (context.Compilation.Options is CSharpCompilationOptions { AllowUnsafe: true }) + // Add [SkipLocalsInit] if the target project allows it and can access it + if (context.Compilation.Options is CSharpCompilationOptions { AllowUnsafe: true } && + context.Compilation.GetTypeByMetadataName("System.Runtime.CompilerServices.SkipLocalsInit") is not null) { attributes.Add(AttributeList(SingletonSeparatedList(Attribute(IdentifierName("global::System.Runtime.CompilerServices.SkipLocalsInit"))))); }