Skip to content

Commit 4e43a14

Browse files
committed
[flang][OpenMP] Fix resolve common block in data-sharing clauses
The previous resolve only creates the host associated varaibles for common block members, but does not replace the original objects with the new created ones. Fix it and also compute the sizes and offsets for the host common block members if they are host associated. Reviewed By: kiranchandramohan Differential Revision: https://reviews.llvm.org/D127214
1 parent d11e406 commit 4e43a14

File tree

5 files changed

+42
-15
lines changed

5 files changed

+42
-15
lines changed

flang/include/flang/Semantics/symbol.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,10 @@ class CommonBlockDetails : public WithBindName {
351351
MutableSymbolVector &objects() { return objects_; }
352352
const MutableSymbolVector &objects() const { return objects_; }
353353
void add_object(Symbol &object) { objects_.emplace_back(object); }
354+
void replace_object(Symbol &object, unsigned index) {
355+
CHECK(index < (unsigned)objects_.size());
356+
objects_[index] = object;
357+
}
354358
std::size_t alignment() const { return alignment_; }
355359
void set_alignment(std::size_t alignment) { alignment_ = alignment; }
356360

flang/lib/Semantics/compute-offsets.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ void ComputeOffsetsHelper::DoCommonBlock(Symbol &commonBlock) {
156156
Symbol &symbol{*object};
157157
auto errorSite{
158158
commonBlock.name().empty() ? symbol.name() : commonBlock.name()};
159-
if (std::size_t padding{DoSymbol(symbol)}) {
159+
if (std::size_t padding{DoSymbol(symbol.GetUltimate())}) {
160160
context_.Say(errorSite,
161161
"COMMON block /%s/ requires %zd bytes of padding before '%s' for alignment"_port_en_US,
162162
commonBlock.name(), padding, symbol.name());

flang/lib/Semantics/resolve-directives.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1677,15 +1677,19 @@ void OmpAttributeVisitor::ResolveOmpObject(
16771677
// 2.15.3 When a named common block appears in a list, it has the
16781678
// same meaning as if every explicit member of the common block
16791679
// appeared in the list
1680-
for (auto &object : symbol->get<CommonBlockDetails>().objects()) {
1680+
auto &details{symbol->get<CommonBlockDetails>()};
1681+
unsigned index{0};
1682+
for (auto &object : details.objects()) {
16811683
if (auto *resolvedObject{
16821684
ResolveOmp(*object, ompFlag, currScope())}) {
16831685
if (dataCopyingAttributeFlags.test(ompFlag)) {
16841686
CheckDataCopyingClause(name, *resolvedObject, ompFlag);
16851687
} else {
16861688
AddToContextObjectWithDSA(*resolvedObject, ompFlag);
16871689
}
1690+
details.replace_object(*resolvedObject, index);
16881691
}
1692+
index++;
16891693
}
16901694
} else {
16911695
context_.Say(name.source, // 2.15.3
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
! RUN: %flang_fc1 -fopenmp -fdebug-dump-symbols %s | FileCheck %s
2+
3+
program main
4+
!CHECK: a size=4 offset=0: ObjectEntity type: REAL(4)
5+
!CHECK: b size=8 offset=4: ObjectEntity type: INTEGER(4) shape: 1_8:2_8
6+
!CHECK: c size=4 offset=12: ObjectEntity type: REAL(4)
7+
!CHECK: blk size=16 offset=0: CommonBlockDetails alignment=4: a b c
8+
real :: a, c
9+
integer :: b(2)
10+
common /blk/ a, b, c
11+
!$omp parallel private(/blk/)
12+
!CHECK: OtherConstruct scope: size=0 alignment=1
13+
!CHECK: a (OmpPrivate): HostAssoc
14+
!CHECK: b (OmpPrivate): HostAssoc
15+
!CHECK: c (OmpPrivate): HostAssoc
16+
call sub(a, b, c)
17+
!$omp end parallel
18+
end program

flang/test/Semantics/OpenMP/omp-threadprivate04.f90

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,44 +5,45 @@
55

66
program main
77
integer :: i, N = 10
8-
integer, save :: x
9-
common /blk/ y
8+
integer, save :: x1, x2, x3, x4, x5, x6, x7, x8, x9
9+
common /blk1/ y1, /blk2/ y2, /blk3/ y3, /blk4/ y4, /blk5/ y5
1010

11-
!$omp threadprivate(x, /blk/)
11+
!$omp threadprivate(x1, x2, x3, x4, x5, x6, x7, x8, x9)
12+
!$omp threadprivate(/blk1/, /blk2/, /blk3/, /blk4/, /blk5/)
1213

13-
!$omp parallel num_threads(x)
14+
!$omp parallel num_threads(x1)
1415
!$omp end parallel
1516

16-
!$omp single copyprivate(x, /blk/)
17+
!$omp single copyprivate(x2, /blk1/)
1718
!$omp end single
1819

19-
!$omp do schedule(static, x)
20+
!$omp do schedule(static, x3)
2021
do i = 1, N
21-
y = x
22+
y1 = x3
2223
end do
2324
!$omp end do
2425

25-
!$omp parallel copyin(x, /blk/)
26+
!$omp parallel copyin(x4, /blk2/)
2627
!$omp end parallel
2728

28-
!$omp parallel if(x > 1)
29+
!$omp parallel if(x5 > 1)
2930
!$omp end parallel
3031

31-
!$omp teams thread_limit(x)
32+
!$omp teams thread_limit(x6)
3233
!$omp end teams
3334

3435
!ERROR: A THREADPRIVATE variable cannot be in PRIVATE clause
3536
!ERROR: A THREADPRIVATE variable cannot be in PRIVATE clause
36-
!$omp parallel private(x, /blk/)
37+
!$omp parallel private(x7, /blk3/)
3738
!$omp end parallel
3839

3940
!ERROR: A THREADPRIVATE variable cannot be in FIRSTPRIVATE clause
4041
!ERROR: A THREADPRIVATE variable cannot be in FIRSTPRIVATE clause
41-
!$omp parallel firstprivate(x, /blk/)
42+
!$omp parallel firstprivate(x8, /blk4/)
4243
!$omp end parallel
4344

4445
!ERROR: A THREADPRIVATE variable cannot be in SHARED clause
4546
!ERROR: A THREADPRIVATE variable cannot be in SHARED clause
46-
!$omp parallel shared(x, /blk/)
47+
!$omp parallel shared(x9, /blk5/)
4748
!$omp end parallel
4849
end

0 commit comments

Comments
 (0)