public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/21931] New: problem with fugly-logint flag and evaluating if statements
@ 2005-06-06 15:48 mark_l_hansen at yahoo dot com
  2005-06-06 15:51 ` [Bug fortran/21931] " mark_l_hansen at yahoo dot com
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: mark_l_hansen at yahoo dot com @ 2005-06-06 15:48 UTC (permalink / raw)
  To: gcc-bugs

The -fugly-logint flag allows FORTRAN to treat integers as logicals and vice 
versa.  The following example program shows some inconsistencies in how the if 
statements evaluate.  If you change VAR1 to 3,2,1,0,-1 and view the results you 
will see some interesting things.  The best way to see the problem is to view 
the output.  Thanks.  I would appreciate an email if anyone has a solution/fix 
for the problem.  Thanks.

Below is the code----

Makefile:
all:
	g77 -c -g -ff90 -ff90-intrinsics-delete -fugly-logint -fno-automatic 
function.for
	g++ -c -g main.cpp
	g++  -o program main.o function.o -lg2c 

main.cpp:
        #include <iostream>
        #include <vector>
        using namespace std;

        extern "C" {
	        void func_();
        }

        int main()
        {
	        func_();
        	return 0;
        }
function.for:
      SUBROUTINE FUNC
      
      IMPLICIT NONE
*
*  LOCAL DECLARATIONS
*
      INTEGER VAR1, VAR2

      LOGICAL LVAR1, LVAR2, LOG1, LOG2

      EQUIVALENCE
     .  (VAR1, LVAR1)
     ., (VAR2, LVAR2)

*C change VAR1 to 2,-1,0,3 and view results     
      VAR1 =  3;
      VAR2 =  -1;
      LOG1 = .true.
      LOG2 = .true.
      
      WRITE (*,*) "LOG1  = ", LOG1
      WRITE (*,*) "LOG2  = ", LOG2
      WRITE (*,*) "VAR1  = ", VAR1
      WRITE (*,*) "VAR2  = ", VAR2
      WRITE (*,*) "LVAR1 = ", LVAR1
      WRITE (*,*) "LVAR2 = ", LVAR2

      IF(.NOT.((LVAR1 .AND. LVAR2) .AND. (LOG1 .AND. LOG2))) THEN
        WRITE (*,*) "LOGICAL TRUE with LOG2"         
      ELSE
        WRITE (*,*) "LOGICAL FALSE with LOG2"         
      ENDIF
      IF(.NOT.(LVAR1 .AND. LVAR2 .AND. LOG1)) THEN
        WRITE (*,*) "LOGICAL TRUE with LOG1"         
      ELSE
        WRITE (*,*) "LOGICAL FALSE with LOG1"         
      ENDIF
      IF(.NOT.(LVAR1 .AND. LVAR2)) THEN
        WRITE (*,*) "LOGICAL TRUE"         
      ELSE
        WRITE (*,*) "LOGICAL FALSE"         
      ENDIF
*----------------------------------------------------------------------      
      IF(.NOT.(VAR1 .AND. VAR2 .AND. LOG1)) THEN
        WRITE (*,*) "BYTE TRUE with LOG1"         
      ELSE
        WRITE (*,*) "BYTE FALSE with LOG1"         
      ENDIF
      IF(.NOT.(VAR1 .AND. VAR2)) THEN
        WRITE (*,*) "BYTE TRUE"         
      ELSE
        WRITE (*,*) "BYTE FALSE"         
      ENDIF
     
      END

-- 
           Summary: problem with fugly-logint flag and evaluating if
                    statements
           Product: gcc
           Version: 3.4.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: mark_l_hansen at yahoo dot com
                CC: gcc-bugs at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21931


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug fortran/21931] problem with fugly-logint flag and evaluating if statements
  2005-06-06 15:48 [Bug fortran/21931] New: problem with fugly-logint flag and evaluating if statements mark_l_hansen at yahoo dot com
@ 2005-06-06 15:51 ` mark_l_hansen at yahoo dot com
  2005-06-10 14:53 ` bdavis9659 at comcast dot net
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: mark_l_hansen at yahoo dot com @ 2005-06-06 15:51 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From mark_l_hansen at yahoo dot com  2005-06-06 15:51 -------
Created an attachment (id=9038)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=9038&action=view)
Test program


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21931


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug fortran/21931] problem with fugly-logint flag and evaluating if statements
  2005-06-06 15:48 [Bug fortran/21931] New: problem with fugly-logint flag and evaluating if statements mark_l_hansen at yahoo dot com
  2005-06-06 15:51 ` [Bug fortran/21931] " mark_l_hansen at yahoo dot com
@ 2005-06-10 14:53 ` bdavis9659 at comcast dot net
  2005-06-18 18:48 ` fxcoudert at gcc dot gnu dot org
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: bdavis9659 at comcast dot net @ 2005-06-10 14:53 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From bdavis9659 at comcast dot net  2005-06-10 14:53 -------
the behavour of -fugly-logint changed between gcc3.2 and above.  which version
are you using ?


--bud davis

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21931


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug fortran/21931] problem with fugly-logint flag and evaluating if statements
  2005-06-06 15:48 [Bug fortran/21931] New: problem with fugly-logint flag and evaluating if statements mark_l_hansen at yahoo dot com
  2005-06-06 15:51 ` [Bug fortran/21931] " mark_l_hansen at yahoo dot com
  2005-06-10 14:53 ` bdavis9659 at comcast dot net
@ 2005-06-18 18:48 ` fxcoudert at gcc dot gnu dot org
  2005-06-19 18:39 ` mark_l_hansen at yahoo dot com
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: fxcoudert at gcc dot gnu dot org @ 2005-06-18 18:48 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From fxcoudert at gcc dot gnu dot org  2005-06-18 18:48 -------
Well, it says: "Reported against: 3.4.2"



-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21931


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug fortran/21931] problem with fugly-logint flag and evaluating if statements
  2005-06-06 15:48 [Bug fortran/21931] New: problem with fugly-logint flag and evaluating if statements mark_l_hansen at yahoo dot com
                   ` (2 preceding siblings ...)
  2005-06-18 18:48 ` fxcoudert at gcc dot gnu dot org
@ 2005-06-19 18:39 ` mark_l_hansen at yahoo dot com
  2005-06-25 13:58 ` bdavis9659 at comcast dot net
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: mark_l_hansen at yahoo dot com @ 2005-06-19 18:39 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From mark_l_hansen at yahoo dot com  2005-06-19 18:39 -------
Correct I am using version 3.4.2

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21931


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug fortran/21931] problem with fugly-logint flag and evaluating if statements
  2005-06-06 15:48 [Bug fortran/21931] New: problem with fugly-logint flag and evaluating if statements mark_l_hansen at yahoo dot com
                   ` (3 preceding siblings ...)
  2005-06-19 18:39 ` mark_l_hansen at yahoo dot com
@ 2005-06-25 13:58 ` bdavis9659 at comcast dot net
  2005-06-25 14:06 ` bdavis9659 at comcast dot net
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: bdavis9659 at comcast dot net @ 2005-06-25 13:58 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From bdavis9659 at comcast dot net  2005-06-25 13:58 -------

here are some things i have found while researching this:


First, this patch:
2002-05-09  Hassan Aurag  <aurag@cae.com>

        * expr.c (ffeexpr_reduced_ugly2log_): Allow logicals-as-integers
        under -fugly-logint as arguments of .and., .or., .xor.

which was then reverted after discussion about what -fugly-logint is supposed to do:

2003-11-24  Toon Moene  <toon@moene.indiv.nluug.nl>

        PR fortran/12633
        * expr.c (ffeexpr_reduced_ugly2log_): Revert
        change allowing logical .and. logical to be
        integer in expressions when -fugly-logint.

And then another patch which was supposed to "do the right thing":

2004-01-13  Ian Lance Taylor  <ian@wasabisystems.com>

        PR fortran/6491
        * expr.c (ffeexpr_reduce_): When handling AND, OR, and XOR, and
        when using -fugly-logint, if both operands are logical, convert
        the result back to logical.
        (ffeexpr_reduced_ugly2log_): Add bothlogical parameter.  Change
        all callers.  Convert logical operands to integer.





-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bbsnider at link dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21931


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug fortran/21931] problem with fugly-logint flag and evaluating if statements
  2005-06-06 15:48 [Bug fortran/21931] New: problem with fugly-logint flag and evaluating if statements mark_l_hansen at yahoo dot com
                   ` (4 preceding siblings ...)
  2005-06-25 13:58 ` bdavis9659 at comcast dot net
@ 2005-06-25 14:06 ` bdavis9659 at comcast dot net
  2005-06-29  2:08 ` mark_l_hansen at yahoo dot com
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: bdavis9659 at comcast dot net @ 2005-06-25 14:06 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From bdavis9659 at comcast dot net  2005-06-25 14:06 -------
in the interest of ensuring credit is given to who actually did the work, the
above analysis was done by bbsnider@link.com and posted by me.

--bud davis

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21931


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug fortran/21931] problem with fugly-logint flag and evaluating if statements
  2005-06-06 15:48 [Bug fortran/21931] New: problem with fugly-logint flag and evaluating if statements mark_l_hansen at yahoo dot com
                   ` (5 preceding siblings ...)
  2005-06-25 14:06 ` bdavis9659 at comcast dot net
@ 2005-06-29  2:08 ` mark_l_hansen at yahoo dot com
  2005-09-09 14:36 ` bdavis9659 at comcast dot net
  2005-09-09 14:38 ` bdavis9659 at comcast dot net
  8 siblings, 0 replies; 10+ messages in thread
From: mark_l_hansen at yahoo dot com @ 2005-06-29  2:08 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From mark_l_hansen at yahoo dot com  2005-06-29 02:08 -------
I did some more research on the bug and found the following:

1) in fortran .TRUE. is 0x1 in hex
2) if(item) statements evaluate to true when the item value is non zero
3) .NOT., .AND., etc either perform bitwise or logical operations depending on
what they are operating on.

The problem occurs when doing bitwise operations and then doing a logical if
check with the -fugly-logint flag.  For example: 0xFF .AND. 0x02 = 0x02 i.e.
True, but  .NOT.(0xFF .AND. 0x02) = 0xFD i.e. also true when the desired result
is false.

I know the above might all be already understood, but I thought it might help if
others are looking into the problems.

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21931


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug fortran/21931] problem with fugly-logint flag and evaluating if statements
  2005-06-06 15:48 [Bug fortran/21931] New: problem with fugly-logint flag and evaluating if statements mark_l_hansen at yahoo dot com
                   ` (6 preceding siblings ...)
  2005-06-29  2:08 ` mark_l_hansen at yahoo dot com
@ 2005-09-09 14:36 ` bdavis9659 at comcast dot net
  2005-09-09 14:38 ` bdavis9659 at comcast dot net
  8 siblings, 0 replies; 10+ messages in thread
From: bdavis9659 at comcast dot net @ 2005-09-09 14:36 UTC (permalink / raw)
  To: gcc-bugs



-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |repucul at link dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21931


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug fortran/21931] problem with fugly-logint flag and evaluating if statements
  2005-06-06 15:48 [Bug fortran/21931] New: problem with fugly-logint flag and evaluating if statements mark_l_hansen at yahoo dot com
                   ` (7 preceding siblings ...)
  2005-09-09 14:36 ` bdavis9659 at comcast dot net
@ 2005-09-09 14:38 ` bdavis9659 at comcast dot net
  8 siblings, 0 replies; 10+ messages in thread
From: bdavis9659 at comcast dot net @ 2005-09-09 14:38 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From bdavis9659 at comcast dot net  2005-09-09 14:38 -------
http://gcc.gnu.org/ml/gcc/2005-09/msg00266.html

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21931


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2005-09-09 14:38 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-06-06 15:48 [Bug fortran/21931] New: problem with fugly-logint flag and evaluating if statements mark_l_hansen at yahoo dot com
2005-06-06 15:51 ` [Bug fortran/21931] " mark_l_hansen at yahoo dot com
2005-06-10 14:53 ` bdavis9659 at comcast dot net
2005-06-18 18:48 ` fxcoudert at gcc dot gnu dot org
2005-06-19 18:39 ` mark_l_hansen at yahoo dot com
2005-06-25 13:58 ` bdavis9659 at comcast dot net
2005-06-25 14:06 ` bdavis9659 at comcast dot net
2005-06-29  2:08 ` mark_l_hansen at yahoo dot com
2005-09-09 14:36 ` bdavis9659 at comcast dot net
2005-09-09 14:38 ` bdavis9659 at comcast dot net

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).