[flang-commits] [flang] 82cf35b - [flang] Fix/work around warnings from GCC 11

Peter Klausler via flang-commits flang-commits at lists.llvm.org
Tue Feb 1 11:54:25 PST 2022


Author: Peter Klausler
Date: 2022-02-01T11:54:04-08:00
New Revision: 82cf35bc89fcbe666243cd6f9e29af0023016a2d

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

LOG: [flang] Fix/work around warnings from GCC 11

Apply part of a pending patch for GCC 11 warnings, and
rework a piece of code, to dodge warnings on flag from
GCC 11 build bots exposed by a recent patch.

Applying without review to get bots working again; changes
also tested against GCC 9.3.0.

Added: 
    

Modified: 
    flang/lib/Evaluate/host.h
    flang/tools/bbc/bbc.cpp

Removed: 
    


################################################################################
diff  --git a/flang/lib/Evaluate/host.h b/flang/lib/Evaluate/host.h
index 7f57a73282171..49accd83b6b47 100644
--- a/flang/lib/Evaluate/host.h
+++ b/flang/lib/Evaluate/host.h
@@ -80,22 +80,27 @@ inline constexpr Scalar<FTN_T> CastHostToFortran(const HostType<FTN_T> &x) {
   }
 }
 
-// Scalar conversion utilities from  F18 scalars to host scalars
+// Scalar conversion utilities from F18 scalars to host scalars.
 template <typename FTN_T>
 inline constexpr HostType<FTN_T> CastFortranToHost(const Scalar<FTN_T> &x) {
   static_assert(HostTypeExists<FTN_T>());
-  if constexpr (FTN_T::category == TypeCategory::Complex &&
-      sizeof(Scalar<FTN_T>) != sizeof(HostType<FTN_T>)) {
-    // X87 is usually padded to 12 or 16bytes. Need to cast piecewise for
-    // complex
-    return HostType<FTN_T>{CastFortranToHost<typename FTN_T::Part>(x.REAL()),
-        CastFortranToHost<typename FTN_T::Part>(x.AIMAG())};
+  if constexpr (FTN_T::category == TypeCategory::Complex) {
+    using FortranPartType = typename FTN_T::Part;
+    return HostType<FTN_T>{CastFortranToHost<FortranPartType>(x.REAL()),
+        CastFortranToHost<FortranPartType>(x.AIMAG())};
+  } else if constexpr (std::is_same_v<FTN_T, Type<TypeCategory::Real, 10>>) {
+    // x87 80-bit floating-point occupies 16 bytes as a C "long double";
+    // copy the data to avoid a legitimate (but benign due to little-endianness)
+    // warning from GCC >= 11.2.0.
+    HostType<FTN_T> y;
+    std::memcpy(&y, &x, sizeof x);
+    return y;
   } else {
+    static_assert(sizeof x == sizeof(HostType<FTN_T>));
     return *reinterpret_cast<const HostType<FTN_T> *>(&x);
   }
 }
 
-// Defining the actual mapping
 template <> struct HostTypeHelper<Type<TypeCategory::Integer, 1>> {
   using Type = std::int8_t;
 };

diff  --git a/flang/tools/bbc/bbc.cpp b/flang/tools/bbc/bbc.cpp
index 1bb20ecf2ea51..8ce24b5df3473 100644
--- a/flang/tools/bbc/bbc.cpp
+++ b/flang/tools/bbc/bbc.cpp
@@ -234,13 +234,13 @@ int main(int argc, char **argv) {
   programPrefix = argv[0] + ": "s;
 
   Fortran::parser::Options options;
-  options.predefinitions.emplace_back("__flang__", "1");
-  options.predefinitions.emplace_back("__flang_major__",
-                                      FLANG_VERSION_MAJOR_STRING);
-  options.predefinitions.emplace_back("__flang_minor__",
-                                      FLANG_VERSION_MINOR_STRING);
-  options.predefinitions.emplace_back("__flang_patchlevel__",
-                                      FLANG_VERSION_PATCHLEVEL_STRING);
+  options.predefinitions.emplace_back("__flang__"s, "1"s);
+  options.predefinitions.emplace_back("__flang_major__"s,
+                                      std::string{FLANG_VERSION_MAJOR_STRING});
+  options.predefinitions.emplace_back("__flang_minor__"s,
+                                      std::string{FLANG_VERSION_MINOR_STRING});
+  options.predefinitions.emplace_back(
+      "__flang_patchlevel__"s, std::string{FLANG_VERSION_PATCHLEVEL_STRING});
 
   Fortran::common::IntrinsicTypeDefaultKinds defaultKinds;
   Fortran::parser::AllSources allSources;


        


More information about the flang-commits mailing list