[flang-commits] [flang] e69cab7 - [Flang] Make SLES 15 build tests (#87498)
via flang-commits
flang-commits at lists.llvm.org
Thu Apr 4 00:37:49 PDT 2024
Author: Jan Patrick Lehr
Date: 2024-04-04T09:37:45+02:00
New Revision: e69cab7f37cf6f35306356cddb26049fd6138df7
URL: https://github.com/llvm/llvm-project/commit/e69cab7f37cf6f35306356cddb26049fd6138df7
DIFF: https://github.com/llvm/llvm-project/commit/e69cab7f37cf6f35306356cddb26049fd6138df7.diff
LOG: [Flang] Make SLES 15 build tests (#87498)
SLES 15 comes with a GCC 7.5 as default, which does not support the
C++17 `<charconv>` header. This results in build errors when trying to
run `check-flang`.
This patch addresses that and uses the older `std::stol` for the string
-> number conversion to allow the SLES 15 buildbot
(https://lab.llvm.org/staging/#/builders/193) to turn green.
Added:
Modified:
flang/unittests/Runtime/Time.cpp
Removed:
################################################################################
diff --git a/flang/unittests/Runtime/Time.cpp b/flang/unittests/Runtime/Time.cpp
index ec0caa743bcdf9..5c93282bca6115 100644
--- a/flang/unittests/Runtime/Time.cpp
+++ b/flang/unittests/Runtime/Time.cpp
@@ -12,7 +12,7 @@
#include "flang/Runtime/time-intrinsic.h"
#include <algorithm>
#include <cctype>
-#include <charconv>
+#include <cerrno>
#include <string>
using namespace Fortran::runtime;
@@ -104,10 +104,9 @@ TEST(TimeIntrinsics, DateAndTime) {
EXPECT_TRUE(true);
} else {
count_t number{-1};
- auto [_, ec]{
- std::from_chars(date.data(), date.data() + date.size(), number)};
- ASSERT_TRUE(ec != std::errc::invalid_argument &&
- ec != std::errc::result_out_of_range);
+ // Use stol to allow GCC 7.5 to build tests
+ number = std::stol(date);
+ ASSERT_TRUE(errno != ERANGE);
EXPECT_GE(number, 0);
auto year = number / 10000;
auto month = (number - year * 10000) / 100;
@@ -121,14 +120,15 @@ TEST(TimeIntrinsics, DateAndTime) {
}
// Validate time is hhmmss.sss or blank.
+ std::string acceptedPattern("hhmmss.sss");
if (isBlank(time)) {
EXPECT_TRUE(true);
} else {
count_t number{-1};
- auto [next, ec]{
- std::from_chars(time.data(), time.data() + date.size(), number)};
- ASSERT_TRUE(ec != std::errc::invalid_argument &&
- ec != std::errc::result_out_of_range);
+ // Use stol to allow GCC 7.5 to build tests
+ auto dotPosition = acceptedPattern.find('.');
+ number = std::stol(time.substr(0, dotPosition));
+ ASSERT_TRUE(errno != ERANGE);
ASSERT_GE(number, 0);
auto hours = number / 10000;
auto minutes = (number - hours * 10000) / 100;
@@ -137,15 +137,11 @@ TEST(TimeIntrinsics, DateAndTime) {
EXPECT_LE(minutes, 59);
// Accept 60 for leap seconds.
EXPECT_LE(seconds, 60);
- ASSERT_TRUE(next != time.data() + time.size());
- EXPECT_EQ(*next, '.');
+ EXPECT_EQ(time.substr(dotPosition, 1), ".");
count_t milliseconds{-1};
- ASSERT_TRUE(next + 1 != time.data() + time.size());
- auto [_, ec2]{
- std::from_chars(next + 1, time.data() + date.size(), milliseconds)};
- ASSERT_TRUE(ec2 != std::errc::invalid_argument &&
- ec2 != std::errc::result_out_of_range);
+ milliseconds = std::stol(time.substr(dotPosition + 1, 3));
+ ASSERT_TRUE(errno != ERANGE);
EXPECT_GE(milliseconds, 0);
EXPECT_LE(milliseconds, 999);
}
@@ -157,10 +153,9 @@ TEST(TimeIntrinsics, DateAndTime) {
ASSERT_TRUE(zone.size() > 1);
EXPECT_TRUE(zone[0] == '+' || zone[0] == '-');
count_t number{-1};
- auto [next, ec]{
- std::from_chars(zone.data() + 1, zone.data() + zone.size(), number)};
- ASSERT_TRUE(ec != std::errc::invalid_argument &&
- ec != std::errc::result_out_of_range);
+ // Use stol to allow GCC 7.5 to build tests
+ number = std::stol(zone.substr(1, 4));
+ ASSERT_TRUE(errno != ERANGE);
ASSERT_GE(number, 0);
auto hours = number / 100;
auto minutes = number % 100;
More information about the flang-commits
mailing list