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

David Blaikie via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 17 16:58:06 PDT 2018


This looks like a true aliasing violation though, I think?

The aliasing rules allow you to take a standard-layout type T and
reinterpret_cast a T* to a char* to read/write the bytes - but it doesn't
allow for a char[] to be pointed at/referenced by a T*/T&.

- Dave

On Mon, Sep 10, 2018 at 12:58 PM JF Bastien via llvm-commits <
llvm-commits at lists.llvm.org> wrote:

> 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
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180917/6c729a85/attachment.html>


More information about the llvm-commits mailing list