Index: lib/Driver/ToolChains/MinGW.cpp =================================================================== --- lib/Driver/ToolChains/MinGW.cpp +++ lib/Driver/ToolChains/MinGW.cpp @@ -82,6 +82,9 @@ CmdArgs.push_back("-lmoldname"); CmdArgs.push_back("-lmingwex"); + for (auto Lib : Args.getAllArgValues(options::OPT_l)) + if (StringRef(Lib).startswith("msvcr") || Lib == "ucrtbase") + return; CmdArgs.push_back("-lmsvcrt"); } Index: test/Driver/mingw-msvcrt.c =================================================================== --- /dev/null +++ test/Driver/mingw-msvcrt.c @@ -0,0 +1,5 @@ +// RUN: %clang -v -target i686-pc-windows-gnu -### %s 2>&1 | FileCheck -check-prefix=CHECK_DEFAULT %s +// RUN: %clang -v -target i686-pc-windows-gnu -lmsvcr120 -### %s 2>&1 | FileCheck -check-prefix=CHECK_MSVCR120 %s + +// CHECK_DEFAULT: "-lmingwex" "-lmsvcrt" "-ladvapi32" +// CHECK_MSVCR120: "-lmingwex" "-ladvapi32"