[flang][OpenMP] Implicit declarations of procedures in DECLARE_TARGET (#201935)

This replaces commit 8f5df8891840b, since it was rejecting the following
case:
```
  function baz(a)
    !$omp declare target to(baz)
    real, intent(in) :: a
    baz = a
  end

  program main
    !$omp declare target(baz)
    integer, save :: baz        ! error: 'baz' is already declared
  end
```
Instead of flagging an error, the 'baz' in the directive should be
resolved to the explicitly declared variable.

The original motivating example was to allow the case where the main
program (from the above snippet) looked like the following:
```
  program main
    real :: a
    !$omp declare target(baz)   ! 'baz' should be resolved to the
    !$omp target                ! external function
      a = baz(a)                ! <- because of this call
    !$omp end target
  end
```

The problem is that "declare_target(baz)" despite being the same in both
cases, should lead to two different outcomes in symbol resolution.

This fix will treat declarations introduced by a DECLARE_TARGET as
eligible for overriding with a potentially conflicting declaration
stemming from the use of that name in a language construct or
expression. Since a mere mention of a name alone declares an object,
such conflict occurs when the name would have been otherwise resolved to
a procedure.
This changes the behavior introduced in 8f5df8891840b, where
yet-undeclared names on a DECLARE_TARGET were preferentially resolved to
external procedures.

The function HandleProcedureName was modified to "undeclare" names
implicitly declared due to their appearance in a DECLARE_TARGET.

GitOrigin-RevId: 4b5f74b154228f5d129ccd7dcb1e09e7193643ae
4 files changed
tree: c6fb68fab9e671b48b456dbe003c9e2502357dbf
  1. cmake/
  2. docs/
  3. examples/
  4. include/
  5. lib/
  6. test/
  7. tools/
  8. unittests/
  9. .clang-format
  10. .clang-tidy
  11. .drone.star
  12. .gitignore
  13. CMakeLists.txt
  14. LICENSE.TXT
  15. Maintainers.md
  16. README.md
README.md

Flang

Flang is a ground-up implementation of a Fortran front end written in modern C++. It started off as the f18 project (https://github.com/flang-compiler/f18) with an aim to replace the previous flang project (https://github.com/flang-compiler/flang) and address its various deficiencies. F18 was subsequently accepted into the LLVM project and rechristened as Flang.

Please note that flang is not ready yet for production usage.

Getting Started

Read more about flang in the docs directory. Start with the compiler overview.

To better understand Fortran as a language and the specific grammar accepted by flang, read Fortran For C Programmers and flang's specifications of the Fortran grammar and the OpenMP grammar.

Treatment of language extensions is covered in this document.

To understand the compilers handling of intrinsics, see the discussion of intrinsics.

To understand how a flang program communicates with libraries at runtime, see the discussion of runtime descriptors.

If you're interested in contributing to the compiler, read the style guide and also review how flang uses modern C++ features.

If you are interested in writing new documentation, follow LLVM's Markdown style guide.

Consult the Getting Started with Flang for information on building and running flang.