From ba9bbd6f584afe2939c44c159cbb1c064becad5c Mon Sep 17 00:00:00 2001 From: Tom de Vries Date: Mon, 29 Aug 2016 16:41:33 +0000 Subject: [PATCH] Handle errors in both args of va_arg 2016-08-29 Tom de Vries PR c/77398 * c-common.c (build_va_arg): Add first argument error. Build va_arg with error_mark_node as va_list instead of with illegal va_list. * gimplify.c (gimplify_va_arg_expr): Replace first argument type error with assert. * g++.dg/ext/va-arg1.C: Add error check for illegal first argument. From-SVN: r239827 --- gcc/ChangeLog | 6 ++++++ gcc/c-family/ChangeLog | 6 ++++++ gcc/c-family/c-common.c | 7 +++++-- gcc/gimplify.c | 7 +------ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/ext/va-arg1.C | 4 +++- 6 files changed, 26 insertions(+), 9 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 7bde05e3304..55906fea96b 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2016-08-29 Tom de Vries + + PR c/77398 + * gimplify.c (gimplify_va_arg_expr): Replace first argument type error + with assert. + 2016-08-29 Eric Botcazou * Makefile.in (gcov-iov.h): Add dummy recipe. diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index f8a7425548c..b6876d4bae0 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,3 +1,9 @@ +2016-08-29 Tom de Vries + + PR c/77398 + * c-common.c (build_va_arg): Add first argument error. Build va_arg + with error_mark_node as va_list instead of with illegal va_list. + 2016-08-25 Marek Polacek David Malcolm diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c index 001070d58bc..eef86744038 100644 --- a/gcc/c-family/c-common.c +++ b/gcc/c-family/c-common.c @@ -5806,16 +5806,19 @@ build_va_arg (location_t loc, tree expr, tree type) { tree va_type = TREE_TYPE (expr); tree canon_va_type = (va_type == error_mark_node - ? NULL_TREE + ? error_mark_node : targetm.canonical_va_list_type (va_type)); if (va_type == error_mark_node || canon_va_type == NULL_TREE) { + if (canon_va_type == NULL_TREE) + error_at (loc, "first argument to % not of type %"); + /* Let's handle things neutrallly, if expr: - has undeclared type, or - is not an va_list type. */ - return build_va_arg_1 (loc, type, expr); + return build_va_arg_1 (loc, type, error_mark_node); } if (TREE_CODE (canon_va_type) != ARRAY_TYPE) diff --git a/gcc/gimplify.c b/gcc/gimplify.c index 4715332eddf..288b4727dd8 100644 --- a/gcc/gimplify.c +++ b/gcc/gimplify.c @@ -11959,12 +11959,7 @@ 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) - { - error_at (loc, "first argument to % not of type %"); - return GS_ERROR; - } + gcc_assert (have_va_type != NULL_TREE); /* Generate a diagnostic for requesting data of a type that cannot be passed through `...' due to type promotion at the call site. */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 6deec7d351e..577df5111b1 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2016-08-29 Tom de Vries + + PR c/77398 + * g++.dg/ext/va-arg1.C: Add error check for illegal first argument. + 2016-08-29 Eric Botcazou * gcc.dg/ipa/iinline-attr.c: XFAIL on Visium. diff --git a/gcc/testsuite/g++.dg/ext/va-arg1.C b/gcc/testsuite/g++.dg/ext/va-arg1.C index 5606128e5f7..c0477adcb76 100644 --- a/gcc/testsuite/g++.dg/ext/va-arg1.C +++ b/gcc/testsuite/g++.dg/ext/va-arg1.C @@ -4,5 +4,7 @@ struct A {}; void foo() { - ++__builtin_va_arg(0, A); // { dg-error "operand type is 'A'" } + ++__builtin_va_arg (0, A); + // { dg-error "operand type is 'A'" "" {target *-*-*} "7" } + // { dg-error "first argument to 'va_arg' not of type 'va_list'" "" {target *-*-*} "7" } } -- 2.30.2