Index: flang/lib/Lower/CallInterface.cpp =================================================================== --- flang/lib/Lower/CallInterface.cpp +++ flang/lib/Lower/CallInterface.cpp @@ -929,13 +929,15 @@ PassEntityBy passBy = PassEntityBy::BaseAddress; Property prop = Property::BaseAddress; if (isValueAttr) { + bool isBuiltinCptrType = fir::isa_builtin_cptr_type(type); if (isBindC || (!type.isa() && !obj.attrs.test(Attrs::Optional) && - dynamicType.category() != - Fortran::common::TypeCategory::Derived)) { + (dynamicType.category() != + Fortran::common::TypeCategory::Derived || + isBuiltinCptrType))) { passBy = PassEntityBy::Value; prop = Property::Value; - if (fir::isa_builtin_cptr_type(type)) { + if (isBuiltinCptrType) { auto recTy = type.dyn_cast(); mlir::Type fieldTy = recTy.getTypeList()[0].second; passType = fir::ReferenceType::get(fieldTy); Index: flang/test/Lower/call-by-value.f90 =================================================================== --- flang/test/Lower/call-by-value.f90 +++ flang/test/Lower/call-by-value.f90 @@ -73,3 +73,20 @@ character(1), value :: x call internal_call4(x) end + +! CHECK-LABEL: func.func @_QPtest_cptr_value( +! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref {fir.bindc_name = "x"}) { +! CHECK: %[[VAL_1:.*]] = fir.alloca !fir.type<_QM__fortran_builtinsT__builtin_c_ptr{__address:i64}> +! CHECK: %[[VAL_2:.*]] = fir.field_index __address, !fir.type<_QM__fortran_builtinsT__builtin_c_ptr{__address:i64}> +! CHECK: %[[VAL_3:.*]] = fir.coordinate_of %[[VAL_1]], %[[VAL_2]] : (!fir.ref>, !fir.field) -> !fir.ref +! CHECK: %[[VAL_4:.*]] = fir.convert %[[VAL_0]] : (!fir.ref) -> i64 +! CHECK: fir.store %[[VAL_4]] to %[[VAL_3]] : !fir.ref +! CHECK: fir.call @_QPinternal_call5(%[[VAL_1]]) : (!fir.ref>) -> () +! CHECK: return +! CHECK: } + +subroutine test_cptr_value(x) + use iso_c_binding + type(c_ptr), value :: x + call internal_call5(x) +end