{"action":"created","issue":{"url":"https://api.github.com/repos/cc65/cc65/issues/632","repository_url":"https://api.github.com/repos/cc65/cc65","labels_url":"https://api.github.com/repos/cc65/cc65/issues/632/labels{/name}","comments_url":"https://api.github.com/repos/cc65/cc65/issues/632/comments","events_url":"https://api.github.com/repos/cc65/cc65/issues/632/events","html_url":"https://github.com/cc65/cc65/issues/632","id":317972243,"number":632,"title":"Compile wrong with -O -Cl","user":{"login":"Ymhr6","id":38753952,"avatar_url":"https://avatars0.githubusercontent.com/u/38753952?v=4","gravatar_id":"","url":"https://api.github.com/users/Ymhr6","html_url":"https://github.com/Ymhr6","followers_url":"https://api.github.com/users/Ymhr6/followers","following_url":"https://api.github.com/users/Ymhr6/following{/other_user}","gists_url":"https://api.github.com/users/Ymhr6/gists{/gist_id}","starred_url":"https://api.github.com/users/Ymhr6/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Ymhr6/subscriptions","organizations_url":"https://api.github.com/users/Ymhr6/orgs","repos_url":"https://api.github.com/users/Ymhr6/repos","events_url":"https://api.github.com/users/Ymhr6/events{/privacy}","received_events_url":"https://api.github.com/users/Ymhr6/received_events","type":"User","site_admin":false},"labels":[{"id":32846633,"url":"https://api.github.com/repos/cc65/cc65/labels/bug","name":"bug","color":"fc2929","default":true}],"state":"open","locked":false,"assignee":{"login":"greg-king5","id":4145570,"avatar_url":"https://avatars0.githubusercontent.com/u/4145570?v=4","gravatar_id":"","url":"https://api.github.com/users/greg-king5","html_url":"https://github.com/greg-king5","followers_url":"https://api.github.com/users/greg-king5/followers","following_url":"https://api.github.com/users/greg-king5/following{/other_user}","gists_url":"https://api.github.com/users/greg-king5/gists{/gist_id}","starred_url":"https://api.github.com/users/greg-king5/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/greg-king5/subscriptions","organizations_url":"https://api.github.com/users/greg-king5/orgs","repos_url":"https://api.github.com/users/greg-king5/repos","events_url":"https://api.github.com/users/greg-king5/events{/privacy}","received_events_url":"https://api.github.com/users/greg-king5/received_events","type":"User","site_admin":false},"assignees":[{"login":"greg-king5","id":4145570,"avatar_url":"https://avatars0.githubusercontent.com/u/4145570?v=4","gravatar_id":"","url":"https://api.github.com/users/greg-king5","html_url":"https://github.com/greg-king5","followers_url":"https://api.github.com/users/greg-king5/followers","following_url":"https://api.github.com/users/greg-king5/following{/other_user}","gists_url":"https://api.github.com/users/greg-king5/gists{/gist_id}","starred_url":"https://api.github.com/users/greg-king5/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/greg-king5/subscriptions","organizations_url":"https://api.github.com/users/greg-king5/orgs","repos_url":"https://api.github.com/users/greg-king5/repos","events_url":"https://api.github.com/users/greg-king5/events{/privacy}","received_events_url":"https://api.github.com/users/greg-king5/received_events","type":"User","site_admin":false}],"milestone":null,"comments":7,"created_at":"2018-04-26T10:40:04Z","updated_at":"2018-04-30T18:37:01Z","closed_at":null,"author_association":"NONE","body":"This simple function loads a little-endian ushort from a buffer:\r\n```C\r\nunsigned short int load_le_ushort(unsigned char* buffer)\r\n{\r\n\tunsigned short int aResult = buffer[1];\r\n\taResult<<=8;\r\n\taResult|=buffer[0];\r\n\treturn aResult;\r\n}\r\n```\r\nCompiling with latest cc65 v 2.17 with optimization and static locals gives me wrong assembler in the bit shift zone:\r\n```asm\r\n\tlda     #$00\r\n\tsta     L0002+1\r\n;\r\n; aResult<<=8;\r\n;\r\n\tsta     L0002\r\n\tsta     L0002+1\r\n;\r\n```\r\nClearly, this will build a 0 (zero) value, that is wrong.\r\n\r\nThis is the entire assembler function\r\n```asm\r\n; ---------------------------------------------------------------\r\n; unsigned short __near__ load_le_ushort (__near__ unsigned char *)\r\n; ---------------------------------------------------------------\r\n\r\n.segment\t\"CODE\"\r\n\r\n.proc\t_load_le_ushort: near\r\n\r\n.segment\t\"BSS\"\r\n\r\nL0002:\r\n\t.res\t2,$00\r\n\r\n.segment\t\"CODE\"\r\n\r\n;\r\n; {\r\n;\r\n\tjsr     pushax\r\n;\r\n; unsigned short int aResult = buffer[1];\r\n;\r\n\tjsr     ldax0sp\r\n\tsta     ptr1\r\n\tstx     ptr1+1\r\n\tldy     #$01\r\n\tlda     (ptr1),y\r\n\tsta     L0002\r\n\tlda     #$00\r\n\tsta     L0002+1\r\n;\r\n; aResult<<=8;\r\n;\r\n\tsta     L0002\r\n\tsta     L0002+1\r\n;\r\n; aResult|=buffer[0];\r\n;\r\n\tjsr     push0\r\n\tldy     #$03\r\n\tjsr     ldaxysp\r\n\tsta     ptr1\r\n\tstx     ptr1+1\r\n\tldx     #$00\r\n\tlda     (ptr1,x)\r\n\tjsr     tosora0\r\n\tsta     L0002\r\n\tstx     L0002+1\r\n;\r\n; }\r\n;\r\n\tjmp     incsp2\r\n\r\n.endproc\r\n```"},"comment":{"url":"https://api.github.com/repos/cc65/cc65/issues/comments/385489351","html_url":"https://github.com/cc65/cc65/issues/632#issuecomment-385489351","issue_url":"https://api.github.com/repos/cc65/cc65/issues/632","id":385489351,"user":{"login":"Ymhr6","id":38753952,"avatar_url":"https://avatars0.githubusercontent.com/u/38753952?v=4","gravatar_id":"","url":"https://api.github.com/users/Ymhr6","html_url":"https://github.com/Ymhr6","followers_url":"https://api.github.com/users/Ymhr6/followers","following_url":"https://api.github.com/users/Ymhr6/following{/other_user}","gists_url":"https://api.github.com/users/Ymhr6/gists{/gist_id}","starred_url":"https://api.github.com/users/Ymhr6/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Ymhr6/subscriptions","organizations_url":"https://api.github.com/users/Ymhr6/orgs","repos_url":"https://api.github.com/users/Ymhr6/repos","events_url":"https://api.github.com/users/Ymhr6/events{/privacy}","received_events_url":"https://api.github.com/users/Ymhr6/received_events","type":"User","site_admin":false},"created_at":"2018-04-30T18:37:01Z","updated_at":"2018-04-30T18:37:01Z","author_association":"NONE","body":"I'm looking also at the last three lines of the function: as we have the return value in ax, storing it in L0002 just before returning is not necessary."}}
{"actor":{"display_login":"Ymhr6"}}