[analyzer]Print field region even when the base region is not printable

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@179395 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/StaticAnalyzer/Checkers/MallocChecker.cpp b/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
index b000bfa..e19e3f7 100644
--- a/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
+++ b/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
@@ -1606,9 +1606,8 @@
   SmallString<200> buf;
   llvm::raw_svector_ostream os(buf);
   if (Region && Region->canPrintPretty()) {
-    os << "Potential leak of memory pointed to by '";
+    os << "Potential leak of memory pointed to by ";
     Region->printPretty(os);
-    os << '\'';
   } else {
     os << "Potential memory leak";
   }
diff --git a/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp b/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
index 9b5f6b2..92159de 100644
--- a/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
+++ b/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
@@ -307,9 +307,9 @@
     if (LValue) {
       if (const MemRegion *MR = LValue->getAsRegion()) {
         if (MR->canPrintPretty()) {
-          Out << " (reference to '";
+          Out << " (reference to ";
           MR->printPretty(Out);
-          Out << "')";
+          Out << ")";
         }
       }
     } else {
@@ -545,13 +545,9 @@
     }
 
     if (action) {
-      if (!R)
-        return 0;
-
-      os << '\'';
       R->printPretty(os);
-      os << "' ";
-
+      os << " ";
+      
       if (V.getAs<loc::ConcreteInt>()) {
         bool b = false;
         if (R->isBoundable()) {
@@ -606,10 +602,8 @@
 
       // Printed parameter indexes are 1-based, not 0-based.
       unsigned Idx = Param->getFunctionScopeIndex() + 1;
-      os << " via " << Idx << llvm::getOrdinalSuffix(Idx) << " parameter '";
-
+      os << " via " << Idx << llvm::getOrdinalSuffix(Idx) << " parameter ";
       R->printPretty(os);
-      os << '\'';
     }
   }
 
@@ -637,9 +631,7 @@
     else
       os << "Value assigned to ";
 
-    os << '\'';
     R->printPretty(os);
-    os << '\'';
   }
 
   // Construct a new PathDiagnosticPiece.
diff --git a/lib/StaticAnalyzer/Core/MemRegion.cpp b/lib/StaticAnalyzer/Core/MemRegion.cpp
index b3a1e65..e244d31 100644
--- a/lib/StaticAnalyzer/Core/MemRegion.cpp
+++ b/lib/StaticAnalyzer/Core/MemRegion.cpp
@@ -559,6 +559,15 @@
 }
 
 void MemRegion::printPretty(raw_ostream &os) const {
+  assert(canPrintPretty() && "This region cannot be printed pretty.");
+  os << "'";
+  printPrettyNoQuotes(os);
+  os << "'";
+  return;
+}
+
+void MemRegion::printPrettyNoQuotes(raw_ostream &os) const {
+  assert(canPrintPretty() && "This region cannot be printed pretty.");
   return;
 }
 
@@ -566,7 +575,7 @@
   return true;
 }
 
-void VarRegion::printPretty(raw_ostream &os) const {
+void VarRegion::printPrettyNoQuotes(raw_ostream &os) const {
   os << getDecl()->getName();
 }
 
@@ -574,17 +583,32 @@
   return true;
 }
 
-void ObjCIvarRegion::printPretty(raw_ostream &os) const {
+void ObjCIvarRegion::printPrettyNoQuotes(raw_ostream &os) const {
   os << getDecl()->getName();
 }
 
 bool FieldRegion::canPrintPretty() const {
-  return superRegion->canPrintPretty();
+  return true;
+}
+
+void FieldRegion::printPrettyNoQuotes(raw_ostream &os) const {
+  if (superRegion->canPrintPretty()) {
+    superRegion->printPrettyNoQuotes(os);
+    os << "." << getDecl()->getName();
+  } else {
+    os << "field " << "\'" << getDecl()->getName() << "'";
+  }
 }
 
 void FieldRegion::printPretty(raw_ostream &os) const {
-  superRegion->printPretty(os);
-  os << "." << getDecl()->getName();
+  if (superRegion->canPrintPretty()) {
+    os << "\'";
+    printPrettyNoQuotes(os);
+    os << "'";
+  } else {
+    printPrettyNoQuotes(os);
+  }
+  return;
 }
 
 //===----------------------------------------------------------------------===//