<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">LGTM</div><div class="gmail_quote"><br></div><div class="gmail_quote">On Tue, Jun 30, 2015 at 4:58 PM, Justin Bogner <span dir="ltr"><<a href="mailto:mail@justinbogner.com" target="_blank">mail@justinbogner.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">ping<br>
<div><div class="h5"><br>
Justin Bogner <<a href="mailto:mail@justinbogner.com">mail@justinbogner.com</a>> writes:<br>
> The LifetimeExtendedCleanupHeader is carefully fit into 32 bytes,<br>
> meaning that cleanups on the LifetimeExtendedCleanupStack are *always*<br>
> allocated at a misaligned address and cause undefined behaviour.<br>
><br>
> There are two ways to solve this - add padding after the header when<br>
> we allocated our cleanups, or just simplify the header and let it use<br>
> 64 bits in the first place. I've opted for the latter, and added a<br>
> static assert to avoid the issue in the future.<br>
><br>
> This does waste some space in the 32-bit case. It wouldn't be too hard<br>
> to make the size of this struct dependent on the host machine if<br>
> that's an issue. WDYT?<br>>
</div></div>> commit 1f1d41a60f5106e9e89fbc917bfc0826b5caad02<br>
> Author: Justin Bogner <<a href="mailto:mail@justinbogner.com">mail@justinbogner.com</a>><br>
> Date:   Mon Jun 22 16:02:17 2015 -0700<br>
><br>
>     CodeGen: Resize LifetimeExtendedCleanupHeader to avoid alignment issues<br>
<span class="">><br>
>     The LifetimeExtendedCleanupHeader is carefully fit into 32 bytes,<br>
>     meaning that cleanups on the LifetimeExtendedCleanupStack are *always*<br>
>     allocated at a misaligned address and cause undefined behaviour.<br>
><br>
>     There are two ways to solve this - add padding after the header when<br>
>     we allocated our cleanups, or just simplify the header and let it use<br>
>     64 bits in the first place. I've opted for the latter, and added a<br>
>     static assert to avoid the issue in the future.<br>
><br>
</span>> diff --git a/lib/CodeGen/CodeGenFunction.h b/lib/CodeGen/CodeGenFunction.h<br>
> index 45475d1..0891b5d 100644<br>
> --- a/lib/CodeGen/CodeGenFunction.h<br>
> +++ b/lib/CodeGen/CodeGenFunction.h<br>
> @@ -283,12 +283,12 @@ public:<br>
>    /// Header for data within LifetimeExtendedCleanupStack.<br>
>    struct LifetimeExtendedCleanupHeader {<br>
>      /// The size of the following cleanup object.<br>
> -    unsigned Size : 29;<br>
> +    unsigned Size;<br>
>      /// The kind of cleanup to push: a value from the CleanupKind enumeration.<br>
> -    unsigned Kind : 3;<br>
> +    CleanupKind Kind;<br>
><br>
> -    size_t getSize() const { return size_t(Size); }<br>
> -    CleanupKind getKind() const { return static_cast<CleanupKind>(Kind); }<br>
> +    size_t getSize() const { return Size; }<br>
> +    CleanupKind getKind() const { return Kind; }<br>
>    };<br>
><br>
>    /// i32s containing the indexes of the cleanup destinations.<br>
> @@ -388,6 +388,8 @@ public:<br>
>      LifetimeExtendedCleanupStack.resize(<br>
>          LifetimeExtendedCleanupStack.size() + sizeof(Header) + Header.Size);<br>
><br>
> +    static_assert(sizeof(Header) % llvm::AlignOf<T>::Alignment == 0,<br>
> +                  "Cleanup will be allocated on misaligned address");<br>
>      char *Buffer = &LifetimeExtendedCleanupStack[OldSize];<br>
>      new (Buffer) LifetimeExtendedCleanupHeader(Header);<br>
>      new (Buffer + sizeof(Header)) T(A...);<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
</blockquote></div><br></div></div>