Browse Source

[spirv] Handle failures properly so error messages bubble up. (#1940)

Ehsan 6 years ago
parent
commit
f8eefcd63a

+ 7 - 1
tools/clang/lib/SPIRV/SpirvEmitter.cpp

@@ -2350,7 +2350,8 @@ SpirvInstruction *SpirvEmitter::doCastExpr(const CastExpr *expr) {
     else if (subExprType->isArrayType()) {
       auto *valInstr = InitListHandler(astContext, *this)
                            .processCast(expr->getType(), subExpr);
-      valInstr->setRValue();
+      if (valInstr)
+        valInstr->setRValue();
       return valInstr;
     }
 
@@ -4758,6 +4759,11 @@ SpirvEmitter::processAssignment(const Expr *lhs, SpirvInstruction *rhs,
 
 void SpirvEmitter::storeValue(SpirvInstruction *lhsPtr,
                               SpirvInstruction *rhsVal, QualType lhsValType) {
+  // Defend against nullptr source or destination so errors can bubble up to the
+  // user.
+  if(!lhsPtr || !rhsVal)
+    return;
+
   if (const auto *refType = lhsValType->getAs<ReferenceType>())
     lhsValType = refType->getPointeeType();
 

+ 12 - 0
tools/clang/test/CodeGenSPIRV/fn.param.unsized-array.hlsl

@@ -0,0 +1,12 @@
+// Run: %dxc -T vs_6_0 -E main
+
+// CHECK: 7: error: initializer for type 'unsigned int []' unimplemented
+void foo(uint value[]) {
+  value[0] = 1;
+}
+
+float4 main() : SV_Position {
+  uint Mem[2];
+  foo(Mem);
+  return float4(Mem[0], Mem[1], 0, 0);
+}

+ 6 - 0
tools/clang/unittests/SPIRV/CodeGenSpirvTest.cpp

@@ -482,6 +482,12 @@ TEST_F(FileTest, FunctionInOutParamNoNeedToCopy) {
   // annotation does not create temporary variables
   runFileTest("fn.param.inout.no-copy.hlsl");
 }
+TEST_F(FileTest, FunctionParamUnsizedArray) {
+  // Unsized ararys as function params are not supported.
+  runFileTest("fn.param.unsized-array.hlsl", Expect::Failure);
+}
+
+
 TEST_F(FileTest, FunctionFowardDeclaration) {
   runFileTest("fn.foward-declaration.hlsl");
 }