[cfe-commits] PATCH: Enhance -fcatch-undefined-behavior for the '<<' operator.

Chandler Carruth chandlerc at google.com
Fri Jun 3 01:32:17 PDT 2011


FYI, this found 3 separate cases of this in TableGen alone. My testing
indicates many many instances elsewhere in LLVM and Clang. =/

I started digging into this because I wanted to add 'nsw' to the shl
instruction when the standard guaranteed it... doing so made the world
break, and i wondered why. =] now I know....

On Fri, Jun 3, 2011 at 12:50 AM, Chandler Carruth <chandlerc at google.com>wrote:

> This patch should catch more integer shift left undefined behavior
> according to C and C++ standard semantics. Specifically it should catch the
> case where a signed integer type when shifted is no longer representable in
> the result type.
>
> There are some general cleanups that can be made to the existing undefined
> behavior check here given the this change, but I just wanted to add
> functionality here. Let me know if I should just commit freely when adding
> these types of checks (provided proper testing and certainty that the
> behavior is in fact undefined). Also any guidance on other languages or
> specs I should be checking prior to enabling such checks (Currently looking
> at C99, C++98, C++03, and C++0x) would be welcome.
>
> Finally, the testcase is a bit lame. I'd really like to test this by
> creating sources that exhibit the undefined behavior being checked, compile
> and run them verifying crash and non-crash inputs. Is that do-able in the
> current test harness? Seems unlikely, but if folks have ideas I'm all ears.
>
> Thanks!
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20110603/a2b63344/attachment.html>


More information about the cfe-commits mailing list