Skip to content

Commit 5ba57a8

Browse files
authored
[HLSL] Update Sema Checking Diagnostics for builtins (#138429)
Update how Sema Checking is done for HLSL builtins to allow for better error messages, mainly using 'err_builtin_invalid_arg_type'. Try to follow the formula outlined in issue #134721 Closes #134721
1 parent cd8094e commit 5ba57a8

24 files changed

+282
-337
lines changed

clang/include/clang/Basic/Builtins.td

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4909,10 +4909,16 @@ def HLSLClamp : LangBuiltin<"HLSL_LANG"> {
49094909
let Prototype = "void(...)";
49104910
}
49114911

4912-
def HLSLCross: LangBuiltin<"HLSL_LANG"> {
4913-
let Spellings = ["__builtin_hlsl_cross"];
4912+
def HLSLCrossFloat: LangBuiltin<"HLSL_LANG"> {
4913+
let Spellings = ["__builtin_hlsl_crossf32"];
49144914
let Attributes = [NoThrow, Const];
4915-
let Prototype = "void(...)";
4915+
let Prototype = "_ExtVector<3, float>(_ExtVector<3, float>, _ExtVector<3, float>)";
4916+
}
4917+
4918+
def HLSLCrossHalf: LangBuiltin<"HLSL_LANG"> {
4919+
let Spellings = ["__builtin_hlsl_crossf16"];
4920+
let Attributes = [NoThrow, Const];
4921+
let Prototype = "_ExtVector<3, __fp16>(_ExtVector<3, __fp16>, _ExtVector<3, __fp16>)";
49164922
}
49174923

49184924
def HLSLDegrees : LangBuiltin<"HLSL_LANG"> {
@@ -4971,7 +4977,7 @@ def HLSLLerp : LangBuiltin<"HLSL_LANG"> {
49714977

49724978
def HLSLMad : LangBuiltin<"HLSL_LANG"> {
49734979
let Spellings = ["__builtin_hlsl_mad"];
4974-
let Attributes = [NoThrow, Const];
4980+
let Attributes = [NoThrow, Const, CustomTypeChecking];
49754981
let Prototype = "void(...)";
49764982
}
49774983

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12711,7 +12711,7 @@ def err_builtin_invalid_arg_type: Error<
1271112711
// An 'or' if non-empty second and third components are combined
1271212712
"%plural{0:|:%plural{0:|:or }2}3"
1271312713
// Third component: floating-point types
12714-
"%select{|floating-point}3"
12714+
"%select{|floating-point|16 or 32 bit floating-point}3"
1271512715
// A space after a non-empty third component
1271612716
"%plural{0:|: }3"
1271712717
"%plural{[0,3]:type|:types}1 (was %4)">;

clang/lib/CodeGen/CGHLSLBuiltins.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,8 @@ Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned BuiltinID,
366366
/*ReturnType=*/OpX->getType(), Intr,
367367
ArrayRef<Value *>{OpX, OpMin, OpMax}, nullptr, "hlsl.clamp");
368368
}
369-
case Builtin::BI__builtin_hlsl_cross: {
369+
case Builtin::BI__builtin_hlsl_crossf16:
370+
case Builtin::BI__builtin_hlsl_crossf32: {
370371
Value *Op0 = EmitScalarExpr(E->getArg(0));
371372
Value *Op1 = EmitScalarExpr(E->getArg(1));
372373
assert(E->getArg(0)->getType()->hasFloatingRepresentation() &&

clang/lib/Headers/hlsl/hlsl_alias_intrinsics.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1882,10 +1882,10 @@ uint64_t4 reversebits(uint64_t4);
18821882
/// x[0] * y[1] - y[0] * x[1]
18831883

18841884
_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
1885-
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_cross)
1885+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_crossf16)
18861886
half3 cross(half3, half3);
18871887

1888-
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_cross)
1888+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_crossf32)
18891889
float3 cross(float3, float3);
18901890

18911891
//===----------------------------------------------------------------------===//

0 commit comments

Comments
 (0)