-
Notifications
You must be signed in to change notification settings - Fork 696
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ambiguous overload resolution chooses the wrong option with no warning #6938
Comments
DXC has some pretty special logic for overload resolution, which is further complicated by treating overload resolution of standard library functions different from user-defined functions. We can't warn on "ambiguous" overloads for two reasons (1) DXC doesn't think they're ambiguous, and (2) it would likely be extremely noisy because a lot of code depends on DXC's odd overload resolution behavior. What we can do is warn on the parameter conversions, and if you pass Changing the overload resolution algorithm for HLSL is planned and implemented in Clang. Clang treats the HLSL standard library functions as if they were any other function, and uses a best match algorithm that aligns more closely to C++. In Clang this code will fail to compile as an ambiguous overload. Here is a Compiler Explorer link demonstrating the warnings from DXC and the error from Clang. Given the context above I don't see any further actionable change for DXC, and the long-term fix is already implemented in Clang. I'm going to close this issue as not planned since we have no plans to make changes to DXC. |
Thanks @llvm-beanz, Is there a list of all such warning settings for DXC somewhere, or is it identical to Clang? I only found DiagnosticGroups.td. |
DXC is a fork of Clang 3.7. Many, but not all of the diagnostics supported by Clang 3.7 are supported by clang. There are additional diagnostics that DXC has added for HLSL. That file does list all the diagnostic groups supported in DXC, but we have no comprehensive documentation. |
Description
Consider the following test shader:
Here, one would expect that
i
is clamped to be between 0 and the value ofu
, making sure that negative values do not pass through. Instead, DXC chooses the version ofclamp
that works onuint
, castsi
touint
before clamping which makes the comparison with 0 useless, and then casts the result back toint
. Adding a castint(u)
makes it choose the right (signed) version ofclamp
.It's unclear to me if this is expected behavior from the HLSL point of view, but it would be great if we got a warning in such ambiguous (and unsafe) cases.
Steps to Reproduce
Compile the shader above with any CS profile.
Actual Behavior
DXIL output - note the
UMin
operation and lack ofUMax
which is optimized away.SPIRV output:
Environment
libdxcompiler.so: 1.8(dev;4746-75ff50ca); libdxil.so: 1.8
The text was updated successfully, but these errors were encountered: