<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On Sep 6, 2009, at 2:01 PM, Török Edwin wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div>On 2009-09-06 20:52, Bill Wendling wrote:<br><blockquote type="cite">The problem he's facing here isn't necessarily one of correctness. <br></blockquote><blockquote type="cite">He's dealing with undefined behavior (at least in C code). There are <br></blockquote><blockquote type="cite">no guarantees that the compiler will retain a certain semantic <br></blockquote><blockquote type="cite">interpretation of an undefined construct between different versions of <br></blockquote><blockquote type="cite">the compiler, let alone different optimization levels.<br></blockquote><blockquote type="cite"><br></blockquote><br>Should LLVM IR inherit all that is undefined behavior in C?<br></div></blockquote><div><br></div><div>Yes, where it is useful for optimization purposes.</div><br><blockquote type="cite"><div>That makes it harder to support other languages, or new languages that<br>want different semantics<br>for things that the C standard defines as undefined.<br></div></blockquote><div><br></div><div>This is another question though. I think that LLVM should support taking advantage of undefined behavior in C, but it should also allow other languages to model what they need.</div><div><br></div><div>As a concrete example, there is no reason not to add a "bit" to LoadInst saying whether an "invalid" load is undefined or whether it causes an "exception". The fun part is nailing down which cases of "invalid" are allowed, but it isn't that big of a deal.</div><br><blockquote type="cite"><div><blockquote type="cite"><font class="Apple-style-span" color="#144FAE"><br></font></blockquote><blockquote type="cite">This is something that LLVM isn't currently good at, but that we're <br></blockquote><blockquote type="cite">actively interested in improving. Here is some related stuff:<br></blockquote><blockquote type="cite"><a href="http://nondot.org/sabre/LLVMNotes/ExceptionHandlingChanges.txt">http://nondot.org/sabre/LLVMNotes/ExceptionHandlingChanges.txt</a><br></blockquote><blockquote type="cite"><br></blockquote><br>Looks interesting, but it also looks like a lot of work to implement.<br></div></blockquote><div><br></div><div>Well that is why it hasn't been done yet :)</div><br><blockquote type="cite"><div>Could instructions have a flag that says whether their semantics is<br>C-like (i.e. undefined behavior when you load from null etc.), or<br>something else? (throw exception, etc.).<br></div></blockquote><div><br></div>Yes. You need to tell the optimizer what the possible control flow is though, or else it will move operations in invalid ways.</div><div><br><blockquote type="cite"><div>What do you think?<br></div></blockquote><div><br></div>Right!</div><div><br></div><div>-Chris</div></body></html>