File: struct.c

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (88 lines) | stat: -rw-r--r-- 2,010 bytes parent folder | download | duplicates (20)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// RUN: %clang_dfsan %s -O1 -o %t && %run %t
// RUN: %clang_dfsan %s -O0 -DO0 -o %t && %run %t

#include <assert.h>
#include <sanitizer/dfsan_interface.h>

typedef struct Pair {
  int i;
  char *ptr;
} Pair;

__attribute__((noinline))
Pair make_pair(int i, char *ptr) {
  Pair pair;
  pair.i = i;
  pair.ptr = ptr;
  return pair;
}

__attribute__((noinline))
Pair copy_pair1(const Pair *pair0) {
  Pair pair;
  pair.i = pair0->i;
  pair.ptr = pair0->ptr;
  return pair;
}

__attribute__((noinline))
Pair copy_pair2(const Pair pair0) {
  Pair pair;
  pair.i = pair0.i;
  pair.ptr = pair0.ptr;
  return pair;
}

int main(void) {
  int i = 1;
  char *ptr = NULL;
  dfsan_label i_label = 1;
  dfsan_label ptr_label = 2;
  dfsan_set_label(i_label, &i, sizeof(i));
  dfsan_set_label(ptr_label, &ptr, sizeof(ptr));

  Pair pair1 = make_pair(i, ptr);
  int i1 = pair1.i;
  char *ptr1 = pair1.ptr;

  dfsan_label i1_label = dfsan_read_label(&i1, sizeof(i1));
  dfsan_label ptr1_label = dfsan_read_label(&ptr1, sizeof(ptr1));
#if defined(O0)
  assert(i1_label == (i_label | ptr_label));
  assert(ptr1_label == (i_label | ptr_label));
#else
  assert(i1_label == i_label);
  assert(ptr1_label == ptr_label);
#endif

  Pair pair2 = copy_pair1(&pair1);
  int i2 = pair2.i;
  char *ptr2 = pair2.ptr;

  dfsan_label i2_label = dfsan_read_label(&i2, sizeof(i2));
  dfsan_label ptr2_label = dfsan_read_label(&ptr2, sizeof(ptr2));
#if defined(O0)
  assert(i2_label == (i_label | ptr_label));
  assert(ptr2_label == (i_label | ptr_label));
#else
  assert(i2_label == i_label);
  assert(ptr2_label == ptr_label);
#endif

  Pair pair3 = copy_pair2(pair1);
  int i3 = pair3.i;
  char *ptr3 = pair3.ptr;

  dfsan_label i3_label = dfsan_read_label(&i3, sizeof(i3));
  dfsan_label ptr3_label = dfsan_read_label(&ptr3, sizeof(ptr3));
#if defined(O0)
  assert(i3_label == (i_label | ptr_label));
  assert(ptr3_label == (i_label | ptr_label));
#else
  assert(i3_label == i_label);
  assert(ptr3_label == ptr_label);
#endif


  return 0;
}