diff options
author | Tom de Vries <tom@codesourcery.com> | 2016-09-10 14:38:56 +0000 |
---|---|---|
committer | Tom de Vries <vries@gcc.gnu.org> | 2016-09-10 14:38:56 +0000 |
commit | 5b28efbbf4abec11f013f4e76f5b55e2974737cf (patch) | |
tree | 3c42070a9bfa92bf3029b74813fd60d1dd925ccc /gcc | |
parent | af4b8a523322d6100b52d41ad12d7b602d01331b (diff) | |
download | gcc-5b28efbbf4abec11f013f4e76f5b55e2974737cf.zip gcc-5b28efbbf4abec11f013f4e76f5b55e2974737cf.tar.gz gcc-5b28efbbf4abec11f013f4e76f5b55e2974737cf.tar.bz2 |
Make canonical_va_list_type more strict
2016-09-10 Tom de Vries <tom@codesourcery.com>
PR C/71602
* builtins.c (std_canonical_va_list_type): Strictly return non-null for
va_list type only.
* config/i386/i386.c (ix86_canonical_va_list_type): Same.
* gimplify.c (gimplify_va_arg_expr): Handle &va_list.
* c-common.c (build_va_arg): Handle more strict
targetm.canonical_va_list_type. Replace first argument type error with
assert.
* c-c++-common/va-arg-va-list-type.c: New test.
From-SVN: r240072
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ChangeLog | 8 | ||||
-rw-r--r-- | gcc/builtins.c | 4 | ||||
-rw-r--r-- | gcc/c-family/ChangeLog | 7 | ||||
-rw-r--r-- | gcc/c-family/c-common.c | 20 | ||||
-rw-r--r-- | gcc/config/i386/i386.c | 8 | ||||
-rw-r--r-- | gcc/gimplify.c | 5 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/c-c++-common/va-arg-va-list-type.c | 9 |
8 files changed, 37 insertions, 29 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 2219333..3a0057e 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,11 @@ +2016-09-10 Tom de Vries <tom@codesourcery.com> + + PR C/71602 + * builtins.c (std_canonical_va_list_type): Strictly return non-null for + va_list type only. + * config/i386/i386.c (ix86_canonical_va_list_type): Same. + * gimplify.c (gimplify_va_arg_expr): Handle &va_list. + 2016-09-09 Peter Bergner <bergner@vnet.ibm.com> PR rtl-optimization/77289 diff --git a/gcc/builtins.c b/gcc/builtins.c index 4a2a398..e779c71 100644 --- a/gcc/builtins.c +++ b/gcc/builtins.c @@ -4087,10 +4087,6 @@ std_canonical_va_list_type (tree type) { tree wtype, htype; - if (INDIRECT_REF_P (type)) - type = TREE_TYPE (type); - else if (POINTER_TYPE_P (type) && POINTER_TYPE_P (TREE_TYPE (type))) - type = TREE_TYPE (type); wtype = va_list_type_node; htype = type; /* Treat structure va_list types. */ diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index 9a78b7aa..635e981 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,3 +1,10 @@ +2016-09-10 Tom de Vries <tom@codesourcery.com> + + PR C/71602 + * c-common.c (build_va_arg): Handle more strict + targetm.canonical_va_list_type. Replace first argument type error with + assert. + 2016-09-09 Martin Sebor <msebor@redhat.com> PR c/77520 diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c index 9a66cfe..16f6548 100644 --- a/gcc/c-family/c-common.c +++ b/gcc/c-family/c-common.c @@ -5864,20 +5864,11 @@ build_va_arg (location_t loc, tree expr, tree type) { /* Case 1: Not an array type. */ - /* Take the address, to get '&ap'. */ + /* Take the address, to get '&ap'. Note that &ap is not a va_list + type. */ mark_addressable (expr); expr = build1 (ADDR_EXPR, build_pointer_type (TREE_TYPE (expr)), expr); - /* Verify that &ap is still recognized as having va_list type. */ - tree canon_expr_type - = targetm.canonical_va_list_type (TREE_TYPE (expr)); - if (canon_expr_type == NULL_TREE) - { - error_at (loc, - "first argument to %<va_arg%> not of type %<va_list%>"); - return error_mark_node; - } - return build_va_arg_1 (loc, type, expr); } @@ -5944,12 +5935,7 @@ build_va_arg (location_t loc, tree expr, tree type) /* Verify that &ap is still recognized as having va_list type. */ tree canon_expr_type = targetm.canonical_va_list_type (TREE_TYPE (expr)); - if (canon_expr_type == NULL_TREE) - { - error_at (loc, - "first argument to %<va_arg%> not of type %<va_list%>"); - return error_mark_node; - } + gcc_assert (canon_expr_type != NULL_TREE); } else { diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c index 1190dab..051fddb 100644 --- a/gcc/config/i386/i386.c +++ b/gcc/config/i386/i386.c @@ -48562,14 +48562,6 @@ ix86_fn_abi_va_list (tree fndecl) static tree ix86_canonical_va_list_type (tree type) { - /* Resolve references and pointers to va_list type. */ - if (TREE_CODE (type) == MEM_REF) - type = TREE_TYPE (type); - else if (POINTER_TYPE_P (type) && POINTER_TYPE_P (TREE_TYPE(type))) - type = TREE_TYPE (type); - else if (POINTER_TYPE_P (type) && TREE_CODE (TREE_TYPE (type)) == ARRAY_TYPE) - type = TREE_TYPE (type); - if (TARGET_64BIT) { if (lookup_attribute ("ms_abi va_list", TYPE_ATTRIBUTES (type))) diff --git a/gcc/gimplify.c b/gcc/gimplify.c index 2f0dd88..e378ed0 100644 --- a/gcc/gimplify.c +++ b/gcc/gimplify.c @@ -11990,6 +11990,11 @@ gimplify_va_arg_expr (tree *expr_p, gimple_seq *pre_p, if (have_va_type == error_mark_node) return GS_ERROR; have_va_type = targetm.canonical_va_list_type (have_va_type); + if (have_va_type == NULL_TREE + && TREE_CODE (valist) == ADDR_EXPR) + /* Handle 'Case 1: Not an array type' from c-common.c/build_va_arg. */ + have_va_type + = targetm.canonical_va_list_type (TREE_TYPE (TREE_TYPE (valist))); gcc_assert (have_va_type != NULL_TREE); /* Generate a diagnostic for requesting data of a type that cannot diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 3d9e0b2..ee50f3d 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2016-09-10 Tom de Vries <tom@codesourcery.com> + + PR C/71602 + * c-c++-common/va-arg-va-list-type.c: New test. + 2016-09-09 Peter Bergner <bergner@vnet.ibm.com> PR rtl-optimization/77289 diff --git a/gcc/testsuite/c-c++-common/va-arg-va-list-type.c b/gcc/testsuite/c-c++-common/va-arg-va-list-type.c new file mode 100644 index 0000000..cdd97cf --- /dev/null +++ b/gcc/testsuite/c-c++-common/va-arg-va-list-type.c @@ -0,0 +1,9 @@ +/* { dg-do compile } */ + +__builtin_va_list *pap; + +void +fn1 (void) +{ + __builtin_va_arg (pap, double); /* { dg-error "first argument to 'va_arg' not of type 'va_list'" } */ +} |