https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113245
--- Comment #1 from anlauf at gcc dot gnu.org ---
The following probably rather obvious patch fixes the issue:
diff --git a/gcc/fortran/trans-intrinsic.cc b/gcc/fortran/trans-intrinsic.cc
index d973c49380c..748cc74de89 100644
--- a/gcc/fortran/trans-intrinsic.cc
+++ b/gcc/fortran/trans-intrinsic.cc
@@ -8025,9 +8092,7 @@ gfc_conv_intrinsic_size (gfc_se * se, gfc_expr * expr)
argse.data_not_needed = 1;
gfc_conv_expr (&argse, actual->expr);
gfc_add_block_to_block (&se->pre, &argse.pre);
- cond = fold_build2_loc (input_location, NE_EXPR, logical_type_node,
- argse.expr, null_pointer_node);
- cond = gfc_evaluate_now (cond, &se->pre);
+ cond = gfc_conv_expr_present (actual->expr->symtree->n.sym);
/* 'block2' contains the arg2 absent case, 'block' the arg2 present
case; size_var can be used in both blocks. */
tree size_var = gfc_create_var (TREE_TYPE (size), "size");