[flang-commits] [flang] [flang] Fix bad attributes on type parameter symbols (PR #174870)
via flang-commits
flang-commits at lists.llvm.org
Wed Jan 7 13:54:47 PST 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-semantics
Author: Peter Klausler (klausler)
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/174870.diff
2 Files Affected:
- (modified) flang/lib/Semantics/resolve-names.cpp (+3)
- (added) flang/test/Semantics/bug174859.f90 (+14)
``````````diff
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
``````````
</details>
https://github.com/llvm/llvm-project/pull/174870
More information about the flang-commits
mailing list