Skip to content

Commit 7f2bcc5

Browse files
tbaederrkrishna2803
authored andcommitted
[clang][bytecode] Fix D3DCOLORtoUBYTE4 hlsl test (llvm#151819)
HLSL is using CK_FloatingToIntegral casts to cast to vectors, which we don't support (neither does the current interpreter). Also fix a crash when trying to promote the HLSL bool, which can't be promoted it seems.
1 parent f645fd3 commit 7f2bcc5

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

clang/lib/AST/ByteCode/Compiler.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,8 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) {
331331
}
332332

333333
case CK_FloatingToIntegral: {
334+
if (!CE->getType()->isIntegralOrEnumerationType())
335+
return false;
334336
if (!this->visit(SubExpr))
335337
return false;
336338
PrimType ToT = classifyPrim(CE);
@@ -1369,10 +1371,15 @@ bool Compiler<Emitter>::VisitVectorBinOp(const BinaryOperator *E) {
13691371
// BitAdd/BitOr/BitXor/Shl/Shr doesn't support bool type, we need perform the
13701372
// integer promotion.
13711373
bool NeedIntPromot = ElemT == PT_Bool && (E->isBitwiseOp() || E->isShiftOp());
1372-
QualType PromotTy =
1373-
Ctx.getASTContext().getPromotedIntegerType(Ctx.getASTContext().BoolTy);
1374-
PrimType PromotT = classifyPrim(PromotTy);
1375-
PrimType OpT = NeedIntPromot ? PromotT : ElemT;
1374+
QualType PromotTy;
1375+
PrimType PromotT = PT_Bool;
1376+
PrimType OpT = ElemT;
1377+
if (NeedIntPromot) {
1378+
PromotTy =
1379+
Ctx.getASTContext().getPromotedIntegerType(Ctx.getASTContext().BoolTy);
1380+
PromotT = classifyPrim(PromotTy);
1381+
OpT = PromotT;
1382+
}
13761383

13771384
auto getElem = [=](unsigned Offset, PrimType ElemT, unsigned Index) {
13781385
if (!this->emitGetLocal(PT_Ptr, Offset, E))

clang/test/AST/ByteCode/hlsl.hlsl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,11 @@ export void fn() {
2929
// smaller vector, then truncated to a float as a constant expression.
3030
_Static_assert(((float2)float4(6, 5, 4, 3)).x == 6, "Woo!");
3131
}
32+
33+
int4 test_D3DCOLORtoUBYTE4(float4 p1) {
34+
return D3DCOLORtoUBYTE4(p1);
35+
}
36+
37+
int4 test_constant_inputs() {
38+
return D3DCOLORtoUBYTE4(float4(0, 11.11, -50.5, 100));
39+
}

0 commit comments

Comments
 (0)