Bug 25717 - [4.0 Regression] -dD does not list all defined macros (in particular, __STDC__)
Summary: [4.0 Regression] -dD does not list all defined macros (in particular, __STDC__)
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: preprocessor (show other bugs)
Version: 3.4.3
: P2 normal
Target Milestone: 4.1.0
Assignee: Jakub Jelinek
URL: http://gcc.gnu.org/ml/gcc-patches/200...
Keywords:
Depends on:
Blocks:
 
Reported: 2006-01-08 22:51 UTC by Shaun Clowes
Modified: 2007-02-03 16:10 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work: 3.2.3 4.1.0 4.2.0
Known to fail: 3.3.3 3.4.0 4.0.0
Last reconfirmed: 2006-01-16 13:47:58


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Shaun Clowes 2006-01-08 22:51:39 UTC
The -dM option is documented to provide a complete list of all defined macros, including all predefined macros, however the list is incomplete. In particular, the following will not list __STDC__ even though it is defined:

   touch test.h; gcc -dM test.h

If you modify test.h to include:

   #ifdef __STDC__
      #error __STDC__ is defined
   #endif

The compilation will result in an error
Comment 1 Andrew Pinski 2006-01-09 00:27:20 UTC
Hmm, __STDC__ is treated special inside the preprocessor.
Comment 2 Andrew Pinski 2006-01-09 01:28:51 UTC
Actually this is a true bug and it was fixed in the past too:
http://gcc.gnu.org/ml/gcc-patches/2001-02/msg01533.html

I have to see where it started to fail now.

Confirmed.
Comment 3 Andrew Pinski 2006-01-09 01:31:35 UTC
Hmm, when cpp0 was removed in 3.3, this was caused.
Comment 4 Steven Bosscher 2006-01-09 21:57:02 UTC
Your command line:

   touch test.h; gcc -dM test.h

creates a precompiled header.

Also, my documentation for -dM says:

@item -dM
@itemx -fdump-rtl-mach
@opindex dM
@opindex fdump-rtl-mach
Dump after performing the machine dependent reorganization pass, to
@file{@var{file}.35.mach}.


What you want is -dD.  But I'm not sure what that is supposed to write out.  GCC 3.3, 4.0, and 4.1 all give no output at all for an empty file, or a file with a single #define.
Comment 5 Steven Bosscher 2006-01-09 22:00:28 UTC
I get a lot of output with:
$ gcc -E -dD test.c

Perhaps that is what you're looking for.  This looks more like a documentation bug to me than a real preprocessor bug.
Comment 6 Andrew Pinski 2006-01-09 22:08:15 UTC
(In reply to comment #5)
> I get a lot of output with:
> $ gcc -E -dD test.c
> 
> Perhaps that is what you're looking for.  This looks more like a documentation
> bug to me than a real preprocessor bug.

It is not, -dD should include __STDC__ and it does in pre 3.3 but not post 3.3 when cpp0 went away.  I forgot to update the summary when I confirmed it after fixing the testcase.
Comment 7 Mark Mitchell 2006-01-15 22:30:45 UTC
This is not critical, as it only affects secondary uses of the compiler.
Comment 8 Jakub Jelinek 2006-01-23 21:50:19 UTC
Subject: Bug 25717

Author: jakub
Date: Mon Jan 23 21:50:15 2006
New Revision: 110144

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=110144
Log:
	PR preprocessor/25717
	* init.c (cpp_init_builtins): If __STDC__ will not change value
	between system headers and other sources, define it as a normal
	macro rather than a builtin.
	* macro.c (_cpp_builtin_macro_text) <case BT_STDC>: Only check
	cpp_in_system_header condition.

Modified:
    trunk/libcpp/ChangeLog
    trunk/libcpp/init.c
    trunk/libcpp/macro.c

Comment 9 Jakub Jelinek 2006-01-23 21:51:12 UTC
Subject: Bug 25717

Author: jakub
Date: Mon Jan 23 21:51:10 2006
New Revision: 110145

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=110145
Log:
	PR preprocessor/25717
	* init.c (cpp_init_builtins): If __STDC__ will not change value
	between system headers and other sources, define it as a normal
	macro rather than a builtin.
	* macro.c (_cpp_builtin_macro_text) <case BT_STDC>: Only check
	cpp_in_system_header condition.

Modified:
    branches/gcc-4_1-branch/libcpp/ChangeLog
    branches/gcc-4_1-branch/libcpp/init.c
    branches/gcc-4_1-branch/libcpp/macro.c

Comment 10 Gabriel Dos Reis 2007-02-03 16:10:53 UTC
Fixed in GCC-4.1.0 and higher.