Skip to content

Commit 3741cb3

Browse files
committed
make include filename as absolute path
1 parent c5e07fb commit 3741cb3

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

llvm/lib/Support/SourceMgr.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "llvm/ADT/StringRef.h"
2121
#include "llvm/ADT/Twine.h"
2222
#include "llvm/Support/ErrorOr.h"
23+
#include "llvm/Support/FileSystem.h"
2324
#include "llvm/Support/Locale.h"
2425
#include "llvm/Support/MemoryBuffer.h"
2526
#include "llvm/Support/Path.h"
@@ -52,15 +53,18 @@ unsigned SourceMgr::AddIncludeFile(const std::string &Filename,
5253
ErrorOr<std::unique_ptr<MemoryBuffer>>
5354
SourceMgr::OpenIncludeFile(const std::string &Filename,
5455
std::string &IncludedFile) {
56+
SmallString<128> Path{Filename};
57+
sys::fs::make_absolute(Path);
5558
ErrorOr<std::unique_ptr<MemoryBuffer>> NewBufOrErr =
56-
MemoryBuffer::getFile(Filename);
59+
MemoryBuffer::getFile(Path);
5760

58-
SmallString<64> Buffer(Filename);
61+
SmallString<64> Buffer(Path);
5962
// If the file didn't exist directly, see if it's in an include path.
6063
for (unsigned i = 0, e = IncludeDirectories.size(); i != e && !NewBufOrErr;
6164
++i) {
6265
Buffer = IncludeDirectories[i];
6366
sys::path::append(Buffer, Filename);
67+
sys::fs::make_absolute(Buffer);
6468
NewBufOrErr = MemoryBuffer::getFile(Buffer);
6569
}
6670

0 commit comments

Comments
 (0)