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

Comments

Projects
None yet
2 participants
@mycoboco
Owner

mycoboco commented Dec 14, 2015

No description provided.

@mycoboco mycoboco added the compiler label Dec 14, 2015

@mycoboco mycoboco self-assigned this Dec 14, 2015

@mycoboco mycoboco added the bug label Dec 14, 2015

@mycoboco

This comment has been minimized.

Show comment
Hide comment
@mycoboco

mycoboco Dec 14, 2015

Owner

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.

Owner

mycoboco commented Dec 14, 2015

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.

@mar77i

This comment has been minimized.

Show comment
Hide comment
@mar77i

mar77i 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.

mar77i 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

This comment has been minimized.

Show comment
Hide comment
@mycoboco

mycoboco Dec 21, 2015

Owner

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.

Owner

mycoboco commented Dec 21, 2015

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

This comment has been minimized.

Show comment
Hide comment
@mycoboco

mycoboco Dec 25, 2015

Owner

Temporarily removed the check for uninitialized references.

Owner

mycoboco commented Dec 25, 2015

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