[flang-commits] [flang] [flang] Fix bad attributes on type parameter symbols (PR #174870)
Peter Klausler via flang-commits
flang-commits at lists.llvm.org
Wed Jan 7 13:54:18 PST 2026
https://github.com/klausler created https://github.com/llvm/llvm-project/pull/174870
When creating new symbols for a derived type's type parameters, the attributes that accumulated for the type itself were also being applied to the parameters' symbols. This led to those attributes being emitted to the module file, rendering it unparseable.
Fixes https://github.com/llvm/llvm-project/issues/174859.
>From f0e7cf6ee238bc2525db4c880ab47ef2a409c7a8 Mon Sep 17 00:00:00 2001
From: Peter Klausler <pklausler at nvidia.com>
Date: Wed, 7 Jan 2026 13:50:40 -0800
Subject: [PATCH] [flang] Fix bad attributes on type parameter symbols
When creating new symbols for a derived type's type parameters,
the attributes that accumulated for the type itself were also
being applied to the parameters' symbols. This led to those
attributes being emitted to the module file, rendering it
unparseable.
Fixes https://github.com/llvm/llvm-project/issues/174859.
---
flang/lib/Semantics/resolve-names.cpp | 3 +++
flang/test/Semantics/bug174859.f90 | 14 ++++++++++++++
2 files changed, 17 insertions(+)
create mode 100644 flang/test/Semantics/bug174859.f90
diff --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp
index ec2b1eb198695..ae251476ed591 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -6534,6 +6534,9 @@ void DeclarationVisitor::Post(const parser::DerivedTypeStmt &x) {
if (!paramNames.empty()) {
set_inPDTDefinition(true);
}
+ // Clear the attributes so that the attributes of the derived type
+ // (ABSTRACT, PUBLIC/PRIVATE, &c.) don't apply to the type's parameters.
+ EndAttrs(), BeginAttrs();
if (auto *details{symbol.detailsIf<DerivedTypeDetails>()}) {
for (const auto &name : paramNames) {
if (Symbol * symbol{MakeTypeSymbol(name, TypeParamDetails{})}) {
diff --git a/flang/test/Semantics/bug174859.f90 b/flang/test/Semantics/bug174859.f90
new file mode 100644
index 0000000000000..fc4ef30e66598
--- /dev/null
+++ b/flang/test/Semantics/bug174859.f90
@@ -0,0 +1,14 @@
+! RUN: %python %S/test_modfile.py %s %flang_fc1
+! Attributes of the derived type were also applied to type parameters.
+module m
+ type, abstract, public :: t(k)
+ integer, kind :: k
+ end type
+end
+
+!Expect: m.mod
+!module m
+!type,abstract::t(k)
+!integer(4),kind::k
+!end type
+!end
More information about the flang-commits
mailing list