From 3fc90d47290298e14b49f131e31726270e882499 Mon Sep 17 00:00:00 2001 From: Yong He Date: Thu, 21 Jan 2021 14:44:01 -0800 Subject: Initialize unused fields in packAnyValue (#1669) --- source/slang/slang-ir-any-value-marshalling.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'source') diff --git a/source/slang/slang-ir-any-value-marshalling.cpp b/source/slang/slang-ir-any-value-marshalling.cpp index 9322ed0eb..b423f3f80 100644 --- a/source/slang/slang-ir-any-value-marshalling.cpp +++ b/source/slang/slang-ir-any-value-marshalling.cpp @@ -308,7 +308,16 @@ namespace Slang context.uintPtrType = builder.getPtrType(builder.getUIntType()); context.anyValueVar = resultVar; emitMarshallingCode(&builder, &context, concreteTypedVar); + context.validateAnyTypeSize(sharedContext->sink, type); + + // Initialize the rest of unused fields to 0 to prevent downstream compiler error. + for (uint32_t offset = context.fieldOffset; offset < (uint32_t)anyValInfo->fieldKeys.getCount(); offset++) + { + auto fieldAddr = builder.emitFieldAddress(builder.getUIntType(), resultVar, context.anyValInfo->fieldKeys[offset]); + builder.emitStore(fieldAddr, builder.getIntValue(builder.getUIntType(), 0)); + } + auto load = builder.emitLoad(resultVar); builder.emitReturn(load); return func; -- cgit v1.2.3