[clang] Adding `asuint` implementation to hlsl (PR #107292)

via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 6 14:18:12 PDT 2024


================
@@ -387,6 +387,23 @@ float3 asin(float3);
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_asin)
 float4 asin(float4);
 
+//===----------------------------------------------------------------------===//
+// asuint builtins
+//===----------------------------------------------------------------------===//
+
+/// \fn uint asuint(T Val)
+/// \brief Interprets the bit pattern of x as an unsigned integer.
+/// \param Val The input value.
+
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_asuint)
+uint asuint(float);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_asuint)
+uint2 asuint(float2);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_asuint)
+uint3 asuint(float3);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_asuint)
+uint4 asuint(float4);
----------------
joaosaffran wrote:

When I add the `uint asuint(int)` and `uint asuint(uint)`, I am seeing the following error:

```
/workspace/llvm-project/clang/test/SemaHLSL/BuiltIns/asuint-errors.hlsl:11:12: error: call to 'asuint' is ambiguous
   11 |     return asuint(p1);
      |            ^~~~~~
/workspace/llvm-project/build-debug/lib/clang/20/include/hlsl/hlsl_intrinsics.h:399:6: note: candidate function
  399 | uint asuint(float);
      |      ^
/workspace/llvm-project/build-debug/lib/clang/20/include/hlsl/hlsl_intrinsics.h:408:6: note: candidate function
  408 | uint asuint(uint);
      |      ^
/workspace/llvm-project/build-debug/lib/clang/20/include/hlsl/hlsl_intrinsics.h:417:6: note: candidate function
  417 | uint asuint(int);
```

It seems like clang is not being able to figure out which function to call. Please let me know if you have a solution for this issue.

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


More information about the cfe-commits mailing list