[flang-commits] [flang] [Flang][OpenMP]: Fix to bind(C) procs inside BLOCK construct (PR #82483)

via flang-commits flang-commits at lists.llvm.org
Wed Feb 21 03:21:58 PST 2024


https://github.com/harishch4 created https://github.com/llvm/llvm-project/pull/82483

Name mangling is invoked for a bind(C) procedure contained in a block in a context that does not have access to block ID mapping. Relaxing an assert to account for this.

Fixes #79408 

>From d9879a14a73fbae3a0b76965979e46673418c8c3 Mon Sep 17 00:00:00 2001
From: Harish Chambeti <harishcse44 at gmail.com>
Date: Wed, 21 Feb 2024 16:44:16 +0530
Subject: [PATCH] [Flang][OpenMP]: Fix to bind(C) procs inside BLOCK construct

---
 flang/lib/Lower/Mangler.cpp                 |  3 ++-
 flang/test/Lower/HLFIR/block_bindc_pocs.f90 | 20 ++++++++++++++++++++
 2 files changed, 22 insertions(+), 1 deletion(-)
 create mode 100644 flang/test/Lower/HLFIR/block_bindc_pocs.f90

diff --git a/flang/lib/Lower/Mangler.cpp b/flang/lib/Lower/Mangler.cpp
index 24abbce01c059e..9a33be318a27d8 100644
--- a/flang/lib/Lower/Mangler.cpp
+++ b/flang/lib/Lower/Mangler.cpp
@@ -182,7 +182,8 @@ Fortran::lower::mangle::mangleName(const Fortran::semantics::Symbol &symbol,
                                    bool underscoring) {
   assert((symbol.owner().kind() !=
               Fortran::semantics::Scope::Kind::BlockConstruct ||
-          symbol.has<Fortran::semantics::SubprogramDetails>()) &&
+          symbol.has<Fortran::semantics::SubprogramDetails>() ||
+          Fortran::semantics::IsBindCProcedure(symbol)) &&
          "block object mangling must specify a scopeBlockIdMap");
   ScopeBlockIdMap scopeBlockIdMap;
   return mangleName(symbol, scopeBlockIdMap, keepExternalInScope, underscoring);
diff --git a/flang/test/Lower/HLFIR/block_bindc_pocs.f90 b/flang/test/Lower/HLFIR/block_bindc_pocs.f90
new file mode 100644
index 00000000000000..cfec45cfcd8545
--- /dev/null
+++ b/flang/test/Lower/HLFIR/block_bindc_pocs.f90
@@ -0,0 +1,20 @@
+! This test checks bind(c) procs inside BLOCK construct.
+
+!RUN: %flang_fc1 -emit-hlfir %s -o - | FileCheck %s
+
+module m
+    interface
+       subroutine test_proc() bind(C)
+       end subroutine test_proc
+    end interface
+end module m
+!CHECK-DAG: %[[S0:.*]] = fir.call @llvm.stacksave.p0() fastmath<contract> : () -> !fir.ref<i8>
+!CHECK-DAG: fir.call @test_proc() fastmath<contract> : () -> ()
+!CHECK-DAG: fir.call @llvm.stackrestore.p0(%[[S0]]) fastmath<contract> : (!fir.ref<i8>) -> ()
+!CHECK-DAG: func.func private @test_proc() attributes {fir.bindc_name = "test_proc"}
+subroutine test
+    BLOCK
+        use m
+        call test_proc
+    END BLOCK
+end subroutine test



More information about the flang-commits mailing list