33 lines · c
1// RUN: %clang_tysan -mllvm -tysan-outline-instrumentation=true -O0 %s -o %t && %run %t >%t.out 2>&12// RUN: FileCheck %s < %t.out3// RUN: %clang_tysan -mllvm -tysan-outline-instrumentation=true -mllvm -tysan-verify-outlined-instrumentation=true -O0 %s -o %t && %run %t >%t.out 2>&14// RUN: FileCheck %s --check-prefixes='CHECK,CHECK-VERIFY' < %t.out5 6#include <stdio.h>7#include <stdlib.h>8 9struct X {10 int i;11 int j;12};13 14int foo(struct X *p, struct X *q) {15 q->j = 1;16 p->i = 0;17 // CHECK: ERROR: TypeSanitizer: type-aliasing-violation18 // CHECK-NEXT: 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)19 // CHECK-NEXT: {{#0 0x.* in foo .*struct-offset-outline.c:}}[[@LINE-3]]20 // CHECK-VERIFY-EMPTY:21 // CHECK-VERIFY-NEXT: ERROR: TypeSanitizer: type-aliasing-violation22 // CHECK-VERIFY-NEXT: 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)23 // CHECK-VERIFY-NEXT: {{#0 0x.* in foo .*struct-offset-outline.c:}}[[@LINE-7]]24 return q->j;25}26 27int main() {28 unsigned char *p = malloc(3 * sizeof(int));29 printf("%i\n", foo((struct X *)(p + sizeof(int)), (struct X *)p));30}31 32// CHECK-NOT: ERROR: TypeSanitizer: type-aliasing-violation33