summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2021-01-21 14:44:01 -0800
committerGitHub <noreply@github.com>2021-01-21 14:44:01 -0800
commit3fc90d47290298e14b49f131e31726270e882499 (patch)
tree56037e4b50c86189095bad320df0d69a824b4b35 /source
parentb52fcf9c85695ee90074df7f9a6eeba9f34ddaeb (diff)
Initialize unused fields in packAnyValue (#1669)
Diffstat (limited to 'source')
-rw-r--r--source/slang/slang-ir-any-value-marshalling.cpp9
1 files changed, 9 insertions, 0 deletions
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;