diff options
Diffstat (limited to 'tools/driver')
-rw-r--r-- | tools/driver/CMakeLists.txt | 73 | ||||
-rw-r--r-- | tools/driver/Makefile | 2 | ||||
-rw-r--r-- | tools/driver/cc1_main.cpp | 7 | ||||
-rw-r--r-- | tools/driver/cc1as_main.cpp | 46 | ||||
-rw-r--r-- | tools/driver/clang_symlink.cmake | 16 | ||||
-rw-r--r-- | tools/driver/driver.cpp | 202 |
6 files changed, 182 insertions, 164 deletions
diff --git a/tools/driver/CMakeLists.txt b/tools/driver/CMakeLists.txt index 97ac7a4..c94bc77 100644 --- a/tools/driver/CMakeLists.txt +++ b/tools/driver/CMakeLists.txt @@ -29,16 +29,31 @@ target_link_libraries(clang clangLex clangParse clangEdit - clangARCMigrate - clangRewriteCore - clangRewriteFrontend clangSema clangSerialization - clangStaticAnalyzerFrontend - clangStaticAnalyzerCheckers - clangStaticAnalyzerCore ) +if(CLANG_ENABLE_STATIC_ANALYZER) + target_link_libraries(clang + clangStaticAnalyzerFrontend + clangStaticAnalyzerCheckers + clangStaticAnalyzerCore + ) +endif() + +if(CLANG_ENABLE_ARCMT) + target_link_libraries(clang + clangARCMigrate + ) +endif() + +if(CLANG_ENABLE_REWRITER) + target_link_libraries(clang + clangRewriteCore + clangRewriteFrontend + ) +endif() + set_target_properties(clang PROPERTIES VERSION ${CLANG_EXECUTABLE_VERSION}) set_target_properties(clang PROPERTIES ENABLE_EXPORTS 1) @@ -50,19 +65,59 @@ if(UNIX) set(clang_binary "clang${CMAKE_EXECUTABLE_SUFFIX}") else() set(CLANGXX_LINK_OR_COPY copy) - set(clang_binary "${LLVM_BINARY_DIR}/bin/${CMAKE_CFG_INTDIR}/clang${CMAKE_EXECUTABLE_SUFFIX}") + set(clang_binary "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR}/clang${CMAKE_EXECUTABLE_SUFFIX}") endif() # Create the clang++ symlink in the build directory. -set(clang_pp "${LLVM_BINARY_DIR}/bin/${CMAKE_CFG_INTDIR}/clang++${CMAKE_EXECUTABLE_SUFFIX}") +set(clang_pp "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR}/clang++${CMAKE_EXECUTABLE_SUFFIX}") add_custom_command(TARGET clang POST_BUILD COMMAND ${CMAKE_COMMAND} -E ${CLANGXX_LINK_OR_COPY} "${clang_binary}" "${clang_pp}") set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES ${clang_pp}) +# Create the clang-cl symlink in the build directory. +set(clang_cl "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR}/clang-cl${CMAKE_EXECUTABLE_SUFFIX}") +add_custom_command(TARGET clang POST_BUILD + COMMAND ${CMAKE_COMMAND} -E ${CLANGXX_LINK_OR_COPY} "${clang_binary}" "${clang_cl}") + +set_property(DIRECTORY APPEND + PROPERTY ADDITIONAL_MAKE_CLEAN_FILES ${clang_cl}) + install(TARGETS clang RUNTIME DESTINATION bin) -# Create the clang++ symlink at installation time. +# Create the clang++ and clang-cl symlinks at installation time. install(SCRIPT clang_symlink.cmake -DCMAKE_INSTALL_PREFIX=\"${CMAKE_INSTALL_PREFIX}\") + +# Configure plist creation for OS X. +set (TOOL_INFO_PLIST "Info.plist" CACHE STRING "Plist name") +if (APPLE) + if (CLANG_VENDOR) + set(TOOL_INFO_NAME "${CLANG_VENDOR} clang") + else() + set(TOOL_INFO_NAME "clang") + endif() + + set(TOOL_INFO_UTI "${CLANG_VENDOR_UTI}") + set(TOOL_INFO_VERSION "${CLANG_VERSION}") + if (LLVM_SUBMIT_VERSION) + set(TOOL_INFO_BUILD_VERSION + "${LLVM_SUBMIT_VERSION}.${LLVM_SUBMIT_SUBVERSION}") + endif() + + set(TOOL_INFO_PLIST_OUT "${CMAKE_CURRENT_BINARY_DIR}/${TOOL_INFO_PLIST}") + target_link_libraries(clang + "-Wl,-sectcreate,__TEXT,__info_plist,${TOOL_INFO_PLIST_OUT}") + configure_file("${TOOL_INFO_PLIST}.in" "${TOOL_INFO_PLIST_OUT}" @ONLY) + + set(TOOL_INFO_UTI) + set(TOOL_INFO_NAME) + set(TOOL_INFO_VERSION) + set(TOOL_INFO_BUILD_VERSION) +endif() + +if(CLANG_ORDER_FILE) + target_link_libraries(clang "-Wl,-order_file,${CLANG_ORDER_FILE}") +endif() + diff --git a/tools/driver/Makefile b/tools/driver/Makefile index cdf3b52..f7a9f8f 100644 --- a/tools/driver/Makefile +++ b/tools/driver/Makefile @@ -30,7 +30,7 @@ TOOL_INFO_PLIST := Info.plist include $(CLANG_LEVEL)/../../Makefile.config LINK_COMPONENTS := $(TARGETS_TO_BUILD) asmparser bitreader bitwriter codegen \ - instrumentation ipo irreader linker selectiondag + instrumentation ipo irreader linker selectiondag option USEDLIBS = clangFrontendTool.a clangFrontend.a clangDriver.a \ clangSerialization.a clangCodeGen.a clangParse.a clangSema.a diff --git a/tools/driver/cc1_main.cpp b/tools/driver/cc1_main.cpp index 35cf5b8..5b3b5ad 100644 --- a/tools/driver/cc1_main.cpp +++ b/tools/driver/cc1_main.cpp @@ -13,10 +13,8 @@ // //===----------------------------------------------------------------------===// -#include "clang/Driver/Arg.h" -#include "clang/Driver/ArgList.h" +#include "llvm/Option/Arg.h" #include "clang/Driver/DriverDiagnostic.h" -#include "clang/Driver/OptTable.h" #include "clang/Driver/Options.h" #include "clang/Frontend/CompilerInstance.h" #include "clang/Frontend/CompilerInvocation.h" @@ -26,6 +24,8 @@ #include "clang/FrontendTool/Utils.h" #include "llvm/ADT/Statistic.h" #include "llvm/LinkAllPasses.h" +#include "llvm/Option/ArgList.h" +#include "llvm/Option/OptTable.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/ManagedStatic.h" #include "llvm/Support/Signals.h" @@ -34,6 +34,7 @@ #include "llvm/Support/raw_ostream.h" #include <cstdio> using namespace clang; +using namespace llvm::opt; //===----------------------------------------------------------------------===// // Main driver diff --git a/tools/driver/cc1as_main.cpp b/tools/driver/cc1as_main.cpp index 232ea2f..31cd236 100644 --- a/tools/driver/cc1as_main.cpp +++ b/tools/driver/cc1as_main.cpp @@ -14,14 +14,12 @@ #include "clang/Basic/Diagnostic.h" #include "clang/Basic/DiagnosticOptions.h" -#include "clang/Driver/Arg.h" -#include "clang/Driver/ArgList.h" #include "clang/Driver/CC1AsOptions.h" #include "clang/Driver/DriverDiagnostic.h" -#include "clang/Driver/OptTable.h" #include "clang/Driver/Options.h" #include "clang/Frontend/FrontendDiagnostic.h" #include "clang/Frontend/TextDiagnosticPrinter.h" +#include "clang/Frontend/Utils.h" #include "llvm/ADT/OwningPtr.h" #include "llvm/ADT/StringSwitch.h" #include "llvm/ADT/Triple.h" @@ -37,8 +35,12 @@ #include "llvm/MC/MCStreamer.h" #include "llvm/MC/MCSubtargetInfo.h" #include "llvm/MC/MCTargetAsmParser.h" +#include "llvm/Option/Arg.h" +#include "llvm/Option/ArgList.h" +#include "llvm/Option/OptTable.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/ErrorHandling.h" +#include "llvm/Support/FileSystem.h" #include "llvm/Support/FormattedStream.h" #include "llvm/Support/Host.h" #include "llvm/Support/ManagedStatic.h" @@ -55,6 +57,7 @@ using namespace clang; using namespace clang::driver; using namespace llvm; +using namespace llvm::opt; namespace { @@ -181,7 +184,7 @@ bool AssemblerInvocation::CreateFromArgs(AssemblerInvocation &Opts, // Language Options Opts.IncludePaths = Args->getAllArgValues(OPT_I); Opts.NoInitialTextSection = Args->hasArg(OPT_n); - Opts.SaveTemporaryLabels = Args->hasArg(OPT_L); + Opts.SaveTemporaryLabels = Args->hasArg(OPT_msave_temp_labels); Opts.GenDwarfForAssembly = Args->hasArg(OPT_g); Opts.DwarfDebugFlags = Args->getLastArgValue(OPT_dwarf_debug_flags); Opts.DwarfDebugProducer = Args->getLastArgValue(OPT_dwarf_debug_producer); @@ -203,8 +206,6 @@ bool AssemblerInvocation::CreateFromArgs(AssemblerInvocation &Opts, } } Opts.LLVMArgs = Args->getAllArgValues(OPT_mllvm); - if (Args->hasArg(OPT_fatal_warnings)) - Opts.LLVMArgs.push_back("-fatal-assembler-warnings"); Opts.OutputPath = Args->getLastArgValue(OPT_o); if (Arg *A = Args->getLastArg(OPT_filetype)) { StringRef Name = A->getValue(); @@ -224,14 +225,14 @@ bool AssemblerInvocation::CreateFromArgs(AssemblerInvocation &Opts, Opts.ShowVersion = Args->hasArg(OPT_version); // Transliterate Options - Opts.OutputAsmVariant = Args->getLastArgIntValue(OPT_output_asm_variant, - 0, Diags); + Opts.OutputAsmVariant = + getLastArgIntValue(*Args.get(), OPT_output_asm_variant, 0, Diags); Opts.ShowEncoding = Args->hasArg(OPT_show_encoding); Opts.ShowInst = Args->hasArg(OPT_show_inst); // Assemble Options - Opts.RelaxAll = Args->hasArg(OPT_relax_all); - Opts.NoExecStack = Args->hasArg(OPT_no_exec_stack); + Opts.RelaxAll = Args->hasArg(OPT_mrelax_all); + Opts.NoExecStack = Args->hasArg(OPT_mno_exec_stack); return Success; } @@ -245,12 +246,12 @@ static formatted_raw_ostream *GetOutputStream(AssemblerInvocation &Opts, // Make sure that the Out file gets unlinked from the disk if we get a // SIGINT. if (Opts.OutputPath != "-") - sys::RemoveFileOnSignal(sys::Path(Opts.OutputPath)); + sys::RemoveFileOnSignal(Opts.OutputPath); std::string Error; raw_fd_ostream *Out = - new raw_fd_ostream(Opts.OutputPath.c_str(), Error, - (Binary ? raw_fd_ostream::F_Binary : 0)); + new raw_fd_ostream(Opts.OutputPath.c_str(), Error, + (Binary ? sys::fs::F_Binary : sys::fs::F_None)); if (!Error.empty()) { Diags.Report(diag::err_fe_unable_to_open_output) << Opts.OutputPath << Error; @@ -287,12 +288,12 @@ static bool ExecuteAssembler(AssemblerInvocation &Opts, // it later. SrcMgr.setIncludeDirs(Opts.IncludePaths); - OwningPtr<MCAsmInfo> MAI(TheTarget->createMCAsmInfo(Opts.Triple)); - assert(MAI && "Unable to create target asm info!"); - OwningPtr<MCRegisterInfo> MRI(TheTarget->createMCRegInfo(Opts.Triple)); assert(MRI && "Unable to create target register info!"); + OwningPtr<MCAsmInfo> MAI(TheTarget->createMCAsmInfo(*MRI, Opts.Triple)); + assert(MAI && "Unable to create target asm info!"); + bool IsBinary = Opts.OutputType == AssemblerInvocation::FT_Obj; formatted_raw_ostream *Out = GetOutputStream(Opts, Diags, IsBinary); if (!Out) @@ -301,7 +302,7 @@ static bool ExecuteAssembler(AssemblerInvocation &Opts, // FIXME: This is not pretty. MCContext has a ptr to MCObjectFileInfo and // MCObjectFileInfo needs a MCContext reference in order to initialize itself. OwningPtr<MCObjectFileInfo> MOFI(new MCObjectFileInfo()); - MCContext Ctx(*MAI, *MRI, MOFI.get(), &SrcMgr); + MCContext Ctx(MAI.get(), MRI.get(), MOFI.get(), &SrcMgr); // FIXME: Assembler behavior can change with -static. MOFI->InitMCObjectFileInfo(Opts.Triple, Reloc::Default, CodeModel::Default, Ctx); @@ -341,7 +342,7 @@ static bool ExecuteAssembler(AssemblerInvocation &Opts, MCAsmBackend *MAB = 0; if (Opts.ShowEncoding) { CE = TheTarget->createMCCodeEmitter(*MCII, *MRI, *STI, Ctx); - MAB = TheTarget->createMCAsmBackend(Opts.Triple, Opts.CPU); + MAB = TheTarget->createMCAsmBackend(*MRI, Opts.Triple, Opts.CPU); } Str.reset(TheTarget->createAsmStreamer(Ctx, *Out, /*asmverbose*/true, /*useLoc*/ true, @@ -355,7 +356,8 @@ static bool ExecuteAssembler(AssemblerInvocation &Opts, assert(Opts.OutputType == AssemblerInvocation::FT_Obj && "Invalid file type!"); MCCodeEmitter *CE = TheTarget->createMCCodeEmitter(*MCII, *MRI, *STI, Ctx); - MCAsmBackend *MAB = TheTarget->createMCAsmBackend(Opts.Triple, Opts.CPU); + MCAsmBackend *MAB = TheTarget->createMCAsmBackend(*MRI, Opts.Triple, + Opts.CPU); Str.reset(TheTarget->createMCObjectStreamer(Opts.Triple, Ctx, *MAB, *Out, CE, Opts.RelaxAll, Opts.NoExecStack)); @@ -364,7 +366,7 @@ static bool ExecuteAssembler(AssemblerInvocation &Opts, OwningPtr<MCAsmParser> Parser(createMCAsmParser(SrcMgr, Ctx, *Str.get(), *MAI)); - OwningPtr<MCTargetAsmParser> TAP(TheTarget->createMCAsmParser(*STI, *Parser)); + OwningPtr<MCTargetAsmParser> TAP(TheTarget->createMCAsmParser(*STI, *Parser, *MCII)); if (!TAP) { Diags.Report(diag::err_target_unknown_triple) << Opts.Triple; return false; @@ -379,7 +381,7 @@ static bool ExecuteAssembler(AssemblerInvocation &Opts, // Delete output on errors. if (!Success && Opts.OutputPath != "-") - sys::Path(Opts.OutputPath).eraseFromDisk(); + sys::fs::remove(Opts.OutputPath); return Success; } @@ -426,7 +428,7 @@ int cc1as_main(const char **ArgBegin, const char **ArgEnd, // Honor -help. if (Asm.ShowHelp) { - OwningPtr<driver::OptTable> Opts(driver::createCC1AsOptTable()); + OwningPtr<OptTable> Opts(driver::createCC1AsOptTable()); Opts->PrintHelp(llvm::outs(), "clang -cc1as", "Clang Integrated Assembler"); return 0; } diff --git a/tools/driver/clang_symlink.cmake b/tools/driver/clang_symlink.cmake index c7341cb..c012595 100644 --- a/tools/driver/clang_symlink.cmake +++ b/tools/driver/clang_symlink.cmake @@ -19,9 +19,25 @@ endif() set(bindir "${CLANGXX_DESTDIR}${CMAKE_INSTALL_PREFIX}/bin/") set(clang "clang${EXECUTABLE_SUFFIX}") set(clangxx "clang++${EXECUTABLE_SUFFIX}") +set(clang_cl "clang-cl${EXECUTABLE_SUFFIX}") +set(cl "cl${EXECUTABLE_SUFFIX}") message("Creating clang++ executable based on ${clang}") execute_process( COMMAND "${CMAKE_COMMAND}" -E ${CLANGXX_LINK_OR_COPY} "${clang}" "${clangxx}" WORKING_DIRECTORY "${bindir}") + +message("Creating clang-cl executable based on ${clang}") + +execute_process( + COMMAND "${CMAKE_COMMAND}" -E ${CLANGXX_LINK_OR_COPY} "${clang}" "${clang_cl}" + WORKING_DIRECTORY "${bindir}") + +if (WIN32) + message("Creating cl executable based on ${clang}") + + execute_process( + COMMAND "${CMAKE_COMMAND}" -E ${CLANGXX_LINK_OR_COPY} "${clang}" "../msbuild-bin/${cl}" + WORKING_DIRECTORY "${bindir}") +endif() diff --git a/tools/driver/driver.cpp b/tools/driver/driver.cpp index 4c40da3..3a6a09b 100644 --- a/tools/driver/driver.cpp +++ b/tools/driver/driver.cpp @@ -14,12 +14,9 @@ #include "clang/Basic/CharInfo.h" #include "clang/Basic/DiagnosticOptions.h" -#include "clang/Driver/ArgList.h" #include "clang/Driver/Compilation.h" #include "clang/Driver/Driver.h" #include "clang/Driver/DriverDiagnostic.h" -#include "clang/Driver/OptTable.h" -#include "clang/Driver/Option.h" #include "clang/Driver/Options.h" #include "clang/Frontend/CompilerInvocation.h" #include "clang/Frontend/TextDiagnosticPrinter.h" @@ -28,6 +25,11 @@ #include "llvm/ADT/OwningPtr.h" #include "llvm/ADT/SmallString.h" #include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/STLExtras.h" +#include "llvm/Option/ArgList.h" +#include "llvm/Option/OptTable.h" +#include "llvm/Option/Option.h" +#include "llvm/Support/CommandLine.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/Host.h" @@ -35,6 +37,7 @@ #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/Path.h" #include "llvm/Support/PrettyStackTrace.h" +#include "llvm/Support/Process.h" #include "llvm/Support/Program.h" #include "llvm/Support/Regex.h" #include "llvm/Support/Signals.h" @@ -45,15 +48,16 @@ #include "llvm/Support/system_error.h" using namespace clang; using namespace clang::driver; +using namespace llvm::opt; -llvm::sys::Path GetExecutablePath(const char *Argv0, bool CanonicalPrefixes) { +std::string GetExecutablePath(const char *Argv0, bool CanonicalPrefixes) { if (!CanonicalPrefixes) - return llvm::sys::Path(Argv0); + return Argv0; // This just needs to be some symbol in the binary; C++ doesn't // allow taking the address of ::main however. void *P = (void*) (intptr_t) GetExecutablePath; - return llvm::sys::Path::GetMainExecutable(Argv0, P); + return llvm::sys::fs::getMainExecutable(Argv0, P); } static const char *SaveStringInSet(std::set<std::string> &SavedStrings, @@ -187,78 +191,6 @@ extern int cc1_main(const char **ArgBegin, const char **ArgEnd, extern int cc1as_main(const char **ArgBegin, const char **ArgEnd, const char *Argv0, void *MainAddr); -static void ExpandArgsFromBuf(const char *Arg, - SmallVectorImpl<const char*> &ArgVector, - std::set<std::string> &SavedStrings) { - const char *FName = Arg + 1; - OwningPtr<llvm::MemoryBuffer> MemBuf; - if (llvm::MemoryBuffer::getFile(FName, MemBuf)) { - ArgVector.push_back(SaveStringInSet(SavedStrings, Arg)); - return; - } - - const char *Buf = MemBuf->getBufferStart(); - char InQuote = ' '; - std::string CurArg; - - for (const char *P = Buf; ; ++P) { - if (*P == '\0' || (isWhitespace(*P) && InQuote == ' ')) { - if (!CurArg.empty()) { - - if (CurArg[0] != '@') { - ArgVector.push_back(SaveStringInSet(SavedStrings, CurArg)); - } else { - ExpandArgsFromBuf(CurArg.c_str(), ArgVector, SavedStrings); - } - - CurArg = ""; - } - if (*P == '\0') - break; - else - continue; - } - - if (isWhitespace(*P)) { - if (InQuote != ' ') - CurArg.push_back(*P); - continue; - } - - if (*P == '"' || *P == '\'') { - if (InQuote == *P) - InQuote = ' '; - else if (InQuote == ' ') - InQuote = *P; - else - CurArg.push_back(*P); - continue; - } - - if (*P == '\\') { - ++P; - if (*P != '\0') - CurArg.push_back(*P); - continue; - } - CurArg.push_back(*P); - } -} - -static void ExpandArgv(int argc, const char **argv, - SmallVectorImpl<const char*> &ArgVector, - std::set<std::string> &SavedStrings) { - for (int i = 0; i < argc; ++i) { - const char *Arg = argv[i]; - if (Arg[0] != '@') { - ArgVector.push_back(SaveStringInSet(SavedStrings, std::string(Arg))); - continue; - } - - ExpandArgsFromBuf(Arg, ArgVector, SavedStrings); - } -} - static void ParseProgName(SmallVectorImpl<const char *> &ArgVector, std::set<std::string> &SavedStrings, Driver &TheDriver) @@ -279,21 +211,24 @@ static void ParseProgName(SmallVectorImpl<const char *> &ArgVector, // is gets added via -target as implicit first argument. static const struct { const char *Suffix; - bool IsCXX; - bool IsCPP; + const char *ModeFlag; } suffixes [] = { - { "clang", false, false }, - { "clang++", true, false }, - { "clang-c++", true, false }, - { "clang-cc", false, false }, - { "clang-cpp", false, true }, - { "clang-g++", true, false }, - { "clang-gcc", false, false }, - { "cc", false, false }, - { "cpp", false, true }, - { "++", true, false }, + { "clang", 0 }, + { "clang++", "--driver-mode=g++" }, + { "clang-c++", "--driver-mode=g++" }, + { "clang-cc", 0 }, + { "clang-cpp", "--driver-mode=cpp" }, + { "clang-g++", "--driver-mode=g++" }, + { "clang-gcc", 0 }, + { "clang-cl", "--driver-mode=cl" }, + { "cc", 0 }, + { "cpp", "--driver-mode=cpp" }, + { "cl" , "--driver-mode=cl" }, + { "++", "--driver-mode=g++" }, }; std::string ProgName(llvm::sys::path::stem(ArgVector[0])); + std::transform(ProgName.begin(), ProgName.end(), ProgName.begin(), + toLowercase); StringRef ProgNameRef(ProgName); StringRef Prefix; @@ -304,10 +239,11 @@ static void ParseProgName(SmallVectorImpl<const char *> &ArgVector, for (i = 0; i < sizeof(suffixes) / sizeof(suffixes[0]); ++i) { if (ProgNameRef.endswith(suffixes[i].Suffix)) { FoundMatch = true; - if (suffixes[i].IsCXX) - TheDriver.CCCIsCXX = true; - if (suffixes[i].IsCPP) - TheDriver.CCCIsCPP = true; + SmallVectorImpl<const char *>::iterator it = ArgVector.begin(); + if (it != ArgVector.end()) + ++it; + if (suffixes[i].ModeFlag) + ArgVector.insert(it, suffixes[i].ModeFlag); break; } } @@ -334,20 +270,41 @@ static void ParseProgName(SmallVectorImpl<const char *> &ArgVector, SmallVectorImpl<const char *>::iterator it = ArgVector.begin(); if (it != ArgVector.end()) ++it; - ArgVector.insert(it, SaveStringInSet(SavedStrings, Prefix)); - ArgVector.insert(it, - SaveStringInSet(SavedStrings, std::string("-target"))); + const char* Strings[] = + { SaveStringInSet(SavedStrings, std::string("-target")), + SaveStringInSet(SavedStrings, Prefix) }; + ArgVector.insert(it, Strings, Strings + llvm::array_lengthof(Strings)); } } +namespace { + class StringSetSaver : public llvm::cl::StringSaver { + public: + StringSetSaver(std::set<std::string> &Storage) : Storage(Storage) {} + const char *SaveString(const char *Str) LLVM_OVERRIDE { + return SaveStringInSet(Storage, Str); + } + private: + std::set<std::string> &Storage; + }; +} + int main(int argc_, const char **argv_) { llvm::sys::PrintStackTraceOnErrorSignal(); llvm::PrettyStackTraceProgram X(argc_, argv_); - std::set<std::string> SavedStrings; - SmallVector<const char*, 256> argv; + SmallVector<const char *, 256> argv; + llvm::SpecificBumpPtrAllocator<char> ArgAllocator; + llvm::error_code EC = llvm::sys::Process::GetArgumentVector( + argv, llvm::ArrayRef<const char *>(argv_, argc_), ArgAllocator); + if (EC) { + llvm::errs() << "error: couldn't get arguments: " << EC.message() << '\n'; + return 1; + } - ExpandArgv(argc_, argv_, argv, SavedStrings); + std::set<std::string> SavedStrings; + StringSetSaver Saver(SavedStrings); + llvm::cl::ExpandResponseFiles(Saver, llvm::cl::TokenizeGNUCommandLine, argv); // Handle -cc1 integrated tools. if (argv.size() > 1 && StringRef(argv[1]).startswith("-cc1")) { @@ -378,36 +335,17 @@ int main(int argc_, const char **argv_) { if (const char *OverrideStr = ::getenv("QA_OVERRIDE_GCC3_OPTIONS")) { // FIXME: Driver shouldn't take extra initial argument. ApplyQAOverride(argv, OverrideStr, SavedStrings); - } else if (const char *Cur = ::getenv("CCC_ADD_ARGS")) { - // FIXME: Driver shouldn't take extra initial argument. - std::vector<const char*> ExtraArgs; - - for (;;) { - const char *Next = strchr(Cur, ','); - - if (Next) { - ExtraArgs.push_back(SaveStringInSet(SavedStrings, - std::string(Cur, Next))); - Cur = Next + 1; - } else { - if (*Cur != '\0') - ExtraArgs.push_back(SaveStringInSet(SavedStrings, Cur)); - break; - } - } - - argv.insert(&argv[1], ExtraArgs.begin(), ExtraArgs.end()); } - llvm::sys::Path Path = GetExecutablePath(argv[0], CanonicalPrefixes); + std::string Path = GetExecutablePath(argv[0], CanonicalPrefixes); IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts = new DiagnosticOptions; { - // Note that ParseDiagnosticArgs() uses the cc1 option table. - OwningPtr<OptTable> CC1Opts(createDriverOptTable()); + OwningPtr<OptTable> Opts(createDriverOptTable()); unsigned MissingArgIndex, MissingArgCount; - OwningPtr<InputArgList> Args(CC1Opts->ParseArgs(argv.begin()+1, argv.end(), - MissingArgIndex, MissingArgCount)); + OwningPtr<InputArgList> Args(Opts->ParseArgs(argv.begin()+1, argv.end(), + MissingArgIndex, + MissingArgCount)); // We ignore MissingArgCount and the return value of ParseDiagnosticArgs. // Any errors that would be diagnosed here will also be diagnosed later, // when the DiagnosticsEngine actually exists. @@ -417,14 +355,20 @@ int main(int argc_, const char **argv_) { // DiagnosticOptions instance. TextDiagnosticPrinter *DiagClient = new TextDiagnosticPrinter(llvm::errs(), &*DiagOpts); - DiagClient->setPrefix(llvm::sys::path::filename(Path.str())); + + // If the clang binary happens to be named cl.exe for compatibility reasons, + // use clang-cl.exe as the prefix to avoid confusion between clang and MSVC. + StringRef ExeBasename(llvm::sys::path::filename(Path)); + if (ExeBasename.equals_lower("cl.exe")) + ExeBasename = "clang-cl.exe"; + DiagClient->setPrefix(ExeBasename); + IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs()); DiagnosticsEngine Diags(DiagID, &*DiagOpts, DiagClient); ProcessWarningOptions(Diags, *DiagOpts, /*ReportDiags=*/false); - Driver TheDriver(Path.str(), llvm::sys::getDefaultTargetTriple(), - "a.out", Diags); + Driver TheDriver(Path, llvm::sys::getDefaultTargetTriple(), "a.out", Diags); // Attempt to find the original path used to invoke the driver, to determine // the installed path. We do this manually, because we want to support that @@ -434,10 +378,10 @@ int main(int argc_, const char **argv_) { // Do a PATH lookup, if there are no directory components. if (llvm::sys::path::filename(InstalledPath) == InstalledPath) { - llvm::sys::Path Tmp = llvm::sys::Program::FindProgramByName( + std::string Tmp = llvm::sys::FindProgramByName( llvm::sys::path::filename(InstalledPath.str())); if (!Tmp.empty()) - InstalledPath = Tmp.str(); + InstalledPath = Tmp; } llvm::sys::fs::make_absolute(InstalledPath); InstalledPath = llvm::sys::path::parent_path(InstalledPath); |