[patch, fortran] pr21061 - gfortran ignores -Werror

Bernhard Fischer rep.nop@aon.at
Sun Nov 5 14:58:00 GMT 2006


On Sun, Nov 05, 2006 at 02:45:34PM +0100, Bernhard Fischer wrote:
>On Sat, Nov 04, 2006 at 12:36:27PM +0100, Bernhard Fischer wrote:
>>On Thu, Nov 02, 2006 at 05:11:06PM -0800, Janis Johnson wrote:
>>>On Thu, Nov 02, 2006 at 06:46:11PM +0100, Bernhard Fischer wrote:
>>>> >It was not yet fixed nor committed due to problems with dejagnu.
>>>> >See http://gcc.gnu.org/ml/gcc/2006-10/msg00408.html
>>>> >
>>>> >I'm rewriting the testcases (for free- and fixed form) now and want to
>>>> >see if i can use dg-final { scan-assembler ".*" }.
>>>
>>>I figured out how to write procs output-exists and output-exists-not
>>>that can be called from dg-final to verify whether or not the compiler
>>>output file was not produced.  Will that help?
>>
>>That would help, yes. I'd need this on trunk, the 4_2 and 4_1 branches
>>if possible.
>>
>>Thanks!
>
>What i did come up with was the attached, fwiw.
>I did not (yet) look at how to distinguish dg-do modes, in order to get
>the output_file extension right.

output_file is already available as upvar 2, so using that.
>
>This works for me for
>$ head -n 4 gcc/testsuite/gfortran.dg/warnings_are_errors_1.f 
>! { dg-do compile }
>! { dg-options " -Werror" }
>! { dg-final { output-exists-not } }
>! PR fortran/21061
>
>but i take it there is a more elegant way to do this.

Also there must be a better place to put this than into scanasm.exp.
Suggestions?

I'm applying the parts against the fortran FE as ACKed by Steve Kargl
now. The testsuite snippet currently has no approval.

fortran/ChangeLog
2006-11-05  Bernhard Fischer  <aldot@gcc.gnu.org>

	PR fortran/21061
	* error.c (gfc_warning): If warnings_are_errors then treat
	warnings as errors with respect to the exit code.
	(gfc_notify_std): Ditto.
	(gfc_warning_now): Ditto.

testsuite/ChangeLog
2006-11-05  Bernhard Fischer  <aldot@gcc.gnu.org>

	PR fortran/21061
	* gfortran.dg/warnings_are_errors.f: New test.
	* gfortran.dg/warnings_are_errors.f90: New test.
	* lib/scanasm.exp (output-exists, output-exists-not): New
	routines to check if an output file does exist or not.


-------------- next part --------------
Index: gcc-4.3/gcc/testsuite/lib/scanasm.exp
===================================================================
--- gcc-4.3/gcc/testsuite/lib/scanasm.exp	(revision 118494)
+++ gcc-4.3/gcc/testsuite/lib/scanasm.exp	(working copy)
@@ -59,6 +59,30 @@ proc dg-scan { name positive testcase ou
     }
 }
 
+# Check that an output file does exist
+proc output-exists { } {
+    upvar 2 name testcase
+    upvar 2 output_file output_file
+
+    if { [file exists $output_file] } {
+        pass "$testcase output-exists $output_file"
+    } else {
+        fail "$testcase output-exists $output_file"
+    }
+}
+
+# Check that an output file does not exist
+proc output-exists-not { } {
+    upvar 2 name testcase
+    upvar 2 output_file output_file
+
+    if { [file exists $output_file] } {
+        fail "$testcase output-exists-not $output_file"
+    } else {
+        pass "$testcase output-exists-not $output_file"
+    }
+}
+
 # Look for a pattern in the .s file produced by the compiler.  See
 # dg-scan for details.
 
Index: gcc-4.3/gcc/testsuite/gfortran.dg/warnings_are_errors_1.f90
===================================================================
--- gcc-4.3/gcc/testsuite/gfortran.dg/warnings_are_errors_1.f90	(revision 0)
+++ gcc-4.3/gcc/testsuite/gfortran.dg/warnings_are_errors_1.f90	(revision 0)
@@ -0,0 +1,27 @@
+! { dg-do compile }
+! { dg-options "-Werror -Wunused" }
+! { dg-final { output-exists-not } }
+! PR fortran/21061
+! gfortran ignores -Werror
+! free-form tests
+
+! gfc_notify_std:
+       function char_ (ch) ! { dg-warning "is obsolescent in fortran 95" }
+       character(*) :: char_, ch
+        char_ = ch
+       end function char_
+
+! warning(0,...):
+!      function wrong_warn (i) ! { -warning "Function does not return a value" }
+!      integer i
+!      end function wrong_warn
+
+       implicit none
+! gfc_warning:
+1234  complex :: cplx ! { dg-warning "defined but cannot be used" }
+      cplx = 20.
+
+! gfc_warning_now:
+ 1 ! { dg-warning "Ignoring statement label in empty statement" }
+       end
+
Index: gcc-4.3/gcc/testsuite/gfortran.dg/warnings_are_errors_1.f
===================================================================
--- gcc-4.3/gcc/testsuite/gfortran.dg/warnings_are_errors_1.f	(revision 0)
+++ gcc-4.3/gcc/testsuite/gfortran.dg/warnings_are_errors_1.f	(revision 0)
@@ -0,0 +1,24 @@
+! { dg-do compile }
+! { dg-options " -Werror" }
+! { dg-final { output-exists-not } }
+! PR fortran/21061
+! gfortran ignores -Werror
+! fixed-form tests
+       program warnings_are_errors_1
+       implicit none
+       integer(kind=1) :: i
+       real :: r1, r2(3)
+! gfc_warning_now:
+0      ! { dg-warning "Zero is not a valid statement label" }
+!
+34 5   i=0 
+! gfc_notify_std(GFC_STD_F95_DEL):
+       do r1 = 1.0, 2 ! { dg-warning "Obsolete: REAL DO loop iterator" }
+         i = i+1
+       end do
+       call foo j bar
+! gfc_warning:
+       r2(4) = 0 ! { dg-warning "is out of bounds" }
+       
+       goto 3 45
+       end
Index: gcc-4.3/gcc/fortran/error.c
===================================================================
--- gcc-4.3/gcc/fortran/error.c	(revision 118494)
+++ gcc-4.3/gcc/fortran/error.c	(working copy)
@@ -476,7 +476,12 @@ gfc_warning (const char *nocmsgid, ...)
 
   va_start (argp, nocmsgid);
   if (buffer_flag == 0)
+  {
     warnings++;
+    if (warnings_are_errors)
+      errors++;
+  }
+
   error_print (_("Warning:"), _(nocmsgid), argp);
   va_end (argp);
 
@@ -519,14 +524,15 @@ gfc_notify_std (int std, const char *noc
 
   if (gfc_suppress_error)
     return warning ? SUCCESS : FAILURE;
-  
-  cur_error_buffer = warning ? &warning_buffer : &error_buffer;
+
+  cur_error_buffer = (warning && !warnings_are_errors)
+    ? &warning_buffer : &error_buffer;
   cur_error_buffer->flag = 1;
   cur_error_buffer->index = 0;
 
   if (buffer_flag == 0)
     {
-      if (warning)
+      if (warning && !warnings_are_errors)
 	warnings++;
       else
 	errors++;
@@ -539,7 +545,7 @@ gfc_notify_std (int std, const char *noc
   va_end (argp);
 
   error_char ('\0');
-  return warning ? SUCCESS : FAILURE;
+  return (warning && !warnings_are_errors) ? SUCCESS : FAILURE;
 }
 
 
@@ -557,6 +563,8 @@ gfc_warning_now (const char *nocmsgid, .
   i = buffer_flag;
   buffer_flag = 0;
   warnings++;
+  if (warnings_are_errors)
+    errors++;
 
   va_start (argp, nocmsgid);
   error_print (_("Warning:"), _(nocmsgid), argp);


More information about the Gcc-patches mailing list