This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug middle-end/49733] Missed optimization: Variable value not propagated to remove "if" condition
- From: "burnus at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Wed, 13 Jul 2011 14:42:50 +0000
- Subject: [Bug middle-end/49733] Missed optimization: Variable value not propagated to remove "if" condition
- Auto-submitted: auto-generated
- References: <bug-49733-4@http.gcc.gnu.org/bugzilla/>
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49733
--- Comment #4 from Tobias Burnus <burnus at gcc dot gnu.org> 2011-07-13 14:42:43 UTC ---
(In reply to comment #3)
> is
[...]
> invalid then?
Yes, the does not even have the correct syntax. I assume you means something
like:
module m
integer :: global
end module m
program main
use m
implicit none
call test(global)
contains
subroutine mod_global()
global = 7
end subroutine mod_global
subroutine mod2(y)
integer :: y
y = 9
end subroutine mod2
subroutine test(x)
integer :: x
x = 5
call mod_global() ! Invalid, modifies "x"
global = 8 ! Also invalid
call mod2(global) ! Ditto.
print *, x ! May print 5, 7, 8, 9, or other garbage
end subroutine
end program main
! or even
! sub (non_aliasing_var)
if (non_aliasing_var /= 5) call foobar()
Well, "call sub (non_aliasing_var)" *may* modify "non_aliasing_var" - but it
may not modify a global variable directly, if it is associated with the actual
argument.
(And for recursion: That's only allowed if the procedure is marked as
RECURSIVE.)
As written, the Fortran standard states (quote in comment 0):
If A is used as actual argument to the dummy argument D then:
a) Anything which *modifies* "A" should only be done by using explicitly "D",
unless "D" is a POINTER or "D" has the TARGET attribute (and some other
conditions).
b) Anything which *reads* "A": If the value is modified through "D", only "D"
may be used to access the value. (With same exceptions for TARGET and POINTER -
and, of course, only applying until the function with the dummy "D" returns).