Home | History | Annotate | Download | only in TestCases
      1 // RUN: %clang_esan_wset -O0 %s -o %t 2>&1
      2 // RUN: %run %t 2>&1 | FileCheck %s
      3 
      4 #include <stdlib.h>
      5 #include <string.h>
      6 #include <sys/mman.h>
      7 #include <assert.h>
      8 
      9 const int size = 0x1 << 25; // 523288 cache lines
     10 const int line_size = 64;
     11 
     12 int main(int argc, char **argv) {
     13   char *bufA = (char *)malloc(sizeof(char) * line_size);
     14   char bufB[64];
     15   char *bufC = (char *)mmap(0, size, PROT_READ | PROT_WRITE,
     16                             MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
     17   bufA[0] = 0;
     18   // This additional access to the same line should not increase the line
     19   // count: but it's difficult to make a non-flaky test that measures the
     20   // lines down to the ones digit so right now we're not really testing that.
     21   // If we add a heap-only mode we may be able to be more precise.
     22   bufA[1] = 0;
     23   bufB[33] = 1;
     24   for (int i = 0; i < size; i += line_size)
     25     bufC[i] = 0;
     26   free(bufA);
     27   munmap(bufC, 0x4000);
     28   // CHECK: {{.*}} EfficiencySanitizer: the total working set size: 32 MB (524{{[0-9][0-9][0-9]}} cache lines)
     29   return 0;
     30 }
     31