Bug 190514 - [Win][Clang] Do not give -Wall to clang-cl because it is treated as -Weverything
Summary: [Win][Clang] Do not give -Wall to clang-cl because it is treated as -Weverything
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: CMake (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Fujii Hironori
URL:
Keywords:
Depends on:
Blocks: 171618
  Show dependency treegraph
 
Reported: 2018-10-12 03:37 PDT by Fujii Hironori
Modified: 2018-10-18 23:45 PDT (History)
6 users (show)

See Also:


Attachments
Patch (1.70 KB, patch)
2018-10-12 04:10 PDT, Fujii Hironori
no flags Details | Formatted Diff | Diff
Patch (4.01 KB, patch)
2018-10-15 02:06 PDT, Fujii Hironori
no flags Details | Formatted Diff | Diff
Patch (4.08 KB, patch)
2018-10-15 03:27 PDT, Fujii Hironori
no flags Details | Formatted Diff | Diff
Patch (4.15 KB, patch)
2018-10-15 03:34 PDT, Fujii Hironori
no flags Details | Formatted Diff | Diff
Patch (3.87 KB, patch)
2018-10-18 00:43 PDT, Fujii Hironori
no flags Details | Formatted Diff | Diff
Patch for landing (4.03 KB, patch)
2018-10-18 19:37 PDT, Fujii Hironori
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Fujii Hironori 2018-10-12 03:37:02 PDT
[Win][Clang] Do not give -Wall to clang-cl because it is treated as -Weverything

According to clang-cl manual, it has following command switch mapping:

https://clang.llvm.org/docs/UsersManual.html#id8

>  /W4                     Enable -Wall and -Wextra
>  /Wall                   Enable -Weverything

As the result, clang-cl treat -Wall as -Weverything, and reports ton of warning messages.
reported
Comment 1 Fujii Hironori 2018-10-12 04:10:34 PDT
Created attachment 352155 [details]
Patch
Comment 2 Fujii Hironori 2018-10-14 20:10:59 PDT
There is another issue some switches aren't effective.
For exampel -Wno-unknown-pragmas.
-Wno-unknown-pragmas should be specified after /W4, not before.
Comment 3 Fujii Hironori 2018-10-14 21:59:27 PDT
GCC and Clang treat -Wall differently.
Clang processes all -W* options in left-to-right order.
GCC processes -Wall and -Wextra options first.

https://bugs.llvm.org/show_bug.cgi?id=24376
https://gist.github.com/fujii/afb137300be40c71ea61b28391035ce7
Comment 4 Fujii Hironori 2018-10-15 02:06:10 PDT
Created attachment 352305 [details]
Patch
Comment 5 Fujii Hironori 2018-10-15 03:27:16 PDT
Created attachment 352306 [details]
Patch
Comment 6 Fujii Hironori 2018-10-15 03:34:09 PDT
Created attachment 352307 [details]
Patch
Comment 7 Konstantin Tokarev 2018-10-15 06:54:10 PDT
I think it would be more reasonable to avoid feeding COMPILER_IS_GCC_OR_CLANG options for clang-cl, because it expects cl.exe options instead
Comment 8 Fujii Hironori 2018-10-15 07:36:28 PDT
Thanks for your feedback. I was also thinking the same idea. But, I'm not confident which is better. I will try to create a patch in another bug ticket.

clang-cl compiles almost same code paths with MSVC. But there is only one exception.
clang-cl uses warning macros for Clang (IGNORE_WARNINGS_* and IGNORE_CLANG_WARNINGS_*), even though those macros are disabled for MSVC.
https://github.com/WebKit/webkit/blob/947003f6e3e05f3387e625d862e18cf61c15f03d/Source/WTF/wtf/Compiler.h#L442
With regard to compilation warnings, clang-cl is closer to clang than MSVC.
Comment 9 Fujii Hironori 2018-10-15 21:00:29 PDT
It turned out it is not simple as I expected.

Here are all usage of COMPILER_IS_GCC_OR_CLANG.
https://github.com/WebKit/webkit/search?q=COMPILER_IS_GCC_OR_CLANG&unscoped_q=COMPILER_IS_GCC_OR_CLANG

Almost all usage of COMPILER_IS_GCC_OR_CLANG is to suppress
compilation warnings, such like the following:

https://github.com/WebKit/webkit/blob/8138e195f0da39b5a476cbab5d3f1b8aafb6be4e/Tools/TestWebKitAPI/CMakeLists.txt#L265

> if (COMPILER_IS_GCC_OR_CLANG)
>     WEBKIT_ADD_TARGET_CXX_FLAGS(TestWTF -Wno-dangling-else
>                                         -Wno-sign-compare
>                                         -Wno-undef
>                                         -Wno-unused-parameter)
> endif ()

I'd like to share these warning switched with clang-cl.
It seems COMPILER_IS_GCC_OR_CLANG should be enabled for clang-cl.
Comment 10 Fujii Hironori 2018-10-16 18:36:48 PDT
Comment on attachment 352307 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=352307&action=review

> Source/cmake/WebKitCompilerFlags.cmake:147
> +    # -Wall and -Wextra should be speficied before -Wno-* for Clang.

s/speficied/specified/
Comment 11 Fujii Hironori 2018-10-18 00:43:58 PDT
Created attachment 352687 [details]
Patch
Comment 12 Fujii Hironori 2018-10-18 18:09:51 PDT
Review, please.
Comment 13 Michael Catanzaro 2018-10-18 18:21:55 PDT
Comment on attachment 352687 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=352687&action=review

> Source/cmake/WebKitCompilerFlags.cmake:148
> +if (NOT MSVC)

What about:

if (COMPILER_IS_GCC_OR_CLANG AND NOT MSVC)

It's just unfriendly to pass GCC flags to random compilers that might not be GCC compatible (even if it's unlikely that somebody would be attempting to use such a compiler nowadays.)
Comment 14 Fujii Hironori 2018-10-18 19:37:21 PDT
Created attachment 352757 [details]
Patch for landing

Thank you for the review. It makes sense. Applied the review feedback.
Comment 15 Fujii Hironori 2018-10-18 23:44:44 PDT
Comment on attachment 352757 [details]
Patch for landing

Clearing flags on attachment: 352757

Committed r237282: <https://trac.webkit.org/changeset/237282>
Comment 16 Fujii Hironori 2018-10-18 23:44:47 PDT
All reviewed patches have been landed.  Closing bug.