File: test_malloc_load_store.c

package info (click to toggle)
llvm-toolchain-13 1%3A13.0.1-11
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,418,840 kB
  • sloc: cpp: 5,290,826; ansic: 996,570; asm: 544,593; python: 188,212; objc: 72,027; lisp: 30,291; f90: 25,395; sh: 24,898; javascript: 9,780; pascal: 9,398; perl: 7,484; ml: 5,432; awk: 3,523; makefile: 2,913; xml: 953; cs: 573; fortran: 539
file content (38 lines) | stat: -rw-r--r-- 1,357 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// Check profile with a single malloc call and set of loads and stores. Ensures
// we get the same profile regardless of whether the memory is deallocated
// before exit.

// RUN: %clang_memprof -O0 %s -o %t
// RUN: %env_memprof_opts=log_path=stderr %run %t 2>&1 | FileCheck %s

// RUN: %clang_memprof -DFREE -O0 %s -o %t
// RUN: %env_memprof_opts=log_path=stderr %run %t 2>&1 | FileCheck %s

// This is actually:
//  Memory allocation stack id = STACKID
//   alloc_count 1, size (ave/min/max) 40.00 / 40 / 40
// but we need to look for them in the same CHECK to get the correct STACKID.
// CHECK:  Memory allocation stack id = [[STACKID:[0-9]+]]{{[[:space:]].*}}alloc_count 1, size (ave/min/max) 40.00 / 40 / 40
// CHECK-NEXT:  access_count (ave/min/max): 20.00 / 20 / 20
// CHECK-NEXT:  lifetime (ave/min/max): [[AVELIFETIME:[0-9]+]].00 / [[AVELIFETIME]] / [[AVELIFETIME]]
// CHECK-NEXT:  num migrated: 0, num lifetime overlaps: 0, num same alloc cpu: 0, num same dealloc_cpu: 0
// CHECK: Stack for id [[STACKID]]:
// CHECK-NEXT: #0 {{.*}} in {{.*}}malloc
// CHECK-NEXT: #1 {{.*}} in main {{.*}}:[[@LINE+6]]

#include <stdio.h>
#include <stdlib.h>

int main() {
  int *p = (int *)malloc(10 * sizeof(int));
  for (int i = 0; i < 10; i++)
    p[i] = i;
  int j = 0;
  for (int i = 0; i < 10; i++)
    j += p[i];
#ifdef FREE
  free(p);
#endif

  return 0;
}