Bug 36437 - Simplify argument to [c_]sizeof
Summary: Simplify argument to [c_]sizeof
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.4.0
: P3 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: missed-optimization
Depends on:
Blocks: 32630 39627 46641
  Show dependency treegraph
 
Reported: 2008-06-04 20:15 UTC by Tobias Burnus
Modified: 2013-03-27 11:29 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2009-03-28 17:14:56


Attachments
Incomplete patch (1.09 KB, patch)
2008-06-04 20:19 UTC, Tobias Burnus
Details | Diff
The real incomplete patch (2.67 KB, patch)
2008-06-04 20:21 UTC, Tobias Burnus
Details | Diff
Draft patch (2.64 KB, patch)
2010-12-20 11:02 UTC, Tobias Burnus
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Burnus 2008-06-04 20:15:34 UTC
 
Comment 1 Tobias Burnus 2008-06-04 20:19:46 UTC
Created attachment 15720 [details]
Incomplete patch

Fortran 2008 supports c_sizeof which is identical to gfortran's sizeof.

This patch does the following:

- Implements c_sizeof (one line in intrinsic.c)
- Fixes argument (sizeof(x) not sizeof(i)) - intrinsic.c
- Document new option  - intrinsic.texi
- trans-intrinsic.c (gfc_conv_intrinsic_sizeof): Don't create
  {
    integer(kind=8) bytes.1;
    i = 4;
  }
  in the simple case but simply "i = 4".
- simplify.c: Add gfc_simplify_sizeof:
  This partially works, is currently quite hacky and fails for substrings.

TODO: Fix the last item.
Comment 2 Tobias Burnus 2008-06-04 20:21:27 UTC
Created attachment 15721 [details]
The real incomplete patch

Previous patch was an older version of this patch.
Comment 3 Tobias Burnus 2008-06-07 18:53:51 UTC
Subject: Bug 36437

Author: burnus
Date: Sat Jun  7 18:53:07 2008
New Revision: 136536

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=136536
Log:
2008-06-04  Tobias Burnus  <burnus@net-b.de>

        PR fortran/36437
        * intrinsic.c (add_functions): Implement c_sizeof.
        * trans-intrinsic.c (gfc_conv_intrinsic_sizeof): Do not
        create unneeded variable in the scalar case.

2008-06-04  Tobias Burnus  <burnus@net-b.de>

        PR fortran/36437
        * gfortran.dg/c_sizeof_1.f90: New.
        * gfortran.dg/c_sizeof_2.f90: New.


Added:
    trunk/gcc/testsuite/gfortran.dg/c_sizeof_1.f90
    trunk/gcc/testsuite/gfortran.dg/c_sizeof_2.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/intrinsic.c
    trunk/gcc/fortran/intrinsic.texi
    trunk/gcc/fortran/trans-intrinsic.c
    trunk/gcc/testsuite/ChangeLog

Comment 4 Tobias Burnus 2008-06-07 18:57:56 UTC
F2008's C_SIZEOF is implemented and also the simplification in trans-*.c. The simplification for arrays in simplify.c is missing; attachment 15721 [details] can be used as starting point.
Comment 5 Daniel Franke 2010-05-02 15:20:46 UTC
http://gcc.gnu.org/onlinedocs/gfortran/C_005fSIZEOF.html#C_005fSIZEOF has

Class:
    Intrinsic function 

Sounds strange, "inquiry" seems to be more likely (haven't checked)?!

See also: PR40568.
Comment 6 Tobias Burnus 2010-12-20 11:02:27 UTC
Created attachment 22829 [details]
Draft patch

A different draft patch (I forgot about attachment 15721 [details] - maybe one can move something over).

This patch implements simplification for c_sizeof/sizeof and for storage_size.

TODO:
- The code (in target-memory.c) currently expects character literal strings or PARAMETERs and thus fails for character variables
- There needs to be a "return NULL" for characters with only run-time known length.
- Maybe some other return-early checks?
- Presumably refs of the kind  foo%bar(1)%blub(1:5)(1:2)  are mishandled
- Test cases are missing
Comment 7 Tobias Burnus 2010-12-20 11:05:36 UTC
(Ignore the match.c and resolve.c part - those are for PR PR46371.)
Comment 8 Tobias Burnus 2013-03-27 11:24:06 UTC
Author: burnus
Date: Wed Mar 27 10:45:58 2013
New Revision: 197159

URL: http://gcc.gnu.org/viewcvs?rev=197159&root=gcc&view=rev
Log:
2013-03-27  Tobias Burnus  <burnus@net-b.de>

        PR fortran/56650
        PR fortran/36437
        * check.c (gfc_check_sizeof, gfc_check_c_sizeof,
        gfc_check_storage_size): Update checks.
        * intrinsic.texi (SIZEOF): Correct class.
        * intrinsic.h (gfc_simplify_sizeof,
        gfc_simplify_storage_size): New prototypes.
        * intrinsic.c (add_functions): Use them.
        * simplify.c (gfc_simplify_sizeof,
        gfc_simplify_storage_size): New functions.

2013-03-27  Tobias Burnus  <burnus@net-b.de>

        PR fortran/56650
        PR fortran/36437
        * gfortran.dg/sizeof_2.f90: New.
        * gfortran.dg/sizeof_3.f90: New.
        * gfortran.dg/sizeof_proc.f90: Update dg-error.


Added:
    trunk/gcc/testsuite/gfortran.dg/sizeof_2.f90
    trunk/gcc/testsuite/gfortran.dg/sizeof_3.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/check.c
    trunk/gcc/fortran/intrinsic.c
    trunk/gcc/fortran/intrinsic.h
    trunk/gcc/fortran/intrinsic.texi
    trunk/gcc/fortran/simplify.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gfortran.dg/sizeof_proc.f90
Comment 9 Tobias Burnus 2013-03-27 11:29:51 UTC
FIXED on the 4.9 trunk.

There might be still bugs - especially for the ill-defined vendor extension SIZEOF, but possibly also for C_SIZEOF and STORAGE_SIZE, but most cases should be handled correctly (including rejecting arguments like TYPE(*)).