зеркало из https://github.com/microsoft/clang-1.git
Tweak PCH -include handling to make sure it matches the name as would be present
in the predefines buffer. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@86903 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Родитель
6a6742a8fc
Коммит
c7162937a4
|
@ -14,6 +14,7 @@
|
||||||
#ifndef LLVM_CLANG_FRONTEND_UTILS_H
|
#ifndef LLVM_CLANG_FRONTEND_UTILS_H
|
||||||
#define LLVM_CLANG_FRONTEND_UTILS_H
|
#define LLVM_CLANG_FRONTEND_UTILS_H
|
||||||
|
|
||||||
|
#include "llvm/ADT/StringRef.h"
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
@ -40,6 +41,10 @@ class SourceManager;
|
||||||
class Stmt;
|
class Stmt;
|
||||||
class TargetInfo;
|
class TargetInfo;
|
||||||
|
|
||||||
|
/// Normalize \arg File for use in a user defined #include directive (in the
|
||||||
|
/// predefines buffer).
|
||||||
|
std::string NormalizeDashIncludePath(llvm::StringRef File);
|
||||||
|
|
||||||
/// 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,
|
||||||
const HeaderSearchOptions &HSOpts,
|
const HeaderSearchOptions &HSOpts,
|
||||||
|
|
|
@ -61,9 +61,7 @@ static void UndefineBuiltinMacro(std::vector<char> &Buf, const char *Macro) {
|
||||||
Buf.push_back('\n');
|
Buf.push_back('\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Add the quoted name of an implicit include file.
|
std::string clang::NormalizeDashIncludePath(llvm::StringRef File) {
|
||||||
static void AddQuotedIncludePath(std::vector<char> &Buf,
|
|
||||||
const std::string &File) {
|
|
||||||
// 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
|
||||||
|
@ -76,9 +74,16 @@ static void AddQuotedIncludePath(std::vector<char> &Buf,
|
||||||
if (!Path.exists())
|
if (!Path.exists())
|
||||||
Path = File;
|
Path = File;
|
||||||
|
|
||||||
|
return Lexer::Stringify(Path.str());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Add the quoted name of an implicit include file.
|
||||||
|
static void AddQuotedIncludePath(std::vector<char> &Buf,
|
||||||
|
const std::string &File) {
|
||||||
|
|
||||||
// Escape double quotes etc.
|
// Escape double quotes etc.
|
||||||
Buf.push_back('"');
|
Buf.push_back('"');
|
||||||
std::string EscapedFile = Lexer::Stringify(Path.str());
|
std::string EscapedFile = NormalizeDashIncludePath(File);
|
||||||
Buf.insert(Buf.end(), EscapedFile.begin(), EscapedFile.end());
|
Buf.insert(Buf.end(), EscapedFile.begin(), EscapedFile.end());
|
||||||
Buf.push_back('"');
|
Buf.push_back('"');
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
|
|
||||||
#include "clang/Frontend/PCHReader.h"
|
#include "clang/Frontend/PCHReader.h"
|
||||||
#include "clang/Frontend/FrontendDiagnostic.h"
|
#include "clang/Frontend/FrontendDiagnostic.h"
|
||||||
|
#include "clang/Frontend/Utils.h"
|
||||||
#include "../Sema/Sema.h" // FIXME: move Sema headers elsewhere
|
#include "../Sema/Sema.h" // FIXME: move Sema headers elsewhere
|
||||||
#include "clang/AST/ASTConsumer.h"
|
#include "clang/AST/ASTConsumer.h"
|
||||||
#include "clang/AST/ASTContext.h"
|
#include "clang/AST/ASTContext.h"
|
||||||
|
@ -158,12 +159,13 @@ bool PCHValidator::ReadPredefinesBuffer(llvm::StringRef PCHPredef,
|
||||||
FileID PCHBufferID,
|
FileID PCHBufferID,
|
||||||
llvm::StringRef OriginalFileName,
|
llvm::StringRef OriginalFileName,
|
||||||
std::string &SuggestedPredefines) {
|
std::string &SuggestedPredefines) {
|
||||||
// We are in the context of an implicit include, so the predefines buffer
|
// We are in the context of an implicit include, so the predefines buffer will
|
||||||
// will have a #include entry for the PCH file itself. Find it and skip over
|
// have a #include entry for the PCH file itself (as normalized by the
|
||||||
// it in the checking below.
|
// preprocessor initialization). Find it and skip over it in the checking
|
||||||
|
// below.
|
||||||
llvm::SmallString<256> PCHInclude;
|
llvm::SmallString<256> PCHInclude;
|
||||||
PCHInclude += "#include \"";
|
PCHInclude += "#include \"";
|
||||||
PCHInclude += OriginalFileName;
|
PCHInclude += NormalizeDashIncludePath(OriginalFileName);
|
||||||
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());
|
||||||
|
|
Загрузка…
Ссылка в новой задаче