HelpText<"Run the SLP vectorization passes">;
def vectorize_slp_aggressive : Flag<["-"], "vectorize-slp-aggressive">,
HelpText<"Run the BB vectorization passes">;
+def dependent_lib : Joined<["--"], "dependent-lib=">,
+ HelpText<"Add dependent library">;
//===----------------------------------------------------------------------===//
// Dependency Output Options
def _SLASH_Fo : CLJoined<"Fo">,
HelpText<"Set output object file, or directory (ends in / or \\)">,
MetaVarName<"<file or directory>">;
+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_Tc : CLJoinedOrSeparate<"Tc">, HelpText<"Specify a C source file">,
MetaVarName<"<filename>">;
def _SLASH_TC : CLFlag<"TC">, HelpText<"Treat all source files as C">;
def _SLASH_Gy : CLFlag<"Gy">;
def _SLASH_Gy_ : CLFlag<"Gy-">;
def _SLASH_GZ : CLFlag<"GZ">;
-def _SLASH_MD : CLFlag<"MD">;
-def _SLASH_MT : CLFlag<"MT">;
-def _SLASH_MDd : CLFlag<"MDd">;
-def _SLASH_MTd : CLFlag<"MTd">;
def _SLASH_Oi : CLFlag<"Oi">;
def _SLASH_RTC : CLJoined<"RTC">;
def _SLASH_showIncludes : CLJoined<"showIncludes">;
/// A list of command-line options to forward to the LLVM backend.
std::vector<std::string> BackendOptions;
+ /// A list of dependent libraries.
+ std::vector<std::string> DependentLibraries;
+
public:
// Define accessors/mutators for code generation options of enumeration type.
#define CODEGENOPT(Name, Bits, Default)
TD.reset(new llvm::DataLayout(Ctx->getTargetInfo().getTargetDescription()));
Builder.reset(new CodeGen::CodeGenModule(Context, CodeGenOpts, *M, *TD,
Diags));
+
+ for (size_t i = 0, e = CodeGenOpts.DependentLibraries.size(); i < e; ++i)
+ HandleDependentLibrary(CodeGenOpts.DependentLibraries[i]);
}
virtual void HandleCXXStaticMemberVarInstantiation(VarDecl *VD) {
break;
}
+ // Add clang-cl arguments.
+ if (getToolChain().getDriver().IsCLMode())
+ AddClangCLArgs(Args, CmdArgs);
+
// Pass the linker version in use.
if (Arg *A = Args.getLastArg(options::OPT_mlinker_version_EQ)) {
CmdArgs.push_back("-target-linker-version");
return runtime;
}
+void Clang::AddClangCLArgs(const ArgList &Args, ArgStringList &CmdArgs) const {
+ unsigned RTOptionID = options::OPT__SLASH_MT;
+
+ if (Arg *A = Args.getLastArg(options::OPT__SLASH_MD,
+ options::OPT__SLASH_MDd,
+ options::OPT__SLASH_MT,
+ options::OPT__SLASH_MTd)) {
+ RTOptionID = A->getOption().getID();
+ }
+
+ switch(RTOptionID) {
+ case options::OPT__SLASH_MD:
+ CmdArgs.push_back("-D_MT");
+ CmdArgs.push_back("-D_DLL");
+ CmdArgs.push_back("--dependent-lib=msvcrt");
+ break;
+ case options::OPT__SLASH_MDd:
+ CmdArgs.push_back("-D_DEBUG");
+ CmdArgs.push_back("-D_MT");
+ CmdArgs.push_back("-D_DLL");
+ CmdArgs.push_back("--dependent-lib=msvcrtd");
+ break;
+ case options::OPT__SLASH_MT:
+ CmdArgs.push_back("-D_MT");
+ CmdArgs.push_back("--dependent-lib=libcmt");
+ break;
+ case options::OPT__SLASH_MTd:
+ CmdArgs.push_back("-D_DEBUG");
+ CmdArgs.push_back("-D_MT");
+ CmdArgs.push_back("--dependent-lib=libcmtd");
+ break;
+ default:
+ llvm_unreachable("Unexpected option ID.");
+ }
+
+ // This provides POSIX compatibility (maps 'open' to '_open'), which most users
+ // want. MSVC has a switch to turn off this autolinking, but it's not
+ // implemented in clang yet.
+ CmdArgs.push_back("--dependent-lib=oldnames");
+}
+
void ClangAs::ConstructJob(Compilation &C, const JobAction &JA,
const InputInfo &Output,
const InputInfoList &Inputs,
llvm::opt::ArgStringList &cmdArgs,
RewriteKind rewrite) const;
+ void AddClangCLArgs(const llvm::opt::ArgList &Args,
+ llvm::opt::ArgStringList &CmdArgs) const;
+
public:
Clang(const ToolChain &TC) : Tool("clang", "clang frontend", TC) {}
}
}
+ Opts.DependentLibraries = Args.getAllArgValues(OPT_dependent_lib);
+
return Success;
}
--- /dev/null
+// RUN: %clang_cc1 %s --dependent-lib=msvcrt -triple i686-pc-win32 -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 %s --dependent-lib=msvcrt -triple x86_64-pc-win32 -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 %s --dependent-lib=msvcrt -triple i686-pc-linux -emit-llvm -o - | FileCheck -check-prefix LINUX %s
+
+// CHECK: !llvm.module.flags = !{!0}
+// CHECK: !0 = metadata !{i32 6, metadata !"Linker Options", metadata ![[link_opts:[0-9]+]]}
+// CHECK: ![[link_opts]] = metadata !{metadata ![[msvcrt:[0-9]+]]}
+// CHECK: ![[msvcrt]] = metadata !{metadata !"/DEFAULTLIB:msvcrt.lib"}
+
+// LINUX: !llvm.module.flags = !{!0}
+// LINUX: !0 = metadata !{i32 6, metadata !"Linker Options", metadata ![[link_opts:[0-9]+]]}
+// LINUX: ![[link_opts]] = metadata !{metadata ![[msvcrt:[0-9]+]]}
+// LINUX: ![[msvcrt]] = metadata !{metadata !"-lmsvcrt"}
+
+int f();
// Unsupported but parsed options. Check that we don't error on them.
// (/Zs is for syntax-only)
// RUN: %clang_cl /Zs /EHsc /Fdfoo /fp:precise /Gd /GL /GL- -- %s 2>&1
-// RUN: %clang_cl /Zs /Gm /Gm- /GS /Gy /Gy- /GZ /MD /MT /MDd /MTd /Oi -- %s 2>&1
+// RUN: %clang_cl /Zs /Gm /Gm- /GS /Gy /Gy- /GZ /Oi -- %s 2>&1
// RUN: %clang_cl /Zs /RTC1 /wfoo /Zc:wchar_t- -- %s 2>&1
// RUN: %clang_cl /Zs /ZI /Zi /showIncludes -- %s 2>&1
--- /dev/null
+// Don't attempt slash switches on msys bash.\r
+// REQUIRES: shell-preserves-root\r
+\r
+// Note: %s must be preceded by --, otherwise it may be interpreted as a\r
+// command-line option, e.g. on Mac where %s is commonly under /Users.\r
+\r
+// First check that regular clang doesn't do any of this stuff.\r
+// RUN: %clang -### %s 2>&1 | FileCheck -check-prefix=CHECK-CLANG %s\r
+// CHECK-CLANG-NOT: "-D_DEBUG"\r
+// CHECK-CLANG-NOT: "-D_MT"\r
+// CHECK-CLANG-NOT: "-D_DLL"\r
+// CHECK-CLANG-NOT: --dependent-lib\r
+\r
+// RUN: %clang_cl -### -- %s 2>&1 | FileCheck -check-prefix=CHECK-MT %s\r
+// RUN: %clang_cl -### /MT -- %s 2>&1 | FileCheck -check-prefix=CHECK-MT %s\r
+// CHECK-MT-NOT: "-D_DEBUG"\r
+// CHECK-MT: "-D_MT"\r
+// CHECK-MT-NOT: "-D_DLL"\r
+// CHECK-MT: "--dependent-lib=libcmt"\r
+// CHECK-MT: "--dependent-lib=oldnames"\r
+\r
+// RUN: %clang_cl -### /MTd -- %s 2>&1 | FileCheck -check-prefix=CHECK-MTd %s\r
+// CHECK-MTd: "-D_DEBUG"\r
+// CHECK-MTd: "-D_MT"\r
+// CHECK-MTd-NOT: "-D_DLL"\r
+// CHECK-MTd: "--dependent-lib=libcmtd"\r
+// CHECK-MTd: "--dependent-lib=oldnames"\r
+\r
+// RUN: %clang_cl -### /MD -- %s 2>&1 | FileCheck -check-prefix=CHECK-MD %s\r
+// CHECK-MD-NOT: "-D_DEBUG"\r
+// CHECK-MD: "-D_MT"\r
+// CHECK-MD: "-D_DLL"\r
+// CHECK-MD: "--dependent-lib=msvcrt"\r
+// CHECK-MD: "--dependent-lib=oldnames"\r
+\r
+// RUN: %clang_cl -### /MDd -- %s 2>&1 | FileCheck -check-prefix=CHECK-MDd %s\r
+// CHECK-MDd: "-D_DEBUG"\r
+// CHECK-MDd: "-D_MT"\r
+// CHECK-MDd: "-D_DLL"\r
+// CHECK-MDd: "--dependent-lib=msvcrtd"\r
+// CHECK-MDd: "--dependent-lib=oldnames"\r