{"action":"created","issue":{"url":"https://api.github.com/repos/arduino/Arduino/issues/7718","repository_url":"https://api.github.com/repos/arduino/Arduino","labels_url":"https://api.github.com/repos/arduino/Arduino/issues/7718/labels{/name}","comments_url":"https://api.github.com/repos/arduino/Arduino/issues/7718/comments","events_url":"https://api.github.com/repos/arduino/Arduino/issues/7718/events","html_url":"https://github.com/arduino/Arduino/issues/7718","id":334946045,"node_id":"MDU6SXNzdWUzMzQ5NDYwNDU=","number":7718,"title":"Comparing an unsigned it fails if it is at 0xFFFF.","user":{"login":"cartolino","id":40498657,"node_id":"MDQ6VXNlcjQwNDk4NjU3","avatar_url":"https://avatars2.githubusercontent.com/u/40498657?v=4","gravatar_id":"","url":"https://api.github.com/users/cartolino","html_url":"https://github.com/cartolino","followers_url":"https://api.github.com/users/cartolino/followers","following_url":"https://api.github.com/users/cartolino/following{/other_user}","gists_url":"https://api.github.com/users/cartolino/gists{/gist_id}","starred_url":"https://api.github.com/users/cartolino/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cartolino/subscriptions","organizations_url":"https://api.github.com/users/cartolino/orgs","repos_url":"https://api.github.com/users/cartolino/repos","events_url":"https://api.github.com/users/cartolino/events{/privacy}","received_events_url":"https://api.github.com/users/cartolino/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":8,"created_at":"2018-06-22T16:41:56Z","updated_at":"2018-07-04T15:13:56Z","closed_at":null,"author_association":"NONE","body":"Code snippets:\r\n```\r\nunsigned int toff; // also tried with uint16_t , same results\r\nvoid setup(){ // .... .... .... .... \r\n```\r\n1) `toff=EEPROM.read(Toff)+256*EEPROM.read(Toff+1);if ((toff)>30000) toff=1500;`\r\n\r\n2) `toff=EEPROM.read(Toff)+256*EEPROM.read(Toff+1);if ((toff-1)>30000) toff=1500;`\r\n\r\n\r\nThe idea is to put a sensible default in RAM if the EEPROM was not programmed.\r\n\r\nProblem: after the 1st version of the code, toff==65535==0xFFFF ; Apparently the comparison fails with FFFF.\r\n\r\n(The 2nd variant with the -1 hack was contributed by a colleague whom I asked to debug this.)\r\n\r\nChecking the assembly code with avr-objdump shows only one difference in the 2 codes, the line shown with >>>>.\r\n```\r\n    1898:       90 93 d6 02     sts     0x02D6, r25     ; 0x8002d6 <toff+0x1>\r\n    189c:       80 93 d5 02     sts     0x02D5, r24     ; 0x8002d5 <toff>\r\n﹥﹥﹥﹥    18a0:       01 97           sbiw    r24, 0x01       ; 1\r\n    18a2:       81 33           cpi     r24, 0x31       ; 49\r\n    18a4:       95 47           sbci    r25, 0x75       ; 117\r\n    18a6:       30 f0           brcs    .+12            ; 0x18b4 <main+0x340>\r\n    18a8:       8c e4           ldi     r24, 0x4C       ; 76\r\n    18aa:       94 e0           ldi     r25, 0x04       ; 4\r\n    18ac:       90 93 d6 02     sts     0x02D6, r25     ; 0x8002d6 <toff+0x1>\r\n    18b0:       80 93 d5 02     sts     0x02D5, r24     ; 0x8002d5 <toff>\r\n```\r\n\r\nNot sure why the comparison fails when r24==0xFF and r25==0xFF but passes when r24=0xFE.\r\nAnd if it is an AVR issue (the MCU used was an Atmega324A with the MightyCore library from MCUDUDE, using LTO), then the compiler should probably adjust for this. \r\n\r\nOr is it an optimization issue?\r\n\r\nAt any rate, I fixed my project now with the hack, but it is still scary that one cannot compare for some input values.\r\n\r\nIf this is deemed a non-issue (due to it happening on 324A) is there any official way to prevent it other than the -1 which could fail on a zero?"},"comment":{"url":"https://api.github.com/repos/arduino/Arduino/issues/comments/402506529","html_url":"https://github.com/arduino/Arduino/issues/7718#issuecomment-402506529","issue_url":"https://api.github.com/repos/arduino/Arduino/issues/7718","id":402506529,"node_id":"MDEyOklzc3VlQ29tbWVudDQwMjUwNjUyOQ==","user":{"login":"cartolino","id":40498657,"node_id":"MDQ6VXNlcjQwNDk4NjU3","avatar_url":"https://avatars2.githubusercontent.com/u/40498657?v=4","gravatar_id":"","url":"https://api.github.com/users/cartolino","html_url":"https://github.com/cartolino","followers_url":"https://api.github.com/users/cartolino/followers","following_url":"https://api.github.com/users/cartolino/following{/other_user}","gists_url":"https://api.github.com/users/cartolino/gists{/gist_id}","starred_url":"https://api.github.com/users/cartolino/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cartolino/subscriptions","organizations_url":"https://api.github.com/users/cartolino/orgs","repos_url":"https://api.github.com/users/cartolino/repos","events_url":"https://api.github.com/users/cartolino/events{/privacy}","received_events_url":"https://api.github.com/users/cartolino/received_events","type":"User","site_admin":false},"created_at":"2018-07-04T15:13:56Z","updated_at":"2018-07-04T15:13:56Z","author_association":"NONE","body":"So, is this a GCC bug or an Arduino tool chain bug?\r\n(Meaning, who needs to be notified in order to get it fixed?)"}}
{"actor":{"display_login":"cartolino"}}