Skip to content

[flang] Add conflicting checks for EXTERNAL attribute #149973

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

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions flang/lib/Semantics/check-declarations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class CheckHelper {
void CheckVolatile(const Symbol &, const DerivedTypeSpec *);
void CheckContiguous(const Symbol &);
void CheckPointer(const Symbol &);
void CheckExternalAttrConflicts(const Symbol &);
void CheckPassArg(
const Symbol &proc, const Symbol *interface, const WithPassArg &);
void CheckProcBinding(const Symbol &, const ProcBindingDetails &);
Expand Down Expand Up @@ -696,6 +697,8 @@ void CheckHelper::CheckObjectEntity(
CheckConflicting(symbol, Attr::SAVE, Attr::PARAMETER);
CheckConflicting(symbol, Attr::TARGET, Attr::PARAMETER);
CheckConflicting(symbol, Attr::VOLATILE, Attr::PARAMETER);
CheckConflicting(symbol, Attr::EXTERNAL, Attr::PARAMETER);
CheckConflicting(symbol, Attr::INTRINSIC, Attr::PARAMETER);
Check(details.shape());
Check(details.coshape());
if (details.shape().Rank() > common::maxRank) {
Expand Down Expand Up @@ -983,6 +986,7 @@ void CheckHelper::CheckObjectEntity(
}
}
if (symbol.attrs().test(Attr::EXTERNAL)) {
CheckExternalAttrConflicts(symbol);
SayWithDeclaration(symbol,
"'%s' is a data object and may not be EXTERNAL"_err_en_US,
symbol.name());
Expand Down Expand Up @@ -2460,6 +2464,10 @@ void CheckHelper::CheckPointer(const Symbol &symbol) { // C852
}
}

void CheckHelper::CheckExternalAttrConflicts(const Symbol &symbol) {
CheckConflicting(symbol, Attr::EXTERNAL, Attr::INTRINSIC); // F'2023 C842
}

// C760 constraints on the passed-object dummy argument
// C757 constraints on procedure pointer components
void CheckHelper::CheckPassArg(
Expand Down
3 changes: 3 additions & 0 deletions flang/test/Semantics/declarations02.f90
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ module m
target x4
volatile x4

!ERROR: 'sin' may not have both the INTRINSIC and PARAMETER attributes
real, parameter, intrinsic :: sin

type :: my_type1
integer :: x4
end type
Expand Down
11 changes: 11 additions & 0 deletions flang/test/Semantics/declarations09.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
! RUN: %python %S/test_errors.py %s %flang_fc1 -pedantic

subroutine bug149771

!ERROR: 'exp' may not have both the EXTERNAL and INTRINSIC attributes
real, external, intrinsic :: exp

!ERROR: 'x2' may not have both the EXTERNAL and PARAMETER attributes
integer, external, parameter :: x2

end subroutine bug149771
Loading