From 3741cb3136eda2a677c64e17869f370c207811a6 Mon Sep 17 00:00:00 2001 From: tcwzxx Date: Tue, 22 Apr 2025 19:09:19 +0800 Subject: [PATCH] make include filename as absolute path --- llvm/lib/Support/SourceMgr.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/llvm/lib/Support/SourceMgr.cpp b/llvm/lib/Support/SourceMgr.cpp index 3f97213d86c05..1a6389737c1fb 100644 --- a/llvm/lib/Support/SourceMgr.cpp +++ b/llvm/lib/Support/SourceMgr.cpp @@ -20,6 +20,7 @@ #include "llvm/ADT/StringRef.h" #include "llvm/ADT/Twine.h" #include "llvm/Support/ErrorOr.h" +#include "llvm/Support/FileSystem.h" #include "llvm/Support/Locale.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/Path.h" @@ -52,15 +53,18 @@ unsigned SourceMgr::AddIncludeFile(const std::string &Filename, ErrorOr> SourceMgr::OpenIncludeFile(const std::string &Filename, std::string &IncludedFile) { + SmallString<128> Path{Filename}; + sys::fs::make_absolute(Path); ErrorOr> NewBufOrErr = - MemoryBuffer::getFile(Filename); + MemoryBuffer::getFile(Path); - SmallString<64> Buffer(Filename); + SmallString<64> Buffer(Path); // If the file didn't exist directly, see if it's in an include path. for (unsigned i = 0, e = IncludeDirectories.size(); i != e && !NewBufOrErr; ++i) { Buffer = IncludeDirectories[i]; sys::path::append(Buffer, Filename); + sys::fs::make_absolute(Buffer); NewBufOrErr = MemoryBuffer::getFile(Buffer); }