[TySan] Type aliasing violations not detected on returned struct. (original) (raw)

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.