public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/autopar_devel] c++: Tweak VLA representation.
@ 2020-08-22 21:06 Giuliano Belinassi
  0 siblings, 0 replies; only message in thread
From: Giuliano Belinassi @ 2020-08-22 21:06 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:528cfed6096176881c6c3fe221192b087f9f4597

commit 528cfed6096176881c6c3fe221192b087f9f4597
Author: Jason Merrill <jason@redhat.com>
Date:   Mon May 11 14:05:46 2020 -0400

    c++: Tweak VLA representation.
    
    If we put the SAVE_EXPR for a VLA size inside the MINUS_EXPR rather than
    outside, it will work better with constant folding.
    
    The equivalent change was made in the C front-end in 2004, in commit
    r0-64535-g8b0b9aefd29dfe6398857bcf5628662e2f0e21f6
    
    gcc/cp/ChangeLog
    2020-05-11  Jason Merrill  <jason@redhat.com>
    
            * decl.c (compute_array_index_type_loc): Stabilize before building
            the MINUS_EXPR.

Diff:
---
 gcc/cp/ChangeLog |  5 +++++
 gcc/cp/decl.c    | 14 +++++++++-----
 2 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index ab5e6abb866..9831c253668 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,8 @@
+2020-05-11  Jason Merrill  <jason@redhat.com>
+
+	* decl.c (compute_array_index_type_loc): Stabilize before building
+	the MINUS_EXPR.
+
 2020-05-11  Jason Merrill  <jason@redhat.com>
 
 	* decl.c (grokdeclarator): Adjust deprecated_state here.
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index adf94658420..dea1ba07c0e 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -10449,6 +10449,15 @@ compute_array_index_type_loc (location_t name_loc, tree name, tree size,
     itype = build_min (MINUS_EXPR, sizetype, size, integer_one_node);
   else
     {
+      if (!TREE_CONSTANT (size))
+	{
+	  /* A variable sized array.  Arrange for the SAVE_EXPR on the inside
+	     of the MINUS_EXPR, which allows the -1 to get folded with the +1
+	     that happens when building TYPE_SIZE.  */
+	  size = variable_size (size);
+	  stabilize_vla_size (size);
+	}
+
       /* Compute the index of the largest element in the array.  It is
 	 one less than the number of elements in the array.  We save
 	 and restore PROCESSING_TEMPLATE_DECL so that computations in
@@ -10466,11 +10475,6 @@ compute_array_index_type_loc (location_t name_loc, tree name, tree size,
 
       if (!TREE_CONSTANT (itype))
 	{
-	  /* A variable sized array.  */
-	  itype = variable_size (itype);
-
-	  stabilize_vla_size (itype);
-
 	  if (sanitize_flags_p (SANITIZE_VLA)
 	      && current_function_decl != NULL_TREE)
 	    {


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

only message in thread, other threads:[~2020-08-22 21:06 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:06 [gcc/devel/autopar_devel] c++: Tweak VLA representation 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).