[clang] [llvm] [HLSL] Implement the `reflect` HLSL function (PR #122992)

Farzon Lotfi via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 15 09:49:31 PST 2025


================
@@ -0,0 +1,33 @@
+// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm-only -disable-llvm-passes -verify
+
+float test_no_second_arg(float2 p0) {
+  return reflect(p0);
+  // expected-error at -1 {{no matching function for call to 'reflect'}}
+  // 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 template not viable: requires 2 arguments, but 1 was provided}}
+  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate function template not viable: requires 2 arguments, but 1 was provided}}
+}
+
+float test_too_many_arg(float2 p0) {
+  return reflect(p0, p0, p0);
+  // expected-error at -1 {{no matching function for call to 'reflect'}}
+  // 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 template not viable: requires 2 arguments, but 3 were provided}}
+  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate function template not viable: requires 2 arguments, but 3 were provided}}
+}
+
+float test_double_inputs(double p0, double p1) {
+  return reflect(p0, p1);
+  // expected-error at -1  {{call to 'reflect' is ambiguous}}
+  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate function}}
+  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate function}}
+}
+
+float test_int_inputs(int p0, int p1) {
+  return reflect(p0, p1);
+  // expected-error at -1  {{call to 'reflect' is ambiguous}}
----------------
farzonl wrote:

This is correct. see `ScalarOverloadResolution.hlsl` When there are more than one overload we get ambiguous. and when there is just one implementation, we get expected warning.

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


More information about the llvm-commits mailing list