[flang-commits] [flang] 6ada493 - [flang] Fix potential null scope when lowering dispatch table op
Valentin Clement via flang-commits
flang-commits at lists.llvm.org
Fri Feb 3 01:17:39 PST 2023
Author: Valentin Clement
Date: 2023-02-03T10:17:33+01:00
New Revision: 6ada493035efcd1e90e8e062595c478babe7cd18
URL: https://github.com/llvm/llvm-project/commit/6ada493035efcd1e90e8e062595c478babe7cd18
DIFF: https://github.com/llvm/llvm-project/commit/6ada493035efcd1e90e8e062595c478babe7cd18.diff
LOG: [flang] Fix potential null scope when lowering dispatch table op
Similary to D140209, the scope might need to be retrieved
from the typeSymbol. The test code was crashing because the
scope passed to CollectBindings was initially null.
Reviewed By: jeanPerier
Differential Revision: https://reviews.llvm.org/D143188
Added:
Modified:
flang/lib/Lower/Bridge.cpp
flang/test/Lower/dispatch.f90
Removed:
################################################################################
diff --git a/flang/lib/Lower/Bridge.cpp b/flang/lib/Lower/Bridge.cpp
index 9033ab8026c22..aa844e592dde1 100644
--- a/flang/lib/Lower/Bridge.cpp
+++ b/flang/lib/Lower/Bridge.cpp
@@ -204,9 +204,11 @@ class DispatchTableConverter {
info.loc, dtName,
parent ? Fortran::lower::mangle::mangleName(*parent) : "");
auto insertPt = builder.saveInsertionPoint();
-
+ const Fortran::semantics::Scope *scope = info.typeSpec->scope();
+ if (!scope)
+ scope = info.typeSpec->typeSymbol().scope();
Fortran::semantics::SymbolVector bindings =
- Fortran::semantics::CollectBindings(*info.typeSpec->scope());
+ Fortran::semantics::CollectBindings(*scope);
if (!bindings.empty())
builder.createBlock(&dt.getRegion());
diff --git a/flang/test/Lower/dispatch.f90 b/flang/test/Lower/dispatch.f90
index 4328ac70747c3..0331bfb08495d 100644
--- a/flang/test/Lower/dispatch.f90
+++ b/flang/test/Lower/dispatch.f90
@@ -39,6 +39,16 @@ subroutine nopass_defferred(x)
procedure(nopass_defferred), deferred, nopass :: nopassd
end type
+ type :: node
+ type(node_ptr), pointer :: n(:)
+ end type
+ type :: use_node
+ type(node) :: n
+ end type
+ type :: node_ptr
+ type(node_ptr), pointer :: n
+ end type
+
contains
! ------------------------------------------------------------------------------
@@ -341,4 +351,8 @@ subroutine check_nodispatch(t)
! CHECK: fir.call @_QMcall_dispatchPtbp_pass_arg0
! CHECK: fir.call @_QMcall_dispatchPtbp_pass_arg1
+ subroutine use_node_test(n)
+ type(use_node) :: n
+ end subroutine
+
end module
More information about the flang-commits
mailing list