public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-4845] middle-end/103038 - avoid ICE with -ftrivial-auto-var-init=pattern
@ 2021-11-02 13:17 Richard Biener
  0 siblings, 0 replies; only message in thread
From: Richard Biener @ 2021-11-02 13:17 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:268b43d2592c196ea101946d7063156a914b2713

commit r12-4845-g268b43d2592c196ea101946d7063156a914b2713
Author: Richard Biener <rguenther@suse.de>
Date:   Tue Nov 2 09:58:00 2021 +0100

    middle-end/103038 - avoid ICE with -ftrivial-auto-var-init=pattern
    
    This avoids ICEing with expanding a VIEW_CONVERT_EXRP of a SSA name
    on the LHS by making sure we can native-interpret OFFSET_TYPE and
    by never building such a LHS but instead view-converting the RHS
    for SSA LHS.
    
    2021-11-02  Richard Biener  <rguenther@suse.de>
    
            PR middle-end/103038
            * fold-const.c (native_interpret_expr): Handle OFFSET_TYPE.
            (can_native_interpret_type_p): Likewise.
            * internal-fn.c (expand_DEFERRED_INIT): View-convert the
            RHS if the LHS is an SSA name.
    
            * g++.dg/pr103038.C: New testcase.

Diff:
---
 gcc/fold-const.c                | 2 ++
 gcc/internal-fn.c               | 8 ++++++--
 gcc/testsuite/g++.dg/pr103038.C | 5 +++++
 3 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index 54f91f0149c..2d3ba07e541 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -8791,6 +8791,7 @@ native_interpret_expr (tree type, const unsigned char *ptr, int len)
     case BOOLEAN_TYPE:
     case POINTER_TYPE:
     case REFERENCE_TYPE:
+    case OFFSET_TYPE:
       return native_interpret_int (type, ptr, len);
 
     case REAL_TYPE:
@@ -8827,6 +8828,7 @@ can_native_interpret_type_p (tree type)
     case REAL_TYPE:
     case COMPLEX_TYPE:
     case VECTOR_TYPE:
+    case OFFSET_TYPE:
       return true;
     default:
       return false;
diff --git a/gcc/internal-fn.c b/gcc/internal-fn.c
index 9e10da0ad5c..fd6cb0995d9 100644
--- a/gcc/internal-fn.c
+++ b/gcc/internal-fn.c
@@ -3090,8 +3090,12 @@ expand_DEFERRED_INIT (internal_fn, gcall *stmt)
 			     (total_bytes * BITS_PER_UNIT, 1);
 	      wide_int w = wi::from_buffer (buf, total_bytes);
 	      init = wide_int_to_tree (itype, w);
-	      /* Pun the LHS to make sure its type has constant size.  */
-	      lhs = build1 (VIEW_CONVERT_EXPR, itype, lhs);
+	      /* Pun the LHS to make sure its type has constant size
+		 unless it is an SSA name where that's already known.  */
+	      if (TREE_CODE (lhs) != SSA_NAME)
+		lhs = build1 (VIEW_CONVERT_EXPR, itype, lhs);
+	      else
+		init = build1 (VIEW_CONVERT_EXPR, TREE_TYPE (lhs), init);
 	    }
 	}
       else
diff --git a/gcc/testsuite/g++.dg/pr103038.C b/gcc/testsuite/g++.dg/pr103038.C
new file mode 100644
index 00000000000..bb7183a460e
--- /dev/null
+++ b/gcc/testsuite/g++.dg/pr103038.C
@@ -0,0 +1,5 @@
+/* { dg-do compile } */
+/* { dg-options "-ftrivial-auto-var-init=pattern" } */
+
+struct S;
+void test() { int(S::*PtrMem); }


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

only message in thread, other threads:[~2021-11-02 13:17 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-02 13:17 [gcc r12-4845] middle-end/103038 - avoid ICE with -ftrivial-auto-var-init=pattern Richard Biener

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