SPV return from main: Simplify a legacy design such returns are not jumps to exit block.
Structured control-flow rules allow leaving the middle of a construct through
a return, but not through a jump to a block that does a return.
Addresses issue #58.
diff --git a/SPIRV/GlslangToSpv.cpp b/SPIRV/GlslangToSpv.cpp
index 0240dea..37ee52f 100755
--- a/SPIRV/GlslangToSpv.cpp
+++ b/SPIRV/GlslangToSpv.cpp
@@ -454,7 +454,7 @@
if (! mainTerminated) {
spv::Block* lastMainBlock = shaderEntry->getLastBlock();
builder.setBuildPoint(lastMainBlock);
- builder.leaveFunction(true);
+ builder.leaveFunction();
}
}
@@ -854,7 +854,7 @@
} else {
if (inMain)
mainTerminated = true;
- builder.leaveFunction(inMain);
+ builder.leaveFunction();
inMain = false;
}
@@ -1276,12 +1276,10 @@
builder.createLoopContinue();
break;
case glslang::EOpReturn:
- if (inMain)
- builder.makeMainReturn();
- else if (node->getExpression())
+ if (node->getExpression())
builder.makeReturn(false, builder.accessChainLoad(convertGlslangToSpvType(node->getExpression()->getType())));
else
- builder.makeReturn();
+ builder.makeReturn(false);
builder.clearAccessChain();
break;