diff options
author | David Malcolm <dmalcolm@redhat.com> | 2015-12-08 17:03:26 +0000 |
---|---|---|
committer | David Malcolm <dmalcolm@gcc.gnu.org> | 2015-12-08 17:03:26 +0000 |
commit | a1b93f8daf8029685f49cd57612d726674b8595c (patch) | |
tree | c9a3f87f1a7b95b9736b2d9e05db06d64e2291b2 /gcc | |
parent | 46c6e1e20e58a8e071c163d9f1a8ea179a437fd3 (diff) | |
download | gcc-a1b93f8daf8029685f49cd57612d726674b8595c.zip gcc-a1b93f8daf8029685f49cd57612d726674b8595c.tar.gz gcc-a1b93f8daf8029685f49cd57612d726674b8595c.tar.bz2 |
C: fix uninitialized ranges for __alignof__
gcc/c/ChangeLog:
* c-parser.c (c_parser_alignof_expression): Capture location of
closing parenthesis (if any), or of end of unary expression, and
use it to build a src_range for the expression.
gcc/testsuite/ChangeLog:
* gcc.dg/plugin/diagnostic-test-expressions-1.c (test_alignof):
New test function.
From-SVN: r231415
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/c/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/c/c-parser.c | 16 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/plugin/diagnostic-test-expressions-1.c | 27 |
4 files changed, 49 insertions, 5 deletions
diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog index 62d92c0..2ba9464 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,5 +1,11 @@ 2015-12-08 David Malcolm <dmalcolm@redhat.com> + * c-parser.c (c_parser_alignof_expression): Capture location of + closing parenthesis (if any), or of end of unary expression, and + use it to build a src_range for the expression. + +2015-12-08 David Malcolm <dmalcolm@redhat.com> + PR c/68757 * c-parser.c (c_parser_get_builtin_args): Add "out_close_paren_loc" param, and write back to it. diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c index 8ea0e95..4611e5b 100644 --- a/gcc/c/c-parser.c +++ b/gcc/c/c-parser.c @@ -6853,7 +6853,8 @@ static struct c_expr c_parser_alignof_expression (c_parser *parser) { struct c_expr expr; - location_t loc = c_parser_peek_token (parser)->location; + location_t start_loc = c_parser_peek_token (parser)->location; + location_t end_loc; tree alignof_spelling = c_parser_peek_token (parser)->value; gcc_assert (c_parser_next_token_is_keyword (parser, RID_ALIGNOF)); bool is_c11_alignof = strcmp (IDENTIFIER_POINTER (alignof_spelling), @@ -6864,10 +6865,10 @@ c_parser_alignof_expression (c_parser *parser) if (is_c11_alignof) { if (flag_isoc99) - pedwarn_c99 (loc, OPT_Wpedantic, "ISO C99 does not support %qE", + pedwarn_c99 (start_loc, OPT_Wpedantic, "ISO C99 does not support %qE", alignof_spelling); else - pedwarn_c99 (loc, OPT_Wpedantic, "ISO C90 does not support %qE", + pedwarn_c99 (start_loc, OPT_Wpedantic, "ISO C90 does not support %qE", alignof_spelling); } c_parser_consume_token (parser); @@ -6884,6 +6885,7 @@ c_parser_alignof_expression (c_parser *parser) c_parser_consume_token (parser); loc = c_parser_peek_token (parser)->location; type_name = c_parser_type_name (parser); + end_loc = c_parser_peek_token (parser)->location; c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); if (type_name == NULL) { @@ -6910,21 +6912,25 @@ c_parser_alignof_expression (c_parser *parser) false, is_c11_alignof, 1); ret.original_code = ERROR_MARK; ret.original_type = NULL; + set_c_expr_source_range (&ret, start_loc, end_loc); return ret; } else { struct c_expr ret; expr = c_parser_unary_expression (parser); + end_loc = expr.src_range.m_finish; alignof_expr: mark_exp_read (expr.value); c_inhibit_evaluation_warnings--; in_alignof--; - pedwarn (loc, OPT_Wpedantic, "ISO C does not allow %<%E (expression)%>", + pedwarn (start_loc, + OPT_Wpedantic, "ISO C does not allow %<%E (expression)%>", alignof_spelling); - ret.value = c_alignof_expr (loc, expr.value); + ret.value = c_alignof_expr (start_loc, expr.value); ret.original_code = ERROR_MARK; ret.original_type = NULL; + set_c_expr_source_range (&ret, start_loc, end_loc); return ret; } } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 00dc041..5ff2177 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,10 @@ 2015-12-08 David Malcolm <dmalcolm@redhat.com> + * gcc.dg/plugin/diagnostic-test-expressions-1.c (test_alignof): + New test function. + +2015-12-08 David Malcolm <dmalcolm@redhat.com> + PR c/68757 * gcc.dg/plugin/diagnostic-test-expressions-1.c (test_builtin_choose_expr): New test function. 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 023385b..175b2ea 100644 --- a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-expressions-1.c +++ b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-expressions-1.c @@ -568,6 +568,33 @@ void test_builtin_shuffle (v4si a, v4si b, v4si mask) { dg-end-multiline-output "" } */ } +void test_alignof (int param) +{ + __emit_expression_range (0, __alignof__ (int) + param ); /* { dg-warning "range" } */ +/* { dg-begin-multiline-output "" } + __emit_expression_range (0, __alignof__ (int) + param ); + ~~~~~~~~~~~~~~~~~~^~~~~~~ + { dg-end-multiline-output "" } */ + + __emit_expression_range (0, param + __alignof__ (int) ); /* { dg-warning "range" } */ +/* { dg-begin-multiline-output "" } + __emit_expression_range (0, param + __alignof__ (int) ); + ~~~~~~^~~~~~~~~~~~~~~~~~~ + { dg-end-multiline-output "" } */ + + __emit_expression_range (0, __alignof__ (param) + param ); /* { dg-warning "range" } */ +/* { dg-begin-multiline-output "" } + __emit_expression_range (0, __alignof__ (param) + param ); + ~~~~~~~~~~~~~~~~~~~~^~~~~~~ + { dg-end-multiline-output "" } */ + + __emit_expression_range (0, param + __alignof__ (param) ); /* { dg-warning "range" } */ +/* { dg-begin-multiline-output "" } + __emit_expression_range (0, param + __alignof__ (param) ); + ~~~~~~^~~~~~~~~~~~~~~~~~~~~ + { dg-end-multiline-output "" } */ +} + /* Examples of non-trivial expressions. ****************************/ extern double sqrt (double x); |