llvm / llvm/llvm-project

[HLSL] Interlocked* functions reject an original_value argument whose signedness differs from the destination

Open
#224,151 0 comments 0 reactions 1 assignee Claimed by @bob80905 View on GitHub
HLSL
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

### Summary

Every `Interlocked*` function fails overload resolution when the `out original_value` argument has a different signedness from the destination. DXC accepts the same code and converts, per [this godbolt](https://godbolt.org/z/4M8xvTTYq) from @inbelic.
And this is an example of InterlockedAdd: https://godbolt.org/z/4Gc1r4jv7

Only `original_value` is affected. A `value` argument with mismatched signedness converts and compiles with `-Wsign-conversion`.

### Reproducer

```hlsl
groupshared int gs_i32;

export void mixed_types(int value, out uint original) {
InterlockedAdd(gs_i32, value, original);
}
```

### Actual

```
error: no matching function for call to 'InterlockedAdd'
note: candidate function not viable: no known conversion from 'uint'
(aka 'unsigned int') to 'int &' for 3rd argument
```

16 candidates are listed.

### Expected

The call compiles, and `original` receives the converted result. A `-Wsign-conversion` warning is acceptable.

### Scope

All `Interlocked*` free functions reject this.

| Case | Result |
| --- | --- |
| `value` signedness differs | compiles, `-Wsign-conversion` |
| `original_value` signedness differs | **error** |
| `value` width differs (`int64_t` into `int`) | compiles, `-Wshorten-64-to-32` |

### Notes
Each overload declares a concrete `int &` or `uint &`, so overload resolution finds no viable candidate and never reaches writeback.

A fix must update the tests that record the current behaviour: `mismatched_orig_type` in `clang/test/SemaHLSL/BuiltIns/InterlockedAdd-errors.hlsl` and `InterlockedMin-errors.hlsl`.

### Environment

`clang -cc1 -std=hlsl202x -finclude-default-header -triple dxil-pc-shadermodel6.6-compute`. Reproduces on `spirv-pc-vulkan1.3-compute` too.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.