[Openmp-commits] [openmp] [clang] [coverage] fix crash in code coverage and `if constexpr` with `ExprWithCleanups` (PR #80292)
Hana Dusíková via Openmp-commits
openmp-commits at lists.llvm.org
Thu Feb 1 13:17:15 PST 2024
https://github.com/hanickadot updated https://github.com/llvm/llvm-project/pull/80292
>From 84817eb419dfe0a66e8b4b1d21cf67cbc6b20199 Mon Sep 17 00:00:00 2001
From: Alexandre Ganea <37383324+aganea at users.noreply.github.com>
Date: Thu, 1 Feb 2024 08:14:05 -0500
Subject: [PATCH] [coverage] fix crash in code coverage and `if constexpr` with
`ExprWithCleanups`
---
clang/lib/CodeGen/CoverageMappingGen.cpp | 6 +++--
clang/test/CoverageMapping/if.cpp | 29 ++++++++++++++++++++++++
openmp/cmake/HandleOpenMPOptions.cmake | 8 +++++++
3 files changed, 41 insertions(+), 2 deletions(-)
diff --git a/clang/lib/CodeGen/CoverageMappingGen.cpp b/clang/lib/CodeGen/CoverageMappingGen.cpp
index 8b5e6c4ad8272..f7f73546af017 100644
--- a/clang/lib/CodeGen/CoverageMappingGen.cpp
+++ b/clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -1812,8 +1812,10 @@ struct CounterCoverageMappingBuilder
assert(S->isConstexpr());
// evaluate constant condition...
- const auto *E = cast<ConstantExpr>(S->getCond());
- const bool isTrue = E->getResultAsAPSInt().getExtValue();
+ const bool isTrue =
+ S->getCond()
+ ->EvaluateKnownConstInt(CVM.getCodeGenModule().getContext())
+ .getBoolValue();
extendRegion(S);
diff --git a/clang/test/CoverageMapping/if.cpp b/clang/test/CoverageMapping/if.cpp
index 3045ffe43948c..4de1467aa7ee3 100644
--- a/clang/test/CoverageMapping/if.cpp
+++ b/clang/test/CoverageMapping/if.cpp
@@ -234,6 +234,35 @@ constexpr int check_macro_consteval_if_skipped(int i) { // CHECK-NEXT: [[@LINE
return i;
}
+struct false_value {
+ constexpr operator bool() {
+ return false;
+ }
+};
+
+template <typename> struct dependable_false_value {
+ constexpr operator bool() {
+ return false;
+ }
+};
+
+// GH-80285
+void should_not_crash() {
+ if constexpr (false_value{}) { };
+}
+
+template <typename> void should_not_crash_dependable() {
+ if constexpr (dependable_false_value<int>{}) { };
+}
+
+void should_not_crash_with_template_instance() {
+ should_not_crash_dependable<int>();
+}
+
+void should_not_crash_with_requires_expr() {
+ if constexpr (requires {42;}) { };
+}
+
int instantiate_consteval(int i) {
i *= check_consteval_with_else_discarded_then(i);
i *= check_notconsteval_with_else_discarded_else(i);
diff --git a/openmp/cmake/HandleOpenMPOptions.cmake b/openmp/cmake/HandleOpenMPOptions.cmake
index 201aeabbd3df9..71346201129b6 100644
--- a/openmp/cmake/HandleOpenMPOptions.cmake
+++ b/openmp/cmake/HandleOpenMPOptions.cmake
@@ -9,6 +9,14 @@ if (NOT COMMAND append_if)
endfunction()
endif()
+if (NOT COMMAND append)
+ function(append value)
+ foreach(variable ${ARGN})
+ set(${variable} "${${variable}} ${value}" PARENT_SCOPE)
+ endforeach(variable)
+ endfunction()
+endif()
+
# MSVC and clang-cl in compatibility mode map -Wall to -Weverything.
# TODO: LLVM adds /W4 instead, check if that works for the OpenMP runtimes.
if (NOT MSVC)
More information about the Openmp-commits
mailing list