Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 6211696

Browse filesBrowse files
committed
[flang] Retrieve shape from selector when generating assoc sym type
This PR extends `genSymbolType` so that the type of an associating symbol carries the shape of the selector expression, if any. This is a fix for a bug that triggered when an associating symbol is used in a locality specifier. For example, given the following input: ```fortran associate(a => aa(4:)) do concurrent (i = 4:11) local(a) a(i) = 0 end do end associate ``` before the changes in the PR, flang would assert that we are casting between incompatible types. The issue happened since for the associating symbol (`a`), flang generated its type as `f32` rather than `!fir.array<8xf32>` as it should be in this case.
1 parent 249d949 commit 6211696
Copy full SHA for 6211696

File tree

Expand file treeCollapse file tree

2 files changed

+39
-0
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+39
-0
lines changed

‎flang/lib/Lower/ConvertType.cpp

Copy file name to clipboardExpand all lines: flang/lib/Lower/ConvertType.cpp
+17Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,23 @@ struct TypeBuilderImpl {
279279
bool isPolymorphic = (Fortran::semantics::IsPolymorphic(symbol) ||
280280
Fortran::semantics::IsUnlimitedPolymorphic(symbol)) &&
281281
!Fortran::semantics::IsAssumedType(symbol);
282+
if (const auto *assocDetails =
283+
ultimate.detailsIf<Fortran::semantics::AssocEntityDetails>()) {
284+
const auto &selector = assocDetails->expr();
285+
286+
if (selector && selector->Rank() > 0) {
287+
auto shapeExpr = Fortran::evaluate::GetShape(
288+
converter.getFoldingContext(), selector);
289+
290+
fir::SequenceType::Shape shape;
291+
// If there is no shapExpr, this is an assumed-rank, and the empty shape
292+
// will build the desired fir.array<*:T> type.
293+
if (shapeExpr)
294+
translateShape(shape, std::move(*shapeExpr));
295+
ty = fir::SequenceType::get(shape, ty);
296+
}
297+
}
298+
282299
if (ultimate.IsObjectArray()) {
283300
auto shapeExpr =
284301
Fortran::evaluate::GetShape(converter.getFoldingContext(), ultimate);
+22Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
! RUN: %flang_fc1 -emit-hlfir -o - %s | FileCheck %s
2+
3+
subroutine local_assoc
4+
implicit none
5+
integer i
6+
real, dimension(2:11) :: aa
7+
8+
associate(a => aa(4:))
9+
do concurrent (i = 4:11) local(a)
10+
a(i) = 0
11+
end do
12+
end associate
13+
end subroutine local_assoc
14+
15+
! CHECK: %[[C8:.*]] = arith.constant 8 : index
16+
17+
! CHECK: fir.do_loop {{.*}} unordered {
18+
! CHECK: %[[LOCAL_ALLOC:.*]] = fir.alloca !fir.array<8xf32> {bindc_name = "a", pinned, uniq_name = "{{.*}}local_assocEa"}
19+
! CHECK: %[[LOCAL_SHAPE:.*]] = fir.shape %[[C8]] :
20+
! CHECK: %[[LOCAL_DECL:.*]]:2 = hlfir.declare %[[LOCAL_ALLOC]](%[[LOCAL_SHAPE]])
21+
! CHECK: hlfir.designate %[[LOCAL_DECL]]#0 (%{{.*}})
22+
! CHECK: }

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.