Skip to content

Commit 61bc5f6

Browse files
authored
[Flang]: Fix to bind(C) procs inside BLOCK construct (#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
1 parent 1a71668 commit 61bc5f6

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

flang/lib/Lower/Mangler.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,8 @@ Fortran::lower::mangle::mangleName(const Fortran::semantics::Symbol &symbol,
182182
bool underscoring) {
183183
assert((symbol.owner().kind() !=
184184
Fortran::semantics::Scope::Kind::BlockConstruct ||
185-
symbol.has<Fortran::semantics::SubprogramDetails>()) &&
185+
symbol.has<Fortran::semantics::SubprogramDetails>() ||
186+
Fortran::semantics::IsBindCProcedure(symbol)) &&
186187
"block object mangling must specify a scopeBlockIdMap");
187188
ScopeBlockIdMap scopeBlockIdMap;
188189
return mangleName(symbol, scopeBlockIdMap, keepExternalInScope, underscoring);
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
! This test checks bind(c) procs inside BLOCK construct.
2+
3+
!RUN: %flang_fc1 -emit-hlfir %s -o - | FileCheck %s
4+
5+
module m
6+
interface
7+
subroutine test_proc() bind(C)
8+
end subroutine test_proc
9+
end interface
10+
end module m
11+
!CHECK-DAG: %[[S0:.*]] = fir.call @llvm.stacksave.p0() fastmath<contract> : () -> !fir.ref<i8>
12+
!CHECK-DAG: fir.call @test_proc() fastmath<contract> : () -> ()
13+
!CHECK-DAG: fir.call @llvm.stackrestore.p0(%[[S0]]) fastmath<contract> : (!fir.ref<i8>) -> ()
14+
!CHECK-DAG: func.func private @test_proc() attributes {fir.bindc_name = "test_proc"}
15+
subroutine test
16+
BLOCK
17+
use m
18+
call test_proc
19+
END BLOCK
20+
end subroutine test

0 commit comments

Comments
 (0)