This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[Patch, Fortran] PR33037 - TRANSFER: Warn if source size < result size
- From: Tobias Burnus <burnus at net-b dot de>
- To: "'fortran at gcc dot gnu dot org'" <fortran at gcc dot gnu dot org>, gcc-patches <gcc-patches at gcc dot gnu dot org>
- Date: Fri, 21 Sep 2007 11:45:03 +0200
- Subject: [Patch, Fortran] PR33037 - TRANSFER: Warn if source size < result size
:ADDPATCH fortran:
If one specifies a SIZE in TRANSFER, the result is undefined if the
SOURCE is smaller than the requested size, example:
transfer('x', 0, 20)
With the patch, gfortran diagnoses:
Warning: Intrinsic TRANSFER at (1) has partly undefined result: source
size 1 < result size 80
Note: The patch does not completely fix PR33037 as we do warn for, e.g.,
integer :: lhs(4)
lhs = transfer(4, 0)
where size(LHS) > size(RHS).
Build and regression tested on x86-64/Linux.
Ok for the trunk?
Tobias
2007-09-21 Tobias Burnus <burnus@net-b.de>
PR fortran/33037
* simplify.c (gfc_simplify_transfer): Warn if source size
is smaller than result size.
2007-09-21 Tobias Burnus <burnus@net-b.de>
PR fortran/33037
* gfortran.dg/transfer_check_1.f90: New.
Index: gcc/fortran/simplify.c
===================================================================
--- gcc/fortran/simplify.c (Revision 128644)
+++ gcc/fortran/simplify.c (Arbeitskopie)
@@ -4059,6 +4059,11 @@ gfc_simplify_transfer (gfc_expr *source,
result_size = result_elt_size;
}
+ if (source_size < result_size)
+ gfc_warning("Intrinsic TRANSFER at %L has partly undefined result: "
+ "source size %ld < result size %ld", &source->where,
+ (long) source_size, (long) result_size);
+
/* Allocate the buffer to store the binary version of the source. */
buffer_size = MAX (source_size, result_size);
buffer = (unsigned char*)alloca (buffer_size);
Index: gcc/testsuite/gfortran.dg/transfer_check_1.f90
===================================================================
--- gcc/testsuite/gfortran.dg/transfer_check_1.f90 (Revision 0)
+++ gcc/testsuite/gfortran.dg/transfer_check_1.f90 (Revision 0)
@@ -0,0 +1,8 @@
+! { dg-do compile }
+! PR fortran/33037
+!
+print *, transfer('x', 0, 20) ! { dg-warning "has partly undefined result" }
+print *, transfer(1_1, 0) ! { dg-warning "has partly undefined result" }
+print *, transfer([1_2,2_2], 0)
+print *, transfer([1_2,2_2], 0_8) ! { dg-warning "has partly undefined result" }
+end