{"action":"created","issue":{"url":"https://api.github.com/repos/ocaml/ocaml/issues/255","labels_url":"https://api.github.com/repos/ocaml/ocaml/issues/255/labels{/name}","comments_url":"https://api.github.com/repos/ocaml/ocaml/issues/255/comments","events_url":"https://api.github.com/repos/ocaml/ocaml/issues/255/events","html_url":"https://github.com/ocaml/ocaml/pull/255","id":110280031,"number":255,"title":"fix undefined left shift of negative value.","user":{"login":"bryant","id":670831,"avatar_url":"https://avatars.githubusercontent.com/u/670831?v=3","gravatar_id":"","url":"https://api.github.com/users/bryant","html_url":"https://github.com/bryant","followers_url":"https://api.github.com/users/bryant/followers","following_url":"https://api.github.com/users/bryant/following{/other_user}","gists_url":"https://api.github.com/users/bryant/gists{/gist_id}","starred_url":"https://api.github.com/users/bryant/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bryant/subscriptions","organizations_url":"https://api.github.com/users/bryant/orgs","repos_url":"https://api.github.com/users/bryant/repos","events_url":"https://api.github.com/users/bryant/events{/privacy}","received_events_url":"https://api.github.com/users/bryant/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2015-10-07T17:46:24Z","updated_at":"2015-10-08T18:45:40Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/ocaml/ocaml/pulls/255","html_url":"https://github.com/ocaml/ocaml/pull/255","diff_url":"https://github.com/ocaml/ocaml/pull/255.diff","patch_url":"https://github.com/ocaml/ocaml/pull/255.patch"},"body":"Left-shifting signed negative values is undefined behavior. From 6.5.7 of http://open-std.org/JTC1/SC22/WG14/www/docs/n1256.pdf:\r\n\r\n```\r\nIf E1 has a signed type and nonnegative value,\r\nand E1 × 2 E2 is representable in the result type,\r\nthen that is the resulting value; otherwise, the\r\nbehavior is undefined.\r\n```\r\n\r\nThis patch also has the pleasant side effect of permitting build with clang."},"comment":{"url":"https://api.github.com/repos/ocaml/ocaml/issues/comments/146650799","html_url":"https://github.com/ocaml/ocaml/pull/255#issuecomment-146650799","issue_url":"https://api.github.com/repos/ocaml/ocaml/issues/255","id":146650799,"user":{"login":"chrismamo1","id":3238755,"avatar_url":"https://avatars.githubusercontent.com/u/3238755?v=3","gravatar_id":"","url":"https://api.github.com/users/chrismamo1","html_url":"https://github.com/chrismamo1","followers_url":"https://api.github.com/users/chrismamo1/followers","following_url":"https://api.github.com/users/chrismamo1/following{/other_user}","gists_url":"https://api.github.com/users/chrismamo1/gists{/gist_id}","starred_url":"https://api.github.com/users/chrismamo1/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chrismamo1/subscriptions","organizations_url":"https://api.github.com/users/chrismamo1/orgs","repos_url":"https://api.github.com/users/chrismamo1/repos","events_url":"https://api.github.com/users/chrismamo1/events{/privacy}","received_events_url":"https://api.github.com/users/chrismamo1/received_events","type":"User","site_admin":false},"created_at":"2015-10-08T18:45:40Z","updated_at":"2015-10-08T18:45:40Z","body":"While shifting by a negative value is technically undefined, most CPU's don't even consider the sign when shifting. For instance, when performing a shift operation on a 32-bit integer, Intel chips only consider the five least significant bits in the second operand. For example, on a 32-bit Intel machine\r\n\r\n    x << (-1)\r\n\r\nis equivalent to\r\n\r\n    x << 31\r\n\r\nbecause their binary representations are identical in the five least-significant bits.\r\n\r\nI doubt that very much OCaml code exploits this (I would hope none) but this update could quietly break any code that does."}}