Re: How does a target make Fortran work?

2018-07-13 Thread Paul Koning



> On Jul 13, 2018, at 9:36 AM, Janus Weil  wrote:
> 
> Hi Paul,
> 
> Fortran problems are best discussed on fort...@gcc.gnu.org 
>  (in CC) ...
> 
> 2018-07-12 21:22 GMT+02:00 Paul Koning  >:
>> I tried to rebuild for target pdp11 with fortran enabled (in the past I've 
>> just enabled C).  It builds fine but the resulting compiler crashes at 
>> startup:
>> 
>> Paul-Konings-MacBook-Pro:gcc pkoning$ ./xgcc -B. -O2 -S ../../hello.f
>> f951: internal compiler error: gfc_validate_kind(): Got bad kind
>> libbacktrace could not find executable to open
>> Please submit a full bug report,
>> with preprocessed source if appropriate.
>> See  for instructions.
>> 
>> "hello.f" is the typical "hello world" program.  Some debugging got me to 
>> here:
>> 
>> * thread #1, queue = 'com.apple.main-thread', stop reason = step over
>>frame #0: 0x0001001c1c93 f951`gfc_init_kinds() [inlined] 
>> gfc_validate_kind(type=BT_REAL, kind=, may_fail=false) at 
>> trans-types.c:814 [opt]
>>   811  }
>>   812
>>   813if (rc < 0 && !may_fail)
>> -> 814  gfc_internal_error ("gfc_validate_kind(): Got bad kind");
>>   815
>>   816return rc;
>>   817  }
>> Target 0: (f951) stopped.
>> 
>> So it's unhappy about some "kind", for BT_REAL.  I'm not sure what that 
>> means.  Is it mapping the available data types to Fortran "KIND" values?  If 
>> so, is there something the target has to do for this to work?  Note that 
>> this isn't an IEEE target, so if the initialization is expecting IEEE float 
>> then that may account for it.  But I have no idea what to do here, and the 
>> manual offers no clue.
> 
> A "kind" in Fortran is the size of the data type in bytes. E.g.
> "real(kind=4)" would be a 'single-precision' 32-bit float number,
> while "real(kind=8)" would be a 'double-precision' 64-bit float
> number. The default kind for REAL variables is 4 in gfortran, see:
> 
> https://gcc.gnu.org/onlinedocs/gcc-8.1.0/gfortran/KIND-Type-Parameters.html 
> 
> 
> Since pdp-11 seems to be a 16-bit platform, such a 32-bit
> floating-point type might not be available there? Possibly it makes
> sense to set the default REAL kind to 2 for such a target?

No, because there isn't a 16 bit float type on that machine.  But your answer 
pointed me straight to the problem.

The pdp11 back end has a command line option to choose whether the C "float" 
type is SFmode or DFmode (32 bit or 64 bit).  For various reasons, it defaults 
to 64, which of course means that "float" and "double" are the same machine 
type -- the only float is "real(kind=8)".  If I override the default with 
-mfloat32, Fortran is happy.  Maybe the right answer is to change the default, 
at least once I take away the historic reason for it.

Thanks!

paul



Re: How does a target make Fortran work?

2018-07-13 Thread Janus Weil
Hi Paul,

Fortran problems are best discussed on fort...@gcc.gnu.org (in CC) ...

2018-07-12 21:22 GMT+02:00 Paul Koning :
> I tried to rebuild for target pdp11 with fortran enabled (in the past I've 
> just enabled C).  It builds fine but the resulting compiler crashes at 
> startup:
>
> Paul-Konings-MacBook-Pro:gcc pkoning$ ./xgcc -B. -O2 -S ../../hello.f
> f951: internal compiler error: gfc_validate_kind(): Got bad kind
> libbacktrace could not find executable to open
> Please submit a full bug report,
> with preprocessed source if appropriate.
> See  for instructions.
>
> "hello.f" is the typical "hello world" program.  Some debugging got me to 
> here:
>
> * thread #1, queue = 'com.apple.main-thread', stop reason = step over
> frame #0: 0x0001001c1c93 f951`gfc_init_kinds() [inlined] 
> gfc_validate_kind(type=BT_REAL, kind=, may_fail=false) at 
> trans-types.c:814 [opt]
>811  }
>812
>813if (rc < 0 && !may_fail)
> -> 814  gfc_internal_error ("gfc_validate_kind(): Got bad kind");
>815
>816return rc;
>817  }
> Target 0: (f951) stopped.
>
> So it's unhappy about some "kind", for BT_REAL.  I'm not sure what that 
> means.  Is it mapping the available data types to Fortran "KIND" values?  If 
> so, is there something the target has to do for this to work?  Note that this 
> isn't an IEEE target, so if the initialization is expecting IEEE float then 
> that may account for it.  But I have no idea what to do here, and the manual 
> offers no clue.

A "kind" in Fortran is the size of the data type in bytes. E.g.
"real(kind=4)" would be a 'single-precision' 32-bit float number,
while "real(kind=8)" would be a 'double-precision' 64-bit float
number. The default kind for REAL variables is 4 in gfortran, see:

https://gcc.gnu.org/onlinedocs/gcc-8.1.0/gfortran/KIND-Type-Parameters.html

Since pdp-11 seems to be a 16-bit platform, such a 32-bit
floating-point type might not be available there? Possibly it makes
sense to set the default REAL kind to 2 for such a target?

Cheers,
Janus


How does a target make Fortran work?

2018-07-12 Thread Paul Koning
I tried to rebuild for target pdp11 with fortran enabled (in the past I've just 
enabled C).  It builds fine but the resulting compiler crashes at startup:

Paul-Konings-MacBook-Pro:gcc pkoning$ ./xgcc -B. -O2 -S ../../hello.f
f951: internal compiler error: gfc_validate_kind(): Got bad kind
libbacktrace could not find executable to open
Please submit a full bug report,
with preprocessed source if appropriate.
See  for instructions.

"hello.f" is the typical "hello world" program.  Some debugging got me to here:

* thread #1, queue = 'com.apple.main-thread', stop reason = step over
frame #0: 0x0001001c1c93 f951`gfc_init_kinds() [inlined] 
gfc_validate_kind(type=BT_REAL, kind=, may_fail=false) at 
trans-types.c:814 [opt]
   811  }
   812  
   813if (rc < 0 && !may_fail)
-> 814  gfc_internal_error ("gfc_validate_kind(): Got bad kind");
   815  
   816return rc;
   817  }
Target 0: (f951) stopped.

So it's unhappy about some "kind", for BT_REAL.  I'm not sure what that means.  
Is it mapping the available data types to Fortran "KIND" values?  If so, is 
there something the target has to do for this to work?  Note that this isn't an 
IEEE target, so if the initialization is expecting IEEE float then that may 
account for it.  But I have no idea what to do here, and the manual offers no 
clue.

paul