<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/119615>119615</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
TySan doesn't catch strict-aliasing violation when using struct initializers
</td>
</tr>
<tr>
<th>Labels</th>
<td>
compiler-rt:tysan
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
fhahn
</td>
</tr>
</table>
<pre>
The initial version of TySan (https://github.com/llvm/llvm-project/pull/76261) doesn't properly report the first strict aliasing violation in the test case below
```
#include <stdio.h>
__attribute__((noinline))
void print(char**v) {
printf("%s\n", v[0]);
}
int main() {
char *values[2] = { "value", 0};
void **curr = ((void *) values);
int count;
for (count = 0; curr && curr[count]; count++);
values[0] = "test";
print(values);
return count;
}
```
Produces the output below with TySan. It looks like it is missing setting the initial type of `values` and the first reported violation is ` values[0] = "test";`, while it should already report the read of `void *` for `curr[count]` from memory with `char *`.
```
> bin/clang -fsanitize=type test.c -O1 -g -isysroot $MACOS_SYSROOT
> ./a.out
==81689==ERROR: TypeSanitizer: type-aliasing-violation on address 0x00016b16b1c0 (pc 0x000104c97dac bp 0x00016b16b1b0 sp 0x00016b16a940 tid 18058865)
WRITE of size 8 at 0x00016b16b1c0 with type p1 omnipotent char accesses an existing object of type p1 void
#0 0x000104c97da8 in main test.c:14
==81689==ERROR: TypeSanitizer: type-aliasing-violation on address 0x00016b16b1c0 (pc 0x000104c97a68 bp 0x00016b16b180 sp 0x00016b16a910 tid 18058865)
READ of size 8 at 0x00016b16b1c0 with type p1 omnipotent char accesses an existing object of type p1 void
#0 0x000104c97a64 in print test.c:5
test
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzEVU-L47gT_TSVS5Egy_8PPjidDszhR_9INyx7amRZibWjSEaS05P59ItkZ5OZaVj2sgsCG6lU9erVUxVzTp60EA3kW8h3Kzb5wdjmOLBBrzrTX5u3QaDU0kum8CKsk0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