Page MenuHomePhabricator

[libc++] avoid a GCC -Wsigned-compare warning where time_t is unsigned
Needs ReviewPublic

Authored by yamt on Feb 2 2023, 12:11 AM.

Details

Reviewers
None
Group Reviewers
Restricted Project
Summary

Note: For some reasons, GCC -Wall enables the warning for C++
while it doesn't for C.

Diff Detail

Unit TestsFailed

TimeTest
1,500,040 mslibcxx CI Apple back-deployment with assertions enabled > apple-libc++-backdeployment-cfg-in.std/thread/thread_condition::notify_all_at_thread_exit_lwg3343.pass.cpp
Script: -- : 'COMPILED WITH'; /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ /Users/libcxx-buildkite-agent/libcxx.buildkite-agent/builds/f1-1-macminivault-com/llvm-project/libcxx-ci/libcxx/test/std/thread/thread.condition/notify_all_at_thread_exit_lwg3343.pass.cpp -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk --target=arm64-apple-macosx11.0 -nostdinc++ -I /Users/libcxx-buildkite-agent/libcxx.buildkite-agent/builds/f1-1-macminivault-com/llvm-project/libcxx-ci/build/apple-system-backdeployment-assertions-11.0/include/c++/v1 -I /Users/libcxx-buildkite-agent/libcxx.buildkite-agent/builds/f1-1-macminivault-com/llvm-project/libcxx-ci/libcxx/test/support -std=c++2b -Werror -Wall -Wctad-maybe-unsupported -Wextra -Wshadow -Wundef -Wno-unused-command-line-argument -Wno-attributes -Wno-pessimizing-move -Wno-c++11-extensions -Wno-noexcept-type -Wno-atomic-alignment -Wno-user-defined-literals -Wno-tautological-compare -Wsign-compare -Wunused-variable -Wunused-parameter -Wunreachable-code -Wno-unused-local-typedef -D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER -D_LIBCPP_ENABLE_ASSERTIONS=1 -Werror=thread-safety -Wuser-defined-warnings -nostdlib++ -L /Users/libcxx-buildkite-agent/libcxx.buildkite-agent/builds/f1-1-macminivault-com/llvm-project/libcxx-ci/build/apple-system-backdeployment-assertions-11.0/lib -lc++ -o /Users/libcxx-buildkite-agent/libcxx.buildkite-agent/builds/f1-1-macminivault-com/llvm-project/libcxx-ci/build/apple-system-backdeployment-assertions-11.0/test/std/thread/thread.condition/Output/notify_all_at_thread_exit_lwg3343.pass.cpp.dir/t.tmp.exe
3,490 mslibcxx CI Clang-cl (no vcruntime exceptions) > llvm-libc++-shared-no-vcruntime-clangcl-cfg-in.std/thread/thread_condition/thread_condition_condvar::notify_all.pass.cpp
Script: -- : 'COMPILED WITH'; 'C:/Program Files/LLVM/bin/clang-cl.exe' C:\ws\w7\llvm-project\libcxx-ci\libcxx\test\std\thread\thread.condition\thread.condition.condvar\notify_all.pass.cpp --driver-mode=g++ --target=x86_64-pc-windows-msvc -nostdinc++ -I C:/ws/w7/llvm-project/libcxx-ci/build/clang-cl-no-vcruntime/include/c++/v1 -I C:/ws/w7/llvm-project/libcxx-ci/build/clang-cl-no-vcruntime/include/c++/v1 -I C:/ws/w7/llvm-project/libcxx-ci/libcxx/test/support -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_WARNINGS -D_CRT_STDIO_ISO_WIDE_SPECIFIERS -DNOMINMAX -D_HAS_EXCEPTIONS=0 -std=c++2b -Werror -Wall -Wctad-maybe-unsupported -Wextra -Wshadow -Wundef -Wno-unused-command-line-argument -Wno-attributes -Wno-pessimizing-move -Wno-c++11-extensions -Wno-noexcept-type -Wno-atomic-alignment -Wno-user-defined-literals -Wno-tautological-compare -Wsign-compare -Wunused-variable -Wunused-parameter -Wunreachable-code -Wno-unused-local-typedef -D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER -D_LIBCPP_DISABLE_AVAILABILITY -Werror=thread-safety -Wuser-defined-warnings -DTEST_WINDOWS_DLL -nostdlib -L C:/ws/w7/llvm-project/libcxx-ci/build/clang-cl-no-vcruntime/lib -lc++ -lmsvcrt -lmsvcprt -loldnames -o C:\ws\w7\llvm-project\libcxx-ci\build\clang-cl-no-vcruntime\test\std\thread\thread.condition\thread.condition.condvar\Output\notify_all.pass.cpp.dir\t.tmp.exe

Event Timeline

yamt created this revision.Feb 2 2023, 12:11 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 2 2023, 12:11 AM
yamt requested review of this revision.Feb 2 2023, 12:11 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 2 2023, 12:11 AM
Herald added a reviewer: Restricted Project. · View Herald Transcript

Thanks for your patch! One suggestion.

libcxx/src/condition_variable.cpp
66

This is consistent with the next line.

yamt added inline comments.Feb 12 2023, 7:44 PM
libcxx/src/condition_variable.cpp
66

my understanding is that s.count() here is long long.
ts_sec is time_t, which can be narrower. (eg. int)

Mordante added inline comments.Feb 18 2023, 5:22 AM
libcxx/src/condition_variable.cpp
66

Good point, ts_sec, might indeed be a smaller type. (There is no guarantee count is long long, but it most likely is.)

I still wonder whether this change fixes anything, in glibc time_t is signed
https://www.gnu.org/software/libc/manual/html_node/Time-Types.html

Maybe it's safer to cast the result to the common type of these two types, WDYT?

yamt added inline comments.Feb 27 2023, 12:06 AM
libcxx/src/condition_variable.cpp
66

you are right this is not necessary for glibc.

however, for other platforms, time_t can be uint32_t, uint64_t, etc.
cf. https://github.com/apache/nuttx/pull/8201