https://github.com/abidh created https://github.com/llvm/llvm-project/pull/236839
Flang asked for the default name table in every compile unit. Now that flang emits DWARF 5 by default, that puts a .debug_names section in every object, and gdb, which only reads an index it built itself, warns on loading: warning: .debug_names not created by gdb; ignoring Clang asks for no name table unless -gpubnames or -ggnu-pubnames is given. This PR makes flang accepts -gpubnames, -ggnu-pubnames, -gno-pubnames and -gno-gnu-pubnames. The driver now forwards those flags and the frontend chooses the kind as clang does. AddDebugInfo takes the kind through a new name-table-kind option. The pass sets it as the compile unit's nameTableKind. Assisted By: Cursor >From b9d9ee909b36a264b8c86ab9fa407017d2e03523 Mon Sep 17 00:00:00 2001 From: Abid Qadeer <[email protected]> Date: Thu, 29 Oct 2026 14:00:13 +0000 Subject: [PATCH] [flang][debug] Leave the name table off by default Flang asked for the default name table in every compile unit. Now that flang emits DWARF 5 by default, that puts a .debug_names section in every object, and gdb, which only reads an index it built itself, warns on loading: warning: .debug_names not created by gdb; ignoring Clang asks for no name table unless -gpubnames or -ggnu-pubnames is given. This PR makes flang accepts -gpubnames, -ggnu-pubnames, -gno-pubnames and -gno-gnu-pubnames. The driver now forwards those flags and the frontend chooses the kind as clang does. AddDebugInfo takes the kind through a new name-table-kind option. The pass sets it as the compile unit's nameTableKind. --- clang/include/clang/Options/Options.td | 10 ++-- clang/lib/Driver/ToolChains/Flang.cpp | 12 +++++ flang/docs/ReleaseNotes.md | 7 +++ .../include/flang/Frontend/CodeGenOptions.def | 1 + flang/include/flang/Frontend/CodeGenOptions.h | 3 ++ .../flang/Optimizer/Transforms/Passes.td | 11 +++++ flang/include/flang/Tools/CrossToolHelpers.h | 4 ++ flang/lib/Frontend/CompilerInvocation.cpp | 19 +++++++- flang/lib/Optimizer/Passes/Pipelines.cpp | 17 +++++++ .../lib/Optimizer/Transforms/AddDebugInfo.cpp | 6 +-- flang/test/Driver/debug-pubnames.f90 | 48 +++++++++++++++++++ .../test/Integration/debug-common-block-1.f90 | 2 +- .../debug-line-directives-only.f90 | 2 + flang/test/Integration/debug-module-2.f90 | 2 +- flang/test/Integration/debug-name-table.f90 | 27 +++++++++++ .../Transforms/debug-line-table-inc-file.fir | 2 +- flang/test/Transforms/debug-line-table.fir | 6 +-- flang/test/Transforms/debug-name-table.fir | 31 ++++++++++++ 18 files changed, 195 insertions(+), 15 deletions(-) create mode 100644 flang/test/Driver/debug-pubnames.f90 create mode 100644 flang/test/Integration/debug-name-table.f90 create mode 100644 flang/test/Transforms/debug-name-table.fir diff --git a/clang/include/clang/Options/Options.td b/clang/include/clang/Options/Options.td index 4419e3cf6f98c5..55f3c4b4aaed93 100644 --- a/clang/include/clang/Options/Options.td +++ b/clang/include/clang/Options/Options.td @@ -5417,11 +5417,13 @@ def gsrc_hash_EQ : Joined<["-"], "gsrc-hash=">, def gno_simple_template_names : Flag<["-"], "gno-simple-template-names">, Group<g_flags_Group>; def ggnu_pubnames : Flag<["-"], "ggnu-pubnames">, Group<g_flags_Group>, - Visibility<[ClangOption, CC1Option]>; -def gno_gnu_pubnames : Flag<["-"], "gno-gnu-pubnames">, Group<g_flags_Group>; + Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>; +def gno_gnu_pubnames : Flag<["-"], "gno-gnu-pubnames">, Group<g_flags_Group>, + Visibility<[ClangOption, FlangOption]>; def gpubnames : Flag<["-"], "gpubnames">, Group<g_flags_Group>, - Visibility<[ClangOption, CC1Option]>; -def gno_pubnames : Flag<["-"], "gno-pubnames">, Group<g_flags_Group>; + Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>; +def gno_pubnames : Flag<["-"], "gno-pubnames">, Group<g_flags_Group>, + Visibility<[ClangOption, FlangOption]>; def gdwarf_aranges : Flag<["-"], "gdwarf-aranges">, Group<g_flags_Group>; def gmodules : Flag <["-"], "gmodules">, Group<gN_Group>, HelpText<"Generate debug info with external references to clang modules" diff --git a/clang/lib/Driver/ToolChains/Flang.cpp b/clang/lib/Driver/ToolChains/Flang.cpp index 94b092e711be64..15f2b70fceba6d 100644 --- a/clang/lib/Driver/ToolChains/Flang.cpp +++ b/clang/lib/Driver/ToolChains/Flang.cpp @@ -273,6 +273,18 @@ void Flang::addDebugOptions(const llvm::opt::ArgList &Args, const JobAction &JA, CmdArgs.push_back( Args.MakeArgString("-dwarf-version=" + Twine(DwarfVersion))); } + + // Handle name table requests (-gpubnames, -ggnu-pubnames). + if (const Arg *A = Args.getLastArg( + options::OPT_ggnu_pubnames, options::OPT_gno_gnu_pubnames, + options::OPT_gpubnames, options::OPT_gno_pubnames); + A && checkDebugInfoOption(A, Args, D, TC)) { + if (A->getOption().matches(options::OPT_ggnu_pubnames)) + CmdArgs.push_back("-ggnu-pubnames"); + else if (A->getOption().matches(options::OPT_gpubnames)) + CmdArgs.push_back("-gpubnames"); + } + if (Args.hasArg(options::OPT_gsplit_dwarf) || Args.hasArg(options::OPT_gsplit_dwarf_EQ)) { // FIXME: -gsplit-dwarf on AIX is currently unimplemented. diff --git a/flang/docs/ReleaseNotes.md b/flang/docs/ReleaseNotes.md index 147b15106b9146..22ebc613917fe9 100644 --- a/flang/docs/ReleaseNotes.md +++ b/flang/docs/ReleaseNotes.md @@ -116,6 +116,9 @@ page](https://llvm.org/releases/). compressing DWARF debug info in ELF object files using zlib or zstd, reducing debug information size in compiled binaries. +- The debug information no longer asks for a name table by default, matching + clang. Use `-gpubnames` to get the table back. + - The FIR loop invariant code motion pass (`flang-licm`) is now enabled by default at optimization levels above `-O0`. It can be turned off with `-mmlir -disable-fir-licm`. The `-mmlir -enable-fir-licm` option that @@ -151,6 +154,10 @@ page](https://llvm.org/releases/). - Added `-gz` and `-gz=<format>` flags to enable compression of DWARF debug sections. Supported formats are `zlib`, `zstd`, and `none`. +- Added `-gpubnames` and `-ggnu-pubnames`, which ask for a name table and for + GNU pubnames respectively, and their `-gno-pubnames` and `-gno-gnu-pubnames` + forms. + - Added `-finit-local=<val>` to initialize automatic local variables that have no explicit or default initialization. Accepted values are `zero` and `0x<hex-byte>` (e.g. `0xAA`). The gfortran diff --git a/flang/include/flang/Frontend/CodeGenOptions.def b/flang/include/flang/Frontend/CodeGenOptions.def index 569a6aa289ca31..b25383ff592b43 100644 --- a/flang/include/flang/Frontend/CodeGenOptions.def +++ b/flang/include/flang/Frontend/CodeGenOptions.def @@ -68,6 +68,7 @@ CODEGENOPT(Underscoring, 1, 1) ENUM_CODEGENOPT(FPMaxminBehavior, Fortran::common::FPMaxminBehavior, 2, Fortran::common::FPMaxminBehavior::Legacy) ENUM_CODEGENOPT(RelocationModel, llvm::Reloc::Model, 3, llvm::Reloc::PIC_) ///< Name of the relocation model to use. ENUM_CODEGENOPT(DebugInfo, llvm::codegenoptions::DebugInfoKind, 4, llvm::codegenoptions::NoDebugInfo) ///< Level of debug info to generate +ENUM_CODEGENOPT(DebugNameTable, DebugNameTableKind, 2, DebugNameTableKind::None) ///< Name table to emit in the debug info ENUM_CODEGENOPT(VecLib, llvm::driver::VectorLibrary, 4, llvm::driver::VectorLibrary::NoLibrary) ///< Vector functions library to use ENUM_CODEGENOPT(FramePointer, llvm::FramePointerKind, 3, llvm::FramePointerKind::None) ///< Enable the usage of frame pointers ENUM_CODEGENOPT(ComplexRange, ComplexRangeKind, 3, ComplexRangeKind::CX_Full) ///< Method for calculating complex number division diff --git a/flang/include/flang/Frontend/CodeGenOptions.h b/flang/include/flang/Frontend/CodeGenOptions.h index 68aa2b1810abf0..0a661e6d778a69 100644 --- a/flang/include/flang/Frontend/CodeGenOptions.h +++ b/flang/include/flang/Frontend/CodeGenOptions.h @@ -232,6 +232,9 @@ class CodeGenOptions : public CodeGenOptionsBase { /// is implemented. (See clang/Basic/LangOptions.h) }; + /// The kind of name table (accelerator table) the debug info asks for. + enum class DebugNameTableKind { None, Default, GNU, Apple }; + // Define accessors/mutators for code generation options of enumeration type. #define CODEGENOPT(Name, Bits, Default) #define ENUM_CODEGENOPT(Name, Type, Bits, Default) \ diff --git a/flang/include/flang/Optimizer/Transforms/Passes.td b/flang/include/flang/Optimizer/Transforms/Passes.td index c4dc0aed2e5d23..34354eb3f6fede 100644 --- a/flang/include/flang/Optimizer/Transforms/Passes.td +++ b/flang/include/flang/Optimizer/Transforms/Passes.td @@ -261,6 +261,17 @@ def AddDebugInfo : Pass<"add-debug-info", "mlir::ModuleOp"> { Option<"dwarfDebugFlags", "dwarf-debug-flags", "std::string", /*default=*/"std::string{}", "Command-line flags to append to DWARF producer">, + Option<"nameTableKind", "name-table-kind", + "mlir::LLVM::DINameTableKind", + /*default=*/"mlir::LLVM::DINameTableKind::None", + "name table to emit", + [{::llvm::cl::values( + clEnumValN(mlir::LLVM::DINameTableKind::Default, "Default", "Emit the default name table"), + clEnumValN(mlir::LLVM::DINameTableKind::GNU, "GNU", "Emit GNU pubnames"), + clEnumValN(mlir::LLVM::DINameTableKind::None, "None", "Emit no name table"), + clEnumValN(mlir::LLVM::DINameTableKind::Apple, "Apple", "Emit Apple accelerator tables") + )}] + >, Option<"emitFakeUseForDebugVars", "emit-fake-use-for-debug-vars", "bool", /*default=*/"false", "Emit fake use for debug variables to extend their lifetime">, diff --git a/flang/include/flang/Tools/CrossToolHelpers.h b/flang/include/flang/Tools/CrossToolHelpers.h index e8b80c9606cb20..0b11c6be04946c 100644 --- a/flang/include/flang/Tools/CrossToolHelpers.h +++ b/flang/include/flang/Tools/CrossToolHelpers.h @@ -149,6 +149,7 @@ struct MLIRToLLVMPassPipelineConfig : public FlangEPCallBacks { DwarfVersion = opts.DwarfVersion; SplitDwarfFile = opts.SplitDwarfFile; DwarfDebugFlags = opts.DwarfDebugFlags; + DebugNameTable = opts.getDebugNameTable(); } llvm::OptimizationLevel OptLevel; ///< optimisation level @@ -198,6 +199,9 @@ struct MLIRToLLVMPassPipelineConfig : public FlangEPCallBacks { int32_t DwarfVersion = 0; ///< Version of DWARF debug info to generate std::string SplitDwarfFile = ""; ///< File name for the split debug info std::string DwarfDebugFlags = ""; ///< Debug flags to append to DWARF producer + Fortran::frontend::CodeGenOptions::DebugNameTableKind DebugNameTable = + Fortran::frontend::CodeGenOptions::DebugNameTableKind:: + None; ///< Name table to emit in the debug info Fortran::common::FPMaxminBehavior fpMaxminBehavior = Fortran::common::FPMaxminBehavior::Legacy; }; diff --git a/flang/lib/Frontend/CompilerInvocation.cpp b/flang/lib/Frontend/CompilerInvocation.cpp index 107fdd37dbd3e9..fe6767f73e12f0 100644 --- a/flang/lib/Frontend/CompilerInvocation.cpp +++ b/flang/lib/Frontend/CompilerInvocation.cpp @@ -132,7 +132,8 @@ bool Fortran::frontend::parseDiagnosticArgs(clang::DiagnosticOptions &opts, static bool parseDebugArgs(Fortran::frontend::CodeGenOptions &opts, llvm::opt::ArgList &args, - clang::DiagnosticsEngine &diags) { + clang::DiagnosticsEngine &diags, + const llvm::Triple &triple) { using DebugInfoKind = llvm::codegenoptions::DebugInfoKind; if (llvm::opt::Arg *arg = args.getLastArg(clang::options::OPT_debug_info_kind_EQ)) { @@ -178,6 +179,19 @@ static bool parseDebugArgs(Fortran::frontend::CodeGenOptions &opts, opts.DebugInfoForProfiling = args.hasArg(clang::options::OPT_fdebug_info_for_profiling); + using NameTableKind = Fortran::frontend::CodeGenOptions::DebugNameTableKind; + NameTableKind nameTable = NameTableKind::None; + if (args.hasArg(clang::options::OPT_ggnu_pubnames)) + nameTable = NameTableKind::GNU; + else if (args.hasArg(clang::options::OPT_gpubnames)) + nameTable = NameTableKind::Default; + // Match the target overrides in clang's CGDebugInfo::CreateCompileUnit. + if (triple.isNVPTX()) + nameTable = NameTableKind::None; + else if (triple.getVendor() == llvm::Triple::Apple) + nameTable = NameTableKind::Apple; + opts.setDebugNameTable(nameTable); + if (const llvm::opt::Arg *a = args.getLastArg(clang::options::OPT_compress_debug_sections_EQ)) { auto type = llvm::StringSwitch<std::optional<llvm::DebugCompressionType>>( @@ -1891,7 +1905,8 @@ bool CompilerInvocation::createFromArgs( parsePreprocessorArgs(invoc.getPreprocessorOpts(), args); parseCodeGenArgs(invoc.getCodeGenOpts(), args, diags); success &= parseDoConcurrentMapping(invoc.getCodeGenOpts(), args, diags); - success &= parseDebugArgs(invoc.getCodeGenOpts(), args, diags); + success &= parseDebugArgs(invoc.getCodeGenOpts(), args, diags, + llvm::Triple(invoc.getTargetOpts().triple)); // Enable USE statement preservation for debug info if debug level is above // LineTablesOnly. diff --git a/flang/lib/Optimizer/Passes/Pipelines.cpp b/flang/lib/Optimizer/Passes/Pipelines.cpp index 1608d29d2db6e2..55a0b85618a707 100644 --- a/flang/lib/Optimizer/Passes/Pipelines.cpp +++ b/flang/lib/Optimizer/Passes/Pipelines.cpp @@ -75,6 +75,22 @@ getEmissionKind(llvm::codegenoptions::DebugInfoKind kind) { } } +static mlir::LLVM::DINameTableKind +getNameTableKind(Fortran::frontend::CodeGenOptions::DebugNameTableKind kind) { + using NameTableKind = Fortran::frontend::CodeGenOptions::DebugNameTableKind; + switch (kind) { + case NameTableKind::None: + return mlir::LLVM::DINameTableKind::None; + case NameTableKind::Default: + return mlir::LLVM::DINameTableKind::Default; + case NameTableKind::GNU: + return mlir::LLVM::DINameTableKind::GNU; + case NameTableKind::Apple: + return mlir::LLVM::DINameTableKind::Apple; + } + llvm_unreachable("unknown debug name table kind"); +} + void addDebugInfoPass(mlir::PassManager &pm, const MLIRToLLVMPassPipelineConfig &config, llvm::StringRef inputFilename) { @@ -86,6 +102,7 @@ void addDebugInfoPass(mlir::PassManager &pm, options.dwarfVersion = config.DwarfVersion; options.splitDwarfFile = config.SplitDwarfFile; options.dwarfDebugFlags = config.DwarfDebugFlags; + options.nameTableKind = getNameTableKind(config.DebugNameTable); options.emitFakeUseForDebugVars = (config.OptLevel == llvm::OptimizationLevel::O0) && !disableArgumentFakeUse; diff --git a/flang/lib/Optimizer/Transforms/AddDebugInfo.cpp b/flang/lib/Optimizer/Transforms/AddDebugInfo.cpp index 6d69a38f403fa8..b85c67456904f6 100644 --- a/flang/lib/Optimizer/Transforms/AddDebugInfo.cpp +++ b/flang/lib/Optimizer/Transforms/AddDebugInfo.cpp @@ -1262,10 +1262,10 @@ void AddDebugInfoPass::runOnOperation() { // points at, is never written. Asking for a name table would have that table // reference a label that does not exist. Clang leaves the name table off for // the same reason. - mlir::LLVM::DINameTableKind nameTableKind = + mlir::LLVM::DINameTableKind cuNameTableKind = debugLevel == mlir::LLVM::DIEmissionKind::DebugDirectivesOnly ? mlir::LLVM::DINameTableKind::None - : mlir::LLVM::DINameTableKind::Default; + : nameTableKind; // Each submodule compiled here imports the one above it, and those entries // hang off the compile unit. They are scoped at modules that name the unit // they are part of, so build them against a placeholder of it first, and give @@ -1280,7 +1280,7 @@ void AddDebugInfoPass::runOnOperation() { mlir::LLVM::DICompileUnitAttr cuAttr = mlir::LLVM::DICompileUnitAttr::get( mlir::DistinctAttr::create(mlir::UnitAttr::get(context)), llvm::dwarf::getLanguage("DW_LANG_Fortran95"), fileAttr, producer, - isOptimized, debugLevel, debugInfoForProfiling, nameTableKind, + isOptimized, debugLevel, debugInfoForProfiling, cuNameTableKind, splitDwarfFile.empty() ? mlir::StringAttr() : mlir::StringAttr::get(context, splitDwarfFile), cuImports); diff --git a/flang/test/Driver/debug-pubnames.f90 b/flang/test/Driver/debug-pubnames.f90 new file mode 100644 index 00000000000000..65cc2edd8c16a6 --- /dev/null +++ b/flang/test/Driver/debug-pubnames.f90 @@ -0,0 +1,48 @@ +! Test that -gpubnames and -ggnu-pubnames are passed on to the frontend, and +! that the last of these and their -gno- forms wins. + +! RUN: %flang -### -c -target x86_64 -g %s 2>&1 \ +! RUN: | FileCheck %s --check-prefix=NONE +! RUN: %flang -### -c -target x86_64 -g -gpubnames %s 2>&1 \ +! RUN: | FileCheck %s --check-prefix=PUB +! RUN: %flang -### -c -target x86_64 -g -ggnu-pubnames %s 2>&1 \ +! RUN: | FileCheck %s --check-prefix=GNU +! RUN: %flang -### -c -target x86_64 -g -ggnu-pubnames -gpubnames %s 2>&1 \ +! RUN: | FileCheck %s --check-prefix=PUB +! RUN: %flang -### -c -target x86_64 -g -gpubnames -ggnu-pubnames %s 2>&1 \ +! RUN: | FileCheck %s --check-prefix=GNU + +! The -gno- forms are accepted on their own, and each cancels both requests. +! RUN: %flang -### -c -target x86_64 -g -gno-pubnames %s 2>&1 \ +! RUN: | FileCheck %s --check-prefix=NONE +! RUN: %flang -### -c -target x86_64 -g -gno-gnu-pubnames %s 2>&1 \ +! RUN: | FileCheck %s --check-prefix=NONE +! RUN: %flang -### -c -target x86_64 -g -gpubnames -gno-pubnames %s 2>&1 \ +! RUN: | FileCheck %s --check-prefix=NONE +! RUN: %flang -### -c -target x86_64 -g -gpubnames -gno-gnu-pubnames %s \ +! RUN: 2>&1 | FileCheck %s --check-prefix=NONE +! RUN: %flang -### -c -target x86_64 -g -ggnu-pubnames -gno-gnu-pubnames %s \ +! RUN: 2>&1 | FileCheck %s --check-prefix=NONE +! RUN: %flang -### -c -target x86_64 -g -ggnu-pubnames -gno-pubnames %s 2>&1 \ +! RUN: | FileCheck %s --check-prefix=NONE +! RUN: %flang -### -c -target x86_64 -g -gno-pubnames -gpubnames %s 2>&1 \ +! RUN: | FileCheck %s --check-prefix=PUB +! RUN: %flang -### -c -target x86_64 -g -gno-gnu-pubnames -ggnu-pubnames %s \ +! RUN: 2>&1 | FileCheck %s --check-prefix=GNU + +! NONE-NOT: error: +! NONE: "-fc1" +! NONE-NOT: "-gpubnames" +! NONE-NOT: "-ggnu-pubnames" + +! PUB-NOT: error: +! PUB: "-fc1" +! PUB-NOT: "-ggnu-pubnames" +! PUB-SAME: "-gpubnames" +! PUB-NOT: "-ggnu-pubnames" + +! GNU-NOT: error: +! GNU: "-fc1" +! GNU-NOT: "-gpubnames" +! GNU-SAME: "-ggnu-pubnames" +! GNU-NOT: "-gpubnames" diff --git a/flang/test/Integration/debug-common-block-1.f90 b/flang/test/Integration/debug-common-block-1.f90 index 07488073377513..66bd36437740d3 100644 --- a/flang/test/Integration/debug-common-block-1.f90 +++ b/flang/test/Integration/debug-common-block-1.f90 @@ -118,7 +118,7 @@ program test ! CHECK-DAG-SAME: !dbg ![[EXPVA2]] ! CHECK-DAG-SAME: !dbg ![[EXPVA3]] -! CHECK-DAG: !DICompileUnit({{.*}}, globals: ![[GLOBALS:[0-9]+]]) +! CHECK-DAG: !DICompileUnit({{.*}}, globals: ![[GLOBALS:[0-9]+]] ! CHECK-DAG: ![[GLOBALS]] ! CHECK-DAG-SAME: ![[EXPXF1]] ! CHECK-DAG-SAME: ![[EXPYF1]] diff --git a/flang/test/Integration/debug-line-directives-only.f90 b/flang/test/Integration/debug-line-directives-only.f90 index 7d49d9f0cf8a57..82ef8f0a65301a 100644 --- a/flang/test/Integration/debug-line-directives-only.f90 +++ b/flang/test/Integration/debug-line-directives-only.f90 @@ -2,6 +2,8 @@ ! RUN: %flang_fc1 -debug-info-kind=line-directives-only -emit-llvm -o - %s \ ! RUN: | FileCheck %s +! RUN: %flang_fc1 -debug-info-kind=line-directives-only -gpubnames \ +! RUN: -emit-llvm -o - %s | FileCheck %s ! CHECK: !DICompileUnit({{.*}}emissionKind: DebugDirectivesOnly ! CHECK-SAME: nameTableKind: None diff --git a/flang/test/Integration/debug-module-2.f90 b/flang/test/Integration/debug-module-2.f90 index bd5dd63508148c..2913071f87a420 100644 --- a/flang/test/Integration/debug-module-2.f90 +++ b/flang/test/Integration/debug-module-2.f90 @@ -5,7 +5,7 @@ ! More than one DIFile can name this source, so take the one the module is ! described in from the module itself rather than trying to tell them apart by ! how each spells the path. -! CHECK-DAG: ![[CU:.*]] = distinct !DICompileUnit({{.*}}globals: ![[GLOBALS:.*]]) +! CHECK-DAG: ![[CU:.*]] = distinct !DICompileUnit({{.*}}globals: ![[GLOBALS:[0-9]+]] ! CHECK-DAG: ![[MOD:.*]] = !DIModule(scope: ![[CU]], name: "helper", file: ![[FILE:[0-9]+]]{{.*}}) ! CHECK-DAG: ![[FILE]] = !DIFile(filename: "debug-module-2.f90"{{.*}}) ! CHECK-DAG: ![[R4:.*]] = !DIBasicType(name: "real(kind=4)", size: 32, encoding: DW_ATE_float) diff --git a/flang/test/Integration/debug-name-table.f90 b/flang/test/Integration/debug-name-table.f90 new file mode 100644 index 00000000000000..d7bef7ef848eee --- /dev/null +++ b/flang/test/Integration/debug-name-table.f90 @@ -0,0 +1,27 @@ +! Test that the compile unit asks for a name table only when -gpubnames or +! -ggnu-pubnames is given, and that Apple targets always ask for Apple ones. + +! REQUIRES: x86-registered-target + +! RUN: %flang_fc1 -triple x86_64-unknown-linux-gnu -emit-llvm \ +! RUN: -debug-info-kind=standalone -o - %s | FileCheck %s --check-prefix=NONE +! RUN: %flang_fc1 -triple x86_64-unknown-linux-gnu -emit-llvm \ +! RUN: -debug-info-kind=standalone -gpubnames -o - %s \ +! RUN: | FileCheck %s --check-prefix=DEFAULT +! RUN: %flang_fc1 -triple x86_64-unknown-linux-gnu -emit-llvm \ +! RUN: -debug-info-kind=standalone -ggnu-pubnames -o - %s \ +! RUN: | FileCheck %s --check-prefix=GNU +! RUN: %flang_fc1 -triple x86_64-apple-macosx -emit-llvm \ +! RUN: -debug-info-kind=standalone -o - %s | FileCheck %s --check-prefix=APPLE +! RUN: %flang_fc1 -triple x86_64-apple-macosx -emit-llvm \ +! RUN: -debug-info-kind=standalone -ggnu-pubnames -o - %s \ +! RUN: | FileCheck %s --check-prefix=APPLE + +! NONE: !DICompileUnit({{.*}}nameTableKind: None +! DEFAULT: !DICompileUnit( +! DEFAULT-NOT: nameTableKind +! GNU: !DICompileUnit({{.*}}nameTableKind: GNU +! APPLE: !DICompileUnit({{.*}}nameTableKind: Apple + +program test +end program test diff --git a/flang/test/Transforms/debug-line-table-inc-file.fir b/flang/test/Transforms/debug-line-table-inc-file.fir index 9e623dde153b7b..b60b1c3c9e00aa 100644 --- a/flang/test/Transforms/debug-line-table-inc-file.fir +++ b/flang/test/Transforms/debug-line-table-inc-file.fir @@ -30,7 +30,7 @@ module { // CHECK: #[[MODULE_LOC]] = loc("{{.*}}simple.f90":0:0) // CHECK: #[[LOC_INC_FILE:.*]] = loc("{{.*}}inc.f90":1:1) // CHECK: #[[LOC_FILE:.*]] = loc("{{.*}}simple.f90":3:1) -// CHECK: #[[DI_CU:.*]] = #llvm.di_compile_unit<id = distinct[{{.*}}]<>, sourceLanguage = DW_LANG_Fortran95, file = #[[DI_FILE]], producer = "{{.*}}flang{{.*}}", emissionKind = LineTablesOnly> +// CHECK: #[[DI_CU:.*]] = #llvm.di_compile_unit<id = distinct[{{.*}}]<>, sourceLanguage = DW_LANG_Fortran95, file = #[[DI_FILE]], producer = "{{.*}}flang{{.*}}", emissionKind = LineTablesOnly // CHECK: #[[DI_SP_INC:.*]] = #llvm.di_subprogram<{{.*}}id = distinct[{{.*}}]<>, compileUnit = #[[DI_CU]], scope = #[[DI_FILE]], name = "sinc", linkageName = "_QPsinc", file = #[[DI_INC_FILE]], {{.*}}> // CHECK: #[[DI_SP:.*]] = #llvm.di_subprogram<{{.*}}id = distinct[{{.*}}]<>, compileUnit = #[[DI_CU]], scope = #[[DI_FILE]], name = "_QQmain", linkageName = "_QQmain", file = #[[DI_FILE]], {{.*}}> // CHECK: #[[FUSED_LOC_INC_FILE]] = loc(fused<#[[DI_SP_INC]]>[#[[LOC_INC_FILE]]]) diff --git a/flang/test/Transforms/debug-line-table.fir b/flang/test/Transforms/debug-line-table.fir index 1c5ac6491d849a..09acddd1839070 100644 --- a/flang/test/Transforms/debug-line-table.fir +++ b/flang/test/Transforms/debug-line-table.fir @@ -25,9 +25,9 @@ module { // CHECK: #[[MODULE_LOC]] = loc("[[DIR_NAME]]/[[FILE_NAME]]":1:1) // CHECK: #[[SB_LOC]] = loc("./simple.f90":2:1) // CHECK: #[[DECL_LOC:.*]] = loc("./simple.f90":10:1) -// FULL: #di_compile_unit = #llvm.di_compile_unit<id = distinct[{{.*}}]<>, sourceLanguage = DW_LANG_Fortran95, file = #di_file, producer = "{{.*}}flang{{.*}}", emissionKind = Full> -// OPT: #di_compile_unit = #llvm.di_compile_unit<id = distinct[{{.*}}]<>, sourceLanguage = DW_LANG_Fortran95, file = #di_file, producer = "{{.*}}flang{{.*}}", isOptimized = true, emissionKind = Full> -// LINETABLE: #di_compile_unit = #llvm.di_compile_unit<id = distinct[{{.*}}]<>, sourceLanguage = DW_LANG_Fortran95, file = #di_file, producer = "{{.*}}flang{{.*}}", emissionKind = LineTablesOnly> +// FULL: #di_compile_unit = #llvm.di_compile_unit<id = distinct[{{.*}}]<>, sourceLanguage = DW_LANG_Fortran95, file = #di_file, producer = "{{.*}}flang{{.*}}", emissionKind = Full +// OPT: #di_compile_unit = #llvm.di_compile_unit<id = distinct[{{.*}}]<>, sourceLanguage = DW_LANG_Fortran95, file = #di_file, producer = "{{.*}}flang{{.*}}", isOptimized = true, emissionKind = Full +// LINETABLE: #di_compile_unit = #llvm.di_compile_unit<id = distinct[{{.*}}]<>, sourceLanguage = DW_LANG_Fortran95, file = #di_file, producer = "{{.*}}flang{{.*}}", emissionKind = LineTablesOnly // DIRECTIVES: #di_compile_unit = #llvm.di_compile_unit<id = distinct[{{.*}}]<>, sourceLanguage = DW_LANG_Fortran95, file = #di_file, producer = "{{.*}}flang{{.*}}", emissionKind = DebugDirectivesOnly, nameTableKind = None> // CHECK: #di_subroutine_type = #llvm.di_subroutine_type<callingConvention = DW_CC_normal, types = #di_basic_type, #di_basic_type> // CHECK: #[[SB_SUBPROGRAM:.*]] = #llvm.di_subprogram<id = distinct[{{.*}}]<>, compileUnit = #di_compile_unit, scope = #di_file, name = "[[SB_NAME]]", linkageName = "[[SB_NAME]]", file = #di_file, line = 1, scopeLine = 1, subprogramFlags = "Definition|Optimized", type = #di_subroutine_type> diff --git a/flang/test/Transforms/debug-name-table.fir b/flang/test/Transforms/debug-name-table.fir new file mode 100644 index 00000000000000..637c68b6e66909 --- /dev/null +++ b/flang/test/Transforms/debug-name-table.fir @@ -0,0 +1,31 @@ +// Test the name table that the compile unit asks for. + +// RUN: fir-opt --add-debug-info --mlir-print-debuginfo %s \ +// RUN: | FileCheck %s --check-prefix=NONE +// RUN: fir-opt --add-debug-info="name-table-kind=None" --mlir-print-debuginfo \ +// RUN: %s | FileCheck %s --check-prefix=NONE +// RUN: fir-opt --add-debug-info="name-table-kind=Default" \ +// RUN: --mlir-print-debuginfo %s | FileCheck %s --check-prefix=DEFAULT +// RUN: fir-opt --add-debug-info="name-table-kind=GNU" --mlir-print-debuginfo \ +// RUN: %s | FileCheck %s --check-prefix=GNU +// RUN: fir-opt --add-debug-info="name-table-kind=Apple" --mlir-print-debuginfo \ +// RUN: %s | FileCheck %s --check-prefix=APPLE + +// A unit that only emits line directives gets no name table, even when one +// is asked for. +// RUN: fir-opt --add-debug-info="debug-level=DebugDirectivesOnly name-table-kind=Default" \ +// RUN: --mlir-print-debuginfo %s | FileCheck %s --check-prefix=NONE + +module { + func.func @_QPsb() { + return loc(#loc_sb) + } loc(#loc_sb) +} loc(#loc_module) +#loc_module = loc("./simple.f90":1:1) +#loc_sb = loc("./simple.f90":2:1) + +// NONE: #llvm.di_compile_unit<{{.*}}nameTableKind = None +// DEFAULT: #llvm.di_compile_unit< +// DEFAULT-NOT: nameTableKind +// GNU: #llvm.di_compile_unit<{{.*}}nameTableKind = GNU +// APPLE: #llvm.di_compile_unit<{{.*}}nameTableKind = Apple _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
