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 double initialisation of variables in ASR #1629

Merged
merged 2 commits into from
Mar 27, 2023

Conversation

czgdp1807
Copy link
Collaborator

Closes #1626


if( init_expr && current_body) {
if( init_expr && current_body &&
(is_runtime_expression || !is_variable_const)) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only those variables will be initialised by converting to assignments which are non-constant or have a runtime expressions. Also an error is thrown if a constant variable is not initialised at declaration (see lines 2215 to 2219).

@czgdp1807 czgdp1807 marked this pull request as ready for review March 26, 2023 14:44
@@ -516,6 +516,15 @@ class VerifyVisitor : public BaseWalkVisitor<VerifyVisitor>
"Variable::m_parent_symtab must be present in the ASR ("
+ std::string(x.m_name) + ")");

if( symtab->parent == nullptr ) {
// For nowRestrict this check only to variables which are present
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// For nowRestrict this check only to variables which are present
// For now restrict this check only to variables which are present

Copy link
Contributor

@certik certik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that this is good, thanks for fixing it and adding a test!

I suggest we merge it, and if there are more issues, we'll tackle it as we discover it.

@czgdp1807
Copy link
Collaborator Author

Okay. Let me check if verify changes work with LFortran. Then I will merge both the PRs.

1. Only those variables which are constant and have a compile time initialisation expression will have non-nullptr values for m_symbolic_value and m_value
2. Rest all will be converted to assignment statements.
@czgdp1807 czgdp1807 merged commit 6ebd4b8 into lcompilers:main Mar 27, 2023
@czgdp1807 czgdp1807 deleted the var_init branch March 27, 2023 14:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

C backend: variable is initialized twice
2 participants