From 4bbf545b8b47ef2a1a2a8a666f88dfe7ba9fe23a Mon Sep 17 00:00:00 2001 From: David Malcolm Date: Fri, 18 Mar 2016 17:45:42 +0000 Subject: [PATCH] PR c/70281: C FE: fix uninitialized range for __builtin_types_compatible_p gcc/c/ChangeLog: PR c/70281 * c-parser.c (c_parser_postfix_expression): Set the source range for uses of "__builtin_types_compatible_p". gcc/testsuite/ChangeLog: PR c/70281 * gcc.dg/plugin/diagnostic-test-expressions-1.c (test_builtin_types_compatible_p): New test function. * gcc.dg/pr70281.c: New test case. From-SVN: r234340 --- gcc/c/ChangeLog | 6 ++++++ gcc/c/c-parser.c | 6 ++++-- gcc/testsuite/ChangeLog | 7 +++++++ .../plugin/diagnostic-test-expressions-1.c | 18 ++++++++++++++++++ gcc/testsuite/gcc.dg/pr70281.c | 9 +++++++++ 5 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/pr70281.c diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog index 3d57c76cd58..c8cb0227e2a 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,3 +1,9 @@ +2016-03-18 David Malcolm + + PR c/70281 + * c-parser.c (c_parser_postfix_expression): Set the source range + for uses of "__builtin_types_compatible_p". + 2016-03-17 Jakub Jelinek PR c/70280 diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c index 82d6eca06fc..646068424bd 100644 --- a/gcc/c/c-parser.c +++ b/gcc/c/c-parser.c @@ -7782,9 +7782,10 @@ c_parser_postfix_expression (c_parser *parser) expr.value = error_mark_node; break; } - c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, - "expected %<)%>"); { + location_t close_paren_loc = c_parser_peek_token (parser)->location; + c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, + "expected %<)%>"); tree e1, e2; e1 = groktypename (t1, NULL, NULL); e2 = groktypename (t2, NULL, NULL); @@ -7799,6 +7800,7 @@ c_parser_postfix_expression (c_parser *parser) expr.value = comptypes (e1, e2) ? integer_one_node : integer_zero_node; + set_c_expr_source_range (&expr, loc, close_paren_loc); } break; case RID_BUILTIN_CALL_WITH_STATIC_CHAIN: diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 4c8b3d17f76..c3ceedbd88e 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,10 @@ +2016-03-18 David Malcolm + + PR c/70281 + * gcc.dg/plugin/diagnostic-test-expressions-1.c + (test_builtin_types_compatible_p): New test function. + * gcc.dg/pr70281.c: New test case. + 2016-03-18 Christophe Lyon PR target/70113 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 170060f9a21..93729361388 100644 --- a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-expressions-1.c +++ b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-expressions-1.c @@ -534,6 +534,24 @@ void test_builtin_choose_expr (int i) } extern int f (int); + +void test_builtin_types_compatible_p (unsigned long i) +{ + __emit_expression_range (0, + f (i) + __builtin_types_compatible_p (long, int)); /* { dg-warning "range" } */ +/* { dg-begin-multiline-output "" } + f (i) + __builtin_types_compatible_p (long, int)); + ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + { dg-end-multiline-output "" } */ + + __emit_expression_range (0, + __builtin_types_compatible_p (long, int) + f (i)); /* { dg-warning "range" } */ +/* { dg-begin-multiline-output "" } + __builtin_types_compatible_p (long, int) + f (i)); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~ + { dg-end-multiline-output "" } */ +} + void test_builtin_call_with_static_chain (int i, void *ptr) { __emit_expression_range (0, __builtin_call_with_static_chain (f (i), ptr)); /* { dg-warning "range" } */ diff --git a/gcc/testsuite/gcc.dg/pr70281.c b/gcc/testsuite/gcc.dg/pr70281.c new file mode 100644 index 00000000000..9447fb1f2a8 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr70281.c @@ -0,0 +1,9 @@ +/* { dg-options "-Wall -fdiagnostics-show-caret" } */ +int bch_stats_show () +{ + return __builtin_types_compatible_p (unsigned, int) ? "" : ""; /* { dg-warning "cast" } */ +/* { dg-begin-multiline-output "" } + return __builtin_types_compatible_p (unsigned, int) ? "" : ""; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~ + { dg-end-multiline-output "" } */ +} -- 2.30.2