[Bug c++/99132] [11 Regression] ICE in C++20 mode for constexpr not_null evaluation -- in cxx_eval_indirect_ref, at cp/constexpr.c:4905
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99132 Jakub Jelinek changed: What|Removed |Added Status|ASSIGNED|RESOLVED Resolution|--- |FIXED --- Comment #11 from Jakub Jelinek --- Fixed.
[Bug c++/99132] [11 Regression] ICE in C++20 mode for constexpr not_null evaluation -- in cxx_eval_indirect_ref, at cp/constexpr.c:4905
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99132 --- Comment #10 from CVS Commits --- The master branch has been updated by Jakub Jelinek : https://gcc.gnu.org/g:3bfa96895b3219afd93a7038850baef4b63c1f82 commit r11-7279-g3bfa96895b3219afd93a7038850baef4b63c1f82 Author: Jakub Jelinek Date: Thu Feb 18 16:21:52 2021 +0100 c++: Fix -std=c++20 ICE on virtual method call [PR99132] On the following testcase we ICE in C++20 mode during cp_get_callee_fndecl -> constexpr evaluation. It is only in C++20 mode on this testcase because virtual methods can't be constexpr in C++17 and earlier and so potential_constant_expression_1 rejects it earlier. And the ICE is caused by genericization changing the h PARM_DECL from having B type to B & DECL_BY_REFERENCE and the constexpr evaluation not being able to deal with that. I think this just shows that we shouldn't do the constexpr evaluation during genericization and later, and other spots e.g. during gimplification also don't call cp_get_callee_fndecl but cp_get_callee_fndecl_nofold. After all, cp_fold has already been run and it did the folding if there was any opportunity to do so. And furthermore, what that cp_genericize_r spot does is check for any left-over immediate function calls (which can be ATM just std::source_location::current() call) and immediate functions outside of immediate functions can't have addresses leaked into the IL, so it will be always a direct call anyway. And immediate functions themselves don't make it into genericization/gimplification. 2021-02-18 Jakub Jelinek PR c++/99132 * cp-gimplify.c (cp_genericize_r) : Use cp_get_callee_fndecl_nofold instead of cp_get_callee_fndecl to check for immediate function calls. * g++.dg/cpp2a/constexpr-virtual18.C: New test.
[Bug c++/99132] [11 Regression] ICE in C++20 mode for constexpr not_null evaluation -- in cxx_eval_indirect_ref, at cp/constexpr.c:4905
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99132 --- Comment #9 from Jakub Jelinek --- Ah, the reason it only ICEs with -std=c++20 is that C++17 and earlier don't allow virtual functions to be constexpr and therefore potential_constant_expression_1 doesn't let it try to evaluate the expression. And the reason for the ICE is that genericization changed the h parameter from having B type to B& as it needs to be passed by invisible reference, and the constexpr code is not prepared to handle that (i.e. be run so late). Thus I think the above patch is the right fix.
[Bug c++/99132] [11 Regression] ICE in C++20 mode for constexpr not_null evaluation -- in cxx_eval_indirect_ref, at cp/constexpr.c:4905
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99132 --- Comment #8 from Jakub Jelinek --- We certainly can (and IMHO should) do: --- gcc/cp/cp-gimplify.c.jj 2021-02-10 07:52:32.702901304 +0100 +++ gcc/cp/cp-gimplify.c2021-02-17 16:06:03.045953720 +0100 @@ -1386,7 +1386,7 @@ cp_genericize_r (tree *stmt_p, int *walk break; } - if (tree fndecl = cp_get_callee_fndecl (stmt)) + if (tree fndecl = cp_get_callee_fndecl_nofold (stmt)) if (DECL_IMMEDIATE_FUNCTION_P (fndecl)) { gcc_assert (source_location_current_p (fndecl)); because addresses of immediate functions shouldn't be leaking in the IL anywhere and so only direct calls to them are possible. The strange thing is why it ICEs only with -std=c++20...
[Bug c++/99132] [11 Regression] ICE in C++20 mode for constexpr not_null evaluation -- in cxx_eval_indirect_ref, at cp/constexpr.c:4905
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99132 Jakub Jelinek changed: What|Removed |Added Status|NEW |ASSIGNED Assignee|unassigned at gcc dot gnu.org |jakub at gcc dot gnu.org --- Comment #7 from Jakub Jelinek --- Ok, will have a look then...
[Bug c++/99132] [11 Regression] ICE in C++20 mode for constexpr not_null evaluation -- in cxx_eval_indirect_ref, at cp/constexpr.c:4905
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99132 --- Comment #6 from Jakub Jelinek --- template struct A { T c; }; template struct B { A d; constexpr T operator->() { return d.c; } B(B &&); }; struct C { virtual void foo (); void bar (B h) { h->foo (); } };
[Bug c++/99132] [11 Regression] ICE in C++20 mode for constexpr not_null evaluation -- in cxx_eval_indirect_ref, at cp/constexpr.c:4905
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99132 --- Comment #5 from Marek Polacek --- Started with r11-5685.
[Bug c++/99132] [11 Regression] ICE in C++20 mode for constexpr not_null evaluation -- in cxx_eval_indirect_ref, at cp/constexpr.c:4905
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99132 Jakub Jelinek changed: What|Removed |Added CC||jakub at gcc dot gnu.org --- Comment #4 from Jakub Jelinek --- Reducing...
[Bug c++/99132] [11 Regression] ICE in C++20 mode for constexpr not_null evaluation -- in cxx_eval_indirect_ref, at cp/constexpr.c:4905
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99132 Marek Polacek changed: What|Removed |Added Summary|ICE in C++20 mode for |[11 Regression] ICE in |constexpr not_null |C++20 mode for constexpr |evaluation -- in |not_null evaluation -- in |cxx_eval_indirect_ref, at |cxx_eval_indirect_ref, at |cp/constexpr.c:4905 |cp/constexpr.c:4905 Target Milestone|--- |11.0 Status|UNCONFIRMED |NEW Ever confirmed|0 |1 CC||mpolacek at gcc dot gnu.org Keywords||ice-on-valid-code Last reconfirmed||2021-02-17 Priority|P3 |P1 --- Comment #3 from Marek Polacek --- Confirmed.