-
Notifications
You must be signed in to change notification settings - Fork 14.7k
release/21.x: [Flang] Fix crash when a derived type with private attribute is specified in extends (#151051) #152687
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
Open
llvmbot
wants to merge
1
commit into
llvm:release/21.x
Choose a base branch
from
llvmbot:issue151051
base: release/21.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…fied in extends (llvm#151051) While lowering to HLFIR, when a parent type is private, its name is mangled, so we need to get it from the parent symbol. Fixes llvm#120922 (cherry picked from commit 9bb31e8)
@tblah What do you think about merging this PR to the release branch? |
@llvm/pr-subscribers-flang-fir-hlfir Author: None (llvmbot) ChangesBackport 9bb31e8 Requested by: @tblah Full diff: https://github.com/llvm/llvm-project/pull/152687.diff 4 Files Affected:
diff --git a/flang/include/flang/Lower/ConvertType.h b/flang/include/flang/Lower/ConvertType.h
index 179a682584046..3c726595c0f76 100644
--- a/flang/include/flang/Lower/ConvertType.h
+++ b/flang/include/flang/Lower/ConvertType.h
@@ -118,6 +118,9 @@ class ComponentReverseIterator {
/// Advance iterator to the last components of the current type parent.
const Fortran::semantics::DerivedTypeSpec &advanceToParentType();
+ /// Get the parent component symbol for the current type.
+ const Fortran::semantics::Symbol *getParentComponent() const;
+
private:
void setCurrentType(const Fortran::semantics::DerivedTypeSpec &derived);
const Fortran::semantics::DerivedTypeSpec *currentParentType = nullptr;
diff --git a/flang/lib/Lower/ConvertExprToHLFIR.cpp b/flang/lib/Lower/ConvertExprToHLFIR.cpp
index 9689f920840fb..906a689821882 100644
--- a/flang/lib/Lower/ConvertExprToHLFIR.cpp
+++ b/flang/lib/Lower/ConvertExprToHLFIR.cpp
@@ -1848,8 +1848,15 @@ class HlfirBuilder {
for (Fortran::lower::ComponentReverseIterator compIterator(
ctor.result().derivedTypeSpec());
!compIterator.lookup(compSym.name());) {
- const auto &parentType = compIterator.advanceToParentType();
- llvm::StringRef parentName = toStringRef(parentType.name());
+ // Private parent components have mangled names. Get the name from the
+ // parent symbol.
+ const Fortran::semantics::Symbol *parentCompSym =
+ compIterator.getParentComponent();
+ assert(parentCompSym && "failed to get parent component symbol");
+ std::string parentName =
+ converter.getRecordTypeFieldName(*parentCompSym);
+ // Advance the iterator, but don't use its return value.
+ compIterator.advanceToParentType();
auto baseRecTy = mlir::cast<fir::RecordType>(
hlfir::getFortranElementType(currentParent.getType()));
auto parentCompType = baseRecTy.getType(parentName);
diff --git a/flang/lib/Lower/ConvertType.cpp b/flang/lib/Lower/ConvertType.cpp
index 7a2e8e5095186..0fde61465fb85 100644
--- a/flang/lib/Lower/ConvertType.cpp
+++ b/flang/lib/Lower/ConvertType.cpp
@@ -669,6 +669,18 @@ Fortran::lower::ComponentReverseIterator::advanceToParentType() {
return *currentParentType;
}
+const Fortran::semantics::Symbol *
+Fortran::lower::ComponentReverseIterator::getParentComponent() const {
+ if (!currentTypeDetails->GetParentComponentName())
+ return nullptr;
+ const Fortran::semantics::Scope *scope = currentParentType->GetScope();
+ auto parentComp =
+ DEREF(scope).find(currentTypeDetails->GetParentComponentName().value());
+ if (parentComp == scope->cend())
+ return nullptr;
+ return &*parentComp->second;
+}
+
void Fortran::lower::ComponentReverseIterator::setCurrentType(
const Fortran::semantics::DerivedTypeSpec &derived) {
currentParentType = &derived;
diff --git a/flang/test/Lower/derived-type-private.f90 b/flang/test/Lower/derived-type-private.f90
new file mode 100644
index 0000000000000..8edcdeedad8b2
--- /dev/null
+++ b/flang/test/Lower/derived-type-private.f90
@@ -0,0 +1,29 @@
+! Test lowering of derived type with private attribute
+! RUN: bbc -emit-hlfir %s -o - | FileCheck %s
+
+program main
+ call test02()
+ print *,"pass"
+end program main
+
+module mod2
+ type,private:: tt
+ integer :: ip = 1
+ end type tt
+ type,extends(tt):: ty1
+ ! CHECK: fir.global @_QMmod2Estr : !fir.type<_QMmod2Tty1{_QMmod2Tty1.tt:!fir.type<_QMmod2Ttt{ip:i32}>,i1:i32,i1p:!fir.type<_QMmod2Ttt{ip:i32}>,i1a:!fir.box<!fir.heap<!fir.array<?xi32>>>}>
+ integer :: i1 = 1
+ type(tt) :: i1p = tt(2)
+ integer,allocatable :: i1a(:)
+ end type ty1
+ type(ty1) :: str
+end module mod2
+
+subroutine test02()
+ use mod2
+ integer,allocatable :: ia(:)
+ allocate(ia(10))
+ ia=2
+ str=ty1(i1a=ia)
+ if (str%i1.ne.1) print *,'ng'
+end subroutine test02
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Backport 9bb31e8
Requested by: @tblah