In physical addressing, functions can return pointers
authorDavid Neto <dneto@google.com>
Mon, 13 Jun 2016 21:26:09 +0000 (17:26 -0400)
committerDavid Neto <dneto@google.com>
Tue, 14 Jun 2016 15:00:39 +0000 (11:00 -0400)
Fixes https://github.com/KhronosGroup/SPIRV-Tools/issues/229

source/validate_id.cpp
test/ValidateID.cpp

index edb559b..2364b99 100644 (file)
@@ -1710,12 +1710,11 @@ bool idUsage::isValid<SpvOpReturnValue>(const spv_instruction_t* inst,
                      << value.second.type_id << "' is missing or void.";
     return false;
   }
-  if (SpvOpTypePointer == valueType.second.opcode) {
-    DIAG(valueIndex) << "OpReturnValue value's type <id> '"
-                     << value.second.type_id
-                     << "' is a pointer, but a pointer can only be an operand "
-                        "to OpLoad, OpStore, OpAccessChain, or "
-                        "OpInBoundsAccessChain.";
+  if (addressingModel == SpvAddressingModelLogical &&
+      SpvOpTypePointer == valueType.second.opcode) {
+    DIAG(valueIndex)
+        << "OpReturnValue value's type <id> '" << value.second.type_id
+        << "' is a pointer, which is invalid in the Logical addressing model.";
     return false;
   }
   // NOTE: Find OpFunction
index 6cff0ab..486f480 100644 (file)
@@ -1564,8 +1564,26 @@ TEST_F(ValidateID, OpReturnValueIsVoid) {
   CHECK(spirv, SPV_ERROR_INVALID_ID);
 }
 
-TEST_F(ValidateID, OpReturnValueIsVariable) {
+TEST_F(ValidateID, OpReturnValueIsVariableInPhysical) {
+  // It's valid to return a pointer in a physical addressing model.
   const char* spirv = R"(
+     OpMemoryModel Physical32 OpenCL
+%1 = OpTypeVoid
+%2 = OpTypeInt 32 0
+%3 = OpTypePointer Private %2
+%4 = OpTypeFunction %3
+%5 = OpFunction %3 None %4
+%6 = OpLabel
+%7 = OpVariable %3 Function
+     OpReturnValue %7
+     OpFunctionEnd)";
+  CHECK(spirv, SPV_SUCCESS);
+}
+
+TEST_F(ValidateID, OpReturnValueIsVariableInLogical) {
+  // It's invalid to return a pointer in a physical addressing model.
+  const char* spirv = R"(
+     OpMemoryModel Logical GLSL450
 %1 = OpTypeVoid
 %2 = OpTypeInt 32 0
 %3 = OpTypePointer Private %2