Go to file
David Malcolm 470a60b2c4 re PR preprocessor/78680 (ICE in get_substring_ranges_for_loc, at input.c:1398)
Fix for PR preprocessor/78680

PR preprocessor/78680 identifies a crash when attempting to issue
a -Wformat warning, where the format string includes a string token
split across multiple physical source lines via backslash-continued
lines.

The issue is that libcpp is generating bogus range information for
such tokens.

For example, in:

void fn1() {
  __builtin_printf("\
     %ld.\n\
        2\n"); };

the range of the string token is printed as:

   __builtin_printf("\
                    ^~

whereas the range ought to be:

  __builtin_printf("\
                   ^~
     %ld.\n\
     ~~~~~~~
        2\n"); };
        ~~~~

The root cause is that the line notes expressing the update
of the buffer in lex.c aren't yet updated when the end-point of
the token is computed

3095	    tok_range.m_finish
3096	      = linemap_position_for_column (pfile->line_table,
3097					     CPP_BUF_COLUMN (buffer, buffer->cur));

so that the physical line is still regarded as that of the start
of the token, and, where CPP_BUF_COLUMN uses (BUF)->line_base,
line_base is still the location of the first physical line in the
and hence the column information is too large (as if it were the
offset in the *logical* line).

(the printed range is somewhat misleading; the actual buggy range
extends beyond the "\ in the line, but within diagnostic-show-locus.c
layout::print_annotation_line only prints up to the xbound set by
layout::print_source_line and so truncates most of the buggy range).

The fix is to ensure that line notes are handled before calculating
the end-point of the token range.

This leads to the range for the string token being correctly
computed, as:

  __builtin_printf("\
                   ^~
     %ld.\n\
     ~~~~~~~
        2\n"); };
        ~~~~

and this leads to get_substring_ranges_for_loc failing gracefully,
rather than crashing.

gcc/testsuite/ChangeLog:
	PR preprocessor/78680
	* gcc.dg/format/pr78680.c: New test case.
	* gcc.dg/plugin/diagnostic-test-expressions-1.c
	(test_multiline_token): New function.
	* gcc.dg/plugin/diagnostic-test-string-literals-1.c
	(test_backslash_continued_logical_lines): New function.

libcpp/ChangeLog:
	PR preprocessor/78680
	* lex.c (_cpp_lex_direct): Ensure line notes are processed before
	computing the end-point of the token.

From-SVN: r243567
2016-12-12 17:37:48 +00:00
config Disable hwcaps on libgfortran 2016-12-12 13:40:21 +00:00
contrib
fixincludes
gcc re PR preprocessor/78680 (ICE in get_substring_ranges_for_loc, at input.c:1398) 2016-12-12 17:37:48 +00:00
gnattools
gotools
include
INSTALL
intl
libada
libatomic
libbacktrace
libcc1
libcilkrts Import libcilkrts Build 4467 (PR target/68945) 2016-12-01 14:48:49 +00:00
libcpp re PR preprocessor/78680 (ICE in get_substring_ranges_for_loc, at input.c:1398) 2016-12-12 17:37:48 +00:00
libdecnumber
libffi
libgcc lib1funcs.S (__ashrdi3): Fix typo from r243545. 2016-12-12 11:57:33 +00:00
libgfortran Disable hwcaps on libgfortran 2016-12-12 13:40:21 +00:00
libgo runtime: mark non-x86 aeshashbody parameters as unused 2016-12-08 20:43:19 +00:00
libgomp [RTEMS] Use spin lock for pool management 2016-12-02 14:13:12 +00:00
libiberty re PR other/78252 (C++ demangler crashes with infinite recursion with lambda (auto)) 2016-12-12 17:00:37 +00:00
libitm Disable hwcaps on libgfortran 2016-12-12 13:40:21 +00:00
libmpx
libobjc configure.ac: Don't use pkg-config to check for bdw-gc. 2016-12-01 12:31:49 +00:00
liboffloadmic
libquadmath
libsanitizer Add PR sanitizer/78532 patch to libsanitizer/LOCAL_PATCHES. 2016-11-30 14:32:55 +02:00
libssp
libstdc++-v3 [libstdc++][testsuite] XFAIL tests relying on long double-to-string conversions on broken newlib 2016-12-12 15:47:47 +00:00
libvtv
lto-plugin
maintainer-scripts
zlib
.dir-locals.el
.gitattributes
.gitignore
ABOUT-NLS
ChangeLog acx.m4: Change "tail +16c" to "tail -c +17". 2016-12-01 16:02:51 -07:00
ChangeLog.jit
ChangeLog.tree-ssa
compile
config-ml.in
config.guess
config.rpath
config.sub
configure acx.m4: Change "tail +16c" to "tail -c +17". 2016-12-01 16:02:51 -07:00
configure.ac configure.ac: Don't use pkg-config to check for bdw-gc. 2016-12-01 12:31:49 +00:00
COPYING
COPYING3
COPYING3.LIB
COPYING.LIB
COPYING.RUNTIME
depcomp
install-sh
libtool-ldflags
libtool.m4
lt~obsolete.m4
ltgcc.m4
ltmain.sh
ltoptions.m4
ltsugar.m4
ltversion.m4
MAINTAINERS
Makefile.def Makefile.def: Remove reference to boehm-gc target module. 2016-11-30 00:12:45 +00:00
Makefile.in Makefile.def: Remove reference to boehm-gc target module. 2016-11-30 00:12:45 +00:00
Makefile.tpl
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.

Copyright years on GCC source files may be listed using range
notation, e.g., 1987-2012, indicating that every year in the range,
inclusive, is a copyrightable year that could otherwise be listed
individually.