diff --git a/flang/lib/Optimizer/Dialect/FIRType.cpp b/flang/lib/Optimizer/Dialect/FIRType.cpp --- a/flang/lib/Optimizer/Dialect/FIRType.cpp +++ b/flang/lib/Optimizer/Dialect/FIRType.cpp @@ -948,6 +948,10 @@ if (ty.getNumResults() == 0) return false; auto resultType = ty.getResult(0); + // FIXME: The interoperable derived type needs more investigations and tests. + // The derived type without BIND attribute may also not be abstract result. + if (fir::isa_builtin_cptr_type(resultType)) + return false; return resultType.isa(); } diff --git a/flang/test/Fir/abstract-results.fir b/flang/test/Fir/abstract-results.fir --- a/flang/test/Fir/abstract-results.fir +++ b/flang/test/Fir/abstract-results.fir @@ -202,6 +202,17 @@ // FUNC-BOX-NOT: fir.save_result } +func.func private @rettcptr() -> !fir.type<_QM__fortran_builtinsT__builtin_c_ptr{__address:i64}> attributes {fir.bindc_name = "rettcptr"} + +// FUNC-REF-LABEL: func @_QPtest_return_cptr() { +// FUNC-BOX-LABEL: func @_QPtest_return_cptr() { +func.func @_QPtest_return_cptr() { + // FUNC-REF: [[VAL:.*]] = fir.call @rettcptr() : () -> !fir.type<_QM__fortran_builtinsT__builtin_c_ptr{__address:i64}> + // FUNC-BOX: [[VAL:.*]] = fir.call @rettcptr() : () -> !fir.type<_QM__fortran_builtinsT__builtin_c_ptr{__address:i64}> + %1 = fir.call @rettcptr() : () -> !fir.type<_QM__fortran_builtinsT__builtin_c_ptr{__address:i64}> + return +} + // ------------------------ Test fir.address_of rewrite ------------------------ func.func private @takesfuncarray((i32) -> !fir.array)