Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions clang/lib/CodeGen/CoverageMappingGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1505,6 +1505,14 @@ struct CounterCoverageMappingBuilder
handleFileExit(getEnd(S));
}

void VisitStmtExpr(const StmtExpr *E) {
Visit(E->getSubStmt());
// Any region termination (such as a noreturn CallExpr) within the statement
// expression has been handled by visiting the sub-statement. The visitor
// cannot be at a terminate statement leaving the statement expression.
HasTerminateStmt = false;
}

void VisitDecl(const Decl *D) {
Stmt *Body = D->getBody();

Expand Down
7 changes: 7 additions & 0 deletions clang/test/CoverageMapping/terminate-statements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,12 @@ int elsecondnoret(void) {
return 0;
}

// CHECK-LABEL: _Z18statementexprnoretb
int statementexprnoret(bool crash) {
int rc = ({ if (crash) abort(); 0; }); // CHECK: File 0, 351:35 -> 352:12 = (#0 - #1)
return rc; // CHECK-NOT: Gap
}

int main() {
foo(0);
foo(1);
Expand All @@ -368,5 +374,6 @@ int main() {
ornoret();
abstractcondnoret();
elsecondnoret();
statementexprnoret(false);
return 0;
}
21 changes: 21 additions & 0 deletions compiler-rt/test/profile/Linux/coverage-statement-expression.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// RUN: %clangxx_profgen -std=gnu++17 -fuse-ld=lld -fcoverage-mapping -o %t %s
// RUN: env LLVM_PROFILE_FILE=%t.profraw %run %t
// RUN: llvm-profdata merge -o %t.profdata %t.profraw
// RUN: llvm-cov show %t -instr-profile=%t.profdata 2>&1 | FileCheck %s

#include <stdio.h>

// clang-format off
__attribute__ ((__noreturn__))
void foo(void) { while (1); } // CHECK: [[@LINE]]| 0|void foo(void)
_Noreturn void bar(void) { while (1); } // CHECK: [[@LINE]]| 0|_Noreturn void bar(void)
// CHECK: [[@LINE]]| |
int main(int argc, char **argv) { // CHECK: [[@LINE]]| 1|int main(
int rc = ({ if (argc > 3) foo(); 0; }); // CHECK: [[@LINE]]| 1| int rc =
printf("coverage after foo is present\n"); // CHECK: [[@LINE]]| 1| printf(
// CHECK: [[@LINE]]| |
int rc2 = ({ if (argc > 3) bar(); 0; }); // CHECK: [[@LINE]]| 1| int rc2 =
printf("coverage after bar is present\n"); // CHECK: [[@LINE]]| 1| printf(
return rc + rc2; // CHECK: [[@LINE]]| 1| return rc
} // CHECK: [[@LINE]]| 1|}
// clang-format on
Loading