[flang-commits] [flang] [flang][rfc] Add represention of volatile references (PR #132486)
Slava Zakharin via flang-commits
flang-commits at lists.llvm.org
Thu Apr 10 20:45:53 PDT 2025
================
@@ -0,0 +1,113 @@
+! RUN: bbc %s -o - | FileCheck %s
+
+program p
+ integer,volatile::i,arr(10)
+ integer,volatile,target::tgt(10)
+ integer,volatile,pointer,dimension(:)::ptr
+ ptr => tgt
+ i=0
+ arr=1
+ call d(arr)
+ call e(arr)
+ call f(arr)
+ call g(ptr)
+contains
+ subroutine d(arr)
+ integer,volatile::arr(10)
+ end subroutine
+ subroutine e(arr)
+ integer,volatile,dimension(:)::arr
+ end subroutine
+ subroutine f(arr)
+ integer,volatile,dimension(10)::arr
+ end subroutine
+ subroutine g(arr)
+ integer,volatile,dimension(:),pointer::arr
+ end subroutine
+end program
+
+! CHECK-LABEL: func.func @_QQmain() attributes {fir.bindc_name = "p"} {
+! CHECK: %[[VAL_0:.*]] = arith.constant 1 : i32
+! CHECK: %[[VAL_1:.*]] = arith.constant 0 : i32
+! CHECK: %[[VAL_2:.*]] = arith.constant 10 : index
+! CHECK: %[[VAL_3:.*]] = fir.address_of(@_QFEarr) : !fir.ref<!fir.array<10xi32>>
+! CHECK: %[[VAL_4:.*]] = fir.shape %[[VAL_2]] : (index) -> !fir.shape<1>
+! CHECK: %[[VAL_5:.*]] = fir.volatile_cast %[[VAL_3]] : (!fir.ref<!fir.array<10xi32>>) -> !fir.ref<!fir.array<10xi32>, volatile>
+! CHECK: %[[VAL_6:.*]]:2 = hlfir.declare %[[VAL_5]](%[[VAL_4]]) {fortran_attrs = #fir.var_attrs<volatile>, uniq_name = "_QFEarr"} : (!fir.ref<!fir.array<10xi32>, volatile>, !fir.shape<1>) -> (!fir.ref<!fir.array<10xi32>, volatile>, !fir.ref<!fir.array<10xi32>, volatile>)
+! CHECK: %[[VAL_7:.*]] = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFEi"}
+! CHECK: %[[VAL_8:.*]] = fir.volatile_cast %[[VAL_7]] : (!fir.ref<i32>) -> !fir.ref<i32, volatile>
+! CHECK: %[[VAL_9:.*]]:2 = hlfir.declare %[[VAL_8]] {fortran_attrs = #fir.var_attrs<volatile>, uniq_name = "_QFEi"} : (!fir.ref<i32, volatile>) -> (!fir.ref<i32, volatile>, !fir.ref<i32, volatile>)
+! CHECK: %[[VAL_10:.*]] = fir.address_of(@_QFEptr) : !fir.ref<!fir.box<!fir.ptr<!fir.array<?xi32>>>>
+! CHECK: %[[VAL_11:.*]] = fir.volatile_cast %[[VAL_10]] : (!fir.ref<!fir.box<!fir.ptr<!fir.array<?xi32>>>>) -> !fir.ref<!fir.box<!fir.ptr<!fir.array<?xi32>>, volatile>, volatile>
+! CHECK: %[[VAL_12:.*]]:2 = hlfir.declare %[[VAL_11]] {fortran_attrs = #fir.var_attrs<pointer, volatile>, uniq_name = "_QFEptr"} : (!fir.ref<!fir.box<!fir.ptr<!fir.array<?xi32>>, volatile>, volatile>) -> (!fir.ref<!fir.box<!fir.ptr<!fir.array<?xi32>>, volatile>, volatile>, !fir.ref<!fir.box<!fir.ptr<!fir.array<?xi32>>, volatile>, volatile>)
----------------
vzakhari wrote:
I just tried this example:
```
integer,target::tgt(10)
integer,volatile,target::tgtv(10)
integer,pointer,dimension(:)::ptr
integer,volatile,pointer,dimension(:)::ptrv
ptr => tgtv
ptrv => tgt
end
```
The frontened compiles it without a warning/error, so it looks like there are no semantics checks for the mismatching associations.
My concern is caused by the following statement in the standard (`8.5.20 VOLATILE attribute`):
```
15 A pointer should have the VOLATILE attribute if its target has the VOLATILE attribute. If, by means not
16 specified by the program, the target is referenced, defined, or becomes undefined, the pointer shall have the
17 VOLATILE attribute. All members of an EQUIVALENCE group should have the VOLATILE attribute if any member has the
18 VOLATILE attribute.
```
So I think `ptr => tgtv` should be an error (due to line 15).
For `ptrv => tgt`, I just want to make sure we generate proper casts/embox/store.
https://github.com/llvm/llvm-project/pull/132486
More information about the flang-commits
mailing list