From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5094 invoked by alias); 19 May 2009 11:55:06 -0000 Received: (qmail 5003 invoked by uid 48); 19 May 2009 11:54:55 -0000 Date: Tue, 19 May 2009 11:55:00 -0000 Message-ID: <20090519115455.5002.qmail@sourceware.org> X-Bugzilla-Reason: CC References: Subject: [Bug middle-end/40194] fortran rules for optimizing In-Reply-To: Reply-To: gcc-bugzilla@gcc.gnu.org To: gcc-bugs@gcc.gnu.org From: "jv244 at cam dot ac dot uk" Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2009-05/txt/msg01620.txt.bz2 ------- Comment #5 from jv244 at cam dot ac dot uk 2009-05-19 11:54 ------- (In reply to comment #3) > Does > > SUBROUTINE S(I1,IP) > INTEGER,INTENT(IN) :: I1 > INTEGER, POINTER :: IP > END SUBROUTINE S > > allow that S stores the pointer to I1 to global memory? this is not a very Fortran-ish way to express this, and I'm not very C-ish, but the answer is no (I don't think you can obtain the address of I1 in S1 using standard conforming Fortran, and certainly there is no guarantee at all that you get the address of I1 in F1). Even if you get the address of I1, no way you're allowed to change the value of I1, either in S1, or in any subroutine called subsequently. The important thing is not so much that (I believe), but the fact that Fortran guarantees that in the caller where I1 is defined (i.e. F1), nothing else can alias that variable. > I think that the easiest way to improve Fortran code generation is to _not_ > pass INTENT(IN) arguments by reference but by value (at least for scalar > types). I believe that his is some kind of misunderstanding. It is not because the FE generates some code that is call by reference that his is actually what the rules are. AFAICT, it would be equally valid for a Fortran implementation to copy in and copy out the data (i.e. the address of the variable in the caller is of no importance in the callee). I think it would be worthwhile to discuss this once with the group of gcc-people that know both Fortran and the middle-end really well (I hope this is a non-zero subset :-) -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40194