[clang] [HLSL] Add matrix support to atan2 (PR #194984)

Deric C. via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 29 21:31:21 PDT 2026


Icohedron wrote:

> hmm I was expecting to see a change in `clang/include/clang/Basic/HLSLIntrinsics.td`? I'm guessing we were implicilty generating matrix signatures just not testing it?
> 
> cc: @Icohedron

There are no matrix overloads being generated.

The `atan2(float4x4, float4x4)` appears to be resolving to `atan2(float, float)` because matrix-to-scalar conversion is possible.

However, `atan2` is an alias of `__builtin_elementwise_atan2` which has the `CustomTypeChecking` attribute. Due to this, the matrix-to-scalar truncation is actually skipped due to these lines in SemaExpr.cpp:
https://github.com/llvm/llvm-project/blob/bcbad84a7c56c99c0d628e2b24fac856c87bb98a/clang/lib/Sema/SemaExpr.cpp#L7206-L7211

It bails out before performing the matrix-to-scalar truncation via `ConvertArgumentsForCall` which would have occurred on line 7255
https://github.com/llvm/llvm-project/blob/bcbad84a7c56c99c0d628e2b24fac856c87bb98a/clang/lib/Sema/SemaExpr.cpp#L7254-L7257

So the arguments are not truncated (they remain as `float4x4`) and proceed to pass through custom type check which this PR has modified (`clang/lib/Sema/SemaHLSL.cpp`). Hence, the test passes.

There are also no implicit matrix truncation warnings because there is no matrix truncation occurring (it got skipped).

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


More information about the cfe-commits mailing list