Bug 182479 - [Win] Fix MSVC's treating __attribute__((warn_unused_result))
Summary: [Win] Fix MSVC's treating __attribute__((warn_unused_result))
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKit2 (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks: 174003
  Show dependency treegraph
 
Reported: 2018-02-05 04:20 PST by Yousuke Kimoto
Modified: 2018-02-20 11:30 PST (History)
8 users (show)

See Also:


Attachments
Patch (1.56 KB, patch)
2018-02-05 04:34 PST, Yousuke Kimoto
no flags Details | Formatted Diff | Diff
Patch (1.41 KB, patch)
2018-02-05 19:45 PST, Yousuke Kimoto
darin: review-
Details | Formatted Diff | Diff
Patch (1.44 KB, patch)
2018-02-15 05:28 PST, Yousuke Kimoto
no flags Details | Formatted Diff | Diff
Patch (1.44 KB, patch)
2018-02-15 09:56 PST, Yousuke Kimoto
darin: review+
commit-queue: commit-queue-
Details | Formatted Diff | Diff
Patch (a rebased version) (1.45 KB, patch)
2018-02-19 18:35 PST, Yousuke Kimoto
no flags Details | Formatted Diff | Diff
Patch (a rebased version) (1.44 KB, patch)
2018-02-19 18:44 PST, Yousuke Kimoto
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Yousuke Kimoto 2018-02-05 04:20:46 PST
MSVC doesn't understand __attribute((warn_unsed_resutl)), but it has a similar option, _Check_return_.

MSVC Annotating Function Behavior:
https://msdn.microsoft.com/en-us/library/jj159529.aspx
Comment 1 Yousuke Kimoto 2018-02-05 04:34:36 PST
Created attachment 333074 [details]
Patch
Comment 2 Yousuke Kimoto 2018-02-05 06:58:57 PST
>ERROR: '/Volumes/Data/EWS/WebKit/WebKitBuild/Release/WebKitFailed to run "['Tools/Scripts/build-webkit', '--release']" exit_code: 65
>Last 500 characters of output:
>A55DEAA61670402E003DB841.sh
>ERROR: >'/Volumes/Data/EWS/WebKit/WebKitBuild/Release/WebKit.framework/Versions/A/PrivateHeaders/WKRetainPtr.h:245' included forbidden macro 'COMPILER' => '#if !COMPILER(MSVC)'
>Command /bin/sh failed with exit code 1
>
>** BUILD FAILED **
>
>The following build commands failed:
>	PhaseScriptExecution Check\ For\ Inappropriate\ Macros\ in\ External\ Headers /Volumes/Data/EWS/WebKit/WebKitBuild/WebKit.build/Release/WebKit.build/Script-A55DEAA61670402E003DB841.sh
>(1 failure)
Mac and iOS failed by the same reason like the above.
Comment 3 Alex Christensen 2018-02-05 17:29:33 PST
Comment on attachment 333074 [details]
Patch

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

> Source/WebKit/UIProcess/API/cpp/WKRetainPtr.h:245
> +#if !COMPILER(MSVC)

We usually try to put the positive first, so this would be #if COMPILER(MSVC)
But you can't use COMPILER here because this header is part of the API.  Elsewhere in the API we've done #if defined(WIN32) || defined(_WIN32), but maybe we should check _MSC_VER instead for people using clang on windows.
Comment 4 Yousuke Kimoto 2018-02-05 19:07:38 PST
(In reply to Alex Christensen from comment #3)
> We usually try to put the positive first, so this would be #if COMPILER(MSVC)
> But you can't use COMPILER here because this header is part of the API. 
> Elsewhere in the API we've done #if defined(WIN32) || defined(_WIN32), but
> maybe we should check _MSC_VER instead for people using clang on windows.

Thank you for your advice. I'll fix it with the condition you suggested.
Comment 5 Yousuke Kimoto 2018-02-05 19:45:46 PST
Created attachment 333152 [details]
Patch
Comment 6 Yousuke Kimoto 2018-02-06 05:04:49 PST
(In reply to Alex Christensen from comment #3)
> maybe we should check _MSC_VER instead for people using clang on windows.
Table about _MSC_VER  and Visual Studio version:
https://blogs.msdn.microsoft.com/vcblog/2015/12/04/clang-with-microsoft-codegen-in-vs-2015-update-1/
https://cpprefjp.github.io/implementation.html#visual_cpp

I have two questions about _MSC_VER.

1. Is VisualStudio 2017 a recommended IDE on windows ?

2. When clang is used on windows, which template should be chosen, a) or b)?
  a) template<typename T> inline WKRetainPtr<T> adoptWK(T) _Check_return_;
  b) template<typename T> inline WKRetainPtr<T> adoptWK(T) __attribute__((warn_unused_result));
Comment 7 Yousuke Kimoto 2018-02-07 19:37:33 PST
Comment on attachment 333152 [details]
Patch

I confirmed this patch works on the wincairo build but the Bot status was failure on wincairo.

If we take care of clang users on windows, for example, the part will be as follows.
(In this case, supposing VisualStudio 2017 and Clang/C2 are used.)
Please give me your comment.

#if defined(WIN32) || defined(_WIN32)
#if (_MSC_VER > 1900) && (__c2__)
template<typename T> inline WKRetainPtr<T> adoptWK(T) __attribute__((warn_unused_result));
#else
template<typename T> inline WKRetainPtr<T> adoptWK(T) _Check_return_;
#endif
#else
template<typename T> inline WKRetainPtr<T> adoptWK(T) __attribute__((warn_unused_result));
#endif
Comment 8 Darin Adler 2018-02-14 16:36:10 PST
Comment on attachment 333152 [details]
Patch

This is the wrong fix. The correct fix would be to use WARN_UNUSED_RETURN from Compiler.h instead of using warn_unused_result directly.
Comment 9 Darin Adler 2018-02-14 16:38:08 PST
Comment on attachment 333152 [details]
Patch

Oh wait, I see, this is in an "API" header. Maybe this is OK, then. Lets try it at least.
Comment 10 Darin Adler 2018-02-14 16:38:52 PST
Comment on attachment 333152 [details]
Patch

Actually, the compiler version issue you mentioned has to be resolved first, so back to review-.
Comment 11 Yousuke Kimoto 2018-02-15 05:28:53 PST
Created attachment 333892 [details]
Patch
Comment 12 Yousuke Kimoto 2018-02-15 09:56:02 PST
Created attachment 333909 [details]
Patch
Comment 13 Yousuke Kimoto 2018-02-15 14:26:00 PST
(In reply to Darin Adler from comment #10)
> Actually, the compiler version issue you mentioned has to be resolved first,
> so back to review-.

> Created attachment 333909 [details]

This patch fixed the compiler version issue. Could you review it again?
Comment 14 WebKit Commit Bot 2018-02-18 08:04:20 PST
Comment on attachment 333909 [details]
Patch

Rejecting attachment 333909 [details] from commit-queue.

Failed to run "['/Volumes/Data/EWS/WebKit/Tools/Scripts/webkit-patch', '--status-host=webkit-queues.webkit.org', '--bot-id=webkit-cq-02', 'land-attachment', '--force-clean', '--non-interactive', '--parent-command=commit-queue', 333909, '--port=mac']" exit_code: 1 cwd: /Volumes/Data/EWS/WebKit

Last 500 characters of output:
rdparty/autoinstalled/mechanize/_urllib2_fork.py", line 332, in _call_chain
    result = func(*args)
  File "/Volumes/Data/EWS/WebKit/Tools/Scripts/webkitpy/thirdparty/autoinstalled/mechanize/_urllib2_fork.py", line 1170, in https_open
    return self.do_open(conn_factory, req)
  File "/Volumes/Data/EWS/WebKit/Tools/Scripts/webkitpy/thirdparty/autoinstalled/mechanize/_urllib2_fork.py", line 1118, in do_open
    raise URLError(err)
urllib2.URLError: <urlopen error [Errno 60] Operation timed out>

Full output: http://webkit-queues.webkit.org/results/6563066
Comment 15 Yousuke Kimoto 2018-02-19 18:35:04 PST
Created attachment 334223 [details]
Patch (a rebased version)

This patch is a rebased version of attachment 333909 [details].
Comment 16 Yousuke Kimoto 2018-02-19 18:44:10 PST
Created attachment 334224 [details]
Patch (a rebased version)
Comment 17 WebKit Commit Bot 2018-02-20 00:42:17 PST
Comment on attachment 334224 [details]
Patch (a rebased version)

Clearing flags on attachment: 334224

Committed r228751: <https://trac.webkit.org/changeset/228751>
Comment 18 Don Olmstead 2018-02-20 11:29:15 PST
Not sure why this didn't get closed automagically.
Comment 19 Radar WebKit Bug Importer 2018-02-20 11:30:46 PST
<rdar://problem/37715172>