[patch, fortran] PR33055 Runtime error in INQUIRE unit existance with -fdefault-integer-8

Jerry DeLisle jvdelisle@verizon.net
Sun Aug 26 10:45:00 GMT 2007


:ADDPATCH fortran:

Hi all,

The attached patch is a bit tricky because there is interaction between the 
front end and the run-time library.

The problem here is that when INQUIRE'ing by UNIT to determine existence, an 
error was generated for a bad unit number.  All UNITs with good unit numbers 
exist since they can be opened implicitly (i.e. fort.10)

So by definition, the unit does not exist when a the unit number is bad.  Bad 
meaning less than zero or greater than GFC_INTEGER_4_HUGE.

In a previous bug we found that certain constructs passed as integer-8 that are 
outside the acceptable integer-4 range would get wrapped when converted to 
integer-4 and result in a valid unit number.  An example of this is:

	unit=2_8*huge(0_4)+20_8

To catch this we had to put error detection in the front end to check the unit 
number before the conversion.  This is done in trans-io.c (set_parameter_value).
The consequence of this was that in the INQUIRE statement we were throwing an 
error when -fdefault-integer-8 was used because this checking is enabled when 
the unit number coming in is not KIND=4.  There was no way that the INQUIRE 
frontend or run-time would know an error occurred.

The attached patch fixes this by doing the following:

In gfc_trans_inquire, if EXIST has been given, we check to see if it is by UNIT 
and if IOSTAT is there.  If IOSTAT is there, we allow the error mechanism to 
operate as-is and pass the IOSTAT variable to generate_error, where it is 
intercepted and no error is emitted, only the IOSTAT variable is set.

If, however, there is no IOSTAT in the INQUIRE, a dummy variable is created and 
  used to pass the error code, if any, to generate_error.  Thus, we pass the 
ERROR_BAD_UNIT code to the library.

In the library, inquire.c (inquire_via_unit), the various conditions are 
checked.  The effect is that if EXIST has been given, no error will be issued 
for a bad unit number, but EXIST is set to FALSE.  If an IOSTAT was passed, it 
is set to ERROR_BAD_UNIT.  Also, (inquire_via_unit) is used by st_inquire for 
INQUIRE by file name, so this is also checked to avoid any conflicts.  INQUIRE 
by UNIT and INQUIRE by file name are always mutually exclusive.

Regression tested on x86-64-Gnu-Linux.  Updated test case provided in patch to 
include the tricky code.  Checked with -fdefault-integer-8.

OK for trunk?

Regards,

Jerry

2007-08-24  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR fortran/33055
	* trans-io.c (create_dummy_iostat): New function to create a unique
	dummy variable expression to use with IOSTAT.
	(gfc_trans_inquire): Use the new function to pass unit number error info
	to run-time library if a regular IOSTAT variable was not given.

	PR libfortran/33055
	* io/inquire.c (inquire_via_unit):  If inquiring by unit, check for
	an error condition from the IOSTAT variable and set EXIST to false if
	there was a bad unit number.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: pr33055.diff
Type: text/x-patch
Size: 3220 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20070826/f298a357/attachment.bin>


More information about the Fortran mailing list