[PATCH] D58743: Handle built-in when importing SourceLocation and FileID
Shafik Yaghmour via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Mar 4 12:26:42 PST 2019
This revision was automatically updated to reflect the committed changes.
Closed by commit rL355332: [ASTImporter] Handle built-in when importing SourceLocation and FileID (authored by shafik, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Changed prior to commit:
https://reviews.llvm.org/D58743?vs=188753&id=189185#toc
Repository:
rL LLVM
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D58743/new/
https://reviews.llvm.org/D58743
Files:
cfe/trunk/include/clang/AST/ASTImporter.h
cfe/trunk/lib/AST/ASTImporter.cpp
Index: cfe/trunk/lib/AST/ASTImporter.cpp
===================================================================
--- cfe/trunk/lib/AST/ASTImporter.cpp
+++ cfe/trunk/lib/AST/ASTImporter.cpp
@@ -8229,9 +8229,10 @@
return {};
SourceManager &FromSM = FromContext.getSourceManager();
+ bool IsBuiltin = FromSM.isWrittenInBuiltinFile(FromLoc);
std::pair<FileID, unsigned> Decomposed = FromSM.getDecomposedLoc(FromLoc);
- FileID ToFileID = Import(Decomposed.first);
+ FileID ToFileID = Import(Decomposed.first, IsBuiltin);
if (ToFileID.isInvalid())
return {};
SourceManager &ToSM = ToContext.getSourceManager();
@@ -8246,13 +8247,13 @@
return SourceRange(Import(FromRange.getBegin()), Import(FromRange.getEnd()));
}
-Expected<FileID> ASTImporter::Import_New(FileID FromID) {
- FileID ToID = Import(FromID);
+Expected<FileID> ASTImporter::Import_New(FileID FromID, bool IsBuiltin) {
+ FileID ToID = Import(FromID, IsBuiltin);
if (ToID.isInvalid() && FromID.isValid())
return llvm::make_error<ImportError>();
return ToID;
}
-FileID ASTImporter::Import(FileID FromID) {
+FileID ASTImporter::Import(FileID FromID, bool IsBuiltin) {
llvm::DenseMap<FileID, FileID>::iterator Pos = ImportedFileIDs.find(FromID);
if (Pos != ImportedFileIDs.end())
return Pos->second;
@@ -8278,25 +8279,29 @@
}
ToID = ToSM.getFileID(MLoc);
} else {
- // Include location of this file.
- SourceLocation ToIncludeLoc = Import(FromSLoc.getFile().getIncludeLoc());
-
const SrcMgr::ContentCache *Cache = FromSLoc.getFile().getContentCache();
- if (Cache->OrigEntry && Cache->OrigEntry->getDir()) {
- // FIXME: We probably want to use getVirtualFile(), so we don't hit the
- // disk again
- // FIXME: We definitely want to re-use the existing MemoryBuffer, rather
- // than mmap the files several times.
- const FileEntry *Entry =
- ToFileManager.getFile(Cache->OrigEntry->getName());
- // FIXME: The filename may be a virtual name that does probably not
- // point to a valid file and we get no Entry here. In this case try with
- // the memory buffer below.
- if (Entry)
- ToID = ToSM.createFileID(Entry, ToIncludeLoc,
- FromSLoc.getFile().getFileCharacteristic());
+
+ if (!IsBuiltin) {
+ // Include location of this file.
+ SourceLocation ToIncludeLoc = Import(FromSLoc.getFile().getIncludeLoc());
+
+ if (Cache->OrigEntry && Cache->OrigEntry->getDir()) {
+ // FIXME: We probably want to use getVirtualFile(), so we don't hit the
+ // disk again
+ // FIXME: We definitely want to re-use the existing MemoryBuffer, rather
+ // than mmap the files several times.
+ const FileEntry *Entry =
+ ToFileManager.getFile(Cache->OrigEntry->getName());
+ // FIXME: The filename may be a virtual name that does probably not
+ // point to a valid file and we get no Entry here. In this case try with
+ // the memory buffer below.
+ if (Entry)
+ ToID = ToSM.createFileID(Entry, ToIncludeLoc,
+ FromSLoc.getFile().getFileCharacteristic());
+ }
}
- if (ToID.isInvalid()) {
+
+ if (ToID.isInvalid() || IsBuiltin) {
// FIXME: We want to re-use the existing MemoryBuffer!
bool Invalid = true;
const llvm::MemoryBuffer *FromBuf = Cache->getBuffer(
Index: cfe/trunk/include/clang/AST/ASTImporter.h
===================================================================
--- cfe/trunk/include/clang/AST/ASTImporter.h
+++ cfe/trunk/include/clang/AST/ASTImporter.h
@@ -337,9 +337,9 @@
///
/// \returns The equivalent file ID in the source manager of the "to"
/// context, or the import error.
- llvm::Expected<FileID> Import_New(FileID);
+ llvm::Expected<FileID> Import_New(FileID, bool IsBuiltin = false);
// FIXME: Remove this version.
- FileID Import(FileID);
+ FileID Import(FileID, bool IsBuiltin = false);
/// Import the given C++ constructor initializer from the "from"
/// context into the "to" context.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D58743.189185.patch
Type: text/x-patch
Size: 4141 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190304/6aaee142/attachment.bin>
More information about the cfe-commits
mailing list