[flang-commits] [flang] 4ed9092 - [Flang][Lower] Handle mangling of a generic name with a homonym specific procedure (#106693)

via flang-commits flang-commits at lists.llvm.org
Mon Sep 2 04:48:43 PDT 2024


Author: Roger Ferrer Ibáñez
Date: 2024-09-02T13:48:39+02:00
New Revision: 4ed90920a84272a4e1737db9bdd50d57cade3cf4

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

LOG: [Flang][Lower] Handle mangling of a generic name with a homonym specific procedure (#106693)

This may happen when using modules.

Fixes #93707

Added: 
    flang/test/Lower/module-generic-with-specific-mangling.f90

Modified: 
    flang/lib/Lower/Mangler.cpp

Removed: 
    


################################################################################
diff  --git a/flang/lib/Lower/Mangler.cpp b/flang/lib/Lower/Mangler.cpp
index 878ba6dea49b6e..a66dae8851a866 100644
--- a/flang/lib/Lower/Mangler.cpp
+++ b/flang/lib/Lower/Mangler.cpp
@@ -165,6 +165,16 @@ std::string Fortran::lower::mangle::mangleName(
             return mangleName(procBinding.symbol(), scopeBlockIdMap,
                               keepExternalInScope, underscoring);
           },
+          [&](const Fortran::semantics::GenericDetails &generic)
+              -> std::string {
+            if (generic.specific())
+              return mangleName(*generic.specific(), scopeBlockIdMap,
+                                keepExternalInScope, underscoring);
+            else
+              llvm::report_fatal_error(
+                  "attempt to mangle a generic name but "
+                  "it has no specific procedure of the same name");
+          },
           [&](const Fortran::semantics::DerivedTypeDetails &) -> std::string {
             // Derived type mangling must use mangleName(DerivedTypeSpec) so
             // that kind type parameter values can be mangled.

diff  --git a/flang/test/Lower/module-generic-with-specific-mangling.f90 b/flang/test/Lower/module-generic-with-specific-mangling.f90
new file mode 100644
index 00000000000000..18a0211b5524c6
--- /dev/null
+++ b/flang/test/Lower/module-generic-with-specific-mangling.f90
@@ -0,0 +1,60 @@
+! RUN: split-file %s %t
+! RUN: bbc -emit-fir %t/mangling_mod_a.f90 -o - | FileCheck %s --check-prefix=FIR
+! RUN: bbc -emit-fir %t/mangling_mod_b.f90 -o - | FileCheck %s --check-prefix=MANGLE
+! RUN: bbc -emit-fir %t/mangling_mod_c.f90 -o - | FileCheck %s --check-prefix=MANGLE
+! RUN: bbc -emit-fir %t/mangling_mod_d.f90 -o - | FileCheck %s --check-prefix=MANGLE
+
+! FIR: module
+! MANGLE: func.func private @_QPmy_sub(!fir.ref<i32>)
+
+!--- mangling_mod_a.f90
+module mangling_mod_a
+  interface
+    subroutine my_sub(a)
+      integer :: a
+    end subroutine my_sub
+  end interface
+
+  ! Generic interface
+  interface my_sub
+      procedure :: my_sub
+  end interface
+  contains
+end module mangling_mod_a
+
+!--- mangling_mod_b.f90
+module mangling_mod_b
+  use mangling_mod_a
+
+  contains
+    subroutine my_sub2(a)
+      integer :: a
+      call my_sub(a)
+    end subroutine my_sub2
+
+end module mangling_mod_b
+
+!--- mangling_mod_c.f90
+module mangling_mod_c
+  use mangling_mod_b
+
+  contains
+    subroutine my_sub3(a)
+      integer :: a
+
+      call my_sub(a)
+    end subroutine my_sub3
+end module mangling_mod_c
+
+!--- mangling_mod_d.f90
+module mangling_mod_d
+  use mangling_mod_b
+  use mangling_mod_c
+
+  contains
+    subroutine my_sub4(a)
+      integer :: a
+
+      call my_sub(a)
+    end subroutine my_sub4
+end module mangling_mod_d


        


More information about the flang-commits mailing list