efriedma created this revision. 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). Repository: rL LLVM https://reviews.llvm.org/D36250 Files: lib/CodeGen/CoverageMappingGen.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: lib/CodeGen/CoverageMappingGen.cpp =================================================================== --- lib/CodeGen/CoverageMappingGen.cpp +++ lib/CodeGen/CoverageMappingGen.cpp @@ -716,6 +716,18 @@ terminateRegion(S); } + void VisitCallExpr(const CallExpr *E) { + extendRegion(E); + for (const Stmt *Child : E->children()) + this->Visit(Child); + + // 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);
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: lib/CodeGen/CoverageMappingGen.cpp =================================================================== --- lib/CodeGen/CoverageMappingGen.cpp +++ lib/CodeGen/CoverageMappingGen.cpp @@ -716,6 +716,18 @@ terminateRegion(S); } + void VisitCallExpr(const CallExpr *E) { + extendRegion(E); + for (const Stmt *Child : E->children()) + this->Visit(Child); + + // 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);
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits