[PATCH] D99363: [Windows] Turn off text mode in TableGen and Rewriter to stop CRLF translation
Abhina Sree via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 25 11:37:21 PDT 2021
abhina.sreeskantharajan created this revision.
abhina.sreeskantharajan added reviewers: rnk, amccarth, yroux, aganea.
Herald added a subscriber: hiraditya.
abhina.sreeskantharajan requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.
This patch should fix the errors shown on the Windows bots by turning off text mode. I plan to investigate a better fix but this should unblock the buildbots for now.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D99363
Files:
clang/lib/Frontend/Rewrite/FrontendActions.cpp
llvm/lib/TableGen/Main.cpp
Index: llvm/lib/TableGen/Main.cpp
===================================================================
--- llvm/lib/TableGen/Main.cpp
+++ llvm/lib/TableGen/Main.cpp
@@ -17,6 +17,7 @@
#include "llvm/TableGen/Main.h"
#include "TGParser.h"
#include "llvm/ADT/StringExtras.h"
+#include "llvm/ADT/Triple.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/MemoryBuffer.h"
@@ -90,10 +91,13 @@
Records.startPhaseTiming();
// Parse the input file.
+ // On Windows, set binary mode to turn off CRLF translation.
+ bool IsWindows = llvm::Triple(LLVM_HOST_TRIPLE).isOSWindows();
Records.startTimer("Parse, build records");
ErrorOr<std::unique_ptr<MemoryBuffer>> FileOrErr =
- MemoryBuffer::getFileOrSTDIN(InputFilename, /*IsText=*/true);
+ MemoryBuffer::getFileOrSTDIN(InputFilename,
+ IsWindows ? /*IsText=*/false : true);
if (std::error_code EC = FileOrErr.getError())
return reportError(argv0, "Could not open input file '" + InputFilename +
"': " + EC.message() + "\n");
@@ -137,8 +141,8 @@
// Only updates the real output file if there are any differences.
// This prevents recompilation of all the files depending on it if there
// aren't any.
- if (auto ExistingOrErr =
- MemoryBuffer::getFile(OutputFilename, /*IsText=*/true))
+ if (auto ExistingOrErr = MemoryBuffer::getFile(
+ OutputFilename, IsWindows ? /*IsText=*/false : true))
if (std::move(ExistingOrErr.get())->getBuffer() == Out.str())
WriteFile = false;
}
Index: clang/lib/Frontend/Rewrite/FrontendActions.cpp
===================================================================
--- clang/lib/Frontend/Rewrite/FrontendActions.cpp
+++ clang/lib/Frontend/Rewrite/FrontendActions.cpp
@@ -24,6 +24,7 @@
#include "clang/Serialization/ModuleFile.h"
#include "clang/Serialization/ModuleManager.h"
#include "llvm/ADT/DenseSet.h"
+#include "llvm/ADT/Triple.h"
#include "llvm/Support/CrashRecoveryContext.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Path.h"
@@ -184,8 +185,10 @@
void RewriteMacrosAction::ExecuteAction() {
CompilerInstance &CI = getCompilerInstance();
- std::unique_ptr<raw_ostream> OS =
- CI.createDefaultOutputFile(/*Binary=*/false, getCurrentFileOrBufferName());
+ // On Windows, set binary mode to avoid CRLF translation.
+ std::unique_ptr<raw_ostream> OS = CI.createDefaultOutputFile(
+ /*Binary=*/llvm::Triple(LLVM_HOST_TRIPLE).isOSWindows(),
+ getCurrentFileOrBufferName());
if (!OS) return;
RewriteMacrosInInput(CI.getPreprocessor(), OS.get());
@@ -193,8 +196,10 @@
void RewriteTestAction::ExecuteAction() {
CompilerInstance &CI = getCompilerInstance();
- std::unique_ptr<raw_ostream> OS =
- CI.createDefaultOutputFile(false, getCurrentFileOrBufferName());
+ // On Windows, set binary mode to avoid CRLF translation.
+ std::unique_ptr<raw_ostream> OS = CI.createDefaultOutputFile(
+ /*Binary=*/llvm::Triple(LLVM_HOST_TRIPLE).isOSWindows(),
+ getCurrentFileOrBufferName());
if (!OS) return;
DoRewriteTest(CI.getPreprocessor(), OS.get());
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D99363.333372.patch
Type: text/x-patch
Size: 3219 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210325/bd4a0d30/attachment.bin>
More information about the llvm-commits
mailing list