Bug 37821 - [4.4 Regression] gfortran is ignoring #includes with the syntax <file.h>
Summary: [4.4 Regression] gfortran is ignoring #includes with the syntax <file.h>
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.4.0
: P4 normal
Target Milestone: 4.4.0
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-10-14 01:47 UTC by Chris Walter
Modified: 2008-11-03 07:35 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2008-10-14 12:11:19


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Chris Walter 2008-10-14 01:47:29 UTC
If I have a 

-Idirectory in my compile path then

#include "file.h" works
but 
#include <file.h> does not.

The compiler complains the file does not exist.

I use the binaries from http://quatramaran.ens.fr/~coudert/gfortran/
and this broke between the snapshot in May and August. It seems to correspond to the switch to internal cpp.
Comment 1 Chris Walter 2008-10-14 01:50:35 UTC
I forgot to include version info:

Using built-in specs.
Target: i386-apple-darwin8.10.1
Configured with: /tmp/gfortran-20081006/ibin/../gcc/configure --prefix=/usr/local/gfortran --enable-languages=c,fortran --with-gmp=/tmp/gfortran-20081006/gfortran_libs --enable-bootstrap
Thread model: posix
gcc version 4.4.0 20081006 (experimental) [trunk revision 140904] (GCC) 
Comment 2 kargls 2008-10-14 06:26:59 UTC
Is there a problem with using the standard conforming
INCLUDE statement?

You forgot to include a small test case.
Comment 3 Tobias Burnus 2008-10-14 12:11:19 UTC
Confirm. gcc (the C compiler) has using -I test_directory:

#include "..." search starts here:
#include <...> search starts here:
 test_directory
 /usr/local/include
 /projects/tob/gcc-trunk/include
 /projects/tob/gcc-trunk/lib/gcc/x86_64-unknown-linux-gnu/4.4.0/include
 /projects/tob/gcc-trunk/lib/gcc/x86_64-unknown-linux-gnu/4.4.0/include-fixed
 /usr/include
End of search list.

whereas gfortran has the following:

#include "..." search starts here:
 test_directory
 /projects/tob/gcc-trunk/lib/gcc/x86_64-unknown-linux-gnu/4.4.0/finclude
 .
#include <...> search starts here:
 /usr/local/include
 /projects/tob/gcc-trunk/include
 /projects/tob/gcc-trunk/lib/gcc/x86_64-unknown-linux-gnu/4.4.0/include
 /projects/tob/gcc-trunk/lib/gcc/x86_64-unknown-linux-gnu/4.4.0/include-fixed
 /usr/include
End of search list.
Comment 4 Daniel Franke 2008-10-14 12:23:27 UTC
Bugger. How much time do we have left before 4.4?
Comment 5 Tobias Burnus 2008-10-14 12:31:30 UTC
(In reply to comment #3)
> #include "..." search starts here:
>  test_directory
>  /projects/tob/gcc-trunk/lib/gcc/x86_64-unknown-linux-gnu/4.4.0/finclude
>  .

That "." comes last is also wrong; it should come first for "...". However, CPP automatically takes care.

Draft patch below; it works, except that I get the warning (-v -I tes):

ignoring duplicate directory "tes"  <<<<<<<<<<<<<<< Warning
#include "..." search starts here:
#include <...> search starts here:
 tes
 /projects/tob/gcc-trunk/lib/gcc/x86_64-unknown-linux-gnu/4.4.0/finclude
 /usr/local/include
 /projects/tob/gcc-trunk/include
 /projects/tob/gcc-trunk/lib/gcc/x86_64-unknown-linux-gnu/4.4.0/include
 /projects/tob/gcc-trunk/lib/gcc/x86_64-unknown-linux-gnu/4.4.0/include-fixed
 /usr/include
End of search list.

Index: cpp.c
===================================================================
--- cpp.c       (Revision 141104)
+++ cpp.c       (Arbeitskopie)
@@ -628,10 +628,9 @@ gfc_cpp_add_include_path (char *path, bo
 {
   /* CHAIN sets cpp_dir->sysp which differs from 0 if PATH is a system
      include path. Fortran does not define any system include paths.  */
-  int chain = 0;
   int cxx_aware = 0;

-  add_path (path, chain, cxx_aware, user_supplied);
+  add_path (path, BRACKET, cxx_aware, user_supplied);
 }

 void
Index: options.c
===================================================================
--- options.c   (Revision 141104)
+++ options.c   (Arbeitskopie)
@@ -266,8 +266,6 @@ gfc_post_options (const char **pfilename
       source_path[i] = 0;
       gfc_add_include_path (source_path, true);
     }
-  else
-    gfc_add_include_path (".", true);

   if (canon_source_file != gfc_source_file)
     gfc_free (CONST_CAST (char *, canon_source_file));
Comment 6 Chris Walter 2008-10-14 13:39:52 UTC
Sorry, for leaving out the test case, but I see it is confirmed now.

I can't use the conforming INCLUDE since I am dealing with a large legacy code base and ~150 colleagues who are also using the code with various compilers etc.
Comment 7 Tobias Burnus 2008-10-15 09:29:03 UTC
Patch does not work - the "." causes problems as a "include" (not "#include") does not work anymore: The "." is not included. Still there is the issue about the order "." should be searched before the "-I" paths and it is not needed to be added for "#include" but only for "include".

The latter can be solved by calling in this case in "gfc_add_include_path" only "add_path_to_list (&include_dirs" and not "gfc_cpp_add_include_path" but I fear that also the order for include_dirs has to be changed as well as OPT_I / -I<dir> come before the filename processing in gfc_post_options.
Comment 8 Tobias Burnus 2008-11-03 07:21:51 UTC
Subject: Bug 37821

Author: burnus
Date: Mon Nov  3 07:20:24 2008
New Revision: 141544

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=141544
Log:
2008-11-03  Tobias Burnus  <burnus@net-b.de>

        PR fortran/37821
        * cpp.c (gfc_cpp_add_include_path): Use BRACKET.
        * scanner.c (add_path_to_list): Argument to add at head.
          (gfc_add_include_path): Add new argument.
          (gfc_add_intrinsic_modules_path) Update call.
          (load_file): Print filename/line in the error message.
        * gfortran.h (gfc_add_include_path): Update prototype.
        * options.c (gfc_post_options,gfc_handle_module_path_options,
          gfc_handle_option): Update call.
        * lang-spec.h (F951_OPTIONS): Don't insert include path twice.

        * arith.c (arith_error): Add -fno-range-error to the message.

2008-11-03  Tobias Burnus  <burnus@net-b.de>

        PR fortran/37821
        * gfortran.dg/include_4.f90: New.
        * gfortran.dg/include_5.f90: New.
        * gfortran.dg/include_4.inc: New.


Added:
    trunk/gcc/testsuite/gfortran.dg/include_4.f90
    trunk/gcc/testsuite/gfortran.dg/include_4.inc
    trunk/gcc/testsuite/gfortran.dg/include_5.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/arith.c
    trunk/gcc/fortran/cpp.c
    trunk/gcc/fortran/gfortran.h
    trunk/gcc/fortran/lang-specs.h
    trunk/gcc/fortran/options.c
    trunk/gcc/fortran/scanner.c
    trunk/gcc/testsuite/ChangeLog

Comment 9 Tobias Burnus 2008-11-03 07:35:17 UTC
FIXED on the trunk.

Thanks for the report and sorry that it took that long to commit the fix.