]> granicus.if.org Git - clang/commitdiff
clang-cl: Warn about overriding /MD with /MT etc.
authorHans Wennborg <hans@hanshq.net>
Wed, 11 Sep 2013 16:38:41 +0000 (16:38 +0000)
committerHans Wennborg <hans@hanshq.net>
Wed, 11 Sep 2013 16:38:41 +0000 (16:38 +0000)
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
include/clang/Driver/CLCompatOptions.td
lib/Driver/Driver.cpp
lib/Driver/Tools.cpp
test/Driver/cl-runtime-flags.c

index fe4a7ede06a7c037ee4b0eab5d3bbb3d384b848c..2f69e5de8eb401ed12c74ecb5a873b84b58f1c82 100644 (file)
@@ -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<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<
index 44418d277539ba9a647297a2fa1866f715cde032..77acfbcea2a9c2536b69925504bcfdacc1adaf74 100644 (file)
@@ -93,6 +93,8 @@ def _SLASH_Zs : CLFlag<"Zs">, HelpText<"Syntax-check only">,
 
 // 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<"Create DLL">;
 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">;
index 9bbbaae33e233be7f3a9c101a83da5f3019d41ee..7461e9996340aa4790dbc88d2da7449b314b6ccd 100644 (file)
@@ -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;
     }
index d519a4c9b5cc67dfc58e292e5211dc2bdd77bf64..eca94b66ef6280411d8b7c0e1f318aa2a2970480 100644 (file)
@@ -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) {
index 907f99b04407c34be09105c6e964ec6f4f29e68e..11a5e94876773216532da0a782abb4d86ca0baf0 100644 (file)
@@ -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"