Port BugReporter and BugType to StringRef.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@90086 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/clang/Analysis/PathSensitive/BugReporter.h b/include/clang/Analysis/PathSensitive/BugReporter.h
index f429735..58c8018 100644
--- a/include/clang/Analysis/PathSensitive/BugReporter.h
+++ b/include/clang/Analysis/PathSensitive/BugReporter.h
@@ -309,32 +309,33 @@
 
   void EmitReport(BugReport *R);
 
-  void EmitBasicReport(const char* BugName, const char* BugStr,
+  void EmitBasicReport(llvm::StringRef BugName, llvm::StringRef BugStr,
                        SourceLocation Loc,
                        SourceRange* RangeBeg, unsigned NumRanges);
 
-  void EmitBasicReport(const char* BugName, const char* BugCategory,
-                       const char* BugStr, SourceLocation Loc,
+  void EmitBasicReport(llvm::StringRef BugName, llvm::StringRef BugCategory,
+                       llvm::StringRef BugStr, SourceLocation Loc,
                        SourceRange* RangeBeg, unsigned NumRanges);
 
 
-  void EmitBasicReport(const char* BugName, const char* BugStr,
+  void EmitBasicReport(llvm::StringRef BugName, llvm::StringRef BugStr,
                        SourceLocation Loc) {
     EmitBasicReport(BugName, BugStr, Loc, 0, 0);
   }
 
-  void EmitBasicReport(const char* BugName, const char* BugCategory,
-                       const char* BugStr, SourceLocation Loc) {
+  void EmitBasicReport(llvm::StringRef BugName, llvm::StringRef BugCategory,
+                       llvm::StringRef BugStr, SourceLocation Loc) {
     EmitBasicReport(BugName, BugCategory, BugStr, Loc, 0, 0);
   }
 
-  void EmitBasicReport(const char* BugName, const char* BugStr,
+  void EmitBasicReport(llvm::StringRef BugName, llvm::StringRef BugStr,
                        SourceLocation Loc, SourceRange R) {
     EmitBasicReport(BugName, BugStr, Loc, &R, 1);
   }
 
-  void EmitBasicReport(const char* BugName, const char* Category,
-                       const char* BugStr, SourceLocation Loc, SourceRange R) {
+  void EmitBasicReport(llvm::StringRef BugName, llvm::StringRef Category,
+                       llvm::StringRef BugStr, SourceLocation Loc,
+                       SourceRange R) {
     EmitBasicReport(BugName, Category, BugStr, Loc, &R, 1);
   }
 
@@ -432,7 +433,7 @@
   std::list<std::string> Strs;
   FullSourceLoc L;
 public:
-  DiagBugReport(BugType& D, const char* desc, FullSourceLoc l) :
+  DiagBugReport(BugType& D, llvm::StringRef desc, FullSourceLoc l) :
   RangedBugReport(D, desc, 0), L(l) {}
 
   virtual ~DiagBugReport() {}
diff --git a/include/clang/Analysis/PathSensitive/BugType.h b/include/clang/Analysis/PathSensitive/BugType.h
index 0789e1e..5148c5f 100644
--- a/include/clang/Analysis/PathSensitive/BugType.h
+++ b/include/clang/Analysis/PathSensitive/BugType.h
@@ -34,7 +34,7 @@
   friend class BugReporter;
   bool SuppressonSink;
 public:
-  BugType(const char *name, const char* cat)
+  BugType(llvm::StringRef name, llvm::StringRef cat)
     : Name(name), Category(cat), SuppressonSink(false) {}
   virtual ~BugType();
 
diff --git a/lib/Analysis/BugReporter.cpp b/lib/Analysis/BugReporter.cpp
index d531b52..c26a60a 100644
--- a/lib/Analysis/BugReporter.cpp
+++ b/lib/Analysis/BugReporter.cpp
@@ -1835,14 +1835,15 @@
   PD->HandlePathDiagnostic(D.take());
 }
 
-void BugReporter::EmitBasicReport(const char* name, const char* str,
+void BugReporter::EmitBasicReport(llvm::StringRef name, llvm::StringRef str,
                                   SourceLocation Loc,
                                   SourceRange* RBeg, unsigned NumRanges) {
   EmitBasicReport(name, "", str, Loc, RBeg, NumRanges);
 }
 
-void BugReporter::EmitBasicReport(const char* name, const char* category,
-                                  const char* str, SourceLocation Loc,
+void BugReporter::EmitBasicReport(llvm::StringRef name,
+                                  llvm::StringRef category,
+                                  llvm::StringRef str, SourceLocation Loc,
                                   SourceRange* RBeg, unsigned NumRanges) {
 
   // 'BT' will be owned by BugReporter as soon as we call 'EmitReport'.
diff --git a/lib/Analysis/CFRefCount.cpp b/lib/Analysis/CFRefCount.cpp
index cb2f9bc..b95f981 100644
--- a/lib/Analysis/CFRefCount.cpp
+++ b/lib/Analysis/CFRefCount.cpp
@@ -2098,7 +2098,7 @@
   protected:
     CFRefCount& TF;
 
-    CFRefBug(CFRefCount* tf, const char* name)
+    CFRefBug(CFRefCount* tf, llvm::StringRef name)
     : BugType(name, "Memory (Core Foundation/Objective-C)"), TF(*tf) {}
   public:
 
@@ -2175,7 +2175,7 @@
   class Leak : public CFRefBug {
     const bool isReturn;
   protected:
-    Leak(CFRefCount* tf, const char* name, bool isRet)
+    Leak(CFRefCount* tf, llvm::StringRef name, bool isRet)
     : CFRefBug(tf, name), isReturn(isRet) {}
   public:
 
@@ -2186,13 +2186,13 @@
 
   class LeakAtReturn : public Leak {
   public:
-    LeakAtReturn(CFRefCount* tf, const char* name)
+    LeakAtReturn(CFRefCount* tf, llvm::StringRef name)
     : Leak(tf, name, true) {}
   };
 
   class LeakWithinFunction : public Leak {
   public:
-    LeakWithinFunction(CFRefCount* tf, const char* name)
+    LeakWithinFunction(CFRefCount* tf, llvm::StringRef name)
     : Leak(tf, name, false) {}
   };
 
@@ -2210,7 +2210,7 @@
       : RangedBugReport(D, D.getDescription(), n), Sym(sym), TF(tf) {}
 
     CFRefReport(CFRefBug& D, const CFRefCount &tf,
-                ExplodedNode *n, SymbolRef sym, const char* endText)
+                ExplodedNode *n, SymbolRef sym, llvm::StringRef endText)
       : RangedBugReport(D, D.getDescription(), endText, n), Sym(sym), TF(tf) {}
 
     virtual ~CFRefReport() {}
@@ -3466,7 +3466,7 @@
 
     CFRefReport *report =
       new CFRefReport(*static_cast<CFRefBug*>(overAutorelease),
-                      *this, N, Sym, os.str().c_str());
+                      *this, N, Sym, os.str());
     BR->EmitReport(report);
   }
 
diff --git a/lib/Analysis/CheckDeadStores.cpp b/lib/Analysis/CheckDeadStores.cpp
index 31958a9..ad63eb4 100644
--- a/lib/Analysis/CheckDeadStores.cpp
+++ b/lib/Analysis/CheckDeadStores.cpp
@@ -76,7 +76,7 @@
         break;
     }
 
-    BR.EmitBasicReport(BugType, "Dead store", msg.c_str(), L, R);
+    BR.EmitBasicReport(BugType, "Dead store", msg, L, R);
   }
 
   void CheckVarDecl(VarDecl* VD, Expr* Ex, Expr* Val,
diff --git a/lib/Analysis/CheckObjCDealloc.cpp b/lib/Analysis/CheckObjCDealloc.cpp
index 92e3e11..87c1f27 100644
--- a/lib/Analysis/CheckObjCDealloc.cpp
+++ b/lib/Analysis/CheckObjCDealloc.cpp
@@ -169,7 +169,7 @@
     os << "Objective-C class '" << D->getNameAsString()
        << "' lacks a 'dealloc' instance method";
 
-    BR.EmitBasicReport(name, os.str().c_str(), D->getLocStart());
+    BR.EmitBasicReport(name, os.str(), D->getLocStart());
     return;
   }
 
@@ -187,7 +187,7 @@
        << "' does not send a 'dealloc' message to its super class"
            " (missing [super dealloc])";
 
-    BR.EmitBasicReport(name, os.str().c_str(), D->getLocStart());
+    BR.EmitBasicReport(name, os.str(), D->getLocStart());
     return;
   }
 
@@ -251,8 +251,7 @@
               "but was released in 'dealloc'";
       }
 
-      BR.EmitBasicReport(name, category,
-                         os.str().c_str(), (*I)->getLocation());
+      BR.EmitBasicReport(name, category, os.str(), (*I)->getLocation());
     }
   }
 }
diff --git a/lib/Analysis/CheckObjCInstMethSignature.cpp b/lib/Analysis/CheckObjCInstMethSignature.cpp
index 8c0d396..10ba896 100644
--- a/lib/Analysis/CheckObjCInstMethSignature.cpp
+++ b/lib/Analysis/CheckObjCInstMethSignature.cpp
@@ -65,7 +65,7 @@
           "behavior for clients of these classes.";
 
     BR.EmitBasicReport("Incompatible instance method return type",
-                       os.str().c_str(), MethDerived->getLocStart());
+                       os.str(), MethDerived->getLocStart());
   }
 }
 
diff --git a/lib/Analysis/CheckObjCUnusedIVars.cpp b/lib/Analysis/CheckObjCUnusedIVars.cpp
index 68a5674..d4067c9 100644
--- a/lib/Analysis/CheckObjCUnusedIVars.cpp
+++ b/lib/Analysis/CheckObjCUnusedIVars.cpp
@@ -157,6 +157,6 @@
             "(although it may be used by category methods).";
 
       BR.EmitBasicReport("Unused instance variable", "Optimization",
-                         os.str().c_str(), I->first->getLocation());
+                         os.str(), I->first->getLocation());
     }
 }
diff --git a/lib/Analysis/CheckSecuritySyntaxOnly.cpp b/lib/Analysis/CheckSecuritySyntaxOnly.cpp
index 0b75bd0..e6ab17a 100644
--- a/lib/Analysis/CheckSecuritySyntaxOnly.cpp
+++ b/lib/Analysis/CheckSecuritySyntaxOnly.cpp
@@ -209,7 +209,7 @@
   ranges.push_back(drInc->getSourceRange());
 
   const char *bugType = "Floating point variable used as loop counter";
-  BR.EmitBasicReport(bugType, "Security", os.str().c_str(),
+  BR.EmitBasicReport(bugType, "Security", os.str(),
                      FS->getLocStart(), ranges.data(), ranges.size());
 }
 
@@ -346,7 +346,7 @@
 
   SourceRange R = CE->getCallee()->getSourceRange();
 
-  BR.EmitBasicReport(os1.str().c_str(), "Security", os2.str().c_str(),
+  BR.EmitBasicReport(os1.str(), "Security", os2.str(),
                      CE->getLocStart(), &R, 1);
 }
 
@@ -436,7 +436,7 @@
 
   SourceRange R = CE->getCallee()->getSourceRange();
 
-  BR.EmitBasicReport(os1.str().c_str(), "Security", os2.str().c_str(),
+  BR.EmitBasicReport(os1.str(), "Security", os2.str(),
                      CE->getLocStart(), &R, 1);
 }
 
diff --git a/lib/Analysis/NSErrorChecker.cpp b/lib/Analysis/NSErrorChecker.cpp
index c5c405e..e3cf57f 100644
--- a/lib/Analysis/NSErrorChecker.cpp
+++ b/lib/Analysis/NSErrorChecker.cpp
@@ -113,13 +113,10 @@
   os << " should have a non-void return value to indicate whether or not an "
         "error occurred";
 
-  // FIXME: Remove when we migrate EmitBasicReport to StringRef.
-  std::string cat = getCategory().str();
-  
   BR.EmitBasicReport(isNSErrorWarning
                      ? "Bad return type when passing NSError**"
                      : "Bad return type when passing CFError*",
-                     cat.c_str(), os.str().c_str(),
+                     getCategory(), os.str(),
                      CodeDecl.getLocation());
 }