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 @@ -333,6 +333,8 @@ VALUE_CODEGENOPT(WarnStackSize , 32, UINT_MAX) ///< Set via -fwarn-stack-size. CODEGENOPT(NoStackArgProbe, 1, 0) ///< Set when -mno-stack-arg-probe is used CODEGENOPT(DebugStrictDwarf, 1, 1) ///< Whether or not to use strict DWARF info. +/// Whether or not to include all members in a type in debug info. +CODEGENOPT(DebugIncompleteTypes, 1, 0) /// Control the Assignment Tracking debug info feature. ENUM_CODEGENOPT(AssignmentTrackingMode, AssignmentTrackingOpts, 2, AssignmentTrackingOpts::Disabled) 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 @@ -3346,6 +3346,10 @@ CodeGenOpts<"DebugStrictDwarf">, DefaultFalse, PosFlag, NegFlag, BothFlags<[CoreOption]>>, Group; +defm incomplete_types : BoolOption<"g", "incomplete-types", + CodeGenOpts<"DebugIncompleteTypes">, DefaultFalse, + PosFlag, NegFlag, BothFlags<[CoreOption]>>, + Group; defm column_info : BoolOption<"g", "column-info", CodeGenOpts<"DebugColumnInfo">, DefaultTrue, NegFlag, PosFlag, BothFlags<[CoreOption]>>, diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp --- a/clang/lib/CodeGen/CGDebugInfo.cpp +++ b/clang/lib/CodeGen/CGDebugInfo.cpp @@ -2740,7 +2740,7 @@ // Collect data fields (including static variables and any initializers). CollectRecordFields(RD, DefUnit, EltTys, FwdDecl); - if (CXXDecl) + if (CXXDecl && !CGM.getCodeGenOpts().DebugIncompleteTypes) CollectCXXMemberFunctions(CXXDecl, DefUnit, EltTys, FwdDecl); LexicalBlockStack.pop_back(); 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 @@ -4308,6 +4308,12 @@ DebuggerTuning != llvm::DebuggerKind::DBX))) CmdArgs.push_back("-gno-column-info"); + if (const Arg *A = Args.getLastArg(options::OPT_gincomplete_types)) + (void)checkDebugInfoOption(A, Args, D, TC); + if (Args.hasFlag(options::OPT_gincomplete_types, + options::OPT_gno_incomplete_types, false)) + CmdArgs.push_back("-gincomplete-types"); + // FIXME: Move backend command line options to the module. if (Args.hasFlag(options::OPT_gmodules, options::OPT_gno_modules, false)) { // If -gline-tables-only or -gline-directives-only is the last option it diff --git a/clang/test/CodeGenCXX/debug-info-incomplete-types.cpp b/clang/test/CodeGenCXX/debug-info-incomplete-types.cpp new file mode 100644 --- /dev/null +++ b/clang/test/CodeGenCXX/debug-info-incomplete-types.cpp @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 -debug-info-kind=limited -gincomplete-types %s -emit-llvm -o - | FileCheck %s + +struct t1 { + void f1(); + void f2(); +}; + +void t1::f1() { } + +// CHECK: distinct !DICompositeType(tag: DW_TAG_structure_type, name: "t1" +// CHECK-SAME: elements: [[ELEMENTS:![0-9]+]] +// CHECK: [[ELEMENTS]] = !{} diff --git a/clang/test/Driver/debug-options.c b/clang/test/Driver/debug-options.c --- a/clang/test/Driver/debug-options.c +++ b/clang/test/Driver/debug-options.c @@ -259,6 +259,9 @@ // RUN: %clang -### -c %s 2>&1 | FileCheck -check-prefix=NORNGBSE %s // RUN: %clang -### -c -fdebug-ranges-base-address -fno-debug-ranges-base-address %s 2>&1 | FileCheck -check-prefix=NORNGBSE %s // +// RUN: %clang -### -c -gincomplete-types %s 2>&1 | FileCheck -check-prefix=INCTYPES %s +// RUN: %clang -### -c %s 2>&1 | FileCheck -check-prefix=NOINCTYPES %s +// // RUN: %clang -### -c -glldb %s 2>&1 | FileCheck -check-prefix=NOPUB %s // RUN: %clang -### -c -glldb -gno-pubnames %s 2>&1 | FileCheck -check-prefix=NOPUB %s // @@ -398,6 +401,9 @@ // RNGBSE: -fdebug-ranges-base-address // NORNGBSE-NOT: -fdebug-ranges-base-address // +// INCTYPES: -gincomplete-types +// NOINCTYPES-NOT: -gincomplete-types +// // GARANGE-DAG: -generate-arange-section // // FDTS: "-mllvm" "-generate-type-units"