diff options
author | Hana Dusíková <hanicka@hanicka.net> | 2024-02-01 23:31:32 +0100 |
---|---|---|
committer | Tom Stellard <tstellar@redhat.com> | 2024-02-01 17:53:25 -0800 |
commit | 3eaa7f3c44597e1027e29ffecb83e374fb7fa52c (patch) | |
tree | 4b146d150e96f714faca0e025f29fb5fbee2f90a /clang | |
parent | 615e6dd1c5856e1657332492c640ba456caa8266 (diff) | |
download | llvm-3eaa7f3c44597e1027e29ffecb83e374fb7fa52c.zip llvm-3eaa7f3c44597e1027e29ffecb83e374fb7fa52c.tar.gz llvm-3eaa7f3c44597e1027e29ffecb83e374fb7fa52c.tar.bz2 |
[coverage] fix crash in code coverage and `if constexpr` with `ExprWithCleanups` (#80292)
Fixes https://github.com/llvm/llvm-project/issues/80285
(cherry picked from commit bfc6eaa26326e4d0d20d1f4a1f0064c6df0135bd)
Diffstat (limited to 'clang')
-rw-r--r-- | clang/lib/CodeGen/CoverageMappingGen.cpp | 6 | ||||
-rw-r--r-- | clang/test/CoverageMapping/if.cpp | 29 |
2 files changed, 33 insertions, 2 deletions
diff --git a/clang/lib/CodeGen/CoverageMappingGen.cpp b/clang/lib/CodeGen/CoverageMappingGen.cpp index 5eca00f..0c43317 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 3045ffe..445cdfc 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); |