r310406 - [coverage] Special-case calls to noreturn functions.
Eli Friedman via cfe-commits
cfe-commits at lists.llvm.org
Tue Aug 8 13:10:15 PDT 2017
Author: efriedma
Date: Tue Aug 8 13:10:14 2017
New Revision: 310406
URL: http://llvm.org/viewvc/llvm-project?rev=310406&view=rev
Log:
[coverage] Special-case calls to noreturn functions.
The code after a noreturn call doesn't execute.
The pattern in the testcase is pretty common in LLVM (a switch with
a default case that calls llvm_unreachable).
The original version of this patch was reverted in r309995 due to a
crash. This version includes a fix for that crash (testcase in
test/CoverageMapping/md.cpp).
Differential Revision: https://reviews.llvm.org/D36250
Modified:
cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp
cfe/trunk/test/CoverageMapping/md.cpp
cfe/trunk/test/CoverageMapping/switch.cpp
Modified: cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp?rev=310406&r1=310405&r2=310406&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp (original)
+++ cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp Tue Aug 8 13:10:14 2017
@@ -716,6 +716,16 @@ struct CounterCoverageMappingBuilder
terminateRegion(S);
}
+ void VisitCallExpr(const CallExpr *E) {
+ VisitStmt(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);
Modified: cfe/trunk/test/CoverageMapping/md.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CoverageMapping/md.cpp?rev=310406&r1=310405&r2=310406&view=diff
==============================================================================
--- cfe/trunk/test/CoverageMapping/md.cpp (original)
+++ cfe/trunk/test/CoverageMapping/md.cpp Tue Aug 8 13:10:14 2017
@@ -27,6 +27,17 @@ void foo(MD i) {
#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;
Modified: cfe/trunk/test/CoverageMapping/switch.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CoverageMapping/switch.cpp?rev=310406&r1=310405&r2=310406&view=diff
==============================================================================
--- cfe/trunk/test/CoverageMapping/switch.cpp (original)
+++ cfe/trunk/test/CoverageMapping/switch.cpp Tue Aug 8 13:10:14 2017
@@ -97,3 +97,16 @@ int fallthrough(int i) { // CHECK-NEXT:
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;
+ }
+}
More information about the cfe-commits
mailing list