[PATCH] Fortran -- Handle BOZ in accordance with F2008/2015.

Steve Kargl sgk@troutmask.apl.washington.edu
Fri Oct 6 20:34:00 GMT 2017


All,

I have spent the last few days trying to reconcile the various Fortran
standards' requirements for handling BOZ.  The short story is that J3
over the last 27 years has made incompatible changes to the interpretation
of a BOZ (under some circumstances).  The interpretations in F2008 and
F2015 now treat a boz-literal-constant as a sequence of bits.  Unfortunately,
due to quirks in how BOZ are currently implemented in gfortran and a boat
load of documented and undocumented extensions, bringing gfortran into 
agreement with F2008/F2015 led to a rewrite of BOZ handling.  In the 
rewrite I have made no attempt to use the -std= option to try to maintain
the incompatibilities between standards.

On x86_64-*-freebsd, the attached patch gives

tail gcc/testsuite/gfortran/gfortran.sum

                === gfortran Summary ===

# of expected passes            45888
# of unexpected failures        4
# of unexpected successes       6
# of expected failures          97
# of unsupported tests          79
/home/sgk/gcc/obj/gcc/gfortran  version 8.0.0 20170927 (experimental) (GCC)

The 4 unexpected failures are not related to this patch.

2017-10-06  Steven G. Kargl  <kargl@gcc.gnu.org>

	PR fortran/45513
	PR fortran/54072
	PR fortran/81509
	* array.c (resolve_array_list): Handle an array descriptor
	with BOZ elements.
	* check.c (numeric_check): Error for BOZ when numeric type is expected.
	(numeric_or_boz_check): New function.  Check for numeric or BOZ arg.
	(int_or_boz_check): New function.  Check for INTEGER or BOZ arg.
	(gfc_check_bge_bgt_ble_blt): Use int_or_boz_check.
	(gfc_check_cmplx): Use numeric_or_boz_check.
	(gfc_check_complex): Permit BOZ arguments.
	(gfc_check_dcmplx): Use numeric_or_boz_check.
	(gfc_check_dble): Allow BOZ argument.
	(boz_args_check): New function.  Disallow two BOZ arguments.
	(gfc_boz2int): New function.  In-place conversion of BOZ to INTEGER.
	(gfc_check_dshift): Use int_or_boz_check, boz_args_check, gfc_boz2int.
	(gfc_check_iand): Renamed to ...
	(gfc_check_iand_ieor_ior): ... this.  Use int_or_boz_check,
	boz_args_check, and gfc_boz2int.  Convert gfc_notify_std to gfc_error.
	(gfc_check_ieor, gfc_check_ior): Removed function.
	(gfc_check_int): Use numeric_or_boz_check 
	(gfc_check_merge_bits): Use int_or_boz_check, boz_args_check,
	gfc_boz2int
	(gfc_check_real): Allow BOZ.  Use numeric_or_boz_check.
	(gfc_check_and): Allow BOZ. Use boz_args_check and gfc_boz2int
	* data.c (gfc_assign_data_value): Implement F2008/F2015 sematics for
	for BOZ in data statement.
	* expr.c (gfc_get_expr): Set boz component of gfc_expr to NULL.
	(gfc_copy_expr, free_expr0): Cope new boz component.
	(gfc_check_assign): Replace old is_boz checks with BT_BOZ checks.
	Use gfc_boz2int.
	* gfortran.h (gfc_expr): Remove is_boz component.  Add boz
	component. Add prototyp gfc_boz2int.
	* intrinsic.c (add_functions): Use gfc_check_iand_ieor_ior
	in place of gfc_check_iand, gfc_check_ieor, and gfc_check_ior.
	* intrinsic.h: Add prototype for gfc_check_iand_ieor_ior.
	Remove prototypes for gfc_check_iand, gfc_check_ieor, gfc_check_ior.
	* intrinsic.texi: Document (some) changes.
	* iresolve.c(gfc_resolve_iand,gfc_resolve_ieor,gfc_resolve_ior): Mark
	j with ATTRIBUTE_UNUSED. Make IAND, IEOR, IOR
	conform to F2008/2015.
	* libgfortran.h: Add new basic type BT_BOZ.
	* primary.c (match_boz_constant): Remove old handling of BOZ.
	Cache BOZ string in gfc_expr's boz component.
 	* resolve.c (resolve_operator): Allow BOZ in binary 
	numeric and rational operators.  Use gfc_boz2int or gfc_convert_boz
	as needed.
	(resolve_allocate_expr): Split declaration and initialization.
	(resolve_ordinary_assign): Replace is_boz checks with BT_BOZ checks.
	* simplify.c (convert_boz): Replace BT_INTEGER with BT_BOZ
	(simplify_cmplx): Rearrange allow simplication of individual args.
	Convert BOZ as needed.
	(gfc_simplify_complex): Account of args with BT_BOZ.
 	(gfc_simplify_float): Replace is_boz check with BT_BOZ check.
	(simplify_intconv): In-place conversin of boz to INTEGER.
	* target-memory.c (boz2int): New function.  Conversion of 
	boz to INTEGER with widest decimal range.
	(gfc_convert_boz): Use it.  Remove clearly is_boz.

2017-10-06  Steven G. Kargl  <kargl@gcc.gnu.org>

	PR fortran/45513
	PR fortran/54072
	PR fortran/81509
	* gfortran.dg/achar_5.f90: Remove BOZ arg tests.
	* gfortran.dg/boz_4.f90: Delete test as it no longer applies.
	* gfortran.dg/graphite/id-26.f03:  Fix test.
	* gfortran.dg/pr81509_1.f90: New test.
	* gfortran.dg/pr81509_2.f90: New test.
	* gfortran.dg/unf_io_convert_2.f90: Fix test.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: boz.diff
Type: text/x-diff
Size: 48603 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20171006/ff1be327/attachment.bin>


More information about the Fortran mailing list