]> granicus.if.org Git - clang/commitdiff
Fix quoting of #pragma comment for MS compat, clang part.
authorMichael Kuperstein <michael.m.kuperstein@intel.com>
Mon, 16 Feb 2015 11:57:43 +0000 (11:57 +0000)
committerMichael Kuperstein <michael.m.kuperstein@intel.com>
Mon, 16 Feb 2015 11:57:43 +0000 (11:57 +0000)
For #pragma comment(linker, ...) MSVC expects the comment string to be quoted, but for #pragma comment(lib, ...) the compiler itself quotes the library name.
Since this distinction disappears by the time the directive reaches the backend, move quoting for the "lib" version to the frontend.

Differential Revision: http://reviews.llvm.org/D7653

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@229376 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/TargetInfo.cpp
test/CodeGen/pragma-comment.c

index d06782141908328406f48d493fd707be8e2262ff..117767d0b3659c6f8114b10920044a688b230041 100644 (file)
@@ -1614,11 +1614,15 @@ public:
 };
 
 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 the argument does not end in .lib, automatically add the suffix.
+  // If the argument contains a space, enclose it in quotes.
+  // This matches the behavior of MSVC.
+  bool Quote = (Lib.find(" ") != StringRef::npos);
+  std::string ArgStr = Quote ? "\"" : "";
+  ArgStr += Lib;
   if (!Lib.endswith_lower(".lib"))
     ArgStr += ".lib";
+  ArgStr += Quote ? "\"" : "";
   return ArgStr;
 }
 
index 5869ca85f33dc32299d8a272e89206b17caccfde..0a7d3c7a47585fbd2808c8a81f067510b0be3418 100644 (file)
@@ -6,17 +6,21 @@
 #pragma comment(lib, "msvcrt.lib")
 #pragma comment(lib, "kernel32")
 #pragma comment(lib, "USER32.LIB")
+#pragma comment(lib, "with space")
 
 #define BAR "2"
 #pragma comment(linker," /bar=" BAR)
+#pragma comment(linker," /foo=\"foo bar\"")
 
 // CHECK: !llvm.module.flags = !{{{.*}}}
 // CHECK: !{{[0-9]+}} = !{i32 6, !"Linker Options", ![[link_opts:[0-9]+]]}
-// CHECK: ![[link_opts]] = !{![[msvcrt:[0-9]+]], ![[kernel32:[0-9]+]], ![[USER32:[0-9]+]], ![[bar:[0-9]+]]}
+// CHECK: ![[link_opts]] = !{![[msvcrt:[0-9]+]], ![[kernel32:[0-9]+]], ![[USER32:[0-9]+]], ![[space:[0-9]+]], ![[bar:[0-9]+]], ![[foo:[0-9]+]]}
 // CHECK: ![[msvcrt]] = !{!"/DEFAULTLIB:msvcrt.lib"}
 // CHECK: ![[kernel32]] = !{!"/DEFAULTLIB:kernel32.lib"}
 // CHECK: ![[USER32]] = !{!"/DEFAULTLIB:USER32.LIB"}
+// CHECK: ![[space]] = !{!"/DEFAULTLIB:\22with space.lib\22"}
 // CHECK: ![[bar]] = !{!" /bar=2"}
+// CHECK: ![[foo]] = !{!" /foo=\22foo bar\22"}
 
 // LINUX: !{!"-lmsvcrt.lib"}
 // LINUX: !{!"-lkernel32"}