From 191ec63b718d85b3445bfb29b01a3f4ddee989e2 Mon Sep 17 00:00:00 2001 From: Justin Bogner Date: Fri, 11 Apr 2014 23:06:35 +0000 Subject: CodeGen: Fix handling of C++11 lambdas in profiling Until now we were generating duplicate counters for lambdas: one set in the function where the lambda was declared and another for the lambda itself. Instead, we should skip over the bodies of lambdas in their containing contexts. llvm-svn: 206081 --- clang/lib/CodeGen/CodeGenPGO.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'clang/lib/CodeGen/CodeGenPGO.cpp') diff --git a/clang/lib/CodeGen/CodeGenPGO.cpp b/clang/lib/CodeGen/CodeGenPGO.cpp index 37ba0fb8851..4dbd01a6619 100644 --- a/clang/lib/CodeGen/CodeGenPGO.cpp +++ b/clang/lib/CodeGen/CodeGenPGO.cpp @@ -331,9 +331,10 @@ namespace { MapRegionCounters(llvm::DenseMap &CounterMap) : NextCounter(0), CounterMap(CounterMap) {} - // Do not traverse the BlockDecl inside a BlockExpr since each BlockDecl - // is handled as a separate function. - bool TraverseBlockExpr(BlockExpr *block) { return true; } + // Blocks and lambdas are handled as separate functions, so we need not + // traverse them in the parent context. + bool TraverseBlockExpr(BlockExpr *BE) { return true; } + bool TraverseLambdaBody(LambdaExpr *LE) { return true; } bool VisitDecl(const Decl *D) { switch (D->getKind()) { @@ -431,6 +432,11 @@ namespace { Visit(D->getBody()); } + // Skip lambda expressions. We visit these as FunctionDecls when we're + // generating them and aren't interested in the body when generating a + // parent context. + void VisitLambdaExpr(const LambdaExpr *LE) {} + void VisitObjCMethodDecl(const ObjCMethodDecl *D) { // Counter tracks entry to the method body. RegionCounter Cnt(PGO, D->getBody()); -- cgit v1.2.3