<div dir="ltr">Hi Mehdi,<div><br></div><div>I couldn't find a paragraph explicitly specifying how objects are located from the text.</div><div><div>It seems it is deliberately underspecified to allow compilations to exotic target machines.</div><div></div></div><div>However, I could find a few paragraphs that look interesting:<br></div><div><br></div><div>6.2.4p2: An object exists, has a constant address,<font size="1">33)</font> and retains its last-stored value throughout its lifetime.<br></div><div><font size="1">33)</font> The term “constant address” means that two pointers to the object constructed at possibly different times will compare equal. The address may be different during two different executions of the same program. </div><div><br></div><div>6.3.2.3.p5 <font size="1">68)</font><br>The mapping functions for converting a pointer to an integer or an integer to a pointer are intended to be consistent with the addressing structure of the execution environment.<br></div><div><br></div><div>7.22.3p1<br></div><div>... Each such allocation shall yield a pointer to an object disjoint from any other object. The pointer returned points to the start (lowest byte address) of the allocated space. ...<br></div><div><br></div><div><a href="https://web.archive.org/web/20181230041359if_/http://www.open-std.org/jtc1/sc22/wg14/www/abq/c17_updated_proposed_fdis.pdf" target="_blank">https://web.archive.org/web/20181230041359if_/http://www.open-std.org/jtc1/sc22/wg14/www/abq/c17_updated_proposed_fdis.pdf</a><br></div><div><br></div><div><br></div><div>Going back to the bug report, I don't think these paragraphs affect the validity of the example. </div><div><br></div><div>Thanks,</div><div>Juneyoung</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Jun 7, 2021 at 2:38 PM Mehdi AMINI <<a href="mailto:joker.eph@gmail.com" target="_blank">joker.eph@gmail.com</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"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, Jun 6, 2021 at 9:25 PM Juneyoung Lee 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"><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></blockquote><div><br></div><div>This is interesting, I'm curious (we're a bit off-topic though) how is the part about "that happens to immediately follow the first array object in the address space" defined?</div><div></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><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>
_______________________________________________<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></div></div></div>
</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>