brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.2 KiB · 87d1565 Raw
65 lines · cpp
1// RUN: %clangxx_asan -O2 -fsanitize-address-outline-instrumentation %s -o %t2// RUN: not %run %t A 2>&1 | FileCheck %s --check-prefix=CHECK_0_BYTES3// RUN: not %run %t B 2>&1 | FileCheck %s --check-prefix=CHECK_0_BYTES4// RUN: not %run %t C 2>&1 | FileCheck %s --check-prefix=CHECK_1_BYTES5// RUN: not %run %t D 2>&1 | FileCheck %s --check-prefix=CHECK_1_BYTES6 7// RUN: %clangxx_asan -O2 -fsanitize-address-outline-instrumentation %s -o %t \8// RUN:   -mllvm -asan-recover=19// RUN: not %run %t A 2>&1 | FileCheck %s --check-prefix=CHECK_0_BYTES10// RUN: not %run %t B 2>&1 | FileCheck %s --check-prefix=CHECK_0_BYTES11// RUN: not %run %t C 2>&1 | FileCheck %s --check-prefix=CHECK_1_BYTES12// RUN: not %run %t D 2>&1 | FileCheck %s --check-prefix=CHECK_1_BYTES13 14// RUN: %clangxx_asan -O2 -fsanitize-address-outline-instrumentation %s -o %t \15// RUN:   -mllvm -asan-force-experiment=4216// RUN: not %run %t A 2>&1 | FileCheck %s --check-prefix=CHECK_0_BYTES17// RUN: not %run %t B 2>&1 | FileCheck %s --check-prefix=CHECK_0_BYTES18// RUN: not %run %t C 2>&1 | FileCheck %s --check-prefix=CHECK_1_BYTES19// RUN: not %run %t D 2>&1 | FileCheck %s --check-prefix=CHECK_1_BYTES20 21// CHECK_0_BYTES: ERROR: AddressSanitizer: global-buffer-overflow on address [[ADDR:.*]] at22// CHECK_0_BYTES: [[ADDR]] is located 0 bytes after23 24// CHECK_1_BYTES: ERROR: AddressSanitizer: global-buffer-overflow on address [[ADDR:.*]] at25// CHECK_1_BYTES: [[ADDR]] is located 1 bytes after26 27#include <sanitizer/asan_interface.h>28 29#include <stdlib.h>30#include <string.h>31 32static int64_t mem = -1;33static int64_t *volatile G = &mem;34 35inline uint16_t UNALIGNED_LOAD(const void *p) {36  uint16_t data;37  memcpy(&data, p, sizeof data);38  return data;39}40 41inline void UNALIGNED_STORE(uint16_t data, void *p) {42  memcpy(p, &data, sizeof data);43}44 45int main(int argc, char **argv) {46  if (argc != 2)47    return 1;48  int res = 1;49  switch (argv[1][0]) {50  case 'A':51    res = UNALIGNED_LOAD(reinterpret_cast<char *>(G) + 7);52    break;53  case 'B':54    UNALIGNED_STORE(0, reinterpret_cast<char *>(G) + 7);55    break;56  case 'C':57    res = UNALIGNED_LOAD(reinterpret_cast<char *>(G) + 9);58    break;59  case 'D':60    UNALIGNED_STORE(0, reinterpret_cast<char *>(G) + 9);61    break;62  }63  return res;64}65