@@ -177,6 +177,12 @@ bool visitFunctionDecl(ASTWalker &Walker, AbstractFunctionDecl *AFD, F Func) {
177
177
return continueWalk;
178
178
}
179
179
180
+ // / Whether to skip visitation of an expression. Children of skipped exprs
181
+ // / should still be visited.
182
+ static bool skipExpr (Expr *E) {
183
+ return !E->getStartLoc ().isValid () || !E->getEndLoc ().isValid ();
184
+ }
185
+
180
186
// / An ASTWalker that maps ASTNodes to profiling counters.
181
187
struct MapRegionCounters : public ASTWalker {
182
188
// / The next counter value to assign.
@@ -238,6 +244,9 @@ struct MapRegionCounters : public ASTWalker {
238
244
}
239
245
240
246
std::pair<bool , Expr *> walkToExprPre (Expr *E) override {
247
+ if (skipExpr (E))
248
+ return {true , E};
249
+
241
250
// If AST visitation begins with an expression, the counter map must be
242
251
// empty. Set up a counter for the root.
243
252
if (Parent.isNull ()) {
@@ -400,7 +409,10 @@ class SourceMappingRegion {
400
409
401
410
bool hasStartLoc () const { return StartLoc.hasValue (); }
402
411
403
- void setStartLoc (SourceLoc Loc) { StartLoc = Loc; }
412
+ void setStartLoc (SourceLoc Loc) {
413
+ assert (Loc.isValid ());
414
+ StartLoc = Loc;
415
+ }
404
416
405
417
const SourceLoc &getStartLoc () const {
406
418
assert (StartLoc && " Region has no start location" );
@@ -409,7 +421,10 @@ class SourceMappingRegion {
409
421
410
422
bool hasEndLoc () const { return EndLoc.hasValue (); }
411
423
412
- void setEndLoc (SourceLoc Loc) { EndLoc = Loc; }
424
+ void setEndLoc (SourceLoc Loc) {
425
+ assert (Loc.isValid ());
426
+ EndLoc = Loc;
427
+ }
413
428
414
429
const SourceLoc &getEndLoc () const {
415
430
assert (EndLoc && " Region has no end location" );
@@ -573,6 +588,9 @@ struct PGOMapping : public ASTWalker {
573
588
}
574
589
575
590
std::pair<bool , Expr *> walkToExprPre (Expr *E) override {
591
+ if (skipExpr (E))
592
+ return {true , E};
593
+
576
594
unsigned parent = getParentCounter ();
577
595
578
596
if (Parent.isNull ()) {
@@ -996,6 +1014,9 @@ struct CoverageMapping : public ASTWalker {
996
1014
}
997
1015
998
1016
std::pair<bool , Expr *> walkToExprPre (Expr *E) override {
1017
+ if (skipExpr (E))
1018
+ return {true , E};
1019
+
999
1020
if (!RegionStack.empty ())
1000
1021
extendRegion (E);
1001
1022
0 commit comments