[IR] Simplify code to print string attributes a bit. NFC.

This commit is contained in:
Benjamin Kramer 2020-04-26 13:06:50 +02:00
parent 65b13610a5
commit d93ad3aedb
1 changed files with 11 additions and 11 deletions

View File

@ -504,19 +504,19 @@ std::string Attribute::getAsString(bool InAttrGrp) const {
//
if (isStringAttribute()) {
std::string Result;
Result += (Twine('"') + getKindAsString() + Twine('"')).str();
std::string AttrVal = std::string(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 << "\"";
OS << '"' << getKindAsString() << '"';
// 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"
const auto &AttrVal = pImpl->getValueAsString();
if (!AttrVal.empty()) {
OS << "=\"";
printEscapedString(AttrVal, OS);
OS << "\"";
}
}
return Result;
}