<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/105960>105960</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[TySan] False positive with struct containing two lists
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
tavianator
</td>
</tr>
</table>
<pre>
I am trying out #76261 (commit 733b3ed3f7441453889157834e0a5b6c288bf976). The following file
```c
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:
```console
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
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJx8VU2P4ygQ_TXkUkqEC3_ggw_pTUfa00o9fW9hDAkrApEh6c4c9revIPZ0kulpyQqkKNd7Va_KiBDMzinVkeqJVJuFOMW9H7sozkY4Ef246P1w6f4GcYA4XozbgT9FIMiaGusCCHLpDwcToWGsZ2pguinLoqwY521RNZyVioqqryVy3uu2qQm2K4DXvQLtrfXvKaQ2VhG6IXQ9_db0-sjr_xDHk4zg_KCANE-za3tnx_VxVGeCf6WtUx-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