diff mbox series

[Fortran] PR 81770: [5/6/7 Regression] Bogus warning: Pointer in pointer assignment might outlive the pointer target

Message ID CAKwh3qjVFKyzehOZ5_qj0=8W83NWrShtuOru_rO98SHy8V77aw@mail.gmail.com
State New
Headers show
Series [Fortran] PR 81770: [5/6/7 Regression] Bogus warning: Pointer in pointer assignment might outlive the pointer target | expand

Commit Message

Janus Weil Aug. 27, 2017, 8:05 p.m. UTC
Hi all,

the attached patch fixes a bogus warning. The purpose of the warning
is to detect cases where a pointer lives longer than its target. If
the target itself is (1) a pointer or (2) a component of a DT pointer,
we do not know about the lifetime of the target at compile time and no
warning should be thrown. The existing check only handles case (1) and
my patch adds the handling of case (2).

Regtestes cleanly on x86_64-linux-gnu. Ok for trunk and the release branches?

Cheers,
Janus



2017-08-27  Janus Weil  <janus@gcc.gnu.org>

    PR fortran/81770
    * expr.c (gfc_check_pointer_assign): Improve the check whether pointer
    may outlive pointer target.


2017-08-27  Janus Weil  <janus@gcc.gnu.org>

    PR fortran/81770
    * gfortran.dg/warn_target_lifetime_4.f90: New testcase.

Comments

Thomas Koenig Aug. 28, 2017, 8:31 a.m. UTC | #1
Hi Janus,

> the attached patch fixes a bogus warning. The purpose of the warning
> is to detect cases where a pointer lives longer than its target. If
> the target itself is (1) a pointer or (2) a component of a DT pointer,
> we do not know about the lifetime of the target at compile time and no
> warning should be thrown. The existing check only handles case (1) and
> my patch adds the handling of case (2).
> 
> Regtestes cleanly on x86_64-linux-gnu. Ok for trunk and the release branches?

OK, and thanks for the patch!

Regards

	Thomas
Janus Weil Aug. 28, 2017, 6:50 p.m. UTC | #2
2017-08-28 10:31 GMT+02:00 Thomas Koenig <tkoenig@netcologne.de>:
> Hi Janus,
>
>> the attached patch fixes a bogus warning. The purpose of the warning
>> is to detect cases where a pointer lives longer than its target. If
>> the target itself is (1) a pointer or (2) a component of a DT pointer,
>> we do not know about the lifetime of the target at compile time and no
>> warning should be thrown. The existing check only handles case (1) and
>> my patch adds the handling of case (2).
>>
>> Regtestes cleanly on x86_64-linux-gnu. Ok for trunk and the release
>> branches?
>
>
> OK, and thanks for the patch!

Thanks, Thomas! Committed as r251390 (together with a small typo fix
in a related test case):

https://gcc.gnu.org/viewcvs/gcc?view=revision&revision=251390

Will take care of the release branches in a couple of days (probably
on the weekend).

Cheers,
Janus
diff mbox series

Patch

Index: gcc/fortran/expr.c
===================================================================
--- gcc/fortran/expr.c	(revision 251368)
+++ gcc/fortran/expr.c	(working copy)
@@ -3806,7 +3806,8 @@  gfc_check_pointer_assign (gfc_expr *lvalue, gfc_ex
   if (warn_target_lifetime
       && rvalue->expr_type == EXPR_VARIABLE
       && !rvalue->symtree->n.sym->attr.save
-      && !attr.pointer && !rvalue->symtree->n.sym->attr.host_assoc
+      && !rvalue->symtree->n.sym->attr.pointer && !attr.pointer
+      && !rvalue->symtree->n.sym->attr.host_assoc
       && !rvalue->symtree->n.sym->attr.in_common
       && !rvalue->symtree->n.sym->attr.use_assoc
       && !rvalue->symtree->n.sym->attr.dummy)