Index: lib/Driver/Tools.cpp =================================================================== --- lib/Driver/Tools.cpp +++ lib/Driver/Tools.cpp @@ -8878,6 +8878,25 @@ Args.AddAllArgValues(CmdArgs, options::OPT__SLASH_link); + if (Args.hasFlag(options::OPT_fopenmp, options::OPT_fopenmp_EQ, + options::OPT_fno_openmp, false)) { + CmdArgs.push_back("-nodefaultlib:vcomp.lib"); + CmdArgs.push_back("-nodefaultlib:vcompd.lib"); + switch (getOpenMPRuntime(getToolChain(), Args)) { + case OMPRT_OMP: + CmdArgs.push_back("-defaultlib:libomp.lib"); + break; + case OMPRT_IOMP5: + CmdArgs.push_back("-defaultlib:libiomp5md.lib"); + break; + case OMPRT_GOMP: + break; + case OMPRT_Unknown: + // Already diagnosed. + break; + } + } + // Add filenames, libraries, and other linker inputs. for (const auto &Input : Inputs) { if (Input.isFilename()) { Index: test/OpenMP/linking.c =================================================================== --- test/OpenMP/linking.c +++ test/OpenMP/linking.c @@ -69,3 +69,15 @@ // CHECK-LD-OVERRIDE-64: "-lgomp" "-lrt" "-lgcc" // CHECK-LD-OVERRIDE-64: "-lpthread" "-lc" // +// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \ +// RUN: -fopenmp=libomp -target x86_64-msvc-win32 \ +// RUN: | FileCheck --check-prefix=CHECK-MSVC-LINK-64 %s +// CHECK-MSVC-LINK-64: "link.exe" +// CHECK-MSVC-LINK-64-SAME: "-nodefaultlib:vcomp.lib" "-nodefaultlib:vcompd.lib" "-defaultlib:libomp.lib" +// +// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \ +// RUN: -fopenmp=libiomp5 -target x86_64-msvc-win32 \ +// RUN: | FileCheck --check-prefix=CHECK-MSVC-ILINK-64 %s +// CHECK-MSVC-ILINK-64: "link.exe" +// CHECK-MSVC-ILINK-64-SAME: "-nodefaultlib:vcomp.lib" "-nodefaultlib:vcompd.lib" "-defaultlib:libiomp5md.lib" +//