gcc/libcpp
Dodji Seketeli 7ca643e17e PR preprocessor/53463 - Fix system header detection for built-in macro tokens
The location for a built-in macro token is BUILTIN_LOCATION.  When we
see that location value, we cannot know if that token was used in a
system header or not.  And that can trigger some unwanted warnings on
e.g, the use of __LONG_LONG_MAX__ built-in macro in system headers
when we compile with -pedantic, like in the test case accompanying
this patch.

In that case, I think we ought to step-up to see where the built-in
macro has been expanded, until we see a location that is not for a
built-in macro.  Then we can check if the resulting location is in a
system header or not.

Now that we step up to the location of first non-built-in-macro token,
it appeared that for
testsuite/c-c++-common/dfp/convert-int-saturate.c, G++ then fails to
emit the warning in:

    volatile unsigned int usi;
    int
    main ()
    {
      usi = DEC32_MAX;  /* { dg-warning "overflow in implicit constant conversion" } */
     ...
    }

Because DEC32_MAX is defined in the system header float.h as a
built-in macro:

    #define DEC32_MAX	__DEC32_MAX__

And during the parsing of the assignment expression that should have
led to the warning above, input_location is set to the location for
the DEC32_MAX, which is actually the location for the built-in
__DECL32_MAX_EXP.

A possible fix is to use the location of the "=" operator as the
default location for assignment expressions.  This is what the patch
does.

I had to adjust a couple of tests to arrange for this.

Bootstrapped and tested on x86_64-unknown-linux-gnu against trunk.

libcpp/

	PR preprocessor/53463
	* line-map.c (linemap_location_in_system_header_p): For built-in
	macro tokens, check the first expansion point location for that is
	not for a token coming from a built-in macro.

gcc/cp/

	PR preprocessor/53463
	* parser.c (cp_parser_assignment_expression): Use the location
	for the LHS as the default location for the expression.

gcc/testsuite/

	PR preprocessor/53463
	* g++.dg/cpp/limits.C: New test.
	* g++.dg/parse/error19.C: Adjust.
	* g++.dg/warn/Wconversion-real-integer2.C: Likewise.
	* g++.dg/warn/pr35635.C: Likewise.
	* g++.old-deja/g++.pt/assign1.C: Likewise.

From-SVN: r188203
2012-06-04 21:19:58 +02:00
..
include directives.c: Fix typos. 2012-05-29 15:53:50 +01:00
po * vi.po: Update. 2012-04-24 23:16:24 +01:00
ChangeLog PR preprocessor/53463 - Fix system header detection for built-in macro tokens 2012-06-04 21:19:58 +02:00
Makefile.in re PR bootstrap/50857 (The compiler is built with exceptions and RTTI enabled) 2011-11-03 17:17:07 +00:00
aclocal.m4 Undo inadvertent commit in rev 160105. 2010-06-01 10:20:24 -04:00
charset.c Update Copyright years for files modified in 2010. 2011-01-03 21:52:22 +01:00
config.in re PR bootstrap/45538 (--enable-build-with-cxx compiling gcc/libcpp/charset.c) 2010-11-18 07:35:34 +00:00
configure Add ports for TILE-Gx and TILEPro. 2012-02-14 10:02:21 +00:00
configure.ac Add ports for TILE-Gx and TILEPro. 2012-02-14 10:02:21 +00:00
directives-only.c LINEMAP_POSITION_FOR_COLUMN had the exact same effect as linemap_position_for_column... 2011-08-15 20:35:58 +00:00
directives.c directives.c: Fix typos. 2012-05-29 15:53:50 +01:00
errors.c Update Copyright years for files modified in 2010. 2011-01-03 21:52:22 +01:00
expr.c PR preprocessor/7263 - Avoid pedantic warnings on system headers macro tokens 2012-05-16 12:51:15 +02:00
files.c re PR c++/52974 (Canonicalize include paths in diagnostics) 2012-04-30 16:57:22 +00:00
identifiers.c Licensing changes to GPLv3 resp. GPLv3 with GCC Runtime Exception. 2009-04-09 17:00:19 +02:00
init.c Switch -ftrack-macro-expansion=2 on by default. 2012-04-30 13:43:43 +02:00
internal.h PR preprocessor/53229 - Fix diagnostics location when pasting tokens 2012-05-29 11:36:29 +02:00
lex.c PR bootstrap/53459 - unused local typedef when building on altivec 2012-05-29 11:42:39 +02:00
line-map.c PR preprocessor/53463 - Fix system header detection for built-in macro tokens 2012-06-04 21:19:58 +02:00
macro.c directives.c: Fix typos. 2012-05-29 15:53:50 +01:00
makeucnid.c Licensing changes to GPLv3 resp. GPLv3 with GCC Runtime Exception. 2009-04-09 17:00:19 +02:00
mkdeps.c files.c (file_hash_eq): Use filename_cmp instead of strcmp. 2011-03-25 20:11:26 +01:00
pch.c remove useless if-before-free tests 2011-04-20 18:19:03 +00:00
symtab.c directives.c (do_linemarker, do_line): Use CPP_STRING for ignored enum value. 2009-07-18 03:22:16 +00:00
system.h system.h: Prior to #define, #undef fopen and freopen unconditionally. 2012-01-03 11:44:34 +00:00
traditional.c Generate virtual locations for tokens 2011-10-17 11:59:12 +02:00
ucnid.h Licensing changes to GPLv3 resp. GPLv3 with GCC Runtime Exception. 2009-04-09 17:00:19 +02:00
ucnid.tab Licensing changes to GPLv3 resp. GPLv3 with GCC Runtime Exception. 2009-04-09 17:00:19 +02:00