[llvm] [llvm-strings] Use small buffer instead of reading whole file (PR #163073)

James Henderson via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 12 02:31:32 PDT 2026


================
@@ -174,13 +195,17 @@ int main(int argc, char **argv) {
     InputFileNames.push_back("-");
 
   for (const auto &File : InputFileNames) {
-    ErrorOr<std::unique_ptr<MemoryBuffer>> Buffer =
-        MemoryBuffer::getFileOrSTDIN(File, /*IsText=*/true);
-    if (std::error_code EC = Buffer.getError())
-      errs() << File << ": " << EC.message() << '\n';
-    else
-      strings(llvm::outs(), File == "-" ? "{standard input}" : File,
-              Buffer.get()->getMemBufferRef().getBuffer());
+    if (File == "-") {
+      strings(llvm::outs(), "{standard input}", sys::fs::getStdinHandle());
+    } else {
+      Expected<sys::fs::file_t> FDOrErr = sys::fs::openNativeFileForReadWrite(
+          File, sys::fs::CD_OpenExisting, sys::fs::OF_None);
----------------
jh7370 wrote:

Is `OF_None` actually correct? We need to make sure this flag matches `getFileOrSTDIN` or it could break things in subtle ways versus the previous behaviour. If I'm following the implementation correctly, `OF_None` isn't the right value to match the old behaviour.

https://github.com/llvm/llvm-project/pull/163073


More information about the llvm-commits mailing list