[PATCH] D141220: [TableGen][SourceMgr] Correctly append filename to include directories

Markus Böck via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Jan 8 12:24:39 PST 2023


zero9178 updated this revision to Diff 487217.
zero9178 marked an inline comment as done.
zero9178 added a comment.

Address review comments:

- Only update IncludeFile if no errors occured


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D141220/new/

https://reviews.llvm.org/D141220

Files:
  llvm/lib/Support/SourceMgr.cpp


Index: llvm/lib/Support/SourceMgr.cpp
===================================================================
--- llvm/lib/Support/SourceMgr.cpp
+++ llvm/lib/Support/SourceMgr.cpp
@@ -15,6 +15,7 @@
 #include "llvm/Support/SourceMgr.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/Twine.h"
@@ -51,18 +52,21 @@
 ErrorOr<std::unique_ptr<MemoryBuffer>>
 SourceMgr::OpenIncludeFile(const std::string &Filename,
                            std::string &IncludedFile) {
-  IncludedFile = Filename;
   ErrorOr<std::unique_ptr<MemoryBuffer>> NewBufOrErr =
       MemoryBuffer::getFile(IncludedFile);
 
+  SmallString<64> Buffer(Filename);
   // 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) {
-    IncludedFile =
-        IncludeDirectories[i] + sys::path::get_separator().data() + Filename;
-    NewBufOrErr = MemoryBuffer::getFile(IncludedFile);
+    Buffer = IncludeDirectories[i];
+    sys::path::append(Buffer, Filename);
+    NewBufOrErr = MemoryBuffer::getFile(Buffer);
   }
 
+  if (NewBufOrErr)
+    IncludedFile = static_cast<std::string>(Buffer);
+
   return NewBufOrErr;
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D141220.487217.patch
Type: text/x-patch
Size: 1331 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230108/61d42e11/attachment.bin>


More information about the llvm-commits mailing list