Преглед на файлове

[spirv] Fix FloatingToIntegral cast of lvalues. (#1568)

Ehsan преди 7 години
родител
ревизия
3777fd31b2
променени са 2 файла, в които са добавени 17 реда и са изтрити 4 реда
  1. 2 2
      tools/clang/lib/SPIRV/SPIRVEmitter.cpp
  2. 15 2
      tools/clang/test/CodeGenSPIRV/cf.switch.opswitch.hlsl

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

@@ -2241,8 +2241,8 @@ SpirvEvalInfo SPIRVEmitter::doCastExpr(const CastExpr *expr) {
     if (const uint32_t valueId = tryToEvaluateAsConst(expr))
       return SpirvEvalInfo(valueId).setConstant().setRValue();
 
-    const auto valueId =
-        castToInt(doExpr(subExpr), subExprType, toType, subExpr->getExprLoc());
+    const auto valueId = castToInt(loadIfGLValue(subExpr), subExprType, toType,
+                                   subExpr->getExprLoc());
     return SpirvEvalInfo(valueId).setRValue();
   }
   case CastKind::CK_FloatingCast:

+ 15 - 2
tools/clang/test/CodeGenSPIRV/cf.switch.opswitch.hlsl

@@ -342,6 +342,19 @@ void main() {
 // CHECK-NEXT: %switch_merge_8 = OpLabel
   }
 
-// CHECK-NEXT: OpReturn
-// CHECK-NEXT: OpFunctionEnd
+
+  //////////////////////////////////////////////////////////////////
+  // Using float as selector results in multiple casts in the AST //
+  //////////////////////////////////////////////////////////////////
+  float sel;
+// CHECK:      [[floatSelector:%\d+]] = OpLoad %float %sel
+// CHECK-NEXT:           [[sel:%\d+]] = OpConvertFToS %int [[floatSelector]]
+// CHECK-NEXT:                          OpSelectionMerge %switch_merge_9 None
+// CHECK-NEXT:                          OpSwitch [[sel]] %switch_merge_9 0 %switch_0_0
+  switch (sel) {
+  case 0:
+    result = 0;
+    break;
+  }
+
 }