Index: lib/Driver/ToolChains/Clang.cpp =================================================================== --- lib/Driver/ToolChains/Clang.cpp +++ lib/Driver/ToolChains/Clang.cpp @@ -2728,7 +2728,8 @@ DwarfVersion = getToolChain().GetDefaultDwarfVersion(); } - // We ignore flags -gstrict-dwarf and -grecord-gcc-switches for now. + // We ignore flag -gstrict-dwarf for now. + // And we handle flag -grecord-gcc-switches later with DwarfDebugFlags. Args.ClaimAllArgs(options::OPT_g_flags_Group); // Column info is included by default for everything except PS4 and CodeView. @@ -4321,7 +4322,12 @@ // Optionally embed the -cc1 level arguments into the debug info, for build // analysis. - if (getToolChain().UseDwarfDebugFlags()) { + // Also record command line arguments into the debug info if + // -grecord-gcc-switches options is set on. + // By default, -gno-record-gcc-switches is set on and no recording. + if (getToolChain().UseDwarfDebugFlags() || + Args.hasFlag(options::OPT_grecord_gcc_switches, + options::OPT_gno_record_gcc_switches, false)) { ArgStringList OriginalArgs; for (const auto &Arg : Args) Arg->render(Args, OriginalArgs); Index: test/Driver/debug-options.c =================================================================== --- test/Driver/debug-options.c +++ test/Driver/debug-options.c @@ -117,8 +117,18 @@ // RUN: %clang -### -c -gline-tables-only -g0 %s 2>&1 \ // RUN: | FileCheck -check-prefix=GLTO_NO %s // -// RUN: %clang -### -c -grecord-gcc-switches -gno-record-gcc-switches \ -// RUN: -gstrict-dwarf -gno-strict-dwarf %s 2>&1 \ +// RUN: %clang -### -c -grecord-gcc-switches %s 2>&1 \ +// | FileCheck -check-prefix=GRECORD %s +// RUN: %clang -### -c -gno-record-gcc-switches %s 2>&1 \ +// | FileCheck -check-prefix=GNO_RECORD %s +// RUN: %clang -### -c -grecord-gcc-switches -gno-record-gcc-switches %s 2>&1 \ +// | FileCheck -check-prefix=GNO_RECORD %s/ +// RUN: %clang -### -c -grecord-gcc-switches -o - %s 2>&1 \ +// | FileCheck -check-prefix=GRECORD_O %s +// RUN: %clang -### -c -O3 -ffunction-sections -grecord-gcc-switches %s 2>&1 \ +// | FileCheck -check-prefix=GRECORD_OPT %s +// +// RUN: %clang -### -c -gstrict-dwarf -gno-strict-dwarf %s 2>&1 \ // RUN: | FileCheck -check-prefix=GIGNORE %s // // RUN: %clang -### -c -ggnu-pubnames %s 2>&1 | FileCheck -check-prefix=GOPT %s @@ -194,6 +204,17 @@ // GLTO_NO: "-cc1" // GLTO_NO-NOT: -debug-info-kind= // +// GRECORD: "-dwarf-debug-flags" +// GRECORD: -### -c -grecord-gcc-switches +// +// GNO_RECORD-NOT: "-dwarf-debug-flags" +// GNO_RECORD-NOT: -### -c -grecord-gcc-switches +// +// GRECORD_O: "-dwarf-debug-flags" +// GRECORD_O: -### -c -grecord-gcc-switches -o - +// +// GRECORD_OPT: -### -c -O3 -ffunction-sections -grecord-gcc-switches +// // GIGNORE-NOT: "argument unused during compilation" // // GOPT: -generate-gnu-dwarf-pub-sections