From 2266fe8afd516dfa893d64ef4d38e7163d40a35d Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sat, 2 Dec 2023 22:20:11 +0100 Subject: [PATCH] Zero-initialize constructor target instance in HLSL --- .../SyntaxRewriters/ShaderSourceRewriter.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/ComputeSharp.SourceGeneration.Hlsl/SyntaxRewriters/ShaderSourceRewriter.cs b/src/ComputeSharp.SourceGeneration.Hlsl/SyntaxRewriters/ShaderSourceRewriter.cs index 206870e5..a001c26e 100644 --- a/src/ComputeSharp.SourceGeneration.Hlsl/SyntaxRewriters/ShaderSourceRewriter.cs +++ b/src/ComputeSharp.SourceGeneration.Hlsl/SyntaxRewriters/ShaderSourceRewriter.cs @@ -690,7 +690,7 @@ internal sealed partial class ShaderSourceRewriter : HlslSourceRewriter // // static __ctor() // { - // __this; + // __this = ()0; // // __this.__ctor__init(); // @@ -702,8 +702,9 @@ internal sealed partial class ShaderSourceRewriter : HlslSourceRewriter .WithParameterList(processedMethod.ParameterList) .AddBodyStatements( LocalDeclarationStatement( - VariableDeclaration(IdentifierName(returnTypeHlslIdentifier)) - .AddVariables(VariableDeclarator(Identifier("__this")))), + VariableDeclaration(IdentifierName(returnTypeHlslIdentifier)).AddVariables( + VariableDeclarator(Identifier("__this")).WithInitializer(EqualsValueClause( + CastExpression(targetType, LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(0))))))), ExpressionStatement( InvocationExpression( MemberAccessExpression(