Skip to content

Failure to infer alignment of pointer returned from malloc #126440

@Kmeakin

Description

@Kmeakin

According to cppreference, malloc should always return pointers that are at least as aligned as max_align_t. So the alignment test should always be true. gcc optimises this but LLVM does not:

https://godbolt.org/z/GnbEfbseE
https://alive2.llvm.org/ce/z/QZign2

bool src(void) {
    void* p = malloc(1);
    return ((uintptr_t)p % alignof(max_align_t)) == 0;
}

bool tgt(void) { return true; }

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions