-
Notifications
You must be signed in to change notification settings - Fork 13.4k
[flang][frontend] warn when a volatile target is pointer associated with an non-volatile pointer #136778
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
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@llvm/pr-subscribers-flang-semantics Author: Andre Kuhlenschmidt (akuhlens) Changescloses #135805 Full diff: https://github.com/llvm/llvm-project/pull/136778.diff 5 Files Affected:
diff --git a/flang/include/flang/Support/Fortran-features.h b/flang/include/flang/Support/Fortran-features.h
index 5b22313754a0f..6cb1bcdb0003f 100644
--- a/flang/include/flang/Support/Fortran-features.h
+++ b/flang/include/flang/Support/Fortran-features.h
@@ -76,7 +76,7 @@ ENUM_CLASS(UsageWarning, Portability, PointerToUndefinable,
MismatchingDummyProcedure, SubscriptedEmptyArray, UnsignedLiteralTruncation,
CompatibleDeclarationsFromDistinctModules,
NullActualForDefaultIntentAllocatable, UseAssociationIntoSameNameSubprogram,
- HostAssociatedIntentOutInSpecExpr)
+ HostAssociatedIntentOutInSpecExpr, NonVolatilePointerToVolatile)
using LanguageFeatures = EnumSet<LanguageFeature, LanguageFeature_enumSize>;
using UsageWarnings = EnumSet<UsageWarning, UsageWarning_enumSize>;
diff --git a/flang/lib/Semantics/pointer-assignment.cpp b/flang/lib/Semantics/pointer-assignment.cpp
index ab3771c808761..36c9c5b845706 100644
--- a/flang/lib/Semantics/pointer-assignment.cpp
+++ b/flang/lib/Semantics/pointer-assignment.cpp
@@ -360,6 +360,20 @@ bool PointerAssignmentChecker::Check(const evaluate::Designator<T> &d) {
} else {
Say(std::get<MessageFormattedText>(*msg));
}
+ }
+
+ // Show warnings after errors
+
+ // 8.5.20(3) A pointer should have the VOLATILE attribute if its target has
+ // the VOLATILE attribute
+ // 8.5.20(4) If an object has the VOLATILE attribute, then all of its
+ // subobjects also have the VOLATILE attribute.
+ if (!isVolatile_ && base->attrs().test(Attr::VOLATILE)) {
+ Warn(common::UsageWarning::NonVolatilePointerToVolatile,
+ "VOLATILE target associated with non-VOLATILE pointer"_warn_en_US);
+ }
+
+ if (msg) {
return false;
} else {
context_.NoteDefinedSymbol(*base);
diff --git a/flang/lib/Support/Fortran-features.cpp b/flang/lib/Support/Fortran-features.cpp
index b3cb62e62f5fb..49a5989849eaa 100644
--- a/flang/lib/Support/Fortran-features.cpp
+++ b/flang/lib/Support/Fortran-features.cpp
@@ -87,6 +87,7 @@ LanguageFeatureControl::LanguageFeatureControl() {
warnUsage_.set(UsageWarning::NullActualForDefaultIntentAllocatable);
warnUsage_.set(UsageWarning::UseAssociationIntoSameNameSubprogram);
warnUsage_.set(UsageWarning::HostAssociatedIntentOutInSpecExpr);
+ warnUsage_.set(UsageWarning::NonVolatilePointerToVolatile);
// New warnings, on by default
warnLanguage_.set(LanguageFeature::SavedLocalInSpecExpr);
warnLanguage_.set(LanguageFeature::NullActualForAllocatable);
diff --git a/flang/test/Semantics/assign02.f90 b/flang/test/Semantics/assign02.f90
index 6775506c21a3b..d83d126e2734c 100644
--- a/flang/test/Semantics/assign02.f90
+++ b/flang/test/Semantics/assign02.f90
@@ -9,6 +9,9 @@ module m1
sequence
real :: t2Field
end type
+ type t3
+ type(t2) :: t3Field
+ end type
contains
! C852
@@ -80,6 +83,7 @@ subroutine s5
real, pointer, volatile :: q
p => x
!ERROR: Pointer must be VOLATILE when target is a VOLATILE coarray
+ !ERROR: VOLATILE target associated with non-VOLATILE pointer
p => y
!ERROR: Pointer may not be VOLATILE when target is a non-VOLATILE coarray
q => x
@@ -165,6 +169,36 @@ subroutine s11
ca[1]%p => x
end
+ subroutine s12
+ real, volatile, target :: x
+ real, pointer :: p
+ real, pointer, volatile :: q
+ !ERROR: VOLATILE target associated with non-VOLATILE pointer
+ p => x
+ q => x
+ end
+
+ subroutine s13
+ type(t3), target, volatile :: y = t3(t2(4.4))
+ real, pointer :: p1
+ type(t2), pointer :: p2
+ type(t3), pointer :: p3
+ real, pointer, volatile :: q1
+ type(t2), pointer, volatile :: q2
+ type(t3), pointer, volatile :: q3
+ !ERROR: VOLATILE target associated with non-VOLATILE pointer
+ p1 => y%t3Field%t2Field
+ !ERROR: VOLATILE target associated with non-VOLATILE pointer
+ p2 => y%t3Field
+ !ERROR: VOLATILE target associated with non-VOLATILE pointer
+ p3 => y
+ !OK:
+ q1 => y%t3Field%t2Field
+ !OK:
+ q2 => y%t3Field
+ !OK:
+ q3 => y
+ end
end
module m2
diff --git a/flang/test/Semantics/call03.f90 b/flang/test/Semantics/call03.f90
index 8f1be1ebff4eb..59513557324e5 100644
--- a/flang/test/Semantics/call03.f90
+++ b/flang/test/Semantics/call03.f90
@@ -386,7 +386,9 @@ subroutine test16() ! C1540
call contiguous(a) ! ok
call pointer(a) ! ok
call pointer(b) ! ok
+ !ERROR: VOLATILE target associated with non-VOLATILE pointer
call pointer(c) ! ok
+ !ERROR: VOLATILE target associated with non-VOLATILE pointer
call pointer(d) ! ok
call valueassumedsize(a) ! ok
call valueassumedsize(b) ! ok
|
klausler
approved these changes
Apr 22, 2025
ashermancinelli
approved these changes
Apr 22, 2025
eugeneepshteyn
approved these changes
Apr 24, 2025
IanWood1
pushed a commit
to IanWood1/llvm-project
that referenced
this pull request
May 6, 2025
…ith an non-volatile pointer (llvm#136778) closes llvm#135805
IanWood1
pushed a commit
to IanWood1/llvm-project
that referenced
this pull request
May 6, 2025
…ith an non-volatile pointer (llvm#136778) closes llvm#135805
IanWood1
pushed a commit
to IanWood1/llvm-project
that referenced
this pull request
May 6, 2025
…ith an non-volatile pointer (llvm#136778) closes llvm#135805
GeorgeARM
pushed a commit
to GeorgeARM/llvm-project
that referenced
this pull request
May 7, 2025
…ith an non-volatile pointer (llvm#136778) closes llvm#135805
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
closes #135805