Commit df1afcca by Harald Anlauf Committed by Harald Anlauf

re PR fortran/90903 (Implement runtime checks for bit manipulation intrinsics)

2019-07-16  Harald Anlauf  <anlauf@gmx.de>

	PR fortran/90903
	* libgfortran.h: Add mask for -fcheck=bits option.
	* options.c (gfc_handle_runtime_check_option): Add option "bits"
	to run-time checks selectable via -fcheck.
	* trans-intrinsic.c (gfc_conv_intrinsic_btest)
	(gfc_conv_intrinsic_singlebitop, gfc_conv_intrinsic_ibits)
	(gfc_conv_intrinsic_shift, gfc_conv_intrinsic_ishft)
	(gfc_conv_intrinsic_ishftc): Implement run-time checks for the
	POS, LEN, SHIFT, and SIZE arguments.
	* gfortran.texi: Document run-time checks for bit manipulation
	intrinsics.
	* invoke.texi: Document new -fcheck=bits option.

	PR fortran/90903
	* gfortran.dg/check_bits_1.f90: New testcase.

From-SVN: r273535
parent 460bf043
2019-07-16 Harald Anlauf <anlauf@gmx.de>
PR fortran/90903
* libgfortran.h: Add mask for -fcheck=bits option.
* options.c (gfc_handle_runtime_check_option): Add option "bits"
to run-time checks selectable via -fcheck.
* trans-intrinsic.c (gfc_conv_intrinsic_btest)
(gfc_conv_intrinsic_singlebitop, gfc_conv_intrinsic_ibits)
(gfc_conv_intrinsic_shift, gfc_conv_intrinsic_ishft)
(gfc_conv_intrinsic_ishftc): Implement run-time checks for the
POS, LEN, SHIFT, and SIZE arguments.
* gfortran.texi: Document run-time checks for bit manipulation
intrinsics.
* invoke.texi: Document new -fcheck=bits option.
2019-07-14 Jerry DeLisle <jvdelisle@gcc.gnu.org>
PR fortran/87233
......
......@@ -3790,7 +3790,8 @@ initialization using @code{_gfortran_set_args}.
Default: enabled.
@item @var{option}[6] @tab Enables run-time checking. Possible values
are (bitwise or-ed): GFC_RTCHECK_BOUNDS (1), GFC_RTCHECK_ARRAY_TEMPS (2),
GFC_RTCHECK_RECURSION (4), GFC_RTCHECK_DO (16), GFC_RTCHECK_POINTER (32).
GFC_RTCHECK_RECURSION (4), GFC_RTCHECK_DO (16), GFC_RTCHECK_POINTER (32),
GFC_RTCHECK_BITS (64).
Default: disabled.
@item @var{option}[7] @tab Unused.
@item @var{option}[8] @tab Show a warning when invoking @code{STOP} and
......
......@@ -183,7 +183,7 @@ and warnings}.
@gccoptlist{-faggressive-function-elimination -fblas-matmul-limit=@var{n} @gol
-fbounds-check -ftail-call-workaround -ftail-call-workaround=@var{n} @gol
-fcheck-array-temporaries @gol
-fcheck=@var{<all|array-temps|bounds|do|mem|pointer|recursion>} @gol
-fcheck=@var{<all|array-temps|bits|bounds|do|mem|pointer|recursion>} @gol
-fcoarray=@var{<none|single|lib>} -fexternal-blas -ff2c
-ffrontend-loop-interchange @gol
-ffrontend-optimize @gol
......@@ -1558,6 +1558,7 @@ library needs to be linked.
@item -fcheck=@var{<keyword>}
@opindex @code{fcheck}
@cindex array, bounds checking
@cindex bit intrinsics checking
@cindex bounds checking
@cindex pointer checking
@cindex memory checking
......@@ -1582,6 +1583,10 @@ sometimes useful in optimization, in order to avoid such temporaries.
Note: The warning is only printed once per location.
@item @samp{bits}
Enable generation of run-time checks for invalid arguments to the bit
manipulation intrinsics.
@item @samp{bounds}
Enable generation of run-time checks for array subscripts
and against the declared minimum and maximum values. It also
......
......@@ -73,9 +73,11 @@ along with GCC; see the file COPYING3. If not see
#define GFC_RTCHECK_DO (1<<3)
#define GFC_RTCHECK_POINTER (1<<4)
#define GFC_RTCHECK_MEM (1<<5)
#define GFC_RTCHECK_BITS (1<<6)
#define GFC_RTCHECK_ALL (GFC_RTCHECK_BOUNDS | GFC_RTCHECK_ARRAY_TEMPS \
| GFC_RTCHECK_RECURSION | GFC_RTCHECK_DO \
| GFC_RTCHECK_POINTER | GFC_RTCHECK_MEM)
| GFC_RTCHECK_POINTER | GFC_RTCHECK_MEM \
| GFC_RTCHECK_BITS)
/* Special unit numbers used to convey certain conditions. Numbers -4
thru -9 available. NEWUNIT values start at -10. */
......
......@@ -580,12 +580,12 @@ gfc_handle_runtime_check_option (const char *arg)
int result, pos = 0, n;
static const char * const optname[] = { "all", "bounds", "array-temps",
"recursion", "do", "pointer",
"mem", NULL };
"mem", "bits", NULL };
static const int optmask[] = { GFC_RTCHECK_ALL, GFC_RTCHECK_BOUNDS,
GFC_RTCHECK_ARRAY_TEMPS,
GFC_RTCHECK_RECURSION, GFC_RTCHECK_DO,
GFC_RTCHECK_POINTER, GFC_RTCHECK_MEM,
0 };
GFC_RTCHECK_BITS, 0 };
while (*arg)
{
......
2019-07-16 Harald Anlauf <anlauf@gmx.de>
PR fortran/90903
* gfortran.dg/check_bits_1.f90: New testcase.
2019-07-16 Jeff Law <law@redhat.com>
PR rtl-optimization/91173
......
! { dg-do run }
! { dg-options "-fcheck=bits -fdump-tree-original" }
! { dg-shouldfail "Fortran runtime error: SIZE argument (0) out of range 1:32 in intrinsic ISHFTC" }
! { dg-output "At line 44 .*" }
!
! Verify that the runtime checks for the bit manipulation intrinsic functions
! do not generate false-positives
program check
implicit none
integer :: i, k, pos, len, shift, size, nb
nb = bit_size (i)
i = 0
do pos = 0, nb-1
k = ibset (i, pos)
i = ibclr (k, pos)
if (btest (i, pos)) stop 1
end do
do pos = 0, nb
do len = 0, nb-pos
i = ibits (i, pos, len)
end do
end do
do shift = 0, nb
k = ishft (i, shift)
i = ishft (k, -shift)
end do
do shift = 0, nb
k = shiftl (i, shift) ! Fortran 2008
i = shiftr (k, shift)
i = shifta (i, shift)
k = lshift (i, shift) ! GNU extensions
i = rshift (k, shift)
end do
do shift = 0, nb
k = ishftc (i, shift)
i = ishftc (k, -shift)
do size = max (1,shift), nb
k = ishftc (i, shift, size)
i = ishftc (k, -shift, size)
end do
end do
size = 0
! The following line should fail with a runtime error:
k = ishftc (i, 0, size)
! Should never get here with -fcheck=bits
stop 2
end program check
! { dg-final { scan-tree-dump-times "_gfortran_runtime_error_at" 21 "original" } }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment