News for hackers. Stuff that matters.
Re:Pointers Are Complicated III, or: Pointer-integer casts e... by camgunz on Friday April 15, 2022 @11:17PM (#31049084)
Sure, but that requires compilation unit level analysis or inlining (when inlined you can include pointer provenance from main), otherwise you can't guarantee the relationship between x and y.

I guess what bugs me about optimizations is that it feels like something _I_ should be doing. Like if GCC told me this code optimizes down to printf 1 and why, I'd question what I was doing (and rightly so). Doing it automatically feels like too much spooky action at a distance.

Re:Pointers Are Complicated III, or: Pointer-integer casts e... by djur on Saturday April 16, 2022 @01:20AM (#31049722)
In the case of the code we're talking about here, gcc/clang do rely on inlining to optimize down to the single printf. I don't think there's any actual compiler that does the dangerous and invalid optimization in the article.
Re:Pointers Are Complicated III, or: Pointer-integer casts e... by camgunz on Saturday April 16, 2022 @11:21AM (#31053007)
OH! I've clearly misunderstood then. Rereading, it does look like this is just a hypothetical to illustrate the tension between allowing pointer-int-pointer round-trips and foiling analysis based on pointer provenance. OK I'm caught up, thank you haha.