[flang-commits] [flang] [flang] Don't pass a hidden length for BIND(C) character dummy arguments (PR #224582)
Tom Eccles via flang-commits
flang-commits at lists.llvm.org
Mon Sep 21 05:26:19 PDT 2026
================
@@ -1274,6 +1274,15 @@ class Fortran::lower::CallInterfaceImpl {
fir::CharacterType::getSingleton(&mlirContext, dynamicType.kind());
addFirOperand(charTy, nextPassedArgPosition(), Property::Value, attrs);
addPassedArg(PassEntityBy::Value, entity, characteristics);
+ } else if (isBindC && dynamicType.knownLength().value_or(0) == 1) {
+ // Pass as fir.ref: a BIND(C) procedure uses the C calling convention,
+ // which has no hidden length argument. Semantics requires a BIND(C)
+ // character dummy to have a length of 1, so the length is already
+ // known to both sides and carries no information.
+ mlir::Type refTy = fir::ReferenceType::get(type);
+ addFirOperand(refTy, nextPassedArgPosition(), Property::BaseAddress,
+ attrs);
----------------
tblah wrote:
I am not sure that the string is guaranteed to be null terminated as the C programme would expect. I think it needs a copy with the extra NULL character.
https://github.com/llvm/llvm-project/pull/224582
More information about the flang-commits
mailing list