[PATCH] D83491: [flang] Fix a crash when creating generics from a copy

Pete Steinfeld via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 9 09:40:55 PDT 2020


PeteSteinfeld created this revision.
PeteSteinfeld added reviewers: klausler, tskeith.
Herald added a reviewer: DavidTruby.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

When a program unit creates a generic based on one defined in a module, the
function `CopyFrom()` is called to create the `GenericDetails`.  This function
copied the `specificProcs_` but failed to copy the `bindingNames_`.  If the
function `CheckGeneric()` then gets called, it tries to index into the empty
binding names and causes the crash.

I fixed this by adding code to `CopyFrom()` to copy the binding names.

I also added a test that causes the crash.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D83491

Files:
  flang/lib/Semantics/symbol.cpp
  flang/test/Semantics/resolve53.f90


Index: flang/test/Semantics/resolve53.f90
===================================================================
--- flang/test/Semantics/resolve53.f90
+++ flang/test/Semantics/resolve53.f90
@@ -457,3 +457,26 @@
     integer :: i, j
   end
 end
+
+module m20
+  interface operator(.not.)
+    real function f(x)
+      character(*),intent(in) :: x
+    end function
+  end interface
+  interface operator(+)
+    procedure f
+  end interface
+end module
+
+subroutine s1()
+  use m20
+  interface operator(.not.)
+    !ERROR: Procedure 'f' is already specified in generic 'operator(.not.)'
+    procedure f
+  end interface
+  interface operator(+)
+    !ERROR: Procedure 'f' is already specified in generic 'operator(+)'
+    procedure f
+  end interface
+end subroutine s1
Index: flang/lib/Semantics/symbol.cpp
===================================================================
--- flang/lib/Semantics/symbol.cpp
+++ flang/lib/Semantics/symbol.cpp
@@ -201,6 +201,14 @@
       specificProcs_.push_back(symbol);
     }
   }
+  for (const SourceName &sourceName : from.bindingNames_) {
+    if (std::find_if(bindingNames_.begin(), bindingNames_.end(),
+            [&](const SourceName &mySource) {
+              return &mySource == &sourceName;
+            }) == bindingNames_.end()) {
+      bindingNames_.push_back(sourceName);
+    }
+  }
 }
 
 // The name of the kind of details for this symbol.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D83491.276763.patch
Type: text/x-patch
Size: 1400 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200709/90710772/attachment.bin>


More information about the llvm-commits mailing list