<commit_before>//===--- Driver.cpp - Clang GCC Compatible Driver -------------------------===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

#include "clang/Driver/Driver.h"

#include "clang/Driver/Action.h"
#include "clang/Driver/Arg.h"
#include "clang/Driver/ArgList.h"
#include "clang/Driver/Compilation.h"
#include "clang/Driver/DriverDiagnostic.h"
#include "clang/Driver/HostInfo.h"
#include "clang/Driver/Job.h"
#include "clang/Driver/OptTable.h"
#include "clang/Driver/Option.h"
#include "clang/Driver/Options.h"
#include "clang/Driver/Tool.h"
#include "clang/Driver/ToolChain.h"
#include "clang/Driver/Types.h"

#include "clang/Basic/Version.h"

#include "llvm/Config/config.h"
#include "llvm/ADT/StringSet.h"
#include "llvm/ADT/OwningPtr.h"
#include "llvm/Support/PrettyStackTrace.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/System/Path.h"
#include "llvm/System/Program.h"

#include "InputInfo.h"

#include <map>

#ifdef __CYGWIN__
#include <cygwin/version.h>
#if defined(CYGWIN_VERSION_DLL_MAJOR) && CYGWIN_VERSION_DLL_MAJOR<1007
#define IS_CYGWIN15 1
#endif
#endif

using namespace clang::driver;
using namespace clang;

Driver::Driver(llvm::StringRef _ClangExecutable,
               llvm::StringRef _DefaultHostTriple,
               llvm::StringRef _DefaultImageName,
               bool IsProduction, bool CXXIsProduction,
               Diagnostic &_Diags)
  : Opts(createDriverOptTable()), Diags(_Diags),
    ClangExecutable(_ClangExecutable), DefaultHostTriple(_DefaultHostTriple),
    DefaultImageName(_DefaultImageName),
    DriverTitle("clang \"gcc-compatible\" driver"),
    Host(0),
    CCPrintOptionsFilename(0), CCCIsCXX(false),
    CCCEcho(false), CCCPrintBindings(false), CCPrintOptions(false), CCCGenericGCCName("gcc"),
    CheckInputsExist(true), CCCUseClang(true), CCCUseClangCXX(true),
    CCCUseClangCPP(true), CCCUsePCH(true), SuppressMissingInputWarning(false) {
  if (IsProduction) {
    // In a "production" build, only use clang on architectures we expect to
    // work, and don't use clang C++.
    //
    // During development its more convenient to always have the driver use
    // clang, but we don't want users to be confused when things don't work, or
    // to file bugs for things we don't support.
    CCCClangArchs.insert(llvm::Triple::x86);
    CCCClangArchs.insert(llvm::Triple::x86_64);
    CCCClangArchs.insert(llvm::Triple::arm);

    if (!CXXIsProduction)
      CCCUseClangCXX = false;
  }

  llvm::sys::Path Executable(ClangExecutable);
  Name = Executable.getBasename();
  Dir = Executable.getDirname();

  // Compute the path to the resource directory.
  llvm::sys::Path P(Dir);
  P.eraseComponent(); // Remove /bin from foo/bin
  P.appendComponent("lib");
  P.appendComponent("clang");
  P.appendComponent(CLANG_VERSION_STRING);
  ResourceDir = P.str();
}

Driver::~Driver() {
  delete Opts;
  delete Host;
}

InputArgList *Driver::ParseArgStrings(const char **ArgBegin,
                                      const char **ArgEnd) {
  llvm::PrettyStackTraceString CrashInfo("Command line argument parsing");
  unsigned MissingArgIndex, MissingArgCount;
  InputArgList *Args = getOpts().ParseArgs(ArgBegin, ArgEnd,
                                           MissingArgIndex, MissingArgCount);

  // Check for missing argument error.
  if (MissingArgCount)
    Diag(clang::diag::err_drv_missing_argument)
      << Args->getArgString(MissingArgIndex) << MissingArgCount;

  // Check for unsupported options.
  for (ArgList::const_iterator it = Args->begin(), ie = Args->end();
       it != ie; ++it) {<commit_msg>Use CLANG_RESOURCE_DIR define if one is provided, otherwise use the default of '../lib/clang/<version>'. Actually use '..' rather than removing the trailing component to correctly handle paths containing '.' or symlinks in the presence of -no-canonical-prefixes, etc. This shouldn't change any existing behavior.<commit_after>//===--- Driver.cpp - Clang GCC Compatible Driver -------------------------===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

#include "clang/Driver/Driver.h"

#include "clang/Driver/Action.h"
#include "clang/Driver/Arg.h"
#include "clang/Driver/ArgList.h"
#include "clang/Driver/Compilation.h"
#include "clang/Driver/DriverDiagnostic.h"
#include "clang/Driver/HostInfo.h"
#include "clang/Driver/Job.h"
#include "clang/Driver/OptTable.h"
#include "clang/Driver/Option.h"
#include "clang/Driver/Options.h"
#include "clang/Driver/Tool.h"
#include "clang/Driver/ToolChain.h"
#include "clang/Driver/Types.h"

#include "clang/Basic/Version.h"

#include "llvm/Config/config.h"
#include "llvm/ADT/StringSet.h"
#include "llvm/ADT/OwningPtr.h"
#include "llvm/Support/PrettyStackTrace.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/System/Path.h"
#include "llvm/System/Program.h"

#include "InputInfo.h"

#include <map>

#ifdef __CYGWIN__
#include <cygwin/version.h>
#if defined(CYGWIN_VERSION_DLL_MAJOR) && CYGWIN_VERSION_DLL_MAJOR<1007
#define IS_CYGWIN15 1
#endif
#endif

using namespace clang::driver;
using namespace clang;

Driver::Driver(llvm::StringRef _ClangExecutable,
               llvm::StringRef _DefaultHostTriple,
               llvm::StringRef _DefaultImageName,
               bool IsProduction, bool CXXIsProduction,
               Diagnostic &_Diags)
  : Opts(createDriverOptTable()), Diags(_Diags),
    ClangExecutable(_ClangExecutable), DefaultHostTriple(_DefaultHostTriple),
    DefaultImageName(_DefaultImageName),
    DriverTitle("clang \"gcc-compatible\" driver"),
    Host(0),
    CCPrintOptionsFilename(0), CCCIsCXX(false),
    CCCEcho(false), CCCPrintBindings(false), CCPrintOptions(false), CCCGenericGCCName("gcc"),
    CheckInputsExist(true), CCCUseClang(true), CCCUseClangCXX(true),
    CCCUseClangCPP(true), CCCUsePCH(true), SuppressMissingInputWarning(false) {
  if (IsProduction) {
    // In a "production" build, only use clang on architectures we expect to
    // work, and don't use clang C++.
    //
    // During development its more convenient to always have the driver use
    // clang, but we don't want users to be confused when things don't work, or
    // to file bugs for things we don't support.
    CCCClangArchs.insert(llvm::Triple::x86);
    CCCClangArchs.insert(llvm::Triple::x86_64);
    CCCClangArchs.insert(llvm::Triple::arm);

    if (!CXXIsProduction)
      CCCUseClangCXX = false;
  }

  llvm::sys::Path Executable(ClangExecutable);
  Name = Executable.getBasename();
  Dir = Executable.getDirname();

  // Compute the path to the resource directory.
  llvm::StringRef ClangResourceDir(CLANG_RESOURCE_DIR);
  llvm::sys::Path P(Dir);
  if (ClangResourceDir != "") {
    P.appendComponent(ClangResourceDir);
  } else {
    P.appendComponent(".."); // Walk up from a 'bin' subdirectory.
    P.appendComponent("lib");
    P.appendComponent("clang");
    P.appendComponent(CLANG_VERSION_STRING);
  }
  ResourceDir = P.str();
}

Driver::~Driver() {
  delete Opts;
  delete Host;
}

InputArgList *Driver::ParseArgStrings(const char **ArgBegin,
                                      const char **ArgEnd) {
  llvm::PrettyStackTraceString CrashInfo("Command line argument parsing");
  unsigned MissingArgIndex, MissingArgCount;
  InputArgList *Args = getOpts().ParseArgs(ArgBegin, ArgEnd,
                                           MissingArgIndex, MissingArgCount);

  // Check for missing argument error.
  if (MissingArgCount)
    Diag(clang::diag::err_drv_missing_argument)
      << Args->getArgString(MissingArgIndex) << MissingArgCount;

  // Check for unsupported options.
  for (ArgList::const_iterator it = Args->begin(), ie = Args->end();
       it != ie; ++it) {
{'fraction_non_alphanumeric': 0.15053363117398857, 'fraction_numerical': 0.0037230081906180195, 'mean_word_length': 3.5022346368715085, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3998644', 'n_tokens_mistral': 2592, 'n_tokens_neox': 2490, 'n_words': 565}