brintos

brintos / llvm-project-archived public Read only

0
0
Text · 768 B · f7ecef5 Raw
40 lines · c
1// RUN: %clang_tysan -O0 %s -o %t && %run %t >%t.out 2>&12// RUN: FileCheck %s < %t.out3 4#include <stdio.h>5 6typedef struct S1 {7  int i1;8} s1;9typedef struct S2 {10  int i2;11} s2;12 13void g(int *i) {14  *i = 5;15  printf("%i\n", *i);16}17 18void h(char *c) {19  *c = 5;20  printf("%i\n", (int)*c);21}22 23void f(s1 *s1p, s2 *s2p) {24  s1p->i1 = 2;25  s2p->i2 = 3;26  // CHECK: ERROR: TypeSanitizer: type-aliasing-violation27  // CHECK: WRITE of size 4 at {{.*}} with type int (in S2 at offset 0) accesses an existing object of type int (in S1 at offset 0)28  // CHECK: {{#0 0x.* in f .*struct.c:}}[[@LINE-3]]29  printf("%i\n", s1p->i1);30}31 32int main() {33  s1 s = {.i1 = 1};34  f(&s, (s2 *)&s);35  g(&s.i1);36  h((char *)&s.i1);37}38 39// CHECK-NOT: ERROR: TypeSanitizer: type-aliasing-violation40