[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:22:16 PST 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-flang-fir-hlfir

Author: None (harishch4)

<details>
<summary>Changes</summary>

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 

---
Full diff: https://github.com/llvm/llvm-project/pull/82483.diff


2 Files Affected:

- (modified) flang/lib/Lower/Mangler.cpp (+2-1) 
- (added) flang/test/Lower/HLFIR/block_bindc_pocs.f90 (+20) 


``````````diff
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

``````````

</details>


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


More information about the flang-commits mailing list