File: omp_realloc_null_ptr.c

package info (click to toggle)
llvm-toolchain-16 1%3A16.0.6-15~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,634,792 kB
  • sloc: cpp: 6,179,261; ansic: 1,216,205; asm: 741,319; python: 196,614; objc: 75,325; f90: 49,640; lisp: 32,396; pascal: 12,286; sh: 9,394; perl: 7,442; ml: 5,494; awk: 3,523; makefile: 2,723; javascript: 1,206; xml: 886; fortran: 581; cs: 573
file content (46 lines) | stat: -rw-r--r-- 1,204 bytes parent folder | download | duplicates (19)
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
39
40
41
42
43
44
45
46
// RUN: %libomp-compile-and-run

#include <stdio.h>
#include <omp.h>

int main()
{
  omp_alloctrait_t at[2];
  omp_allocator_handle_t a;
  omp_allocator_handle_t f_a;
  void *ptr[2];
  void *nptr[2];
  at[0].key = omp_atk_pool_size;
  at[0].value = 2*1024*1024;
  at[1].key = omp_atk_fallback;
  at[1].value = omp_atv_default_mem_fb;

  a = omp_init_allocator(omp_large_cap_mem_space, 2, at);
  f_a = omp_init_allocator(omp_default_mem_space, 2, at);
  printf("allocator large created: %p\n", (void *)a);
  printf("allocator default created: %p\n", (void *)f_a);

  #pragma omp parallel num_threads(2)
  {
    int i = omp_get_thread_num();
    ptr[i] = omp_alloc(0, f_a);
    #pragma omp barrier
    nptr[i] = omp_realloc(ptr[i], 1024 * 1024, a, f_a);
    #pragma omp barrier
    printf("th %d, nptr %p\n", i, nptr[i]);
    omp_free(nptr[i], a);
  }

  // Both ptr pointers should be NULL
  if (ptr[0] != NULL || ptr[1] != NULL) {
    printf("failed: pointers %p %p\n", ptr[0], ptr[1]);
    return 1;
  }
  // Both nptr pointers should be non-NULL
  if (nptr[0] == NULL || nptr[1] == NULL) {
    printf("failed: pointers %p %p\n", nptr[0], nptr[1]);
    return 1;
  }
  printf("passed\n");
  return 0;
}