]> granicus.if.org Git - clang/commitdiff
InstrProf: Don't start or end coverage regions inside of system macros
authorJustin Bogner <mail@justinbogner.com>
Tue, 5 May 2015 21:46:14 +0000 (21:46 +0000)
committerJustin Bogner <mail@justinbogner.com>
Tue, 5 May 2015 21:46:14 +0000 (21:46 +0000)
It doesn't make much sense to try to show coverage inside system
macros, and source locations in builtins confuses the coverage
mapping. Just avoid doing this.

Fixes an assert that fired when a __block storage specifier starts a
region.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@236547 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CoverageMappingGen.cpp
test/CoverageMapping/block-storage-starts-region.m [new file with mode: 0644]

index fca17264e8fc4a9138f12ea46c1c152dd5763e54..65415d9d2d29759b31f5dfe35fef2c2e6054d269 100644 (file)
@@ -134,18 +134,18 @@ public:
                            : SM.getIncludeLoc(SM.getFileID(Loc));
   }
 
-  /// \brief Get the start of \c S ignoring macro argument locations.
+  /// \brief Get the start of \c S ignoring macro arguments and system macros.
   SourceLocation getStart(const Stmt *S) {
     SourceLocation Loc = S->getLocStart();
-    while (SM.isMacroArgExpansion(Loc))
+    while (SM.isMacroArgExpansion(Loc) || SM.isInSystemMacro(Loc))
       Loc = SM.getImmediateExpansionRange(Loc).first;
     return Loc;
   }
 
-  /// \brief Get the end of \c S ignoring macro argument locations.
+  /// \brief Get the end of \c S ignoring macro arguments and system macros.
   SourceLocation getEnd(const Stmt *S) {
     SourceLocation Loc = S->getLocEnd();
-    while (SM.isMacroArgExpansion(Loc))
+    while (SM.isMacroArgExpansion(Loc) || SM.isInSystemMacro(Loc))
       Loc = SM.getImmediateExpansionRange(Loc).first;
     return getPreciseTokenLocEnd(Loc);
   }
diff --git a/test/CoverageMapping/block-storage-starts-region.m b/test/CoverageMapping/block-storage-starts-region.m
new file mode 100644 (file)
index 0000000..7997c8d
--- /dev/null
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -fprofile-instr-generate -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -triple x86_64-apple-darwin -fobjc-runtime=macosx-10.10.0 -fblocks -fobjc-arc %s | FileCheck %s
+
+@interface Foo
+@end
+
+// CHECK-LABEL: doSomething:
+void doSomething() { // CHECK: File 0, [[@LINE]]:20 -> {{[0-9:]+}} = #0
+  return;
+  __block Foo *f; // CHECK: File 0, [[@LINE]]:3 -> {{[0-9:]+}} = 0
+}
+
+int main() {}