forked from OSchip/llvm-project
Revert r110440, the fix for PR4897. Chris claims to have a better way.
llvm-svn: 110544
This commit is contained in:
parent
bb10e90487
commit
618e64a23b
|
@ -16,7 +16,6 @@
|
|||
|
||||
#include "clang/Lex/DirectoryLookup.h"
|
||||
#include "llvm/ADT/StringMap.h"
|
||||
#include "llvm/System/Path.h"
|
||||
#include <vector>
|
||||
|
||||
namespace clang {
|
||||
|
@ -145,16 +144,16 @@ public:
|
|||
|
||||
/// LookupFile - Given a "foo" or <foo> reference, look up the indicated file,
|
||||
/// return null on failure. isAngled indicates whether the file reference is
|
||||
/// a <> reference. If successful, this returns 'CurDir', the
|
||||
/// a <> reference. If successful, this returns 'UsedDir', the
|
||||
/// DirectoryLookup member the file was found in, or null if not applicable.
|
||||
/// If CurDir is non-null, the file was found in the specified directory
|
||||
/// search location. This is used to implement #include_next. RelSearchPath,
|
||||
/// if non-empty, indicates where the #including file is, in case a relative
|
||||
/// search location. This is used to implement #include_next. CurFileEnt, if
|
||||
/// non-null, indicates where the #including file is, in case a relative
|
||||
/// search is needed.
|
||||
const FileEntry *LookupFile(llvm::StringRef Filename, bool isAngled,
|
||||
const DirectoryLookup *FromDir,
|
||||
const DirectoryLookup *&CurDir,
|
||||
const llvm::sys::Path &RelSearchPath);
|
||||
const FileEntry *CurFileEnt);
|
||||
|
||||
/// LookupSubframeworkHeader - Look up a subframework for the specified
|
||||
/// #include file. For example, if #include'ing <HIToolbox/HIToolbox.h> from
|
||||
|
|
|
@ -203,14 +203,14 @@ const FileEntry *DirectoryLookup::DoFrameworkLookup(llvm::StringRef Filename,
|
|||
|
||||
/// LookupFile - Given a "foo" or <foo> reference, look up the indicated file,
|
||||
/// return null on failure. isAngled indicates whether the file reference is
|
||||
/// for system #include's or not (i.e. using <> instead of ""). RelSearchDir,
|
||||
/// if non-empty, indicates where the #including file is, in case a relative
|
||||
/// search is needed.
|
||||
/// for system #include's or not (i.e. using <> instead of ""). CurFileEnt, if
|
||||
/// non-null, indicates where the #including file is, in case a relative search
|
||||
/// is needed.
|
||||
const FileEntry *HeaderSearch::LookupFile(llvm::StringRef Filename,
|
||||
bool isAngled,
|
||||
const DirectoryLookup *FromDir,
|
||||
const DirectoryLookup *&CurDir,
|
||||
const llvm::sys::Path &RelPath) {
|
||||
const FileEntry *CurFileEnt) {
|
||||
// If 'Filename' is absolute, check to see if it exists and no searching.
|
||||
if (llvm::sys::Path::isAbsolute(Filename.begin(), Filename.size())) {
|
||||
CurDir = 0;
|
||||
|
@ -223,29 +223,25 @@ const FileEntry *HeaderSearch::LookupFile(llvm::StringRef Filename,
|
|||
}
|
||||
|
||||
// Step #0, unless disabled, check to see if the file is in the #includer's
|
||||
// directory. This has to be based on RelPath, not CurDir, because
|
||||
// RelPath could be a #include of a subdirectory (#include "foo/bar.h") and
|
||||
// directory. This has to be based on CurFileEnt, not CurDir, because
|
||||
// CurFileEnt could be a #include of a subdirectory (#include "foo/bar.h") and
|
||||
// a subsequent include of "baz.h" should resolve to "whatever/foo/baz.h".
|
||||
// This search is not done for <> headers.
|
||||
if (!RelPath.isEmpty() && !isAngled && !NoCurDirSearch) {
|
||||
|
||||
// Default SrcMgr::CharacteristicKind
|
||||
unsigned DirInfo = SrcMgr::C_User;
|
||||
llvm::sys::Path TmpPath(RelPath);
|
||||
|
||||
// Update DirInfo if needed and remove filename from path if
|
||||
// treating actual file (the non-stdin case)
|
||||
if (!TmpPath.isDirectory()) {
|
||||
const FileEntry *MainFile = FileMgr.getFile(TmpPath.c_str());
|
||||
DirInfo = getFileInfo(MainFile).DirInfo;
|
||||
TmpPath.eraseComponent();
|
||||
}
|
||||
|
||||
// Formulate path to try
|
||||
TmpPath.appendComponent(Filename);
|
||||
llvm::StringRef RelSearchFilename(TmpPath.c_str());
|
||||
if (const FileEntry *FE = FileMgr.getFile(RelSearchFilename)) {
|
||||
if (CurFileEnt && !isAngled && !NoCurDirSearch) {
|
||||
llvm::SmallString<1024> TmpDir;
|
||||
// Concatenate the requested file onto the directory.
|
||||
// FIXME: Portability. Filename concatenation should be in sys::Path.
|
||||
TmpDir += CurFileEnt->getDir()->getName();
|
||||
TmpDir.push_back('/');
|
||||
TmpDir.append(Filename.begin(), Filename.end());
|
||||
if (const FileEntry *FE = FileMgr.getFile(TmpDir.str())) {
|
||||
// Leave CurDir unset.
|
||||
// This file is a system header or C++ unfriendly if the old file is.
|
||||
//
|
||||
// Note that the temporary 'DirInfo' is required here, as either call to
|
||||
// getFileInfo could resize the vector and we don't want to rely on order
|
||||
// of evaluation.
|
||||
unsigned DirInfo = getFileInfo(CurFileEnt).DirInfo;
|
||||
getFileInfo(FE).DirInfo = DirInfo;
|
||||
return FE;
|
||||
}
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
#include "clang/Basic/FileManager.h"
|
||||
#include "clang/Basic/SourceManager.h"
|
||||
#include "llvm/ADT/APInt.h"
|
||||
#include "llvm/System/Path.h"
|
||||
using namespace clang;
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
@ -417,49 +416,33 @@ const FileEntry *Preprocessor::LookupFile(llvm::StringRef Filename,
|
|||
const DirectoryLookup *&CurDir) {
|
||||
// If the header lookup mechanism may be relative to the current file, pass in
|
||||
// info about where the current file is.
|
||||
llvm::sys::Path RelSearchPath;
|
||||
|
||||
const FileEntry *CurFileEnt = 0;
|
||||
if (!FromDir) {
|
||||
FileID FID = getCurrentFileLexer()->getFileID();
|
||||
const FileEntry *CurFileEnt = SourceMgr.getFileEntryForID(FID);
|
||||
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. When the main file is actually stdin, resolve references
|
||||
// as if they came from the current working directory.
|
||||
if (CurFileEnt) {
|
||||
if (!RelSearchPath.set(CurFileEnt->getDir()->getName())) {
|
||||
assert("Main file somehow invalid path?");
|
||||
}
|
||||
} else {
|
||||
// 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);
|
||||
|
||||
if (CurFileEnt) {
|
||||
// 'main file' case
|
||||
RelSearchPath.set(CurFileEnt->getDir()->getName());
|
||||
} else {
|
||||
// stdin case
|
||||
RelSearchPath = llvm::sys::Path::GetCurrentDirectory();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Do a standard file entry lookup.
|
||||
CurDir = CurDirLookup;
|
||||
const FileEntry *FE =
|
||||
HeaderInfo.LookupFile(Filename, isAngled, FromDir, CurDir, RelSearchPath);
|
||||
HeaderInfo.LookupFile(Filename, isAngled, FromDir, CurDir, CurFileEnt);
|
||||
if (FE) return FE;
|
||||
|
||||
// Otherwise, see if this is a subframework header. If so, this is relative
|
||||
// to one of the headers on the #include stack. Walk the list of the current
|
||||
// headers on the #include stack and pass them to HeaderInfo.
|
||||
if (IsFileLexer()) {
|
||||
const FileEntry *CurFileEnt = 0;
|
||||
if ((CurFileEnt = SourceMgr.getFileEntryForID(CurPPLexer->getFileID())))
|
||||
if ((FE = HeaderInfo.LookupSubframeworkHeader(Filename, CurFileEnt)))
|
||||
return FE;
|
||||
|
@ -468,7 +451,6 @@ const FileEntry *Preprocessor::LookupFile(llvm::StringRef Filename,
|
|||
for (unsigned i = 0, e = IncludeMacroStack.size(); i != e; ++i) {
|
||||
IncludeStackInfo &ISEntry = IncludeMacroStack[e-i-1];
|
||||
if (IsFileLexer(ISEntry)) {
|
||||
const FileEntry *CurFileEnt = 0;
|
||||
if ((CurFileEnt =
|
||||
SourceMgr.getFileEntryForID(ISEntry.ThePPLexer->getFileID())))
|
||||
if ((FE = HeaderInfo.LookupSubframeworkHeader(Filename, CurFileEnt)))
|
||||
|
|
|
@ -1,11 +0,0 @@
|
|||
// RUN: cd %S && %clang_cc1 -E - < stdin2.c
|
||||
|
||||
/*
|
||||
* Bug 4897; current working directory should be searched
|
||||
* for #includes when input is stdin.
|
||||
*/
|
||||
|
||||
#ifndef BUG_4897
|
||||
#define BUG_4897
|
||||
#include "stdin2.c"
|
||||
#endif
|
Loading…
Reference in New Issue