diff --git a/clang/include/clang/Basic/CodeGenOptions.def b/clang/include/clang/Basic/CodeGenOptions.def --- a/clang/include/clang/Basic/CodeGenOptions.def +++ b/clang/include/clang/Basic/CodeGenOptions.def @@ -135,6 +135,8 @@ ///< enabled. CODEGENOPT(NoWarn , 1, 0) ///< Set when -Wa,--no-warn is enabled. CODEGENOPT(EnableSegmentedStacks , 1, 0) ///< Set when -fsplit-stack is enabled. +CODEGENOPT(NoInlineLineTables, 1, 0) ///< Whether debug info should contain + ///< inline line tables. CODEGENOPT(NoImplicitFloat , 1, 0) ///< Set when -mno-implicit-float is enabled. CODEGENOPT(NoInfsFPMath , 1, 0) ///< Assume FP arguments, results not +-Inf. CODEGENOPT(NoSignedZeros , 1, 0) ///< Allow ignoring the signedness of FP zero diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -1938,6 +1938,9 @@ HelpText<"Emit type record hashes in a .debug$H section">, Flags<[CC1Option, CoreOption]>; def gno_codeview_ghash : Flag<["-"], "gno-codeview-ghash">, Flags<[CoreOption]>; +def ginline_line_tables : Flag<["-"], "ginline-line-tables">, Flags<[CoreOption]>; +def gno_inline_line_tables : Flag<["-"], "gno-inline-line-tables">, + Flags<[CC1Option, CoreOption]>, HelpText<"Don't emit inline line tables">; // Equivalent to our default dwarf version. Forces usual dwarf emission when // CodeView is enabled. diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -764,6 +764,10 @@ Fn->addFnAttr("no-jump-tables", llvm::toStringRef(CGM.getCodeGenOpts().NoUseJumpTables)); + // Add no-inline-line-tables value. + if (CGM.getCodeGenOpts().NoInlineLineTables) + Fn->addFnAttr("no-inline-line-tables"); + // Add profile-sample-accurate value. if (CGM.getCodeGenOpts().ProfileSampleAccurate) Fn->addFnAttr("profile-sample-accurate"); diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -3374,6 +3374,12 @@ options::OPT_gno_codeview_ghash, false)) { CmdArgs.push_back("-gcodeview-ghash"); } + + // Omit inline line tables if requested. + if (!Args.hasFlag(options::OPT_ginline_line_tables, + options::OPT_gno_inline_line_tables, false)) { + CmdArgs.push_back("-gno-inline-line-tables"); + } } // Adjust the debug info kind for the given toolchain. diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -800,6 +800,7 @@ Opts.RecordCommandLine = Args.getLastArgValue(OPT_record_command_line); Opts.MergeAllConstants = Args.hasArg(OPT_fmerge_all_constants); Opts.NoCommon = Args.hasArg(OPT_fno_common); + Opts.NoInlineLineTables = Args.hasArg(OPT_gno_inline_line_tables); Opts.NoImplicitFloat = Args.hasArg(OPT_no_implicit_float); Opts.OptimizeSize = getOptimizationLevelSize(Args); Opts.SimplifyLibCalls = !(Args.hasArg(OPT_fno_builtin) || diff --git a/clang/test/CodeGen/debug-info-no-inline-line-tables.c b/clang/test/CodeGen/debug-info-no-inline-line-tables.c new file mode 100644 --- /dev/null +++ b/clang/test/CodeGen/debug-info-no-inline-line-tables.c @@ -0,0 +1,20 @@ +// RUN: %clang_cc1 -triple x86_64-windows-msvc -gcodeview -debug-info-kind=limited \ +// RUN: -gno-inline-line-tables -emit-llvm -o - %s | FileCheck %s +// Check that clang doesn't emit the location of the inlined function in the +// debug info. + +int x; +__attribute((always_inline)) void f() { + x += 1; +} +int main() { + f(); + x += 2; + return x; +} + +// CHECK-LABEL: define dso_local i32 @main() +// CHECK: %{{.+}} = load i32, i32* @x, align 4, !dbg [[DbgLoc:![0-9]+]] +// CHECK: [[DbgLoc]] = distinct !DILocation( +// CHECK-SAME: line: 11, +// CHECK-NOT: inlinedAt: diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst --- a/llvm/docs/LangRef.rst +++ b/llvm/docs/LangRef.rst @@ -1433,6 +1433,10 @@ ``naked`` This attribute disables prologue / epilogue emission for the function. This can have very system-specific consequences. +``no-inline-line-tables`` + When this attribute is set to true, inline line tables are not generated + for this function if it is inlined and the location of the inlined code + becomes the call site. ``no-jump-tables`` When this attribute is set to true, the jump tables and lookup tables that can be generated from a switch case lowering are disabled. diff --git a/llvm/include/llvm/IR/Attributes.td b/llvm/include/llvm/IR/Attributes.td --- a/llvm/include/llvm/IR/Attributes.td +++ b/llvm/include/llvm/IR/Attributes.td @@ -220,6 +220,7 @@ def NoNansFPMath : StrBoolAttr<"no-nans-fp-math">; def UnsafeFPMath : StrBoolAttr<"unsafe-fp-math">; def NoJumpTables : StrBoolAttr<"no-jump-tables">; +def NoInlineLineTables : StrBoolAttr<"no-inline-line-tables">; def ProfileSampleAccurate : StrBoolAttr<"profile-sample-accurate">; class CompatRule { diff --git a/llvm/lib/Transforms/Utils/InlineFunction.cpp b/llvm/lib/Transforms/Utils/InlineFunction.cpp --- a/llvm/lib/Transforms/Utils/InlineFunction.cpp +++ b/llvm/lib/Transforms/Utils/InlineFunction.cpp @@ -1417,6 +1417,13 @@ } if (DebugLoc DL = BI->getDebugLoc()) { + // If we are not generating inline line tables, set the debug location + // of the inlined code to be the call site. + if (Fn->hasFnAttribute("no-inline-line-tables")) { + BI->setDebugLoc(InlinedAtNode); + continue; + } + DebugLoc IDL = inlineDebugLoc(DL, InlinedAtNode, BI->getContext(), IANodes); BI->setDebugLoc(IDL);