public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/autopar_devel] c++: ICE with -Wall and constexpr if [PR94937]
@ 2020-08-22 21:22 Giuliano Belinassi
0 siblings, 0 replies; only message in thread
From: Giuliano Belinassi @ 2020-08-22 21:22 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:f04f784a3f182bc68c66caf2b5bae6cdd748d83d
commit f04f784a3f182bc68c66caf2b5bae6cdd748d83d
Author: Marek Polacek <polacek@redhat.com>
Date: Wed May 6 19:24:58 2020 -0400
c++: ICE with -Wall and constexpr if [PR94937]
An ICE arises here because we call cp_get_callee_fndecl_nofold in a
template, and we've got a CALL_EXPR whose CALL_EXPR_FN is a BASELINK.
This tickles the INDIRECT_TYPE_P assert in cp_get_fndecl_from_callee.
Fixed by turning the assert into a condition and returning NULL_TREE
in that case.
PR c++/94937
* cvt.c (cp_get_fndecl_from_callee): Return NULL_TREE if the function
type is not INDIRECT_TYPE_P.
* decl.c (omp_declare_variant_finalize_one): Call
cp_get_callee_fndecl_nofold instead of looking for the function decl
manually.
* g++.dg/cpp1z/constexpr-if34.C: New test.
* g++.dg/cpp2a/is-constant-evaluated10.C: New test.
Diff:
---
gcc/cp/ChangeLog | 9 +++++++
gcc/cp/cvt.c | 3 +--
gcc/cp/decl.c | 12 +--------
gcc/testsuite/ChangeLog | 6 +++++
gcc/testsuite/g++.dg/cpp1z/constexpr-if34.C | 15 +++++++++++
.../g++.dg/cpp2a/is-constant-evaluated10.C | 30 ++++++++++++++++++++++
6 files changed, 62 insertions(+), 13 deletions(-)
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index d8ad1d63bd4..605cdf33ae4 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,12 @@
+2020-05-18 Marek Polacek <polacek@redhat.com>
+
+ PR c++/94937
+ * cvt.c (cp_get_fndecl_from_callee): Return NULL_TREE if the function
+ type is not INDIRECT_TYPE_P.
+ * decl.c (omp_declare_variant_finalize_one): Call
+ cp_get_callee_fndecl_nofold instead of looking for the function decl
+ manually.
+
2020-05-18 Marek Polacek <polacek@redhat.com>
PR c++/90915
diff --git a/gcc/cp/cvt.c b/gcc/cp/cvt.c
index 656e7fd3ec0..371002833d0 100644
--- a/gcc/cp/cvt.c
+++ b/gcc/cp/cvt.c
@@ -995,9 +995,8 @@ cp_get_fndecl_from_callee (tree fn, bool fold /* = true */)
if (TREE_CODE (fn) == FUNCTION_DECL)
return fn;
tree type = TREE_TYPE (fn);
- if (type == unknown_type_node)
+ if (type == NULL_TREE || !INDIRECT_TYPE_P (type))
return NULL_TREE;
- gcc_assert (INDIRECT_TYPE_P (type));
if (fold)
fn = maybe_constant_init (fn);
STRIP_NOPS (fn);
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 7c7ca1ff1c0..6469850e2dc 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -7295,17 +7295,7 @@ omp_declare_variant_finalize_one (tree decl, tree attr)
if (variant == error_mark_node && !processing_template_decl)
return true;
- variant = cp_get_callee (variant);
- if (variant)
- {
- if (TREE_CODE (variant) == FUNCTION_DECL)
- ;
- else if (TREE_TYPE (variant) && INDIRECT_TYPE_P (TREE_TYPE (variant)))
- variant = cp_get_fndecl_from_callee (variant, false);
- else
- variant = NULL_TREE;
- }
-
+ variant = cp_get_callee_fndecl_nofold (variant);
input_location = save_loc;
if (variant)
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 40e9d666f00..67f2c550ff0 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,9 @@
+2020-05-18 Marek Polacek <polacek@redhat.com>
+
+ PR c++/94937
+ * g++.dg/cpp1z/constexpr-if34.C: New test.
+ * g++.dg/cpp2a/is-constant-evaluated10.C: New test.
+
2020-05-18 Martin Sebor <msebor@redhat.com>
PR middle-end/92815
diff --git a/gcc/testsuite/g++.dg/cpp1z/constexpr-if34.C b/gcc/testsuite/g++.dg/cpp1z/constexpr-if34.C
new file mode 100644
index 00000000000..6e0b2597a53
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1z/constexpr-if34.C
@@ -0,0 +1,15 @@
+// PR c++/94937 - ICE with -Wall and constexpr if.
+// { dg-do compile { target c++17 } }
+// { dg-options "-Wall" }
+
+struct B {
+ static constexpr bool foo() { return false; }
+};
+
+template<typename T>
+struct C {
+ static void bar ()
+ {
+ if constexpr (B::foo()) ;
+ }
+};
diff --git a/gcc/testsuite/g++.dg/cpp2a/is-constant-evaluated10.C b/gcc/testsuite/g++.dg/cpp2a/is-constant-evaluated10.C
new file mode 100644
index 00000000000..7b2e345f448
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/is-constant-evaluated10.C
@@ -0,0 +1,30 @@
+// { dg-do compile { target c++2a } }
+// { dg-options "-Wtautological-compare" }
+
+namespace std {
+ constexpr inline bool
+ is_constant_evaluated () noexcept
+ {
+ return __builtin_is_constant_evaluated ();
+ }
+}
+
+template<typename>
+constexpr int
+foo(int i)
+{
+ if constexpr (std::is_constant_evaluated ()) // { dg-warning ".std::is_constant_evaluated. always evaluates to true in .if constexpr." }
+ return 42;
+ else
+ return i;
+}
+
+template<typename>
+constexpr int
+foo2(int i)
+{
+ if constexpr (__builtin_is_constant_evaluated ()) // { dg-warning ".std::is_constant_evaluated. always evaluates to true in .if constexpr." }
+ return 42;
+ else
+ return i;
+}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2020-08-22 21:22 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-22 21:22 [gcc/devel/autopar_devel] c++: ICE with -Wall and constexpr if [PR94937] Giuliano Belinassi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).