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

    <tr>
        <th>Summary</th>
        <td>
            [flang][OpenMP]Flang crashes with implicit none and undeclared variables
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            flang
      </td>
    </tr>

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

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

<pre>
    

```
program omp_examples
  implicit none
  integer, parameter :: n = 100
  real :: values(n)
  integer :: i
!  real :: sum
  
  call random_number(values)

  sum = 0
  !$omp parallel do reduction(+:sum)
 do i = 1, n
     sum = sum + values(i)
  end do

  
  print *, values
 print *, "sum=", sum
end program omp_examples
```

Uncomment the declaration for `sum` and it compiles fine.

To reproduce, save the sample above and compile with `flang -fc1 -fopenmp sample.f90`

The crash appears in the following code, where `GetLastName(*desg).symbol` is NULL. 

```
const Symbol *OmpStructureChecker::GetObjectSymbol(
    const parser::OmpObject &object) {
  if (auto *name{std::get_if<parser::Name>(&object.u)}) {
    return &name->symbol->GetUltimate();
  } else if (auto *desg{std::get_if<parser::Designator>(&object.u)}) {
    return &GetLastName(*desg).symbol->GetUltimate();
  }
  return nullptr;
}
```

I'm recording this now, as I found it broken the other day. I may well fix this in the next day or two, but I'd rather report a bug and fix it quickly, than find that someone else found the same bug, and it wasn't fixed for ages... :)
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyUlc1u4zgMx59GuRA1bDmx40MOyWQyGKA7XWCm50K2aFtbfXj1kbRvv5CUoO0sFsUCge3Y5I9_UhTFnBOTRtyRzYFsjisW_Gzs7h4XY9nAtJ_FENyqN_x1R8p9_DXl9VfuF2smyxQYtTzhC1OLREfKPYBQixSD8KCNxvxGe5zQEvoFFmaZQo8WSL0n9R40kPoIVVkmS4tM3r6cmQzoCN1qQrv3nJuBiIpo9dHLBZVs02Vg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