瀏覽代碼

[spirv] Test for returning a struct from function. (#637)

Ehsan 8 年之前
父節點
當前提交
82463dd3d1
共有 2 個文件被更改,包括 28 次插入0 次删除
  1. 25 0
      tools/clang/test/CodeGenSPIRV/cf.return.struct.hlsl
  2. 3 0
      tools/clang/unittests/SPIRV/CodeGenSPIRVTest.cpp

+ 25 - 0
tools/clang/test/CodeGenSPIRV/cf.return.struct.hlsl

@@ -0,0 +1,25 @@
+// Run: %dxc -T ps_6_0 -E main
+
+struct S {
+  int x;
+  float y;
+};
+
+S foo();
+
+void main() {
+
+// CHECK: [[foo:%\d+]] = OpFunctionCall %S %foo
+// CHECK: OpStore %result [[foo]]
+  S result = foo();
+}
+
+S foo() {
+// CHECK: %s = OpVariable %_ptr_Function_S Function
+// CHECK: OpStore %s {{%\d+}}
+  S s = {1, 2.0};
+
+// CHECK: [[s:%\d+]] = OpLoad %S %s
+// CHECK: OpReturnValue [[s]]
+  return s;
+}

+ 3 - 0
tools/clang/unittests/SPIRV/CodeGenSPIRVTest.cpp

@@ -299,6 +299,9 @@ TEST_F(FileTest, EarlyReturnFloat4) {
   runFileTest("cf.return.early.float4.hlsl");
   runFileTest("cf.return.early.float4.hlsl");
 }
 }
 
 
+// For returning a structure
+TEST_F(FileTest, ReturnStruct) { runFileTest("cf.return.struct.hlsl"); }
+
 // For control flows
 // For control flows
 TEST_F(FileTest, ControlFlowNestedIfForStmt) { runFileTest("cf.if.for.hlsl"); }
 TEST_F(FileTest, ControlFlowNestedIfForStmt) { runFileTest("cf.if.for.hlsl"); }
 TEST_F(FileTest, ControlFlowLogicalAnd) { runFileTest("cf.logical-and.hlsl"); }
 TEST_F(FileTest, ControlFlowLogicalAnd) { runFileTest("cf.logical-and.hlsl"); }