summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--llvm/include/llvm/ADT/StringExtras.h5
-rw-r--r--llvm/lib/IR/AsmWriter.cpp4
-rw-r--r--llvm/lib/IR/Attributes.cpp16
3 files changed, 18 insertions, 7 deletions
diff --git a/llvm/include/llvm/ADT/StringExtras.h b/llvm/include/llvm/ADT/StringExtras.h
index bdbb4d3f593..05513e149be 100644
--- a/llvm/include/llvm/ADT/StringExtras.h
+++ b/llvm/include/llvm/ADT/StringExtras.h
@@ -19,6 +19,7 @@
#include <iterator>
namespace llvm {
+class raw_ostream;
template<typename T> class SmallVectorImpl;
/// hexdigit - Return the hexadecimal character for the
@@ -150,6 +151,10 @@ static inline StringRef getOrdinalSuffix(unsigned Val) {
}
}
+/// PrintEscapedString - Print each character of the specified string, escaping
+/// it if it is not printable or if it is an escape char.
+void PrintEscapedString(StringRef Name, raw_ostream &Out);
+
template <typename IteratorT>
inline std::string join_impl(IteratorT Begin, IteratorT End,
StringRef Separator, std::input_iterator_tag) {
diff --git a/llvm/lib/IR/AsmWriter.cpp b/llvm/lib/IR/AsmWriter.cpp
index 828767e0736..0709676b9be 100644
--- a/llvm/lib/IR/AsmWriter.cpp
+++ b/llvm/lib/IR/AsmWriter.cpp
@@ -337,9 +337,7 @@ static void PrintCallingConv(unsigned cc, raw_ostream &Out) {
}
}
-// PrintEscapedString - Print each character of the specified string, escaping
-// it if it is not printable or if it is an escape char.
-static void PrintEscapedString(StringRef Name, raw_ostream &Out) {
+void llvm::PrintEscapedString(StringRef Name, raw_ostream &Out) {
for (unsigned i = 0, e = Name.size(); i != e; ++i) {
unsigned char C = Name[i];
if (isprint(C) && C != '\\' && C != '"')
diff --git a/llvm/lib/IR/Attributes.cpp b/llvm/lib/IR/Attributes.cpp
index 95ddc3628a0..2b76de77dca 100644
--- a/llvm/lib/IR/Attributes.cpp
+++ b/llvm/lib/IR/Attributes.cpp
@@ -381,10 +381,18 @@ std::string Attribute::getAsString(bool InAttrGrp) const {
std::string Result;
Result += (Twine('"') + getKindAsString() + Twine('"')).str();
- StringRef Val = pImpl->getValueAsString();
- if (Val.empty()) return Result;
-
- Result += ("=\"" + Val + Twine('"')).str();
+ std::string AttrVal = pImpl->getValueAsString();
+ if (AttrVal.empty()) return Result;
+
+ // Since some attribute strings contain special characters that cannot be
+ // printable, those have to be escaped to make the attribute value printable
+ // as is. e.g. "\01__gnu_mcount_nc"
+ {
+ raw_string_ostream OS(Result);
+ OS << "=\"";
+ PrintEscapedString(AttrVal, OS);
+ OS << "\"";
+ }
return Result;
}
OpenPOWER on IntegriCloud