[clang] [llvm] [Coverage][MC/DC] Show uncoverable and unreachable conditions (PR #94137)

Alan Phipps via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 21 07:56:42 PDT 2024


================
@@ -1128,15 +1132,22 @@ struct CounterCoverageMappingBuilder
         BranchParams = mcdc::BranchParameters{ID, Conds};
 
       // If a condition can fold to true or false, the corresponding branch
-      // will be removed.  Create a region with both counters hard-coded to
-      // zero. This allows us to visualize them in a special way.
+      // will be removed. Create a region with the relative counter hard-coded
+      // to zero. This allows us to visualize them in a special way.
       // Alternatively, we can prevent any optimization done via
       // constant-folding by ensuring that ConstantFoldsToSimpleInteger() in
       // CodeGenFunction.c always returns false, but that is very heavy-handed.
-      if (ConditionFoldsToBool(C))
-        popRegions(pushRegion(Counter::getZero(), getStart(C), getEnd(C),
-                              Counter::getZero(), BranchParams));
-      else
+      bool ConstantBool = false;
+      if (ConditionFoldsToBool(C, ConstantBool)) {
+        if (ConstantBool) {
+          popRegions(pushRegion(TrueCnt, getStart(C), getEnd(C),
+                                Counter::getZero(), BranchParams));
+        } else {
+          popRegions(pushRegion(Counter::getZero(), getStart(C), getEnd(C),
----------------
evodius96 wrote:

Since I added `FalseCount` (i.e. the 2nd Counter for CounterMappingRegion), I think overriding what hard "0" means for this purpose is fine. However, for `Count` (i.e. the 1st Counter for CounterMappingRegion), we ought to be sure that the hard "0" doesn't already mean something.  I suspect that when used with the `BranchRegion` or `MCDCBranchRegion`, this is also fine.

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


More information about the llvm-commits mailing list