42 lines · c
1// RUN: %clang_hwasan %s -DTEST_NO=1 -mllvm -hwasan-instrument-mem-intrinsics -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=WRITE2// RUN: %clang_hwasan %s -DTEST_NO=2 -mllvm -hwasan-instrument-mem-intrinsics -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=READ3// RUN: %clang_hwasan %s -DTEST_NO=3 -mllvm -hwasan-instrument-mem-intrinsics -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=WRITE4// RUN: %clang_hwasan %s -DTEST_NO=2 -mllvm -hwasan-instrument-mem-intrinsics -o %t && not %env_hwasan_opts=halt_on_error=0 %run %t 2>&1 | FileCheck %s --check-prefix=RECOVER5 6// REQUIRES: pointer-tagging7 8#include <stdio.h>9#include <stdlib.h>10#include <string.h>11#include <unistd.h>12 13int main() {14 char Q[16] __attribute__((aligned(256)));15 char P[16] __attribute__((aligned(256)));16#if TEST_NO == 117 memset(Q, 0, 32);18#elif TEST_NO == 219 memmove(Q, Q + 16, 16);20#elif TEST_NO == 321 memcpy(Q, P, 32);22#endif23 write(STDOUT_FILENO, "recovered\n", 10);24 fflush(stdout);25 // WRITE: ERROR: HWAddressSanitizer: tag-mismatch on address26 // WRITE: WRITE of size 32 at {{.*}} tags: [[PTR_TAG:..]]/[[MEM_TAG:..]] (ptr/mem)27 // WRITE: Invalid access starting at offset 1628 // WRITE: Memory tags around the buggy address (one tag corresponds to 16 bytes):29 // WRITE: =>{{.*}}[[PTR_TAG]]{{[[:space:]]\[}}[[MEM_TAG]]30 // WRITE-NOT: recovered31 32 // READ: ERROR: HWAddressSanitizer: tag-mismatch on address33 // READ-NOT: Invalid access starting at offset34 // READ: READ {{.*}} tags: [[PTR_TAG:..]]/[[MEM_TAG:..]] (ptr/mem)35 // READ: Memory tags around the buggy address (one tag corresponds to 16 bytes):36 // READ: =>{{.*}}[[PTR_TAG]]{{[[:space:]]\[}}[[MEM_TAG]]37 // READ-NOT: recovered38 39 // RECOVER: recovered40 return 0;41}42