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

Compilation Warnings Related to Uninitialized Struct Fields #4872

Closed
karel-tomanec opened this issue Aug 20, 2024 · 0 comments · Fixed by #4911
Closed

Compilation Warnings Related to Uninitialized Struct Fields #4872

karel-tomanec opened this issue Aug 20, 2024 · 0 comments · Fixed by #4911
Assignees
Labels
goal:client support Feature or fix needed for a current slang user. kind:enhancement a desirable new feature, option, or behavior

Comments

@karel-tomanec
Copy link

Issue Summary:
The provided code produces the following compilation warnings:

warning 41020: exiting constructor without initializing field 'barycentrics'
warning 41020: exiting constructor without initializing field 'primitiveIndex'

These warnings occur in the struct HitInfo, which has two fields: float3 barycentrics and uint primitiveIndex. The warnings indicate that the constructors (__init functions) may not be properly initializing these fields.

Code Snippet:

struct HitInfo
{
    float3 barycentrics;
    uint primitiveIndex;
    
    [[mutating]] void init(float2 hitBarycentrics, uint hitPrimitiveIndex)
    {
        barycentrics = { 1.0 - hitBarycentrics.x - hitBarycentrics.y, hitBarycentrics.x, hitBarycentrics.y };
        primitiveIndex = hitPrimitiveIndex;
    }

    __init(float2 hitBarycentrics, uint hitPrimitiveIndex)
    {
        init(hitBarycentrics, hitPrimitiveIndex);
    }

    __init(BuiltInTriangleIntersectionAttributes attr)
    {
        init(attr.barycentrics, PrimitiveIndex());
    }
}

Root Cause:
The warnings are triggered because the compiler may not recognize that the init function, which is a [[mutating]] method, properly initializes the struct members barycentrics and primitiveIndex. Since these members are not explicitly initialized within the __init functions themselves, the compiler assumes they might remain uninitialized, hence the warnings.

Suggestion for Improvement:
Would it be possible to enhance compiler to check whether [[mutating]] functions called within constructors are initializing all the struct members?

@ArielG-NV ArielG-NV added kind:enhancement a desirable new feature, option, or behavior goal:client support Feature or fix needed for a current slang user. labels Aug 21, 2024
@bmillsNV bmillsNV added this to the Q3 2024 (Summer) milestone Aug 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
goal:client support Feature or fix needed for a current slang user. kind:enhancement a desirable new feature, option, or behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants