[clang] a1dfcc6 - [clang][bytecode] Fix D3DCOLORtoUBYTE4 hlsl test (#151819)
via cfe-commits
cfe-commits at lists.llvm.org
Sat Aug 2 07:18:42 PDT 2025
Author: Timm Baeder
Date: 2025-08-02T16:18:38+02:00
New Revision: a1dfcc6e8154bb8c188062f0a50436a27b54f763
URL: https://github.com/llvm/llvm-project/commit/a1dfcc6e8154bb8c188062f0a50436a27b54f763
DIFF: https://github.com/llvm/llvm-project/commit/a1dfcc6e8154bb8c188062f0a50436a27b54f763.diff
LOG: [clang][bytecode] Fix D3DCOLORtoUBYTE4 hlsl test (#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.
Added:
Modified:
clang/lib/AST/ByteCode/Compiler.cpp
clang/test/AST/ByteCode/hlsl.hlsl
Removed:
################################################################################
diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp
index 8b9e5e0cb318e..6e451acd4b6b4 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -331,6 +331,8 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) {
}
case CK_FloatingToIntegral: {
+ if (!CE->getType()->isIntegralOrEnumerationType())
+ return false;
if (!this->visit(SubExpr))
return false;
PrimType ToT = classifyPrim(CE);
@@ -1369,10 +1371,15 @@ bool Compiler<Emitter>::VisitVectorBinOp(const BinaryOperator *E) {
// BitAdd/BitOr/BitXor/Shl/Shr doesn't support bool type, we need perform the
// integer promotion.
bool NeedIntPromot = ElemT == PT_Bool && (E->isBitwiseOp() || E->isShiftOp());
- QualType PromotTy =
- Ctx.getASTContext().getPromotedIntegerType(Ctx.getASTContext().BoolTy);
- PrimType PromotT = classifyPrim(PromotTy);
- PrimType OpT = NeedIntPromot ? PromotT : ElemT;
+ QualType PromotTy;
+ PrimType PromotT = PT_Bool;
+ PrimType OpT = ElemT;
+ if (NeedIntPromot) {
+ PromotTy =
+ Ctx.getASTContext().getPromotedIntegerType(Ctx.getASTContext().BoolTy);
+ PromotT = classifyPrim(PromotTy);
+ OpT = PromotT;
+ }
auto getElem = [=](unsigned Offset, PrimType ElemT, unsigned Index) {
if (!this->emitGetLocal(PT_Ptr, Offset, E))
diff --git a/clang/test/AST/ByteCode/hlsl.hlsl b/clang/test/AST/ByteCode/hlsl.hlsl
index 073e430191991..60a7f44c443a2 100644
--- a/clang/test/AST/ByteCode/hlsl.hlsl
+++ b/clang/test/AST/ByteCode/hlsl.hlsl
@@ -29,3 +29,11 @@ export void fn() {
// smaller vector, then truncated to a float as a constant expression.
_Static_assert(((float2)float4(6, 5, 4, 3)).x == 6, "Woo!");
}
+
+int4 test_D3DCOLORtoUBYTE4(float4 p1) {
+ return D3DCOLORtoUBYTE4(p1);
+}
+
+int4 test_constant_inputs() {
+ return D3DCOLORtoUBYTE4(float4(0, 11.11, -50.5, 100));
+}
More information about the cfe-commits
mailing list