summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/Support
diff options
context:
space:
mode:
authorFrancis Visoiu Mistrih <francisvm@yahoo.com>2017-12-18 17:38:03 +0000
committerFrancis Visoiu Mistrih <francisvm@yahoo.com>2017-12-18 17:38:03 +0000
commitb213b27ee3cba7d0b7ad2a45c8cbd42e59510220 (patch)
tree887a44fd8bb29d305bc2c240e44a01467ca9cc38 /llvm/unittests/Support
parent6c0858e41413de10b7194519fc6cb9d4a1eda959 (diff)
downloadbcm5719-llvm-b213b27ee3cba7d0b7ad2a45c8cbd42e59510220.tar.gz
bcm5719-llvm-b213b27ee3cba7d0b7ad2a45c8cbd42e59510220.zip
[YAML] Add support for non-printable characters
LLVM IR function names which disable mangling start with '\01' (https://www.llvm.org/docs/LangRef.html#identifiers). When an identifier like "\01@abc@" gets dumped to MIR, it is quoted, but only with single quotes. http://www.yaml.org/spec/1.2/spec.html#id2770814: "The allowed character range explicitly excludes the C0 control block allowed), the surrogate block #xD800-#xDFFF, #xFFFE, and #xFFFF." http://www.yaml.org/spec/1.2/spec.html#id2776092: "All non-printable characters must be escaped. [...] Note that escape sequences are only interpreted in double-quoted scalars." This patch adds support for printing escaped non-printable characters between double quotes if needed. Should also fix PR31743. Differential Revision: https://reviews.llvm.org/D41290 llvm-svn: 320996
Diffstat (limited to 'llvm/unittests/Support')
-rw-r--r--llvm/unittests/Support/YAMLIOTest.cpp94
1 files changed, 90 insertions, 4 deletions
diff --git a/llvm/unittests/Support/YAMLIOTest.cpp b/llvm/unittests/Support/YAMLIOTest.cpp
index 120773a0c8d..9caff85a596 100644
--- a/llvm/unittests/Support/YAMLIOTest.cpp
+++ b/llvm/unittests/Support/YAMLIOTest.cpp
@@ -860,7 +860,7 @@ namespace yaml {
return "malformed by";
}
}
- static bool mustQuote(StringRef) { return true; }
+ static QuotingType mustQuote(StringRef) { return QuotingType::Single; }
};
}
}
@@ -1064,7 +1064,7 @@ namespace yaml {
return StringRef();
}
- static bool mustQuote(StringRef) { return false; }
+ static QuotingType mustQuote(StringRef) { return QuotingType::None; }
};
template <> struct ScalarTraits<MyString> {
@@ -1075,7 +1075,9 @@ namespace yaml {
static StringRef input(StringRef S, void *Ctx, MyString &V) {
return Impl::input(S, Ctx, V.value);
}
- static bool mustQuote(StringRef S) { return Impl::mustQuote(S); }
+ static QuotingType mustQuote(StringRef S) {
+ return Impl::mustQuote(S);
+ }
};
}
}
@@ -2232,7 +2234,7 @@ struct ScalarTraits<FlowSeq> {
return "";
}
- static bool mustQuote(StringRef S) { return false; }
+ static QuotingType mustQuote(StringRef S) { return QuotingType::None; }
};
}
}
@@ -2455,3 +2457,87 @@ TEST(YAMLIO, InvalidInput) {
yin >> Data;
EXPECT_TRUE((bool)yin.error());
}
+
+TEST(YAMLIO, TestEscapedSingleQuote) {
+ std::string Id = "@abc@";
+
+ std::string out;
+ llvm::raw_string_ostream ostr(out);
+ Output xout(ostr, nullptr, 0);
+
+ llvm::yaml::EmptyContext Ctx;
+ yamlize(xout, Id, true, Ctx);
+
+ ostr.flush();
+ EXPECT_EQ("'@abc@'", out);
+}
+
+TEST(YAMLIO, TestEscapedNoQuote) {
+ std::string Id = "abc/";
+
+ std::string out;
+ llvm::raw_string_ostream ostr(out);
+ Output xout(ostr, nullptr, 0);
+
+ llvm::yaml::EmptyContext Ctx;
+ yamlize(xout, Id, true, Ctx);
+
+ ostr.flush();
+ EXPECT_EQ("abc/", out);
+}
+
+TEST(YAMLIO, TestEscapedDoubleQuoteNonPrintable) {
+ std::string Id = "\01@abc@";
+
+ std::string out;
+ llvm::raw_string_ostream ostr(out);
+ Output xout(ostr, nullptr, 0);
+
+ llvm::yaml::EmptyContext Ctx;
+ yamlize(xout, Id, true, Ctx);
+
+ ostr.flush();
+ EXPECT_EQ("\"\\x01@abc@\"", out);
+}
+
+TEST(YAMLIO, TestEscapedDoubleQuoteInsideSingleQuote) {
+ std::string Id = "abc\"fdf";
+
+ std::string out;
+ llvm::raw_string_ostream ostr(out);
+ Output xout(ostr, nullptr, 0);
+
+ llvm::yaml::EmptyContext Ctx;
+ yamlize(xout, Id, true, Ctx);
+
+ ostr.flush();
+ EXPECT_EQ("'abc\"fdf'", out);
+}
+
+TEST(YAMLIO, TestEscapedDoubleQuoteInsideDoubleQuote) {
+ std::string Id = "\01bc\"fdf";
+
+ std::string out;
+ llvm::raw_string_ostream ostr(out);
+ Output xout(ostr, nullptr, 0);
+
+ llvm::yaml::EmptyContext Ctx;
+ yamlize(xout, Id, true, Ctx);
+
+ ostr.flush();
+ EXPECT_EQ("\"\\x01bc\\\"fdf\"", out);
+}
+
+TEST(YAMLIO, TestEscapedSingleQuoteInsideSingleQuote) {
+ std::string Id = "abc'fdf";
+
+ std::string out;
+ llvm::raw_string_ostream ostr(out);
+ Output xout(ostr, nullptr, 0);
+
+ llvm::yaml::EmptyContext Ctx;
+ yamlize(xout, Id, true, Ctx);
+
+ ostr.flush();
+ EXPECT_EQ("'abc''fdf'", out);
+}
OpenPOWER on IntegriCloud