<div dir="ltr">I actually didn't know that attribute existed. It does look like the right thing to use here. However, unfortunately, it appears it doesn't work for enum class in clang [[1]]. It *does* seem to work in GCC.<div><br></div><div>Unfortunately, it seems that GCC has actually hardcoded the type name "std::byte" (in gcc/cp/decl.c). To be compatible with libstdc++, we'll either need to fix libstdc++ to use also may_alias, or also hardcode the name. The former seems like it ought to be an acceptable patch.</div><div><br><div><br></div><div>[[1]] E.g. Given:</div><div><div><font face="monospace, monospace">namespace std { enum class __attribute__((may_alias)) byte  : unsigned char {}; }</font></div><div><font face="monospace, monospace">int foo(std::byte* x) { return (int)*x; }<br></font></div></div><div><div><br></div><div>Running:</div><div></div></div><div><span style="font-family:monospace"><span style="color:rgb(0,0,0)">bin/clang -O2 -S -std=c++1z -emit-llvm -o - test.cc</span><br></span></div><div><span style="font-family:monospace"><span style="color:rgb(0,0,0)"><br></span></span></div><div>still has:</div><div><span style="font-family:monospace"><span style="color:rgb(0,0,0)">  %0 = load i8, i8* %x, align 1, !tbaa !2</span></span></div><div><span style="font-family:monospace"><font color="#000000">...</font></span></div><div><span style="font-family:monospace"><span style="color:rgb(0,0,0)">!2 = !{!3, !3, i64 0}
</span><br>!3 = !{!"_ZTSSt4byte", !4, i64 0}<br>
<br></span><span style="font-family:monospace">
<br></span></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jul 5, 2017 at 3:51 PM, David Majnemer via cfe-commits <span dir="ltr"><<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>FWIW, doesn't this just need a may_alias attribute on the definition?<div class="gmail_quote"><div><div class="h5"><div>On Wed, Jul 5, 2017 at 2:39 PM James Y Knight via Phabricator via cfe-commits <<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>> wrote:<br></div></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5">jyknight added a comment.<br>
<br>
Ping. I don't think this got resolved, and I really wouldn't like to see  released in this state...can you either revert this from the library, or implement the compiler support, before the 5.0 release branch?<br>
<br>
In <a href="https://reviews.llvm.org/D31022#716702" rel="noreferrer" target="_blank">https://reviews.llvm.org/<wbr>D31022#716702</a>, @jyknight wrote:<br>
<br>
> I believe this needs compiler support, too, in order to treat<br>
><br>
>   namespace std { enum class byte : unsigned char {}; }<br>
><br>
> as directly having tbaa type "omnipotent char" instead of a subtype.<br>
><br>
> That is, given:<br>
><br>
>   void foo(char* x, int *y) {<br>
>     x[1] = char(y[0] & 0xff);<br>
>     x[0] = char((y[0] & 0xff00) >> 8);<br>
>   }<br>
><br>
> the compiler assumes that x and y might alias each-other, and thus must have two loads of y[0]. If you replace "char" with "std::byte", the same should happen, but as of now does not.<br>
<br>
<br>
<br>
<br>
<br>
<a href="https://reviews.llvm.org/D31022" rel="noreferrer" target="_blank">https://reviews.llvm.org/<wbr>D31022</a><br>
<br>
<br>
<br></div></div><span class="">
______________________________<wbr>_________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/cfe-commits</a><br>
</span></blockquote></div></div>
<br>______________________________<wbr>_________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/cfe-commits</a><br>
<br></blockquote></div><br></div>