diff --git a/flang/include/flang/Lower/BoxAnalyzer.h b/flang/include/flang/Lower/BoxAnalyzer.h --- a/flang/include/flang/Lower/BoxAnalyzer.h +++ b/flang/include/flang/Lower/BoxAnalyzer.h @@ -490,7 +490,7 @@ sym.GetType()->characterTypeSpec().length(); if (Fortran::semantics::MaybeIntExpr expr = lenParam.GetExplicit()) return {Fortran::evaluate::AsGenericExpr(std::move(*expr))}; - // For assumed length parameters, the length comes from the initialization + // For assumed LEN parameters, the length comes from the initialization // expression. if (sym.attrs().test(Fortran::semantics::Attr::PARAMETER)) if (const auto *objectDetails = diff --git a/flang/include/flang/Optimizer/Builder/FIRBuilder.h b/flang/include/flang/Optimizer/Builder/FIRBuilder.h --- a/flang/include/flang/Optimizer/Builder/FIRBuilder.h +++ b/flang/include/flang/Optimizer/Builder/FIRBuilder.h @@ -445,7 +445,7 @@ /// available without having to read any fir.box values). Empty if \p exv has no /// LEN parameters or if they are all deferred. llvm::SmallVector -getNonDeferredLengthParams(const fir::ExtendedValue &exv); +getNonDeferredLenParams(const fir::ExtendedValue &exv); //===----------------------------------------------------------------------===// // String literal helper helpers diff --git a/flang/include/flang/Optimizer/Builder/MutableBox.h b/flang/include/flang/Optimizer/Builder/MutableBox.h --- a/flang/include/flang/Optimizer/Builder/MutableBox.h +++ b/flang/include/flang/Optimizer/Builder/MutableBox.h @@ -98,7 +98,7 @@ mlir::Location loc, const fir::MutableBoxValue &box, mlir::ValueRange shape, - mlir::ValueRange lengthParams); + mlir::ValueRange lenParams); void finalizeRealloc(fir::FirOpBuilder &builder, mlir::Location loc, const fir::MutableBoxValue &box, mlir::ValueRange lbounds, diff --git a/flang/lib/Lower/Bridge.cpp b/flang/lib/Lower/Bridge.cpp --- a/flang/lib/Lower/Bridge.cpp +++ b/flang/lib/Lower/Bridge.cpp @@ -468,7 +468,7 @@ [&](const auto &) -> fir::ExtendedValue { mlir::Value temp = allocate(fir::factory::getExtents(loc, *builder, hexv), - fir::getTypeParams(hexv)); + fir::factory::getTypeParams(loc, *builder, hexv)); return fir::substBase(hexv, temp); }); @@ -494,7 +494,7 @@ // 3) Perform the assignment. builder->setInsertionPointAfter(fir::getBase(exv).getDefiningOp()); - mlir::Location loc = getCurrentLocation(); + mlir::Location loc = genLocation(sym.name()); mlir::Type symType = genType(sym); if (auto seqTy = symType.dyn_cast()) { Fortran::lower::StatementContext stmtCtx; diff --git a/flang/lib/Lower/ConvertExpr.cpp b/flang/lib/Lower/ConvertExpr.cpp --- a/flang/lib/Lower/ConvertExpr.cpp +++ b/flang/lib/Lower/ConvertExpr.cpp @@ -892,7 +892,7 @@ } static bool - isDerivedTypeWithLengthParameters(const Fortran::semantics::Symbol &sym) { + isDerivedTypeWithLenParameters(const Fortran::semantics::Symbol &sym) { if (const Fortran::semantics::DeclTypeSpec *declTy = sym.GetType()) if (const Fortran::semantics::DerivedTypeSpec *derived = declTy->AsDerived()) @@ -943,7 +943,7 @@ continue; } - if (isDerivedTypeWithLengthParameters(sym)) + if (isDerivedTypeWithLenParameters(sym)) TODO(loc, "component with length parameters in structure constructor"); if (isBuiltinCPtr(sym)) { @@ -1013,7 +1013,7 @@ if (sym.test(Fortran::semantics::Symbol::Flag::ParentComp)) TODO(loc, "parent component in structure constructor"); - if (isDerivedTypeWithLengthParameters(sym)) + if (isDerivedTypeWithLenParameters(sym)) TODO(loc, "component with length parameters in structure constructor"); llvm::StringRef name = toStringRef(sym.name()); @@ -2136,7 +2136,7 @@ mlir::Value box = builder.createBox(loc, exv); return fir::BoxValue( box, fir::factory::getNonDefaultLowerBounds(builder, loc, exv), - fir::factory::getNonDeferredLengthParams(exv)); + fir::factory::getNonDeferredLenParams(exv)); } /// Generate a call to a Fortran intrinsic or intrinsic module procedure. diff --git a/flang/lib/Lower/ConvertVariable.cpp b/flang/lib/Lower/ConvertVariable.cpp --- a/flang/lib/Lower/ConvertVariable.cpp +++ b/flang/lib/Lower/ConvertVariable.cpp @@ -48,7 +48,6 @@ return fir::getBase(Fortran::lower::createSomeExtendedExpression( loc, converter, expr, symMap, context)); } - /// Does this variable have a default initialization? static bool hasDefaultInitialization(const Fortran::semantics::Symbol &sym) { if (sym.has() && sym.size()) @@ -103,6 +102,15 @@ llvm::StringRef globalName, mlir::StringAttr linkage); +static mlir::Location genLocation(Fortran::lower::AbstractConverter &converter, + const Fortran::semantics::Symbol &sym) { + // Compiler generated name cannot be used as source location, their name + // is not pointing to the source files. + if (!sym.test(Fortran::semantics::Symbol::Flag::CompilerCreated)) + return converter.genLocation(sym.name()); + return converter.getCurrentLocation(); +} + /// Create the global op declaration without any initializer static fir::GlobalOp declareGlobal(Fortran::lower::AbstractConverter &converter, const Fortran::lower::pft::Variable &var, @@ -117,7 +125,7 @@ linkage == builder.createLinkOnceLinkage()) return defineGlobal(converter, var, globalName, linkage); const Fortran::semantics::Symbol &sym = var.getSymbol(); - mlir::Location loc = converter.genLocation(sym.name()); + mlir::Location loc = genLocation(converter, sym); // Resolve potential host and module association before checking that this // symbol is an object of a function pointer. const Fortran::semantics::Symbol &ultimate = sym.GetUltimate(); @@ -371,7 +379,7 @@ mlir::StringAttr linkage) { fir::FirOpBuilder &builder = converter.getFirOpBuilder(); const Fortran::semantics::Symbol &sym = var.getSymbol(); - mlir::Location loc = converter.genLocation(sym.name()); + mlir::Location loc = genLocation(converter, sym); bool isConst = isConstant(sym); fir::GlobalOp global = builder.getNamedGlobal(globalName); mlir::Type symTy = converter.genType(var); @@ -508,7 +516,7 @@ assert(!var.isAlias() && "must be handled in instantiateAlias"); fir::FirOpBuilder &builder = converter.getFirOpBuilder(); std::string globalName = Fortran::lower::mangle::mangleName(sym); - mlir::Location loc = converter.genLocation(sym.name()); + mlir::Location loc = genLocation(converter, sym); fir::GlobalOp global = builder.getNamedGlobal(globalName); mlir::StringAttr linkage = getLinkageAttribute(builder, var); if (var.isModuleVariable()) { @@ -780,7 +788,7 @@ fir::FirOpBuilder &builder = converter.getFirOpBuilder(); assert(var.isAlias()); const Fortran::semantics::Symbol &sym = var.getSymbol(); - const mlir::Location loc = converter.genLocation(sym.name()); + const mlir::Location loc = genLocation(converter, sym); mlir::IndexType idxTy = builder.getIndexType(); std::size_t aliasOffset = var.getAlias(); mlir::Value store = getAggregateStore(storeMap, var); @@ -1228,7 +1236,7 @@ mlir::Value preAlloc) { fir::FirOpBuilder &builder = converter.getFirOpBuilder(); const Fortran::semantics::Symbol &sym = var.getSymbol(); - const mlir::Location loc = converter.genLocation(sym.name()); + const mlir::Location loc = genLocation(converter, sym); mlir::IndexType idxTy = builder.getIndexType(); const bool isDeclaredDummy = Fortran::semantics::IsDummy(sym); // An active dummy from the current entry point. diff --git a/flang/lib/Lower/HostAssociations.cpp b/flang/lib/Lower/HostAssociations.cpp --- a/flang/lib/Lower/HostAssociations.cpp +++ b/flang/lib/Lower/HostAssociations.cpp @@ -222,8 +222,7 @@ }; /// Is \p sym a derived type entity with length parameters ? -static bool -isDerivedWithLengthParameters(const Fortran::semantics::Symbol &sym) { +static bool isDerivedWithLenParameters(const Fortran::semantics::Symbol &sym) { if (const auto *declTy = sym.GetType()) if (const auto *derived = declTy->AsDerived()) return Fortran::semantics::CountLenParameters(*derived) != 0; @@ -301,7 +300,7 @@ nonDeferredLenParams.push_back(readLength()); } } - } else if (isDerivedWithLengthParameters(sym)) { + } else if (isDerivedWithLenParameters(sym)) { TODO(loc, "host associated derived type allocatable or pointer with " "length parameters"); } @@ -426,7 +425,7 @@ const Fortran::semantics::DeclTypeSpec *type = sym.GetType(); bool isPolymorphic = type && type->IsPolymorphic(); return isScalarOrContiguous && !isPolymorphic && - !isDerivedWithLengthParameters(sym); + !isDerivedWithLenParameters(sym); } }; @@ -438,7 +437,7 @@ typename T::Result walkCaptureCategories(T visitor, Fortran::lower::AbstractConverter &converter, const Fortran::semantics::Symbol &sym) { - if (isDerivedWithLengthParameters(sym)) + if (isDerivedWithLenParameters(sym)) // Should be boxed. TODO(converter.genLocation(sym.name()), "host associated derived type with length parameters"); diff --git a/flang/lib/Optimizer/Builder/FIRBuilder.cpp b/flang/lib/Optimizer/Builder/FIRBuilder.cpp --- a/flang/lib/Optimizer/Builder/FIRBuilder.cpp +++ b/flang/lib/Optimizer/Builder/FIRBuilder.cpp @@ -715,7 +715,7 @@ } llvm::SmallVector -fir::factory::getNonDeferredLengthParams(const fir::ExtendedValue &exv) { +fir::factory::getNonDeferredLenParams(const fir::ExtendedValue &exv) { return exv.match( [&](const fir::CharArrayBoxValue &character) -> llvm::SmallVector { return {character.getLen()}; }, diff --git a/flang/lib/Optimizer/CodeGen/CodeGen.cpp b/flang/lib/Optimizer/CodeGen/CodeGen.cpp --- a/flang/lib/Optimizer/CodeGen/CodeGen.cpp +++ b/flang/lib/Optimizer/CodeGen/CodeGen.cpp @@ -2192,7 +2192,6 @@ operands[coor.lenParamsOffset()]); offset = rewriter.create(loc, idxTy, offset, length); - } else { TODO(loc, "compute size of derived type with type parameters"); }