From 4f750f6ebc412869ce6bb28331313a9c9a9d9af7 Mon Sep 17 00:00:00 2001 From: Abhina Sreeskantharajan Date: Fri, 19 Mar 2021 08:09:01 -0400 Subject: [SystemZ][z/OS] Distinguish between text and binary files on z/OS This patch consists of the initial changes to help distinguish between text and binary content correctly on z/OS. I would like to get feedback from Windows users on setting OF_None for all ToolOutputFiles. This seems to have been done as an optimization to prevent CRLF translation on Windows in the past. Reviewed By: zibi Differential Revision: https://reviews.llvm.org/D97785 --- clang/lib/Frontend/FrontendActions.cpp | 55 ++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 25 deletions(-) (limited to 'clang/lib/Frontend/FrontendActions.cpp') diff --git a/clang/lib/Frontend/FrontendActions.cpp b/clang/lib/Frontend/FrontendActions.cpp index 38b6f75..4e5043b 100644 --- a/clang/lib/Frontend/FrontendActions.cpp +++ b/clang/lib/Frontend/FrontendActions.cpp @@ -795,7 +795,7 @@ void PreprocessOnlyAction::ExecuteAction() { void PrintPreprocessedAction::ExecuteAction() { CompilerInstance &CI = getCompilerInstance(); // Output file may need to be set to 'Binary', to avoid converting Unix style - // line feeds () to Microsoft style line feeds (). + // line feeds () to Microsoft style line feeds () on Windows. // // Look to see what type of line endings the file uses. If there's a // CRLF, then we won't open the file up in binary mode. If there is @@ -807,30 +807,35 @@ void PrintPreprocessedAction::ExecuteAction() { // all of their source code on a single line. However, that is still a // concern, so if we scan for too long, we'll just assume the file should // be opened in binary mode. - bool BinaryMode = true; - const SourceManager& SM = CI.getSourceManager(); - if (llvm::Optional Buffer = - SM.getBufferOrNone(SM.getMainFileID())) { - const char *cur = Buffer->getBufferStart(); - const char *end = Buffer->getBufferEnd(); - const char *next = (cur != end) ? cur + 1 : end; - - // Limit ourselves to only scanning 256 characters into the source - // file. This is mostly a sanity check in case the file has no - // newlines whatsoever. - if (end - cur > 256) end = cur + 256; - - while (next < end) { - if (*cur == 0x0D) { // CR - if (*next == 0x0A) // CRLF - BinaryMode = false; - - break; - } else if (*cur == 0x0A) // LF - break; - - ++cur; - ++next; + + bool BinaryMode = false; + if (llvm::Triple(LLVM_HOST_TRIPLE).isOSWindows()) { + BinaryMode = true; + const SourceManager &SM = CI.getSourceManager(); + if (llvm::Optional Buffer = + SM.getBufferOrNone(SM.getMainFileID())) { + const char *cur = Buffer->getBufferStart(); + const char *end = Buffer->getBufferEnd(); + const char *next = (cur != end) ? cur + 1 : end; + + // Limit ourselves to only scanning 256 characters into the source + // file. This is mostly a sanity check in case the file has no + // newlines whatsoever. + if (end - cur > 256) + end = cur + 256; + + while (next < end) { + if (*cur == 0x0D) { // CR + if (*next == 0x0A) // CRLF + BinaryMode = false; + + break; + } else if (*cur == 0x0A) // LF + break; + + ++cur; + ++next; + } } } -- cgit v1.1