{"action":"opened","issue":{"url":"https://api.github.com/repos/halide/Halide/issues/941","labels_url":"https://api.github.com/repos/halide/Halide/issues/941/labels{/name}","comments_url":"https://api.github.com/repos/halide/Halide/issues/941/comments","events_url":"https://api.github.com/repos/halide/Halide/issues/941/events","html_url":"https://github.com/halide/Halide/issues/941","id":110704541,"number":941,"title":"Consider Applying Analysis to Detect Integer Division By Zero","user":{"login":"dan-tull","id":13667418,"avatar_url":"https://avatars.githubusercontent.com/u/13667418?v=3","gravatar_id":"","url":"https://api.github.com/users/dan-tull","html_url":"https://github.com/dan-tull","followers_url":"https://api.github.com/users/dan-tull/followers","following_url":"https://api.github.com/users/dan-tull/following{/other_user}","gists_url":"https://api.github.com/users/dan-tull/gists{/gist_id}","starred_url":"https://api.github.com/users/dan-tull/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dan-tull/subscriptions","organizations_url":"https://api.github.com/users/dan-tull/orgs","repos_url":"https://api.github.com/users/dan-tull/repos","events_url":"https://api.github.com/users/dan-tull/events{/privacy}","received_events_url":"https://api.github.com/users/dan-tull/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-10-09T17:37:31Z","updated_at":"2015-10-09T17:37:31Z","closed_at":null,"body":"Halide's bounds checking traps a lot of mistakes that would otherwise result in out of range indexing of buffers that could cause crashes.\r\n\r\nIt seems like similar analysis of the denominator in integer division operations to ensure the range of possible values does not include zero might be useful.\r\n\r\nHere's a trivial example.\r\n\r\nBecause the size parameter includes zero, this code will crash for certain inputs. A more complex denominator expression would require more complex reasoning to determine if zero could occur.\r\n\r\n    Var x, y, c;\r\n\r\n    Param<int> size(\"size\", 32, 0, 32);\r\n    result(x, y, c) = cast<uint8_t>(32 / size);\r\n    result.parallel(y).vectorize(x, 8);\r\n\r\nMaybe this doesn't come up enough in practice to be important, but seems worth considering.\r\n"}}