[clang] Hlsl dst function (PR #133828)

Farzon Lotfi via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 2 08:08:33 PDT 2025


================
@@ -0,0 +1,37 @@
+// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm-only -disable-llvm-passes -verify
+
+float4 test_too_many_arg(float4 p0)
+{
+    dst(p0, p0, p0);
+  // expected-error at -1 {{no matching function for call to 'dst'}}
+  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate function not viable: requires 2 arguments, but 3 were provided}}
+  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate function not viable: requires 2 arguments, but 3 were provided}}
+  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate function not viable: requires 2 arguments, but 3 were provided}}
+}
+
+float4 test_no_second_arg(float4 p0)
+{
+    return dst(p0);
+  // expected-error at -1 {{no matching function for call to 'dst'}}
+  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate function not viable: requires 2 arguments, but 1 was provided}}
+  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate function not viable: requires 2 arguments, but 1 was provided}}
+  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate function not viable: requires 2 arguments, but 1 was provided}}
+}
+
+float4 test_no_args()
+{
+    return dst();
+  // expected-error at -1 {{no matching function for call to 'dst'}}
+  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate function not viable: requires 2 arguments, but 0 were provided}}
+  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate function not viable: requires 2 arguments, but 0 were provided}}
+  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate function not viable: requires 2 arguments, but 0 were provided}}
+}
+
+float4 test_3_components(float3 p0, float3 p1)
+{
+    return dst(p0, p1);
+  // expected-error at -1 {{no matching function for call to 'dst'}}
+  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate function not viable: no known conversion from 'vector<[...], 3>' to 'vector<[...], 4>' for 1st argument}}
+  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate function not viable: no known conversion from 'vector<float, 3>' to 'vector<half, 4>' for 1st argument}}
+  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate function not viable: no known conversion from 'vector<float, 3>' to 'vector<double, 4>' for 1st argument}}
+}
----------------
farzonl wrote:

Add a test case where we constrain the return vector to a smaller type like 
```hlsl
float2 test_float2_return(float4  p0, float4 p1) {
    return dst(p0, p1);
}
```
You should hit this code path: https://github.com/llvm/llvm-project/blob/3843dfeaf71a310d77a8c481dcea207a685fde8e/clang/lib/Sema/SemaChecking.cpp#L11785-L11792

and dst should emit a vector truncation warning.

https://github.com/llvm/llvm-project/pull/133828


More information about the cfe-commits mailing list