diff --git a/clang/include/clang/Tooling/ReplacementsYaml.h b/clang/include/clang/Tooling/ReplacementsYaml.h --- a/clang/include/clang/Tooling/ReplacementsYaml.h +++ b/clang/include/clang/Tooling/ReplacementsYaml.h @@ -35,13 +35,7 @@ NormalizedReplacement(const IO &, const clang::tooling::Replacement &R) : FilePath(R.getFilePath()), Offset(R.getOffset()), - Length(R.getLength()), ReplacementText(R.getReplacementText()) { - size_t lineBreakPos = ReplacementText.find('\n'); - while (lineBreakPos != std::string::npos) { - ReplacementText.replace(lineBreakPos, 1, "\n\n"); - lineBreakPos = ReplacementText.find('\n', lineBreakPos + 2); - } - } + Length(R.getLength()), ReplacementText(R.getReplacementText()) {} clang::tooling::Replacement denormalize(const IO &) { return clang::tooling::Replacement(FilePath, Offset, Length, diff --git a/clang/unittests/Tooling/ReplacementsYamlTest.cpp b/clang/unittests/Tooling/ReplacementsYamlTest.cpp --- a/clang/unittests/Tooling/ReplacementsYamlTest.cpp +++ b/clang/unittests/Tooling/ReplacementsYamlTest.cpp @@ -65,7 +65,7 @@ " - FilePath: '/path/to/file1.h'\n" " Offset: 0\n" " Length: 0\n" - " ReplacementText: '#include \n\n'\n" + " ReplacementText: \"#include \\n\"\n" "...\n", YamlContentStream.str().c_str()); } diff --git a/llvm/include/llvm/Support/YAMLTraits.h b/llvm/include/llvm/Support/YAMLTraits.h --- a/llvm/include/llvm/Support/YAMLTraits.h +++ b/llvm/include/llvm/Support/YAMLTraits.h @@ -649,24 +649,25 @@ inline QuotingType needsQuotes(StringRef S) { if (S.empty()) return QuotingType::Single; + + QuotingType MaxQuotingNeeded = QuotingType::None; if (isSpace(static_cast(S.front())) || isSpace(static_cast(S.back()))) - return QuotingType::Single; + MaxQuotingNeeded = QuotingType::Single; if (isNull(S)) - return QuotingType::Single; + MaxQuotingNeeded = QuotingType::Single; if (isBool(S)) - return QuotingType::Single; + MaxQuotingNeeded = QuotingType::Single; if (isNumeric(S)) - return QuotingType::Single; + MaxQuotingNeeded = QuotingType::Single; // 7.3.3 Plain Style // Plain scalars must not begin with most indicators, as this would cause // ambiguity with other YAML constructs. static constexpr char Indicators[] = R"(-?:\,[]{}#&*!|>'"%@`)"; if (S.find_first_of(Indicators) == 0) - return QuotingType::Single; + MaxQuotingNeeded = QuotingType::Single; - QuotingType MaxQuotingNeeded = QuotingType::None; for (unsigned char C : S) { // Alphanum is safe. if (isAlnum(C)) @@ -684,11 +685,11 @@ case 0x9: continue; // LF(0xA) and CR(0xD) may delimit values and so require at least single - // quotes. + // quotes. LLVM YAML parser cannot handle single quoted multiline so use + // double quoting to produce valid YAML. case 0xA: case 0xD: - MaxQuotingNeeded = QuotingType::Single; - continue; + return QuotingType::Double; // DEL (0x7F) are excluded from the allowed character range. case 0x7F: return QuotingType::Double; diff --git a/llvm/lib/Support/YAMLTraits.cpp b/llvm/lib/Support/YAMLTraits.cpp --- a/llvm/lib/Support/YAMLTraits.cpp +++ b/llvm/lib/Support/YAMLTraits.cpp @@ -878,12 +878,12 @@ } void ScalarTraits::output(const std::string &Val, void *, - raw_ostream &Out) { + raw_ostream &Out) { Out << Val; } StringRef ScalarTraits::input(StringRef Scalar, void *, - std::string &Val) { + std::string &Val) { Val = Scalar.str(); return StringRef(); } diff --git a/llvm/test/Transforms/LowerMatrixIntrinsics/remarks-shared-subtrees.ll b/llvm/test/Transforms/LowerMatrixIntrinsics/remarks-shared-subtrees.ll --- a/llvm/test/Transforms/LowerMatrixIntrinsics/remarks-shared-subtrees.ll +++ b/llvm/test/Transforms/LowerMatrixIntrinsics/remarks-shared-subtrees.ll @@ -18,8 +18,7 @@ ; YAML-NEXT: - String: ' loads, ' ; YAML-NEXT: - NumComputeOps: '0' ; YAML-NEXT: - String: ' compute ops' -; YAML-NEXT: - String: ', -; YAML-NEXT: additionally ' +; YAML-NEXT: - String: ",\nadditionally " ; YAML-NEXT: - NumStores: '0' ; YAML-NEXT: - String: ' stores, ' ; YAML-NEXT: - NumLoads: '4' @@ -47,8 +46,7 @@ ; YAML-NEXT: - String: ' loads, ' ; YAML-NEXT: - NumComputeOps: '120' ; YAML-NEXT: - String: ' compute ops' -; YAML-NEXT: - String: ', -; YAML-NEXT: additionally ' +; YAML-NEXT: - String: ",\nadditionally " ; YAML-NEXT: - NumStores: '0' ; YAML-NEXT: - String: ' stores, ' ; YAML-NEXT: - NumLoads: '4' diff --git a/llvm/unittests/Support/YAMLIOTest.cpp b/llvm/unittests/Support/YAMLIOTest.cpp --- a/llvm/unittests/Support/YAMLIOTest.cpp +++ b/llvm/unittests/Support/YAMLIOTest.cpp @@ -285,10 +285,8 @@ YOut << Original; } auto Expected = "---\n" - "str1: 'a multiline string\n" - "foobarbaz'\n" - "str2: 'another one\r" - "foobarbaz'\n" + "str1: \"a multiline string\\nfoobarbaz\"\n" + "str2: \"another one\\rfoobarbaz\"\n" "str3: a one-line string\n" "...\n"; ASSERT_EQ(Serialized, Expected);