diff options
author | Marek Polacek <polacek@redhat.com> | 2014-05-02 18:13:43 +0000 |
---|---|---|
committer | Marek Polacek <mpolacek@gcc.gnu.org> | 2014-05-02 18:13:43 +0000 |
commit | a0e24419cfc3b66a642d00fa7a13b147a8c57c2e (patch) | |
tree | 96bc1e7d8e5757f56500c47af2b25e01bd148229 /gcc/c | |
parent | 19fc9faaaf98b3c45ede31da2e3cb970ef7b372a (diff) | |
download | gcc-a0e24419cfc3b66a642d00fa7a13b147a8c57c2e.zip gcc-a0e24419cfc3b66a642d00fa7a13b147a8c57c2e.tar.gz gcc-a0e24419cfc3b66a642d00fa7a13b147a8c57c2e.tar.bz2 |
re PR c/25801 (bad diagnostic for increment/decrement of pointer to incomplete array)
PR c/25801
* c-typeck.c (c_size_in_bytes): Update comment. Don't call error.
Return size_one_node when the type is not complete.
(pointer_diff): Remove comment.
(build_unary_op): Improve error messages.
* gcc.dg/pr25801.c: New test.
From-SVN: r210013
Diffstat (limited to 'gcc/c')
-rw-r--r-- | gcc/c/ChangeLog | 8 | ||||
-rw-r--r-- | gcc/c/c-typeck.c | 23 |
2 files changed, 19 insertions, 12 deletions
diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog index b32e4fd..e408fef 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,5 +1,13 @@ 2014-05-02 Marek Polacek <polacek@redhat.com> + PR c/25801 + * c-typeck.c (c_size_in_bytes): Update comment. Don't call error. + Return size_one_node when the type is not complete. + (pointer_diff): Remove comment. + (build_unary_op): Improve error messages. + +2014-05-02 Marek Polacek <polacek@redhat.com> + * c-typeck.c (c_finish_return): Separate warning_at calls. 2014-05-02 Marek Polacek <polacek@redhat.com> diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c index f7ad91e..65fb035 100644 --- a/gcc/c/c-typeck.c +++ b/gcc/c/c-typeck.c @@ -1754,22 +1754,20 @@ type_lists_compatible_p (const_tree args1, const_tree args2, } } -/* Compute the size to increment a pointer by. */ +/* Compute the size to increment a pointer by. When a function type or void + type or incomplete type is passed, size_one_node is returned. + This function does not emit any diagnostics; the caller is responsible + for that. */ static tree c_size_in_bytes (const_tree type) { enum tree_code code = TREE_CODE (type); - if (code == FUNCTION_TYPE || code == VOID_TYPE || code == ERROR_MARK) + if (code == FUNCTION_TYPE || code == VOID_TYPE || code == ERROR_MARK + || !COMPLETE_TYPE_P (type)) return size_one_node; - if (!COMPLETE_OR_VOID_TYPE_P (type)) - { - error ("arithmetic on pointer to an incomplete type"); - return size_one_node; - } - /* Convert in case a char is more than one unit. */ return size_binop_loc (input_location, CEIL_DIV_EXPR, TYPE_SIZE_UNIT (type), size_int (TYPE_PRECISION (char_type_node) @@ -3530,7 +3528,6 @@ pointer_diff (location_t loc, tree op0, tree op1) if (!COMPLETE_OR_VOID_TYPE_P (TREE_TYPE (TREE_TYPE (orig_op1)))) error_at (loc, "arithmetic on pointer to an incomplete type"); - /* This generates an error if op0 is pointer to incomplete type. */ op1 = c_size_in_bytes (target_type); if (pointer_to_zero_sized_aggr_p (TREE_TYPE (orig_op1))) @@ -4004,16 +4001,18 @@ build_unary_op (location_t location, if (typecode == POINTER_TYPE) { - /* If pointer target is an undefined struct, + /* If pointer target is an incomplete type, we just cannot know how to do the arithmetic. */ if (!COMPLETE_OR_VOID_TYPE_P (TREE_TYPE (argtype))) { if (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR) error_at (location, - "increment of pointer to unknown structure"); + "increment of pointer to an incomplete type %qT", + TREE_TYPE (argtype)); else error_at (location, - "decrement of pointer to unknown structure"); + "decrement of pointer to an incomplete type %qT", + TREE_TYPE (argtype)); } else if (TREE_CODE (TREE_TYPE (argtype)) == FUNCTION_TYPE || TREE_CODE (TREE_TYPE (argtype)) == VOID_TYPE) |