{"action":"created","issue":{"url":"https://api.github.com/repos/kripken/emscripten/issues/405","repository_url":"https://api.github.com/repos/kripken/emscripten","labels_url":"https://api.github.com/repos/kripken/emscripten/issues/405/labels{/name}","comments_url":"https://api.github.com/repos/kripken/emscripten/issues/405/comments","events_url":"https://api.github.com/repos/kripken/emscripten/issues/405/events","html_url":"https://github.com/kripken/emscripten/issues/405","id":4224978,"number":405,"title":"Fix llvm_uadd_with_overflow_i64 to detect overflows properly","user":{"login":"SiggyBar","id":770564,"avatar_url":"https://avatars.githubusercontent.com/u/770564?v=3","gravatar_id":"","url":"https://api.github.com/users/SiggyBar","html_url":"https://github.com/SiggyBar","followers_url":"https://api.github.com/users/SiggyBar/followers","following_url":"https://api.github.com/users/SiggyBar/following{/other_user}","gists_url":"https://api.github.com/users/SiggyBar/gists{/gist_id}","starred_url":"https://api.github.com/users/SiggyBar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SiggyBar/subscriptions","organizations_url":"https://api.github.com/users/SiggyBar/orgs","repos_url":"https://api.github.com/users/SiggyBar/repos","events_url":"https://api.github.com/users/SiggyBar/events{/privacy}","received_events_url":"https://api.github.com/users/SiggyBar/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2012-04-21T17:53:15Z","updated_at":"2016-05-12T14:41:31Z","closed_at":null,"body":"main.cpp:\r\n\r\n```cpp\r\n#include <stdint.h>\r\n\r\nextern uint64_t a, b;\r\n\r\nint main(int argc, char *argv[])\r\n{\r\n    if (a > a + b || a > a + b + 1)\r\n        return 1;\r\n\r\n    return 0;\r\n}\r\n```\r\n\r\n(I know this looks a bit strange, it is a condensed repro from 7zip's lzma extractor.)  And then I compile like this:\r\n\r\n```\r\npython em++ -O2 --closure 0 main.cpp\r\n```\r\n\r\nThe generated JS code for main.cpp is:\r\n\r\n```js\r\nfunction _main($argc, $argv) {\r\n  var $1$0 = HEAP32[_a >> 2];\r\n  var $1$1 = HEAP32[_a + 4 >> 2];\r\n  var $2$0 = HEAP32[_b >> 2];\r\n  var $2$1 = HEAP32[_b + 4 >> 2];\r\n  var $uadd = _llvm_uadd_with_overflow_i64($1$0, $1$1, $2$0, $2$1);\r\n  var $3 = $uadd.f1;\r\n  do {\r\n    if ($3) {\r\n      var $_0 = 1;\r\n    } else {\r\n      var $5 = $uadd.f0;\r\n      var $6$0 = (i64Math.add($5$0, $5$1, 1, 0), i64Math.result[0]);\r\n      var $6$1 = i64Math.result[1];\r\n      if ($1$1 >>> 0 > $6$1 >>> 0 || $1$1 >>> 0 == $6$1 >>> 0 && $1$0 >>> 0 > $6$0 >>> 0) {\r\n        var $_0 = 1;\r\n        break;\r\n      }\r\n      var $_0 = 0;\r\n    }\r\n  } while (0);\r\n  var $_0;\r\n  return $_0;\r\n  return null;\r\n}\r\n```\r\n\r\nThere are two problems here:\r\n1. ```llvm_uadd_with_overflow_i64``` is not implemented in library.js\r\n2. The code uses undeclared variables ```$5$0``` and ```$5$1```.\r\n\r\nI do not think it is correct to implement ```llvm_uadd_with_overflow_i64``` in the same way as ```llvm_uadd_with_overflow_i32```, e.g.\r\n\r\n```js\r\n  llvm_uadd_with_overflow_i64: function(x, y) {\r\n    x = x>>>0;\r\n    y = y>>>0;\r\n    return {\r\n      f0: (x+y)>>>0,\r\n      f1: x+y > 18446744073709551615\r\n    };\r\n  },\r\n```\r\n\r\nsince ```18446744073709551615```  is too large to represent in JavaScript's number type (and potentially also ```x+y```).\r\n\r\nI could not find any tests that exercise ```llvm_uadd_with_overflow_i32``` and ```llvm_umul_with_overflow_i32```.  (See also issues #48 and #108.)"},"comment":{"url":"https://api.github.com/repos/kripken/emscripten/issues/comments/218778642","html_url":"https://github.com/kripken/emscripten/issues/405#issuecomment-218778642","issue_url":"https://api.github.com/repos/kripken/emscripten/issues/405","id":218778642,"user":{"login":"juj","id":225351,"avatar_url":"https://avatars.githubusercontent.com/u/225351?v=3","gravatar_id":"","url":"https://api.github.com/users/juj","html_url":"https://github.com/juj","followers_url":"https://api.github.com/users/juj/followers","following_url":"https://api.github.com/users/juj/following{/other_user}","gists_url":"https://api.github.com/users/juj/gists{/gist_id}","starred_url":"https://api.github.com/users/juj/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/juj/subscriptions","organizations_url":"https://api.github.com/users/juj/orgs","repos_url":"https://api.github.com/users/juj/repos","events_url":"https://api.github.com/users/juj/events{/privacy}","received_events_url":"https://api.github.com/users/juj/received_events","type":"User","site_admin":false},"created_at":"2016-05-12T14:41:31Z","updated_at":"2016-05-12T14:41:31Z","body":"Is this still an unsupported item? Do we have this as a test case in bug tracker?"}}