Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Flang]: Fix to bind(C) procs inside BLOCK construct #82483

Merged
merged 1 commit into from
Feb 21, 2024

Conversation

harishch4
Copy link
Contributor

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

@llvmbot llvmbot added the flang Flang issues not falling into any other category label Feb 21, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Feb 21, 2024

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

Author: None (harishch4)

Changes

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

Copy link
Contributor

@NimishMishra NimishMishra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LG.

@kiranchandramohan
Copy link
Contributor

Since this is not an OpenMP issue, please remove the [OpenMP] tag. Looks OK to me. Please wait for @vdonaldson

@harishch4 harishch4 changed the title [Flang][OpenMP]: Fix to bind(C) procs inside BLOCK construct [Flang]: Fix to bind(C) procs inside BLOCK construct Feb 21, 2024
Copy link
Contributor

@vdonaldson vdonaldson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks ok to me; thanks for the fix

@harishch4 harishch4 merged commit 61bc5f6 into llvm:main Feb 21, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang:fir-hlfir flang Flang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Flang] BLOCK construct throws assertion error during lowering.
5 participants