On 18 August 2012 20:01, David Nadlinger <[email protected]> wrote: > On Sat, Aug 18, 2012 at 8:38 PM, kenji hara <[email protected]> wrote: >> My answer is: optimizer doesn't affect the result of semantic analysis. >> In other words, flow analysis by the optimizer also doesn't affect to >> the compilation. > > I think you ares completely missing the point missing the point. Flow > analysis performed by the optimizer _does_ affect compilation, because > it leads to code being treated as illegal which would be perfectly > fine otherwise. How much bigger of an effect on language semantics can > there be? > >> The "used before set" error disappears if you don't specify -O. >> Therefore it is backend optimizer's work, and is not a part of the >> spec. > > Which is a big problem. Whether a program compiles or not should be > clear from the spec, and not be dependent on the compiler writer's > mood. If the optimizer detects undefined behavior, it can enable all > sorts of crazy optimizations – for example, LLVM routinely optimizes > down big chunks of code with just a trap if it detects undefined > values –, but it can't change language semantics: if the spec says > that something is undefined behavior, executing the code results in, > well, undefined behavior, but the code is still perfectly legal, the > compiler should _not_ be allowed to generate an error. > > To illustrate my point, consider the following example. It contains > code which exhibits undefined behavior, but since this code is never > invoked, there should be no problem: > > --- > void foo() { > int a = void; > import std.stdio; > writeln(a); > } > void main() {} > ---- > > David
You can only be certain that a function is never invoked unless it is marked 'static' IMO. My opinion is that it should warn you anyway, as it is potentially buggy code, even if unused. -- Iain Buclaw *(p < e ? p++ : p) = (c & 0x0f) + '0'; _______________________________________________ dmd-internals mailing list [email protected] http://lists.puremagic.com/mailman/listinfo/dmd-internals
