[clang] [HLSL] Shore up floating point conversions (PR #90222)

Chris B via cfe-commits cfe-commits at lists.llvm.org
Fri Apr 26 11:32:07 PDT 2024


================
@@ -0,0 +1,229 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -fnative-half-type -finclude-default-header -Wconversion -verify -o - %s
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -fnative-half-type -finclude-default-header -ast-dump %s | FileCheck %s
+
+// This test verifies floating point type implicit conversion ranks for overload
+// resolution. In HLSL the built-in type ranks are half < float < double. This
+// applies to both scalar and vector types.
+
+// HLSL allows implicit truncation fo types, so it differentiates between
+// promotions (converting to larger types) and conversions (converting to
+// smaller types). Promotions are preferred over conversions. Promotions prefer
+// promoting to the next lowest type in the ranking order. Conversions prefer
+// converting to the next highest type in the ranking order.
+
+void HalfFloatDouble(double D);
+void HalfFloatDouble(float F);
+void HalfFloatDouble(half H);
+
+// CHECK: FunctionDecl {{.*}} used HalfFloatDouble 'void (double)'
----------------
llvm-beanz wrote:

Yea, the ones at the top are just sanity checking and could be removed.

The checks for the `Case*` function decls below force FileCheck to scan up to the declaration, which can improve error reporting if anything goes wrong in the test because it can give you a "last match" marker or show if your match skipped ahead.

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


More information about the cfe-commits mailing list