Skip to content

[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

Merged
merged 1 commit into from
May 10, 2025
Merged
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
7 changes: 6 additions & 1 deletion flang/lib/Semantics/pointer-assignment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)};
Expand Down
10 changes: 10 additions & 0 deletions flang/test/Semantics/assign02.f90
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down