brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1022 B · 290ce07 Raw
43 lines · c
1// Test that disabling/enabling tagging does not trigger false reports on2// allocations happened in a different state.3 4// RUN: %clang_hwasan -O1 %s -o %t && %run %t 2>&15 6#include <assert.h>7#include <sanitizer/hwasan_interface.h>8#include <stdlib.h>9 10enum {11  COUNT = 5,12  SZ = 10,13};14void *x[COUNT];15 16int main() {17  __hwasan_enable_allocator_tagging();18  for (unsigned i = 0; i < COUNT; ++i) {19    x[i] = malloc(SZ);20    assert(__hwasan_test_shadow(x[i], SZ) == -1);21  }22  for (unsigned i = 0; i < COUNT; ++i)23    free(x[i]);24 25  __hwasan_disable_allocator_tagging();26  for (unsigned i = 0; i < COUNT; ++i) {27    x[i] = malloc(SZ);28    assert(__hwasan_tag_pointer(x[i], 0) == x[i]);29    assert(__hwasan_test_shadow(x[i], SZ) == -1);30  }31  for (unsigned i = 0; i < COUNT; ++i)32    free(x[i]);33 34  __hwasan_enable_allocator_tagging();35  for (unsigned i = 0; i < COUNT; ++i) {36    x[i] = malloc(SZ);37    assert(__hwasan_test_shadow(x[i], SZ) == -1);38  }39  for (unsigned i = 0; i < COUNT; ++i)40    free(x[i]);41  return 0;42}43