[flang-commits] [flang] [llvm] [Flang][OpenMP] Fix mapping of character type with LEN > 1 specified (PR #154172)
Pranav Bhandarkar via flang-commits
flang-commits at lists.llvm.org
Thu Sep 4 21:05:44 PDT 2025
================
@@ -69,13 +84,58 @@ struct MapInfoOpConversion
return mlir::failure();
llvm::SmallVector<mlir::NamedAttribute> newAttrs;
- mlir::omp::MapInfoOp newOp;
+ mlir::omp::MapBoundsOp mapBoundsOp;
for (mlir::NamedAttribute attr : curOp->getAttrs()) {
if (auto typeAttr = mlir::dyn_cast<mlir::TypeAttr>(attr.getValue())) {
mlir::Type newAttr;
if (fir::isTypeWithDescriptor(typeAttr.getValue())) {
newAttr = lowerTy().convertBoxTypeAsStruct(
mlir::cast<fir::BaseBoxType>(typeAttr.getValue()));
+ } else if (fir::isa_char_string(fir::unwrapSequenceType(
+ fir::unwrapPassByRefType(typeAttr.getValue()))) &&
+ !characterWithDynamicLen(
+ fir::unwrapPassByRefType(typeAttr.getValue()))) {
+ // Characters with a LEN param are represented as char
+ // arrays/strings, the initial lowering doesn't generate
+ // bounds for these, however, we require them to map the
+ // data appropriately in the later lowering stages. This
+ // is to prevent the need for unecessary caveats
+ // specific to Flang. We also strip the array from the
+ // type so that all variations of strings are treated
+ // identically and there's no caveats or specialisations
+ // required in the later stages. As an example, Boxed
+ // char strings will emit a single char array no matter
+ // the number of dimensions caused by additional array
+ // dimensions which needs specialised for, as it differs
+ // from the non-box variation which will emit each array
+ // wrapping the character array, e.g. given a type of
+ // the same dimensions, if one is boxed, the types would
----------------
bhandarkar-pranav wrote:
I think I understand now. What you are saying is that essentially, in the case of strings (CHARACTER with LEN parameter), we cannot generalize/unify the translation of an `n-dimensional array of bytes (i8 or chars)` which is also a `n-1 dimensional array of CHARACTERS with LEN parameters` because the innermost (constant) size/bound is baked into the type but not pulled out as a bound.
So we dive into the `fir.char<>` type and pull out the constant as a bound so that the translation can now be simplified by generalizing it to the n-dimensional mapping of i8 types, correct?
https://github.com/llvm/llvm-project/pull/154172
More information about the flang-commits
mailing list