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

Init_expr pass creates the array initialisation twice #1687

Closed
Tracked by #1600
Thirumalai-Shaktivel opened this issue Apr 9, 2023 · 1 comment · Fixed by lfortran/lfortran#1603
Closed
Tracked by #1600
Labels
bug Something isn't working

Comments

@Thirumalai-Shaktivel
Copy link
Collaborator

Example:

program arrays_05
implicit none
integer, dimension(5) :: numbers = [10]
end program

ASR:

(TranslationUnit
    (SymbolTable
        1
        {
            arrays_05:
                (Program
                    (SymbolTable
                        2
                        {
                            __1_k:
                                (Variable
                                    2
                                    __1_k
                                    []
                                    Local
                                    ()
                                    ()
                                    Default
                                    (Integer 4 [])
                                    Source
                                    Public
                                    Required
                                    .false.
                                ),
                            numbers:
                                (Variable
                                    2
                                    numbers
                                    []
                                    Local
                                    (ArrayConstant
                                        [(IntegerConstant 10 (Integer 4 []))]
                                        (Integer 4 [((IntegerConstant 1 (Integer 4 []))
                                        (IntegerConstant 1 (Integer 4 [])))])
                                        ColMajor
                                    )
                                    (ArrayConstant
                                        [(IntegerConstant 10 (Integer 4 []))]
                                        (Integer 4 [((IntegerConstant 1 (Integer 4 []))
                                        (IntegerConstant 1 (Integer 4 [])))])
                                        ColMajor
                                    )
                                    Save
                                    (Integer 4 [((IntegerConstant 1 (Integer 4 []))
                                    (IntegerConstant 5 (Integer 4 [])))])
                                    Source
                                    Public
                                    Required
                                    .false.
                                )
                        })
                    arrays_05
                    []
                    [(=
                        (Var 2 __1_k)
                        (ArrayBound
                            (Var 2 numbers)
                            (IntegerConstant 1 (Integer 4 []))
                            (Integer 4 [])
                            LBound
                            ()
                        )
                        ()
                    )
                    (=
                        (ArrayItem
                            (Var 2 numbers)
                            [(()
                            (Var 2 __1_k)
                            ())]
                            (Integer 4 [])
                            ColMajor
                            ()
                        )
                        (IntegerConstant 10 (Integer 4 []))
                        ()
                    )
                    (=
                        (Var 2 __1_k)
                        (IntegerBinOp
                            (Var 2 __1_k)
                            Add
                            (IntegerConstant 1 (Integer 4 []))
                            (Integer 4 [])
                            ()
                        )
                        ()
                    )
                    (=
                        (Var 2 __1_k)
                        (ArrayBound
                            (Var 2 numbers)
                            (IntegerConstant 1 (Integer 4 []))
                            (Integer 4 [])
                            LBound
                            ()
                        )
                        ()
                    )
                    (=
                        (ArrayItem
                            (Var 2 numbers)
                            [(()
                            (Var 2 __1_k)
                            ())]
                            (Integer 4 [])
                            ColMajor
                            ()
                        )
                        (IntegerConstant 10 (Integer 4 []))
                        ()
                    )
                    (=
                        (Var 2 __1_k)
                        (IntegerBinOp
                            (Var 2 __1_k)
                            Add
                            (IntegerConstant 1 (Integer 4 []))
                            (Integer 4 [])
                            ()
                        )
                        ()
                    )]
                )
        })
    []
)

Here, the array is initialized twice using the init_expr pass
I think the initialization is caused because the pass visits both the m_symbolic_value and m_value of the Variable node and creates init two times.

@certik
Copy link
Contributor

certik commented Apr 11, 2023

We need to fix it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants