Quellcode durchsuchen

[spirv] stop compilation if decl evaluation results in an error. (#2756)

* [spirv] Stop compilation if decl evaluation results in an error.

* Address code review comments.

Co-authored-by: Jaebaek Seo <[email protected]>
Ehsan vor 5 Jahren
Ursprung
Commit
821e4e99b5
22 geänderte Dateien mit 226 neuen und 92 gelöschten Zeilen
  1. 5 3
      tools/clang/lib/SPIRV/SpirvEmitter.cpp
  2. 12 0
      tools/clang/test/CodeGenSPIRV/type.append-structured-buffer.array.error.hlsl
  3. 12 0
      tools/clang/test/CodeGenSPIRV/type.consume-structured-buffer.array.error.hlsl
  4. 0 4
      tools/clang/test/CodeGenSPIRV/type.structured-buffer.array.error.hlsl
  5. 0 18
      tools/clang/test/CodeGenSPIRV/vk.attribute.invalid.hlsl
  6. 14 0
      tools/clang/test/CodeGenSPIRV/vk.attribute.push-constant.invalid.hlsl
  7. 14 0
      tools/clang/test/CodeGenSPIRV/vk.attribute.shader-record-nv.invalid.hlsl
  8. 0 1
      tools/clang/test/CodeGenSPIRV/vk.layout.non-fp-matrix.array.struct.error.hlsl
  9. 0 1
      tools/clang/test/CodeGenSPIRV/vk.layout.non-fp-matrix.error.hlsl
  10. 0 5
      tools/clang/test/CodeGenSPIRV/vk.push-constant.multiple.hlsl
  11. 0 29
      tools/clang/test/CodeGenSPIRV/vk.spec-constant.error.hlsl
  12. 16 0
      tools/clang/test/CodeGenSPIRV/vk.spec-constant.error.not.segfault.hlsl
  13. 13 0
      tools/clang/test/CodeGenSPIRV/vk.spec-constant.error1.hlsl
  14. 13 0
      tools/clang/test/CodeGenSPIRV/vk.spec-constant.error2.hlsl
  15. 13 0
      tools/clang/test/CodeGenSPIRV/vk.spec-constant.error3.hlsl
  16. 13 0
      tools/clang/test/CodeGenSPIRV/vk.spec-constant.error4.hlsl
  17. 13 0
      tools/clang/test/CodeGenSPIRV/vk.spec-constant.error5.hlsl
  18. 0 23
      tools/clang/test/CodeGenSPIRV/vk.subpass-input.error.hlsl
  19. 15 0
      tools/clang/test/CodeGenSPIRV/vk.subpass-input.missing-attr.error.hlsl
  20. 16 0
      tools/clang/test/CodeGenSPIRV/vk.subpass-input.static.error.hlsl
  21. 16 0
      tools/clang/test/CodeGenSPIRV/vk.subpass-input.type.error.hlsl
  22. 41 8
      tools/clang/unittests/SPIRV/CodeGenSpirvTest.cpp

+ 5 - 3
tools/clang/lib/SPIRV/SpirvEmitter.cpp

@@ -600,6 +600,9 @@ void SpirvEmitter::HandleTranslationUnit(ASTContext &context) {
     } else {
       doDecl(decl);
     }
+
+    if (context.getDiagnostics().hasErrorOccurred())
+      return;
   }
 
   // Translate all functions reachable from the entry function.
@@ -609,11 +612,10 @@ void SpirvEmitter::HandleTranslationUnit(ASTContext &context) {
     const FunctionInfo *curEntryOrCallee = workQueue[i];
     spvContext.setCurrentShaderModelKind(curEntryOrCallee->shaderModelKind);
     doDecl(curEntryOrCallee->funcDecl);
+    if (context.getDiagnostics().hasErrorOccurred())
+      return;
   }
 
-  if (context.getDiagnostics().hasErrorOccurred())
-    return;
-
   const spv_target_env targetEnv = featureManager.getTargetEnv();
 
   // Addressing and memory model are required in a valid SPIR-V module.

+ 12 - 0
tools/clang/test/CodeGenSPIRV/type.append-structured-buffer.array.error.hlsl

@@ -0,0 +1,12 @@
+// Run: %dxc -T ps_6_0 -E main
+
+struct T {
+  float  a;
+  float3 b;
+};
+
+AppendStructuredBuffer<T> myAppendStructuredBuffer[];
+
+void main() {}
+
+// CHECK: :8:27: error: arrays of RW/append/consume structured buffers unsupported

+ 12 - 0
tools/clang/test/CodeGenSPIRV/type.consume-structured-buffer.array.error.hlsl

@@ -0,0 +1,12 @@
+// Run: %dxc -T ps_6_0 -E main
+
+struct T {
+  float  a;
+  float3 b;
+};
+
+ConsumeStructuredBuffer<T> myConsumeStructuredBuffer[2];
+
+void main() {}
+
+// CHECK: :8:28: error: arrays of RW/append/consume structured buffers unsupported

+ 0 - 4
tools/clang/test/CodeGenSPIRV/type.structured-buffer.array.error.hlsl

@@ -6,11 +6,7 @@ struct T {
 };
 
 RWStructuredBuffer<T> myRWStructuredBuffer[4];
-AppendStructuredBuffer<T> myAppendStructuredBuffer[];
-ConsumeStructuredBuffer<T> myConsumeStructuredBuffer[2];
 
 void main() {}
 
 // CHECK: :8:23: error: arrays of RW/append/consume structured buffers unsupported
-// CHECK: :9:27: error: arrays of RW/append/consume structured buffers unsupported
-// CHECK: :10:28: error: arrays of RW/append/consume structured buffers unsupported

+ 0 - 18
tools/clang/test/CodeGenSPIRV/vk.attribute.invalid.hlsl

@@ -1,18 +0,0 @@
-// Run: %dxc -T vs_6_0 -E main
-
-struct S {
-    float f;
-};
-
-[[vk::push_constant, vk::binding(5)]]
-S pcs;
-
-[[vk::shader_record_nv, vk::binding(6)]]
-ConstantBuffer<S> recordBuf;
-
-float main() : A {
-    return 1.0;
-}
-
-// CHECK: :7:3: error: vk::push_constant attribute cannot be used together with vk::binding attribute
-// CHECK: :10:3: error: vk::shader_record_nv attribute cannot be used together with vk::binding attribute

+ 14 - 0
tools/clang/test/CodeGenSPIRV/vk.attribute.push-constant.invalid.hlsl

@@ -0,0 +1,14 @@
+// Run: %dxc -T vs_6_0 -E main
+
+struct S {
+    float f;
+};
+
+[[vk::push_constant, vk::binding(5)]]
+S pcs;
+
+float main() : A {
+    return 1.0;
+}
+
+// CHECK: :7:3: error: vk::push_constant attribute cannot be used together with vk::binding attribute

+ 14 - 0
tools/clang/test/CodeGenSPIRV/vk.attribute.shader-record-nv.invalid.hlsl

@@ -0,0 +1,14 @@
+// Run: %dxc -T vs_6_0 -E main
+
+struct S {
+    float f;
+};
+
+[[vk::shader_record_nv, vk::binding(6)]]
+ConstantBuffer<S> recordBuf;
+
+float main() : A {
+    return 1.0;
+}
+
+// CHECK: :7:3: error: vk::shader_record_nv attribute cannot be used together with vk::binding attribute

+ 0 - 1
tools/clang/test/CodeGenSPIRV/vk.layout.non-fp-matrix.array.struct.error.hlsl

@@ -35,4 +35,3 @@ void main()
 
 
 // CHECK: :11:21: error: externally initialized non-floating-point column-major matrices not supported yet
-// CHECK: :30:21: error: externally initialized non-floating-point column-major matrices not supported yet

+ 0 - 1
tools/clang/test/CodeGenSPIRV/vk.layout.non-fp-matrix.error.hlsl

@@ -17,4 +17,3 @@ void main() {
 }
 
 // CHECK: :6:5: error: externally initialized non-floating-point column-major matrices not supported yet
-// CHECK: :13:23: error: externally initialized non-floating-point column-major matrices not supported yet

+ 0 - 5
tools/clang/test/CodeGenSPIRV/vk.push-constant.multiple.hlsl

@@ -10,9 +10,6 @@ S pcs1;
 [[vk::push_constant]] // error
 S pcs2;
 
-[[vk::push_constant]] // error
-S pcs3;
-
 float main() : A {
     return 1.0;
 }
@@ -20,5 +17,3 @@ float main() : A {
 // CHECK: :10:3: error: cannot have more than one push constant block
 // CHECK: :7:3: note: push constant block previously defined here
 
-// CHECK: :13:3: error: cannot have more than one push constant block
-// CHECK: :7:3: note: push constant block previously defined here

+ 0 - 29
tools/clang/test/CodeGenSPIRV/vk.spec-constant.error.hlsl

@@ -1,29 +0,0 @@
-// Run: %dxc -T vs_6_0 -E main
-
-[[vk::constant_id(0)]]
-const bool sc0 = true;
-
-[[vk::constant_id(1)]]
-const bool sc1 = sc0; // error
-
-[[vk::constant_id(2)]]
-const double sc2 = 42; // error
-
-[[vk::constant_id(3)]]
-const int sc3; // error
-
-[[vk::constant_id(4)]]
-const int sc4 = sc3 + sc3; // error
-
-[[vk::constant_id(5)]]
-static const int sc5 = 1; // error
-
-float main() : A {
-    return 1.0;
-}
-
-// CHECK:  :7:18: error: unsupported specialization constant initializer
-// CHECK:  :10:1: error: unsupported specialization constant type
-// CHECK: :13:11: error: missing default value for specialization constant
-// CHECK: :16:17: error: unsupported specialization constant initializer
-// CHECK: :19:18: error: specialization constant must be externally visible

+ 16 - 0
tools/clang/test/CodeGenSPIRV/vk.spec-constant.error.not.segfault.hlsl

@@ -0,0 +1,16 @@
+// Run: %dxc -T cs_6_0 -E main
+
+[[vk::binding(0)]] RWByteAddressBuffer src;
+#define LOCAL_SIZE 32
+
+[[vk::constant_id(0)]] int gBufferSize;
+[[vk::constant_id(1)]] int gSetValue;
+
+[numthreads(LOCAL_SIZE, 1, 1)]
+void main(uint3 dispatchThreadID : SV_DispatchThreadID)
+{
+  if ((4 * dispatchThreadID.x) < gBufferSize)
+    src.Store4(4 * dispatchThreadID.x, uint4(gSetValue, gSetValue, gSetValue, gSetValue));
+}
+
+// CHECK: :6:28: error: missing default value for specialization constant

+ 13 - 0
tools/clang/test/CodeGenSPIRV/vk.spec-constant.error1.hlsl

@@ -0,0 +1,13 @@
+// Run: %dxc -T vs_6_0 -E main
+
+[[vk::constant_id(0)]]
+const bool sc0 = true;
+
+[[vk::constant_id(1)]]
+const bool sc1 = sc0; // error
+
+float main() : A {
+    return 1.0;
+}
+
+// CHECK: :7:18: error: unsupported specialization constant initializer

+ 13 - 0
tools/clang/test/CodeGenSPIRV/vk.spec-constant.error2.hlsl

@@ -0,0 +1,13 @@
+// Run: %dxc -T vs_6_0 -E main
+
+[[vk::constant_id(0)]]
+const bool sc0 = true;
+
+[[vk::constant_id(2)]]
+const double sc2 = 42; // error
+
+float main() : A {
+    return 1.0;
+}
+
+// CHECK:  :7:1: error: unsupported specialization constant type

+ 13 - 0
tools/clang/test/CodeGenSPIRV/vk.spec-constant.error3.hlsl

@@ -0,0 +1,13 @@
+// Run: %dxc -T vs_6_0 -E main
+
+[[vk::constant_id(0)]]
+const bool sc0 = true;
+
+[[vk::constant_id(3)]]
+const int sc3; // error
+
+float main() : A {
+    return 1.0;
+}
+
+// CHECK: :7:11: error: missing default value for specialization constant

+ 13 - 0
tools/clang/test/CodeGenSPIRV/vk.spec-constant.error4.hlsl

@@ -0,0 +1,13 @@
+// Run: %dxc -T vs_6_0 -E main
+
+[[vk::constant_id(0)]]
+const bool sc0 = true;
+
+[[vk::constant_id(4)]]
+const int sc4 = sc0 + sc0; // error
+
+float main() : A {
+    return 1.0;
+}
+
+// CHECK: :7:17: error: unsupported specialization constant initializer

+ 13 - 0
tools/clang/test/CodeGenSPIRV/vk.spec-constant.error5.hlsl

@@ -0,0 +1,13 @@
+// Run: %dxc -T vs_6_0 -E main
+
+[[vk::constant_id(0)]]
+const bool sc0 = true;
+
+[[vk::constant_id(5)]]
+static const int sc5 = 1; // error
+
+float main() : A {
+    return 1.0;
+}
+
+// CHECK: :7:18: error: specialization constant must be externally visible

+ 0 - 23
tools/clang/test/CodeGenSPIRV/vk.subpass-input.error.hlsl

@@ -1,23 +0,0 @@
-// Run: %dxc -T ps_6_0 -E main
-
-struct S {
-    float  a;
-    float2 b;
-    float  c;
-};
-
-SubpassInput SI0; // error
-
-[[vk::input_attachment_index(0)]]
-SubpassInput<S> SI1; // error
-
-[[vk::input_attachment_index(1)]]
-static SubpassInput SI2; // error
-
-void main() {
-
-}
-
-// CHECK:  :9:14: error: missing vk::input_attachment_index attribute
-// CHECK: :12:17: error: only scalar/vector types allowed as SubpassInput(MS) parameter type
-// CHECK: :15:21: error: SubpassInput(MS) must be externally visible

+ 15 - 0
tools/clang/test/CodeGenSPIRV/vk.subpass-input.missing-attr.error.hlsl

@@ -0,0 +1,15 @@
+// Run: %dxc -T ps_6_0 -E main
+
+struct S {
+    float  a;
+    float2 b;
+    float  c;
+};
+
+SubpassInput SI0; // error
+
+void main() {
+
+}
+
+// CHECK:  :9:14: error: missing vk::input_attachment_index attribute

+ 16 - 0
tools/clang/test/CodeGenSPIRV/vk.subpass-input.static.error.hlsl

@@ -0,0 +1,16 @@
+// Run: %dxc -T ps_6_0 -E main
+
+struct S {
+    float  a;
+    float2 b;
+    float  c;
+};
+
+[[vk::input_attachment_index(1)]]
+static SubpassInput SI2; // error
+
+void main() {
+
+}
+
+// CHECK: :10:21: error: SubpassInput(MS) must be externally visible

+ 16 - 0
tools/clang/test/CodeGenSPIRV/vk.subpass-input.type.error.hlsl

@@ -0,0 +1,16 @@
+// Run: %dxc -T ps_6_0 -E main
+
+struct S {
+    float  a;
+    float2 b;
+    float  c;
+};
+
+[[vk::input_attachment_index(0)]]
+SubpassInput<S> SI1; // error
+
+void main() {
+
+}
+
+// CHECK: :10:17: error: only scalar/vector types allowed as SubpassInput(MS) parameter type

+ 41 - 8
tools/clang/unittests/SPIRV/CodeGenSpirvTest.cpp

@@ -109,9 +109,17 @@ TEST_F(FileTest, StructuredByteBufferArray) {
   setBeforeHLSLLegalization();
   runFileTest("type.structured-buffer.array.hlsl");
 }
-TEST_F(FileTest, StructuredByteBufferArrayError) {
+TEST_F(FileTest, StructuredBufferArrayError) {
   runFileTest("type.structured-buffer.array.error.hlsl", Expect::Failure);
 }
+TEST_F(FileTest, AppendStructuredBufferArrayError) {
+  runFileTest("type.append-structured-buffer.array.error.hlsl",
+              Expect::Failure);
+}
+TEST_F(FileTest, ConsumeStructuredBufferArrayError) {
+  runFileTest("type.consume-structured-buffer.array.error.hlsl",
+              Expect::Failure);
+}
 TEST_F(FileTest, AppendConsumeStructuredBufferTypeCast) {
   runFileTest("type.append.consume-structured-buffer.cast.hlsl");
 }
@@ -1586,8 +1594,11 @@ TEST_F(FileTest, SpirvDebugControlUnknown) {
 TEST_F(FileTest, VulkanAttributeErrors) {
   runFileTest("vk.attribute.error.hlsl", Expect::Failure);
 }
-TEST_F(FileTest, VulkanAttributeInvalidUsages) {
-  runFileTest("vk.attribute.invalid.hlsl", Expect::Failure);
+TEST_F(FileTest, VulkanAttributePushConstantInvalidUsages) {
+  runFileTest("vk.attribute.push-constant.invalid.hlsl", Expect::Failure);
+}
+TEST_F(FileTest, VulkanAttributeShaderRecordNVInvalidUsages) {
+  runFileTest("vk.attribute.shader-record-nv.invalid.hlsl", Expect::Failure);
 }
 
 TEST_F(FileTest, VulkanCLOptionInvertYVS) {
@@ -1747,8 +1758,23 @@ TEST_F(FileTest, VulkanSpecConstantInit) {
 TEST_F(FileTest, VulkanSpecConstantUsage) {
   runFileTest("vk.spec-constant.usage.hlsl");
 }
-TEST_F(FileTest, VulkanSpecConstantError) {
-  runFileTest("vk.spec-constant.error.hlsl", Expect::Failure);
+TEST_F(FileTest, VulkanSpecConstantError1) {
+  runFileTest("vk.spec-constant.error1.hlsl", Expect::Failure);
+}
+TEST_F(FileTest, VulkanSpecConstantError2) {
+  runFileTest("vk.spec-constant.error2.hlsl", Expect::Failure);
+}
+TEST_F(FileTest, VulkanSpecConstantError3) {
+  runFileTest("vk.spec-constant.error3.hlsl", Expect::Failure);
+}
+TEST_F(FileTest, VulkanSpecConstantError4) {
+  runFileTest("vk.spec-constant.error4.hlsl", Expect::Failure);
+}
+TEST_F(FileTest, VulkanSpecConstantError5) {
+  runFileTest("vk.spec-constant.error5.hlsl", Expect::Failure);
+}
+TEST_F(FileTest, VulkanSpecConstantErrorNotSegfault) {
+  runFileTest("vk.spec-constant.error.not.segfault.hlsl", Expect::Failure);
 }
 
 TEST_F(FileTest, VulkanLayoutCBufferMatrixZpr) {
@@ -1895,15 +1921,22 @@ TEST_F(FileTest, VulkanSubpassInput) { runFileTest("vk.subpass-input.hlsl"); }
 TEST_F(FileTest, VulkanSubpassInputBinding) {
   runFileTest("vk.subpass-input.binding.hlsl");
 }
-TEST_F(FileTest, VulkanSubpassInputError) {
-  runFileTest("vk.subpass-input.error.hlsl", Expect::Failure);
+TEST_F(FileTest, VulkanSubpassInputError1) {
+  runFileTest("vk.subpass-input.missing-attr.error.hlsl", Expect::Failure);
+}
+TEST_F(FileTest, VulkanSubpassInputError2) {
+  runFileTest("vk.subpass-input.type.error.hlsl", Expect::Failure);
+}
+TEST_F(FileTest, VulkanSubpassInputError3) {
+  runFileTest("vk.subpass-input.static.error.hlsl", Expect::Failure);
 }
 
 TEST_F(FileTest, NonFpColMajorError) {
   runFileTest("vk.layout.non-fp-matrix.error.hlsl", Expect::Failure);
 }
 TEST_F(FileTest, NonFpColMajorErrorArrayStruct) {
-  runFileTest("vk.layout.non-fp-matrix.array.struct.error.hlsl", Expect::Failure);
+  runFileTest("vk.layout.non-fp-matrix.array.struct.error.hlsl",
+              Expect::Failure);
 }
 
 TEST_F(FileTest, NamespaceFunctions) {