[PATCH] D36250: [coverage] Special-case calls to noreturn functions.

Eli Friedman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Aug 4 17:03:05 PDT 2017


efriedma updated this revision to Diff 109838.
efriedma added a comment.

Add missing call to handleFileExit().

Not sure I'm really calling it in the right place, but this seems to work.


Repository:
  rL LLVM

https://reviews.llvm.org/D36250

Files:
  lib/CodeGen/CoverageMappingGen.cpp
  test/CoverageMapping/md.cpp
  test/CoverageMapping/switch.cpp


Index: test/CoverageMapping/switch.cpp
===================================================================
--- test/CoverageMapping/switch.cpp
+++ test/CoverageMapping/switch.cpp
@@ -97,3 +97,16 @@
     break;
   }
 }
+
+void abort(void) __attribute((noreturn));
+                   // CHECK: noret
+int noret(int x) { // CHECK-NEXT: File 0, [[@LINE]]:18 -> [[@LINE+9]]:2
+  switch (x) {
+  default:         // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+1]]:12
+    abort();
+  case 1:         // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+1]]:13
+    return 5;
+  case 2:         // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+1]]:14
+    return 10;
+  }
+}
Index: test/CoverageMapping/md.cpp
===================================================================
--- test/CoverageMapping/md.cpp
+++ test/CoverageMapping/md.cpp
@@ -27,6 +27,17 @@
   #include "Inputs/md.def"
 }
 
+// CHECK: bar
+// CHECK-NEXT: File 0, [[@LINE+3]]:12 -> [[@LINE+8]]:2 = #0
+bool isVal1();
+bool isVal2();
+bool bar() {
+ #define HANDLE_MD(X) is##X() ||
+  return
+#include "Inputs/md.def"
+  0;
+}
+
 int main(int argc, const char *argv[]) {
   foo(MD::Val1);
   return 0;
Index: lib/CodeGen/CoverageMappingGen.cpp
===================================================================
--- lib/CodeGen/CoverageMappingGen.cpp
+++ lib/CodeGen/CoverageMappingGen.cpp
@@ -716,6 +716,19 @@
     terminateRegion(S);
   }
 
+  void VisitCallExpr(const CallExpr *E) {
+    extendRegion(E);
+    for (const Stmt *Child : E->children())
+      this->Visit(Child);
+    handleFileExit(getEnd(E));
+
+    // Terminate the region when we hit a noreturn function.
+    // (This is helpful dealing with switch statements.)
+    QualType CalleeType = E->getCallee()->getType();
+    if (getFunctionExtInfo(*CalleeType).getNoReturn())
+      terminateRegion(E);
+  }
+
   void VisitWhileStmt(const WhileStmt *S) {
     extendRegion(S);
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D36250.109838.patch
Type: text/x-patch
Size: 1898 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170805/7babd35c/attachment.bin>


More information about the cfe-commits mailing list