[flang-commits] [flang] b86c7da - [flang] Fix bad attributes on type parameter symbols (#174870)
via flang-commits
flang-commits at lists.llvm.org
Thu Jan 8 08:59:11 PST 2026
Author: Peter Klausler
Date: 2026-01-08T08:59:07-08:00
New Revision: b86c7daf93582848f7b5c7c92828e8b9658a575b
URL: https://github.com/llvm/llvm-project/commit/b86c7daf93582848f7b5c7c92828e8b9658a575b
DIFF: https://github.com/llvm/llvm-project/commit/b86c7daf93582848f7b5c7c92828e8b9658a575b.diff
LOG: [flang] Fix bad attributes on type parameter symbols (#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.
Added:
flang/test/Semantics/bug174859.f90
Modified:
flang/lib/Semantics/resolve-names.cpp
Removed:
################################################################################
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