Просмотр исходного кода

[spirv] Avoid nullptr reference to get errors to the surface.

Ehsan Nasiri 6 лет назад
Родитель
Сommit
0814267e96

+ 3 - 3
tools/clang/lib/SPIRV/SPIRVEmitter.cpp

@@ -4537,7 +4537,7 @@ SPIRVEmitter::doHLSLVectorElementExpr(const HLSLVectorElementExpr *expr) {
   if (accessorSize == 1) {
     auto *baseInfo = doExpr(baseExpr);
 
-    if (baseSize == 1) {
+    if (!baseInfo || baseSize == 1) {
       // Selecting one element from a size-1 vector. The underlying vector is
       // already treated as a scalar.
       return baseInfo;
@@ -4620,7 +4620,7 @@ SpirvInstruction *SPIRVEmitter::doMemberExpr(const MemberExpr *expr) {
       expr, /*rawIndex*/ false, /*rawIndices*/ nullptr, &indices);
   auto *instr = loadIfAliasVarRef(base);
 
-  if (!indices.empty()) {
+  if (instr && !indices.empty()) {
     instr =
         turnIntoElementPtr(base->getType(), instr, expr->getType(), indices);
   }
@@ -5423,7 +5423,7 @@ SpirvInstruction *SPIRVEmitter::createVectorSplat(const Expr *scalarExpr,
     scalarVal = doExpr(scalarExpr);
   }
 
-  if (size == 1) {
+  if (!scalarVal || size == 1) {
     // Just return the scalar value for vector splat with size 1.
     // Note that can be used as an lvalue, so we need to carry over
     // the lvalueness for non-constant cases.

+ 1 - 1
tools/clang/test/CodeGenSPIRV/type.buffer.struct.error1.hlsl

@@ -1,4 +1,4 @@
-// Run: %dxc -T vs_6_0 -E main
+// Run: %dxc -T ps_6_0 -E main
 
 struct S {
     float4 a;

+ 1 - 1
tools/clang/test/CodeGenSPIRV/type.buffer.struct.error2.hlsl

@@ -1,4 +1,4 @@
-// Run: %dxc -T vs_6_0 -E main
+// Run: %dxc -T ps_6_0 -E main
 
 struct S {
     float2 a;

+ 1 - 1
tools/clang/test/CodeGenSPIRV/type.buffer.struct.error3.hlsl

@@ -1,4 +1,4 @@
-// Run: %dxc -T vs_6_0 -E main
+// Run: %dxc -T ps_6_0 -E main
 
 struct B {
     float2 b;