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