[flang-commits] [flang] [flang] Allow OpenMP declarations before type declarations (PR #112414)

Leandro Lupori via flang-commits flang-commits at lists.llvm.org
Wed Oct 16 07:56:47 PDT 2024


================
@@ -758,6 +759,10 @@ class ScopeHandler : public ImplicitRulesVisitor {
     }
   }
 
+  void SkipImplicitTyping(bool skip) {
+    deferImplicitTyping_ = skipImplicitTyping_ = skip;
----------------
luporl wrote:

When `deferImplicitTyping_` is set, checks for explicit types in contexts that require it (e.g. `implicit none`) are performed later. Not setting it would result in errors, as in the following example:
```
implicit none
save :: x1
!$omp threadprivate(x1)
integer :: x1
```
`error: No explicit type declared for 'x1'`

This happens because there is a data reference to `x1`, in `!$omp threadprivate(x1)`, which in other cases would require its explicit type to have already been specified.

The `skipImplicitTyping_` flag handles another case. The idea is that it skips setting implicit types. Even when `deferImplicitTyping_` is set, the implicit type of an entity is set when it is referenced, as in the example above. The problem is that, if the type that is declared after the reference doesn't match the previous implicit type, an error is reported.
In the example above, with `skipImplicitTyping_ = false`, `x1` type is set to `real` in the `threadprivate` line, which doesn't match the `integer` type specified later.

https://github.com/llvm/llvm-project/pull/112414


More information about the flang-commits mailing list