[llvm] r341853 - NFC: bit.h don't warn on strict aliasing for GCC <= 7.1

JF Bastien via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 10 12:56:42 PDT 2018


Author: jfb
Date: Mon Sep 10 12:56:42 2018
New Revision: 341853

URL: http://llvm.org/viewvc/llvm-project?rev=341853&view=rev
Log:
NFC: bit.h don't warn on strict aliasing for GCC <= 7.1

Summary: Addressed https://bugs.llvm.org/show_bug.cgi?id=38885

Subscribers: dexonsmith, llvm-commits, rsmith, steven_wu, RKSimon, Abhilash, srhines

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

Modified:
    llvm/trunk/include/llvm/ADT/bit.h

Modified: llvm/trunk/include/llvm/ADT/bit.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/bit.h?rev=341853&r1=341852&r2=341853&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/bit.h (original)
+++ llvm/trunk/include/llvm/ADT/bit.h Mon Sep 10 12:56:42 2018
@@ -26,7 +26,15 @@ template <typename To, typename From,
 inline To bit_cast(const From &from) noexcept {
   alignas(To) unsigned char storage[sizeof(To)];
   std::memcpy(&storage, &from, sizeof(To));
+#if defined(__GNUC__)
+  // Before GCC 7.2, GCC thought that this violated strict aliasing.
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wstrict-aliasing"
+#endif
   return reinterpret_cast<To &>(storage);
+#if defined(__GNUC__)
+#pragma GCC diagnostic pop
+#endif
 }
 
 } // namespace llvm




More information about the llvm-commits mailing list