diff --git a/flang/lib/Optimizer/OpenACC/Support/FIROpenACCTypeInterfaces.cpp b/flang/lib/Optimizer/OpenACC/Support/FIROpenACCTypeInterfaces.cpp index 684de4b2fd4a5..89aa010e7d9a1 100644 --- a/flang/lib/Optimizer/OpenACC/Support/FIROpenACCTypeInterfaces.cpp +++ b/flang/lib/Optimizer/OpenACC/Support/FIROpenACCTypeInterfaces.cpp @@ -365,6 +365,14 @@ getBaseRef(mlir::TypedValue varPtr) { // object, get the base object. return op.getRef(); }) + .Case([&](auto op) -> mlir::Value { + // Strip the conversion and recursively check the operand + if (auto ptrLikeOperand = mlir::dyn_cast_if_present< + mlir::TypedValue>( + op.getValue())) + return getBaseRef(ptrLikeOperand); + return varPtr; + }) .Default([&](mlir::Operation *) { return varPtr; }); return baseRef; diff --git a/flang/test/Fir/OpenACC/openacc-type-categories.mlir b/flang/test/Fir/OpenACC/openacc-type-categories.mlir new file mode 100644 index 0000000000000..2275039dc3aff --- /dev/null +++ b/flang/test/Fir/OpenACC/openacc-type-categories.mlir @@ -0,0 +1,36 @@ +// 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 { + fir.global linkonce @test_string constant : !fir.char<1,26> { + %0 = fir.string_lit "hello_world_test_string\00"(26) : !fir.char<1,26> + fir.has_value %0 : !fir.char<1,26> + } + + // Test global constant string with pointer conversion + func.func @_QPtest_global_string_ptr() { + %0 = fir.address_of(@test_string) : !fir.ref> + %1 = fir.convert %0 : (!fir.ref>) -> !fir.ref + %2 = acc.copyin varPtr(%1 : !fir.ref) -> !fir.ref {name = "test_string", structured = false} + acc.enter_data dataOperands(%2 : !fir.ref) + return + } + + // CHECK: Visiting: %{{.*}} = acc.copyin varPtr(%{{.*}} : !fir.ref) -> !fir.ref {name = "test_string", structured = false} + // CHECK: Pointer-like and Mappable: !fir.ref + // CHECK: Type category: nonscalar + + // Test array with pointer conversion + func.func @_QPtest_alloca_array_ptr() { + %c10 = arith.constant 10 : index + %0 = fir.alloca !fir.array<10xf32> {bindc_name = "local_array", uniq_name = "_QFtest_alloca_array_ptrElocal_array"} + %1 = fir.convert %0 : (!fir.ref>) -> !fir.ref + %2 = acc.copyin varPtr(%1 : !fir.ref) -> !fir.ref {name = "local_array", structured = false} + acc.enter_data dataOperands(%2 : !fir.ref) + return + } + + // CHECK: Visiting: %{{.*}} = acc.copyin varPtr(%{{.*}} : !fir.ref) -> !fir.ref {name = "local_array", structured = false} + // CHECK: Pointer-like and Mappable: !fir.ref + // CHECK: Type category: array +}