aboutsummaryrefslogtreecommitdiff
path: root/Lex/HeaderSearch.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Lex/HeaderSearch.cpp')
-rw-r--r--Lex/HeaderSearch.cpp34
1 files changed, 32 insertions, 2 deletions
diff --git a/Lex/HeaderSearch.cpp b/Lex/HeaderSearch.cpp
index bd36f35d49..899c9d87a9 100644
--- a/Lex/HeaderSearch.cpp
+++ b/Lex/HeaderSearch.cpp
@@ -228,7 +228,22 @@ const FileEntry *HeaderSearch::LookupFile(const char *FilenameStart,
if (const FileEntry *FE = FileMgr.getFile(TmpDir.begin(), TmpDir.end())) {
// Leave CurDir unset.
// This file is a system header or C++ unfriendly if the old file is.
- getFileInfo(FE).DirInfo = getFileInfo(CurFileEnt).DirInfo;
+
+ // Note: Don't use:
+ //
+ // getFileInfo(FE).DirInfo = getFileInfo(CurFileEnt).DirInfo;
+ //
+ // MSVC, behind the scenes, does this:
+ //
+ // PerFileInfo &pf1 = getFileInfo(CurFileEnt);
+ // PerFileInfo &pf2 = getFileInfo(FE);
+ // pf2.DirInfo = pf1.DirInfo
+ //
+ // The problem is that if there's a resize() of the FileInfo vector during
+ // the getFileInfo(FE) call, pf1 will point to invalid data. To fix
+ // this problem, make the assignment through a temporary.
+ unsigned int tmp = getFileInfo(CurFileEnt).DirInfo;
+ getFileInfo(FE).DirInfo = tmp;
return FE;
}
}
@@ -357,7 +372,22 @@ LookupSubframeworkHeader(const char *FilenameStart,
}
// This file is a system header or C++ unfriendly if the old file is.
- getFileInfo(FE).DirInfo = getFileInfo(ContextFileEnt).DirInfo;
+
+ // Note: Don't use:
+ //
+ // getFileInfo(FE).DirInfo = getFileInfo(ContextFileEnt).DirInfo;
+ //
+ // MSVC, behind the scenes, does this:
+ //
+ // PerFileInfo &pf1 = getFileInfo(ContextFileEnt);
+ // PerFileInfo &pf2 = getFileInfo(FE);
+ // pf2.DirInfo = pf1.DirInfo
+ //
+ // The problem is that if there's a resize() of the FileInfo vector during
+ // the getFileInfo(FE) call, pf1 will point to invalid data. The solution
+ // is to make the assignment through a temporary.
+ unsigned int tmp = getFileInfo(ContextFileEnt).DirInfo;
+ getFileInfo(FE).DirInfo = tmp;
return FE;
}