r341620 - [analyzer] [NFC] Prefer passing around reference to std::unique_ptr&

George Karpenkov via cfe-commits cfe-commits at lists.llvm.org
Thu Sep 6 17:43:56 PDT 2018


Author: george.karpenkov
Date: Thu Sep  6 17:43:55 2018
New Revision: 341620

URL: http://llvm.org/viewvc/llvm-project?rev=341620&view=rev
Log:
[analyzer] [NFC] Prefer passing around reference to std::unique_ptr&

When object is owned elsewhere

Differential Revision: https://reviews.llvm.org/D51669

Modified:
    cfe/trunk/lib/StaticAnalyzer/Core/BugReporter.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Core/BugReporter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/BugReporter.cpp?rev=341620&r1=341619&r2=341620&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/BugReporter.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/BugReporter.cpp Thu Sep  6 17:43:55 2018
@@ -3010,7 +3010,7 @@ void BugReporter::FlushReport(BugReportE
 /// into \p ExecutedLines.
 static void populateExecutedLinesWithFunctionSignature(
     const Decl *Signature, SourceManager &SM,
-    std::unique_ptr<FilesToLineNumsMap> &ExecutedLines) {
+    FilesToLineNumsMap &ExecutedLines) {
   SourceRange SignatureSourceRange;
   const Stmt* Body = Signature->getBody();
   if (const auto FD = dyn_cast<FunctionDecl>(Signature)) {
@@ -3030,19 +3030,19 @@ static void populateExecutedLinesWithFun
 
   FileID FID = SM.getFileID(SM.getExpansionLoc(Start));
   for (unsigned Line = StartLine; Line <= EndLine; Line++)
-    ExecutedLines->operator[](FID).insert(Line);
+    ExecutedLines[FID].insert(Line);
 }
 
 static void populateExecutedLinesWithStmt(
     const Stmt *S, SourceManager &SM,
-    std::unique_ptr<FilesToLineNumsMap> &ExecutedLines) {
+    FilesToLineNumsMap &ExecutedLines) {
   SourceLocation Loc = S->getSourceRange().getBegin();
   if (!Loc.isValid())
     return;
   SourceLocation ExpansionLoc = SM.getExpansionLoc(Loc);
   FileID FID = SM.getFileID(ExpansionLoc);
   unsigned LineNo = SM.getExpansionLineNumber(ExpansionLoc);
-  ExecutedLines->operator[](FID).insert(LineNo);
+  ExecutedLines[FID].insert(LineNo);
 }
 
 /// \return all executed lines including function signatures on the path
@@ -3055,13 +3055,13 @@ findExecutedLines(SourceManager &SM, con
     if (N->getFirstPred() == nullptr) {
       // First node: show signature of the entrance point.
       const Decl *D = N->getLocationContext()->getDecl();
-      populateExecutedLinesWithFunctionSignature(D, SM, ExecutedLines);
+      populateExecutedLinesWithFunctionSignature(D, SM, *ExecutedLines);
     } else if (auto CE = N->getLocationAs<CallEnter>()) {
       // Inlined function: show signature.
       const Decl* D = CE->getCalleeContext()->getDecl();
-      populateExecutedLinesWithFunctionSignature(D, SM, ExecutedLines);
+      populateExecutedLinesWithFunctionSignature(D, SM, *ExecutedLines);
     } else if (const Stmt *S = PathDiagnosticLocation::getStmt(N)) {
-      populateExecutedLinesWithStmt(S, SM, ExecutedLines);
+      populateExecutedLinesWithStmt(S, SM, *ExecutedLines);
 
       // Show extra context for some parent kinds.
       const Stmt *P = N->getParentMap().getParent(S);
@@ -3070,12 +3070,12 @@ findExecutedLines(SourceManager &SM, con
       // return statement is generated, but we do want to show the whole
       // return.
       if (const auto *RS = dyn_cast_or_null<ReturnStmt>(P)) {
-        populateExecutedLinesWithStmt(RS, SM, ExecutedLines);
+        populateExecutedLinesWithStmt(RS, SM, *ExecutedLines);
         P = N->getParentMap().getParent(RS);
       }
 
       if (P && (isa<SwitchCase>(P) || isa<LabelStmt>(P)))
-        populateExecutedLinesWithStmt(P, SM, ExecutedLines);
+        populateExecutedLinesWithStmt(P, SM, *ExecutedLines);
     }
 
     N = N->getFirstPred();




More information about the cfe-commits mailing list