brintos

brintos / llvm-project-archived public Read only

0
0
Text · 680 B · 7295e0a Raw
27 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#include <stdlib.h>6 7struct X {8  int i;9  int j;10};11 12int foo(struct X *p, struct X *q) {13  q->j = 1;14  p->i = 0;15  // CHECK: ERROR: TypeSanitizer: type-aliasing-violation16  // CHECK: WRITE of size 4 at {{.*}} with type int (in X at offset 0) accesses an existing object of type int (in X at offset 4)17  // CHECK: {{#0 0x.* in foo .*struct-offset.c:}}[[@LINE-3]]18  return q->j;19}20 21int main() {22  unsigned char *p = malloc(3 * sizeof(int));23  printf("%i\n", foo((struct X *)(p + sizeof(int)), (struct X *)p));24}25 26// CHECK-NOT: ERROR: TypeSanitizer: type-aliasing-violation27