HLSL: Validate implicit initializer assignment to opaque members.
Fixes #1091.
diff --git a/hlsl/hlslGrammar.cpp b/hlsl/hlslGrammar.cpp
index 88eacd9..515922e 100755
--- a/hlsl/hlslGrammar.cpp
+++ b/hlsl/hlslGrammar.cpp
@@ -2426,6 +2426,9 @@
node = parseContext.handleFunctionCall(token.loc, constructor, node);
}
+ if (node == nullptr)
+ return false;
+
// If this is simply a constant, we can use it directly.
if (node->getAsConstantUnion())
return true;
@@ -2862,7 +2865,7 @@
parseContext.handleFunctionArgument(constructorFunction, arguments, node);
node = parseContext.handleFunctionCall(loc, constructorFunction, arguments);
- return true;
+ return node != nullptr;
} else {
// This could be a parenthesized constructor, ala (int(3)), and we just accepted
// the '(int' part. We must back up twice.
@@ -3072,7 +3075,7 @@
// hook it up
node = parseContext.handleFunctionCall(arguments->getLoc(), constructorFunction, arguments);
- return true;
+ return node != nullptr;
}
return false;
@@ -3120,7 +3123,7 @@
// call
node = parseContext.handleFunctionCall(loc, function, arguments);
- return true;
+ return node != nullptr;
}
// arguments
diff --git a/hlsl/hlslParseHelper.cpp b/hlsl/hlslParseHelper.cpp
index a336bd7..706173d 100755
--- a/hlsl/hlslParseHelper.cpp
+++ b/hlsl/hlslParseHelper.cpp
@@ -4981,8 +4981,10 @@
// It's a constructor, of type 'type'.
//
result = handleConstructor(loc, arguments, type);
- if (result == nullptr)
+ if (result == nullptr) {
error(loc, "cannot construct with these arguments", type.getCompleteString().c_str(), "");
+ return nullptr;
+ }
}
} else {
//
@@ -7736,6 +7738,14 @@
return addConstructor(loc, initList, arrayType);
} else if (type.isStruct()) {
+ // do we have implicit assignments to opaques?
+ for (size_t i = initList->getSequence().size(); i < type.getStruct()->size(); ++i) {
+ if ((*type.getStruct())[i].type->containsOpaque()) {
+ error(loc, "cannot implicitly initialize opaque members", "initializer list", "");
+ return nullptr;
+ }
+ }
+
// lengthen list to be long enough
lengthenList(loc, initList->getSequence(), static_cast<int>(type.getStruct()->size()), scalarInit);