Go to file
Dodji Seketeli 165ca58dc3 Make unwound macro expansion trace less redundant
As discussed previously, the unwinder for macro expansion is quite
verbose [1].  This patch proposes to address that shortcoming.

Consider this test case:

    $ cat -n test.c
	 1	#define MYMAX(A,B) __extension__ ({ __typeof__(A) __a = (A); \
	 2	 __typeof__(B) __b = (B); __a < __b ? __b : __a; })
	 3
	 4	struct mystruct {};
	 5	void
	 6	foo()
	 7	{
	 8	  struct mystruct p;
	 9	  float f = 0.0;
	10	  MYMAX (p, f);
	11	}
    $

The output of the compiler from trunk yields:

    $ cc1 -quiet ./test.c
    ./test.c: In function ‘foo’:
    ./test.c:2:31: error: invalid operands to binary < (have ‘struct mystruct’ and ‘float’)
      __typeof__(B) __b = (B); __a < __b ? __b : __a; })
				   ^
    ./test.c:2:31: note: in expansion of macro 'MYMAX'
      __typeof__(B) __b = (B); __a < __b ? __b : __a; })
				   ^
    ./test.c:10:3: note: expanded from here
       MYMAX (p, f);
       ^
    $

After this patch, the compiler yields:

    $ ./cc1 -quiet ./test.c
    ./test.c: In function ‘foo’:
    ./test.c:2:31: error: invalid operands to binary < (have ‘struct mystruct’ and ‘float’)
      __typeof__(B) __b = (B); __a < __b ? __b : __a; })
				   ^
    ./test.c:10:3: note: in expansion of macro 'MYMAX'
       MYMAX (p, f);
       ^
    $

The gotcha is, in the general case, we cannot simply eliminate the
context of the macro definition.  That is, the line from the first
output that is redundant with the first diagnostic line that has
line/column number:

    ./test.c:2:31: note: in expansion of macro 'MYMAX'
      __typeof__(B) __b = (B); __a < __b ? __b : __a; })
                                   ^

We cannot simply eliminate that context of macro definition because
there are cases where the first diagnostic that has a line/column
number doesn't point to a location inside the definition of the macro
where the relevant token is used.  For instance:

    $ cat -n test2.c
	 1	#define OPERATE(OPRD1, OPRT, OPRD2) \
	 2	  OPRD1 OPRT OPRD2;
	 3
	 4	#define SHIFTL(A,B) \
	 5	  OPERATE (A,<<,B)
	 6
	 7	#define MULT(A) \
	 8	  SHIFTL (A,1)
	 9
	10	void
	11	g ()
	12	{
	13	  MULT (1.0);// 1.0 << 1; <-- so this is an error.
	14	}
    $

Which yields without the patch:

    $ cc1 -quiet ./test2.c
    ./test2.c: In function ‘g’:
    ./test2.c:5:14: error: invalid operands to binary << (have ‘double’ and ‘int’)
       OPERATE (A,<<,B)
		  ^
    ./test2.c:2:9: note: in expansion of macro 'OPERATE'
       OPRD1 OPRT OPRD2;
	     ^
    ./test2.c:5:3: note: expanded from here
       OPERATE (A,<<,B)
       ^
    ./test2.c:5:14: note: in expansion of macro 'SHIFTL'
       OPERATE (A,<<,B)
		  ^
    ./test2.c:8:3: note: expanded from here
       SHIFTL (A,1)
       ^
    ./test2.c:8:3: note: in expansion of macro 'MULT'
       SHIFTL (A,1)
       ^
    ./test2.c:13:3: note: expanded from here
       MULT (1.0);// 1.0 << 1; <-- so this is an error.
       ^
    $

Here, the line that has the context of macro definition:

    ./test2.c:2:9: note: in expansion of macro 'OPERATE'
       OPRD1 OPRT OPRD2;
	     ^
is useful, because the first diagnostic that has line/column number
wasn't pointing into the definition of the macro OPERATE, where the
token '<<' is used.

    ./test2.c:5:14: error: invalid operands to binary << (have ‘double’ and ‘int’)
       OPERATE (A,<<,B)
		  ^
So in this this case, displaying the macro definition context is not
redundant.  I think it is even desirable.

The patch changes the output in that case to be:

    ./test2.c: In function ‘g’:
    ./test2.c:5:14: erreur: invalid operands to binary << (have ‘double’ and ‘int’)
       OPERATE (A,<<,B)
		  ^
    ./test2.c:2:9: note: in definition of macro 'OPERATE'
       OPRD1 OPRT OPRD2;
	     ^
    ./test2.c:8:3: note: in expansion of macro 'SHIFTL'
       SHIFTL (A,1)
       ^
    ./test2.c:13:3: note: in expansion of macro 'MULT'
       MULT (1.0);// 1.0 << 1; <-- so this is an error.
       ^
    $

It's shorter, but I believe it has all the information that was
present before the patch.

[1]: http://gcc.gnu.org/ml/gcc-patches/2012-05/msg00321.html

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

gcc/

	Make unwound macro expansion trace less redundant
	* tree-diagnostic.c (maybe_unwind_expanded_macro_loc): Don't print
	context of macro definition in the trace, when it's redundant.
	Update comments.

gcc/testsuite/

	Make unwound macro expansion trace less redundant
	* gcc.dg/cpp/macro-exp-tracking-1.c: Adjust.
	* gcc.dg/cpp/macro-exp-tracking-2.c: Likewise.
	* gcc.dg/cpp/macro-exp-tracking-3.c: Likewise.
	* gcc.dg/cpp/macro-exp-tracking-4.c: Likewise.
	* gcc.dg/cpp/macro-exp-tracking-5.c: Likewise.
	* gcc.dg/cpp/pragma-diagnostic-2.c: Likewise.

From-SVN: r187845
2012-05-24 21:37:45 +02:00
INSTALL
boehm-gc Regenerate configure files for libtool.m4 change 2012-05-16 15:11:18 -07:00
config mh-ppc-aix (LDFLAGS): Quote $(CC). 2012-05-03 15:39:07 +00:00
contrib * gcc_update: Use $GCC_SVN to retrieve branch and revision. 2012-05-09 11:35:00 -04:00
fixincludes fixincl.c (fix_with_system): Add missing specifier. 2012-04-24 09:24:55 +00:00
gcc Make unwound macro expansion trace less redundant 2012-05-24 21:37:45 +02:00
gnattools Remove obsolete IRIX 6.5 support 2012-03-14 16:33:37 +00:00
include leb128.h: #include stdint.h, inttypes.h. 2012-05-23 23:42:25 +00:00
intl
libada Adjust. 2012-05-06 09:24:21 +00:00
libatomic re PR other/53231 (libatomic/tas_n.c💯10: error: 'ret' undeclared (first use in this function)) 2012-05-22 23:54:32 +00:00
libcpp PR preprocessor/7263 - Avoid pedantic warnings on system headers macro tokens 2012-05-16 12:51:15 +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 Regenerate configure files for libtool.m4 change 2012-05-16 15:11:18 -07:00
libgcc Fix typo in latest ChangeLog entry addition. 2012-05-24 14:58:49 +00:00
libgfortran PR 53456 clock_gettime fallback for gf_gettime 2012-05-23 21:52:47 +03:00
libgo runtime: Tweak runtime.Callers for Go 1 compatibility. 2012-05-22 21:52:56 +00:00
libgomp Regenerate configure files for libtool.m4 change 2012-05-16 15:11:18 -07:00
libiberty demangle-expected: Add regression test. 2012-05-22 13:55:02 +00:00
libitm eh_cpp.cc: Fix __cxa_end_catch declaration. 2012-05-21 22:48:00 +00:00
libjava re PR bootstrap/52700 (lib* configure fails on --enable-symvers=gnu-versioned-namespace.) 2012-05-21 17:34:25 +00:00
libmudflap Regenerate configure files for libtool.m4 change 2012-05-16 15:11:18 -07:00
libobjc Regenerate configure files for libtool.m4 change 2012-05-16 15:11:18 -07:00
libquadmath Regenerate configure files for libtool.m4 change 2012-05-16 15:11:18 -07:00
libssp Regenerate configure files for libtool.m4 change 2012-05-16 15:11:18 -07:00
libstdc++-v3 PR c++/53322 - -Wunused-local-typedefs is not enabled by Wall or Wunused 2012-05-22 05:50:26 +02:00
lto-plugin Regenerate configure files for libtool.m4 change 2012-05-16 15:11:18 -07:00
maintainer-scripts crontab: Enable snapshots from gcc-4_7-branch. 2012-03-22 09:25:49 +00:00
zlib Regenerate configure files for libtool.m4 change 2012-05-16 15:11:18 -07:00
ABOUT-NLS
COPYING
COPYING.LIB
COPYING.RUNTIME
COPYING3
COPYING3.LIB
ChangeLog Makefile.tpl (gcc-no-fixedincludes): Rename into ... 2012-05-16 13:37:14 +00:00
ChangeLog.tree-ssa
MAINTAINERS MAINTAINERS (Write After Approval): Add myself. 2012-05-14 20:28:00 +00:00
Makefile.def Add libatomic as a target library. 2012-05-01 08:48:28 -07:00
Makefile.in Makefile.tpl (gcc-no-fixedincludes): Rename into ... 2012-05-16 13:37:14 +00:00
Makefile.tpl Makefile.tpl (gcc-no-fixedincludes): Rename into ... 2012-05-16 13:37:14 +00:00
README
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 Remove freebsd1 from libtool.m4 macros and config.rpath. 2011-02-13 11:45:53 +00:00
config.sub Update config.sub to 2012-04-18 version from official repo. 2012-04-25 15:48:28 +00:00
configure re PR bootstrap/50461 (mpfr.h found in mpfr-3.1.0/src instead of mpfr-3.0.1/. as previously) 2012-05-09 16:20:17 +00:00
configure.ac re PR bootstrap/50461 (mpfr.h found in mpfr-3.1.0/src instead of mpfr-3.0.1/. as previously) 2012-05-09 16:20:17 +00:00
depcomp
install-sh
libtool-ldflags
libtool.m4 Add x32 support to libtool.m4 2012-05-15 09:07:28 -07:00
ltgcc.m4
ltmain.sh
ltoptions.m4
ltsugar.m4
ltversion.m4
lt~obsolete.m4
missing
mkdep
mkinstalldirs
move-if-change Import move-if-change script from gnulib. 2011-02-12 15:48:30 +00:00
symlink-tree
ylwrap

README

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.