[Bug fortran/29489] LBOUND (array) and LBOUND (array, DIM) give different results.

fxcoudert at gcc dot gnu dot org gcc-bugzilla@gcc.gnu.org
Wed Oct 18 21:51:00 GMT 2006



------- Comment #4 from fxcoudert at gcc dot gnu dot org  2006-10-18 21:50 -------
Also, I should say, from my understanding the correct answer would be:

 SIZE =            0
 LBOUND (soda, DIM) =            1           1
 LBOUND (soda)      =            1           1
 UBOUND (soda, DIM) =            0           2
 UBOUND (soda)      =            0           2

And the difference (for the bounds with DIM arg specified) with what we
currently yield is due to my conditions in trans-intrinsic being stupidly
wrong:

Index: trans-intrinsic.c
===================================================================
--- trans-intrinsic.c   (revision 117862)
+++ trans-intrinsic.c   (working copy)
@@ -710,7 +710,7 @@
   tree type;
   tree bound;
   tree tmp;
-  tree cond, cond1, cond2, cond3, size;
+  tree cond, cond1, cond2, cond3, cond4, size;
   tree ubound;
   tree lbound;
   gfc_se argse;
@@ -840,15 +840,21 @@
   if (as)
     {
       tree stride = gfc_conv_descriptor_stride (desc, bound);
+
       cond1 = fold_build2 (GE_EXPR, boolean_type_node, ubound, lbound);
       cond2 = fold_build2 (LE_EXPR, boolean_type_node, ubound, lbound);
+
       cond3 = fold_build2 (GT_EXPR, boolean_type_node, stride,
                           gfc_index_zero_node);
+      cond3 = fold_build2 (TRUTH_AND_EXPR, boolean_type_node, cond3, cond1);

+      cond4 = fold_build2 (LT_EXPR, boolean_type_node, stride,
+                          gfc_index_zero_node);
+      cond4 = fold_build2 (TRUTH_AND_EXPR, boolean_type_node, cond4, cond2);
+
       if (upper)
        {
-         cond = fold_build2 (TRUTH_AND_EXPR, boolean_type_node, cond3, cond1);
-         cond = fold_build2 (TRUTH_OR_EXPR, boolean_type_node, cond, cond2);
+         cond = fold_build2 (TRUTH_OR_EXPR, boolean_type_node, cond3, cond4);

          se->expr = fold_build3 (COND_EXPR, gfc_array_index_type, cond,
                                  ubound, gfc_index_zero_node);
@@ -862,9 +868,7 @@
          else
            cond = boolean_false_node;

-         cond1 = fold_build2 (TRUTH_AND_EXPR, boolean_type_node, cond3,
cond1);
-         cond1 = fold_build2 (TRUTH_OR_EXPR, boolean_type_node, cond1, cond2);
-
+         cond1 = fold_build2 (TRUTH_OR_EXPR, boolean_type_node, cond3, cond4);
          cond = fold_build2 (TRUTH_OR_EXPR, boolean_type_node, cond, cond1);

          se->expr = fold_build3 (COND_EXPR, gfc_array_index_type, cond,


-- 

fxcoudert at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |fxcoudert at gcc dot gnu dot
                   |dot org                     |org
             Status|UNCONFIRMED                 |ASSIGNED
     Ever Confirmed|0                           |1
   Last reconfirmed|0000-00-00 00:00:00         |2006-10-18 21:50:55
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29489



More information about the Gcc-bugs mailing list