[PATCH] D111195: [clang][Tooling] Use Windows command lines on all Windows, except Cygwin

Reid Kleckner via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 6 09:47:42 PDT 2021


rnk added a comment.

In D111195#3044594 <https://reviews.llvm.org/D111195#3044594>, @mstorsjo wrote:

> This looks ok to me I guess. Technically in this case, this is pretty much equivalent to `#ifdef _WIN32`, i.e. any form when running on windows, where the process considers itself windows (cygwin doesn't define `_WIN32`), but I guess keeping it based on `getProcessTriple()` is fine too.
>
> I'll leave it open for discussion for a while, but if there's no further opinions I can accept it later.
>
> @rnk Do you happen to have any experience here?

I think the largest producer of JSON compilation databases with untokenized command line strings is CMake. If CMake uses Windows quoting rules to build up command lines, then clang should make the same assumption.



================
Comment at: clang/lib/Tooling/JSONCompilationDatabase.cpp:138-144
     Syntax = JSONCommandLineSyntax::Gnu;
     llvm::Triple Triple(llvm::sys::getProcessTriple());
-    if (Triple.getOS() == llvm::Triple::OSType::Win32) {
+    if (Triple.isOSWindows()) {
       // Assume Windows command line parsing on Win32 unless the triple
       // explicitly tells us otherwise.
-      if (!Triple.hasEnvironment() ||
-          Triple.getEnvironment() == llvm::Triple::EnvironmentType::MSVC)
+      if (!Triple.isWindowsCygwinEnvironment())
         Syntax = JSONCommandLineSyntax::Windows;
----------------
This seems like it can be simplified to:
  Syntax = (Triple.isOSWindows() && !Triple.isWindowsCygwinEnvironment()) ?
            JSONCommandLineSyntax::Windows : JSONCommandLineSyntax::Gnu;
Alternatively, the ifdef _WIN32 would work.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D111195/new/

https://reviews.llvm.org/D111195



More information about the cfe-commits mailing list