diff --git a/flang/include/flang/Frontend/CompilerInvocation.h b/flang/include/flang/Frontend/CompilerInvocation.h --- a/flang/include/flang/Frontend/CompilerInvocation.h +++ b/flang/include/flang/Frontend/CompilerInvocation.h @@ -96,9 +96,10 @@ bool warnAsErr = false; - /// This flag controls the unparsing and is used to decide whether to print out - /// the semantically analyzed version of an object or expression or the plain - /// version that does not include any information from semantic analysis. + /// This flag controls the unparsing and is used to decide whether to print + /// out the semantically analyzed version of an object or expression or the + /// plain version that does not include any information from semantic + /// analysis. bool useAnalyzedObjectsForUnparse = true; // Fortran Dialect options diff --git a/flang/include/flang/Frontend/FrontendAction.h b/flang/include/flang/Frontend/FrontendAction.h --- a/flang/include/flang/Frontend/FrontendAction.h +++ b/flang/include/flang/Frontend/FrontendAction.h @@ -135,7 +135,8 @@ } private: - template bool reportFatalErrors(const char (&message)[N]); + template + bool reportFatalErrors(const char (&message)[N]); }; } // namespace Fortran::frontend diff --git a/flang/include/flang/Frontend/FrontendActions.h b/flang/include/flang/Frontend/FrontendActions.h --- a/flang/include/flang/Frontend/FrontendActions.h +++ b/flang/include/flang/Frontend/FrontendActions.h @@ -29,8 +29,12 @@ // TODO: This is a copy from f18.cpp. It doesn't really belong here and should // be moved to a more suitable place in future. struct MeasurementVisitor { - template bool Pre(const A &) { return true; } - template void Post(const A &) { + template + bool Pre(const A &) { + return true; + } + template + void Post(const A &) { ++objects; bytes += sizeof(A); } @@ -148,8 +152,8 @@ /// \param extension The extension to use for the output file (ignored when /// the user decides to print to stdout via `-o -`) /// \return Null on error, ostream for the output file otherwise - std::unique_ptr createOutputFile( - llvm::StringRef extension); + std::unique_ptr + createOutputFile(llvm::StringRef extension); }; //===----------------------------------------------------------------------===// @@ -184,10 +188,10 @@ /// maintain some level of consistency/similarity between the drivers. enum class BackendActionTy { Backend_EmitAssembly, ///< Emit native assembly files - Backend_EmitObj, ///< Emit native object files - Backend_EmitBC, ///< Emit LLVM bitcode files - Backend_EmitLL, ///< Emit human-readable LLVM assembly - Backend_EmitMLIR ///< Emit MLIR files + Backend_EmitObj, ///< Emit native object files + Backend_EmitBC, ///< Emit LLVM bitcode files + Backend_EmitLL, ///< Emit human-readable LLVM assembly + Backend_EmitMLIR ///< Emit MLIR files }; /// Abstract base class for actions that generate code (MLIR, LLVM IR, assembly diff --git a/flang/include/flang/Frontend/TextDiagnosticBuffer.h b/flang/include/flang/Frontend/TextDiagnosticBuffer.h --- a/flang/include/flang/Frontend/TextDiagnosticBuffer.h +++ b/flang/include/flang/Frontend/TextDiagnosticBuffer.h @@ -45,7 +45,7 @@ public: void HandleDiagnostic(clang::DiagnosticsEngine::Level diagLevel, - const clang::Diagnostic &info) override; + const clang::Diagnostic &info) override; /// Flush the buffered diagnostics to a given diagnostic engine. void flushDiagnostics(clang::DiagnosticsEngine &diags) const; diff --git a/flang/include/flang/Frontend/TextDiagnosticPrinter.h b/flang/include/flang/Frontend/TextDiagnosticPrinter.h --- a/flang/include/flang/Frontend/TextDiagnosticPrinter.h +++ b/flang/include/flang/Frontend/TextDiagnosticPrinter.h @@ -51,7 +51,7 @@ void setPrefix(std::string value) { prefix = std::move(value); } void HandleDiagnostic(clang::DiagnosticsEngine::Level level, - const clang::Diagnostic &info) override; + const clang::Diagnostic &info) override; }; } // namespace Fortran::frontend diff --git a/flang/include/flang/Optimizer/Builder/Runtime/Derived.h b/flang/include/flang/Optimizer/Builder/Runtime/Derived.h --- a/flang/include/flang/Optimizer/Builder/Runtime/Derived.h +++ b/flang/include/flang/Optimizer/Builder/Runtime/Derived.h @@ -17,7 +17,7 @@ namespace fir { class FirOpBuilder; class RecordType; -} +} // namespace fir namespace fir::runtime { diff --git a/flang/include/flang/Semantics/symbol.h b/flang/include/flang/Semantics/symbol.h --- a/flang/include/flang/Semantics/symbol.h +++ b/flang/include/flang/Semantics/symbol.h @@ -625,28 +625,27 @@ bool IsSubprogram() const; bool IsFromModFile() const; bool HasExplicitInterface() const { - return common::visit(common::visitors{ - [](const SubprogramDetails &) { return true; }, - [](const SubprogramNameDetails &) { return true; }, - [&](const ProcEntityDetails &x) { - return attrs_.test(Attr::INTRINSIC) || - x.HasExplicitInterface(); - }, - [](const ProcBindingDetails &x) { - return x.symbol().HasExplicitInterface(); - }, - [](const UseDetails &x) { - return x.symbol().HasExplicitInterface(); - }, - [](const HostAssocDetails &x) { - return x.symbol().HasExplicitInterface(); - }, - [](const GenericDetails &x) { - return x.specific() && - x.specific()->HasExplicitInterface(); - }, - [](const auto &) { return false; }, - }, + return common::visit( + common::visitors{ + [](const SubprogramDetails &) { return true; }, + [](const SubprogramNameDetails &) { return true; }, + [&](const ProcEntityDetails &x) { + return attrs_.test(Attr::INTRINSIC) || x.HasExplicitInterface(); + }, + [](const ProcBindingDetails &x) { + return x.symbol().HasExplicitInterface(); + }, + [](const UseDetails &x) { + return x.symbol().HasExplicitInterface(); + }, + [](const HostAssocDetails &x) { + return x.symbol().HasExplicitInterface(); + }, + [](const GenericDetails &x) { + return x.specific() && x.specific()->HasExplicitInterface(); + }, + [](const auto &) { return false; }, + }, details_); } diff --git a/flang/lib/Evaluate/characteristics.cpp b/flang/lib/Evaluate/characteristics.cpp --- a/flang/lib/Evaluate/characteristics.cpp +++ b/flang/lib/Evaluate/characteristics.cpp @@ -506,9 +506,7 @@ } return intrinsic; } - const semantics::ProcInterface &interface { - proc.interface() - }; + const semantics::ProcInterface &interface { proc.interface() }; if (const semantics::Symbol * interfaceSymbol{interface.symbol()}) { auto interface { CharacterizeProcedure(*interfaceSymbol, context, seenProcs) diff --git a/flang/lib/Evaluate/fold-integer.cpp b/flang/lib/Evaluate/fold-integer.cpp --- a/flang/lib/Evaluate/fold-integer.cpp +++ b/flang/lib/Evaluate/fold-integer.cpp @@ -763,20 +763,20 @@ context, std::move(funcRef), &Scalar::IEOR, Scalar{}); } else if (name == "ishft") { return FoldElementalIntrinsic(context, std::move(funcRef), - ScalarFunc([&](const Scalar &i, - const Scalar &pos) -> Scalar { - auto posVal{static_cast(pos.ToInt64())}; - if (posVal < -i.bits) { - context.messages().Say( - "SHIFT=%d count for ishft is less than %d"_err_en_US, posVal, - -i.bits); - } else if (posVal > i.bits) { - context.messages().Say( - "SHIFT=%d count for ishft is greater than %d"_err_en_US, posVal, - i.bits); - } - return i.ISHFT(posVal); - })); + ScalarFunc( + [&](const Scalar &i, const Scalar &pos) -> Scalar { + auto posVal{static_cast(pos.ToInt64())}; + if (posVal < -i.bits) { + context.messages().Say( + "SHIFT=%d count for ishft is less than %d"_err_en_US, + posVal, -i.bits); + } else if (posVal > i.bits) { + context.messages().Say( + "SHIFT=%d count for ishft is greater than %d"_err_en_US, + posVal, i.bits); + } + return i.ISHFT(posVal); + })); } else if (name == "ishftc") { if (args.at(2)) { // SIZE= is present return FoldElementalIntrinsic(context, @@ -940,16 +940,15 @@ })); } else if (name == "modulo") { return FoldElementalIntrinsic(context, std::move(funcRef), - ScalarFuncWithContext( - [](FoldingContext &context, const Scalar &x, - const Scalar &y) -> Scalar { - auto result{x.MODULO(y)}; - if (result.overflow) { - context.messages().Say( - "modulo() folding overflowed"_warn_en_US); - } - return result.value; - })); + ScalarFuncWithContext([](FoldingContext &context, + const Scalar &x, + const Scalar &y) -> Scalar { + auto result{x.MODULO(y)}; + if (result.overflow) { + context.messages().Say("modulo() folding overflowed"_warn_en_US); + } + return result.value; + })); } else if (name == "not") { return FoldElementalIntrinsic( context, std::move(funcRef), &Scalar::NOT); @@ -1062,16 +1061,15 @@ })); } else if (name == "sign") { return FoldElementalIntrinsic(context, std::move(funcRef), - ScalarFunc( - [&context](const Scalar &j, const Scalar &k) -> Scalar { - typename Scalar::ValueWithOverflow result{j.SIGN(k)}; - if (result.overflow) { - context.messages().Say( - "sign(integer(kind=%d)) folding overflowed"_warn_en_US, - KIND); - } - return result.value; - })); + ScalarFunc([&context](const Scalar &j, + const Scalar &k) -> Scalar { + typename Scalar::ValueWithOverflow result{j.SIGN(k)}; + if (result.overflow) { + context.messages().Say( + "sign(integer(kind=%d)) folding overflowed"_warn_en_US, KIND); + } + return result.value; + })); } else if (name == "size") { if (auto shape{GetContextFreeShape(context, args[0])}) { if (auto &dimArg{args[1]}) { // DIM= is present, get one extent diff --git a/flang/lib/Evaluate/fold-real.cpp b/flang/lib/Evaluate/fold-real.cpp --- a/flang/lib/Evaluate/fold-real.cpp +++ b/flang/lib/Evaluate/fold-real.cpp @@ -127,15 +127,15 @@ ? common::RoundingMode::ToZero : common::RoundingMode::TiesAwayFromZero}; return FoldElementalIntrinsic(context, std::move(funcRef), - ScalarFunc([&name, &context, mode]( - const Scalar &x) -> Scalar { - ValueWithRealFlags> y{x.ToWholeNumber(mode)}; - if (y.flags.test(RealFlag::Overflow)) { - context.messages().Say( - "%s intrinsic folding overflow"_warn_en_US, name); - } - return y.value; - })); + ScalarFunc( + [&name, &context, mode](const Scalar &x) -> Scalar { + ValueWithRealFlags> y{x.ToWholeNumber(mode)}; + if (y.flags.test(RealFlag::Overflow)) { + context.messages().Say( + "%s intrinsic folding overflow"_warn_en_US, name); + } + return y.value; + })); } else if (name == "dim") { return FoldElementalIntrinsic(context, std::move(funcRef), ScalarFunc( diff --git a/flang/lib/Frontend/CompilerInstance.cpp b/flang/lib/Frontend/CompilerInstance.cpp --- a/flang/lib/Frontend/CompilerInstance.cpp +++ b/flang/lib/Frontend/CompilerInstance.cpp @@ -117,7 +117,8 @@ std::unique_ptr os; std::error_code error; - os.reset(new llvm::raw_fd_ostream(outputFilePath, error, + os.reset(new llvm::raw_fd_ostream( + outputFilePath, error, (binary ? llvm::sys::fs::OF_None : llvm::sys::fs::OF_TextWithCRLF))); if (error) { return llvm::errorCodeToError(error); diff --git a/flang/lib/Frontend/CompilerInvocation.cpp b/flang/lib/Frontend/CompilerInvocation.cpp --- a/flang/lib/Frontend/CompilerInvocation.cpp +++ b/flang/lib/Frontend/CompilerInvocation.cpp @@ -379,12 +379,13 @@ } // Set fortranForm based on options -ffree-form and -ffixed-form. - if (const auto *arg = args.getLastArg(clang::driver::options::OPT_ffixed_form, - clang::driver::options::OPT_ffree_form)) { + if (const auto *arg = + args.getLastArg(clang::driver::options::OPT_ffixed_form, + clang::driver::options::OPT_ffree_form)) { opts.fortranForm = arg->getOption().matches(clang::driver::options::OPT_ffixed_form) - ? FortranForm::FixedForm - : FortranForm::FreeForm; + ? FortranForm::FixedForm + : FortranForm::FreeForm; } // Set fixedFormColumns based on -ffixed-line-length= @@ -425,22 +426,26 @@ opts.features.Enable( Fortran::common::LanguageFeature::ImplicitNoneTypeAlways, args.hasFlag(clang::driver::options::OPT_fimplicit_none, - clang::driver::options::OPT_fno_implicit_none, false)); + clang::driver::options::OPT_fno_implicit_none, false)); // -f{no-}backslash opts.features.Enable(Fortran::common::LanguageFeature::BackslashEscapes, - args.hasFlag(clang::driver::options::OPT_fbackslash, - clang::driver::options::OPT_fno_backslash, false)); + args.hasFlag(clang::driver::options::OPT_fbackslash, + clang::driver::options::OPT_fno_backslash, + false)); // -f{no-}logical-abbreviations - opts.features.Enable(Fortran::common::LanguageFeature::LogicalAbbreviations, + opts.features.Enable( + Fortran::common::LanguageFeature::LogicalAbbreviations, args.hasFlag(clang::driver::options::OPT_flogical_abbreviations, - clang::driver::options::OPT_fno_logical_abbreviations, false)); + clang::driver::options::OPT_fno_logical_abbreviations, + false)); // -f{no-}xor-operator - opts.features.Enable(Fortran::common::LanguageFeature::XOROperator, + opts.features.Enable( + Fortran::common::LanguageFeature::XOROperator, args.hasFlag(clang::driver::options::OPT_fxor_operator, - clang::driver::options::OPT_fno_xor_operator, false)); + clang::driver::options::OPT_fno_xor_operator, false)); // -fno-automatic if (args.hasArg(clang::driver::options::OPT_fno_automatic)) { @@ -494,11 +499,11 @@ /// /// \param [in] opts The preprocessor options instance /// \param [out] args The list of input arguments -static void parsePreprocessorArgs( - Fortran::frontend::PreprocessorOptions &opts, llvm::opt::ArgList &args) { +static void parsePreprocessorArgs(Fortran::frontend::PreprocessorOptions &opts, + llvm::opt::ArgList &args) { // Add macros from the command line. - for (const auto *currentArg : args.filtered( - clang::driver::options::OPT_D, clang::driver::options::OPT_U)) { + for (const auto *currentArg : args.filtered(clang::driver::options::OPT_D, + clang::driver::options::OPT_U)) { if (currentArg->getOption().matches(clang::driver::options::OPT_D)) { opts.addMacroDef(currentArg->getValue()); } else { @@ -513,7 +518,7 @@ // Prepend the ordered list of -intrinsic-modules-path // to the default location to search. for (const auto *currentArg : - args.filtered(clang::driver::options::OPT_fintrinsic_modules_path)) + args.filtered(clang::driver::options::OPT_fintrinsic_modules_path)) opts.searchDirectoriesFromIntrModPath.emplace_back(currentArg->getValue()); // -cpp/-nocpp @@ -521,8 +526,8 @@ clang::driver::options::OPT_cpp, clang::driver::options::OPT_nocpp)) opts.macrosFlag = (currentArg->getOption().matches(clang::driver::options::OPT_cpp)) - ? PPMacrosFlag::Include - : PPMacrosFlag::Exclude; + ? PPMacrosFlag::Include + : PPMacrosFlag::Exclude; opts.noReformat = args.hasArg(clang::driver::options::OPT_fno_reformat); opts.noLineDirectives = args.hasArg(clang::driver::options::OPT_P); @@ -531,7 +536,7 @@ /// Parses all semantic related arguments and populates the variables /// options accordingly. Returns false if new errors are generated. static bool parseSemaArgs(CompilerInvocation &res, llvm::opt::ArgList &args, - clang::DiagnosticsEngine &diags) { + clang::DiagnosticsEngine &diags) { unsigned numErrorsBefore = diags.getNumErrors(); // -J/module-dir option @@ -542,7 +547,7 @@ if (moduleDirList.size() > 1) { const unsigned diagID = diags.getCustomDiagID(clang::DiagnosticsEngine::Error, - "Only one '-module-dir/-J' option allowed"); + "Only one '-module-dir/-J' option allowed"); diags.Report(diagID); } if (moduleDirList.size() == 1) @@ -570,7 +575,7 @@ /// Parses all diagnostics related arguments and populates the variables /// options accordingly. Returns false if new errors are generated. static bool parseDiagArgs(CompilerInvocation &res, llvm::opt::ArgList &args, - clang::DiagnosticsEngine &diags) { + clang::DiagnosticsEngine &diags) { unsigned numErrorsBefore = diags.getNumErrors(); // -Werror option @@ -583,7 +588,7 @@ } else { const unsigned diagID = diags.getCustomDiagID(clang::DiagnosticsEngine::Error, - "Only `-Werror` is supported currently."); + "Only `-Werror` is supported currently."); diags.Report(diagID); } } @@ -598,7 +603,7 @@ /// Parses all Dialect related arguments and populates the variables /// options accordingly. Returns false if new errors are generated. static bool parseDialectArgs(CompilerInvocation &res, llvm::opt::ArgList &args, - clang::DiagnosticsEngine &diags) { + clang::DiagnosticsEngine &diags) { unsigned numErrorsBefore = diags.getNumErrors(); // -fdefault* family @@ -615,9 +620,9 @@ if (!args.hasArg(clang::driver::options::OPT_fdefault_real_8)) { // -fdefault-double-8 has to be used with -fdefault-real-8 // to be compatible with gfortran - const unsigned diagID = - diags.getCustomDiagID(clang::DiagnosticsEngine::Error, - "Use of `-fdefault-double-8` requires `-fdefault-real-8`"); + const unsigned diagID = diags.getCustomDiagID( + clang::DiagnosticsEngine::Error, + "Use of `-fdefault-double-8` requires `-fdefault-real-8`"); diags.Report(diagID); } // https://gcc.gnu.org/onlinedocs/gfortran/Fortran-Dialect-Options.html @@ -651,7 +656,7 @@ } else { const unsigned diagID = diags.getCustomDiagID(clang::DiagnosticsEngine::Error, - "Only -std=f2018 is allowed currently."); + "Only -std=f2018 is allowed currently."); diags.Report(diagID); } } @@ -812,12 +817,12 @@ // Populate the macro list with version numbers and other predefinitions. fortranOptions.predefinitions.emplace_back("__flang__", "1"); - fortranOptions.predefinitions.emplace_back( - "__flang_major__", FLANG_VERSION_MAJOR_STRING); - fortranOptions.predefinitions.emplace_back( - "__flang_minor__", FLANG_VERSION_MINOR_STRING); - fortranOptions.predefinitions.emplace_back( - "__flang_patchlevel__", FLANG_VERSION_PATCHLEVEL_STRING); + fortranOptions.predefinitions.emplace_back("__flang_major__", + FLANG_VERSION_MAJOR_STRING); + fortranOptions.predefinitions.emplace_back("__flang_minor__", + FLANG_VERSION_MINOR_STRING); + fortranOptions.predefinitions.emplace_back("__flang_patchlevel__", + FLANG_VERSION_PATCHLEVEL_STRING); // Add predefinitions based on extensions enabled if (frontendOptions.features.IsEnabled( diff --git a/flang/lib/Frontend/FrontendOptions.cpp b/flang/lib/Frontend/FrontendOptions.cpp --- a/flang/lib/Frontend/FrontendOptions.cpp +++ b/flang/lib/Frontend/FrontendOptions.cpp @@ -17,22 +17,23 @@ bool Fortran::frontend::isFixedFormSuffix(llvm::StringRef suffix) { // Note: Keep this list in-sync with flang/test/lit.cfg.py return suffix == "f77" || suffix == "f" || suffix == "F" || suffix == "ff" || - suffix == "for" || suffix == "FOR" || suffix == "fpp" || suffix == "FPP"; + suffix == "for" || suffix == "FOR" || suffix == "fpp" || + suffix == "FPP"; } bool Fortran::frontend::isFreeFormSuffix(llvm::StringRef suffix) { // Note: Keep this list in-sync with flang/test/lit.cfg.py // TODO: Add Cuda Fortan files (i.e. `*.cuf` and `*.CUF`). return suffix == "f90" || suffix == "F90" || suffix == "ff90" || - suffix == "f95" || suffix == "F95" || suffix == "ff95" || - suffix == "f03" || suffix == "F03" || suffix == "f08" || - suffix == "F08" || suffix == "f18" || suffix == "F18"; + suffix == "f95" || suffix == "F95" || suffix == "ff95" || + suffix == "f03" || suffix == "F03" || suffix == "f08" || + suffix == "F08" || suffix == "f18" || suffix == "F18"; } bool Fortran::frontend::isToBePreprocessed(llvm::StringRef suffix) { return suffix == "F" || suffix == "FOR" || suffix == "fpp" || - suffix == "FPP" || suffix == "F90" || suffix == "F95" || - suffix == "F03" || suffix == "F08" || suffix == "F18"; + suffix == "FPP" || suffix == "F90" || suffix == "F95" || + suffix == "F03" || suffix == "F08" || suffix == "F18"; } InputKind FrontendOptions::getInputKindForExtension(llvm::StringRef extension) { diff --git a/flang/lib/Frontend/TextDiagnosticPrinter.cpp b/flang/lib/Frontend/TextDiagnosticPrinter.cpp --- a/flang/lib/Frontend/TextDiagnosticPrinter.cpp +++ b/flang/lib/Frontend/TextDiagnosticPrinter.cpp @@ -46,7 +46,7 @@ // We only emit diagnostics in contexts that lack valid source locations. assert(!info.getLocation().isValid() && - "Diagnostics with valid source location are not supported"); + "Diagnostics with valid source location are not supported"); Fortran::frontend::TextDiagnostic::printDiagnosticLevel(os, level, diagOpts->ShowColors); diff --git a/flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp b/flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp --- a/flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp +++ b/flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp @@ -82,7 +82,7 @@ return std::make_unique(); case PluginAction: { for (const FrontendPluginRegistry::entry &plugin : - FrontendPluginRegistry::entries()) { + FrontendPluginRegistry::entries()) { if (plugin.getName() == ci.getFrontendOpts().actionName) { std::unique_ptr p(plugin.instantiate()); return std::move(p); @@ -101,8 +101,9 @@ bool executeCompilerInvocation(CompilerInstance *flang) { // Honor -help. if (flang->getFrontendOpts().showHelp) { - clang::driver::getDriverOptTable().printHelp(llvm::outs(), - "flang-new -fc1 [options] file...", "LLVM 'Flang' Compiler", + clang::driver::getDriverOptTable().printHelp( + llvm::outs(), "flang-new -fc1 [options] file...", + "LLVM 'Flang' Compiler", /*Include=*/clang::driver::options::FC1Option, /*Exclude=*/llvm::opt::DriverFlag::HelpHidden, /*ShowAllAliases=*/false); diff --git a/flang/lib/Optimizer/Builder/MutableBox.cpp b/flang/lib/Optimizer/Builder/MutableBox.cpp --- a/flang/lib/Optimizer/Builder/MutableBox.cpp +++ b/flang/lib/Optimizer/Builder/MutableBox.cpp @@ -809,28 +809,29 @@ TODO(loc, "automatic allocation of derived type allocatable with " "length parameters"); } - auto ifOp = - builder - .genIfOp(loc, {addrType}, mustReallocate, - /*withElseRegion=*/true) - .genThen([&]() { - // If shape or length mismatch, allocate new storage. - // When rhs is a scalar, keep the previous shape - auto extents = shape.empty() - ? mlir::ValueRange(previousExtents) - : shape; - auto heap = allocateAndInitNewStorage( - builder, loc, box, extents, lengthParams, - ".auto.alloc"); - if (storageHandler) - storageHandler(getExtValForStorage(heap)); - builder.create(loc, heap); - }) - .genElse([&]() { - if (storageHandler) - storageHandler(getExtValForStorage(addr)); - builder.create(loc, addr); - }); + auto ifOp = builder + .genIfOp(loc, {addrType}, mustReallocate, + /*withElseRegion=*/true) + .genThen([&]() { + // If shape or length mismatch, allocate new + // storage. When rhs is a scalar, keep the + // previous shape + auto extents = + shape.empty() + ? mlir::ValueRange(previousExtents) + : shape; + auto heap = allocateAndInitNewStorage( + builder, loc, box, extents, lengthParams, + ".auto.alloc"); + if (storageHandler) + storageHandler(getExtValForStorage(heap)); + builder.create(loc, heap); + }) + .genElse([&]() { + if (storageHandler) + storageHandler(getExtValForStorage(addr)); + builder.create(loc, addr); + }); ifOp.end(); auto newAddr = ifOp.getResults()[0]; builder.create( diff --git a/flang/lib/Optimizer/CodeGen/TargetRewrite.cpp b/flang/lib/Optimizer/CodeGen/TargetRewrite.cpp --- a/flang/lib/Optimizer/CodeGen/TargetRewrite.cpp +++ b/flang/lib/Optimizer/CodeGen/TargetRewrite.cpp @@ -841,17 +841,17 @@ auto argNo = newInTys.size(); if (attr.isByVal()) { if (auto align = attr.getAlignment()) - fixups.emplace_back( - FixupTy::Codes::ArgumentAsLoad, argNo, - [=](mlir::func::FuncOp func) { - auto elemType = fir::dyn_cast_ptrOrBoxEleTy( - func.getFunctionType().getInput(argNo)); - func.setArgAttr(argNo, "llvm.byval", - mlir::TypeAttr::get(elemType)); - func.setArgAttr(argNo, "llvm.align", - rewriter->getIntegerAttr( - rewriter->getIntegerType(32), align)); - }); + fixups.emplace_back(FixupTy::Codes::ArgumentAsLoad, argNo, + [=](mlir::func::FuncOp func) { + auto elemType = fir::dyn_cast_ptrOrBoxEleTy( + func.getFunctionType().getInput(argNo)); + func.setArgAttr(argNo, "llvm.byval", + mlir::TypeAttr::get(elemType)); + func.setArgAttr( + argNo, "llvm.align", + rewriter->getIntegerAttr( + rewriter->getIntegerType(32), align)); + }); else fixups.emplace_back(FixupTy::Codes::ArgumentAsLoad, newInTys.size(), [=](mlir::func::FuncOp func) { diff --git a/flang/lib/Semantics/check-acc-structure.h b/flang/lib/Semantics/check-acc-structure.h --- a/flang/lib/Semantics/check-acc-structure.h +++ b/flang/lib/Semantics/check-acc-structure.h @@ -70,7 +70,6 @@ #include "llvm/Frontend/OpenACC/ACC.inc" private: - bool CheckAllowedModifier(llvm::acc::Clause clause); bool IsComputeConstruct(llvm::acc::Directive directive) const; bool IsInsideComputeConstruct() const; diff --git a/flang/lib/Semantics/check-declarations.cpp b/flang/lib/Semantics/check-declarations.cpp --- a/flang/lib/Semantics/check-declarations.cpp +++ b/flang/lib/Semantics/check-declarations.cpp @@ -1573,9 +1573,7 @@ return; } const auto &name{proc.name()}; - const Symbol *interface { - interface0 ? FindInterface(*interface0) : nullptr - }; + const Symbol *interface { interface0 ? FindInterface(*interface0) : nullptr }; if (!interface) { messages_.Say(name, "Procedure component '%s' must have NOPASS attribute or explicit interface"_err_en_US, diff --git a/flang/lib/Semantics/data-to-inits.h b/flang/lib/Semantics/data-to-inits.h --- a/flang/lib/Semantics/data-to-inits.h +++ b/flang/lib/Semantics/data-to-inits.h @@ -18,7 +18,7 @@ namespace Fortran::parser { struct DataStmtSet; struct DataStmtValue; -} +} // namespace Fortran::parser namespace Fortran::evaluate { class ExpressionAnalyzer; } diff --git a/flang/lib/Semantics/expression.cpp b/flang/lib/Semantics/expression.cpp --- a/flang/lib/Semantics/expression.cpp +++ b/flang/lib/Semantics/expression.cpp @@ -2307,17 +2307,17 @@ const parser::ProcedureDesignator &pd, ActualArguments &&arguments, bool isSubroutine, bool mightBeStructureConstructor) -> std::optional { - return common::visit( - common::visitors{ - [&](const parser::Name &name) { - return GetCalleeAndArguments(name, std::move(arguments), - isSubroutine, mightBeStructureConstructor); - }, - [&](const parser::ProcComponentRef &pcr) { - return AnalyzeProcedureComponentRef( - pcr, std::move(arguments), isSubroutine); - }, - }, + return common::visit(common::visitors{ + [&](const parser::Name &name) { + return GetCalleeAndArguments(name, + std::move(arguments), isSubroutine, + mightBeStructureConstructor); + }, + [&](const parser::ProcComponentRef &pcr) { + return AnalyzeProcedureComponentRef( + pcr, std::move(arguments), isSubroutine); + }, + }, pd.u); } @@ -3417,26 +3417,26 @@ // be detected and represented (they're not expressions). // TODO: C1534: Don't allow a "restricted" specific intrinsic to be passed. std::optional actual; - common::visit( - common::visitors{ - [&](const common::Indirection &x) { - actual = AnalyzeExpr(x.value()); - SetArgSourceLocation(actual, x.value().source); - }, - [&](const parser::AltReturnSpec &label) { - if (!isSubroutine) { - context_.Say("alternate return specification may not appear on" - " function reference"_err_en_US); - } - actual = ActualArgument(label.v); - }, - [&](const parser::ActualArg::PercentRef &) { - context_.Say("%REF() intrinsic for arguments"_todo_en_US); - }, - [&](const parser::ActualArg::PercentVal &) { - context_.Say("%VAL() intrinsic for arguments"_todo_en_US); - }, - }, + common::visit(common::visitors{ + [&](const common::Indirection &x) { + actual = AnalyzeExpr(x.value()); + SetArgSourceLocation(actual, x.value().source); + }, + [&](const parser::AltReturnSpec &label) { + if (!isSubroutine) { + context_.Say( + "alternate return specification may not appear on" + " function reference"_err_en_US); + } + actual = ActualArgument(label.v); + }, + [&](const parser::ActualArg::PercentRef &) { + context_.Say("%REF() intrinsic for arguments"_todo_en_US); + }, + [&](const parser::ActualArg::PercentVal &) { + context_.Say("%VAL() intrinsic for arguments"_todo_en_US); + }, + }, std::get(arg.t).u); if (actual) { if (const auto &argKW{std::get>(arg.t)}) { diff --git a/flang/lib/Semantics/mod-file.cpp b/flang/lib/Semantics/mod-file.cpp --- a/flang/lib/Semantics/mod-file.cpp +++ b/flang/lib/Semantics/mod-file.cpp @@ -687,7 +687,7 @@ return; } const auto &details{symbol.get()}; - const ProcInterface &interface{details.interface()}; + const ProcInterface &interface { details.interface() }; Attrs attrs{symbol.attrs()}; if (details.passName()) { attrs.reset(Attr::PASS); diff --git a/flang/lib/Semantics/symbol.cpp b/flang/lib/Semantics/symbol.cpp --- a/flang/lib/Semantics/symbol.cpp +++ b/flang/lib/Semantics/symbol.cpp @@ -715,7 +715,8 @@ return y && *y == x; } -bool SymbolOffsetCompare::operator()(const SymbolRef &x, const SymbolRef &y) const { +bool SymbolOffsetCompare::operator()( + const SymbolRef &x, const SymbolRef &y) const { const Symbol *xCommon{FindCommonBlockContaining(*x)}; const Symbol *yCommon{FindCommonBlockContaining(*y)}; if (xCommon) { diff --git a/flang/lib/Semantics/tools.cpp b/flang/lib/Semantics/tools.cpp --- a/flang/lib/Semantics/tools.cpp +++ b/flang/lib/Semantics/tools.cpp @@ -456,9 +456,7 @@ return common::visit( common::visitors{ [](const ProcEntityDetails &details) { - const Symbol *interface { - details.interface().symbol() - }; + const Symbol *interface { details.interface().symbol() }; return interface ? FindInterface(*interface) : nullptr; }, [](const ProcBindingDetails &details) { diff --git a/flang/tools/flang-driver/driver.cpp b/flang/tools/flang-driver/driver.cpp --- a/flang/tools/flang-driver/driver.cpp +++ b/flang/tools/flang-driver/driver.cpp @@ -72,8 +72,8 @@ return 1; } -static void ExpandResponseFiles( - llvm::StringSaver &saver, llvm::SmallVectorImpl &args) { +static void ExpandResponseFiles(llvm::StringSaver &saver, + llvm::SmallVectorImpl &args) { // We're defaulting to the GNU syntax, since we don't have a CL mode. llvm::cl::TokenizerCallback tokenizer = &llvm::cl::TokenizeGNUCommandLine; llvm::cl::ExpansionContext ExpCtx(saver.getAllocator(), tokenizer); @@ -96,8 +96,8 @@ ExpandResponseFiles(saver, args); // Check if flang-new is in the frontend mode - auto firstArg = std::find_if( - args.begin() + 1, args.end(), [](const char *a) { return a != nullptr; }); + auto firstArg = std::find_if(args.begin() + 1, args.end(), + [](const char *a) { return a != nullptr; }); if (firstArg != args.end()) { if (llvm::StringRef(args[1]).startswith("-cc1")) { llvm::errs() << "error: unknown integrated tool '" << args[1] << "'. " @@ -127,7 +127,8 @@ // Prepare the driver clang::driver::Driver theDriver(driverPath, - llvm::sys::getDefaultTargetTriple(), diags, "flang LLVM compiler"); + llvm::sys::getDefaultTargetTriple(), diags, + "flang LLVM compiler"); theDriver.setTargetAndMode(targetandMode); std::unique_ptr c( theDriver.BuildCompilation(args)); diff --git a/flang/unittests/Optimizer/FIRContextTest.cpp b/flang/unittests/Optimizer/FIRContextTest.cpp --- a/flang/unittests/Optimizer/FIRContextTest.cpp +++ b/flang/unittests/Optimizer/FIRContextTest.cpp @@ -7,11 +7,11 @@ //===----------------------------------------------------------------------===// #include "flang/Optimizer/Support/FIRContext.h" -#include "flang/Optimizer/Support/KindMapping.h" +#include "gtest/gtest.h" #include "mlir/IR/BuiltinAttributes.h" #include "mlir/IR/BuiltinOps.h" +#include "flang/Optimizer/Support/KindMapping.h" #include "llvm/Support/Host.h" -#include "gtest/gtest.h" #include using namespace fir; diff --git a/flang/unittests/Runtime/Time.cpp b/flang/unittests/Runtime/Time.cpp --- a/flang/unittests/Runtime/Time.cpp +++ b/flang/unittests/Runtime/Time.cpp @@ -166,4 +166,3 @@ EXPECT_LE(minutes, 59); } } -