Skip to content

Conversation

@klausler
Copy link
Contributor

Enforce an obscure constraint from the standard: an abstract interface is not allowed to have the same name as an intrinsic type keyword. I suspect this is meant to prevent a declaration like "PROCEDURE(REAL), POINTER :: P" from being ambiguous.

Fixes #128744.

Enforce an obscure constraint from the standard: an abstract
interface is not allowed to have the same name as an intrinsic
type keyword.  I suspect this is meant to prevent a declaration
like "PROCEDURE(REAL), POINTER :: P" from being ambiguous.

Fixes llvm#128744.
@llvmbot llvmbot added flang Flang issues not falling into any other category flang:semantics labels Feb 26, 2025
@llvmbot
Copy link
Member

llvmbot commented Feb 26, 2025

@llvm/pr-subscribers-flang-semantics

Author: Peter Klausler (klausler)

Changes

Enforce an obscure constraint from the standard: an abstract interface is not allowed to have the same name as an intrinsic type keyword. I suspect this is meant to prevent a declaration like "PROCEDURE(REAL), POINTER :: P" from being ambiguous.

Fixes #128744.


Full diff: https://github.com/llvm/llvm-project/pull/128962.diff

2 Files Affected:

  • (modified) flang/lib/Semantics/check-declarations.cpp (+8)
  • (modified) flang/test/Semantics/abstract02.f90 (+6)
diff --git a/flang/lib/Semantics/check-declarations.cpp b/flang/lib/Semantics/check-declarations.cpp
index bf4dc16a15b4a..b42d1a1629a3b 100644
--- a/flang/lib/Semantics/check-declarations.cpp
+++ b/flang/lib/Semantics/check-declarations.cpp
@@ -1496,6 +1496,14 @@ void CheckHelper::CheckSubprogram(
       messages_.Say(details.result().name(),
           "A function interface may not declare an assumed-length CHARACTER(*) result"_err_en_US);
     }
+    if (symbol.attrs().test(Attr::ABSTRACT) &&
+        (symbol.name() == "integer" || symbol.name() == "unsigned" ||
+            symbol.name() == "real" || symbol.name() == "complex" ||
+            symbol.name() == "character" ||
+            symbol.name() == "logical")) { // F'2023 C1503
+      messages_.Say(
+          "An ABSTRACT interface may not have the same name as an intrinsic type"_err_en_US);
+    }
   }
   CheckExternal(symbol);
   CheckModuleProcedureDef(symbol);
diff --git a/flang/test/Semantics/abstract02.f90 b/flang/test/Semantics/abstract02.f90
index 29aad7b03e537..22183e445d5c6 100644
--- a/flang/test/Semantics/abstract02.f90
+++ b/flang/test/Semantics/abstract02.f90
@@ -4,6 +4,12 @@ program test
   abstract interface
     subroutine abstract
     end subroutine
+    !ERROR: An ABSTRACT interface may not have the same name as an intrinsic type
+    function integer()
+    end
+    !ERROR: An ABSTRACT interface may not have the same name as an intrinsic type
+    subroutine logical
+    end
   end interface
   procedure(abstract), pointer :: p
   !ERROR: Abstract procedure interface 'abstract' may not be referenced

Copy link
Contributor

@DanielCChen DanielCChen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.
Thanks for fixing it.

@klausler klausler merged commit 78acf7b into llvm:main Feb 27, 2025
14 checks passed
@klausler klausler deleted the bug128744 branch February 27, 2025 22:32
cheezeburglar pushed a commit to cheezeburglar/llvm-project that referenced this pull request Feb 28, 2025
Enforce an obscure constraint from the standard: an abstract interface
is not allowed to have the same name as an intrinsic type keyword. I
suspect this is meant to prevent a declaration like "PROCEDURE(REAL),
POINTER :: P" from being ambiguous.

Fixes llvm#128744.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

flang:semantics flang Flang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Flang] Missing diagnostic on abstract interface name being the same as the keyword of an intrinsic type

4 participants