Skip to content
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

[DXIL] Null pointer exception due to double floating-point literals in fmod intrinsic #6410

Closed
LukasBanana opened this issue Mar 13, 2024 · 3 comments · Fixed by #6543 · May be fixed by #6411
Closed

[DXIL] Null pointer exception due to double floating-point literals in fmod intrinsic #6410

LukasBanana opened this issue Mar 13, 2024 · 3 comments · Fixed by #6543 · May be fixed by #6411
Assignees
Labels
bug Bug, regression, crash crash DXC crashing or hitting an assert rca Candidate for a root cause analysis discussion sm6.8 Shader Model 6.8 validation Related to validation or signing

Comments

@LukasBanana
Copy link
Contributor

Description
There is a null pointer exception during the translation of FMod (TranslateFMod) when the arguments are floating-point literals, because the latest DXC version does not reduce them to float during compilation. The null pointer occurs inside TrivialDxilUnaryOperation(OP::OpCode::Frc, absDiv, hlslOP, Builder) because Frc won't find the respective function for double-precision floats. Previous versions had this assertion in OP::GetOpFunc:

DXASSERT(IsOverloadLegal(opCode, pOverloadType), "otherwise the caller requested illegal operation overload (eg HLSL function with unsupported types for mapped intrinsic function)");

But the latest version only returns a null pointer that is not handled correctly:

if (!IsOverloadLegal(opCode, pOverloadType))
  return nullptr;

Steps to Reproduce
This issue can be reproduced with the latest version of the main branch and compiling with dxc -E PSMain -T ps_6_0 (or by following https://godbolt.org/z/beK7oPsx6):

float4 PSMain() : SV_Target {
    return (float4)fmod(1.0, 2.0);
}

Making the floating-point literals explicitly single-precision with the f suffix compiles fine:

float4 PSMain() : SV_Target {
    return (float4)fmod(1.0f, 2.0f);
}

This does not reproduce with other intrinsics such as sin.

@LukasBanana LukasBanana added bug Bug, regression, crash needs-triage Awaiting triage labels Mar 13, 2024
@damyanp damyanp added this to the Release 1.8.2403.1 milestone Mar 14, 2024
@damyanp
Copy link
Member

damyanp commented Mar 14, 2024

Possibly introduced in #6302

@damyanp damyanp added crash DXC crashing or hitting an assert sm6.8 Shader Model 6.8 validation Related to validation or signing rca Candidate for a root cause analysis discussion and removed needs-triage Awaiting triage labels Mar 14, 2024
@LukasBanana
Copy link
Contributor Author

@damyanp this definitely looks like it introduced the null pointer exception, since all those assertions were removed and the null pointer isn't handled. The fix @tex3d linked to this issue works for us, although it's not a long term fix as he mentioned it can still crash with explicit double variables.

@damyanp
Copy link
Member

damyanp commented Mar 14, 2024

See #6419 - plan is to revert #6302 from the release branch and to continue to use this issue to track a more permament fix.

@damyanp damyanp removed this from the Release 1.8.2403.1 milestone Mar 14, 2024
@damyanp damyanp added the needs-triage Awaiting triage label Mar 14, 2024
@damyanp damyanp added this to the Next Release milestone Mar 15, 2024
@damyanp damyanp removed the needs-triage Awaiting triage label Mar 15, 2024
python3kgae added a commit that referenced this issue Apr 26, 2024
This change removes the IsOverloadLegal check in OP::GetOpFunc.

It will permit the generation of illegal DXIL operations. Subsequently,
the validation should catch these illegal DXIL operations if they are
not optimized later in SimplifyDxilCall.


Fixes #6410
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug, regression, crash crash DXC crashing or hitting an assert rca Candidate for a root cause analysis discussion sm6.8 Shader Model 6.8 validation Related to validation or signing
Projects
Status: Done
Archived in project
4 participants