[llvm] [Support] Use absolute paths for include filenames (PR #136687)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 22 04:30:16 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-support
Author: tcwzxx (tcwzxx)
<details>
<summary>Changes</summary>
Since the LSP file URL requires an absolute path, ensure that all include files use absolute paths
---
Full diff: https://github.com/llvm/llvm-project/pull/136687.diff
1 Files Affected:
- (modified) llvm/lib/Support/SourceMgr.cpp (+6-2)
``````````diff
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<std::unique_ptr<MemoryBuffer>>
SourceMgr::OpenIncludeFile(const std::string &Filename,
std::string &IncludedFile) {
+ SmallString<128> Path{Filename};
+ sys::fs::make_absolute(Path);
ErrorOr<std::unique_ptr<MemoryBuffer>> 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);
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/136687
More information about the llvm-commits
mailing list