public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Patch, Fortran] PR 34495 - Add -std=f95/f2003 diagnostics for real/float  ...
@ 2007-12-16 21:25 Tobias Burnus
  2007-12-16 21:28 ` Jerry DeLisle
  2007-12-17  9:01 ` Manfred Schwarb
  0 siblings, 2 replies; 4+ messages in thread
From: Tobias Burnus @ 2007-12-16 21:25 UTC (permalink / raw)
  To: gcc-patches, 'fortran@gcc.gnu.org'

[-- Attachment #1: Type: text/plain, Size: 482 bytes --]

This fixes the easier part of PR34495:

gfortran -std=f95 allowed REAL(), DBLE() and CMPLX() in initialization
expressions while the Fortran 95 standard does not.

Now, this is properly diagnosed.

Additionally, FLOAT and SNGL were marked as GFC_STD_F77, they are G77
extensions and should thus be marked as GFC_STD_GNU.

Build and regression tested on x86-64-linux with no failures (except for
the old common_6.f90 [PR33375] and ltrans-7.f90 [PR34413]).

OK for the trunk?

Tobias

[-- Attachment #2: init-real.diff --]
[-- Type: text/plain, Size: 2753 bytes --]

2007-12-16  Tobias Burnus  <burnus@net-b.de>

	PR fortran/34495
	* intrinsic.c (add_functions): Mark float and sngl as STD_GNU.
	(gfc_intrinsic_func_interface): Reject REAL, DBLE and CMPLX
	in initialization expressions for -std=f95.

2007-12-16  Tobias Burnus  <burnus@net-b.de>

	PR fortran/34495
	* gfortran.dg/initialization_16.f90: New.

Index: gcc/fortran/intrinsic.c
===================================================================
--- gcc/fortran/intrinsic.c	(revision 130991)
+++ gcc/fortran/intrinsic.c	(working copy)
@@ -2047,11 +2047,11 @@ add_functions (void)
 	     gfc_check_fn_c, gfc_simplify_realpart, gfc_resolve_realpart,
 	     a, BT_UNKNOWN, dr, REQUIRED);
 
-  add_sym_1 ("float", GFC_ISYM_REAL, CLASS_ELEMENTAL, ACTUAL_NO, BT_REAL, dr, GFC_STD_F77,
+  add_sym_1 ("float", GFC_ISYM_REAL, CLASS_ELEMENTAL, ACTUAL_NO, BT_REAL, dr, GFC_STD_GNU,
 	     gfc_check_i, gfc_simplify_float, NULL,
 	     a, BT_INTEGER, di, REQUIRED);
 
-  add_sym_1 ("sngl", GFC_ISYM_REAL, CLASS_ELEMENTAL, ACTUAL_NO, BT_REAL, dr, GFC_STD_F77,
+  add_sym_1 ("sngl", GFC_ISYM_REAL, CLASS_ELEMENTAL, ACTUAL_NO, BT_REAL, dr, GFC_STD_GNU,
 	     NULL, gfc_simplify_sngl, NULL,
 	     a, BT_REAL, dd, REQUIRED);
 
@@ -3388,6 +3388,14 @@ gfc_intrinsic_func_interface (gfc_expr *
   if (check_intrinsic_standard (name, isym->standard, &expr->where) == FAILURE)
     return MATCH_ERROR;
 
+  if ((isym->id == GFC_ISYM_REAL || isym->id == GFC_ISYM_DBLE
+       || isym->id == GFC_ISYM_CMPLX)
+      && gfc_init_expr
+      && gfc_notify_std (GFC_STD_F2003, "Fortran 2003: Function '%s' "
+			 "as initialization expression at %L", name,
+			 &expr->where) == FAILURE)
+    return MATCH_ERROR;
+
   gfc_current_intrinsic_where = &expr->where;
 
   /* Bypass the generic list for min and max.  */
Index: gcc/testsuite/gfortran.dg/initialization_16.f90
===================================================================
--- gcc/testsuite/gfortran.dg/initialization_16.f90	(revision 0)
+++ gcc/testsuite/gfortran.dg/initialization_16.f90	(revision 0)
@@ -0,0 +1,15 @@
+! { dg-do compile }
+! { dg-options "-std=f95 -Wall" }
+!
+! PR fortran/34495
+!
+! Check for invalid Fortran 95 initialization expressions
+!
+program main
+  implicit none
+  real, parameter :: r1 = real(33)    ! { dg-error "Fortran 2003: Function 'real' as initialization expression" } 
+  real, parameter :: r2 = dble(33)    ! { dg-error "Fortran 2003: Function 'dble' as initialization expression" }
+  real, parameter :: r4 = cmplx(33,33)! { dg-error "Fortran 2003: Function 'cmplx' as initialization expression" }
+  print *, sngl(1.0d0) ! { dg-error "not included in the selected standard" }
+  print *, float(1.0)  ! { dg-error "not included in the selected standard" }
+end program main

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Patch, Fortran] PR 34495 - Add -std=f95/f2003 diagnostics for  real/float  ...
  2007-12-16 21:25 [Patch, Fortran] PR 34495 - Add -std=f95/f2003 diagnostics for real/float Tobias Burnus
@ 2007-12-16 21:28 ` Jerry DeLisle
  2007-12-17  9:01 ` Manfred Schwarb
  1 sibling, 0 replies; 4+ messages in thread
From: Jerry DeLisle @ 2007-12-16 21:28 UTC (permalink / raw)
  To: Tobias Burnus; +Cc: gcc-patches, 'fortran@gcc.gnu.org'

Tobias Burnus wrote:
> This fixes the easier part of PR34495:
> 
> gfortran -std=f95 allowed REAL(), DBLE() and CMPLX() in initialization
> expressions while the Fortran 95 standard does not.
> 
> Now, this is properly diagnosed.
> 
> Additionally, FLOAT and SNGL were marked as GFC_STD_F77, they are G77
> extensions and should thus be marked as GFC_STD_GNU.
> 
> Build and regression tested on x86-64-linux with no failures (except for
> the old common_6.f90 [PR33375] and ltrans-7.f90 [PR34413]).
> 
> OK for the trunk?
> 
> Tobias
> 
This one is easy.  OK

Jerry

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Patch, Fortran] PR 34495 - Add -std=f95/f2003 diagnostics for  real/float  ...
  2007-12-16 21:25 [Patch, Fortran] PR 34495 - Add -std=f95/f2003 diagnostics for real/float Tobias Burnus
  2007-12-16 21:28 ` Jerry DeLisle
@ 2007-12-17  9:01 ` Manfred Schwarb
  2007-12-17 11:43   ` [Patch, committed] " Tobias Burnus
  1 sibling, 1 reply; 4+ messages in thread
From: Manfred Schwarb @ 2007-12-17  9:01 UTC (permalink / raw)
  To: Tobias Burnus, fortran, gcc-patches

Tobias,

> 
> Additionally, FLOAT and SNGL were marked as GFC_STD_F77, they are G77
> extensions and should thus be marked as GFC_STD_GNU.
> 

FLOAT and SNGL are very much standard Fortran77, they are mentioned
in every single fortran77 textbook I have. Additionally, they are
correctly listed in the g77 manual 
[listed as "Intrinsic groups: (standard FORTRAN 77)"].

Fortran has the concept of "Generic Names" and "Specific Names" 
for intrinsics.
For this case, REAL is the generic name, and REAL, FLOAT and SNGL
are the corresponding specific names.

Thanks,
Manfred
-- 
GMX FreeMail: 1 GB Postfach, 5 E-Mail-Adressen, 10 Free SMS.
Alle Infos und kostenlose Anmeldung: http://www.gmx.net/de/go/freemail

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Patch, committed] Re: [Patch, Fortran] PR 34495 - Add -std=f95/f2003  diagnostics for  real/float  ...
  2007-12-17  9:01 ` Manfred Schwarb
@ 2007-12-17 11:43   ` Tobias Burnus
  0 siblings, 0 replies; 4+ messages in thread
From: Tobias Burnus @ 2007-12-17 11:43 UTC (permalink / raw)
  To: Manfred Schwarb; +Cc: fortran, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 1109 bytes --]

Manfred Schwarb wrote:
>> Additionally, FLOAT and SNGL were marked as GFC_STD_F77, they are G77
>> extensions and should thus be marked as GFC_STD_GNU
> FLOAT and SNGL are very much standard Fortran77, they are mentioned
> in every single fortran77 textbook I have. Additionally, they are
> correctly listed in the g77 manual 
> [listed as "Intrinsic groups: (standard FORTRAN 77)"].
>   

I thought I check the Fortran 95/2003 standard carefully, but obviously
I missed it. They are only listed in "13.6 Specific names for standard
intrinsic functions" (Fortran 2003); they are not even listed in the index.


Thanks for pointing out and sorry for my mistake.


However, there is something good in this mistake:

a) The gfortran documentation was wrong (now fixed)

b) FLOAT and SNGL allow with -std=f2003/f95 more types/kinds for the
argument than the Fortran standard; I filled a bug:
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34505


I committed (Rev. 131007) now the following patch as obvious after
bootstapping and doing check-gfortran/libgomp check on x86-64-linux. I
also did a "make pdf".

Tobias

[-- Attachment #2: committed.diff --]
[-- Type: text/plain, Size: 4326 bytes --]

Index: gcc/testsuite/ChangeLog
===================================================================
--- gcc/testsuite/ChangeLog	(Revision 131006)
+++ gcc/testsuite/ChangeLog	(Arbeitskopie)
@@ -1,3 +1,8 @@
+2007-12-17  Tobias Burnus  <burnus@net-b.de>
+
+	* gfortran.dg/initialization_16.f90: Update as FLOAT/SNGL are
+	part of Fortran 77/95/2003.
+
 2007-12-17  Dorit Nuzman  <dorit@il.ibm.com>
 
 	PR tree-optimization/34445
Index: gcc/testsuite/gfortran.dg/initialization_16.f90
===================================================================
--- gcc/testsuite/gfortran.dg/initialization_16.f90	(Revision 131004)
+++ gcc/testsuite/gfortran.dg/initialization_16.f90	(Arbeitskopie)
@@ -9,7 +9,7 @@
   implicit none
   real, parameter :: r1 = real(33)    ! { dg-error "Fortran 2003: Function 'real' as initialization expression" } 
   real, parameter :: r2 = dble(33)    ! { dg-error "Fortran 2003: Function 'dble' as initialization expression" }
-  real, parameter :: r4 = cmplx(33,33)! { dg-error "Fortran 2003: Function 'cmplx' as initialization expression" }
-  print *, sngl(1.0d0) ! { dg-error "not included in the selected standard" }
-  print *, float(1.0)  ! { dg-error "not included in the selected standard" }
+  complex, parameter :: z = cmplx(33,33)! { dg-error "Fortran 2003: Function 'cmplx' as initialization expression" }
+  real, parameter :: r4 = sngl(3.d0)  ! { dg-error "Fortran 2003: Function 'sngl' as initialization expression" }
+  real, parameter :: r5 = float(33)   ! { dg-error "Fortran 2003: Function 'float' as initialization expression" }
 end program main
Index: gcc/fortran/intrinsic.c
===================================================================
--- gcc/fortran/intrinsic.c	(Revision 131004)
+++ gcc/fortran/intrinsic.c	(Arbeitskopie)
@@ -2047,11 +2047,11 @@
 	     gfc_check_fn_c, gfc_simplify_realpart, gfc_resolve_realpart,
 	     a, BT_UNKNOWN, dr, REQUIRED);
 
-  add_sym_1 ("float", GFC_ISYM_REAL, CLASS_ELEMENTAL, ACTUAL_NO, BT_REAL, dr, GFC_STD_GNU,
+  add_sym_1 ("float", GFC_ISYM_REAL, CLASS_ELEMENTAL, ACTUAL_NO, BT_REAL, dr, GFC_STD_F77,
 	     gfc_check_i, gfc_simplify_float, NULL,
 	     a, BT_INTEGER, di, REQUIRED);
 
-  add_sym_1 ("sngl", GFC_ISYM_REAL, CLASS_ELEMENTAL, ACTUAL_NO, BT_REAL, dr, GFC_STD_GNU,
+  add_sym_1 ("sngl", GFC_ISYM_REAL, CLASS_ELEMENTAL, ACTUAL_NO, BT_REAL, dr, GFC_STD_F77,
 	     NULL, gfc_simplify_sngl, NULL,
 	     a, BT_REAL, dd, REQUIRED);
 
Index: gcc/fortran/gfortran.texi
===================================================================
--- gcc/fortran/gfortran.texi	(Revision 131004)
+++ gcc/fortran/gfortran.texi	(Arbeitskopie)
@@ -1101,8 +1101,8 @@
 and @code{CMPLX}; the result is the same as if the integer BOZ
 literal had been converted by @code{TRANSFER} to, respectively,
 @code{real}, @code{double precision}, @code{integer} or @code{complex}.
-The GNU Fortran intrinsic procedure @code{FLOAT}, @code{DFLOAT},
-@code{COMPLEX} and @code{DCMPLX} are treated alike.
+As GNU Fortran extension the intrinsic procedures @code{FLOAT},
+@code{DFLOAT}, @code{COMPLEX} and @code{DCMPLX} are treated alike.
 
 As an extension, GNU Fortran allows hexadecimal BOZ literal constants to
 be specified using the @code{X} prefix, in addition to the standard
Index: gcc/fortran/ChangeLog
===================================================================
--- gcc/fortran/ChangeLog	(Revision 131004)
+++ gcc/fortran/ChangeLog	(Arbeitskopie)
@@ -1,3 +1,10 @@
+2007-12-17  Tobias Burnus  <burnus@net-b.de>
+
+	* intrinsic.c (add_functions): Undo change; mark float and
+	sngl as STD_F77.
+	* intrinsic.texi (FLOAT, SNGL): Change standard to F77 or later.
+	* gfortran.texi (BOZ): Make note about FLOAT etc. clearer.
+
 2007-12-16  Tobias Burnus  <burnus@net-b.de>
 
 	PR fortran/34495
Index: gcc/fortran/intrinsic.texi
===================================================================
--- gcc/fortran/intrinsic.texi	(Revision 131004)
+++ gcc/fortran/intrinsic.texi	(Arbeitskopie)
@@ -3850,7 +3850,7 @@
 @code{FLOAT(I)} converts the integer @var{I} to a default real value.
 
 @item @emph{Standard}:
-GNU extension
+F77 and later
 
 @item @emph{Class}:
 Elemental function
@@ -9700,7 +9700,7 @@
 that is specific to one type for @var{A}.
 
 @item @emph{Standard}:
-GNU extension
+F77 and later
 
 @item @emph{Class}:
 Elemental function

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2007-12-17 11:26 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-12-16 21:25 [Patch, Fortran] PR 34495 - Add -std=f95/f2003 diagnostics for real/float Tobias Burnus
2007-12-16 21:28 ` Jerry DeLisle
2007-12-17  9:01 ` Manfred Schwarb
2007-12-17 11:43   ` [Patch, committed] " Tobias Burnus

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).