Skip to content

Commit 9c6b2c1

Browse files
authored
Remove invalid assert in literal visitor (microsoft#6875)
The code has an assert when processing an OpLoad in the literal visitor to make sure that the result of the load is not a literal type. This is not always true. If there is a compiler-generated, temporary variable that gets its type from a literal, then the result type of the load will have to be decuded by the literal visitor. That is not always possible. However, the code already handle this situation correctly. If the result of the load is a literal type, then the function will return true without doing anything because `canDeduceTypeFromLitType` will return false, as it should. Fixes microsoft#6798
1 parent 7dcf2b4 commit 9c6b2c1

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

tools/clang/lib/SPIRV/LiteralTypeVisitor.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,6 @@ bool LiteralTypeVisitor::visit(SpirvLoad *inst) {
311311

312312
assert(inst->hasAstResultType());
313313
QualType resultType = inst->getAstResultType();
314-
assert(!isLitTypeOrVecOfLitType(resultType));
315314

316315
if (!canDeduceTypeFromLitType(pointerType, resultType))
317316
return true;
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// RUN: %dxc -T ps_6_0 -HV 2021 -E main -fcgl %s -spirv | FileCheck %s
2+
3+
// In this case, the types for the literals in the select cannot be deduced
4+
// because the cast to a bool does not force the literals to be any particular
5+
// bitwidth. So the types should fall back to a 32-bit signed interger.
6+
void foo(uint x) {
7+
// CHECK: %temp_var_ternary = OpVariable %_ptr_Function_int Function
8+
// CHECK: [[x:%[0-9]+]] = OpLoad %uint %x
9+
// CHECK: [[cond:%[0-9]+]] = OpULessThan %bool [[x]] %uint_64
10+
// CHECK: OpSelectionMerge %ternary_merge None
11+
// CHECK: OpBranchConditional [[cond]] %ternary_lhs %ternary_rhs
12+
// CHECK: %ternary_lhs = OpLabel
13+
// CHECK: OpStore %temp_var_ternary %int_1
14+
// CHECK: OpBranch %ternary_merge
15+
// CHECK: %ternary_rhs = OpLabel
16+
// CHECK: OpStore %temp_var_ternary %int_0
17+
// CHECK: OpBranch %ternary_merge
18+
// CHECK: %ternary_merge = OpLabel
19+
// CHECK: [[ld:%[0-9]+]] = OpLoad %int %temp_var_ternary
20+
// CHECK: [[res:%[0-9]+]] = OpINotEqual %bool [[ld]] %int_0
21+
// CHECK: OpStore %value [[res]]
22+
bool value = x < 64 ? 1 : 0;
23+
}
24+
25+
void main() {
26+
foo(2);
27+
}

0 commit comments

Comments
 (0)