[cfe-commits] r63764 - in /cfe/trunk: lib/Lex/PPDirectives.cpp test/Preprocessor/include-directive1.c test/Preprocessor/include-directive3.c

Daniel Dunbar daniel at zuster.org
Wed Feb 4 13:06:13 PST 2009


I don't think this is correct; I believe the -include searches
relative to the current working directory, not the main file.
--
ddunbar at milton:tmp$ mkdir x
ddunbar at milton:tmp$ touch x/a.h
ddunbar at milton:tmp$ mkdir y
ddunbar at milton:tmp$ touch y/a.c
ddunbar at milton:tmp$ gcc -fsyntax-only -include x/a.h y/a.c
ddunbar at milton:tmp$ clang -fsyntax-only -include x/a.h y/a.c
<predefines>:90:10: error: 'x/a.h' file not found
#include "x/a.h"
         ^
1 diagnostic generated.
--

Would it be terrible to give the predefines buffer a file entry, with
the path being the current working directory? This would also allow
things in the predefines buffer to have a valid source location...

 - Daniel

On Wed, Feb 4, 2009 at 11:45 AM, Chris Lattner <sabre at nondot.org> wrote:
> Author: lattner
> Date: Wed Feb  4 13:45:07 2009
> New Revision: 63764
>
> URL: http://llvm.org/viewvc/llvm-project?rev=63764&view=rev
> Log:
> Fix PR3464 by searching for headers from the predefines
> buffer as if the #include happened from the main file.
>
> Added:
>    cfe/trunk/test/Preprocessor/include-directive3.c
> Modified:
>    cfe/trunk/lib/Lex/PPDirectives.cpp
>    cfe/trunk/test/Preprocessor/include-directive1.c
>
> Modified: cfe/trunk/lib/Lex/PPDirectives.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPDirectives.cpp?rev=63764&r1=63763&r2=63764&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/Lex/PPDirectives.cpp (original)
> +++ cfe/trunk/lib/Lex/PPDirectives.cpp Wed Feb  4 13:45:07 2009
> @@ -399,13 +399,24 @@
>   if (!FromDir) {
>     FileID FID = getCurrentFileLexer()->getFileID();
>     CurFileEnt = SourceMgr.getFileEntryForID(FID);
> +
> +    // If there is no file entry associated with this file, it must be the
> +    // predefines buffer.  Any other file is not lexed with a normal lexer, so
> +    // it won't be scanned for preprocessor directives.   If we have the
> +    // predefines buffer, resolve #include references (which come from the
> +    // -include command line argument) as if they came from the main file, this
> +    // affects file lookup etc.
> +    if (CurFileEnt == 0) {
> +      FID = SourceMgr.getMainFileID();
> +      CurFileEnt = SourceMgr.getFileEntryForID(FID);
> +    }
>   }
>
>   // Do a standard file entry lookup.
>   CurDir = CurDirLookup;
>   const FileEntry *FE =
> -  HeaderInfo.LookupFile(FilenameStart, FilenameEnd,
> -                        isAngled, FromDir, CurDir, CurFileEnt);
> +    HeaderInfo.LookupFile(FilenameStart, FilenameEnd,
> +                          isAngled, FromDir, CurDir, CurFileEnt);
>   if (FE) return FE;
>
>   // Otherwise, see if this is a subframework header.  If so, this is relative
>
> Modified: cfe/trunk/test/Preprocessor/include-directive1.c
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/include-directive1.c?rev=63764&r1=63763&r2=63764&view=diff
>
> ==============================================================================
> --- cfe/trunk/test/Preprocessor/include-directive1.c (original)
> +++ cfe/trunk/test/Preprocessor/include-directive1.c Wed Feb  4 13:45:07 2009
> @@ -1,4 +1,3 @@
> -
>  // RUN: clang -E %s -fno-caret-diagnostics 2>&1 >/dev/null | grep 'file successfully included' | count 3
>
>  // XX expands to nothing.
> @@ -13,7 +12,3 @@
>  // normal include
>  #include "file_to_include.h"
>
> -// Expand and paste angled strings.
> -#  define HEADER <file_to_include.h>
> -#  include HEADER
> -
>
> Added: cfe/trunk/test/Preprocessor/include-directive3.c
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/include-directive3.c?rev=63764&view=auto
>
> ==============================================================================
> --- cfe/trunk/test/Preprocessor/include-directive3.c (added)
> +++ cfe/trunk/test/Preprocessor/include-directive3.c Wed Feb  4 13:45:07 2009
> @@ -0,0 +1,3 @@
> +// RUN: clang -include file_to_include.h -E %s -fno-caret-diagnostics 2>&1 >/dev/null | grep 'file successfully included' | count 1
> +// PR3464
> +
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>



More information about the cfe-commits mailing list