[PATCH] D51869: NFC: bit.h don't warn on strict aliasing for GCC <= 7.1

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


jfb created this revision.
Herald added subscribers: llvm-commits, dexonsmith.

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


Repository:
  rL LLVM

https://reviews.llvm.org/D51869

Files:
  include/llvm/ADT/bit.h


Index: include/llvm/ADT/bit.h
===================================================================
--- include/llvm/ADT/bit.h
+++ include/llvm/ADT/bit.h
@@ -26,7 +26,15 @@
 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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D51869.164700.patch
Type: text/x-patch
Size: 625 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180910/0795722d/attachment.bin>


More information about the llvm-commits mailing list