Skip to content
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,14 @@ getBaseRef(mlir::TypedValue<mlir::acc::PointerLikeType> varPtr) {
// calculation op.
mlir::Value baseRef =
llvm::TypeSwitch<mlir::Operation *, mlir::Value>(op)
.Case<fir::DeclareOp>([&](auto op) {
// If this declare binds a view with an underlying storage operand,
// treat that storage as the base reference. Otherwise, fall back
// to the declared memref.
if (auto storage = op.getStorage())
return storage;
return op.getMemref();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not desirable because in FIR, having access to the fir.declare as the "base reference" allows us to get all of the Fortran properties. I would suggest returning varPtr instead.

})
.Case<hlfir::DesignateOp>([&](auto op) {
// Get the base object.
return op.getMemref();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Use --mlir-disable-threading so that the diagnostic printing is serialized.
// RUN: fir-opt %s -pass-pipeline='builtin.module(test-fir-openacc-interfaces)' -split-input-file --mlir-disable-threading 2>&1 | FileCheck %s

module {
// Build a scalar view via fir.declare with a storage operand into an array of i8
func.func @_QPdeclare_with_storage_is_nonscalar() {
%c0 = arith.constant 0 : index
%arr = fir.alloca !fir.array<4xi8>
%elem_i8 = fir.coordinate_of %arr, %c0 : (!fir.ref<!fir.array<4xi8>>, index) -> !fir.ref<i8>
%elem_f32 = fir.convert %elem_i8 : (!fir.ref<i8>) -> !fir.ref<f32>
%view = fir.declare %elem_f32 storage(%arr[0]) {uniq_name = "_QFpi"}
: (!fir.ref<f32>, !fir.ref<!fir.array<4xi8>>) -> !fir.ref<f32>
// Force interface query through an acc op that prints type category
%cp = acc.copyin varPtr(%view : !fir.ref<f32>) -> !fir.ref<f32> {name = "pi", structured = false}
acc.enter_data dataOperands(%cp : !fir.ref<f32>)
return
}

// CHECK: Visiting: %{{.*}} = acc.copyin varPtr(%{{.*}} : !fir.ref<f32>) -> !fir.ref<f32> {name = "pi", structured = false}
// CHECK: Pointer-like and Mappable: !fir.ref<f32>
// CHECK: Type category: array
}