[openmp] [clang] [coverage] fix crash in code coverage and `if constexpr` with `ExprWithCleanups` (PR #80292)

Hana Dusíková via cfe-commits cfe-commits at lists.llvm.org
Thu Feb 1 13:18:05 PST 2024


================
@@ -1808,12 +1808,24 @@ struct CounterCoverageMappingBuilder
     }
   }
 
+private:
+  static bool evaluateConstantCondition(const Expr *Condition) {
+    if (const auto *Expr = dyn_cast<ConstantExpr>(Condition))
+      return Expr->getResultAsAPSInt().getExtValue();
+
+    if (const auto *Expr = dyn_cast<ExprWithCleanups>(Condition))
+      return evaluateConstantCondition(Expr->getSubExpr()); // recursion
+
+    assert(false && "Unexpected node in 'if constexpr' condition");
+    return false;
+  }
+
+public:
----------------
hanickadot wrote:

Thanks!

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


More information about the cfe-commits mailing list