Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix incorrect "uninitialized reference" problem #23

Open
mycoboco opened this issue Dec 14, 2015 · 4 comments
Open

fix incorrect "uninitialized reference" problem #23

mycoboco opened this issue Dec 14, 2015 · 4 comments

Comments

@mycoboco
Copy link
Owner

No description provided.

@mycoboco mycoboco self-assigned this Dec 14, 2015
@mycoboco mycoboco added the bug label Dec 14, 2015
@mycoboco
Copy link
Owner Author

This issue is because the order in which an expression appers in code differs from that in which it is evaluated. For example, given this:

for (p = q; p < q+n; p = r)
    r = next();

when beluga encounters the third expression, it mistakenly issues a warning that r is referenced uninitialized.

Probably I have to give this kind of detection up until a more formal form of control flow analysis is introduced.

@ghost
Copy link

ghost commented Dec 19, 2015

I'll have to look at the source code, but isn't it possible to just put the third expression on a stack that would then be popped once the scope ends? You basically need a pointer on whatever scope abstraction there is and delay the detection to there.

@mycoboco
Copy link
Owner Author

Thanks for your comment.

Sounds like a nice approach. The parse tree from for's last expression can be remembered and used to check for uninitialized access after parsing the loop body, as you said. However, without tracking of control flow, it is not easy, for example, to say that i is referenced after being initialized in this contrived example:

int j, i;

goto label1;
label3:
j = i;
goto label2;
label1:
i = 0;
goto label3;
label2:
;

The diagnostic for "uninitialized reference" was mistakenly included when I designed code to issue similar warnings, "defined but not used" and "set but not used". Rather introducing a workaround for a specific case, preparing a method to traverse parse trees following control flow would allow other useful diagnostics not to mention fixing the problem.

@mycoboco
Copy link
Owner Author

Temporarily removed the check for uninitialized references.

@mycoboco mycoboco removed their assignment Mar 15, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant