{"action":"created","comment":{"url":"https://api.github.com/repos/uxmal/reko/pulls/comments/82531746","pull_request_review_id":3433548,"id":82531746,"diff_hunk":"@@ -95,14 +102,57 @@ private void RewriteCall(Statement stm, CallInstruction call)\n             var ft = pt.Pointee as FunctionType;\n             if (ft == null)\n                 return;\n-            var returnId = ft.ReturnValue.DataType is VoidType ?\n-                null : ft.ReturnValue;\n-            var sigCallee = new FunctionType(returnId, ft.Parameters);\n+            AdjustStack(stm, call, ft.StackDelta);\n             var ab = new FrameApplicationBuilder(\n                  program.Architecture, proc.Frame, call.CallSite,\n-                 call.Callee, true);\n-            stm.Instruction = ab.CreateInstruction(sigCallee, null);\n+                 call.Callee, false);\n+            stm.Instruction = ab.CreateInstruction(ft, null);\n             ssaIdTransformer.Transform(stm, call);\n+            changed = true;\n+        }\n+\n+        private void AdjustStack(\n+            Statement stm,\n+            CallInstruction call,\n+            int stackDelta)\n+        {\n+            var defSpBinding = call.Definitions.Where(\n+                u => u.Storage == program.Architecture.StackRegister)\n+                .FirstOrDefault();\n+            if (defSpBinding == null)\n+                return;\n+            var defSpId = defSpBinding.Expression as Identifier;\n+            if (defSpId == null)\n+                return;\n+            var usedSpExp = call.Uses.Where(\n+                u => u.Storage == program.Architecture.StackRegister)\n+                .Select(u => u.Expression)\n+                .FirstOrDefault();\n+            if (usedSpExp == null)\n+                return;\n+            var retSize = call.CallSite.SizeOfReturnAddressOnStack;\n+            var offset = stackDelta - retSize;\n+            var src = emiter.IAdd(usedSpExp, Constant.Word32(offset));\n+            var ass = new Assignment(defSpId, src);","path":"src/Decompiler/Analysis/IndirectCallRewriter.cs","position":80,"original_position":80,"commit_id":"fbcde84cf1dee3768ccc4a991467346565ff1a0b","original_commit_id":"fbcde84cf1dee3768ccc4a991467346565ff1a0b","user":{"login":"uxmal","id":10154465,"avatar_url":"https://avatars.githubusercontent.com/u/10154465?v=3","gravatar_id":"","url":"https://api.github.com/users/uxmal","html_url":"https://github.com/uxmal","followers_url":"https://api.github.com/users/uxmal/followers","following_url":"https://api.github.com/users/uxmal/following{/other_user}","gists_url":"https://api.github.com/users/uxmal/gists{/gist_id}","starred_url":"https://api.github.com/users/uxmal/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/uxmal/subscriptions","organizations_url":"https://api.github.com/users/uxmal/orgs","repos_url":"https://api.github.com/users/uxmal/repos","events_url":"https://api.github.com/users/uxmal/events{/privacy}","received_events_url":"https://api.github.com/users/uxmal/received_events","type":"User","site_admin":false},"body":"Micro-optimization: don't inject an `sp_n = sp_m + offset` statement if `offset = 0` -- which is the common `__cdecl` case.","created_at":"2016-10-09T21:13:39Z","updated_at":"2016-10-09T21:13:39Z","html_url":"https://github.com/uxmal/reko/pull/329#discussion_r82531746","pull_request_url":"https://api.github.com/repos/uxmal/reko/pulls/329","_links":{"self":{"href":"https://api.github.com/repos/uxmal/reko/pulls/comments/82531746"},"html":{"href":"https://github.com/uxmal/reko/pull/329#discussion_r82531746"},"pull_request":{"href":"https://api.github.com/repos/uxmal/reko/pulls/329"}}},"pull_request":{"url":"https://api.github.com/repos/uxmal/reko/pulls/329","id":88579217,"html_url":"https://github.com/uxmal/reko/pull/329","diff_url":"https://github.com/uxmal/reko/pull/329.diff","patch_url":"https://github.com/uxmal/reko/pull/329.patch","issue_url":"https://api.github.com/repos/uxmal/reko/issues/329","number":329,"state":"open","locked":false,"title":"Make IndirectCallRewriter works on VCExeSample","user":{"login":"ptomin","id":13188041,"avatar_url":"https://avatars.githubusercontent.com/u/13188041?v=3","gravatar_id":"","url":"https://api.github.com/users/ptomin","html_url":"https://github.com/ptomin","followers_url":"https://api.github.com/users/ptomin/followers","following_url":"https://api.github.com/users/ptomin/following{/other_user}","gists_url":"https://api.github.com/users/ptomin/gists{/gist_id}","starred_url":"https://api.github.com/users/ptomin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ptomin/subscriptions","organizations_url":"https://api.github.com/users/ptomin/orgs","repos_url":"https://api.github.com/users/ptomin/repos","events_url":"https://api.github.com/users/ptomin/events{/privacy}","received_events_url":"https://api.github.com/users/ptomin/received_events","type":"User","site_admin":false},"body":"Make `IndirectCallRewriter` works on `VCExeSample`\r\n- Call `IndirectCallRewriter` at data flow analysis stage.\r\n- Add stack adjustment statement after rewritten call\r\n- Do not ensure variables. Create direct memory access instead. It allows to avoid dependency on stack depth on function entry\r\n- `TrashedRegisterFinder2`: check if definition statement is `null`\r\n- Fix broken tests ","created_at":"2016-10-09T12:26:38Z","updated_at":"2016-10-09T21:13:39Z","closed_at":null,"merged_at":null,"merge_commit_sha":"a15e7547e4abdc17d38642d77c9c36679b307b1f","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/uxmal/reko/pulls/329/commits","review_comments_url":"https://api.github.com/repos/uxmal/reko/pulls/329/comments","review_comment_url":"https://api.github.com/repos/uxmal/reko/pulls/comments{/number}","comments_url":"https://api.github.com/repos/uxmal/reko/issues/329/comments","statuses_url":"https://api.github.com/repos/uxmal/reko/statuses/fbcde84cf1dee3768ccc4a991467346565ff1a0b","head":{"label":"ptomin:execute-icrw","ref":"execute-icrw","sha":"fbcde84cf1dee3768ccc4a991467346565ff1a0b","user":{"login":"ptomin","id":13188041,"avatar_url":"https://avatars.githubusercontent.com/u/13188041?v=3","gravatar_id":"","url":"https://api.github.com/users/ptomin","html_url":"https://github.com/ptomin","followers_url":"https://api.github.com/users/ptomin/followers","following_url":"https://api.github.com/users/ptomin/following{/other_user}","gists_url":"https://api.github.com/users/ptomin/gists{/gist_id}","starred_url":"https://api.github.com/users/ptomin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ptomin/subscriptions","organizations_url":"https://api.github.com/users/ptomin/orgs","repos_url":"https://api.github.com/users/ptomin/repos","events_url":"https://api.github.com/users/ptomin/events{/privacy}","received_events_url":"https://api.github.com/users/ptomin/received_events","type":"User","site_admin":false},"repo":{"id":48247195,"name":"reko","full_name":"ptomin/reko","owner":{"login":"ptomin","id":13188041,"avatar_url":"https://avatars.githubusercontent.com/u/13188041?v=3","gravatar_id":"","url":"https://api.github.com/users/ptomin","html_url":"https://github.com/ptomin","followers_url":"https://api.github.com/users/ptomin/followers","following_url":"https://api.github.com/users/ptomin/following{/other_user}","gists_url":"https://api.github.com/users/ptomin/gists{/gist_id}","starred_url":"https://api.github.com/users/ptomin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ptomin/subscriptions","organizations_url":"https://api.github.com/users/ptomin/orgs","repos_url":"https://api.github.com/users/ptomin/repos","events_url":"https://api.github.com/users/ptomin/events{/privacy}","received_events_url":"https://api.github.com/users/ptomin/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/ptomin/reko","description":"Reko is a binary decompiler.","fork":true,"url":"https://api.github.com/repos/ptomin/reko","forks_url":"https://api.github.com/repos/ptomin/reko/forks","keys_url":"https://api.github.com/repos/ptomin/reko/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ptomin/reko/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ptomin/reko/teams","hooks_url":"https://api.github.com/repos/ptomin/reko/hooks","issue_events_url":"https://api.github.com/repos/ptomin/reko/issues/events{/number}","events_url":"https://api.github.com/repos/ptomin/reko/events","assignees_url":"https://api.github.com/repos/ptomin/reko/assignees{/user}","branches_url":"https://api.github.com/repos/ptomin/reko/branches{/branch}","tags_url":"https://api.github.com/repos/ptomin/reko/tags","blobs_url":"https://api.github.com/repos/ptomin/reko/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ptomin/reko/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ptomin/reko/git/refs{/sha}","trees_url":"https://api.github.com/repos/ptomin/reko/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ptomin/reko/statuses/{sha}","languages_url":"https://api.github.com/repos/ptomin/reko/languages","stargazers_url":"https://api.github.com/repos/ptomin/reko/stargazers","contributors_url":"https://api.github.com/repos/ptomin/reko/contributors","subscribers_url":"https://api.github.com/repos/ptomin/reko/subscribers","subscription_url":"https://api.github.com/repos/ptomin/reko/subscription","commits_url":"https://api.github.com/repos/ptomin/reko/commits{/sha}","git_commits_url":"https://api.github.com/repos/ptomin/reko/git/commits{/sha}","comments_url":"https://api.github.com/repos/ptomin/reko/comments{/number}","issue_comment_url":"https://api.github.com/repos/ptomin/reko/issues/comments{/number}","contents_url":"https://api.github.com/repos/ptomin/reko/contents/{+path}","compare_url":"https://api.github.com/repos/ptomin/reko/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ptomin/reko/merges","archive_url":"https://api.github.com/repos/ptomin/reko/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ptomin/reko/downloads","issues_url":"https://api.github.com/repos/ptomin/reko/issues{/number}","pulls_url":"https://api.github.com/repos/ptomin/reko/pulls{/number}","milestones_url":"https://api.github.com/repos/ptomin/reko/milestones{/number}","notifications_url":"https://api.github.com/repos/ptomin/reko/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ptomin/reko/labels{/name}","releases_url":"https://api.github.com/repos/ptomin/reko/releases{/id}","deployments_url":"https://api.github.com/repos/ptomin/reko/deployments","created_at":"2015-12-18T17:15:47Z","updated_at":"2016-04-24T08:20:54Z","pushed_at":"2016-10-09T13:06:52Z","git_url":"git://github.com/ptomin/reko.git","ssh_url":"git@github.com:ptomin/reko.git","clone_url":"https://github.com/ptomin/reko.git","svn_url":"https://github.com/ptomin/reko","homepage":"https://uxmal.github.io/reko","size":98945,"stargazers_count":2,"watchers_count":2,"language":"Assembly","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":2,"default_branch":"master"}},"base":{"label":"uxmal:analysis-development","ref":"analysis-development","sha":"ac6d1d7a97417bc49d470cbca2ec6ec30718ed81","user":{"login":"uxmal","id":10154465,"avatar_url":"https://avatars.githubusercontent.com/u/10154465?v=3","gravatar_id":"","url":"https://api.github.com/users/uxmal","html_url":"https://github.com/uxmal","followers_url":"https://api.github.com/users/uxmal/followers","following_url":"https://api.github.com/users/uxmal/following{/other_user}","gists_url":"https://api.github.com/users/uxmal/gists{/gist_id}","starred_url":"https://api.github.com/users/uxmal/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/uxmal/subscriptions","organizations_url":"https://api.github.com/users/uxmal/orgs","repos_url":"https://api.github.com/users/uxmal/repos","events_url":"https://api.github.com/users/uxmal/events{/privacy}","received_events_url":"https://api.github.com/users/uxmal/received_events","type":"User","site_admin":false},"repo":{"id":39718308,"name":"reko","full_name":"uxmal/reko","owner":{"login":"uxmal","id":10154465,"avatar_url":"https://avatars.githubusercontent.com/u/10154465?v=3","gravatar_id":"","url":"https://api.github.com/users/uxmal","html_url":"https://github.com/uxmal","followers_url":"https://api.github.com/users/uxmal/followers","following_url":"https://api.github.com/users/uxmal/following{/other_user}","gists_url":"https://api.github.com/users/uxmal/gists{/gist_id}","starred_url":"https://api.github.com/users/uxmal/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/uxmal/subscriptions","organizations_url":"https://api.github.com/users/uxmal/orgs","repos_url":"https://api.github.com/users/uxmal/repos","events_url":"https://api.github.com/users/uxmal/events{/privacy}","received_events_url":"https://api.github.com/users/uxmal/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/uxmal/reko","description":"Reko is a binary decompiler.","fork":false,"url":"https://api.github.com/repos/uxmal/reko","forks_url":"https://api.github.com/repos/uxmal/reko/forks","keys_url":"https://api.github.com/repos/uxmal/reko/keys{/key_id}","collaborators_url":"https://api.github.com/repos/uxmal/reko/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/uxmal/reko/teams","hooks_url":"https://api.github.com/repos/uxmal/reko/hooks","issue_events_url":"https://api.github.com/repos/uxmal/reko/issues/events{/number}","events_url":"https://api.github.com/repos/uxmal/reko/events","assignees_url":"https://api.github.com/repos/uxmal/reko/assignees{/user}","branches_url":"https://api.github.com/repos/uxmal/reko/branches{/branch}","tags_url":"https://api.github.com/repos/uxmal/reko/tags","blobs_url":"https://api.github.com/repos/uxmal/reko/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/uxmal/reko/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/uxmal/reko/git/refs{/sha}","trees_url":"https://api.github.com/repos/uxmal/reko/git/trees{/sha}","statuses_url":"https://api.github.com/repos/uxmal/reko/statuses/{sha}","languages_url":"https://api.github.com/repos/uxmal/reko/languages","stargazers_url":"https://api.github.com/repos/uxmal/reko/stargazers","contributors_url":"https://api.github.com/repos/uxmal/reko/contributors","subscribers_url":"https://api.github.com/repos/uxmal/reko/subscribers","subscription_url":"https://api.github.com/repos/uxmal/reko/subscription","commits_url":"https://api.github.com/repos/uxmal/reko/commits{/sha}","git_commits_url":"https://api.github.com/repos/uxmal/reko/git/commits{/sha}","comments_url":"https://api.github.com/repos/uxmal/reko/comments{/number}","issue_comment_url":"https://api.github.com/repos/uxmal/reko/issues/comments{/number}","contents_url":"https://api.github.com/repos/uxmal/reko/contents/{+path}","compare_url":"https://api.github.com/repos/uxmal/reko/compare/{base}...{head}","merges_url":"https://api.github.com/repos/uxmal/reko/merges","archive_url":"https://api.github.com/repos/uxmal/reko/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/uxmal/reko/downloads","issues_url":"https://api.github.com/repos/uxmal/reko/issues{/number}","pulls_url":"https://api.github.com/repos/uxmal/reko/pulls{/number}","milestones_url":"https://api.github.com/repos/uxmal/reko/milestones{/number}","notifications_url":"https://api.github.com/repos/uxmal/reko/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/uxmal/reko/labels{/name}","releases_url":"https://api.github.com/repos/uxmal/reko/releases{/id}","deployments_url":"https://api.github.com/repos/uxmal/reko/deployments","created_at":"2015-07-26T07:58:30Z","updated_at":"2016-10-03T11:44:43Z","pushed_at":"2016-10-09T12:26:38Z","git_url":"git://github.com/uxmal/reko.git","ssh_url":"git@github.com:uxmal/reko.git","clone_url":"https://github.com/uxmal/reko.git","svn_url":"https://github.com/uxmal/reko","homepage":"https://uxmal.github.io/reko","size":100361,"stargazers_count":100,"watchers_count":100,"language":"Assembly","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":21,"mirror_url":null,"open_issues_count":58,"forks":21,"open_issues":58,"watchers":100,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/uxmal/reko/pulls/329"},"html":{"href":"https://github.com/uxmal/reko/pull/329"},"issue":{"href":"https://api.github.com/repos/uxmal/reko/issues/329"},"comments":{"href":"https://api.github.com/repos/uxmal/reko/issues/329/comments"},"review_comments":{"href":"https://api.github.com/repos/uxmal/reko/pulls/329/comments"},"review_comment":{"href":"https://api.github.com/repos/uxmal/reko/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/uxmal/reko/pulls/329/commits"},"statuses":{"href":"https://api.github.com/repos/uxmal/reko/statuses/fbcde84cf1dee3768ccc4a991467346565ff1a0b"}}}}
{"actor":{"display_login":"uxmal"}}