Bug 13213 - [g77] Hex constant problem when compiling with -fugly-logint and -ftypeless-boz
Summary: [g77] Hex constant problem when compiling with -fugly-logint and -ftypeless-boz
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 3.2.2
: P2 normal
Target Milestone: 3.3.3
Assignee: Not yet assigned to anyone
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2003-11-27 17:25 UTC by Pablo Samuel Castro
Modified: 2005-07-23 22:49 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Pablo Samuel Castro 2003-11-27 17:25:05 UTC
If you have code doing something like:
      INTEGER*2 RES1, RES2, RES3
      REAL*4    GPA
      RES1 = GPA * X'6B5'
      RES2 = GPA * (X'6B5')
      WRITE(*,*) RES1
      WRITE(*,*) RES2

these are the results you get with different compilation options:
%>g77 -fugly-logint -ftypeless-boz test.f
%>./a.out
 0
 9271
%>g77 -fugly-logint test.f
%>./a.out
 9271
 9271
%>g77 -ftypeless-boz test.f
test.f: In program `main':
test.f:10:
         RES1 = GPA * X'6B5'
                    1 2
Arithmetic operator at (1) must operate on two subexpressions of arithmetic
type, but the subexpression at (2) is not of arithmetic type
%>g77 test.f
%>./a.out
 9271
 9271
%>
Comment 1 Andrew Pinski 2003-11-27 17:37:28 UTC
On the mainline (20031029 on powerpc-apple-darwin7.0):
[zhivago2:~/src/gccPRs] pinskia% ~/fsf-clean-nocheck/bin/g77 -fugly-logint -ftypeless-boz 
pr13213.f
[zhivago2:~/src/gccPRs] pinskia% ./a.out 
 0
 0
[zhivago2:~/src/gccPRs] pinskia% ~/fsf-clean-nocheck/bin/g77 -fugly-logint  pr13213.f
[zhivago2:~/src/gccPRs] pinskia% ./a.out 
 0
 0
[zhivago2:~/src/gccPRs] pinskia% ~/fsf-clean-nocheck/bin/g77 -ftypeless-boz pr13213.f
pr13213.f: In program `MAIN__':
pr13213.f:4: 
           RES1 = GPA * X'6B5'
                      1 2
Arithmetic operator at (1) must operate on two subexpressions of arithmetic type, but the 
subexpression at (2) is not of arithmetic type
[zhivago2:~/src/gccPRs] pinskia% ~/fsf-clean-nocheck/bin/g77  pr13213.f
[zhivago2:~/src/gccPRs] pinskia% ./a.out 
 0
 0
What version are you using or has something changed since then?
Comment 2 Pablo Samuel Castro 2003-11-27 17:56:43 UTC
Same problem on version 2.96
Comment 3 Andrew Pinski 2003-11-27 21:55:00 UTC
Some how related to bug 12633 and 6491.
Comment 4 Pablo Samuel Castro 2003-11-28 16:38:08 UTC
I don't know if it's necessarily related to those bugs... they seem to be an
order of operations problem. The problem I presented here is more of a
typecasting problem. Also, I don't have a problem if I *only* use ugly-logint
(like the other two bugs)... it's only if I use ugly-logint *with* typeless-boz.

In my source line:
RES1 = GPA * X'6B5'
GPA is a REAL, so what I believe is happening is that X'6B5' is being
interpreted as the hex representation of a real (not sure), but anyway, it's
evaluating to zero. If, however, you use the other way:
RES2 = GPA * (X'6B5')
then X'6B5' evaluates to its decimal equivalent: 1717

I found that the same problem occurs with .le., .eq., etc.
If you compile the following lines with BOTH ugly-logint and typeless-boz:
GPA = 5.4
IF (GPA.LE.X'B0')
IF (GPA.LE.(X'B0'))
the first line evaluates to FALSE while the second line evaluates to TRUE.
The same thing happens if you use .EQ., .GT., etc.
Comment 5 Andrew Pinski 2003-12-01 02:04:36 UTC
What is the correct answer?
Comment 6 Andrew Pinski 2003-12-21 23:58:42 UTC
Okay I am just going to say this is fixed, the patch which fixed this was also applied to the 
3.3 branch, so this fixed for 3.3.3 and 3.4.
Comment 7 Giovanni Bajo 2003-12-22 01:45:58 UTC
There is no reference of the patch, would you please provide a link Andrew?
Comment 8 Andrew Pinski 2003-12-22 03:29:40 UTC
Patch for mainline: <http://gcc.gnu.org/ml/gcc-patches/2003-11/msg01961.html>.
Patch that was reverted for 3.3.3: <http://gcc.gnu.org/ml/gcc-patches/2003-12/
msg00599.html>.