Path: csiph.com!weretis.net!feeder6.news.weretis.net!news.misty.com!news.iecc.com!.POSTED.news.iecc.com!nerds-end From: Kaz Kylheku <864-117-4973@kylheku.com> Newsgroups: comp.compilers Subject: Re: Undefined Behavior Optimizations in C Date: Sun, 15 Jan 2023 04:17:31 -0000 (UTC) Organization: A noiseless patient Spider Sender: news@iecc.com Approved: comp.compilers@iecc.com Message-ID: <23-01-058@comp.compilers> References: <23-01-027@comp.compilers> <23-01-031@comp.compilers> <23-01-036@comp.compilers> <23-01-045@comp.compilers> Injection-Info: gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970"; logging-data="38641"; mail-complaints-to="abuse@iecc.com" Keywords: C, optimize, comment Posted-Date: 15 Jan 2023 13:09:50 EST X-submission-address: compilers@iecc.com X-moderator-address: compilers-request@iecc.com X-FAQ-and-archives: http://compilers.iecc.com Xref: csiph.com comp.compilers:3326 On 2023-01-12, the moderator wrote: > [I don't see the problem, since there's invariably an "as if" rule > that lets you do whatever you want so long as the results are the same > as if you'd done everything in sequence. If a linktime optimizer looks > at the code, promotes a couple of very busy variables that never have > their addresses taken into global registers, so what? Or if it can > globally tell that two variables are never aliased so it can reuse a > register copy of one after modifying the other, again so what? -John] We can look at this as if the translation units have been rolled back in time to translation phase 7, where semantic analysis is now taking place again in an aternative future. This time, there is a magic oracle present that provides information about all the translation units which will be linked to produce the program. I'm skeptical whether the GCC and Clang LTO systems always behave like a magic oracle that supplies iron-clad truths to translation phase 7. And even if so, it seems wrong for the translation phase semantic analysis to be looking at information from any other part of a program than the translation unit at hand. The standard clearly says what is subject to semantic analysis, and it's only the material from the translation unit: 7. White-space characters separating tokens are no longer significant. Each preprocessing token is converted into a token. The resulting tokens are syntactically and semantically analyzed and translated as a translation unit. "The resulting tokens" are those from this translation unit, and nowhere else. Nothing other than those tokens is to be semantically analyzed. -- TXR Programming Language: http://nongnu.org/txr Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal Mastodon: @Kazinator@mstdn.ca [Hey, wait, it's one thing to say LTO might be buggy, another to say it's fundamentally imposible. Any optimizer might be buggy. -John]