Update aosp/master Clang for rebase to r222490.

Change-Id: Ic557ac55e97fbf6ee08771c7b7c3594777b0aefd
diff --git a/lib/Tooling/CommonOptionsParser.cpp b/lib/Tooling/CommonOptionsParser.cpp
index e0b844c..f16a6be 100644
--- a/lib/Tooling/CommonOptionsParser.cpp
+++ b/lib/Tooling/CommonOptionsParser.cpp
@@ -25,6 +25,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "llvm/Support/CommandLine.h"
+#include "clang/Tooling/ArgumentsAdjusters.h"
 #include "clang/Tooling/CommonOptionsParser.h"
 #include "clang/Tooling/Tooling.h"
 
@@ -53,6 +54,42 @@
     "\tsuffix of a path in the compile command database.\n"
     "\n";
 
+class ArgumentsAdjustingCompilations : public CompilationDatabase {
+public:
+  ArgumentsAdjustingCompilations(
+      std::unique_ptr<CompilationDatabase> Compilations)
+      : Compilations(std::move(Compilations)) {}
+
+  void appendArgumentsAdjuster(std::unique_ptr<ArgumentsAdjuster> Adjuster) {
+    Adjusters.push_back(std::move(Adjuster));
+  }
+
+  std::vector<CompileCommand>
+  getCompileCommands(StringRef FilePath) const override {
+    return adjustCommands(Compilations->getCompileCommands(FilePath));
+  }
+
+  std::vector<std::string> getAllFiles() const override {
+    return Compilations->getAllFiles();
+  }
+
+  std::vector<CompileCommand> getAllCompileCommands() const override {
+    return adjustCommands(Compilations->getAllCompileCommands());
+  }
+
+private:
+  std::unique_ptr<CompilationDatabase> Compilations;
+  std::vector<std::unique_ptr<ArgumentsAdjuster>> Adjusters;
+
+  std::vector<CompileCommand>
+  adjustCommands(std::vector<CompileCommand> Commands) const {
+    for (CompileCommand &Command : Commands)
+      for (const auto &Adjuster : Adjusters)
+        Command.CommandLine = Adjuster->Adjust(Command.CommandLine);
+    return Commands;
+  }
+};
+
 CommonOptionsParser::CommonOptionsParser(int &argc, const char **argv,
                                          cl::OptionCategory &Category,
                                          const char *Overview) {
@@ -65,6 +102,16 @@
       cl::Positional, cl::desc("<source0> [... <sourceN>]"), cl::OneOrMore,
       cl::cat(Category));
 
+  static cl::list<std::string> ArgsAfter(
+      "extra-arg",
+      cl::desc("Additional argument to append to the compiler command line"),
+      cl::cat(Category));
+
+  static cl::list<std::string> ArgsBefore(
+      "extra-arg-before",
+      cl::desc("Additional argument to prepend to the compiler command line"),
+      cl::cat(Category));
+
   // Hide unrelated options.
   StringMap<cl::Option*> Options;
   cl::getRegisteredOptions(Options);
@@ -82,13 +129,23 @@
   if (!Compilations) {
     std::string ErrorMessage;
     if (!BuildPath.empty()) {
-      Compilations.reset(CompilationDatabase::autoDetectFromDirectory(
-                              BuildPath, ErrorMessage));
+      Compilations =
+          CompilationDatabase::autoDetectFromDirectory(BuildPath, ErrorMessage);
     } else {
-      Compilations.reset(CompilationDatabase::autoDetectFromSource(
-                              SourcePaths[0], ErrorMessage));
+      Compilations = CompilationDatabase::autoDetectFromSource(SourcePaths[0],
+                                                               ErrorMessage);
     }
     if (!Compilations)
       llvm::report_fatal_error(ErrorMessage);
   }
+  auto AdjustingCompilations =
+      llvm::make_unique<ArgumentsAdjustingCompilations>(
+          std::move(Compilations));
+  AdjustingCompilations->appendArgumentsAdjuster(
+      llvm::make_unique<InsertArgumentAdjuster>(ArgsBefore,
+                                                InsertArgumentAdjuster::BEGIN));
+  AdjustingCompilations->appendArgumentsAdjuster(
+      llvm::make_unique<InsertArgumentAdjuster>(ArgsAfter,
+                                                InsertArgumentAdjuster::END));
+  Compilations = std::move(AdjustingCompilations);
 }