This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[gfortran,patch] Fix wrong-code for ASSOCIATED

:ADDPATCH fortran:

The two-lines attached patch fixes PR fortran/26801, where we used to segfault at run-time on the following valid code:
integer :: i = 1
logical :: l
type dt
integer, pointer :: a
end type dt
type(dt) :: obj(1)

  l = associated(obj(i)%a)
  print *, l

While building the code to check whether obj(i)%a is associated, we used to call gfc_conv_expr (&arg1se, arg1->expr), while never actually adding the arg1se.pre (and blocks the final code block. This missing block of code could later lead to variables being used without begin initialized.

Regtested on i686-linux. Comes with a testcase from the PR.
OK for mainline and 4.1?

Index: trans-intrinsic.c
--- trans-intrinsic.c   (revision 114721)
+++ trans-intrinsic.c   (working copy)
@@ -2840,6 +2840,8 @@
           gfc_conv_expr_lhs (&arg1se, arg1->expr);
           tmp2 = gfc_conv_descriptor_data_get (arg1se.expr);
+      gfc_add_block_to_block (&se->pre, &arg1se.pre);
+      gfc_add_block_to_block (&se->post, &;
       tmp = build2 (NE_EXPR, boolean_type_node, tmp2,
                    fold_convert (TREE_TYPE (tmp2), null_pointer_node));
       se->expr = tmp;

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]