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

    <tr>
        <th>Summary</th>
        <td>
            [flang]  Extra level of indirection to access the EnvironmentDefaultList after https://github.com/llvm/llvm-project/pull/89938
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            bug,
            flang:ir
      </td>
    </tr>

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

    <tr>
      <th>Reporter</th>
      <td>
          Renaud-K
      </td>
    </tr>
</table>

<pre>
    We used to pass the environment as such:
```
extern const struct EnvironmentDefaultList *_QQEnvironmentDefaults;

/* C main stub */
int main(int argc, const char *argv[], const char *envp[]) {
 RTNAME(ProgramStart)(argc, argv, envp, _QQEnvironmentDefaults);
 _QQmain();
  RTNAME(ProgramEndStatement)();
  return 0;
}
```
whereby the global `_QQEnvironmentDefaults` was holding a pointer to an `EnvironmentDefaultList`

After the PR, when passed in LLVM, we are now passing the address of `_QQEnvironmentDefaults`
```
@_QQEnvironmentDefaults.items = linkonce constant [1 x { ptr, ptr }] [{ ptr, ptr } { ptr @_QQclX464F52545F434F4E5645525400, ptr @_QQclX5357415000 }], comdat
@_QQclX464F52545F434F4E5645525400 = linkonce constant [13 x i8] c"FORT_CONVERT\00", comdat
@_QQclX5357415000 = linkonce constant [5 x i8] c"SWAP\00", comdat
@_QQEnvironmentDefaults.list = linkonce constant { i32, ptr } { i32 1, ptr @_QQEnvironmentDefaults.items }, comdat
@_QQEnvironmentDefaults = constant ptr @_QQEnvironmentDefaults.list
...
define i32 @main(i32 %0, ptr %1, ptr %2) {
  call void @_FortranAProgramStart(i32 %0, ptr %1, ptr %2, ptr @_QQEnvironmentDefaults)
  call void @_QQmain()
  call void @_FortranAProgramEndStatement()
  ret i32 0
}
```

You can see the issue with an empty program
```
flang-new  main.f90 -fconvert=swap
./a,out
Segmentation fault
```
(You may have to try several times)




</pre>
<img width="1px" height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