diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 982a203ec65..f1f518411db 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,12 @@ +2016-12-12 David Malcolm + + 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. + 2016-12-12 Nathan Sidwell PR c++/78252 diff --git a/gcc/testsuite/gcc.dg/format/pr78680.c b/gcc/testsuite/gcc.dg/format/pr78680.c new file mode 100644 index 00000000000..0c599f37b6f --- /dev/null +++ b/gcc/testsuite/gcc.dg/format/pr78680.c @@ -0,0 +1,16 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -Wall -Wextra -fdiagnostics-show-caret" } */ + +void fn1() { + __builtin_printf("\ + %ld.\n\ + 2\n"); }; +/* { dg-warning "expects a matching" "" { target *-*-* } .-3 } */ +/* { dg-begin-multiline-output "" } + __builtin_printf("\ + ^~ + %ld.\n\ + ~~~~~~~ + 2\n"); }; + ~~~~ + { dg-end-multiline-output "" } */ diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-expressions-1.c b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-expressions-1.c index 93729361388..afbe0f734a2 100644 --- a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-expressions-1.c +++ b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-expressions-1.c @@ -689,3 +689,22 @@ void test_multiple_ordinary_maps (void) ~~ { dg-end-multiline-output "" } */ } + +/* Verify that we correctly handle a token that spans multiple + physical lines. */ + +const char *test_multiline_token (void) +{ + __emit_expression_range (0, "foo\ +bar\ +baz"); +/* { dg-warning "range" "" { target *-*-* } .-3 } */ +/* { dg-begin-multiline-output "" } + __emit_expression_range (0, "foo\ + ^~~~~ + bar\ + ~~~~ + baz"); + ~~~~ + { dg-end-multiline-output "" } */ +} diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-string-literals-1.c b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-string-literals-1.c index 76a085e9779..03f042abf7b 100644 --- a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-string-literals-1.c +++ b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-string-literals-1.c @@ -272,3 +272,23 @@ test_terminator_location (void) ^ { dg-end-multiline-output "" } */ } + +/* Verify that we fail gracefully when a string literal token is split + across multiple physical lines. */ + +void +test_backslash_continued_logical_lines (void) +{ + __emit_string_literal_range ("\ +01234\ +56789", 6, 6, 7); + /* { dg-error "unable to read substring location: range endpoints are on different lines" "" { target *-*-* } .-3 } */ + /* { dg-begin-multiline-output "" } + __emit_string_literal_range ("\ + ^~ + 01234\ + ~~~~~~ + 56789", 6, 6, 7); + ~~~~~~ + { dg-end-multiline-output "" } */ +} diff --git a/libcpp/ChangeLog b/libcpp/ChangeLog index 1a7e737cd95..63681220187 100644 --- a/libcpp/ChangeLog +++ b/libcpp/ChangeLog @@ -1,3 +1,9 @@ +2016-12-12 David Malcolm + + PR preprocessor/78680 + * lex.c (_cpp_lex_direct): Ensure line notes are processed before + computing the end-point of the token. + 2016-11-23 Paolo Bonzini * include/cpplib.h (struct cpp_options): Add new member diff --git a/libcpp/lex.c b/libcpp/lex.c index cea88488f36..ae458926b75 100644 --- a/libcpp/lex.c +++ b/libcpp/lex.c @@ -3089,6 +3089,13 @@ _cpp_lex_direct (cpp_reader *pfile) break; } + /* Ensure that any line notes are processed, so that we have the + correct physical line/column for the end-point of the token even + when a logical line is split via one or more backslashes. */ + if (buffer->cur >= buffer->notes[buffer->cur_note].pos + && !pfile->overlaid_buffer) + _cpp_process_line_notes (pfile, false); + source_range tok_range; tok_range.m_start = result->src_loc; if (result->src_loc >= RESERVED_LOCATION_COUNT)