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.
Created attachment 15721 [details] The real incomplete patch Previous patch was an older version of this patch.
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
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.
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.
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
(Ignore the match.c and resolve.c part - those are for PR PR46371.)
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
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(*)).