Find a file
Dodji Seketeli 3600218c8b Fix expansion point loc for macro-like tokens
Consider the test case gcc/testsuite/gcc.dg/debug/dwarf2/pr41445-5.c.
Its interesting part is:

    #define A(x) vari x /* line 7.  */
    #define vari(x)
    #define B , varj
    int A(B) ;  /* line 10.  */

In its initial version, this test was being pre-processed as:

    # 1 "gcc/testsuite/gcc.dg/debug/dwarf2/pr41445-5.c"
    # 1 "build/gcc//"
    # 1 "<command-line>"
    # 1 "gcc/testsuite/gcc.dg/debug/dwarf2/pr41445-5.c"
    # 10 "gcc/testsuite/gcc.dg/debug/dwarf2/pr41445-5.c"
    int
    # 7 "gcc/testsuite/gcc.dg/debug/dwarf2/pr41445-5.c"
		 vari

	, varj ;

Note how "int" and "vari" are on separate lines, whereas "int" and
", varj" are on the same line.

This looks like a bug to me, even independantly from the macro
location tracking work.

With macro location tracking turned on, the preprocessed output
becomes:

    # 1 "gcc/testsuite/gcc.dg/debug/dwarf2/pr41445-5.c"
    # 1 "<command-line>"
    # 1 "gcc/testsuite/gcc.dg/debug/dwarf2/pr41445-5.c"
    # 10 "gcc/testsuite/gcc.dg/debug/dwarf2/pr41445-5.c"
    int vari , varj ;

Which, IMO, is what we'd expect.

This is due to an unexpected side effect of enter_macro_context when
passed a token that might look like a function-like macro at first
sight, but that it eventually considers to not be a macro after all.

This is the case for the "vari" token which looks like a macro when it
is first lexed, but is eventually considered to be a normal token by
enter_macro_context because it's not used as a function-like macro
invocation.

In that case, besides returning NULL, enter_macro_context sets
pfile->context->c.macro to NULL, making cpp_get_token_1 forget to set
the location of the "vari" to the expansion point of A.

enter_macro_context sets pfile->context->c.macro to NULL in that case
because funlike_invocation_p reads one token pass "foo", sees that
there is no '(' token, so we are not invoking the function-like
parameter.  It then puts the tokens (which it has read after "foo")
back into the tokens stream by calling _cpp_push_token_context on it,
which sets pfile->context->c.macro to NULL, saying in essence that the
current macro expansion context is "stopped".

The fix here is to teach _cpp_push_token and
push_extended_tokens_context to continue the current macro context
when passed a NULL macro.  But then, now that there can be several
continguous contexts associated with the same macro, we need to teach
_cpp_pop_context to re-enable the expansion of the current macro only
when we are really out of expanding the current macro.  Otherwise we
can run in cases where we have recursive expansions of the same macro.

Tested on x86_64-unknown-linux-gnu against trunk.  Now this test has
the same output with and without tracking locations accross macro
expansions.

Note that the bootstrap with -ftrack-macro-expansion exhibits other
separate issues that are addressed in subsequent patches.  This patch
just fixes one class of problems.

The patch does pass bootstrap with -ftrack-macro-expansion turned off,
though.

libcpp/
	* macro.c (macro_of_context): New static function.
	(_cpp_push_token_context, push_extended_tokens_context): If the
	macro argument is NULL, it means we are continuing the expansion
	of the current macro, if any.  Update comments.
	(_cpp_pop_context): Re-enable expansion of the macro only when we
	are really out of the context of the current expansion.

gcc/testsuite/

	* gcc.dg/debug/dwarf2/pr41445-5.c: Adjust.
	* gcc.dg/debug/dwarf2/pr41445-6.c: Likewise.

From-SVN: r186968
2012-04-30 13:41:46 +02:00
boehm-gc Fix changelog format. 2012-02-28 18:02:56 +00:00
config mmap.m4: Use *vms* instead of vms*. 2012-04-03 12:07:28 +00:00
contrib compare_tests: Append '/' to make 'find' traverse symlinked directories. 2012-04-24 07:22:41 +00:00
fixincludes fixincl.c (fix_with_system): Add missing specifier. 2012-04-24 09:24:55 +00:00
gcc Fix expansion point loc for macro-like tokens 2012-04-30 13:41:46 +02:00
gnattools Remove obsolete IRIX 6.5 support 2012-03-14 16:33:37 +00:00
include * dwarf2.def (DW_OP): Add DW_OP_GNU_addr_index. 2012-04-28 21:37:19 +00:00
INSTALL
intl
libada Makefile.in (bindir): Import from autoconf and pass down to submake. 2012-02-24 16:17:01 +00:00
libcpp Fix expansion point loc for macro-like tokens 2012-04-30 13:41:46 +02:00
libdecnumber warnings.m4 (ACX_PROG_CC_WARNING_OPTS): Avoid leading dash in expr call. 2011-12-20 16:54:12 +00:00
libffi ffi.c (ffi_prep_args_SYSV): Declare double_tmp. 2012-04-02 13:29:22 -05:00
libgcc config.host (mips64*-*-linux*, [...]): Remove. 2012-04-28 08:03:54 +00:00
libgfortran re PR libfortran/53051 (I/O: Support reading floating-point numbers which use "Q" for the exponent) 2012-04-22 19:28:34 +02:00
libgo re PR go/52358 (math FAILs on Solaris 8 and 9) 2012-04-27 16:38:11 +00:00
libgomp prune.exp (TEST_ALWAYS_FLAGS): If undefined, set to empty. 2012-04-11 20:15:35 +00:00
libiberty dwarf2out.c (dwarf_stack_op_name): Use get_DW_OP_name. 2012-04-27 14:14:14 +00:00
libitm Use long long in gtm_jmpbuf for x86-64 2012-04-04 08:49:23 -07:00
libjava defineclass.cc (MAJOR_1_7, MINOR_1_7): New. 2012-04-23 13:33:32 +00:00
libmudflap re PR c++/24985 (caret diagnostics) 2012-04-11 09:26:48 +00:00
libobjc Remove obsolete Tru64 UNIX V5.1B support 2012-03-12 15:35:56 +00:00
libquadmath Additional fixes for FreeBSD-10 build: 2011-11-21 20:22:35 +01:00
libssp Additional fixes for FreeBSD-10 build: 2011-11-21 20:22:35 +01:00
libstdc++-v3 re PR libstdc++/51795 (linear_congruential_engine doesn't work correctly) 2012-04-29 23:36:09 +00:00
lto-plugin re PR lto/50616 (lto1.exe: internal compiler error: invalid resolution in the resolution file) 2012-02-22 11:19:22 +01:00
maintainer-scripts crontab: Enable snapshots from gcc-4_7-branch. 2012-03-22 09:25:49 +00:00
zlib 2012-03-02 Matthias Klose <doko@ubuntu.com> 2012-03-02 17:15:20 +00:00
ABOUT-NLS
ChangeLog Update config.sub to 2012-04-18 version from official repo. 2012-04-25 15:48:28 +00:00
ChangeLog.tree-ssa
compile
config-ml.in MAINTAINERS (crx port, [...]): Remove. 2011-03-22 19:58:18 +00:00
config.guess oops - omitted from previous delta. 2011-06-06 10:34:35 +00:00
config.rpath
config.sub Update config.sub to 2012-04-18 version from official repo. 2012-04-25 15:48:28 +00:00
configure Remove obsolete IRIX 6.5 support 2012-03-14 16:33:37 +00:00
configure.ac Remove obsolete IRIX 6.5 support 2012-03-14 16:33:37 +00:00
COPYING
COPYING.LIB
COPYING.RUNTIME
COPYING3
COPYING3.LIB
depcomp
install-sh
libtool-ldflags
libtool.m4 Additional fixes for FreeBSD-10 build: 2011-11-21 20:22:35 +01:00
ltgcc.m4
ltmain.sh
ltoptions.m4
ltsugar.m4
ltversion.m4
lt~obsolete.m4
MAINTAINERS Add myself in Write After Approval list in MAINTAINERS file. 2012-04-24 07:49:14 +00:00
Makefile.def re PR bootstrap/51686 ("make install-strip-gcc" didn't install liblto-plugin* files) 2012-01-02 10:59:04 +00:00
Makefile.in re PR bootstrap/51686 ("make install-strip-gcc" didn't install liblto-plugin* files) 2012-01-02 10:59:04 +00:00
Makefile.tpl configure.ac: Add tool checks for READELF and READELF_FOR_TARGET. 2011-11-09 13:57:26 -05:00
missing
mkdep
mkinstalldirs
move-if-change
README
symlink-tree
ylwrap

This directory contains the GNU Compiler Collection (GCC).

The GNU Compiler Collection is free software.  See the files whose
names start with COPYING for copying permission.  The manuals, and
some of the runtime libraries, are under different terms; see the
individual source files for details.

The directory INSTALL contains copies of the installation information
as HTML and plain text.  The source of this information is
gcc/doc/install.texi.  The installation information includes details
of what is included in the GCC sources and what files GCC installs.

See the file gcc/doc/gcc.texi (together with other files that it
includes) for usage and porting information.  An online readable
version of the manual is in the files gcc/doc/gcc.info*.

See http://gcc.gnu.org/bugs/ for how to report bugs usefully.