File: unaligned_loads_and_stores.cpp

package info (click to toggle)
llvm-toolchain-14 1%3A14.0.6-12
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,496,180 kB
  • sloc: cpp: 5,593,972; ansic: 986,872; asm: 585,869; python: 184,223; objc: 72,530; lisp: 31,119; f90: 27,793; javascript: 9,780; pascal: 9,762; sh: 9,482; perl: 7,468; ml: 5,432; awk: 3,523; makefile: 2,538; xml: 953; cs: 573; fortran: 567
file content (52 lines) | stat: -rw-r--r-- 2,511 bytes parent folder | download | duplicates (7)
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
// RUN: %clangxx_asan -O0 %s -o %t
// RUN: not %run %t A 2>&1 | FileCheck --check-prefix=CHECK-A %s
// RUN: not %run %t B 2>&1 | FileCheck --check-prefix=CHECK-B %s
// RUN: not %run %t C 2>&1 | FileCheck --check-prefix=CHECK-C %s
// RUN: not %run %t D 2>&1 | FileCheck --check-prefix=CHECK-D %s
// RUN: not %run %t E 2>&1 | FileCheck --check-prefix=CHECK-E %s

// RUN: not %run %t K 2>&1 | FileCheck --check-prefix=CHECK-K %s
// RUN: not %run %t L 2>&1 | FileCheck --check-prefix=CHECK-L %s
// RUN: not %run %t M 2>&1 | FileCheck --check-prefix=CHECK-M %s
// RUN: not %run %t N 2>&1 | FileCheck --check-prefix=CHECK-N %s
// RUN: not %run %t O 2>&1 | FileCheck --check-prefix=CHECK-O %s

#include <sanitizer/asan_interface.h>

#include <stdlib.h>
#include <string.h>
int main(int argc, char **argv) {
  if (argc != 2) return 1;
  char *x = new char[16];
  memset(x, 0xab, 16);
  int res = 1;
  switch (argv[1][0]) {
    case 'A': res = __sanitizer_unaligned_load16(x + 15); break;
//  CHECK-A ERROR: AddressSanitizer: heap-buffer-overflow on address
//  CHECK-A: main{{.*}}unaligned_loads_and_stores.cpp:[[@LINE-2]]
//  CHECK-A: is located 0 bytes to the right of 16-byte region
    case 'B': res = __sanitizer_unaligned_load32(x + 14); break;
//  CHECK-B: main{{.*}}unaligned_loads_and_stores.cpp:[[@LINE-1]]
    case 'C': res = __sanitizer_unaligned_load32(x + 13); break;
//  CHECK-C: main{{.*}}unaligned_loads_and_stores.cpp:[[@LINE-1]]
    case 'D': res = __sanitizer_unaligned_load64(x + 15); break;
//  CHECK-D: main{{.*}}unaligned_loads_and_stores.cpp:[[@LINE-1]]
    case 'E': res = __sanitizer_unaligned_load64(x + 9); break;
//  CHECK-E: main{{.*}}unaligned_loads_and_stores.cpp:[[@LINE-1]]

    case 'K': __sanitizer_unaligned_store16(x + 15, 0); break;
//  CHECK-K ERROR: AddressSanitizer: heap-buffer-overflow on address
//  CHECK-K: main{{.*}}unaligned_loads_and_stores.cpp:[[@LINE-2]]
//  CHECK-K: is located 0 bytes to the right of 16-byte region
    case 'L': __sanitizer_unaligned_store32(x + 15, 0); break;
//  CHECK-L: main{{.*}}unaligned_loads_and_stores.cpp:[[@LINE-1]]
    case 'M': __sanitizer_unaligned_store32(x + 13, 0); break;
//  CHECK-M: main{{.*}}unaligned_loads_and_stores.cpp:[[@LINE-1]]
    case 'N': __sanitizer_unaligned_store64(x + 10, 0); break;
//  CHECK-N: main{{.*}}unaligned_loads_and_stores.cpp:[[@LINE-1]]
    case 'O': __sanitizer_unaligned_store64(x + 14, 0); break;
//  CHECK-O: main{{.*}}unaligned_loads_and_stores.cpp:[[@LINE-1]]
  }
  delete x;
  return res;
}