summaryrefslogtreecommitdiff
path: root/source/slang/ir-legalize-types.cpp
diff options
context:
space:
mode:
authorTim Foley <tfoleyNV@users.noreply.github.com>2018-06-13 11:18:44 -0700
committerGitHub <noreply@github.com>2018-06-13 11:18:44 -0700
commit860b0d604377d3635f6fa994993371399327129f (patch)
treebbe5d1376bf8bf1d5e9a865a0956f5e820bebec5 /source/slang/ir-legalize-types.cpp
parent167d8579870db18756c234755b197e4ded930b0e (diff)
Fixes related to handling of empty types (#600)
PR #577 tries to eliminate empty `struct` types by replacing them with a `LegalType::tuple` with zero elements, but this seems to run into problems in some cases, where we end up trying to match up `::none` values with empty `::tuple`s. An alternative way to handle this is to never create empty `LegalType::tuple`s (and the same for `LegalVal::tuple`), and instead create `LegalType::none` and `LegalVal::none`. PR #577 avoided this because there were various cases in the legalization logic that didn't robustly handle `LegalType::Flavor::none`. This PR thus includes two main changes: 1. Construct a `::none` type when we have an empty `struct` type. 2. Survery all places that handle the `::tuple` case and extend them to handle the `::none` case if it was missing. This fixes an issue filed in Falcor's internal GitLab as number 424.
Diffstat (limited to 'source/slang/ir-legalize-types.cpp')
-rw-r--r--source/slang/ir-legalize-types.cpp14
1 files changed, 14 insertions, 0 deletions
diff --git a/source/slang/ir-legalize-types.cpp b/source/slang/ir-legalize-types.cpp
index df3e190e1..9136ad671 100644
--- a/source/slang/ir-legalize-types.cpp
+++ b/source/slang/ir-legalize-types.cpp
@@ -21,6 +21,8 @@ namespace Slang
LegalVal LegalVal::tuple(RefPtr<TuplePseudoVal> tupleVal)
{
+ SLANG_ASSERT(tupleVal->elements.Count());
+
LegalVal result;
result.flavor = LegalVal::Flavor::tuple;
result.obj = tupleVal;
@@ -343,6 +345,9 @@ static LegalVal legalizeFieldAddress(
switch (legalPtrOperand.flavor)
{
+ case LegalVal::Flavor::none:
+ return LegalVal();
+
case LegalVal::Flavor::simple:
return LegalVal::simple(
builder->emitFieldAddress(
@@ -457,6 +462,9 @@ static LegalVal legalizeFieldExtract(
switch (legalStructOperand.flavor)
{
+ case LegalVal::Flavor::none:
+ return LegalVal();
+
case LegalVal::Flavor::simple:
return LegalVal::simple(
builder->emitFieldExtract(
@@ -571,6 +579,9 @@ static LegalVal legalizeGetElementPtr(
switch (legalPtrOperand.flavor)
{
+ case LegalVal::Flavor::none:
+ return LegalVal();
+
case LegalVal::Flavor::simple:
return LegalVal::simple(
builder->emitElementAddress(
@@ -679,6 +690,9 @@ static LegalVal legalizeMakeStruct(
switch(legalType.flavor)
{
+ case LegalType::Flavor::none:
+ return LegalVal();
+
case LegalType::Flavor::simple:
{
List<IRInst*> args;