public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-4898] c++: cp_stabilize_reference and non-dep exprs [PR111919]
@ 2023-10-24 21:48 Patrick Palka
  0 siblings, 0 replies; only message in thread
From: Patrick Palka @ 2023-10-24 21:48 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:51f164f76212feaf896d65616f60877d3217b701

commit r14-4898-g51f164f76212feaf896d65616f60877d3217b701
Author: Patrick Palka <ppalka@redhat.com>
Date:   Tue Oct 24 17:48:00 2023 -0400

    c++: cp_stabilize_reference and non-dep exprs [PR111919]
    
    After the removal of NON_DEPENDENT_EXPR, cp_stabilize_reference (which
    used to just exit early for NON_DEPENDENT_EXPR) is now more prone to
    passing a weird templated tree to middle-end routines, which for the
    testcase below leads to a crash from contains_placeholder_p.  It seems
    the best fix is to just exit early when in a template context, like we
    do in the closely related function cp_save_expr.
    
            PR c++/111919
    
    gcc/cp/ChangeLog:
    
            * tree.cc (cp_stabilize_reference): Do nothing when
            processing_template_decl.
    
    gcc/testsuite/ChangeLog:
    
            * g++.dg/template/non-dependent27.C: New test.

Diff:
---
 gcc/cp/tree.cc                                  | 4 ++++
 gcc/testsuite/g++.dg/template/non-dependent27.C | 8 ++++++++
 2 files changed, 12 insertions(+)

diff --git a/gcc/cp/tree.cc b/gcc/cp/tree.cc
index a3d61d3e7c9..417c92ba76f 100644
--- a/gcc/cp/tree.cc
+++ b/gcc/cp/tree.cc
@@ -408,6 +408,10 @@ bitfield_p (const_tree ref)
 tree
 cp_stabilize_reference (tree ref)
 {
+  if (processing_template_decl)
+    /* As in cp_save_expr.  */
+    return ref;
+
   STRIP_ANY_LOCATION_WRAPPER (ref);
   switch (TREE_CODE (ref))
     {
diff --git a/gcc/testsuite/g++.dg/template/non-dependent27.C b/gcc/testsuite/g++.dg/template/non-dependent27.C
new file mode 100644
index 00000000000..c06bca73d64
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/non-dependent27.C
@@ -0,0 +1,8 @@
+// PR c++/111919
+
+int i[42];
+
+template<class T>
+void f() {
+  i[42 / (int)sizeof(T)] |= 42;
+}

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-10-24 21:48 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-24 21:48 [gcc r14-4898] c++: cp_stabilize_reference and non-dep exprs [PR111919] Patrick Palka

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).