瀏覽代碼

[spirv] Ignore const-ness when comparing types. (#985)

Ehsan 7 年之前
父節點
當前提交
231619361a
共有 2 個文件被更改,包括 12 次插入0 次删除
  1. 4 0
      tools/clang/lib/SPIRV/SPIRVEmitter.cpp
  2. 8 0
      tools/clang/test/CodeGenSPIRV/binary-op.logical-and.hlsl

+ 4 - 0
tools/clang/lib/SPIRV/SPIRVEmitter.cpp

@@ -62,6 +62,10 @@ bool patchConstFuncTakesHullOutputPatch(FunctionDecl *pcf) {
 
 /// Returns true if the two types are the same scalar or vector type.
 bool isSameScalarOrVecType(QualType type1, QualType type2) {
+  // Consider cases such as 'const bool' and 'bool' to be the same type.
+  type1.removeLocalConst();
+  type2.removeLocalConst();
+
   {
     QualType scalarType1 = {}, scalarType2 = {};
     if (TypeTranslator::isScalarType(type1, &scalarType1) &&

+ 8 - 0
tools/clang/test/CodeGenSPIRV/binary-op.logical-and.hlsl

@@ -24,4 +24,12 @@ void main() {
 // CHECK-NEXT: OpStore %q [[and2]]
     k = i && j;
     q = o && p;
+
+// The result of '&&' could be 'const bool'. In such cases, make sure
+// the result type is correct.
+// CHECK:        [[a1:%\d+]] = OpLoad %bool %a
+// CHECK-NEXT:   [[b1:%\d+]] = OpLoad %bool %b
+// CHECK-NEXT: [[and3:%\d+]] = OpLogicalAnd %bool [[a1]] [[b1]]
+// CHECK-NEXT:      {{%\d+}} = OpCompositeConstruct %v2bool [[and3]] %true
+    bool2 t = bool2(a&&b, true);
 }