Commit ba9bbd6f by Tom de Vries Committed by Tom de Vries

Handle errors in both args of va_arg

2016-08-29  Tom de Vries  <tom@codesourcery.com>

	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
parent 6c77dacd
2016-08-29 Tom de Vries <tom@codesourcery.com>
PR c/77398
* gimplify.c (gimplify_va_arg_expr): Replace first argument type error
with assert.
2016-08-29 Eric Botcazou <ebotcazou@adacore.com> 2016-08-29 Eric Botcazou <ebotcazou@adacore.com>
* Makefile.in (gcov-iov.h): Add dummy recipe. * Makefile.in (gcov-iov.h): Add dummy recipe.
......
2016-08-29 Tom de Vries <tom@codesourcery.com>
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 <polacek@redhat.com> 2016-08-25 Marek Polacek <polacek@redhat.com>
David Malcolm <dmalcolm@redhat.com> David Malcolm <dmalcolm@redhat.com>
......
...@@ -5806,16 +5806,19 @@ build_va_arg (location_t loc, tree expr, tree type) ...@@ -5806,16 +5806,19 @@ build_va_arg (location_t loc, tree expr, tree type)
{ {
tree va_type = TREE_TYPE (expr); tree va_type = TREE_TYPE (expr);
tree canon_va_type = (va_type == error_mark_node tree canon_va_type = (va_type == error_mark_node
? NULL_TREE ? error_mark_node
: targetm.canonical_va_list_type (va_type)); : targetm.canonical_va_list_type (va_type));
if (va_type == error_mark_node if (va_type == error_mark_node
|| canon_va_type == NULL_TREE) || canon_va_type == NULL_TREE)
{ {
if (canon_va_type == NULL_TREE)
error_at (loc, "first argument to %<va_arg%> not of type %<va_list%>");
/* Let's handle things neutrallly, if expr: /* Let's handle things neutrallly, if expr:
- has undeclared type, or - has undeclared type, or
- is not an va_list type. */ - 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) if (TREE_CODE (canon_va_type) != ARRAY_TYPE)
......
...@@ -11959,12 +11959,7 @@ gimplify_va_arg_expr (tree *expr_p, gimple_seq *pre_p, ...@@ -11959,12 +11959,7 @@ gimplify_va_arg_expr (tree *expr_p, gimple_seq *pre_p,
if (have_va_type == error_mark_node) if (have_va_type == error_mark_node)
return GS_ERROR; return GS_ERROR;
have_va_type = targetm.canonical_va_list_type (have_va_type); have_va_type = targetm.canonical_va_list_type (have_va_type);
gcc_assert (have_va_type != NULL_TREE);
if (have_va_type == NULL_TREE)
{
error_at (loc, "first argument to %<va_arg%> not of type %<va_list%>");
return GS_ERROR;
}
/* Generate a diagnostic for requesting data of a type that cannot /* Generate a diagnostic for requesting data of a type that cannot
be passed through `...' due to type promotion at the call site. */ be passed through `...' due to type promotion at the call site. */
......
2016-08-29 Tom de Vries <tom@codesourcery.com>
PR c/77398
* g++.dg/ext/va-arg1.C: Add error check for illegal first argument.
2016-08-29 Eric Botcazou <ebotcazou@adacore.com> 2016-08-29 Eric Botcazou <ebotcazou@adacore.com>
* gcc.dg/ipa/iinline-attr.c: XFAIL on Visium. * gcc.dg/ipa/iinline-attr.c: XFAIL on Visium.
......
...@@ -4,5 +4,7 @@ struct A {}; ...@@ -4,5 +4,7 @@ struct A {};
void foo() 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" }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment