[clang] [clang][coverage] fixing "if constexpr" and "if consteval" coverage report (PR #77214)

Jessica Paquette via cfe-commits cfe-commits at lists.llvm.org
Mon Jan 8 20:02:12 PST 2024


================
@@ -98,3 +104,49 @@ int main() {                    // CHECK: File 0, [[@LINE]]:12 -> {{[0-9]+}}:2 =
 void ternary() {
   true ? FOO : FOO; // CHECK-NOT: Gap,{{.*}}, [[@LINE]]:8 ->
 }
+
+// FIXME: Do not generate coverage for discarded branches in if consteval
+// GH-57377
+// CHECK-LABEL: _Z16check_constevalAi:
+constexpr int check_constevalA(int i) { // CHECK-NEXT: [[@LINE]]:39 -> {{[0-9]+}}:2 = #0
+  if consteval {                        
+    i *= 3;                             // CHECK-NEXT: [[@LINE-1]]:16 -> [[@LINE+1]]:4 = #1
+  } else {                              // CHECK-NEXT: Gap,File 0, [[@LINE]]:4 -> [[@LINE]]:10 = #0
+    i *= 5;                             // CHECK-NEXT: [[@LINE-1]]:10 -> [[@LINE+1]]:4 = #0
----------------
ornata wrote:

Specifically, it's the `else` region that shouldn't generate any coverage mapping data, right?

It'd be good to mention that in the `FIXME`; something like

> FIXME: Do not generate coverage for discarded branches in if consteval. The else case is discarded and should not be covered.

https://github.com/llvm/llvm-project/pull/77214


More information about the cfe-commits mailing list