This is an archive of the discontinued LLVM Phabricator instance.

[libcxx] Fix building on Windows after 346ef5e5879e9143fe008c35c3dd6ea3c402634a
AbandonedPublic

Authored by mstorsjo on Dec 21 2021, 1:09 PM.

Details

Reviewers
ldionne
Group Reviewers
Restricted Project
Summary

That commit, while intended to be NFC, wasn't.

libcxx/src/random.cpp used to first include <__config>, which used
to define _LIBCPP_USING_WIN32_RANDOM (but which doesn't include
any other system headers). After that, it checked for
_LIBCPP_USING_WIN32_RANDOM, and conditionally defined _CRT_RAND_S.
This was defined before including any further headers, as this has
to be defined for the declaration of rand_s() to be visible, and
has to be defined before including stdlib.h.

After that commit, _LIBCPP_USING_WIN32_RANDOM was defined only
later, in __random/random_device.h (which is included in
<random>). But we can't define _CRT_RAND_S after that, because
stdlib.h probably has been pulled in already at that point.

Instead loosen the criteria for defining _CRT_RAND_S to
_LIBCPP_WIN32API, which practically is defined exactly when
_LIBCPP_USING_WIN32_RANDOM is defined.

Diff Detail

Event Timeline

mstorsjo requested review of this revision.Dec 21 2021, 1:09 PM
mstorsjo created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptDec 21 2021, 1:09 PM
Herald added a reviewer: Restricted Project. · View Herald Transcript