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

Chris B via cfe-commits cfe-commits at lists.llvm.org
Wed May 1 12:27:58 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:

Personal preference. Since clang's AST output prints line numbers I find it useful to add the checks after the line I'm comparing so that as I'm modifying and writing tests the line numbers of the thing that relates to the `CHECK` remain stable.

We don't really have a standard for this in LLVM or Clang.

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


More information about the cfe-commits mailing list