Revert "[analyzer] Try to re-apply r283092 "Extend bug reports with extra notes"

Vector of smart pointers wasn't the thing that caused msvc crash.

llvm-svn: 283537
diff --git a/clang/lib/Rewrite/HTMLRewrite.cpp b/clang/lib/Rewrite/HTMLRewrite.cpp
index 27bb976..78aad39 100644
--- a/clang/lib/Rewrite/HTMLRewrite.cpp
+++ b/clang/lib/Rewrite/HTMLRewrite.cpp
@@ -324,7 +324,6 @@
       " .msgT { padding:0x; spacing:0x }\n"
       " .msgEvent { background-color:#fff8b4; color:#000000 }\n"
       " .msgControl { background-color:#bbbbbb; color:#000000 }\n"
-      " .msgNote { background-color:#ddeeff; color:#000000 }\n"
       " .mrange { background-color:#dfddf3 }\n"
       " .mrange { border-bottom:1px solid #6F9DBE }\n"
       " .PathIndex { font-weight: bold; padding:0px 5px; "
@@ -344,12 +343,8 @@
       "   border-collapse: collapse; border-spacing: 0px;\n"
       " }\n"
       " td.rowname {\n"
-      "   text-align: right;\n"
-      "   vertical-align: top;\n"
-      "   font-weight: bold;\n"
-      "   color:#444444;\n"
-      "   padding-right:2ex;\n"
-      " }\n"
+      "   text-align:right; font-weight:bold; color:#444444;\n"
+      "   padding-right:2ex; }\n"
       "</style>\n</head>\n<body>";
 
   // Generate header
diff --git a/clang/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp b/clang/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
index 86c194e..54c668c 100644
--- a/clang/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
+++ b/clang/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
@@ -344,10 +344,3 @@
     WidenLoops = getBooleanOption("widen-loops", /*Default=*/false);
   return WidenLoops.getValue();
 }
-
-bool AnalyzerOptions::shouldDisplayNotesAsEvents() {
-  if (!DisplayNotesAsEvents.hasValue())
-    DisplayNotesAsEvents =
-        getBooleanOption("notes-as-events", /*Default=*/false);
-  return DisplayNotesAsEvents.getValue();
-}
diff --git a/clang/lib/StaticAnalyzer/Core/BugReporter.cpp b/clang/lib/StaticAnalyzer/Core/BugReporter.cpp
index 9bc7470..1800eff 100644
--- a/clang/lib/StaticAnalyzer/Core/BugReporter.cpp
+++ b/clang/lib/StaticAnalyzer/Core/BugReporter.cpp
@@ -114,15 +114,15 @@
     path.pop_front();
 
     switch (piece->getKind()) {
-      case PathDiagnosticPiece::Call:
+      case clang::ento::PathDiagnosticPiece::Call:
         removeRedundantMsgs(cast<PathDiagnosticCallPiece>(piece)->path);
         break;
-      case PathDiagnosticPiece::Macro:
+      case clang::ento::PathDiagnosticPiece::Macro:
         removeRedundantMsgs(cast<PathDiagnosticMacroPiece>(piece)->subPieces);
         break;
-      case PathDiagnosticPiece::ControlFlow:
+      case clang::ento::PathDiagnosticPiece::ControlFlow:
         break;
-      case PathDiagnosticPiece::Event: {
+      case clang::ento::PathDiagnosticPiece::Event: {
         if (i == N-1)
           break;
 
@@ -142,8 +142,6 @@
         }
         break;
       }
-      case PathDiagnosticPiece::Note:
-        break;
     }
     path.push_back(piece);
   }
@@ -201,9 +199,6 @@
       }
       case PathDiagnosticPiece::ControlFlow:
         break;
-
-      case PathDiagnosticPiece::Note:
-        break;
     }
 
     pieces.push_back(piece);
@@ -2559,12 +2554,6 @@
   while (!interestingSymbols.empty()) {
     popInterestingSymbolsAndRegions();
   }
-
-  // FIXME: Replace Notes with a list of shared pointers.
-  for (const auto *P: Notes) {
-    delete P;
-  }
-  Notes.clear();
 }
 
 const Decl *BugReport::getDeclWithIssue() const {
@@ -3416,28 +3405,25 @@
       exampleReport->getUniqueingLocation(),
       exampleReport->getUniqueingDecl()));
 
-  if (exampleReport->isPathSensitive()) {
-    // Generate the full path diagnostic, using the generation scheme
-    // specified by the PathDiagnosticConsumer. Note that we have to generate
-    // path diagnostics even for consumers which do not support paths, because
-    // the BugReporterVisitors may mark this bug as a false positive.
-    assert(!bugReports.empty());
+  MaxBugClassSize = std::max(bugReports.size(),
+                             static_cast<size_t>(MaxBugClassSize));
 
-    MaxBugClassSize =
-        std::max(bugReports.size(), static_cast<size_t>(MaxBugClassSize));
-
+  // Generate the full path diagnostic, using the generation scheme
+  // specified by the PathDiagnosticConsumer. Note that we have to generate
+  // path diagnostics even for consumers which do not support paths, because
+  // the BugReporterVisitors may mark this bug as a false positive.
+  if (!bugReports.empty())
     if (!generatePathDiagnostic(*D.get(), PD, bugReports))
       return;
 
-    MaxValidBugClassSize =
-        std::max(bugReports.size(), static_cast<size_t>(MaxValidBugClassSize));
+  MaxValidBugClassSize = std::max(bugReports.size(),
+                                  static_cast<size_t>(MaxValidBugClassSize));
 
-    // Examine the report and see if the last piece is in a header. Reset the
-    // report location to the last piece in the main source file.
-    AnalyzerOptions &Opts = getAnalyzerOptions();
-    if (Opts.shouldReportIssuesInMainSourceFile() && !Opts.AnalyzeAll)
-      D->resetDiagnosticLocationToMainFile();
-  }
+  // Examine the report and see if the last piece is in a header. Reset the
+  // report location to the last piece in the main source file.
+  AnalyzerOptions& Opts = getAnalyzerOptions();
+  if (Opts.shouldReportIssuesInMainSourceFile() && !Opts.AnalyzeAll)
+    D->resetDiagnosticLocationToMainFile();
 
   // If the path is empty, generate a single step path with the location
   // of the issue.
@@ -3450,28 +3436,6 @@
     D->setEndOfPath(std::move(piece));
   }
 
-  PathPieces &Pieces = D->getMutablePieces();
-  bool ShouldConvert = getAnalyzerOptions().shouldDisplayNotesAsEvents();
-  // For path diagnostic consumers that don't support extra notes,
-  // we may optionally convert those to path notes.
-  for (auto I = exampleReport->getNotes().rbegin(),
-            E = exampleReport->getNotes().rend(); I != E; ++I) {
-    const PathDiagnosticNotePiece *Piece = *I;
-    // FIXME: getNotes() was supposed to return a list of shared pointers,
-    // and then we wouldn't normally create a new piece here,
-    // unless ShouldConvert is set.
-    PathDiagnosticPiece *ConvertedPiece =
-        ShouldConvert
-            ? static_cast<PathDiagnosticPiece *>(new PathDiagnosticEventPiece(
-                  Piece->getLocation(), Piece->getString()))
-            : static_cast<PathDiagnosticPiece *>(new PathDiagnosticNotePiece(
-                  Piece->getLocation(), Piece->getString()));
-    for (const auto &R : Piece->getRanges())
-      ConvertedPiece->addRange(R);
-
-    Pieces.push_front(ConvertedPiece);
-  }
-
   // Get the meta data.
   const BugReport::ExtraTextList &Meta = exampleReport->getExtraText();
   for (BugReport::ExtraTextList::const_iterator i = Meta.begin(),
@@ -3556,13 +3520,6 @@
   // FIXME: Print which macro is being invoked.
 }
 
-LLVM_DUMP_METHOD void PathDiagnosticNotePiece::dump() const {
-  llvm::errs() << "NOTE\n--------------\n";
-  llvm::errs() << getString() << "\n";
-  llvm::errs() << " ---- at ----\n";
-  getLocation().dump();
-}
-
 LLVM_DUMP_METHOD void PathDiagnosticLocation::dump() const {
   if (!isValid()) {
     llvm::errs() << "<INVALID>\n";
diff --git a/clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp b/clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
index f157c3d..3a18956 100644
--- a/clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
+++ b/clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
@@ -152,30 +152,13 @@
   }
 
   // Process the path.
-  // Maintain the counts of extra note pieces separately.
-  unsigned TotalPieces = path.size();
-  unsigned TotalNotePieces =
-      std::count_if(path.begin(), path.end(),
-                    [](const IntrusiveRefCntPtr<PathDiagnosticPiece> &p) {
-                      return isa<PathDiagnosticNotePiece>(p.get());
-                    });
+  unsigned n = path.size();
+  unsigned max = n;
 
-  unsigned TotalRegularPieces = TotalPieces - TotalNotePieces;
-  unsigned NumRegularPieces = TotalRegularPieces;
-  unsigned NumNotePieces = TotalNotePieces;
-
-  for (auto I = path.rbegin(), E = path.rend(); I != E; ++I) {
-    if (isa<PathDiagnosticNotePiece>(I->get())) {
-      // This adds diagnostic bubbles, but not navigation.
-      // Navigation through note pieces would be added later,
-      // as a separate pass through the piece list.
-      HandlePiece(R, FID, **I, NumNotePieces, TotalNotePieces);
-      --NumNotePieces;
-    } else {
-      HandlePiece(R, FID, **I, NumRegularPieces, TotalRegularPieces);
-      --NumRegularPieces;
-    }
-  }
+  for (PathPieces::const_reverse_iterator I = path.rbegin(),
+       E = path.rend();
+        I != E; ++I, --n)
+    HandlePiece(R, FID, **I, n, max);
 
   // Add line numbers, header, footer, etc.
 
@@ -209,38 +192,24 @@
   int ColumnNumber = path.back()->getLocation().asLocation().getExpansionColumnNumber();
 
   // Add the name of the file as an <h1> tag.
+
   {
     std::string s;
     llvm::raw_string_ostream os(s);
 
     os << "<!-- REPORTHEADER -->\n"
-       << "<h3>Bug Summary</h3>\n<table class=\"simpletable\">\n"
+      << "<h3>Bug Summary</h3>\n<table class=\"simpletable\">\n"
           "<tr><td class=\"rowname\">File:</td><td>"
-       << html::EscapeText(DirName)
-       << html::EscapeText(Entry->getName())
-       << "</td></tr>\n<tr><td class=\"rowname\">Warning:</td><td>"
-          "<a href=\"#EndPath\">line "
-       << LineNumber
-       << ", column "
-       << ColumnNumber
-       << "</a><br />"
-       << D.getVerboseDescription() << "</td></tr>\n";
-
-    // The navigation across the extra notes pieces.
-    unsigned NumExtraPieces = 0;
-    for (const auto &Piece : path) {
-      if (const auto *P = dyn_cast<PathDiagnosticNotePiece>(Piece.get())) {
-        int LineNumber =
-            P->getLocation().asLocation().getExpansionLineNumber();
-        int ColumnNumber =
-            P->getLocation().asLocation().getExpansionColumnNumber();
-        os << "<tr><td class=\"rowname\">Note:</td><td>"
-           << "<a href=\"#Note" << NumExtraPieces << "\">line "
-           << LineNumber << ", column " << ColumnNumber << "</a><br />"
-           << P->getString() << "</td></tr>";
-        ++NumExtraPieces;
-      }
-    }
+      << html::EscapeText(DirName)
+      << html::EscapeText(Entry->getName())
+      << "</td></tr>\n<tr><td class=\"rowname\">Location:</td><td>"
+         "<a href=\"#EndPath\">line "
+      << LineNumber
+      << ", column "
+      << ColumnNumber
+      << "</a></td></tr>\n"
+         "<tr><td class=\"rowname\">Description:</td><td>"
+      << D.getVerboseDescription() << "</td></tr>\n";
 
     // Output any other meta data.
 
@@ -416,20 +385,13 @@
   // Create the html for the message.
 
   const char *Kind = nullptr;
-  bool IsNote = false;
-  bool SuppressIndex = (max == 1);
   switch (P.getKind()) {
   case PathDiagnosticPiece::Call:
-      llvm_unreachable("Calls and extra notes should already be handled");
+      llvm_unreachable("Calls should already be handled");
   case PathDiagnosticPiece::Event:  Kind = "Event"; break;
   case PathDiagnosticPiece::ControlFlow: Kind = "Control"; break;
     // Setting Kind to "Control" is intentional.
   case PathDiagnosticPiece::Macro: Kind = "Control"; break;
-  case PathDiagnosticPiece::Note:
-    Kind = "Note";
-    IsNote = true;
-    SuppressIndex = true;
-    break;
   }
 
   std::string sbuf;
@@ -437,9 +399,7 @@
 
   os << "\n<tr><td class=\"num\"></td><td class=\"line\"><div id=\"";
 
-  if (IsNote)
-    os << "Note" << num;
-  else if (num == max)
+  if (num == max)
     os << "EndPath";
   else
     os << "Path" << num;
@@ -501,7 +461,7 @@
 
   os << "\">";
 
-  if (!SuppressIndex) {
+  if (max > 1) {
     os << "<table class=\"msgT\"><tr><td valign=\"top\">";
     os << "<div class=\"PathIndex";
     if (Kind) os << " PathIndex" << Kind;
@@ -541,7 +501,7 @@
 
     os << "':\n";
 
-    if (!SuppressIndex) {
+    if (max > 1) {
       os << "</td>";
       if (num < max) {
         os << "<td><div class=\"PathNav\"><a href=\"#";
@@ -563,7 +523,7 @@
   else {
     os << html::EscapeText(P.getString());
 
-    if (!SuppressIndex) {
+    if (max > 1) {
       os << "</td>";
       if (num < max) {
         os << "<td><div class=\"PathNav\"><a href=\"#";
diff --git a/clang/lib/StaticAnalyzer/Core/PathDiagnostic.cpp b/clang/lib/StaticAnalyzer/Core/PathDiagnostic.cpp
index 5675cb2..9d2f7e8 100644
--- a/clang/lib/StaticAnalyzer/Core/PathDiagnostic.cpp
+++ b/clang/lib/StaticAnalyzer/Core/PathDiagnostic.cpp
@@ -60,7 +60,6 @@
 PathDiagnosticCallPiece::~PathDiagnosticCallPiece() {}
 PathDiagnosticControlFlowPiece::~PathDiagnosticControlFlowPiece() {}
 PathDiagnosticMacroPiece::~PathDiagnosticMacroPiece() {}
-PathDiagnosticNotePiece::~PathDiagnosticNotePiece() {}
 
 void PathPieces::flattenTo(PathPieces &Primary, PathPieces &Current,
                            bool ShouldFlattenMacros) const {
@@ -96,7 +95,6 @@
     }
     case PathDiagnosticPiece::Event:
     case PathDiagnosticPiece::ControlFlow:
-    case PathDiagnosticPiece::Note:
       Current.push_back(Piece);
       break;
     }
@@ -356,16 +354,15 @@
   }
 
   switch (X.getKind()) {
-    case PathDiagnosticPiece::ControlFlow:
+    case clang::ento::PathDiagnosticPiece::ControlFlow:
       return compareControlFlow(cast<PathDiagnosticControlFlowPiece>(X),
                                 cast<PathDiagnosticControlFlowPiece>(Y));
-    case PathDiagnosticPiece::Event:
-    case PathDiagnosticPiece::Note:
+    case clang::ento::PathDiagnosticPiece::Event:
       return None;
-    case PathDiagnosticPiece::Macro:
+    case clang::ento::PathDiagnosticPiece::Macro:
       return compareMacro(cast<PathDiagnosticMacroPiece>(X),
                           cast<PathDiagnosticMacroPiece>(Y));
-    case PathDiagnosticPiece::Call:
+    case clang::ento::PathDiagnosticPiece::Call:
       return compareCall(cast<PathDiagnosticCallPiece>(X),
                          cast<PathDiagnosticCallPiece>(Y));
   }
@@ -1113,10 +1110,6 @@
     ID.Add(**I);
 }
 
-void PathDiagnosticNotePiece::Profile(llvm::FoldingSetNodeID &ID) const {
-  PathDiagnosticSpotPiece::Profile(ID);
-}
-
 void PathDiagnostic::Profile(llvm::FoldingSetNodeID &ID) const {
   ID.Add(getLocation());
   ID.AddString(BugType);
diff --git a/clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp b/clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
index c5263ee..206156c 100644
--- a/clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
+++ b/clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
@@ -281,9 +281,6 @@
       ReportMacro(o, cast<PathDiagnosticMacroPiece>(P), FM, SM, LangOpts,
                   indent, depth);
       break;
-    case PathDiagnosticPiece::Note:
-      // FIXME: Extend the plist format to support those.
-      break;
   }
 }
 
diff --git a/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp b/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
index 8bd0e12..3b55a1d 100644
--- a/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
+++ b/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
@@ -113,28 +113,16 @@
       Diag.Report(WarnLoc, WarnID) << PD->getShortDescription()
                                    << PD->path.back()->getRanges();
 
-      // First, add extra notes, even if paths should not be included.
-      for (const auto &Piece : PD->path) {
-        if (!isa<PathDiagnosticNotePiece>(Piece.get()))
-          continue;
-
-        SourceLocation NoteLoc = Piece->getLocation().asLocation();
-        Diag.Report(NoteLoc, NoteID) << Piece->getString()
-                                     << Piece->getRanges();
-      }
-
       if (!IncludePath)
         continue;
 
-      // Then, add the path notes if necessary.
       PathPieces FlatPath = PD->path.flatten(/*ShouldFlattenMacros=*/true);
-      for (const auto &Piece : FlatPath) {
-        if (isa<PathDiagnosticNotePiece>(Piece.get()))
-          continue;
-
-        SourceLocation NoteLoc = Piece->getLocation().asLocation();
-        Diag.Report(NoteLoc, NoteID) << Piece->getString()
-                                     << Piece->getRanges();
+      for (PathPieces::const_iterator PI = FlatPath.begin(),
+                                      PE = FlatPath.end();
+           PI != PE; ++PI) {
+        SourceLocation NoteLoc = (*PI)->getLocation().asLocation();
+        Diag.Report(NoteLoc, NoteID) << (*PI)->getString()
+                                     << (*PI)->getRanges();
       }
     }
   }