Skip to content

[flang] Catch both EXTERNAL and INTRINSIC on type declaration stmt #150254

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

Merged
merged 1 commit into from
Jul 25, 2025

Conversation

klausler
Copy link
Contributor

The EXTERNAL and INTRINSIC attributes can't both appear on the same type declarations statement.

Fixes #149771.

The EXTERNAL and INTRINSIC attributes can't both appear on the same
type declarations statement.

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

llvmbot commented Jul 23, 2025

@llvm/pr-subscribers-flang-semantics

Author: Peter Klausler (klausler)

Changes

The EXTERNAL and INTRINSIC attributes can't both appear on the same type declarations statement.

Fixes #149771.


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

2 Files Affected:

  • (modified) flang/lib/Semantics/resolve-names.cpp (+2-1)
  • (added) flang/test/Semantics/resolve126.f90 (+7)
diff --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp
index b3268605e7c0c..d08c669377cb2 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -2351,7 +2351,8 @@ bool AttrsVisitor::IsConflictingAttr(Attr attrName) {
       HaveAttrConflict(attrName, Attr::PASS, Attr::NOPASS) || // C781
       HaveAttrConflict(attrName, Attr::PURE, Attr::IMPURE) ||
       HaveAttrConflict(attrName, Attr::PUBLIC, Attr::PRIVATE) ||
-      HaveAttrConflict(attrName, Attr::RECURSIVE, Attr::NON_RECURSIVE);
+      HaveAttrConflict(attrName, Attr::RECURSIVE, Attr::NON_RECURSIVE) ||
+      HaveAttrConflict(attrName, Attr::INTRINSIC, Attr::EXTERNAL);
 }
 bool AttrsVisitor::CheckAndSet(Attr attrName) {
   if (IsConflictingAttr(attrName) || IsDuplicateAttr(attrName)) {
diff --git a/flang/test/Semantics/resolve126.f90 b/flang/test/Semantics/resolve126.f90
new file mode 100644
index 0000000000000..6313f8c539bf8
--- /dev/null
+++ b/flang/test/Semantics/resolve126.f90
@@ -0,0 +1,7 @@
+! RUN: %python %S/test_errors.py %s %flang_fc1
+!ERROR: Attributes 'INTRINSIC' and 'EXTERNAL' conflict with each other
+real, external, intrinsic :: exp
+!ERROR: Symbol 'sin' cannot have both EXTERNAL and INTRINSIC attributes
+external sin
+intrinsic sin
+end

@@ -2351,7 +2351,8 @@ bool AttrsVisitor::IsConflictingAttr(Attr attrName) {
HaveAttrConflict(attrName, Attr::PASS, Attr::NOPASS) || // C781
HaveAttrConflict(attrName, Attr::PURE, Attr::IMPURE) ||
HaveAttrConflict(attrName, Attr::PUBLIC, Attr::PRIVATE) ||
HaveAttrConflict(attrName, Attr::RECURSIVE, Attr::NON_RECURSIVE);
HaveAttrConflict(attrName, Attr::RECURSIVE, Attr::NON_RECURSIVE) ||
HaveAttrConflict(attrName, Attr::INTRINSIC, Attr::EXTERNAL);
Copy link
Contributor

@c8ef c8ef Jul 23, 2025

Choose a reason for hiding this comment

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

Nit: Add a comment stating it violates C842(F2023)?

@klausler klausler merged commit 129db4d into llvm:main Jul 25, 2025
12 checks passed
@klausler klausler deleted the bug149771 branch July 25, 2025 21:48
mahesh-attarde pushed a commit to mahesh-attarde/llvm-project that referenced this pull request Jul 28, 2025
…lvm#150254)

The EXTERNAL and INTRINSIC attributes can't both appear on the same type
declarations statement.

Fixes llvm#149771.
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] external must conflict with intrinsic and vice versa
5 participants