llvm / llvm/llvm-project

[HLSL] Erroring on valid overload sets with array parameters + crash

Open
#178,509 3 comments 0 reactions 1 assignee Claimed by @spall View on GitHub
HLSL
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

This case crashes due to a null pointer. (the crash is not the important part just incidental)
```
export void fn1(int foo[2]);
export void fn1(inout int foo[2]);
```
https://godbolt.org/z/95K87ed37
https://godbolt.org/z/s5YYozzc5 (the reverse order also crashes)

This case is equivalent but successfully produces the diagnostic the above case is attempting to produce.
```
export void fn1(in int foo[2]);
export void fn1(inout int foo[2]);
```
the error: (NOTE: this is a valid overload set in DXC)
```
source>:2:27: error: conflicting parameter qualifier 'inout' on parameter 'foo'
2 | export void fn1(inout int foo[2]);
| ^
:1:24: note: previously declared as 'in' here
1 | export void fn1(in int foo[2]);
```
https://godbolt.org/z/qMr3Pro6c

A similar overload set using vectors instead of arrays is legal in both Clang and DXC.
```
export void fn1(inout int2 foo);
export void fn1(int2 foo);
```
https://godbolt.org/z/zcn3Ghh6h

In summary there seems to be an issue with how overloads for functions with array parameters are handled and incidentally there is an associated crash.

Additional context:
Clang disallows this overload set very intentionally while DXC allows it.
The comment of the function which disallows this:
```
// HLSL parameter declarations for inout and out must match between
// declarations. In HLSL inout and out are ambiguous at the call site,
// but have different calling behavior, so you cannot overload a
// method based on a difference between inout and out annotations.
```
```
export void fn1(inout int2 foo);
export void fn1(out int2 foo);

```
https://godbolt.org/z/jocdMnTrM

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.