]> granicus.if.org Git - clang/commitdiff
[analyzer] Replace calls to getNameAsString() with StringRef equivalents.
authorJordy Rose <jediknil@belkadan.com>
Sun, 21 Aug 2011 05:25:15 +0000 (05:25 +0000)
committerJordy Rose <jediknil@belkadan.com>
Sun, 21 Aug 2011 05:25:15 +0000 (05:25 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@138215 91177308-0d34-0410-b5e6-96231b3b80d8

lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp
lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp
lib/StaticAnalyzer/Core/BugReporter.cpp
lib/StaticAnalyzer/Core/CFRefCount.cpp

index d36951814867c91472b9a239c837e287ee5f4423..66787f7a82128a87ce2cb825fff4f71272671913 100644 (file)
@@ -103,26 +103,25 @@ public:
     if (!reachableCode->isReachable(currentBlock))
       return;
 
-    const std::string &name = V->getNameAsString();
-
-    const char* BugType = 0;
-    std::string msg;
+    llvm::SmallString<64> buf;
+    llvm::raw_svector_ostream os(buf);
+    const char *BugType = 0;
 
     switch (dsk) {
       default:
-        assert(false && "Impossible dead store type.");
+        llvm_unreachable("Impossible dead store type.");
 
       case DeadInit:
         BugType = "Dead initialization";
-        msg = "Value stored to '" + name +
-          "' during its initialization is never read";
+        os << "Value stored to '" << V
+           << "' during its initialization is never read";
         break;
 
       case DeadIncrement:
         BugType = "Dead increment";
       case Standard:
         if (!BugType) BugType = "Dead assignment";
-        msg = "Value stored to '" + name + "' is never read";
+        os << "Value stored to '" << V << "' is never read";
         break;
 
       case Enclosing:
@@ -132,7 +131,7 @@ public:
         return;
     }
 
-    BR.EmitBasicReport(BugType, "Dead store", msg, L, R);
+    BR.EmitBasicReport(BugType, "Dead store", os.str(), L, R);
   }
 
   void CheckVarDecl(const VarDecl *VD, const Expr *Ex, const Expr *Val,
index dc5fe0843a32cc6b9188a6655bd17d53a4651602..b004aa9c647b2fec5bd69dbd3c1128d83c7e3cac 100644 (file)
@@ -202,7 +202,7 @@ void StackAddrEscapeChecker::checkEndPath(EndOfFunctionNodeBuilder &B,
                                 Eng.getContext().getSourceManager());
     os << " is still referred to by the global variable '";
     const VarRegion *VR = cast<VarRegion>(cb.V[i].first->getBaseRegion());
-    os << VR->getDecl()->getNameAsString() 
+    os << VR->getDecl()
        << "' upon returning to the caller.  This will be a dangling reference";
     BugReport *report = new BugReport(*BT_stackleak, os.str(), N);
     if (range.isValid())
index b82d12310e62a76be3f85cfa35e840de822d5e5c..31786dd002ab6fce4348ed9cc82b248e1b4ec788 100644 (file)
@@ -438,10 +438,11 @@ public:
     FullSourceLoc L(S->getLocStart(), BR.getSourceManager());
 
     if (Loc::isLocType(VD->getType())) {
-      std::string msg = "'" + std::string(VD->getNameAsString()) +
-      "' now aliases '" + MostRecent->getNameAsString() + "'";
+      llvm::SmallString<64> buf;
+      llvm::raw_svector_ostream os(buf);
+      os << '\'' << VD << "' now aliases '" << MostRecent << '\'';
 
-      PD.push_front(new PathDiagnosticEventPiece(L, msg));
+      PD.push_front(new PathDiagnosticEventPiece(L, os.str()));
     }
 
     return true;
index 1b4e4a8673d1f79fd33f7b7e92e1e4376f536f5f..7cffdb23881884d49d8636eac352eef431ddb2af 100644 (file)
@@ -2189,13 +2189,12 @@ PathDiagnosticPiece *CFRefReportVisitor::VisitNode(const ExplodedNode *N,
       const Stmt *S = cast<PostStmt>(N->getLocation()).getStmt();
       SVal X = CurrSt->getSValAsScalarOrLoc(cast<CallExpr>(S)->getCallee());
       const FunctionDecl *FD = X.getAsFunctionDecl();
-      const std::string& FName = FD->getNameAsString();
 
       if (TF.isGCEnabled()) {
         // Determine if the object's reference count was pushed to zero.
         assert(!(PrevV == CurrV) && "The typestate *must* have changed.");
 
-        os << "In GC mode a call to '" << FName
+        os << "In GC mode a call to '" << FD
         <<  "' decrements an object's retain count and registers the "
         "object with the garbage collector. ";
 
@@ -2210,7 +2209,7 @@ PathDiagnosticPiece *CFRefReportVisitor::VisitNode(const ExplodedNode *N,
           << '.';
       }
       else
-        os << "When GC is not enabled a call to '" << FName
+        os << "When GC is not enabled a call to '" << FD
         << "' has no effect on its argument.";
 
       // Nothing more to say.