70 lines · c
1// RUN: %clang_tysan -O0 -mllvm -tysan-outline-instrumentation=false %s -o %t && %run %t 10 >%t.out.0 2>&12// RUN: FileCheck %s < %t.out.03// RUN: %clang_tysan -O2 -mllvm -tysan-outline-instrumentation=false %s -o %t && %run %t 10 >%t.out 2>&14// RUN: FileCheck %s < %t.out5// RUN: %clang_tysan -O0 -mllvm -tysan-outline-instrumentation=true %s -o %t && %run %t 10 >%t.out.0 2>&16// RUN: FileCheck %s < %t.out.07// RUN: %clang_tysan -O2 -mllvm -tysan-outline-instrumentation=true %s -o %t && %run %t 10 >%t.out 2>&18// RUN: FileCheck %s < %t.out9 10#include <stdio.h>11#include <stdlib.h>12#include <string.h>13 14void __attribute__((noinline)) add_flt(float *a) {15 *a += 2.0f;16 // CHECK: ERROR: TypeSanitizer: type-aliasing-violation17 // CHECK: READ of size 4 at {{.*}} with type float accesses an existing object of type int18 // CHECK: {{#0 0x.* in add_flt .*basic.c:}}[[@LINE-3]]19 // CHECK: ERROR: TypeSanitizer: type-aliasing-violation20 // CHECK: WRITE of size 4 at {{.*}} with type float accesses an existing object of type int21 // CHECK: {{#0 0x.* in add_flt .*basic.c:}}[[@LINE-6]]22 // CHECK: ERROR: TypeSanitizer: type-aliasing-violation23 // CHECK: READ of size 4 at {{.*}} with type float accesses an existing object of type long24 // CHECK: {{#0 0x.* in add_flt .*basic.c:}}[[@LINE-9]]25 // CHECK: ERROR: TypeSanitizer: type-aliasing-violation26 // CHECK: WRITE of size 4 at {{.*}} with type float accesses an existing object of type long27 // CHECK: {{#0 0x.* in add_flt .*basic.c:}}[[@LINE-12]]28 // CHECK: ERROR: TypeSanitizer: type-aliasing-violation29 // CHECK: READ of size 4 at {{.*}} with type float accesses part of an existing object of type long that starts at offset -430 // CHECK: {{#0 0x.* in add_flt .*basic.c:}}[[@LINE-15]]31 // CHECK: ERROR: TypeSanitizer: type-aliasing-violation32 // CHECK: WRITE of size 4 at {{.*}} with type float accesses part of an existing object of type long that starts at offset -433 // CHECK: {{#0 0x.* in add_flt .*basic.c:}}[[@LINE-18]]34 // CHECK: ERROR: TypeSanitizer: type-aliasing-violation35 // CHECK: READ of size 4 at {{.*}} with type float partially accesses an object of type short that starts at offset 236 // CHECK: {{#0 0x.* in add_flt .*basic.c:}}[[@LINE-21]]37}38 39int main(int argc, char *argv[]) {40 int x = atoi(argv[1]);41 add_flt((float *)&x);42 printf("x = %d\n", x);43 44 long y = x;45 add_flt((float *)&y);46 printf("y = %ld\n", y);47 48 add_flt(((float *)&y) + 1);49 printf("y = %ld\n", y);50 51 char *mem = (char *)malloc(4 * sizeof(short));52 memset(mem, 0, 4 * sizeof(short));53 *(short *)(mem + 2) = x;54 add_flt((float *)mem);55 short s1 = *(short *)mem;56 // CHECK: ERROR: TypeSanitizer: type-aliasing-violation57 // CHECK: READ of size 2 at {{.*}} with type short accesses an existing object of type float58 // CHECK: {{#0 0x.* in main .*basic.c:}}[[@LINE-3]]59 short s2 = *(short *)(mem + 2);60 // CHECK: ERROR: TypeSanitizer: type-aliasing-violation61 // CHECK: READ of size 2 at {{.*}} with type short accesses part of an existing object of type float that starts at offset -262 // CHECK: {{#0 0x.* in main .*basic.c:}}[[@LINE-3]]63 printf("m[0] = %d, m[1] = %d\n", s1, s2);64 free(mem);65 66 return 0;67}68 69// CHECK-NOT: ERROR: TypeSanitizer: type-aliasing-violation70