[llvm-branch-commits] [llvm] 9373c49 - LTO: Pass more aggresive optimization options

2021-02-01 Thread Tobias Hieta via llvm-branch-commits

Author: Tobias Hieta
Date: 2020-12-29T09:16:31+01:00
New Revision: 9373c496c2eaeea19ed8e6c6d1b4ab0d488279fb

URL: 
https://github.com/llvm/llvm-project/commit/9373c496c2eaeea19ed8e6c6d1b4ab0d488279fb
DIFF: 
https://github.com/llvm/llvm-project/commit/9373c496c2eaeea19ed8e6c6d1b4ab0d488279fb.diff

LOG: LTO: Pass more aggresive optimization options

Added: 


Modified: 
llvm/cmake/modules/HandleLLVMOptions.cmake

Removed: 




diff  --git a/llvm/cmake/modules/HandleLLVMOptions.cmake 
b/llvm/cmake/modules/HandleLLVMOptions.cmake
index 5ef22eb493ba..c929cb5abe52 100644
--- a/llvm/cmake/modules/HandleLLVMOptions.cmake
+++ b/llvm/cmake/modules/HandleLLVMOptions.cmake
@@ -956,9 +956,9 @@ if(LLVM_ENABLE_LTO AND LLVM_ON_WIN32 AND NOT 
LINKER_IS_LLD_LINK AND NOT MINGW)
   message(FATAL_ERROR "When compiling for Windows, LLVM_ENABLE_LTO requires 
using lld as the linker (point CMAKE_LINKER at lld-link.exe)")
 endif()
 if(uppercase_LLVM_ENABLE_LTO STREQUAL "THIN")
-  append("-flto=thin" CMAKE_CXX_FLAGS CMAKE_C_FLAGS)
+  append("-flto=thin -fwhole-program-vtables" CMAKE_CXX_FLAGS CMAKE_C_FLAGS)
   if(NOT LINKER_IS_LLD_LINK)
-append("-flto=thin" CMAKE_EXE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS)
+append("-flto=thin -fwhole-program-vtables 
-Wl,--lto-whole-program-visibility -Wl,--icf=all" CMAKE_EXE_LINKER_FLAGS 
CMAKE_SHARED_LINKER_FLAGS)
   endif()
   # If the linker supports it, enable the lto cache. This improves initial 
build
   # time a little since we re-link a lot of the same objects, and significantly



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] 153ed7e - roll back some options

2021-02-01 Thread Tobias Hieta via llvm-branch-commits

Author: Tobias Hieta
Date: 2020-12-29T09:16:31+01:00
New Revision: 153ed7e0b4da674decff9730f6164ebf7da8dbca

URL: 
https://github.com/llvm/llvm-project/commit/153ed7e0b4da674decff9730f6164ebf7da8dbca
DIFF: 
https://github.com/llvm/llvm-project/commit/153ed7e0b4da674decff9730f6164ebf7da8dbca.diff

LOG: roll back some options

Added: 


Modified: 
llvm/cmake/modules/HandleLLVMOptions.cmake

Removed: 




diff  --git a/llvm/cmake/modules/HandleLLVMOptions.cmake 
b/llvm/cmake/modules/HandleLLVMOptions.cmake
index c929cb5abe52..c661b772fcc3 100644
--- a/llvm/cmake/modules/HandleLLVMOptions.cmake
+++ b/llvm/cmake/modules/HandleLLVMOptions.cmake
@@ -958,7 +958,7 @@ endif()
 if(uppercase_LLVM_ENABLE_LTO STREQUAL "THIN")
   append("-flto=thin -fwhole-program-vtables" CMAKE_CXX_FLAGS CMAKE_C_FLAGS)
   if(NOT LINKER_IS_LLD_LINK)
-append("-flto=thin -fwhole-program-vtables 
-Wl,--lto-whole-program-visibility -Wl,--icf=all" CMAKE_EXE_LINKER_FLAGS 
CMAKE_SHARED_LINKER_FLAGS)
+append("-flto=thin -fwhole-program-vtables" CMAKE_EXE_LINKER_FLAGS 
CMAKE_SHARED_LINKER_FLAGS)
   endif()
   # If the linker supports it, enable the lto cache. This improves initial 
build
   # time a little since we re-link a lot of the same objects, and significantly



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [libcxx] dde4343 - [libc++] NFCI: Refactor chrono.cpp to make it easier to support new platforms

2021-02-01 Thread Tobias Hieta via llvm-branch-commits

Author: Louis Dionne
Date: 2021-02-01T14:09:15+01:00
New Revision: dde4343cae5ecfa29b57c5af5043f3dfb3845ea1

URL: 
https://github.com/llvm/llvm-project/commit/dde4343cae5ecfa29b57c5af5043f3dfb3845ea1
DIFF: 
https://github.com/llvm/llvm-project/commit/dde4343cae5ecfa29b57c5af5043f3dfb3845ea1.diff

LOG: [libc++] NFCI: Refactor chrono.cpp to make it easier to support new 
platforms

Also simplify a few conditionals along the way for readability.

Added: 


Modified: 
libcxx/src/chrono.cpp

Removed: 




diff  --git a/libcxx/src/chrono.cpp b/libcxx/src/chrono.cpp
index c88224c61bdb..1419cf2f74a8 100644
--- a/libcxx/src/chrono.cpp
+++ b/libcxx/src/chrono.cpp
@@ -42,14 +42,13 @@ _LIBCPP_BEGIN_NAMESPACE_STD
 namespace chrono
 {
 
+//
 // system_clock
+//
 
-const bool system_clock::is_steady;
-
-system_clock::time_point
-system_clock::now() _NOEXCEPT
-{
 #if defined(_LIBCPP_WIN32API)
+
+static system_clock::time_point __libcpp_system_clock_now() {
   // FILETIME is in 100ns units
   using filetime_duration =
   _VSTD::chrono::duration<__int64,
@@ -60,31 +59,42 @@ system_clock::now() _NOEXCEPT
   static _LIBCPP_CONSTEXPR const seconds nt_to_unix_epoch{11644473600};
 
   FILETIME ft;
-#if _WIN32_WINNT >= _WIN32_WINNT_WIN8
-#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
+#if _WIN32_WINNT >= _WIN32_WINNT_WIN8 && 
WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
   GetSystemTimePreciseAsFileTime(&ft);
-#else
-  GetSystemTimeAsFileTime(&ft);
-#endif
 #else
   GetSystemTimeAsFileTime(&ft);
 #endif
 
   filetime_duration d{(static_cast<__int64>(ft.dwHighDateTime) << 32) |
static_cast<__int64>(ft.dwLowDateTime)};
-  return time_point(duration_cast(d - nt_to_unix_epoch));
-#else
-#if defined(CLOCK_REALTIME) && defined(_LIBCPP_USE_CLOCK_GETTIME)
+  return system_clock::time_point(duration_cast(d - 
nt_to_unix_epoch));
+}
+
+#elif defined(CLOCK_REALTIME) && defined(_LIBCPP_USE_CLOCK_GETTIME)
+
+static system_clock::time_point __libcpp_system_clock_now() {
   struct timespec tp;
   if (0 != clock_gettime(CLOCK_REALTIME, &tp))
 __throw_system_error(errno, "clock_gettime(CLOCK_REALTIME) failed");
-  return time_point(seconds(tp.tv_sec) + microseconds(tp.tv_nsec / 1000));
+  return system_clock::time_point(seconds(tp.tv_sec) + microseconds(tp.tv_nsec 
/ 1000));
+}
+
 #else
+
+static system_clock::time_point __libcpp_system_clock_now() {
 timeval tv;
 gettimeofday(&tv, 0);
-return time_point(seconds(tv.tv_sec) + microseconds(tv.tv_usec));
-#endif
+return system_clock::time_point(seconds(tv.tv_sec) + 
microseconds(tv.tv_usec));
+}
+
 #endif
+
+const bool system_clock::is_steady;
+
+system_clock::time_point
+system_clock::now() _NOEXCEPT
+{
+return __libcpp_system_clock_now();
 }
 
 time_t
@@ -99,33 +109,28 @@ system_clock::from_time_t(time_t t) _NOEXCEPT
 return system_clock::time_point(seconds(t));
 }
 
-#ifndef _LIBCPP_HAS_NO_MONOTONIC_CLOCK
+//
 // steady_clock
 //
 // Warning:  If this is not truly steady, then it is non-conforming.  It is
 //  better for it to not exist and have the rest of libc++ use system_clock
 //  instead.
+//
 
-const bool steady_clock::is_steady;
+#ifndef _LIBCPP_HAS_NO_MONOTONIC_CLOCK
 
 #if defined(__APPLE__)
 
-#if !defined(CLOCK_MONOTONIC_RAW)
-#  error "Building libc++ on Apple platforms requires CLOCK_MONOTONIC_RAW"
-#endif
-
 // On Apple platforms, only CLOCK_UPTIME_RAW, CLOCK_MONOTONIC_RAW or
 // mach_absolute_time are able to time functions in the nanosecond range.
 // Furthermore, only CLOCK_MONOTONIC_RAW is truly monotonic, because it
 // also counts cycles when the system is asleep. Thus, it is the only
 // acceptable implementation of steady_clock.
-steady_clock::time_point
-steady_clock::now() _NOEXCEPT
-{
+static steady_clock::time_point __libcpp_steady_clock_now() {
 struct timespec tp;
 if (0 != clock_gettime(CLOCK_MONOTONIC_RAW, &tp))
 __throw_system_error(errno, "clock_gettime(CLOCK_MONOTONIC_RAW) 
failed");
-return time_point(seconds(tp.tv_sec) + nanoseconds(tp.tv_nsec));
+return steady_clock::time_point(seconds(tp.tv_sec) + 
nanoseconds(tp.tv_nsec));
 }
 
 #elif defined(_LIBCPP_WIN32API)
@@ -138,36 +143,40 @@ steady_clock::now() _NOEXCEPT
 static LARGE_INTEGER
 __QueryPerformanceFrequency()
 {
-   LARGE_INTEGER val;
-   (void) QueryPerformanceFrequency(&val);
-   return val;
+LARGE_INTEGER val;
+(void) QueryPerformanceFrequency(&val);
+return val;
 }
 
-steady_clock::time_point
-steady_clock::now() _NOEXCEPT
-{
+static steady_clock::time_point __libcpp_steady_clock_now() {
   static const LARGE_INTEGER freq = __QueryPerformanceFrequency();
 
   LARGE_INTEGER counter;
   (void) QueryPerformanceCounter(&counter);
-  return time_point(duration(counter.QuadPart * nano::den / freq.QuadPart));
+  return steady_clock::time_point(steady_clock::duration(counter.QuadPart * 
nano::den / freq

[llvm-branch-commits] [llvm] bb798f2 - Add support for -delete_all_rpaths to llvm-install-name-tool

2021-02-01 Thread Tobias Hieta via llvm-branch-commits

Author: Tobias Hieta
Date: 2020-12-29T09:16:32+01:00
New Revision: bb798f2a85a50991ed05aa10d4146f5855d9b24f

URL: 
https://github.com/llvm/llvm-project/commit/bb798f2a85a50991ed05aa10d4146f5855d9b24f
DIFF: 
https://github.com/llvm/llvm-project/commit/bb798f2a85a50991ed05aa10d4146f5855d9b24f.diff

LOG: Add support for -delete_all_rpaths to llvm-install-name-tool

Added: 


Modified: 
llvm/tools/llvm-objcopy/CopyConfig.cpp
llvm/tools/llvm-objcopy/CopyConfig.h
llvm/tools/llvm-objcopy/InstallNameToolOpts.td
llvm/tools/llvm-objcopy/MachO/MachOObjcopy.cpp

Removed: 




diff  --git a/llvm/tools/llvm-objcopy/CopyConfig.cpp 
b/llvm/tools/llvm-objcopy/CopyConfig.cpp
index 1fde54dd290a..f9a3b030dc64 100644
--- a/llvm/tools/llvm-objcopy/CopyConfig.cpp
+++ b/llvm/tools/llvm-objcopy/CopyConfig.cpp
@@ -909,6 +909,8 @@ parseInstallNameToolOptions(ArrayRef ArgsArr) 
{
 Config.InstallNamesToUpdate.insert({Arg->getValue(0), Arg->getValue(1)});
   }
 
+  Config.RemoveAllRpaths = 
InputArgs.hasArg(INSTALL_NAME_TOOL_delete_all_rpaths);
+
   SmallVector Positional;
   for (auto Arg : InputArgs.filtered(INSTALL_NAME_TOOL_UNKNOWN))
 return createStringError(errc::invalid_argument, "unknown argument '%s'",

diff  --git a/llvm/tools/llvm-objcopy/CopyConfig.h 
b/llvm/tools/llvm-objcopy/CopyConfig.h
index 1341dd674c7b..44acbb62d90b 100644
--- a/llvm/tools/llvm-objcopy/CopyConfig.h
+++ b/llvm/tools/llvm-objcopy/CopyConfig.h
@@ -230,6 +230,9 @@ struct CopyConfig {
   bool StripUnneeded = false;
   bool Weaken = false;
   bool DecompressDebugSections = false;
+  // install-name-tool's delete_all_rpaths
+  bool RemoveAllRpaths = false;
+
   DebugCompressionType CompressionType = DebugCompressionType::None;
 
   // parseELFConfig performs ELF-specific command-line parsing. Fills `ELF` on

diff  --git a/llvm/tools/llvm-objcopy/InstallNameToolOpts.td 
b/llvm/tools/llvm-objcopy/InstallNameToolOpts.td
index 04ffe62c42fc..97236cf623b7 100644
--- a/llvm/tools/llvm-objcopy/InstallNameToolOpts.td
+++ b/llvm/tools/llvm-objcopy/InstallNameToolOpts.td
@@ -21,6 +21,9 @@ def add_rpath : Option<["-", "--"], "add_rpath", 
KIND_SEPARATE>,
 def delete_rpath: Option<["-", "--"], "delete_rpath", KIND_SEPARATE>,
   HelpText<"Delete specified rpath">;
 
+def delete_all_rpaths: Flag<["--"], "delete_all_rpaths">,
+  HelpText<"Delete all rpath directives">;
+
 def rpath: MultiArg<["-", "--"], "rpath", 2>,
HelpText<"Change rpath path name">;
 

diff  --git a/llvm/tools/llvm-objcopy/MachO/MachOObjcopy.cpp 
b/llvm/tools/llvm-objcopy/MachO/MachOObjcopy.cpp
index 5ca5b133572b..c0615e6b84ba 100644
--- a/llvm/tools/llvm-objcopy/MachO/MachOObjcopy.cpp
+++ b/llvm/tools/llvm-objcopy/MachO/MachOObjcopy.cpp
@@ -133,9 +133,16 @@ static Error processLoadCommands(const CopyConfig &Config, 
Object &Obj) {
   DenseSet RPathsToRemove(Config.RPathsToRemove.begin(),
  Config.RPathsToRemove.end());
 
-  LoadCommandPred RemovePred = [&RPathsToRemove](const LoadCommand &LC) {
+  LoadCommandPred RemovePred = [&RPathsToRemove, &Config](const LoadCommand 
&LC) {
 if (LC.MachOLoadCommand.load_command_data.cmd == MachO::LC_RPATH) {
+  // When removing all RPaths we don't need to care
+  // about what it contains
+  if (Config.RemoveAllRpaths) {
+return true;
+  }
+
   StringRef RPath = getPayloadString(LC);
+
   if (RPathsToRemove.count(RPath)) {
 RPathsToRemove.erase(RPath);
 return true;



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [libcxx] 470bc83 - [libc++] Check _LIBCPP_USE_CLOCK_GETTIME before using clock_gettime

2021-02-01 Thread Tobias Hieta via llvm-branch-commits

Author: Hafiz Abid Qadeer
Date: 2021-02-01T14:08:48+01:00
New Revision: 470bc83efffe3e4b6a5a00ec47069a972b7db94d

URL: 
https://github.com/llvm/llvm-project/commit/470bc83efffe3e4b6a5a00ec47069a972b7db94d
DIFF: 
https://github.com/llvm/llvm-project/commit/470bc83efffe3e4b6a5a00ec47069a972b7db94d.diff

LOG: [libc++] Check _LIBCPP_USE_CLOCK_GETTIME before using clock_gettime

The clock_gettime function is available when _POSIX_TIMERS is defined.
We check for this and set _LIBCPP_USE_CLOCK_GETTIME accordingly since
59b3102739c. But check for _LIBCPP_USE_CLOCK_GETTIME was removed in
babd3aefc91. As a result, code is now trying to use clock_gettime even
on platforms where it is not available and it is causing build failure
with newlib.

This patch restores the checks to fix this.

Differential Revision: https://reviews.llvm.org/D88825

Added: 


Modified: 
libcxx/src/chrono.cpp

Removed: 




diff  --git a/libcxx/src/chrono.cpp b/libcxx/src/chrono.cpp
index f0a5d50ddf77..c88224c61bdb 100644
--- a/libcxx/src/chrono.cpp
+++ b/libcxx/src/chrono.cpp
@@ -13,11 +13,15 @@
 #include "include/apple_availability.h"
 
 #if __has_include()
-#include 
+# include 
+#endif
+
+#if __has_include()
+# include  // for gettimeofday and timeval
 #endif
 
 #if !defined(__APPLE__) && _POSIX_TIMERS > 0
-#define _LIBCPP_USE_CLOCK_GETTIME
+# define _LIBCPP_USE_CLOCK_GETTIME
 #endif
 
 #if defined(_LIBCPP_WIN32API)
@@ -27,10 +31,6 @@
 #  if _WIN32_WINNT >= _WIN32_WINNT_WIN8
 #include 
 #  endif
-#else
-#  if !defined(CLOCK_REALTIME)
-#include // for gettimeofday and timeval
-#  endif // !defined(CLOCK_REALTIME)
 #endif // defined(_LIBCPP_WIN32API)
 
 #if defined(__ELF__) && defined(_LIBCPP_LINK_RT_LIB)
@@ -74,7 +74,7 @@ system_clock::now() _NOEXCEPT
static_cast<__int64>(ft.dwLowDateTime)};
   return time_point(duration_cast(d - nt_to_unix_epoch));
 #else
-#if defined(CLOCK_REALTIME)
+#if defined(CLOCK_REALTIME) && defined(_LIBCPP_USE_CLOCK_GETTIME)
   struct timespec tp;
   if (0 != clock_gettime(CLOCK_REALTIME, &tp))
 __throw_system_error(errno, "clock_gettime(CLOCK_REALTIME) failed");
@@ -83,7 +83,7 @@ system_clock::now() _NOEXCEPT
 timeval tv;
 gettimeofday(&tv, 0);
 return time_point(seconds(tv.tv_sec) + microseconds(tv.tv_usec));
-#endif // CLOCK_REALTIME
+#endif
 #endif
 }
 



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [libcxx] bbce4b6 - [libc++] Bring back mach_absolute_time implementation of steady_clock

2021-02-01 Thread Tobias Hieta via llvm-branch-commits

Author: Louis Dionne
Date: 2021-02-01T14:09:36+01:00
New Revision: bbce4b6cb1e2b38c7aac416dcb5567f23c6d39d6

URL: 
https://github.com/llvm/llvm-project/commit/bbce4b6cb1e2b38c7aac416dcb5567f23c6d39d6
DIFF: 
https://github.com/llvm/llvm-project/commit/bbce4b6cb1e2b38c7aac416dcb5567f23c6d39d6.diff

LOG: [libc++] Bring back mach_absolute_time implementation of steady_clock

This is meant to unblock Chrome, as discussed in https://llvm.org/D74489.

Differential Revision: https://reviews.llvm.org/D95177

Added: 


Modified: 
libcxx/src/chrono.cpp

Removed: 




diff  --git a/libcxx/src/chrono.cpp b/libcxx/src/chrono.cpp
index 5291d4fa8dc6..085fbfde26c1 100644
--- a/libcxx/src/chrono.cpp
+++ b/libcxx/src/chrono.cpp
@@ -33,6 +33,10 @@
 #  endif
 #endif // defined(_LIBCPP_WIN32API)
 
+#if __has_include()
+# include 
+#endif
+
 #if defined(__ELF__) && defined(_LIBCPP_LINK_RT_LIB)
 #  pragma comment(lib, "rt")
 #endif
@@ -121,6 +125,59 @@ system_clock::from_time_t(time_t t) _NOEXCEPT
 
 #if defined(__APPLE__)
 
+// TODO(ldionne):
+// This old implementation of steady_clock is retained until Chrome drops 
supports
+// for macOS < 10.12. The issue is that they link libc++ statically into their
+// application, which means that libc++ must support being built for such 
deployment
+// targets. See https://llvm.org/D74489 for details.
+#if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && 
__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 101200) || \
+(defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && 
__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ < 10) || \
+(defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__) && 
__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ < 10) || \
+(defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__) && 
__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ < 3)
+# define _LIBCPP_USE_OLD_MACH_ABSOLUTE_TIME
+#endif
+
+#if defined(_LIBCPP_USE_OLD_MACH_ABSOLUTE_TIME)
+
+//   mach_absolute_time() * MachInfo.numer / MachInfo.denom is the number of
+//   nanoseconds since the computer booted up.  MachInfo.numer and 
MachInfo.denom
+//   are run time constants supplied by the OS.  This clock has no relationship
+//   to the Gregorian calendar.  It's main use is as a high resolution timer.
+
+// MachInfo.numer / MachInfo.denom is often 1 on the latest equipment.  
Specialize
+//   for that case as an optimization.
+
+static steady_clock::rep steady_simplified() {
+return static_cast(mach_absolute_time());
+}
+static double compute_steady_factor() {
+mach_timebase_info_data_t MachInfo;
+mach_timebase_info(&MachInfo);
+return static_cast(MachInfo.numer) / MachInfo.denom;
+}
+
+static steady_clock::rep steady_full() {
+static const double factor = compute_steady_factor();
+return static_cast(mach_absolute_time() * factor);
+}
+
+typedef steady_clock::rep (*FP)();
+
+static FP init_steady_clock() {
+mach_timebase_info_data_t MachInfo;
+mach_timebase_info(&MachInfo);
+if (MachInfo.numer == MachInfo.denom)
+return &steady_simplified;
+return &steady_full;
+}
+
+static steady_clock::time_point __libcpp_steady_clock_now() {
+static FP fp = init_steady_clock();
+return steady_clock::time_point(steady_clock::duration(fp()));
+}
+
+#else // v default behavior for Apple platforms  v
+
 // On Apple platforms, only CLOCK_UPTIME_RAW, CLOCK_MONOTONIC_RAW or
 // mach_absolute_time are able to time functions in the nanosecond range.
 // Furthermore, only CLOCK_MONOTONIC_RAW is truly monotonic, because it
@@ -133,6 +190,8 @@ static steady_clock::time_point __libcpp_steady_clock_now() 
{
 return steady_clock::time_point(seconds(tp.tv_sec) + 
nanoseconds(tp.tv_nsec));
 }
 
+#endif
+
 #elif defined(_LIBCPP_WIN32API)
 
 // 
https://msdn.microsoft.com/en-us/library/windows/desktop/ms644905(v=vs.85).aspx 
says:



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [libcxx] 579d0dc - [libcxx] Avoid overflows in the windows __libcpp_steady_clock_now()

2021-02-01 Thread Tobias Hieta via llvm-branch-commits

Author: Martin Storsjö
Date: 2021-02-01T14:09:23+01:00
New Revision: 579d0dc25dcd72e0a0a1411426c921cf01bfefe3

URL: 
https://github.com/llvm/llvm-project/commit/579d0dc25dcd72e0a0a1411426c921cf01bfefe3
DIFF: 
https://github.com/llvm/llvm-project/commit/579d0dc25dcd72e0a0a1411426c921cf01bfefe3.diff

LOG: [libcxx] Avoid overflows in the windows __libcpp_steady_clock_now()

As freq.QuadValue can be in the range of 1000 to 1920,
the multiplication before division makes the calculation overflow
and wrap to negative values every 16-30 minutes.

Instead count the whole seconds separately before adding the
scaled fractional seconds.

Add a testcase for steady_clock to check that the values returned for
now() compare as bigger than the zero time origin; this
corresponds to a testcase in Qt [1] [2] (that failed spuriously
due to this).

[1] https://bugreports.qt.io/browse/QTBUG-89539
[2] 
https://code.qt.io/cgit/qt/qtbase.git/tree/tests/auto/corelib/kernel/qdeadlinetimer/tst_qdeadlinetimer.cpp?id=f8de5e54022b8b7471131b7ad55c83b69b2684c0#n569

Differential Revision: https://reviews.llvm.org/D93456

Added: 


Modified: 
libcxx/src/chrono.cpp
libcxx/test/std/utilities/time/time.clock/time.clock.steady/now.pass.cpp

Removed: 




diff  --git a/libcxx/src/chrono.cpp b/libcxx/src/chrono.cpp
index 1419cf2f74a8..5291d4fa8dc6 100644
--- a/libcxx/src/chrono.cpp
+++ b/libcxx/src/chrono.cpp
@@ -153,7 +153,10 @@ static steady_clock::time_point 
__libcpp_steady_clock_now() {
 
   LARGE_INTEGER counter;
   (void) QueryPerformanceCounter(&counter);
-  return steady_clock::time_point(steady_clock::duration(counter.QuadPart * 
nano::den / freq.QuadPart));
+  auto seconds = counter.QuadPart / freq.QuadPart;
+  auto fractions = counter.QuadPart % freq.QuadPart;
+  auto dur = seconds * nano::den + fractions * nano::den / freq.QuadPart;
+  return steady_clock::time_point(steady_clock::duration(dur));
 }
 
 #elif defined(CLOCK_MONOTONIC)

diff  --git 
a/libcxx/test/std/utilities/time/time.clock/time.clock.steady/now.pass.cpp 
b/libcxx/test/std/utilities/time/time.clock/time.clock.steady/now.pass.cpp
index 4b8104dd1a6f..14dc9a9832dc 100644
--- a/libcxx/test/std/utilities/time/time.clock/time.clock.steady/now.pass.cpp
+++ b/libcxx/test/std/utilities/time/time.clock/time.clock.steady/now.pass.cpp
@@ -25,6 +25,8 @@ int main(int, char**)
 C::time_point t1 = C::now();
 C::time_point t2 = C::now();
 assert(t2 >= t1);
+// make sure t2 didn't wrap around
+assert(t2 > std::chrono::time_point());
 
   return 0;
 }



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits