зеркало из https://github.com/microsoft/clang-1.git
Preserve what the user passed to -include when emitting .d files. Fixes PR8974!
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@126334 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Родитель
af5800a1e2
Коммит
277a6e7525
|
@ -28,6 +28,7 @@ class Decl;
|
||||||
class DependencyOutputOptions;
|
class DependencyOutputOptions;
|
||||||
class Diagnostic;
|
class Diagnostic;
|
||||||
class DiagnosticOptions;
|
class DiagnosticOptions;
|
||||||
|
class FileManager;
|
||||||
class HeaderSearch;
|
class HeaderSearch;
|
||||||
class HeaderSearchOptions;
|
class HeaderSearchOptions;
|
||||||
class IdentifierTable;
|
class IdentifierTable;
|
||||||
|
@ -42,7 +43,8 @@ class FrontendOptions;
|
||||||
|
|
||||||
/// Normalize \arg File for use in a user defined #include directive (in the
|
/// Normalize \arg File for use in a user defined #include directive (in the
|
||||||
/// predefines buffer).
|
/// predefines buffer).
|
||||||
std::string NormalizeDashIncludePath(llvm::StringRef File);
|
std::string NormalizeDashIncludePath(llvm::StringRef File,
|
||||||
|
FileManager &FileMgr);
|
||||||
|
|
||||||
/// Apply the header search options to get given HeaderSearch object.
|
/// Apply the header search options to get given HeaderSearch object.
|
||||||
void ApplyHeaderSearchOptions(HeaderSearch &HS,
|
void ApplyHeaderSearchOptions(HeaderSearch &HS,
|
||||||
|
|
|
@ -116,7 +116,8 @@ public:
|
||||||
/// \returns true to indicate the predefines are invalid or false otherwise.
|
/// \returns true to indicate the predefines are invalid or false otherwise.
|
||||||
virtual bool ReadPredefinesBuffer(const PCHPredefinesBlocks &Buffers,
|
virtual bool ReadPredefinesBuffer(const PCHPredefinesBlocks &Buffers,
|
||||||
llvm::StringRef OriginalFileName,
|
llvm::StringRef OriginalFileName,
|
||||||
std::string &SuggestedPredefines) {
|
std::string &SuggestedPredefines,
|
||||||
|
FileManager &FileMgr) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -143,7 +144,8 @@ public:
|
||||||
virtual bool ReadTargetTriple(llvm::StringRef Triple);
|
virtual bool ReadTargetTriple(llvm::StringRef Triple);
|
||||||
virtual bool ReadPredefinesBuffer(const PCHPredefinesBlocks &Buffers,
|
virtual bool ReadPredefinesBuffer(const PCHPredefinesBlocks &Buffers,
|
||||||
llvm::StringRef OriginalFileName,
|
llvm::StringRef OriginalFileName,
|
||||||
std::string &SuggestedPredefines);
|
std::string &SuggestedPredefines,
|
||||||
|
FileManager &FileMgr);
|
||||||
virtual void ReadHeaderFileInfo(const HeaderFileInfo &HFI, unsigned ID);
|
virtual void ReadHeaderFileInfo(const HeaderFileInfo &HFI, unsigned ID);
|
||||||
virtual void ReadCounter(unsigned Value);
|
virtual void ReadCounter(unsigned Value);
|
||||||
|
|
||||||
|
|
|
@ -389,7 +389,8 @@ public:
|
||||||
|
|
||||||
virtual bool ReadPredefinesBuffer(const PCHPredefinesBlocks &Buffers,
|
virtual bool ReadPredefinesBuffer(const PCHPredefinesBlocks &Buffers,
|
||||||
llvm::StringRef OriginalFileName,
|
llvm::StringRef OriginalFileName,
|
||||||
std::string &SuggestedPredefines) {
|
std::string &SuggestedPredefines,
|
||||||
|
FileManager &FileMgr) {
|
||||||
Predefines = Buffers[0].Data;
|
Predefines = Buffers[0].Data;
|
||||||
for (unsigned I = 1, N = Buffers.size(); I != N; ++I) {
|
for (unsigned I = 1, N = Buffers.size(); I != N; ++I) {
|
||||||
Predefines += Buffers[I].Data;
|
Predefines += Buffers[I].Data;
|
||||||
|
|
|
@ -48,12 +48,13 @@ static void DefineBuiltinMacro(MacroBuilder &Builder, llvm::StringRef Macro,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string clang::NormalizeDashIncludePath(llvm::StringRef File) {
|
std::string clang::NormalizeDashIncludePath(llvm::StringRef File,
|
||||||
|
FileManager &FileMgr) {
|
||||||
// Implicit include paths should be resolved relative to the current
|
// Implicit include paths should be resolved relative to the current
|
||||||
// working directory first, and then use the regular header search
|
// working directory first, and then use the regular header search
|
||||||
// mechanism. The proper way to handle this is to have the
|
// mechanism. The proper way to handle this is to have the
|
||||||
// predefines buffer located at the current working directory, but
|
// predefines buffer located at the current working directory, but
|
||||||
// it has not file entry. For now, workaround this by using an
|
// it has no file entry. For now, workaround this by using an
|
||||||
// absolute path if we find the file here, and otherwise letting
|
// absolute path if we find the file here, and otherwise letting
|
||||||
// header search handle it.
|
// header search handle it.
|
||||||
llvm::SmallString<128> Path(File);
|
llvm::SmallString<128> Path(File);
|
||||||
|
@ -61,21 +62,25 @@ std::string clang::NormalizeDashIncludePath(llvm::StringRef File) {
|
||||||
bool exists;
|
bool exists;
|
||||||
if (llvm::sys::fs::exists(Path.str(), exists) || !exists)
|
if (llvm::sys::fs::exists(Path.str(), exists) || !exists)
|
||||||
Path = File;
|
Path = File;
|
||||||
|
else if (exists)
|
||||||
|
FileMgr.getFile(File);
|
||||||
|
|
||||||
return Lexer::Stringify(Path.str());
|
return Lexer::Stringify(Path.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// AddImplicitInclude - Add an implicit #include of the specified file to the
|
/// AddImplicitInclude - Add an implicit #include of the specified file to the
|
||||||
/// predefines buffer.
|
/// predefines buffer.
|
||||||
static void AddImplicitInclude(MacroBuilder &Builder, llvm::StringRef File) {
|
static void AddImplicitInclude(MacroBuilder &Builder, llvm::StringRef File,
|
||||||
|
FileManager &FileMgr) {
|
||||||
Builder.append("#include \"" +
|
Builder.append("#include \"" +
|
||||||
llvm::Twine(NormalizeDashIncludePath(File)) + "\"");
|
llvm::Twine(NormalizeDashIncludePath(File, FileMgr)) + "\"");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void AddImplicitIncludeMacros(MacroBuilder &Builder,
|
static void AddImplicitIncludeMacros(MacroBuilder &Builder,
|
||||||
llvm::StringRef File) {
|
llvm::StringRef File,
|
||||||
|
FileManager &FileMgr) {
|
||||||
Builder.append("#__include_macros \"" +
|
Builder.append("#__include_macros \"" +
|
||||||
llvm::Twine(NormalizeDashIncludePath(File)) + "\"");
|
llvm::Twine(NormalizeDashIncludePath(File, FileMgr)) + "\"");
|
||||||
// Marker token to stop the __include_macros fetch loop.
|
// Marker token to stop the __include_macros fetch loop.
|
||||||
Builder.append("##"); // ##?
|
Builder.append("##"); // ##?
|
||||||
}
|
}
|
||||||
|
@ -94,7 +99,7 @@ static void AddImplicitIncludePTH(MacroBuilder &Builder, Preprocessor &PP,
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
AddImplicitInclude(Builder, OriginalFile);
|
AddImplicitInclude(Builder, OriginalFile, PP.getFileManager());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// PickFP - This is used to pick a value based on the FP semantics of the
|
/// PickFP - This is used to pick a value based on the FP semantics of the
|
||||||
|
@ -590,7 +595,8 @@ void clang::InitializePreprocessor(Preprocessor &PP,
|
||||||
// If -imacros are specified, include them now. These are processed before
|
// If -imacros are specified, include them now. These are processed before
|
||||||
// any -include directives.
|
// any -include directives.
|
||||||
for (unsigned i = 0, e = InitOpts.MacroIncludes.size(); i != e; ++i)
|
for (unsigned i = 0, e = InitOpts.MacroIncludes.size(); i != e; ++i)
|
||||||
AddImplicitIncludeMacros(Builder, InitOpts.MacroIncludes[i]);
|
AddImplicitIncludeMacros(Builder, InitOpts.MacroIncludes[i],
|
||||||
|
PP.getFileManager());
|
||||||
|
|
||||||
// Process -include directives.
|
// Process -include directives.
|
||||||
for (unsigned i = 0, e = InitOpts.Includes.size(); i != e; ++i) {
|
for (unsigned i = 0, e = InitOpts.Includes.size(); i != e; ++i) {
|
||||||
|
@ -598,7 +604,7 @@ void clang::InitializePreprocessor(Preprocessor &PP,
|
||||||
if (Path == InitOpts.ImplicitPTHInclude)
|
if (Path == InitOpts.ImplicitPTHInclude)
|
||||||
AddImplicitIncludePTH(Builder, PP, Path);
|
AddImplicitIncludePTH(Builder, PP, Path);
|
||||||
else
|
else
|
||||||
AddImplicitInclude(Builder, Path);
|
AddImplicitInclude(Builder, Path, PP.getFileManager());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Exit the command line and go back to <built-in> (2 is LC_LEAVE).
|
// Exit the command line and go back to <built-in> (2 is LC_LEAVE).
|
||||||
|
|
|
@ -244,14 +244,15 @@ FindMacro(const PCHPredefinesBlocks &Buffers, llvm::StringRef MacroDef) {
|
||||||
|
|
||||||
bool PCHValidator::ReadPredefinesBuffer(const PCHPredefinesBlocks &Buffers,
|
bool PCHValidator::ReadPredefinesBuffer(const PCHPredefinesBlocks &Buffers,
|
||||||
llvm::StringRef OriginalFileName,
|
llvm::StringRef OriginalFileName,
|
||||||
std::string &SuggestedPredefines) {
|
std::string &SuggestedPredefines,
|
||||||
|
FileManager &FileMgr) {
|
||||||
// We are in the context of an implicit include, so the predefines buffer will
|
// We are in the context of an implicit include, so the predefines buffer will
|
||||||
// have a #include entry for the PCH file itself (as normalized by the
|
// have a #include entry for the PCH file itself (as normalized by the
|
||||||
// preprocessor initialization). Find it and skip over it in the checking
|
// preprocessor initialization). Find it and skip over it in the checking
|
||||||
// below.
|
// below.
|
||||||
llvm::SmallString<256> PCHInclude;
|
llvm::SmallString<256> PCHInclude;
|
||||||
PCHInclude += "#include \"";
|
PCHInclude += "#include \"";
|
||||||
PCHInclude += NormalizeDashIncludePath(OriginalFileName);
|
PCHInclude += NormalizeDashIncludePath(OriginalFileName, FileMgr);
|
||||||
PCHInclude += "\"\n";
|
PCHInclude += "\"\n";
|
||||||
std::pair<llvm::StringRef,llvm::StringRef> Split =
|
std::pair<llvm::StringRef,llvm::StringRef> Split =
|
||||||
llvm::StringRef(PP.getPredefines()).split(PCHInclude.str());
|
llvm::StringRef(PP.getPredefines()).split(PCHInclude.str());
|
||||||
|
@ -961,7 +962,8 @@ bool ASTReader::CheckPredefinesBuffers() {
|
||||||
if (Listener)
|
if (Listener)
|
||||||
return Listener->ReadPredefinesBuffer(PCHPredefinesBuffers,
|
return Listener->ReadPredefinesBuffer(PCHPredefinesBuffers,
|
||||||
ActualOriginalFileName,
|
ActualOriginalFileName,
|
||||||
SuggestedPredefines);
|
SuggestedPredefines,
|
||||||
|
FileMgr);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4934,4 +4936,3 @@ ASTReader::PerFileData::~PerFileData() {
|
||||||
delete static_cast<HeaderFileInfoLookupTable *>(HeaderFileInfoTable);
|
delete static_cast<HeaderFileInfoLookupTable *>(HeaderFileInfoTable);
|
||||||
delete static_cast<ASTSelectorLookupTable *>(SelectorLookupTable);
|
delete static_cast<ASTSelectorLookupTable *>(SelectorLookupTable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,3 +6,10 @@
|
||||||
// RUN: %clang -S -M -x c %s -o %t.d
|
// RUN: %clang -S -M -x c %s -o %t.d
|
||||||
// RUN: grep '.*dependency-gen.*:' %t.d
|
// RUN: grep '.*dependency-gen.*:' %t.d
|
||||||
// RUN: grep 'dependency-gen.c' %t.d
|
// RUN: grep 'dependency-gen.c' %t.d
|
||||||
|
|
||||||
|
// PR8974
|
||||||
|
// RUN: mkdir %t.dir
|
||||||
|
// RUN: echo > %t.dir/x.h
|
||||||
|
// RUN: %clang -include %t.dir/x.h -MD -MF %t.d -S -x c -o %t.o %s
|
||||||
|
// RUN: grep ' %t.dir/x.h' %t.d
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче