llvm.org GIT mirror llvm / 0195c0b
[FileCheck] Don't permit overlapping CHECK-DAG That is, make CHECK-DAG skip matches that overlap the matches of any preceding consecutive CHECK-DAG directives. This change makes CHECK-DAG more consistent with other directives, and there is evidence it makes CHECK-DAG more intuitive and less error-prone. See the RFC discussion starting at: http://lists.llvm.org/pipermail/llvm-dev/2018-May/123010.html Moreover, this behavior enables CHECK-DAG groups for unordered, non-unique strings or patterns. For example, it is useful for verifying output or logs from a parallel program, such as the OpenMP runtime. This patch also implements the command-line option -allow-deprecated-dag-overlap, which reverts CHECK-DAG to the old overlapping behavior. This option should not be used in new tests. It is meant only for the existing tests that are broken by this change and that need time to update. See the following bugzilla issue for tracking of such tests: https://bugs.llvm.org/show_bug.cgi?id=37532 Patches to add -allow-deprecated-dag-overlap to those tests will follow immediately. Reviewed By: probinson Differential Revision: https://reviews.llvm.org/D47106 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@336847 91177308-0d34-0410-b5e6-96231b3b80d8 Joel E. Denny 1 year, 4 months ago
4 changed file(s) with 604 addition(s) and 13 deletion(s). Raw diff Collapse all Expand all
9393 .. option:: -version
9494
9595 Show the version number of this program.
96
97 .. option:: --allow-deprecated-dag-overlap
98
99 Enable overlapping among matches in a group of consecutive ``CHECK-DAG:``
100 directives. This option is deprecated and is only provided for convenience
101 as old tests are migrated to the new non-overlapping ``CHECK-DAG:``
102 implementation.
96103
97104 EXIT STATUS
98105 -----------
358365 real bugs away.
359366
360367 In those cases, to enforce the order, use a non-DAG directive between DAG-blocks.
368
369 A ``CHECK-DAG:`` directive skips matches that overlap the matches of any
370 preceding ``CHECK-DAG:`` directives in the same ``CHECK-DAG:`` block. Not only
371 is this non-overlapping behavior consistent with other directives, but it's
372 also necessary to handle sets of non-unique strings or patterns. For example,
373 the following directives look for unordered log entries for two tasks in a
374 parallel program, such as the OpenMP runtime:
375
376 .. code-block:: text
377
378 // CHECK-DAG: [[THREAD_ID:[0-9]+]]: task_begin
379 // CHECK-DAG: [[THREAD_ID]]: task_end
380 //
381 // CHECK-DAG: [[THREAD_ID:[0-9]+]]: task_begin
382 // CHECK-DAG: [[THREAD_ID]]: task_end
383
384 The second pair of directives is guaranteed not to match the same log entries
385 as the first pair even though the patterns are identical and even if the text
386 of the log entries is identical because the thread ID manages to be reused.
361387
362388 The "CHECK-LABEL:" directive
363389 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0 ;---------------------------------------------------------------------
1 ; RUN: not FileCheck -allow-deprecated-dag-overlap -input-file %s %s \
2 ; RUN: -check-prefix=EndAfterEnd
3 ; RUN: FileCheck -input-file %s %s -check-prefix=EndAfterEnd
4
5 new match end after old match end
6
7 __EndAfterEnd
8 (abcxyz)
9 (abcxyz)
10 (abcxyz >xyz)
11 (abcxyz no>xyz)
12 (abcxyz xyz)
13 (abcxyz cxyz)
14 (abcxyz abcxyz)
15 __EndAfterEnd
16
17 ; EndAfterEnd: __EndAfterEnd
18
19 ; EndAfterEnd: {{^}}(
20 ; EndAfterEnd-DAG:
21 ; EndAfterEnd-DAG: yz
22 ; EndAfterEnd-NOT: {{.}}
23 ; EndAfterEnd-SAME: ){{$}}
24
25 ; EndAfterEnd: {{^}}(
26 ; EndAfterEnd-DAG:
27 ; EndAfterEnd-DAG: xyz
28 ; EndAfterEnd-NOT: {{.}}
29 ; EndAfterEnd-SAME: ){{$}}
30
31 ; EndAfterEnd: {{^}}(
32 ; EndAfterEnd-DAG:
33 ; EndAfterEnd-DAG: >xyz
34 ; EndAfterEnd-NOT: {{.}}
35 ; EndAfterEnd-SAME: ){{$}}
36
37 ; EndAfterEnd: {{^}}(
38 ; EndAfterEnd-DAG:
39 ; EndAfterEnd-DAG: no>xyz
40 ; EndAfterEnd-NOT: {{.}}
41 ; EndAfterEnd-SAME: ){{$}}
42
43 ; EndAfterEnd: {{^}}(
44 ; EndAfterEnd-DAG:
45 ; EndAfterEnd-DAG: xyz
46 ; EndAfterEnd-NOT: {{.}}
47 ; EndAfterEnd-SAME: ){{$}}
48
49 ; EndAfterEnd: {{^}}(
50 ; EndAfterEnd-DAG:
51 ; EndAfterEnd-DAG: cxyz
52 ; EndAfterEnd-NOT: {{.}}
53 ; EndAfterEnd-SAME: ){{$}}
54
55 ; EndAfterEnd: {{^}}(
56 ; EndAfterEnd-DAG:
57 ; EndAfterEnd-DAG: abcxyz
58 ; EndAfterEnd-NOT: {{.}}
59 ; EndAfterEnd-SAME: ){{$}}
60
61 ; EndAfterEnd: __EndAfterEnd
62
63 ;---------------------------------------------------------------------
64 ; RUN: not FileCheck -allow-deprecated-dag-overlap -input-file %s %s \
65 ; RUN: -check-prefix=EndRightAfterEnd
66 ; RUN: FileCheck -input-file %s %s -check-prefix=EndRightAfterEnd
67
68 new match end right after old match end
69
70 __EndRightAfterEnd
71 (abcxyz)
72 (abcxyz >x)
73 (abcxyz no>x)
74 (abcxyz x)
75 (abcxyz cx)
76 (abcxyz abcx)
77 __EndRightAfterEnd
78
79 ; EndRightAfterEnd: __EndRightAfterEnd
80
81 ; EndRightAfterEnd: {{^}}(
82 ; EndRightAfterEnd-DAG:
83 ; EndRightAfterEnd-DAG: x
84 ; EndRightAfterEnd-NOT: {{.}}
85 ; EndRightAfterEnd-SAME: yz){{$}}
86
87 ; EndRightAfterEnd: {{^}}(
88 ; EndRightAfterEnd-DAG:
89 ; EndRightAfterEnd-DAG: >x
90 ; EndRightAfterEnd-NOT: {{.}}
91 ; EndRightAfterEnd-SAME: ){{$}}
92
93 ; EndRightAfterEnd: {{^}}(
94 ; EndRightAfterEnd-DAG:
95 ; EndRightAfterEnd-DAG: no>x
96 ; EndRightAfterEnd-NOT: {{.}}
97 ; EndRightAfterEnd-SAME: ){{$}}
98
99 ; EndRightAfterEnd: {{^}}(
100 ; EndRightAfterEnd-DAG:
101 ; EndRightAfterEnd-DAG: x
102 ; EndRightAfterEnd-NOT: {{.}}
103 ; EndRightAfterEnd-SAME: ){{$}}
104
105 ; EndRightAfterEnd: {{^}}(
106 ; EndRightAfterEnd-DAG:
107 ; EndRightAfterEnd-DAG: cx
108 ; EndRightAfterEnd-NOT: {{.}}
109 ; EndRightAfterEnd-SAME: ){{$}}
110
111 ; EndRightAfterEnd: {{^}}(
112 ; EndRightAfterEnd-DAG:
113 ; EndRightAfterEnd-DAG: abcx
114 ; EndRightAfterEnd-NOT: {{.}}
115 ; EndRightAfterEnd-SAME: ){{$}}
116
117 ; EndRightAfterEnd: __EndRightAfterEnd
118
119 ;---------------------------------------------------------------------
120 ; RUN: not FileCheck -allow-deprecated-dag-overlap -input-file %s %s \
121 ; RUN: -check-prefix=EndAtEnd
122 ; RUN: FileCheck -input-file %s %s -check-prefix=EndAtEnd
123
124 new match end at old match end
125
126 __EndAtEnd
127 (abcxyz >)
128 (abcxyz no>)
129 (abcxyz )
130 (abcxyz c)
131 (abcxyz abc)
132 __EndAtEnd
133
134 ; EndAtEnd: __EndAtEnd
135
136 ; EndAtEnd: {{^}}(
137 ; EndAtEnd-DAG:
138 ; EndAtEnd-DAG: >
139 ; EndAtEnd-NOT: {{.}}
140 ; EndAtEnd-SAME: ){{$}}
141
142 ; EndAtEnd: {{^}}(
143 ; EndAtEnd-DAG:
144 ; EndAtEnd-DAG: no>
145 ; EndAtEnd-NOT: {{.}}
146 ; EndAtEnd-SAME: ){{$}}
147
148 ; EndAtEnd: {{^}}(
149 ; EndAtEnd-DAG:
150 ; EndAtEnd-DAG:
151 ; EndAtEnd-NOT: {{.}}
152 ; EndAtEnd-SAME: ){{$}}
153
154 ; EndAtEnd: {{^}}(
155 ; EndAtEnd-DAG:
156 ; EndAtEnd-DAG: c
157 ; EndAtEnd-NOT: {{.}}
158 ; EndAtEnd-SAME: ){{$}}
159
160 ; EndAtEnd: {{^}}(
161 ; EndAtEnd-DAG:
162 ; EndAtEnd-DAG: abc
163 ; EndAtEnd-NOT: {{.}}
164 ; EndAtEnd-SAME: ){{$}}
165
166 ; EndAtEnd: __EndAtEnd
167
168 ;---------------------------------------------------------------------
169 ; RUN: not FileCheck -allow-deprecated-dag-overlap -input-file %s %s \
170 ; RUN: -check-prefix=EndWithin
171 ; RUN: FileCheck -input-file %s %s -check-prefix=EndWithin
172
173 new match end within old match
174
175 __EndWithin
176 (abcxyz m)
177 (abcxyz
178 (abcxyz c
179 (abcxyz abc
180 __EndWithin
181
182 ; EndWithin: __EndWithin
183
184 ; EndWithin: {{^}}(
185 ; EndWithin-DAG:
186 ; EndWithin-DAG: m
187 ; EndWithin-NOT: {{.}}
188 ; EndWithin-SAME: ){{$}}
189
190 ; EndWithin: {{^}}(
191 ; EndWithin-DAG:
192 ; EndWithin-DAG:
193 ; EndWithin-NOT: {{.}}
194 ; EndWithin-SAME: ){{$}}
195
196 ; EndWithin: {{^}}(
197 ; EndWithin-DAG:
198 ; EndWithin-DAG: c
199 ; EndWithin-NOT: {{.}}
200 ; EndWithin-SAME: ){{$}}
201
202 ; EndWithin: {{^}}(
203 ; EndWithin-DAG:
204 ; EndWithin-DAG: abc
205 ; EndWithin-NOT: {{.}}
206 ; EndWithin-SAME: ){{$}}
207
208 ; EndWithin: __EndWithin
209
210 ;---------------------------------------------------------------------
211 ; RUN: not FileCheck -allow-deprecated-dag-overlap -input-file %s %s \
212 ; RUN: -check-prefix=EndRightAfterStart
213 ; RUN: FileCheck -input-file %s %s -check-prefix=EndRightAfterStart
214
215 new match end right after old match start
216
217 __EndRightAfterStart
218 (abcxyz <)
219 (abcxyz c<)
220 (abcxyz abc<)
221 __EndRightAfterStart
222
223 ; EndRightAfterStart: __EndRightAfterStart
224
225 ; EndRightAfterStart: {{^}}(
226 ; EndRightAfterStart-DAG:
227 ; EndRightAfterStart-DAG: <
228 ; EndRightAfterStart-NOT: {{.}}
229 ; EndRightAfterStart-SAME: ){{$}}
230
231 ; EndRightAfterStart: {{^}}(
232 ; EndRightAfterStart-DAG:
233 ; EndRightAfterStart-DAG: c<
234 ; EndRightAfterStart-NOT: {{.}}
235 ; EndRightAfterStart-SAME: ){{$}}
236
237 ; EndRightAfterStart: {{^}}(
238 ; EndRightAfterStart-DAG:
239 ; EndRightAfterStart-DAG: abc<
240 ; EndRightAfterStart-NOT: {{.}}
241 ; EndRightAfterStart-SAME: ){{$}}
242
243 ; EndRightAfterStart: __EndRightAfterStart
244
245 ;---------------------------------------------------------------------
246 ; RUN: FileCheck -allow-deprecated-dag-overlap -input-file %s %s \
247 ; RUN: -check-prefix=EndAtStart
248 ; RUN: FileCheck -input-file %s %s -check-prefix=EndAtStart
249
250 new match end at old match start
251
252 __EndAtStart
253 (abcxyz)
254 (abcxyz)
255 __EndAtStart
256
257 ; EndAtStart: __EndAtStart
258
259 ; EndAtStart: {{^}}(
260 ; EndAtStart-DAG:
261 ; EndAtStart-DAG: c
262 ; EndAtStart-DAG: xyz
263 ; EndAtStart-NOT: {{.}}
264 ; EndAtStart-SAME: ){{$}}
265
266 ; EndAtStart: {{^}}(
267 ; EndAtStart-DAG:
268 ; EndAtStart-DAG: abc
269 ; EndAtStart-DAG: xyz
270 ; EndAtStart-NOT: {{.}}
271 ; EndAtStart-SAME: ){{$}}
272
273 ; EndAtStart: __EndAtStart
274
275 ;---------------------------------------------------------------------
276 ; RUN: FileCheck -allow-deprecated-dag-overlap -input-file %s %s \
277 ; RUN: -check-prefix=EndBeforeStart
278 ; RUN: FileCheck -input-file %s %s -check-prefix=EndBeforeStart
279
280 new match end before old match start
281
282 __EndBeforeStart
283 (abcxyz)
284 (abcxyz)
285 __EndBeforeStart
286
287 ; EndBeforeStart: __EndBeforeStart
288
289 ; EndBeforeStart: {{^}}(
290 ; EndBeforeStart-DAG:
291 ; EndBeforeStart-DAG: b
292 ; EndBeforeStart-DAG: xyz
293 ; EndBeforeStart-NOT: {{.}}
294 ; EndBeforeStart-SAME: ){{$}}
295
296 ; EndBeforeStart: {{^}}(
297 ; EndBeforeStart-DAG:
298 ; EndBeforeStart-DAG: ab
299 ; EndBeforeStart-DAG: xyz
300 ; EndBeforeStart-NOT: {{.}}
301 ; EndBeforeStart-SAME: ){{$}}
302
303 ; EndBeforeStart: __EndBeforeStart
0 ;---------------------------------------------------------------------
1 ; RUN: not FileCheck -allow-deprecated-dag-overlap -input-file %s %s \
2 ; RUN: -check-prefix=IdentPat
3 ; RUN: FileCheck -input-file %s %s -check-prefix=IdentPat
4
5 __IdentPat
6 add r10, r1, r2
7 add r11, r3, r4
8 mul r5, r10, r11
9 __IdentPat
10
11 ; IdentPat: {{^}}__IdentPat
12 ; IdentPat-DAG: {{^}}add [[REG1:r[0-9]+]], {{r[0-9]+}}, {{r[0-9]+}}
13 ; IdentPat-DAG: {{^}}add [[REG2:r[0-9]+]], {{r[0-9]+}}, {{r[0-9]+}}
14 ; IdentPat: {{^}}mul r5, [[REG1]], [[REG2]]
15 ; IdentPat: {{^}}__IdentPat
16
17 ;---------------------------------------------------------------------
18 ; RUN: not FileCheck -allow-deprecated-dag-overlap -input-file %s %s \
19 ; RUN: -check-prefix=IdentPatNot
20 ; RUN: FileCheck -input-file %s %s -check-prefix=IdentPatNot
21
22 __IdentPatNot
23 add r11, r1, r2
24 xor r12, r1, r2
25 add r10, r3, r4
26 mul r5, r10, r11
27 __IdentPatNot
28
29 ; IdentPatNot: {{^}}__IdentPatNot
30 ; IdentPatNot-DAG: {{^}}add {{r[0-9]+}}, {{r[0-9]+}}, {{r[0-9]+}}
31 ; IdentPatNot-DAG: {{^}}add {{r[0-9]+}}, {{r[0-9]+}}, {{r[0-9]+}}
32 ; IdentPatNot-NOT: {{^}}xor
33 ; IdentPatNot-DAG: {{^}}mul r5, r10, r11
34 ; IdentPatNot: {{^}}__IdentPatNot
35
36 ;---------------------------------------------------------------------
37 ; RUN: FileCheck -allow-deprecated-dag-overlap -input-file %s %s \
38 ; RUN: -check-prefix=IdentPatVarDiff
39 ; RUN: FileCheck -input-file %s %s -check-prefix=IdentPatVarDiff
40
41 __IdentPatVarDiff
42 call void @foo(), !dbg !0
43 call void @bar(), !dbg !1
44 !1 = !DILocation(line: 1,
45 !0 = !DILocation(line: 1,
46 __IdentPatVarDiff
47
48 ; IdentPatVarDiff: {{^}}__IdentPatVarDiff
49 ; IdentPatVarDiff: {{^}}call void @foo(), !dbg [[DBG0:![0-9]+]]
50 ; IdentPatVarDiff: {{^}}call void @bar(), !dbg [[DBG1:![0-9]+]]
51 ; IdentPatVarDiff-DAG: {{^}}[[DBG0]] = !DILocation(line: 1,
52 ; IdentPatVarDiff-DAG: {{^}}[[DBG1]] = !DILocation(line: 1,
53 ; IdentPatVarDiff: {{^}}__IdentPatVarDiff
54
55 ;---------------------------------------------------------------------
56 ; RUN: FileCheck -allow-deprecated-dag-overlap -input-file %s %s \
57 ; RUN: -check-prefix=IdentPatVarSame
58 ; RUN: not FileCheck -input-file %s %s -check-prefix=IdentPatVarSame
59
60 __IdentPatVarSame
61 call void @foo(), !dbg !0
62 call void @bar(), !dbg !0
63 !1 = !DILocation(line: 1,
64 !0 = !DILocation(line: 1,
65 __IdentPatVarSame
66
67 ; IdentPatVarSame: {{^}}__IdentPatVarSame
68 ; IdentPatVarSame: {{^}}call void @foo(), !dbg [[DBG0:![0-9]+]]
69 ; IdentPatVarSame: {{^}}call void @bar(), !dbg [[DBG1:![0-9]+]]
70 ; IdentPatVarSame-DAG: {{^}}[[DBG0]] = !DILocation(line: 1,
71 ; IdentPatVarSame-DAG: {{^}}[[DBG1]] = !DILocation(line: 1,
72 ; IdentPatVarSame: {{^}}__IdentPatVarSame
73
74 ;---------------------------------------------------------------------
75 ; RUN: FileCheck -allow-deprecated-dag-overlap -input-file %s %s \
76 ; RUN: -check-prefix=SupSubSet
77 ; RUN: not FileCheck -input-file %s %s -check-prefix=SupSubSet
78
79 __SupSubSet
80 store i64 8, i64* %a
81 store i64 4, i64* %a
82 store i64 4, i64* %b
83 store i64 8, i64* %b
84 __SupSubSet
85
86 ; SupSubSet: {{^}}__SupSubSet
87 ; SupSubSet-DAG: {{^}}store i64 {{4|8}}, i64* %a
88 ; SupSubSet-DAG: {{^}}store i64 4, i64* %a
89 ; SupSubSet-DAG: {{^}}store i64 {{4|8}}, i64* %b
90 ; SupSubSet-DAG: {{^}}store i64 4, i64* %b
91 ; SupSubSet: {{^}}__SupSubSet
92
93 ;---------------------------------------------------------------------
94 ; RUN: FileCheck -allow-deprecated-dag-overlap -input-file %s %s \
95 ; RUN: -check-prefix=SubSupSet
96 ; RUN: FileCheck -input-file %s %s -check-prefix=SubSupSet
97
98 __SubSupSet
99 store i64 8, i64* %a
100 store i64 4, i64* %a
101 store i64 4, i64* %b
102 store i64 8, i64* %b
103 __SubSupSet
104
105 ; SubSupSet: {{^}}__SubSupSet
106 ; SubSupSet-DAG: {{^}}store i64 4, i64* %a
107 ; SubSupSet-DAG: {{^}}store i64 {{4|8}}, i64* %a
108 ; SubSupSet-DAG: {{^}}store i64 4, i64* %b
109 ; SubSupSet-DAG: {{^}}store i64 {{4|8}}, i64* %b
110 ; SubSupSet: {{^}}__SubSupSet
111
112 ;---------------------------------------------------------------------
113 ; RUN: not FileCheck -allow-deprecated-dag-overlap -input-file %s %s \
114 ; RUN: -check-prefixes=WrongNumReps
115 ; RUN: not FileCheck -input-file %s %s -check-prefixes=WrongNumReps
116 ;
117 ; RUN: not FileCheck -allow-deprecated-dag-overlap -input-file %s %s \
118 ; RUN: -check-prefixes=WrongNumReps,WrongNumReps2
119 ; RUN: FileCheck -input-file %s %s \
120 ; RUN: -check-prefixes=WrongNumReps,WrongNumReps2
121 ;
122 ; RUN: not FileCheck -allow-deprecated-dag-overlap -input-file %s %s \
123 ; RUN: -check-prefixes=WrongNumReps,WrongNumReps2,WrongNumReps3
124 ; RUN: not FileCheck -input-file %s %s \
125 ; RUN: -check-prefixes=WrongNumReps,WrongNumReps2,WrongNumReps3
126
127 __WrongNumReps
128 0: task_begin
129 1: task_begin
130 0: barrier_begin
131 1: barrier_begin
132 __WrongNumReps
133
134 ; WrongNumReps: {{^}}__WrongNumReps
135 ; WrongNumReps-DAG: {{^}}[[THID:[0-9]+]]: task_begin
136 ; WrongNumReps-DAG: {{^}}[[THID]]: barrier_begin
137 ; WrongNumReps2-DAG: {{^}}[[THID:[0-9]+]]: task_begin
138 ; WrongNumReps2-DAG: {{^}}[[THID]]: barrier_begin
139 ; WrongNumReps3-DAG: {{^}}[[THID:[0-9]+]]: task_begin
140 ; WrongNumReps3-DAG: {{^}}[[THID]]: barrier_begin
141 ; WrongNumReps-NEXT: {{^}}__WrongNumReps
142
143 ;---------------------------------------------------------------------
144 ; RUN: not FileCheck -allow-deprecated-dag-overlap -input-file %s %s \
145 ; RUN: -check-prefix=SameSimple
146 ; RUN: FileCheck -input-file %s %s -check-prefix=SameSimple
147
148 __SameSimple
149 ()
150 __SameSimple
151
152 ; SameSimple: {{^}}__SameSimple
153 ; SameSimple: {{^}}(
154 ; SameSimple-DAG:
155 ; SameSimple-DAG:
156 ; SameSimple-DAG:
157 ; SameSimple-NOT:
158 ; SameSimple-SAME: ){{$}}
159 ; SameSimple: {{^}}__SameSimple
160
161 ;---------------------------------------------------------------------
162 ; RUN: not FileCheck -allow-deprecated-dag-overlap -input-file %s %s \
163 ; RUN: -check-prefix=DagNotDag
164 ; RUN: FileCheck -input-file %s %s -check-prefix=DagNotDag
165
166 Assume we have DAGs, NOTs, DAGs, NOTs, and then DAGs. Let X, Y, and Z be
167 the DAG groups such that the leading DAGs are x, y, and z. y won't match
168 overlaps with matches from:
169
170 1. X. Otherwise, we could get a spurious reordering complaint.
171 2. Y, because y is in Y. To prevent these overlaps, the implementation must be
172 careful not to drop y's match from the previous matches list when it drops
173 matches from X to save search time.
174 3. z. This follows by applying rule #1 for z instead of y.
175
176 __DagNotDag
177 abcdefgh
178 abcd
179 efgh
180
181 abcd
182 ab
183 cd
184
185 abcd
186 cd
187 ab
188 __DagNotDag
189
190 ; DagNotDag: {{^}}__DagNotDag
191 ;
192 ; X:
193 ; x:DagNotDag-DAG: {{^}}abcdefgh
194 ; DagNotDag-DAG: {{^}}abcd
195 ; DagNotDag-DAG: efgh{{$}}
196 ;
197 ; Reordering complaint if rule #1 is broken.
198 ; DagNotDag-NOT: abcd
199 ; DagNotDag-NOT: efgh
200 ;
201 ; Y:
202 ; y:DagNotDag-DAG: {{^}}abcd
203 ; DagNotDag-DAG: {{^}}ab
204 ; DagNotDag-DAG: cd{{$}}
205 ;
206 ; Matches if rule #2 is broken.
207 ; DagNotDag-NOT: ab
208 ; DagNotDag-NOT: cd
209 ;
210 ; Z:
211 ; z:DagNotDag-DAG: {{^}}abcd
212 ; DagNotDag-DAG: {{^}}ab
213 ; DagNotDag-DAG: cd{{$}}
214 ;
215 ; Matches if rule #3 is broken.
216 ; DagNotDag-NOT: {{^}}ab
217 ; DagNotDag-NOT: {{^}}cd
218 ;
219 ; DagNotDag: {{^}}__DagNotDag
2727 #include "llvm/Support/raw_ostream.h"
2828 #include
2929 #include
30 #include
3031 #include
3132 #include
3233 #include
8081 cl::desc("Enables scope for regex variables. Variables with names that\n"
8182 "do not start with '$' will be reset at the beginning of\n"
8283 "each CHECK-LABEL block."));
84
85 static cl::opt AllowDeprecatedDagOverlap(
86 "allow-deprecated-dag-overlap", cl::init(false),
87 cl::desc("Enable overlapping among matches in a group of consecutive\n"
88 "CHECK-DAG directives. This option is deprecated and is only\n"
89 "provided for convenience as old tests are migrated to the new\n"
90 "non-overlapping CHECK-DAG implementation.\n"));
8391
8492 typedef cl::list::const_iterator prefix_iterator;
8593
11911199 size_t LastPos = 0;
11921200 size_t StartPos = LastPos;
11931201
1202 // A sorted list of ranges for non-overlapping dag matches.
1203 struct Match {
1204 size_t Pos;
1205 size_t End;
1206 };
1207 std::list Matches;
1208
11941209 for (const Pattern &Pat : DagNotStrings) {
11951210 assert((Pat.getCheckTy() == Check::CheckDAG ||
11961211 Pat.getCheckTy() == Check::CheckNot) &&
12031218
12041219 assert((Pat.getCheckTy() == Check::CheckDAG) && "Expect CHECK-DAG!");
12051220
1206 size_t MatchLen = 0, MatchPos;
1207
12081221 // CHECK-DAG always matches from the start.
1209 StringRef MatchBuffer = Buffer.substr(StartPos);
1210 MatchPos = Pat.Match(MatchBuffer, MatchLen, VariableTable);
1211 // With a group of CHECK-DAGs, a single mismatching means the match on
1212 // that group of CHECK-DAGs fails immediately.
1213 if (MatchPos == StringRef::npos) {
1214 PrintCheckFailed(SM, Pat.getLoc(), Pat, MatchBuffer, VariableTable);
1215 return StringRef::npos;
1216 }
1217 // Re-calc it as the offset relative to the start of the original string.
1218 MatchPos += StartPos;
1222 size_t MatchLen = 0, MatchPos = StartPos;
1223
1224 // Search for a match that doesn't overlap a previous match in this
1225 // CHECK-DAG group.
1226 for (auto MI = Matches.begin(), ME = Matches.end(); true; ++MI) {
1227 StringRef MatchBuffer = Buffer.substr(MatchPos);
1228 size_t MatchPosBuf = Pat.Match(MatchBuffer, MatchLen, VariableTable);
1229 // With a group of CHECK-DAGs, a single mismatching means the match on
1230 // that group of CHECK-DAGs fails immediately.
1231 if (MatchPosBuf == StringRef::npos) {
1232 PrintCheckFailed(SM, Pat.getLoc(), Pat, MatchBuffer, VariableTable);
1233 return StringRef::npos;
1234 }
1235 // Re-calc it as the offset relative to the start of the original string.
1236 MatchPos += MatchPosBuf;
1237 if (AllowDeprecatedDagOverlap)
1238 break;
1239 // Iterate previous matches until overlapping match or insertion point.
1240 Match M{MatchPos, MatchPos + MatchLen};
1241 bool Overlap = false;
1242 for (; MI != ME; ++MI) {
1243 if (M.Pos < MI->End) {
1244 // !Overlap => New match has no overlap and is before this old match.
1245 // Overlap => New match overlaps this old match.
1246 Overlap = MI->Pos < M.End;
1247 break;
1248 }
1249 }
1250 if (!Overlap) {
1251 // Insert non-overlapping match into list.
1252 Matches.insert(MI, M);
1253 break;
1254 }
1255 MatchPos = MI->End;
1256 }
12191257
12201258 if (!NotStrings.empty()) {
12211259 if (MatchPos < LastPos) {
12371275 return StringRef::npos;
12381276 }
12391277 // All subsequent CHECK-DAGs should be matched from the farthest
1240 // position of all precedent CHECK-DAGs (including this one.)
1278 // position of all precedent CHECK-DAGs (not including this one).
12411279 StartPos = LastPos;
1280 // Don't waste time checking for (impossible) overlaps before that.
1281 Matches.clear();
1282 Matches.push_back(Match{MatchPos, MatchPos + MatchLen});
12421283 // If there's CHECK-NOTs between two CHECK-DAGs or from CHECK to
12431284 // CHECK-DAG, verify that there's no 'not' strings occurred in that
12441285 // region.