<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/62432>62432</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [Flang] Default initialize module variables to zero [527.cam4_r failure]
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          kiranchandramohan
      </td>
    </tr>
</table>

<pre>
    The cam4 spec2017 benchmark is failing since module variables are initialized as `undef`. This can cause not well-defined behaviour to happen if the module variable is used in an `if` statement. Use the `zeroinitializer` to fix the issue.

A simple reproducer is :
```
module simple
logical :: async_interf
contains
 subroutine one
    print *, "one = ", async_interf
    if (async_interf) then
      print *, "Inside async"
    end if
  end subroutine
end module
program mn
use simple
call one()
end program
```
The code above will print the following result with flang when compiled with LTO and O2.
```
one = F
Inside async 
```
The LLVM IR generated marks the module variable async_interf as undefined.
```
 @_QMsimpleEasync_interf = local_unnamed_addr global i32 undef
```
The variable being marked as undef makes the if comparison pointless and optimisation either remove the if check or hoists the code outside the if.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJx0VE1v2zgQ_TX0ZRBBoizFOuiQrtdAgRTFLrJ7NUbkSJoNRQokFW_76wtKbpwiKWDYJjnz5s2bDwyBB0vUiuqTqI47XOLofPvMHq0a0WqPkxvR7jqnv7VPI4HCaQ9hJiXz4h46smqc0D8DB-iRDdsBAltFMDm9GIIX9IydoQDoCdhyZDT8nTRgAFHni9XUizrP4GnkAAotKFwCgXURLmTMnaaeLWnoaMQXdouH6GDEeSYL3EMc38VKZJZAGtgC2hSFUwgIESNNZGMG_wRaPUWdfyfvbrx8MowOev5_NeAQFspEfhT5w_b9AIGn2RB4mr3TiyKfAory-i7q_PpZj1dum892ZdzACs3qUj4Ahm9WndlG8v1moJyNyDZsJwhL590S2RI4e8UAAJg92whCPgj5Bwg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