Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[flang] Allow empty SEQUENCE types #66252

Merged
merged 1 commit into from
Sep 18, 2023
Merged

[flang] Allow empty SEQUENCE types #66252

merged 1 commit into from
Sep 18, 2023

Conversation

klausler
Copy link
Contributor

The Fortran standards require (F'2023 C745) that a derived type with the SEQUENCE attribute have at least one component. No Fortran compiler actually enforces this constraint. Accept this usage with a warning.

The Fortran standards require (F'2023 C745) that a derived
type with the SEQUENCE attribute have at least one component.
No Fortran compiler actually enforces this constraint.
Accept this usage with a warning.

Pull request: llvm#66252
@klausler klausler requested a review from a team as a code owner September 13, 2023 17:14
@llvmbot llvmbot added flang Flang issues not falling into any other category flang:semantics labels Sep 13, 2023
@llvmbot
Copy link
Collaborator

llvmbot commented Sep 13, 2023

@llvm/pr-subscribers-flang-semantics

Changes The Fortran standards require (F'2023 C745) that a derived type with the SEQUENCE attribute have at least one component. No Fortran compiler actually enforces this constraint. Accept this usage with a warning. -- Full diff: https://github.com//pull/66252.diff

3 Files Affected:

  • (modified) flang/docs/Extensions.md (+3)
  • (modified) flang/lib/Semantics/resolve-names.cpp (+3-2)
  • (modified) flang/test/Semantics/resolve31.f90 (+1-1)
diff --git a/flang/docs/Extensions.md b/flang/docs/Extensions.md
index 49e78a10fa6bcdb..4d0b2c7319818a7 100644
--- a/flang/docs/Extensions.md
+++ b/flang/docs/Extensions.md
@@ -428,6 +428,9 @@ end
 * Since Fortran 90, INCLUDE lines have been allowed to have
   a numeric kind parameter prefix on the file name.  No other
   Fortran compiler supports them that I can find.
+* A `SEQUENCE` derived type is required (F'2023 C745) to have
+  at least one component.  No compiler enforces this constraint;
+  this compiler emits a warning.
 
 ## Behavior in cases where the standard is ambiguous or indefinite
 
diff --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp
index 865c198424696a9..f56f7a71f367be6 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -5225,9 +5225,10 @@ bool DeclarationVisitor::Pre(const parser::DerivedTypeDef &x) {
   Walk(componentDefs);
   if (derivedTypeInfo_.sequence) {
     details.set_sequence(true);
-    if (componentDefs.empty()) { // C740
+    if (componentDefs.empty()) {
+      // F'2023 C745 - not enforced by any compiler
       Say(stmt.source,
-          "A sequence type must have at least one component"_err_en_US);
+          "A sequence type should have at least one component"_warn_en_US);
     }
     if (!details.paramNames().empty()) { // C740
       Say(stmt.source,
diff --git a/flang/test/Semantics/resolve31.f90 b/flang/test/Semantics/resolve31.f90
index 0c604c0ee9734b9..6bf8e877a515668 100644
--- a/flang/test/Semantics/resolve31.f90
+++ b/flang/test/Semantics/resolve31.f90
@@ -68,7 +68,7 @@ module m4
   !ERROR: A sequence type may not have a CONTAINS statement
   contains
   end type
-  !ERROR: A sequence type must have at least one component
+  !WARNING: A sequence type should have at least one component
   type :: emptyType
     sequence
   end type emptyType

@klausler klausler merged commit 7991078 into llvm:main Sep 18, 2023
4 checks passed
@klausler klausler deleted the rl7 branch September 18, 2023 19:11
ZijunZhaoCCK pushed a commit to ZijunZhaoCCK/llvm-project that referenced this pull request Sep 19, 2023
The Fortran standards require (F'2023 C745) that a derived type with the
SEQUENCE attribute have at least one component. No Fortran compiler
actually enforces this constraint. Accept this usage with a warning.
zahiraam pushed a commit to tahonermann/llvm-project that referenced this pull request Oct 24, 2023
The Fortran standards require (F'2023 C745) that a derived type with the
SEQUENCE attribute have at least one component. No Fortran compiler
actually enforces this constraint. Accept this usage with a warning.
zahiraam pushed a commit to tahonermann/llvm-project that referenced this pull request Oct 24, 2023
The Fortran standards require (F'2023 C745) that a derived type with the
SEQUENCE attribute have at least one component. No Fortran compiler
actually enforces this constraint. Accept this usage with a warning.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang Flang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants