<div dir="ltr">According to C17 it is legal:<div><br></div><div>6.5.9.p6<br><br>Two pointers compare equal if and only if both are null pointers, both are pointers to the same object (including a pointer to an object and a subobject at its beginning) or function, both are pointers to one past the last element of the same array object, or <u>one is a pointer to one past the end of one array object and the other is a pointer to the start of a different array object that happens to immediately follow the first array object in the address space</u>.</div><div><br></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Jun 7, 2021 at 6:25 AM Joerg Sonnenberger via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Sun, Jun 06, 2021 at 11:52:13AM -0700, Marshall Clow via llvm-dev wrote:<br>
> On Jun 6, 2021, at 12:54 AM, James Courtier-Dutton via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>> wrote:<br>
> > <br>
> > Hi,<br>
> > <br>
> > I would also oppose adding a byte type, but mainly because the bug<br>
> > report mentioned (<a href="https://bugs.llvm.org/show_bug.cgi?id=37469" rel="noreferrer" target="_blank">https://bugs.llvm.org/show_bug.cgi?id=37469</a>) is not<br>
> > a bug at all.<br>
> > The example in the bug report is just badly written C code.<br>
> > Specifically:<br>
> > <br>
> > int main() {<br>
> >  int A[4], B[4];<br>
> >  printf("%p %p\n", A, &B[4]);<br>
> >  if ((uintptr_t)A == (uintptr_t)&B[4]) {<br>
> >    store_10_to_p(A, &B[4]);<br>
> >    printf("%d\n", A[0]);<br>
> >  }<br>
> >  return 0;<br>
> > }<br>
> > <br>
> > "int B[4];" allows values between 0 and 3 only, and referring to 4 in<br>
> > &B[4] is undef, so in my view, it is correctly optimised out which is<br>
> > why it disappears in -O3.<br>
> <br>
> Taking the address of the “one-past-the end” element of an array is perfectly legal in both C and C++.<br>
> *Dereferencing* that pointer is UB.<br>
<br>
Not just dereferencing, but also comparing it to a random other point?<br>
<br>
Joerg<br>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr"><div dir="ltr"><div><br></div><font size="1">Juneyoung Lee</font><div><font size="1">Software Foundation Lab, Seoul National University</font></div></div></div>