]> gcc.gnu.org Git - gcc.git/commitdiff
C FE: fix range of primary-expression in c_parser_postfix_expression
authorDavid Malcolm <dmalcolm@redhat.com>
Wed, 16 Dec 2015 17:34:27 +0000 (17:34 +0000)
committerDavid Malcolm <dmalcolm@gcc.gnu.org>
Wed, 16 Dec 2015 17:34:27 +0000 (17:34 +0000)
gcc/c/ChangeLog:
* c-parser.c (c_parser_postfix_expression): Use EXPR_LOC_OR_LOC
to preserve range information for the primary expression
in the call to c_parser_postfix_expression_after_primary.

gcc/testsuite/ChangeLog:
* gcc.dg/cast-function-1.c (bar): Update column numbers.
* gcc.dg/diagnostic-range-bad-called-object.c: New test case.

From-SVN: r231709

gcc/c/ChangeLog
gcc/c/c-parser.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/cast-function-1.c
gcc/testsuite/gcc.dg/diagnostic-range-bad-called-object.c [new file with mode: 0644]

index 3ed1326fd05a1650f3417e54bab47ee0a05415d4..49c3cbb73dcf26c4339f56e5acdab804822b645c 100644 (file)
@@ -1,3 +1,9 @@
+2015-12-16  David Malcolm  <dmalcolm@redhat.com>
+
+       * c-parser.c (c_parser_postfix_expression): Use EXPR_LOC_OR_LOC
+       to preserve range information for the primary expression
+       in the call to c_parser_postfix_expression_after_primary.
+
 2015-12-16  David Malcolm  <dmalcolm@redhat.com>
 
        * c-parser.c (c_parser_static_assert_declaration_no_semi): Use the
index 5c32f45e21e72b16bf3044e851f1d46f50829cad..e149e19bc2c63b6f07a9f12d76514deb1544ee19 100644 (file)
@@ -7954,7 +7954,8 @@ c_parser_postfix_expression (c_parser *parser)
       expr.value = error_mark_node;
       break;
     }
-  return c_parser_postfix_expression_after_primary (parser, loc, expr);
+  return c_parser_postfix_expression_after_primary
+    (parser, EXPR_LOC_OR_LOC (expr.value, loc), expr);
 }
 
 /* Parse a postfix expression after a parenthesized type name: the
index adfb4e059a01b859bc3dd2fb57ed010244be22bd..91ae32a58720358ed9aea5ca289e6cd40ef069d5 100644 (file)
@@ -1,3 +1,8 @@
+2015-12-16  David Malcolm  <dmalcolm@redhat.com>
+
+       * gcc.dg/cast-function-1.c (bar): Update column numbers.
+       * gcc.dg/diagnostic-range-bad-called-object.c: New test case.
+
 2015-12-16  David Malcolm  <dmalcolm@redhat.com>
 
        * gcc.dg/diagnostic-range-static-assert.c: New test case.
index ab42db1196c7e682cf56ce39e0b2d41d59377af4..5228b5591659644696c2c858f835c726b8efbad9 100644 (file)
@@ -18,14 +18,14 @@ typedef struct {
 
 void bar(double d, int i, str_t s)
 {
-  d = ((double (*) (int)) foo1) (i);  /* { dg-warning "7:non-compatible|abort" } */
-  i = ((int (*) (double)) foo1) (d);  /* { dg-warning "7:non-compatible|abort" } */
-  s = ((str_t (*) (int)) foo1) (i);   /* { dg-warning "7:non-compatible|abort" } */
+  d = ((double (*) (int)) foo1) (i);  /* { dg-warning "8:non-compatible|abort" } */
+  i = ((int (*) (double)) foo1) (d);  /* { dg-warning "8:non-compatible|abort" } */
+  s = ((str_t (*) (int)) foo1) (i);   /* { dg-warning "8:non-compatible|abort" } */
   ((void (*) (int)) foo1) (d);        /* { dg-warning "non-compatible|abort" } */
   i = ((int (*) (int)) foo1) (i);     /* { dg-bogus "non-compatible|abort" } */
   (void) foo1 (i);                    /* { dg-bogus "non-compatible|abort" } */
 
-  d = ((double (*) (int)) foo2) (i);  /* { dg-warning "7:non-compatible|abort" } */
+  d = ((double (*) (int)) foo2) (i);  /* { dg-warning "8:non-compatible|abort" } */
   i = ((int (*) (double)) foo2) (d);  /* { dg-bogus "non-compatible|abort" } */
   s = ((str_t (*) (int)) foo2) (i);   /* { dg-warning "non-compatible|abort" } */
   ((void (*) (int)) foo2) (d);        /* { dg-warning "non-compatible|abort" } */
diff --git a/gcc/testsuite/gcc.dg/diagnostic-range-bad-called-object.c b/gcc/testsuite/gcc.dg/diagnostic-range-bad-called-object.c
new file mode 100644 (file)
index 0000000..95fb3e9
--- /dev/null
@@ -0,0 +1,24 @@
+/* { dg-options "-fdiagnostics-show-caret" } */
+
+/* Adapted from https://gcc.gnu.org/wiki/ClangDiagnosticsComparison */
+
+void call_of_non_function_ptr (char **argP, char **argQ)
+{
+  (argP - argQ)(); /* { dg-error "called object is not a function or function pointer" } */
+
+/* { dg-begin-multiline-output "" }
+   (argP - argQ)();
+   ~~~~~~^~~~~~~
+   { dg-end-multiline-output "" } */
+
+  argP();       /* { dg-error "called object 'argP' is not a function or function pointer" } */
+
+/* { dg-begin-multiline-output "" }
+   argP();
+   ^~~~
+   { dg-end-multiline-output "" }
+   { dg-begin-multiline-output "" }
+ void call_of_non_function_ptr (char **argP, char **argQ)
+                                       ^~~~
+   { dg-end-multiline-output "" } */
+}
This page took 0.100507 seconds and 5 git commands to generate.