Skip to content

Bogus alignment mismatch diagnostic #125916

@PJBoy

Description

@PJBoy

Testcase ( https://godbolt.org/z/o1b83cEbG )

#include <cstdint>

using UnalignedType [[gnu::aligned(1)]] = struct
{
    uint32_t x;
};

alignas(4) UnalignedType alignedVariable{};

void f(UnalignedType)
{}

static_assert(alignof(UnalignedType) == 1);
static_assert(alignof(alignedVariable) == 4);

int main()
{
    f(alignedVariable);
}

The diagnostic reported is

passing 1-byte aligned argument to 4-byte aligned parameter 'this' of 'UnalignedType' may result in an unaligned pointer access [-Walign-mismatch]
18 | f(alignedVariable);
| ^

However, the argument alignedVariable is 4-byte aligned, and I would expect UnalignedType to be a one-byte aligned parameter; the reported alignments seem to be reversed

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzer

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions