brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.0 KiB · 247ee76 Raw
32 lines · c
1// RUN: %clang_tysan -O0 %s -o %t && %run %t >%t.out 2>&12// RUN: FileCheck %s < %t.out3#include <stdlib.h>4#include <string.h>5 6float P;7long L;8 9int main() {10  *(int *)&P = 5;11  // CHECK: ERROR: TypeSanitizer: type-aliasing-violation12  // CHECK: WRITE of size 4 at {{.*}} with type int accesses an existing object of type float13  // CHECK: {{#0 0x.* in main .*global.c:}}[[@LINE-3]]14 15  void *mem = malloc(sizeof(long));16  *(int *)mem = 6;17  memcpy(mem, &L, sizeof(L));18  *(int *)mem = 8;19  // CHECK: ERROR: TypeSanitizer: type-aliasing-violation20  // CHECK: WRITE of size 4 at {{.*}} with type int accesses an existing object of type long21  // CHECK: {{#0 0x.* in main .*global.c:}}[[@LINE-3]]22  int r = *(((int *)mem) + 1);23  // CHECK: ERROR: TypeSanitizer: type-aliasing-violation24  // CHECK: READ of size 4 at {{.*}} with type int accesses part of an existing object of type long that starts at offset -425  // CHECK: {{#0 0x.* in main .*global.c:}}[[@LINE-3]]26  free(mem);27 28  return r;29}30 31// CHECK-NOT: ERROR: TypeSanitizer: type-aliasing-violation32