[ELF] Reorder target-specific error messaes
[llvm-project.git] / openmp / runtime / test / transform / unroll / factor_foreach.cpp
blob29fef7c1873622f330e05a8a39851b55ff726ff2
1 // RUN: %libomp-cxx20-compile-and-run | FileCheck %s --match-full-lines
3 #ifndef HEADER
4 #define HEADER
6 #include <cstdlib>
7 #include <cstdarg>
8 #include <cstdio>
9 #include <vector>
11 struct Reporter {
12 const char *name;
14 Reporter(const char *name) : name(name) { print("ctor"); }
16 Reporter() : name("<anon>") { print("ctor"); }
18 Reporter(const Reporter &that) : name(that.name) { print("copy ctor"); }
20 Reporter(Reporter &&that) : name(that.name) { print("move ctor"); }
22 ~Reporter() { print("dtor"); }
24 const Reporter &operator=(const Reporter &that) {
25 print("copy assign");
26 this->name = that.name;
27 return *this;
30 const Reporter &operator=(Reporter &&that) {
31 print("move assign");
32 this->name = that.name;
33 return *this;
36 struct Iterator {
37 const Reporter *owner;
38 int pos;
40 Iterator(const Reporter *owner, int pos) : owner(owner), pos(pos) {}
42 Iterator(const Iterator &that) : owner(that.owner), pos(that.pos) {
43 owner->print("iterator copy ctor");
46 Iterator(Iterator &&that) : owner(that.owner), pos(that.pos) {
47 owner->print("iterator move ctor");
50 ~Iterator() { owner->print("iterator dtor"); }
52 const Iterator &operator=(const Iterator &that) {
53 owner->print("iterator copy assign");
54 this->owner = that.owner;
55 this->pos = that.pos;
56 return *this;
59 const Iterator &operator=(Iterator &&that) {
60 owner->print("iterator move assign");
61 this->owner = that.owner;
62 this->pos = that.pos;
63 return *this;
66 bool operator==(const Iterator &that) const {
67 owner->print("iterator %d == %d", 2 - this->pos, 2 - that.pos);
68 return this->pos == that.pos;
71 bool operator!=(const Iterator &that) const {
72 owner->print("iterator %d != %d", 2 - this->pos, 2 - that.pos);
73 return this->pos != that.pos;
76 Iterator &operator++() {
77 owner->print("iterator prefix ++");
78 pos -= 1;
79 return *this;
82 Iterator operator++(int) {
83 owner->print("iterator postfix ++");
84 auto result = *this;
85 pos -= 1;
86 return result;
89 int operator*() const {
90 int result = 2 - pos;
91 owner->print("iterator deref: %i", result);
92 return result;
95 size_t operator-(const Iterator &that) const {
96 int result = (2 - this->pos) - (2 - that.pos);
97 owner->print("iterator distance: %d", result);
98 return result;
101 Iterator operator+(int steps) const {
102 owner->print("iterator advance: %i += %i", 2 - this->pos, steps);
103 return Iterator(owner, pos - steps);
106 void print(const char *msg) const { owner->print(msg); }
109 Iterator begin() const {
110 print("begin()");
111 return Iterator(this, 2);
114 Iterator end() const {
115 print("end()");
116 return Iterator(this, -1);
119 void print(const char *msg, ...) const {
120 va_list args;
121 va_start(args, msg);
122 printf("[%s] ", name);
123 vprintf(msg, args);
124 printf("\n");
125 va_end(args);
129 int main() {
130 printf("do\n");
131 #pragma omp unroll partial(2)
132 for (Reporter c{"init-stmt"}; auto &&v : Reporter("range"))
133 printf("v=%d\n", v);
134 printf("done\n");
135 return EXIT_SUCCESS;
138 #endif /* HEADER */
140 // CHECK: do
141 // CHECK-NEXT: [init-stmt] ctor
142 // CHECK-NEXT: [range] ctor
143 // CHECK-NEXT: [range] begin()
144 // CHECK-NEXT: [range] end()
145 // CHECK-NEXT: [range] iterator 0 != 3
146 // CHECK-NEXT: [range] iterator deref: 0
147 // CHECK-NEXT: v=0
148 // CHECK-NEXT: [range] iterator prefix ++
149 // CHECK-NEXT: [range] iterator 1 != 3
150 // CHECK-NEXT: [range] iterator deref: 1
151 // CHECK-NEXT: v=1
152 // CHECK-NEXT: [range] iterator prefix ++
153 // CHECK-NEXT: [range] iterator 2 != 3
154 // CHECK-NEXT: [range] iterator deref: 2
155 // CHECK-NEXT: v=2
156 // CHECK-NEXT: [range] iterator prefix ++
157 // CHECK-NEXT: [range] iterator 3 != 3
158 // CHECK-NEXT: [range] iterator dtor
159 // CHECK-NEXT: [range] iterator dtor
160 // CHECK-NEXT: [range] dtor
161 // CHECK-NEXT: [init-stmt] dtor
162 // CHECK-NEXT: done