Skip to content

Commit c0e52f3

Browse files
[flang] Component references are volatile if their parent is (#138339)
Component references inherit volatility from their base derived types. Moved the base type volatility check before the box type is built, and merge it (instead of overwrite it) with the volatility of the base type.
1 parent 0926d94 commit c0e52f3

File tree

2 files changed

+54
-6
lines changed

2 files changed

+54
-6
lines changed

flang/lib/Lower/ConvertExprToHLFIR.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,12 @@ class HlfirDesignatorBuilder {
236236
isVolatile = true;
237237
}
238238

239+
// Check if the base type is volatile
240+
if (partInfo.base.has_value()) {
241+
mlir::Type baseType = partInfo.base.value().getType();
242+
isVolatile = isVolatile || fir::isa_volatile_type(baseType);
243+
}
244+
239245
// Arrays with non default lower bounds or dynamic length or dynamic extent
240246
// need a fir.box to hold the dynamic or lower bound information.
241247
if (fir::hasDynamicSize(resultValueType) ||
@@ -249,12 +255,6 @@ class HlfirDesignatorBuilder {
249255
/*namedConstantSectionsAreAlwaysContiguous=*/false))
250256
return fir::BoxType::get(resultValueType, isVolatile);
251257

252-
// Check if the base type is volatile
253-
if (partInfo.base.has_value()) {
254-
mlir::Type baseType = partInfo.base.value().getType();
255-
isVolatile = fir::isa_volatile_type(baseType);
256-
}
257-
258258
// Other designators can be handled as raw addresses.
259259
return fir::ReferenceType::get(resultValueType, isVolatile);
260260
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
! RUN: bbc --strict-fir-volatile-verifier %s -o - | FileCheck %s
2+
! Ensure member access of a volatile derived type is volatile.
3+
type t
4+
integer :: e(4)=2
5+
end type t
6+
type(t), volatile :: f
7+
call test (f%e(::2))
8+
contains
9+
subroutine test(v)
10+
integer, asynchronous :: v(:)
11+
end subroutine
12+
end
13+
! CHECK-LABEL: func.func @_QQmain() {
14+
! CHECK: %[[VAL_0:.*]] = arith.constant 4 : index
15+
! CHECK: %[[VAL_1:.*]] = arith.constant 1 : index
16+
! CHECK: %[[VAL_2:.*]] = arith.constant 2 : index
17+
! CHECK: %[[VAL_3:.*]] = arith.constant 0 : index
18+
! CHECK: %[[VAL_4:.*]] = fir.dummy_scope : !fir.dscope
19+
! CHECK: %[[VAL_5:.*]] = fir.address_of(@_QFE.b.t.e) : !fir.ref<!fir.array<2x1x!fir.type<_QM__fortran_type_infoTvalue{genre:i8,__padding0:!fir.array<7xi8>,value:i64}>>>
20+
! CHECK: %[[VAL_6:.*]] = fir.shape_shift %[[VAL_3]], %[[VAL_2]], %[[VAL_3]], %[[VAL_1]] : (index, index, index, index) -> !fir.shapeshift<2>
21+
! CHECK: %[[VAL_7:.*]]:2 = hlfir.declare %[[VAL_5]](%[[VAL_6]]) {fortran_attrs = #fir.var_attrs<target>, uniq_name = "_QFE.b.t.e"} :
22+
! CHECK: %[[VAL_8:.*]] = fir.address_of(@_QFE.n.e) : !fir.ref<!fir.char<1>>
23+
! CHECK: %[[VAL_9:.*]]:2 = hlfir.declare %[[VAL_8]] typeparams %[[VAL_1]] {fortran_attrs = #fir.var_attrs<target>, uniq_name = "_QFE.n.e"} : (!fir.ref<!fir.char<1>>, index) -> (!fir.ref<!fir.char<1>>, !fir.ref<!fir.char<1>>)
24+
! CHECK: %[[VAL_10:.*]] = fir.address_of(@_QFE.di.t.e) : !fir.ref<!fir.array<4xi32>>
25+
! CHECK: %[[VAL_11:.*]] = fir.shape %[[VAL_0]] : (index) -> !fir.shape<1>
26+
! CHECK: %[[VAL_12:.*]]:2 = hlfir.declare %[[VAL_10]](%[[VAL_11]]) {fortran_attrs = #fir.var_attrs<target>, uniq_name = "_QFE.di.t.e"} : (!fir.ref<!fir.array<4xi32>>, !fir.shape<1>) -> (!fir.ref<!fir.array<4xi32>>, !fir.ref<!fir.array<4xi32>>)
27+
! CHECK: %[[VAL_13:.*]] = fir.address_of(@_QFE.n.t) : !fir.ref<!fir.char<1>>
28+
! CHECK: %[[VAL_14:.*]]:2 = hlfir.declare %[[VAL_13]] typeparams %[[VAL_1]] {fortran_attrs = #fir.var_attrs<target>, uniq_name = "_QFE.n.t"} : (!fir.ref<!fir.char<1>>, index) -> (!fir.ref<!fir.char<1>>, !fir.ref<!fir.char<1>>)
29+
! CHECK: %[[VAL_15:.*]] = fir.alloca !fir.type<_QFTt{e:!fir.array<4xi32>}> {bindc_name = "f", uniq_name = "_QFEf"}
30+
! CHECK: %[[VAL_16:.*]] = fir.volatile_cast %[[VAL_15]] : (!fir.ref<!fir.type<_QFTt{e:!fir.array<4xi32>}>>) -> !fir.ref<!fir.type<_QFTt{e:!fir.array<4xi32>}>, volatile>
31+
! CHECK: %[[VAL_17:.*]]:2 = hlfir.declare %[[VAL_16]] {fortran_attrs = #fir.var_attrs<volatile>, uniq_name = "_QFEf"} : (!fir.ref<!fir.type<_QFTt{e:!fir.array<4xi32>}>, volatile>) -> (!fir.ref<!fir.type<_QFTt{e:!fir.array<4xi32>}>, volatile>, !fir.ref<!fir.type<_QFTt{e:!fir.array<4xi32>}>, volatile>)
32+
! CHECK: %[[VAL_18:.*]] = fir.address_of(@_QQ_QFTt.DerivedInit) : !fir.ref<!fir.type<_QFTt{e:!fir.array<4xi32>}>>
33+
! CHECK: fir.copy %[[VAL_18]] to %[[VAL_17]]#0 no_overlap : !fir.ref<!fir.type<_QFTt{e:!fir.array<4xi32>}>>, !fir.ref<!fir.type<_QFTt{e:!fir.array<4xi32>}>, volatile>
34+
! CHECK: %[[VAL_20:.*]] = fir.shape_shift %[[VAL_3]], %[[VAL_1]] : (index, index) -> !fir.shapeshift<1>
35+
! CHECK: %[[VAL_21:.*]]:2 = hlfir.declare %{{.+}}(%[[VAL_20]]) {fortran_attrs = #fir.var_attrs<target>, uniq_name = "_QFE.c.t"} :
36+
! CHECK: %[[VAL_24:.*]] = fir.shape %[[VAL_2]] : (index) -> !fir.shape<1>
37+
! CHECK: %[[VAL_25:.*]] = hlfir.designate %[[VAL_17]]#0{"e"} <%[[VAL_11]]> (%[[VAL_1]]:%[[VAL_0]]:%[[VAL_2]]) shape %[[VAL_24]] : (!fir.ref<!fir.type<_QFTt{e:!fir.array<4xi32>}>, volatile>, !fir.shape<1>, index, index, index, !fir.shape<1>) -> !fir.box<!fir.array<2xi32>, volatile>
38+
! CHECK: %[[VAL_26:.*]] = fir.volatile_cast %[[VAL_25]] : (!fir.box<!fir.array<2xi32>, volatile>) -> !fir.box<!fir.array<2xi32>>
39+
! CHECK: %[[VAL_27:.*]] = fir.convert %[[VAL_26]] : (!fir.box<!fir.array<2xi32>>) -> !fir.box<!fir.array<?xi32>>
40+
! CHECK: fir.call @_QFPtest(%[[VAL_27]]) fastmath<contract> : (!fir.box<!fir.array<?xi32>>) -> ()
41+
! CHECK: return
42+
! CHECK: }
43+
! CHECK-LABEL: func.func private @_QFPtest(
44+
! CHECK-SAME: %[[VAL_0:[0-9]+|[a-zA-Z$._-][a-zA-Z0-9$._-]*]]: !fir.box<!fir.array<?xi32>> {fir.asynchronous, fir.bindc_name = "v"}) attributes {fir.host_symbol = @_QQmain, llvm.linkage = #llvm.linkage<internal>} {
45+
! CHECK: %[[VAL_1:.*]] = fir.dummy_scope : !fir.dscope
46+
! CHECK: %[[VAL_2:.*]]:2 = hlfir.declare %[[VAL_0]] dummy_scope %[[VAL_1]] {fortran_attrs = #fir.var_attrs<asynchronous>, uniq_name = "_QFFtestEv"} : (!fir.box<!fir.array<?xi32>>, !fir.dscope) -> (!fir.box<!fir.array<?xi32>>, !fir.box<!fir.array<?xi32>>)
47+
! CHECK: return
48+
! CHECK: }

0 commit comments

Comments
 (0)