[flang-commits] [flang] a61835b - [flang] Fix use-associated false-positive error

Daniil Dudkin via flang-commits flang-commits at lists.llvm.org
Fri May 20 02:14:25 PDT 2022


Author: Daniil Dudkin
Date: 2022-05-20T12:14:02+03:00
New Revision: a61835b1e3f5e074f4c8174edadfc6bef975138f

URL: https://github.com/llvm/llvm-project/commit/a61835b1e3f5e074f4c8174edadfc6bef975138f
DIFF: https://github.com/llvm/llvm-project/commit/a61835b1e3f5e074f4c8174edadfc6bef975138f.diff

LOG: [flang] Fix use-associated false-positive error

For the program provided as the test case flang fired the following
error:

    error: Semantic errors in main.f90
    error: 'foo' is not a procedure

This change fixes the error by postponing handling of `UseErrorDetails`
from `CharacterizeProcedure` to a later stage.

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D125791

Added: 
    flang/test/Semantics/resolve112.f90

Modified: 
    flang/lib/Evaluate/characteristics.cpp

Removed: 
    


################################################################################
diff  --git a/flang/lib/Evaluate/characteristics.cpp b/flang/lib/Evaluate/characteristics.cpp
index 95bc5f1327034..2cfdb9d282426 100644
--- a/flang/lib/Evaluate/characteristics.cpp
+++ b/flang/lib/Evaluate/characteristics.cpp
@@ -485,6 +485,11 @@ static std::optional<Procedure> CharacterizeProcedure(
           [&](const semantics::UseDetails &use) {
             return CharacterizeProcedure(use.symbol(), context, seenProcs);
           },
+          [](const semantics::UseErrorDetails &) {
+            // Ambiguous use-association will be handled later during symbol
+            // checks, ignore UseErrorDetails here without actual symbol usage.
+            return std::optional<Procedure>{};
+          },
           [&](const semantics::HostAssocDetails &assoc) {
             return CharacterizeProcedure(assoc.symbol(), context, seenProcs);
           },

diff  --git a/flang/test/Semantics/resolve112.f90 b/flang/test/Semantics/resolve112.f90
new file mode 100644
index 0000000000000..6c45854079ff6
--- /dev/null
+++ b/flang/test/Semantics/resolve112.f90
@@ -0,0 +1,32 @@
+! RUN: %python %S/test_errors.py %s %flang_fc1
+
+! If there are 2 or more use-associated symbols
+! from 
diff erent modules with the same name,
+! the error should be generated only if
+! the name is actually used.
+module a
+  contains
+    function foo()
+      foo = 42
+    end function foo
+end module a
+
+module b
+  contains
+    function foo()
+      foo = 42
+    end function foo
+end module b
+
+subroutine without_error
+  use a
+  use b
+end subroutine without_error
+
+subroutine with_error
+  use a
+  use b
+  integer :: res
+  ! ERROR: Reference to 'foo' is ambiguous
+  res = foo()
+end subroutine with_error


        


More information about the flang-commits mailing list