[gcc(refs/users/mikael/heads/refactor_descriptor_v291.01)] Refactor set_dimension_fields descriptor_init_count

Mikael Morin via Gcc-cvs <[email protected]>
Newsgroups gmane.comp.gcc.cvs
Message-ID <[email protected]>
https://gcc.gnu.org/g:16ca502e802caf9eb30e4c12c5af76766c87a8d8

commit 16ca502e802caf9eb30e4c12c5af76766c87a8d8
Author: Mikael Morin <[email protected]>
Date:   Sat Aug 16 19:16:15 2025 +0200

    Refactor set_dimension_fields descriptor_init_count
    
    Correction régression class_allocate_22
    
    Ajout scan tree var
    
    Correction dumps coarray_12

Diff:
---
 gcc/fortran/trans-descriptor.cc          | 18 +++---------
 gcc/testsuite/gfortran.dg/coarray_12.f90 |  3 +-
 gcc/testsuite/lib/scandump.exp           | 50 ++++++++++++++++++++++++++++++++
 gcc/testsuite/lib/scantree.exp           | 26 +++++++++++++++++
 4 files changed, 82 insertions(+), 15 deletions(-)

diff --git a/gcc/fortran/trans-descriptor.cc b/gcc/fortran/trans-descriptor.cc
index 74de4f4d420f..e76b10386d3b 100644
--- a/gcc/fortran/trans-descriptor.cc
+++ b/gcc/fortran/trans-descriptor.cc
@@ -2798,15 +2798,8 @@ gfc_descriptor_init_count (tree descriptor, int rank, int corank,
 	      ubound = lower[n];
 	    }
 	}
-      gfc_conv_descriptor_lbound_set (descriptor_block, descriptor,
-				      gfc_rank_cst[n], se.expr);
       conv_lbound = se.expr;
-
-      /* Work out the offset for this component.  */
-      tmp = fold_build2_loc (input_location, MULT_EXPR, gfc_array_index_type,
-			     se.expr, stride);
-      offset = fold_build2_loc (input_location, MINUS_EXPR,
-				gfc_array_index_type, offset, tmp);
+      conv_lbound = gfc_evaluate_now (conv_lbound, pblock);
 
       /* Set upper bound.  */
       gfc_init_se (&se, NULL);
@@ -2842,13 +2835,11 @@ gfc_descriptor_init_count (tree descriptor, int rank, int corank,
 	  if (ubound->expr_type == EXPR_FUNCTION)
 	    se.expr = gfc_evaluate_now (se.expr, pblock);
 	}
-      gfc_conv_descriptor_ubound_set (descriptor_block, descriptor,
-				      gfc_rank_cst[n], se.expr);
       conv_ubound = se.expr;
+      conv_ubound = gfc_evaluate_now (conv_ubound, pblock);
 
-      /* Store the stride.  */
-      gfc_conv_descriptor_stride_set (descriptor_block, descriptor,
-				      gfc_rank_cst[n], stride);
+      set_dimension_fields (descriptor_block, descriptor, gfc_rank_cst[n],
+			    conv_lbound, conv_ubound, stride, &offset);
 
       /* Calculate size and check whether extent is negative.  */
       size = gfc_conv_array_extent_dim (conv_lbound, conv_ubound, &empty_cond);
@@ -2932,7 +2923,6 @@ gfc_descriptor_init_count (tree descriptor, int rank, int corank,
     return gfc_index_one_node;
 
   /* Update the array descriptor with the offset and the span.  */
-  offset = gfc_evaluate_now (offset, pblock);
   gfc_conv_descriptor_offset_set (descriptor_block, descriptor, offset);
   tmp = fold_convert (gfc_array_index_type, element_size);
   gfc_conv_descriptor_span_set (descriptor_block, descriptor, tmp);
diff --git a/gcc/testsuite/gfortran.dg/coarray_12.f90 b/gcc/testsuite/gfortran.dg/coarray_12.f90
index 70efaaff5160..9bbb9e3a3035 100644
--- a/gcc/testsuite/gfortran.dg/coarray_12.f90
+++ b/gcc/testsuite/gfortran.dg/coarray_12.f90
@@ -46,7 +46,8 @@ end subroutine testAlloc5
 
 
 ! { dg-final { scan-tree-dump-times "a.dim.0..lbound = 1;"     1 "original" } }
-! { dg-final { scan-tree-dump-times "a.dim.0..ubound = .*nn;" 1 "original" } }
+! { dg-final { global ubound_value; scan-tree-dump-var {a\.dim\[0\]\.ubound = (D\.\d+);} "original" "ubound_value" } }
+! { dg-final { global ubound_value; scan-tree-dump-times "$ubound_value = .*nn;" 1 "original" } }
 ! { dg-final { scan-tree-dump-times "a.dim.1..lbound = 1;"     1 "original" } }
 ! { dg-final { scan-tree-dump-times "a.dim.1..ubound = .*mm;" 1 "original" } }
 ! { dg-final { scan-tree-dump-times "a.dim.2..lbound = 1;"     1 "original" } }
diff --git a/gcc/testsuite/lib/scandump.exp b/gcc/testsuite/lib/scandump.exp
index 43ba7fbace42..b07d1490c003 100644
--- a/gcc/testsuite/lib/scandump.exp
+++ b/gcc/testsuite/lib/scandump.exp
@@ -214,6 +214,56 @@ proc scan-dump-not { args } {
     }
 }
 
+# Utility for scanning compiler result, invoked via dg-final.
+# Call pass if pattern is present, otherwise fail.
+#
+# Argument 0 is the type of dump we are searching (rtl, tree, ipa)
+# Argument 1 is the regexp to match.
+# Argument 2 is the suffix for the dump file
+# Argument 3 is the suffix of the dump base
+# Argument 4 is the variable name to store the matched content
+# Argument 5 handles expected failures and the like
+proc scan-dump-var { args } {
+
+    if { [llength $args] >= 6 } {
+        switch [dg-process-target [lindex $args 5]] {
+            "S" { }
+            "N" { return }
+            "F" { setup_xfail "*-*-*" }
+            "P" { }
+        }
+    }
+
+    set testcase [testname-for-summary]
+    # The name might include a list of options; extract the file name.
+    set filename [lindex $testcase 0]
+
+    set printable_pattern [make_pattern_printable [lindex $args 1]]
+    set suf [dump-suffix [lindex $args 2]]
+    set testname "$testcase scan-[lindex $args 0]-dump $suf \"$printable_pattern\""
+    set src [file tail $filename]
+    set dumpbase [dump-base $src [lindex $args 3]]
+
+    set pattern "$dumpbase.[lindex $args 2]"
+    set output_file "[glob-dump-file $testcase $pattern]"
+    if { $output_file == "" } {
+	unresolved "$testname"
+	return
+    }
+
+    set fd [open $output_file r]
+    set text [read $fd]
+    close $fd
+
+    global [lindex $args 4]
+    set [lindex $args 4] {}
+    if [regexp -- [lindex $args 1] $text scratch [lindex $args 4]] {
+	pass "$testname"
+    } else {
+	fail "$testname"
+    }
+}
+
 # Utility for scanning demangled compiler result, invoked via dg-final.
 # Call pass if pattern is present, otherwise fail.
 #
diff --git a/gcc/testsuite/lib/scantree.exp b/gcc/testsuite/lib/scantree.exp
index 93d46d2e257c..9c7cf5a9e474 100644
--- a/gcc/testsuite/lib/scantree.exp
+++ b/gcc/testsuite/lib/scantree.exp
@@ -94,6 +94,32 @@ proc scan-tree-dump-not { args } {
     }
 }
 
+# Utility for scanning compiler result, invoked via dg-final.
+# Call pass if pattern is present, otherwise fail.
+#
+# Argument 0 is the regexp to match
+# Argument 1 is the name of the dumped tree pass
+# Argument 2 is the variable name to store the matched content
+# Argument 3 handles expected failures and the like
+proc scan-tree-dump-var { args } {
+
+    if { [llength $args] < 3 } {
+	error "scan-tree-dump-var: too few arguments"
+	return
+    }
+    if { [llength $args] > 4 } {
+	error "scan-tree-dump-var: too many arguments"
+	return
+    }
+    if { [llength $args] >= 4 } {
+	scan-dump-var "tree" [lindex $args 0] \
+		  "\[0-9\]\[0-9\]\[0-9\]t.[lindex $args 1]" "" [lindex $args 2] [lindex $args 3]
+    } else {
+	scan-dump-var "tree" [lindex $args 0] \
+		  "\[0-9\]\[0-9\]\[0-9\]t.[lindex $args 1]" "" [lindex $args 2]
+    }
+}
+
 # Utility for scanning demangled compiler result, invoked via dg-final.
 # Call pass if pattern is present, otherwise fail.
 #
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.