From 76b86c2e79a58910a641d449f229889d671d8a38 Mon Sep 17 00:00:00 2001 From: Hans Wennborg Date: Thu, 18 Jul 2013 20:29:38 +0000 Subject: [PATCH] Turn Driver::CCCIsCXX and CCCIsCPP into a single Mode enum, and add a new option --driver-mode= to control it explicitly. The CCCIsCXX and CCCIsCPP flags were non-overlapping, i.e. there are currently really three modes that Clang can run in: gcc, g++ or cpp, so it makes sense to represent them as an enum. Having a command line flag to control it helps testing. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@186605 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Driver/Driver.h | 13 ++++++-- include/clang/Driver/Options.td | 4 +-- lib/Driver/Driver.cpp | 50 +++++++++++++++++++++++------ lib/Driver/Tools.cpp | 38 +++++++++++----------- test/Driver/ccc-as-cpp.c | 5 +-- test/Driver/hexagon-toolchain-elf.c | 16 ++++----- test/Driver/hexagon-toolchain.c | 16 ++++----- test/Driver/immediate-options.c | 4 +-- test/lit.cfg | 7 +++- tools/driver/driver.cpp | 32 +++++++++--------- 10 files changed, 113 insertions(+), 72 deletions(-) diff --git a/include/clang/Driver/Driver.h b/include/clang/Driver/Driver.h index 1459e0d371..18d81e1b5f 100644 --- a/include/clang/Driver/Driver.h +++ b/include/clang/Driver/Driver.h @@ -51,6 +51,12 @@ class Driver { DiagnosticsEngine &Diags; + enum DriverMode { + GCCMode, + GXXMode, + CPPMode + } Mode; + public: // Diag - Forwarding function for diagnostics. DiagnosticBuilder Diag(unsigned DiagID) const { @@ -117,10 +123,10 @@ public: InputList; /// Whether the driver should follow g++ like behavior. - unsigned CCCIsCXX : 1; + bool CCCIsCXX() const { return Mode == GXXMode; } /// Whether the driver is just the preprocessor. - unsigned CCCIsCPP : 1; + bool CCCIsCPP() const { return Mode == CPPMode; } /// Echo commands while executing (in -v style). unsigned CCCEcho : 1; @@ -236,6 +242,9 @@ public: /// @name Driver Steps /// @{ + /// ParseDriverMode - Look for and handle the driver mode option in Args. + void ParseDriverMode(ArrayRef Args); + /// ParseArgStrings - Parse the given list of strings into an /// ArgList. llvm::opt::InputArgList *ParseArgStrings(ArrayRef Args); diff --git a/include/clang/Driver/Options.td b/include/clang/Driver/Options.td index 7e7e111aa4..fb37228a4f 100644 --- a/include/clang/Driver/Options.td +++ b/include/clang/Driver/Options.td @@ -112,8 +112,8 @@ def ccc_debug_Group : OptionGroup<"">, Group, HelpText<"DEBUG/DEVELOPMENT OPTIONS">; class CCCDriverOpt : Group, Flags<[DriverOption, HelpHidden]>; -def ccc_cxx : Flag<["-"], "ccc-cxx">, CCCDriverOpt, - HelpText<"Act as a C++ driver">; +def driver_mode : Joined<["--"], "driver-mode=">, CCCDriverOpt, + HelpText<"Set the driver mode to either 'gcc', 'g++' or 'cpp'">; def ccc_echo : Flag<["-"], "ccc-echo">, CCCDriverOpt, HelpText<"Echo commands before running them">; def ccc_gcc_name : Separate<["-"], "ccc-gcc-name">, CCCDriverOpt, diff --git a/lib/Driver/Driver.cpp b/lib/Driver/Driver.cpp index f49e79046a..a5910be5ec 100644 --- a/lib/Driver/Driver.cpp +++ b/lib/Driver/Driver.cpp @@ -21,6 +21,7 @@ #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/OwningPtr.h" #include "llvm/ADT/StringSet.h" +#include "llvm/ADT/StringSwitch.h" #include "llvm/Option/Arg.h" #include "llvm/Option/ArgList.h" #include "llvm/Option/OptTable.h" @@ -53,8 +54,8 @@ Driver::Driver(StringRef ClangExecutable, DefaultImageName(DefaultImageName), DriverTitle("clang LLVM compiler"), CCPrintOptionsFilename(0), CCPrintHeadersFilename(0), - CCLogDiagnosticsFilename(0), CCCIsCXX(false), - CCCIsCPP(false),CCCEcho(false), CCCPrintBindings(false), + CCLogDiagnosticsFilename(0), Mode(GCCMode), + CCCEcho(false), CCCPrintBindings(false), CCPrintOptions(false), CCPrintHeaders(false), CCLogDiagnostics(false), CCGenDiagnostics(false), CCCGenericGCCName(""), CheckInputsExist(true), CCCUsePCH(true), SuppressMissingInputWarning(false) { @@ -81,6 +82,29 @@ Driver::~Driver() { delete I->second; } +void Driver::ParseDriverMode(ArrayRef Args) { + const std::string OptName = + getOpts().getOption(options::OPT_driver_mode).getPrefixedName(); + + for (size_t I = 0, E = Args.size(); I != E; ++I) { + const StringRef Arg = Args[I]; + if (!Arg.startswith(OptName)) + continue; + + const StringRef Value = Arg.drop_front(OptName.size()); + const unsigned M = llvm::StringSwitch(Value) + .Case("gcc", GCCMode) + .Case("g++", GXXMode) + .Case("cpp", CPPMode) + .Default(~0U); + + if (M != ~0U) + Mode = static_cast(M); + else + Diag(diag::err_drv_unsupported_option_argument) << OptName << Value; + } +} + InputArgList *Driver::ParseArgStrings(ArrayRef ArgList) { llvm::PrettyStackTraceString CrashInfo("Command line argument parsing"); unsigned MissingArgIndex, MissingArgCount; @@ -121,7 +145,7 @@ const { phases::ID FinalPhase; // -{E,M,MM} only run the preprocessor. - if (CCCIsCPP || + if (CCCIsCPP() || (PhaseArg = DAL.getLastArg(options::OPT_E)) || (PhaseArg = DAL.getLastArg(options::OPT_M, options::OPT_MM))) { FinalPhase = phases::Preprocess; @@ -249,6 +273,10 @@ Compilation *Driver::BuildCompilation(ArrayRef ArgList) { } } + // We look for the driver mode option early, because the mode can affect + // how other options are parsed. + ParseDriverMode(ArgList.slice(1)); + // FIXME: What are we going to do with -V and -b? // FIXME: This stuff needs to go into the Compilation, not the driver. @@ -271,7 +299,6 @@ Compilation *Driver::BuildCompilation(ArrayRef ArgList) { CCCPrintOptions = Args->hasArg(options::OPT_ccc_print_options); CCCPrintActions = Args->hasArg(options::OPT_ccc_print_phases); CCCPrintBindings = Args->hasArg(options::OPT_ccc_print_bindings); - CCCIsCXX = Args->hasArg(options::OPT_ccc_cxx) || CCCIsCXX; CCCEcho = Args->hasArg(options::OPT_ccc_echo); if (const Arg *A = Args->getLastArg(options::OPT_ccc_gcc_name)) CCCGenericGCCName = A->getValue(); @@ -361,7 +388,7 @@ void Driver::generateCompilationDiagnostics(Compilation &C, "crash backtrace, preprocessed source, and associated run script."; // Suppress driver output and emit preprocessor output to temp file. - CCCIsCPP = true; + Mode = CPPMode; CCGenDiagnostics = true; C.getArgs().AddFlagArg(0, Opts->getOption(options::OPT_frewrite_includes)); @@ -917,7 +944,7 @@ void Driver::BuildInputs(const ToolChain &TC, const DerivedArgList &Args, // // Otherwise emit an error but still use a valid type to avoid // spurious errors (e.g., no inputs). - if (!Args.hasArgNoClaim(options::OPT_E) && !CCCIsCPP) + if (!Args.hasArgNoClaim(options::OPT_E) && !CCCIsCPP()) Diag(clang::diag::err_drv_unknown_stdin_type); Ty = types::TY_C; } else { @@ -929,7 +956,7 @@ void Driver::BuildInputs(const ToolChain &TC, const DerivedArgList &Args, Ty = TC.LookupTypeForExtension(Ext + 1); if (Ty == types::TY_INVALID) { - if (CCCIsCPP) + if (CCCIsCPP()) Ty = types::TY_C; else Ty = types::TY_Object; @@ -937,7 +964,7 @@ void Driver::BuildInputs(const ToolChain &TC, const DerivedArgList &Args, // If the driver is invoked as C++ compiler (like clang++ or c++) it // should autodetect some input files as C++ for g++ compatibility. - if (CCCIsCXX) { + if (CCCIsCXX()) { types::ID OldTy = Ty; Ty = types::lookupCXXTypeForCType(Ty); @@ -1001,7 +1028,7 @@ void Driver::BuildInputs(const ToolChain &TC, const DerivedArgList &Args, } } } - if (CCCIsCPP && Inputs.empty()) { + if (CCCIsCPP() && Inputs.empty()) { // If called as standalone preprocessor, stdin is processed // if no other input is present. unsigned Index = Args.getBaseArgs().MakeIndex("-"); @@ -1052,7 +1079,7 @@ void Driver::BuildActions(const ToolChain &TC, const DerivedArgList &Args, // Special case when final phase determined by binary name, rather than // by a command-line argument with a corresponding Arg. - if (CCCIsCPP) + if (CCCIsCPP()) Diag(clang::diag::warn_drv_input_file_unused_by_cpp) << InputArg->getAsString(Args) << getPhaseName(InitialPhase); @@ -1257,6 +1284,9 @@ void Driver::BuildJobs(Compilation &C) const { // Claim -### here. (void) C.getArgs().hasArg(options::OPT__HASH_HASH_HASH); + // Claim --driver-mode, it was handled earlier. + (void) C.getArgs().hasArg(options::OPT_driver_mode); + for (ArgList::const_iterator it = C.getArgs().begin(), ie = C.getArgs().end(); it != ie; ++it) { Arg *A = *it; diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp index d19486ec61..87fbcd7688 100644 --- a/lib/Driver/Tools.cpp +++ b/lib/Driver/Tools.cpp @@ -45,7 +45,7 @@ using namespace llvm::opt; /// arguments that is shared with gcc. static void CheckPreprocessingOptions(const Driver &D, const ArgList &Args) { if (Arg *A = Args.getLastArg(options::OPT_C, options::OPT_CC)) - if (!Args.hasArg(options::OPT_E) && !D.CCCIsCPP) + if (!Args.hasArg(options::OPT_E) && !D.CCCIsCPP()) D.Diag(diag::err_drv_argument_only_allowed_with) << A->getAsString(Args) << "-E"; } @@ -3985,7 +3985,7 @@ void gcc::Common::ConstructJob(Compilation &C, const JobAction &JA, const char *GCCName; if (!customGCCName.empty()) GCCName = customGCCName.c_str(); - else if (D.CCCIsCXX) { + else if (D.CCCIsCXX()) { GCCName = "g++"; } else GCCName = "gcc"; @@ -4247,7 +4247,7 @@ void hexagon::Link::ConstructJob(Compilation &C, const JobAction &JA, // Libraries //---------------------------------------------------------------------------- if (incStdLib && incDefLibs) { - if (D.CCCIsCXX) { + if (D.CCCIsCXX()) { ToolChain.AddCXXStdlibLibArgs(Args, CmdArgs); CmdArgs.push_back("-lm"); } @@ -4828,7 +4828,7 @@ void darwin::Link::ConstructJob(Compilation &C, const JobAction &JA, if (!Args.hasArg(options::OPT_nostdlib) && !Args.hasArg(options::OPT_nodefaultlibs)) { - if (getToolChain().getDriver().CCCIsCXX) + if (getToolChain().getDriver().CCCIsCXX()) getToolChain().AddCXXStdlibLibArgs(Args, CmdArgs); // link_ssp spec is empty. @@ -5010,7 +5010,7 @@ void solaris::Link::ConstructJob(Compilation &C, const JobAction &JA, CmdArgs.push_back(Args.MakeArgString(LibPath + "values-Xa.o")); CmdArgs.push_back(Args.MakeArgString(GCCLibPath + "crtbegin.o")); } - if (getToolChain().getDriver().CCCIsCXX) + if (getToolChain().getDriver().CCCIsCXX()) CmdArgs.push_back(Args.MakeArgString(LibPath + "cxa_finalize.o")); } @@ -5025,7 +5025,7 @@ void solaris::Link::ConstructJob(Compilation &C, const JobAction &JA, if (!Args.hasArg(options::OPT_nostdlib) && !Args.hasArg(options::OPT_nodefaultlibs)) { - if (getToolChain().getDriver().CCCIsCXX) + if (getToolChain().getDriver().CCCIsCXX()) getToolChain().AddCXXStdlibLibArgs(Args, CmdArgs); CmdArgs.push_back("-lgcc_s"); if (!Args.hasArg(options::OPT_shared)) { @@ -5266,7 +5266,7 @@ void openbsd::Link::ConstructJob(Compilation &C, const JobAction &JA, if (!Args.hasArg(options::OPT_nostdlib) && !Args.hasArg(options::OPT_nodefaultlibs)) { - if (D.CCCIsCXX) { + if (D.CCCIsCXX()) { getToolChain().AddCXXStdlibLibArgs(Args, CmdArgs); if (Args.hasArg(options::OPT_pg)) CmdArgs.push_back("-lm_p"); @@ -5396,7 +5396,7 @@ void bitrig::Link::ConstructJob(Compilation &C, const JobAction &JA, if (!Args.hasArg(options::OPT_nostdlib) && !Args.hasArg(options::OPT_nodefaultlibs)) { - if (D.CCCIsCXX) { + if (D.CCCIsCXX()) { getToolChain().AddCXXStdlibLibArgs(Args, CmdArgs); if (Args.hasArg(options::OPT_pg)) CmdArgs.push_back("-lm_p"); @@ -5636,7 +5636,7 @@ void freebsd::Link::ConstructJob(Compilation &C, const JobAction &JA, if (!Args.hasArg(options::OPT_nostdlib) && !Args.hasArg(options::OPT_nodefaultlibs)) { - if (D.CCCIsCXX) { + if (D.CCCIsCXX()) { ToolChain.AddCXXStdlibLibArgs(Args, CmdArgs); if (Args.hasArg(options::OPT_pg)) CmdArgs.push_back("-lm_p"); @@ -5806,7 +5806,7 @@ void netbsd::Link::ConstructJob(Compilation &C, const JobAction &JA, if (!Args.hasArg(options::OPT_nostdlib) && !Args.hasArg(options::OPT_nodefaultlibs)) { - if (D.CCCIsCXX) { + if (D.CCCIsCXX()) { getToolChain().AddCXXStdlibLibArgs(Args, CmdArgs); CmdArgs.push_back("-lm"); } @@ -5958,23 +5958,23 @@ static void AddLibgcc(llvm::Triple Triple, const Driver &D, bool isAndroid = Triple.getEnvironment() == llvm::Triple::Android; bool StaticLibgcc = Args.hasArg(options::OPT_static_libgcc) || Args.hasArg(options::OPT_static); - if (!D.CCCIsCXX) + if (!D.CCCIsCXX()) CmdArgs.push_back("-lgcc"); if (StaticLibgcc || isAndroid) { - if (D.CCCIsCXX) + if (D.CCCIsCXX()) CmdArgs.push_back("-lgcc"); } else { - if (!D.CCCIsCXX) + if (!D.CCCIsCXX()) CmdArgs.push_back("--as-needed"); CmdArgs.push_back("-lgcc_s"); - if (!D.CCCIsCXX) + if (!D.CCCIsCXX()) CmdArgs.push_back("--no-as-needed"); } if (StaticLibgcc && !isAndroid) CmdArgs.push_back("-lgcc_eh"); - else if (!Args.hasArg(options::OPT_shared) && D.CCCIsCXX) + else if (!Args.hasArg(options::OPT_shared) && D.CCCIsCXX()) CmdArgs.push_back("-lgcc"); // According to Android ABI, we have to link with libdl if we are @@ -6203,7 +6203,7 @@ void gnutools::Link::ConstructJob(Compilation &C, const JobAction &JA, // Call these before we add the C++ ABI library. if (Sanitize.needsUbsanRt()) - addUbsanRTLinux(getToolChain(), Args, CmdArgs, D.CCCIsCXX, + addUbsanRTLinux(getToolChain(), Args, CmdArgs, D.CCCIsCXX(), Sanitize.needsAsanRt() || Sanitize.needsTsanRt() || Sanitize.needsMsanRt() || Sanitize.needsLsanRt()); if (Sanitize.needsAsanRt()) @@ -6218,7 +6218,7 @@ void gnutools::Link::ConstructJob(Compilation &C, const JobAction &JA, // The profile runtime also needs access to system libraries. addProfileRTLinux(getToolChain(), Args, CmdArgs); - if (D.CCCIsCXX && + if (D.CCCIsCXX() && !Args.hasArg(options::OPT_nostdlib) && !Args.hasArg(options::OPT_nodefaultlibs)) { bool OnlyLibstdcxxStatic = Args.hasArg(options::OPT_static_libstdcxx) && @@ -6334,7 +6334,7 @@ void minix::Link::ConstructJob(Compilation &C, const JobAction &JA, if (!Args.hasArg(options::OPT_nostdlib) && !Args.hasArg(options::OPT_nodefaultlibs)) { - if (D.CCCIsCXX) { + if (D.CCCIsCXX()) { getToolChain().AddCXXStdlibLibArgs(Args, CmdArgs); CmdArgs.push_back("-lm"); } @@ -6482,7 +6482,7 @@ void dragonfly::Link::ConstructJob(Compilation &C, const JobAction &JA, } } - if (D.CCCIsCXX) { + if (D.CCCIsCXX()) { getToolChain().AddCXXStdlibLibArgs(Args, CmdArgs); CmdArgs.push_back("-lm"); } diff --git a/test/Driver/ccc-as-cpp.c b/test/Driver/ccc-as-cpp.c index feead5191d..6c004338ed 100644 --- a/test/Driver/ccc-as-cpp.c +++ b/test/Driver/ccc-as-cpp.c @@ -1,6 +1,3 @@ -// REQUIRES: shell -// RUN: ln -sf %clang %T/clang-cpp - // PR13529: Don't crash. -// RUN: %T/clang-cpp -lfoo -M %s 2>&1 | FileCheck --check-prefix=CHECK-PR13529 %s +// RUN: %clang_cpp -lfoo -M %s 2>&1 | FileCheck --check-prefix=CHECK-PR13529 %s // CHECK-PR13529: warning: -lfoo: 'linker' input unused in cpp mode diff --git a/test/Driver/hexagon-toolchain-elf.c b/test/Driver/hexagon-toolchain-elf.c index 945888c5f4..62ad8634d7 100644 --- a/test/Driver/hexagon-toolchain-elf.c +++ b/test/Driver/hexagon-toolchain-elf.c @@ -13,7 +13,7 @@ // CHECK001: "-internal-externc-isystem" "{{.*}}/Inputs/hexagon_tree/qc/bin/../../gnu/hexagon/include" // CHECK001-NEXT: "{{.*}}/Inputs/hexagon_tree/qc/bin/../../gnu/bin{{/|\\}}hexagon-as" -// RUN: %clang -ccc-cxx -x c++ -### -target hexagon-unknown-elf \ +// RUN: %clangxx -### -target hexagon-unknown-elf \ // RUN: -ccc-install-dir %S/Inputs/hexagon_tree/qc/bin \ // RUN: %s 2>&1 \ // RUN: | FileCheck -check-prefix=CHECK002 %s @@ -49,7 +49,7 @@ // CHECK004-NOT: "-internal-externc-isystem" "{{.*}}/Inputs/hexagon_tree/qc/bin/../../gnu/hexagon/include" // CHECK004-NEXT: "{{.*}}/Inputs/hexagon_tree/qc/bin/../../gnu/bin{{/|\\}}hexagon-as" -// RUN: %clang -ccc-cxx -x c++ -### -target hexagon-unknown-elf \ +// RUN: %clangxx -### -target hexagon-unknown-elf \ // RUN: -ccc-install-dir %S/Inputs/hexagon_tree/qc/bin \ // RUN: -nostdlibinc \ // RUN: %s 2>&1 \ @@ -61,7 +61,7 @@ // CHECK005-NOT: "-internal-externc-isystem" "{{.*}}/Inputs/hexagon_tree/qc/bin/../../gnu/hexagon/include" // CHECK005-NEXT: "{{.*}}/Inputs/hexagon_tree/qc/bin/../../gnu/bin{{/|\\}}hexagon-as" -// RUN: %clang -ccc-cxx -x c++ -### -target hexagon-unknown-elf \ +// RUN: %clangxx -### -target hexagon-unknown-elf \ // RUN: -ccc-install-dir %S/Inputs/hexagon_tree/qc/bin \ // RUN: -nostdinc++ \ // RUN: %s 2>&1 \ @@ -155,7 +155,7 @@ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // Defaults for C++ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -// RUN: %clang -ccc-cxx -x c++ -### -target hexagon-unknown-elf \ +// RUN: %clangxx -### -target hexagon-unknown-elf \ // RUN: -ccc-install-dir %S/Inputs/hexagon_tree/qc/bin \ // RUN: %s 2>&1 \ // RUN: | FileCheck -check-prefix=CHECK012 %s @@ -287,7 +287,7 @@ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // -nostdlib, -nostartfiles, -nodefaultlibs // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -// RUN: %clang -ccc-cxx -x c++ -### -target hexagon-unknown-elf \ +// RUN: %clangxx -### -target hexagon-unknown-elf \ // RUN: -ccc-install-dir %S/Inputs/hexagon_tree/qc/bin \ // RUN: -nostdlib \ // RUN: %s 2>&1 \ @@ -313,7 +313,7 @@ // CHECK017-NOT: "--end-group" // CHECK017-NOT: fini.o -// RUN: %clang -ccc-cxx -x c++ -### -target hexagon-unknown-elf \ +// RUN: %clangxx -### -target hexagon-unknown-elf \ // RUN: -ccc-install-dir %S/Inputs/hexagon_tree/qc/bin \ // RUN: -nostartfiles \ // RUN: %s 2>&1 \ @@ -339,7 +339,7 @@ // CHECK018: "--end-group" // CHECK018-NOT: fini.o -// RUN: %clang -ccc-cxx -x c++ -### -target hexagon-unknown-elf \ +// RUN: %clangxx -### -target hexagon-unknown-elf \ // RUN: -ccc-install-dir %S/Inputs/hexagon_tree/qc/bin \ // RUN: -nodefaultlibs \ // RUN: %s 2>&1 \ @@ -421,7 +421,7 @@ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // Other args to pass to linker // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -// RUN: %clang -ccc-cxx -x c++ -### -target hexagon-unknown-elf \ +// RUN: %clangxx -### -target hexagon-unknown-elf \ // RUN: -ccc-install-dir %S/Inputs/hexagon_tree/qc/bin \ // RUN: -s \ // RUN: -Tbss 0xdead -Tdata 0xbeef -Ttext 0xcafe \ diff --git a/test/Driver/hexagon-toolchain.c b/test/Driver/hexagon-toolchain.c index 5d80c4a418..cfc64467ff 100644 --- a/test/Driver/hexagon-toolchain.c +++ b/test/Driver/hexagon-toolchain.c @@ -13,7 +13,7 @@ // CHECK001: "-internal-externc-isystem" "{{.*}}/Inputs/hexagon_tree/qc/bin/../../gnu/hexagon/include" // CHECK001-NEXT: "{{.*}}/Inputs/hexagon_tree/qc/bin/../../gnu/bin{{/|\\}}hexagon-as" -// RUN: %clang -ccc-cxx -x c++ -### -target hexagon-unknown-linux \ +// RUN: %clangxx -### -target hexagon-unknown-linux \ // RUN: -ccc-install-dir %S/Inputs/hexagon_tree/qc/bin \ // RUN: %s 2>&1 \ // RUN: | FileCheck -check-prefix=CHECK002 %s @@ -49,7 +49,7 @@ // CHECK004-NOT: "-internal-externc-isystem" "{{.*}}/Inputs/hexagon_tree/qc/bin/../../gnu/hexagon/include" // CHECK004-NEXT: "{{.*}}/Inputs/hexagon_tree/qc/bin/../../gnu/bin{{/|\\}}hexagon-as" -// RUN: %clang -ccc-cxx -x c++ -### -target hexagon-unknown-linux \ +// RUN: %clangxx -### -target hexagon-unknown-linux \ // RUN: -ccc-install-dir %S/Inputs/hexagon_tree/qc/bin \ // RUN: -nostdlibinc \ // RUN: %s 2>&1 \ @@ -61,7 +61,7 @@ // CHECK005-NOT: "-internal-externc-isystem" "{{.*}}/Inputs/hexagon_tree/qc/bin/../../gnu/hexagon/include" // CHECK005-NEXT: "{{.*}}/Inputs/hexagon_tree/qc/bin/../../gnu/bin{{/|\\}}hexagon-as" -// RUN: %clang -ccc-cxx -x c++ -### -target hexagon-unknown-linux \ +// RUN: %clangxx -### -target hexagon-unknown-linux \ // RUN: -ccc-install-dir %S/Inputs/hexagon_tree/qc/bin \ // RUN: -nostdinc++ \ // RUN: %s 2>&1 \ @@ -155,7 +155,7 @@ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // Defaults for C++ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -// RUN: %clang -ccc-cxx -x c++ -### -target hexagon-unknown-linux \ +// RUN: %clangxx -### -target hexagon-unknown-linux \ // RUN: -ccc-install-dir %S/Inputs/hexagon_tree/qc/bin \ // RUN: %s 2>&1 \ // RUN: | FileCheck -check-prefix=CHECK012 %s @@ -287,7 +287,7 @@ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // -nostdlib, -nostartfiles, -nodefaultlibs // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -// RUN: %clang -ccc-cxx -x c++ -### -target hexagon-unknown-linux \ +// RUN: %clangxx -### -target hexagon-unknown-linux \ // RUN: -ccc-install-dir %S/Inputs/hexagon_tree/qc/bin \ // RUN: -nostdlib \ // RUN: %s 2>&1 \ @@ -313,7 +313,7 @@ // CHECK017-NOT: "--end-group" // CHECK017-NOT: fini.o -// RUN: %clang -ccc-cxx -x c++ -### -target hexagon-unknown-linux \ +// RUN: %clangxx -### -target hexagon-unknown-linux \ // RUN: -ccc-install-dir %S/Inputs/hexagon_tree/qc/bin \ // RUN: -nostartfiles \ // RUN: %s 2>&1 \ @@ -339,7 +339,7 @@ // CHECK018: "--end-group" // CHECK018-NOT: fini.o -// RUN: %clang -ccc-cxx -x c++ -### -target hexagon-unknown-linux \ +// RUN: %clangxx -### -target hexagon-unknown-linux \ // RUN: -ccc-install-dir %S/Inputs/hexagon_tree/qc/bin \ // RUN: -nodefaultlibs \ // RUN: %s 2>&1 \ @@ -421,7 +421,7 @@ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // Other args to pass to linker // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -// RUN: %clang -ccc-cxx -x c++ -### -target hexagon-unknown-linux \ +// RUN: %clangxx -### -target hexagon-unknown-linux \ // RUN: -ccc-install-dir %S/Inputs/hexagon_tree/qc/bin \ // RUN: -s \ // RUN: -Tbss 0xdead -Tdata 0xbeef -Ttext 0xcafe \ diff --git a/test/Driver/immediate-options.c b/test/Driver/immediate-options.c index d095bc5f4e..f50ccae642 100644 --- a/test/Driver/immediate-options.c +++ b/test/Driver/immediate-options.c @@ -1,10 +1,10 @@ // RUN: %clang --help | FileCheck %s -check-prefix=HELP // HELP: isystem // HELP-NOT: ast-dump -// HELP-NOT: ccc-cxx +// HELP-NOT: driver-mode // RUN: %clang --help-hidden | FileCheck %s -check-prefix=HELP-HIDDEN -// HELP-HIDDEN: ccc-cxx +// HELP-HIDDEN: driver-mode // RUN: %clang -dumpversion | FileCheck %s -check-prefix=DUMPVERSION // DUMPVERSION: 4.2.1 diff --git a/test/lit.cfg b/test/lit.cfg index 7bc6321a7f..46fc5b5008 100644 --- a/test/lit.cfg +++ b/test/lit.cfg @@ -202,9 +202,11 @@ def getClangBuiltinIncludeDir(clang): config.substitutions.append( ('%clang_cc1', '%s -cc1 -internal-isystem %s' % (config.clang, getClangBuiltinIncludeDir(config.clang))) ) +config.substitutions.append( ('%clang_cpp', ' ' + config.clang + + ' --driver-mode=cpp ')) config.substitutions.append( ('%clangxx', ' ' + config.clang + - ' -ccc-cxx ')) + ' --driver-mode=g++ ')) config.substitutions.append( ('%clang', ' ' + config.clang + ' ') ) config.substitutions.append( ('%test_debuginfo', ' ' + config.llvm_src_root + '/utils/test_debuginfo.pl ') ) @@ -222,6 +224,9 @@ config.substitutions.append( config.substitutions.append( (' %clang-cc1 ', """*** invalid substitution, use '%clang_cc1'. ***""") ) +config.substitutions.append( + (' %clang-cpp ', + """*** invalid substitution, use '%clang_cpp'. ***""") ) ### diff --git a/tools/driver/driver.cpp b/tools/driver/driver.cpp index 2a40a86c91..b3f2a83e12 100644 --- a/tools/driver/driver.cpp +++ b/tools/driver/driver.cpp @@ -210,19 +210,18 @@ static void ParseProgName(SmallVectorImpl &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 }, + { "cc", 0 }, + { "cpp", "--driver-mode=cpp" }, + { "++", "--driver-mode=g++" }, }; std::string ProgName(llvm::sys::path::stem(ArgVector[0])); StringRef ProgNameRef(ProgName); @@ -235,10 +234,11 @@ static void ParseProgName(SmallVectorImpl &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::iterator it = ArgVector.begin(); + if (it != ArgVector.end()) + ++it; + if (suffixes[i].ModeFlag) + ArgVector.insert(it, suffixes[i].ModeFlag); break; } } -- 2.40.0