diff options
author | David Malcolm <dmalcolm@redhat.com> | 2016-08-16 18:19:34 +0000 |
---|---|---|
committer | David Malcolm <dmalcolm@gcc.gnu.org> | 2016-08-16 18:19:34 +0000 |
commit | 65e736c0efc463270764ea3012b9804c495c71bc (patch) | |
tree | f13ad9e3631ebbae2255d5fef36928ccaf345409 /gcc/testsuite/gcc.dg | |
parent | eb3a5bcc74b063c05ceb78f8e0bfee3e03b021a6 (diff) | |
download | gcc-65e736c0efc463270764ea3012b9804c495c71bc.zip gcc-65e736c0efc463270764ea3012b9804c495c71bc.tar.gz gcc-65e736c0efc463270764ea3012b9804c495c71bc.tar.bz2 |
Fix caret locations in format_type_warning (PR c/72857)
gcc/c-family/ChangeLog:
PR c/72857
* c-common.c (substring_loc::get_range): Rename to...
(substring_loc::get_location): ...this, converting param from a
source_range * to a location_t *. Call
get_source_location_for_substring rather than
get_source_range_for_substring, and pass in m_caret_idx.
* c-common.h (substring_loc::substring_loc): Add param "caret_idx".
(substring_loc::get_range): Replace with...
(substring_loc::get_location): ...this.
(substring_loc::set_caret_index): New method.
(substring_loc): Add field m_caret_idx.
* c-format.c (format_warning_va): Update for above changes.
Rename local "substring_loc" to "fmt_substring_loc" to avoid
clashing with type name.
(format_warning_at_char): Add caret_idx param to substring_loc ctor.
(check_argument_type): Likewise.
(format_type_warning): Rename param "fmt_loc" to "whole_fmt_loc"
Use a copy when emitting warnings, setting the caret index from TYPE.
gcc/ChangeLog:
PR c/72857
* input.c (get_source_range_for_substring): Rename to...
(get_source_location_for_substring): ...this, adding param
"caret_idx", and converting output param from source_range * to
location_t *.
(get_source_range_for_char): New function.
(get_num_source_ranges_for_substring): Update comment to reflect
above renaming.
(assert_char_at_range): Update to use get_source_range_for_char
rather than get_source_range_for_substring.
(test_lexer_string_locations_concatenation_2): Likewise.
* substring-locations.h (get_source_range_for_substring): Rename
to...
(get_source_location_for_substring): ...this, and adding param
"caret_idx", and converting output param from source_range * to
location_t *.
gcc/testsuite/ChangeLog:
PR c/72857
* gcc.dg/format/asm_fprintf-1.c: Restore column numbers
for embedded NUL.
* gcc.dg/format/c90-printf-1.c: Restore column numbers.
* gcc.dg/format/diagnostic-ranges.c (test_hex): Update expected
caret placement.
(test_oct): Likewise.
(test_multiple): Likewise.
(test_field_width_specifier): Likewise.
(test_field_width_specifier_2): New function.
(test_field_precision_specifier): New function.
(test_embedded_nul): Update expected caret placement.
(test_non_contiguous_strings): Update line number.
* gcc.dg/plugin/diagnostic-test-string-literals-1.c
(__emit_string_literal_range): Add "caret_idx" param.
(test_simple_string_literal): Add value for new param, updating
expected output..
(test_concatenated_string_literal): Likewise.
(test_multiline_string_literal): Likewise.
(test_hex): Likewise.
(test_oct): Likewise.
(test_multiple): Likewise.
(test_ucn4): Likewise.
(test_ucn8): Likewise.
(test_u8): Likewise.
(test_u): Likewise; update expected message, from "range" to
"location".
(test_U): Likewise.
(test_L): Likewise.
(test_macro): Add value for new param.
* gcc.dg/plugin/diagnostic-test-string-literals-2.c
(__emit_string_literal_range): Add "caret_idx" param.
(test_stringified_token_1): Add value for new param. Update
expected message, from "range" to "location".
(test_stringized_token_2): Likewise, adding param to macro.
(test_stringified_token_3): Likewise.
* gcc.dg/plugin/diagnostic_plugin_test_string_literals.c
(emit_warning): Convert param from source_range to location_t.
(test_string_literals): Add caret_idx param, and use it when
constructing a substring_loc. Update error message, from
"range" to "location".
From-SVN: r239510
Diffstat (limited to 'gcc/testsuite/gcc.dg')
6 files changed, 112 insertions, 72 deletions
diff --git a/gcc/testsuite/gcc.dg/format/asm_fprintf-1.c b/gcc/testsuite/gcc.dg/format/asm_fprintf-1.c index 50ca572..2eabbf9 100644 --- a/gcc/testsuite/gcc.dg/format/asm_fprintf-1.c +++ b/gcc/testsuite/gcc.dg/format/asm_fprintf-1.c @@ -66,9 +66,9 @@ foo (int i, int i1, int i2, unsigned int u, double d, char *s, void *p, asm_fprintf ("%d", i, i); /* { dg-warning "16:arguments" "wrong number of args" } */ /* Miscellaneous bogus constructions. */ asm_fprintf (""); /* { dg-warning "16:zero-length" "warning for empty format" } */ - asm_fprintf ("\0"); /* { dg-warning "18:embedded" "warning for embedded NUL" } */ - asm_fprintf ("%d\0", i); /* { dg-warning "20:embedded" "warning for embedded NUL" } */ - asm_fprintf ("%d\0%d", i, i); /* { dg-warning "20:embedded|too many" "warning for embedded NUL" } */ + asm_fprintf ("\0"); /* { dg-warning "17:embedded" "warning for embedded NUL" } */ + asm_fprintf ("%d\0", i); /* { dg-warning "19:embedded" "warning for embedded NUL" } */ + asm_fprintf ("%d\0%d", i, i); /* { dg-warning "19:embedded|too many" "warning for embedded NUL" } */ asm_fprintf (NULL); /* { dg-warning "null" "null format string warning" } */ asm_fprintf ("%"); /* { dg-warning "17:trailing" "trailing % warning" } */ asm_fprintf ("%++d", i); /* { dg-warning "19:repeated" "repeated flag warning" } */ diff --git a/gcc/testsuite/gcc.dg/format/c90-printf-1.c b/gcc/testsuite/gcc.dg/format/c90-printf-1.c index 338b971..5329dad 100644 --- a/gcc/testsuite/gcc.dg/format/c90-printf-1.c +++ b/gcc/testsuite/gcc.dg/format/c90-printf-1.c @@ -58,11 +58,11 @@ foo (int i, int i1, int i2, unsigned int u, double d, char *s, void *p, printf ("%-%"); /* { dg-warning "13:type" "missing type" } */ /* { dg-warning "14:trailing" "bogus %%" { target *-*-* } 58 } */ printf ("%-%\n"); /* { dg-warning "13:format" "bogus %%" } */ - /* { dg-warning "16:format" "bogus %%" { target *-*-* } 60 } */ + /* { dg-warning "15:format" "bogus %%" { target *-*-* } 60 } */ printf ("%5%\n"); /* { dg-warning "13:format" "bogus %%" } */ - /* { dg-warning "16:format" "bogus %%" { target *-*-* } 62 } */ + /* { dg-warning "15:format" "bogus %%" { target *-*-* } 62 } */ printf ("%h%\n"); /* { dg-warning "13:format" "bogus %%" } */ - /* { dg-warning "16:format" "bogus %%" { target *-*-* } 64 } */ + /* { dg-warning "15:format" "bogus %%" { target *-*-* } 64 } */ /* Valid and invalid %h, %l, %L constructions. */ printf ("%hd", i); printf ("%hi", i); @@ -184,8 +184,8 @@ foo (int i, int i1, int i2, unsigned int u, double d, char *s, void *p, printf ("%-08G", d); /* { dg-warning "11:flags|ignored" "0 flag ignored with - flag" } */ /* Various tests of bad argument types. */ printf ("%d", l); /* { dg-warning "13:format" "bad argument types" } */ - printf ("%*.*d", l, i2, i); /* { dg-warning "16:field" "bad * argument types" } */ - printf ("%*.*d", i1, l, i); /* { dg-warning "16:field" "bad * argument types" } */ + printf ("%*.*d", l, i2, i); /* { dg-warning "13:field" "bad * argument types" } */ + printf ("%*.*d", i1, l, i); /* { dg-warning "15:field" "bad * argument types" } */ printf ("%ld", i); /* { dg-warning "14:format" "bad argument types" } */ printf ("%s", n); /* { dg-warning "13:format" "bad argument types" } */ printf ("%p", i); /* { dg-warning "13:format" "bad argument types" } */ @@ -231,8 +231,8 @@ foo (int i, int i1, int i2, unsigned int u, double d, char *s, void *p, printf ("%d", i, i); /* { dg-warning "11:arguments" "wrong number of args" } */ /* Miscellaneous bogus constructions. */ printf (""); /* { dg-warning "11:zero-length" "warning for empty format" } */ - printf ("\0"); /* { dg-warning "13:embedded" "warning for embedded NUL" } */ - printf ("%d\0", i); /* { dg-warning "15:embedded" "warning for embedded NUL" } */ + printf ("\0"); /* { dg-warning "12:embedded" "warning for embedded NUL" } */ + printf ("%d\0", i); /* { dg-warning "14:embedded" "warning for embedded NUL" } */ printf ("%d\0%d", i, i); /* { dg-warning "embedded|too many" "warning for embedded NUL" } */ printf (NULL); /* { dg-warning "3:null" "null format string warning" } */ printf ("%"); /* { dg-warning "12:trailing" "trailing % warning" } */ diff --git a/gcc/testsuite/gcc.dg/format/diagnostic-ranges.c b/gcc/testsuite/gcc.dg/format/diagnostic-ranges.c index ff51833..63075c8 100644 --- a/gcc/testsuite/gcc.dg/format/diagnostic-ranges.c +++ b/gcc/testsuite/gcc.dg/format/diagnostic-ranges.c @@ -87,7 +87,7 @@ void test_hex (const char *msg) /* TODO: ideally would also underline "msg". */ /* { dg-begin-multiline-output "" } printf("hello \x25\x69", msg); - ~~~~~~~^ + ~~~~^~~~ %s { dg-end-multiline-output "" } */ } @@ -101,7 +101,7 @@ void test_oct (const char *msg) /* TODO: ideally would also underline "msg". */ /* { dg-begin-multiline-output "" } printf("hello \045\151", msg); - ~~~~~~~^ + ~~~~^~~~ %s { dg-end-multiline-output "" } */ } @@ -120,7 +120,7 @@ void test_multiple (const char *msg) /* TODO: ideally would also underline "msg". */ /* { dg-begin-multiline-output "" } printf("prefix" "\x25" "\151" "suffix", - ~~~~~~~~~~~^ + ~~~~~~~~^~~~ %s { dg-end-multiline-output "" } */ } @@ -148,10 +148,44 @@ void test_param (long long_i, long long_j) void test_field_width_specifier (long l, int i1, int i2) { - printf (" %*.*d ", l, i1, i2); /* { dg-warning "17: field width specifier '\\*' expects argument of type 'int', but argument 2 has type 'long int'" } */ + printf (" %*.*d ", l, i1, i2); /* { dg-warning "14: field width specifier '\\*' expects argument of type 'int', but argument 2 has type 'long int'" } */ /* { dg-begin-multiline-output "" } printf (" %*.*d ", l, i1, i2); - ~~~~^ + ~^~~~ + { dg-end-multiline-output "" } */ +} + +/* PR c/72857. */ + +void test_field_width_specifier_2 (char *d, long foo, long bar) +{ + __builtin_sprintf (d, " %*ld ", foo, foo); /* { dg-warning "28: field width specifier '\\*' expects argument of type 'int', but argument 3 has type 'long int'" } */ + /* TODO: ideally we'd underline the first "foo" here". */ + /* { dg-begin-multiline-output "" } + __builtin_sprintf (d, " %*ld ", foo, foo); + ~^~~ + { dg-end-multiline-output "" } */ + + __builtin_sprintf (d, " %*ld ", foo + bar, foo); /* { dg-warning "28: field width specifier '\\*' expects argument of type 'int', but argument 3 has type 'long int'" } */ + /* { dg-begin-multiline-output "" } + __builtin_sprintf (d, " %*ld ", foo + bar, foo); + ~^~~ ~~~~~~~~~ + { dg-end-multiline-output "" } */ +} + +void test_field_precision_specifier (char *d, long foo, long bar) +{ + __builtin_sprintf (d, " %.*ld ", foo, foo); /* { dg-warning "29: field precision specifier '\\.\\*' expects argument of type 'int', but argument 3 has type 'long int'" } */ + /* TODO: ideally we'd underline the first "foo" here". */ + /* { dg-begin-multiline-output "" } + __builtin_sprintf (d, " %.*ld ", foo, foo); + ~~^~~ + { dg-end-multiline-output "" } */ + + __builtin_sprintf (d, " %.*ld ", foo + bar, foo); /* { dg-warning "29: field precision specifier '\\.\\*' expects argument of type 'int', but argument 3 has type 'long int'" } */ + /* { dg-begin-multiline-output "" } + __builtin_sprintf (d, " %.*ld ", foo + bar, foo); + ~~^~~ ~~~~~~~~~ { dg-end-multiline-output "" } */ } @@ -200,10 +234,10 @@ void test_conversion_lacks_type (void) void test_embedded_nul (void) { - printf (" \0 "); /* { dg-warning "14:embedded" "warning for embedded NUL" } */ + printf (" \0 "); /* { dg-warning "13:embedded" "warning for embedded NUL" } */ /* { dg-begin-multiline-output "" } printf (" \0 "); - ~^ + ^~ { dg-end-multiline-output "" } */ } @@ -225,7 +259,7 @@ void test_macro (const char *msg) void test_non_contiguous_strings (void) { __builtin_printf(" %" "d ", 0.5); /* { dg-warning "20: format .%d. expects argument of type .int., but argument 2 has type .double." } */ - /* { dg-message "26: format string is defined here" "" { target *-*-* } 227 } */ + /* { dg-message "26: format string is defined here" "" { target *-*-* } 261 } */ /* { dg-begin-multiline-output "" } __builtin_printf(" %" "d ", 0.5); ^~~~ 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 82689b4..d5be021 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 @@ -13,14 +13,14 @@ LITERAL is a const void * to allow testing the various kinds of wide string literal, rather than just const char *. */ -extern void __emit_string_literal_range (const void *literal, +extern void __emit_string_literal_range (const void *literal, int caret_idx, int start_idx, int end_idx); void test_simple_string_literal (void) { __emit_string_literal_range ("0123456789", /* { dg-warning "range" } */ - 6, 7); + 6, 6, 7); /* { dg-begin-multiline-output "" } __emit_string_literal_range ("0123456789", ^~ @@ -31,10 +31,10 @@ void test_concatenated_string_literal (void) { __emit_string_literal_range ("01234" "56789", /* { dg-warning "range" } */ - 3, 6); + 4, 3, 6); /* { dg-begin-multiline-output "" } __emit_string_literal_range ("01234" "56789", - ^~~~~~~ + ~^~~~~~ { dg-end-multiline-output "" } */ } @@ -43,14 +43,14 @@ test_multiline_string_literal (void) { __emit_string_literal_range ("01234" /* { dg-warning "range" } */ "56789", - 3, 6); + 4, 3, 6); /* { dg-begin-multiline-output "" } __emit_string_literal_range ("01234" - ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ "56789", - ~~~ + ~~~ { dg-end-multiline-output "" } */ - /* FIXME: why does the above need two trailing spaces? */ + /* FIXME: why does the above need three trailing spaces? */ } /* Tests of various unicode encodings. @@ -79,10 +79,10 @@ test_hex (void) and with a space in place of digit 6, to terminate the escaped hex code. */ __emit_string_literal_range ("01234\x35 789", /* { dg-warning "range" } */ - 3, 7); + 4, 3, 7); /* { dg-begin-multiline-output "" } __emit_string_literal_range ("01234\x35 789" - ^~~~~~~~ + ~^~~~~~~ { dg-end-multiline-output "" } */ } @@ -93,10 +93,10 @@ test_oct (void) and with a space in place of digit 6, to terminate the escaped octal code. */ __emit_string_literal_range ("01234\065 789", /* { dg-warning "range" } */ - 3, 7); + 4, 3, 7); /* { dg-begin-multiline-output "" } __emit_string_literal_range ("01234\065 789" - ^~~~~~~~ + ~^~~~~~~ { dg-end-multiline-output "" } */ } @@ -106,10 +106,10 @@ test_multiple (void) /* Digits 0-9, expressing digit 5 in ASCII as hex "\x35" digit 6 in ASCII as octal "\066", concatenating multiple strings. */ __emit_string_literal_range ("01234" "\x35" "\066" "789", /* { dg-warning "range" } */ - 3, 8); + 5, 3, 8); /* { dg-begin-multiline-output "" } __emit_string_literal_range ("01234" "\x35" "\066" "789", - ^~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~^~~~~~~~~~~~~~~~~~ { dg-end-multiline-output "" } */ } @@ -123,10 +123,10 @@ test_ucn4 (void) Hence to underline digits 4-7 we need to underling using bytes 4-11 in the UTF-8 encoding. */ __emit_string_literal_range ("01234\u2174\u2175789", /* { dg-warning "range" } */ - 4, 11); + 5, 4, 11); /* { dg-begin-multiline-output "" } __emit_string_literal_range ("01234\u2174\u2175789", - ^~~~~~~~~~~~~~ + ~^~~~~~~~~~~~~ { dg-end-multiline-output "" } */ } @@ -138,10 +138,10 @@ test_ucn8 (void) has the same UTF-8 encoding, and so we again need to underline bytes 4-11 in the UTF-8 encoding in order to underline digits 4-7. */ __emit_string_literal_range ("01234\U00002174\U00002175789", /* { dg-warning "range" } */ - 4, 11); + 5, 4, 11); /* { dg-begin-multiline-output "" } __emit_string_literal_range ("01234\U00002174\U00002175789", - ^~~~~~~~~~~~~~~~~~~~~~ + ~^~~~~~~~~~~~~~~~~~~~~ { dg-end-multiline-output "" } */ } @@ -150,10 +150,10 @@ test_u8 (void) { /* Digits 0-9. */ __emit_string_literal_range (u8"0123456789", /* { dg-warning "range" } */ - 4, 7); + 6, 4, 7); /* { dg-begin-multiline-output "" } __emit_string_literal_range (u8"0123456789", - ^~~~ + ~~^~ { dg-end-multiline-output "" } */ } @@ -161,8 +161,8 @@ void test_u (void) { /* Digits 0-9. */ - __emit_string_literal_range (u"0123456789", /* { dg-error "unable to read substring range: execution character set != source character set" } */ - 4, 7); + __emit_string_literal_range (u"0123456789", /* { dg-error "unable to read substring location: execution character set != source character set" } */ + 6, 4, 7); /* { dg-begin-multiline-output "" } __emit_string_literal_range (u"0123456789", ^~~~~~~~~~~~~ @@ -173,8 +173,8 @@ void test_U (void) { /* Digits 0-9. */ - __emit_string_literal_range (U"0123456789", /* { dg-error "unable to read substring range: execution character set != source character set" } */ - 4, 7); + __emit_string_literal_range (U"0123456789", /* { dg-error "unable to read substring location: execution character set != source character set" } */ + 6, 4, 7); /* { dg-begin-multiline-output "" } __emit_string_literal_range (U"0123456789", ^~~~~~~~~~~~~ @@ -185,8 +185,8 @@ void test_L (void) { /* Digits 0-9. */ - __emit_string_literal_range (L"0123456789", /* { dg-error "unable to read substring range: execution character set != source character set" } */ - 4, 7); + __emit_string_literal_range (L"0123456789", /* { dg-error "unable to read substring location: execution character set != source character set" } */ + 6, 4, 7); /* { dg-begin-multiline-output "" } __emit_string_literal_range (L"0123456789", ^~~~~~~~~~~~~ @@ -199,10 +199,10 @@ test_macro (void) #define START "01234" /* { dg-warning "range" } */ __emit_string_literal_range (START "56789", - 3, 6); + 4, 3, 6); /* { dg-begin-multiline-output "" } #define START "01234" - ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ __emit_string_literal_range (START ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ "56789", diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-string-literals-2.c b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-string-literals-2.c index 7851c02..25cb3f0 100644 --- a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-string-literals-2.c +++ b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-string-literals-2.c @@ -3,7 +3,7 @@ /* See the notes in diagnostic-test-string-literals-1.c. This test case has caret-printing disabled. */ -extern void __emit_string_literal_range (const void *literal, +extern void __emit_string_literal_range (const void *literal, int caret_idx, int start_idx, int end_idx); /* Test of a stringified macro argument, by itself. */ @@ -12,8 +12,8 @@ test_stringified_token_1 (int x) { #define STRINGIFY(EXPR) #EXPR - __emit_string_literal_range (STRINGIFY(x > 0), /* { dg-error "unable to read substring range: macro expansion" } */ - 0, 4); + __emit_string_literal_range (STRINGIFY(x > 0), /* { dg-error "unable to read substring location: macro expansion" } */ + 0, 0, 4); #undef STRINGIFY } @@ -23,14 +23,14 @@ test_stringified_token_1 (int x) void test_stringized_token_2 (int x) { -#define EXAMPLE(EXPR, START_IDX, END_IDX) \ +#define EXAMPLE(EXPR, CARET_IDX, START_IDX, END_IDX) \ do { \ __emit_string_literal_range (" before " #EXPR " after \n", \ - START_IDX, END_IDX); \ + CARET_IDX, START_IDX, END_IDX); \ } while (0) - EXAMPLE(x > 0, 1, 6); - /* { dg-error "unable to read substring range: cpp_interpret_string_1 failed" "" { target *-*-* } 28 } */ + EXAMPLE(x > 0, 1, 1, 6); + /* { dg-error "unable to read substring location: cpp_interpret_string_1 failed" "" { target *-*-* } 28 } */ #undef EXAMPLE } @@ -43,8 +43,8 @@ test_stringified_token_3 (int x) #define XSTR(s) STR(s) #define STR(s) #s #define FOO 123456789 - __emit_string_literal_range (XSTR (FOO), /* { dg-error "unable to read substring range: macro expansion" } */ - 2, 3); + __emit_string_literal_range (XSTR (FOO), /* { dg-error "unable to read substring location: macro expansion" } */ + 2, 2, 3); #undef XSTR #undef STR diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_string_literals.c b/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_string_literals.c index d44612a..dff999c 100644 --- a/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_string_literals.c +++ b/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_string_literals.c @@ -95,14 +95,12 @@ check_for_named_call (gimple *stmt, return call; } -/* Emit a warning covering SRC_RANGE, with the caret at the start of - SRC_RANGE. */ +/* Emit a warning at LOC. */ static void -emit_warning (source_range src_range) +emit_warning (location_t loc) { - location_t loc - = make_location (src_range.m_start, src_range.m_start, src_range.m_finish); + source_range src_range = get_range_from_loc (line_table, loc); warning_at (loc, 0, "range %i:%i-%i:%i", LOCATION_LINE (src_range.m_start), LOCATION_COLUMN (src_range.m_start), @@ -114,14 +112,14 @@ emit_warning (source_range src_range) within string literals, for use by diagnostic-test-string-literals-*.c. Emit a warning showing the range of a string literal, for each call to a function named "__emit_string_literal_range". - The initial argument should be a string literal; arguments 2 and 3 - should be integer constants, giving the range within the string + The initial argument should be a string literal; arguments 2, 3, and 4 + should be integer constants, giving the caret and range within the string to be printed. */ static void test_string_literals (gimple *stmt) { - gcall *call = check_for_named_call (stmt, "__emit_string_literal_range", 3); + gcall *call = check_for_named_call (stmt, "__emit_string_literal_range", 4); if (!call) return; @@ -141,32 +139,40 @@ test_string_literals (gimple *stmt) return; } - tree t_start_idx = gimple_call_arg (call, 1); - if (TREE_CODE (t_start_idx) != INTEGER_CST) + tree t_caret_idx = gimple_call_arg (call, 1); + if (TREE_CODE (t_caret_idx) != INTEGER_CST) { error_at (call->location, "integer constant required for arg 2"); return; } + int caret_idx = TREE_INT_CST_LOW (t_caret_idx); + + tree t_start_idx = gimple_call_arg (call, 2); + if (TREE_CODE (t_start_idx) != INTEGER_CST) + { + error_at (call->location, "integer constant required for arg 3"); + return; + } int start_idx = TREE_INT_CST_LOW (t_start_idx); - tree t_end_idx = gimple_call_arg (call, 2); + tree t_end_idx = gimple_call_arg (call, 3); if (TREE_CODE (t_end_idx) != INTEGER_CST) { - error_at (call->location, "integer constant required for arg 3"); + error_at (call->location, "integer constant required for arg 4"); return; } int end_idx = TREE_INT_CST_LOW (t_end_idx); /* A STRING_CST doesn't have a location, but the ADDR_EXPR does. */ location_t strloc = EXPR_LOCATION (t_addr_string); - source_range src_range; + location_t loc; substring_loc substr_loc (strloc, TREE_TYPE (t_string), - start_idx, end_idx); - const char *err = substr_loc.get_range (&src_range); + caret_idx, start_idx, end_idx); + const char *err = substr_loc.get_location (&loc); if (err) - error_at (strloc, "unable to read substring range: %s", err); + error_at (strloc, "unable to read substring location: %s", err); else - emit_warning (src_range); + emit_warning (loc); } /* Call test_string_literals on every statement within FUN. */ |