r230304 - InstrProf: Make sure counts in lambdas don't escape to the parent scope

Justin Bogner mail at justinbogner.com
Mon Feb 23 20:13:57 PST 2015


Author: bogner
Date: Mon Feb 23 22:13:56 2015
New Revision: 230304

URL: http://llvm.org/viewvc/llvm-project?rev=230304&view=rev
Log:
InstrProf: Make sure counts in lambdas don't escape to the parent scope

When generating coverage maps, we were traversing the body as if it
were part of the parent function, but this doesn't make sense since
we're currently counting lambdas as separate functions.

Added:
    cfe/trunk/test/CoverageMapping/lambda.cpp
Modified:
    cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp

Modified: cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp?rev=230304&r1=230303&r2=230304&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp (original)
+++ cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp Mon Feb 23 22:13:56 2015
@@ -850,6 +850,11 @@ struct CounterCoverageMappingBuilder
     extendRegion(E->getRHS());
     propagateCounts(getRegionCounter(E), E->getRHS());
   }
+
+  void VisitLambdaExpr(const LambdaExpr *LE) {
+    // Lambdas are treated as their own functions for now, so we shouldn't
+    // propagate counts into them.
+  }
 };
 }
 

Added: cfe/trunk/test/CoverageMapping/lambda.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CoverageMapping/lambda.cpp?rev=230304&view=auto
==============================================================================
--- cfe/trunk/test/CoverageMapping/lambda.cpp (added)
+++ cfe/trunk/test/CoverageMapping/lambda.cpp Mon Feb 23 22:13:56 2015
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 -x c++ -std=c++11 -triple %itanium_abi_triple -fprofile-instr-generate -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only %s -main-file-name lambda.cpp | FileCheck %s
+
+// CHECK-LABEL: _Z3fooi:
+void foo(int i) { // CHECK: File 0, [[@LINE]]:17 -> {{[0-9]+}}:2 = #0
+  auto f = [](int x) {
+    return x + 1;
+  };
+
+  f(i);
+  // Make sure the zero region after the return doesn't escape the lambda.
+  // CHECK-NOT: File 0, {{[0-9:]+}} -> [[@LINE+1]]:2 = 0
+}
+
+int main(int argc, const char *argv[]) {
+  foo(1);
+  return 0;
+}





More information about the cfe-commits mailing list