Fix lvalue check in SPIR-V generation
There were several locations in TGlslangToSpvTraverser::handleUserFunctionCall testing for
whether a fn argument should be in the lvalue or rvalue array. They must get the same
result for indexing sanity, but had slightly different logic.
They're now forced into the same test.
diff --git a/SPIRV/GlslangToSpv.cpp b/SPIRV/GlslangToSpv.cpp
index b6c9705..a82867a 100755
--- a/SPIRV/GlslangToSpv.cpp
+++ b/SPIRV/GlslangToSpv.cpp
@@ -3529,6 +3529,11 @@
const glslang::TIntermSequence& glslangArgs = node->getSequence();
const glslang::TQualifierList& qualifiers = node->getQualifierList();
+ // Encapsulate lvalue logic, used in two places below, for safety.
+ const auto isLValue = [](int qualifier, const glslang::TType& paramType) -> bool {
+ return qualifier != glslang::EvqConstReadOnly || paramType.containsOpaque();
+ };
+
// See comments in makeFunctions() for details about the semantics for parameter passing.
//
// These imply we need a four step process:
@@ -3548,7 +3553,7 @@
glslangArgs[a]->traverse(this);
argTypes.push_back(¶mType);
// keep outputs and opaque objects as l-values, evaluate input-only as r-values
- if (qualifiers[a] != glslang::EvqConstReadOnly || paramType.containsOpaque()) {
+ if (isLValue(qualifiers[a], paramType)) {
// save l-value
lValues.push_back(builder.getAccessChain());
} else {
@@ -3573,7 +3578,7 @@
builder.setAccessChain(lValues[lValueCount]);
arg = builder.accessChainGetLValue();
++lValueCount;
- } else if (qualifiers[a] != glslang::EvqConstReadOnly) {
+ } else if (isLValue(qualifiers[a], paramType)) {
// need space to hold the copy
arg = builder.createVariable(spv::StorageClassFunction, convertGlslangToSpvType(paramType), "param");
if (qualifiers[a] == glslang::EvqIn || qualifiers[a] == glslang::EvqInOut) {
@@ -3600,7 +3605,7 @@
lValueCount = 0;
for (int a = 0; a < (int)glslangArgs.size(); ++a) {
const glslang::TType& paramType = glslangArgs[a]->getAsTyped()->getType();
- if (qualifiers[a] != glslang::EvqConstReadOnly) {
+ if (isLValue(qualifiers[a], paramType)) {
if (qualifiers[a] == glslang::EvqOut || qualifiers[a] == glslang::EvqInOut) {
spv::Id copy = builder.createLoad(spvArgs[a]);
builder.setAccessChain(lValues[lValueCount]);