Skip to content

Commit 5bc0f4a

Browse files
[flang][OpenMP] Fix regression in OpenMP master region with private target integer
When handling TARGET variables in dummy arguments, the code was calling getFuncArgName() unconditionally. This could cause an assertion failure when getUniqName() returns an unengaged optional for TARGET variables. Move getFuncArgName() call to only execute when the variable is not a TARGET or POINTER, avoiding the assertion error. Fixes issue #172075
1 parent f3c1645 commit 5bc0f4a

File tree

2 files changed

+38
-8
lines changed

2 files changed

+38
-8
lines changed

flang/lib/Optimizer/Transforms/AddAliasTags.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -702,20 +702,24 @@ void AddAliasTagsPass::runOnAliasInterface(fir::FirAliasTagOpInterface op,
702702
source.kind == fir::AliasAnalysis::SourceKind::Argument) {
703703
LLVM_DEBUG(llvm::dbgs().indent(2)
704704
<< "Found reference to dummy argument at " << *op << "\n");
705-
std::string name = getFuncArgName(llvm::cast<mlir::Value>(source.origin.u));
706705
// POINTERS can alias with any POINTER or TARGET. Assume that TARGET dummy
707706
// arguments might alias with each other (because of the "TARGET" hole for
708707
// dummy arguments). See flang/docs/Aliasing.md.
708+
// If it is a TARGET or POINTER, then we do not care about the name,
709+
// because the tag points to the root of the subtree currently.
709710
if (source.isTargetOrPointer()) {
710711
tag = state.getFuncTreeWithScope(func, scopeOp).targetDataTree.getTag();
711-
} else if (!name.empty()) {
712-
tag = state.getFuncTreeWithScope(func, scopeOp)
713-
.dummyArgDataTree.getTag(name);
714712
} else {
715-
LLVM_DEBUG(llvm::dbgs().indent(2)
716-
<< "WARN: couldn't find a name for dummy argument " << *op
717-
<< "\n");
718-
tag = state.getFuncTreeWithScope(func, scopeOp).dummyArgDataTree.getTag();
713+
std::string name = getFuncArgName(llvm::cast<mlir::Value>(source.origin.u));
714+
if (!name.empty()) {
715+
tag = state.getFuncTreeWithScope(func, scopeOp)
716+
.dummyArgDataTree.getTag(name);
717+
} else {
718+
LLVM_DEBUG(llvm::dbgs().indent(2)
719+
<< "WARN: couldn't find a name for dummy argument " << *op
720+
<< "\n");
721+
tag = state.getFuncTreeWithScope(func, scopeOp).dummyArgDataTree.getTag();
722+
}
719723
}
720724

721725
// TBAA for global variables without descriptors
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
! Test case for regression in OpenMP master region with private target integer
2+
! This test was failing with an assertion error in AddAliasTags.cpp
3+
! See issue #172075
4+
5+
! RUN: %flang -fopenmp -c -O1 %s -o %t.o 2>&1 | FileCheck %s --allow-empty
6+
7+
module test
8+
contains
9+
subroutine omp_master_repro()
10+
implicit none
11+
integer, parameter :: nim = 4
12+
integer, parameter :: nvals = 8
13+
integer, target :: ui
14+
integer :: hold1(nvals, nim)
15+
hold1 = 0
16+
!$OMP PARALLEL DEFAULT(NONE) &
17+
!$OMP PRIVATE(ui) &
18+
!$OMP SHARED(hold1, nim)
19+
!$OMP MASTER
20+
do ui = 1, nim
21+
hold1(:, ui) = 1
22+
end do
23+
!$OMP END MASTER
24+
!$OMP END PARALLEL
25+
end subroutine omp_master_repro
26+
end module test

0 commit comments

Comments
 (0)