@@ -247,6 +247,11 @@ struct MapRegionCounters : public ASTWalker {
247
247
if (skipExpr (E))
248
248
return {true , E};
249
249
250
+ // Profiling for closures should be handled separately. Do not visit
251
+ // closure expressions twice.
252
+ if (isa<AbstractClosureExpr>(E) && !Parent.isNull ())
253
+ return {false , E};
254
+
250
255
// If AST visitation begins with an expression, the counter map must be
251
256
// empty. Set up a counter for the root.
252
257
if (Parent.isNull ()) {
@@ -430,6 +435,20 @@ class SourceMappingRegion {
430
435
assert (EndLoc && " Region has no end location" );
431
436
return *EndLoc;
432
437
}
438
+
439
+ void print (llvm::raw_ostream &OS, const SourceManager &SM) const {
440
+ OS << " [" ;
441
+ if (hasStartLoc ())
442
+ getStartLoc ().print (OS, SM);
443
+ else
444
+ OS << " ?" ;
445
+ OS << " , " ;
446
+ if (hasEndLoc ())
447
+ getEndLoc ().print (OS, SM);
448
+ else
449
+ OS << " ?" ;
450
+ OS << " ]" ;
451
+ }
433
452
};
434
453
435
454
// / An ASTWalker that maps ASTNodes to profiling counters.
@@ -591,6 +610,11 @@ struct PGOMapping : public ASTWalker {
591
610
if (skipExpr (E))
592
611
return {true , E};
593
612
613
+ // Profiling for closures should be handled separately. Do not visit
614
+ // closure expressions twice.
615
+ if (isa<AbstractClosureExpr>(E) && !Parent.isNull ())
616
+ return {false , E};
617
+
594
618
unsigned parent = getParentCounter ();
595
619
596
620
if (Parent.isNull ()) {
@@ -754,6 +778,11 @@ struct CoverageMapping : public ASTWalker {
754
778
void pushRegion (ASTNode Node) {
755
779
RegionStack.emplace_back (Node, getCounter (Node), Node.getStartLoc (),
756
780
getEndLoc (Node));
781
+ LLVM_DEBUG ({
782
+ llvm::dbgs () << " Pushed region: " ;
783
+ RegionStack.back ().print (llvm::dbgs (), SM);
784
+ llvm::dbgs () << " \n " ;
785
+ });
757
786
}
758
787
759
788
// / Replace the current region's count by pushing an incomplete region.
@@ -780,6 +809,8 @@ struct CoverageMapping : public ASTWalker {
780
809
auto ParentIt = I;
781
810
SourceLoc EndLoc = ParentIt->getEndLoc ();
782
811
812
+ unsigned FirstPoppedIndex = SourceRegions.size ();
813
+ (void )FirstPoppedIndex;
783
814
SourceRegions.push_back (std::move (*I++));
784
815
for (; I != E; ++I) {
785
816
if (!I->hasStartLoc ())
@@ -789,6 +820,14 @@ struct CoverageMapping : public ASTWalker {
789
820
SourceRegions.push_back (std::move (*I));
790
821
}
791
822
823
+ LLVM_DEBUG ({
824
+ for (unsigned Idx = FirstPoppedIndex; Idx < SourceRegions.size (); ++Idx) {
825
+ llvm::dbgs () << " Popped region: " ;
826
+ SourceRegions[Idx].print (llvm::dbgs (), SM);
827
+ llvm::dbgs () << " \n " ;
828
+ }
829
+ });
830
+
792
831
RegionStack.erase (ParentIt, E);
793
832
}
794
833
@@ -1017,6 +1056,11 @@ struct CoverageMapping : public ASTWalker {
1017
1056
if (skipExpr (E))
1018
1057
return {true , E};
1019
1058
1059
+ // Profiling for closures should be handled separately. Do not visit
1060
+ // closure expressions twice.
1061
+ if (isa<AbstractClosureExpr>(E) && !Parent.isNull ())
1062
+ return {false , E};
1063
+
1020
1064
if (!RegionStack.empty ())
1021
1065
extendRegion (E);
1022
1066
0 commit comments