Index: lib/IR/Attributes.cpp =================================================================== --- lib/IR/Attributes.cpp +++ lib/IR/Attributes.cpp @@ -223,6 +223,21 @@ return unpackAllocSizeArgs(pImpl->getValueAsInt()); } +static std::string GetEscapedString(StringRef Name) { + std::string EscapedName; + for (unsigned i = 0, e = Name.size(); i != e; ++i) { + unsigned char C = Name[i]; + if (isprint(C) && C != '\\' && C != '"') + EscapedName += C; + else { + EscapedName += "\\"; + EscapedName += hexdigit(C >> 4); + EscapedName += hexdigit(C & 0x0F); + } + } + return EscapedName; +} + std::string Attribute::getAsString(bool InAttrGrp) const { if (!pImpl) return ""; @@ -384,7 +399,9 @@ StringRef Val = pImpl->getValueAsString(); if (Val.empty()) return Result; - Result += ("=\"" + Val + Twine('"')).str(); + Result += "=\""; + Result += GetEscapedString(Val); + Result += "\""; return Result; }