On Fri, Jun 3, 2011 at 9:55 AM, Chris Lattner <[email protected]> wrote:
> Hi Chandler, > > Does this trap on: > > int x = 1; > x = x << 31; > Yep. > While this is technically a signed overflow, I believe that we define it as > valid. > Certain Clang and GCC both define this as valid, but I'm a bit leery of not trapping on it with -fcatch-undefined-behavior. The standard says its flat out undefined, not just unspecified. It doesn't even distinguish between the case of 1 << 31 and 2 << 31. It seems strange for Clang to do so. Anyways, I see this as an open question. I'll let the debate carry on. I'm happy to adjust the patch in either direction. Currently, I'm leaning toward a conservative interpretation of the standard by -fcatch-undefined-behavior as it seems a flag intended to help improve portability / conformance. >From another perspective, do you want LLVM and Clang's source code to rely on 1 << 31 not being UB? Currently there are many places in the code that do this. I was preparing patches for them, but I'll hold off until the discussion is resolved. Finally, are there any optimizations that marking the shift left that results from this as "nsw" enables which would not be enabled by marking it as "nuw"? (Am I even correct in my thinking that making 1 << 31 be well defined would move the possible "nsw" flag to an "nuw" to model the allowed semantics correctly?)
_______________________________________________ cfe-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
