jansvoboda11 created this revision.
jansvoboda11 added reviewers: Bigcheese, dexonsmith.
Herald added subscribers: steakhal, ASDenysPetrov, martong, Charusso, dkrupp, 
donat.nagy, Szelethus, mikhail.ramalho, a.sidorin, szepet, baloghadamsoftware, 
xazax.hun.
jansvoboda11 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This patch replaces `StringMap<...>` with `std::map<std::string, ...>` in 
`AnalyzerOptions::ConfigTable`. It seems to be the only non-owning reference to 
command line arguments in the whole `CompilerInvocation`, which would introduce 
a lot of complexity with round-tripping arguments (D94472 
<https://reviews.llvm.org/D94472>).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D95629

Files:
  clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/StaticAnalyzer/Checkers/DebugCheckers.cpp
  clang/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
  clang/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp

Index: clang/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp
===================================================================
--- clang/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp
+++ clang/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp
@@ -358,7 +358,7 @@
   // to it's default value, and if we're in non-compatibility mode, we'll also
   // emit an error.
 
-  StringRef SuppliedValue = It.first->getValue();
+  StringRef SuppliedValue = It.first->second;
 
   if (Option.OptionType == "bool") {
     if (SuppliedValue != "true" && SuppliedValue != "false") {
@@ -367,7 +367,7 @@
             << FullOption << "a boolean value";
       }
 
-      It.first->setValue(std::string(Option.DefaultValStr));
+      It.first->second = std::string(Option.DefaultValStr);
     }
     return;
   }
@@ -381,7 +381,7 @@
             << FullOption << "an integer value";
       }
 
-      It.first->setValue(std::string(Option.DefaultValStr));
+      It.first->second = std::string(Option.DefaultValStr);
     }
     return;
   }
@@ -495,7 +495,7 @@
     StringRef SuppliedCheckerOrPackage;
     StringRef SuppliedOption;
     std::tie(SuppliedCheckerOrPackage, SuppliedOption) =
-        Config.getKey().split(':');
+        StringRef(Config.first).split(':');
 
     if (SuppliedOption.empty())
       continue;
Index: clang/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
===================================================================
--- clang/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
+++ clang/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
@@ -126,7 +126,7 @@
     ConfigTable::const_iterator I =
         Config.find((Twine(CheckerName) + ":" + OptionName).str());
     if (I != E)
-      return StringRef(I->getValue());
+      return StringRef(I->second);
     size_t Pos = CheckerName.rfind('.');
     if (Pos == StringRef::npos)
       break;
Index: clang/lib/StaticAnalyzer/Checkers/DebugCheckers.cpp
===================================================================
--- clang/lib/StaticAnalyzer/Checkers/DebugCheckers.cpp
+++ clang/lib/StaticAnalyzer/Checkers/DebugCheckers.cpp
@@ -259,9 +259,9 @@
 class ConfigDumper : public Checker< check::EndOfTranslationUnit > {
   typedef AnalyzerOptions::ConfigTable Table;
 
-  static int compareEntry(const Table::MapEntryTy *const *LHS,
-                          const Table::MapEntryTy *const *RHS) {
-    return (*LHS)->getKey().compare((*RHS)->getKey());
+  static int compareEntry(const Table::value_type *const *LHS,
+                          const Table::value_type *const *RHS) {
+    return (*LHS)->first.compare((*RHS)->first);
   }
 
 public:
@@ -270,7 +270,7 @@
                                  BugReporter &BR) const {
     const Table &Config = mgr.options.Config;
 
-    SmallVector<const Table::MapEntryTy *, 32> Keys;
+    SmallVector<const Table::value_type *, 32> Keys;
     for (Table::const_iterator I = Config.begin(), E = Config.end(); I != E;
          ++I)
       Keys.push_back(&*I);
@@ -278,7 +278,7 @@
 
     llvm::errs() << "[config]\n";
     for (unsigned I = 0, E = Keys.size(); I != E; ++I)
-      llvm::errs() << Keys[I]->getKey() << " = "
+      llvm::errs() << Keys[I]->first << " = "
                    << (Keys[I]->second.empty() ? "\"\"" : Keys[I]->second)
                    << '\n';
   }
Index: clang/lib/Frontend/CompilerInvocation.cpp
===================================================================
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -859,7 +859,7 @@
       }
 
       A->claim();
-      Opts.Config[key] = std::string(val);
+      Opts.Config[std::string(key)] = std::string(val);
     }
   }
 
@@ -881,7 +881,8 @@
 
 static StringRef getStringOption(AnalyzerOptions::ConfigTable &Config,
                                  StringRef OptionName, StringRef DefaultVal) {
-  return Config.insert({OptionName, std::string(DefaultVal)}).first->second;
+  return Config.insert({std::string(OptionName), std::string(DefaultVal)})
+      .first->second;
 }
 
 static void initOption(AnalyzerOptions::ConfigTable &Config,
Index: clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
===================================================================
--- clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
+++ clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
@@ -18,9 +18,9 @@
 #include "clang/Basic/LLVM.h"
 #include "llvm/ADT/IntrusiveRefCntPtr.h"
 #include "llvm/ADT/Optional.h"
-#include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/StringSwitch.h"
+#include <map>
 #include <string>
 #include <utility>
 #include <vector>
@@ -162,7 +162,7 @@
 /// make sense for things that do not affect the actual analysis.
 class AnalyzerOptions : public RefCountedBase<AnalyzerOptions> {
 public:
-  using ConfigTable = llvm::StringMap<std::string>;
+  using ConfigTable = std::map<std::string, std::string>;
 
   /// Retrieves the list of checkers generated from Checkers.td. This doesn't
   /// contain statically linked but non-generated checkers and plugin checkers!
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
  • [PATCH] D95629: [c... Jan Svoboda via Phabricator via cfe-commits

Reply via email to