[flang-commits] [flang] [flang][OpenMP] Fix regression in OpenMP master region with private t… (PR #172085)
Priyanshu Singh via flang-commits
flang-commits at lists.llvm.org
Mon Dec 15 10:31:43 PST 2025
https://github.com/dev-priyanshu15 updated https://github.com/llvm/llvm-project/pull/172085
>From cae7f747a680084117e9bed1aa70d698b1921de8 Mon Sep 17 00:00:00 2001
From: spriyanshucoder <s.priyanshu.coder at gmail.com>
Date: Sat, 13 Dec 2025 02:50:35 +0530
Subject: [PATCH] [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
---
.../lib/Optimizer/Transforms/AddAliasTags.cpp | 20 ++++++++------
.../alias-tags-master-private-target.f90 | 26 +++++++++++++++++++
2 files changed, 38 insertions(+), 8 deletions(-)
create mode 100644 flang/test/Transforms/alias-tags-master-private-target.f90
diff --git a/flang/lib/Optimizer/Transforms/AddAliasTags.cpp b/flang/lib/Optimizer/Transforms/AddAliasTags.cpp
index 3718848c05775..a0b10d1858a92 100644
--- a/flang/lib/Optimizer/Transforms/AddAliasTags.cpp
+++ b/flang/lib/Optimizer/Transforms/AddAliasTags.cpp
@@ -702,20 +702,24 @@ void AddAliasTagsPass::runOnAliasInterface(fir::FirAliasTagOpInterface op,
source.kind == fir::AliasAnalysis::SourceKind::Argument) {
LLVM_DEBUG(llvm::dbgs().indent(2)
<< "Found reference to dummy argument at " << *op << "\n");
- std::string name = getFuncArgName(llvm::cast<mlir::Value>(source.origin.u));
// POINTERS can alias with any POINTER or TARGET. Assume that TARGET dummy
// arguments might alias with each other (because of the "TARGET" hole for
// dummy arguments). See flang/docs/Aliasing.md.
+ // If it is a TARGET or POINTER, then we do not care about the name,
+ // because the tag points to the root of the subtree currently.
if (source.isTargetOrPointer()) {
tag = state.getFuncTreeWithScope(func, scopeOp).targetDataTree.getTag();
- } else if (!name.empty()) {
- tag = state.getFuncTreeWithScope(func, scopeOp)
- .dummyArgDataTree.getTag(name);
} else {
- LLVM_DEBUG(llvm::dbgs().indent(2)
- << "WARN: couldn't find a name for dummy argument " << *op
- << "\n");
- tag = state.getFuncTreeWithScope(func, scopeOp).dummyArgDataTree.getTag();
+ std::string name = getFuncArgName(llvm::cast<mlir::Value>(source.origin.u));
+ if (!name.empty()) {
+ tag = state.getFuncTreeWithScope(func, scopeOp)
+ .dummyArgDataTree.getTag(name);
+ } else {
+ LLVM_DEBUG(llvm::dbgs().indent(2)
+ << "WARN: couldn't find a name for dummy argument " << *op
+ << "\n");
+ tag = state.getFuncTreeWithScope(func, scopeOp).dummyArgDataTree.getTag();
+ }
}
// TBAA for global variables without descriptors
diff --git a/flang/test/Transforms/alias-tags-master-private-target.f90 b/flang/test/Transforms/alias-tags-master-private-target.f90
new file mode 100644
index 0000000000000..0251376476c64
--- /dev/null
+++ b/flang/test/Transforms/alias-tags-master-private-target.f90
@@ -0,0 +1,26 @@
+! Test case for regression in OpenMP master region with private target integer
+! This test was failing with an assertion error in AddAliasTags.cpp
+! See issue #172075
+
+! RUN: %flang -fopenmp -c -O1 %s -o %t.o 2>&1 | FileCheck %s --allow-empty
+
+module test
+contains
+subroutine omp_master_repro()
+ implicit none
+ integer, parameter :: nim = 4
+ integer, parameter :: nvals = 8
+ integer, target :: ui
+ integer :: hold1(nvals, nim)
+ hold1 = 0
+ !$OMP PARALLEL DEFAULT(NONE) &
+ !$OMP PRIVATE(ui) &
+ !$OMP SHARED(hold1, nim)
+ !$OMP MASTER
+ do ui = 1, nim
+ hold1(:, ui) = 1
+ end do
+ !$OMP END MASTER
+ !$OMP END PARALLEL
+end subroutine omp_master_repro
+end module test
More information about the flang-commits
mailing list