[flang-commits] [flang] 1087708 - [flang][OpenMP] Fix crash in defaultmap(none) on structure constructors (#220994)
via flang-commits
flang-commits at lists.llvm.org
Thu Sep 24 02:08:29 PDT 2026
Author: CHANDRA GHALE
Date: 2026-09-24T14:38:23+05:30
New Revision: 108770859571a22679b9f5e871ac6ffc311b0f4e
URL: https://github.com/llvm/llvm-project/commit/108770859571a22679b9f5e871ac6ffc311b0f4e
DIFF: https://github.com/llvm/llvm-project/commit/108770859571a22679b9f5e871ac6ffc311b0f4e.diff
LOG: [flang][OpenMP] Fix crash in defaultmap(none) on structure constructors (#220994)
Fixes :
[https://github.com/llvm/llvm-project/issues/218929](https://github.com/llvm/llvm-project/issues/218929)
Flang was crashing when a target defaultmap(none:...) region contained a
structure constructor, like this:
```
program p
type t
end type
type(t) :: x
!$omp target defaultmap(none:aggregate)
x = t()
!$omp end target
end
```
The problem is in `IsOpenMPAggregate` and `IsOpenMPScalar`. When the
OpenMP attribute visitor walks the names in the region, it hits the t in
t(), which resolves to the derived-type definition symbol rather than a
variable. `Symbol::GetType() `returns nullptr for such a symbol, and
both helpers dereferenced that pointer directly `(type->category())`
without checking, causing a segfault. The fix adds a null check to both
helpers returning false since a symbol with no declared type belongs to
no defaultmap category.
Co-authored-by: Chandra Ghale <ghale at pe34genoa.hpc.amslabs.hpecorp.net>
Added:
Modified:
flang/lib/Semantics/resolve-directives.cpp
flang/test/Semantics/OpenMP/defaultmap-clause-none.f90
Removed:
################################################################################
diff --git a/flang/lib/Semantics/resolve-directives.cpp b/flang/lib/Semantics/resolve-directives.cpp
index f7a9e252d0d49..0ce2d5fe67c27 100644
--- a/flang/lib/Semantics/resolve-directives.cpp
+++ b/flang/lib/Semantics/resolve-directives.cpp
@@ -2907,6 +2907,10 @@ static bool IsOpenMPAggregate(const Symbol &symbol) {
return false;
const auto *type{symbol.GetType()};
+ // Symbols without a declared type (e.g. a derived-type name) are not
+ // variables and belong to no defaultmap category.
+ if (!type)
+ return false;
// OpenMP categorizes Fortran characters as aggregates.
if (type->category() == Fortran::semantics::DeclTypeSpec::Category::Character)
return true;
@@ -2930,6 +2934,8 @@ static bool IsOpenMPScalar(const Symbol &symbol) {
IsAllocatable(symbol))
return false;
const auto *type{symbol.GetType()};
+ if (!type)
+ return false;
if ((!symbol.GetShape() || symbol.GetShape()->empty()) &&
(type->category() ==
Fortran::semantics::DeclTypeSpec::Category::Numeric ||
diff --git a/flang/test/Semantics/OpenMP/defaultmap-clause-none.f90 b/flang/test/Semantics/OpenMP/defaultmap-clause-none.f90
index 0b74e3412e472..417f762118e73 100644
--- a/flang/test/Semantics/OpenMP/defaultmap-clause-none.f90
+++ b/flang/test/Semantics/OpenMP/defaultmap-clause-none.f90
@@ -130,4 +130,18 @@ subroutine defaultmap_func_and_procedure_pointer()
i = test_procedure()
!$omp end target
end subroutine defaultmap_func_and_procedure_pointer
+
+! Verify we do not crash on a derived-type name in a structure constructor,
+! which has no declared type of its own, in defaultmap(none)
+subroutine defaultmap_structure_constructor_none
+ implicit none
+ type t
+ end type
+ type(t) :: x
+
+ !$omp target defaultmap(none: aggregate)
+!ERROR: The DEFAULTMAP(NONE) clause requires that 'x' must be listed in a data-sharing attribute, data-mapping attribute, or is_device_ptr clause
+ x = t()
+ !$omp end target
+end subroutine defaultmap_structure_constructor_none
end module
More information about the flang-commits
mailing list