[flang] Address most review comments
authorpeter klausler <pklausler@nvidia.com>
Thu, 22 Aug 2019 19:08:39 +0000 (12:08 -0700)
committerpeter klausler <pklausler@nvidia.com>
Fri, 23 Aug 2019 18:31:46 +0000 (11:31 -0700)
Original-commit: flang-compiler/f18@e6164782eac607d376eac59baa9107c971c92c19
Reviewed-on: https://github.com/flang-compiler/f18/pull/671
Tree-same-pre-rewrite: false

flang/lib/decimal/binary-floating-point.h
flang/lib/decimal/decimal.h
flang/lib/evaluate/real.cc

index d03de13..7fd86f6 100644 (file)
@@ -67,6 +67,7 @@ template<int PRECISION> struct BinaryFloatingPointNumber {
       BinaryFloatingPointNumber &&that) = default;
 
   template<typename A> explicit constexpr BinaryFloatingPointNumber(A x) {
+    static_assert(sizeof raw == sizeof x);
     std::memcpy(reinterpret_cast<void *>(&raw),
         reinterpret_cast<const void *>(&x), sizeof raw);
   }
index a63a230..12fceeb 100644 (file)
@@ -1,25 +1,26 @@
-// Copyright (c) 2018-2019, NVIDIA CORPORATION.  All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//     http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-// C and C++ API for binary-to/from-decimal conversion package.
+/* Copyright (c) 2018-2019, NVIDIA CORPORATION.  All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* C and C++ API for binary-to/from-decimal conversion package. */
 
 #ifndef FORTRAN_DECIMAL_DECIMAL_H_
 #define FORTRAN_DECIMAL_DECIMAL_H_
 
-#include "binary-floating-point.h"
 #include <stddef.h>
 
+#ifdef __cplusplus
 // Binary-to-decimal conversions (formatting) produce a sequence of decimal
 // digit characters in a NUL-terminated user-supplied buffer that constitute
 // a decimal fraction (or zero), accompanied by a decimal exponent that
@@ -30,9 +31,9 @@
 // If the conversion can't fit in the user-supplied buffer, a null pointer
 // is returned.
 
-#ifdef __cplusplus
+#include "binary-floating-point.h"
 namespace Fortran::decimal {
-#endif
+#endif /* C++ */
 
 enum ConversionResultFlags {
   Exact = 0,
@@ -116,29 +117,28 @@ extern template ConversionToBinaryResult<112> ConvertToBinary<112>(
 }  // namespace Fortran::decimal
 extern "C" {
 #define NS(x) Fortran::decimal::x
-#else
+#else /* C++ */
 #define NS(x) x
 #endif /* C++ */
 
-NS(ConversionToDecimalResult)
-ConvertFloatToDecimal(char *, size_t, enum NS(DecimalConversionFlags),
-    int digits, enum NS(FortranRounding), float);
-NS(ConversionToDecimalResult)
-ConvertDoubleToDecimal(char *, size_t, enum NS(DecimalConversionFlags),
-    int digits, enum NS(FortranRounding), double);
+struct NS(ConversionToDecimalResult)
+    ConvertFloatToDecimal(char *, size_t, enum NS(DecimalConversionFlags),
+        int digits, enum NS(FortranRounding), float);
+struct NS(ConversionToDecimalResult)
+    ConvertDoubleToDecimal(char *, size_t, enum NS(DecimalConversionFlags),
+        int digits, enum NS(FortranRounding), double);
 #if __x86_64__
-NS(ConversionToDecimalResult)
-ConvertLongDoubleToDecimal(char *, size_t, enum NS(DecimalConversionFlags),
-    int digits, enum NS(FortranRounding), long double);
+struct NS(ConversionToDecimalResult)
+    ConvertLongDoubleToDecimal(char *, size_t, enum NS(DecimalConversionFlags),
+        int digits, enum NS(FortranRounding), long double);
 #endif
 
-NS(ConversionResultFlags)
-ConvertDecimalToFloat(const char **, float *, enum NS(FortranRounding));
-NS(ConversionResultFlags)
-ConvertDecimalToDouble(const char **, double *, enum NS(FortranRounding));
+enum NS(ConversionResultFlags)
+    ConvertDecimalToFloat(const char **, float *, enum NS(FortranRounding));
+enum NS(ConversionResultFlags)
+    ConvertDecimalToDouble(const char **, double *, enum NS(FortranRounding));
 #if __x86_64__
-NS(ConversionResultFlags)
-ConvertDecimalToLongDouble(
+enum NS(ConversionResultFlags) ConvertDecimalToLongDouble(
     const char **, long double *, enum NS(FortranRounding));
 #endif
 #undef NS
index 6fd17f4..fafe94d 100644 (file)
@@ -477,8 +477,8 @@ std::ostream &Real<W, P, IM>::AsFortran(std::ostream &o, int kind) const {
     const auto *value{reinterpret_cast<const B *>(this)};
     char buffer[24000];  // accommodate real*16
     auto result{decimal::ConvertToDecimal<P>(buffer, sizeof buffer,
-        static_cast<decimal::DecimalConversionFlags>(0), 999999,
-        decimal::RoundNearest, *value)};
+        static_cast<decimal::DecimalConversionFlags>(0),
+        static_cast<int>(sizeof buffer), decimal::RoundNearest, *value)};
     const char *p{result.str};
     if (DEREF(p) == '-' || *p == '+') {
       o << *p++;