-
Notifications
You must be signed in to change notification settings - Fork 13.4k
[flang][volatile] Get volatility of designators from base instead of component symbol #138611
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
base: main
Are you sure you want to change the base?
Conversation
@llvm/pr-subscribers-flang-semantics Author: Andre Kuhlenschmidt (akuhlens) ChangesThe standard says in [8.5.20 VOLATILE attribute]: This code takes this into account and uses the volatility of the base of the designator instead of that of the component. In fact, fields in a structure are not allowed to have the volatile attribute. So given the code, This PR should address the comments on this PR #132486 Full diff: https://github.com/llvm/llvm-project/pull/138611.diff 2 Files Affected:
diff --git a/flang/lib/Semantics/pointer-assignment.cpp b/flang/lib/Semantics/pointer-assignment.cpp
index 36c9c5b845706..c17eb0aa941ec 100644
--- a/flang/lib/Semantics/pointer-assignment.cpp
+++ b/flang/lib/Semantics/pointer-assignment.cpp
@@ -329,7 +329,6 @@ bool PointerAssignmentChecker::Check(const evaluate::Designator<T> &d) {
" shape"_err_en_US;
} else if (rhsType->corank() > 0 &&
(isVolatile_ != last->attrs().test(Attr::VOLATILE))) { // C1020
- // TODO: what if A is VOLATILE in A%B%C? need a better test here
if (isVolatile_) {
msg = "Pointer may not be VOLATILE when target is a"
" non-VOLATILE coarray"_err_en_US;
@@ -569,6 +568,12 @@ bool CheckPointerAssignment(SemanticsContext &context, const SomeExpr &lhs,
return false; // error was reported
}
PointerAssignmentChecker checker{context, scope, *pointer};
+ const Symbol *base{GetFirstSymbol(lhs)};
+ if (base) {
+ // 8.5.20(4) If an object has the VOLATILE attribute, then all of its
+ // subobjects also have the VOLATILE attribute.
+ checker.set_isVolatile(base->attrs().test(Attr::VOLATILE));
+ }
checker.set_isBoundsRemapping(isBoundsRemapping);
checker.set_isAssumedRank(isAssumedRank);
bool lhsOk{checker.CheckLeftHandSide(lhs)};
diff --git a/flang/test/Semantics/assign02.f90 b/flang/test/Semantics/assign02.f90
index d83d126e2734c..9fa672025bfe7 100644
--- a/flang/test/Semantics/assign02.f90
+++ b/flang/test/Semantics/assign02.f90
@@ -8,9 +8,11 @@ module m1
type t2
sequence
real :: t2Field
+ real, pointer :: t2FieldPtr
end type
type t3
type(t2) :: t3Field
+ type(t2), pointer :: t3FieldPtr
end type
contains
@@ -198,6 +200,14 @@ subroutine s13
q2 => y%t3Field
!OK:
q3 => y
+ !ERROR: VOLATILE target associated with non-VOLATILE pointer
+ p3%t3FieldPtr => y%t3Field
+ !ERROR: VOLATILE target associated with non-VOLATILE pointer
+ p3%t3FieldPtr%t2FieldPtr => y%t3Field%t2Field
+ !OK
+ q3%t3FieldPtr => y%t3Field
+ !OK
+ q3%t3FieldPtr%t2FieldPtr => y%t3Field%t2Field
end
end
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This patch fixed the incorrect warning. Thanks!
The standard says in [8.5.20 VOLATILE attribute]:
If an object has the VOLATILE attribute, then all of its sub-objects also have the VOLATILE attribute.
This code takes this into account and uses the volatility of the base of the designator instead of that of the component. In fact, fields in a structure are not allowed to have the volatile attribute. So given the code,
A%B => t
, symbolB
could never directly have the volatile attribute, and the volatility ofA
indicates the volatility ofB
.This PR should address the comments on this PR #132486