};
+static std::string qualifyWindowsLibrary(llvm::StringRef Lib) {
+ // If the argument does not end in .lib, automatically add the suffix. This
+ // matches the behavior of MSVC.
+ std::string ArgStr = Lib;
+ if (Lib.size() <= 4 ||
+ Lib.substr(Lib.size() - 4).compare_lower(".lib") != 0) {
+ ArgStr += ".lib";
+ }
+ return ArgStr;
+}
+
class WinX86_32TargetCodeGenInfo : public X86_32TargetCodeGenInfo {
public:
WinX86_32TargetCodeGenInfo(CodeGen::CodeGenTypes &CGT, unsigned RegParms)
void getDependentLibraryOption(llvm::StringRef Lib,
llvm::SmallString<24> &Opt) const {
Opt = "/DEFAULTLIB:";
- Opt += Lib;
+ Opt += qualifyWindowsLibrary(Lib);
}
};
void getDependentLibraryOption(llvm::StringRef Lib,
llvm::SmallString<24> &Opt) const {
Opt = "/DEFAULTLIB:";
- Opt += Lib;
+ Opt += qualifyWindowsLibrary(Lib);
}
};
case PCK_Linker:
Consumer.HandleLinkerOptionPragma(Arg);
return;
- case PCK_Lib: {
+ case PCK_Lib:
Consumer.HandleDependentLibrary(Arg);
return;
- }
case PCK_Compiler:
case PCK_ExeStr:
case PCK_User:
// RUN: %clang_cc1 %s -triple i686-pc-linux -fms-extensions -emit-llvm -o - | FileCheck -check-prefix LINUX %s
#pragma comment(lib, "msvcrt.lib")
+#pragma comment(lib, "kernel32")
+#pragma comment(lib, "USER32.LIB")
#define BAR "2"
#pragma comment(linker," /bar=" BAR)
// 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]+]], metadata ![[bar:[0-9]+]]}
+// CHECK: ![[link_opts]] = metadata !{metadata ![[msvcrt:[0-9]+]], metadata ![[kernel32:[0-9]+]], metadata ![[USER32:[0-9]+]], metadata ![[bar:[0-9]+]]}
// CHECK: ![[msvcrt]] = metadata !{metadata !"/DEFAULTLIB:msvcrt.lib"}
+// CHECK: ![[kernel32]] = metadata !{metadata !"/DEFAULTLIB:kernel32.lib"}
+// CHECK: ![[USER32]] = metadata !{metadata !"/DEFAULTLIB:USER32.LIB"}
// CHECK: ![[bar]] = metadata !{metadata !" /bar=2"}
// LINUX: metadata !{metadata !"-lmsvcrt.lib"}
+// LINUX: metadata !{metadata !"-lkernel32"}
+// LINUX: metadata !{metadata !"-lUSER32.LIB"}
// LINUX: metadata !{metadata !" /bar=2"}
// CHECK: !4 = metadata !{i32 6, metadata !"Linker Options", metadata ![[AUTOLINK_OPTIONS:[0-9]+]]}
// CHECK: ![[AUTOLINK_OPTIONS]] = metadata !{metadata ![[AUTOLINK_FRAMEWORK:[0-9]+]], metadata ![[AUTOLINK:[0-9]+]], metadata ![[DEPENDSONMODULE:[0-9]+]], metadata ![[MODULE:[0-9]+]], metadata ![[NOUMBRELLA:[0-9]+]]}
// CHECK: ![[AUTOLINK_FRAMEWORK]] = metadata !{metadata !"-framework", metadata !"autolink_framework"}
-// CHECK: ![[AUTOLINK]] = metadata !{metadata !"{{(-l|/DEFAULTLIB:)}}autolink"}
+// CHECK: ![[AUTOLINK]] = metadata !{metadata !"{{(-l|/DEFAULTLIB:)}}autolink{{(\.lib)?}}"}
// CHECK: ![[DEPENDSONMODULE]] = metadata !{metadata !"-framework", metadata !"DependsOnModule"}
// CHECK: ![[MODULE]] = metadata !{metadata !"-framework", metadata !"Module"}
// CHECK: ![[NOUMBRELLA]] = metadata !{metadata !"-framework", metadata !"NoUmbrella"}