From 42ade496f79d2b9b1ff9fbdc30dd025c168be7a3 Mon Sep 17 00:00:00 2001 From: Hans Wennborg Date: Wed, 11 Sep 2013 16:38:41 +0000 Subject: [PATCH] clang-cl: Warn about overriding /MD with /MT etc. This also bakes the /M options into a separate option group to make them easier to refer to from the code. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@190529 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/DiagnosticDriverKinds.td | 2 +- include/clang/Driver/CLCompatOptions.td | 16 ++++++++++------ lib/Driver/Driver.cpp | 4 ++-- lib/Driver/Tools.cpp | 16 ++++++++++++---- test/Driver/cl-runtime-flags.c | 4 ++++ 5 files changed, 29 insertions(+), 13 deletions(-) diff --git a/include/clang/Basic/DiagnosticDriverKinds.td b/include/clang/Basic/DiagnosticDriverKinds.td index fe4a7ede06..2f69e5de8e 100644 --- a/include/clang/Basic/DiagnosticDriverKinds.td +++ b/include/clang/Basic/DiagnosticDriverKinds.td @@ -141,7 +141,7 @@ def warn_ignoring_ftabstop_value : Warning< def warn_drv_overriding_joined_option : Warning< "overriding '%0%1' option with '%2%3'">, InGroup>; -def warn_drv_overriding_t_option : Warning< +def warn_drv_overriding_flag_option : Warning< "overriding '%0' option with '%1'">, InGroup>; def warn_drv_treating_input_as_cxx : Warning< diff --git a/include/clang/Driver/CLCompatOptions.td b/include/clang/Driver/CLCompatOptions.td index 44418d2775..77acfbcea2 100644 --- a/include/clang/Driver/CLCompatOptions.td +++ b/include/clang/Driver/CLCompatOptions.td @@ -93,6 +93,8 @@ def _SLASH_Zs : CLFlag<"Zs">, HelpText<"Syntax-check only">, // Non-aliases: +def _SLASH_M_Group : OptionGroup<"">, Group; + def _SLASH_Fe : CLJoined<"Fe">, HelpText<"Set output executable file or directory (ends in / or \\)">, MetaVarName<"">; @@ -103,12 +105,14 @@ def _SLASH_LD : CLFlag<"LD">, HelpText<"Create DLL">; def _SLASH_LDd : CLFlag<"LDd">, HelpText<"Create debug DLL">; def _SLASH_link : CLRemainingArgs<"link">, HelpText<"Forward options to the linker">, MetaVarName<"">; -def _SLASH_MD : CLFlag<"MD">, - HelpText<"Use DLL run-time">; -def _SLASH_MDd : CLFlag<"MDd">, - HelpText<"Use DLL debug run-time">; -def _SLASH_MT : CLFlag<"MT">, HelpText<"Use static run-time">; -def _SLASH_MTd : CLFlag<"MTd">, HelpText<"Use static debug run-time">; +def _SLASH_MD : Option<["/", "-"], "MD", KIND_FLAG>, Group<_SLASH_M_Group>, + Flags<[CLOption, DriverOption]>, HelpText<"Use DLL run-time">; +def _SLASH_MDd : Option<["/", "-"], "MDd", KIND_FLAG>, Group<_SLASH_M_Group>, + Flags<[CLOption, DriverOption]>, HelpText<"Use DLL debug run-time">; +def _SLASH_MT : Option<["/", "-"], "MT", KIND_FLAG>, Group<_SLASH_M_Group>, + Flags<[CLOption, DriverOption]>, HelpText<"Use static run-time">; +def _SLASH_MTd : Option<["/", "-"], "MTd", KIND_FLAG>, Group<_SLASH_M_Group>, + Flags<[CLOption, DriverOption]>, HelpText<"Use static debug run-time">; def _SLASH_Tc : CLJoinedOrSeparate<"Tc">, HelpText<"Specify a C source file">, MetaVarName<"">; def _SLASH_TC : CLFlag<"TC">, HelpText<"Treat all source files as C">; diff --git a/lib/Driver/Driver.cpp b/lib/Driver/Driver.cpp index 9bbbaae33e..7461e99963 100644 --- a/lib/Driver/Driver.cpp +++ b/lib/Driver/Driver.cpp @@ -1011,8 +1011,8 @@ void Driver::BuildInputs(const ToolChain &TC, const DerivedArgList &Args, Arg *Previous = *it++; bool ShowNote = false; while (it != ie) { - Diag(clang::diag::warn_drv_overriding_t_option) << Previous->getSpelling() - << (*it)->getSpelling(); + Diag(clang::diag::warn_drv_overriding_flag_option) + << Previous->getSpelling() << (*it)->getSpelling(); Previous = *it++; ShowNote = true; } diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp index d519a4c9b5..eca94b66ef 100644 --- a/lib/Driver/Tools.cpp +++ b/lib/Driver/Tools.cpp @@ -3722,11 +3722,19 @@ void Clang::AddClangCLArgs(const ArgList &Args, ArgStringList &CmdArgs) const { // but defining _DEBUG is sticky. RTOptionID = options::OPT__SLASH_MTd; - if (Arg *A = Args.getLastArg(options::OPT__SLASH_MD, - options::OPT__SLASH_MDd, - options::OPT__SLASH_MT, - options::OPT__SLASH_MTd)) { + if (Arg *A = Args.getLastArg(options::OPT__SLASH_M_Group)) { RTOptionID = A->getOption().getID(); + + // Diagnose overrides. + arg_iterator it = Args.filtered_begin(options::OPT__SLASH_M_Group); + Arg *Previous = *it++; + const arg_iterator ie = Args.filtered_end(); + while (it != ie) { + const Driver &D = getToolChain().getDriver(); + D.Diag(clang::diag::warn_drv_overriding_flag_option) + << Previous->getSpelling() << (*it)->getSpelling(); + Previous = *it++; + } } switch(RTOptionID) { diff --git a/test/Driver/cl-runtime-flags.c b/test/Driver/cl-runtime-flags.c index 907f99b044..11a5e94876 100644 --- a/test/Driver/cl-runtime-flags.c +++ b/test/Driver/cl-runtime-flags.c @@ -84,3 +84,7 @@ // CHECK-LDMDd: "-D_MT" // CHECK-LDMDd: "-D_DLL" // CHECK-LDMDd: "--dependent-lib=msvcrtd" + +// RUN: %clang_cl /MD /MT -### -- %s 2>&1 | FileCheck -check-prefix=MTOVERRIDE %s +// MTOVERRIDE: warning: overriding '/MD' option with '/MT' +// MTOVERRIDE: "--dependent-lib=libcmt" -- 2.40.0