r190529 - clang-cl: Warn about overriding /MD with /MT etc.
Hans Wennborg
hans at hanshq.net
Wed Sep 11 09:38:42 PDT 2013
Author: hans
Date: Wed Sep 11 11:38:41 2013
New Revision: 190529
URL: http://llvm.org/viewvc/llvm-project?rev=190529&view=rev
Log:
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.
Modified:
cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
cfe/trunk/include/clang/Driver/CLCompatOptions.td
cfe/trunk/lib/Driver/Driver.cpp
cfe/trunk/lib/Driver/Tools.cpp
cfe/trunk/test/Driver/cl-runtime-flags.c
Modified: cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td?rev=190529&r1=190528&r2=190529&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td Wed Sep 11 11:38:41 2013
@@ -141,7 +141,7 @@ def warn_ignoring_ftabstop_value : Warni
def warn_drv_overriding_joined_option : Warning<
"overriding '%0%1' option with '%2%3'">,
InGroup<DiagGroup<"overriding-fo-option">>;
-def warn_drv_overriding_t_option : Warning<
+def warn_drv_overriding_flag_option : Warning<
"overriding '%0' option with '%1'">,
InGroup<DiagGroup<"overriding-t-option">>;
def warn_drv_treating_input_as_cxx : Warning<
Modified: cfe/trunk/include/clang/Driver/CLCompatOptions.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/CLCompatOptions.td?rev=190529&r1=190528&r2=190529&view=diff
==============================================================================
--- cfe/trunk/include/clang/Driver/CLCompatOptions.td (original)
+++ cfe/trunk/include/clang/Driver/CLCompatOptions.td Wed Sep 11 11:38:41 2013
@@ -93,6 +93,8 @@ def _SLASH_Zs : CLFlag<"Zs">, HelpText<"
// Non-aliases:
+def _SLASH_M_Group : OptionGroup<"</M group>">, Group<cl_Group>;
+
def _SLASH_Fe : CLJoined<"Fe">,
HelpText<"Set output executable file or directory (ends in / or \\)">,
MetaVarName<"<file or directory>">;
@@ -103,12 +105,14 @@ def _SLASH_LD : CLFlag<"LD">, HelpText<"
def _SLASH_LDd : CLFlag<"LDd">, HelpText<"Create debug DLL">;
def _SLASH_link : CLRemainingArgs<"link">,
HelpText<"Forward options to the linker">, MetaVarName<"<options>">;
-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<"<filename>">;
def _SLASH_TC : CLFlag<"TC">, HelpText<"Treat all source files as C">;
Modified: cfe/trunk/lib/Driver/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Driver.cpp?rev=190529&r1=190528&r2=190529&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Driver.cpp (original)
+++ cfe/trunk/lib/Driver/Driver.cpp Wed Sep 11 11:38:41 2013
@@ -1011,8 +1011,8 @@ void Driver::BuildInputs(const ToolChain
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;
}
Modified: cfe/trunk/lib/Driver/Tools.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=190529&r1=190528&r2=190529&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Wed Sep 11 11:38:41 2013
@@ -3722,11 +3722,19 @@ void Clang::AddClangCLArgs(const ArgList
// 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) {
Modified: cfe/trunk/test/Driver/cl-runtime-flags.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/cl-runtime-flags.c?rev=190529&r1=190528&r2=190529&view=diff
==============================================================================
--- cfe/trunk/test/Driver/cl-runtime-flags.c (original)
+++ cfe/trunk/test/Driver/cl-runtime-flags.c Wed Sep 11 11:38:41 2013
@@ -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"
More information about the cfe-commits
mailing list