[PATCH] D71400: [RFC] [MinGW] Implicitly add .exe suffix if not provided

Martin Storsjö via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Dec 12 01:30:29 PST 2019


mstorsjo created this revision.
mstorsjo added a reviewer: rnk.
Herald added a project: clang.

GCC implicitly adds an .exe suffix if it is given an output file name, but the file name doesn't contain a suffix, and there are certain users of GCC that rely on this behaviour (and run into issues when trying to use Clang instead of GCC). And MSVC's cl.exe also does the same (but not link.exe).

However, GCC only does this when actually running on windows, not when operating as a cross compiler.

This was reported to me at https://github.com/mstorsjo/llvm-mingw/issues/60.

As GCC doesn't have this behaviour when cross compiling, we definitely shouldn't introduce the behaviour in such cases (as it would break at least as many cases as this fixes).

Is it worth adding such inconsistent behaviour (with two separate tests, one for running on windows and one elsewhere)?


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D71400

Files:
  clang/lib/Driver/ToolChains/MinGW.cpp


Index: clang/lib/Driver/ToolChains/MinGW.cpp
===================================================================
--- clang/lib/Driver/ToolChains/MinGW.cpp
+++ clang/lib/Driver/ToolChains/MinGW.cpp
@@ -160,7 +160,15 @@
   }
 
   CmdArgs.push_back("-o");
-  CmdArgs.push_back(Output.getFilename());
+  const char *OutputFile = Output.getFilename();
+#ifdef _WIN32
+  if (!llvm::sys::path::filename(OutputFile).contains('.'))
+    CmdArgs.push_back(Args.MakeArgString(Twine(OutputFile) + ".exe"));
+  else
+    CmdArgs.push_back(OutputFile);
+#else
+  CmdArgs.push_back(OutputFile);
+#endif
 
   Args.AddAllArgs(CmdArgs, options::OPT_e);
   // FIXME: add -N, -n flags


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D71400.233532.patch
Type: text/x-patch
Size: 665 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20191212/8498108d/attachment.bin>


More information about the cfe-commits mailing list