Hi! The driver enables -dD when preprocessing when -g3 is specified, for obvious reasons that we need the macros to be preserved somewhere for them to make up the debug info. But it enables it even if -g3 is later overridden to -g2, -g1 or -g0, where we in the end don't emit .debug_mac{ros,info}.
The following patch passes -dD only if we'll need it. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2020-11-26 Jakub Jelinek <ja...@redhat.com> PR debug/97989 * gcc.c (cpp_unique_options): Add -dD if %:debug-level-gt(2) rather than g3|ggdb3|gstabs3|gxcoff3|gvms3. * gcc.dg/cpp/pr97989-1.c: New test. * gcc.dg/cpp/pr97989-2.c: New test. --- gcc/gcc.c.jj 2020-11-18 09:40:09.680662345 +0100 +++ gcc/gcc.c 2020-11-25 18:35:29.255919853 +0100 @@ -1212,7 +1212,7 @@ static const char *cpp_unique_options = %{MMD:-MMD %{!o:%b.d}%{o*:%.d%*}}\ %{M} %{MM} %{MF*} %{MG} %{MP} %{MQ*} %{MT*}\ %{!E:%{!M:%{!MM:%{!MT:%{!MQ:%{MD|MMD:%{o*:-MQ %*}}}}}}}\ - %{remap} %{g3|ggdb3|gstabs3|gxcoff3|gvms3:-dD}\ + %{remap} %{%:debug-level-gt(2):-dD}\ %{!iplugindir*:%{fplugin*:%:find-plugindir()}}\ %{H} %C %{D*&U*&A*} %{i*} %Z %i\ %{E|M|MM:%W{o*}}"; --- gcc/testsuite/gcc.dg/cpp/pr97989-1.c.jj 2020-11-25 18:30:34.008243484 +0100 +++ gcc/testsuite/gcc.dg/cpp/pr97989-1.c 2020-11-25 18:33:31.504245962 +0100 @@ -0,0 +1,8 @@ +/* PR debug/97989 */ +/* { dg-do preprocess } */ +/* { dg-options "-g3 -g2 -P" } */ + +#define foo bar +int i; + +/* { dg-final { scan-file-not pr97989-1.i "(^|\\n)#define foo bar($|\\n)" } } */ --- gcc/testsuite/gcc.dg/cpp/pr97989-2.c.jj 2020-11-25 18:32:23.291013634 +0100 +++ gcc/testsuite/gcc.dg/cpp/pr97989-2.c 2020-11-25 18:33:39.467156290 +0100 @@ -0,0 +1,8 @@ +/* PR debug/97989 */ +/* { dg-do preprocess } */ +/* { dg-options "-g2 -g3 -P" } */ + +#define foo bar +int i; + +/* { dg-final { scan-file pr97989-2.i "(^|\\n)#define foo bar($|\\n)" } } */ Jakub