components/llvm/patches/019-21870099-clang.patch
changeset 5434 9f55c805ce9d
equal deleted inserted replaced
5428:3c05d530e67e 5434:9f55c805ce9d
       
     1 # 21870099 - 128 bytes for a filesystem path is definitely not enough
       
     2 # 21870283 - llvm::sys::Process::GetArgumentVector should overload for
       
     3 # std::vector
       
     4 # For upstream - maybe.
       
     5 --- tools/clang/tools/driver/driver.cpp	2015-09-20 11:19:37.402058833 -0700
       
     6 +++ tools/clang/tools/driver/driver.cpp	2015-09-20 17:00:21.850124658 -0700
       
     7 @@ -89,21 +89,21 @@
       
     8  ///  and the following argument.
       
     9  ///
       
    10  ///  'Ox': Removes all flags matching 'O' or 'O[sz0-9]' and adds 'Ox'
       
    11  ///  at the end of the command line.
       
    12  ///
       
    13  /// \param OS - The stream to write edit information to.
       
    14  /// \param Args - The vector of command line arguments.
       
    15  /// \param Edit - The override command to perform.
       
    16  /// \param SavedStrings - Set to use for storing string representations.
       
    17  static void ApplyOneQAOverride(raw_ostream &OS,
       
    18 -                               SmallVectorImpl<const char*> &Args,
       
    19 +                               std::vector<const char*> &Args,
       
    20                                 StringRef Edit,
       
    21                                 std::set<std::string> &SavedStrings) {
       
    22    // This does not need to be efficient.
       
    23  
       
    24    if (Edit[0] == '^') {
       
    25      const char *Str =
       
    26        GetStableCStr(SavedStrings, Edit.substr(1));
       
    27      OS << "### Adding argument " << Str << " at beginning\n";
       
    28      Args.insert(Args.begin() + 1, Str);
       
    29    } else if (Edit[0] == '+') {
       
    30 @@ -161,21 +161,21 @@
       
    31      }
       
    32      OS << "### Adding argument " << Edit << " at end\n";
       
    33      Args.push_back(GetStableCStr(SavedStrings, '-' + Edit.str()));
       
    34    } else {
       
    35      OS << "### Unrecognized edit: " << Edit << "\n";
       
    36    }
       
    37  }
       
    38  
       
    39  /// ApplyQAOverride - Apply a comma separate list of edits to the
       
    40  /// input argument lists. See ApplyOneQAOverride.
       
    41 -static void ApplyQAOverride(SmallVectorImpl<const char*> &Args,
       
    42 +static void ApplyQAOverride(std::vector<const char*> &Args,
       
    43                              const char *OverrideStr,
       
    44                              std::set<std::string> &SavedStrings) {
       
    45    raw_ostream *OS = &llvm::errs();
       
    46  
       
    47    if (OverrideStr[0] == '#') {
       
    48      ++OverrideStr;
       
    49      OS = &llvm::nulls();
       
    50    }
       
    51  
       
    52    *OS << "### CCC_OVERRIDE_OPTIONS: " << OverrideStr << "\n";
       
    53 @@ -223,21 +223,21 @@
       
    54        {"cl", "--driver-mode=cl"},
       
    55        {"++", "--driver-mode=g++"},
       
    56    };
       
    57  
       
    58    for (size_t i = 0; i < llvm::array_lengthof(DriverSuffixes); ++i)
       
    59      if (ProgName.endswith(DriverSuffixes[i].Suffix))
       
    60        return &DriverSuffixes[i];
       
    61    return nullptr;
       
    62  }
       
    63  
       
    64 -static void ParseProgName(SmallVectorImpl<const char *> &ArgVector,
       
    65 +static void ParseProgName(std::vector<const char *> &ArgVector,
       
    66                            std::set<std::string> &SavedStrings) {
       
    67    // Try to infer frontend type and default target from the program name by
       
    68    // comparing it against DriverSuffixes in order.
       
    69  
       
    70    // If there is a match, the function tries to identify a target as prefix.
       
    71    // E.g. "x86_64-linux-clang" as interpreted as suffix "clang" with target
       
    72    // prefix "x86_64-linux". If such a target prefix is found, is gets added via
       
    73    // -target as implicit first argument.
       
    74  
       
    75    std::string ProgName =llvm::sys::path::stem(ArgVector[0]);
       
    76 @@ -325,39 +325,40 @@
       
    77    // use clang-cl.exe as the prefix to avoid confusion between clang and MSVC.
       
    78    StringRef ExeBasename(llvm::sys::path::filename(Path));
       
    79    if (ExeBasename.equals_lower("cl.exe"))
       
    80      ExeBasename = "clang-cl.exe";
       
    81    DiagClient->setPrefix(ExeBasename);
       
    82  }
       
    83  
       
    84  // This lets us create the DiagnosticsEngine with a properly-filled-out
       
    85  // DiagnosticOptions instance.
       
    86  static DiagnosticOptions *
       
    87 -CreateAndPopulateDiagOpts(SmallVectorImpl<const char *> &argv) {
       
    88 -  auto *DiagOpts = new DiagnosticOptions;
       
    89 +CreateAndPopulateDiagOpts(std::vector<const char *> &argv) {
       
    90 +  auto *DiagOpts = new DiagnosticOptions();
       
    91    std::unique_ptr<OptTable> Opts(createDriverOptTable());
       
    92    unsigned MissingArgIndex, MissingArgCount;
       
    93    std::unique_ptr<InputArgList> Args(Opts->ParseArgs(
       
    94 -      argv.begin() + 1, argv.end(), MissingArgIndex, MissingArgCount));
       
    95 +      argv.data() + 1, argv.data() + argv.size(), MissingArgIndex,
       
    96 +      MissingArgCount));
       
    97    // We ignore MissingArgCount and the return value of ParseDiagnosticArgs.
       
    98    // Any errors that would be diagnosed here will also be diagnosed later,
       
    99    // when the DiagnosticsEngine actually exists.
       
   100    (void) ParseDiagnosticArgs(*DiagOpts, *Args);
       
   101    return DiagOpts;
       
   102  }
       
   103  
       
   104 -static void SetInstallDir(SmallVectorImpl<const char *> &argv,
       
   105 +static void SetInstallDir(std::vector<const char *> &argv,
       
   106                            Driver &TheDriver) {
       
   107    // Attempt to find the original path used to invoke the driver, to determine
       
   108    // the installed path. We do this manually, because we want to support that
       
   109    // path being a symlink.
       
   110 -  SmallString<128> InstalledPath(argv[0]);
       
   111 +  SmallString<PATH_MAX> InstalledPath(argv[0]);
       
   112  
       
   113    // Do a PATH lookup, if there are no directory components.
       
   114    if (llvm::sys::path::filename(InstalledPath) == InstalledPath)
       
   115      if (llvm::ErrorOr<std::string> Tmp = llvm::sys::findProgramByName(
       
   116              llvm::sys::path::filename(InstalledPath.str())))
       
   117        InstalledPath = *Tmp;
       
   118    llvm::sys::fs::make_absolute(InstalledPath);
       
   119    InstalledPath = llvm::sys::path::parent_path(InstalledPath);
       
   120    if (llvm::sys::fs::exists(InstalledPath.c_str()))
       
   121      TheDriver.setInstalledDir(InstalledPath);
       
   122 @@ -375,24 +376,26 @@
       
   123    return 1;
       
   124  }
       
   125  
       
   126  int main(int argc_, const char **argv_) {
       
   127    llvm::sys::PrintStackTraceOnErrorSignal();
       
   128    llvm::PrettyStackTraceProgram X(argc_, argv_);
       
   129  
       
   130    if (llvm::sys::Process::FixupStandardFileDescriptors())
       
   131      return 1;
       
   132  
       
   133 -  SmallVector<const char *, 256> argv;
       
   134 +  std::vector<const char*> argv;
       
   135    llvm::SpecificBumpPtrAllocator<char> ArgAllocator;
       
   136 -  std::error_code EC = llvm::sys::Process::GetArgumentVector(
       
   137 -      argv, llvm::makeArrayRef(argv_, argc_), ArgAllocator);
       
   138 +  llvm::ArrayRef<const char*> AAR = llvm::makeArrayRef(argv_, argc_);
       
   139 +  std::error_code EC =
       
   140 +    llvm::sys::Process::GetArgumentVector(argv, AAR);
       
   141 +
       
   142    if (EC) {
       
   143      llvm::errs() << "error: couldn't get arguments: " << EC.message() << '\n';
       
   144      return 1;
       
   145    }
       
   146  
       
   147    std::set<std::string> SavedStrings;
       
   148    StringSetSaver Saver(SavedStrings);
       
   149  
       
   150    // Determines whether we want nullptr markers in argv to indicate response
       
   151    // files end-of-lines. We only use this for the /LINK driver argument.
       
   152 @@ -459,21 +462,21 @@
       
   153    Driver TheDriver(Path, llvm::sys::getDefaultTargetTriple(), Diags);
       
   154    SetInstallDir(argv, TheDriver);
       
   155  
       
   156    llvm::InitializeAllTargets();
       
   157    ParseProgName(argv, SavedStrings);
       
   158  
       
   159    SetBackdoorDriverOutputsFromEnvVars(TheDriver);
       
   160  
       
   161    std::unique_ptr<Compilation> C(TheDriver.BuildCompilation(argv));
       
   162    int Res = 0;
       
   163 -  SmallVector<std::pair<int, const Command *>, 4> FailingCommands;
       
   164 +  SmallVector<std::pair<int, const Command *>, 8> FailingCommands;
       
   165    if (C.get())
       
   166      Res = TheDriver.ExecuteCompilation(*C, FailingCommands);
       
   167  
       
   168    // Force a crash to test the diagnostics.
       
   169    if (::getenv("FORCE_CLANG_DIAGNOSTICS_CRASH")) {
       
   170      Diags.Report(diag::err_drv_force_crash) << "FORCE_CLANG_DIAGNOSTICS_CRASH";
       
   171  
       
   172      // Pretend that every command failed.
       
   173      FailingCommands.clear();
       
   174      for (const auto &J : C->getJobs())