This is an archive of the discontinued LLVM Phabricator instance.

[libc++] Fix the wrong usage of __STDC_HOSTED__
ClosedPublic

Authored by hyd-dev on Aug 17 2020, 4:05 AM.

Details

Reviewers
__simt__
jfb
ldionne
Group Reviewers
Restricted Project
Commits
rG44cc78da056f: [libc++] Fix incorrect usage of __STDC_HOSTED__
Summary

D56913 introduced the _LIBCPP_FREESTANDING macro and implemented it as:

#ifndef __STDC_HOSTED__
#  define _LIBCPP_FREESTANDING
#endif

However, __STDC_HOSTED__ is defined as 0 in freestanding implementations instead of undefined (according to https://github.com/llvm/llvm-project/blob/cd2139a527f2d829bdde7877c992215f598e927b/clang/lib/Frontend/InitPreprocessor.cpp#L356-L362 and https://en.cppreference.com/w/cpp/preprocessor/replace).
This patch corrects the above as:

#if __STDC_HOSTED__ == 0
#  define _LIBCPP_FREESTANDING
#endif

Diff Detail

Event Timeline

hyd-dev created this revision.Aug 17 2020, 4:05 AM
Herald added a reviewer: Restricted Project. · View Herald TranscriptAug 17 2020, 4:05 AM
hyd-dev requested review of this revision.Aug 17 2020, 4:05 AM
hyd-dev updated this revision to Diff 288919.Aug 31 2020, 4:31 AM
hyd-dev edited the summary of this revision. (Show Details)

Add a test (libcxx/test/libcxx/libcpp_freestanding.sh.cpp).

ldionne requested changes to this revision.Sep 1 2020, 7:57 AM

Thanks for the fix. See my concern about the test, though.

libcxx/test/libcxx/libcpp_freestanding.sh.cpp
2

Did you run this test? I don't think we can use FileCheck in the libcxx tests yet, can we?

I had a patch lying somewhere that enabled FileCheck in the libc++ test suite, but I had shelved it when it became a lot more complicated than expected. Perhaps it's now time to revive it?

This revision now requires changes to proceed.Sep 1 2020, 7:57 AM
hyd-dev added inline comments.Sep 2 2020, 1:00 AM
libcxx/test/libcxx/libcpp_freestanding.sh.cpp
2

Did you run this test? I don't think we can use FileCheck in the libcxx tests yet, can we?

Sorry, I have run this test before submitting it and it passed, but that was because I installed FileCheck using the system package manager.

I had a patch lying somewhere that enabled FileCheck in the libc++ test suite, but I had shelved it when it became a lot more complicated than expected. Perhaps it's now time to revive it?

That's not necessary. I'll update the test to use #ifdefs and #errors.

hyd-dev updated this revision to Diff 289366.Sep 2 2020, 1:37 AM

Update the test to use #if defineds and #error.

hyd-dev marked an inline comment as done.Sep 2 2020, 1:39 AM
ldionne accepted this revision.Sep 2 2020, 8:52 AM

Thanks for fixing!

This revision is now accepted and ready to land.Sep 2 2020, 8:52 AM

@ldionne Thanks! Could you commit it for me (hyd-dev <yd-huang@outlook.com>)?

Committed, thanks!

This revision was automatically updated to reflect the committed changes.