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

Benjamin Kramer via llvm-commits llvm-commits at lists.llvm.org
Sun Apr 26 04:08:49 PDT 2020


Author: Benjamin Kramer
Date: 2020-04-26T13:06:50+02:00
New Revision: d93ad3aedbb49e7c0ab1255da17a9f5757c5b414

URL: https://github.com/llvm/llvm-project/commit/d93ad3aedbb49e7c0ab1255da17a9f5757c5b414
DIFF: https://github.com/llvm/llvm-project/commit/d93ad3aedbb49e7c0ab1255da17a9f5757c5b414.diff

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

Added: 
    

Modified: 
    llvm/lib/IR/Attributes.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/IR/Attributes.cpp b/llvm/lib/IR/Attributes.cpp
index 2d9910419bf7..28e0505de89b 100644
--- a/llvm/lib/IR/Attributes.cpp
+++ b/llvm/lib/IR/Attributes.cpp
@@ -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;
   }


        


More information about the llvm-commits mailing list