diff mbox

[fortran] Fix PR 54033, problems with -I

Message ID 50117B5D.8030304@netcologne.de
State New
Headers show

Commit Message

Thomas Koenig July 26, 2012, 5:16 p.m. UTC
Hello world,

the attached, rather obvious patch emits warnings for several
cases where there is something wrong with include directories.
No test case because I couldn't figure out how to test for a
warning with no line number.

OK for trunk?

	Thomas

2012-07-26  Thomas König  <tkoenig@gcc.gnu.org>

         PR fortran/54033
         * scanner.c (add_path_to_list): Emit warning if an error occurs
         for an include path, if it is not present or if it is not a
         directory.  Do not add the path in these cases.

Comments

Janis Johnson July 26, 2012, 6:20 p.m. UTC | #1
On 07/26/2012 10:16 AM, Thomas Koenig wrote:

> No test case because I couldn't figure out how to test for a
> warning with no line number.

Try using line number 0.

Janis
Thomas Koenig July 27, 2012, 8:06 p.m. UTC | #2
Hi Janis,

> On 07/26/2012 10:16 AM, Thomas Koenig wrote:
>
>> No test case because I couldn't figure out how to test for a
>> warning with no line number.
>
> Try using line number 0.

That didn't work for me. Using

! { dg-do compile }
! { dg-options "-I include_6.f90 -I missing_dir" }
! { dg-warning "not a directory" "missing directory" target *-*-* 0 }
! { dg-warning "does not exist" "nonexisting directory" target *-*-* 0 }
end

got me

Warning: Include directory "include_6.f90" does not exist^M
Warning: Include directory "missing_dir" does not exist^M
output is:
Warning: Include directory "include_6.f90" does not exist^M
Warning: Include directory "missing_dir" does not exist^M

FAIL: gfortran.dg/include_6.f90  -O  (test for excess errors)
Excess errors:
:0:0: Warning: Include directory "include_6.f90" does not exist
:0:0: Warning: Include directory "missing_dir" does not exist

and

! { dg-do compile }
! { dg-options "-I include_6.f90 -I missing_dir" }
! { dg-warning "not a directory" "missing directory" target *-*-* 0 }
! { dg-warning "does not exist" "nonexisting directory" target *-*-* 0 }
! { dg-excess-errors "Include directory" }
end

resulted in an XFAIL:

Warning: Include directory "include_6.f90" does not exist^M
Warning: Include directory "missing_dir" does not exist^M
output is:
Warning: Include directory "include_6.f90" does not exist^M
Warning: Include directory "missing_dir" does not exist^M

XFAIL: gfortran.dg/include_6.f90  -O  (test for excess errors)
Excess errors:
:0:0: Warning: Include directory "include_6.f90" does not exist
:0:0: Warning: Include directory "missing_dir" does not exist

so dg-excess-errors seems to imply XFAIL.

The problem may be related to the fact that, when we process the
options, we do not yet have a file name, so dejagnu may have trouble
parsing the warning.

Any other ideas?

	Thomas
Janis Johnson July 27, 2012, 10 p.m. UTC | #3
On 07/27/2012 01:06 PM, Thomas Koenig wrote:
> Hi Janis,
> 
>> On 07/26/2012 10:16 AM, Thomas Koenig wrote:
>>
>>> No test case because I couldn't figure out how to test for a
>>> warning with no line number.
>>
>> Try using line number 0.
> 
> That didn't work for me. Using
> 
> ! { dg-do compile }
> ! { dg-options "-I include_6.f90 -I missing_dir" }
> ! { dg-warning "not a directory" "missing directory" target *-*-* 0 }
> ! { dg-warning "does not exist" "nonexisting directory" target *-*-* 0 }
> end
> 
> got me
> 
> Warning: Include directory "include_6.f90" does not exist^M
> Warning: Include directory "missing_dir" does not exist^M
> output is:
> Warning: Include directory "include_6.f90" does not exist^M
> Warning: Include directory "missing_dir" does not exist^M
> 
> FAIL: gfortran.dg/include_6.f90  -O  (test for excess errors)
> Excess errors:
> :0:0: Warning: Include directory "include_6.f90" does not exist
> :0:0: Warning: Include directory "missing_dir" does not exist

Use "{ target *-*-* }" instead of "target *-*-*".

Notice that the two warnings have the same text, so the directive
looking for "not a directory" will fail.

Janis
diff mbox

Patch

Index: scanner.c
===================================================================
--- scanner.c	(Revision 189754)
+++ scanner.c	(Arbeitskopie)
@@ -311,12 +311,31 @@  add_path_to_list (gfc_directorylist **list, const
 {
   gfc_directorylist *dir;
   const char *p;
-
+  struct stat st;
+  
   p = path;
   while (*p == ' ' || *p == '\t')  /* someone might do "-I include" */
     if (*p++ == '\0')
       return;
 
+  if (stat (p, &st))
+    {
+      if (errno != ENOENT)
+	gfc_warning_now ("Include directory \"%s\": %s", path,
+			 xstrerror(errno));
+      else
+	/* FIXME:  Also support -Wmissing-include-dirs.  */
+	gfc_warning_now ("Include directory \"%s\" does not exist",
+			 path);
+      return;
+    }
+
+  else if (!S_ISDIR (st.st_mode))
+    {
+      gfc_warning_now ("\"%s\" is not a directory", path);
+      return;
+    }
+
   if (head || *list == NULL)
     {
       dir = XCNEW (gfc_directorylist);