Skip to content

[TySan] Type aliasing violations not detected on returned struct. #168577

@BStott6

Description

@BStott6

Reproducer (C):

struct S {
    int a;
    float b;
};

struct S returns_s(void) {
    struct S x;
    x.a = 1;
    x.b = 1.0f;
    return x;
}

int main(void) {
    struct S x = returns_s();

    // This should produce an aliasing violation.
    float aliased = *((float *) &x.a);
}

When compiled with clang -fsanitize=type, the sanitizer does not catch the type aliasing violation reading x.a through a float pointer. If x has its members assigned in main, then the aliasing violation is correctly reported.

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