<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/85714>85714</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[HLSL] Default literal floating point types to smallest supported type
</td>
</tr>
<tr>
<th>Labels</th>
<td>
HLSL
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
llvm-beanz
</td>
</tr>
</table>
<pre>
In C/C++ literal floating point values default as double. In HLSL the behavior is a bit more complicated.
In DXC, literal types were given their own type which was then preserved through instantiation of builtin functions. This ends up being extremely complicated and fragile as templates and other type inference were added to the language.
For Clang, we can accomplish a comparable source-compatible implementation by having the default type for floating point literals resolve to the smallest supported type (i.e. 32-bits by default or 16-bit if 16-bit types are enabled).
This implementation will prevent some bugs that exist in DXC today like the bugs described in [this issue](https://github.com/microsoft/hlsl-specs/issues/73) or [this one](https://github.com/microsoft/DirectXShaderCompiler/issues/2432), which incorrectly emit 64-bit types instead of 32-bit.
It also is a _way_ simpler approach to the problem that will not collide with template type deduction or other language features that rely on type inference.
### Acceptance Criteria
A set of tests that demonstrate floating point literal values resolving to the smallest appropriate floating point type and code generation verifying correctness.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUVEGP2zgP_TXKhZjAkeMmOeQwkyD4CvTW79BbQUu0zV1ZMiQ6afbXLyQn3cGgXWCBADEoiXyP75GYEvee6KiaN9WcVzjLEOLRuev40hL6v1ZtsPfjZw8npS8npd-UfgPHQhEddC6gsO9hCuwFruhmSmCpw9kJYAIb5tbRGj57-N-Xr19ABoKWBrxyiMAJEFoWGEMkMGGcHBsUsmtVvarq9bOH87eT0qef9eQ-UYIbRYKer-RzPo4Qbr4cwW1gM8ANUz7wMEVKFK9kQYYY5n4A9knQC6Nw8BA6aGd2wh662ZscS2v4_8AJyNsE8wQtZXr0QyKN5O7vUQJ6C13Enh1lrkLj5FAolYMgA8UFFfuOInlDC3K0NiMKpR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