[Bug fortran/40605] -fcheck=pointer: Problems with OPTIONAL

burnus at gcc dot gnu dot org gcc-bugzilla@gcc.gnu.org
Wed Jul 1 13:41:00 GMT 2009



------- Comment #3 from burnus at gcc dot gnu dot org  2009-07-01 13:40 -------
But of cause also the run-time test fails; for absent arguments a NULL is
passed.

We need to check:
a) optional pointer actual to non-optional dummy
b) optional pointer actual to optional dummy

The -fcheck=pointer specific check would be to check for
 "*actual == NULL"
though that needs to be guarded by "actual != NULL".

In general, passing a not-present optional to a non-optional dummy should be
checked somewhere; the question is with which option (-fcheck=call?).

Patch below.
(Note: One has to use TRUTH_ANDIF_EXPR and not TRUTH_AND_EXPR!)

--- trans-expr.c        (revision 149129)
+++ trans-expr.c        (working copy)
@@ -2778 +2778 @@ gfc_conv_procedure_call (gfc_se * se, gf
-      if (gfc_option.rtcheck & GFC_RTCHECK_POINTER)
+      if (gfc_option.rtcheck & GFC_RTCHECK_POINTER && e != NULL)
@@ -2806 +2806,15 @@ gfc_conv_procedure_call (gfc_se * se, gf
-         cond  = fold_build2 (EQ_EXPR, boolean_type_node, parmse.expr,
+          if (sym->attr.optional)
+           {
+             tree present, nullptr, type;
+             type = TREE_TYPE (parmse.expr);
+              present = fold_build2 (NE_EXPR, boolean_type_node, parmse.expr,
+                                    fold_convert (type, null_pointer_node));
+             type = TREE_TYPE (type);
+             nullptr = fold_build2 (EQ_EXPR, boolean_type_node,
+                                    build1 (INDIRECT_REF, type, parmse.expr),
+                                    fold_convert (type, null_pointer_node));
+             cond = fold_build2 (TRUTH_ANDIF_EXPR, boolean_type_node,
+                                 present, nullptr);
+           }
+          else
+          cond = fold_build2 (EQ_EXPR, boolean_type_node, parmse.expr,


-- 

burnus at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |burnus at gcc dot gnu dot
                   |dot org                     |org
             Status|NEW                         |ASSIGNED
   Last reconfirmed|2009-07-01 13:16:43         |2009-07-01 13:40:51
               date|                            |


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



More information about the Gcc-bugs mailing list