Closed
Description
I am trying out #76261 (commit 733b3ed). The following file
struct node {
struct node *prev, *next;
};
struct list {
unsigned long n;
struct node *head, *tail;
};
void list_init(struct list *list) {
list->n = 0;
list->head = list->tail = 0;
}
struct lists {
struct list foo;
struct list bar;
};
int main(void) {
struct lists *lists = __builtin_malloc(sizeof(*lists));
if (lists) {
list_init(&lists->foo);
list_init(&lists->bar);
for (struct node *node = lists->foo.head; node; node = node->next);
}
return 0;
}
gives a false positive:
tavianator@tachyon $ ~/code/llvm/llvm-project/build/bin/clang -g -fsanitize=type foo.c -o foo
tavianator@tachyon $ ./foo
==478819==ERROR: TypeSanitizer: type-aliasing-violation on address 0x5590bcd3e2a8 (pc 0x559084519178 bp 0x7ffc5c0f0100 sp 0x7ffc5c0f00a8 tid 478819)
READ of size 8 at 0x5590bcd3e2a8 with type any pointer (in lists at offset 8) accesses an existing object of type any pointer (in list at offset 8)
#0 0x559084519177 in main /home/tavianator/code/bfs/foo.c:25:39