[flang-commits] [flang] [flang][rfc] Add represention of volatile references (PR #132486)

Asher Mancinelli via flang-commits flang-commits at lists.llvm.org
Tue Mar 25 14:09:05 PDT 2025


================
@@ -0,0 +1,21 @@
+// RUN: fir-opt --convert-hlfir-to-fir %s -o - | FileCheck %s
+func.func @foo() {
+  %true = arith.constant true
+  %false = arith.constant false
+  %0 = fir.alloca !fir.logical<4> {bindc_name = "a", uniq_name = "_QFEa"}
+  %1 = fir.convert %0 : (!fir.ref<!fir.logical<4>>) -> !fir.ref<!fir.logical<4>, volatile>
+  %2:2 = hlfir.declare %1 {fortran_attrs = #fir.var_attrs<volatile>, uniq_name = "_QFEa"} : (!fir.ref<!fir.logical<4>, volatile>) -> (!fir.ref<!fir.logical<4>, volatile>, !fir.ref<!fir.logical<4>, volatile>)
----------------
ashermancinelli wrote:

`volatile_cast` is helpful. Regular fir.convert will fail to verify it an implicit conversion between volatile non-volatile ops is added, and this is the error message we will get.
```
llvm-project/flang/test/Fir/volatile.fir:8:8: error: 'fir.convert' op cannot convert between volatile and non-volatile types, use fir.volatile_cast instead '!fir.ref<!fir.logical<4>>' / '!fir.ref<!fir.logical<4>, volatile>'
  %1 = fir.convert %0 : (!fir.ref<!fir.logical<4>>) -> !fir.ref<!fir.logical<4>, volatile>
       ^
```
@vzakhari does this look good to you?

https://github.com/llvm/llvm-project/pull/132486


More information about the flang-commits mailing list