From 15ed55eabb0cf8a2974b8025a9f46c9e58960811 Mon Sep 17 00:00:00 2001 From: Marek Polacek Date: Wed, 22 Jan 2020 11:44:13 -0500 Subject: [PATCH] PR c++/93324 - ICE with -Wall on constexpr if. This is a crash with constexpr if, when trying to see if the call in the if-statement is std::is_constant_evaluated. cp_get_callee_fndecl_nofold can return NULL_TREE and fndecl_built_in_p doesn't expect to get a null tree, so check FNDECL first. --- gcc/cp/ChangeLog | 5 +++++ gcc/cp/semantics.c | 3 +++ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/cpp1z/constexpr-if33.C | 16 ++++++++++++++++ 4 files changed, 29 insertions(+) create mode 100644 gcc/testsuite/g++.dg/cpp1z/constexpr-if33.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 3d582383227..d9946997ba0 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2020-01-22 Marek Polacek + + PR c++/93324 - ICE with -Wall on constexpr if. + * semantics.c (is_std_constant_evaluated_p): Check fndecl. + 2020-01-22 Patrick Palka * constraint.cc (get_mapped_args): Avoid using auto_vec diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index 3669b247e34..3b88f1520bc 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -734,6 +734,9 @@ is_std_constant_evaluated_p (tree fn) return false; tree fndecl = cp_get_callee_fndecl_nofold (fn); + if (fndecl == NULL_TREE) + return false; + if (fndecl_built_in_p (fndecl, CP_BUILT_IN_IS_CONSTANT_EVALUATED, BUILT_IN_FRONTEND)) return true; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index d22747b1dfe..70d7e8869e1 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2020-01-22 Marek Polacek + + PR c++/93324 - ICE with -Wall on constexpr if. + * g++.dg/cpp1z/constexpr-if33.C: New test. + 2020-01-22 Richard Sandiford * gcc.target/aarch64/sve/acle/general/stack_vars_1.c: New test. diff --git a/gcc/testsuite/g++.dg/cpp1z/constexpr-if33.C b/gcc/testsuite/g++.dg/cpp1z/constexpr-if33.C new file mode 100644 index 00000000000..e5ef659932b --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1z/constexpr-if33.C @@ -0,0 +1,16 @@ +// PR c++/93324 - ICE with -Wall on constexpr if. +// { dg-do compile { target c++17 } } +// { dg-options "-Wall" } + +struct { + template + static constexpr bool a() { return 0; } +} e; + +template +void d() +{ + auto c(e); + using b = decltype(c); + if constexpr (b::a<2>()); +} -- 2.30.2