Browse Source

[spirv] Use proper signedness in LowerTypeVisitor for LitInt. (#2100)

Ehsan 6 năm trước cách đây
mục cha
commit
c0890437df

+ 2 - 1
tools/clang/lib/SPIRV/LowerTypeVisitor.cpp

@@ -300,7 +300,8 @@ const SpirvType *LowerTypeVisitor::lowerType(QualType type,
         // Example:
         // void main() { 1.0; 1; }
         case BuiltinType::LitInt:
-          return spvContext.getUIntType(32);
+          return type->isSignedIntegerType() ? spvContext.getSIntType(32)
+                                             : spvContext.getUIntType(32);
         case BuiltinType::LitFloat: {
           return spvContext.getFloatType(32);
 

+ 4 - 2
tools/clang/test/CodeGenSPIRV/literal.unused.hlsl

@@ -8,8 +8,10 @@
 
 float4 main() : SV_Target {
 
-// CHECK: %uint_0 = OpConstant %uint 0
-  0;
+// CHECK: %int_2 = OpConstant %int 2
+  2;
+// CHECK: %uint_2 = OpConstant %uint 2
+  2u;
 // CHECK: %float_0 = OpConstant %float 0
   0.0;
 

+ 2 - 2
tools/clang/test/CodeGenSPIRV/ternary-op.cond-op.hlsl

@@ -117,8 +117,8 @@ void main() {
   // CHECK-NEXT:       {{%\d+}} = OpSelect %uint {{%\d+}} %uint_9 [[inner]]
   uint h = cond ? 9 : (cond ? 1 : 2);
 
-  //CHECK:      [[i_int:%\d+]] = OpSelect %uint {{%\d+}} %uint_1 %uint_0
-  //CHECK-NEXT:       {{%\d+}} = OpINotEqual %bool [[i_int]] %uint_0
+  //CHECK:      [[i_int:%\d+]] = OpSelect %int {{%\d+}} %int_1 %int_0
+  //CHECK-NEXT:       {{%\d+}} = OpINotEqual %bool [[i_int]] %int_0
   bool i = cond ? 1 : 0;
 
   // CHECK:     [[foo:%\d+]] = OpFunctionCall %uint %foo