Debian Codegraph @

libgomp/testsuite/libgomp.c/target-map-zero-sized-2.c

raw
1 int
2 main ()
3 {
4 int i, n;
5 int data[] = {1,2};
6 struct S { int **ptrset; };
7
8 // -----------------------------------
9
10 /* The produced mapping for sptr1->ptrset[i][:n]
11
12 GOMP_MAP_STRUCT (size = 1)
13 GOMP_MAP_ZERO_LEN_ARRAY_SECTION
14 GOMP_MAP_ZERO_LEN_ARRAY_SECTION
15 GOMP_MAP_ATTACH
16 GOMP_MAP_ATTACH -> attaching to 2nd GOMP_MAP_ZERO_LEN_ARRAY_SECTION
17
18 which get split into 3 separate map_vars call; in particular,
19 the latter is separate and points to an unmpapped variable.
20
21 Thus, it failed with:
22 libgomp: pointer target not mapped for attach */
23
24 struct S s1, *sptr1;
25 s1.ptrset = (int **) __builtin_malloc (sizeof(void*) * 3);
26 s1.ptrset[0] = data;
27 s1.ptrset[1] = data;
28 s1.ptrset[2] = data;
29 sptr1 = &s1;
30
31 i = 1;
32 n = 0;
33 #pragma omp target enter data map(sptr1[:1], sptr1->ptrset[:3])
34 #pragma omp target enter data map(sptr1->ptrset[i][:n])
35
36 #pragma omp target exit data map(sptr1->ptrset[i][:n])
37 #pragma omp target exit data map(sptr1[:1], sptr1->ptrset[:3])
38
39 __builtin_free (s1.ptrset);
40
41 // -----------------------------------
42
43 /* The produced mapping for sptr2->ptrset[i][:n] is similar:
44
45 GOMP_MAP_STRUCT (size = 1)
46 GOMP_MAP_ZERO_LEN_ARRAY_SECTION
47 GOMP_MAP_TO ! this one has now a finite size
48 GOMP_MAP_ATTACH
49 GOMP_MAP_ATTACH -> attach to the GOMP_MAP_TO
50
51 As the latter GOMP_MAP_ATTACH has now a pointer target,
52 the attachment worked. */
53
54 struct S s2, *sptr2;
55 s2.ptrset = (int **) __builtin_malloc (sizeof(void*) * 3);
56 s2.ptrset[0] = data;
57 s2.ptrset[1] = data;
58 s2.ptrset[2] = data;
59 sptr2 = &s2;
60
61 i = 1;
62 n = 2;
63 #pragma omp target enter data map(sptr2[:1], sptr2->ptrset[:3])
64 #pragma omp target enter data map(sptr2->ptrset[i][:n])
65
66 #pragma omp target
67 if (sptr2->ptrset[1][0] != 1 || sptr2->ptrset[1][1] != 2)
68 __builtin_abort ();
69
70 #pragma omp target exit data map(sptr2->ptrset[i][:n])
71 #pragma omp target exit data map(sptr2[:1], sptr2->ptrset[:3])
72
73 __builtin_free (s2.ptrset);
74 }