{"action":"created","comment":{"url":"https://api.github.com/repos/freebasic/fbc/pulls/comments/198928071","pull_request_review_id":132950058,"id":198928071,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDE5ODkyODA3MQ==","diff_hunk":"@@ -472,6 +484,41 @@ function astNewCONV _\n \tn->l = l\n \tn->cast.doconv = doconv\n \tn->cast.do_convfd2fs = FALSE\n+\tn->cast.convconst = FALSE\n+\n+\t'' Discarding/changing const qualifier bits ?\n+\t'' TODO: reuse symbCheckConstAssign()?","path":"src/compiler/ast-node-conv.bas","position":28,"original_position":28,"commit_id":"cb957b366582dc9ecd4f58b9d8f99608cb613871","original_commit_id":"cb957b366582dc9ecd4f58b9d8f99608cb613871","user":{"login":"dkl","id":212549,"node_id":"MDQ6VXNlcjIxMjU0OQ==","avatar_url":"https://avatars0.githubusercontent.com/u/212549?v=4","gravatar_id":"","url":"https://api.github.com/users/dkl","html_url":"https://github.com/dkl","followers_url":"https://api.github.com/users/dkl/followers","following_url":"https://api.github.com/users/dkl/following{/other_user}","gists_url":"https://api.github.com/users/dkl/gists{/gist_id}","starred_url":"https://api.github.com/users/dkl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dkl/subscriptions","organizations_url":"https://api.github.com/users/dkl/orgs","repos_url":"https://api.github.com/users/dkl/repos","events_url":"https://api.github.com/users/dkl/events{/privacy}","received_events_url":"https://api.github.com/users/dkl/received_events","type":"User","site_admin":false},"body":"yea, I think re-using symbCheckConstAssign and astPtrCheck (see astNewASSIGN/hCheckConstAndPointerOps) would be useful. The code below seems to be effectively the same as symbCheckConstAssign, and astPtrCheck uses the overload resolution (typeCalcMatch()) which will also check procedure pointer parameter types recursively.\r\n\r\n```\r\nsub sub_const(byref i as const integer)\r\n\tprint i\r\nend sub\r\n\r\nsub sub_noconst(byref i as integer)\r\n\ti = 123\r\n\tprint i\r\nend sub\r\n\r\ntype type_const as sub(byref as const integer)\r\ntype type_noconst as sub(byref as integer)\r\n\r\ndim ptr_const as type_const\r\ndim ptr_noconst as type_noconst\r\n\r\nptr_const   = @sub_const   '' safe, same type\r\nptr_const   = @sub_noconst '' unsafe, because when calling through the ptr the param appears const, but the sub actually modifies it\r\nptr_noconst = @sub_const   '' safe, ptr allows more than the sub will do\r\nptr_noconst = @sub_noconst '' safe, same type\r\n\r\nprint cptr(sub(byref as const integer), @sub_const) '' safe\r\nprint cptr(sub(byref as const integer), @sub_noconst) '' unsafe, currently no warning even with -w constness\r\nprint cptr(sub(byref as integer), @sub_const) '' safe\r\nprint cptr(sub(byref as integer), @sub_noconst) '' safe\r\n```","created_at":"2018-06-28T17:45:27Z","updated_at":"2018-06-28T17:45:27Z","html_url":"https://github.com/freebasic/fbc/pull/90#discussion_r198928071","pull_request_url":"https://api.github.com/repos/freebasic/fbc/pulls/90","author_association":"COLLABORATOR","_links":{"self":{"href":"https://api.github.com/repos/freebasic/fbc/pulls/comments/198928071"},"html":{"href":"https://github.com/freebasic/fbc/pull/90#discussion_r198928071"},"pull_request":{"href":"https://api.github.com/repos/freebasic/fbc/pulls/90"}}},"pull_request":{"url":"https://api.github.com/repos/freebasic/fbc/pulls/90","id":197294715,"node_id":"MDExOlB1bGxSZXF1ZXN0MTk3Mjk0NzE1","html_url":"https://github.com/freebasic/fbc/pull/90","diff_url":"https://github.com/freebasic/fbc/pull/90.diff","patch_url":"https://github.com/freebasic/fbc/pull/90.patch","issue_url":"https://api.github.com/repos/freebasic/fbc/issues/90","number":90,"state":"open","locked":false,"title":"Casting, Conversions, Const Qualifiers, Byref","user":{"login":"jayrm","id":12654929,"node_id":"MDQ6VXNlcjEyNjU0OTI5","avatar_url":"https://avatars1.githubusercontent.com/u/12654929?v=4","gravatar_id":"","url":"https://api.github.com/users/jayrm","html_url":"https://github.com/jayrm","followers_url":"https://api.github.com/users/jayrm/followers","following_url":"https://api.github.com/users/jayrm/following{/other_user}","gists_url":"https://api.github.com/users/jayrm/gists{/gist_id}","starred_url":"https://api.github.com/users/jayrm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jayrm/subscriptions","organizations_url":"https://api.github.com/users/jayrm/orgs","repos_url":"https://api.github.com/users/jayrm/repos","events_url":"https://api.github.com/users/jayrm/events{/privacy}","received_events_url":"https://api.github.com/users/jayrm/received_events","type":"User","site_admin":false},"body":"For:\r\n#642 Pointer casting allows constness dropping\r\n#801 parser allows more constructs under -exx than without it \r\n#842 BYREF (variable) does not report some assignment errors detectable on its internal pointer \r\n#886 Inconsistent error with BYREF and CAST on CONST variables \r\n\r\nPrimary issue is in AST, the conversion node (AST_NODECLASS_CONV), records information used later in code generation (i.e. different sizes or classes) and type information (i.e. different levels of pointer indirection or const-ness).  Often, the TYPE information needs to be preserved until an expression is completely parsed.  Because some type information is only present in the AST, it needs to remain valid at least long enough to be used.  In this patch, a separate flag is used to track const qualifier changes.\r\n\r\nSecondary issue, is with -exx and Null ptr checks.  For some expressions, it's only after the expression is fully parsed can it be determined that any null pointer checks that were injected, should be removed.  Some null ptr checks were not being cleanly removed and so the resulting AST was different depending on if -exx was enabled or not.\r\n\r\nThe beginning of this pull request is a starting point for a WIP, and creating PR seems like an efficient way to develop and discuss the progress.\r\n\r\nSome behaviour is only seen when '-w constness' command line option given, otherwise, most of the tests/warnings/test.sh tests will fail.  For example:\r\n```\r\ndim x as const integer = 1\r\ndim p as integer ptr\r\n\r\np = cast( byte ptr, @x )\r\n\r\n'' a.bas(4) warning 40(0): CONST qualifier discarded\r\n'' a.bas(4) warning 4(1): Suspicious pointer assignment\r\n```\r\n\r\nThere are several TODO's in the code to record next steps, or places the need more investigation.\r\n\r\nThe location of the new warning is not ideal.  Ideally, astNewCONV would just initialize the conversion node and the parser would already have determined if the operation is valid.  That's not always possible (or at least very complex/duplicating), and using astNewCONV to catch all and generate the warning is convenient.","created_at":"2018-06-26T03:52:57Z","updated_at":"2018-06-28T17:45:27Z","closed_at":null,"merged_at":null,"merge_commit_sha":"8eea184e36e1b2ed9d0fa953c629d82dfecbd865","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/freebasic/fbc/pulls/90/commits","review_comments_url":"https://api.github.com/repos/freebasic/fbc/pulls/90/comments","review_comment_url":"https://api.github.com/repos/freebasic/fbc/pulls/comments{/number}","comments_url":"https://api.github.com/repos/freebasic/fbc/issues/90/comments","statuses_url":"https://api.github.com/repos/freebasic/fbc/statuses/cb957b366582dc9ecd4f58b9d8f99608cb613871","head":{"label":"jayrm:cast-conv-ptr","ref":"cast-conv-ptr","sha":"cb957b366582dc9ecd4f58b9d8f99608cb613871","user":{"login":"jayrm","id":12654929,"node_id":"MDQ6VXNlcjEyNjU0OTI5","avatar_url":"https://avatars1.githubusercontent.com/u/12654929?v=4","gravatar_id":"","url":"https://api.github.com/users/jayrm","html_url":"https://github.com/jayrm","followers_url":"https://api.github.com/users/jayrm/followers","following_url":"https://api.github.com/users/jayrm/following{/other_user}","gists_url":"https://api.github.com/users/jayrm/gists{/gist_id}","starred_url":"https://api.github.com/users/jayrm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jayrm/subscriptions","organizations_url":"https://api.github.com/users/jayrm/orgs","repos_url":"https://api.github.com/users/jayrm/repos","events_url":"https://api.github.com/users/jayrm/events{/privacy}","received_events_url":"https://api.github.com/users/jayrm/received_events","type":"User","site_admin":false},"repo":{"id":36485266,"node_id":"MDEwOlJlcG9zaXRvcnkzNjQ4NTI2Ng==","name":"fbc","full_name":"jayrm/fbc","owner":{"login":"jayrm","id":12654929,"node_id":"MDQ6VXNlcjEyNjU0OTI5","avatar_url":"https://avatars1.githubusercontent.com/u/12654929?v=4","gravatar_id":"","url":"https://api.github.com/users/jayrm","html_url":"https://github.com/jayrm","followers_url":"https://api.github.com/users/jayrm/followers","following_url":"https://api.github.com/users/jayrm/following{/other_user}","gists_url":"https://api.github.com/users/jayrm/gists{/gist_id}","starred_url":"https://api.github.com/users/jayrm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jayrm/subscriptions","organizations_url":"https://api.github.com/users/jayrm/orgs","repos_url":"https://api.github.com/users/jayrm/repos","events_url":"https://api.github.com/users/jayrm/events{/privacy}","received_events_url":"https://api.github.com/users/jayrm/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/jayrm/fbc","description":"FreeBASIC is a completely free, open-source, multi-platform BASIC compiler, with syntax similar to MS-QuickBASIC, that adds new features such as pointers, unsigned data types, inline assembly, object orientation, and many others.","fork":true,"url":"https://api.github.com/repos/jayrm/fbc","forks_url":"https://api.github.com/repos/jayrm/fbc/forks","keys_url":"https://api.github.com/repos/jayrm/fbc/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jayrm/fbc/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jayrm/fbc/teams","hooks_url":"https://api.github.com/repos/jayrm/fbc/hooks","issue_events_url":"https://api.github.com/repos/jayrm/fbc/issues/events{/number}","events_url":"https://api.github.com/repos/jayrm/fbc/events","assignees_url":"https://api.github.com/repos/jayrm/fbc/assignees{/user}","branches_url":"https://api.github.com/repos/jayrm/fbc/branches{/branch}","tags_url":"https://api.github.com/repos/jayrm/fbc/tags","blobs_url":"https://api.github.com/repos/jayrm/fbc/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jayrm/fbc/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jayrm/fbc/git/refs{/sha}","trees_url":"https://api.github.com/repos/jayrm/fbc/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jayrm/fbc/statuses/{sha}","languages_url":"https://api.github.com/repos/jayrm/fbc/languages","stargazers_url":"https://api.github.com/repos/jayrm/fbc/stargazers","contributors_url":"https://api.github.com/repos/jayrm/fbc/contributors","subscribers_url":"https://api.github.com/repos/jayrm/fbc/subscribers","subscription_url":"https://api.github.com/repos/jayrm/fbc/subscription","commits_url":"https://api.github.com/repos/jayrm/fbc/commits{/sha}","git_commits_url":"https://api.github.com/repos/jayrm/fbc/git/commits{/sha}","comments_url":"https://api.github.com/repos/jayrm/fbc/comments{/number}","issue_comment_url":"https://api.github.com/repos/jayrm/fbc/issues/comments{/number}","contents_url":"https://api.github.com/repos/jayrm/fbc/contents/{+path}","compare_url":"https://api.github.com/repos/jayrm/fbc/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jayrm/fbc/merges","archive_url":"https://api.github.com/repos/jayrm/fbc/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jayrm/fbc/downloads","issues_url":"https://api.github.com/repos/jayrm/fbc/issues{/number}","pulls_url":"https://api.github.com/repos/jayrm/fbc/pulls{/number}","milestones_url":"https://api.github.com/repos/jayrm/fbc/milestones{/number}","notifications_url":"https://api.github.com/repos/jayrm/fbc/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jayrm/fbc/labels{/name}","releases_url":"https://api.github.com/repos/jayrm/fbc/releases{/id}","deployments_url":"https://api.github.com/repos/jayrm/fbc/deployments","created_at":"2015-05-29T06:07:46Z","updated_at":"2018-06-01T23:26:11Z","pushed_at":"2018-06-27T22:47:16Z","git_url":"git://github.com/jayrm/fbc.git","ssh_url":"git@github.com:jayrm/fbc.git","clone_url":"https://github.com/jayrm/fbc.git","svn_url":"https://github.com/jayrm/fbc","homepage":"http://www.freebasic.net","size":49711,"stargazers_count":2,"watchers_count":2,"language":"Visual Basic","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":null,"forks":0,"open_issues":0,"watchers":2,"default_branch":"master"}},"base":{"label":"freebasic:master","ref":"master","sha":"4f0d5057f4859de918b66e888654eaef45d396db","user":{"login":"freebasic","id":298124,"node_id":"MDQ6VXNlcjI5ODEyNA==","avatar_url":"https://avatars3.githubusercontent.com/u/298124?v=4","gravatar_id":"","url":"https://api.github.com/users/freebasic","html_url":"https://github.com/freebasic","followers_url":"https://api.github.com/users/freebasic/followers","following_url":"https://api.github.com/users/freebasic/following{/other_user}","gists_url":"https://api.github.com/users/freebasic/gists{/gist_id}","starred_url":"https://api.github.com/users/freebasic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/freebasic/subscriptions","organizations_url":"https://api.github.com/users/freebasic/orgs","repos_url":"https://api.github.com/users/freebasic/repos","events_url":"https://api.github.com/users/freebasic/events{/privacy}","received_events_url":"https://api.github.com/users/freebasic/received_events","type":"User","site_admin":false},"repo":{"id":2458946,"node_id":"MDEwOlJlcG9zaXRvcnkyNDU4OTQ2","name":"fbc","full_name":"freebasic/fbc","owner":{"login":"freebasic","id":298124,"node_id":"MDQ6VXNlcjI5ODEyNA==","avatar_url":"https://avatars3.githubusercontent.com/u/298124?v=4","gravatar_id":"","url":"https://api.github.com/users/freebasic","html_url":"https://github.com/freebasic","followers_url":"https://api.github.com/users/freebasic/followers","following_url":"https://api.github.com/users/freebasic/following{/other_user}","gists_url":"https://api.github.com/users/freebasic/gists{/gist_id}","starred_url":"https://api.github.com/users/freebasic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/freebasic/subscriptions","organizations_url":"https://api.github.com/users/freebasic/orgs","repos_url":"https://api.github.com/users/freebasic/repos","events_url":"https://api.github.com/users/freebasic/events{/privacy}","received_events_url":"https://api.github.com/users/freebasic/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/freebasic/fbc","description":"FreeBASIC is a completely free, open-source, multi-platform BASIC compiler, with syntax similar to MS-QuickBASIC, that adds new features such as pointers, unsigned data types, inline assembly, object orientation, and many others.","fork":false,"url":"https://api.github.com/repos/freebasic/fbc","forks_url":"https://api.github.com/repos/freebasic/fbc/forks","keys_url":"https://api.github.com/repos/freebasic/fbc/keys{/key_id}","collaborators_url":"https://api.github.com/repos/freebasic/fbc/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/freebasic/fbc/teams","hooks_url":"https://api.github.com/repos/freebasic/fbc/hooks","issue_events_url":"https://api.github.com/repos/freebasic/fbc/issues/events{/number}","events_url":"https://api.github.com/repos/freebasic/fbc/events","assignees_url":"https://api.github.com/repos/freebasic/fbc/assignees{/user}","branches_url":"https://api.github.com/repos/freebasic/fbc/branches{/branch}","tags_url":"https://api.github.com/repos/freebasic/fbc/tags","blobs_url":"https://api.github.com/repos/freebasic/fbc/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/freebasic/fbc/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/freebasic/fbc/git/refs{/sha}","trees_url":"https://api.github.com/repos/freebasic/fbc/git/trees{/sha}","statuses_url":"https://api.github.com/repos/freebasic/fbc/statuses/{sha}","languages_url":"https://api.github.com/repos/freebasic/fbc/languages","stargazers_url":"https://api.github.com/repos/freebasic/fbc/stargazers","contributors_url":"https://api.github.com/repos/freebasic/fbc/contributors","subscribers_url":"https://api.github.com/repos/freebasic/fbc/subscribers","subscription_url":"https://api.github.com/repos/freebasic/fbc/subscription","commits_url":"https://api.github.com/repos/freebasic/fbc/commits{/sha}","git_commits_url":"https://api.github.com/repos/freebasic/fbc/git/commits{/sha}","comments_url":"https://api.github.com/repos/freebasic/fbc/comments{/number}","issue_comment_url":"https://api.github.com/repos/freebasic/fbc/issues/comments{/number}","contents_url":"https://api.github.com/repos/freebasic/fbc/contents/{+path}","compare_url":"https://api.github.com/repos/freebasic/fbc/compare/{base}...{head}","merges_url":"https://api.github.com/repos/freebasic/fbc/merges","archive_url":"https://api.github.com/repos/freebasic/fbc/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/freebasic/fbc/downloads","issues_url":"https://api.github.com/repos/freebasic/fbc/issues{/number}","pulls_url":"https://api.github.com/repos/freebasic/fbc/pulls{/number}","milestones_url":"https://api.github.com/repos/freebasic/fbc/milestones{/number}","notifications_url":"https://api.github.com/repos/freebasic/fbc/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/freebasic/fbc/labels{/name}","releases_url":"https://api.github.com/repos/freebasic/fbc/releases{/id}","deployments_url":"https://api.github.com/repos/freebasic/fbc/deployments","created_at":"2011-09-26T08:20:19Z","updated_at":"2018-06-28T02:48:04Z","pushed_at":"2018-06-28T02:48:03Z","git_url":"git://github.com/freebasic/fbc.git","ssh_url":"git@github.com:freebasic/fbc.git","clone_url":"https://github.com/freebasic/fbc.git","svn_url":"https://github.com/freebasic/fbc","homepage":"http://www.freebasic.net","size":49557,"stargazers_count":212,"watchers_count":212,"language":"Visual Basic","has_issues":true,"has_projects":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":52,"mirror_url":null,"archived":false,"open_issues_count":4,"license":null,"forks":52,"open_issues":4,"watchers":212,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/freebasic/fbc/pulls/90"},"html":{"href":"https://github.com/freebasic/fbc/pull/90"},"issue":{"href":"https://api.github.com/repos/freebasic/fbc/issues/90"},"comments":{"href":"https://api.github.com/repos/freebasic/fbc/issues/90/comments"},"review_comments":{"href":"https://api.github.com/repos/freebasic/fbc/pulls/90/comments"},"review_comment":{"href":"https://api.github.com/repos/freebasic/fbc/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/freebasic/fbc/pulls/90/commits"},"statuses":{"href":"https://api.github.com/repos/freebasic/fbc/statuses/cb957b366582dc9ecd4f58b9d8f99608cb613871"}},"author_association":"COLLABORATOR"}}
{"actor":{"display_login":"dkl"}}