brintos

brintos / llvm-project-archived public Read only

0
0
Text · 875 B · f7baa14 Raw
52 lines · cpp
1// RUN: %clangxx_tysan -O0 %s -c -o %t.o2// RUN: %clangxx_tysan -O0 %s -DPMAIN -c -o %tm.o3// RUN: %clangxx_tysan -O0 %s -DPINIT -c -o %tinit.o4// RUN: %clangxx_tysan -O0 %t.o %tm.o %tinit.o -o %t5// RUN: %run %t 2>&1 | FileCheck %s6 7#include <stdio.h>8#include <stdlib.h>9 10extern "C" {11typedef struct X {12  int *start;13  int *end;14  int i;15} X;16};17 18#ifdef PMAIN19int foo(struct X *);20void bar(struct X *);21void init(struct X *);22 23int main() {24  struct X x;25  init(&x);26  printf("%d\n", foo(&x));27  free(x.start);28  return 0;29}30 31#elif PINIT32 33void init(struct X *x) {34  x->start = (int *)calloc(100, sizeof(int));35  x->end = x->start + 99;36  x->i = 0;37}38 39#else40 41__attribute__((noinline)) int foo(struct X *x) {42  if (x->start < x->end)43    return 30;44  return 10;45}46 47void bar(struct X *x) { x->end = NULL; }48 49#endif50 51// CHECK-NOT: ERROR: TypeSanitizer: type-aliasing-violation52