diff options
author | Honggyu Kim <hong.gyu.kim@lge.com> | 2016-09-01 11:44:06 +0000 |
---|---|---|
committer | Honggyu Kim <hong.gyu.kim@lge.com> | 2016-09-01 11:44:06 +0000 |
commit | 9eb6a1025147d2d8f1c5cf90bff7a4fdc2916424 (patch) | |
tree | bc648712f572c5e2619b1e19ecee5c14d211bba5 /llvm/lib | |
parent | 2e50d8edc6dfb3908903da116395a2a43d26eb87 (diff) | |
download | bcm5719-llvm-9eb6a1025147d2d8f1c5cf90bff7a4fdc2916424.tar.gz bcm5719-llvm-9eb6a1025147d2d8f1c5cf90bff7a4fdc2916424.zip |
[IR] Properly handle escape characters in Attribute::getAsString()
If an attribute name has special characters such as '\01', it is not
properly printed in LLVM assembly language format. Since the format
expects the special characters are printed as it is, it has to contain
escape characters to make it printable.
Before:
attributes #0 = { ... "counting-function"="^A__gnu_mcount_nc" ...
After:
attributes #0 = { ... "counting-function"="\01__gnu_mcount_nc" ...
Reviewers: hfinkel, rengolin, rjmccall, compnerd
Subscribers: nemanjai, mcrosier, hans, shenhan, majnemer, llvm-commits
Differential Revision: https://reviews.llvm.org/D23792
llvm-svn: 280357
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/IR/AsmWriter.cpp | 4 | ||||
-rw-r--r-- | llvm/lib/IR/Attributes.cpp | 16 |
2 files changed, 13 insertions, 7 deletions
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; } |