Bug 42122 - [F03] -fdump-tree-original shows wrong static decl for functions with procptr argument
Summary: [F03] -fdump-tree-original shows wrong static decl for functions with procptr...
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.5.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2009-11-20 16:07 UTC by janus
Modified: 2019-08-14 10:16 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2019-08-14 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description janus 2009-11-20 16:07:38 UTC
Follow-up to PR42072. Consider this simple program:


contains

  subroutine setpointer (p)
    procedure(), pointer :: p
  end subroutine

end


Compiling this with -fdump-tree-original shows:


setpointer (void (*<T62>) (void) * p)
{
  (void) 0;
}

MAIN__ ()
{
  static void setpointer (void (*<T62>) (void));

  (void) 0;
}


As one can see, the static declaration inside MAIN__ differs from the actual declaration of 'setpointer'.
Comment 1 Paul Thomas 2009-12-17 05:41:16 UTC
Confirmed.

This is where it comes from:
Index: gcc/fortran/trans-decl.c
===================================================================
*** gcc/fortran/trans-decl.c	(revision 155192)
--- gcc/fortran/trans-decl.c	(working copy)
*************** build_function_decl (gfc_symbol * sym)
*** 1644,1653 ****
    if (DECL_CONTEXT (fndecl) == NULL_TREE
        && !sym->attr.entry_master && !sym->attr.is_main_program)
      TREE_PUBLIC (fndecl) = 1;
! 
    /* TREE_STATIC means the function body is defined here.  */
    TREE_STATIC (fndecl) = 1;
! 
    /* Set attributes for PURE functions. A call to a PURE function in the
       Fortran 95 sense is both pure and without side effects in the C
       sense.  */
--- 1644,1653 ----
    if (DECL_CONTEXT (fndecl) == NULL_TREE
        && !sym->attr.entry_master && !sym->attr.is_main_program)
      TREE_PUBLIC (fndecl) = 1;
! #if 0
    /* TREE_STATIC means the function body is defined here.  */
    TREE_STATIC (fndecl) = 1;
! #endif
    /* Set attributes for PURE functions. A call to a PURE function in the
       Fortran 95 sense is both pure and without side effects in the C
       sense.  */

Paul
Comment 2 Richard Biener 2009-12-17 11:29:09 UTC
Hm?  The TREE_STATIC is ok, the bug is that the actual arguments are
different and maybe that inside the __MAIN BLOCK vars there shouldn't
be a function decl.
Comment 3 Dominique d'Humieres 2018-03-04 14:18:14 UTC
With gcc 4.8 up to trunk (8.0) the dump is

setpointer (void (*<T4bb>) () * p)
{
  
}


MAIN__ ()
{
  static void setpointer (void (*<T4bb>) ());

  
}

Is this eight-year old PR fixed or not?
Comment 4 Dominique d'Humieres 2019-03-17 17:40:05 UTC
> Is this eight-year old PR fixed or not?

Should I close this PR as FIXED to get an answer?
Comment 5 Thomas Koenig 2019-08-14 10:09:22 UTC
Not fixed.
Comment 6 Thomas Koenig 2019-08-14 10:12:01 UTC
Also crashes with -fdump-global-original:

MAIN__ setpointer main==4365== Invalid read of size 8
==4365==    at 0x8F8B0D: gfc_traverse_gsymbol(gfc_gsymbol*, void (*)(gfc_gsymbol*, void*), void*) (symbol.c:4365)
==4365==    by 0x8BDAB1: gfc_parse_file() (parse.c:6374)
==4365==    by 0x906D4F: gfc_be_parse_file() (f95-lang.c:204)
==4365==    by 0xE35CBF: compile_file() (toplev.c:456)
==4365==    by 0x829190: do_compile (toplev.c:2190)
==4365==    by 0x829190: toplev::main(int, char**) (toplev.c:2325)
==4365==    by 0x82CCBE: main (main.c:39)
==4365==  Address 0x8 is not stack'd, malloc'd or (recently) free'd
==4365== 
decl.f90:6:0:

    6 |   end subroutine
      | 
interner Compiler-Fehler: Speicherzugriffsfehler
Bitte senden Sie einen vollständigen Fehlerbericht auf Englisch ein;
inclusive vorverarbeitetem Quellcode, wenn es dienlich ist.
Weitere Hinweise finden Sie unter »<https://gcc.gnu.org/bugs/>«.
==4365==