]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c/60114 (Incorrect column number for -pedantic and -Wconversion)
authorMarek Polacek <polacek@redhat.com>
Fri, 25 Apr 2014 10:49:56 +0000 (10:49 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Fri, 25 Apr 2014 10:49:56 +0000 (10:49 +0000)
PR c/60114
c/
* c-parser.c (c_parser_initelt): Pass input_location to
process_init_element.
(c_parser_initval): Pass loc to process_init_element.
* c-tree.h (process_init_element): Adjust declaration.
* c-typeck.c (push_init_level): Pass input_location to
process_init_element.
(pop_init_level): Likewise.
(set_designator): Likewise.
(output_init_element): Add location_t parameter.  Pass loc to
digest_init.
(output_pending_init_elements): Pass input_location to
output_init_element.
(process_init_element): Add location_t parameter.  Pass loc to
output_init_element.
testsuite/
* gcc.dg/pr60114.c: New test.

From-SVN: r209794

gcc/c/ChangeLog
gcc/c/c-parser.c
gcc/c/c-tree.h
gcc/c/c-typeck.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pr60114.c [new file with mode: 0644]

index 14e616903cb5c9cb73a9d9d38e30461715cb3244..7369065d20efae65b85df4bca0e8acac39ab57d7 100644 (file)
@@ -1,3 +1,21 @@
+2014-04-25  Marek Polacek  <polacek@redhat.com>
+
+       PR c/60114
+       * c-parser.c (c_parser_initelt): Pass input_location to
+       process_init_element.
+       (c_parser_initval): Pass loc to process_init_element.
+       * c-tree.h (process_init_element): Adjust declaration.
+       * c-typeck.c (push_init_level): Pass input_location to
+       process_init_element.
+       (pop_init_level): Likewise.
+       (set_designator): Likewise.
+       (output_init_element): Add location_t parameter.  Pass loc to
+       digest_init.
+       (output_pending_init_elements): Pass input_location to
+       output_init_element.
+       (process_init_element): Add location_t parameter.  Pass loc to
+       output_init_element.
+
 2014-04-24  Prathamesh Kulkarni  <bilbotheelffriend@gmail.com>
 
        * c-parser.c (c_parser_sizeof_expression): Reorganize slightly to
index c229bdb47ad5d4ce6dce52b18b9c8e8074025528..56f79f6a795b61af07f49743dfead069f5a759a5 100644 (file)
@@ -4219,7 +4219,8 @@ c_parser_initelt (c_parser *parser, struct obstack * braced_init_obstack)
                  init.original_type = NULL;
                  c_parser_error (parser, "expected identifier");
                  c_parser_skip_until_found (parser, CPP_COMMA, NULL);
-                 process_init_element (init, false, braced_init_obstack);
+                 process_init_element (input_location, init, false,
+                                       braced_init_obstack);
                  return;
                }
            }
@@ -4351,7 +4352,8 @@ c_parser_initelt (c_parser *parser, struct obstack * braced_init_obstack)
                  init.original_type = NULL;
                  c_parser_error (parser, "expected %<=%>");
                  c_parser_skip_until_found (parser, CPP_COMMA, NULL);
-                 process_init_element (init, false, braced_init_obstack);
+                 process_init_element (input_location, init, false,
+                                       braced_init_obstack);
                  return;
                }
            }
@@ -4372,18 +4374,19 @@ c_parser_initval (c_parser *parser, struct c_expr *after,
 {
   struct c_expr init;
   gcc_assert (!after || c_dialect_objc ());
+  location_t loc = c_parser_peek_token (parser)->location;
+
   if (c_parser_next_token_is (parser, CPP_OPEN_BRACE) && !after)
     init = c_parser_braced_init (parser, NULL_TREE, true);
   else
     {
-      location_t loc = c_parser_peek_token (parser)->location;
       init = c_parser_expr_no_commas (parser, after);
       if (init.value != NULL_TREE
          && TREE_CODE (init.value) != STRING_CST
          && TREE_CODE (init.value) != COMPOUND_LITERAL_EXPR)
        init = convert_lvalue_to_rvalue (loc, init, true, true);
     }
-  process_init_element (init, false, braced_init_obstack);
+  process_init_element (loc, init, false, braced_init_obstack);
 }
 
 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
index 85df8858dea398a05d64c33501ea306c4fff6746..53768d619b7c0f525ac244691b7d90a479ef71f4 100644 (file)
@@ -612,7 +612,8 @@ extern void push_init_level (int, struct obstack *);
 extern struct c_expr pop_init_level (int, struct obstack *);
 extern void set_init_index (tree, tree, struct obstack *);
 extern void set_init_label (tree, struct obstack *);
-extern void process_init_element (struct c_expr, bool, struct obstack *);
+extern void process_init_element (location_t, struct c_expr, bool,
+                                 struct obstack *);
 extern tree build_compound_literal (location_t, tree, tree, bool);
 extern void check_compound_literal_type (location_t, struct c_type_name *);
 extern tree c_start_case (location_t, location_t, tree);
index 65aad45651c9b29ecac7b217244b3f123c6d4558..62c72dfdd70884d29d5a330ab3765a4121e551a4 100644 (file)
@@ -102,8 +102,8 @@ static int spelling_length (void);
 static char *print_spelling (char *);
 static void warning_init (int, const char *);
 static tree digest_init (location_t, tree, tree, tree, bool, bool, int);
-static void output_init_element (tree, tree, bool, tree, tree, int, bool,
-                                struct obstack *);
+static void output_init_element (location_t, tree, tree, bool, tree, tree, int,
+                                bool, struct obstack *);
 static void output_pending_init_elements (int, struct obstack *);
 static int set_designator (int, struct obstack *);
 static void push_range_stack (tree, struct obstack *);
@@ -7183,13 +7183,15 @@ push_init_level (int implicit, struct obstack * braced_init_obstack)
          if ((TREE_CODE (constructor_type) == RECORD_TYPE
               || TREE_CODE (constructor_type) == UNION_TYPE)
              && constructor_fields == 0)
-           process_init_element (pop_init_level (1, braced_init_obstack),
+           process_init_element (input_location,
+                                 pop_init_level (1, braced_init_obstack),
                                  true, braced_init_obstack);
          else if (TREE_CODE (constructor_type) == ARRAY_TYPE
                   && constructor_max_index
                   && tree_int_cst_lt (constructor_max_index,
                                       constructor_index))
-           process_init_element (pop_init_level (1, braced_init_obstack),
+           process_init_element (input_location,
+                                 pop_init_level (1, braced_init_obstack),
                                  true, braced_init_obstack);
          else
            break;
@@ -7389,10 +7391,9 @@ pop_init_level (int implicit, struct obstack * braced_init_obstack)
       /* When we come to an explicit close brace,
         pop any inner levels that didn't have explicit braces.  */
       while (constructor_stack->implicit)
-       {
-         process_init_element (pop_init_level (1, braced_init_obstack),
-                               true, braced_init_obstack);
-       }
+       process_init_element (input_location,
+                             pop_init_level (1, braced_init_obstack),
+                             true, braced_init_obstack);
       gcc_assert (!constructor_range_stack);
     }
 
@@ -7570,10 +7571,9 @@ set_designator (int array, struct obstack * braced_init_obstack)
       /* Designator list starts at the level of closest explicit
         braces.  */
       while (constructor_stack->implicit)
-       {
-         process_init_element (pop_init_level (1, braced_init_obstack),
-                               true, braced_init_obstack);
-       }
+       process_init_element (input_location,
+                             pop_init_level (1, braced_init_obstack),
+                             true, braced_init_obstack);
       constructor_designated = 1;
       return 0;
     }
@@ -8193,9 +8193,9 @@ find_init_member (tree field, struct obstack * braced_init_obstack)
    existing initializer.  */
 
 static void
-output_init_element (tree value, tree origtype, bool strict_string, tree type,
-                    tree field, int pending, bool implicit,
-                    struct obstack * braced_init_obstack)
+output_init_element (location_t loc, tree value, tree origtype,
+                    bool strict_string, tree type, tree field, int pending,
+                    bool implicit, struct obstack * braced_init_obstack)
 {
   tree semantic_type = NULL_TREE;
   bool maybe_const = true;
@@ -8293,8 +8293,8 @@ output_init_element (tree value, tree origtype, bool strict_string, tree type,
 
   if (semantic_type)
     value = build1 (EXCESS_PRECISION_EXPR, semantic_type, value);
-  value = digest_init (input_location, type, value, origtype, npc,
-                      strict_string, require_constant_value);
+  value = digest_init (loc, type, value, origtype, npc, strict_string,
+                      require_constant_value);
   if (value == error_mark_node)
     {
       constructor_erroneous = 1;
@@ -8421,8 +8421,8 @@ output_pending_init_elements (int all, struct obstack * braced_init_obstack)
        {
          if (tree_int_cst_equal (elt->purpose,
                                  constructor_unfilled_index))
-           output_init_element (elt->value, elt->origtype, true,
-                                TREE_TYPE (constructor_type),
+           output_init_element (input_location, elt->value, elt->origtype,
+                                true, TREE_TYPE (constructor_type),
                                 constructor_unfilled_index, 0, false,
                                 braced_init_obstack);
          else if (tree_int_cst_lt (constructor_unfilled_index,
@@ -8476,8 +8476,8 @@ output_pending_init_elements (int all, struct obstack * braced_init_obstack)
          if (tree_int_cst_equal (elt_bitpos, ctor_unfilled_bitpos))
            {
              constructor_unfilled_fields = elt->purpose;
-             output_init_element (elt->value, elt->origtype, true,
-                                  TREE_TYPE (elt->purpose),
+             output_init_element (input_location, elt->value, elt->origtype,
+                                  true, TREE_TYPE (elt->purpose),
                                   elt->purpose, 0, false,
                                   braced_init_obstack);
            }
@@ -8550,7 +8550,7 @@ output_pending_init_elements (int all, struct obstack * braced_init_obstack)
    existing initializer.  */
 
 void
-process_init_element (struct c_expr value, bool implicit,
+process_init_element (location_t loc, struct c_expr value, bool implicit,
                      struct obstack * braced_init_obstack)
 {
   tree orig_value = value.value;
@@ -8594,14 +8594,14 @@ process_init_element (struct c_expr value, bool implicit,
       if ((TREE_CODE (constructor_type) == RECORD_TYPE
           || TREE_CODE (constructor_type) == UNION_TYPE)
          && constructor_fields == 0)
-       process_init_element (pop_init_level (1, braced_init_obstack),
+       process_init_element (loc, pop_init_level (1, braced_init_obstack),
                              true, braced_init_obstack);
       else if ((TREE_CODE (constructor_type) == ARRAY_TYPE
                || TREE_CODE (constructor_type) == VECTOR_TYPE)
               && constructor_max_index
               && tree_int_cst_lt (constructor_max_index,
                                   constructor_index))
-       process_init_element (pop_init_level (1, braced_init_obstack),
+       process_init_element (loc, pop_init_level (1, braced_init_obstack),
                              true, braced_init_obstack);
       else
        break;
@@ -8679,7 +8679,7 @@ process_init_element (struct c_expr value, bool implicit,
          if (value.value)
            {
              push_member_name (constructor_fields);
-             output_init_element (value.value, value.original_type,
+             output_init_element (loc, value.value, value.original_type,
                                   strict_string, fieldtype,
                                   constructor_fields, 1, implicit,
                                   braced_init_obstack);
@@ -8771,7 +8771,7 @@ process_init_element (struct c_expr value, bool implicit,
          if (value.value)
            {
              push_member_name (constructor_fields);
-             output_init_element (value.value, value.original_type,
+             output_init_element (loc, value.value, value.original_type,
                                   strict_string, fieldtype,
                                   constructor_fields, 1, implicit,
                                   braced_init_obstack);
@@ -8823,7 +8823,7 @@ process_init_element (struct c_expr value, bool implicit,
          if (value.value)
            {
              push_array_bounds (tree_to_uhwi (constructor_index));
-             output_init_element (value.value, value.original_type,
+             output_init_element (loc, value.value, value.original_type,
                                   strict_string, elttype,
                                   constructor_index, 1, implicit,
                                   braced_init_obstack);
@@ -8858,7 +8858,7 @@ process_init_element (struct c_expr value, bool implicit,
            {
              if (TREE_CODE (value.value) == VECTOR_CST)
                elttype = TYPE_MAIN_VARIANT (constructor_type);
-             output_init_element (value.value, value.original_type,
+             output_init_element (loc, value.value, value.original_type,
                                   strict_string, elttype,
                                   constructor_index, 1, implicit,
                                   braced_init_obstack);
@@ -8887,7 +8887,7 @@ process_init_element (struct c_expr value, bool implicit,
       else
        {
          if (value.value)
-           output_init_element (value.value, value.original_type,
+           output_init_element (loc, value.value, value.original_type,
                                 strict_string, constructor_type,
                                 NULL_TREE, 1, implicit,
                                 braced_init_obstack);
@@ -8906,8 +8906,8 @@ process_init_element (struct c_expr value, bool implicit,
          while (constructor_stack != range_stack->stack)
            {
              gcc_assert (constructor_stack->implicit);
-             process_init_element (pop_init_level (1,
-                                                   braced_init_obstack),
+             process_init_element (loc,
+                                   pop_init_level (1, braced_init_obstack),
                                    true, braced_init_obstack);
            }
          for (p = range_stack;
@@ -8915,7 +8915,8 @@ process_init_element (struct c_expr value, bool implicit,
               p = p->prev)
            {
              gcc_assert (constructor_stack->implicit);
-             process_init_element (pop_init_level (1, braced_init_obstack),
+             process_init_element (loc,
+                                   pop_init_level (1, braced_init_obstack),
                                    true, braced_init_obstack);
            }
 
index ad87aa27eed1a8bfb9c0a28eab28ef7048058e4e..9aa2a25792691b2b527d8f34d2446f668ca97b54 100644 (file)
@@ -1,3 +1,8 @@
+2014-04-25  Marek Polacek  <polacek@redhat.com>
+
+       PR c/60114
+       * gcc.dg/pr60114.c: New test.
+
 2014-04-25  Eric Botcazou  <ebotcazou@adacore.com>
 
        * gcc.c-torture/execute/20140425-1.c: New test.
diff --git a/gcc/testsuite/gcc.dg/pr60114.c b/gcc/testsuite/gcc.dg/pr60114.c
new file mode 100644 (file)
index 0000000..83f9852
--- /dev/null
@@ -0,0 +1,31 @@
+/* PR c/60114 */
+/* { dg-do compile } */
+/* { dg-options "-Wconversion" } */
+
+struct S { int n, u[2]; };
+const char z[] = {
+  [0] = 0x100, /* { dg-warning "9:overflow in implicit constant conversion" } */
+  [2] = 0x101, /* { dg-warning "9:overflow in implicit constant conversion" } */
+};
+int A[] = {
+            0, 0x80000000, /* { dg-warning "16:conversion of unsigned constant value to negative integer" } */
+            0xA, 0x80000000, /* { dg-warning "18:conversion of unsigned constant value to negative integer" } */
+            0xA, 0xA, 0x80000000 /* { dg-warning "23:conversion of unsigned constant value to negative integer" } */
+          };
+int *p = (int []) { 0x80000000 }; /* { dg-warning "21:conversion of unsigned constant value to negative integer" } */
+union { int k; } u = { .k = 0x80000000 }; /* { dg-warning "29:conversion of unsigned constant value to negative integer" } */
+typedef int H[];
+void
+foo (void)
+{
+  char a[][3] = { { 0x100, /* { dg-warning "21:overflow in implicit constant conversion" } */
+                    1, 0x100 }, /* { dg-warning "24:overflow in implicit constant conversion" } */
+                  { '\0', 0x100, '\0' } /* { dg-warning "27:overflow in implicit constant conversion" } */
+                };
+  (const char []) { 0x100 }; /* { dg-warning "21:overflow in implicit constant conversion" } */
+  (const float []) { 1e0, 1e1, 1e100 }; /* { dg-warning "32:conversion" } */
+  struct S s1 = { 0x80000000 }; /* { dg-warning "19:conversion of unsigned constant value to negative integer" } */
+  struct S s2 = { .n = 0x80000000 }; /* { dg-warning "24:conversion of unsigned constant value to negative integer" } */
+  struct S s3 = { .u[1] = 0x80000000 }; /* { dg-warning "27:conversion of unsigned constant value to negative integer" } */
+  H h = { 1, 2, 0x80000000 }; /* { dg-warning "17:conversion of unsigned constant value to negative integer" } */
+}