diff options
author | Sacha Ballantyne <Sacha.Ballantyne@arm.com> | 2023-03-27 13:12:10 +0000 |
---|---|---|
committer | Sacha Ballantyne <Sacha.Ballantyne@arm.com> | 2023-03-29 12:21:26 +0000 |
commit | e2b7424d06663f92b958c0b4649ed08b55216a49 (patch) | |
tree | cd3c6c6efe6befab936c78f3a246a88e2aa163cb /flang/lib/Frontend/CompilerInvocation.cpp | |
parent | 6b6f312ccedff8322e246f9022148a5bc8805ae5 (diff) | |
download | llvm-e2b7424d06663f92b958c0b4649ed08b55216a49.zip llvm-e2b7424d06663f92b958c0b4649ed08b55216a49.tar.gz llvm-e2b7424d06663f92b958c0b4649ed08b55216a49.tar.bz2 |
[Flang] Add debug flag to enable current debug information pass
While a pass exists to generate basic debug information, currently there is not a corresponding flag to enable it.
This patch adds support for activating this pass at any debug level >= -g1, as well as emiting a warning for higher levels that the functionality is not yet fully implemented.
This patch also adds -g and -gline-tables-only to appear when `flang-new` --help is run
Depends on D142347.
Reviewed By: awarzynski
Differential Revision: https://reviews.llvm.org/D146814
Diffstat (limited to 'flang/lib/Frontend/CompilerInvocation.cpp')
-rw-r--r-- | flang/lib/Frontend/CompilerInvocation.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/flang/lib/Frontend/CompilerInvocation.cpp b/flang/lib/Frontend/CompilerInvocation.cpp index 49dfeed..9fbf5bb 100644 --- a/flang/lib/Frontend/CompilerInvocation.cpp +++ b/flang/lib/Frontend/CompilerInvocation.cpp @@ -25,6 +25,7 @@ #include "clang/Driver/Options.h" #include "llvm/ADT/StringRef.h" #include "llvm/ADT/StringSwitch.h" +#include "llvm/Frontend/Debug/Options.h" #include "llvm/Option/Arg.h" #include "llvm/Option/ArgList.h" #include "llvm/Option/OptTable.h" @@ -117,6 +118,38 @@ bool Fortran::frontend::parseDiagnosticArgs(clang::DiagnosticOptions &opts, return true; } +static bool parseDebugArgs(Fortran::frontend::CodeGenOptions &opts, + llvm::opt::ArgList &args, + clang::DiagnosticsEngine &diags) { + using DebugInfoKind = llvm::codegenoptions::DebugInfoKind; + if (llvm::opt::Arg *arg = + args.getLastArg(clang::driver::options::OPT_debug_info_kind_EQ)) { + std::optional<DebugInfoKind> val = + llvm::StringSwitch<std::optional<DebugInfoKind>>(arg->getValue()) + .Case("line-tables-only", llvm::codegenoptions::DebugLineTablesOnly) + .Case("line-directives-only", + llvm::codegenoptions::DebugDirectivesOnly) + .Case("constructor", llvm::codegenoptions::DebugInfoConstructor) + .Case("limited", llvm::codegenoptions::LimitedDebugInfo) + .Case("standalone", llvm::codegenoptions::FullDebugInfo) + .Case("unused-types", llvm::codegenoptions::UnusedTypeInfo) + .Default(std::nullopt); + if (!val.has_value()) { + diags.Report(clang::diag::err_drv_invalid_value) + << arg->getAsString(args) << arg->getValue(); + return false; + } + opts.setDebugInfo(val.value()); + if (val != llvm::codegenoptions::DebugLineTablesOnly && + val != llvm::codegenoptions::NoDebugInfo) { + const auto debugWarning = diags.getCustomDiagID( + clang::DiagnosticsEngine::Warning, "Unsupported debug option: %0"); + diags.Report(debugWarning) << arg->getValue(); + } + } + return true; +} + static void parseCodeGenArgs(Fortran::frontend::CodeGenOptions &opts, llvm::opt::ArgList &args, clang::DiagnosticsEngine &diags) { @@ -830,6 +863,7 @@ bool CompilerInvocation::createFromArgs( parseTargetArgs(res.getTargetOpts(), args); parsePreprocessorArgs(res.getPreprocessorOpts(), args); parseCodeGenArgs(res.getCodeGenOpts(), args, diags); + success &= parseDebugArgs(res.getCodeGenOpts(), args, diags); success &= parseSemaArgs(res, args, diags); success &= parseDialectArgs(res, args, diags); success &= parseDiagArgs(res, args, diags); |