[flang-commits] [flang] 3604119 - [flang][MSVC] Fix building with `/permissive-` flag
Michael Kruse via flang-commits
flang-commits at lists.llvm.org
Tue May 24 21:36:16 PDT 2022
Author: Mehdi Chinoune
Date: 2022-05-24T23:36:04-05:00
New Revision: 360411957b6f40f50b35097b7abedd91250f2434
URL: https://github.com/llvm/llvm-project/commit/360411957b6f40f50b35097b7abedd91250f2434
DIFF: https://github.com/llvm/llvm-project/commit/360411957b6f40f50b35097b7abedd91250f2434.diff
LOG: [flang][MSVC] Fix building with `/permissive-` flag
CLOCK_REALTIME is POSIX defined and never available with MSVC, even without /permissive-.
The difference is that the template is never instantiated and the compiler ignores the undefined identifier.
Reviewed By: Meinersbur
Differential Revision: https://reviews.llvm.org/D125262
Added:
Modified:
flang/runtime/time-intrinsic.cpp
Removed:
################################################################################
diff --git a/flang/runtime/time-intrinsic.cpp b/flang/runtime/time-intrinsic.cpp
index 7ca3a22ee2cb6..5f7b50964fe2a 100644
--- a/flang/runtime/time-intrinsic.cpp
+++ b/flang/runtime/time-intrinsic.cpp
@@ -62,10 +62,13 @@ template <typename Unused = void> double GetCpuTime(fallback_implementation) {
#define CLOCKID CLOCK_THREAD_CPUTIME_ID
#elif defined CLOCK_MONOTONIC
#define CLOCKID CLOCK_MONOTONIC
-#else
+#elif defined CLOCK_REALTIME
#define CLOCKID CLOCK_REALTIME
+#else
+#undef CLOCKID
#endif
+#ifdef CLOCKID
// POSIX implementation using clock_gettime. This is only enabled where
// clock_gettime is available.
template <typename T = int, typename U = struct timespec>
@@ -80,6 +83,7 @@ double GetCpuTime(preferred_implementation,
// Return some negative value to represent failure.
return -1.0;
}
+#endif
using count_t = std::int64_t;
using unsigned_count_t = std::uint64_t;
@@ -136,6 +140,7 @@ constexpr unsigned_count_t DS_PER_SEC{10u};
constexpr unsigned_count_t MS_PER_SEC{1'000u};
constexpr unsigned_count_t NS_PER_SEC{1'000'000'000u};
+#ifdef CLOCKID
template <typename T = int, typename U = struct timespec>
count_t GetSystemClockCount(int kind, preferred_implementation,
// We need some dummy parameters to pass to decltype(clock_gettime).
@@ -156,6 +161,7 @@ count_t GetSystemClockCount(int kind, preferred_implementation,
return (sec * DS_PER_SEC + (nsec / (NS_PER_SEC / DS_PER_SEC))) % (huge + 1);
}
}
+#endif
template <typename T = int, typename U = struct timespec>
count_t GetSystemClockCountRate(int kind, preferred_implementation,
More information about the flang-commits
mailing list