Skip to content

Creating a nested MaybeUninit array unnecessarily calls memset #139355

Open
@abgros

Description

@abgros

This function calls memset:

fn create_uninit_array() -> [[MaybeUninit<u8>; 4]; 200] {
    [[MaybeUninit::<u8>::uninit(); 4]; 200]
}

and this one doesn't:

fn create_uninit_array_fast() -> [MaybeUninit<u8>; 800] {
    [MaybeUninit::<u8>::uninit(); 800]
}

I would have expected the same assembly to be generated for both cases.

See on Godbolt

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.C-optimizationCategory: An issue highlighting optimization opportunities or PRs implementing suchI-slowIssue: Problems and improvements with respect to performance of generated code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions