News for hackers. Stuff that matters.

abra529

I see, thanks for the explanation. Just read your previous blog post that goes into more detail about this. [1] I don't know much about compilers, but I guess Defect Report #260 supports the interpretation that dereferencing q isn't the same as dereferencing (p+1), even inside an if block where p+1 == q: "[Implementations] may also treat pointers based on different origins as distinct even though they are bitwise identical." [2]

[1] https://www.ralfj.de/blog/2018/07/24/pointers-and-bytes.html

[2] http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_260.htm

Is it not guaranteed? Looking at this question [1] on StackOverflow and the quotes from the standard included in the question, it seems that the value should be preserved.

(It raises the issue of whether (char※)iq should technically be (char※)(void※)iq if this were C code, but the (void※) cast can be inserted without changing anything about the problems discussed in the article.)

[1] https://stackoverflow.com/q/34291377

Commenters here as well as the author seem content with asserting that under C semantics, the code after the second optimization exhibits UB when it dereferences (p+1). Is it really UB?

Here's the snippet for reference:

    char p[1], q[1] = {0};
    uintptr_t ip = (uintptr_t)(p+1);
    uintptr_t iq = (uintptr_t)q;
    if (iq == ip) {
      *(p+1) = 10; // <- This line changed
      print(q[0]);
    }
From the article: "LLVM IR (just like C) does not permit memory accesses through one-past-the-end pointers." I think this is a mental shortcut we make that can lead us astray here. Of course, one-past-the-end pointers can't usually be dereferenced legally. But I think it's legal here because when (iq == ip), (p+1) points to a valid location. I don't see (at least in the C99 standard) why this code would be illegal.

I realize that the code is not meant to represent C but rather LLVM IR, but surely, if this snippet is legal C code, then LLVM can't treat it as if it were UB? So that would mean the third optimization is incorrect here.

Re:Traffic Prediction with Advanced Graph Neural Networks on Saturday September 05, 2020 @06:09PM (#24387240)
Surprisingly, it isn't always the case that each driver optimizing their own route will lead to a global optimum - see Braess's paradox. "If every driver takes the path that looks most favourable to them, the resultant running times need not be minimal." [0]

[0] https://en.wikipedia.org/wiki/Braess's_paradox

Re:GCC x86 Performance Hints (2012) on Friday August 21, 2020 @12:46PM (#24236518)
> 15,0000 lines

Did you mean 150,000 or 15,000?

Re:Intuitive Guide to Maxwell's Equations on Wednesday July 01, 2020 @03:24PM (#23705394)
Wikipedia is a tertiary source. Pedagogical resources are also usually tertiary sources.[0]

[0] https://en.wikipedia.org/wiki/Wikipedia:TERTIARY